]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/msgdlg.cpp
use popen() instead of wxExecute(), it works inside wxYield() unlike the latter
[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
31IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
32
33wxMessageDialog::wxMessageDialog(wxWindow *parent,
34 const wxString& message,
35 const wxString& caption,
36 long style,
37 const wxPoint& WXUNUSED(pos))
38{
ffecfa5a
JS
39 m_caption = caption;
40 m_message = message;
e2731512 41 m_parent = parent;
e5b50758 42 SetMessageDialogStyle(style);
ffecfa5a
JS
43}
44
45int wxMessageDialog::ShowModal()
46{
47 int AlertID=1000;
48 int Result=0;
49 int wxResult=wxID_OK;
e5b50758 50 const long style = GetMessageDialogStyle();
e2731512 51
ffecfa5a
JS
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
e5b50758 57 if (style & wxYES_NO)
ffecfa5a 58 {
e5b50758 59 if (style & wxCANCEL)
ffecfa5a
JS
60 AlertID=1300; // Yes No Cancel
61 else
62 AlertID=1200; // Yes No
63 }
e5b50758 64 if (style & wxOK)
ffecfa5a 65 {
e5b50758 66 if (style & wxCANCEL)
ffecfa5a
JS
67 AlertID=1100; // Ok Cancel
68 else
69 AlertID=1000; // Ok
70 }
71
72 // Add the icon styles
e5b50758 73 if (style & wxICON_EXCLAMATION)
ffecfa5a 74 AlertID=AlertID+0; // Warning
e5b50758 75 else if (style & wxICON_HAND)
ffecfa5a 76 AlertID=AlertID+1; // Error
e5b50758 77 else if (style & wxICON_INFORMATION)
ffecfa5a 78 AlertID=AlertID+2; // Information
e5b50758 79 else if (style & wxICON_QUESTION)
ffecfa5a
JS
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
e2731512 94 // because using MemSet is not supported on resources and could result in
ffecfa5a
JS
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;
e2731512 103
ffecfa5a
JS
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);
e2731512 110
ffecfa5a
JS
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
e2731512 151 return wxResult;
ffecfa5a
JS
152}
153