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 <stdio.h>
21 #include <windows.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 "ap_Strings.h"
31 #include "ap_Dialog_Id.h"
32 #include "ap_Dialog_FormatFootnotes.h"
33 #include "ap_Win32Dialog_FormatFootnotes.h"
34 #include "ap_Win32Resources.rc2"
35 #include "xap_Win32DialogHelper.h"
36 #include "xap_Win32LabelledSeparator.h"
37
38 #define _DS(c,s) setDlgItemText(AP_RID_DIALOG_FORMATFOOTNOTES_##c,pSS->getValue(AP_STRING_ID_##s))
39 #define _DSX(c,s) setDlgItemText(AP_RID_DIALOG_FORMATFOOTNOTES_##c,pSS->getValue(XAP_STRING_ID_##s))
40
41 /*****************************************************************/
42
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id id)43 XAP_Dialog * AP_Win32Dialog_FormatFootnotes::static_constructor(XAP_DialogFactory * pFactory,
44 XAP_Dialog_Id id)
45 {
46 AP_Win32Dialog_FormatFootnotes * p = new AP_Win32Dialog_FormatFootnotes(pFactory,id);
47 return p;
48 }
49
AP_Win32Dialog_FormatFootnotes(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)50 AP_Win32Dialog_FormatFootnotes::AP_Win32Dialog_FormatFootnotes(XAP_DialogFactory * pDlgFactory,
51 XAP_Dialog_Id id)
52 : AP_Dialog_FormatFootnotes(pDlgFactory,id)
53 {
54 }
55
~AP_Win32Dialog_FormatFootnotes(void)56 AP_Win32Dialog_FormatFootnotes::~AP_Win32Dialog_FormatFootnotes(void)
57 {
58 }
59
runModal(XAP_Frame * pFrame)60 void AP_Win32Dialog_FormatFootnotes::runModal(XAP_Frame * pFrame)
61 {
62 UT_return_if_fail (pFrame);
63 setFrame(pFrame);
64
65 // raise the dialog
66 XAP_Win32App * pWin32App = static_cast<XAP_Win32App *>(m_pApp);
67 XAP_Win32LabelledSeparator_RegisterClass(pWin32App);
68 UT_return_if_fail (m_id == AP_DIALOG_ID_FORMAT_FOOTNOTES);
69
70 createModal(pFrame, MAKEINTRESOURCEW(AP_RID_DIALOG_FORMATFOOTNOTES));
71 }
72
73
74 // This handles the WM_INITDIALOG message for the top-level dialog.
_onInitDialog(HWND hWnd,WPARAM,LPARAM)75 BOOL AP_Win32Dialog_FormatFootnotes::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
76 {
77 const XAP_StringSet * pSS = m_pApp->getStringSet();
78 wchar_t szText[16];
79
80 /* localize controls */
81 _DSX(BTN_OK, DLG_OK);
82 _DSX(BTN_CANCEL, DLG_Cancel);
83 _DS(RADIO_RSEL, DLG_FormatFootnotes_FootRestartSec);
84 _DS(RADIO_PAGE, DLG_FormatFootnotes_FootRestartPage);
85 _DS(RADIO_DONOT, DLG_FormatFootnotes_FootRestartNone);
86 _DS(STATIC_INITFOOTVAL, DLG_FormatFootnotes_FootInitialVal);
87 _DS(STATIC_FSTYLES1, DLG_FormatFootnotes_FootStyle);
88 _DS(STATIC_FSTYLES2, DLG_FormatFootnotes_FootStyle);
89 _DS(RADIO_ENDDOC, DLG_FormatFootnotes_EndPlaceEndDoc);
90 _DS(RADIO_ENDSEC, DLG_FormatFootnotes_EndPlaceEndSec);
91 _DS(STATIC_INITENDVAL, DLG_FormatFootnotes_EndInitialVal);
92 _DS(STATIC_ESTYLES1, DLG_FormatFootnotes_EndStyle);
93 _DS(STATIC_ESTYLES2, DLG_FormatFootnotes_EndStyle);
94 _DS(RADIO_ERSTSEC, DLG_FormatFootnotes_EndRestartSec);
95 _DS(STATIC_PLACEMENT, DLG_FormatFootnotes_EndPlacement);
96 _DS(STATIC_NUMBERING, DLG_FormatFootnotes_FootnoteRestart);
97
98
99 /*Caption*/
100 setDialogTitle (pSS->getValue(AP_STRING_ID_DLG_FormatFootnotes_Title));
101
102 setInitialValues(); /* Parent class loads data*/
103
104 /* Footnote style combobox*/
105 int nItem;
106 int nDefF = 0;
107 int nDefE = 0;
108 const FootnoteTypeDesc * footnoteTypeList = getFootnoteTypeLabelList();
109
110 for(UT_uint32 i = 0; footnoteTypeList->n != _FOOTNOTE_TYPE_INVALID; footnoteTypeList++, i++)
111 {
112 nItem = addItemToCombo (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_FSTYLE, footnoteTypeList->label);
113 setComboDataItem (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_FSTYLE, nItem, (LPARAM)i);
114
115 if (i==(UT_uint32)getFootnoteType())
116 nDefF = i;
117
118 nItem = addItemToCombo (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_ESTYLE, footnoteTypeList->label);
119 setComboDataItem (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_ESTYLE, nItem, (LPARAM)i);
120 if (i==(UT_uint32)getEndnoteType())
121 nDefE = i;
122 }
123
124 selectComboItem (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_FSTYLE, nDefF);
125 selectComboItem (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_ESTYLE, nDefE);
126
127 /*Set Default Radio buttons Footnotes */
128 if (getRestartFootnoteOnSection() || getRestartFootnoteOnPage())
129 CheckRadioButton(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_RSEL, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_DONOT,
130 getRestartFootnoteOnSection() ? AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_RSEL : AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_PAGE);
131 else
132 CheckRadioButton(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_RSEL, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_DONOT,
133 AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_DONOT);
134
135
136 /*Set Default Radio buttons Endnotes */
137 CheckRadioButton(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDDOC, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDSEC,
138 getPlaceAtDocEnd() ? AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDDOC: AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDSEC);
139
140 /* Set Footnotes Spin*/
141 SendMessageW(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATFOOTNOTES_SPIN_FSTYLE),UDM_SETRANGE,(WPARAM)1,(WPARAM)9999);
142 SendMessageW(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATFOOTNOTES_TEXT_FSTYLE),EM_LIMITTEXT,(WPARAM)4,(WPARAM)0);
143 swprintf (szText, L"%u", getFootnoteVal());
144 SetDlgItemTextW(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_TEXT_FSTYLE, szText);
145
146 /* Set Endnotes Spin*/
147 SendMessageW(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATFOOTNOTES_SPIN_ESTYLE),UDM_SETRANGE,(WPARAM)1,(WPARAM)9999);
148 SendMessageW(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATFOOTNOTES_TEXT_ESTYLE),EM_LIMITTEXT,(WPARAM)4,(WPARAM)0);
149 swprintf (szText, L"%u", getEndnoteVal());
150 SetDlgItemTextW(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_TEXT_ESTYLE, szText);
151
152
153 CheckDlgButton(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ERSTSEC, getRestartEndnoteOnSection());
154
155 centerDialog();
156
157 return 0; // 0 because we called SetFocus
158
159 }
160
_onCommand(HWND hWnd,WPARAM wParam,LPARAM)161 BOOL AP_Win32Dialog_FormatFootnotes::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
162 {
163 WORD wNotifyCode = HIWORD(wParam);
164 WORD wId = LOWORD(wParam);
165
166 switch (wId)
167 {
168 case AP_RID_DIALOG_FORMATFOOTNOTES_BTN_CANCEL:
169 setAnswer(AP_Dialog_FormatFootnotes::a_CANCEL);
170 EndDialog(hWnd,0);
171 return 1;
172
173 case AP_RID_DIALOG_FORMATFOOTNOTES_BTN_OK:
174 {
175 wchar_t szValue[16];
176
177 if (GetDlgItemTextW(m_hDlg, AP_RID_DIALOG_FORMATFOOTNOTES_TEXT_FSTYLE, szValue, 16))
178 setFootnoteVal(_wtoi(szValue));
179
180 if (GetDlgItemTextW(m_hDlg, AP_RID_DIALOG_FORMATFOOTNOTES_TEXT_ESTYLE, szValue, 16))
181 setEndnoteVal(_wtoi(szValue));
182
183 setAnswer(AP_Dialog_FormatFootnotes::a_OK);
184 EndDialog(hWnd,0);
185 return 1;
186 }
187
188 /*Footnote*/
189 case AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_RSEL:
190 {
191 if (IsDlgButtonChecked(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_RSEL))
192 {
193 setRestartFootnoteOnPage(false);
194 setRestartFootnoteOnSection(true);
195 }
196 break;
197 }
198
199 case AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_PAGE:
200 {
201 if (IsDlgButtonChecked(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_PAGE))
202 {
203 setRestartFootnoteOnPage(true);
204 setRestartFootnoteOnSection(false);
205 }
206 break;
207 }
208
209 case AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_DONOT:
210 {
211 if (IsDlgButtonChecked(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_DONOT))
212 {
213 setRestartFootnoteOnPage(false);
214 setRestartFootnoteOnSection(false);
215 }
216 break;
217 }
218
219 /*Endnote*/
220 case AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDDOC:
221 {
222 if (IsDlgButtonChecked(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDDOC))
223 {
224 setPlaceAtSecEnd(false);
225 setPlaceAtDocEnd(true);
226 }
227 break;
228 }
229
230 case AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDSEC:
231 {
232 if (IsDlgButtonChecked(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ENDSEC))
233 {
234 setPlaceAtSecEnd(true);
235 setPlaceAtDocEnd(false);
236 }
237 break;
238 }
239
240
241 /*Checkbox*/
242 case AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ERSTSEC:
243 {
244 bool bChecked;
245
246 bChecked = (IsDlgButtonChecked( hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_RADIO_ERSTSEC) == BST_CHECKED);
247 setRestartEndnoteOnSection(bChecked);
248 break;
249 }
250
251
252 case AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_FSTYLE:
253 {
254 if (wNotifyCode == CBN_SELCHANGE)
255 {
256 int nItem = getComboSelectedIndex (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_FSTYLE);
257
258 if (nItem!=CB_ERR)
259 {
260 UT_uint32 n = (UT_uint32)SendDlgItemMessageW(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_FSTYLE,
261 CB_GETITEMDATA, (WPARAM)nItem, 0);
262
263 setFootnoteType((FootnoteType)n);
264 }
265 }
266
267 break;
268 }
269
270 case AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_ESTYLE:
271 {
272 if (wNotifyCode == CBN_SELCHANGE)
273 {
274 int nItem = getComboSelectedIndex (AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_ESTYLE);
275
276 if (nItem!=CB_ERR)
277 {
278 UT_uint32 n = (UT_uint32)SendDlgItemMessageW(hWnd, AP_RID_DIALOG_FORMATFOOTNOTES_COMBO_ESTYLE,
279 CB_GETITEMDATA, (WPARAM)nItem, 0);
280
281 setEndnoteType((FootnoteType)n);
282 }
283 }
284
285 break;
286 }
287
288 default: // we did not handle this notification
289 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
290 return 0; // return zero to let windows take care of it.
291 }
292
293 return 0;
294 }
295
296