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