[main]    [up]  

WxExtLib - MessageExtDialog.h

00001: // -*- c++ -*-
00002: /*
00003: -------------------------------------------------------------------------
00004: This file is part of WxWidgetsExtensions library.
00005: -------------------------------------------------------------------------
00006: 
00007: WxExtLib (WxWidgetsExtensions) library
00008: -----------------------------
00009: 
00010: COPYRIGHT NOTICE:
00011: 
00012: WxExtLib library Copyright (c) 2003-2007 Daniel Käps
00013: 
00014: The WxWidgetsExtensions library and associated documentation files (the
00015: "Software") is provided "AS IS".  The author(s) disclaim all
00016: warranties, expressed or implied, including, without limitation, the
00017: warranties of merchantability and of fitness for any purpose.  The
00018: author(s) assume no liability for direct, indirect, incidental,
00019: special, exemplary, or consequential damages, which may result from
00020: the use of or other dealings in the Software, even if advised of the
00021: possibility of such damage.
00022: 
00023: Permission is hereby granted, free of charge, to any person obtaining
00024: a copy of this Software, to deal in the Software without restriction,
00025: including without limitation the rights to use, copy, modify, merge,
00026: publish, distribute, sublicense, and/or sell copies of the Software,
00027: and to permit persons to whom the Software is furnished to do so,
00028: subject to the following conditions:
00029: 
00030:  1. The origin of this source code must not be misrepresented.
00031:  2. Altered versions must be plainly marked as such and must not be
00032:     misrepresented as being the original source.
00033:  3. This Copyright notice may not be removed or altered from any 
00034:     source or altered source distribution.
00035: 
00036: End of WxExtLib library Copyright Notice
00037: 
00038: -------------------------------------------------------------------------
00039: 
00040: RATIONALE
00041: 
00042: The normal wxMessageBox supports only predefined sets of Buttons --
00043: this is a disadvantage, because the naming of the buttons cannot be
00044: done specific to the problem. The used messagebox implementations in
00045: X11, Motif, GTK, MSW seem to be equally restricted.
00046: 
00047: Examples (flags for MSW C-API): 
00048: 1) An error occured, but there is only the MB_OK style (which produces a
00049:    MessageBox with a single 'OK' button). However, a single 'Cancel'
00050:    button would be more appropriate.
00051: 2) The user is asked whether he/she wants to save a file. The buttons
00052:    can be named 'Yes/No/Cancel' with the MB_YESNOCANCEL style, but with
00053:    the normal MessageBox we cannot label the buttons
00054:    'Save/Discard/Cancel'. 'Save/Discard/Cancel' should be faster
00055:    recognizable than 'Yes/No/Cancel', because the actions are quite clear
00056:    even without reading the question.
00057: 
00058: Another disadvantage of the normal MessageBox implementations is that
00059: the message text cannot be copied to the clipboard. This is just
00060: impractical if the user wants, for example, to note an uncommon error
00061: message. Moreover, automatic linebreak and automatic use of scrollbars
00062: for long message texts would be desireable.
00063: 
00064: wxMessageExtDialog tries to overcome these shortcomings by providing a
00065: dialog class which allows specification of a message text, a title and
00066: arbitrary named buttons. It also tries to keep the usage of the
00067: programming interface simple, so that using the class isn't much
00068: more complicated than calling e.g. wxMessageBox().
00069: 
00070: Automatic line-break (wrapping) and scrolling is solved in
00071: wxMessageExtDialog by using either a wxTextCtrl or wxHtmlWindow (in case
00072: wxTextCtrl's functionality is not sufficient under the used platform).
00073: 
00074: Copying to the clipboard is possible if the used control supports it
00075: (works for wxTextCtrl under MSW; doesn't work for wxHtmlWindow in
00076: wxWindows 2.4.1; works for wxHtmlWindow in wxWidgets 2.5.2 in GTK
00077: port).
00078: 
00079: ------------------------------------------------------------------------- */
00080: 
00081: #ifndef _INCLUDED_MessageExtDialog_h
00082: #define _INCLUDED_MessageExtDialog_h
00083: 
00084: #include "WxExtLibConfig.h"
00085: 
00086: #define M_MessageExtDialog_EnableCInterface
00087: #ifdef __cplusplus
00088: #   define M_MessageExtDialog_EnableCxxInterface
00089: #endif
00090: 
00091: // can #define M_MessageExtDialog_EnableCInterface to get 
00092: // global/static functions to display a dialog box callable from C-code.
00093: // May be useful if an application consists of mixed C and C++ source code
00094: // (these C functions are only wrappers, actual functionality is provided 
00095: // from C++ code).
00096: 
00097: //-------------------------------------------------------------------------
00098: 
00099: #ifdef M_MessageExtDialog_EnableCxxInterface
00100: 
00101: #if defined(__GNUG__) && (!defined(__APPLE__)) && (!(defined M_NoPragmaInterface))
00102: #   pragma interface "MessageExtDialog.h"
00103: #endif
00104: 
00105: #include <wx/defs.h>
00106: 
00107: #ifndef WX_PRECOMP
00108: #   include <wx/dialog.h>
00109: #endif
00110: 
00111: #include "WxExtDialog.h"
00112: #include "WxMisc.h"
00113: 
00114: //-------------------------------------------------------------------------
00115: 
00116: #define M_IsDefineExportMagic 1
00117: #    include "WxExtLibAliases.h"
00118: #undef M_IsDefineExportMagic
00119: 
00120: //-------------------------------------------------------------------------
00121: 
00122: // wxMessageExtDialog:
00123: // - support for arbitrary named buttons
00124: // - support for automatic line-wrap and use of scrollbars in case
00125: //   of long message texts
00126: // - indication of message box style via wxColourBarWindow
00127: // - message and button text font is a little bigger than normal text
00128: //   to increase readability
00129: // - allows definition of a global title postfix added to all wxMessageExtDialog
00130: //   titles (could be set, for example, to the application's name)
00131: // - easy to use functions MessageExtDialog() (in case only an 'OK' button
00132: //   is required)
00133: // - finally, a HTML mode was added: it is now possible to display HTML messages
00134: // Notes:
00135: // - don't confuse this class with wxMessageDialog - wxMessageDialog is currently
00136: //   only a wrapper to the platform specific message box implementation;
00137: //   wxGenericMessageDialog is also quite restricted
00138: class wxMessageExtDialog: public wxExtDialog
00139: {
00140: public:
00141:     // DEF if the IsHtmlMode flag is specified, MessageString must be a HTML
00142:     // string (without the <html>, <body> tags - they are added automatically)
00143: 
00144:     //-------------------------------------------------------------------------
00145:     //-- construction, destruction
00146:     wxMessageExtDialog ();
00147:     wxMessageExtDialog (wxWindow *ParentWindow,
00148:                       const wxString & MessageString,
00149:                       const wxString & TitleString = wxEmptyString);
00150:     void Create (wxWindow *ParentWindow,
00151:                  const wxString & MessageString,
00152:                  const wxString & TitleString = wxEmptyString);
00153:     void init (const wxString & MessageString, const wxString & TitleString);
00154: 
00155:     //-------------------------------------------------------------------------
00156:     //-- set title postfix that is added to all titles
00157:     static void setGlobalTitlePostfix (const wxString & String);
00158:     static void getGlobalTitlePostfix (wxString & String);
00159:     static void setGlobalMessageExtDialogZoom (double ZoomValue);
00160:     static double getGlobalMessageExtDialogZoom ();
00161:     static void setGlobalGetDefaultParentWindowFunc (wxDefaultParentWindowFunc Func);
00162:   
00163:     wxWindow * getUsedParentWindow (wxWindow * ParentWindow);
00164: 
00165:     //-- message to display
00166:     void setDialogMessage (const wxString & MessageString);
00167: 
00168:     //-- button managment
00169:     wxMessageExtDialog & addButton (const wxString & Label,
00170:                                   int ButtonIdent);
00171:     // DEF addButton(Label) returns the generated ButtonIdent/Control Id
00172:     int addButton (const wxString & Label);
00173:     void makeLastAddedButtonDefault ();
00174: 
00175:     wxButton * getButton (int ButtonIdent);
00176:     void enableButton (int ButtonIdent, bool IsEnable = true);
00177:     void setButtonLabel (int ButtonIdent, const wxString & LabelString);
00178: 
00179:     //-- status control
00180:     // (status control could be useful if deriving from wxMessageExtDialog)
00181:     wxMessageExtDialog & addStatusTextCtrl ();
00182: 
00183:     //-- message box style
00184:     // style is visualized with a wxColourBarWindow (don't like icons
00185:     // to visualize message box type, and believe that for the purpose
00186:     // of visualizing message box type, an icon does not make a lot of 
00187:     // sense from a perceptual point of view - maybe unless the icon/image
00188:     // is specific for the problem/message box text).
00189:     enum EStyle 
00190:     {
00191:       MessageStyle          = 0x0001, 
00192:       InformationStyle,
00193:       WarningStyle,
00194:       ErrorStyle,
00195:       CriticalErrorStyle,
00196:       QuestionStyle,
00197:       StyleMask             = 0x000F,
00198:       
00199:       IsHtmlMode            = 0x0100
00200:     };
00201:     /* EStyle */ long m_Style;
00202:     void setStyle (/* EStyle */ long Style);
00203: 
00204:     enum EFlags
00205:     {
00206:       DisplayColourBar      = 0x0001,
00207:       DisplayImage          = 0x0002
00208:     };
00209:     static void setGlobalFlags (/* EFlags */ long Flags);
00210:     
00211:     //-- show dialog and return pressed ButtonIdent
00212:     virtual int ShowModal ();
00213: 
00214:     //-------------------------------------------------------------------------
00215:     //-- message handling:
00216:     virtual void OnCancel(wxCommandEvent & Event);
00217:     virtual void OnOK(wxCommandEvent & Event);
00218:     virtual void OnButtonEvent (wxCommandEvent & Event);
00219:     virtual void handleButtonEvent (wxCommandEvent & Event);
00220: 
00221:     void OnChar (wxKeyEvent & KeyEvent);
00222:     void OnKeyDown (wxKeyEvent & KeyEvent);
00223: 
00224:     //-- actual creation of controls
00225:     void createControls ();
00226: 
00227:  private:
00228: 
00229:     //-------------------------------------------------------------------------
00230:     wxFont m_TextCtrlFont;
00231:     wxFont m_ButtonFont;
00232: 
00233:     wxSizer * m_PanelSizer;
00234:     wxMultiLineText m_MessageMultiLineText;
00235: 
00236:     wxFlexGridSizer * m_ButtonFlexGridSizer;
00237:     wxButton * m_DefaultButton;
00238:     wxButton * m_LastAddedButton;
00239: 
00240:     //-------------------------------------------------------------------------
00241:     // WARN Automatically choosen button idents may conflict with dialog
00242:     // controls in other windows, must check this
00243:     // maybe one should better use the automatically choosen control idents 
00244:     // choosen by wxWindows, don't know which is better
00245:     enum
00246:     {
00247:       FirstAutoButtonIdent = 50
00248:     };
00249:     int m_LastAddedAutoButtonIdent;
00250:     int m_CurrentButtonIndex;
00251: 
00252:     wxString m_DialogMessageString;
00253:     wxString m_TitleString;
00254:     static wxString s_GlobalTitlePostfix;
00255:     static double s_GlobalMessageExtDialogZoom;
00256:     static long s_GlobalFlags;
00257:     // now in WxMisc:
00258:     //   static wxGetDefaultParentWindowFunc s_GlobalGetDefaultParentWindowFunc;
00259: 
00260:     bool m_IsControlsCreated;
00261: 
00262:  public:
00263:     wxButton * findButtonForKey (char KeyChar);
00264: 
00265:     DECLARE_EVENT_TABLE()
00266: };
00267: 
00268: 
00269: //-------------------------------------------------------------------------
00270: 
00271: // easy-to-use functions to display a message dialog that contains
00272: // the specified message and an "OK" button
00273: // - if the IsHtmlMode flag is specified, MessageString must be a HTML
00274: //   string (without the <html>, <body> tags - they are added automatically)
00275: // TODO 
00276: // - add possibility to specify button label
00277: // - could provide overloads for one, two, three (arbitrary) buttons
00278: extern int MessageExtDialog (wxWindow * ParentWindow,
00279:                              const wxString & MessageString,
00280:                              const wxString & TitleString,
00281:                              /* wxMessageExtDialog::EStyle */ long Style);
00282: 
00283: extern int MessageExtDialog (const wxString & MessageString,
00284:                              const wxString & TitleString,
00285:                              /* wxMessageExtDialog::EStyle */ long Style);
00286: 
00287: extern int MessageExtDialog (const wxString & MessageString,
00288:                              /* wxMessageExtDialog::EStyle */ long Style);
00289: 
00290: extern int MessageExtDialog (const wxString & MessageString);
00291: 
00292: //-------------------------------------------------------------------------
00293: 
00294: #define M_IsUndefExportMagic 1
00295: #    include "WxExtLibAliases.h"
00296: #undef M_IsUndefExportMagic
00297: 
00298: //-------------------------------------------------------------------------
00299: 
00300: #endif // M_MessageExtDialog_EnableCxxInterface
00301: #ifdef M_MessageExtDialog_EnableCInterface
00302: 
00303: // interface for code compiled in C mode:
00304: 
00305: #ifdef __cplusplus
00306: extern "C"
00307: {
00308: #endif
00309: 
00310: // repeat style definitions from inside the wxMessageExtDialog class:
00311: enum EMessageExtDialogStyle
00312: {
00313:   wxMessageExtDialog_MessageStyle          = 0x0001, 
00314:   wxMessageExtDialog_InformationStyle,
00315:   wxMessageExtDialog_WarningStyle,
00316:   wxMessageExtDialog_ErrorStyle,
00317:   wxMessageExtDialog_CriticalErrorStyle,
00318:   wxMessageExtDialog_QuestionStyle,
00319:   wxMessageExtDialog_IsHtmlMode            = 0x0100
00320: };
00321: 
00322: M_WxExtLib_ExportDecl int MessageExtDialog_ (const char * MessageString,
00323:                                             EMessageExtDialogStyle Style);
00324: 
00325: #ifdef __cplusplus
00326: }
00327: #endif
00328: 
00329: #endif  // M_MessageExtDialog_EnableCInterface
00330: 
00331: //-------------------------------------------------------------------------
00332: 
00333: #endif
00334: 
  [main]    [up]  
DaicasWeb v.1.50.0102  //   Daniel Käps  //   April 12, 2007  //   Impressum / Imprint 
http://www.daicas.net/WxExtLib/src/MessageExtDialog.h.html