| 1 |
/* AbiWord |
| 2 |
* Copyright (C) 2003 Tomas Frydrych <[email protected]> |
| 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 <commctrl.h> |
| 22 |
|
| 23 |
#include "ut_string.h" |
| 24 |
#include "ut_assert.h" |
| 25 |
#include "ut_debugmsg.h" |
| 26 |
|
| 27 |
#include "xap_App.h" |
| 28 |
#include "xap_Win32App.h" |
| 29 |
#include "xap_Win32FrameImpl.h" |
| 30 |
#include "xap_Win32DialogHelper.h" |
| 31 |
|
| 32 |
#include "xap_Strings.h" |
| 33 |
#include "xap_Dialog_Id.h" |
| 34 |
#include "xap_Dlg_ListDocuments.h" |
| 35 |
#include "xap_Win32Dlg_ListDocuments.h" |
| 36 |
#include "xap_Win32LabelledSeparator.h" |
| 37 |
|
| 38 |
#include "xap_Win32Resources.rc2" |
| 39 |
|
| 40 |
/*****************************************************************/ |
| 41 |
|
| 42 |
XAP_Dialog * XAP_Win32Dialog_ListDocuments::static_constructor(XAP_DialogFactory * pFactory, |
| 43 |
XAP_Dialog_Id id) |
| 44 |
{ |
| 45 |
XAP_Win32Dialog_ListDocuments * p = new XAP_Win32Dialog_ListDocuments(pFactory,id); |
| 46 |
return p; |
| 47 |
} |
| 48 |
|
| 49 |
XAP_Win32Dialog_ListDocuments::XAP_Win32Dialog_ListDocuments(XAP_DialogFactory * pDlgFactory, |
| 50 |
XAP_Dialog_Id id) |
| 51 |
: XAP_Dialog_ListDocuments(pDlgFactory,id) |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
XAP_Win32Dialog_ListDocuments::~XAP_Win32Dialog_ListDocuments(void) |
| 56 |
{ |
| 57 |
} |
| 58 |
|
| 59 |
void XAP_Win32Dialog_ListDocuments::runModal(XAP_Frame * pFrame) |
| 60 |
{ |
| 61 |
XAP_Win32App * pWin32App = static_cast<XAP_Win32App *>(m_pApp); |
| 62 |
|
| 63 |
XAP_Win32LabelledSeparator_RegisterClass(pWin32App); |
| 64 |
createModal(pFrame, MAKEINTRESOURCEW(XAP_RID_DIALOG_LIST_DOCUMENTS)); |
| 65 |
} |
| 66 |
|
| 67 |
#define _DSX(c,s) setDlgItemText(XAP_RID_DIALOG_LIST_DOCUMENTS_##c,pSS->getValue(XAP_STRING_ID_##s)) |
| 68 |
#define _DSXS(c,s) setDlgItemText(XAP_RID_DIALOG_LIST_DOCUMENTS_##c,s) |
| 69 |
|
| 70 |
BOOL XAP_Win32Dialog_ListDocuments::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/) |
| 71 |
{ |
| 72 |
const XAP_StringSet * pSS = m_pApp->getStringSet(); |
| 73 |
|
| 74 |
setDialogTitle(_getTitle()); |
| 75 |
|
| 76 |
// localize controls |
| 77 |
_DSXS(BTN_OK, _getOKButtonText()); |
| 78 |
_DSX(BTN_CANCEL, DLG_Cancel); |
| 79 |
|
| 80 |
setDlgItemText(XAP_RID_DIALOG_LIST_DOCUMENTS_HEADING,_getHeading()); |
| 81 |
|
| 82 |
// set the column headings |
| 83 |
HWND h = GetDlgItem(hWnd, XAP_RID_DIALOG_LIST_DOCUMENTS_LIST); |
| 84 |
|
| 85 |
// DWORD dwStyle = GetWindowLongPtrW(h, GWL_STYLE); |
| 86 |
|
| 87 |
RECT r; |
| 88 |
GetWindowRect(h, &r); |
| 89 |
|
| 90 |
LVCOLUMN col; |
| 91 |
col.mask = LVCF_SUBITEM | LVCF_WIDTH; |
| 92 |
|
| 93 |
col.iSubItem = 0; |
| 94 |
col.cx = r.right - r.left - 5; |
| 95 |
|
| 96 |
//col.pszText = const_cast<char*>(getColumn1Label()); |
| 97 |
ListView_InsertColumn(h,0,&col); // TODO: to Unicode, names instead of URLs |
| 98 |
|
| 99 |
ListView_SetItemCount(h, _getDocumentCount()); |
| 100 |
LVITEM item; |
| 101 |
for(UT_sint32 i = 0; i < _getDocumentCount(); i++) |
| 102 |
{ |
| 103 |
item.pszText = (char *)_getNthDocumentName(i); |
| 104 |
item.iItem = i; |
| 105 |
item.iSubItem = 0; |
| 106 |
item.lParam = i; |
| 107 |
item.mask = LVIF_TEXT | LVIF_PARAM; |
| 108 |
ListView_InsertItem(h, &item); |
| 109 |
} |
| 110 |
|
| 111 |
centerDialog(); |
| 112 |
return 1; // 1 == we did not call SetFocus() |
| 113 |
} |
| 114 |
|
| 115 |
BOOL XAP_Win32Dialog_ListDocuments::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/) |
| 116 |
{ |
| 117 |
WORD wId = LOWORD(wParam); |
| 118 |
|
| 119 |
switch (wId) |
| 120 |
{ |
| 121 |
case IDCANCEL: |
| 122 |
_setAnswer(a_CANCEL); |
| 123 |
EndDialog(hWnd,0); |
| 124 |
return 1; |
| 125 |
|
| 126 |
case IDOK: |
| 127 |
{ |
| 128 |
HWND h = GetDlgItem(hWnd, XAP_RID_DIALOG_LIST_DOCUMENTS_LIST); |
| 129 |
int iSelCount = ListView_GetSelectedCount(h); |
| 130 |
_setAnswer(a_OK); |
| 131 |
if(iSelCount) |
| 132 |
{ |
| 133 |
LVITEM item; |
| 134 |
|
| 135 |
item.iSubItem = 0; |
| 136 |
item.iItem = ListView_GetSelectionMark(h); |
| 137 |
item.mask = LVIF_PARAM; |
| 138 |
item.pszText = 0; |
| 139 |
item.cchTextMax = 0; |
| 140 |
|
| 141 |
ListView_GetItem(h,&item); |
| 142 |
|
| 143 |
_setSelDocumentIndx(item.lParam); |
| 144 |
} |
| 145 |
else |
| 146 |
_setSelDocumentIndx(-1); |
| 147 |
|
| 148 |
EndDialog(hWnd,0); |
| 149 |
return 1; |
| 150 |
} |
| 151 |
|
| 152 |
default: // we did not handle this notification |
| 153 |
UT_DEBUGMSG(("WM_Command for id %ld\n",wId)); |
| 154 |
return 0; // return zero to let windows take care of it. |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|