bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / index / cnttab.cxx
blob64e3661073dad70e660ea15f6e482129026c1a79
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/string.hxx>
21 #include <rsc/rscsfx.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <vcl/help.hxx>
24 #include <svl/stritem.hxx>
25 #include <svl/urihelper.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <sfx2/request.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <svx/dialogs.hrc>
32 #include <svx/svxdlg.hxx>
33 #include <svx/flagsdef.hxx>
34 #include <svx/simptabl.hxx>
35 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
36 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
37 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
38 #include <svtools/indexentryres.hxx>
39 #include "svtools/treelistentry.hxx"
40 #include <editeng/unolingu.hxx>
41 #include <column.hxx>
42 #include <fmtfsize.hxx>
43 #include <shellio.hxx>
44 #include <authfld.hxx>
45 #include <swtypes.hxx>
46 #include <wrtsh.hxx>
47 #include <view.hxx>
48 #include <basesh.hxx>
49 #include <outline.hxx>
50 #include <cnttab.hxx>
51 #include <swuicnttab.hxx>
52 #include <formedt.hxx>
53 #include <poolfmt.hxx>
54 #include <poolfmt.hrc>
55 #include <uitool.hxx>
56 #include <fmtcol.hxx>
57 #include <fldbas.hxx>
58 #include <expfld.hxx>
59 #include <unotools.hxx>
60 #include <unotxdoc.hxx>
61 #include <docsh.hxx>
62 #include <swmodule.hxx>
63 #include <modcfg.hxx>
65 #include <cmdid.h>
66 #include <helpid.h>
67 #include <utlui.hrc>
68 #include <index.hrc>
69 #include <cnttab.hrc>
70 #include <globals.hrc>
71 #include <SwStyleNameMapper.hxx>
72 #include <sfx2/filedlghelper.hxx>
73 #include <toxwrap.hxx>
74 #include <chpfld.hxx>
76 #include "utlui.hrc"
78 #include <sfx2/app.hxx>
80 #include <unomid.h>
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::lang;
83 using namespace ::com::sun::star::uno;
84 using namespace com::sun::star::ui::dialogs;
85 using namespace ::sfx2;
86 #include <svtools/editbrowsebox.hxx>
88 static const sal_Unicode aDeliStart = '['; // for the form
89 static const sal_Unicode aDeliEnd = ']'; // for the form
91 #define IDX_FILE_EXTENSION OUString("*.sdi")
93 static String lcl_CreateAutoMarkFileDlg( const String& rURL,
94 const String& rFileString, bool bOpen )
96 String sRet;
98 FileDialogHelper aDlgHelper( bOpen ?
99 TemplateDescription::FILEOPEN_SIMPLE : TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
100 uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
102 uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
103 String sCurFltr( IDX_FILE_EXTENSION );
104 xFltMgr->appendFilter( rFileString, sCurFltr );
105 xFltMgr->setCurrentFilter( rFileString ) ;
107 String& rLastSaveDir = (String&)SFX_APP()->GetLastSaveDirectory();
108 String sSaveDir = rLastSaveDir;
110 if( rURL.Len() )
111 xFP->setDisplayDirectory( rURL );
112 else
114 SvtPathOptions aPathOpt;
115 xFP->setDisplayDirectory( aPathOpt.GetUserConfigPath() );
118 if( aDlgHelper.Execute() == ERRCODE_NONE )
120 sRet = xFP->getFiles().getConstArray()[0];
122 rLastSaveDir = sSaveDir;
123 return sRet;
126 struct AutoMarkEntry
128 String sSearch;
129 String sAlternative;
130 String sPrimKey;
131 String sSecKey;
132 String sComment;
133 sal_Bool bCase;
134 sal_Bool bWord;
136 AutoMarkEntry() :
137 bCase(sal_False),
138 bWord(sal_False){}
140 typedef boost::ptr_vector<AutoMarkEntry> AutoMarkEntryArr;
142 typedef ::svt::EditBrowseBox SwEntryBrowseBox_Base;
143 class SwEntryBrowseBox : public SwEntryBrowseBox_Base
145 Edit aCellEdit;
146 ::svt::CheckBoxControl aCellCheckBox;
148 String sSearch;
149 String sAlternative;
150 String sPrimKey;
151 String sSecKey;
152 String sComment;
153 String sCaseSensitive;
154 String sWordOnly;
155 String sYes;
156 String sNo;
158 AutoMarkEntryArr aEntryArr;
160 ::svt::CellControllerRef xController;
161 ::svt::CellControllerRef xCheckController;
163 long nCurrentRow;
164 bool bModified;
167 void SetModified() {bModified = true;}
169 protected:
170 virtual sal_Bool SeekRow( long nRow );
171 virtual void PaintCell(OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId) const;
172 virtual void InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol);
173 virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol);
174 virtual sal_Bool SaveModified();
176 public:
177 SwEntryBrowseBox(Window* pParent, const ResId& rId,
178 BrowserMode nMode = 0 );
179 void ReadEntries(SvStream& rInStr);
180 void WriteEntries(SvStream& rOutStr);
182 sal_Bool IsModified()const;
184 virtual String GetCellText( long nRow, sal_uInt16 nColumn ) const;
187 class SwAutoMarkDlg_Impl : public ModalDialog
189 OKButton aOKPB;
190 CancelButton aCancelPB;
191 HelpButton aHelpPB;
193 SwEntryBrowseBox aEntriesBB;
194 FixedLine aEntriesFL;
196 String sAutoMarkURL;
197 const String sAutoMarkType;
199 bool bCreateMode;
201 DECL_LINK(OkHdl, void *);
202 public:
203 SwAutoMarkDlg_Impl(Window* pParent, const String& rAutoMarkURL,
204 const String& rAutoMarkType, bool bCreate);
205 ~SwAutoMarkDlg_Impl();
209 sal_uInt16 CurTOXType::GetFlatIndex() const
211 sal_uInt16 nRet = static_cast< sal_uInt16 >(eType);
212 if(eType == TOX_USER && nIndex)
214 nRet = static_cast< sal_uInt16 >(TOX_AUTHORITIES + nIndex);
216 return nRet;
219 #define EDIT_MINWIDTH 15
221 SwMultiTOXTabDialog::SwMultiTOXTabDialog(Window* pParent, const SfxItemSet& rSet,
222 SwWrtShell &rShell,
223 SwTOXBase* pCurTOX,
224 sal_uInt16 nToxType, sal_Bool bGlobal) :
225 SfxTabDialog( pParent, SW_RES(DLG_MULTI_TOX), &rSet),
226 aExampleContainerWIN(this, SW_RES(WIN_EXAMPLE)),
227 aShowExampleCB( this, SW_RES(CB_SHOWEXAMPLE)),
228 pMgr( new SwTOXMgr( &rShell ) ),
229 rSh(rShell),
230 pExampleFrame(0),
231 pParamTOXBase(pCurTOX),
232 sUserDefinedIndex(SW_RES(ST_USERDEFINEDINDEX)),
233 nInitialTOXType(nToxType),
235 bEditTOX(sal_False),
236 bExampleCreated(sal_False),
237 bGlobalFlag(bGlobal)
239 FreeResource();
241 eCurrentTOXType.eType = TOX_CONTENT;
242 eCurrentTOXType.nIndex = 0;
244 sal_uInt16 nUserTypeCount = rSh.GetTOXTypeCount(TOX_USER);
245 nTypeCount = nUserTypeCount + 6;
246 pFormArr = new SwForm*[nTypeCount];
247 pDescArr = new SwTOXDescription*[nTypeCount];
248 pxIndexSectionsArr = new SwIndexSections_Impl*[nTypeCount];
249 //the standard user index is on position TOX_USER
250 //all user user indexes follow after position TOX_AUTHORITIES
251 if(pCurTOX)
253 bEditTOX = sal_True;
255 for(int i = nTypeCount - 1; i > -1; i--)
257 pFormArr[i] = 0;
258 pDescArr[i] = 0;
259 pxIndexSectionsArr[i] = new SwIndexSections_Impl;
260 if(pCurTOX)
262 eCurrentTOXType.eType = pCurTOX->GetType();
263 sal_uInt16 nArrayIndex = static_cast< sal_uInt16 >(eCurrentTOXType.eType);
264 if(eCurrentTOXType.eType == TOX_USER)
266 //which user type is it?
267 for(sal_uInt16 nUser = 0; nUser < nUserTypeCount; nUser++)
269 const SwTOXType* pTemp = rSh.GetTOXType(TOX_USER, nUser);
270 if(pCurTOX->GetTOXType() == pTemp)
272 eCurrentTOXType.nIndex = nUser;
273 nArrayIndex = static_cast< sal_uInt16 >(nUser > 0 ? TOX_AUTHORITIES + nUser : TOX_USER);
274 break;
278 pFormArr[nArrayIndex] = new SwForm(pCurTOX->GetTOXForm());
279 pDescArr[nArrayIndex] = CreateTOXDescFromTOXBase(pCurTOX);
280 if(TOX_AUTHORITIES == eCurrentTOXType.eType)
282 const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
283 rSh.GetFldType(RES_AUTHORITY, aEmptyStr);
284 if(pFType)
286 String sBrackets;
287 if(pFType->GetPrefix())
288 sBrackets += pFType->GetPrefix();
289 if(pFType->GetSuffix())
290 sBrackets += pFType->GetSuffix();
291 pDescArr[nArrayIndex]->SetAuthBrackets(sBrackets);
292 pDescArr[nArrayIndex]->SetAuthSequence(pFType->IsSequence());
294 else
296 pDescArr[nArrayIndex]->SetAuthBrackets(OUString("[]"));
301 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
302 OSL_ENSURE(pFact, "Dialogdiet fail!");
303 AddTabPage(TP_TOX_SELECT, SwTOXSelectTabPage::Create, 0);
304 AddTabPage(TP_TOX_STYLES, SwTOXStylesTabPage::Create, 0);
305 AddTabPage(TP_COLUMN, SwColumnPage::Create, 0);
306 AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
307 AddTabPage(TP_TOX_ENTRY, SwTOXEntryTabPage::Create, 0);
308 if(!pCurTOX)
309 SetCurPageId(TP_TOX_SELECT);
311 aShowExampleCB.SetClickHdl(LINK(this, SwMultiTOXTabDialog, ShowPreviewHdl));
313 aShowExampleCB.Check( SW_MOD()->GetModuleConfig()->IsShowIndexPreview());
315 aExampleContainerWIN.SetAccessibleName(aShowExampleCB.GetText());
316 SetViewAlign( WINDOWALIGN_LEFT );
317 // SetViewWindow does not work if the dialog is visible!
319 if(!aShowExampleCB.IsChecked())
320 SetViewWindow( &aExampleContainerWIN );
322 Point aOldPos = GetPosPixel();
323 ShowPreviewHdl(0);
324 Point aNewPos = GetPosPixel();
325 //72040: initial position may be left of the view - that has to be corrected
326 if(aNewPos.X() < 0)
327 SetPosPixel(aOldPos);
330 SwMultiTOXTabDialog::~SwMultiTOXTabDialog()
332 SW_MOD()->GetModuleConfig()->SetShowIndexPreview(aShowExampleCB.IsChecked());
334 // fdo#38515 Avoid setting focus on deleted controls in the destructors
335 EnableInput( sal_False );
337 for(sal_uInt16 i = 0; i < nTypeCount; i++)
339 delete pFormArr[i];
340 delete pDescArr[i];
341 delete pxIndexSectionsArr[i];
343 delete[] pxIndexSectionsArr;
345 delete[] pFormArr;
346 delete[] pDescArr;
347 delete pMgr;
348 delete pExampleFrame;
351 void SwMultiTOXTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
353 if( TP_BACKGROUND == nId )
355 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
356 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
357 rPage.PageCreated(aSet);
359 else if(TP_COLUMN == nId )
361 const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)GetInputSetImpl()->Get(RES_FRM_SIZE);
363 ((SwColumnPage&)rPage).SetPageWidth(rSize.GetWidth());
365 else if(TP_TOX_ENTRY == nId)
366 ((SwTOXEntryTabPage&)rPage).SetWrtShell(rSh);
367 if(TP_TOX_SELECT == nId)
369 ((SwTOXSelectTabPage&)rPage).SetWrtShell(rSh);
370 if(USHRT_MAX != nInitialTOXType)
371 ((SwTOXSelectTabPage&)rPage).SelectType((TOXTypes)nInitialTOXType);
375 short SwMultiTOXTabDialog::Ok()
377 short nRet = SfxTabDialog::Ok();
378 SwTOXDescription& rDesc = GetTOXDescription(eCurrentTOXType);
379 SwTOXBase aNewDef(*rSh.GetDefaultTOXBase( eCurrentTOXType.eType, true ));
381 sal_uInt16 nIndex = static_cast< sal_uInt16 >(eCurrentTOXType.eType);
382 if(eCurrentTOXType.eType == TOX_USER && eCurrentTOXType.nIndex)
384 nIndex = static_cast< sal_uInt16 >(TOX_AUTHORITIES + eCurrentTOXType.nIndex);
387 if(pFormArr[nIndex])
389 rDesc.SetForm(*pFormArr[nIndex]);
390 aNewDef.SetTOXForm(*pFormArr[nIndex]);
392 rDesc.ApplyTo(aNewDef);
393 if(!bGlobalFlag)
394 pMgr->UpdateOrInsertTOX(
395 rDesc, 0, GetOutputItemSet());
396 else if(bEditTOX)
397 pMgr->UpdateOrInsertTOX(
398 rDesc, &pParamTOXBase, GetOutputItemSet());
400 if(!eCurrentTOXType.nIndex)
401 rSh.SetDefaultTOXBase(aNewDef);
403 return nRet;
406 SwForm* SwMultiTOXTabDialog::GetForm(CurTOXType eType)
408 sal_uInt16 nIndex = eType.GetFlatIndex();
409 if(!pFormArr[nIndex])
410 pFormArr[nIndex] = new SwForm(eType.eType);
411 return pFormArr[nIndex];
414 SwTOXDescription& SwMultiTOXTabDialog::GetTOXDescription(CurTOXType eType)
416 sal_uInt16 nIndex = eType.GetFlatIndex();
417 if(!pDescArr[nIndex])
419 const SwTOXBase* pDef = rSh.GetDefaultTOXBase( eType.eType );
420 if(pDef)
421 pDescArr[nIndex] = CreateTOXDescFromTOXBase(pDef);
422 else
424 pDescArr[nIndex] = new SwTOXDescription(eType.eType);
425 if(eType.eType == TOX_USER)
426 pDescArr[nIndex]->SetTitle(sUserDefinedIndex);
427 else
428 pDescArr[nIndex]->SetTitle(
429 rSh.GetTOXType(eType.eType, 0)->GetTypeName());
431 if(TOX_AUTHORITIES == eType.eType)
433 const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
434 rSh.GetFldType(RES_AUTHORITY, aEmptyStr);
435 if(pFType)
437 String sBrackets = OUString(pFType->GetPrefix());
438 sBrackets += pFType->GetSuffix();
439 pDescArr[nIndex]->SetAuthBrackets(sBrackets);
440 pDescArr[nIndex]->SetAuthSequence(pFType->IsSequence());
442 else
444 pDescArr[nIndex]->SetAuthBrackets(OUString("[]"));
447 else if(TOX_INDEX == eType.eType)
448 pDescArr[nIndex]->SetMainEntryCharStyle(SW_RESSTR(STR_POOLCHR_IDX_MAIN_ENTRY));
451 return *pDescArr[nIndex];
454 SwTOXDescription* SwMultiTOXTabDialog::CreateTOXDescFromTOXBase(
455 const SwTOXBase*pCurTOX)
457 SwTOXDescription * pDesc = new SwTOXDescription(pCurTOX->GetType());
458 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
459 pDesc->SetStyleNames(pCurTOX->GetStyleNames(i), i);
460 pDesc->SetAutoMarkURL(rSh.GetTOIAutoMarkURL());
461 pDesc->SetTitle(pCurTOX->GetTitle());
464 pDesc->SetContentOptions(pCurTOX->GetCreateType());
465 if(pDesc->GetTOXType() == TOX_INDEX)
466 pDesc->SetIndexOptions(pCurTOX->GetOptions());
467 pDesc->SetMainEntryCharStyle(pCurTOX->GetMainEntryCharStyle());
468 if(pDesc->GetTOXType() != TOX_INDEX)
469 pDesc->SetLevel((sal_uInt8)pCurTOX->GetLevel());
470 pDesc->SetCreateFromObjectNames(pCurTOX->IsFromObjectNames());
471 pDesc->SetSequenceName(pCurTOX->GetSequenceName());
472 pDesc->SetCaptionDisplay(pCurTOX->GetCaptionDisplay());
473 pDesc->SetFromChapter(pCurTOX->IsFromChapter());
474 pDesc->SetReadonly(pCurTOX->IsProtected());
475 pDesc->SetOLEOptions(pCurTOX->GetOLEOptions());
476 pDesc->SetLevelFromChapter(pCurTOX->IsLevelFromChapter());
477 pDesc->SetLanguage(pCurTOX->GetLanguage());
478 pDesc->SetSortAlgorithm(pCurTOX->GetSortAlgorithm());
479 return pDesc;
482 IMPL_LINK( SwMultiTOXTabDialog, ShowPreviewHdl, CheckBox *, pBox )
484 if(aShowExampleCB.IsChecked())
486 if(!pExampleFrame && !bExampleCreated)
488 bExampleCreated = sal_True;
489 String sTemplate(OUString("internal"));
490 sTemplate += INET_PATH_TOKEN;
491 sTemplate.AppendAscii( RTL_CONSTASCII_STRINGPARAM("idxexample") );
492 String sTemplateWithoutExt( sTemplate );
493 sTemplate.AppendAscii( RTL_CONSTASCII_STRINGPARAM(".odt") );
495 SvtPathOptions aOpt;
496 aOpt.SetTemplatePath(String("share/template/common"));
497 // 6.0 (extension .sxw)
498 sal_Bool bExist = aOpt.SearchFile( sTemplate, SvtPathOptions::PATH_TEMPLATE );
500 if( !bExist )
502 // 6.0 (extension .sxw)
503 sTemplate = sTemplateWithoutExt;
504 sTemplate.AppendAscii( RTL_CONSTASCII_STRINGPARAM(".sxw") );
505 bExist = aOpt.SearchFile( sTemplate, SvtPathOptions::PATH_TEMPLATE );
507 if( !bExist )
509 // 5.0 (extension .vor)
510 sTemplate = sTemplateWithoutExt;
511 sTemplate.AppendAscii( RTL_CONSTASCII_STRINGPARAM(".sdw") );
512 bExist = aOpt.SearchFile( sTemplate, SvtPathOptions::PATH_TEMPLATE );
515 if(!bExist)
517 String sInfo(SW_RES(STR_FILE_NOT_FOUND));
518 sInfo.SearchAndReplaceAscii( "%1", sTemplate );
519 sInfo.SearchAndReplaceAscii( "%2", aOpt.GetTemplatePath() );
520 InfoBox aInfo(GetParent(), sInfo);
521 aInfo.Execute();
523 else
525 Link aLink(LINK(this, SwMultiTOXTabDialog, CreateExample_Hdl));
526 pExampleFrame = new SwOneExampleFrame(
527 aExampleContainerWIN, EX_SHOW_ONLINE_LAYOUT, &aLink, &sTemplate);
529 if(!pExampleFrame->IsServiceAvailable())
531 pExampleFrame->CreateErrorMessage(0);
534 aShowExampleCB.Show(pExampleFrame && pExampleFrame->IsServiceAvailable());
537 sal_Bool bSetViewWindow = aShowExampleCB.IsChecked()
538 && pExampleFrame && pExampleFrame->IsServiceAvailable();
540 aExampleContainerWIN.Show( bSetViewWindow );
541 SetViewWindow( bSetViewWindow ? &aExampleContainerWIN : 0 );
543 Window *pTopmostParent = this;
544 while(pTopmostParent->GetParent())
545 pTopmostParent = pTopmostParent->GetParent();
546 ::Rectangle aRect(GetClientWindowExtentsRelative(pTopmostParent));
547 ::Point aPos = aRect.TopLeft();
548 Size aSize = GetSizePixel();
549 if(pBox)
550 AdjustLayout();
551 long nDiffWidth = GetSizePixel().Width() - aSize.Width();
552 aPos.X() -= nDiffWidth;
553 SetPosPixel(aPos);
555 return 0;
558 sal_Bool SwMultiTOXTabDialog::IsNoNum(SwWrtShell& rSh, const String& rName)
560 SwTxtFmtColl* pColl = rSh.GetParaStyle(rName);
561 if(pColl && ! pColl->IsAssignedToListLevelOfOutlineStyle()) //<-end,zhaojianwei
562 return sal_True;
564 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
565 if(nId != USHRT_MAX &&
566 ! rSh.GetTxtCollFromPool(nId)->IsAssignedToListLevelOfOutlineStyle()) //<-end,zhaojianwei
567 return sal_True;
569 return sal_False;
572 class SwIndexTreeLB : public SvTreeListBox
574 const HeaderBar* pHeaderBar;
575 public:
576 SwIndexTreeLB(Window* pWin, const ResId& rResId) :
577 SvTreeListBox(pWin, rResId), pHeaderBar(0){}
579 virtual void KeyInput( const KeyEvent& rKEvt );
580 virtual long GetTabPos( SvTreeListEntry*, SvLBoxTab* );
581 void SetHeaderBar(const HeaderBar* pHB) {pHeaderBar = pHB;}
584 long SwIndexTreeLB::GetTabPos( SvTreeListEntry* pEntry, SvLBoxTab* pTab)
586 long nData = (long)pEntry->GetUserData();
587 if(nData != USHRT_MAX)
589 long nPos = pHeaderBar->GetItemRect( static_cast< sal_uInt16 >(101 + nData) ).TopLeft().X();
590 nData = nPos;
592 else
593 nData = 0;
594 nData += pTab->GetPos();
595 return nData;
598 void SwIndexTreeLB::KeyInput( const KeyEvent& rKEvt )
600 SvTreeListEntry* pEntry = FirstSelected();
601 KeyCode aCode = rKEvt.GetKeyCode();
602 sal_Bool bChanged = sal_False;
603 if(pEntry)
605 long nLevel = (long)pEntry->GetUserData();
606 if(aCode.GetCode() == KEY_ADD )
608 if(nLevel < MAXLEVEL - 1)
609 nLevel++;
610 else if(nLevel == USHRT_MAX)
611 nLevel = 0;
612 bChanged = sal_True;
614 else if(aCode.GetCode() == KEY_SUBTRACT)
616 if(!nLevel)
617 nLevel = USHRT_MAX;
618 else if(nLevel != USHRT_MAX)
619 nLevel--;
620 bChanged = sal_True;
622 if(bChanged)
624 pEntry->SetUserData((void*)nLevel);
625 Invalidate();
628 if(!bChanged)
629 SvTreeListBox::KeyInput(rKEvt);
632 class SwHeaderTree : public Control
634 HeaderBar aStylesHB;
635 SwIndexTreeLB aStylesTLB;
637 public:
638 SwHeaderTree(Window* pParent, const ResId rResId);
640 HeaderBar& GetHeaderBar() {return aStylesHB;}
641 SwIndexTreeLB& GetTreeListBox() { return aStylesTLB;}
643 virtual void GetFocus();
646 SwHeaderTree::SwHeaderTree(Window* pParent, const ResId rResId) :
647 Control(pParent, rResId),
648 aStylesHB( this, ResId(HB_STYLES, *rResId.GetResMgr())),
649 aStylesTLB( this, ResId(TLB_STYLES, *rResId.GetResMgr()))
651 FreeResource();
652 aStylesHB.SetStyle(aStylesHB.GetStyle()|WB_BUTTONSTYLE|WB_TABSTOP|WB_BORDER);
653 Size aHBSize(aStylesHB.GetSizePixel());
654 aHBSize.Height() = aStylesHB.CalcWindowSizePixel().Height();
655 aStylesHB.SetSizePixel(aHBSize);
656 aStylesTLB.SetPosPixel(Point(0, aHBSize.Height()));
657 Size aTLBSize(aStylesHB.GetSizePixel());
658 aTLBSize.Height() = GetOutputSizePixel().Height() - aHBSize.Height();
659 aStylesTLB.SetSizePixel(aTLBSize);
660 aStylesTLB.SetHeaderBar(&aStylesHB);
663 void SwHeaderTree::GetFocus()
665 Control::GetFocus();
666 aStylesTLB.GrabFocus();
669 class SwAddStylesDlg_Impl : public SfxModalDialog
671 OKButton aOk;
672 CancelButton aCancel;
673 HelpButton aHelp;
675 FixedLine aStylesFL;
676 SwHeaderTree aHeaderTree;
677 ImageButton aLeftPB;
678 ImageButton aRightPB;
680 String sHBFirst;
681 String* pStyleArr;
683 DECL_LINK(OkHdl, void *);
684 DECL_LINK(LeftRightHdl, PushButton*);
685 DECL_LINK(HeaderDragHdl, void *);
687 public:
688 SwAddStylesDlg_Impl(Window* pParent, SwWrtShell& rWrtSh, String rStringArr[]);
689 ~SwAddStylesDlg_Impl();
692 SwAddStylesDlg_Impl::SwAddStylesDlg_Impl(Window* pParent,
693 SwWrtShell& rWrtSh, String rStringArr[]) :
694 SfxModalDialog(pParent, SW_RES(DLG_ADD_IDX_STYLES)),
695 aOk( this, SW_RES(PB_OK )),
696 aCancel( this, SW_RES(PB_CANCEL )),
697 aHelp( this, SW_RES(PB_HELP )),
699 aStylesFL( this, SW_RES(FL_STYLES )),
700 aHeaderTree(this, SW_RES(TR_HEADER )),
701 aLeftPB( this, SW_RES(PB_LEFT )),
702 aRightPB( this, SW_RES(PB_RIGHT )),
704 sHBFirst( SW_RES(ST_HB_FIRST)),
705 pStyleArr(rStringArr)
707 FreeResource();
709 aHeaderTree.SetAccessibleRelationMemberOf(&aStylesFL);
710 aLeftPB.SetAccessibleRelationMemberOf(&aStylesFL);
711 aRightPB.SetAccessibleRelationMemberOf(&aStylesFL);
713 aOk.SetClickHdl(LINK(this, SwAddStylesDlg_Impl, OkHdl));
714 aLeftPB.SetClickHdl(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
715 aRightPB.SetClickHdl(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
717 HeaderBar& rHB = aHeaderTree.GetHeaderBar();
718 rHB.SetEndDragHdl(LINK(this, SwAddStylesDlg_Impl, HeaderDragHdl));
720 long nWidth = rHB.GetSizePixel().Width();
721 sal_uInt16 i;
723 nWidth /= 14;
724 nWidth--;
725 rHB.InsertItem( 100, sHBFirst, 4 * nWidth );
726 for( i = 1; i <= MAXLEVEL; i++)
727 rHB.InsertItem( 100 + i, OUString::number(i), nWidth );
728 rHB.Show();
730 SwIndexTreeLB& rTLB = aHeaderTree.GetTreeListBox();
731 rTLB.SetStyle(rTLB.GetStyle()|WB_CLIPCHILDREN|WB_SORT);
732 rTLB.GetModel()->SetSortMode(SortAscending);
733 for(i = 0; i < MAXLEVEL; ++i)
735 String sStyles(rStringArr[i]);
736 for(sal_uInt16 nToken = 0; nToken < comphelper::string::getTokenCount(sStyles, TOX_STYLE_DELIMITER); nToken++)
738 String sTmp(sStyles.GetToken(nToken, TOX_STYLE_DELIMITER));
739 SvTreeListEntry* pEntry = rTLB.InsertEntry(sTmp);
740 pEntry->SetUserData(reinterpret_cast<void*>(i));
743 // now the other styles
745 const SwTxtFmtColl *pColl = 0;
746 const sal_uInt16 nSz = rWrtSh.GetTxtFmtCollCount();
748 for ( sal_uInt16 j = 0;j < nSz; ++j )
750 pColl = &rWrtSh.GetTxtFmtColl(j);
751 if(pColl->IsDefault())
752 continue;
754 const String& rName = pColl->GetName();
756 if(rName.Len() > 0)
758 SvTreeListEntry* pEntry = rTLB.First();
759 bool bFound = false;
760 while(pEntry && !bFound)
762 if(rTLB.GetEntryText(pEntry) == rName)
763 bFound = true;
764 pEntry = rTLB.Next(pEntry);
766 if(!bFound)
768 rTLB.InsertEntry(rName)->SetUserData((void*)USHRT_MAX);
772 rTLB.GetModel()->Resort();
775 SwAddStylesDlg_Impl::~SwAddStylesDlg_Impl()
779 IMPL_LINK_NOARG(SwAddStylesDlg_Impl, OkHdl)
781 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
782 pStyleArr[i].Erase();
784 SwIndexTreeLB& rTLB = aHeaderTree.GetTreeListBox();
785 SvTreeListEntry* pEntry = rTLB.First();
786 while(pEntry)
788 long nLevel = (long)pEntry->GetUserData();
789 if(nLevel != USHRT_MAX)
791 String sName(rTLB.GetEntryText(pEntry));
792 if(pStyleArr[nLevel].Len())
793 pStyleArr[nLevel] += TOX_STYLE_DELIMITER;
794 pStyleArr[nLevel] += sName;
796 pEntry = rTLB.Next(pEntry);
799 //TODO write back style names
800 EndDialog(RET_OK);
801 return 0;
804 IMPL_LINK_NOARG(SwAddStylesDlg_Impl, HeaderDragHdl)
806 aHeaderTree.GetTreeListBox().Invalidate();
807 return 0;
810 IMPL_LINK(SwAddStylesDlg_Impl, LeftRightHdl, PushButton*, pBtn)
812 sal_Bool bLeft = pBtn == &aLeftPB;
813 SvTreeListEntry* pEntry = aHeaderTree.GetTreeListBox().FirstSelected();
814 if(pEntry)
816 long nLevel = (long)pEntry->GetUserData();
817 if(bLeft)
819 if(!nLevel)
820 nLevel = USHRT_MAX;
821 else if(nLevel != USHRT_MAX)
822 nLevel--;
824 else
826 if(nLevel < MAXLEVEL - 1)
827 nLevel++;
828 else if(nLevel == USHRT_MAX)
829 nLevel = 0;
831 pEntry->SetUserData((void*)nLevel);
832 aHeaderTree.GetTreeListBox().Invalidate();
834 return 0;
837 SwTOXSelectTabPage::SwTOXSelectTabPage(Window* pParent, const SfxItemSet& rAttrSet) :
838 SfxTabPage(pParent, SW_RES(TP_TOX_SELECT), rAttrSet),
840 aTypeTitleFL( this, SW_RES(FL_TYPETITLE )),
841 aTitleFT( this, SW_RES(FT_TITLE )),
842 aTitleED( this, SW_RES(ED_TITLE )),
843 aTypeFT( this, SW_RES(FT_TYPE )),
844 aTypeLB( this, SW_RES(LB_TYPE )),
845 aReadOnlyCB( this, SW_RES(CB_READONLY )),
847 aAreaFL( this, SW_RES(FL_AREA )),
848 aAreaFT( this, SW_RES(FT_AREA )),
849 aAreaLB( this, SW_RES(LB_AREA )),
850 aLevelFT( this, SW_RES(FT_LEVEL )),
851 aLevelNF( this, SW_RES(NF_LEVEL )),
853 aCreateFromFL( this, SW_RES(FL_CREATEFROM )),
854 aFromHeadingsCB( this, SW_RES(CB_FROMHEADINGS )),
855 aAddStylesCB( this, SW_RES(CB_ADDSTYLES )),
856 aAddStylesPB( this, SW_RES(PB_ADDSTYLES )),
858 aFromTablesCB( this, SW_RES(CB_FROMTABLES )),
859 aFromFramesCB( this, SW_RES(CB_FROMFRAMES )),
860 aFromGraphicsCB( this, SW_RES(CB_FROMGRAPHICS )),
861 aFromOLECB( this, SW_RES(CB_FROMOLE )),
862 aLevelFromChapterCB(this, SW_RES(CB_LEVELFROMCHAPTER )),
864 aFromCaptionsRB( this, SW_RES(RB_FROMCAPTIONS )),
865 aFromObjectNamesRB( this, SW_RES(RB_FROMOBJECTNAMES )),
867 aCaptionSequenceFT( this, SW_RES(FT_CAPTIONSEQUENCE )),
868 aCaptionSequenceLB( this, SW_RES(LB_CAPTIONSEQUENCE )),
869 aDisplayTypeFT( this, SW_RES(FT_DISPLAYTYPE )),
870 aDisplayTypeLB( this, SW_RES(LB_DISPLAYTYPE )),
872 aTOXMarksCB( this, SW_RES(CB_TOXMARKS )),
874 aIdxOptionsFL( this, SW_RES(FL_IDXOPTIONS )),
875 aCollectSameCB( this, SW_RES(CB_COLLECTSAME )),
876 aUseFFCB( this, SW_RES(CB_USEFF )),
877 aUseDashCB( this, SW_RES(CB_USE_DASH )),
878 aCaseSensitiveCB( this, SW_RES(CB_CASESENSITIVE )),
879 aInitialCapsCB( this, SW_RES(CB_INITIALCAPS )),
880 aKeyAsEntryCB( this, SW_RES(CB_KEYASENTRY )),
881 aFromFileCB( this, SW_RES(CB_FROMFILE )),
882 aAutoMarkPB( this, SW_RES(MB_AUTOMARK )),
884 aFromNames( SW_RES(RES_SRCTYPES )),
885 aFromObjCLB( this, SW_RES(CLB_FROMOBJ )),
886 aFromObjFL( this, SW_RES(FL_FROMOBJ )),
888 aSequenceCB( this, SW_RES(CB_SEQUENCE )),
889 aBracketFT( this, SW_RES(FT_BRACKET )),
890 aBracketLB( this, SW_RES(LB_BRACKET )),
891 aAuthorityFormatFL( this, SW_RES(FL_AUTHORITY )),
893 aSortOptionsFL( this, SW_RES(FL_SORTOPTIONS )),
894 aLanguageFT( this, SW_RES(FT_LANGUAGE )),
895 aLanguageLB( this, SW_RES(LB_LANGUAGE )),
896 aSortAlgorithmFT( this, SW_RES(FT_SORTALG )),
897 aSortAlgorithmLB( this, SW_RES(LB_SORTALG )),
899 pIndexRes(0),
901 sAutoMarkType(SW_RES(ST_AUTOMARK_TYPE)),
902 sAddStyleUser(SW_RES(ST_USER_ADDSTYLE)),
903 bFirstCall(sal_True)
905 aBracketLB.InsertEntry(String(SW_RES(ST_NO_BRACKET)), 0);
907 aAddStylesPB.SetAccessibleRelationMemberOf(&aCreateFromFL);
908 aAddStylesPB.SetAccessibleRelationLabeledBy(&aAddStylesCB);
909 aAddStylesPB.SetAccessibleName(aAddStylesCB.GetText());
911 FreeResource();
913 pIndexEntryWrapper = new IndexEntrySupplierWrapper();
915 aLanguageLB.SetLanguageList( LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN,
916 sal_False, sal_False, sal_False );
918 sAddStyleContent = aAddStylesCB.GetText();
920 aCBLeftPos1 = aFromHeadingsCB.GetPosPixel();
921 aCBLeftPos2 = aAddStylesCB.GetPosPixel();
922 aCBLeftPos3 = aTOXMarksCB.GetPosPixel();
924 ResStringArray& rNames = aFromNames.GetNames();
925 for(sal_uInt16 i = 0; i < rNames.Count(); i++)
927 aFromObjCLB.InsertEntry(rNames.GetString(i));
928 aFromObjCLB.SetEntryData( i, (void*)rNames.GetValue(i) );
930 aFromObjCLB.SetHelpId(HID_OLE_CHECKLB);
932 SetExchangeSupport();
933 aTypeLB.SetSelectHdl(LINK(this, SwTOXSelectTabPage, TOXTypeHdl));
935 aAddStylesPB.SetClickHdl(LINK(this, SwTOXSelectTabPage, AddStylesHdl));
937 PopupMenu* pMenu = aAutoMarkPB.GetPopupMenu();
938 pMenu->SetActivateHdl(LINK(this, SwTOXSelectTabPage, MenuEnableHdl));
939 pMenu->SetSelectHdl(LINK(this, SwTOXSelectTabPage, MenuExecuteHdl));
941 Link aLk = LINK(this, SwTOXSelectTabPage, CheckBoxHdl);
942 aAddStylesCB .SetClickHdl(aLk);
943 aFromHeadingsCB .SetClickHdl(aLk);
944 aTOXMarksCB .SetClickHdl(aLk);
945 aFromFileCB .SetClickHdl(aLk);
946 aCollectSameCB .SetClickHdl(aLk);
947 aUseFFCB .SetClickHdl(aLk);
948 aUseDashCB .SetClickHdl(aLk);
949 aInitialCapsCB .SetClickHdl(aLk);
950 aKeyAsEntryCB .SetClickHdl(aLk);
952 Link aModifyLk = LINK(this, SwTOXSelectTabPage, ModifyHdl);
953 aTitleED.SetModifyHdl(aModifyLk);
954 aLevelNF.SetModifyHdl(aModifyLk);
955 aSortAlgorithmLB.SetSelectHdl(aModifyLk);
957 aLk = LINK(this, SwTOXSelectTabPage, RadioButtonHdl);
958 aFromCaptionsRB.SetClickHdl(aLk);
959 aFromObjectNamesRB.SetClickHdl(aLk);
960 RadioButtonHdl(&aFromCaptionsRB);
962 aLanguageLB.SetSelectHdl(LINK(this, SwTOXSelectTabPage, LanguageHdl));
963 aTypeLB.SelectEntryPos(0);
964 aTitleED.SaveValue();
967 SwTOXSelectTabPage::~SwTOXSelectTabPage()
969 delete pIndexRes;
970 delete pIndexEntryWrapper;
973 void SwTOXSelectTabPage::SetWrtShell(SwWrtShell& rSh)
975 sal_uInt16 nUserTypeCount = rSh.GetTOXTypeCount(TOX_USER);
976 if(nUserTypeCount > 1)
978 //insert all new user indexes names after the standard user index
979 sal_uInt16 nPos = aTypeLB.GetEntryPos((void*)(sal_uInt32)TO_USER);
980 nPos++;
981 for(sal_uInt16 nUser = 1; nUser < nUserTypeCount; nUser++)
983 nPos = aTypeLB.InsertEntry(rSh.GetTOXType(TOX_USER, nUser)->GetTypeName(), nPos);
984 sal_uIntPtr nEntryData = nUser << 8;
985 nEntryData |= TO_USER;
986 aTypeLB.SetEntryData(nPos, (void*)nEntryData);
991 sal_Bool SwTOXSelectTabPage::FillItemSet( SfxItemSet& )
993 return sal_True;
996 static long lcl_TOXTypesToUserData(CurTOXType eType)
998 sal_uInt16 nRet = TOX_INDEX;
999 switch(eType.eType)
1001 case TOX_INDEX : nRet = TO_INDEX; break;
1002 case TOX_USER :
1004 nRet = eType.nIndex << 8;
1005 nRet |= TO_USER;
1007 break;
1008 case TOX_CONTENT : nRet = TO_CONTENT; break;
1009 case TOX_ILLUSTRATIONS:nRet = TO_ILLUSTRATION; break;
1010 case TOX_OBJECTS : nRet = TO_OBJECT; break;
1011 case TOX_TABLES : nRet = TO_TABLE; break;
1012 case TOX_AUTHORITIES : nRet = TO_AUTHORITIES; break;
1014 return nRet;
1017 void SwTOXSelectTabPage::SelectType(TOXTypes eSet)
1019 CurTOXType eCurType (eSet, 0);
1021 long nData = lcl_TOXTypesToUserData(eCurType);
1022 aTypeLB.SelectEntryPos(aTypeLB.GetEntryPos((void*)nData));
1023 aTypeFT.Enable(sal_False);
1024 aTypeLB.Enable(sal_False);
1025 TOXTypeHdl(&aTypeLB);
1028 static CurTOXType lcl_UserData2TOXTypes(sal_uInt16 nData)
1030 CurTOXType eRet;
1032 switch(nData&0xff)
1034 case TO_INDEX : eRet.eType = TOX_INDEX; break;
1035 case TO_USER :
1037 eRet.eType = TOX_USER;
1038 eRet.nIndex = (nData&0xff00) >> 8;
1040 break;
1041 case TO_CONTENT : eRet.eType = TOX_CONTENT; break;
1042 case TO_ILLUSTRATION: eRet.eType = TOX_ILLUSTRATIONS; break;
1043 case TO_OBJECT : eRet.eType = TOX_OBJECTS; break;
1044 case TO_TABLE : eRet.eType = TOX_TABLES; break;
1045 case TO_AUTHORITIES : eRet.eType = TOX_AUTHORITIES; break;
1046 default: OSL_FAIL("what a type?");
1048 return eRet;
1051 void SwTOXSelectTabPage::ApplyTOXDescription()
1053 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
1054 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1055 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
1056 aReadOnlyCB.Check(rDesc.IsReadonly());
1057 if(aTitleED.GetText() == aTitleED.GetSavedValue())
1059 if(rDesc.GetTitle())
1060 aTitleED.SetText(*rDesc.GetTitle());
1061 else
1062 aTitleED.SetText(aEmptyStr);
1063 aTitleED.SaveValue();
1066 aAreaLB.SelectEntryPos(rDesc.IsFromChapter() ? 1 : 0);
1068 if(aCurType.eType != TOX_INDEX)
1069 aLevelNF.SetValue(rDesc.GetLevel()); //content, user
1071 sal_uInt16 nCreateType = rDesc.GetContentOptions();
1073 //user + content
1074 sal_Bool bHasStyleNames = sal_False;
1075 sal_uInt16 i;
1077 for( i = 0; i < MAXLEVEL; i++)
1078 if(rDesc.GetStyleNames(i).Len())
1080 bHasStyleNames = sal_True;
1081 break;
1083 aAddStylesCB.Check(bHasStyleNames && (nCreateType & nsSwTOXElement::TOX_TEMPLATE));
1085 aFromOLECB. Check( 0 != (nCreateType & nsSwTOXElement::TOX_OLE) );
1086 aFromTablesCB. Check( 0 != (nCreateType & nsSwTOXElement::TOX_TABLE) );
1087 aFromGraphicsCB.Check( 0 != (nCreateType & nsSwTOXElement::TOX_GRAPHIC) );
1088 aFromFramesCB. Check( 0 != (nCreateType & nsSwTOXElement::TOX_FRAME) );
1090 aLevelFromChapterCB.Check(rDesc.IsLevelFromChapter());
1092 //all but illustration and table
1093 aTOXMarksCB.Check( 0 != (nCreateType & nsSwTOXElement::TOX_MARK) );
1095 //content
1096 if(TOX_CONTENT == aCurType.eType)
1098 aFromHeadingsCB.Check( 0 != (nCreateType & nsSwTOXElement::TOX_OUTLINELEVEL) );
1099 aAddStylesCB.SetText(sAddStyleContent);
1100 aAddStylesPB.Enable(aAddStylesCB.IsChecked());
1102 //index only
1103 else if(TOX_INDEX == aCurType.eType)
1105 sal_uInt16 nIndexOptions = rDesc.GetIndexOptions();
1106 aCollectSameCB. Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_SAME_ENTRY) );
1107 aUseFFCB. Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_FF) );
1108 aUseDashCB. Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_DASH) );
1109 if(aUseFFCB.IsChecked())
1110 aUseDashCB.Enable(sal_False);
1111 else if(aUseDashCB.IsChecked())
1112 aUseFFCB.Enable(sal_False);
1114 aCaseSensitiveCB. Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_CASE_SENSITIVE) );
1115 aInitialCapsCB. Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_INITIAL_CAPS) );
1116 aKeyAsEntryCB. Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_KEY_AS_ENTRY) );
1118 else if(TOX_ILLUSTRATIONS == aCurType.eType ||
1119 TOX_TABLES == aCurType.eType)
1121 aFromObjectNamesRB.Check(rDesc.IsCreateFromObjectNames());
1122 aFromCaptionsRB.Check(!rDesc.IsCreateFromObjectNames());
1123 aCaptionSequenceLB.SelectEntry(rDesc.GetSequenceName());
1124 aDisplayTypeLB.SelectEntryPos( static_cast< sal_uInt16 >(rDesc.GetCaptionDisplay()) );
1125 RadioButtonHdl(&aFromCaptionsRB);
1128 else if(TOX_OBJECTS == aCurType.eType)
1130 long nOLEData = rDesc.GetOLEOptions();
1131 for(sal_uInt16 nFromObj = 0; nFromObj < aFromObjCLB.GetEntryCount(); nFromObj++)
1133 long nData = (long)aFromObjCLB.GetEntryData(nFromObj);
1134 aFromObjCLB.CheckEntryPos(nFromObj, 0 != (nData & nOLEData));
1137 else if(TOX_AUTHORITIES == aCurType.eType)
1139 String sBrackets(rDesc.GetAuthBrackets());
1140 if(!sBrackets.Len() || sBrackets.EqualsAscii(" "))
1141 aBracketLB.SelectEntryPos(0);
1142 else
1143 aBracketLB.SelectEntry(sBrackets);
1144 aSequenceCB.Check(rDesc.IsAuthSequence());
1146 aAutoMarkPB.Enable(aFromFileCB.IsChecked());
1148 for(i = 0; i < MAXLEVEL; i++)
1149 aStyleArr[i] = rDesc.GetStyleNames(i);
1151 aLanguageLB.SelectLanguage(rDesc.GetLanguage());
1152 LanguageHdl(0);
1153 for( long nCnt = 0; nCnt < aSortAlgorithmLB.GetEntryCount(); ++nCnt )
1155 const String* pEntryData = (const String*)aSortAlgorithmLB.GetEntryData( (sal_uInt16)nCnt );
1156 OSL_ENSURE(pEntryData, "no entry data available");
1157 if( pEntryData && *pEntryData == rDesc.GetSortAlgorithm())
1159 aSortAlgorithmLB.SelectEntryPos( (sal_uInt16)nCnt );
1160 break;
1165 void SwTOXSelectTabPage::FillTOXDescription()
1167 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
1168 CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1169 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
1170 rDesc.SetTitle(aTitleED.GetText());
1171 rDesc.SetFromChapter(1 == aAreaLB.GetSelectEntryPos());
1172 sal_uInt16 nContentOptions = 0;
1173 if(aTOXMarksCB.IsVisible() && aTOXMarksCB.IsChecked())
1174 nContentOptions |= nsSwTOXElement::TOX_MARK;
1176 sal_uInt16 nIndexOptions = rDesc.GetIndexOptions()&nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
1177 switch(rDesc.GetTOXType())
1179 case TOX_CONTENT:
1180 if(aFromHeadingsCB.IsChecked())
1181 nContentOptions |= nsSwTOXElement::TOX_OUTLINELEVEL;
1182 break;
1183 case TOX_USER:
1185 rDesc.SetTOUName(aTypeLB.GetSelectEntry());
1187 if(aFromOLECB.IsChecked())
1188 nContentOptions |= nsSwTOXElement::TOX_OLE;
1189 if(aFromTablesCB.IsChecked())
1190 nContentOptions |= nsSwTOXElement::TOX_TABLE;
1191 if(aFromFramesCB.IsChecked())
1192 nContentOptions |= nsSwTOXElement::TOX_FRAME;
1193 if(aFromGraphicsCB.IsChecked())
1194 nContentOptions |= nsSwTOXElement::TOX_GRAPHIC;
1196 break;
1197 case TOX_INDEX:
1199 nContentOptions = nsSwTOXElement::TOX_MARK;
1201 if(aCollectSameCB.IsChecked())
1202 nIndexOptions |= nsSwTOIOptions::TOI_SAME_ENTRY;
1203 if(aUseFFCB.IsChecked())
1204 nIndexOptions |= nsSwTOIOptions::TOI_FF;
1205 if(aUseDashCB.IsChecked())
1206 nIndexOptions |= nsSwTOIOptions::TOI_DASH;
1207 if(aCaseSensitiveCB.IsChecked())
1208 nIndexOptions |= nsSwTOIOptions::TOI_CASE_SENSITIVE;
1209 if(aInitialCapsCB.IsChecked())
1210 nIndexOptions |= nsSwTOIOptions::TOI_INITIAL_CAPS;
1211 if(aKeyAsEntryCB.IsChecked())
1212 nIndexOptions |= nsSwTOIOptions::TOI_KEY_AS_ENTRY;
1213 if(aFromFileCB.IsChecked())
1214 rDesc.SetAutoMarkURL(sAutoMarkURL);
1215 else
1216 rDesc.SetAutoMarkURL(aEmptyStr);
1218 break;
1219 case TOX_ILLUSTRATIONS:
1220 case TOX_TABLES :
1221 rDesc.SetCreateFromObjectNames(aFromObjectNamesRB.IsChecked());
1222 rDesc.SetSequenceName(aCaptionSequenceLB.GetSelectEntry());
1223 rDesc.SetCaptionDisplay((SwCaptionDisplay)aDisplayTypeLB.GetSelectEntryPos());
1224 break;
1225 case TOX_OBJECTS:
1227 long nOLEData = 0;
1228 for(sal_uInt16 i = 0; i < aFromObjCLB.GetEntryCount(); i++)
1230 if(aFromObjCLB.IsChecked(i))
1232 long nData = (long)aFromObjCLB.GetEntryData(i);
1233 nOLEData |= nData;
1236 rDesc.SetOLEOptions((sal_uInt16)nOLEData);
1238 break;
1239 case TOX_AUTHORITIES:
1241 if(aBracketLB.GetSelectEntryPos())
1242 rDesc.SetAuthBrackets(aBracketLB.GetSelectEntry());
1243 else
1244 rDesc.SetAuthBrackets(aEmptyStr);
1245 rDesc.SetAuthSequence(aSequenceCB.IsChecked());
1247 break;
1250 rDesc.SetLevelFromChapter( aLevelFromChapterCB.IsVisible() &&
1251 aLevelFromChapterCB.IsChecked());
1252 if(aTOXMarksCB.IsChecked() && aTOXMarksCB.IsVisible())
1253 nContentOptions |= nsSwTOXElement::TOX_MARK;
1254 if(aFromHeadingsCB.IsChecked() && aFromHeadingsCB.IsVisible())
1255 nContentOptions |= nsSwTOXElement::TOX_OUTLINELEVEL;
1256 if(aAddStylesCB.IsChecked() && aAddStylesCB.IsVisible())
1257 nContentOptions |= nsSwTOXElement::TOX_TEMPLATE;
1259 rDesc.SetContentOptions(nContentOptions);
1260 rDesc.SetIndexOptions(nIndexOptions);
1261 rDesc.SetLevel( static_cast< sal_uInt8 >(aLevelNF.GetValue()) );
1263 rDesc.SetReadonly(aReadOnlyCB.IsChecked());
1265 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
1266 rDesc.SetStyleNames(aStyleArr[i], i);
1268 rDesc.SetLanguage(aLanguageLB.GetSelectLanguage());
1269 const String* pEntryData = (const String*)aSortAlgorithmLB.GetEntryData(
1270 aSortAlgorithmLB.GetSelectEntryPos() );
1271 OSL_ENSURE(pEntryData, "no entry data available");
1272 if(pEntryData)
1273 rDesc.SetSortAlgorithm(*pEntryData);
1276 void SwTOXSelectTabPage::Reset( const SfxItemSet& )
1278 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
1279 SwWrtShell& rSh = pTOXDlg->GetWrtShell();
1280 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1281 long nData = lcl_TOXTypesToUserData(aCurType);
1282 aTypeLB.SelectEntryPos(aTypeLB.GetEntryPos((void*)nData));
1284 sAutoMarkURL = INetURLObject::decode( rSh.GetTOIAutoMarkURL(),
1285 INET_HEX_ESCAPE,
1286 INetURLObject::DECODE_UNAMBIGUOUS,
1287 RTL_TEXTENCODING_UTF8 );
1288 aFromFileCB.Check( 0 != sAutoMarkURL.Len() );
1290 aCaptionSequenceLB.Clear();
1291 sal_uInt16 i, nCount = rSh.GetFldTypeCount(RES_SETEXPFLD);
1292 for (i = 0; i < nCount; i++)
1294 SwFieldType *pType = rSh.GetFldType( i, RES_SETEXPFLD );
1295 if( pType->Which() == RES_SETEXPFLD &&
1296 ((SwSetExpFieldType *) pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
1297 aCaptionSequenceLB.InsertEntry(pType->GetName());
1300 if(pTOXDlg->IsTOXEditMode())
1302 aTypeFT.Enable(sal_False);
1303 aTypeLB.Enable(sal_False);
1305 TOXTypeHdl(&aTypeLB);
1306 CheckBoxHdl(&aAddStylesCB);
1309 void SwTOXSelectTabPage::ActivatePage( const SfxItemSet& )
1311 //nothing to do
1314 int SwTOXSelectTabPage::DeactivatePage( SfxItemSet* _pSet )
1316 if(_pSet)
1317 _pSet->Put(SfxUInt16Item(FN_PARAM_TOX_TYPE,
1318 (sal_uInt16)(long)aTypeLB.GetEntryData( aTypeLB.GetSelectEntryPos() )));
1319 FillTOXDescription();
1320 return LEAVE_PAGE;
1323 SfxTabPage* SwTOXSelectTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet)
1325 return new SwTOXSelectTabPage(pParent, rAttrSet);
1328 IMPL_LINK(SwTOXSelectTabPage, TOXTypeHdl, ListBox*, pBox)
1330 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
1331 if(!bFirstCall)
1333 // save current values into the proper TOXDescription
1334 FillTOXDescription();
1336 bFirstCall = sal_False;
1337 const sal_uInt16 nType = sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(
1338 pBox->GetEntryData( pBox->GetSelectEntryPos() )));
1339 CurTOXType eCurType = lcl_UserData2TOXTypes(nType);
1340 pTOXDlg->SetCurrentTOXType(eCurType);
1342 aAreaLB.Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1343 aLevelFT.Show( 0 != (nType & (TO_CONTENT)) );
1344 aLevelNF.Show( 0 != (nType & (TO_CONTENT)) );
1345 aLevelFromChapterCB.Show( 0 != (nType & (TO_USER)) );
1346 aAreaFT.Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1347 aAreaFL.Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
1349 aFromHeadingsCB.Show( 0 != (nType & (TO_CONTENT)) );
1350 aAddStylesCB.Show( 0 != (nType & (TO_CONTENT|TO_USER)) );
1351 aAddStylesPB.Show( 0 != (nType & (TO_CONTENT|TO_USER)) );
1353 aFromTablesCB.Show( 0 != (nType & (TO_USER)) );
1354 aFromFramesCB.Show( 0 != (nType & (TO_USER)) );
1355 aFromGraphicsCB.Show( 0 != (nType & (TO_USER)) );
1356 aFromOLECB.Show( 0 != (nType & (TO_USER)) );
1358 aFromCaptionsRB.Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1359 aFromObjectNamesRB.Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1361 aTOXMarksCB.Show( 0 != (nType & (TO_CONTENT|TO_USER)) );
1363 aCreateFromFL.Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_TABLE)) );
1364 aCaptionSequenceFT.Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1365 aCaptionSequenceLB.Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1366 aDisplayTypeFT.Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1367 aDisplayTypeLB.Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
1369 aSequenceCB.Show( 0 != (nType & TO_AUTHORITIES) );
1370 aBracketFT.Show( 0 != (nType & TO_AUTHORITIES) );
1371 aBracketLB.Show( 0 != (nType & TO_AUTHORITIES) );
1372 aAuthorityFormatFL.Show( 0 != (nType & TO_AUTHORITIES) );
1374 sal_Bool bEnableSortLanguage = 0 != (nType & (TO_INDEX|TO_AUTHORITIES));
1375 aSortOptionsFL.Show(bEnableSortLanguage);
1376 aLanguageFT.Show(bEnableSortLanguage);
1377 aLanguageLB.Show(bEnableSortLanguage);
1378 aSortAlgorithmFT.Show(bEnableSortLanguage);
1379 aSortAlgorithmLB.Show(bEnableSortLanguage);
1381 // initialize button positions
1383 //#i111993# add styles button has two different positions
1384 if( !aAddStylesPosDef.X() )
1386 aAddStylesPosDef = ( aAddStylesPB.GetPosPixel() );
1387 // move left!
1388 Point aPos(aAddStylesPosDef);
1389 aPos.X() -= 2 * aAddStylesPB.GetSizePixel().Width();
1390 aAddStylesPosUser = aPos;
1393 if( nType & TO_ILLUSTRATION ) //add by zhaojianwei
1394 aCaptionSequenceLB.SelectEntry( SwStyleNameMapper::GetUIName(
1395 RES_POOLCOLL_LABEL_ABB, aEmptyStr ));
1396 else if( nType & TO_TABLE )
1397 aCaptionSequenceLB.SelectEntry( SwStyleNameMapper::GetUIName(
1398 RES_POOLCOLL_LABEL_TABLE, aEmptyStr ));
1399 else if( nType & TO_USER )
1401 aAddStylesCB.SetText(sAddStyleUser);
1402 aAddStylesPB.SetPosPixel(aAddStylesPosUser);
1404 else if( nType & TO_CONTENT )
1406 aAddStylesPB.SetPosPixel(aAddStylesPosDef);
1409 aCollectSameCB.Show( 0 != (nType & TO_INDEX) );
1410 aUseFFCB.Show( 0 != (nType & TO_INDEX) );
1411 aUseDashCB.Show( 0 != (nType & TO_INDEX) );
1412 aCaseSensitiveCB.Show( 0 != (nType & TO_INDEX) );
1413 aInitialCapsCB.Show( 0 != (nType & TO_INDEX) );
1414 aKeyAsEntryCB.Show( 0 != (nType & TO_INDEX) );
1415 aFromFileCB.Show( 0 != (nType & TO_INDEX) );
1416 aAutoMarkPB.Show( 0 != (nType & TO_INDEX) );
1418 aIdxOptionsFL.Show( 0 != (nType & TO_INDEX) );
1420 //object index
1421 aFromObjCLB.Show( 0 != (nType & TO_OBJECT) );
1422 aFromObjFL.Show( 0 != (nType & TO_OBJECT) );
1424 //move controls
1425 aAddStylesCB.SetPosPixel(nType & TO_USER ? aCBLeftPos1 : aCBLeftPos2);
1426 Point aPBPos(aAddStylesPB.GetPosPixel());
1427 aPBPos.Y() = nType & TO_USER ? aCBLeftPos1.Y() : aCBLeftPos2.Y();
1428 aAddStylesPB.SetPosPixel(aPBPos);
1429 aTOXMarksCB.SetPosPixel(nType & TO_USER ? aCBLeftPos2 : aCBLeftPos3);
1430 //set control values from the proper TOXDescription
1432 ApplyTOXDescription();
1434 ModifyHdl(0);
1435 return 0;
1438 IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifyHdl)
1440 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
1441 if(pTOXDlg)
1443 FillTOXDescription();
1444 pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_SELECT);
1446 return 0;
1449 IMPL_LINK(SwTOXSelectTabPage, CheckBoxHdl, CheckBox*, pBox )
1451 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
1452 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
1453 if(TOX_CONTENT == aCurType.eType)
1455 //at least one of the three CheckBoxes must be checked
1456 if(!aAddStylesCB.IsChecked() && !aFromHeadingsCB.IsChecked() && !aTOXMarksCB.IsChecked())
1458 //TODO: InfoBox?
1459 pBox->Check(sal_True);
1461 aAddStylesPB.Enable(aAddStylesCB.IsChecked());
1463 if(TOX_USER == aCurType.eType)
1465 aAddStylesPB.Enable(aAddStylesCB.IsChecked());
1467 else if(TOX_INDEX == aCurType.eType)
1469 aAutoMarkPB.Enable(aFromFileCB.IsChecked());
1470 aUseFFCB.Enable(aCollectSameCB.IsChecked() && !aUseDashCB.IsChecked());
1471 aUseDashCB.Enable(aCollectSameCB.IsChecked() && !aUseFFCB.IsChecked());
1472 aCaseSensitiveCB.Enable(aCollectSameCB.IsChecked());
1474 ModifyHdl(0);
1475 return 0;
1478 IMPL_LINK_NOARG(SwTOXSelectTabPage, RadioButtonHdl)
1480 sal_Bool bEnable = aFromCaptionsRB.IsChecked();
1481 aCaptionSequenceFT.Enable(bEnable);
1482 aCaptionSequenceLB.Enable(bEnable);
1483 aDisplayTypeFT.Enable(bEnable);
1484 aDisplayTypeLB.Enable(bEnable);
1485 ModifyHdl(0);
1486 return 0;
1489 IMPL_LINK(SwTOXSelectTabPage, LanguageHdl, ListBox*, pBox)
1491 lang::Locale aLcl( LanguageTag( aLanguageLB.GetSelectLanguage() ).getLocale() );
1492 Sequence< OUString > aSeq = pIndexEntryWrapper->GetAlgorithmList( aLcl );
1494 if( !pIndexRes )
1495 pIndexRes = new IndexEntryResource();
1497 String sOldString;
1498 void* pUserData;
1499 if( 0 != (pUserData = aSortAlgorithmLB.GetEntryData( aSortAlgorithmLB.GetSelectEntryPos())) )
1500 sOldString = *(String*)pUserData;
1501 void* pDel;
1502 sal_uInt16 nEnd = aSortAlgorithmLB.GetEntryCount();
1503 for( sal_uInt16 n = 0; n < nEnd; ++n )
1504 if( 0 != ( pDel = aSortAlgorithmLB.GetEntryData( n )) )
1505 delete (String*)pDel;
1506 aSortAlgorithmLB.Clear();
1508 sal_uInt16 nInsPos;
1509 String sAlg, sUINm;
1510 nEnd = static_cast< sal_uInt16 >(aSeq.getLength());
1511 for( sal_uInt16 nCnt = 0; nCnt < nEnd; ++nCnt )
1513 sUINm = pIndexRes->GetTranslation( sAlg = aSeq[ nCnt ] );
1514 nInsPos = aSortAlgorithmLB.InsertEntry( sUINm );
1515 aSortAlgorithmLB.SetEntryData( nInsPos, new String( sAlg ));
1516 if( sAlg == sOldString )
1517 aSortAlgorithmLB.SelectEntryPos( nInsPos );
1520 if( LISTBOX_ENTRY_NOTFOUND == aSortAlgorithmLB.GetSelectEntryPos() )
1521 aSortAlgorithmLB.SelectEntryPos( 0 );
1523 if(pBox)
1524 ModifyHdl(0);
1525 return 0;
1528 IMPL_LINK(SwTOXSelectTabPage, AddStylesHdl, PushButton*, pButton)
1530 SwAddStylesDlg_Impl* pDlg = new SwAddStylesDlg_Impl(pButton,
1531 ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell(),
1532 aStyleArr);
1533 pDlg->Execute();
1534 delete pDlg;
1535 ModifyHdl(0);
1536 return 0;
1539 IMPL_LINK(SwTOXSelectTabPage, MenuEnableHdl, Menu*, pMenu)
1541 pMenu->EnableItem(MN_AUTOMARK_EDIT, sAutoMarkURL.Len() > 0);
1542 return 0;
1545 IMPL_LINK(SwTOXSelectTabPage, MenuExecuteHdl, Menu*, pMenu)
1547 const String sSaveAutoMarkURL = sAutoMarkURL;
1548 switch(pMenu->GetCurItemId())
1550 case MN_AUTOMARK_OPEN:
1551 sAutoMarkURL = lcl_CreateAutoMarkFileDlg(
1552 sAutoMarkURL, sAutoMarkType, true);
1553 break;
1554 case MN_AUTOMARK_NEW :
1555 sAutoMarkURL = lcl_CreateAutoMarkFileDlg(
1556 sAutoMarkURL, sAutoMarkType, false);
1557 if( !sAutoMarkURL.Len() )
1558 break;
1559 //no break
1560 case MN_AUTOMARK_EDIT:
1562 bool bNew = pMenu->GetCurItemId()== MN_AUTOMARK_NEW;
1563 SwAutoMarkDlg_Impl* pAutoMarkDlg = new SwAutoMarkDlg_Impl(
1564 &aAutoMarkPB, sAutoMarkURL, sAutoMarkType, bNew );
1566 if( RET_OK != pAutoMarkDlg->Execute() && bNew )
1567 sAutoMarkURL = sSaveAutoMarkURL;
1568 delete pAutoMarkDlg;
1571 break;
1573 return 0;
1576 class SwTOXEdit : public Edit
1578 SwFormToken aFormToken;
1579 Link aPrevNextControlLink;
1580 bool bNextControl;
1581 SwTokenWindow* m_pParent;
1582 public:
1583 SwTOXEdit( Window* pParent, SwTokenWindow* pTokenWin,
1584 const SwFormToken& aToken)
1585 : Edit( pParent, WB_BORDER|WB_TABSTOP|WB_CENTER),
1586 aFormToken(aToken),
1587 bNextControl(false),
1588 m_pParent( pTokenWin )
1590 SetHelpId( HID_TOX_ENTRY_EDIT );
1593 virtual void KeyInput( const KeyEvent& rKEvt );
1594 virtual void RequestHelp( const HelpEvent& rHEvt );
1596 bool IsNextControl() const {return bNextControl;}
1597 void SetPrevNextLink( const Link& rLink ) {aPrevNextControlLink = rLink;}
1599 const SwFormToken& GetFormToken()
1601 aFormToken.sText = GetText();
1602 return aFormToken;
1605 void SetCharStyleName(const String& rSet, sal_uInt16 nPoolId)
1607 aFormToken.sCharStyleName = rSet;
1608 aFormToken.nPoolId = nPoolId;
1611 void AdjustSize();
1614 void SwTOXEdit::RequestHelp( const HelpEvent& rHEvt )
1616 if(!m_pParent->CreateQuickHelp(this, aFormToken, rHEvt))
1617 Edit::RequestHelp(rHEvt);
1620 void SwTOXEdit::KeyInput( const KeyEvent& rKEvt )
1622 const Selection& rSel = GetSelection();
1623 sal_Int32 nTextLen = GetText().getLength();
1624 if((rSel.A() == rSel.B() &&
1625 !rSel.A()) || rSel.A() == (sal_uInt16)nTextLen )
1627 bool bCall = false;
1628 KeyCode aCode = rKEvt.GetKeyCode();
1629 if(aCode.GetCode() == KEY_RIGHT && rSel.A() == nTextLen)
1631 bNextControl = true;
1632 bCall = true;
1634 else if(aCode.GetCode() == KEY_LEFT && !rSel.A() )
1636 bNextControl = false;
1637 bCall = true;
1640 if(bCall && aPrevNextControlLink.IsSet())
1641 aPrevNextControlLink.Call(this);
1644 Edit::KeyInput(rKEvt);
1647 void SwTOXEdit::AdjustSize()
1649 Size aSize(GetSizePixel());
1650 Size aTextSize(GetTextWidth(GetText()), GetTextHeight());
1651 aTextSize = LogicToPixel(aTextSize);
1652 aSize.Width() = aTextSize.Width() + EDIT_MINWIDTH;
1653 SetSizePixel(aSize);
1656 class SwTOXButton : public PushButton
1658 SwFormToken aFormToken;
1659 Link aPrevNextControlLink;
1660 bool bNextControl;
1661 SwTokenWindow* m_pParent;
1662 public:
1663 SwTOXButton( Window* pParent, SwTokenWindow* pTokenWin,
1664 const SwFormToken& rToken)
1665 : PushButton(pParent, WB_BORDER|WB_TABSTOP),
1666 aFormToken(rToken),
1667 bNextControl(false),
1668 m_pParent(pTokenWin)
1670 SetHelpId(HID_TOX_ENTRY_BUTTON);
1673 virtual void KeyInput( const KeyEvent& rKEvt );
1674 virtual void RequestHelp( const HelpEvent& rHEvt );
1676 bool IsNextControl() const {return bNextControl;}
1677 void SetPrevNextLink(const Link& rLink) {aPrevNextControlLink = rLink;}
1678 const SwFormToken& GetFormToken() const {return aFormToken;}
1680 void SetCharStyleName(const String& rSet, sal_uInt16 nPoolId)
1682 aFormToken.sCharStyleName = rSet;
1683 aFormToken.nPoolId = nPoolId;
1686 void SetTabPosition(SwTwips nSet)
1687 { aFormToken.nTabStopPosition = nSet; }
1689 void SetFillChar( sal_Unicode cSet )
1690 { aFormToken.cTabFillChar = cSet; }
1692 void SetTabAlign(SvxTabAdjust eAlign)
1693 { aFormToken.eTabAlign = eAlign;}
1695 //---> i89791
1696 //used for entry number format, in TOC only
1697 //needed for different UI dialog position
1698 void SetEntryNumberFormat(sal_uInt16 nSet) {
1699 switch(nSet)
1701 default:
1702 case 0:
1703 aFormToken.nChapterFormat = CF_NUMBER;
1704 break;
1705 case 1:
1706 aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
1707 break;
1711 void SetChapterInfo(sal_uInt16 nSet) {
1712 switch(nSet)
1714 default:
1715 case 0:
1716 aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
1717 break;
1718 case 1:
1719 aFormToken.nChapterFormat = CF_TITLE;
1720 break;
1721 case 2:
1722 aFormToken.nChapterFormat = CF_NUMBER_NOPREPST;
1723 break;
1726 sal_uInt16 GetChapterInfo() const{ return aFormToken.nChapterFormat;}
1728 void SetOutlineLevel( sal_uInt16 nSet ) { aFormToken.nOutlineLevel = nSet;}//i53420
1729 sal_uInt16 GetOutlineLevel() const{ return aFormToken.nOutlineLevel;}
1731 void SetLinkEnd()
1733 OSL_ENSURE(TOKEN_LINK_START == aFormToken.eTokenType,
1734 "call SetLinkEnd for link start only!");
1735 aFormToken.eTokenType = TOKEN_LINK_END;
1736 aFormToken.sText.AssignAscii(SwForm::aFormLinkEnd);
1737 SetText(aFormToken.sText);
1739 void SetLinkStart()
1741 OSL_ENSURE(TOKEN_LINK_END == aFormToken.eTokenType,
1742 "call SetLinkStart for link start only!");
1743 aFormToken.eTokenType = TOKEN_LINK_START;
1744 aFormToken.sText.AssignAscii(SwForm::aFormLinkStt);
1745 SetText(aFormToken.sText);
1749 void SwTOXButton::KeyInput( const KeyEvent& rKEvt )
1751 bool bCall = false;
1752 KeyCode aCode = rKEvt.GetKeyCode();
1753 if(aCode.GetCode() == KEY_RIGHT)
1755 bNextControl = true;
1756 bCall = true;
1758 else if(aCode.GetCode() == KEY_LEFT )
1760 bNextControl = false;
1761 bCall = true;
1763 else if(aCode.GetCode() == KEY_DELETE)
1765 m_pParent->RemoveControl(this, sal_True);
1766 //this is invalid here
1767 return;
1769 if(bCall && aPrevNextControlLink.IsSet())
1770 aPrevNextControlLink.Call(this);
1771 else
1772 PushButton::KeyInput(rKEvt);
1775 void SwTOXButton::RequestHelp( const HelpEvent& rHEvt )
1777 if(!m_pParent->CreateQuickHelp(this, aFormToken, rHEvt))
1778 Button::RequestHelp(rHEvt);
1781 SwIdxTreeListBox::SwIdxTreeListBox(SwTOXEntryTabPage* pPar, const ResId& rResId) :
1782 SvTreeListBox(pPar, rResId),
1783 pParent(pPar)
1787 void SwIdxTreeListBox::RequestHelp( const HelpEvent& rHEvt )
1789 if( rHEvt.GetMode() & HELPMODE_QUICK )
1791 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
1792 SvTreeListEntry* pEntry = GetEntry( aPos );
1793 if( pEntry )
1795 sal_uInt16 nLevel = static_cast< sal_uInt16 >(GetModel()->GetAbsPos(pEntry));
1796 String sEntry = pParent->GetLevelHelp(++nLevel);
1797 if (comphelper::string::equals(sEntry, '*'))
1798 sEntry = GetEntryText(pEntry);
1799 if(sEntry.Len())
1801 SvLBoxTab* pTab;
1802 SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
1803 if (pItem && SV_ITEM_ID_LBOXSTRING == pItem->GetType())
1805 aPos = GetEntryPosition( pEntry );
1807 aPos.X() = GetTabPos( pEntry, pTab );
1808 Size aSize( pItem->GetSize( this, pEntry ) );
1810 if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
1811 aSize.Width() = GetSizePixel().Width() - aPos.X();
1813 aPos = OutputToScreenPixel(aPos);
1814 Rectangle aItemRect( aPos, aSize );
1815 Help::ShowQuickHelp( this, aItemRect, sEntry,
1816 QUICKHELP_LEFT|QUICKHELP_VCENTER );
1821 else
1822 SvTreeListBox::RequestHelp(rHEvt);
1825 SwTOXEntryTabPage::SwTOXEntryTabPage(Window* pParent, const SfxItemSet& rAttrSet) :
1826 SfxTabPage(pParent, SW_RES(TP_TOX_ENTRY), rAttrSet),
1827 aLevelFT(this, SW_RES(FT_LEVEL )),
1828 aLevelLB(this, SW_RES(LB_LEVEL )),
1829 aEntryFL(this, SW_RES(FL_ENTRY )),
1831 aTokenFT(this, SW_RES(FT_TOKEN )),
1832 aTokenWIN(this, SW_RES(WIN_TOKEN )),
1833 aAllLevelsPB(this, SW_RES(PB_ALL_LEVELS )),
1835 aEntryNoPB(this, SW_RES(PB_ENTRYNO )),
1836 aEntryPB(this, SW_RES(PB_ENTRY )),
1837 aTabPB(this, SW_RES(PB_TAB )),
1838 aChapterInfoPB(this, SW_RES(PB_CHAPTERINFO )),
1839 aPageNoPB(this, SW_RES(PB_PAGENO )),
1840 aHyperLinkPB(this, SW_RES(PB_HYPERLINK )),
1842 aAuthFieldsLB(this, SW_RES(LB_AUTHFIELD )),
1843 aAuthInsertPB(this, SW_RES(PB_AUTHINSERT )),
1844 aAuthRemovePB(this, SW_RES(PB_AUTHREMOVE )),
1846 aCharStyleFT(this, SW_RES(FT_CHARSTYLE )),
1847 aCharStyleLB(this, SW_RES(LB_CHARSTYLE )),
1848 aEditStylePB(this, SW_RES(PB_EDITSTYLE )),
1850 aChapterEntryFT(this, SW_RES(FT_CHAPTERENTRY )),
1851 aChapterEntryLB(this, SW_RES(LB_CHAPTERENTRY )),
1853 aNumberFormatFT(this, SW_RES(FT_ENTRY_NO )),//i53420
1854 aNumberFormatLB(this, SW_RES(LB_ENTRY_NO )),
1855 aEntryOutlineLevelFT(this, SW_RES(FT_LEVEL_OL )),//i53420
1856 aEntryOutlineLevelNF(this, SW_RES(NF_LEVEL_OL )),
1858 aFillCharFT(this, SW_RES(FT_FILLCHAR )),
1859 aFillCharCB(this, SW_RES(CB_FILLCHAR )),
1860 aTabPosFT(this, SW_RES(FT_TABPOS )),
1861 aTabPosMF(this, SW_RES(MF_TABPOS )),
1862 aAutoRightCB(this, SW_RES(CB_AUTORIGHT )),
1863 aFormatFL(this, SW_RES(FL_FORMAT )),
1866 aRelToStyleCB(this, SW_RES(CB_RELTOSTYLE )),
1867 aMainEntryStyleFT(this, SW_RES(FT_MAIN_ENTRY_STYLE)),
1868 aMainEntryStyleLB(this, SW_RES(LB_MAIN_ENTRY_STYLE)),
1869 aAlphaDelimCB(this, SW_RES(CB_ALPHADELIM )),
1870 aCommaSeparatedCB(this, SW_RES(CB_COMMASEPARATED )),
1872 aSortDocPosRB(this, SW_RES(RB_DOCPOS )),
1873 aSortContentRB(this, SW_RES(RB_SORTCONTENT )),
1874 aSortingFL(this, SW_RES(FL_SORTING )),
1876 aFirstKeyFT(this, SW_RES(FT_FIRSTKEY )),
1877 aFirstKeyLB(this, SW_RES(LB_FIRSTKEY )),
1878 aFirstSortUpRB(this, SW_RES(RB_SORTUP1 )),
1879 aFirstSortDownRB(this, SW_RES(RB_SORTDOWN1 )),
1881 aSecondKeyFT(this, SW_RES(FT_SECONDKEY )),
1882 aSecondKeyLB(this, SW_RES(LB_SECONDKEY )),
1883 aSecondSortUpRB(this, SW_RES(RB_SORTUP2 )),
1884 aSecondSortDownRB(this, SW_RES(RB_SORTDOWN2 )),
1886 aThirdKeyFT(this, SW_RES(FT_THIRDDKEY )),
1887 aThirdKeyLB(this, SW_RES(LB_THIRDKEY )),
1888 aThirdSortUpRB(this, SW_RES(RB_SORTUP3 )),
1889 aThirdSortDownRB(this, SW_RES(RB_SORTDOWN3 )),
1891 aSortKeyFL(this, SW_RES(FL_SORTKEY )),
1893 sDelimStr( SW_RES(STR_DELIM)),
1894 sAuthTypeStr( SW_RES(ST_AUTHTYPE)),
1896 sNoCharStyle( SW_RES(STR_NO_CHAR_STYLE)),
1897 sNoCharSortKey( SW_RES(STR_NOSORTKEY )),
1898 m_pCurrentForm(0),
1899 bInLevelHdl(sal_False)
1901 aEditStylePB.SetAccessibleRelationMemberOf(&aEntryFL);
1902 aHyperLinkPB.SetAccessibleRelationMemberOf(&aEntryFL);
1903 aPageNoPB.SetAccessibleRelationMemberOf(&aEntryFL);
1904 aTabPB.SetAccessibleRelationMemberOf(&aEntryFL);
1905 aEntryPB.SetAccessibleRelationMemberOf(&aEntryFL);
1906 aEntryNoPB.SetAccessibleRelationMemberOf(&aEntryFL);
1907 aAllLevelsPB.SetAccessibleRelationMemberOf(&aEntryFL);
1908 aTokenWIN.SetAccessibleRelationMemberOf(&aEntryFL);
1909 aTokenWIN.SetAccessibleRelationLabeledBy(&aTokenFT);
1911 FreeResource();
1913 sLevelStr = aLevelFT.GetText();
1914 aLevelLB.SetStyle( aLevelLB.GetStyle() | WB_HSCROLL );
1915 aLevelLB.SetSpaceBetweenEntries(0);
1916 aLevelLB.SetSelectionMode( SINGLE_SELECTION );
1917 aLevelLB.SetHighlightRange(); // select full width
1918 aLevelLB.SetHelpId(HID_INSERT_INDEX_ENTRY_LEVEL_LB);
1919 aLevelLB.Show();
1921 aLastTOXType.eType = (TOXTypes)USHRT_MAX;
1922 aLastTOXType.nIndex = 0;
1923 aLevelFLSize = aLevelFT.GetSizePixel();
1925 SetExchangeSupport();
1926 aEntryNoPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1927 aEntryPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1928 aChapterInfoPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1929 aPageNoPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1930 aTabPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1931 aHyperLinkPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
1932 aEditStylePB.SetClickHdl(LINK(this, SwTOXEntryTabPage, EditStyleHdl));
1933 aLevelLB.SetSelectHdl(LINK(this, SwTOXEntryTabPage, LevelHdl));
1934 aTokenWIN.SetButtonSelectedHdl(LINK(this, SwTOXEntryTabPage, TokenSelectedHdl));
1935 aTokenWIN.SetModifyHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
1936 aCharStyleLB.SetSelectHdl(LINK(this, SwTOXEntryTabPage, StyleSelectHdl));
1937 aCharStyleLB.InsertEntry(sNoCharStyle);
1938 aChapterEntryLB.SetSelectHdl(LINK(this, SwTOXEntryTabPage, ChapterInfoHdl));
1939 aEntryOutlineLevelNF.SetModifyHdl(LINK(this, SwTOXEntryTabPage, ChapterInfoOutlineHdl));
1940 aNumberFormatLB.SetSelectHdl(LINK(this, SwTOXEntryTabPage, NumberFormatHdl));
1942 aTabPosMF.SetModifyHdl(LINK(this, SwTOXEntryTabPage, TabPosHdl));
1943 aFillCharCB.SetModifyHdl(LINK(this, SwTOXEntryTabPage, FillCharHdl));
1944 aAutoRightCB.SetClickHdl(LINK(this, SwTOXEntryTabPage, AutoRightHdl));
1945 aAuthInsertPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
1946 aAuthRemovePB.SetClickHdl(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
1947 aSortDocPosRB.SetClickHdl(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
1948 aSortContentRB.SetClickHdl(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
1949 aAllLevelsPB.SetClickHdl(LINK(this, SwTOXEntryTabPage, AllLevelsHdl));
1951 aAlphaDelimCB.SetClickHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
1952 aCommaSeparatedCB.SetClickHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
1953 aRelToStyleCB.SetClickHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
1955 FieldUnit aMetric = ::GetDfltMetric(sal_False);
1956 SetMetric(aTabPosMF, aMetric);
1958 aSortDocPosRB.Check();
1960 aFillCharCB.SetMaxTextLen(1);
1961 aFillCharCB.InsertEntry(OUString(' '));
1962 aFillCharCB.InsertEntry(OUString('.'));
1963 aFillCharCB.InsertEntry(OUString('-'));
1964 aFillCharCB.InsertEntry(OUString('_'));
1966 aButtonPositions[0] = aEntryNoPB.GetPosPixel();
1967 aButtonPositions[1] = aEntryPB.GetPosPixel();
1968 aButtonPositions[2] = aChapterInfoPB.GetPosPixel();
1969 aButtonPositions[3] = aPageNoPB.GetPosPixel();
1970 aButtonPositions[4] = aTabPB.GetPosPixel();
1972 aRelToStylePos = aRelToStyleCB.GetPosPixel();
1973 aRelToStyleIdxPos = aCommaSeparatedCB.GetPosPixel();
1974 aRelToStyleIdxPos.Y() +=
1975 (aRelToStyleIdxPos.Y() - aAlphaDelimCB.GetPosPixel().Y());
1976 aEditStylePB.Enable(sal_False);
1978 //get position for Numbering and other stuff
1979 aChapterEntryFTPosition = aChapterEntryFT.GetPosPixel();
1980 aEntryOutlineLevelFTPosition = aEntryOutlineLevelFT.GetPosPixel();
1981 nBiasToEntryPoint = aEntryOutlineLevelNF.GetPosPixel().X() -
1982 aEntryOutlineLevelFT.GetPosPixel().X();
1984 //fill the types in
1985 sal_uInt16 i;
1986 for( i = 0; i < AUTH_FIELD_END; i++)
1988 String sTmp(SW_RES(STR_AUTH_FIELD_START + i));
1989 sal_uInt16 nPos = aAuthFieldsLB.InsertEntry(sTmp);
1990 aAuthFieldsLB.SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(i)));
1992 sal_uInt16 nPos = aFirstKeyLB.InsertEntry(sNoCharSortKey);
1993 aFirstKeyLB.SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(USHRT_MAX)));
1994 nPos = aSecondKeyLB.InsertEntry(sNoCharSortKey);
1995 aSecondKeyLB.SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(USHRT_MAX)));
1996 nPos = aThirdKeyLB.InsertEntry(sNoCharSortKey);
1997 aThirdKeyLB.SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(USHRT_MAX)));
1999 for( i = 0; i < AUTH_FIELD_END; i++)
2001 String sTmp(aAuthFieldsLB.GetEntry(i));
2002 void* pEntryData = aAuthFieldsLB.GetEntryData(i);
2003 nPos = aFirstKeyLB.InsertEntry(sTmp);
2004 aFirstKeyLB.SetEntryData(nPos, pEntryData);
2005 nPos = aSecondKeyLB.InsertEntry(sTmp);
2006 aSecondKeyLB.SetEntryData(nPos, pEntryData);
2007 nPos = aThirdKeyLB.InsertEntry(sTmp);
2008 aThirdKeyLB.SetEntryData(nPos, pEntryData);
2010 aFirstKeyLB.SelectEntryPos(0);
2011 aSecondKeyLB.SelectEntryPos(0);
2012 aThirdKeyLB.SelectEntryPos(0);
2014 /* --------------------------------------------------
2015 pVoid is used as signal to change all levels of the example
2016 --------------------------------------------------*/
2017 IMPL_LINK(SwTOXEntryTabPage, ModifyHdl, void*, pVoid)
2019 UpdateDescriptor();
2020 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
2022 if(pTOXDlg)
2024 sal_uInt16 nCurLevel = static_cast< sal_uInt16 >(aLevelLB.GetModel()->GetAbsPos(aLevelLB.FirstSelected()) + 1);
2025 if(aLastTOXType.eType == TOX_CONTENT && pVoid)
2026 nCurLevel = USHRT_MAX;
2027 pTOXDlg->CreateOrUpdateExample(
2028 pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_ENTRY, nCurLevel);
2030 return 0;
2033 SwTOXEntryTabPage::~SwTOXEntryTabPage()
2037 sal_Bool SwTOXEntryTabPage::FillItemSet( SfxItemSet& )
2039 // nothing to do
2040 return sal_True;
2043 void SwTOXEntryTabPage::Reset( const SfxItemSet& )
2045 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
2046 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
2047 m_pCurrentForm = pTOXDlg->GetForm(aCurType);
2048 if(TOX_INDEX == aCurType.eType)
2050 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
2051 String sMainEntryCharStyle = rDesc.GetMainEntryCharStyle();
2052 if(sMainEntryCharStyle.Len())
2054 if( LISTBOX_ENTRY_NOTFOUND ==
2055 aMainEntryStyleLB.GetEntryPos(sMainEntryCharStyle))
2056 aMainEntryStyleLB.InsertEntry(
2057 sMainEntryCharStyle);
2058 aMainEntryStyleLB.SelectEntry(sMainEntryCharStyle);
2060 else
2061 aMainEntryStyleLB.SelectEntry(sNoCharStyle);
2062 aAlphaDelimCB.Check( 0 != (rDesc.GetIndexOptions() & nsSwTOIOptions::TOI_ALPHA_DELIMITTER) );
2064 aRelToStyleCB.Check(m_pCurrentForm->IsRelTabPos());
2065 aCommaSeparatedCB.Check(m_pCurrentForm->IsCommaSeparated());
2068 static void lcl_ChgWidth(Window& rWin, long nDiff)
2070 Size aTempSz(rWin.GetSizePixel());
2071 aTempSz.Width() += nDiff;
2072 rWin.SetSizePixel(aTempSz);
2075 static void lcl_ChgXPos(Window& rWin, long nDiff)
2077 Point aTempPos(rWin.GetPosPixel());
2078 aTempPos.X() += nDiff;
2079 rWin.SetPosPixel(aTempPos);
2082 void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& /*rSet*/)
2084 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
2085 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
2087 m_pCurrentForm = pTOXDlg->GetForm(aCurType);
2088 if( !( aLastTOXType == aCurType ))
2090 sal_Bool bToxIsAuthorities = TOX_AUTHORITIES == aCurType.eType;
2091 sal_Bool bToxIsIndex = TOX_INDEX == aCurType.eType;
2092 sal_Bool bToxIsContent = TOX_CONTENT == aCurType.eType;
2093 sal_Bool bToxIsSequence = TOX_ILLUSTRATIONS == aCurType.eType;
2095 aLevelLB.Clear();
2096 for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
2098 if(bToxIsAuthorities)
2099 aLevelLB.InsertEntry( SwAuthorityFieldType::GetAuthTypeName(
2100 (ToxAuthorityType) (i - 1)) );
2101 else if( bToxIsIndex )
2103 if(i == 1)
2104 aLevelLB.InsertEntry( sDelimStr );
2105 else
2106 aLevelLB.InsertEntry( OUString::number(i - 1) );
2108 else
2109 aLevelLB.InsertEntry(OUString::number(i));
2111 if(bToxIsAuthorities)
2114 SwWrtShell& rSh = pTOXDlg->GetWrtShell();
2115 const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
2116 rSh.GetFldType(RES_AUTHORITY, aEmptyStr);
2117 if(pFType)
2119 if(pFType->IsSortByDocument())
2120 aSortDocPosRB.Check();
2121 else
2123 aSortContentRB.Check();
2124 sal_uInt16 nKeyCount = pFType->GetSortKeyCount();
2125 if(0 < nKeyCount)
2127 const SwTOXSortKey* pKey = pFType->GetSortKey(0);
2128 aFirstKeyLB.SelectEntryPos(
2129 aFirstKeyLB.GetEntryPos((void*)(sal_uIntPtr)pKey->eField));
2130 aFirstSortUpRB.Check(pKey->bSortAscending);
2131 aFirstSortDownRB.Check(!pKey->bSortAscending);
2133 if(1 < nKeyCount)
2135 const SwTOXSortKey* pKey = pFType->GetSortKey(1);
2136 aSecondKeyLB.SelectEntryPos(
2137 aSecondKeyLB.GetEntryPos((void*)(sal_uIntPtr)pKey->eField));
2138 aSecondSortUpRB.Check(pKey->bSortAscending);
2139 aSecondSortDownRB.Check(!pKey->bSortAscending);
2141 if(2 < nKeyCount)
2143 const SwTOXSortKey* pKey = pFType->GetSortKey(2);
2144 aThirdKeyLB.SelectEntryPos(
2145 aThirdKeyLB.GetEntryPos((void*)(sal_uIntPtr)pKey->eField));
2146 aThirdSortUpRB.Check(pKey->bSortAscending);
2147 aThirdSortDownRB.Check(!pKey->bSortAscending);
2151 SortKeyHdl(aSortDocPosRB.IsChecked() ? &aSortDocPosRB : &aSortContentRB);
2152 aLevelFT.SetText(sAuthTypeStr);
2154 else
2155 aLevelFT.SetText(sLevelStr);
2157 long nDiff = 0;
2158 if( bToxIsAuthorities ? aLevelFT.GetSizePixel() == aLevelFLSize
2159 : aLevelFT.GetSizePixel() != aLevelFLSize )
2161 nDiff = aLevelFLSize.Width();
2162 if( !bToxIsAuthorities )
2163 nDiff *= -1;
2166 if(nDiff)
2168 lcl_ChgWidth(aLevelFT, nDiff);
2169 lcl_ChgWidth(aLevelLB, nDiff);
2170 lcl_ChgXPos(aCharStyleFT, nDiff);
2171 lcl_ChgXPos(aCharStyleLB, nDiff);
2172 lcl_ChgWidth(aCharStyleLB, -nDiff);
2173 lcl_ChgXPos(aFillCharFT, nDiff);
2174 lcl_ChgXPos(aFillCharCB, nDiff);
2175 lcl_ChgXPos(aTabPosFT, nDiff);
2176 lcl_ChgXPos(aTabPosMF, nDiff);
2177 lcl_ChgXPos(aAutoRightCB, nDiff);
2178 lcl_ChgXPos(aAuthFieldsLB, nDiff);
2179 lcl_ChgXPos(aAuthInsertPB, nDiff);
2180 lcl_ChgXPos(aAuthRemovePB, nDiff);
2181 lcl_ChgXPos(aTokenFT, nDiff);
2182 lcl_ChgXPos(aTokenWIN, nDiff);
2183 lcl_ChgWidth(aTokenWIN, -nDiff);
2184 lcl_ChgXPos(aSortDocPosRB, nDiff);
2185 lcl_ChgXPos(aSortContentRB, nDiff);
2186 lcl_ChgXPos(aFormatFL, nDiff);
2187 lcl_ChgWidth(aFormatFL, -nDiff);
2188 lcl_ChgXPos(aSortingFL, nDiff);
2189 lcl_ChgWidth(aSortingFL, -nDiff);
2190 lcl_ChgXPos(aEntryFL, nDiff);
2191 lcl_ChgWidth(aEntryFL, -nDiff);
2193 lcl_ChgXPos(aFirstKeyFT, nDiff);
2194 lcl_ChgXPos(aFirstKeyLB, nDiff);
2195 lcl_ChgXPos(aSecondKeyFT, nDiff);
2196 lcl_ChgXPos(aSecondKeyLB, nDiff);
2197 lcl_ChgXPos(aThirdKeyFT, nDiff);
2198 lcl_ChgXPos(aThirdKeyLB, nDiff);
2199 lcl_ChgXPos(aSortKeyFL, nDiff);
2201 lcl_ChgWidth(aFirstKeyLB, -nDiff);
2202 lcl_ChgWidth(aSecondKeyLB, -nDiff);
2203 lcl_ChgWidth(aThirdKeyLB, -nDiff);
2204 lcl_ChgWidth(aSortKeyFL, -nDiff);
2206 Link aLink = aLevelLB.GetSelectHdl();
2207 aLevelLB.SetSelectHdl(Link());
2208 aLevelLB.Select( aLevelLB.GetEntry( bToxIsIndex ? 1 : 0 ) );
2209 aLevelLB.SetSelectHdl(aLink);
2211 // sort token buttons
2212 aEntryNoPB.SetPosPixel(aButtonPositions[0]);
2213 aEntryPB.SetPosPixel(aButtonPositions[ bToxIsContent ? 1 : 0]);
2214 aChapterInfoPB.SetPosPixel(aButtonPositions[2]);
2215 aPageNoPB.SetPosPixel(aButtonPositions[3]);
2216 sal_uInt16 nBtPos = 1;
2217 if( bToxIsContent )
2218 nBtPos = 2;
2219 else if( bToxIsAuthorities )
2220 nBtPos = 4;
2221 aTabPB.SetPosPixel(aButtonPositions[nBtPos]);
2222 aHyperLinkPB.SetPosPixel(aButtonPositions[4]);
2224 //show or hide controls
2225 aEntryNoPB.Show( bToxIsContent );
2226 aHyperLinkPB.Show( bToxIsContent || bToxIsSequence );
2227 aRelToStyleCB.Show( !bToxIsAuthorities );
2228 aChapterInfoPB.Show( !bToxIsContent && !bToxIsAuthorities);
2229 aEntryPB.Show( !bToxIsAuthorities );
2230 aPageNoPB.Show( !bToxIsAuthorities );
2231 aAuthFieldsLB.Show( bToxIsAuthorities );
2232 aAuthInsertPB.Show( bToxIsAuthorities );
2233 aAuthRemovePB.Show( bToxIsAuthorities );
2234 aFormatFL.Show( !bToxIsAuthorities );
2235 aSortDocPosRB.Show( bToxIsAuthorities );
2236 aSortContentRB.Show( bToxIsAuthorities );
2237 aSortingFL.Show( bToxIsAuthorities );
2238 aFirstKeyFT.Show( bToxIsAuthorities );
2239 aFirstKeyLB.Show( bToxIsAuthorities );
2240 aSecondKeyFT.Show( bToxIsAuthorities );
2241 aSecondKeyLB.Show( bToxIsAuthorities );
2242 aThirdKeyFT.Show( bToxIsAuthorities );
2243 aThirdKeyLB.Show( bToxIsAuthorities );
2244 aSortKeyFL.Show( bToxIsAuthorities );
2245 aFirstSortUpRB.Show( bToxIsAuthorities );
2246 aFirstSortDownRB.Show( bToxIsAuthorities );
2247 aSecondSortUpRB.Show( bToxIsAuthorities );
2248 aSecondSortDownRB.Show( bToxIsAuthorities );
2249 aThirdSortUpRB.Show( bToxIsAuthorities );
2250 aThirdSortDownRB.Show( bToxIsAuthorities );
2252 aRelToStyleCB.SetPosPixel( bToxIsIndex ? aRelToStyleIdxPos
2253 : aRelToStylePos );
2255 aMainEntryStyleFT.Show( bToxIsIndex );
2256 aMainEntryStyleLB.Show( bToxIsIndex );
2257 aAlphaDelimCB.Show( bToxIsIndex );
2258 aCommaSeparatedCB.Show( bToxIsIndex );
2260 aLastTOXType = aCurType;
2262 //invalidate PatternWindow
2263 aTokenWIN.SetInvalid();
2264 LevelHdl(&aLevelLB);
2267 void SwTOXEntryTabPage::UpdateDescriptor()
2269 WriteBackLevel();
2270 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
2271 SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aLastTOXType);
2272 if(TOX_INDEX == aLastTOXType.eType)
2274 String sTemp(aMainEntryStyleLB.GetSelectEntry());
2275 rDesc.SetMainEntryCharStyle(sNoCharStyle == sTemp ? aEmptyStr : sTemp);
2276 sal_uInt16 nIdxOptions = rDesc.GetIndexOptions() & ~nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
2277 if(aAlphaDelimCB.IsChecked())
2278 nIdxOptions |= nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
2279 rDesc.SetIndexOptions(nIdxOptions);
2281 else if(TOX_AUTHORITIES == aLastTOXType.eType)
2283 rDesc.SetSortByDocument(aSortDocPosRB.IsChecked());
2284 SwTOXSortKey aKey1, aKey2, aKey3;
2285 aKey1.eField = (ToxAuthorityField)(sal_uIntPtr)aFirstKeyLB.GetEntryData(
2286 aFirstKeyLB.GetSelectEntryPos());
2287 aKey1.bSortAscending = aFirstSortUpRB.IsChecked();
2288 aKey2.eField = (ToxAuthorityField)(sal_uIntPtr)aSecondKeyLB.GetEntryData(
2289 aSecondKeyLB.GetSelectEntryPos());
2290 aKey2.bSortAscending = aSecondSortUpRB.IsChecked();
2291 aKey3.eField = (ToxAuthorityField)(sal_uIntPtr)aThirdKeyLB.GetEntryData(
2292 aThirdKeyLB.GetSelectEntryPos());
2293 aKey3.bSortAscending = aThirdSortUpRB.IsChecked();
2296 rDesc.SetSortKeys(aKey1, aKey2, aKey3);
2298 SwForm* pCurrentForm = pTOXDlg->GetForm(aLastTOXType);
2299 if(aRelToStyleCB.IsVisible())
2301 pCurrentForm->SetRelTabPos(aRelToStyleCB.IsChecked());
2303 if(aCommaSeparatedCB.IsVisible())
2304 pCurrentForm->SetCommaSeparated(aCommaSeparatedCB.IsChecked());
2307 int SwTOXEntryTabPage::DeactivatePage( SfxItemSet* /*pSet*/)
2309 UpdateDescriptor();
2310 return LEAVE_PAGE;
2313 SfxTabPage* SwTOXEntryTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet)
2315 return new SwTOXEntryTabPage(pParent, rAttrSet);
2318 IMPL_LINK(SwTOXEntryTabPage, EditStyleHdl, PushButton*, pBtn)
2320 if( LISTBOX_ENTRY_NOTFOUND != aCharStyleLB.GetSelectEntryPos())
2322 SfxStringItem aStyle(SID_STYLE_EDIT, aCharStyleLB.GetSelectEntry());
2323 SfxUInt16Item aFamily(SID_STYLE_FAMILY, SFX_STYLE_FAMILY_CHAR);
2324 // TODO: WrtShell?
2325 // SwPtrItem aShell(FN_PARAM_WRTSHELL, pWrtShell);
2326 Window* pDefDlgParent = Application::GetDefDialogParent();
2327 Application::SetDefDialogParent( pBtn );
2328 ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell().
2329 GetView().GetViewFrame()->GetDispatcher()->Execute(
2330 SID_STYLE_EDIT, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_MODAL,
2331 &aStyle, &aFamily/*, &aShell*/, 0L);
2332 Application::SetDefDialogParent( pDefDlgParent );
2334 return 0;
2337 IMPL_LINK(SwTOXEntryTabPage, RemoveInsertAuthHdl, PushButton*, pButton)
2339 bool bInsert = pButton == &aAuthInsertPB;
2340 if(bInsert)
2342 sal_uInt16 nSelPos = aAuthFieldsLB.GetSelectEntryPos();
2343 String sToInsert(aAuthFieldsLB.GetSelectEntry());
2344 SwFormToken aInsert(TOKEN_AUTHORITY);
2345 aInsert.nAuthorityField = (sal_uInt16)(sal_uIntPtr)aAuthFieldsLB.GetEntryData(nSelPos);
2346 aTokenWIN.InsertAtSelection(OUString::createFromAscii(
2347 SwForm::aFormAuth), aInsert);
2348 aAuthFieldsLB.RemoveEntry(sToInsert);
2349 aAuthFieldsLB.SelectEntryPos( nSelPos ? nSelPos - 1 : 0);
2351 else
2353 Control* pCtrl = aTokenWIN.GetActiveControl();
2354 OSL_ENSURE(WINDOW_EDIT != pCtrl->GetType(), "Remove should be disabled");
2355 if( WINDOW_EDIT != pCtrl->GetType() )
2357 //fill it into the ListBox
2358 const SwFormToken& rToken = ((SwTOXButton*)pCtrl)->GetFormToken();
2359 PreTokenButtonRemoved(rToken);
2360 aTokenWIN.RemoveControl((SwTOXButton*)pCtrl);
2363 ModifyHdl(0);
2364 return 0;
2367 void SwTOXEntryTabPage::PreTokenButtonRemoved(const SwFormToken& rToken)
2369 //fill it into the ListBox
2370 sal_uInt32 nData = rToken.nAuthorityField;
2371 String sTemp(SW_RES(STR_AUTH_FIELD_START + nData));
2372 sal_uInt16 nPos = aAuthFieldsLB.InsertEntry(sTemp);
2373 aAuthFieldsLB.SetEntryData(nPos, (void*)(sal_uIntPtr)(nData));
2375 /*-----------------------------------------------------------------------
2377 This function inizializes the default value in the Token
2378 put here the UI dependent initializations
2379 -----------------------------------------------------------------------*/
2380 IMPL_LINK(SwTOXEntryTabPage, InsertTokenHdl, PushButton*, pBtn)
2382 String sText;
2383 FormTokenType eTokenType = TOKEN_ENTRY_NO;
2384 String sCharStyle;
2385 sal_uInt16 nChapterFormat = CF_NUMBER; // i89791
2386 if(pBtn == &aEntryNoPB)
2388 sText.AssignAscii(SwForm::aFormEntryNum);
2389 eTokenType = TOKEN_ENTRY_NO;
2391 else if(pBtn == &aEntryPB)
2393 if( TOX_CONTENT == m_pCurrentForm->GetTOXType() )
2395 sText.AssignAscii( SwForm::aFormEntryTxt );
2396 eTokenType = TOKEN_ENTRY_TEXT;
2398 else
2400 sText.AssignAscii( SwForm::aFormEntry);
2401 eTokenType = TOKEN_ENTRY;
2404 else if(pBtn == &aChapterInfoPB)
2406 sText.AssignAscii( SwForm::aFormChapterMark);
2407 eTokenType = TOKEN_CHAPTER_INFO;
2408 nChapterFormat = CF_NUM_NOPREPST_TITLE; // i89791
2410 else if(pBtn == &aPageNoPB)
2412 sText.AssignAscii(SwForm::aFormPageNums);
2413 eTokenType = TOKEN_PAGE_NUMS;
2415 else if(pBtn == &aHyperLinkPB)
2417 sText.AssignAscii(SwForm::aFormLinkStt);
2418 eTokenType = TOKEN_LINK_START;
2419 sCharStyle = String(SW_RES(STR_POOLCHR_TOXJUMP));
2421 else if(pBtn == &aTabPB)
2423 sText.AssignAscii(SwForm::aFormTab);
2424 eTokenType = TOKEN_TAB_STOP;
2426 SwFormToken aInsert(eTokenType);
2427 aInsert.sCharStyleName = sCharStyle;
2428 aInsert.nTabStopPosition = 0;
2429 aInsert.nChapterFormat = nChapterFormat; // i89791
2430 aTokenWIN.InsertAtSelection(sText, aInsert);
2431 ModifyHdl(0);
2432 return 0;
2435 IMPL_LINK_NOARG(SwTOXEntryTabPage, AllLevelsHdl)
2437 //get current level
2438 //write it into all levels
2439 if(aTokenWIN.IsValid())
2441 String sNewToken = aTokenWIN.GetPattern();
2442 for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
2443 m_pCurrentForm->SetPattern(i, sNewToken);
2445 ModifyHdl(this);
2447 return 0;
2450 void SwTOXEntryTabPage::WriteBackLevel()
2452 if(aTokenWIN.IsValid())
2454 String sNewToken = aTokenWIN.GetPattern();
2455 sal_uInt16 nLastLevel = aTokenWIN.GetLastLevel();
2456 if(nLastLevel != USHRT_MAX)
2457 m_pCurrentForm->SetPattern(nLastLevel + 1, sNewToken );
2461 IMPL_LINK(SwTOXEntryTabPage, LevelHdl, SvTreeListBox*, pBox)
2463 if(bInLevelHdl)
2464 return 0;
2465 bInLevelHdl = sal_True;
2466 WriteBackLevel();
2468 sal_uInt16 nLevel = static_cast< sal_uInt16 >(pBox->GetModel()->GetAbsPos(pBox->FirstSelected()));
2469 aTokenWIN.SetForm(*m_pCurrentForm, nLevel);
2470 if(TOX_AUTHORITIES == m_pCurrentForm->GetTOXType())
2472 //fill the types in
2473 aAuthFieldsLB.Clear();
2474 for( sal_uInt32 i = 0; i < AUTH_FIELD_END; i++)
2476 String sTmp(SW_RES(STR_AUTH_FIELD_START + i));
2477 sal_uInt16 nPos = aAuthFieldsLB.InsertEntry(sTmp);
2478 aAuthFieldsLB.SetEntryData(nPos, (void*)(sal_uIntPtr)(i));
2481 // #i21237#
2482 SwFormTokens aPattern = m_pCurrentForm->GetPattern(nLevel + 1);
2483 SwFormTokens::iterator aIt = aPattern.begin();
2485 while(aIt != aPattern.end())
2487 SwFormToken aToken = *aIt; // #i21237#
2488 if(TOKEN_AUTHORITY == aToken.eTokenType)
2490 sal_uInt32 nSearch = aToken.nAuthorityField;
2491 sal_uInt16 nLstBoxPos = aAuthFieldsLB.GetEntryPos( (void*)(sal_uIntPtr)nSearch );
2492 OSL_ENSURE(LISTBOX_ENTRY_NOTFOUND != nLstBoxPos, "Entry not found?");
2493 aAuthFieldsLB.RemoveEntry(nLstBoxPos);
2496 aIt++; // #i21237#
2498 aAuthFieldsLB.SelectEntryPos(0);
2500 bInLevelHdl = sal_False;
2501 pBox->GrabFocus();
2502 return 0;
2505 IMPL_LINK(SwTOXEntryTabPage, SortKeyHdl, RadioButton*, pButton)
2507 sal_Bool bEnable = &aSortContentRB == pButton;
2508 aFirstKeyFT.Enable(bEnable);
2509 aFirstKeyLB.Enable(bEnable);
2510 aSecondKeyFT.Enable(bEnable);
2511 aSecondKeyLB.Enable(bEnable);
2512 aThirdKeyFT.Enable(bEnable);
2513 aThirdKeyLB.Enable(bEnable);
2514 aSortKeyFL.Enable(bEnable);
2515 aFirstSortUpRB.Enable(bEnable);
2516 aFirstSortDownRB.Enable(bEnable);
2517 aSecondSortUpRB.Enable(bEnable);
2518 aSecondSortDownRB.Enable(bEnable);
2519 aThirdSortUpRB.Enable(bEnable);
2520 aThirdSortDownRB.Enable(bEnable);
2521 return 0;
2524 IMPL_LINK(SwTOXEntryTabPage, TokenSelectedHdl, SwFormToken*, pToken)
2526 if(pToken->sCharStyleName.Len())
2527 aCharStyleLB.SelectEntry(pToken->sCharStyleName);
2528 else
2529 aCharStyleLB.SelectEntry(sNoCharStyle);
2531 String sEntry = aCharStyleLB.GetSelectEntry();
2532 aEditStylePB.Enable(sEntry != sNoCharStyle);
2534 if(pToken->eTokenType == TOKEN_CHAPTER_INFO)
2536 //---> i89791
2537 switch(pToken->nChapterFormat)
2539 default:
2540 aChapterEntryLB.SetNoSelection();//to alert the user
2541 break;
2542 case CF_NUM_NOPREPST_TITLE:
2543 aChapterEntryLB.SelectEntryPos(0);
2544 break;
2545 case CF_TITLE:
2546 aChapterEntryLB.SelectEntryPos(1);
2547 break;
2548 case CF_NUMBER_NOPREPST:
2549 aChapterEntryLB.SelectEntryPos(2);
2550 break;
2552 //i53420
2554 aEntryOutlineLevelNF.SetValue(pToken->nOutlineLevel);
2557 //i53420
2558 if(pToken->eTokenType == TOKEN_ENTRY_NO)
2560 aEntryOutlineLevelNF.SetValue(pToken->nOutlineLevel);
2561 sal_uInt16 nFormat = 0;
2562 if( pToken->nChapterFormat == CF_NUM_NOPREPST_TITLE )
2563 nFormat = 1;
2564 aNumberFormatLB.SelectEntryPos(nFormat);
2567 sal_Bool bTabStop = TOKEN_TAB_STOP == pToken->eTokenType;
2568 aFillCharFT.Show(bTabStop);
2569 aFillCharCB.Show(bTabStop);
2570 aTabPosFT.Show(bTabStop);
2571 aTabPosMF.Show(bTabStop);
2572 aAutoRightCB.Show(bTabStop);
2573 aAutoRightCB.Enable(bTabStop);
2574 if(bTabStop)
2576 aTabPosMF.SetValue(aTabPosMF.Normalize(pToken->nTabStopPosition), FUNIT_TWIP);
2577 aAutoRightCB.Check(SVX_TAB_ADJUST_END == pToken->eTabAlign);
2578 aFillCharCB.SetText(OUString(pToken->cTabFillChar));
2579 aTabPosFT.Enable(!aAutoRightCB.IsChecked());
2580 aTabPosMF.Enable(!aAutoRightCB.IsChecked());
2582 else
2584 aTabPosMF.Enable(sal_False);
2587 sal_Bool bIsChapterInfo = pToken->eTokenType == TOKEN_CHAPTER_INFO;
2588 sal_Bool bIsEntryNumber = pToken->eTokenType == TOKEN_ENTRY_NO;
2589 aChapterEntryFT.Show( bIsChapterInfo );
2590 aChapterEntryLB.Show( bIsChapterInfo );
2591 aEntryOutlineLevelFT.Show( bIsChapterInfo || bIsEntryNumber );
2592 aEntryOutlineLevelNF.Show( bIsChapterInfo || bIsEntryNumber );
2593 aNumberFormatFT.Show( bIsEntryNumber );
2594 aNumberFormatLB.Show( bIsEntryNumber );
2597 //now enable the visible buttons
2598 //- inserting the same type of control is not allowed
2599 //- some types of controls can only appear once (EntryText EntryNumber)
2601 if(aEntryNoPB.IsVisible())
2603 aEntryNoPB.Enable(TOKEN_ENTRY_NO != pToken->eTokenType );
2605 if(aEntryPB.IsVisible())
2607 aEntryPB.Enable(TOKEN_ENTRY_TEXT != pToken->eTokenType &&
2608 !aTokenWIN.Contains(TOKEN_ENTRY_TEXT)
2609 && !aTokenWIN.Contains(TOKEN_ENTRY));
2612 if(aChapterInfoPB.IsVisible())
2614 aChapterInfoPB.Enable(TOKEN_CHAPTER_INFO != pToken->eTokenType);
2616 if(aPageNoPB.IsVisible())
2618 aPageNoPB.Enable(TOKEN_PAGE_NUMS != pToken->eTokenType &&
2619 !aTokenWIN.Contains(TOKEN_PAGE_NUMS));
2621 if(aTabPB.IsVisible())
2623 aTabPB.Enable(!bTabStop);
2625 if(aHyperLinkPB.IsVisible())
2627 aHyperLinkPB.Enable(TOKEN_LINK_START != pToken->eTokenType &&
2628 TOKEN_LINK_END != pToken->eTokenType);
2630 //table of authorities
2631 if(aAuthInsertPB.IsVisible())
2633 bool bText = TOKEN_TEXT == pToken->eTokenType;
2634 aAuthInsertPB.Enable(bText && aAuthFieldsLB.GetSelectEntry().Len());
2635 aAuthRemovePB.Enable(!bText);
2638 return 0;
2641 IMPL_LINK(SwTOXEntryTabPage, StyleSelectHdl, ListBox*, pBox)
2643 String sEntry = pBox->GetSelectEntry();
2644 sal_uInt16 nId = (sal_uInt16)(long)pBox->GetEntryData(pBox->GetSelectEntryPos());
2645 aEditStylePB.Enable(sEntry != sNoCharStyle);
2646 if(sEntry == sNoCharStyle)
2647 sEntry.Erase();
2648 Control* pCtrl = aTokenWIN.GetActiveControl();
2649 OSL_ENSURE(pCtrl, "no active control?");
2650 if(pCtrl)
2652 if(WINDOW_EDIT == pCtrl->GetType())
2653 ((SwTOXEdit*)pCtrl)->SetCharStyleName(sEntry, nId);
2654 else
2655 ((SwTOXButton*)pCtrl)->SetCharStyleName(sEntry, nId);
2658 ModifyHdl(0);
2659 return 0;
2662 IMPL_LINK(SwTOXEntryTabPage, ChapterInfoHdl, ListBox*, pBox)
2664 sal_uInt16 nPos = pBox->GetSelectEntryPos();
2665 if(LISTBOX_ENTRY_NOTFOUND != nPos)
2667 Control* pCtrl = aTokenWIN.GetActiveControl();
2668 OSL_ENSURE(pCtrl, "no active control?");
2669 if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
2670 ((SwTOXButton*)pCtrl)->SetChapterInfo(nPos);
2672 ModifyHdl(0);
2674 return 0;
2677 IMPL_LINK(SwTOXEntryTabPage, ChapterInfoOutlineHdl, NumericField*, pField)
2679 const sal_uInt16 nLevel = static_cast<sal_uInt8>(pField->GetValue());
2681 Control* pCtrl = aTokenWIN.GetActiveControl();
2682 OSL_ENSURE(pCtrl, "no active control?");
2683 if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
2684 ((SwTOXButton*)pCtrl)->SetOutlineLevel(nLevel);
2686 ModifyHdl(0);
2687 return 0;
2690 IMPL_LINK(SwTOXEntryTabPage, NumberFormatHdl, ListBox*, pBox)
2692 const sal_uInt16 nPos = pBox->GetSelectEntryPos();
2694 if(LISTBOX_ENTRY_NOTFOUND != nPos)
2696 Control* pCtrl = aTokenWIN.GetActiveControl();
2697 OSL_ENSURE(pCtrl, "no active control?");
2698 if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
2700 ((SwTOXButton*)pCtrl)->SetEntryNumberFormat(nPos);//i89791
2702 ModifyHdl(0);
2704 return 0;
2707 IMPL_LINK(SwTOXEntryTabPage, TabPosHdl, MetricField*, pField)
2709 Control* pCtrl = aTokenWIN.GetActiveControl();
2710 OSL_ENSURE(pCtrl && WINDOW_EDIT != pCtrl->GetType() &&
2711 TOKEN_TAB_STOP == ((SwTOXButton*)pCtrl)->GetFormToken().eTokenType,
2712 "no active style::TabStop control?");
2713 if( pCtrl && WINDOW_EDIT != pCtrl->GetType() )
2715 ((SwTOXButton*)pCtrl)->SetTabPosition( static_cast< SwTwips >(
2716 pField->Denormalize( pField->GetValue( FUNIT_TWIP ))));
2718 ModifyHdl(0);
2719 return 0;
2722 IMPL_LINK(SwTOXEntryTabPage, FillCharHdl, ComboBox*, pBox)
2724 Control* pCtrl = aTokenWIN.GetActiveControl();
2725 OSL_ENSURE(pCtrl && WINDOW_EDIT != pCtrl->GetType() &&
2726 TOKEN_TAB_STOP == ((SwTOXButton*)pCtrl)->GetFormToken().eTokenType,
2727 "no active style::TabStop control?");
2728 if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
2730 sal_Unicode cSet;
2731 if( !pBox->GetText().isEmpty() )
2732 cSet = pBox->GetText()[0];
2733 else
2734 cSet = ' ';
2735 ((SwTOXButton*)pCtrl)->SetFillChar( cSet );
2737 ModifyHdl(0);
2738 return 0;
2741 IMPL_LINK(SwTOXEntryTabPage, AutoRightHdl, CheckBox*, pBox)
2743 //the most right style::TabStop is usually right aligned
2744 Control* pCurCtrl = aTokenWIN.GetActiveControl();
2745 OSL_ENSURE(WINDOW_EDIT != pCurCtrl->GetType() &&
2746 ((SwTOXButton*)pCurCtrl)->GetFormToken().eTokenType == TOKEN_TAB_STOP,
2747 "no style::TabStop selected!");
2749 const SwFormToken& rToken = ((SwTOXButton*)pCurCtrl)->GetFormToken();
2750 sal_Bool bChecked = pBox->IsChecked();
2751 if(rToken.eTokenType == TOKEN_TAB_STOP)
2752 ((SwTOXButton*)pCurCtrl)->SetTabAlign(
2753 bChecked ? SVX_TAB_ADJUST_END : SVX_TAB_ADJUST_LEFT);
2754 aTabPosFT.Enable(!bChecked);
2755 aTabPosMF.Enable(!bChecked);
2756 ModifyHdl(0);
2757 return 0;
2760 void SwTOXEntryTabPage::SetWrtShell(SwWrtShell& rSh)
2762 SwDocShell* pDocSh = rSh.GetView().GetDocShell();
2763 ::FillCharStyleListBox(aCharStyleLB, pDocSh, true, true);
2764 const String sDefault(SW_RES(STR_POOLCOLL_STANDARD));
2765 for(sal_uInt16 i = 0; i < aCharStyleLB.GetEntryCount(); i++)
2767 String sEntry = aCharStyleLB.GetEntry(i);
2768 if(sDefault != sEntry)
2770 aMainEntryStyleLB.InsertEntry( sEntry );
2771 aMainEntryStyleLB.SetEntryData(i, aCharStyleLB.GetEntryData(i));
2774 aMainEntryStyleLB.SelectEntry( SwStyleNameMapper::GetUIName(
2775 RES_POOLCHR_IDX_MAIN_ENTRY, aEmptyStr ));
2778 String SwTOXEntryTabPage::GetLevelHelp(sal_uInt16 nLevel) const
2780 String sRet;
2781 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
2782 const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
2783 if( TOX_INDEX == aCurType.eType )
2784 SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(1 == nLevel ? RES_POOLCOLL_TOX_IDXBREAK
2785 : RES_POOLCOLL_TOX_IDX1 + nLevel-2), sRet );
2787 else if( TOX_AUTHORITIES == aCurType.eType )
2789 //wildcard -> show entry text
2790 sRet = '*';
2792 return sRet;
2795 SwTokenWindow::SwTokenWindow(SwTOXEntryTabPage* pParent, const ResId& rResId) :
2796 Window( pParent, rResId ),
2797 aLeftScrollWin(this, ResId(WIN_LEFT_SCROLL, *rResId.GetResMgr() )),
2798 aCtrlParentWin(this, ResId(WIN_CTRL_PARENT, *rResId.GetResMgr() )),
2799 aRightScrollWin(this, ResId(WIN_RIGHT_SCROLL, *rResId.GetResMgr() )),
2800 pForm(0),
2801 nLevel(0),
2802 bValid(sal_False),
2803 sCharStyle(ResId(STR_CHARSTYLE, *rResId.GetResMgr())),
2804 pActiveCtrl(0),
2805 m_pParent(pParent)
2807 SetStyle(GetStyle()|WB_TABSTOP|WB_DIALOGCONTROL);
2808 SetHelpId(HID_TOKEN_WINDOW);
2809 for(sal_uInt16 i = 0; i < TOKEN_END; i++)
2811 sal_uInt16 nTextId = STR_BUTTON_TEXT_START + i;
2812 if( STR_TOKEN_ENTRY_TEXT == nTextId )
2813 nTextId = STR_TOKEN_ENTRY;
2814 aButtonTexts[i] = String(ResId(nTextId, *rResId.GetResMgr()));
2816 sal_uInt16 nHelpId = STR_BUTTON_HELP_TEXT_START + i;
2817 if(STR_TOKEN_HELP_ENTRY_TEXT == nHelpId)
2818 nHelpId = STR_TOKEN_HELP_ENTRY;
2819 aButtonHelpTexts[i] = String(ResId(nHelpId, *rResId.GetResMgr()));
2822 FreeResource();
2824 Link aLink(LINK(this, SwTokenWindow, ScrollHdl));
2825 aLeftScrollWin.SetClickHdl(aLink);
2826 aRightScrollWin.SetClickHdl(aLink);
2829 SwTokenWindow::~SwTokenWindow()
2831 for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
2833 Control* pControl = (*it);
2834 pControl->SetGetFocusHdl( Link() );
2835 pControl->SetLoseFocusHdl( Link() );
2836 delete pControl;
2840 void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
2842 SetActiveControl(0);
2843 bValid = sal_True;
2845 if(pForm)
2847 //apply current level settings to the form
2848 for (ctrl_iterator iter = aControlList.begin(); iter != aControlList.end(); ++iter)
2849 delete (*iter);
2851 aControlList.clear();
2854 nLevel = nL;
2855 pForm = &rForm;
2856 //now the display
2857 if(nLevel < MAXLEVEL || rForm.GetTOXType() == TOX_AUTHORITIES)
2859 // #i21237#
2860 SwFormTokens aPattern = pForm->GetPattern(nLevel + 1);
2861 SwFormTokens::iterator aIt = aPattern.begin();
2862 bool bLastWasText = false; //assure alternating text - code - text
2864 Control* pSetActiveControl = 0;
2865 while(aIt != aPattern.end()) // #i21237#
2867 SwFormToken aToken(*aIt); // #i21237#
2869 if(TOKEN_TEXT == aToken.eTokenType)
2871 OSL_ENSURE(!bLastWasText, "text following text is invalid");
2872 Control* pCtrl = InsertItem(aToken.sText, aToken);
2873 bLastWasText = true;
2874 if(!GetActiveControl())
2875 SetActiveControl(pCtrl);
2877 else
2879 if( !bLastWasText )
2881 bLastWasText = true;
2882 SwFormToken aTemp(TOKEN_TEXT);
2883 Control* pCtrl = InsertItem(aEmptyStr, aTemp);
2884 if(!pSetActiveControl)
2885 pSetActiveControl = pCtrl;
2887 const sal_Char* pTmp = 0;
2888 switch( aToken.eTokenType )
2890 case TOKEN_ENTRY_NO: pTmp = SwForm::aFormEntryNum; break;
2891 case TOKEN_ENTRY_TEXT: pTmp = SwForm::aFormEntryTxt; break;
2892 case TOKEN_ENTRY: pTmp = SwForm::aFormEntry; break;
2893 case TOKEN_TAB_STOP: pTmp = SwForm::aFormTab; break;
2894 case TOKEN_PAGE_NUMS: pTmp = SwForm::aFormPageNums; break;
2895 case TOKEN_CHAPTER_INFO:pTmp = SwForm::aFormChapterMark; break;
2896 case TOKEN_LINK_START: pTmp = SwForm::aFormLinkStt; break;
2897 case TOKEN_LINK_END: pTmp = SwForm::aFormLinkEnd; break;
2898 case TOKEN_AUTHORITY: pTmp = SwForm::aFormAuth; break;
2899 default:; //prevent warning
2902 InsertItem( pTmp ? OUString::createFromAscii(pTmp)
2903 : OUString(), aToken );
2904 bLastWasText = false;
2907 ++aIt; // #i21237#
2909 if(!bLastWasText)
2911 bLastWasText = true;
2912 SwFormToken aTemp(TOKEN_TEXT);
2913 Control* pCtrl = InsertItem(aEmptyStr, aTemp);
2914 if(!pSetActiveControl)
2915 pSetActiveControl = pCtrl;
2917 SetActiveControl(pSetActiveControl);
2919 AdjustScrolling();
2922 void SwTokenWindow::SetActiveControl(Control* pSet)
2924 if( pSet != pActiveCtrl )
2926 pActiveCtrl = pSet;
2927 if( pActiveCtrl )
2929 pActiveCtrl->GrabFocus();
2930 //it must be a SwTOXEdit
2931 const SwFormToken* pFToken;
2932 if( WINDOW_EDIT == pActiveCtrl->GetType() )
2933 pFToken = &((SwTOXEdit*)pActiveCtrl)->GetFormToken();
2934 else
2935 pFToken = &((SwTOXButton*)pActiveCtrl)->GetFormToken();
2937 SwFormToken aTemp( *pFToken );
2938 aButtonSelectedHdl.Call( &aTemp );
2943 Control* SwTokenWindow::InsertItem(const String& rText, const SwFormToken& rToken)
2945 Control* pRet = 0;
2946 Size aControlSize(GetOutputSizePixel());
2947 Point aControlPos;
2949 if(!aControlList.empty())
2951 Control* pLast = *(aControlList.rbegin());
2953 aControlSize = pLast->GetSizePixel();
2954 aControlPos = pLast->GetPosPixel();
2955 aControlPos.X() += aControlSize.Width();
2958 if(TOKEN_TEXT == rToken.eTokenType)
2960 SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, rToken);
2961 pEdit->SetPosPixel(aControlPos);
2963 aControlList.push_back(pEdit);
2965 pEdit->SetText(rText);
2966 Size aEditSize(aControlSize);
2967 aEditSize.Width() = pEdit->GetTextWidth(rText) + EDIT_MINWIDTH;
2968 pEdit->SetSizePixel(aEditSize);
2969 pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
2970 pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
2971 pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
2972 pEdit->Show();
2973 pRet = pEdit;
2975 else
2977 SwTOXButton* pButton = new SwTOXButton(&aCtrlParentWin, this, rToken);
2978 pButton->SetPosPixel(aControlPos);
2980 aControlList.push_back(pButton);
2982 Size aEditSize(aControlSize);
2983 aEditSize.Width() = pButton->GetTextWidth(rText) + 5;
2984 pButton->SetSizePixel(aEditSize);
2985 pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
2986 pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
2988 if(TOKEN_AUTHORITY != rToken.eTokenType)
2989 pButton->SetText(aButtonTexts[rToken.eTokenType]);
2990 else
2992 //use the first two chars as symbol
2993 String sTmp(SwAuthorityFieldType::GetAuthFieldName(
2994 (ToxAuthorityField)rToken.nAuthorityField));
2995 pButton->SetText(sTmp.Copy(0, 2));
2998 pButton->Show();
2999 pRet = pButton;
3002 return pRet;
3005 void SwTokenWindow::InsertAtSelection(
3006 const String& rText,
3007 const SwFormToken& rToken)
3009 OSL_ENSURE(pActiveCtrl, "no active control!");
3011 if(!pActiveCtrl)
3012 return;
3014 SwFormToken aToInsertToken(rToken);
3016 if(TOKEN_LINK_START == aToInsertToken.eTokenType)
3018 //determine if start or end of hyperlink is appropriate
3019 //eventually change a following link start into a link end
3020 // groups of LS LE should be ignored
3021 // <insert>
3022 //LS <insert>
3023 //LE <insert>
3024 //<insert> LS
3025 //<insert> LE
3026 //<insert>
3027 bool bPreStartLinkFound = false;
3028 bool bPreEndLinkFound = false;
3030 const Control* pControl = 0;
3031 const Control* pExchange = 0;
3033 ctrl_const_iterator it = aControlList.begin();
3034 for( ; it != aControlList.end() && pActiveCtrl != (*it); ++it )
3036 pControl = *it;
3038 if( WINDOW_EDIT != pControl->GetType())
3040 const SwFormToken& rNewToken =
3041 ((SwTOXButton*)pControl)->GetFormToken();
3043 if( TOKEN_LINK_START == rNewToken.eTokenType )
3045 bPreStartLinkFound = true;
3046 pExchange = 0;
3048 else if(TOKEN_LINK_END == rNewToken.eTokenType)
3050 if( bPreStartLinkFound )
3051 bPreStartLinkFound = false;
3052 else
3054 bPreEndLinkFound = false;
3055 pExchange = pControl;
3061 bool bPostLinkStartFound = false;
3063 if(!bPreStartLinkFound && !bPreEndLinkFound)
3065 for( ; it != aControlList.end(); ++it )
3067 pControl = *it;
3069 if( pControl != pActiveCtrl &&
3070 WINDOW_EDIT != pControl->GetType())
3072 const SwFormToken& rNewToken =
3073 ((SwTOXButton*)pControl)->GetFormToken();
3075 if( TOKEN_LINK_START == rNewToken.eTokenType )
3077 if(bPostLinkStartFound)
3078 break;
3079 bPostLinkStartFound = sal_True;
3080 pExchange = pControl;
3082 else if(TOKEN_LINK_END == rNewToken.eTokenType )
3084 if(bPostLinkStartFound)
3086 bPostLinkStartFound = sal_False;
3087 pExchange = 0;
3089 break;
3095 if(bPreStartLinkFound)
3097 aToInsertToken.eTokenType = TOKEN_LINK_END;
3098 aToInsertToken.sText = aButtonTexts[TOKEN_LINK_END];
3101 if(bPostLinkStartFound)
3103 OSL_ENSURE(pExchange, "no control to exchange?");
3104 if(pExchange)
3106 ((SwTOXButton*)pExchange)->SetLinkEnd();
3107 ((SwTOXButton*)pExchange)->SetText(aButtonTexts[TOKEN_LINK_END]);
3111 if(bPreEndLinkFound)
3113 OSL_ENSURE(pExchange, "no control to exchange?");
3115 if(pExchange)
3117 ((SwTOXButton*)pExchange)->SetLinkStart();
3118 ((SwTOXButton*)pExchange)->SetText(aButtonTexts[TOKEN_LINK_START]);
3123 //if the active control is text then insert a new button at the selection
3124 //else replace the button
3125 ctrl_iterator iterActive = std::find(aControlList.begin(),
3126 aControlList.end(), pActiveCtrl);
3128 Size aControlSize(GetOutputSizePixel());
3130 if( WINDOW_EDIT == pActiveCtrl->GetType())
3132 ++iterActive;
3134 Selection aSel = ((SwTOXEdit*)pActiveCtrl)->GetSelection();
3135 aSel.Justify();
3137 String sEditText = ((SwTOXEdit*)pActiveCtrl)->GetText();
3138 String sLeft = sEditText.Copy( 0, static_cast< sal_uInt16 >(aSel.A()) );
3139 String sRight = sEditText.Copy( static_cast< sal_uInt16 >(aSel.B()),
3140 static_cast< sal_uInt16 >(sEditText.Len() - aSel.B()));
3142 ((SwTOXEdit*)pActiveCtrl)->SetText(sLeft);
3143 ((SwTOXEdit*)pActiveCtrl)->AdjustSize();
3145 SwFormToken aTmpToken(TOKEN_TEXT);
3146 SwTOXEdit* pEdit = new SwTOXEdit(&aCtrlParentWin, this, aTmpToken);
3148 iterActive = aControlList.insert(iterActive, pEdit);
3150 pEdit->SetText(sRight);
3151 pEdit->SetSizePixel(aControlSize);
3152 pEdit->AdjustSize();
3153 pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
3154 pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
3155 pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
3156 pEdit->Show();
3158 else
3160 iterActive = aControlList.erase(iterActive);
3161 pActiveCtrl->Hide();
3162 delete pActiveCtrl;
3165 //now the new button
3166 SwTOXButton* pButton = new SwTOXButton(&aCtrlParentWin, this, aToInsertToken);
3168 aControlList.insert(iterActive, pButton);
3170 pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
3171 pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
3173 if(TOKEN_AUTHORITY != aToInsertToken.eTokenType)
3175 pButton->SetText(aButtonTexts[aToInsertToken.eTokenType]);
3177 else
3179 //use the first two chars as symbol
3180 String sTmp(SwAuthorityFieldType::GetAuthFieldName(
3181 (ToxAuthorityField)aToInsertToken.nAuthorityField));
3182 pButton->SetText(sTmp.Copy(0, 2));
3185 Size aEditSize(GetOutputSizePixel());
3186 aEditSize.Width() = pButton->GetTextWidth(rText) + 5;
3187 pButton->SetSizePixel(aEditSize);
3188 pButton->Check(sal_True);
3189 pButton->Show();
3190 SetActiveControl(pButton);
3192 AdjustPositions();
3195 void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall )
3197 if(bInternalCall && TOX_AUTHORITIES == pForm->GetTOXType())
3198 m_pParent->PreTokenButtonRemoved(pDel->GetFormToken());
3200 ctrl_iterator it = std::find(aControlList.begin(), aControlList.end(), pDel);
3202 OSL_ENSURE(it != aControlList.end(), "Control does not exist!");
3204 // the two neighbours of the box must be merged
3205 // the properties of the right one will be lost
3206 OSL_ENSURE(it != aControlList.begin() && it != aControlList.end() - 1,
3207 "Button at first or last position?");
3209 ctrl_iterator itLeft = it, itRight = it;
3210 --itLeft;
3211 ++itRight;
3212 Control *pLeftEdit = *itLeft;
3213 Control *pRightEdit = *itRight;
3215 String sTemp(((SwTOXEdit*)pLeftEdit)->GetText());
3216 sTemp += ((SwTOXEdit*)pRightEdit)->GetText();
3217 ((SwTOXEdit*)pLeftEdit)->SetText(sTemp);
3218 ((SwTOXEdit*)pLeftEdit)->AdjustSize();
3220 aControlList.erase(itRight);
3221 delete pRightEdit;
3223 aControlList.erase(it);
3224 pActiveCtrl->Hide();
3225 delete pActiveCtrl;
3227 SetActiveControl(pLeftEdit);
3228 AdjustPositions();
3229 if(aModifyHdl.IsSet())
3230 aModifyHdl.Call(0);
3233 void SwTokenWindow::AdjustPositions()
3235 if(aControlList.size() > 1)
3237 ctrl_iterator it = aControlList.begin();
3238 Control* pCtrl = *it;
3239 ++it;
3241 Point aNextPos = pCtrl->GetPosPixel();
3242 aNextPos.X() += pCtrl->GetSizePixel().Width();
3244 for(; it != aControlList.end(); ++it)
3246 pCtrl = *it;
3247 pCtrl->SetPosPixel(aNextPos);
3248 aNextPos.X() += pCtrl->GetSizePixel().Width();
3251 AdjustScrolling();
3255 void SwTokenWindow::MoveControls(long nOffset)
3257 // move the complete list
3258 for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3260 Control *pCtrl = *it;
3262 Point aPos = pCtrl->GetPosPixel();
3263 aPos.X() += nOffset;
3265 pCtrl->SetPosPixel(aPos);
3269 void SwTokenWindow::AdjustScrolling()
3271 if(aControlList.size() > 1)
3273 //validate scroll buttons
3274 Control* pFirstCtrl = *(aControlList.begin());
3275 Control* pLastCtrl = *(aControlList.rbegin());
3277 long nSpace = aCtrlParentWin.GetSizePixel().Width();
3278 long nWidth = pLastCtrl->GetPosPixel().X() - pFirstCtrl->GetPosPixel().X()
3279 + pLastCtrl->GetSizePixel().Width();
3280 bool bEnable = nWidth > nSpace;
3282 //the active control must be visible
3283 if(bEnable && pActiveCtrl)
3285 Point aActivePos(pActiveCtrl->GetPosPixel());
3287 long nMove = 0;
3289 if(aActivePos.X() < 0)
3290 nMove = -aActivePos.X();
3291 else if((aActivePos.X() + pActiveCtrl->GetSizePixel().Width()) > nSpace)
3292 nMove = -(aActivePos.X() + pActiveCtrl->GetSizePixel().Width() - nSpace);
3294 if(nMove)
3295 MoveControls(nMove);
3297 aLeftScrollWin.Enable(pFirstCtrl->GetPosPixel().X() < 0);
3299 aRightScrollWin.Enable((pLastCtrl->GetPosPixel().X() + pLastCtrl->GetSizePixel().Width()) > nSpace);
3301 else
3303 if(pFirstCtrl)
3305 //if the control fits into the space then the first control must be at postion 0
3306 long nFirstPos = pFirstCtrl->GetPosPixel().X();
3308 if(nFirstPos != 0)
3309 MoveControls(-nFirstPos);
3312 aRightScrollWin.Enable(false);
3313 aLeftScrollWin.Enable(false);
3318 IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
3320 if(aControlList.empty())
3321 return 0;
3323 const long nSpace = aCtrlParentWin.GetSizePixel().Width();
3324 #if OSL_DEBUG_LEVEL > 1
3325 //find all start/end positions and print it
3326 String sMessage(OUString("Space: "));
3327 sMessage += OUString::number(nSpace);
3328 sMessage += OUString(" | ");
3330 for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3332 Control *pDebugCtrl = *it;
3334 long nDebugXPos = pDebugCtrl->GetPosPixel().X();
3335 long nDebugWidth = pDebugCtrl->GetSizePixel().Width();
3337 sMessage += OUString::number( nDebugXPos );
3338 sMessage += OUString(" ");
3339 sMessage += OUString::number(nDebugXPos + nDebugWidth);
3340 sMessage += OUString(" | ");
3343 #endif
3345 long nMove = 0;
3346 if(pBtn == &aLeftScrollWin)
3348 //find the first completely visible control (left edge visible)
3349 for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3351 Control *pCtrl = *it;
3353 long nXPos = pCtrl->GetPosPixel().X();
3355 if (nXPos >= 0)
3357 if (it == aControlList.begin())
3359 //move the current control to the left edge
3360 nMove = -nXPos;
3362 else
3364 //move the left neighbor to the start position
3365 ctrl_iterator itLeft = it;
3366 --itLeft;
3367 Control *pLeft = *itLeft;
3369 nMove = -pLeft->GetPosPixel().X();
3372 break;
3376 else
3378 //find the first completely visible control (right edge visible)
3379 for (ctrl_reverse_iterator it = aControlList.rbegin(); it != aControlList.rend(); ++it)
3381 Control *pCtrl = *it;
3383 long nCtrlWidth = pCtrl->GetSizePixel().Width();
3384 long nXPos = pCtrl->GetPosPixel().X() + nCtrlWidth;
3386 if (nXPos <= nSpace)
3388 if (it != aControlList.rbegin())
3390 //move the right neighbor to the right edge right aligned
3391 ctrl_reverse_iterator itRight = it;
3392 --itRight;
3393 Control *pRight = *itRight;
3394 nMove = nSpace - pRight->GetPosPixel().X() - pRight->GetSizePixel().Width();
3397 break;
3401 //move it left until it's completely visible
3404 if(nMove)
3406 // move the complete list
3407 MoveControls(nMove);
3409 Control *pCtrl = 0;
3411 pCtrl = *(aControlList.begin());
3412 aLeftScrollWin.Enable(pCtrl->GetPosPixel().X() < 0);
3414 pCtrl = *(aControlList.rbegin());
3415 aRightScrollWin.Enable((pCtrl->GetPosPixel().X() + pCtrl->GetSizePixel().Width()) > nSpace);
3418 return 0;
3421 String SwTokenWindow::GetPattern() const
3423 String sRet;
3425 for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3427 const Control *pCtrl = *it;
3429 const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT
3430 ? ((SwTOXEdit*)pCtrl)->GetFormToken()
3431 : ((SwTOXButton*)pCtrl)->GetFormToken();
3433 //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput
3434 sRet += rNewToken.GetString();
3437 return sRet;
3439 /* --------------------------------------------------
3440 Description: Check if a control of the specified
3441 TokenType is already contained in the list
3442 --------------------------------------------------*/
3443 sal_Bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
3445 bool bRet = false;
3447 for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3449 const Control *pCtrl = *it;
3451 const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT
3452 ? ((SwTOXEdit*)pCtrl)->GetFormToken()
3453 : ((SwTOXButton*)pCtrl)->GetFormToken();
3455 if (eSearchFor == rNewToken.eTokenType)
3457 bRet = true;
3458 break;
3462 return bRet;
3465 sal_Bool SwTokenWindow::CreateQuickHelp(Control* pCtrl,
3466 const SwFormToken& rToken,
3467 const HelpEvent& rHEvt)
3469 sal_Bool bRet = sal_False;
3470 if( rHEvt.GetMode() & HELPMODE_QUICK )
3472 sal_Bool bBalloon = Help::IsBalloonHelpEnabled();
3473 String sEntry;
3474 if(bBalloon || rToken.eTokenType != TOKEN_AUTHORITY)
3475 sEntry = (aButtonHelpTexts[rToken.eTokenType]);
3476 if(rToken.eTokenType == TOKEN_AUTHORITY )
3478 sEntry += SwAuthorityFieldType::GetAuthFieldName(
3479 (ToxAuthorityField) rToken.nAuthorityField);
3482 Point aPos = OutputToScreenPixel(pCtrl->GetPosPixel());
3483 Rectangle aItemRect( aPos, pCtrl->GetSizePixel() );
3484 if(rToken.eTokenType == TOKEN_TAB_STOP )
3487 else
3489 if(rToken.sCharStyleName.Len())
3491 if(bBalloon)
3492 sEntry += '\n';
3493 else
3494 sEntry += ' ';
3495 sEntry += sCharStyle;
3496 sEntry += rToken.sCharStyleName;
3499 if(bBalloon)
3501 Help::ShowBalloon( this, aPos, aItemRect, sEntry );
3503 else
3504 Help::ShowQuickHelp( this, aItemRect, sEntry,
3505 QUICKHELP_LEFT|QUICKHELP_VCENTER );
3506 bRet = sal_True;
3508 return bRet;
3511 void SwTokenWindow::Resize()
3513 Size aCompleteSize(GetOutputSizePixel());
3515 Point aRightPos(aRightScrollWin.GetPosPixel());
3516 Size aRightSize(aRightScrollWin.GetSizePixel());
3518 Size aMiddleSize(aCtrlParentWin.GetSizePixel());
3520 long nMove = aCompleteSize.Width() - aRightSize.Width() - aRightPos.X();
3522 aRightPos.X() += nMove;
3523 aRightScrollWin.SetPosPixel(aRightPos);
3524 aMiddleSize.Width() += nMove;
3525 aCtrlParentWin.SetSizePixel(aMiddleSize);
3528 IMPL_LINK(SwTokenWindow, EditResize, Edit*, pEdit)
3530 ((SwTOXEdit*)pEdit)->AdjustSize();
3531 AdjustPositions();
3532 if(aModifyHdl.IsSet())
3533 aModifyHdl.Call(0);
3534 return 0;
3537 IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit*, pEdit)
3539 ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pEdit);
3541 if (it == aControlList.end())
3542 return 0;
3544 ctrl_iterator itTest = it;
3545 ++itTest;
3547 if ((it != aControlList.begin() && !pEdit->IsNextControl()) ||
3548 (itTest != aControlList.end() && pEdit->IsNextControl()))
3550 ctrl_iterator iterFocus = it;
3551 pEdit->IsNextControl() ? ++iterFocus : --iterFocus;
3553 Control *pCtrlFocus = *iterFocus;
3554 pCtrlFocus->GrabFocus();
3555 static_cast<SwTOXButton*>(pCtrlFocus)->Check();
3557 AdjustScrolling();
3560 return 0;
3563 IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit)
3565 for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3567 Control *pCtrl = *it;
3569 if (pCtrl && pCtrl->GetType() != WINDOW_EDIT)
3570 static_cast<SwTOXButton*>(pCtrl)->Check(false);
3573 SetActiveControl(pEdit);
3575 return 0;
3578 IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn )
3580 ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pBtn);
3582 if (it == aControlList.end())
3583 return 0;
3585 ctrl_iterator itTest = it;
3586 ++itTest;
3588 if (!pBtn->IsNextControl() || (itTest != aControlList.end() && pBtn->IsNextControl()))
3590 bool isNext = pBtn->IsNextControl();
3592 ctrl_iterator iterFocus = it;
3593 isNext ? ++iterFocus : --iterFocus;
3595 Control *pCtrlFocus = *iterFocus;
3596 pCtrlFocus->GrabFocus();
3597 Selection aSel(0,0);
3599 if (!isNext)
3601 sal_Int32 nLen = static_cast<SwTOXEdit*>(pCtrlFocus)->GetText().getLength();
3603 aSel.A() = (sal_uInt16)nLen;
3604 aSel.B() = (sal_uInt16)nLen;
3607 static_cast<SwTOXEdit*>(pCtrlFocus)->SetSelection(aSel);
3609 pBtn->Check(false);
3611 AdjustScrolling();
3614 return 0;
3617 IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXButton*, pBtn )
3619 for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
3621 Control *pControl = *it;
3623 if (pControl && WINDOW_EDIT != pControl->GetType())
3624 static_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl);
3627 SetActiveControl(pBtn);
3629 return 0;
3632 void SwTokenWindow::GetFocus()
3634 if(GETFOCUS_TAB & GetGetFocusFlags())
3636 if (!aControlList.empty())
3638 Control *pFirst = *aControlList.begin();
3640 if (pFirst)
3642 pFirst->GrabFocus();
3643 SetActiveControl(pFirst);
3644 AdjustScrolling();
3650 SwTOXStylesTabPage::SwTOXStylesTabPage(Window* pParent, const SfxItemSet& rAttrSet ) :
3651 SfxTabPage(pParent, SW_RES(TP_TOX_STYLES), rAttrSet),
3652 aFormatFL(this, SW_RES(FL_FORMAT )),
3653 aLevelFT2(this, SW_RES(FT_LEVEL )),
3654 aLevelLB(this, SW_RES(LB_LEVEL )),
3655 aAssignBT(this, SW_RES(BT_ASSIGN )),
3656 aTemplateFT(this, SW_RES(FT_TEMPLATE)),
3657 aParaLayLB(this, SW_RES(LB_PARALAY )),
3658 aStdBT(this, SW_RES(BT_STD )),
3659 aEditStyleBT(this, SW_RES(BT_EDIT_STYLE )),
3660 m_pCurrentForm(0)
3662 FreeResource();
3664 SetExchangeSupport( sal_True );
3666 aEditStyleBT.SetClickHdl (LINK( this, SwTOXStylesTabPage, EditStyleHdl));
3667 aAssignBT.SetClickHdl (LINK( this, SwTOXStylesTabPage, AssignHdl));
3668 aStdBT.SetClickHdl (LINK( this, SwTOXStylesTabPage, StdHdl));
3669 aParaLayLB.SetSelectHdl (LINK( this, SwTOXStylesTabPage, EnableSelectHdl));
3670 aLevelLB.SetSelectHdl (LINK( this, SwTOXStylesTabPage, EnableSelectHdl));
3671 aParaLayLB.SetDoubleClickHdl(LINK( this, SwTOXStylesTabPage, DoubleClickHdl));
3673 aStdBT.SetAccessibleRelationMemberOf(&aFormatFL);
3674 aAssignBT.SetAccessibleRelationMemberOf(&aFormatFL);
3675 aEditStyleBT.SetAccessibleRelationMemberOf(&aFormatFL);
3679 SwTOXStylesTabPage::~SwTOXStylesTabPage()
3681 delete m_pCurrentForm;
3684 sal_Bool SwTOXStylesTabPage::FillItemSet( SfxItemSet& )
3686 return sal_True;
3689 void SwTOXStylesTabPage::Reset( const SfxItemSet& rSet )
3691 ActivatePage(rSet);
3694 void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
3696 m_pCurrentForm = new SwForm(GetForm());
3697 aParaLayLB.Clear();
3698 aLevelLB.Clear();
3700 // not hyperlink for user directories
3702 sal_uInt16 i, nSize = m_pCurrentForm->GetFormMax();
3704 // display form pattern without title
3706 // display 1st TemplateEntry
3707 String aStr( SW_RES( STR_TITLE ));
3708 if( m_pCurrentForm->GetTemplate( 0 ).Len() )
3710 aStr += ' ';
3711 aStr += aDeliStart;
3712 aStr += m_pCurrentForm->GetTemplate( 0 );
3713 aStr += aDeliEnd;
3715 aLevelLB.InsertEntry(aStr);
3717 for( i=1; i < nSize; ++i )
3719 if( TOX_INDEX == m_pCurrentForm->GetTOXType() &&
3720 FORM_ALPHA_DELIMITTER == i )
3721 aStr = SW_RESSTR(STR_ALPHA);
3722 else
3724 aStr = SW_RESSTR(STR_LEVEL);
3725 aStr += OUString::number(
3726 TOX_INDEX == m_pCurrentForm->GetTOXType() ? i - 1 : i );
3728 String aCpy( aStr );
3730 if( m_pCurrentForm->GetTemplate( i ).Len() )
3732 aCpy += ' ';
3733 aCpy += aDeliStart;
3734 aCpy += m_pCurrentForm->GetTemplate( i );
3735 aCpy += aDeliEnd;
3737 aLevelLB.InsertEntry( aCpy );
3740 // initialise templates
3741 const SwTxtFmtColl *pColl;
3742 SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
3743 const sal_uInt16 nSz = rSh.GetTxtFmtCollCount();
3745 for( i = 0; i < nSz; ++i )
3746 if( !(pColl = &rSh.GetTxtFmtColl( i ))->IsDefault() )
3747 aParaLayLB.InsertEntry( pColl->GetName() );
3749 // query pool collections and set them for the directory
3750 for( i = 0; i < m_pCurrentForm->GetFormMax(); ++i )
3752 aStr = m_pCurrentForm->GetTemplate( i );
3753 if( aStr.Len() &&
3754 LISTBOX_ENTRY_NOTFOUND == aParaLayLB.GetEntryPos( aStr ))
3755 aParaLayLB.InsertEntry( aStr );
3758 EnableSelectHdl(&aParaLayLB);
3761 int SwTOXStylesTabPage::DeactivatePage( SfxItemSet* /*pSet*/ )
3763 GetForm() = *m_pCurrentForm;
3764 return LEAVE_PAGE;
3767 SfxTabPage* SwTOXStylesTabPage::Create( Window* pParent,
3768 const SfxItemSet& rAttrSet)
3770 return new SwTOXStylesTabPage(pParent, rAttrSet);
3773 IMPL_LINK( SwTOXStylesTabPage, EditStyleHdl, Button *, pBtn )
3775 if( LISTBOX_ENTRY_NOTFOUND != aParaLayLB.GetSelectEntryPos())
3777 SfxStringItem aStyle(SID_STYLE_EDIT, aParaLayLB.GetSelectEntry());
3778 SfxUInt16Item aFamily(SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA);
3779 Window* pDefDlgParent = Application::GetDefDialogParent();
3780 Application::SetDefDialogParent( pBtn );
3781 SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
3782 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(
3783 SID_STYLE_EDIT, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_MODAL,
3784 &aStyle, &aFamily, 0L);
3785 Application::SetDefDialogParent( pDefDlgParent );
3787 return 0;
3789 /*--------------------------------------------------------------------
3790 Description: allocate templates
3791 --------------------------------------------------------------------*/
3792 IMPL_LINK_NOARG(SwTOXStylesTabPage, AssignHdl)
3794 sal_uInt16 nLevPos = aLevelLB.GetSelectEntryPos();
3795 sal_uInt16 nTemplPos = aParaLayLB.GetSelectEntryPos();
3796 if(nLevPos != LISTBOX_ENTRY_NOTFOUND &&
3797 nTemplPos != LISTBOX_ENTRY_NOTFOUND)
3799 String aStr(aLevelLB.GetEntry(nLevPos));
3800 sal_uInt16 nDelPos = aStr.Search(aDeliStart);
3801 if(nDelPos != STRING_NOTFOUND)
3802 aStr.Erase(nDelPos-1);
3803 aStr += ' ';
3804 aStr += aDeliStart;
3805 aStr += aParaLayLB.GetSelectEntry();
3807 m_pCurrentForm->SetTemplate(nLevPos, aParaLayLB.GetSelectEntry());
3809 aStr += aDeliEnd;
3811 aLevelLB.RemoveEntry(nLevPos);
3812 aLevelLB.InsertEntry(aStr, nLevPos);
3813 aLevelLB.SelectEntry(aStr);
3814 Modify();
3816 return 0;
3819 IMPL_LINK_NOARG(SwTOXStylesTabPage, StdHdl)
3821 sal_uInt16 nPos = aLevelLB.GetSelectEntryPos();
3822 if(nPos != LISTBOX_ENTRY_NOTFOUND)
3823 { String aStr(aLevelLB.GetEntry(nPos));
3824 sal_uInt16 nDelPos = aStr.Search(aDeliStart);
3825 if(nDelPos != STRING_NOTFOUND)
3826 aStr.Erase(nDelPos-1);
3827 aLevelLB.RemoveEntry(nPos);
3828 aLevelLB.InsertEntry(aStr, nPos);
3829 aLevelLB.SelectEntry(aStr);
3830 m_pCurrentForm->SetTemplate(nPos, aEmptyStr);
3831 Modify();
3833 return 0;
3836 IMPL_LINK_NOARG_INLINE_START(SwTOXStylesTabPage, DoubleClickHdl)
3838 String aTmpName( aParaLayLB.GetSelectEntry() );
3839 SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
3841 if(aParaLayLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND &&
3842 (aLevelLB.GetSelectEntryPos() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)))
3843 AssignHdl(&aAssignBT);
3844 return 0;
3846 IMPL_LINK_NOARG_INLINE_END(SwTOXStylesTabPage, DoubleClickHdl)
3848 /*--------------------------------------------------------------------
3849 Description: enable only when selected
3850 --------------------------------------------------------------------*/
3851 IMPL_LINK_NOARG(SwTOXStylesTabPage, EnableSelectHdl)
3853 aStdBT.Enable(aLevelLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND);
3855 SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
3856 String aTmpName(aParaLayLB.GetSelectEntry());
3857 aAssignBT.Enable(aParaLayLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND &&
3858 LISTBOX_ENTRY_NOTFOUND != aLevelLB.GetSelectEntryPos() &&
3859 (aLevelLB.GetSelectEntryPos() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)));
3860 aEditStyleBT.Enable(aParaLayLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND );
3861 return 0;
3864 void SwTOXStylesTabPage::Modify()
3866 SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
3867 if(pTOXDlg)
3869 GetForm() = *m_pCurrentForm;
3870 pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_STYLES);
3874 #define ITEM_SEARCH 1
3875 #define ITEM_ALTERNATIVE 2
3876 #define ITEM_PRIM_KEY 3
3877 #define ITEM_SEC_KEY 4
3878 #define ITEM_COMMENT 5
3879 #define ITEM_CASE 6
3880 #define ITEM_WORDONLY 7
3883 SwEntryBrowseBox::SwEntryBrowseBox(Window* pParent, const ResId& rId,
3884 BrowserMode nMode ) :
3885 SwEntryBrowseBox_Base( pParent, rId, nMode,
3886 BROWSER_KEEPSELECTION |
3887 BROWSER_COLUMNSELECTION |
3888 BROWSER_MULTISELECTION |
3889 BROWSER_TRACKING_TIPS |
3890 BROWSER_HLINESFULL |
3891 BROWSER_VLINESFULL |
3892 BROWSER_AUTO_VSCROLL|
3893 BROWSER_HIDECURSOR ),
3894 aCellEdit(&GetDataWindow(), 0),
3895 aCellCheckBox(&GetDataWindow()),
3897 sSearch( ResId(ST_SEARCH, *rId.GetResMgr() )),
3898 sAlternative( ResId(ST_ALTERNATIVE, *rId.GetResMgr() )),
3899 sPrimKey( ResId(ST_PRIMKEY, *rId.GetResMgr() )),
3900 sSecKey( ResId(ST_SECKEY, *rId.GetResMgr() )),
3901 sComment( ResId(ST_COMMENT, *rId.GetResMgr() )),
3902 sCaseSensitive( ResId(ST_CASESENSITIVE, *rId.GetResMgr() )),
3903 sWordOnly( ResId(ST_WORDONLY, *rId.GetResMgr() )),
3904 sYes( ResId(ST_TRUE, *rId.GetResMgr() )),
3905 sNo( ResId(ST_FALSE, *rId.GetResMgr() )),
3906 bModified(false)
3908 FreeResource();
3909 aCellCheckBox.GetBox().EnableTriState(sal_False);
3910 xController = new ::svt::EditCellController(&aCellEdit);
3911 xCheckController = new ::svt::CheckBoxCellController(&aCellCheckBox);
3913 //////////////////////////////////////////////////////////////////////
3914 // HACK: BrowseBox doesn't invalidate its children, how it should be.
3915 // That's why WB_CLIPCHILDREN is reset in order to enforce the
3916 // children' invalidation
3917 WinBits aStyle = GetStyle();
3918 if( aStyle & WB_CLIPCHILDREN )
3920 aStyle &= ~WB_CLIPCHILDREN;
3921 SetStyle( aStyle );
3923 const String* aTitles[7] =
3925 &sSearch,
3926 &sAlternative,
3927 &sPrimKey,
3928 &sSecKey,
3929 &sComment,
3930 &sCaseSensitive,
3931 &sWordOnly
3934 long nWidth = GetSizePixel().Width();
3935 nWidth /=7;
3936 --nWidth;
3937 for(sal_uInt16 i = 1; i < 8; i++)
3938 InsertDataColumn( i, *aTitles[i - 1], nWidth,
3939 HIB_STDSTYLE, HEADERBAR_APPEND );
3943 sal_Bool SwEntryBrowseBox::SeekRow( long nRow )
3945 nCurrentRow = nRow;
3946 return sal_True;
3949 String SwEntryBrowseBox::GetCellText(long nRow, sal_uInt16 nColumn) const
3951 const String* pRet = &aEmptyStr;
3952 if(static_cast<sal_uInt16>( aEntryArr.size() ) > nRow)
3954 const AutoMarkEntry* pEntry = &aEntryArr[ nRow ];
3955 switch(nColumn)
3957 case ITEM_SEARCH :pRet = &pEntry->sSearch; break;
3958 case ITEM_ALTERNATIVE :pRet = &pEntry->sAlternative; break;
3959 case ITEM_PRIM_KEY :pRet = &pEntry->sPrimKey ; break;
3960 case ITEM_SEC_KEY :pRet = &pEntry->sSecKey ; break;
3961 case ITEM_COMMENT :pRet = &pEntry->sComment ; break;
3962 case ITEM_CASE :pRet = pEntry->bCase ? &sYes : &sNo; break;
3963 case ITEM_WORDONLY :pRet = pEntry->bWord ? &sYes : &sNo; break;
3966 return *pRet;
3969 void SwEntryBrowseBox::PaintCell(OutputDevice& rDev,
3970 const Rectangle& rRect, sal_uInt16 nColumnId) const
3972 String sPaint = GetCellText( nCurrentRow, nColumnId );
3973 sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
3974 rDev.DrawText( rRect, sPaint, nStyle );
3977 ::svt::CellController* SwEntryBrowseBox::GetController(long /*nRow*/, sal_uInt16 nCol)
3979 return nCol < ITEM_CASE ? xController : xCheckController;
3982 sal_Bool SwEntryBrowseBox::SaveModified()
3984 SetModified();
3985 sal_uInt16 nRow = static_cast< sal_uInt16 >(GetCurRow());
3986 sal_uInt16 nCol = GetCurColumnId();
3988 String sNew;
3989 sal_Bool bVal = sal_False;
3990 ::svt::CellController* pController = 0;
3991 if(nCol < ITEM_CASE)
3993 pController = xController;
3994 sNew = ((::svt::EditCellController*)pController)->GetEditImplementation()->GetText( LINEEND_LF );
3996 else
3998 pController = xCheckController;
3999 bVal = ((::svt::CheckBoxCellController*)pController)->GetCheckBox().IsChecked();
4001 AutoMarkEntry* pEntry = nRow >= aEntryArr.size() ? new AutoMarkEntry
4002 : &aEntryArr[nRow];
4003 switch(nCol)
4005 case ITEM_SEARCH : pEntry->sSearch = sNew; break;
4006 case ITEM_ALTERNATIVE : pEntry->sAlternative = sNew; break;
4007 case ITEM_PRIM_KEY : pEntry->sPrimKey = sNew; break;
4008 case ITEM_SEC_KEY : pEntry->sSecKey = sNew; break;
4009 case ITEM_COMMENT : pEntry->sComment = sNew; break;
4010 case ITEM_CASE : pEntry->bCase = bVal; break;
4011 case ITEM_WORDONLY : pEntry->bWord = bVal; break;
4013 if(nRow >= aEntryArr.size())
4015 aEntryArr.push_back( pEntry );
4016 RowInserted(nRow, 1, sal_True, sal_True);
4017 if(nCol < ITEM_WORDONLY)
4019 pController->ClearModified();
4020 GoToRow( nRow );
4023 return sal_True;
4026 void SwEntryBrowseBox::InitController(
4027 ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol)
4029 String rTxt = GetCellText( nRow, nCol );
4030 if(nCol < ITEM_CASE)
4032 rController = xController;
4033 ::svt::CellController* pController = xController;
4034 ((::svt::EditCellController*)pController)->GetEditImplementation()->SetText( rTxt );
4036 else
4038 rController = xCheckController;
4039 ::svt::CellController* pController = xCheckController;
4040 ((::svt::CheckBoxCellController*)pController)->GetCheckBox().Check(
4041 rTxt == sYes );
4045 void SwEntryBrowseBox::ReadEntries(SvStream& rInStr)
4047 AutoMarkEntry* pToInsert = 0;
4048 rtl_TextEncoding eTEnc = osl_getThreadTextEncoding();
4049 while( !rInStr.GetError() && !rInStr.IsEof() )
4051 String sLine;
4052 rInStr.ReadByteStringLine( sLine, eTEnc );
4054 // # -> comment
4055 // ; -> delimiter between entries ->
4056 // Format: TextToSearchFor;AlternativeString;PrimaryKey;SecondaryKey
4057 // Leading and trailing blanks are ignored
4058 if( sLine.Len() )
4060 //comments are contained in separate lines but are put into the struct of the following data
4061 //line (if available)
4062 if( '#' != sLine.GetChar(0) )
4064 if( !pToInsert )
4065 pToInsert = new AutoMarkEntry;
4067 sal_Int32 nSttPos = 0;
4068 pToInsert->sSearch = sLine.GetToken(0, ';', nSttPos );
4069 pToInsert->sAlternative = sLine.GetToken(0, ';', nSttPos );
4070 pToInsert->sPrimKey = sLine.GetToken(0, ';', nSttPos );
4071 pToInsert->sSecKey = sLine.GetToken(0, ';', nSttPos );
4073 String sStr = sLine.GetToken(0, ';', nSttPos );
4074 pToInsert->bCase = sStr.Len() && !comphelper::string::equals(sStr, '0');
4076 sStr = sLine.GetToken(0, ';', nSttPos );
4077 pToInsert->bWord = sStr.Len() && !comphelper::string::equals(sStr, '0');
4079 aEntryArr.push_back( pToInsert );
4080 pToInsert = 0;
4082 else
4084 if(pToInsert)
4085 aEntryArr.push_back(pToInsert);
4086 pToInsert = new AutoMarkEntry;
4087 pToInsert->sComment = sLine;
4088 pToInsert->sComment.Erase(0, 1);
4092 if( pToInsert )
4093 aEntryArr.push_back(pToInsert);
4094 RowInserted(0, aEntryArr.size() + 1, sal_True);
4097 void SwEntryBrowseBox::WriteEntries(SvStream& rOutStr)
4099 //check if the current controller is modified
4100 sal_uInt16 nCol = GetCurColumnId();
4101 ::svt::CellController* pController;
4102 if(nCol < ITEM_CASE)
4103 pController = xController;
4104 else
4105 pController = xCheckController;
4106 if(pController ->IsModified())
4107 GoToColumnId(nCol < ITEM_CASE ? ++nCol : --nCol );
4109 rtl_TextEncoding eTEnc = osl_getThreadTextEncoding();
4110 for(sal_uInt16 i = 0; i < aEntryArr.size(); i++)
4112 AutoMarkEntry* pEntry = &aEntryArr[i];
4113 if(pEntry->sComment.Len())
4115 String sWrite = OUString('#');
4116 sWrite += pEntry->sComment;
4117 rOutStr.WriteByteStringLine( sWrite, eTEnc );
4120 String sWrite( pEntry->sSearch );
4121 sWrite += ';';
4122 sWrite += pEntry->sAlternative;
4123 sWrite += ';';
4124 sWrite += pEntry->sPrimKey;
4125 sWrite += ';';
4126 sWrite += pEntry->sSecKey;
4127 sWrite += ';';
4128 sWrite += pEntry->bCase ? '1' : '0';
4129 sWrite += ';';
4130 sWrite += pEntry->bWord ? '1' : '0';
4132 if( sWrite.Len() > 5 )
4133 rOutStr.WriteByteStringLine( sWrite, eTEnc );
4137 sal_Bool SwEntryBrowseBox::IsModified()const
4139 if(bModified)
4140 return sal_True;
4143 //check if the current controller is modified
4144 sal_uInt16 nCol = GetCurColumnId();
4145 ::svt::CellController* pController;
4146 if(nCol < ITEM_CASE)
4147 pController = xController;
4148 else
4149 pController = xCheckController;
4150 return pController ->IsModified();
4153 SwAutoMarkDlg_Impl::SwAutoMarkDlg_Impl(Window* pParent, const String& rAutoMarkURL,
4154 const String& rAutoMarkType, bool bCreate) :
4155 ModalDialog(pParent, SW_RES(DLG_CREATE_AUTOMARK)),
4156 aOKPB( this, SW_RES(PB_OK )),
4157 aCancelPB( this, SW_RES(PB_CANCEL )),
4158 aHelpPB( this, SW_RES(PB_HELP )),
4159 aEntriesBB( this, SW_RES(BB_ENTRIES )),
4160 aEntriesFL( this, SW_RES(FL_ENTRIES )),
4161 sAutoMarkURL(rAutoMarkURL),
4162 sAutoMarkType(rAutoMarkType),
4163 bCreateMode(bCreate)
4165 FreeResource();
4166 aOKPB.SetClickHdl(LINK(this, SwAutoMarkDlg_Impl, OkHdl));
4168 String sTitle = GetText();
4169 sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM(": "));
4170 sTitle += sAutoMarkURL;
4171 SetText(sTitle);
4172 bool bError = false;
4173 if( bCreateMode )
4174 aEntriesBB.RowInserted(0, 1, sal_True);
4175 else
4177 SfxMedium aMed( sAutoMarkURL, STREAM_STD_READ );
4178 if( aMed.GetInStream() && !aMed.GetInStream()->GetError() )
4179 aEntriesBB.ReadEntries( *aMed.GetInStream() );
4180 else
4181 bError = true;
4184 if(bError)
4185 EndDialog(RET_CANCEL);
4188 SwAutoMarkDlg_Impl::~SwAutoMarkDlg_Impl()
4192 IMPL_LINK_NOARG(SwAutoMarkDlg_Impl, OkHdl)
4194 bool bError = false;
4195 if(aEntriesBB.IsModified() || bCreateMode)
4197 SfxMedium aMed( sAutoMarkURL,
4198 bCreateMode ? STREAM_WRITE
4199 : STREAM_WRITE| STREAM_TRUNC );
4200 SvStream* pStrm = aMed.GetOutStream();
4201 pStrm->SetStreamCharSet( RTL_TEXTENCODING_MS_1253 );
4202 if( !pStrm->GetError() )
4204 aEntriesBB.WriteEntries( *pStrm );
4205 aMed.Commit();
4207 else
4208 bError = true;
4210 if( !bError )
4211 EndDialog(RET_OK);
4212 return 0;
4215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */