]> git.saurik.com Git - wxWidgets.git/blob - src/motif/msgdlg.cpp
added a WXDLLEXPORT
[wxWidgets.git] / src / motif / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 #ifdef __GNUG__
17 #pragma implementation "msgdlg.h"
18 #endif
19
20 // ----------------------------------------------------------------------------
21 // headers
22 // ----------------------------------------------------------------------------
23
24 #include <X11/Xlib.h>
25
26 #include <Xm/Xm.h>
27 #include <Xm/MessageB.h>
28
29 #include "wx/app.h"
30 #include "wx/intl.h"
31 #include "wx/motif/msgdlg.h"
32 #include "wx/motif/private.h"
33
34 // ----------------------------------------------------------------------------
35 // macros
36 // ----------------------------------------------------------------------------
37
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
40 #endif
41
42 // ============================================================================
43 // implementation
44 // ============================================================================
45
46 // ----------------------------------------------------------------------------
47 // the callbacks for message box buttons
48 // ----------------------------------------------------------------------------
49
50 // the common part
51 static void msgboxCallBack(Widget w, int client_data, int id)
52 {
53 // close the dialog
54 XtUnmanageChild(w);
55
56 wxMessageDialog *dlg = (wxMessageDialog *)client_data;
57 dlg->SetResult(id);
58 }
59
60 static void msgboxCallBackOk(Widget w,
61 int client_data,
62 XmAnyCallbackStruct *WXUNUSED(call_data))
63 {
64 msgboxCallBack(w, client_data, wxID_OK);
65 }
66
67 static void msgboxCallBackCancel(Widget w,
68 int client_data,
69 XmAnyCallbackStruct *WXUNUSED(call_data))
70 {
71 msgboxCallBack(w, client_data, wxID_CANCEL);
72 }
73
74 static void msgboxCallBackHelp(Widget w,
75 int client_data,
76 XmAnyCallbackStruct *WXUNUSED(call_data))
77 {
78 msgboxCallBack(w, client_data, wxID_HELP);
79 }
80
81 static void msgboxCallBackClose(Widget w,
82 int client_data,
83 XmAnyCallbackStruct *WXUNUSED(call_data))
84 {
85 msgboxCallBack(w, client_data, wxID_CANCEL);
86 }
87
88 // ----------------------------------------------------------------------------
89 // wxMessageDialog
90 // ----------------------------------------------------------------------------
91
92 wxMessageDialog::wxMessageDialog(wxWindow *parent,
93 const wxString& message,
94 const wxString& caption,
95 long style,
96 const wxPoint& WXUNUSED(pos))
97 {
98 m_caption = caption;
99 m_message = message;
100 m_dialogStyle = style;
101 m_parent = parent;
102 }
103
104 int wxMessageDialog::ShowModal()
105 {
106 Widget (*dialogCreateFunction)(Widget, String, ArgList, Cardinal) = NULL;
107 if ( m_dialogStyle & wxYES_NO )
108 {
109 // if we have [Yes], it must be a question
110 dialogCreateFunction = XmCreateQuestionDialog;
111 }
112 else if ( m_dialogStyle & wxICON_STOP )
113 {
114 // error dialog is the one with error icon...
115 dialogCreateFunction = XmCreateErrorDialog;
116 }
117 else if ( m_dialogStyle & wxICON_EXCLAMATION )
118 {
119 // ...and the warning dialog too
120 dialogCreateFunction = XmCreateWarningDialog;
121 }
122 else
123 {
124 // finally, use the info dialog by default
125 dialogCreateFunction = XmCreateInformationDialog;
126 }
127
128 Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0;
129 if ( !wParent )
130 {
131 wxWindow *window = wxTheApp->GetTopWindow();
132 if ( !window )
133 {
134 wxFAIL_MSG("can't show message box without parent window");
135
136 return wxID_CANCEL;
137 }
138
139 wParent = GetWidget(window);
140 }
141
142 // prepare the arg list
143 Arg args[10];
144 int ac = 0;
145
146 wxXmString text(m_message);
147 wxXmString title(m_caption);
148 XtSetArg(args[ac], XmNmessageString, text()); ac++;
149 XtSetArg(args[ac], XmNdialogTitle, title()); ac++;
150
151 wxComputeColours (XtDisplay(wParent), & m_backgroundColour,
152 (wxColour*) NULL);
153
154 XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
155 XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
156 XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
157 XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
158
159 // do create message box
160
161 Widget wMsgBox = (*dialogCreateFunction)(wParent, "", args, ac);
162
163 wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" );
164
165 // get the buttons which we might either remove or rename
166 // depending on the requested style
167 //
168 Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON);
169 Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON);
170 Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON);
171
172 if ( m_dialogStyle & wxYES_NO )
173 {
174 wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel"));
175
176 if ( m_dialogStyle & wxCANCEL )
177 {
178 // use the cancel button for No and the help button for
179 // Cancel Yuk :-) MB
180 //
181 XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL);
182 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
183 XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL);
184 }
185 else
186 {
187 // no cancel button requested...
188 // remove the help button and use cancel for no
189 //
190 XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL);
191 XtUnmanageChild(wBtnHelp);
192 }
193 }
194 else
195 {
196 // remove the help button and the cancel button (unless it was
197 // requested)
198 //
199 XtUnmanageChild(wBtnHelp);
200 if ( !(m_dialogStyle & wxCANCEL ) ) XtUnmanageChild(wBtnCancel);
201 }
202
203 // set the callbacks for the message box buttons
204 XtAddCallback(wMsgBox, XmNokCallback,
205 (XtCallbackProc)msgboxCallBackOk, (XtPointer)this);
206 XtAddCallback(wMsgBox, XmNcancelCallback,
207 (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this);
208 XtAddCallback(wMsgBox, XmNhelpCallback,
209 (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this);
210 XtAddCallback(wMsgBox, XmNunmapCallback,
211 (XtCallbackProc)msgboxCallBackClose, (XtPointer)this);
212
213 // show it as a modal dialog
214 XtManageChild(wMsgBox);
215 XtAddGrab(wMsgBox, True, False);
216
217 // the m_result will be changed when message box goes away
218 m_result = -1;
219
220 // local message loop
221 XtAppContext context = XtWidgetToApplicationContext(wParent);
222 XEvent event;
223 while ( m_result == -1 )
224 {
225 XtAppNextEvent(context, &event);
226 XtDispatchEvent(&event);
227 }
228
229 // translate the result if necessary
230 if ( m_dialogStyle & wxYES_NO )
231 {
232 if ( m_result == wxID_OK )
233 m_result = wxID_YES;
234 else if ( m_result == wxID_CANCEL )
235 m_result = wxID_NO;
236 else if ( m_result == wxID_HELP )
237 m_result = wxID_CANCEL;
238 }
239
240 return m_result;
241 }
242