]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/msgdlgg.cpp
9ad504ce9411ac20a32a1880e1dd936a44e435a8
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxGenericMessageDialog 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart and Markus Holzem 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "msgdlgg.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  25 #include "wx/dialog.h" 
  26 #include "wx/listbox.h" 
  27 #include "wx/button.h" 
  28 #include "wx/stattext.h" 
  29 #include "wx/layout.h" 
  36 #include "wx/generic/msgdlgg.h" 
  38 /////////////////////////////////////////////////////////////////// 
  39 // New dialog box implementations 
  41 // Split message, using constraints to position controls 
  42 void wxSplitMessage2(const char *message
, wxList 
*messageList
, wxWindow 
*parent
, wxRowColSizer 
*sizer
) 
  44   char *copyMessage 
= copystring(message
); 
  46   size_t len 
= strlen(copyMessage
); 
  47   char *currentMessage 
= copyMessage
; 
  49 //  wxWindow *lastWindow = parent; 
  52     while ((i 
< len
) && (copyMessage
[i
] != '\n')) i
++; 
  53     if (i 
< len
) copyMessage
[i
] = 0; 
  54     wxStaticText 
*mess 
= new wxStaticText(parent
, -1, currentMessage
); 
  57     wxLayoutConstraints *c = new wxLayoutConstraints; 
  58     c->left.SameAs              (parent, wxLeft, 10); 
  59     c->top.SameAs               (lastWindow, wxBottom, 5); 
  63     mess->SetConstraints(c); 
  65     sizer
->AddSizerChild(mess
); 
  67     messageList
->Append(mess
); 
  69     currentMessage 
= copyMessage 
+ i 
+ 1; 
  74 #if !USE_SHARED_LIBRARY 
  75 BEGIN_EVENT_TABLE(wxGenericMessageDialog
, wxDialog
) 
  76         EVT_BUTTON(wxID_YES
, wxGenericMessageDialog::OnYes
) 
  77         EVT_BUTTON(wxID_NO
, wxGenericMessageDialog::OnNo
) 
  78         EVT_BUTTON(wxID_CANCEL
, wxGenericMessageDialog::OnCancel
) 
  81 IMPLEMENT_CLASS(wxGenericMessageDialog
, wxDialog
) 
  84 wxGenericMessageDialog::wxGenericMessageDialog(wxWindow 
*parent
, const wxString
& message
, const wxString
& caption
, 
  85         long style
, const wxPoint
& pos
): 
  86         wxDialog(parent
, -1, caption
, pos
, 
  92            wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
) 
  94     m_dialogStyle 
= style
; 
  98     wxSizer 
*topSizer 
= new wxSizer(this, wxSizerShrink
); 
  99     topSizer
->SetBorder(10, 10); 
 101     wxRowColSizer 
*messageSizer 
= new wxRowColSizer(topSizer
, wxSIZER_COLS
, 100); 
 102     messageSizer
->SetName("messageSizer"); 
 104 //    bool centre = ((style & wxCENTRE) == wxCENTRE); 
 107     wxSplitMessage2(message
, &messageList
, this, messageSizer
); 
 110     wxSpacingSizer 
*spacingSizer 
= new wxSpacingSizer(topSizer
, wxBelow
, messageSizer
, 20); 
 112     wxRowColSizer 
*buttonSizer 
= new wxRowColSizer(topSizer
, wxSIZER_ROWS
); 
 113     buttonSizer
->SetName("buttonSizer"); 
 114     buttonSizer
->SetSpacing(12,0); 
 116     // Specify constraints for the button sizer 
 117     wxLayoutConstraints 
*c 
= new wxLayoutConstraints
; 
 120     c
->top
.Below                (spacingSizer
); 
 121     c
->centreX
.SameAs   (spacingSizer
, wxCentreX
); 
 122     buttonSizer
->SetConstraints(c
); 
 124     wxButton 
*ok 
= (wxButton 
*) NULL
; 
 125     wxButton 
*cancel 
= (wxButton 
*) NULL
; 
 126     wxButton 
*yes 
= (wxButton 
*) NULL
; 
 127     wxButton 
*no 
= (wxButton 
*) NULL
; 
 129     if (style 
& wxYES_NO
) { 
 130        yes 
= new wxButton(this, wxID_YES
, _("Yes"), wxDefaultPosition
, wxSize(75,-1) ); 
 131        no 
= new wxButton(this, wxID_NO
, _("No"), wxDefaultPosition
, wxSize(75,-1) ); 
 133        buttonSizer
->AddSizerChild(yes
); 
 134        buttonSizer
->AddSizerChild(no
); 
 138         ok 
= new wxButton(this, wxID_OK
, _("OK"), wxDefaultPosition
, wxSize(75,-1) ); 
 139         buttonSizer
->AddSizerChild(ok
); 
 142     if (style 
& wxCANCEL
) { 
 143         cancel 
= new wxButton(this, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxSize(75,-1) ); 
 144         buttonSizer
->AddSizerChild(cancel
); 
 164 void wxGenericMessageDialog::OnYes(wxCommandEvent
& WXUNUSED(event
)) 
 169 void wxGenericMessageDialog::OnNo(wxCommandEvent
& WXUNUSED(event
)) 
 174 void wxGenericMessageDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
)) 
 176     // Allow cancellation via ESC/Close button except if 
 177     // only YES and NO are specified. 
 178     if ( (m_dialogStyle 
& wxYES_NO
) != wxYES_NO 
|| (m_dialogStyle 
& wxCANCEL
) ) 
 179         EndModal(wxID_CANCEL
);