]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlgg.cpp | |
3 | // Purpose: wxGenericMessageDialog | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
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/stattext.h" | |
29 | #include "wx/layout.h" | |
30 | #include "wx/intl.h" | |
31 | #endif | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <string.h> | |
35 | ||
36 | #include "wx/generic/msgdlgg.h" | |
37 | ||
38 | /////////////////////////////////////////////////////////////////// | |
39 | // New dialog box implementations | |
40 | ||
41 | // Split message, using constraints to position controls | |
87138c52 | 42 | void wxSplitMessage2(const wxChar *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer) |
c801d85f | 43 | { |
87138c52 | 44 | wxChar *copyMessage = copystring(message); |
c801d85f | 45 | size_t i = 0; |
87138c52 OK |
46 | size_t len = wxStrlen(copyMessage); |
47 | wxChar *currentMessage = copyMessage; | |
c801d85f KB |
48 | |
49 | // wxWindow *lastWindow = parent; | |
50 | ||
51 | while (i < len) { | |
87138c52 | 52 | while ((i < len) && (copyMessage[i] != _T('\n'))) i++; |
c801d85f KB |
53 | if (i < len) copyMessage[i] = 0; |
54 | wxStaticText *mess = new wxStaticText(parent, -1, currentMessage); | |
55 | ||
56 | /* | |
dfc54541 JS |
57 | wxLayoutConstraints *c = new wxLayoutConstraints; |
58 | c->left.SameAs (parent, wxLeft, 10); | |
59 | c->top.SameAs (lastWindow, wxBottom, 5); | |
60 | c->right.AsIs (); | |
61 | c->height.AsIs (); | |
c801d85f | 62 | |
dfc54541 | 63 | mess->SetConstraints(c); |
c801d85f | 64 | */ |
dfc54541 | 65 | sizer->AddSizerChild(mess); |
c801d85f KB |
66 | |
67 | messageList->Append(mess); | |
68 | ||
69 | currentMessage = copyMessage + i + 1; | |
70 | } | |
71 | delete[] copyMessage; | |
72 | } | |
73 | ||
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) | |
79 | END_EVENT_TABLE() | |
80 | ||
81 | IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog) | |
82 | #endif | |
83 | ||
84 | wxGenericMessageDialog::wxGenericMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption, | |
85 | long style, const wxPoint& pos): | |
dfc54541 JS |
86 | wxDialog(parent, -1, caption, pos, |
87 | #ifdef __WXMOTIF_ | |
88 | wxSize(400, 300), | |
89 | #else | |
90 | wxDefaultSize, | |
91 | #endif | |
92 | wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL) | |
c801d85f | 93 | { |
dfc54541 | 94 | m_dialogStyle = style; |
c801d85f | 95 | |
dfc54541 | 96 | wxBeginBusyCursor(); |
c801d85f | 97 | |
dfc54541 JS |
98 | wxSizer *topSizer = new wxSizer(this, wxSizerShrink); |
99 | topSizer->SetBorder(10, 10); | |
c801d85f | 100 | |
227e5e99 | 101 | // message sizer at the top |
dfc54541 | 102 | wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100); |
87138c52 | 103 | messageSizer->SetName(_T("messageSizer")); |
c801d85f KB |
104 | |
105 | // bool centre = ((style & wxCENTRE) == wxCENTRE); | |
106 | ||
dfc54541 JS |
107 | wxList messageList; |
108 | wxSplitMessage2(message, &messageList, this, messageSizer); | |
c801d85f | 109 | |
227e5e99 | 110 | // spacer size in the middle |
dfc54541 | 111 | wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 20); |
c801d85f | 112 | |
227e5e99 RR |
113 | // row size at the bottom |
114 | wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS ); | |
87138c52 | 115 | buttonSizer->SetName(_T("buttonSizer")); |
3502e687 | 116 | buttonSizer->SetSpacing(12,0); |
c801d85f | 117 | |
dfc54541 JS |
118 | // Specify constraints for the button sizer |
119 | wxLayoutConstraints *c = new wxLayoutConstraints; | |
120 | c->width.AsIs (); | |
121 | c->height.AsIs (); | |
122 | c->top.Below (spacingSizer); | |
227e5e99 RR |
123 | c->left.Absolute (10); |
124 | // c->centreX.SameAs (spacingSizer, wxCentreX); | |
dfc54541 | 125 | buttonSizer->SetConstraints(c); |
227e5e99 | 126 | |
c67daf87 | 127 | wxButton *ok = (wxButton *) NULL; |
dfc54541 JS |
128 | wxButton *cancel = (wxButton *) NULL; |
129 | wxButton *yes = (wxButton *) NULL; | |
130 | wxButton *no = (wxButton *) NULL; | |
131 | ||
132 | if (style & wxYES_NO) { | |
3502e687 RR |
133 | yes = new wxButton(this, wxID_YES, _("Yes"), wxDefaultPosition, wxSize(75,-1) ); |
134 | no = new wxButton(this, wxID_NO, _("No"), wxDefaultPosition, wxSize(75,-1) ); | |
dfc54541 JS |
135 | |
136 | buttonSizer->AddSizerChild(yes); | |
137 | buttonSizer->AddSizerChild(no); | |
138 | } | |
139 | ||
140 | if (style & wxOK) { | |
3502e687 | 141 | ok = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxSize(75,-1) ); |
dfc54541 JS |
142 | buttonSizer->AddSizerChild(ok); |
143 | } | |
144 | ||
145 | if (style & wxCANCEL) { | |
3502e687 | 146 | cancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(75,-1) ); |
dfc54541 JS |
147 | buttonSizer->AddSizerChild(cancel); |
148 | } | |
149 | ||
150 | if (ok) | |
151 | { | |
152 | ok->SetDefault(); | |
153 | ok->SetFocus(); | |
154 | } | |
155 | else if (yes) | |
156 | { | |
157 | yes->SetDefault(); | |
158 | yes->SetFocus(); | |
159 | } | |
160 | ||
161 | Layout(); | |
227e5e99 | 162 | |
c801d85f KB |
163 | Centre(wxBOTH); |
164 | ||
dfc54541 | 165 | wxEndBusyCursor(); |
c801d85f KB |
166 | } |
167 | ||
168 | void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) | |
169 | { | |
dfc54541 | 170 | EndModal(wxID_YES); |
c801d85f KB |
171 | } |
172 | ||
173 | void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) | |
174 | { | |
dfc54541 | 175 | EndModal(wxID_NO); |
c801d85f KB |
176 | } |
177 | ||
178 | void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
179 | { | |
dfc54541 JS |
180 | // Allow cancellation via ESC/Close button except if |
181 | // only YES and NO are specified. | |
182 | if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) ) | |
183 | EndModal(wxID_CANCEL); | |
c801d85f KB |
184 | } |
185 | ||
186 |