xref: /trunk/main/sw/source/ui/frmdlg/column.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 #include "column.hxx"
36 
37 #include "hintids.hxx"
38 #include <svx/htmlmode.hxx>
39 #include <editeng/borderline.hxx>
40 #include <editeng/boxitem.hxx>
41 #include <editeng/lrspitem.hxx>
42 #include <editeng/sizeitem.hxx>
43 #include "editeng/frmdiritem.hxx"
44 #include <svl/ctloptions.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <vcl/msgbox.hxx>
47 #include <swmodule.hxx>
48 
49 #include <helpid.h>
50 #include "globals.hrc"
51 #include "swtypes.hxx"
52 #include "wrtsh.hxx"
53 #include "view.hxx"
54 #include "docsh.hxx"
55 #include "uitool.hxx"
56 #include "cmdid.h"
57 #include "viewopt.hxx"
58 #include "format.hxx"
59 #include "frmmgr.hxx"
60 #include "frmdlg.hxx"
61 #include "colmgr.hxx"
62 #include "prcntfld.hxx"
63 #include "paratr.hxx"
64 #include "frmui.hrc"
65 #include "poolfmt.hrc"
66 #include "column.hrc"
67 #include <section.hxx>
68 #include <docary.hxx>
69 #include <pagedesc.hxx>
70 
71 #include "access.hrc"
72 
73 #define FRAME_FORMAT_WIDTH 1000
74 
75 // sw/inc/fmtclds.hxx
76 SV_IMPL_PTRARR( SwColumns, SwColumnPtr )
77 
78 /*--------------------------------------------------------------------
79 	Beschreibung:  Statische Daten
80  --------------------------------------------------------------------*/
81 
82 static const sal_uInt16 __FAR_DATA nLines[] = {
83 	DEF_LINE_WIDTH_0,
84 	DEF_LINE_WIDTH_1,
85 	DEF_LINE_WIDTH_2,
86 	DEF_LINE_WIDTH_3,
87 	DEF_LINE_WIDTH_4
88 };
89 
90 static const sal_uInt16 nLineCount = sizeof(nLines) / sizeof(nLines[0]);
91 static const sal_uInt16 nVisCols = 3;
92 
93 inline sal_Bool IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect )
94 {
95 	rWrtSh.SwapPam();
96 	sal_Bool bRet = pSect == rWrtSh.GetCurrSection();
97 	rWrtSh.SwapPam();
98 	return bRet;
99 }
100 
101 /*--------------------------------------------------------------------
102 	Beschreibung:
103  --------------------------------------------------------------------*/
104 
105 SwColumnDlg::SwColumnDlg(Window* pParent, SwWrtShell& rSh) :
106 	SfxModalDialog(pParent, SW_RES(DLG_COLUMN)),
107 	aOK(this, 		SW_RES(PB_OK)),
108 	aCancel(this, 	SW_RES(PB_CANCEL)),
109 	aHelp(this, 	SW_RES(PB_HELP)),
110 	aApplyToFT(this, SW_RES(FT_APPLY_TO)),
111 	aApplyToLB(this, SW_RES(LB_APPLY_TO)),
112 	rWrtShell(rSh),
113 	pPageSet(0),
114 	pSectionSet(0),
115 	pSelectionSet(0),
116 	pFrameSet(0),
117 	nOldSelection(0),
118     nSelectionWidth(0),
119 	bPageChanged(sal_False),
120 	bSectionChanged(sal_False),
121 	bSelSectionChanged(sal_False),
122 	bFrameChanged(sal_False)
123 {
124 	FreeResource();
125 
126 	SwRect aRect;
127     rWrtShell.CalcBoundRect(aRect, FLY_AS_CHAR);
128 
129 	nSelectionWidth = aRect.Width();
130 
131 	SfxItemSet* pColPgSet = 0;
132 	static sal_uInt16 __READONLY_DATA aSectIds[] = { RES_COL, RES_COL,
133 												RES_FRM_SIZE, RES_FRM_SIZE,
134                                                 RES_COLUMNBALANCE, RES_FRAMEDIR,
135 												0 };
136 
137 	const SwSection* pCurrSection = rWrtShell.GetCurrSection();
138 	sal_uInt16 nFullSectCnt = rWrtShell.GetFullSelectedSectionCount();
139 	if( pCurrSection && ( !rWrtShell.HasSelection() || 0 != nFullSectCnt ))
140 	{
141 		nSelectionWidth = rSh.GetSectionWidth(*pCurrSection->GetFmt());
142 		if ( !nSelectionWidth )
143 			nSelectionWidth = USHRT_MAX;
144 		pSectionSet = new SfxItemSet( rWrtShell.GetAttrPool(), aSectIds );
145 		pSectionSet->Put( pCurrSection->GetFmt()->GetAttrSet() );
146 		pColPgSet = pSectionSet;
147 		aApplyToLB.RemoveEntry( aApplyToLB.GetEntryPos(
148 										(void*)( 1 >= nFullSectCnt
149 													? LISTBOX_SECTIONS
150 													: LISTBOX_SECTION )));
151 	}
152 	else
153 	{
154 		aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*) LISTBOX_SECTION ));
155 		aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*) LISTBOX_SECTIONS ));
156 	}
157 
158 	if( rWrtShell.HasSelection() && rWrtShell.IsInsRegionAvailable() &&
159 		( !pCurrSection || ( 1 != nFullSectCnt &&
160 			IsMarkInSameSection( rWrtShell, pCurrSection ) )))
161 	{
162 		pSelectionSet = new SfxItemSet( rWrtShell.GetAttrPool(), aSectIds );
163 		pColPgSet = pSelectionSet;
164 	}
165 	else
166 		aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*) LISTBOX_SELECTION ));
167 
168 	if( rWrtShell.GetFlyFrmFmt() )
169 	{
170 		const SwFrmFmt* pFmt = rSh.GetFlyFrmFmt() ;
171 		pFrameSet = new SfxItemSet(rWrtShell.GetAttrPool(), aSectIds );
172 		pFrameSet->Put(pFmt->GetFrmSize());
173 		pFrameSet->Put(pFmt->GetCol());
174 		pColPgSet = pFrameSet;
175 	}
176 	else
177 		aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*) LISTBOX_FRAME ));
178 
179 
180 	sal_uInt16 nPagePos = aApplyToLB.GetEntryPos( (void*) LISTBOX_PAGE );
181 	const SwPageDesc* pPageDesc = rWrtShell.GetSelectedPageDescs();
182 	if( pPageDesc )
183 	{
184 		pPageSet = new SfxItemSet( rWrtShell.GetAttrPool(),
185 									RES_COL, RES_COL,
186 									RES_FRM_SIZE, RES_FRM_SIZE,
187 									RES_LR_SPACE, RES_LR_SPACE,
188 									0 );
189 
190 		String sPageStr = aApplyToLB.GetEntry(nPagePos);
191 		aApplyToLB.RemoveEntry( nPagePos );
192 		sPageStr += pPageDesc->GetName();
193 		aApplyToLB.InsertEntry( sPageStr, nPagePos );
194 		aApplyToLB.SetEntryData( nPagePos, (void*) LISTBOX_PAGE);
195 
196 		const SwFrmFmt &rFmt = pPageDesc->GetMaster();
197 		nPageWidth = rFmt.GetFrmSize().GetSize().Width();
198 
199 		const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rFmt.GetLRSpace();
200         const SvxBoxItem& rBox = (const SvxBoxItem&) rFmt.GetBox();
201         nPageWidth -= rLRSpace.GetLeft() + rLRSpace.GetRight() + rBox.GetDistance();
202 
203 		pPageSet->Put(rFmt.GetCol());
204 		pPageSet->Put(rFmt.GetLRSpace());
205 		pColPgSet = pPageSet;
206 	}
207 	else
208 		aApplyToLB.RemoveEntry( nPagePos );
209 
210 
211 	ASSERT( pColPgSet, "" );
212 	// TabPage erzeugen
213 	SwColumnPage* pPage = (SwColumnPage*) SwColumnPage::Create( this,
214 																*pColPgSet );
215 	pTabPage = pPage;
216 
217 	//Groesse anpassen
218 	Size aPageSize(pTabPage->GetSizePixel());
219 	Size aDlgSize(GetOutputSizePixel());
220 	aDlgSize.Height() = aPageSize.Height();
221 	SetOutputSizePixel(aDlgSize);
222 	pTabPage->Show();
223 
224 	aApplyToLB.SelectEntryPos(0);
225 	ObjectHdl(0);
226 
227 	aApplyToLB.SetSelectHdl(LINK(this, SwColumnDlg, ObjectHdl));
228 	aOK.SetClickHdl(LINK(this, SwColumnDlg, OkHdl));
229     //#i80458# if no columns can be set then disable OK
230     if( !aApplyToLB.GetEntryCount() )
231         aOK.Enable( sal_False );
232     //#i97810# set focus to the TabPage
233     pTabPage->ActivateColumnControl();
234 }
235 
236 /*--------------------------------------------------------------------
237 	Beschreibung:
238  --------------------------------------------------------------------*/
239 
240 SwColumnDlg::~SwColumnDlg()
241 {
242 	delete pTabPage;
243 	delete pPageSet;
244 	delete pSectionSet;
245 	delete pSelectionSet;
246 }
247 
248 /* -----------------26.05.99 11:40-------------------
249  *
250  * --------------------------------------------------*/
251 IMPL_LINK(SwColumnDlg, ObjectHdl, ListBox*, pBox)
252 {
253 	SfxItemSet* pSet = 0;
254 	switch(nOldSelection)
255 	{
256 		case LISTBOX_SELECTION  :
257 			pSet = pSelectionSet;
258 		break;
259 		case LISTBOX_SECTION	:
260 			pSet = pSectionSet;
261 			bSectionChanged = sal_True;
262 		break;
263 		case LISTBOX_SECTIONS	:
264 			pSet = pSectionSet;
265 			bSelSectionChanged = sal_True;
266 		break;
267 		case LISTBOX_PAGE		:
268 			pSet = pPageSet;
269 			bPageChanged = sal_True;
270 		break;
271 		case LISTBOX_FRAME:
272 			pSet = pFrameSet;
273 			bFrameChanged = sal_True;
274 		break;
275 	}
276 	if(pBox)
277 	{
278 		pTabPage->FillItemSet(*pSet);
279 	}
280 	nOldSelection = (long)aApplyToLB.GetEntryData(aApplyToLB.GetSelectEntryPos());
281 	long nWidth = nSelectionWidth;
282 	switch(nOldSelection)
283 	{
284 		case LISTBOX_SELECTION  :
285 			pSet = pSelectionSet;
286             if( pSelectionSet )
287 			    pSet->Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth, nWidth));
288 		break;
289 		case LISTBOX_SECTION	:
290 		case LISTBOX_SECTIONS	:
291 			pSet = pSectionSet;
292 			pSet->Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth, nWidth));
293 		break;
294 		case LISTBOX_PAGE		:
295 			nWidth = nPageWidth;
296 			pSet = pPageSet;
297 			pSet->Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth, nWidth));
298 		break;
299 		case LISTBOX_FRAME:
300 			pSet = pFrameSet;
301 		break;
302 	}
303 
304     sal_Bool bIsSection = pSet == pSectionSet || pSet == pSelectionSet;
305     pTabPage->ShowBalance(bIsSection);
306     pTabPage->SetInSection(bIsSection);
307     pTabPage->SetFrmMode(sal_True);
308 	pTabPage->SetPageWidth(nWidth);
309 	if( pSet )
310         pTabPage->Reset(*pSet);
311 	return 0;
312 }
313 /* -----------------26.05.99 12:32-------------------
314  *
315  * --------------------------------------------------*/
316 IMPL_LINK(SwColumnDlg, OkHdl, OKButton*, EMPTYARG)
317 {
318 	//aktuelle Selektion auswerten
319 	SfxItemSet* pSet = 0;
320 	switch(nOldSelection)
321 	{
322 		case LISTBOX_SELECTION  :
323 			pSet = pSelectionSet;
324 		break;
325 		case LISTBOX_SECTION	:
326 			pSet = pSectionSet;
327 			bSectionChanged = sal_True;
328 		break;
329 		case LISTBOX_SECTIONS	:
330 			pSet = pSectionSet;
331 			bSelSectionChanged = sal_True;
332 		break;
333 		case LISTBOX_PAGE		:
334 			pSet = pPageSet;
335 			bPageChanged = sal_True;
336 		break;
337 		case LISTBOX_FRAME:
338 			pSet = pFrameSet;
339 			bFrameChanged = sal_True;
340 		break;
341 	}
342 	pTabPage->FillItemSet(*pSet);
343 
344 	if(pSelectionSet && SFX_ITEM_SET == pSelectionSet->GetItemState(RES_COL))
345 	{
346 		//Bereich mit Spalten einfuegen
347 		const SwFmtCol& rColItem = (const SwFmtCol&)pSelectionSet->Get(RES_COL);
348 		//nur, wenn es auch Spalten gibt!
349 		if(rColItem.GetNumCols() > 1)
350 			rWrtShell.GetView().GetViewFrame()->GetDispatcher()->Execute(
351                 FN_INSERT_REGION, SFX_CALLMODE_ASYNCHRON, *pSelectionSet );
352 	}
353 
354 	if(pSectionSet && pSectionSet->Count() && bSectionChanged )
355 	{
356 		const SwSection* pCurrSection = rWrtShell.GetCurrSection();
357 		const SwSectionFmt* pFmt = pCurrSection->GetFmt();
358 		sal_uInt16 nNewPos = rWrtShell.GetSectionFmtPos( *pFmt );
359         SwSectionData aData(*pCurrSection);
360         rWrtShell.UpdateSection( nNewPos, aData, pSectionSet );
361 	}
362 
363 	if(pSectionSet && pSectionSet->Count() && bSelSectionChanged )
364 	{
365 		rWrtShell.SetSectionAttr( *pSectionSet );
366 	}
367 
368 	if(pPageSet && SFX_ITEM_SET == pPageSet->GetItemState(RES_COL) && bPageChanged)
369 	{
370 		// aktuellen PageDescriptor ermitteln und damit den Set fuellen
371 		const sal_uInt16 nCurIdx = rWrtShell.GetCurPageDesc();
372 		SwPageDesc aPageDesc(rWrtShell.GetPageDesc(nCurIdx));
373 		SwFrmFmt &rFmt = aPageDesc.GetMaster();
374         rFmt.SetFmtAttr(pPageSet->Get(RES_COL));
375 		rWrtShell.ChgPageDesc(nCurIdx, aPageDesc);
376 	}
377 	if(pFrameSet && SFX_ITEM_SET == pFrameSet->GetItemState(RES_COL) && bFrameChanged)
378 	{
379 		SfxItemSet aTmp(*pFrameSet->GetPool(), RES_COL, RES_COL);
380 		aTmp.Put(*pFrameSet);
381 		rWrtShell.StartAction();
382 		rWrtShell.Push();
383 		rWrtShell.SetFlyFrmAttr( aTmp );
384 		//die Rahmenselektion wieder aufheben
385 		if(rWrtShell.IsFrmSelected())
386 		{
387 			rWrtShell.UnSelectFrm();
388 			rWrtShell.LeaveSelFrmMode();
389 		}
390 		rWrtShell.Pop();
391 		rWrtShell.EndAction();
392 	}
393 	EndDialog(RET_OK);
394 	return 0;
395 }
396 
397 /*--------------------------------------------------------------------
398 	Beschreibung:
399  --------------------------------------------------------------------*/
400 
401 #if OSL_DEBUG_LEVEL < 2
402 inline
403 #endif
404 sal_uInt16 GetMaxWidth( SwColMgr* pColMgr, sal_uInt16 nCols )
405 {
406 	sal_uInt16 nMax = pColMgr->GetActualSize();
407 	if( --nCols )
408 		nMax -= pColMgr->GetGutterWidth() * nCols;
409 	return nMax;
410 }
411 
412 static sal_uInt16 __FAR_DATA aPageRg[] = {
413 	RES_COL, RES_COL,
414 	0
415 };
416 
417 
418 DBG_NAME(columnhdl)
419 
420 
421 
422 sal_uInt16 lcl_LineWidthToPos(sal_uLong nWidth)
423 {
424 	const sal_uInt16 nUShortWidth = (sal_uInt16)nWidth;
425 	for(sal_uInt16 i = 0; i < nLineCount; ++i)
426 		if(nUShortWidth == nLines[i])
427 			return i;
428 	return 0;
429 }
430 
431 
432 
433 void SwColumnPage::ResetColWidth()
434 {
435 	if( nCols )
436 	{
437 		sal_uInt16 nWidth = GetMaxWidth( pColMgr, nCols );
438         nWidth = nWidth / nCols;
439 
440 		for(sal_uInt16 i = 0; i < nCols; ++i)
441 			nColWidth[i] = (long) nWidth;
442 	}
443 
444 }
445 
446 /*--------------------------------------------------------------------
447 	Beschreibung:	Jetzt als TabPage
448  --------------------------------------------------------------------*/
449 
450 
451 
452 SwColumnPage::SwColumnPage(Window *pParent, const SfxItemSet &rSet)
453 
454 	: SfxTabPage(pParent, SW_RES(TP_COLUMN), rSet),
455 
456     aFLGroup(this,          SW_RES(FL_COLUMNS )),
457     aClNrLbl(this,          SW_RES(FT_NUMBER  )),
458     aCLNrEdt(this,          SW_RES(ED_NUMBER  )),
459     aDefaultVS(this,        SW_RES(VS_DEFAULTS)),
460     aBalanceColsCB(this,    SW_RES(CB_BALANCECOLS)),
461 
462     aFLLayout(this,         SW_RES(FL_LAYOUT)),
463     aBtnUp(this,            SW_RES(BTN_DOWN)),
464     aColumnFT(this,         SW_RES(FT_COLUMN)),
465     aWidthFT(this,          SW_RES(FT_WIDTH)),
466     aDistFT(this,           SW_RES(FT_DIST)),
467     aLbl1(this,             SW_RES(FT_1)),
468     aEd1(this,              SW_RES(ED_1)),
469     aDistEd1(this,          SW_RES(ED_DIST1)),
470     aLbl2(this,             SW_RES(FT_2)),
471     aEd2(this,              SW_RES(ED_2)),
472     aDistEd2(this,          SW_RES(ED_DIST2)),
473     aLbl3(this,             SW_RES(FT_3)),
474     aEd3(this,              SW_RES(ED_3)),
475     aBtnDown(this,          SW_RES(BTN_UP)),
476     aAutoWidthBox(this,     SW_RES(CB_AUTO_WIDTH)),
477 
478     aFLLineType(this,       SW_RES(FL_LINETYPE)),
479     aLineTypeLbl(this,      SW_RES(FT_STYLE)),
480     aLineTypeDLB(this,      SW_RES(LB_STYLE)),
481     aLineHeightLbl(this,    SW_RES(FT_HEIGHT)),
482     aLineHeightEdit(this,   SW_RES(ED_HEIGHT)),
483     aLinePosLbl(this,       SW_RES(FT_POSITION)),
484     aLinePosDLB(this,       SW_RES(LB_POSITION)),
485 
486     aVertFL(this,         SW_RES(FL_VERT)),
487     aPropertiesFL(  this,    SW_RES( FL_PROPERTIES    )),
488     aTextDirectionFT( this,  SW_RES( FT_TEXTDIRECTION )),
489     aTextDirectionLB( this,  SW_RES( LB_TEXTDIRECTION )),
490 
491     aPgeExampleWN(this,     SW_RES(WN_BSP)),
492     aFrmExampleWN(this,     SW_RES(WN_BSP)),
493 
494     pColMgr(0),
495 
496     nFirstVis(0),
497     nMinWidth(MINLAY),
498     pModifiedField(0),
499     bFormat(sal_False),
500 	bFrm(sal_False),
501 	bHtmlMode(sal_False),
502 	bLockUpdate(sal_False)
503 {
504     sal_uInt16 i;
505 
506 	FreeResource();
507 	SetExchangeSupport();
508 
509 	aBtnDown.SetAccessibleRelationMemberOf(&aFLLayout);
510 	aEd1.SetAccessibleRelationLabeledBy(&aWidthFT);
511 	aEd2.SetAccessibleRelationLabeledBy(&aWidthFT);
512 	aEd3.SetAccessibleRelationLabeledBy(&aWidthFT);
513 	aDistEd1.SetAccessibleRelationLabeledBy(&aDistFT);
514 	aDistEd2.SetAccessibleRelationLabeledBy(&aDistFT);
515 	aBtnUp.SetAccessibleRelationLabeledBy(&aColumnFT);
516 	aBtnDown.SetAccessibleRelationLabeledBy(&aColumnFT);
517 
518     aDefaultVS.SetHelpId(HID_COLUMN_VALUESET);
519     aDefaultVS.SetColCount( 5 );
520 	aDefaultVS.SetStyle(  aDefaultVS.GetStyle()
521 							| WB_ITEMBORDER
522 							| WB_DOUBLEBORDER );
523 
524     for( i = 0; i < 5; i++)
525 		aDefaultVS.InsertItem( i + 1, i );
526 
527 	aDefaultVS.SetSelectHdl(LINK(this, SwColumnPage, SetDefaultsHdl));
528 
529 	// Controls fuer Zusaetzebereich beim MoreButton anmelden
530     Link aCLNrLk = LINK(this, SwColumnPage, ColModify);
531     aCLNrEdt.SetLoseFocusHdl(aCLNrLk);
532     aCLNrEdt.SetUpHdl(aCLNrLk);
533     aCLNrEdt.SetDownHdl(aCLNrLk);
534     Link aLk = LINK(this, SwColumnPage, GapModify);
535 	aDistEd1.SetUpHdl(aLk);
536 	aDistEd1.SetDownHdl(aLk);
537 	aDistEd1.SetLoseFocusHdl(aLk);
538 	aDistEd2.SetUpHdl(aLk);
539 	aDistEd2.SetDownHdl(aLk);
540 	aDistEd2.SetLoseFocusHdl(aLk);
541 
542 	aLk = LINK(this, SwColumnPage, EdModify);
543 
544 	aEd1.SetUpHdl(aLk);
545 	aEd1.SetDownHdl(aLk);
546 	aEd1.SetLoseFocusHdl(aLk);
547 
548 	aEd2.SetUpHdl(aLk);
549 	aEd2.SetDownHdl(aLk);
550 	aEd2.SetLoseFocusHdl(aLk);
551 
552 	aEd3.SetUpHdl(aLk);
553 	aEd3.SetDownHdl(aLk);
554 	aEd3.SetLoseFocusHdl(aLk);
555 
556 	aBtnUp.SetClickHdl(LINK(this, SwColumnPage, Up));
557 	aBtnDown.SetClickHdl(LINK(this, SwColumnPage, Down));
558 	aAutoWidthBox.SetClickHdl(LINK(this, SwColumnPage, AutoWidthHdl));
559 
560 	aLk = LINK( this, SwColumnPage, UpdateColMgr );
561 	aLineTypeDLB.SetSelectHdl( aLk );
562 	aLineHeightEdit.SetModifyHdl( aLk );
563 	aLinePosDLB.SetSelectHdl( aLk );
564 
565 		// Trennlinie
566 	aLineTypeDLB.SetUnit( FUNIT_POINT );
567 	aLineTypeDLB.SetSourceUnit( FUNIT_TWIP );
568 	for( i = 0; i < nLineCount; ++i )
569 		aLineTypeDLB.InsertEntry( 100 * nLines[ i ] );
570 }
571 
572 
573 
574 SwColumnPage::~SwColumnPage()
575 {
576 	delete pColMgr;
577 }
578 
579 /*--------------------------------------------------------------------
580 	Beschreibung:
581  --------------------------------------------------------------------*/
582 
583 
584 void SwColumnPage::SetPageWidth(long nPageWidth)
585 {
586     long nNewMaxWidth = static_cast< long >(aEd1.NormalizePercent(nPageWidth));
587 
588 	aDistEd1.SetMax(nNewMaxWidth, FUNIT_TWIP);
589 	aDistEd2.SetMax(nNewMaxWidth, FUNIT_TWIP);
590 	aEd1.SetMax(nNewMaxWidth, FUNIT_TWIP);
591 	aEd2.SetMax(nNewMaxWidth, FUNIT_TWIP);
592 	aEd3.SetMax(nNewMaxWidth, FUNIT_TWIP);
593 }
594 
595 /*--------------------------------------------------------------------
596 	Beschreibung:
597  --------------------------------------------------------------------*/
598 
599 
600 
601 void SwColumnPage::Reset(const SfxItemSet &rSet)
602 {
603 	sal_uInt16 nHtmlMode = ::GetHtmlMode((const SwDocShell*)SfxObjectShell::Current());
604 	if(nHtmlMode & HTMLMODE_ON)
605 	{
606 		bHtmlMode = sal_True;
607 		aAutoWidthBox.Enable(sal_False);
608 	}
609 	FieldUnit aMetric = ::GetDfltMetric(bHtmlMode);
610 	SetMetric(aEd1, aMetric);
611 	SetMetric(aEd2, aMetric);
612 	SetMetric(aEd3, aMetric);
613 	SetMetric(aDistEd1, aMetric);
614 	SetMetric(aDistEd2, aMetric);
615 
616 	delete pColMgr;
617 	pColMgr = new SwColMgr(rSet);
618 	nCols 	= pColMgr->GetCount() ;
619 	aCLNrEdt.SetMax(Max((sal_uInt16)aCLNrEdt.GetMax(), (sal_uInt16)nCols));
620 	aCLNrEdt.SetLast(Max(nCols,(sal_uInt16)aCLNrEdt.GetMax()));
621 
622 	if(bFrm)
623 	{
624 		if(bFormat)                     // hier gibt es keine Size
625 			pColMgr->SetActualWidth(FRAME_FORMAT_WIDTH);
626 		else
627 		{
628 			const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE);
629 			const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
630 			pColMgr->SetActualWidth((sal_uInt16)rSize.GetSize().Width() - rBox.GetDistance());
631 		}
632 	}
633     if(aBalanceColsCB.IsVisible())
634 	{
635         const SfxPoolItem* pItem;
636         if( SFX_ITEM_SET == rSet.GetItemState( RES_COLUMNBALANCE, sal_False, &pItem ))
637 			aBalanceColsCB.Check(!((const SwFmtNoBalancedColumns*)pItem)->GetValue());
638 		else
639 			aBalanceColsCB.Check( sal_True );
640 	}
641 
642     //text direction
643     if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( RES_FRAMEDIR ) )
644 	{
645         const SvxFrameDirectionItem& rItem = (const SvxFrameDirectionItem&)rSet.Get(RES_FRAMEDIR);
646         sal_uInt32 nVal  = rItem.GetValue();
647         sal_uInt16 nPos = aTextDirectionLB.GetEntryPos( (void*) nVal );
648         aTextDirectionLB.SelectEntryPos( nPos );
649         aTextDirectionLB.SaveValue();
650 	}
651 
652     Init();
653 	ActivatePage( rSet );
654 }
655 
656 /*--------------------------------------------------------------------
657 	Beschreibung:	TabPage erzeugen
658  --------------------------------------------------------------------*/
659 
660 
661 
662 SfxTabPage* SwColumnPage::Create(Window *pParent, const SfxItemSet &rSet)
663 {
664 	return new SwColumnPage(pParent, rSet);
665 }
666 
667 /*--------------------------------------------------------------------
668 	Beschreibung:	Attribute in den Set stopfen bei OK
669  --------------------------------------------------------------------*/
670 
671 
672 
673 sal_Bool SwColumnPage::FillItemSet(SfxItemSet &rSet)
674 {
675     if(aCLNrEdt.HasChildPathFocus())
676         aCLNrEdt.GetDownHdl().Call(&aCLNrEdt);
677     // Im ItemSet setzen
678 	// Die aktuellen Einstellungen sind
679 	// schon vorhanden
680 	//
681 	const SfxPoolItem* pOldItem;
682 	const SwFmtCol& rCol = pColMgr->GetColumns();
683 	if(0 == (pOldItem = GetOldItem( rSet, RES_COL )) ||
684 				rCol != *pOldItem )
685 		rSet.Put(rCol);
686 
687 	if(aBalanceColsCB.IsVisible() )
688 	{
689 		rSet.Put(SwFmtNoBalancedColumns(!aBalanceColsCB.IsChecked() ));
690 	}
691     sal_uInt16 nPos;
692     if( aTextDirectionLB.IsVisible() &&
693         ( nPos = aTextDirectionLB.GetSelectEntryPos() ) !=
694                                             aTextDirectionLB.GetSavedValue() )
695 	{
696         sal_uInt32 nDirection = (sal_uInt32)(sal_IntPtr)aTextDirectionLB.GetEntryData( nPos );
697         rSet.Put( SvxFrameDirectionItem( (SvxFrameDirection)nDirection, RES_FRAMEDIR));
698 	}
699     return sal_True;
700 }
701 
702 /*--------------------------------------------------------------------
703 	Beschreibung:	ColumnManager updaten
704  --------------------------------------------------------------------*/
705 
706 
707 
708 IMPL_LINK( SwColumnPage, UpdateColMgr, void *, /*pField*/ )
709 {
710 	long nGutterWidth = pColMgr->GetGutterWidth();
711 	if(nCols > 1)
712 	{
713 			// Ermitteln, ob die schmalste Spalte zu schmal ist
714 			// fuer den eingestellten Spaltenabstand
715 		long nMin = nColWidth[0];
716 		sal_uInt16 i;
717 
718 		for( i = 1; i < nCols; ++i)
719 			nMin = Min(nMin, nColWidth[i]);
720 
721 		sal_Bool bAutoWidth = aAutoWidthBox.IsChecked();
722 		if(!bAutoWidth)
723 		{
724 			pColMgr->SetAutoWidth(sal_False);
725 				// falls der Benutzer nicht die Gesamtbreite vergeben hat,
726 				// den fehlenden Betrag auf die letzte Spalte addieren.
727 			long nSum = 0;
728 			for(i = 0; i < nCols; ++i)
729 				nSum += nColWidth[i];
730 			nGutterWidth = 0;
731 			for(i = 0; i < nCols - 1; ++i)
732 				nGutterWidth += nColDist[i];
733 			nSum += nGutterWidth;
734 
735 			long nMaxW = pColMgr->GetActualSize();
736 
737 			if( nSum < nMaxW  )
738 				nColWidth[nCols - 1] += nMaxW - nSum;
739 
740             pColMgr->SetColWidth( 0, static_cast< sal_uInt16 >(nColWidth[0] + (sal_uInt16)nColDist[0]/2) );
741 			for( i = 1; i < nCols-1; ++i )
742 			{
743 				long nActDist = (nColDist[i] + nColDist[i - 1]) / 2;
744 				pColMgr->SetColWidth( i, (sal_uInt16)nColWidth[i] + (sal_uInt16)nActDist );
745 			}
746             pColMgr->SetColWidth( nCols-1, static_cast< sal_uInt16 >(nColWidth[nCols-1] + nColDist[nCols -2]/2) );
747 
748 		}
749 
750 			// keins ist ausgeschaltet
751         const sal_uInt16 nPos = aLineTypeDLB.GetSelectEntryPos();
752         sal_Bool bEnable = 0 != nPos;
753 		aLineHeightEdit.Enable( bEnable );
754 		aLineHeightLbl.Enable( bEnable );
755 		if( !bEnable )
756 			pColMgr->SetNoLine();
757 		else if( LISTBOX_ENTRY_NOTFOUND != nPos )
758 		{
759 			pColMgr->SetLineWidthAndColor(nLines[nPos - 1], Color(COL_BLACK) );
760 			pColMgr->SetAdjust( SwColLineAdj(
761 									aLinePosDLB.GetSelectEntryPos() + 1) );
762 			pColMgr->SetLineHeightPercent((short)aLineHeightEdit.GetValue());
763 			bEnable = pColMgr->GetLineHeightPercent() != 100;
764 		}
765 		aLinePosLbl.Enable( bEnable );
766 		aLinePosDLB.Enable( bEnable );
767 	}
768 	else
769 	{
770 		pColMgr->NoCols();
771         nCols = 0;
772 	}
773 
774 	//Maximalwerte setzen
775 	aCLNrEdt.SetMax(Max(1L,
776 		Min(long(nMaxCols), long( pColMgr->GetActualSize() / (nGutterWidth + MINLAY)) )));
777 	aCLNrEdt.SetLast(aCLNrEdt.GetMax());
778 	aCLNrEdt.Reformat();
779 
780 	//Beispielfenster anregen
781 	if(!bLockUpdate)
782 	{
783 		if(bFrm)
784 		{
785 			aFrmExampleWN.SetColumns( pColMgr->GetColumns() );
786 			aFrmExampleWN.Invalidate();
787 		}
788 		else
789 			aPgeExampleWN.Invalidate();
790 	}
791 
792 	return 0;
793 }
794 
795 /*------------------------------------------------------------------------
796  Beschreibung:	Initialisierung
797 ------------------------------------------------------------------------*/
798 
799 
800 
801 void SwColumnPage::Init()
802 {
803 	aCLNrEdt.SetValue(nCols);
804 
805     sal_Bool bAutoWidth = pColMgr->IsAutoWidth() || bHtmlMode;
806     aAutoWidthBox.Check( bAutoWidth );
807 
808     sal_Int32 nColumnWidthSum = 0;
809     // Setzen der Breiten
810     sal_uInt16 i;
811     for(i = 0; i < nCols; ++i)
812 	{
813 		nColWidth[i] = pColMgr->GetColWidth(i);
814         nColumnWidthSum += nColWidth[i];
815 		if(i < nCols - 1)
816 			nColDist[i] = pColMgr->GetGutterWidth(i);
817 	}
818 
819 	if( 1 < nCols )
820 	{
821         // #97495# make sure that the automatic column widht's are always equal
822         if(bAutoWidth)
823         {
824             nColumnWidthSum /= nCols;
825             for(i = 0; i < nCols; ++i)
826                 nColWidth[i] = nColumnWidthSum;
827         }
828         SwColLineAdj eAdj = pColMgr->GetAdjust();
829 		if( COLADJ_NONE == eAdj )		// der Dialog kennt kein NONE!
830 		{
831 			eAdj = COLADJ_TOP;
832 			//ohne Adjust auch kein Linientyp
833 			aLineTypeDLB.SelectEntryPos( 0 );
834 			aLineHeightEdit.SetValue( 100 );
835 		}
836 		else
837 		{
838 			aLineTypeDLB.SelectEntryPos( lcl_LineWidthToPos(( pColMgr->GetLineWidth() )) + 1);
839 			aLineHeightEdit.SetValue( pColMgr->GetLineHeightPercent() );
840 		}
841         aLinePosDLB.SelectEntryPos( static_cast< sal_uInt16 >(eAdj - 1) );
842 	}
843 	else
844 	{
845 		aLinePosDLB.SelectEntryPos( 0 );
846 		aLineTypeDLB.SelectEntryPos( 0 );
847 		aLineHeightEdit.SetValue( 100 );
848 	}
849 
850 	UpdateCols();
851 	Update();
852 
853 		// Maximale Spaltenzahl setzen
854 		// Werte kleiner als 1 sind nicht erlaubt
855 	aCLNrEdt.SetMax(Max(1L,
856 		Min(long(nMaxCols), long( pColMgr->GetActualSize() / nMinWidth) )));
857 }
858 
859 /*------------------------------------------------------------------------
860  Beschreibung:	Die Anzahl der Spalten hat sich veraendert -- hier werden
861 				die Controls fuer die Bearbeitung der Spalten entsprechend
862 				der Spaltenzahl en- oder disabled.
863 				Falls es mehr als nVisCols (= 3) Spalten gibt, werden
864 				alle Edit enabled und die Buttons fuer das Scrollen
865 				ebenfalls.
866 				Andernfalls werden die Edits jeweils fuer die entsprechenden
867 				Spaltenzahl enabled; eine Spalte kann nicht bearbeitet werden.
868 ------------------------------------------------------------------------*/
869 
870 
871 
872 void SwColumnPage::UpdateCols()
873 {
874 	sal_Bool bEnableBtns= sal_False;
875 	sal_Bool bEnable12	= sal_False;
876 	sal_Bool bEnable3	= sal_False;
877 	const sal_Bool bEdit = !aAutoWidthBox.IsChecked();
878 	if ( nCols > nVisCols )
879 	{
880 		bEnableBtns = sal_True && !bHtmlMode;
881 		bEnable12 = bEnable3 = bEdit;
882 	}
883 	else if( bEdit )
884 	{
885 		// hier gibt es absichtlich kaum noch breaks
886 		switch(nCols)
887 		{
888 			case 3: bEnable3 = sal_True;
889 			case 2: bEnable12= sal_True; break;
890 			default: /* do nothing */;
891 		}
892 	}
893 	aEd1.Enable( bEnable12 );
894 	aDistEd1.Enable(nCols > 1);
895 	aEd2.Enable( bEnable12 );
896 	aDistEd2.Enable(bEnable3);
897 	aEd3.Enable( bEnable3  );
898     aLbl1.Enable(bEnable12 );
899     aLbl2.Enable(bEnable12 );
900     aLbl3.Enable(bEnable3  );
901 	aBtnUp.Enable( bEnableBtns );
902 	aBtnDown.Enable( bEnableBtns );
903 
904 	const sal_Bool bEnable = nCols > 1;
905 	if( !bEnable )
906 	{
907 		aLinePosDLB.Enable( sal_False );
908 		aLinePosLbl.Enable( sal_False );
909 	}
910 	aLineHeightEdit.Enable( bEnable );
911 	aLineHeightLbl.Enable( bEnable );
912 	aLineTypeDLB.Enable( bEnable );
913 	aLineTypeLbl.Enable( bEnable );
914 	aAutoWidthBox.Enable( bEnable && !bHtmlMode );
915 }
916 
917 void SwColumnPage::SetLabels( sal_uInt16 nVis )
918 {
919 	String sLbl( '~' );
920 
921 	String sLbl2( String::CreateFromInt32( nVis + 1 ));
922 	String tmp1(sLbl2);
923 	sLbl2.Insert(sLbl, sLbl2.Len() - 1);
924     aLbl1.SetText(sLbl2);
925 
926 	sLbl2 = String::CreateFromInt32( nVis + 2 );
927 	String tmp2(sLbl2);
928 	sLbl2.Insert(sLbl, sLbl2.Len() - 1);
929     aLbl2.SetText(sLbl2);
930 
931 	sLbl2 = String::CreateFromInt32( nVis + 3 );
932 	String tmp3(sLbl2);
933 	sLbl2.Insert(sLbl, sLbl2.Len() - 1);
934     aLbl3.SetText(sLbl2);
935 	String sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH ) ;
936 	sColumnWidth.SearchAndReplaceAscii("%1", tmp1);
937 	aEd1.SetAccessibleName(sColumnWidth);
938 
939 	sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH ) ;
940 	sColumnWidth.SearchAndReplaceAscii("%1", tmp2);
941 	aEd2.SetAccessibleName(sColumnWidth);
942 
943 	sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH ) ;
944 	sColumnWidth.SearchAndReplaceAscii("%1", tmp3);
945 	aEd3.SetAccessibleName(sColumnWidth);
946 
947 	String sDist = SW_RESSTR( STR_ACCESS_PAGESETUP_SPACING ) ;
948 	String sDist1 = sDist;
949 	sDist1.SearchAndReplaceAscii("%1", tmp1);
950 	sDist1.SearchAndReplaceAscii("%2", tmp2);
951 	aDistEd1.SetAccessibleName(sDist1);
952 
953 	String sDist2 = sDist;
954 	sDist2.SearchAndReplaceAscii("%1", tmp2);
955 	sDist2.SearchAndReplaceAscii("%2", tmp3);
956 	aDistEd2.SetAccessibleName(sDist2);
957 }
958 
959 /*------------------------------------------------------------------------
960  Beschreibung:	Handler, der bei einer Veraenderung der Spaltenzahl
961 				gerufen wird.
962 				Eine Aenderung der Spaltenzahl ueberschreibt eventuelle
963 				Breiteneinstellungen des Benutzers; alle Spalten sind
964 				gleich breit.
965 ------------------------------------------------------------------------*/
966 
967 IMPL_LINK( SwColumnPage, ColModify, NumericField *, pNF )
968 {
969     nCols = (sal_uInt16)aCLNrEdt.GetValue();
970     //#107890# the handler is also called from LoseFocus()
971     //then no change has been made and thus no action should be taken
972 	// #i17816# changing the displayed types within the ValueSet
973 	//from two columns to two columns with different settings doesn't invalidate the
974 	// example windows in ::ColModify()
975     if(!pNF ||(pColMgr->GetCount() != nCols))
976     {
977         if(pNF)
978             aDefaultVS.SetNoSelection();
979         long nDist = static_cast< long >(aDistEd1.DenormalizePercent(aDistEd1.GetValue(FUNIT_TWIP)));
980         pColMgr->SetCount(nCols, (sal_uInt16)nDist);
981         for(sal_uInt16 i = 0; i < nCols; i++)
982             nColDist[i] = nDist;
983         nFirstVis = 0;
984         SetLabels( nFirstVis );
985         UpdateCols();
986         ResetColWidth();
987         Update();
988     }
989 
990 	return 0;
991 }
992 
993 /*------------------------------------------------------------------------
994  Beschreibung:	Modify- Handler fuer eine Aenderung der Spaltenbreite
995 				oder des Spaltenabstandes.
996 				Diese Aenderungen wirken sich erst zeitversetzt aus.
997 				Durch eine Aenderung der Spaltenbreite wird die automatische
998 				Berechnung der Spaltenbreite ausser Kraft gesetzt; erst
999 				eine Aenderung der Spaltenzahl kehrt wieder zu diesem
1000 				Default zurueck.
1001 ------------------------------------------------------------------------*/
1002 
1003 
1004 
1005 IMPL_LINK( SwColumnPage, GapModify, PercentField *, pFld )
1006 {
1007     long nActValue = static_cast< long >(pFld->DenormalizePercent(pFld->GetValue(FUNIT_TWIP)));
1008 	if(nCols < 2)
1009 		return 0;
1010 	if(aAutoWidthBox.IsChecked())
1011 	{
1012 		sal_uInt16 nMaxGap = pColMgr->GetActualSize() - nCols * MINLAY;
1013 		DBG_ASSERT(nCols, "Abstand kann nicht ohne Spalten eingestellt werden");
1014 		nMaxGap /= nCols - 1;
1015 		if(nActValue > nMaxGap)
1016 		{
1017 			nActValue = nMaxGap;
1018             aDistEd1.SetPrcntValue(aDistEd1.NormalizePercent(nMaxGap), FUNIT_TWIP);
1019 		}
1020 		pColMgr->SetGutterWidth((sal_uInt16)nActValue);
1021 		for(sal_uInt16 i = 0; i < nCols; i++)
1022 			nColDist[i] = nActValue;
1023 
1024 		ResetColWidth();
1025 		UpdateCols();
1026 	}
1027 	else
1028 
1029 	{
1030 		sal_uInt16 nOffset = 0;
1031 		if(pFld == &aDistEd2)
1032 		{
1033 			nOffset = 1;
1034 		}
1035 		long nDiff = nActValue - nColDist[nFirstVis + nOffset];
1036 		if(nDiff)
1037 		{
1038 			long nLeft = nColWidth[nFirstVis + nOffset];
1039 			long nRight = nColWidth[nFirstVis + nOffset + 1];
1040 			if(nLeft + nRight + 2 * MINLAY < nDiff)
1041 				nDiff = nLeft + nRight - 2 * MINLAY;
1042 			if(nDiff < nRight - MINLAY)
1043 			{
1044 				nRight -= nDiff;
1045 			}
1046 			else
1047 			{
1048 				long nTemp = nDiff - nRight + MINLAY;
1049 				nRight = MINLAY;
1050 				if(nLeft > nTemp - MINLAY)
1051 				{
1052 					nLeft -= nTemp;
1053 					nTemp = 0;
1054 				}
1055 				else
1056 				{
1057 					nTemp -= nLeft + MINLAY;
1058 					nLeft = MINLAY;
1059 				}
1060 				nDiff = nTemp;
1061 			}
1062 			nColWidth[nFirstVis + nOffset] = nLeft;
1063 			nColWidth[nFirstVis + nOffset + 1] = nRight;
1064 			nColDist[nFirstVis + nOffset] += nDiff;
1065 
1066 			pColMgr->SetColWidth( nFirstVis + nOffset, sal_uInt16(nLeft) );
1067 			pColMgr->SetColWidth( nFirstVis + nOffset + 1, sal_uInt16(nRight) );
1068 			pColMgr->SetGutterWidth( sal_uInt16(nColDist[nFirstVis + nOffset]), nFirstVis + nOffset );
1069 		}
1070 
1071 	}
1072 	Update();
1073 	return 0;
1074 }
1075 
1076 /*------------------------------------------------------------------------
1077  Beschreibung:
1078 ------------------------------------------------------------------------*/
1079 
1080 
1081 
1082 IMPL_LINK( SwColumnPage, EdModify, PercentField *, pField )
1083 {
1084 	pModifiedField = pField;
1085 	Timeout(0);
1086 	return 0;
1087 }
1088 /*------------------------------------------------------------------------
1089  Beschreibung:	Handler hinter der Checkbox fuer automatische Breite.
1090 				Ist die Box gecheckt, koennen keine expliziten Werte
1091 				fuer die Spaltenbreite eingegeben werden.
1092 ------------------------------------------------------------------------*/
1093 
1094 
1095 
1096 IMPL_LINK( SwColumnPage, AutoWidthHdl, CheckBox *, pBox )
1097 {
1098     long nDist = static_cast< long >(aDistEd1.DenormalizePercent(aDistEd1.GetValue(FUNIT_TWIP)));
1099 	pColMgr->SetCount(nCols, (sal_uInt16)nDist);
1100 	for(sal_uInt16 i = 0; i < nCols; i++)
1101 		nColDist[i] = nDist;
1102 	if(pBox->IsChecked())
1103 	{
1104 		pColMgr->SetGutterWidth(sal_uInt16(nDist));
1105 		ResetColWidth();
1106 	}
1107 	pColMgr->SetAutoWidth(pBox->IsChecked(), sal_uInt16(nDist));
1108 	UpdateCols();
1109 	Update();
1110 	return 0;
1111 }
1112 
1113 /*------------------------------------------------------------------------
1114  Beschreibung:	Raufscrollen der Inhalte der Edits.
1115 ------------------------------------------------------------------------*/
1116 
1117 IMPL_LINK( SwColumnPage, Up, Button *, EMPTYARG )
1118 {
1119 	if( nFirstVis )
1120 	{
1121 		--nFirstVis;
1122 		SetLabels( nFirstVis );
1123 		Update();
1124 	}
1125 	return 0;
1126 }
1127 /*------------------------------------------------------------------------
1128  Beschreibung:	Runterscrollen der Inhalte der Edits.
1129 ------------------------------------------------------------------------*/
1130 
1131 IMPL_LINK( SwColumnPage, Down, Button *, EMPTYARG )
1132 {
1133 	if( nFirstVis + nVisCols < nCols )
1134 	{
1135 		++nFirstVis;
1136 		SetLabels( nFirstVis );
1137 		Update();
1138 	}
1139 	return 0;
1140 }
1141 /*------------------------------------------------------------------------
1142  Beschreibung:	Relikt aus alten Zeiten - jetzt direkt ohne time
1143  * 				Timer- Handler; angetriggert durch eine Aenderung der
1144 				Spaltenbreite oder des Spaltenabstandes.
1145 ------------------------------------------------------------------------*/
1146 
1147 IMPL_LINK( SwColumnPage, Timeout, Timer *, EMPTYARG )
1148 {
1149 	DBG_PROFSTART(columnhdl) ;
1150 	if(pModifiedField)
1151 	{
1152 			// Finden der veraenderten Spalte
1153 		sal_uInt16 nChanged = nFirstVis;
1154 		if(pModifiedField == &aEd2)
1155 			++nChanged;
1156 		else if(pModifiedField == &aEd3)
1157 			nChanged += 2;
1158 		/*else if(pModifiedField == &aEd4)
1159 			nChanged += 3;*/
1160 
1161 		long nNewWidth = (sal_uInt16)
1162 			pModifiedField->DenormalizePercent(pModifiedField->GetValue(FUNIT_TWIP));
1163 		long nDiff = nNewWidth - nColWidth[nChanged];
1164 
1165 		// wenn es die letzte Spalte ist
1166 		if(nChanged == nCols - 1)
1167 		{
1168 			nColWidth[0] -= nDiff;
1169 			if(nColWidth[0] < (long)nMinWidth)
1170 			{
1171 				nNewWidth -= nMinWidth - nColWidth[0];
1172 				nColWidth[0] = nMinWidth;
1173 			}
1174 
1175 		}
1176 		else if(nDiff)
1177 		{
1178 			nColWidth[nChanged + 1] -= nDiff;
1179 			if(nColWidth[nChanged + 1] < (long) nMinWidth)
1180 			{
1181 				nNewWidth -= nMinWidth - nColWidth[nChanged + 1];
1182 				nColWidth[nChanged + 1] = nMinWidth;
1183 			}
1184 		}
1185 		nColWidth[nChanged] = nNewWidth;
1186 		pModifiedField = 0;
1187 	}
1188 	Update();
1189 	DBG_PROFSTOP(columnhdl) ;
1190 	return 0;
1191 }
1192 /*------------------------------------------------------------------------
1193  Beschreibung:	Aktualisierung der Anzeige
1194 ------------------------------------------------------------------------*/
1195 
1196 
1197 
1198 void SwColumnPage::Update()
1199 {
1200 	aBalanceColsCB.Enable(nCols > 1);
1201 	if(nCols >= 2)
1202 	{
1203         aEd1.SetPrcntValue(aEd1.NormalizePercent(nColWidth[nFirstVis]), FUNIT_TWIP);
1204         aDistEd1.SetPrcntValue(aDistEd1.NormalizePercent(nColDist[nFirstVis]), FUNIT_TWIP);
1205         aEd2.SetPrcntValue(aEd2.NormalizePercent(nColWidth[nFirstVis + 1]), FUNIT_TWIP);
1206 		if(nCols >= 3)
1207 		{
1208             aDistEd2.SetPrcntValue(aDistEd2.NormalizePercent(nColDist[nFirstVis + 1]), FUNIT_TWIP);
1209             aEd3.SetPrcntValue(aEd3.NormalizePercent(nColWidth[nFirstVis + 2]), FUNIT_TWIP);
1210 		}
1211 		else
1212 		{
1213 			aEd3.SetText(aEmptyStr);
1214 			aDistEd2.SetText(aEmptyStr);
1215 		}
1216 	}
1217 	else
1218 	{
1219 		aEd1.SetText(aEmptyStr);
1220 		aEd2.SetText(aEmptyStr);
1221 		aEd3.SetText(aEmptyStr);
1222 		aDistEd1.SetText(aEmptyStr);
1223 		aDistEd2.SetText(aEmptyStr);
1224 	}
1225 	UpdateColMgr(0);
1226 }
1227 
1228 /*--------------------------------------------------------------------
1229 	Beschreibung:	Update Bsp
1230  --------------------------------------------------------------------*/
1231 
1232 
1233 
1234 void SwColumnPage::ActivatePage(const SfxItemSet& rSet)
1235 {
1236 	if(!bFrm)
1237 	{
1238 		if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_SIZE ))
1239 		{
1240 			const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get(
1241 												SID_ATTR_PAGE_SIZE);
1242 			const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rSet.Get(
1243 																RES_LR_SPACE );
1244 			const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
1245             sal_uInt16 nActWidth = static_cast< sal_uInt16 >(rSize.GetSize().Width()
1246                             - rLRSpace.GetLeft() - rLRSpace.GetRight() - rBox.GetDistance());
1247 
1248 			if( pColMgr->GetActualSize() != nActWidth)
1249 			{
1250 				pColMgr->SetActualWidth(nActWidth);
1251 				ColModify( 0 );
1252 				UpdateColMgr( 0 );
1253 			}
1254 		}
1255 		aFrmExampleWN.Hide();
1256 		aPgeExampleWN.UpdateExample( rSet, pColMgr );
1257 		aPgeExampleWN.Show();
1258 
1259 	}
1260 	else
1261 	{
1262 		aPgeExampleWN.Hide();
1263 		aFrmExampleWN.Show();
1264 
1265 		// Size
1266         const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE);
1267         const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
1268 
1269         long nDistance = rBox.GetDistance();
1270 		const sal_uInt16 nTotalWish = bFormat ? FRAME_FORMAT_WIDTH : sal_uInt16(rSize.GetWidth() - 2 * nDistance);
1271 
1272 		// Maximalwerte der Spaltenbreiten setzen
1273 		SetPageWidth(nTotalWish);
1274 
1275 		if(pColMgr->GetActualSize() != nTotalWish)
1276 		{
1277 			pColMgr->SetActualWidth(nTotalWish);
1278 			Init();
1279 		}
1280 		sal_Bool bPercent;
1281 		// im Rahmenformat nur relative Angaben
1282 		if ( bFormat || (rSize.GetWidthPercent() && rSize.GetWidthPercent() != 0xff) )
1283 		{
1284 			// Wert fuer 100% setzen
1285 			aEd1.SetRefValue(nTotalWish);
1286 			aEd2.SetRefValue(nTotalWish);
1287 			aEd3.SetRefValue(nTotalWish);
1288 			aDistEd1.SetRefValue(nTotalWish);
1289 			aDistEd2.SetRefValue(nTotalWish);
1290 
1291 			// Auf %-Darstellung umschalten
1292 			bPercent = sal_True;
1293 		}
1294 		else
1295 			bPercent = sal_False;
1296 
1297 		aEd1.ShowPercent(bPercent);
1298 		aEd2.ShowPercent(bPercent);
1299 		aEd3.ShowPercent(bPercent);
1300 		aDistEd1.ShowPercent(bPercent);
1301 		aDistEd2.ShowPercent(bPercent);
1302 		aDistEd1.MetricField::SetMin(0);
1303 		aDistEd2.MetricField::SetMin(0);
1304 	}
1305 	Update();
1306 }
1307 
1308 /*--------------------------------------------------------------------
1309 	Beschreibung:
1310  --------------------------------------------------------------------*/
1311 
1312 
1313 
1314 int SwColumnPage::DeactivatePage(SfxItemSet *_pSet)
1315 {
1316     if(_pSet)
1317         FillItemSet(*_pSet);
1318 
1319 	return sal_True;
1320 }
1321 
1322 
1323 
1324 sal_uInt16* SwColumnPage::GetRanges()
1325 {
1326 	return aPageRg;
1327 }
1328 
1329 /*--------------------------------------------------------------------
1330 	Beschreibung:
1331  --------------------------------------------------------------------*/
1332 
1333 
1334 
1335 IMPL_LINK( SwColumnPage, SetDefaultsHdl, ValueSet *, pVS )
1336 {
1337 	sal_uInt16 nItem = pVS->GetSelectItemId();
1338 	if( nItem < 4 )
1339 	{
1340 		aCLNrEdt.SetValue( nItem );
1341 		aAutoWidthBox.Check();
1342         aDistEd1.SetPrcntValue(0);
1343 		ColModify(0);
1344 	}
1345 	else
1346 	{
1347 		bLockUpdate = sal_True;
1348 		aCLNrEdt.SetValue( 2 );
1349 		aAutoWidthBox.Check(sal_False);
1350         aDistEd1.SetPrcntValue(0);
1351 		ColModify(0);
1352 		// jetzt noch das Breitenverhaeltnisse auf 2 : 1 bzw. 1 : 2 stellen
1353 		sal_uInt16 nSmall = pColMgr->GetActualSize()  / 3;
1354 		if(nItem == 4)
1355 		{
1356             aEd2.SetPrcntValue(aEd2.NormalizePercent(long(nSmall)), FUNIT_TWIP);
1357 			pModifiedField = &aEd2;
1358 		}
1359 		else
1360 		{
1361             aEd1.SetPrcntValue(aEd1.NormalizePercent(long(nSmall)), FUNIT_TWIP);
1362 			pModifiedField = &aEd1;
1363 		}
1364 		bLockUpdate = sal_False;
1365 		Timeout(0);
1366 
1367 	}
1368 	return 0;
1369 }
1370 
1371 /*-----------------25.10.96 11.41-------------------
1372 
1373 --------------------------------------------------*/
1374 
1375 
1376 void SwColumnPage::SetFrmMode(sal_Bool bMod)
1377 {
1378 	bFrm = bMod;
1379 }
1380 /* -----------------------------2002/06/19 13:08------------------------------
1381 
1382  ---------------------------------------------------------------------------*/
1383 void SwColumnPage::SetInSection(sal_Bool bSet)
1384 {
1385     if(!SW_MOD()->GetCTLOptions().IsCTLFontEnabled())
1386         return;
1387 
1388     aVertFL.Show(bSet);
1389     aPropertiesFL.Show(bSet);
1390     aTextDirectionFT.Show(bSet);
1391     aTextDirectionLB.Show(bSet);
1392     if(bSet)
1393     {
1394         //resize line type FixedLine
1395         Point aLtPos = aFLLineType.GetPosPixel();
1396         Point aPropPos = aPropertiesFL.GetPosPixel();
1397         Size aSz = aFLLineType.GetSizePixel();
1398         aSz.Width() = aPropPos.X() - aLtPos.X() - LogicToPixel(Size(8, 8), MAP_APPFONT).Width();
1399         aFLLineType.SetSizePixel(aSz);
1400     }
1401     else
1402     {
1403         Size aSz = aFLLineType.GetSizePixel();
1404         aSz.Width() = LogicToPixel(Size(248, 248), MAP_APPFONT).Width();
1405         aFLLineType.SetSizePixel(aSz);
1406     }
1407 }
1408 
1409 /*-----------------07.03.97 08.33-------------------
1410 
1411 --------------------------------------------------*/
1412 
1413 
1414 void ColumnValueSet::UserDraw( const UserDrawEvent& rUDEvt )
1415 {
1416 	OutputDevice*  pDev = rUDEvt.GetDevice();
1417     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1418 
1419 	Rectangle aRect = rUDEvt.GetRect();
1420 	sal_uInt16	nItemId = rUDEvt.GetItemId();
1421 	long nRectWidth = aRect.GetWidth();
1422 	long nRectHeight = aRect.GetHeight();
1423 
1424 	Point aBLPos = aRect.TopLeft();
1425     Color aFillColor(pDev->GetFillColor());
1426     Color aLineColor(pDev->GetLineColor());
1427     pDev->SetFillColor(rStyleSettings.GetFieldColor());
1428     pDev->SetLineColor(SwViewOption::GetFontColor());
1429 
1430 	long nStep = Abs(Abs(nRectHeight * 95 /100) / 11);
1431 	long nTop = (nRectHeight - 11 * nStep ) / 2;
1432     sal_uInt16 nCols = 0;
1433 	long nStarts[3];
1434 	long nEnds[3];
1435 	nStarts[0] = nRectWidth * 10 / 100;
1436 	switch( nItemId )
1437 	{
1438 		case 1:
1439 			nEnds[0] = nRectWidth * 9 / 10;
1440 			nCols = 1;
1441 		break;
1442 		case 2: nCols = 2;
1443 			nEnds[0] = nRectWidth * 45 / 100;
1444 			nStarts[1] = nEnds[0] + nStep;
1445 			nEnds[1] = nRectWidth * 9 / 10;
1446 		break;
1447 		case 3: nCols = 3;
1448 			nEnds[0] 	= nRectWidth * 30 / 100;
1449 			nStarts[1] 	= nEnds[0] + nStep;
1450 			nEnds[1] 	= nRectWidth * 63 / 100;
1451 			nStarts[2] 	= nEnds[1] + nStep;
1452 			nEnds[2] 	= nRectWidth * 9 / 10;
1453 		break;
1454 		case 4: nCols = 2;
1455 			nEnds[0] = nRectWidth * 63 / 100;
1456 			nStarts[1] = nEnds[0] + nStep;
1457 			nEnds[1] = nRectWidth * 9 / 10;
1458 		break;
1459 		case 5: nCols = 2;
1460 			nEnds[0] = nRectWidth * 30 / 100;
1461 			nStarts[1] = nEnds[0] + nStep;
1462 			nEnds[1] = nRectWidth * 9 / 10;
1463 		break;
1464 	}
1465 	for(sal_uInt16 j = 0; j < nCols; j++ )
1466 	{
1467 		Point aStart(aBLPos.X() + nStarts[j], 0);
1468 		Point aEnd(aBLPos.X() + nEnds[j], 0);
1469 		for( sal_uInt16 i = 0; i < 12; i ++)
1470 		{
1471 			aStart.Y() = aEnd.Y() = aBLPos.Y() + nTop + i * nStep;
1472 			pDev->DrawLine(aStart, aEnd);
1473 		}
1474 	}
1475     pDev->SetFillColor(aFillColor);
1476     pDev->SetLineColor(aLineColor);
1477 }
1478 
1479 /*-----------------07.03.97 08.48-------------------
1480 
1481 --------------------------------------------------*/
1482 
1483 ColumnValueSet::~ColumnValueSet()
1484 {
1485 }
1486 /* -----------------------------02.04.2002 16:01------------------------------
1487 
1488  ---------------------------------------------------------------------------*/
1489 void ColumnValueSet::DataChanged( const DataChangedEvent& rDCEvt )
1490 {
1491 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1492          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1493     {
1494         Format();
1495     }
1496     ValueSet::DataChanged( rDCEvt );
1497 }
1498 
1499