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