]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/msgdlg.cpp
Cygwin compile fix
[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 #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
31 #include <Loader.h>
32 #include <Form.h>
33
34 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
35
36 wxMessageDialog::wxMessageDialog(wxWindow *parent,
37 const wxString& message,
38 const wxString& caption,
39 long style,
40 const wxPoint& WXUNUSED(pos))
41 {
42 m_caption = caption;
43 m_message = message;
44 m_parent = parent;
45 SetMessageDialogStyle(style);
46 }
47
48 int wxMessageDialog::ShowModal()
49 {
50 int AlertID=1000;
51 int Result=0;
52 int wxResult=wxID_OK;
53 const long style = GetMessageDialogStyle();
54
55 // Handle to the currently running application database
56 DmOpenRef AppDB;
57 SysGetModuleDatabase(SysGetRefNum(), NULL, &AppDB);
58
59 // Translate wx styles into Palm OS styles
60 if (style & wxYES_NO)
61 {
62 if (style & wxCANCEL)
63 AlertID=1300; // Yes No Cancel
64 else
65 AlertID=1200; // Yes No
66 }
67 if (style & wxOK)
68 {
69 if (style & wxCANCEL)
70 AlertID=1100; // Ok Cancel
71 else
72 AlertID=1000; // Ok
73 }
74
75 // Add the icon styles
76 if (style & wxICON_EXCLAMATION)
77 AlertID=AlertID+0; // Warning
78 else if (style & wxICON_HAND)
79 AlertID=AlertID+1; // Error
80 else if (style & wxICON_INFORMATION)
81 AlertID=AlertID+2; // Information
82 else if (style & wxICON_QUESTION)
83 AlertID=AlertID+3; // Confirmation
84
85 // The Palm OS Dialog API does not support custom titles in a dialog box.
86 // So we have to set the title by manipulating the resource.
87
88 // Get the alert resource
89 char *AlertPtr;
90 MemHandle AlertHandle;
91 AlertHandle=DmGetResource(AppDB,'Talt',AlertID);
92
93 AlertPtr=(char *)MemHandleLock(AlertHandle);
94 AlertPtr+=8;
95
96 // Clear out any old title. This must be done with a static array of chars
97 // because using MemSet is not supported on resources and could result in
98 // crashes or unpredictable behaviour.
99 char ClearTitle[25]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
100 MemMove(AlertPtr,&ClearTitle,25);
101
102 // Get the title length and make sure it is not too long
103 int TitleLength=m_caption.length();
104 if(TitleLength>25)
105 TitleLength=25;
106
107 // Center the title in the window
108 int BufferLength=(25-TitleLength)/2;
109 AlertPtr+=BufferLength;
110
111 // Copy the title
112 MemMove(AlertPtr,m_caption.c_str(),TitleLength);
113
114 // Release the resource
115 MemHandleUnlock(AlertHandle);
116 DmReleaseResource(AlertHandle);
117
118 // Display the dialog
119 Result=FrmCustomAlert(AppDB,AlertID,m_message.c_str(),"","");
120
121 // Convert the Palm OS result to wxResult
122 if(AlertID<1100)
123 {
124 // Ok
125 wxResult=wxID_OK;
126 }
127 else if(AlertID<1200)
128 {
129 // Ok Cancel
130 if(Result==0)
131 wxResult=wxID_OK;
132 else
133 wxResult=wxID_CANCEL;
134 }
135 else if(AlertID<1300)
136 {
137 // Yes No
138 if(Result==0)
139 wxResult=wxID_YES;
140 else
141 wxResult=wxID_NO;
142 }
143 else
144 {
145 // Yes No Cancel
146 if(Result==0)
147 wxResult=wxID_YES;
148 else if(Result==1)
149 wxResult=wxID_NO;
150 else
151 wxResult=wxID_CANCEL;
152 }
153
154 return wxResult;
155 }
156