]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/msgdlg.cpp
Remove semicolon after if statmce that can potentially cause harm later. Patch #14438...
[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__
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
20bc5ad8
WS
27#include <Loader.h>
28#include <Form.h>
29
ffecfa5a
JS
30IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
31
32wxMessageDialog::wxMessageDialog(wxWindow *parent,
33 const wxString& message,
34 const wxString& caption,
35 long style,
36 const wxPoint& WXUNUSED(pos))
37{
ffecfa5a
JS
38 m_caption = caption;
39 m_message = message;
e2731512 40 m_parent = parent;
e5b50758 41 SetMessageDialogStyle(style);
ffecfa5a
JS
42}
43
44int wxMessageDialog::ShowModal()
45{
46 int AlertID=1000;
47 int Result=0;
48 int wxResult=wxID_OK;
e5b50758 49 const long style = GetMessageDialogStyle();
e2731512 50
ffecfa5a
JS
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
e5b50758 56 if (style & wxYES_NO)
ffecfa5a 57 {
e5b50758 58 if (style & wxCANCEL)
ffecfa5a
JS
59 AlertID=1300; // Yes No Cancel
60 else
61 AlertID=1200; // Yes No
62 }
e5b50758 63 if (style & wxOK)
ffecfa5a 64 {
e5b50758 65 if (style & wxCANCEL)
ffecfa5a
JS
66 AlertID=1100; // Ok Cancel
67 else
68 AlertID=1000; // Ok
69 }
70
71 // Add the icon styles
e5b50758 72 if (style & wxICON_EXCLAMATION)
ffecfa5a 73 AlertID=AlertID+0; // Warning
e5b50758 74 else if (style & wxICON_HAND)
ffecfa5a 75 AlertID=AlertID+1; // Error
e5b50758 76 else if (style & wxICON_INFORMATION)
ffecfa5a 77 AlertID=AlertID+2; // Information
e5b50758 78 else if (style & wxICON_QUESTION)
ffecfa5a
JS
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
e2731512 93 // because using MemSet is not supported on resources and could result in
ffecfa5a
JS
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;
e2731512 102
ffecfa5a
JS
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);
e2731512 109
ffecfa5a
JS
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
e2731512 150 return wxResult;
ffecfa5a
JS
151}
152