]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/msgdlg.cpp
Small changed to wxExtDialog
[wxWidgets.git] / src / gtk1 / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlgg.cpp
3 // Purpose: wxGenericMessageDialog
4 // Author: Julian Smart, Robert Roebling
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart, Markus Holzem, Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "msgdlgg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/utils.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"
31 #include "wx/intl.h"
32 #include "wx/bitmap.h"
33 #endif
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "wx/gtk/msgdlg.h"
39 #include "wx/statline.h"
40
41 #include "wx/gtk/info.xpm"
42 #include "wx/gtk/error.xpm"
43 #include "wx/gtk/question.xpm"
44 #include "wx/gtk/warning.xpm"
45
46 ///////////////////////////////////////////////////////////////////
47 // New dialog box implementations
48
49 // Split message, using constraints to position controls
50 wxSize wxSplitMessage2( const wxString &message, wxWindow *parent, int text_pos_x )
51 {
52 int y = 15;
53 int w = 50;
54 wxString line( _T("") );
55 for (uint pos = 0; pos < message.Len(); pos++)
56 {
57 if (message[pos] == _T('\n'))
58 {
59 if (!line.IsEmpty())
60 {
61 wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(text_pos_x,y) );
62 wxSize size1( s1->GetSize() );
63 if (size1.x > w) w = size1.x;
64 line = _T("");
65 }
66 y += 18;
67 }
68 else
69 {
70 line += message[pos];
71 }
72 }
73
74 if (!line.IsEmpty())
75 {
76 wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(text_pos_x,y) );
77 wxSize size2( s2->GetSize() );
78 if (size2.x > w) w = size2.x;
79 }
80
81 y += 18;
82
83 return wxSize(w+15+text_pos_x,y);
84 }
85
86 #if !USE_SHARED_LIBRARY
87 BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
88 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
89 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
90 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
91 END_EVENT_TABLE()
92
93 IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
94 #endif
95
96 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString& message,
97 const wxString& caption, long style, const wxPoint& pos) :
98 wxDialog( parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE )
99 {
100 m_dialogStyle = style;
101
102 int text_pos_x = 15;
103
104 if (m_dialogStyle & wxICON_MASK)
105 text_pos_x += 80;
106
107 wxSize message_size( wxSplitMessage2( message, this, text_pos_x ) );
108
109 if (m_dialogStyle & wxICON_MASK)
110 if (message_size.y < 50) message_size.y = 50;
111
112 if (m_dialogStyle & wxICON_INFORMATION)
113 (void) new wxStaticBitmap( this, -1, wxBitmap( info_xpm ), wxPoint(15,message_size.y/2-16) );
114 else
115 if (m_dialogStyle & wxICON_HAND)
116 (void) new wxStaticBitmap( this, -1, wxBitmap( error_xpm ), wxPoint(15,message_size.y/2-16) );
117 else
118 if (m_dialogStyle & wxICON_QUESTION)
119 (void) new wxStaticBitmap( this, -1, wxBitmap( question_xpm ), wxPoint(15,message_size.y/2-16) );
120 else
121 if (m_dialogStyle & wxICON_EXCLAMATION)
122 (void) new wxStaticBitmap( this, -1, wxBitmap( warning_xpm ), wxPoint(15,message_size.y/2-16) );
123
124 wxButton *ok = (wxButton *) NULL;
125 wxButton *cancel = (wxButton *) NULL;
126 wxButton *yes = (wxButton *) NULL;
127 wxButton *no = (wxButton *) NULL;
128
129 int y = message_size.y + 30;
130
131 if (style & wxYES_NO)
132 {
133 yes = new wxButton( this, wxID_YES, _("Yes"), wxPoint(-1,y), wxSize(80,-1) );
134 m_buttons.Append( yes );
135 no = new wxButton( this, wxID_NO, _("No"), wxPoint(-1,y), wxSize(80,-1) );
136 m_buttons.Append( no );
137 }
138
139 if (style & wxOK)
140 {
141 ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) );
142 m_buttons.Append( ok );
143 }
144
145 if (style & wxCANCEL)
146 {
147 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) );
148 m_buttons.Append( cancel );
149 }
150
151 if (ok)
152 {
153 ok->SetDefault();
154 ok->SetFocus();
155 }
156 else if (yes)
157 {
158 yes->SetDefault();
159 yes->SetFocus();
160 }
161
162 int w = m_buttons.GetCount() * 100;
163 if (message_size.x > w) w = message_size.x;
164 int space = w / (m_buttons.GetCount()*2);
165
166 int n = 0;
167 wxNode *node = m_buttons.First();
168 while (node)
169 {
170 wxWindow *win = (wxWindow*)node->Data();
171 int x = (n*2+1)*space - 40 + 15;
172 win->Move( x, -1 );
173 node = node->Next();
174 n++;
175 }
176
177 #ifdef __WXGTK__
178 (void) new wxStaticLine( this, -1, wxPoint(0,y-20), wxSize(w+30, 5) );
179 #endif
180
181 SetSize( w+30, y+40 );
182
183 Centre( wxBOTH );
184 }
185
186 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
187 {
188 EndModal( wxID_YES );
189 }
190
191 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
192 {
193 EndModal( wxID_NO );
194 }
195
196 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
197 {
198 /* Allow cancellation via ESC/Close button except if
199 only YES and NO are specified. */
200 if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) )
201 {
202 EndModal( wxID_CANCEL );
203 }
204 }
205
206