]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlgg.cpp | |
3 | // Purpose: wxGenericMessageDialog | |
15b24b14 | 4 | // Author: Julian Smart, Robert Roebling |
c801d85f KB |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
15b24b14 | 8 | // Copyright: (c) Julian Smart, Markus Holzem, Robert Roebling |
f03fc89f | 9 | // Licence: wxWindows license |
c801d85f KB |
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 | ||
b0351fc9 RR |
38 | #ifdef __WXGTK__ |
39 | #include "wx/statline.h" | |
40 | #endif | |
41 | ||
c801d85f KB |
42 | /////////////////////////////////////////////////////////////////// |
43 | // New dialog box implementations | |
44 | ||
45 | // Split message, using constraints to position controls | |
15b24b14 | 46 | wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) |
c801d85f | 47 | { |
15b24b14 RR |
48 | int y = 10; |
49 | int w = 50; | |
50 | wxString line( _T("") ); | |
51 | for (uint pos = 0; pos < message.Len(); pos++) | |
52 | { | |
53 | if (message[pos] == _T('\n')) | |
f03fc89f VZ |
54 | { |
55 | if (!line.IsEmpty()) | |
56 | { | |
57 | wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); | |
58 | wxSize size1( s1->GetSize() ); | |
59 | if (size1.x > w) w = size1.x; | |
60 | line = _T(""); | |
61 | } | |
62 | y += 18; | |
63 | } | |
64 | else | |
65 | { | |
66 | line += message[pos]; | |
67 | } | |
15b24b14 RR |
68 | } |
69 | ||
70 | if (!line.IsEmpty()) | |
71 | { | |
f03fc89f VZ |
72 | wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); |
73 | wxSize size2( s2->GetSize() ); | |
74 | if (size2.x > w) w = size2.x; | |
15b24b14 | 75 | } |
f03fc89f | 76 | |
15b24b14 RR |
77 | y += 18; |
78 | ||
79 | return wxSize(w+30,y); | |
c801d85f KB |
80 | } |
81 | ||
82 | #if !USE_SHARED_LIBRARY | |
83 | BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog) | |
f03fc89f VZ |
84 | EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes) |
85 | EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo) | |
86 | EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel) | |
c801d85f KB |
87 | END_EVENT_TABLE() |
88 | ||
89 | IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog) | |
90 | #endif | |
91 | ||
15b24b14 RR |
92 | wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString& message, |
93 | const wxString& caption, long style, const wxPoint& pos) : | |
aa64626e | 94 | wxDialog( parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ) |
c801d85f | 95 | { |
dfc54541 | 96 | m_dialogStyle = style; |
c801d85f | 97 | |
15b24b14 | 98 | wxSize message_size( wxSplitMessage2( message, this ) ); |
c801d85f | 99 | |
c67daf87 | 100 | wxButton *ok = (wxButton *) NULL; |
dfc54541 JS |
101 | wxButton *cancel = (wxButton *) NULL; |
102 | wxButton *yes = (wxButton *) NULL; | |
103 | wxButton *no = (wxButton *) NULL; | |
15b24b14 RR |
104 | |
105 | int y = message_size.y + 30; | |
106 | ||
107 | if (style & wxYES_NO) | |
108 | { | |
109 | yes = new wxButton( this, wxID_YES, _("Yes"), wxPoint(-1,y), wxSize(80,-1) ); | |
f03fc89f | 110 | m_buttons.Append( yes ); |
15b24b14 | 111 | no = new wxButton( this, wxID_NO, _("No"), wxPoint(-1,y), wxSize(80,-1) ); |
f03fc89f | 112 | m_buttons.Append( no ); |
dfc54541 JS |
113 | } |
114 | ||
15b24b14 RR |
115 | if (style & wxOK) |
116 | { | |
117 | ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) ); | |
f03fc89f | 118 | m_buttons.Append( ok ); |
dfc54541 JS |
119 | } |
120 | ||
15b24b14 RR |
121 | if (style & wxCANCEL) |
122 | { | |
123 | cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) ); | |
f03fc89f | 124 | m_buttons.Append( cancel ); |
dfc54541 JS |
125 | } |
126 | ||
127 | if (ok) | |
128 | { | |
15b24b14 RR |
129 | ok->SetDefault(); |
130 | ok->SetFocus(); | |
dfc54541 JS |
131 | } |
132 | else if (yes) | |
133 | { | |
15b24b14 RR |
134 | yes->SetDefault(); |
135 | yes->SetFocus(); | |
dfc54541 | 136 | } |
227e5e99 | 137 | |
15b24b14 RR |
138 | int w = m_buttons.GetCount() * 100; |
139 | if (message_size.x > w) w = message_size.x; | |
140 | int space = w / (m_buttons.GetCount()*2); | |
141 | ||
142 | int n = 0; | |
143 | wxNode *node = m_buttons.First(); | |
144 | while (node) | |
145 | { | |
146 | wxWindow *win = (wxWindow*)node->Data(); | |
f03fc89f VZ |
147 | int x = (n*2+1)*space - 40 + 15; |
148 | win->Move( x, -1 ); | |
15b24b14 | 149 | node = node->Next(); |
f03fc89f | 150 | n++; |
15b24b14 RR |
151 | } |
152 | ||
88ac883a | 153 | #if wxUSE_STATICLINE |
b0351fc9 RR |
154 | (void) new wxStaticLine( this, -1, wxPoint(0,y-20), wxSize(w+30, 5) ); |
155 | #endif | |
156 | ||
15b24b14 | 157 | SetSize( w+30, y+40 ); |
c801d85f | 158 | |
15b24b14 | 159 | Centre( wxBOTH ); |
c801d85f KB |
160 | } |
161 | ||
162 | void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) | |
163 | { | |
15b24b14 | 164 | EndModal( wxID_YES ); |
c801d85f KB |
165 | } |
166 | ||
167 | void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) | |
168 | { | |
15b24b14 | 169 | EndModal( wxID_NO ); |
c801d85f KB |
170 | } |
171 | ||
172 | void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
173 | { | |
15b24b14 RR |
174 | /* Allow cancellation via ESC/Close button except if |
175 | only YES and NO are specified. */ | |
dfc54541 | 176 | if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) ) |
15b24b14 RR |
177 | { |
178 | EndModal( wxID_CANCEL ); | |
179 | } | |
c801d85f KB |
180 | } |
181 | ||
182 |