]> git.saurik.com Git - wxWidgets.git/blob - src/generic/msgdlgg.cpp
wxGetUserName() returns the user name (wxGetUserId()) if all else fails
[wxWidgets.git] / src / generic / msgdlgg.cpp
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
42 void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer)
43 {
44 char *copyMessage = copystring(message);
45 size_t i = 0;
46 size_t len = strlen(copyMessage);
47 char *currentMessage = copyMessage;
48
49 // wxWindow *lastWindow = parent;
50
51 while (i < len) {
52 while ((i < len) && (copyMessage[i] != '\n')) i++;
53 if (i < len) copyMessage[i] = 0;
54 wxStaticText *mess = new wxStaticText(parent, -1, currentMessage);
55
56 /*
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 ();
62
63 mess->SetConstraints(c);
64 */
65 sizer->AddSizerChild(mess);
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):
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)
93 {
94 m_dialogStyle = style;
95
96 wxBeginBusyCursor();
97
98 wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
99 topSizer->SetBorder(10, 10);
100
101 wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
102 messageSizer->SetName("messageSizer");
103
104 // bool centre = ((style & wxCENTRE) == wxCENTRE);
105
106 wxList messageList;
107 wxSplitMessage2(message, &messageList, this, messageSizer);
108
109 // Insert a spacer
110 wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 20);
111
112 wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
113 buttonSizer->SetName("buttonSizer");
114
115 // Specify constraints for the button sizer
116 wxLayoutConstraints *c = new wxLayoutConstraints;
117 c->width.AsIs ();
118 c->height.AsIs ();
119 c->top.Below (spacingSizer);
120 c->centreX.SameAs (spacingSizer, wxCentreX);
121 buttonSizer->SetConstraints(c);
122
123 wxButton *ok = (wxButton *) NULL;
124 wxButton *cancel = (wxButton *) NULL;
125 wxButton *yes = (wxButton *) NULL;
126 wxButton *no = (wxButton *) NULL;
127
128 if (style & wxYES_NO) {
129 yes = new wxButton(this, wxID_YES, _("Yes"));
130 no = new wxButton(this, wxID_NO, _("No"));
131
132 buttonSizer->AddSizerChild(yes);
133 buttonSizer->AddSizerChild(no);
134 }
135
136 if (style & wxOK) {
137 ok = new wxButton(this, wxID_OK, _("OK"));
138 buttonSizer->AddSizerChild(ok);
139 }
140
141 if (style & wxCANCEL) {
142 cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
143 buttonSizer->AddSizerChild(cancel);
144 }
145
146 if (ok)
147 {
148 ok->SetDefault();
149 ok->SetFocus();
150 }
151 else if (yes)
152 {
153 yes->SetDefault();
154 yes->SetFocus();
155 }
156
157 Layout();
158 Centre(wxBOTH);
159
160 wxEndBusyCursor();
161 }
162
163 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
164 {
165 EndModal(wxID_YES);
166 }
167
168 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
169 {
170 EndModal(wxID_NO);
171 }
172
173 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
174 {
175 // Allow cancellation via ESC/Close button except if
176 // only YES and NO are specified.
177 if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) )
178 EndModal(wxID_CANCEL);
179 }
180
181