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