| 1 |
/* AbiWord |
| 2 |
* Copyright (C) 2000 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 |
|
| 22 |
#include "ut_string.h" |
| 23 |
#include "ut_assert.h" |
| 24 |
#include "ut_debugmsg.h" |
| 25 |
|
| 26 |
#include "xap_App.h" |
| 27 |
#include "xap_Win32App.h" |
| 28 |
#include "xap_Win32FrameImpl.h" |
| 29 |
|
| 30 |
#include "xap_Strings.h" |
| 31 |
#include "xap_Dialog_Id.h" |
| 32 |
#include "xap_Win32Dlg_Encoding.h" |
| 33 |
|
| 34 |
#include "xap_Win32Resources.rc2" |
| 35 |
|
| 36 |
/*****************************************************************/ |
| 37 |
|
| 38 |
XAP_Dialog * XAP_Win32Dialog_Encoding::static_constructor(XAP_DialogFactory * pFactory, |
| 39 |
XAP_Dialog_Id id) |
| 40 |
{ |
| 41 |
XAP_Win32Dialog_Encoding * p = new XAP_Win32Dialog_Encoding(pFactory,id); |
| 42 |
return p; |
| 43 |
} |
| 44 |
|
| 45 |
XAP_Win32Dialog_Encoding::XAP_Win32Dialog_Encoding(XAP_DialogFactory * pDlgFactory, |
| 46 |
XAP_Dialog_Id id) |
| 47 |
: XAP_Dialog_Encoding(pDlgFactory,id) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
XAP_Win32Dialog_Encoding::~XAP_Win32Dialog_Encoding(void) |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
void XAP_Win32Dialog_Encoding::runModal(XAP_Frame * pFrame) |
| 56 |
{ |
| 57 |
UT_ASSERT(pFrame); |
| 58 |
UT_ASSERT(m_id == XAP_DIALOG_ID_ENCODING); |
| 59 |
|
| 60 |
setDialog(this); |
| 61 |
createModal(pFrame, MAKEINTRESOURCEW(XAP_RID_DIALOG_ENCODING)); |
| 62 |
} |
| 63 |
|
| 64 |
BOOL XAP_Win32Dialog_Encoding::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/) |
| 65 |
{ |
| 66 |
localizeDialogTitle(XAP_STRING_ID_DLG_UENC_EncTitle); |
| 67 |
|
| 68 |
// localize controls |
| 69 |
localizeControlText(XAP_RID_DIALOG_ENCODING_BTN_OK, XAP_STRING_ID_DLG_OK); |
| 70 |
localizeControlText(XAP_RID_DIALOG_ENCODING_BTN_CANCEL, XAP_STRING_ID_DLG_Cancel); |
| 71 |
localizeControlText(XAP_RID_DIALOG_ENCODING_FRM_ENCODING, XAP_STRING_ID_DLG_UENC_EncLabel); |
| 72 |
|
| 73 |
// Load Initial Data into Listbox |
| 74 |
{ |
| 75 |
resetContent(XAP_RID_DIALOG_ENCODING_LBX_ENCODING); |
| 76 |
|
| 77 |
// load each string name into the list |
| 78 |
for ( UT_uint32 i=0; i < _getEncodingsCount(); i++ ) |
| 79 |
{ |
| 80 |
const gchar* s = _getAllEncodings()[i]; |
| 81 |
addItemToList(XAP_RID_DIALOG_ENCODING_LBX_ENCODING, (LPCSTR) s); |
| 82 |
setListDataItem(XAP_RID_DIALOG_ENCODING_LBX_ENCODING, i, (DWORD) i); |
| 83 |
} |
| 84 |
|
| 85 |
// Set to default or guessed encoding |
| 86 |
selectListItem(XAP_RID_DIALOG_ENCODING_LBX_ENCODING, _getSelectionIndex()); |
| 87 |
|
| 88 |
SetFocus(GetDlgItem(hWnd, XAP_RID_DIALOG_ENCODING_LBX_ENCODING)); |
| 89 |
} |
| 90 |
|
| 91 |
return 0; // 1 == we did not call SetFocus() |
| 92 |
} |
| 93 |
|
| 94 |
BOOL XAP_Win32Dialog_Encoding::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/) |
| 95 |
{ |
| 96 |
WORD wId = LOWORD(wParam); |
| 97 |
int nItem; |
| 98 |
|
| 99 |
switch (wId) |
| 100 |
{ |
| 101 |
case XAP_RID_DIALOG_ENCODING_LBX_ENCODING: |
| 102 |
switch (HIWORD(wParam)) |
| 103 |
{ |
| 104 |
case LBN_SELCHANGE: |
| 105 |
// NOTE: we get away with only grabbing this in IDOK case |
| 106 |
return 0; |
| 107 |
|
| 108 |
case LBN_DBLCLK: |
| 109 |
nItem = getListSelectedIndex(wId); |
| 110 |
_setEncoding( _getAllEncodings()[nItem] ); |
| 111 |
_setAnswer(a_OK); |
| 112 |
EndDialog(hWnd,0); |
| 113 |
return 1; |
| 114 |
|
| 115 |
default: |
| 116 |
return 0; |
| 117 |
} |
| 118 |
break; |
| 119 |
|
| 120 |
case IDCANCEL: // also XAP_RID_DIALOG_ENCODING_BTN_CANCEL |
| 121 |
_setAnswer(a_CANCEL); |
| 122 |
EndDialog(hWnd,0); |
| 123 |
return 1; |
| 124 |
|
| 125 |
case IDOK: // also XAP_RID_DIALOG_ENCODING_BTN_OK |
| 126 |
nItem = getListSelectedIndex(XAP_RID_DIALOG_ENCODING_LBX_ENCODING); |
| 127 |
if( nItem != LB_ERR) |
| 128 |
{ |
| 129 |
_setEncoding( _getAllEncodings()[nItem] ); |
| 130 |
_setAnswer(a_OK); |
| 131 |
} |
| 132 |
else |
| 133 |
{ |
| 134 |
_setAnswer(a_CANCEL); |
| 135 |
} |
| 136 |
EndDialog(hWnd,0); |
| 137 |
return 1; |
| 138 |
|
| 139 |
default: // we did not handle this notification |
| 140 |
UT_DEBUGMSG(("WM_Command for id %ld\n",wId)); |
| 141 |
return 0; // return zero to let windows take care of it. |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
BOOL XAP_Win32Dialog_Encoding::_onDeltaPos(NM_UPDOWN * /*pnmud*/) |
| 146 |
{ |
| 147 |
// respond to WM_NOTIFY/UDN_DELTAPOS message |
| 148 |
// return TRUE to prevent the change from happening |
| 149 |
// return FALSE to allow it to occur |
| 150 |
return FALSE; |
| 151 |
} |