Framework/WorkInProgress/Easy To Use Message Boxes

From Apache OpenOffice Wiki
Jump to: navigation, search

Easy to use message boxes

For 2.2 we want to help 3rd party developers to use UNO AWT. Easy to use message boxes is one of our efforts to make the uno awt much more appealing. The new way to create a message box is much easier:
The entry point is the well known uno awt service "com::sun::star::awt::Toolkit"

[cpp] published service Toolkit {

  interface XToolkit;
  [optional] interface com::sun::star::awt::XDataTransferProviderAccess;
  [optional] interface com::sun::star::awt::XSystemChildFactory;
  [optional] interface com::sun::star::awt::XMessageBoxFactory;


This service now support one more optional interface called XMessageBoxFactory. The message box factory creates messages boxes and initialize them with one call. The caller has to provide all necessary arguments and retrieves a reference to the message box.

[cpp] /** specifies a factory interface for creating message boxes.

  • /

published interface XMessageBoxFactory : com::sun::star::uno::XInterface {

    /** creates a message box.
      the created message box or a null reference if it cannot be
      @param aParent
      a valid XWindowPeer reference which is used as a parent. This parameter
      must not be null.
      @param aPosSize
      a rectangle which defines the position and size of the message
      box in pixel.
      @param aType
      a string which determines the message box type.
      The following strings are defined.
      infobox    A message box to inform the user about a certain event.
      warningbox A message to warn the user about a certain problem.
      errorbox   A message box to provide an error message to the user.
      querybox   A message box to query information from the user.
      messbox    A normal message box.
      @param aButtons
      specifies which buttons should be available on the
      message box. A combination of com::sun::star::awt::MessageBoxButtons. 
      An infobox ignores this paramter and always use button "OK".
      @param aTitle
      specifies the title of the message box.
      @param aMessage
      specifies text which will be shown by the message box.
      Line-breaks must be added using 'CR' or 'CR+LF'.
  XMessageBox createMessageBox( [in] com::sun::star::awt::XWindowPeer aParent, 
                                [in] com::sun::star::awt::Rectangle aPosSize, 
                                [in] string aType, 
                                [in] long aButtons, 
                                [in] string aTitle, 
                                [in] string aMessage );


[cpp] /** defines constants for the possible message box button

  • /

constants MessageBoxButtons {

  /** specifies a message with "OK" button.
  const long BUTTONS_OK                   = 1;
  /** specifies a message box with "OK" and "CANCEL" button.
  const long BUTTONS_OK_CANCEL            = 2;
  /** specifies a message box with "YES" and "NO" button.
  const long BUTTONS_YES_NO               = 3;
  /** specifies a message box with "YES", "NO" and "CANCEL" button.
  const long BUTTONS_YES_NO_CANCEL        = 4;
  /** specifies a message box with "RETRY" and "CANCEL" button.
  const long BUTTONS_RETRY_CANCEL         = 5;
  /** specifies a message box with "ABORT", "IGNORE" and "RETRY" button.
  const long BUTTONS_ABORT_IGNORE_RETRY   = 6;
  /** specifies that OK is the default button.
  const long DEFAULT_BUTTON_OK            = 0x10000;
     /** specifies that CANCEL is the default button.
  const long DEFAULT_BUTTON_CANCEL        = 0x20000;
  /** specifies that RETRY is the default button.
  const long DEFAULT_BUTTON_RETRY         = 0x30000;
     /** specifies that YES is the default button.
  const long DEFAULT_BUTTON_YES           = 0x40000;
  /** specifies that NO is the default button.
  const long DEFAULT_BUTTON_NO            = 0x50000;
  /** specifies that IGNORE is the default button.
  const long DEFAULT_BUTTON_IGNORE        = 0x60000;


Below you can see a simple example using Basic. [cpp] REM ***** BASIC *****

Sub Main

   oMsgBoxFactory = createUnoService( "" )
   oDesktop       = createUnoService( "" )
   REM ***** Empty rectangle means use default values *****
   Dim aRectangle as new
   oButtons =
   REM ***** Don't use getCurrentFrame() in your relase code!! *****
   REM ***** This example uses it just be small *****
   oParent  = oDesktop.getCurrentFrame().getContainerWindow()
   oMsgBox  = oMsgBoxFactory.createMessageBox( oParent, aRectangle, "infobox", oButtons, "Title", "This is the message box text" )

End Sub

Personal tools