Modified WM hints handling which should be much better now.
[wxWidgets.git] / src / generic / msgdlgg.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/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
42 wxSize wxSplitMessage2( const wxString &message, wxWindow *parent )
43 {
44 int y = 10;
45 int w = 50;
46 wxString line( _T("") );
47 for (uint pos = 0; pos < message.Len(); pos++)
48 {
49 if (message[pos] == _T('\n'))
50 {
51 if (!line.IsEmpty())
52 {
53 wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) );
54 wxSize size1( s1->GetSize() );
55 if (size1.x > w) w = size1.x;
56 line = _T("");
57 }
58 y += 18;
59 }
60 else
61 {
62 line += message[pos];
63 }
64 }
65
66 if (!line.IsEmpty())
67 {
68 wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) );
69 wxSize size2( s2->GetSize() );
70 if (size2.x > w) w = size2.x;
71 }
72
73 y += 18;
74
75 return wxSize(w+30,y);
76 }
77
78 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
80 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
81 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
82 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
83 END_EVENT_TABLE()
84
85 IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
86 #endif
87
88 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString& message,
89 const wxString& caption, long style, const wxPoint& pos) :
90 wxDialog( parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE )
91 {
92 m_dialogStyle = style;
93
94 wxSize message_size( wxSplitMessage2( message, this ) );
95
96 wxButton *ok = (wxButton *) NULL;
97 wxButton *cancel = (wxButton *) NULL;
98 wxButton *yes = (wxButton *) NULL;
99 wxButton *no = (wxButton *) NULL;
100
101 int y = message_size.y + 30;
102
103 if (style & wxYES_NO)
104 {
105 yes = new wxButton( this, wxID_YES, _("Yes"), wxPoint(-1,y), wxSize(80,-1) );
106 m_buttons.Append( yes );
107 no = new wxButton( this, wxID_NO, _("No"), wxPoint(-1,y), wxSize(80,-1) );
108 m_buttons.Append( no );
109 }
110
111 if (style & wxOK)
112 {
113 ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) );
114 m_buttons.Append( ok );
115 }
116
117 if (style & wxCANCEL)
118 {
119 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) );
120 m_buttons.Append( cancel );
121 }
122
123 if (ok)
124 {
125 ok->SetDefault();
126 ok->SetFocus();
127 }
128 else if (yes)
129 {
130 yes->SetDefault();
131 yes->SetFocus();
132 }
133
134 int w = m_buttons.GetCount() * 100;
135 if (message_size.x > w) w = message_size.x;
136 int space = w / (m_buttons.GetCount()*2);
137
138 int n = 0;
139 wxNode *node = m_buttons.First();
140 while (node)
141 {
142 wxWindow *win = (wxWindow*)node->Data();
143 int x = (n*2+1)*space - 40 + 15;
144 win->Move( x, -1 );
145 node = node->Next();
146 n++;
147 }
148
149 SetSize( w+30, y+40 );
150
151 Centre( wxBOTH );
152 }
153
154 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
155 {
156 EndModal( wxID_YES );
157 }
158
159 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
160 {
161 EndModal( wxID_NO );
162 }
163
164 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
165 {
166 /* Allow cancellation via ESC/Close button except if
167 only YES and NO are specified. */
168 if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) )
169 {
170 EndModal( wxID_CANCEL );
171 }
172 }
173
174