| 1 |
/* AbiSource Application Framework |
| 2 |
* Copyright (C) 1998 AbiSource, Inc. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 |
| 7 |
* of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 |
* 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <windows.h> |
| 21 |
#include "ut_assert.h" |
| 22 |
#include "xap_Win32Dlg_MessageBox.h" |
| 23 |
#include "xap_Win32App.h" |
| 24 |
#include "xap_Win32FrameImpl.h" |
| 25 |
#include "xap_EncodingManager.h" |
| 26 |
#include "ut_Win32LocaleString.h" |
| 27 |
|
| 28 |
/*****************************************************************/ |
| 29 |
XAP_Dialog * XAP_Win32Dialog_MessageBox::static_constructor(XAP_DialogFactory * pFactory, |
| 30 |
XAP_Dialog_Id id) |
| 31 |
{ |
| 32 |
XAP_Win32Dialog_MessageBox * p = new XAP_Win32Dialog_MessageBox(pFactory,id); |
| 33 |
return p; |
| 34 |
} |
| 35 |
|
| 36 |
XAP_Win32Dialog_MessageBox::XAP_Win32Dialog_MessageBox(XAP_DialogFactory * pDlgFactory, |
| 37 |
XAP_Dialog_Id id) |
| 38 |
: XAP_Dialog_MessageBox(pDlgFactory,id) |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
XAP_Win32Dialog_MessageBox::~XAP_Win32Dialog_MessageBox(void) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
/*****************************************************************/ |
| 47 |
|
| 48 |
void XAP_Win32Dialog_MessageBox::runModal(XAP_Frame * pFrame) |
| 49 |
{ |
| 50 |
UT_return_if_fail(pFrame); |
| 51 |
XAP_Win32App * pApp = static_cast<XAP_Win32App *>(XAP_App::getApp()); |
| 52 |
UT_return_if_fail(pApp); |
| 53 |
|
| 54 |
UT_Win32LocaleString caption, message; |
| 55 |
caption.fromASCII (pApp->getApplicationTitleForTitleBar()); |
| 56 |
|
| 57 |
HWND hwnd = static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow(); |
| 58 |
UINT flags; |
| 59 |
|
| 60 |
switch (m_buttons) |
| 61 |
{ |
| 62 |
case b_O: |
| 63 |
flags = MB_ICONASTERISK | MB_OK; |
| 64 |
flags |= ((m_defaultAnswer == a_OK) ? MB_DEFBUTTON1 : 0); |
| 65 |
break; |
| 66 |
|
| 67 |
case b_OC: |
| 68 |
flags = MB_ICONQUESTION | MB_OKCANCEL; |
| 69 |
flags |= ((m_defaultAnswer == a_OK) ? MB_DEFBUTTON1 : 0); |
| 70 |
flags |= ((m_defaultAnswer == a_CANCEL) ? MB_DEFBUTTON2 : 0); |
| 71 |
break; |
| 72 |
|
| 73 |
case b_YN: |
| 74 |
flags = MB_ICONQUESTION | MB_YESNO; |
| 75 |
flags |= ((m_defaultAnswer == a_YES) ? MB_DEFBUTTON1 : 0); |
| 76 |
flags |= ((m_defaultAnswer == a_NO) ? MB_DEFBUTTON2 : 0); |
| 77 |
break; |
| 78 |
|
| 79 |
case b_YNC: |
| 80 |
flags = MB_ICONQUESTION | MB_YESNOCANCEL; |
| 81 |
flags |= ((m_defaultAnswer == a_YES) ? MB_DEFBUTTON1 : 0); |
| 82 |
flags |= ((m_defaultAnswer == a_NO) ? MB_DEFBUTTON2 : 0); |
| 83 |
flags |= ((m_defaultAnswer == a_CANCEL) ? MB_DEFBUTTON3 : 0); |
| 84 |
break; |
| 85 |
|
| 86 |
default: |
| 87 |
flags = 0; |
| 88 |
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); |
| 89 |
} |
| 90 |
|
| 91 |
message.fromUTF8(m_szMessage); |
| 92 |
int res = MessageBoxW(hwnd, message.c_str(), caption.c_str(), flags); |
| 93 |
|
| 94 |
switch (res) |
| 95 |
{ |
| 96 |
case IDCANCEL: |
| 97 |
m_answer = a_CANCEL; |
| 98 |
break; |
| 99 |
|
| 100 |
case IDNO: |
| 101 |
m_answer = a_NO; |
| 102 |
break; |
| 103 |
|
| 104 |
case IDOK: |
| 105 |
m_answer = a_OK; |
| 106 |
break; |
| 107 |
|
| 108 |
case IDYES: |
| 109 |
m_answer = a_YES; |
| 110 |
break; |
| 111 |
|
| 112 |
case IDABORT: |
| 113 |
case IDIGNORE: |
| 114 |
case IDRETRY: |
| 115 |
default: |
| 116 |
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); |
| 117 |
} |
| 118 |
|
| 119 |
// the caller can get the answer from getAnswer(). |
| 120 |
} |
| 121 |
|