1 /* AbiWord
2 * Copyright (C) 2004-2005 Jordi Mas i Hern�ndez <jmas@softcatala.org>
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 <stdlib.h>
21 #include <time.h>
22 #include <windows.h>
23
24 #include "ut_string.h"
25 #include "ut_string_class.h"
26 #include "ut_assert.h"
27 #include "ut_debugmsg.h"
28
29 #include "xap_App.h"
30 #include "xap_Frame.h"
31 #include "xap_Win32App.h"
32
33 #include "ap_Strings.h"
34 #include "ap_Dialog_Id.h"
35 #include "ap_Dialog_FormatTOC.h"
36 #include "ap_Win32Dialog_FormatTOC.h"
37 #include "xap_Win32PropertySheet.h"
38 #include "ap_Win32Resources.rc2"
39 #include "xap_Win32DialogHelper.h"
40 #include "ap_Dialog_FormatFootnotes.h"
41 #include "ap_Win32App.h"
42 #include "pt_PieceTable.h"
43
44 /*****************************************************************/
45
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id id)46 XAP_Dialog * AP_Win32Dialog_FormatTOC::static_constructor(XAP_DialogFactory * pFactory,
47 XAP_Dialog_Id id)
48 {
49 AP_Win32Dialog_FormatTOC * p = new AP_Win32Dialog_FormatTOC(pFactory,id);
50 return p;
51 }
52
AP_Win32Dialog_FormatTOC(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)53 AP_Win32Dialog_FormatTOC::AP_Win32Dialog_FormatTOC(XAP_DialogFactory * pDlgFactory,
54 XAP_Dialog_Id id)
55 : AP_Dialog_FormatTOC(pDlgFactory,id)
56 {
57 m_iStartValue = 1;
58 }
59
~AP_Win32Dialog_FormatTOC(void)60 AP_Win32Dialog_FormatTOC::~AP_Win32Dialog_FormatTOC(void)
61 {
62
63 }
64
notifyActiveFrame(XAP_Frame *)65 void AP_Win32Dialog_FormatTOC::notifyActiveFrame(XAP_Frame * /*pFrame*/)
66 {
67
68 }
69
setTOCPropsInGUI(void)70 void AP_Win32Dialog_FormatTOC::setTOCPropsInGUI(void)
71 {
72 if (m_pGeneral)
73 m_pGeneral->_fillGUI();
74
75 if (m_pLayout)
76 m_pLayout->_fillGUI();
77
78 }
79
80
setSensitivity(bool bSensitive)81 void AP_Win32Dialog_FormatTOC::setSensitivity(bool bSensitive)
82 {
83 if (m_pGeneral)
84 m_pGeneral->setChanged (bSensitive);
85
86 if (m_pLayout)
87 m_pLayout->setChanged (bSensitive);
88
89 }
90
destroy(void)91 void AP_Win32Dialog_FormatTOC::destroy(void)
92 {
93
94 finalize();
95
96 //Property sheet will be autodestroyed by the cancel action
97 if (m_pGeneral) {
98 delete m_pGeneral;
99 m_pGeneral = NULL;
100 }
101
102 if (m_pLayout) {
103 delete m_pLayout;
104 m_pLayout = NULL;
105 }
106
107 //delete m_pSheet;
108
109 }
110
activate(void)111 void AP_Win32Dialog_FormatTOC::activate(void)
112 {
113
114
115 }
116
117
118
runModeless(XAP_Frame * pFrame)119 void AP_Win32Dialog_FormatTOC::runModeless(XAP_Frame * pFrame)
120 {
121
122 UT_return_if_fail (pFrame);
123 RECT rect;
124 POINT pnt;
125 XAP_Win32App * pWin32App = static_cast<XAP_Win32App *>(XAP_App::getApp());
126
127 m_pSheet = new AP_Win32Dialog_FormatTOC_Sheet();
128 m_pSheet->setContainer (this);
129 m_pSheet->setApplyButton (true);
130 m_pSheet->setOkButton (true);
131 m_pSheet->setCancelButton(false);
132
133 m_pGeneral = new AP_Win32Dialog_FormatTOC_General();
134 m_pGeneral->setContainer (this);
135 m_pGeneral->createPage(pWin32App, AP_RID_DIALOG_FORMATTOC_GENERAL, AP_STRING_ID_DLG_FormatTOC_General);
136
137 m_pLayout = new AP_Win32Dialog_FormatTOC_Layout();
138 m_pLayout->setContainer (this);
139 m_pLayout->createPage(pWin32App, AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS, AP_STRING_ID_DLG_FormatTOC_LayoutDetails);
140
141 m_pSheet->addPage(m_pGeneral);
142 m_pSheet->addPage(m_pLayout);
143 m_pSheet->runModeless(pWin32App, pFrame, AP_STRING_ID_DLG_FormatTOC_Title);
144
145 GetWindowRect(GetDlgItem(m_pSheet->getHandle() ,IDCANCEL), &rect);
146 pnt.x = rect.left;
147 pnt.y = rect.top;
148 ScreenToClient (m_pSheet->getHandle(), &pnt);
149
150 HWND hwndOK = GetDlgItem(m_pSheet->getHandle(),IDOK);
151 MoveWindow (hwndOK,
152 pnt.x, pnt.y, rect.right - rect.left, rect.bottom - rect.top, true);
153
154 UT_sint32 sid =(UT_sint32) getDialogId();
155 m_pApp->rememberModelessId( sid, (XAP_Dialog_Modeless *) m_pDialog);
156
157 startUpdater();
158 }
159
setStyle(HWND hWnd,int nCtrlID)160 void AP_Win32Dialog_FormatTOC::setStyle(HWND hWnd, int nCtrlID)
161 {
162 UT_UTF8String sVal;
163 std::string str_loc;
164 UT_UTF8String sProp;
165 UT_String str;
166 HWND hwndCtrl = GetDlgItem (hWnd, nCtrlID);
167
168 switch (nCtrlID)
169 {
170 case AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE:
171 sProp = "toc-heading-style";
172 break;
173
174 case AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_FILLSTYLEVALUE:
175 sProp = "toc-source-style";
176 break;
177
178 case AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_DISPLAYSTYLEVALUE:
179 sProp = "toc-dest-style";
180 break;
181
182 default:
183 break;
184 }
185
186 if(g_ascii_strcasecmp("toc-heading-style",sProp.utf8_str()) != 0)
187 {
188 UT_String sNum = UT_String_sprintf("%d",getMainLevel());
189 sProp += sNum.c_str();
190 }
191
192 sVal = getNewStyle(sProp);
193 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
194
195 SendMessageW (hwndCtrl, WM_SETTEXT, 0, (LPARAM)
196 (AP_Win32App::s_fromUTF8ToWinLocale (str_loc.c_str())).c_str() );
197
198 setTOCProperty(sProp,sVal);
199 applyTOCPropsToDoc ();
200
201 }
202
203
setMainLevel(UT_sint32 iLevel)204 void AP_Win32Dialog_FormatTOC::setMainLevel(UT_sint32 iLevel)
205 {
206 AP_Dialog_FormatTOC::setMainLevel(iLevel);
207 UT_UTF8String sVal;
208 std::string str_loc;
209 UT_Win32LocaleString str;
210
211 sVal = getTOCPropVal("toc-dest-style",getMainLevel());
212
213 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
214 str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.c_str());
215
216 SendMessageW (GetDlgItem (m_pGeneral->getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_DISPLAYSTYLEVALUE),
217 WM_SETTEXT, 0, (LPARAM)str.c_str());
218
219 sVal = getTOCPropVal("toc-source-style",getMainLevel());
220
221 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
222 str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.c_str());
223
224 SendMessageW (GetDlgItem (m_pGeneral->getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_FILLSTYLEVALUE),
225 WM_SETTEXT, 0, (LPARAM)str.c_str());
226
227 sVal = getTOCPropVal("toc-has-label",getMainLevel());
228
229 CheckDlgButton(m_pGeneral->getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASLEVEL,
230 (g_ascii_strcasecmp(sVal.utf8_str(),"1") == 0) ? BST_CHECKED :BST_UNCHECKED);
231 }
232
233
setDetailsLevel(UT_sint32 iLevel)234 void AP_Win32Dialog_FormatTOC::setDetailsLevel(UT_sint32 iLevel)
235 {
236
237 UT_UTF8String sVal, str_loc;
238 UT_String str;
239
240 AP_Dialog_FormatTOC::setDetailsLevel(iLevel);
241
242
243 /* Start at */
244 sVal = getTOCPropVal("toc-label-start", getDetailsLevel());
245
246 setWindowText (GetDlgItem (m_pLayout->getHandle(),
247 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_STARTAT), sVal.utf8_str());
248
249 m_pLayout->loadCtrlsValuesForDetailsLevel ();
250
251 }
252
253 /*
254
255 Sheet
256
257 */
AP_Win32Dialog_FormatTOC_Sheet()258 AP_Win32Dialog_FormatTOC_Sheet::AP_Win32Dialog_FormatTOC_Sheet() :
259 XAP_Win32PropertySheet()
260 {
261 setCallBack(s_sheetInit);
262 }
263
s_sheetInit(HWND hwnd,UINT uMsg,LPARAM)264 int CALLBACK AP_Win32Dialog_FormatTOC_Sheet::s_sheetInit(HWND hwnd, UINT uMsg, LPARAM /*lParam*/)
265 {
266 if (uMsg==PSCB_INITIALIZED)
267 {
268 /* Force the creation of all pages*/
269 PropSheet_SetCurSel(hwnd, 0,1);
270 PropSheet_SetCurSel(hwnd, 0,0);
271 }
272 return 0;
273 }
274
275
_onOK()276 void AP_Win32Dialog_FormatTOC_Sheet::_onOK()
277 {
278 getContainer()->destroy();
279 destroy();
280 }
281
_onInitDialog(HWND)282 void AP_Win32Dialog_FormatTOC_Sheet::_onInitDialog(HWND /*hwnd*/)
283 {
284 const XAP_StringSet * pSS = getContainer()->getApp()->getStringSet();
285
286 UT_Win32LocaleString str;
287 str.fromUTF8(pSS->getValue(XAP_STRING_ID_DLG_OK));
288
289 SendMessageW(GetDlgItem(getHandle(),IDOK), WM_SETTEXT, 0,
290 (LPARAM) str.c_str());
291 }
292
293
cleanup(void)294 void AP_Win32Dialog_FormatTOC_Sheet::cleanup(void)
295 {
296 getContainer()->modeless_cleanup ();
297 }
298
299
300 /*
301
302 General
303
304 */
AP_Win32Dialog_FormatTOC_General()305 AP_Win32Dialog_FormatTOC_General::AP_Win32Dialog_FormatTOC_General()
306 {
307
308 }
309
~AP_Win32Dialog_FormatTOC_General()310 AP_Win32Dialog_FormatTOC_General::~AP_Win32Dialog_FormatTOC_General()
311 {
312
313 }
314
_fillGUI()315 void AP_Win32Dialog_FormatTOC_General::_fillGUI()
316 {
317
318 UT_UTF8String sVal;
319 std::string str_loc;
320 UT_Win32LocaleString str;
321
322 sVal = getContainer()->getTOCPropVal("toc-has-heading");
323 if(g_ascii_strcasecmp(sVal.utf8_str(),"1") == 0)
324 {
325 CheckDlgButton(getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASHEADING, BST_CHECKED);
326 EnableWindow(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_HEADINGSTYLE), true);
327 EnableWindow(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE), true);
328 }
329 else
330 {
331 CheckDlgButton(getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASHEADING, BST_UNCHECKED);
332 EnableWindow(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_HEADINGSTYLE), false);
333 EnableWindow(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE), false);
334 }
335
336 sVal = getContainer()->getTOCPropVal("toc-has-label", getContainer()->getMainLevel());
337 CheckDlgButton(getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASLEVEL,
338 (g_ascii_strcasecmp(sVal.utf8_str(),"1") == 0) ? BST_CHECKED :BST_UNCHECKED);
339
340 sVal = getContainer()->getTOCPropVal("toc-heading-style");
341 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
342 str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.c_str());
343
344 SendMessageW (GetDlgItem (getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE),
345 WM_SETTEXT, 0, (LPARAM)str.c_str());
346
347 // Set MainLevel for the Combobox
348 selectComboItem ( AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL, getContainer()->getMainLevel() - 1);
349 getContainer()->setMainLevel(getContainer()->getMainLevel());
350
351 sVal = getContainer()->getTOCPropVal("toc-heading");
352 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
353
354 setWindowText (GetDlgItem (getHandle(),
355 AP_RID_DIALOG_FORMATTOC_GENERAL_EDIT_HEADINGTEXT), str_loc.c_str());
356 }
357
_onInitDialog()358 void AP_Win32Dialog_FormatTOC_General::_onInitDialog()
359 {
360
361 const XAP_StringSet * pSS = getApp()->getStringSet();
362 int i;
363
364 struct control_id_string_id {
365 UT_sint32 controlId;
366 XAP_String_Id stringId;
367 } static const rgMapping[] =
368 {
369 {AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASHEADING, AP_STRING_ID_DLG_FormatTOC_HasHeading},
370 {AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGTEXT, AP_STRING_ID_DLG_FormatTOC_HeadingText},
371 {AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLE, AP_STRING_ID_DLG_FormatTOC_HeadingStyle},
372 {AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_HEADINGSTYLE, AP_STRING_ID_DLG_FormatTOC_ChangeStyle},
373 {AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_MAINPROPERTIES, AP_STRING_ID_DLG_FormatTOC_LevelDefs},
374 {AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASLEVEL, AP_STRING_ID_DLG_FormatTOC_HasLabel},
375 {AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_FILLSTYLE, AP_STRING_ID_DLG_FormatTOC_FillStyle},
376 {AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_FILLSTYLE, AP_STRING_ID_DLG_FormatTOC_ChangeStyle},
377 {AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_DISPLAYSTYLE, AP_STRING_ID_DLG_FormatTOC_DispStyle},
378 {AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_DISPLAYSTYLE, AP_STRING_ID_DLG_FormatTOC_ChangeStyle},
379 {0,0}
380 };
381
382 // Localise the controls
383 for (i = 0; i < rgMapping[i].controlId; i++)
384 setDlgItemText(getHandle(), rgMapping[i].controlId, pSS->getValue(rgMapping[i].stringId));
385
386 /* Levels */
387 int item;
388 int nID [4] = {AP_STRING_ID_DLG_FormatTOC_Level1, AP_STRING_ID_DLG_FormatTOC_Level2,
389 AP_STRING_ID_DLG_FormatTOC_Level3, AP_STRING_ID_DLG_FormatTOC_Level4};
390 for (i = 0; i < 4; i++)
391 {
392 item = addItemToCombo ( AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL, pSS->getValue(nID[i]));
393 setComboDataItem(AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL, item, i+1);
394 }
395
396 selectComboItem (AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL, 0);
397
398 getContainer()->setTOCPropsInGUI();
399 }
400
401
_onCommand(HWND hWnd,WPARAM wParam,LPARAM)402 BOOL AP_Win32Dialog_FormatTOC_General::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
403 {
404 WORD wNotifyCode = HIWORD(wParam);
405 WORD wId = LOWORD(wParam);
406 // HWND hWndCtrl = (HWND)lParam;
407
408 switch (wId)
409 {
410 case AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASHEADING:
411 {
412 UT_UTF8String sProp = "toc-has-heading";
413 UT_UTF8String sVal = "1";
414
415 if (IsDlgButtonChecked(hWnd, AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASHEADING) != BST_CHECKED)
416 {
417 EnableWindow(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_HEADINGSTYLE), false);
418 EnableWindow(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE), false);
419 sVal = "0";
420 }
421 else
422 {
423 EnableWindow(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_HEADINGSTYLE), true);
424 EnableWindow(GetDlgItem(hWnd,AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE), true);
425 }
426 getContainer()->setTOCProperty(sProp,sVal);
427 return TRUE;
428 }
429
430 case AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_HEADINGSTYLE:
431 getContainer()->setStyle(hWnd, AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_HEADINGSTYLEVALUE);
432 return TRUE;
433
434 case AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_FILLSTYLE:
435 getContainer()->setStyle(hWnd, AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_FILLSTYLEVALUE);
436 return TRUE;
437
438 case AP_RID_DIALOG_FORMATTOC_GENERAL_BUTTON_DISPLAYSTYLE:
439 getContainer()->setStyle(hWnd, AP_RID_DIALOG_FORMATTOC_GENERAL_TEXT_DISPLAYSTYLEVALUE);
440 return TRUE;
441
442 case AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL:
443 {
444 if (wNotifyCode == CBN_SELCHANGE)
445 {
446 int nSelected, nLevel;
447 HWND hCombo = GetDlgItem(hWnd, AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL);
448 nSelected = getComboSelectedIndex(AP_RID_DIALOG_FORMATTOC_GENERAL_COMBO_LEVEL);
449
450 if (nSelected!=CB_ERR)
451 {
452 nLevel = SendMessageW(hCombo, CB_GETITEMDATA, nSelected, 0);
453 getContainer()->setMainLevel (nLevel);
454 }
455 }
456 return TRUE;
457
458 }
459
460 case AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASLEVEL:
461 {
462
463 UT_UTF8String sProp = "toc-has-label";
464 UT_UTF8String sVal = "1";
465 UT_String sNum = UT_String_sprintf("%d",getContainer()->getMainLevel());
466
467 /* Has label */
468 sVal = getContainer()->getTOCPropVal(sProp.utf8_str(), getContainer()->getMainLevel());
469 sVal = "1";
470
471 if (IsDlgButtonChecked(getHandle(), AP_RID_DIALOG_FORMATTOC_GENERAL_CHECK_HASLEVEL) != BST_CHECKED)
472 sVal = "0";
473
474 sProp += sNum.c_str();
475 getContainer()->setTOCProperty(sProp,sVal);
476 return TRUE;
477 }
478
479 default:
480 break;
481 }
482 return FALSE;
483 }
484
_onApply()485 void AP_Win32Dialog_FormatTOC_General::_onApply()
486 {
487 UT_UTF8String sUTF8;
488 wchar_t szText[1024];
489 UT_Win32LocaleString str;
490
491 GetWindowTextW(GetDlgItem (getHandle(),
492 AP_RID_DIALOG_FORMATTOC_GENERAL_EDIT_HEADINGTEXT), szText, 1024);
493 str.fromLocale (szText);
494 sUTF8 = str.utf8_str ();
495
496 getContainer()->setTOCProperty("toc-heading", sUTF8.utf8_str());
497 getContainer()->Apply();
498 }
499
_onOK()500 void AP_Win32Dialog_FormatTOC_General::_onOK()
501 {
502 _onApply();
503 }
504
505
506 /*
507
508 Layout Details
509
510 */
AP_Win32Dialog_FormatTOC_Layout()511 AP_Win32Dialog_FormatTOC_Layout::AP_Win32Dialog_FormatTOC_Layout()
512 {
513
514 }
515
~AP_Win32Dialog_FormatTOC_Layout()516 AP_Win32Dialog_FormatTOC_Layout::~AP_Win32Dialog_FormatTOC_Layout()
517 {
518
519 }
520
_fillGUI()521 void AP_Win32Dialog_FormatTOC_Layout::_fillGUI()
522 {
523 UT_UTF8String sVal;
524 std::string str_loc;
525
526 UT_Win32LocaleString str;
527 /* Text Before */
528 sVal = getContainer()->getTOCPropVal("toc-label-before", getContainer()->getDetailsLevel());
529 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
530 setWindowText (GetDlgItem (getHandle(),
531 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_TEXTBEFORE), str_loc.c_str());
532
533 /* Text After */
534 sVal = getContainer()->getTOCPropVal("toc-label-after", getContainer()->getDetailsLevel());
535 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
536
537 setWindowText (GetDlgItem (getHandle(),
538 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_TEXTAFTER), str_loc.c_str());
539
540 /* Start at */
541 sVal = getContainer()->getTOCPropVal("toc-label-start", getContainer()->getDetailsLevel());
542
543 setWindowText (GetDlgItem (getHandle(),
544 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_STARTAT), sVal.utf8_str());
545
546 }
547
_onInitDialog()548 void AP_Win32Dialog_FormatTOC_Layout::_onInitDialog()
549 {
550 UT_UTF8String sVal, str_loc;
551 UT_String str;
552 const XAP_StringSet * pSS = getApp()->getStringSet();
553 int i;
554
555 struct control_id_string_id {
556 UT_sint32 controlId;
557 XAP_String_Id stringId;
558 } static const rgMapping[] =
559 {
560 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_STARTAT, AP_STRING_ID_DLG_FormatTOC_StartAt},
561 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_TEXTBEFORE, AP_STRING_ID_DLG_FormatTOC_TextBefore},
562 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_TABSPAGENUM, AP_STRING_ID_DLG_FormatTOC_DetailsTabPage},
563 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_LABELDEF, AP_STRING_ID_DLG_FormatTOC_DetailsTop},
564 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_NUMTYPE, AP_STRING_ID_DLG_FormatTOC_NumberingType},
565 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_TEXTAFTER, AP_STRING_ID_DLG_FormatTOC_TextAfter},
566 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_CHECK_INHERITLABEL, AP_STRING_ID_DLG_FormatTOC_InheritLabel},
567 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_TABLEADER, AP_STRING_ID_DLG_FormatTOC_TabLeader},
568 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_PAGENUMERING, AP_STRING_ID_DLG_FormatTOC_PageNumbering},
569 {AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_TEXT_IDENT, AP_STRING_ID_DLG_FormatTOC_Indent},
570 {0, 0}
571 };
572
573 // Localise the controls
574 for (i = 0; i < rgMapping[i].controlId; i++)
575 setDlgItemText(getHandle(), rgMapping[i].controlId, pSS->getValue(rgMapping[i].stringId));
576
577 /* Spin controls */
578 SendMessage(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_SPIN_STARTAT),
579 UDM_SETBUDDY, (WPARAM) GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_STARTAT),0);
580
581 SendMessage(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_SPIN_STARTAT),UDM_SETRANGE,
582 0,(WPARAM)9999);
583
584 SendMessage(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_SPIN_IDENT),
585 UDM_SETBUDDY, (WPARAM) GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_IDENT),0);
586
587 SendMessage(GetDlgItem(getHandle(),AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_SPIN_IDENT),UDM_SETRANGE,
588 0,(WPARAM)9999);
589
590 /* Levels */
591 int item;
592 int nID [4] = {AP_STRING_ID_DLG_FormatTOC_Level1, AP_STRING_ID_DLG_FormatTOC_Level2,
593 AP_STRING_ID_DLG_FormatTOC_Level3, AP_STRING_ID_DLG_FormatTOC_Level4};
594 for (i = 0; i < 4; i++)
595 {
596 item = addItemToCombo(AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_LEVEL, pSS->getValue(nID[i]));
597 setComboDataItem(AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_LEVEL, item, i+1);
598 }
599
600 selectComboItem (AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_LEVEL, 0);
601
602 /* Now the Page Numbering style */
603 const FootnoteTypeDesc * vecTypeList = AP_Dialog_FormatFootnotes::getFootnoteTypeLabelList();
604 UT_UTF8String val;
605
606 for (; vecTypeList->n != _FOOTNOTE_TYPE_INVALID; vecTypeList++)
607 {
608 const char * szVal = vecTypeList->label;
609 addItemToCombo ( AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_NUMTYPE, szVal);
610 addItemToCombo ( AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_PAGENUMERING, szVal);
611 }
612
613 /*FV_View * pView = static_cast<FV_View *>(getContainer()->getActiveFrame()->getCurrentView());
614 val = getContainer()->getTOCPropVal("toc-page-type", getContainer()->getDetailsLevel());
615 UT_sint32 iHist = static_cast<UT_sint32>(pView->getLayout()->FootnoteTypeFromString(val.utf8_str()));
616
617 SendDlgItemMessage(getHandle(), AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_NUMTYPE, CB_SETCURSEL, iHist, 0); */
618
619 /* Tab Type styles */
620 const UT_GenericVector<const gchar*> * vecLabels = getContainer()->getVecTABLeadersLabel();
621 UT_sint32 nTypes = vecLabels->getItemCount();
622
623 for(UT_sint32 j=0; j< nTypes; j++)
624 {
625 const char * szLab = static_cast<const char *>(vecLabels->getNthItem(j));
626 UT_DEBUGMSG(("Got label %s for item %d \n",szLab,j));
627
628 addItemToCombo ( AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_TABLEADER, szLab);
629 }
630
631 selectComboItem ( AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_TABLEADER, 0);
632
633 loadCtrlsValuesForDetailsLevel ();
634
635 }
636
637
_onCommand(HWND hWnd,WPARAM wParam,LPARAM)638 BOOL AP_Win32Dialog_FormatTOC_Layout::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
639 {
640 WORD wNotifyCode = HIWORD(wParam);
641 WORD wId = LOWORD(wParam);
642 // HWND hWndCtrl = (HWND)lParam;
643
644 switch (wId)
645 {
646 case AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_LEVEL:
647 {
648 if (wNotifyCode == CBN_SELCHANGE)
649 {
650 int nSelected, nLevel;
651 HWND hCombo = GetDlgItem(hWnd, AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_LEVEL);
652 nSelected = getComboSelectedIndex(AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_LEVEL);
653
654 if (nSelected!=CB_ERR)
655 {
656 saveCtrlsValuesForDetailsLevel (); // Save current level settings
657
658 nLevel = SendMessageW(hCombo, CB_GETITEMDATA, nSelected, 0);
659 getContainer()->setDetailsLevel (nLevel);
660 }
661 }
662
663 return TRUE;
664 }
665 default:
666 break;
667 }
668 return FALSE;
669 }
670
671 // Spin control notification
_onNotify(LPNMHDR pNMHDR,int)672 void AP_Win32Dialog_FormatTOC_Layout::_onNotify(LPNMHDR pNMHDR, int /*iCtrlID*/)
673 {
674
675 if (pNMHDR->code != UDN_DELTAPOS)
676 return;
677
678 NMUPDOWN* up = (NMUPDOWN* ) pNMHDR;
679
680 /* Start at*/
681 UT_sint32 iNew = up->iPos + up->iDelta;
682 bool bInc = true;
683 if(iNew != getContainer()->m_iStartValue)
684 {
685 UT_UTF8String sVal;
686
687 if(iNew < getContainer()->m_iStartValue)
688 bInc = false;
689
690 getContainer()->m_iStartValue = iNew;
691 getContainer()->incrementStartAt(getContainer()->getDetailsLevel(),bInc);
692 sVal = getContainer()->getTOCPropVal("toc-label-start",getContainer()->getDetailsLevel());
693 SetWindowText (GetDlgItem (getHandle(),
694 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_STARTAT), sVal.utf8_str());
695 }
696
697 }
698
loadCtrlsValuesForDetailsLevel()699 void AP_Win32Dialog_FormatTOC_Layout::loadCtrlsValuesForDetailsLevel ()
700 {
701 UT_UTF8String sVal;
702 std::string str_loc;
703 UT_Win32LocaleString str;
704 UT_sint32 iHist;
705
706 FV_View * pView = static_cast<FV_View *>(getContainer()->getActiveFrame()->getCurrentView());
707 sVal = getContainer()->getTOCPropVal("toc-page-type", getContainer()->getDetailsLevel());
708 iHist = static_cast<UT_sint32>(pView->getLayout()->FootnoteTypeFromString(sVal.utf8_str()));
709 SendDlgItemMessage(getHandle(), AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_NUMTYPE,
710 CB_SETCURSEL, iHist, 0); //TODO
711
712 /* Text Before */
713 sVal = getContainer()->getTOCPropVal("toc-label-before", getContainer()->getDetailsLevel());
714 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
715 str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.c_str());
716
717 SetWindowTextW (GetDlgItem (getHandle(),
718 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_TEXTBEFORE), str.c_str());
719
720 /* Text After */
721 sVal = getContainer()->getTOCPropVal("toc-label-after", getContainer()->getDetailsLevel());
722 pt_PieceTable::s_getLocalisedStyleName (sVal.utf8_str(), str_loc);
723 str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.c_str());
724
725 SetWindowTextW (GetDlgItem (getHandle(),
726 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_TEXTAFTER), str.c_str());
727
728 }
729
saveCtrlsValuesForDetailsLevel()730 void AP_Win32Dialog_FormatTOC_Layout::saveCtrlsValuesForDetailsLevel ()
731 {
732
733 UT_UTF8String sProp, sVal;
734 UT_String sNum;
735 char szText[1024];
736 int nSelected;
737
738
739 /* Text Before */
740 GetWindowText(GetDlgItem (getHandle(),
741 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_TEXTBEFORE), szText, 1024);
742
743 sVal = AP_Win32App::s_fromWinLocaleToUTF8 (szText);
744
745 sNum = UT_String_sprintf("%d",getContainer()->getDetailsLevel());
746 sProp = "toc-label-before";
747 sProp += sNum.c_str();
748 getContainer()->setTOCProperty(sProp, sVal);
749
750 /* Text After */
751 GetWindowText(GetDlgItem (getHandle(),
752 AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_EDIT_TEXTAFTER), szText, 1024);
753
754 sVal = AP_Win32App::s_fromWinLocaleToUTF8 (szText);
755 sProp = "toc-label-after";
756 sProp += sNum.c_str();
757 getContainer()->setTOCProperty(sProp, sVal);
758
759 /* Numering type */
760 nSelected = getComboSelectedIndex(AP_RID_DIALOG_FORMATTOC_LAYOUTDETAILS_COMBO_NUMTYPE);
761
762 if (nSelected!=CB_ERR)
763 {
764 const FootnoteTypeDesc * footnoteTypeList = AP_Dialog_FormatFootnotes::getFootnoteTypeLabelList();
765 const char * szVal = footnoteTypeList[nSelected].prop;
766 sProp = "toc-page-type";
767 sVal = szVal;
768
769 sNum = UT_String_sprintf("%d",getContainer()->getDetailsLevel());
770 sProp += sNum.c_str();
771 getContainer()->setTOCProperty(sProp,sVal);
772
773 }
774
775
776 }
777
_onApply()778 void AP_Win32Dialog_FormatTOC_Layout::_onApply()
779 {
780
781 saveCtrlsValuesForDetailsLevel ();
782 getContainer()->Apply(); /* Apply */
783
784 }
785
786
_onOK()787 void AP_Win32Dialog_FormatTOC_Layout::_onOK()
788 {
789 _onApply();
790 }
791