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