]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/msgdlg.cpp
Comment correction.
[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
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
20bc5ad8
WS
31#include <Loader.h>
32#include <Form.h>
33
ffecfa5a
JS
34IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
35
36wxMessageDialog::wxMessageDialog(wxWindow *parent,
37 const wxString& message,
38 const wxString& caption,
39 long style,
40 const wxPoint& WXUNUSED(pos))
41{
ffecfa5a
JS
42 m_caption = caption;
43 m_message = message;
e2731512 44 m_parent = parent;
e5b50758 45 SetMessageDialogStyle(style);
ffecfa5a
JS
46}
47
48int wxMessageDialog::ShowModal()
49{
50 int AlertID=1000;
51 int Result=0;
52 int wxResult=wxID_OK;
e5b50758 53 const long style = GetMessageDialogStyle();
e2731512 54
ffecfa5a
JS
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
e5b50758 60 if (style & wxYES_NO)
ffecfa5a 61 {
e5b50758 62 if (style & wxCANCEL)
ffecfa5a
JS
63 AlertID=1300; // Yes No Cancel
64 else
65 AlertID=1200; // Yes No
66 }
e5b50758 67 if (style & wxOK)
ffecfa5a 68 {
e5b50758 69 if (style & wxCANCEL)
ffecfa5a
JS
70 AlertID=1100; // Ok Cancel
71 else
72 AlertID=1000; // Ok
73 }
74
75 // Add the icon styles
e5b50758 76 if (style & wxICON_EXCLAMATION)
ffecfa5a 77 AlertID=AlertID+0; // Warning
e5b50758 78 else if (style & wxICON_HAND)
ffecfa5a 79 AlertID=AlertID+1; // Error
e5b50758 80 else if (style & wxICON_INFORMATION)
ffecfa5a 81 AlertID=AlertID+2; // Information
e5b50758 82 else if (style & wxICON_QUESTION)
ffecfa5a
JS
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
e2731512 97 // because using MemSet is not supported on resources and could result in
ffecfa5a
JS
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;
e2731512 106
ffecfa5a
JS
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);
e2731512 113
ffecfa5a
JS
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
e2731512 154 return wxResult;
ffecfa5a
JS
155}
156