]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/palmos/msgdlg.cpp
Reverted changes that set m_widget to NULL in native
[wxWidgets.git] / src / palmos / msgdlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: msgdlg.cpp
3// Purpose: wxMessageDialog
4// Author: William Osborne
5// Modified by:
6// Created: 10/13/04
7// RCS-ID: $Id:
8// Copyright: (c) William Osborne
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "msgdlg.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/app.h"
25 #include "wx/defs.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
29#endif
30
31IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
32
33wxMessageDialog::wxMessageDialog(wxWindow *parent,
34 const wxString& message,
35 const wxString& caption,
36 long style,
37 const wxPoint& WXUNUSED(pos))
38{
39#ifdef __WXDEBUG__
40 // check for common programming errors
41 if ( (style & wxID_OK) == wxID_OK )
42 {
43 // programmer probably confused wxID_OK with wxOK. Correct one is wxOK.
44 wxFAIL_MSG( _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") );
45 }
46#endif // __WXDEBUG__
47
48 m_caption = caption;
49 m_message = message;
50 m_dialogStyle = style;
51 m_parent = parent;
52}
53
54int wxMessageDialog::ShowModal()
55{
56 int AlertID=1000;
57 int Result=0;
58 int wxResult=wxID_OK;
59
60 // Handle to the currently running application database
61 DmOpenRef AppDB;
62 SysGetModuleDatabase(SysGetRefNum(), NULL, &AppDB);
63
64 // Translate wx styles into Palm OS styles
65 if (m_dialogStyle & wxYES_NO)
66 {
67 if (m_dialogStyle & wxCANCEL)
68 AlertID=1300; // Yes No Cancel
69 else
70 AlertID=1200; // Yes No
71 }
72 if (m_dialogStyle & wxOK)
73 {
74 if (m_dialogStyle & wxCANCEL)
75 AlertID=1100; // Ok Cancel
76 else
77 AlertID=1000; // Ok
78 }
79
80 // Add the icon styles
81 if (m_dialogStyle & wxICON_EXCLAMATION)
82 AlertID=AlertID+0; // Warning
83 else if (m_dialogStyle & wxICON_HAND)
84 AlertID=AlertID+1; // Error
85 else if (m_dialogStyle & wxICON_INFORMATION)
86 AlertID=AlertID+2; // Information
87 else if (m_dialogStyle & wxICON_QUESTION)
88 AlertID=AlertID+3; // Confirmation
89
90 // The Palm OS Dialog API does not support custom titles in a dialog box.
91 // So we have to set the title by manipulating the resource.
92
93 // Get the alert resource
94 char *AlertPtr;
95 MemHandle AlertHandle;
96 AlertHandle=DmGetResource(AppDB,'Talt',AlertID);
97
98 AlertPtr=(char *)MemHandleLock(AlertHandle);
99 AlertPtr+=8;
100
101 // Clear out any old title. This must be done with a static array of chars
102 // because using MemSet is not supported on resources and could result in
103 // crashes or unpredictable behaviour.
104 char ClearTitle[25]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
105 MemMove(AlertPtr,&ClearTitle,25);
106
107 // Get the title length and make sure it is not too long
108 int TitleLength=m_caption.length();
109 if(TitleLength>25)
110 TitleLength=25;
111
112 // Center the title in the window
113 int BufferLength=(25-TitleLength)/2;
114 AlertPtr+=BufferLength;
115
116 // Copy the title
117 MemMove(AlertPtr,m_caption.c_str(),TitleLength);
118
119 // Release the resource
120 MemHandleUnlock(AlertHandle);
121 DmReleaseResource(AlertHandle);
122
123 // Display the dialog
124 Result=FrmCustomAlert(AppDB,AlertID,m_message.c_str(),"","");
125
126 // Convert the Palm OS result to wxResult
127 if(AlertID<1100)
128 {
129 // Ok
130 wxResult=wxID_OK;
131 }
132 else if(AlertID<1200)
133 {
134 // Ok Cancel
135 if(Result==0)
136 wxResult=wxID_OK;
137 else
138 wxResult=wxID_CANCEL;
139 }
140 else if(AlertID<1300)
141 {
142 // Yes No
143 if(Result==0)
144 wxResult=wxID_YES;
145 else
146 wxResult=wxID_NO;
147 }
148 else
149 {
150 // Yes No Cancel
151 if(Result==0)
152 wxResult=wxID_YES;
153 else if(Result==1)
154 wxResult=wxID_NO;
155 else
156 wxResult=wxID_CANCEL;
157 }
158
159 return wxResult;
160}
161