]> git.saurik.com Git - wxWidgets.git/blame - src/generic/msgdlgg.cpp
wxWindow::FindFocus() doesn't exist in wxGTK - #ifdef'd out
[wxWidgets.git] / src / generic / msgdlgg.cpp
CommitLineData
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
42void 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
75BEGIN_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)
79END_EVENT_TABLE()
80
81IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
82#endif
83
84wxGenericMessageDialog::wxGenericMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
85 long style, const wxPoint& pos):
86 wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
87{
88 m_dialogStyle = style;
89
90 wxBeginBusyCursor();
91
92 wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
93 topSizer->SetBorder(10, 10);
94
95 wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
96 messageSizer->SetName("messageSizer");
97
98// bool centre = ((style & wxCENTRE) == wxCENTRE);
99
100 wxList messageList;
101 wxSplitMessage2(message, &messageList, this, messageSizer);
102
103 // Insert a spacer
104 wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 20);
105
106 wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
107 buttonSizer->SetName("buttonSizer");
108
109 // Specify constraints for the button sizer
110 wxLayoutConstraints *c = new wxLayoutConstraints;
111 c->width.AsIs ();
112 c->height.AsIs ();
113 c->top.Below (spacingSizer);
114 c->centreX.SameAs (spacingSizer, wxCentreX);
115 buttonSizer->SetConstraints(c);
116
117 wxButton *ok = NULL;
118 wxButton *cancel = NULL;
119 wxButton *yes = NULL;
120 wxButton *no = NULL;
121
122 if (style & wxYES_NO) {
123 yes = new wxButton(this, wxID_YES, _("Yes"));
124 no = new wxButton(this, wxID_NO, _("No"));
125
126 buttonSizer->AddSizerChild(yes);
127 buttonSizer->AddSizerChild(no);
128 }
129
130 if (style & wxOK) {
131 ok = new wxButton(this, wxID_OK, _("OK"));
132 buttonSizer->AddSizerChild(ok);
133 }
134
135 if (style & wxCANCEL) {
136 cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
137 buttonSizer->AddSizerChild(cancel);
138 }
139
140 if (ok)
141 {
142 ok->SetDefault();
143 ok->SetFocus();
144 }
145 else if (yes)
146 {
147 yes->SetDefault();
148 yes->SetFocus();
149 }
150
151 Layout();
152 Centre(wxBOTH);
153
154 wxEndBusyCursor();
155}
156
157void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
158{
159 EndModal(wxID_YES);
160}
161
162void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
163{
164 EndModal(wxID_NO);
165}
166
167void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
168{
169 // Allow cancellation via ESC/Close button except if
170 // only YES and NO are specified.
171 if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) )
172 EndModal(wxID_CANCEL);
173}
174
175
debe6624
JS
176int wxMessageBox(const wxString& message, const wxString& caption, long style,
177 wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) )
c801d85f
KB
178{
179 wxMessageDialog dialog(parent, message, caption, style);
180
181 int ans = dialog.ShowModal();
182 switch ( ans )
183 {
184 case wxID_OK:
185 return wxOK;
186 break;
187 case wxID_YES:
188 return wxYES;
189 break;
190 case wxID_NO:
191 return wxNO;
192 break;
193 default:
194 case wxID_CANCEL:
195 return wxCANCEL;
196 break;
197 }
198
199 return ans;
200}
201