]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericMessageDialog
4 // Author: Julian Smart, Robert Roebling
8 // Copyright: (c) Julian Smart, Markus Holzem, Robert Roebling
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/statbmp.h"
29 #include "wx/stattext.h"
30 #include "wx/layout.h"
32 #include "wx/bitmap.h"
39 #include "wx/gtk/msgdlg.h"
40 #include "wx/statline.h"
42 ///////////////////////////////////////////////////////////////////
43 // New dialog box implementations
45 // Split message, using constraints to position controls
46 wxSize
wxSplitMessage2( const wxString
&message
, wxWindow
*parent
, int text_pos_x
)
50 wxString
line( _T("") );
51 for (uint pos
= 0; pos
< message
.Len(); pos
++)
53 if (message
[pos
] == _T('\n'))
57 wxStaticText
*s1
= new wxStaticText( parent
, -1, line
, wxPoint(text_pos_x
,y
) );
58 wxSize
size1( s1
->GetSize() );
59 if (size1
.x
> w
) w
= size1
.x
;
72 wxStaticText
*s2
= new wxStaticText( parent
, -1, line
, wxPoint(text_pos_x
,y
) );
73 wxSize
size2( s2
->GetSize() );
74 if (size2
.x
> w
) w
= size2
.x
;
79 return wxSize(w
+15+text_pos_x
,y
);
82 #if !USE_SHARED_LIBRARY
83 BEGIN_EVENT_TABLE(wxGenericMessageDialog
, wxDialog
)
84 EVT_BUTTON(wxID_YES
, wxGenericMessageDialog::OnYes
)
85 EVT_BUTTON(wxID_NO
, wxGenericMessageDialog::OnNo
)
86 EVT_BUTTON(wxID_CANCEL
, wxGenericMessageDialog::OnCancel
)
89 IMPLEMENT_CLASS(wxGenericMessageDialog
, wxDialog
)
92 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow
*parent
, const wxString
& message
,
93 const wxString
& caption
, long style
, const wxPoint
& pos
) :
94 wxDialog( parent
, -1, caption
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
)
96 m_dialogStyle
= style
;
100 if (m_dialogStyle
& wxICON_MASK
)
103 wxSize
message_size( wxSplitMessage2( message
, this, text_pos_x
) );
105 if (m_dialogStyle
& wxICON_MASK
)
107 if (message_size
.y
< 50) message_size
.y
= 50;
108 (void) new wxStaticBitmap( this, -1,
109 wxTheApp
->GetStdIcon(m_dialogStyle
111 wxPoint(15,message_size
.y
/2-16) );
114 wxButton
*ok
= (wxButton
*) NULL
;
115 wxButton
*cancel
= (wxButton
*) NULL
;
116 wxButton
*yes
= (wxButton
*) NULL
;
117 wxButton
*no
= (wxButton
*) NULL
;
119 int y
= message_size
.y
+ 30;
121 if (style
& wxYES_NO
)
123 yes
= new wxButton( this, wxID_YES
, _("Yes"), wxPoint(-1,y
), wxSize(80,-1) );
124 m_buttons
.Append( yes
);
125 no
= new wxButton( this, wxID_NO
, _("No"), wxPoint(-1,y
), wxSize(80,-1) );
126 m_buttons
.Append( no
);
131 ok
= new wxButton( this, wxID_OK
, _("OK"), wxPoint(-1,y
), wxSize(80,-1) );
132 m_buttons
.Append( ok
);
135 if (style
& wxCANCEL
)
137 cancel
= new wxButton( this, wxID_CANCEL
, _("Cancel"), wxPoint(-1,y
), wxSize(80,-1) );
138 m_buttons
.Append( cancel
);
152 int w
= m_buttons
.GetCount() * 100;
153 if (message_size
.x
> w
) w
= message_size
.x
;
154 int space
= w
/ (m_buttons
.GetCount()*2);
157 wxNode
*node
= m_buttons
.First();
160 wxWindow
*win
= (wxWindow
*)node
->Data();
161 int x
= (n
*2+1)*space
- 40 + 15;
169 (void) new wxStaticLine( this, -1, wxPoint(edge_margin
,y
-20), wxSize(w
+30-2*edge_margin
, 5) );
172 SetSize( w
+30, y
+40 );
177 void wxGenericMessageDialog::OnYes(wxCommandEvent
& WXUNUSED(event
))
179 EndModal( wxID_YES
);
182 void wxGenericMessageDialog::OnNo(wxCommandEvent
& WXUNUSED(event
))
187 void wxGenericMessageDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
189 /* Allow cancellation via ESC/Close button except if
190 only YES and NO are specified. */
191 if ( (m_dialogStyle
& wxYES_NO
) != wxYES_NO
|| (m_dialogStyle
& wxCANCEL
) )
193 EndModal( wxID_CANCEL
);