Debian Codegraph @

src/af/xap/win/xap_Win32Dlg_History.cpp

raw
1 /* AbiWord
2 * Copyright (C) 1998-2000 AbiSource, Inc.
3 * Copyright (C) 2002 Tomas Frydrych <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301 USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <windows.h>
26 #include <commctrl.h>
27
28 #include "ut_string.h"
29 #include "ut_assert.h"
30 #include "ut_debugmsg.h"
31
32 #include "xap_App.h"
33 #include "xap_Win32App.h"
34 #include "xap_Win32FrameImpl.h"
35
36 #include "xap_Dialog_Id.h"
37 #include "xap_Dlg_History.h"
38 #include "xap_Win32Dlg_History.h"
39 #include "xap_Win32LabelledSeparator.h"
40
41 #include "xap_Win32Resources.rc2"
42 #include "xap_Win32DialogHelper.h"
43
44 /*****************************************************************/
45
46 XAP_Dialog * XAP_Win32Dialog_History::static_constructor(XAP_DialogFactory * pFactory,
47 XAP_Dialog_Id id)
48 {
49 XAP_Win32Dialog_History * p = new XAP_Win32Dialog_History(pFactory,id);
50 return p;
51 }
52
53 XAP_Win32Dialog_History::XAP_Win32Dialog_History(XAP_DialogFactory * pDlgFactory,
54 XAP_Dialog_Id id)
55 : XAP_Dialog_History(pDlgFactory,id)
56 {
57 }
58
59 XAP_Win32Dialog_History::~XAP_Win32Dialog_History(void)
60 {
61 }
62
63 void XAP_Win32Dialog_History::runModal(XAP_Frame * pFrame)
64 {
65 XAP_Win32App * pWin32App = static_cast<XAP_Win32App *>(m_pApp);
66
67 XAP_Win32LabelledSeparator_RegisterClass(pWin32App);
68 UT_ASSERT(m_id == XAP_DIALOG_ID_HISTORY);
69 createModal(pFrame, MAKEINTRESOURCEW(XAP_RID_DIALOG_HISTORY));
70 }
71
72 BOOL XAP_Win32Dialog_History::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
73 {
74 UT_Win32LocaleString str;
75 // set the window title
76 setDialogTitle(getWindowLabel());
77
78 // localize buttons
79 setDlgItemText(XAP_RID_DIALOG_HISTORY_BTN_OK,getButtonLabel(0));
80 //setDlgItemText(XAP_RID_DIALOG_HISTORY_BTN_SHOW,getButtonLabel(1));
81 setDlgItemText(XAP_RID_DIALOG_HISTORY_BTN_CANCEL,getButtonLabel(getButtonCount()-1));
82
83 // set the list title
84 setDlgItemText(XAP_RID_DIALOG_HISTORY_FRAME,getListTitle());
85
86 // fill in the section above the list
87 UT_uint32 i;
88 UT_uint32 k1 = XAP_RID_DIALOG_HISTORY_LABEL_PATH;
89 UT_uint32 k2 = XAP_RID_DIALOG_HISTORY_PATH;
90
91 for(i = 0; i < getHeaderItemCount(); i++)
92 {
93 setDlgItemText(k1 + i,getHeaderLabel(i));
94
95 char * t = getHeaderValue(i);
96 setDlgItemText(hWnd,k2 + i, t); // !
97 FREEP(t);
98 }
99
100 // set the column headings
101 HWND h = GetDlgItem(hWnd, XAP_RID_DIALOG_HISTORY_LIST_VERSIONS);
102
103 LVCOLUMNW col;
104
105
106 for(i = 0; i < getListColumnCount(); i++)
107 {
108 str.fromUTF8(getListHeader(i));
109 col.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
110 col.iSubItem = i;
111 col.cx = 120;
112 col.pszText = (wchar_t *)str.c_str();
113 SendMessageW(h, LVM_INSERTCOLUMNW, i, (LPARAM)&col);
114 }
115
116 // fill the list
117 ListView_SetItemCount(h, getListItemCount());
118
119 LVITEMW item;
120 item.state = 0;
121 item.stateMask = 0;
122 item.iImage = 0;
123
124 //wchar_t buf[80];
125 //item.pszText = buf;
126 char * t;
127
128 for(i = 0; i < getListItemCount(); i++)
129 {
130 item.iItem = i;
131
132 for(UT_uint32 j = 0; j < getListColumnCount(); j++)
133 {
134 item.iSubItem = j;
135 t = getListValue(i,j);
136 str.fromUTF8(t);
137 item.pszText = (wchar_t *) str.c_str();
138 item.mask = LVIF_TEXT;
139
140 if(j==0)
141 {
142 item.lParam = getListItemId(i);
143 item.mask |= LVIF_PARAM;
144 SendMessageW(h, LVM_INSERTITEMW, 0, (LPARAM)&item);
145 }
146 else
147 {
148 SendMessageW(h, LVM_SETITEMW, 0, (LPARAM)&item);
149 }
150
151 FREEP(t);
152 }
153 }
154
155 SendMessageW(h, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
156 centerDialog();
157
158 return 1; // 1 == we did not call SetFocus()
159 }
160
161 BOOL XAP_Win32Dialog_History::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
162 {
163 WORD wId = LOWORD(wParam);
164
165 switch (wId)
166 {
167 case IDCANCEL:
168 m_answer = a_CANCEL;
169 EndDialog(hWnd,0);
170 return 1;
171
172 case XAP_RID_DIALOG_HISTORY_BTN_SHOW:
173 case IDOK:
174 {
175 HWND h = GetDlgItem(hWnd, XAP_RID_DIALOG_HISTORY_LIST_VERSIONS);
176 int iSelCount = ListView_GetSelectedCount(h);
177 if(iSelCount)
178 {
179 LVITEMW item;
180
181 item.iSubItem = 0;
182 item.iItem = ListView_GetSelectionMark(h);
183 item.mask = LVIF_PARAM;
184 item.pszText = 0;
185 item.cchTextMax = 0;
186
187 SendMessageW(h, LVM_GETITEMW, 0, (LPARAM)&item);
188
189 setSelectionId(item.lParam);
190 }
191 else
192 setSelectionId(0);
193
194 if(wId == IDOK)
195 m_answer = a_OK;
196 else
197 m_answer = a_SHOW;
198
199 EndDialog(hWnd,0);
200 return 1;
201 }
202
203 default: // we did not handle this notification
204 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
205 return 0; // return zero to let windows take care of it.
206 }
207 }
208
209