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