xref: /aoo4110/main/sw/source/ui/misc/outline.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #ifdef SW_DLLIMPLEMENTATION
27 #undef SW_DLLIMPLEMENTATION
28 #endif
29 #include <hintids.hxx>
30 #include <tools/shl.hxx>
31 #ifndef _MENU_HXX //autogen
32 #include <vcl/menu.hxx>
33 #endif
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
36 #endif
37 #include <sfx2/tabdlg.hxx>
38 #include <editeng/brshitem.hxx>
39 #include <unotools/configmgr.hxx>
40 #include <SwStyleNameMapper.hxx>
41 
42 #ifndef _NUM_HXX //autogen
43 #define USE_NUMTABPAGES
44 #include <num.hxx>
45 #endif
46 #ifndef _VIEW_HXX
47 #include <view.hxx>
48 #endif
49 #ifndef _DOCSH_HXX
50 #include <docsh.hxx>
51 #endif
52 #include <uitool.hxx>
53 #include <errhdl.hxx>
54 #include <wrtsh.hxx>
55 #include <swmodule.hxx>
56 #include <fmtcol.hxx>
57 #include <outline.hxx>
58 #include <uinums.hxx>
59 #include <poolfmt.hxx>
60 #include <shellres.hxx>
61 #include <svl/style.hxx>
62 #include <charfmt.hxx>
63 #include <docstyle.hxx>
64 #include <viewopt.hxx>
65 #include <svtools/ctrlbox.hxx>
66 #ifndef _HELPID_H
67 #include <helpid.h>
68 #endif
69 #ifndef _GLOBALS_HRC
70 #include <globals.hrc>		// fuer Vorlagenname 'keins'
71 #endif
72 #ifndef _MISC_HRC
73 #include <misc.hrc>
74 #endif
75 #ifndef _OUTLINE_HRC
76 #include <outline.hrc>
77 #endif
78 #include <paratr.hxx>
79 
80 #include <unomid.h>
81 
82 #include <IDocumentOutlineNodes.hxx>
83 // --> OD 2008-04-14 #outlinelevel#
84 #include <app.hrc>
85 // <--
86 
87 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
88 #include <com/sun/star/accessibility/AccessibleRole.hpp>
89 #endif
90 
91 using namespace ::com::sun::star;
92 
93 /* -----------------------------31.01.01 10:23--------------------------------
94 
95  ---------------------------------------------------------------------------*/
96 
97 DBG_NAME(outlinehdl)
98 
99 /*---------------------------------------------------------------------
100 
101 ---------------------------------------------------------------------*/
102 
103 class SwNumNamesDlg: public ModalDialog
104 {
105     FixedLine    aFormFL;
106 	Edit         aFormEdit;
107 	ListBox      aFormBox;
108 	OKButton     aOKBtn;
109 	CancelButton aCancelBtn;
110 	HelpButton   aHelpBtn;
111 
112 	DECL_LINK( ModifyHdl, Edit * );
113 	DECL_LINK( SelectHdl, ListBox * );
114 	DECL_LINK( DoubleClickHdl, ListBox * );
115 
116 public:
117 	SwNumNamesDlg(Window *pParent);
118 	~SwNumNamesDlg();
119 	void SetUserNames(const String *pList[]);
GetName() const120 	String GetName() const { return aFormEdit.GetText(); }
GetCurEntryPos() const121 	sal_uInt16 GetCurEntryPos() const { return aFormBox.GetSelectEntryPos(); }
122 };
123 
124 /*------------------------------------------------------------------------
125  Beschreibung:  selektierten Eintrag merken
126 ------------------------------------------------------------------------*/
127 
128 
IMPL_LINK_INLINE_START(SwNumNamesDlg,SelectHdl,ListBox *,pBox)129 IMPL_LINK_INLINE_START( SwNumNamesDlg, SelectHdl, ListBox *, pBox )
130 {
131 	aFormEdit.SetText(pBox->GetSelectEntry());
132 	aFormEdit.SetSelection(Selection(0, SELECTION_MAX));
133 	return 0;
134 }
IMPL_LINK_INLINE_END(SwNumNamesDlg,SelectHdl,ListBox *,pBox)135 IMPL_LINK_INLINE_END( SwNumNamesDlg, SelectHdl, ListBox *, pBox )
136 
137 /*------------------------------------------------------------------------
138  Beschreibung:  Setzen der vom Benutzer vergebenen Namen
139  Parameter:     Liste der vom Benutzer vergebenen Namen;
140 				nicht vom Benutzer benannte Positionen sind 0.
141 ------------------------------------------------------------------------*/
142 
143 
144 void SwNumNamesDlg::SetUserNames(const String *pList[])
145 {
146 	sal_uInt16 nSelect = 0;
147 	for(sal_uInt16 i = 0; i < SwBaseNumRules::nMaxRules; ++i)
148 	{
149 		if(pList[i])
150 		{
151 			aFormBox.RemoveEntry(i);
152 			aFormBox.InsertEntry(*pList[i], i);
153 			if(i == nSelect && nSelect < SwBaseNumRules::nMaxRules)
154 				nSelect++;
155 		}
156 	}
157 	aFormBox.SelectEntryPos(nSelect);
158 	SelectHdl(&aFormBox);
159 }
160 /*------------------------------------------------------------------------
161  Beschreibung:  OK-Button freischalten, wenn Text im Edit steht.
162 ------------------------------------------------------------------------*/
163 
164 
IMPL_LINK_INLINE_START(SwNumNamesDlg,ModifyHdl,Edit *,pBox)165 IMPL_LINK_INLINE_START( SwNumNamesDlg, ModifyHdl, Edit *, pBox )
166 {
167 	aOKBtn.Enable(0 != pBox->GetText().Len());
168 	return 0;
169 }
IMPL_LINK_INLINE_END(SwNumNamesDlg,ModifyHdl,Edit *,pBox)170 IMPL_LINK_INLINE_END( SwNumNamesDlg, ModifyHdl, Edit *, pBox )
171 /*------------------------------------------------------------------------
172  Beschreibung:  DoubleClickHdl
173 ------------------------------------------------------------------------*/
174 
175 
176 IMPL_LINK_INLINE_START( SwNumNamesDlg, DoubleClickHdl, ListBox *, EMPTYARG )
177 {
178 	EndDialog(RET_OK);
179 	return 0;
180 }
IMPL_LINK_INLINE_END(SwNumNamesDlg,DoubleClickHdl,ListBox *,EMPTYARG)181 IMPL_LINK_INLINE_END( SwNumNamesDlg, DoubleClickHdl, ListBox *, EMPTYARG )
182 
183 /*--------------------------------------------------
184 
185 --------------------------------------------------*/
186 
187 SwNumNamesDlg::SwNumNamesDlg(Window *pParent)
188 	: ModalDialog(pParent, SW_RES(DLG_NUM_NAMES)),
189 	aFormFL(this, SW_RES(FL_FORM)),
190     aFormEdit(this, SW_RES(ED_FORM)),
191 	aFormBox(this, SW_RES(LB_FORM)),
192 	aOKBtn(this, SW_RES(BT_OK)),
193 	aCancelBtn(this, SW_RES(BT_CANCEL)),
194 	aHelpBtn(this, SW_RES(BT_HELP))
195 {
196 	FreeResource();
197 	aFormEdit.SetModifyHdl(LINK(this, SwNumNamesDlg, ModifyHdl));
198 	aFormBox.SetSelectHdl(LINK(this, SwNumNamesDlg, SelectHdl));
199 	aFormBox.SetDoubleClickHdl(LINK(this, SwNumNamesDlg, DoubleClickHdl));
200 	SelectHdl(&aFormBox);
201 }
202 
203 /*--------------------------------------------------
204 
205 --------------------------------------------------*/
206 
~SwNumNamesDlg()207 __EXPORT SwNumNamesDlg::~SwNumNamesDlg() {}
208 
209 
210 /* -----------------08.07.98 08:46-------------------
211  *
212  * --------------------------------------------------*/
lcl_BitToLevel(sal_uInt16 nActLevel)213 sal_uInt16 lcl_BitToLevel(sal_uInt16 nActLevel)
214 {
215 	sal_uInt16 nTmp = nActLevel;
216 	sal_uInt16 nTmpLevel = 0;
217 	while( 0 != (nTmp >>= 1) )
218 		nTmpLevel++;
219 	return nTmpLevel;
220 }
221 
222 /* -----------------07.07.98 14:13-------------------
223  *
224  * --------------------------------------------------*/
225 sal_uInt16 SwOutlineTabDialog::nNumLevel = 1;
SwOutlineTabDialog(Window * pParent,const SfxItemSet * pSwItemSet,SwWrtShell & rSh)226 SwOutlineTabDialog::SwOutlineTabDialog(Window* pParent,
227 					const SfxItemSet* pSwItemSet,
228 					SwWrtShell &rSh) :
229 									//der UserString wird danach richtig gesetzt
230 		SfxTabDialog(pParent, SW_RES(DLG_TAB_OUTLINE), pSwItemSet, sal_False, &aEmptyStr),
231         aNullStr(C2S("____")),
232 		aFormMenu(SW_RES(MN_FORM)),
233         rWrtSh(rSh),
234 		pChapterNumRules(SW_MOD()->GetChapterNumRules()),
235         bModified(rWrtSh.IsModified())
236 {
237     // --> OD 2008-04-14 #outlinelevel#
238     SetText( SW_RES( STR_OUTLINE_NUMBERING ) );
239     // <--
240     PushButton* pUserButton = GetUserButton();
241     pUserButton->SetText(SW_RES(ST_FORM));
242     pUserButton->SetHelpId(HID_OUTLINE_FORM);
243     pUserButton->SetClickHdl(LINK(this, SwOutlineTabDialog, FormHdl));
244 	pUserButton->SetAccessibleRole( com::sun::star::accessibility::AccessibleRole::BUTTON_MENU );
245 
246 	FreeResource();
247 	pNumRule = new SwNumRule( *rSh.GetOutlineNumRule() );
248 	GetCancelButton().SetClickHdl(LINK(this, SwOutlineTabDialog, CancelHdl));
249 
250 	AddTabPage(TP_NUM_POSITION	 , &SwNumPositionTabPage::Create, 0);
251 	AddTabPage(TP_OUTLINE_NUM	 , &SwOutlineSettingsTabPage::Create, 0);
252 
253 	String sHeadline;
254 	sal_uInt16 i;
255 
256 	for( i = 0; i < MAXLEVEL; ++i )
257 	{
258 		// wurde die Vorlage noch nicht angelegt, dann ist sie noch an dieserPosition
259 		if( !rWrtSh.GetParaStyle( sHeadline =
260             SwStyleNameMapper::GetUIName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i),
261                                           sHeadline )) )
262 			aCollNames[i] = sHeadline;
263 	}
264 
265 	// Erfragen der Gliederungsebenen der Textvorlagen
266 	const sal_uInt16 nCount = rWrtSh.GetTxtFmtCollCount();
267 	for(i = 0; i < nCount; ++i )
268 	{
269 		SwTxtFmtColl &rTxtColl = rWrtSh.GetTxtFmtColl(i);
270 		if(!rTxtColl.IsDefault())
271 		{
272 			//sal_uInt8 nOutLevel = rTxtColl.GetOutlineLevel();	//<-#outline level, removed out by zhaojianwei
273 			//if(nOutLevel != NO_NUMBERING)
274 			//->added by zhaojianwei
275 			if(rTxtColl.IsAssignedToListLevelOfOutlineStyle())
276 			{
277 				int nOutLevel = rTxtColl.GetAssignedOutlineStyleLevel();
278 				aCollNames[ nOutLevel ] = rTxtColl.GetName();
279 			}
280 			//<-end
281 		}
282 	}
283 }
284 
285 /* -----------------07.07.98 14:13-------------------
286  *
287  * --------------------------------------------------*/
~SwOutlineTabDialog()288 SwOutlineTabDialog::~SwOutlineTabDialog()
289 {
290 	delete pNumRule;
291 }
292 
293 /* -----------------07.07.98 14:13-------------------
294  *
295  * --------------------------------------------------*/
PageCreated(sal_uInt16 nPageId,SfxTabPage & rPage)296 void 	SwOutlineTabDialog::PageCreated(sal_uInt16 nPageId, SfxTabPage& rPage)
297 {
298 	switch ( nPageId )
299 	{
300 		case TP_NUM_POSITION:
301                 ((SwNumPositionTabPage&)rPage).SetWrtShell(&rWrtSh);
302                 ((SwNumPositionTabPage&)rPage).SetOutlineTabDialog(this);
303 		break;
304 		case TP_OUTLINE_NUM:
305 				((SwOutlineSettingsTabPage&)rPage).SetWrtShell(&rWrtSh);
306 		break;
307 	}
308 }
309 /* -----------------07.07.98 14:19-------------------
310  *
311  * --------------------------------------------------*/
IMPL_LINK(SwOutlineTabDialog,CancelHdl,Button *,EMPTYARG)312 IMPL_LINK( SwOutlineTabDialog, CancelHdl, Button *, EMPTYARG )
313 {
314 	if (!bModified)
315 		rWrtSh.ResetModified();
316 	EndDialog(RET_CANCEL);
317 	return 0;
318 }
319 /* -----------------08.07.98 12:14-------------------
320  *
321  * --------------------------------------------------*/
IMPL_LINK(SwOutlineTabDialog,FormHdl,Button *,pBtn)322 IMPL_LINK( SwOutlineTabDialog, FormHdl, Button *, pBtn )
323 {
324 	//PopupMenu auffuellen
325 	for( sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i )
326 	{
327 		const SwNumRulesWithName *pRules = pChapterNumRules->GetRules(i);
328 		if( pRules )
329 			aFormMenu.SetItemText(i + MN_FORMBASE, pRules->GetName());
330 	}
331 	aFormMenu.SetSelectHdl(LINK(this, SwOutlineTabDialog, MenuSelectHdl));
332 	aFormMenu.Execute(pBtn, Rectangle(Point(0,0), pBtn->GetSizePixel()), POPUPMENU_EXECUTE_DOWN);
333 	return 0;
334 }
335 
336 /* -----------------08.07.98 12:14-------------------
337  *
338  * --------------------------------------------------*/
IMPL_LINK(SwOutlineTabDialog,MenuSelectHdl,Menu *,pMenu)339 IMPL_LINK( SwOutlineTabDialog, MenuSelectHdl, Menu *, pMenu )
340 {
341 	sal_uInt8 nLevelNo = 0;
342 	switch(pMenu->GetCurItemId())
343 	{
344 		case MN_FORM1: nLevelNo = 1;	break;
345 		case MN_FORM2: nLevelNo = 2;	break;
346 		case MN_FORM3: nLevelNo = 3;	break;
347 		case MN_FORM4: nLevelNo = 4;	break;
348 		case MN_FORM5: nLevelNo = 5;	break;
349 		case MN_FORM6: nLevelNo = 6;	break;
350 		case MN_FORM7: nLevelNo = 7;	break;
351 		case MN_FORM8: nLevelNo = 8;	break;
352 		case MN_FORM9: nLevelNo = 9;	break;
353 
354 		case MN_SAVE:
355 		{
356 			SwNumNamesDlg *pDlg = new SwNumNamesDlg(this);
357 			const String *aStrArr[SwChapterNumRules::nMaxRules];
358 			for(sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i)
359 			{
360 				const SwNumRulesWithName *pRules = pChapterNumRules->GetRules(i);
361 				if(pRules)
362 					aStrArr[i] = &pRules->GetName();
363 				else
364 					aStrArr[i] = 0;
365 			}
366 			pDlg->SetUserNames(aStrArr);
367 			if(RET_OK == pDlg->Execute())
368 			{
369 				const String aName(pDlg->GetName());
370 				pChapterNumRules->ApplyNumRules( SwNumRulesWithName(
371 						*pNumRule, aName ), pDlg->GetCurEntryPos() );
372 				pMenu->SetItemText(
373 						pDlg->GetCurEntryPos() + MN_FORMBASE, aName);
374 			}
375 			delete pDlg;
376 			return 0;
377 
378 		}
379 
380 	}
381 	if( nLevelNo-- )
382 	{
383 		const SwNumRulesWithName *pRules = pChapterNumRules->GetRules( nLevelNo );
384 		if( pRules )
385 		{
386 			pRules->MakeNumRule( rWrtSh, *pNumRule );
387 			pNumRule->SetRuleType( OUTLINE_RULE );
388 		}
389 		else
390 			*pNumRule = *rWrtSh.GetOutlineNumRule();
391 	}
392 
393 	sal_uInt16	nPageId = GetCurPageId();
394 	SfxTabPage*	pPage = GetTabPage( nPageId );
395 	pPage->Reset(*GetOutputItemSet());
396 
397 	return 0;
398 }
399 /* -----------------07.07.98 14:19-------------------
400  *
401  * --------------------------------------------------*/
GetLevel(const String & rFmtName) const402 sal_uInt16 	SwOutlineTabDialog::GetLevel(const String &rFmtName) const
403 {
404 	for(sal_uInt16 i = 0; i < MAXLEVEL; ++i)
405 	{
406 		if(aCollNames[i] == rFmtName)
407 			return i;
408 	}
409 	return MAXLEVEL;//NO_NUMBERING;	//#outline level,zhaojianwei
410 
411 }
412 /* -----------------07.07.98 16:30-------------------
413  *
414  * --------------------------------------------------*/
Ok()415 short SwOutlineTabDialog::Ok()
416 {
417     SfxTabDialog::Ok();
418 	// bei allen erzeugten Vorlagen die Ebenen setzen, muss
419 	// geschehen, um evtl. aufgehobene Zuordnungen
420 	// auch wieder zu loeschen
421 
422     // --> OD 2006-12-11 #130443#
423     // encapsulate changes into a action to avoid effects on the current cursor
424     // position during the changes.
425     rWrtSh.StartAction();
426     // <--
427 
428     const SwNumRule * pOutlineRule = rWrtSh.GetOutlineNumRule();
429 
430 	sal_uInt16 i, nCount = rWrtSh.GetTxtFmtCollCount();
431 	for( i = 0; i < nCount; ++i )
432 	{
433 		SwTxtFmtColl &rTxtColl = rWrtSh.GetTxtFmtColl(i);
434 		if( !rTxtColl.IsDefault() )
435         {
436 			//rTxtColl.SetOutlineLevel( (sal_uInt8)GetLevel(rTxtColl.GetName()));//#outline level,removed by zhaojianwei
437 
438             const SfxPoolItem & rItem =
439                 rTxtColl.GetFmtAttr(RES_PARATR_NUMRULE, sal_False);
440 
441 			//if ((sal_uInt8)GetLevel(rTxtColl.GetName()) == NO_NUMBERING)	//#outline level,removed by zhaojianwei
442 			//{
443 			//	if (static_cast<const SwNumRuleItem &>(rItem).GetValue() ==
444 			//		pOutlineRule->GetName())
445 			//	{
446 			//		rTxtColl.ResetFmtAttr(RES_PARATR_NUMRULE);
447 			//	}
448 			//}
449 			//else
450 			//{
451 			//	if (static_cast<const SwNumRuleItem &>(rItem).GetValue() !=
452 			//		pOutlineRule->GetName())
453 			//	{
454 			//		SwNumRuleItem aItem(pOutlineRule->GetName());
455 			//		rTxtColl.SetFmtAttr(aItem);
456 			//	}
457 			//}
458            if ((sal_uInt8)GetLevel(rTxtColl.GetName()) == MAXLEVEL) //add by zhaojianwei
459             {
460 			    if(rTxtColl.IsAssignedToListLevelOfOutlineStyle())
461 				{
462 					rTxtColl.DeleteAssignmentToListLevelOfOutlineStyle();
463 				}
464 				if (static_cast<const SwNumRuleItem &>(rItem).GetValue() ==
465                     pOutlineRule->GetName())
466                 {
467                     rTxtColl.ResetFmtAttr(RES_PARATR_NUMRULE);
468                 }
469             }
470             else
471             {
472 				rTxtColl.AssignToListLevelOfOutlineStyle(GetLevel(rTxtColl.GetName()));
473 
474 				if (static_cast<const SwNumRuleItem &>(rItem).GetValue() !=
475                     pOutlineRule->GetName())
476                 {
477                     SwNumRuleItem aItem(pOutlineRule->GetName());
478                     rTxtColl.SetFmtAttr(aItem);
479                 }
480             }							//<-end,zhaojianwei
481         }
482 	}
483 
484     for(i = 0; i < MAXLEVEL; ++i )
485     {
486         String sHeadline;
487         ::SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i),
488                                          sHeadline );
489         SwTxtFmtColl* pColl = rWrtSh.FindTxtFmtCollByName( sHeadline );
490         if( !pColl )
491         {
492 			//if( !aCollNames[i].Len() )			//#outline level,removed by zhaojianwei
493 			//{
494 			//	SwTxtFmtColl* pTxtColl = rWrtSh.GetTxtCollFromPool(
495 			//		static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i) );
496 			//	pTxtColl->SetOutlineLevel( NO_NUMBERING );
497 			//	pTxtColl->ResetFmtAttr(RES_PARATR_NUMRULE);
498 			//}
499 			//else if(aCollNames[i] != sHeadline)
500 			//{
501 			//	SwTxtFmtColl* pTxtColl = rWrtSh.GetParaStyle(
502 			//		aCollNames[i], SwWrtShell::GETSTYLE_CREATESOME);
503 			//	if(pTxtColl)
504 			//	{
505 			//		pTxtColl->SetOutlineLevel( static_cast< sal_uInt8 >(i) );
506 
507 			//		SwNumRuleItem aItem(pOutlineRule->GetName());
508 			//		pTxtColl->SetFmtAttr(aItem);
509 			//	}
510 			//}
511             if(aCollNames[i] != sHeadline)//->added by zhaojianwei
512             {
513 				SwTxtFmtColl* pTxtColl = rWrtSh.GetTxtCollFromPool(
514 					static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i) );
515 				pTxtColl->DeleteAssignmentToListLevelOfOutlineStyle();
516 				pTxtColl->ResetFmtAttr(RES_PARATR_NUMRULE);
517 
518 				if( aCollNames[i].Len() )
519 				{
520 					pTxtColl = rWrtSh.GetParaStyle(
521                                 aCollNames[i], SwWrtShell::GETSTYLE_CREATESOME);
522 					if(pTxtColl)
523 					{
524 						pTxtColl->AssignToListLevelOfOutlineStyle(i);
525 						SwNumRuleItem aItem(pOutlineRule->GetName());
526 						pTxtColl->SetFmtAttr(aItem);
527 					}
528                 }
529             }//<--end,zhaojianwei
530         }
531     }
532 
533 	rWrtSh.SetOutlineNumRule( *pNumRule);
534 
535     // --> OD 2006-12-11 #130443#
536     rWrtSh.EndAction();
537     // <--
538 
539 	return RET_OK;
540 }
541 
542 /* -----------------07.07.98 14:19-------------------
543  *
544  * --------------------------------------------------*/
SwOutlineSettingsTabPage(Window * pParent,const SfxItemSet & rSet)545 SwOutlineSettingsTabPage::SwOutlineSettingsTabPage(Window* pParent, const SfxItemSet& rSet) :
546 	SfxTabPage(pParent, SW_RES(TP_OUTLINE_NUM), rSet),
547     aLevelFL(       this, SW_RES(FL_LEVEL    )),
548     aLevelLB(       this, SW_RES(LB_LEVEL   )),
549 	aNumberFL(this, SW_RES(FL_NUMBER)),
550     aCollLbl(this, SW_RES(FT_COLL)),
551 	aCollBox(this, SW_RES(LB_COLL)),
552     aNumberLbl(this, SW_RES(FT_NUMBER)),
553     aNumberBox(this, SW_RES(LB_NUMBER), INSERT_NUM_TYPE_NO_NUMBERING|INSERT_NUM_EXTENDED_TYPES),
554 	aCharFmtFT(this, SW_RES(FT_CHARFMT)),
555 	aCharFmtLB(this, SW_RES(LB_CHARFMT)),
556 	aAllLevelFT(	this, SW_RES(FT_ALL_LEVEL)),
557 	aAllLevelNF(	this, SW_RES(NF_ALL_LEVEL)),
558 	aDelim(this, SW_RES(FT_DELIM)),
559 	aPrefixFT(this, SW_RES(FT_PREFIX)),
560 	aPrefixED(this, SW_RES(ED_PREFIX)),
561 	aSuffixFT(this, SW_RES(FT_SUFFIX)),
562 	aSuffixED(this, SW_RES(ED_SUFFIX)),
563 	aStartLbl(this, SW_RES(FT_START)),
564 	aStartEdit(this, SW_RES(ED_START)),
565     aPreviewWIN(    this, SW_RES(WIN_PREVIEW )),
566 
567     aNoFmtName(SW_RES(ST_NO_COLL)),
568     pSh(0),
569     pCollNames(0),
570     nActLevel(1)
571 {
572 	FreeResource();
573 	SetExchangeSupport();
574 
575 	aCollBox.InsertEntry(aNoFmtName);
576 	aLevelLB.SetSelectHdl(LINK(this, 	SwOutlineSettingsTabPage, LevelHdl));
577 	aAllLevelNF.SetModifyHdl(LINK(this, SwOutlineSettingsTabPage, ToggleComplete));
578 	aCollBox.SetSelectHdl(LINK(this, 	SwOutlineSettingsTabPage, CollSelect));
579 	aCollBox.SetGetFocusHdl(LINK(this, 	SwOutlineSettingsTabPage, CollSelectGetFocus));
580 	aNumberBox.SetSelectHdl(LINK(this, 	SwOutlineSettingsTabPage, NumberSelect));
581 	aPrefixED.SetModifyHdl(LINK(this, 	SwOutlineSettingsTabPage, DelimModify));
582 	aSuffixED.SetModifyHdl(LINK(this, 	SwOutlineSettingsTabPage, DelimModify));
583 	aStartEdit.SetModifyHdl(LINK(this, 	SwOutlineSettingsTabPage, StartModified));
584 	aCharFmtLB.SetSelectHdl(LINK(this, 	SwOutlineSettingsTabPage, CharFmtHdl));
585 
586 }
587 /* -----------------07.07.98 14:19-------------------
588  *
589  * --------------------------------------------------*/
Update()590 void   	SwOutlineSettingsTabPage::Update()
591 {
592 		// falls eine Vorlage fuer diese Ebene bereits selektiert wurde,
593 		// diese in der ListBox auswaehlean
594 	aCollBox.Enable(USHRT_MAX != nActLevel);
595 	if(USHRT_MAX == nActLevel)
596 	{
597 		sal_Bool bSamePrefix = sal_True;
598 		sal_Bool bSameSuffix = sal_True;
599 		sal_Bool bSameType = sal_True;
600 		sal_Bool bSameComplete = sal_True;
601 		sal_Bool bSameStart = sal_True;
602 		sal_Bool bSameCharFmt = sal_True;
603 
604 		const SwNumFmt* aNumFmtArr[MAXLEVEL];
605 		const SwCharFmt* pFirstFmt = 0;
606 
607 		for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
608 		{
609 
610 			aNumFmtArr[ i ] = &pNumRule->Get(i);
611 			if(i == 0)
612 				pFirstFmt = aNumFmtArr[i]->GetCharFmt();
613 			else
614 			{
615 				bSameType 	&= aNumFmtArr[i]->GetNumberingType() == aNumFmtArr[0]->GetNumberingType();
616 				bSameStart	&= aNumFmtArr[i]->GetStart() == aNumFmtArr[0]->GetStart();
617 				bSamePrefix &= aNumFmtArr[i]->GetPrefix() == aNumFmtArr[0]->GetPrefix();
618 				bSameSuffix &= aNumFmtArr[i]->GetSuffix() == aNumFmtArr[0]->GetSuffix();
619 				bSameComplete &= aNumFmtArr[i]->GetIncludeUpperLevels() == aNumFmtArr[0]->GetIncludeUpperLevels();
620 				const SwCharFmt* pFmt = aNumFmtArr[i]->GetCharFmt();
621 				bSameCharFmt &= 	(!pFirstFmt && !pFmt)
622 									|| (pFirstFmt && pFmt && pFmt->GetName() == pFirstFmt->GetName());
623 			}
624 		}
625         CheckForStartValue_Impl(aNumFmtArr[0]->GetNumberingType());
626         if(bSameType)
627 			aNumberBox.SelectNumberingType( aNumFmtArr[0]->GetNumberingType() );
628 		else
629 			aNumberBox.SetNoSelection();
630 		if(bSameStart)
631 			aStartEdit.SetValue(aNumFmtArr[0]->GetStart());
632 		else
633 			aStartEdit.SetText(aEmptyStr);
634 		if(bSamePrefix)
635 			aPrefixED.SetText(aNumFmtArr[0]->GetPrefix());
636 		else
637 			aPrefixED.SetText(aEmptyStr);
638 		if(bSameSuffix)
639 			aSuffixED.SetText(aNumFmtArr[0]->GetSuffix());
640 		else
641 			aSuffixED.SetText(aEmptyStr);
642 
643 		if(bSameCharFmt)
644 		{
645 			if(pFirstFmt)
646 				aCharFmtLB.SelectEntry(pFirstFmt->GetName());
647 			else
648 				aCharFmtLB.SelectEntry( ViewShell::GetShellRes()->aStrNone );
649 		}
650 		else
651 			aCharFmtLB.SetNoSelection();
652 
653 		aAllLevelFT.Enable(sal_True);
654 		aAllLevelNF.Enable(sal_True);
655 		aAllLevelNF.SetMax(MAXLEVEL);
656 		if(bSameComplete)
657 		{
658 			aAllLevelNF.SetValue(aNumFmtArr[0]->GetIncludeUpperLevels());
659 		}
660 		else
661 		{
662 			aAllLevelNF.SetText(aEmptyStr);
663 		}
664 	}
665 	else
666 	{
667 		sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel);
668 		String aColl(pCollNames[nTmpLevel]);
669 		if(aColl.Len())
670 			aCollBox.SelectEntry(aColl);
671 		else
672 			aCollBox.SelectEntry(aNoFmtName);
673 		const SwNumFmt &rFmt = pNumRule->Get(nTmpLevel);
674 
675 		aNumberBox.SelectNumberingType( rFmt.GetNumberingType() );
676 		aPrefixED.SetText(rFmt.GetPrefix());
677 		aSuffixED.SetText(rFmt.GetSuffix());
678 		const SwCharFmt* pFmt = rFmt.GetCharFmt();
679 		if(pFmt)
680 			aCharFmtLB.SelectEntry(pFmt->GetName());
681 		else
682 			aCharFmtLB.SelectEntry( ViewShell::GetShellRes()->aStrNone );
683 
684 		if(nTmpLevel)
685 		{
686 			aAllLevelFT.Enable(sal_True);
687 			aAllLevelNF.Enable(sal_True);
688 			aAllLevelNF.SetMax(nTmpLevel + 1);
689 			aAllLevelNF.SetValue(rFmt.GetIncludeUpperLevels());
690 		}
691 		else
692 		{
693 			aAllLevelNF.SetText(aEmptyStr);
694 			aAllLevelNF.Enable(sal_False);
695 			aAllLevelFT.Enable(sal_False);
696 		}
697         CheckForStartValue_Impl(rFmt.GetNumberingType());
698 		aStartEdit.SetValue( rFmt.GetStart() );
699 	}
700 	SetModified();
701 }
702 
703 /* -----------------07.07.98 14:19-------------------
704  *
705  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,LevelHdl,ListBox *,pBox)706 IMPL_LINK( SwOutlineSettingsTabPage, LevelHdl, ListBox *, pBox )
707 {
708 	nActLevel = 0;
709 	if(pBox->IsEntryPosSelected( MAXLEVEL ))
710 	{
711 		nActLevel = 0xFFFF;
712 	}
713 	else
714 	{
715 		sal_uInt16 nMask = 1;
716 		for( sal_uInt16 i = 0; i < MAXLEVEL; i++ )
717 		{
718 			if(pBox->IsEntryPosSelected( i ))
719 				nActLevel |= nMask;
720 			nMask <<= 1;
721 		}
722 	}
723 	Update();
724 	return 0;
725 }
726 /* -----------------07.07.98 14:19-------------------
727  *
728  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,ToggleComplete,NumericField *,pFld)729 IMPL_LINK( SwOutlineSettingsTabPage, ToggleComplete, NumericField *, pFld )
730 {
731 	sal_uInt16 nMask = 1;
732 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
733 	{
734 		if(nActLevel & nMask)
735 		{
736 			SwNumFmt aNumFmt(pNumRule->Get(i));
737 			aNumFmt.SetIncludeUpperLevels( Min( (sal_uInt8)pFld->GetValue(),
738 												(sal_uInt8)(i + 1)) );
739 			pNumRule->Set(i, aNumFmt);
740 		}
741 		nMask <<= 1;
742 	}
743 	SetModified();
744 	return 0;
745 }
746 /* -----------------07.07.98 14:19-------------------
747  *
748  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,CollSelect,ListBox *,pBox)749 IMPL_LINK( SwOutlineSettingsTabPage, CollSelect, ListBox *, pBox )
750 {
751 	sal_uInt8 i;
752 
753 	const String aCollName(pBox->GetSelectEntry());
754 	//0xFFFF darf hier nicht sein (disable)
755 	sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel);
756 	String sOldName( pCollNames[nTmpLevel] );
757 
758 	for( i = 0; i < MAXLEVEL; ++i)
759 		pCollNames[i] = aSaveCollNames[i];
760 
761 	if(aCollName == aNoFmtName)
762 		pCollNames[nTmpLevel] = aEmptyStr;
763 	else
764 	{
765 		pCollNames[nTmpLevel] = aCollName;
766 				// wird die Vorlage bereits verwendet ?
767 		for( i = 0; i < MAXLEVEL; ++i)
768 			if(i != nTmpLevel && pCollNames[i] == aCollName )
769 				pCollNames[i] = aEmptyStr;
770 	}
771 
772 	// search the oldname and put it into the current entries
773 	if( sOldName.Len() )
774 		for( i = 0; i < MAXLEVEL; ++i)
775 			if( aSaveCollNames[ i ] == sOldName && i != nTmpLevel &&
776 				!pCollNames[ i ].Len() )
777 			{
778 				sal_uInt8 n;
779 				for( n = 0; n < MAXLEVEL; ++n )
780 					if( pCollNames[ n ] == sOldName )
781 						break;
782 
783 				if( MAXLEVEL == n )
784 					// it was a outline leveld name and the current entries is zero.
785 					pCollNames[ i ] = sOldName;
786 			}
787 
788 	SetModified();
789 	return 0;
790 }
791 
IMPL_LINK(SwOutlineSettingsTabPage,CollSelectGetFocus,ListBox *,EMPTYARG)792 IMPL_LINK( SwOutlineSettingsTabPage, CollSelectGetFocus, ListBox *, EMPTYARG )
793 {
794 	for( sal_uInt8 i = 0; i < MAXLEVEL; ++i)
795 		aSaveCollNames[i] =  pCollNames[i];
796 	return 0;
797 }
798 
799 /* -----------------07.07.98 14:19-------------------
800  *
801  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,NumberSelect,SwNumberingTypeListBox *,pBox)802 IMPL_LINK( SwOutlineSettingsTabPage, NumberSelect, SwNumberingTypeListBox *, pBox )
803 {
804 	sal_uInt16 nMask = 1;
805 	sal_Int16 nNumberType = pBox->GetSelectedNumberingType();//(sal_Int16)(sal_uLong)pBox->GetEntryData(pBox->GetSelectEntryPos());
806 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
807 	{
808 		if(nActLevel & nMask)
809 		{
810 			SwNumFmt aNumFmt(pNumRule->Get(i));
811 			aNumFmt.SetNumberingType(nNumberType);
812 			pNumRule->Set(i, aNumFmt);
813             CheckForStartValue_Impl(nNumberType);
814         }
815 		nMask <<= 1;
816 	}
817 	SetModified();
818 	return 0;
819 }
820 /* -----------------07.07.98 14:19-------------------
821  *
822  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,DelimModify,Edit *,EMPTYARG)823 IMPL_LINK( SwOutlineSettingsTabPage, DelimModify, Edit *, EMPTYARG )
824 {
825 	sal_uInt16 nMask = 1;
826 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
827 	{
828 		if(nActLevel & nMask)
829 		{
830 			SwNumFmt aNumFmt(pNumRule->Get(i));
831 			aNumFmt.SetPrefix( aPrefixED.GetText() );
832 			aNumFmt.SetSuffix( aSuffixED.GetText() );
833 			pNumRule->Set(i, aNumFmt);
834 		}
835 		nMask <<= 1;
836 	}
837 	SetModified();
838 	return 0;
839 }
840 /* -----------------07.07.98 14:19-------------------
841  *
842  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,StartModified,NumericField *,pFld)843 IMPL_LINK( SwOutlineSettingsTabPage, StartModified, NumericField *, pFld )
844 {
845 	sal_uInt16 nMask = 1;
846 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
847 	{
848 		if(nActLevel & nMask)
849 		{
850 			SwNumFmt aNumFmt(pNumRule->Get(i));
851 			aNumFmt.SetStart( (sal_uInt16)pFld->GetValue() );
852 			pNumRule->Set(i, aNumFmt);
853 		}
854 		nMask <<= 1;
855 	}
856     SetModified();
857 	return 0;
858 }
859 /* -----------------21.09.98 12:21-------------------
860  *
861  * --------------------------------------------------*/
IMPL_LINK(SwOutlineSettingsTabPage,CharFmtHdl,ListBox *,EMPTYARG)862 IMPL_LINK( SwOutlineSettingsTabPage, CharFmtHdl, ListBox *, EMPTYARG )
863 {
864 //	bAutomaticCharStyles = sal_False;
865 	String sEntry = aCharFmtLB.GetSelectEntry();
866 	sal_uInt16 nMask = 1;
867 	sal_Bool bFormatNone = sEntry == ViewShell::GetShellRes()->aStrNone;
868 	SwCharFmt* pFmt = 0;
869 	if(!bFormatNone)
870 	{
871 		sal_uInt16 nChCount = pSh->GetCharFmtCount();
872 		for(sal_uInt16 i = 0; i < nChCount; i++)
873 		{
874 			SwCharFmt& rChFmt = pSh->GetCharFmt(i);
875 			if(rChFmt.GetName() == sEntry)
876 			{
877 				pFmt = &rChFmt;
878 				break;
879 			}
880 		}
881 		if(!pFmt)
882 		{
883 			SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
884 			SfxStyleSheetBase* pBase;
885 			pBase = pPool->Find(sEntry, SFX_STYLE_FAMILY_CHAR);
886 			if(!pBase)
887 				pBase = &pPool->Make(sEntry, SFX_STYLE_FAMILY_PAGE);
888 			pFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
889 
890 		}
891 	}
892 
893 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
894 	{
895 		if(nActLevel & nMask)
896 		{
897 			SwNumFmt aNumFmt(pNumRule->Get(i));
898 			if(bFormatNone)
899 				aNumFmt.SetCharFmt(0);
900 			else
901 				aNumFmt.SetCharFmt(pFmt);
902 			pNumRule->Set(i, aNumFmt);
903 		}
904 		nMask <<= 1;
905 	}
906 	return RET_OK;
907 }
908 /* -----------------07.07.98 14:19-------------------
909  *
910  * --------------------------------------------------*/
~SwOutlineSettingsTabPage()911 SwOutlineSettingsTabPage::~SwOutlineSettingsTabPage()
912 {
913 }
914 /* -----------------07.07.98 16:27-------------------
915  *
916  * --------------------------------------------------*/
SetWrtShell(SwWrtShell * pShell)917 void SwOutlineSettingsTabPage::SetWrtShell(SwWrtShell* pShell)
918 {
919 	pSh = pShell;
920 	// Erfragen der NumRules dieses Dokumentes
921 	pNumRule = ((SwOutlineTabDialog*)GetTabDialog())->GetNumRule();
922 	pCollNames = ((SwOutlineTabDialog*)GetTabDialog())->GetCollNames();
923 
924 	//pNumRule = new SwNumRule( *rSh.GetOutlineNumRule() );
925 
926 	aPreviewWIN.SetNumRule(pNumRule);
927 	aPreviewWIN.SetOutlineNames(pCollNames);
928 	// Startwert setzen - nActLevel muss hier 1 sein
929 	sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel);
930 	const SwNumFmt& rNumFmt = pNumRule->Get( nTmpLevel );
931 	aStartEdit.SetValue( rNumFmt.GetStart() );
932 
933 	// Poolformate fuer Ueberschriften anlegen
934 	String sStr;
935 	sal_uInt16 i;
936 	for( i = 0; i < MAXLEVEL; ++i )
937 	{
938 		aCollBox.InsertEntry( SwStyleNameMapper::GetUIName(
939                                     static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i), aEmptyStr ));
940 		aLevelLB.InsertEntry( String::CreateFromInt32(i + 1) );
941 	}
942 	sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "1 - " ));
943 	sStr += String::CreateFromInt32(MAXLEVEL);
944 	aLevelLB.InsertEntry( sStr );
945 
946 	// Erfragen der Gliederungsebenen der Textvorlagen
947 	const sal_uInt16 nCount = pSh->GetTxtFmtCollCount();
948 	for( i = 0; i < nCount; ++i )
949 	{
950 		SwTxtFmtColl &rTxtColl = pSh->GetTxtFmtColl(i);
951 		if(!rTxtColl.IsDefault())
952 		{
953 			sStr = rTxtColl.GetName();
954 			if(LISTBOX_ENTRY_NOTFOUND == aCollBox.GetEntryPos( sStr ))
955 				aCollBox.InsertEntry( sStr );
956 		}
957 	}
958 
959 	aNumberBox.SelectNumberingType(rNumFmt.GetNumberingType());
960 	sal_uInt16 nOutlinePos = pSh->GetOutlinePos(MAXLEVEL);
961 	sal_uInt16 nTmp = 0;
962 	if(nOutlinePos != USHRT_MAX)
963 	{
964         nTmp = static_cast<sal_uInt16>(pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos));
965 	}
966 	aLevelLB.SelectEntryPos(nTmp-1);//nTmp);//#outline level,zhaojianwei
967 
968 	// Zeichenvorlagen sammeln
969 	aCharFmtLB.Clear();
970 	aCharFmtLB.InsertEntry( ViewShell::GetShellRes()->aStrNone );
971 
972 	// Zeichenvorlagen
973 	::FillCharStyleListBox(aCharFmtLB,
974 						pSh->GetView().GetDocShell());
975 	Update();
976 }
977 /* -----------------07.07.98 14:19-------------------
978  *
979  * --------------------------------------------------*/
ActivatePage(const SfxItemSet &)980 void    SwOutlineSettingsTabPage::ActivatePage(const SfxItemSet& )
981 {
982     nActLevel = SwOutlineTabDialog::GetActNumLevel();
983 	if(nActLevel != USHRT_MAX)
984 		aLevelLB.SelectEntryPos(lcl_BitToLevel(nActLevel));
985 	else
986 		aLevelLB.SelectEntryPos(MAXLEVEL);
987 	LevelHdl(&aLevelLB);
988 }
989 /* -----------------07.07.98 14:19-------------------
990  *
991  * --------------------------------------------------*/
DeactivatePage(SfxItemSet *)992 int     SwOutlineSettingsTabPage::DeactivatePage(SfxItemSet*)
993 {
994     SwOutlineTabDialog::SetActNumLevel(nActLevel);
995 	return LEAVE_PAGE;
996 }
997 /* -----------------07.07.98 14:19-------------------
998  *
999  * --------------------------------------------------*/
FillItemSet(SfxItemSet &)1000 sal_Bool    SwOutlineSettingsTabPage::FillItemSet( SfxItemSet&  )
1001 {
1002 	return sal_True;
1003 }
1004 /* -----------------07.07.98 14:19-------------------
1005  *
1006  * --------------------------------------------------*/
Reset(const SfxItemSet & rSet)1007 void 	SwOutlineSettingsTabPage::Reset( const SfxItemSet& rSet )
1008 {
1009 	ActivatePage(rSet);
1010 }
1011 /* -----------------07.07.98 14:19-------------------
1012  *
1013  * --------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)1014 SfxTabPage*	SwOutlineSettingsTabPage::Create( Window* pParent,
1015 								const SfxItemSet& rAttrSet)
1016 {
1017 	return new SwOutlineSettingsTabPage(pParent, rAttrSet);
1018 }
1019 /* -----------------07.11.2002 15:13-----------------
1020  *
1021  * --------------------------------------------------*/
CheckForStartValue_Impl(sal_uInt16 nNumberingType)1022 void SwOutlineSettingsTabPage::CheckForStartValue_Impl(sal_uInt16 nNumberingType)
1023 {
1024     sal_Bool bIsNull = aStartEdit.GetValue() == 0;
1025     sal_Bool bNoZeroAllowed = nNumberingType < SVX_NUM_ARABIC ||
1026                         SVX_NUM_CHARS_UPPER_LETTER_N == nNumberingType ||
1027                         SVX_NUM_CHARS_LOWER_LETTER_N == nNumberingType;
1028     aStartEdit.SetMin(bNoZeroAllowed ? 1 : 0);
1029     if(bIsNull && bNoZeroAllowed)
1030         aStartEdit.GetModifyHdl().Call(&aStartEdit);
1031 }
1032 /*-----------------09.12.97 11:54-------------------
1033 
1034 --------------------------------------------------*/
lcl_DrawBullet(VirtualDevice * pVDev,const SwNumFmt & rFmt,sal_uInt16 nXStart,sal_uInt16 nYStart,const Size & rSize)1035 sal_uInt16 lcl_DrawBullet(VirtualDevice* pVDev,
1036 			const SwNumFmt& rFmt, sal_uInt16 nXStart,
1037 			sal_uInt16 nYStart, const Size& rSize)
1038 {
1039 	Font aTmpFont(pVDev->GetFont());
1040 
1041 	Font aFont(*rFmt.GetBulletFont());
1042 	aFont.SetSize(rSize);
1043 	aFont.SetTransparent(sal_True);
1044 	pVDev->SetFont( aFont );
1045 	String aText(rFmt.GetBulletChar());
1046 	pVDev->DrawText( Point(nXStart, nYStart), aText );
1047 	sal_uInt16 nRet = (sal_uInt16)pVDev->GetTextWidth(aText);
1048 
1049 	pVDev->SetFont(aTmpFont);
1050 	return nRet;
1051 }
1052 /*-----------------09.12.97 11:49-------------------
1053 
1054 --------------------------------------------------*/
lcl_DrawGraphic(VirtualDevice * pVDev,const SwNumFmt & rFmt,sal_uInt16 nXStart,sal_uInt16 nYStart,sal_uInt16 nDivision)1055 sal_uInt16 lcl_DrawGraphic(VirtualDevice* pVDev, const SwNumFmt &rFmt, sal_uInt16 nXStart,
1056 						sal_uInt16 nYStart, sal_uInt16 nDivision)
1057 {
1058 	const SvxBrushItem* pBrushItem = rFmt.GetBrush();
1059 	sal_uInt16 nRet = 0;
1060 	if(pBrushItem)
1061 	{
1062 		const Graphic* pGrf = pBrushItem->GetGraphic();
1063 		if(pGrf)
1064 		{
1065 			Size aGSize( rFmt.GetGraphicSize());
1066 			aGSize.Width() /= nDivision;
1067 			nRet = (sal_uInt16)aGSize.Width();
1068 			aGSize.Height() /= nDivision;
1069 			pGrf->Draw( pVDev, Point(nXStart,nYStart),
1070 					pVDev->PixelToLogic( aGSize ) );
1071 		}
1072 	}
1073 	return nRet;
1074 
1075 }
1076 /*-----------------02.12.97 10:34-------------------
1077 	Vorschau der Numerierung painten
1078 --------------------------------------------------*/
Paint(const Rectangle &)1079 void    NumberingPreview::Paint( const Rectangle& /*rRect*/ )
1080 {
1081 	Size aSize(PixelToLogic(GetOutputSizePixel()));
1082 	Rectangle aRect(Point(0,0), aSize);
1083 
1084 	VirtualDevice* pVDev = new VirtualDevice(*this);
1085 	pVDev->SetMapMode(GetMapMode());
1086 	pVDev->SetOutputSize( aSize );
1087 
1088 	// #101524# OJ
1089 	pVDev->SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
1090 	pVDev->SetLineColor( GetSettings().GetStyleSettings().GetButtonTextColor() );
1091 	pVDev->DrawRect(aRect);
1092 
1093 	if(pActNum)
1094 	{
1095 		sal_uInt16 nWidthRelation;
1096 		if(nPageWidth)
1097 		{
1098 			nWidthRelation = sal_uInt16 (nPageWidth / aSize.Width());
1099 			if(bPosition)
1100 				nWidthRelation = nWidthRelation * 2 / 3;
1101 			else
1102 				nWidthRelation = nWidthRelation / 4;
1103 		}
1104 		else
1105 			nWidthRelation = 30; // Kapiteldialog
1106 
1107 		//Hoehe pro Ebene
1108         sal_uInt16 nXStep = sal_uInt16(aSize.Width() / (3 * MAXLEVEL));
1109 		if(MAXLEVEL < 10)
1110 			nXStep /= 2;
1111 		sal_uInt16 nYStart = 4;
1112         sal_uInt16 nYStep = sal_uInt16((aSize.Height() - 6)/ MAXLEVEL);
1113         aStdFont = OutputDevice::GetDefaultFont(
1114                                     DEFAULTFONT_UI_SANS, (LanguageType)GetAppLanguage(),
1115 									DEFAULTFONT_FLAGS_ONLYONE, this );
1116 		// #101524# OJ
1117         aStdFont.SetColor( SwViewOption::GetFontColor() );
1118 
1119 		//
1120 		sal_uInt16 nFontHeight = nYStep * 6 / 10;
1121 		if(bPosition)
1122 			nFontHeight = nYStep * 15 / 10;
1123 		aStdFont.SetSize(Size( 0, nFontHeight ));
1124 
1125 		sal_uInt16 nPreNum = pActNum->Get(0).GetStart();
1126 
1127 		if(bPosition)
1128 		{
1129 			sal_uInt16 nLineHeight = nFontHeight * 8 / 7;
1130 			sal_uInt8 nStart = 0;
1131 			while( !(nActLevel & (1<<nStart)) )
1132 			{
1133 				nStart++;
1134 			}
1135 			if(nStart) // damit moeglichs Vorgaenger und Nachfolger gezeigt werden
1136 				nStart--;
1137 
1138             SwNumberTree::tNumberVector aNumVector;
1139 			sal_uInt8 nEnd = Min( (sal_uInt8)(nStart + 3), MAXLEVEL );
1140 			for( sal_uInt8 nLevel = nStart; nLevel < nEnd; ++nLevel )
1141 			{
1142 				const SwNumFmt &rFmt = pActNum->Get(nLevel);
1143 				aNumVector.push_back(rFmt.GetStart());
1144 
1145                 // --> OD 2008-02-01 #newlistlevelattrs#
1146                 sal_uInt16 nXStart( 0 );
1147                 short nTextOffset( 0 );
1148                 sal_uInt16 nNumberXPos( 0 );
1149                 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1150                 {
1151                     nXStart = rFmt.GetAbsLSpace() / nWidthRelation;
1152                     nTextOffset = rFmt.GetCharTextDistance() / nWidthRelation;
1153                     nNumberXPos = nXStart;
1154                     sal_uInt16 nFirstLineOffset = (-rFmt.GetFirstLineOffset()) / nWidthRelation;
1155 
1156                     if(nFirstLineOffset <= nNumberXPos)
1157                         nNumberXPos = nNumberXPos - nFirstLineOffset;
1158                     else
1159                         nNumberXPos = 0;
1160                 }
1161                 else if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1162                 {
1163                     const long nTmpNumberXPos( ( rFmt.GetIndentAt() +
1164                                                  rFmt.GetFirstLineIndent() ) /
1165                                                nWidthRelation );
1166                     if ( nTmpNumberXPos < 0 )
1167                     {
1168                         nNumberXPos = 0;
1169                     }
1170                     else
1171                     {
1172                         nNumberXPos = static_cast<sal_uInt16>(nTmpNumberXPos);
1173                     }
1174                 }
1175                 // <--
1176 
1177 				sal_uInt16 nBulletWidth = 0;
1178 				if( SVX_NUM_BITMAP == rFmt.GetNumberingType() )
1179 				{
1180 					nBulletWidth = lcl_DrawGraphic(pVDev, rFmt,
1181 										nNumberXPos,
1182 											nYStart, nWidthRelation);
1183 				}
1184 				else if( SVX_NUM_CHAR_SPECIAL == rFmt.GetNumberingType() )
1185 				{
1186 					nBulletWidth =  lcl_DrawBullet(pVDev, rFmt, nNumberXPos, nYStart, aStdFont.GetSize());
1187 				}
1188 				else
1189 				{
1190 					pVDev->SetFont(aStdFont);
1191 					if(pActNum->IsContinusNum())
1192 						aNumVector[nLevel] = nPreNum;
1193                     // --> OD 2005-11-17 #128041#
1194                     String aText(pActNum->MakeNumString( aNumVector ));
1195                     // <--
1196 					pVDev->DrawText( Point(nNumberXPos, nYStart), aText );
1197 					nBulletWidth = (sal_uInt16)pVDev->GetTextWidth(aText);
1198 					nPreNum++;
1199 				}
1200                 // --> OD 2008-02-01 #newlistlevelattrs#
1201                 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT &&
1202                      rFmt.GetLabelFollowedBy() == SvxNumberFormat::SPACE )
1203                 {
1204                     pVDev->SetFont(aStdFont);
1205                     String aText(' ');
1206                     pVDev->DrawText( Point(nNumberXPos, nYStart), aText );
1207                     nBulletWidth = nBulletWidth + (sal_uInt16)pVDev->GetTextWidth(aText);
1208                 }
1209                 // <--
1210 
1211                 // --> OD 2008-02-01 #newlistlevelattrs#
1212                 sal_uInt16 nTextXPos( 0 );
1213                 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1214                 {
1215                     nTextXPos = nXStart;
1216                     if(nTextOffset < 0)
1217                          nTextXPos = nTextXPos + nTextOffset;
1218                     if(nNumberXPos + nBulletWidth + nTextOffset > nTextXPos )
1219                         nTextXPos = nNumberXPos + nBulletWidth + nTextOffset;
1220                 }
1221                 else if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1222                 {
1223                     switch ( rFmt.GetLabelFollowedBy() )
1224                     {
1225                         case SvxNumberFormat::LISTTAB:
1226                         {
1227                             nTextXPos = static_cast<sal_uInt16>(
1228                                             rFmt.GetListtabPos() / nWidthRelation );
1229                             if ( nTextXPos < nNumberXPos + nBulletWidth )
1230                             {
1231                                 nTextXPos = nNumberXPos + nBulletWidth;
1232                             }
1233                         }
1234                         break;
1235                         case SvxNumberFormat::SPACE:
1236                         case SvxNumberFormat::NOTHING:
1237                         {
1238                             nTextXPos = nNumberXPos + nBulletWidth;
1239                         }
1240                         break;
1241                     }
1242 
1243                     nXStart = static_cast<sal_uInt16>( rFmt.GetIndentAt() / nWidthRelation );
1244                 }
1245                 // <--
1246 
1247 
1248                 Rectangle aRect1(Point(nTextXPos, nYStart + nFontHeight / 2), Size(aSize.Width() / 2, 2));
1249 				pVDev->SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() ); // Color( COL_BLACK ) );
1250 				pVDev->DrawRect( aRect1 );
1251 
1252 				Rectangle aRect2(Point(nXStart, nYStart + nLineHeight + nFontHeight / 2 ), Size(aSize.Width() / 2, 2));
1253 				pVDev->DrawRect( aRect2 );
1254 				nYStart += 2 * nLineHeight;
1255 			}
1256 		}
1257 		else
1258 		{
1259             SwNumberTree::tNumberVector aNumVector;
1260 			sal_uInt16 nLineHeight = nFontHeight * 3 / 2;
1261 			for( sal_uInt8 nLevel = 0; nLevel < MAXLEVEL;
1262                             ++nLevel, nYStart = nYStart + nYStep )
1263 			{
1264 				const SwNumFmt &rFmt = pActNum->Get(nLevel);
1265 				aNumVector.push_back(rFmt.GetStart());
1266                 // --> OD 2008-02-01 #newlistlevelattrs#
1267                 sal_uInt16 nXStart( 0 );
1268                 if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1269                 {
1270                     nXStart = rFmt.GetAbsLSpace() / nWidthRelation;
1271                 }
1272                 else if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1273                 {
1274                     const long nTmpXStart( ( rFmt.GetIndentAt() +
1275                                              rFmt.GetFirstLineIndent() ) /
1276                                            nWidthRelation );
1277                     if ( nTmpXStart < 0 )
1278                     {
1279                         nXStart = 0;
1280                     }
1281                     else
1282                     {
1283                         nXStart = static_cast<sal_uInt16>(nTmpXStart);
1284                     }
1285                 }
1286                 nXStart /= 2;
1287                 nXStart += 2;
1288                 // <--
1289 				sal_uInt16 nTextOffset = 2 * nXStep;
1290 				if( SVX_NUM_BITMAP == rFmt.GetNumberingType() )
1291 				{
1292 					lcl_DrawGraphic(pVDev, rFmt, nXStart, nYStart, nWidthRelation);
1293 					nTextOffset = nLineHeight + nXStep;
1294 				}
1295 				else if( SVX_NUM_CHAR_SPECIAL == rFmt.GetNumberingType() )
1296 				{
1297 					nTextOffset =  lcl_DrawBullet(pVDev, rFmt, nXStart, nYStart, aStdFont.GetSize());
1298                     nTextOffset = nTextOffset + nXStep;
1299 				}
1300 				else
1301 				{
1302 					pVDev->SetFont(aStdFont);
1303 					if(pActNum->IsContinusNum())
1304 						aNumVector[nLevel] = nPreNum;
1305                     // --> OD 2005-11-17 #128041#
1306                     String aText(pActNum->MakeNumString( aNumVector ));
1307                     // <--
1308 					pVDev->DrawText( Point(nXStart, nYStart), aText );
1309 					nTextOffset = (sal_uInt16)pVDev->GetTextWidth(aText);
1310                     nTextOffset = nTextOffset + nXStep;
1311 					nPreNum++;
1312 				}
1313 				pVDev->SetFont(aStdFont);
1314 
1315 				// Changed as per BugID 79541 Branding/Configuration
1316                 uno::Any MyAny = ::utl::ConfigManager::GetConfigManager()->
1317                         GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME );
1318                 ::rtl::OUString aProductName;
1319 
1320 				MyAny >>= aProductName;
1321 				String sMsg(C2S("%PRODUCTNAME"));
1322 				sMsg.SearchAndReplaceAscii( "%PRODUCTNAME" , aProductName );
1323 
1324 				if(pOutlineNames)
1325 					sMsg = pOutlineNames[nLevel];
1326 				pVDev->DrawText( Point(nXStart + nTextOffset, nYStart), sMsg );
1327 			}
1328 		}
1329 	}
1330 	DrawOutDev(	Point(0,0), aSize,
1331 				Point(0,0), aSize,
1332 						*pVDev );
1333 	delete pVDev;
1334 
1335 }
1336 
1337 /*-----------------02.12.97 10:34-------------------
1338 
1339 --------------------------------------------------*/
~NumberingPreview()1340 NumberingPreview::~NumberingPreview()
1341 {
1342 }
1343 
1344 
1345