Difference between revisions of "Framework/Article/Easy To Use Message Boxes"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Easy to use message boxes)
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== Easy to use message boxes ==
 
== Easy to use message boxes ==
  
OpenOffice.org 2.2 provides better support for 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:
+
OpenOffice.org 2.2 and later provide better support for 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:
 
<br/>
 
<br/>
The entry point is the well known uno awt service "com::sun::star::awt::Toolkit"
+
The entry point is the well known UNO AWT service '''com::sun::star::awt::Toolkit'''
  
<code>[cpp]
+
<source lang="cpp">
 
published service Toolkit
 
published service Toolkit
 
{
 
{
Line 16: Line 16:
 
   [optional] interface com::sun::star::awt::XMessageBoxFactory;
 
   [optional] interface com::sun::star::awt::XMessageBoxFactory;
 
};
 
};
</code>
+
</source>
  
 
This service now support one more optional interface called '''com::sun::star::awt::XMessageBoxFactory'''. The message box factory creates messages boxes and initialize them with one call. The caller has to provide all necessary arguments and gets back a reference to the newly created message box.
 
This service now support one more optional interface called '''com::sun::star::awt::XMessageBoxFactory'''. The message box factory creates messages boxes and initialize them with one call. The caller has to provide all necessary arguments and gets back a reference to the newly created message box.
  
<code>[cpp]
+
<source lang="cpp">
 
/** specifies a factory interface for creating message boxes.
 
/** specifies a factory interface for creating message boxes.
 
*/
 
*/
Line 45: Line 45:
 
        
 
        
 
       infobox    A message box to inform the user about a certain event.
 
       infobox    A message box to inform the user about a certain event.
 +
                  Attention:
 +
                  This type of message box ignores the argument aButton
 +
                  because a infobox always shows a OK button.
 
       warningbox A message to warn the user about a certain problem.
 
       warningbox A message to warn the user about a certain problem.
 
       errorbox  A message box to provide an error message to the user.
 
       errorbox  A message box to provide an error message to the user.
Line 69: Line 72:
 
                                 [in] string aMessage );
 
                                 [in] string aMessage );
 
};
 
};
</code>
+
</source>
  
<code>[cpp]
+
<source lang="cpp">
 
/** defines constants for the possible message box button
 
/** defines constants for the possible message box button
 
   combinations.
 
   combinations.
Line 126: Line 129:
 
   const long DEFAULT_BUTTON_IGNORE        = 0x60000;
 
   const long DEFAULT_BUTTON_IGNORE        = 0x60000;
 
};
 
};
</code>
+
</source>
  
 
Below you can see a simple example using OpenOffice.org Basic.
 
Below you can see a simple example using OpenOffice.org Basic.
<code>[cpp]
+
 
 +
<source lang="vb">
 
REM  *****  BASIC  *****
 
REM  *****  BASIC  *****
  
Line 142: Line 146:
 
      
 
      
 
     REM ***** Don not use getCurrentFrame() in your relase code!! *****
 
     REM ***** Don not use getCurrentFrame() in your relase code!! *****
     REM ***** This example uses it just be small *****
+
     REM ***** This example uses it just to be small *****
 
     oParent  = oDesktop.getCurrentFrame().getContainerWindow()
 
     oParent  = oDesktop.getCurrentFrame().getContainerWindow()
 
      
 
      
     oMsgBox  = oMsgBoxFactory.createMessageBox( oParent, aRectangle, "infobox", oButtons, "Title", "This is the message box text" )
+
     oMsgBox  = oMsgBoxFactory.createMessageBox( oParent, aRectangle, "messbox", oButtons, "Title", "This is the message box text" )
 
 
 
     oMsgBox.execute()
 
     oMsgBox.execute()
 
End Sub
 
End Sub
</code>
+
</source>
  
 
[[category:API]]
 
[[category:API]]
Line 155: Line 159:
 
[[category:Article]]
 
[[category:Article]]
 
[[category:Framework]]
 
[[category:Framework]]
 +
[[Category:Documentation/Developer]]
 +
{{Documentation/Candidate}}

Revision as of 12:55, 15 February 2008

Easy to use message boxes

OpenOffice.org 2.2 and later provide better support for 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

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 com::sun::star::awt::XMessageBoxFactory. The message box factory creates messages boxes and initialize them with one call. The caller has to provide all necessary arguments and gets back a reference to the newly created message box.

/** specifies a factory interface for creating message boxes.
*/
published interface XMessageBoxFactory : com::sun::star::uno::XInterface
{
   //-------------------------------------------------------------------------
     /** creates a message box.
 
       @returns
       the created message box or a null reference if it cannot be
       created.
 
       @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.
                  Attention:
                  This type of message box ignores the argument aButton
                  because a infobox always shows a OK button.
       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 );
};
/** defines constants for the possible message box button
   combinations.
 
*/
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 OpenOffice.org Basic.

REM  *****  BASIC  *****
 
Sub Main
    oMsgBoxFactory = createUnoService( "com.sun.star.awt.Toolkit" )
    oDesktop       = createUnoService( "com.sun.star.frame.Desktop" )
 
    REM ***** Empty rectangle means use default values *****
    Dim aRectangle as new com.sun.star.awt.Rectangle
 
    oButtons = com.sun.star.awt.MessageBoxButtons.BUTTONS_YES_NO_CANCEL+com.sun.star.awt.MessageBoxButtons.DEFAULT_BUTTON_YES
 
    REM ***** Don not use getCurrentFrame() in your relase code!! *****
    REM ***** This example uses it just to be small *****
    oParent  = oDesktop.getCurrentFrame().getContainerWindow()
 
    oMsgBox  = oMsgBoxFactory.createMessageBox( oParent, aRectangle, "messbox", oButtons, "Title", "This is the message box text" )
 
    oMsgBox.execute()
End Sub
Personal tools