Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "column.hxx"
21 :
22 : #include "hintids.hxx"
23 : #include <svx/dialogs.hrc>
24 : #include <svx/dialmgr.hxx>
25 : #include <svx/htmlmode.hxx>
26 : #include <svx/xtable.hxx>
27 : #include <svx/drawitem.hxx>
28 : #include <editeng/borderline.hxx>
29 : #include <editeng/boxitem.hxx>
30 : #include <editeng/lrspitem.hxx>
31 : #include <editeng/sizeitem.hxx>
32 : #include "editeng/frmdiritem.hxx"
33 : #include <svl/ctloptions.hxx>
34 : #include <sfx2/dispatch.hxx>
35 : #include <vcl/msgbox.hxx>
36 : #include <swmodule.hxx>
37 : #include <sal/macros.h>
38 :
39 : #include <helpid.h>
40 : #include "globals.hrc"
41 : #include "swtypes.hxx"
42 : #include "wrtsh.hxx"
43 : #include "view.hxx"
44 : #include "docsh.hxx"
45 : #include "uitool.hxx"
46 : #include "cmdid.h"
47 : #include "viewopt.hxx"
48 : #include "format.hxx"
49 : #include "frmmgr.hxx"
50 : #include "frmdlg.hxx"
51 : #include "colmgr.hxx"
52 : #include "prcntfld.hxx"
53 : #include "paratr.hxx"
54 : #include "frmui.hrc"
55 : #include "poolfmt.hrc"
56 : #include "column.hrc"
57 : #include <section.hxx>
58 : #include <docary.hxx>
59 : #include <pagedesc.hxx>
60 :
61 : #include "access.hrc"
62 :
63 :
64 : using namespace ::com::sun::star;
65 :
66 : #define FRAME_FORMAT_WIDTH 1000
67 :
68 : /*--------------------------------------------------------------------
69 : Description: static data
70 : --------------------------------------------------------------------*/
71 :
72 : static const sal_uInt16 nVisCols = 3;
73 :
74 0 : inline sal_Bool IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect )
75 : {
76 0 : rWrtSh.SwapPam();
77 0 : sal_Bool bRet = pSect == rWrtSh.GetCurrSection();
78 0 : rWrtSh.SwapPam();
79 0 : return bRet;
80 : }
81 :
82 0 : SwColumnDlg::SwColumnDlg(Window* pParent, SwWrtShell& rSh) :
83 : SfxModalDialog(pParent, SW_RES(DLG_COLUMN)),
84 : aOK(this, SW_RES(PB_OK)),
85 : aCancel(this, SW_RES(PB_CANCEL)),
86 : aHelp(this, SW_RES(PB_HELP)),
87 : aApplyToFT(this, SW_RES(FT_APPLY_TO)),
88 : aApplyToLB(this, SW_RES(LB_APPLY_TO)),
89 : rWrtShell(rSh),
90 : pPageSet(0),
91 : pSectionSet(0),
92 : pSelectionSet(0),
93 : pFrameSet(0),
94 : nOldSelection(0),
95 : nSelectionWidth(0),
96 : bPageChanged(sal_False),
97 : bSectionChanged(sal_False),
98 : bSelSectionChanged(sal_False),
99 0 : bFrameChanged(sal_False)
100 : {
101 0 : FreeResource();
102 :
103 0 : SwRect aRect;
104 0 : rWrtShell.CalcBoundRect(aRect, FLY_AS_CHAR);
105 :
106 0 : nSelectionWidth = aRect.Width();
107 :
108 0 : SfxItemSet* pColPgSet = 0;
109 : static sal_uInt16 const aSectIds[] = { RES_COL, RES_COL,
110 : RES_FRM_SIZE, RES_FRM_SIZE,
111 : RES_COLUMNBALANCE, RES_FRAMEDIR,
112 : 0 };
113 :
114 0 : const SwSection* pCurrSection = rWrtShell.GetCurrSection();
115 0 : sal_uInt16 nFullSectCnt = rWrtShell.GetFullSelectedSectionCount();
116 0 : if( pCurrSection && ( !rWrtShell.HasSelection() || 0 != nFullSectCnt ))
117 : {
118 0 : nSelectionWidth = rSh.GetSectionWidth(*pCurrSection->GetFmt());
119 0 : if ( !nSelectionWidth )
120 0 : nSelectionWidth = USHRT_MAX;
121 0 : pSectionSet = new SfxItemSet( rWrtShell.GetAttrPool(), aSectIds );
122 0 : pSectionSet->Put( pCurrSection->GetFmt()->GetAttrSet() );
123 0 : pColPgSet = pSectionSet;
124 : aApplyToLB.RemoveEntry( aApplyToLB.GetEntryPos(
125 : (void*)(sal_IntPtr)( 1 >= nFullSectCnt
126 : ? LISTBOX_SECTIONS
127 0 : : LISTBOX_SECTION )));
128 : }
129 : else
130 : {
131 0 : aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*)(sal_IntPtr)LISTBOX_SECTION ));
132 0 : aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*)(sal_IntPtr)LISTBOX_SECTIONS ));
133 : }
134 :
135 0 : if( rWrtShell.HasSelection() && rWrtShell.IsInsRegionAvailable() &&
136 : ( !pCurrSection || ( 1 != nFullSectCnt &&
137 0 : IsMarkInSameSection( rWrtShell, pCurrSection ) )))
138 : {
139 0 : pSelectionSet = new SfxItemSet( rWrtShell.GetAttrPool(), aSectIds );
140 0 : pColPgSet = pSelectionSet;
141 : }
142 : else
143 0 : aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*)(sal_IntPtr)LISTBOX_SELECTION ));
144 :
145 0 : if( rWrtShell.GetFlyFrmFmt() )
146 : {
147 0 : const SwFrmFmt* pFmt = rSh.GetFlyFrmFmt() ;
148 0 : pFrameSet = new SfxItemSet(rWrtShell.GetAttrPool(), aSectIds );
149 0 : pFrameSet->Put(pFmt->GetFrmSize());
150 0 : pFrameSet->Put(pFmt->GetCol());
151 0 : pColPgSet = pFrameSet;
152 : }
153 : else
154 0 : aApplyToLB.RemoveEntry(aApplyToLB.GetEntryPos( (void*) LISTBOX_FRAME ));
155 :
156 :
157 0 : sal_uInt16 nPagePos = aApplyToLB.GetEntryPos( (void*) LISTBOX_PAGE );
158 0 : const SwPageDesc* pPageDesc = rWrtShell.GetSelectedPageDescs();
159 0 : if( pPageDesc )
160 : {
161 0 : pPageSet = new SfxItemSet( rWrtShell.GetAttrPool(),
162 : RES_COL, RES_COL,
163 : RES_FRM_SIZE, RES_FRM_SIZE,
164 : RES_LR_SPACE, RES_LR_SPACE,
165 0 : 0 );
166 :
167 0 : String sPageStr = aApplyToLB.GetEntry(nPagePos);
168 0 : aApplyToLB.RemoveEntry( nPagePos );
169 0 : sPageStr += pPageDesc->GetName();
170 0 : aApplyToLB.InsertEntry( sPageStr, nPagePos );
171 0 : aApplyToLB.SetEntryData( nPagePos, (void*) LISTBOX_PAGE);
172 :
173 0 : const SwFrmFmt &rFmt = pPageDesc->GetMaster();
174 0 : nPageWidth = rFmt.GetFrmSize().GetSize().Width();
175 :
176 0 : const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rFmt.GetLRSpace();
177 0 : const SvxBoxItem& rBox = (const SvxBoxItem&) rFmt.GetBox();
178 0 : nPageWidth -= rLRSpace.GetLeft() + rLRSpace.GetRight() + rBox.GetDistance();
179 :
180 0 : pPageSet->Put(rFmt.GetCol());
181 0 : pPageSet->Put(rFmt.GetLRSpace());
182 0 : pColPgSet = pPageSet;
183 : }
184 : else
185 0 : aApplyToLB.RemoveEntry( nPagePos );
186 :
187 : OSL_ENSURE( pColPgSet, "" );
188 : // create TabPage
189 : SwColumnPage* pPage = (SwColumnPage*) SwColumnPage::Create( this,
190 0 : *pColPgSet );
191 0 : pTabPage = pPage;
192 :
193 : // adjust size
194 0 : Size aPageSize(pTabPage->GetSizePixel());
195 0 : Size aDlgSize(GetOutputSizePixel());
196 0 : aDlgSize.Height() = aPageSize.Height();
197 0 : SetOutputSizePixel(aDlgSize);
198 0 : pTabPage->Show();
199 :
200 0 : aApplyToLB.SelectEntryPos(0);
201 0 : ObjectHdl(0);
202 :
203 0 : aApplyToLB.SetSelectHdl(LINK(this, SwColumnDlg, ObjectHdl));
204 0 : aOK.SetClickHdl(LINK(this, SwColumnDlg, OkHdl));
205 : //#i80458# if no columns can be set then disable OK
206 0 : if( !aApplyToLB.GetEntryCount() )
207 0 : aOK.Enable( sal_False );
208 : //#i97810# set focus to the TabPage
209 0 : pTabPage->ActivateColumnControl();
210 0 : }
211 :
212 0 : SwColumnDlg::~SwColumnDlg()
213 : {
214 0 : delete pTabPage;
215 0 : delete pPageSet;
216 0 : delete pSectionSet;
217 0 : delete pSelectionSet;
218 0 : }
219 :
220 0 : IMPL_LINK(SwColumnDlg, ObjectHdl, ListBox*, pBox)
221 : {
222 0 : SfxItemSet* pSet = 0;
223 0 : switch(nOldSelection)
224 : {
225 : case LISTBOX_SELECTION :
226 0 : pSet = pSelectionSet;
227 0 : break;
228 : case LISTBOX_SECTION :
229 0 : pSet = pSectionSet;
230 0 : bSectionChanged = sal_True;
231 0 : break;
232 : case LISTBOX_SECTIONS :
233 0 : pSet = pSectionSet;
234 0 : bSelSectionChanged = sal_True;
235 0 : break;
236 : case LISTBOX_PAGE :
237 0 : pSet = pPageSet;
238 0 : bPageChanged = sal_True;
239 0 : break;
240 : case LISTBOX_FRAME:
241 0 : pSet = pFrameSet;
242 0 : bFrameChanged = sal_True;
243 0 : break;
244 : }
245 0 : if(pBox)
246 : {
247 0 : pTabPage->FillItemSet(*pSet);
248 : }
249 0 : nOldSelection = (long)aApplyToLB.GetEntryData(aApplyToLB.GetSelectEntryPos());
250 0 : long nWidth = nSelectionWidth;
251 0 : switch(nOldSelection)
252 : {
253 : case LISTBOX_SELECTION :
254 0 : pSet = pSelectionSet;
255 0 : if( pSelectionSet )
256 0 : pSet->Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth, nWidth));
257 0 : break;
258 : case LISTBOX_SECTION :
259 : case LISTBOX_SECTIONS :
260 0 : pSet = pSectionSet;
261 0 : pSet->Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth, nWidth));
262 0 : break;
263 : case LISTBOX_PAGE :
264 0 : nWidth = nPageWidth;
265 0 : pSet = pPageSet;
266 0 : pSet->Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth, nWidth));
267 0 : break;
268 : case LISTBOX_FRAME:
269 0 : pSet = pFrameSet;
270 0 : break;
271 : }
272 :
273 0 : sal_Bool bIsSection = pSet == pSectionSet || pSet == pSelectionSet;
274 0 : pTabPage->ShowBalance(bIsSection);
275 0 : pTabPage->SetInSection(bIsSection);
276 0 : pTabPage->SetFrmMode(sal_True);
277 0 : pTabPage->SetPageWidth(nWidth);
278 0 : if( pSet )
279 0 : pTabPage->Reset(*pSet);
280 0 : return 0;
281 : }
282 :
283 0 : IMPL_LINK_NOARG(SwColumnDlg, OkHdl)
284 : {
285 : // evaluate current selection
286 0 : SfxItemSet* pSet = 0;
287 0 : switch(nOldSelection)
288 : {
289 : case LISTBOX_SELECTION :
290 0 : pSet = pSelectionSet;
291 0 : break;
292 : case LISTBOX_SECTION :
293 0 : pSet = pSectionSet;
294 0 : bSectionChanged = sal_True;
295 0 : break;
296 : case LISTBOX_SECTIONS :
297 0 : pSet = pSectionSet;
298 0 : bSelSectionChanged = sal_True;
299 0 : break;
300 : case LISTBOX_PAGE :
301 0 : pSet = pPageSet;
302 0 : bPageChanged = sal_True;
303 0 : break;
304 : case LISTBOX_FRAME:
305 0 : pSet = pFrameSet;
306 0 : bFrameChanged = sal_True;
307 0 : break;
308 : }
309 0 : pTabPage->FillItemSet(*pSet);
310 :
311 0 : if(pSelectionSet && SFX_ITEM_SET == pSelectionSet->GetItemState(RES_COL))
312 : {
313 : //insert region with columns
314 0 : const SwFmtCol& rColItem = (const SwFmtCol&)pSelectionSet->Get(RES_COL);
315 : //only if there actually are columns!
316 0 : if(rColItem.GetNumCols() > 1)
317 0 : rWrtShell.GetView().GetViewFrame()->GetDispatcher()->Execute(
318 0 : FN_INSERT_REGION, SFX_CALLMODE_ASYNCHRON, *pSelectionSet );
319 : }
320 :
321 0 : if(pSectionSet && pSectionSet->Count() && bSectionChanged )
322 : {
323 0 : const SwSection* pCurrSection = rWrtShell.GetCurrSection();
324 0 : const SwSectionFmt* pFmt = pCurrSection->GetFmt();
325 0 : sal_uInt16 nNewPos = rWrtShell.GetSectionFmtPos( *pFmt );
326 0 : SwSectionData aData(*pCurrSection);
327 0 : rWrtShell.UpdateSection( nNewPos, aData, pSectionSet );
328 : }
329 :
330 0 : if(pSectionSet && pSectionSet->Count() && bSelSectionChanged )
331 : {
332 0 : rWrtShell.SetSectionAttr( *pSectionSet );
333 : }
334 :
335 0 : if(pPageSet && SFX_ITEM_SET == pPageSet->GetItemState(RES_COL) && bPageChanged)
336 : {
337 : // deterine current PageDescriptor and fill the Set with it
338 0 : const sal_uInt16 nCurIdx = rWrtShell.GetCurPageDesc();
339 0 : SwPageDesc aPageDesc(rWrtShell.GetPageDesc(nCurIdx));
340 0 : SwFrmFmt &rFmt = aPageDesc.GetMaster();
341 0 : rFmt.SetFmtAttr(pPageSet->Get(RES_COL));
342 0 : rWrtShell.ChgPageDesc(nCurIdx, aPageDesc);
343 : }
344 0 : if(pFrameSet && SFX_ITEM_SET == pFrameSet->GetItemState(RES_COL) && bFrameChanged)
345 : {
346 0 : SfxItemSet aTmp(*pFrameSet->GetPool(), RES_COL, RES_COL);
347 0 : aTmp.Put(*pFrameSet);
348 0 : rWrtShell.StartAction();
349 0 : rWrtShell.Push();
350 0 : rWrtShell.SetFlyFrmAttr( aTmp );
351 : // undo the frame selction again
352 0 : if(rWrtShell.IsFrmSelected())
353 : {
354 0 : rWrtShell.UnSelectFrm();
355 0 : rWrtShell.LeaveSelFrmMode();
356 : }
357 0 : rWrtShell.Pop();
358 0 : rWrtShell.EndAction();
359 : }
360 0 : EndDialog(RET_OK);
361 0 : return 0;
362 : }
363 :
364 : #if OSL_DEBUG_LEVEL < 2
365 : inline
366 : #endif
367 0 : sal_uInt16 GetMaxWidth( SwColMgr* pColMgr, sal_uInt16 nCols )
368 : {
369 0 : sal_uInt16 nMax = pColMgr->GetActualSize();
370 0 : if( --nCols )
371 0 : nMax -= pColMgr->GetGutterWidth() * nCols;
372 0 : return nMax;
373 : }
374 :
375 : static sal_uInt16 aPageRg[] = {
376 : RES_COL, RES_COL,
377 : 0
378 : };
379 :
380 : DBG_NAME(columnhdl)
381 :
382 0 : void SwColumnPage::ResetColWidth()
383 : {
384 0 : if( nCols )
385 : {
386 0 : sal_uInt16 nWidth = GetMaxWidth( pColMgr, nCols );
387 0 : nWidth = nWidth / nCols;
388 :
389 0 : for(sal_uInt16 i = 0; i < nCols; ++i)
390 0 : nColWidth[i] = (long) nWidth;
391 : }
392 :
393 0 : }
394 :
395 : /*--------------------------------------------------------------------
396 : Description: Now as TabPage
397 : --------------------------------------------------------------------*/
398 0 : SwColumnPage::SwColumnPage(Window *pParent, const SfxItemSet &rSet)
399 :
400 : : SfxTabPage(pParent, SW_RES(TP_COLUMN), rSet),
401 :
402 : aFLGroup(this, SW_RES(FL_COLUMNS )),
403 : aClNrLbl(this, SW_RES(FT_NUMBER )),
404 : aCLNrEdt(this, SW_RES(ED_NUMBER )),
405 : aDefaultVS(this, SW_RES(VS_DEFAULTS)),
406 : aBalanceColsCB(this, SW_RES(CB_BALANCECOLS)),
407 :
408 : aFLLayout(this, SW_RES(FL_LAYOUT)),
409 : aBtnUp(this, SW_RES(BTN_DOWN)),
410 : aColumnFT(this, SW_RES(FT_COLUMN)),
411 : aWidthFT(this, SW_RES(FT_WIDTH)),
412 : aDistFT(this, SW_RES(FT_DIST)),
413 : aLbl1(this, SW_RES(FT_1)),
414 : aEd1(this, SW_RES(ED_1)),
415 : aDistEd1(this, SW_RES(ED_DIST1)),
416 : aLbl2(this, SW_RES(FT_2)),
417 : aEd2(this, SW_RES(ED_2)),
418 : aDistEd2(this, SW_RES(ED_DIST2)),
419 : aLbl3(this, SW_RES(FT_3)),
420 : aEd3(this, SW_RES(ED_3)),
421 : aBtnDown(this, SW_RES(BTN_UP)),
422 : aAutoWidthBox(this, SW_RES(CB_AUTO_WIDTH)),
423 :
424 : aFLLineType(this, SW_RES(FL_LINETYPE)),
425 : aLineTypeLbl(this, SW_RES(FT_STYLE)),
426 : aLineTypeDLB(this, SW_RES(LB_STYLE)),
427 : aLineWidthLbl(this, SW_RES(FT_LINEWIDTH)),
428 : aLineWidthEdit(this, SW_RES(ED_LINEWIDTH)),
429 : aLineColorLbl(this, SW_RES(FT_COLOR)),
430 : aLineColorDLB(this, SW_RES(LB_COLOR)),
431 : aLineHeightLbl(this, SW_RES(FT_HEIGHT)),
432 : aLineHeightEdit(this, SW_RES(ED_HEIGHT)),
433 : aLinePosLbl(this, SW_RES(FT_POSITION)),
434 : aLinePosDLB(this, SW_RES(LB_POSITION)),
435 :
436 : aTextDirectionFT( this, SW_RES( FT_TEXTDIRECTION )),
437 : aTextDirectionLB( this, SW_RES( LB_TEXTDIRECTION )),
438 :
439 : aPgeExampleWN(this, SW_RES(WN_BSP)),
440 : aFrmExampleWN(this, SW_RES(WN_BSP)),
441 :
442 : pColMgr(0),
443 :
444 : nFirstVis(0),
445 : nMinWidth(MINLAY),
446 : pModifiedField(0),
447 : bFormat(sal_False),
448 : bFrm(sal_False),
449 : bHtmlMode(sal_False),
450 0 : bLockUpdate(sal_False)
451 : {
452 : long i;
453 :
454 0 : FreeResource();
455 0 : SetExchangeSupport();
456 :
457 0 : aBtnDown.SetAccessibleRelationMemberOf(&aFLLayout);
458 0 : aEd1.SetAccessibleRelationLabeledBy(&aWidthFT);
459 0 : aEd2.SetAccessibleRelationLabeledBy(&aWidthFT);
460 0 : aEd3.SetAccessibleRelationLabeledBy(&aWidthFT);
461 0 : aDistEd1.SetAccessibleRelationLabeledBy(&aDistFT);
462 0 : aDistEd2.SetAccessibleRelationLabeledBy(&aDistFT);
463 0 : aBtnUp.SetAccessibleRelationLabeledBy(&aColumnFT);
464 0 : aBtnDown.SetAccessibleRelationLabeledBy(&aColumnFT);
465 :
466 0 : aDefaultVS.SetHelpId(HID_COLUMN_VALUESET);
467 0 : aDefaultVS.SetColCount( 5 );
468 0 : aDefaultVS.SetStyle( aDefaultVS.GetStyle()
469 : | WB_ITEMBORDER
470 0 : | WB_DOUBLEBORDER );
471 :
472 0 : for( i = 0; i < 5; i++)
473 0 : aDefaultVS.InsertItem( i + 1, i );
474 :
475 0 : aDefaultVS.SetSelectHdl(LINK(this, SwColumnPage, SetDefaultsHdl));
476 :
477 : // announce Controls for additional region at the MoreButton
478 0 : Link aCLNrLk = LINK(this, SwColumnPage, ColModify);
479 0 : aCLNrEdt.SetLoseFocusHdl(aCLNrLk);
480 0 : aCLNrEdt.SetUpHdl(aCLNrLk);
481 0 : aCLNrEdt.SetDownHdl(aCLNrLk);
482 0 : Link aLk = LINK(this, SwColumnPage, GapModify);
483 0 : aDistEd1.SetUpHdl(aLk);
484 0 : aDistEd1.SetDownHdl(aLk);
485 0 : aDistEd1.SetLoseFocusHdl(aLk);
486 0 : aDistEd2.SetUpHdl(aLk);
487 0 : aDistEd2.SetDownHdl(aLk);
488 0 : aDistEd2.SetLoseFocusHdl(aLk);
489 :
490 0 : aLk = LINK(this, SwColumnPage, EdModify);
491 :
492 0 : aEd1.SetUpHdl(aLk);
493 0 : aEd1.SetDownHdl(aLk);
494 0 : aEd1.SetLoseFocusHdl(aLk);
495 :
496 0 : aEd2.SetUpHdl(aLk);
497 0 : aEd2.SetDownHdl(aLk);
498 0 : aEd2.SetLoseFocusHdl(aLk);
499 :
500 0 : aEd3.SetUpHdl(aLk);
501 0 : aEd3.SetDownHdl(aLk);
502 0 : aEd3.SetLoseFocusHdl(aLk);
503 :
504 0 : aBtnUp.SetClickHdl(LINK(this, SwColumnPage, Up));
505 0 : aBtnDown.SetClickHdl(LINK(this, SwColumnPage, Down));
506 0 : aAutoWidthBox.SetClickHdl(LINK(this, SwColumnPage, AutoWidthHdl));
507 :
508 0 : aLk = LINK( this, SwColumnPage, UpdateColMgr );
509 0 : aLineTypeDLB.SetSelectHdl( aLk );
510 0 : aLineWidthEdit.SetModifyHdl( aLk );
511 0 : aLineColorDLB.SetSelectHdl( aLk );
512 0 : aLineHeightEdit.SetModifyHdl( aLk );
513 0 : aLinePosDLB.SetSelectHdl( aLk );
514 :
515 : // Separator line
516 0 : aLineTypeDLB.SetUnit( FUNIT_POINT );
517 0 : aLineTypeDLB.SetSourceUnit( FUNIT_TWIP );
518 :
519 : // Fill the line styles listbox
520 0 : aLineTypeDLB.SetNone( SVX_RESSTR( RID_SVXSTR_NONE ) );
521 : aLineTypeDLB.InsertEntry(
522 : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::SOLID),
523 0 : table::BorderLineStyle::SOLID );
524 : aLineTypeDLB.InsertEntry(
525 : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DOTTED),
526 0 : table::BorderLineStyle::DOTTED );
527 : aLineTypeDLB.InsertEntry(
528 : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DASHED),
529 0 : table::BorderLineStyle::DASHED );
530 :
531 : long nLineWidth = static_cast<long>(MetricField::ConvertDoubleValue(
532 : aLineWidthEdit.GetValue( ),
533 0 : aLineWidthEdit.GetDecimalDigits( ),
534 0 : aLineWidthEdit.GetUnit(), MAP_TWIP ));
535 0 : aLineTypeDLB.SetWidth( nLineWidth );
536 :
537 : // Fill the color listbox
538 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
539 0 : const SfxPoolItem* pItem = NULL;
540 0 : XColorListRef pColorList;
541 0 : if ( pDocSh )
542 : {
543 0 : pItem = pDocSh->GetItem( SID_COLOR_TABLE );
544 0 : if ( pItem != NULL )
545 0 : pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
546 : }
547 :
548 0 : if ( pColorList.is() )
549 : {
550 0 : aLineColorDLB.SetUpdateMode( sal_False );
551 :
552 0 : for ( i = 0; i < pColorList->Count(); ++i )
553 : {
554 0 : XColorEntry* pEntry = pColorList->GetColor(i);
555 0 : aLineColorDLB.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
556 : }
557 0 : aLineColorDLB.SetUpdateMode( sal_True );
558 : }
559 0 : aLineColorDLB.SelectEntryPos( 0 );
560 0 : }
561 :
562 0 : SwColumnPage::~SwColumnPage()
563 : {
564 0 : delete pColMgr;
565 0 : }
566 :
567 0 : void SwColumnPage::SetPageWidth(long nPageWidth)
568 : {
569 0 : long nNewMaxWidth = static_cast< long >(aEd1.NormalizePercent(nPageWidth));
570 :
571 0 : aDistEd1.SetMax(nNewMaxWidth, FUNIT_TWIP);
572 0 : aDistEd2.SetMax(nNewMaxWidth, FUNIT_TWIP);
573 0 : aEd1.SetMax(nNewMaxWidth, FUNIT_TWIP);
574 0 : aEd2.SetMax(nNewMaxWidth, FUNIT_TWIP);
575 0 : aEd3.SetMax(nNewMaxWidth, FUNIT_TWIP);
576 0 : }
577 :
578 0 : void SwColumnPage::Reset(const SfxItemSet &rSet)
579 : {
580 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode((const SwDocShell*)SfxObjectShell::Current());
581 0 : if(nHtmlMode & HTMLMODE_ON)
582 : {
583 0 : bHtmlMode = sal_True;
584 0 : aAutoWidthBox.Enable(sal_False);
585 : }
586 0 : FieldUnit aMetric = ::GetDfltMetric(bHtmlMode);
587 0 : SetMetric(aEd1, aMetric);
588 0 : SetMetric(aEd2, aMetric);
589 0 : SetMetric(aEd3, aMetric);
590 0 : SetMetric(aDistEd1, aMetric);
591 0 : SetMetric(aDistEd2, aMetric);
592 :
593 0 : delete pColMgr;
594 0 : pColMgr = new SwColMgr(rSet);
595 0 : nCols = pColMgr->GetCount() ;
596 0 : aCLNrEdt.SetMax(Max((sal_uInt16)aCLNrEdt.GetMax(), (sal_uInt16)nCols));
597 0 : aCLNrEdt.SetLast(Max(nCols,(sal_uInt16)aCLNrEdt.GetMax()));
598 :
599 0 : if(bFrm)
600 : {
601 0 : if(bFormat) // there is no size here
602 0 : pColMgr->SetActualWidth(FRAME_FORMAT_WIDTH);
603 : else
604 : {
605 0 : const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE);
606 0 : const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
607 0 : pColMgr->SetActualWidth((sal_uInt16)rSize.GetSize().Width() - rBox.GetDistance());
608 : }
609 : }
610 0 : if(aBalanceColsCB.IsVisible())
611 : {
612 : const SfxPoolItem* pItem;
613 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_COLUMNBALANCE, sal_False, &pItem ))
614 0 : aBalanceColsCB.Check(!((const SwFmtNoBalancedColumns*)pItem)->GetValue());
615 : else
616 0 : aBalanceColsCB.Check( sal_True );
617 : }
618 :
619 : //text direction
620 0 : if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( RES_FRAMEDIR ) )
621 : {
622 0 : const SvxFrameDirectionItem& rItem = (const SvxFrameDirectionItem&)rSet.Get(RES_FRAMEDIR);
623 0 : sal_uIntPtr nVal = rItem.GetValue();
624 0 : sal_uInt16 nPos = aTextDirectionLB.GetEntryPos( (void*) nVal );
625 0 : aTextDirectionLB.SelectEntryPos( nPos );
626 0 : aTextDirectionLB.SaveValue();
627 : }
628 :
629 0 : Init();
630 0 : ActivatePage( rSet );
631 0 : }
632 :
633 : /*--------------------------------------------------------------------
634 : Description: create TabPage
635 : --------------------------------------------------------------------*/
636 0 : SfxTabPage* SwColumnPage::Create(Window *pParent, const SfxItemSet &rSet)
637 : {
638 0 : return new SwColumnPage(pParent, rSet);
639 : }
640 :
641 : /*--------------------------------------------------------------------
642 : Description: stuff attributes into the Set when OK
643 : --------------------------------------------------------------------*/
644 0 : sal_Bool SwColumnPage::FillItemSet(SfxItemSet &rSet)
645 : {
646 0 : if(aCLNrEdt.HasChildPathFocus())
647 0 : aCLNrEdt.GetDownHdl().Call(&aCLNrEdt);
648 : // set in ItemSet setzen
649 : // the current settings are already present
650 : //
651 : const SfxPoolItem* pOldItem;
652 0 : const SwFmtCol& rCol = pColMgr->GetColumns();
653 0 : if(0 == (pOldItem = GetOldItem( rSet, RES_COL )) ||
654 0 : rCol != *pOldItem )
655 0 : rSet.Put(rCol);
656 :
657 0 : if(aBalanceColsCB.IsVisible() )
658 : {
659 0 : rSet.Put(SwFmtNoBalancedColumns(!aBalanceColsCB.IsChecked() ));
660 : }
661 : sal_uInt16 nPos;
662 0 : if( aTextDirectionLB.IsVisible() &&
663 0 : ( nPos = aTextDirectionLB.GetSelectEntryPos() ) !=
664 0 : aTextDirectionLB.GetSavedValue() )
665 : {
666 0 : sal_uInt32 nDirection = (sal_uInt32)(sal_IntPtr)aTextDirectionLB.GetEntryData( nPos );
667 0 : rSet.Put( SvxFrameDirectionItem( (SvxFrameDirection)nDirection, RES_FRAMEDIR));
668 : }
669 0 : return sal_True;
670 : }
671 :
672 : /*--------------------------------------------------------------------
673 : Description: update ColumnManager
674 : --------------------------------------------------------------------*/
675 0 : IMPL_LINK( SwColumnPage, UpdateColMgr, void *, /*pField*/ )
676 : {
677 0 : long nGutterWidth = pColMgr->GetGutterWidth();
678 0 : if(nCols > 1)
679 : {
680 : // Determine whether the most narrow column is too narrow
681 : // for the adjusted column gap
682 0 : long nMin = nColWidth[0];
683 : sal_uInt16 i;
684 :
685 0 : for( i = 1; i < nCols; ++i)
686 0 : nMin = Min(nMin, nColWidth[i]);
687 :
688 0 : sal_Bool bAutoWidth = aAutoWidthBox.IsChecked();
689 0 : if(!bAutoWidth)
690 : {
691 0 : pColMgr->SetAutoWidth(sal_False);
692 : // when the user didn't allocate the whole width,
693 : // add the missing amount to the last column.
694 0 : long nSum = 0;
695 0 : for(i = 0; i < nCols; ++i)
696 0 : nSum += nColWidth[i];
697 0 : nGutterWidth = 0;
698 0 : for(i = 0; i < nCols - 1; ++i)
699 0 : nGutterWidth += nColDist[i];
700 0 : nSum += nGutterWidth;
701 :
702 0 : long nMaxW = pColMgr->GetActualSize();
703 :
704 0 : if( nSum < nMaxW )
705 0 : nColWidth[nCols - 1] += nMaxW - nSum;
706 :
707 0 : pColMgr->SetColWidth( 0, static_cast< sal_uInt16 >(nColWidth[0] + (sal_uInt16)nColDist[0]/2) );
708 0 : for( i = 1; i < nCols-1; ++i )
709 : {
710 0 : long nActDist = (nColDist[i] + nColDist[i - 1]) / 2;
711 0 : pColMgr->SetColWidth( i, (sal_uInt16)nColWidth[i] + (sal_uInt16)nActDist );
712 : }
713 0 : pColMgr->SetColWidth( nCols-1, static_cast< sal_uInt16 >(nColWidth[nCols-1] + nColDist[nCols -2]/2) );
714 :
715 : }
716 :
717 : // nothing is turned off
718 0 : const sal_uInt16 nPos = aLineTypeDLB.GetSelectEntryPos();
719 0 : sal_Bool bEnable = 0 != nPos;
720 0 : aLineHeightEdit.Enable( bEnable );
721 0 : aLineHeightLbl.Enable( bEnable );
722 : long nLineWidth = static_cast<long>(MetricField::ConvertDoubleValue(
723 : aLineWidthEdit.GetValue( ),
724 0 : aLineWidthEdit.GetDecimalDigits( ),
725 0 : aLineWidthEdit.GetUnit(), MAP_TWIP ));
726 0 : if( !bEnable )
727 0 : pColMgr->SetNoLine();
728 0 : else if( LISTBOX_ENTRY_NOTFOUND != nPos )
729 : {
730 : pColMgr->SetLineWidthAndColor(
731 0 : ::editeng::SvxBorderStyle( aLineTypeDLB.GetSelectEntryStyle( ) ),
732 : nLineWidth,
733 0 : aLineColorDLB.GetSelectEntryColor() );
734 : pColMgr->SetAdjust( SwColLineAdj(
735 0 : aLinePosDLB.GetSelectEntryPos() + 1) );
736 0 : pColMgr->SetLineHeightPercent((short)aLineHeightEdit.GetValue());
737 0 : bEnable = pColMgr->GetLineHeightPercent() != 100;
738 : }
739 0 : aLinePosLbl.Enable( bEnable );
740 0 : aLinePosDLB.Enable( bEnable );
741 :
742 0 : aLineTypeDLB.SetWidth( nLineWidth );
743 0 : aLineTypeDLB.SetColor( aLineColorDLB.GetSelectEntryColor( ) );
744 : }
745 : else
746 : {
747 0 : pColMgr->NoCols();
748 0 : nCols = 0;
749 : }
750 :
751 : //set maximum values
752 : aCLNrEdt.SetMax(Max(1L,
753 0 : Min(long(nMaxCols), long( pColMgr->GetActualSize() / (nGutterWidth + MINLAY)) )));
754 0 : aCLNrEdt.SetLast(aCLNrEdt.GetMax());
755 0 : aCLNrEdt.Reformat();
756 :
757 : //prompt example window
758 0 : if(!bLockUpdate)
759 : {
760 0 : if(bFrm)
761 : {
762 0 : aFrmExampleWN.SetColumns( pColMgr->GetColumns() );
763 0 : aFrmExampleWN.Invalidate();
764 : }
765 : else
766 0 : aPgeExampleWN.Invalidate();
767 : }
768 :
769 0 : return 0;
770 : }
771 :
772 : /*------------------------------------------------------------------------
773 : Description: Initialisation
774 : ------------------------------------------------------------------------*/
775 0 : void SwColumnPage::Init()
776 : {
777 0 : aCLNrEdt.SetValue(nCols);
778 :
779 0 : sal_Bool bAutoWidth = pColMgr->IsAutoWidth() || bHtmlMode;
780 0 : aAutoWidthBox.Check( bAutoWidth );
781 :
782 0 : sal_Int32 nColumnWidthSum = 0;
783 : // set the widths
784 : sal_uInt16 i;
785 0 : for(i = 0; i < nCols; ++i)
786 : {
787 0 : nColWidth[i] = pColMgr->GetColWidth(i);
788 0 : nColumnWidthSum += nColWidth[i];
789 0 : if(i < nCols - 1)
790 0 : nColDist[i] = pColMgr->GetGutterWidth(i);
791 : }
792 :
793 0 : if( 1 < nCols )
794 : {
795 : // #97495# make sure that the automatic column widht's are always equal
796 0 : if(bAutoWidth)
797 : {
798 0 : nColumnWidthSum /= nCols;
799 0 : for(i = 0; i < nCols; ++i)
800 0 : nColWidth[i] = nColumnWidthSum;
801 : }
802 0 : SwColLineAdj eAdj = pColMgr->GetAdjust();
803 0 : if( COLADJ_NONE == eAdj ) // the dialog doesn't know a NONE!
804 : {
805 0 : eAdj = COLADJ_TOP;
806 : //without Adjust no line type
807 0 : aLineTypeDLB.SelectEntryPos( 0 );
808 0 : aLineHeightEdit.SetValue( 100 );
809 : }
810 : else
811 : {
812 : // Need to multiply by 100 because of the 2 decimals
813 0 : aLineWidthEdit.SetValue( pColMgr->GetLineWidth() * 100, FUNIT_TWIP );
814 0 : aLineColorDLB.SelectEntry( pColMgr->GetLineColor() );
815 0 : aLineTypeDLB.SelectEntry( pColMgr->GetLineStyle() );
816 0 : aLineTypeDLB.SetWidth( pColMgr->GetLineWidth( ) );
817 0 : aLineHeightEdit.SetValue( pColMgr->GetLineHeightPercent() );
818 :
819 : }
820 0 : aLinePosDLB.SelectEntryPos( static_cast< sal_uInt16 >(eAdj - 1) );
821 : }
822 : else
823 : {
824 0 : aLinePosDLB.SelectEntryPos( 0 );
825 0 : aLineTypeDLB.SelectEntryPos( 0 );
826 0 : aLineHeightEdit.SetValue( 100 );
827 : }
828 :
829 0 : UpdateCols();
830 0 : Update();
831 :
832 : // set maximum number of columns
833 : // values below 1 are not allowed
834 : aCLNrEdt.SetMax(Max(1L,
835 0 : Min(long(nMaxCols), long( pColMgr->GetActualSize() / nMinWidth) )));
836 0 : }
837 :
838 : /*------------------------------------------------------------------------
839 : Description: The number of columns has changed -- here the controls for
840 : editing of the columns are en- or disabled according to the
841 : column number.
842 : In case there are more than nVisCols (=3) all Edit are being
843 : enabled and the buttons for scrolling too.
844 : Otherwise Edits are being enabled according to the column
845 : numbers; one column can not be edited.
846 : ------------------------------------------------------------------------*/
847 0 : void SwColumnPage::UpdateCols()
848 : {
849 0 : sal_Bool bEnableBtns= sal_False;
850 0 : sal_Bool bEnable12 = sal_False;
851 0 : sal_Bool bEnable3 = sal_False;
852 0 : const sal_Bool bEdit = !aAutoWidthBox.IsChecked();
853 0 : if ( nCols > nVisCols )
854 : {
855 0 : bEnableBtns = sal_True && !bHtmlMode;
856 0 : bEnable12 = bEnable3 = bEdit;
857 : }
858 0 : else if( bEdit )
859 : {
860 : // here are purposely hardly any breaks
861 0 : switch(nCols)
862 : {
863 0 : case 3: bEnable3 = sal_True;
864 0 : case 2: bEnable12= sal_True; break;
865 : default: /* do nothing */;
866 : }
867 : }
868 0 : aEd1.Enable( bEnable12 );
869 0 : aDistEd1.Enable(nCols > 1);
870 0 : aEd2.Enable( bEnable12 );
871 0 : aDistEd2.Enable(bEnable3);
872 0 : aEd3.Enable( bEnable3 );
873 0 : aLbl1.Enable(bEnable12 );
874 0 : aLbl2.Enable(bEnable12 );
875 0 : aLbl3.Enable(bEnable3 );
876 0 : aBtnUp.Enable( bEnableBtns );
877 0 : aBtnDown.Enable( bEnableBtns );
878 :
879 0 : const sal_Bool bEnable = nCols > 1;
880 0 : if( !bEnable )
881 : {
882 0 : aLinePosDLB.Enable( sal_False );
883 0 : aLinePosLbl.Enable( sal_False );
884 : }
885 0 : aLineHeightEdit.Enable( bEnable );
886 0 : aLineHeightLbl.Enable( bEnable );
887 0 : aLineTypeDLB.Enable( bEnable );
888 0 : aLineTypeLbl.Enable( bEnable );
889 0 : aLineWidthLbl.Enable( bEnable );
890 0 : aLineWidthEdit.Enable( bEnable );
891 0 : aLineColorDLB.Enable( bEnable );
892 0 : aLineColorLbl.Enable( bEnable );
893 0 : aAutoWidthBox.Enable( bEnable && !bHtmlMode );
894 0 : }
895 :
896 0 : void SwColumnPage::SetLabels( sal_uInt16 nVis )
897 : {
898 0 : rtl::OUString sLbl( '~' );
899 :
900 0 : String sLbl2( String::CreateFromInt32( nVis + 1 ));
901 0 : String tmp1(sLbl2);
902 0 : sLbl2.Insert(sLbl, sLbl2.Len() - 1);
903 0 : aLbl1.SetText(sLbl2);
904 :
905 0 : sLbl2 = String::CreateFromInt32( nVis + 2 );
906 0 : String tmp2(sLbl2);
907 0 : sLbl2.Insert(sLbl, sLbl2.Len() - 1);
908 0 : aLbl2.SetText(sLbl2);
909 :
910 0 : sLbl2 = String::CreateFromInt32( nVis + 3 );
911 0 : String tmp3(sLbl2);
912 0 : sLbl2.Insert(sLbl, sLbl2.Len() - 1);
913 0 : aLbl3.SetText(sLbl2);
914 0 : String sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH ) ;
915 0 : sColumnWidth.SearchAndReplaceAscii("%1", tmp1);
916 0 : aEd1.SetAccessibleName(sColumnWidth);
917 :
918 0 : sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH ) ;
919 0 : sColumnWidth.SearchAndReplaceAscii("%1", tmp2);
920 0 : aEd2.SetAccessibleName(sColumnWidth);
921 :
922 0 : sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH ) ;
923 0 : sColumnWidth.SearchAndReplaceAscii("%1", tmp3);
924 0 : aEd3.SetAccessibleName(sColumnWidth);
925 :
926 0 : String sDist = SW_RESSTR( STR_ACCESS_PAGESETUP_SPACING ) ;
927 0 : String sDist1 = sDist;
928 0 : sDist1.SearchAndReplaceAscii("%1", tmp1);
929 0 : sDist1.SearchAndReplaceAscii("%2", tmp2);
930 0 : aDistEd1.SetAccessibleName(sDist1);
931 :
932 0 : String sDist2 = sDist;
933 0 : sDist2.SearchAndReplaceAscii("%1", tmp2);
934 0 : sDist2.SearchAndReplaceAscii("%2", tmp3);
935 0 : aDistEd2.SetAccessibleName(sDist2);
936 0 : }
937 :
938 : /*------------------------------------------------------------------------
939 : Description: Handler that is called at alteration of the column number.
940 : An alteration of the column number overwrites potential
941 : user's width settings; all columns are equally wide.
942 : ------------------------------------------------------------------------*/
943 0 : IMPL_LINK( SwColumnPage, ColModify, NumericField *, pNF )
944 : {
945 0 : nCols = (sal_uInt16)aCLNrEdt.GetValue();
946 : //#107890# the handler is also called from LoseFocus()
947 : //then no change has been made and thus no action should be taken
948 : // #i17816# changing the displayed types within the ValueSet
949 : //from two columns to two columns with different settings doesn't invalidate the
950 : // example windows in ::ColModify()
951 0 : if(!pNF ||(pColMgr->GetCount() != nCols))
952 : {
953 0 : if(pNF)
954 0 : aDefaultVS.SetNoSelection();
955 0 : long nDist = static_cast< long >(aDistEd1.DenormalizePercent(aDistEd1.GetValue(FUNIT_TWIP)));
956 0 : pColMgr->SetCount(nCols, (sal_uInt16)nDist);
957 0 : for(sal_uInt16 i = 0; i < nCols; i++)
958 0 : nColDist[i] = nDist;
959 0 : nFirstVis = 0;
960 0 : SetLabels( nFirstVis );
961 0 : UpdateCols();
962 0 : ResetColWidth();
963 0 : Update();
964 : }
965 :
966 0 : return 0;
967 : }
968 :
969 : /*------------------------------------------------------------------------
970 : Description: Modify handler for an alteration of the column width or
971 : the column gap.
972 : These changes take effect time-displaced. With an
973 : alteration of the column width the automatic calculation
974 : of the column width is overruled; only an alteration
975 : of the column number leads back to that default.
976 : ------------------------------------------------------------------------*/
977 0 : IMPL_LINK( SwColumnPage, GapModify, PercentField *, pFld )
978 : {
979 0 : long nActValue = static_cast< long >(pFld->DenormalizePercent(pFld->GetValue(FUNIT_TWIP)));
980 0 : if(nCols < 2)
981 0 : return 0;
982 0 : if(aAutoWidthBox.IsChecked())
983 : {
984 0 : sal_uInt16 nMaxGap = pColMgr->GetActualSize() - nCols * MINLAY;
985 : OSL_ENSURE(nCols, "Abstand kann nicht ohne Spalten eingestellt werden");
986 0 : nMaxGap /= nCols - 1;
987 0 : if(nActValue > nMaxGap)
988 : {
989 0 : nActValue = nMaxGap;
990 0 : aDistEd1.SetPrcntValue(aDistEd1.NormalizePercent(nMaxGap), FUNIT_TWIP);
991 : }
992 0 : pColMgr->SetGutterWidth((sal_uInt16)nActValue);
993 0 : for(sal_uInt16 i = 0; i < nCols; i++)
994 0 : nColDist[i] = nActValue;
995 :
996 0 : ResetColWidth();
997 0 : UpdateCols();
998 : }
999 : else
1000 :
1001 : {
1002 0 : sal_uInt16 nOffset = 0;
1003 0 : if(pFld == &aDistEd2)
1004 : {
1005 0 : nOffset = 1;
1006 : }
1007 0 : long nDiff = nActValue - nColDist[nFirstVis + nOffset];
1008 0 : if(nDiff)
1009 : {
1010 0 : long nLeft = nColWidth[nFirstVis + nOffset];
1011 0 : long nRight = nColWidth[nFirstVis + nOffset + 1];
1012 0 : if(nLeft + nRight + 2 * MINLAY < nDiff)
1013 0 : nDiff = nLeft + nRight - 2 * MINLAY;
1014 0 : if(nDiff < nRight - MINLAY)
1015 : {
1016 0 : nRight -= nDiff;
1017 : }
1018 : else
1019 : {
1020 0 : long nTemp = nDiff - nRight + MINLAY;
1021 0 : nRight = MINLAY;
1022 0 : if(nLeft > nTemp - MINLAY)
1023 : {
1024 0 : nLeft -= nTemp;
1025 0 : nTemp = 0;
1026 : }
1027 : else
1028 : {
1029 0 : nTemp -= nLeft + MINLAY;
1030 0 : nLeft = MINLAY;
1031 : }
1032 0 : nDiff = nTemp;
1033 : }
1034 0 : nColWidth[nFirstVis + nOffset] = nLeft;
1035 0 : nColWidth[nFirstVis + nOffset + 1] = nRight;
1036 0 : nColDist[nFirstVis + nOffset] += nDiff;
1037 :
1038 0 : pColMgr->SetColWidth( nFirstVis + nOffset, sal_uInt16(nLeft) );
1039 0 : pColMgr->SetColWidth( nFirstVis + nOffset + 1, sal_uInt16(nRight) );
1040 0 : pColMgr->SetGutterWidth( sal_uInt16(nColDist[nFirstVis + nOffset]), nFirstVis + nOffset );
1041 : }
1042 :
1043 : }
1044 0 : Update();
1045 0 : return 0;
1046 : }
1047 :
1048 0 : IMPL_LINK( SwColumnPage, EdModify, PercentField *, pField )
1049 : {
1050 0 : pModifiedField = pField;
1051 0 : Timeout();
1052 0 : return 0;
1053 : }
1054 :
1055 : /*------------------------------------------------------------------------
1056 : Description: Handler behind the Checkbox for automatic width.
1057 : When the box is checked no expicit values for the column
1058 : width can be entered.
1059 : ------------------------------------------------------------------------*/
1060 0 : IMPL_LINK( SwColumnPage, AutoWidthHdl, CheckBox *, pBox )
1061 : {
1062 0 : long nDist = static_cast< long >(aDistEd1.DenormalizePercent(aDistEd1.GetValue(FUNIT_TWIP)));
1063 0 : pColMgr->SetCount(nCols, (sal_uInt16)nDist);
1064 0 : for(sal_uInt16 i = 0; i < nCols; i++)
1065 0 : nColDist[i] = nDist;
1066 0 : if(pBox->IsChecked())
1067 : {
1068 0 : pColMgr->SetGutterWidth(sal_uInt16(nDist));
1069 0 : ResetColWidth();
1070 : }
1071 0 : pColMgr->SetAutoWidth(pBox->IsChecked(), sal_uInt16(nDist));
1072 0 : UpdateCols();
1073 0 : Update();
1074 0 : return 0;
1075 : }
1076 :
1077 : /*------------------------------------------------------------------------
1078 : Description: scroll up the contents of the edits
1079 : ------------------------------------------------------------------------*/
1080 0 : IMPL_LINK_NOARG(SwColumnPage, Up)
1081 : {
1082 0 : if( nFirstVis )
1083 : {
1084 0 : --nFirstVis;
1085 0 : SetLabels( nFirstVis );
1086 0 : Update();
1087 : }
1088 0 : return 0;
1089 : }
1090 :
1091 : /*------------------------------------------------------------------------
1092 : Description: scroll down the contents of the edits.
1093 : ------------------------------------------------------------------------*/
1094 0 : IMPL_LINK_NOARG(SwColumnPage, Down)
1095 : {
1096 0 : if( nFirstVis + nVisCols < nCols )
1097 : {
1098 0 : ++nFirstVis;
1099 0 : SetLabels( nFirstVis );
1100 0 : Update();
1101 : }
1102 0 : return 0;
1103 : }
1104 :
1105 : /*------------------------------------------------------------------------
1106 : Description: relict from ancient times - now directly without time
1107 : handler; triggered by an alteration of the column width
1108 : or the column gap.
1109 : ------------------------------------------------------------------------*/
1110 0 : void SwColumnPage::Timeout()
1111 : {
1112 : DBG_PROFSTART(columnhdl) ;
1113 0 : if(pModifiedField)
1114 : {
1115 : // find the changed column
1116 0 : sal_uInt16 nChanged = nFirstVis;
1117 0 : if(pModifiedField == &aEd2)
1118 0 : ++nChanged;
1119 0 : else if(pModifiedField == &aEd3)
1120 0 : nChanged += 2;
1121 :
1122 : long nNewWidth = (sal_uInt16)
1123 0 : pModifiedField->DenormalizePercent(pModifiedField->GetValue(FUNIT_TWIP));
1124 0 : long nDiff = nNewWidth - nColWidth[nChanged];
1125 :
1126 : // when it's the last column
1127 0 : if(nChanged == nCols - 1)
1128 : {
1129 0 : nColWidth[0] -= nDiff;
1130 0 : if(nColWidth[0] < (long)nMinWidth)
1131 : {
1132 0 : nNewWidth -= nMinWidth - nColWidth[0];
1133 0 : nColWidth[0] = nMinWidth;
1134 : }
1135 :
1136 : }
1137 0 : else if(nDiff)
1138 : {
1139 0 : nColWidth[nChanged + 1] -= nDiff;
1140 0 : if(nColWidth[nChanged + 1] < (long) nMinWidth)
1141 : {
1142 0 : nNewWidth -= nMinWidth - nColWidth[nChanged + 1];
1143 0 : nColWidth[nChanged + 1] = nMinWidth;
1144 : }
1145 : }
1146 0 : nColWidth[nChanged] = nNewWidth;
1147 0 : pModifiedField = 0;
1148 : }
1149 0 : Update();
1150 : DBG_PROFSTOP(columnhdl) ;
1151 0 : }
1152 :
1153 : /*------------------------------------------------------------------------
1154 : Description: Update the view
1155 : ------------------------------------------------------------------------*/
1156 0 : void SwColumnPage::Update()
1157 : {
1158 0 : aBalanceColsCB.Enable(nCols > 1);
1159 0 : if(nCols >= 2)
1160 : {
1161 0 : aEd1.SetPrcntValue(aEd1.NormalizePercent(nColWidth[nFirstVis]), FUNIT_TWIP);
1162 0 : aDistEd1.SetPrcntValue(aDistEd1.NormalizePercent(nColDist[nFirstVis]), FUNIT_TWIP);
1163 0 : aEd2.SetPrcntValue(aEd2.NormalizePercent(nColWidth[nFirstVis + 1]), FUNIT_TWIP);
1164 0 : if(nCols >= 3)
1165 : {
1166 0 : aDistEd2.SetPrcntValue(aDistEd2.NormalizePercent(nColDist[nFirstVis + 1]), FUNIT_TWIP);
1167 0 : aEd3.SetPrcntValue(aEd3.NormalizePercent(nColWidth[nFirstVis + 2]), FUNIT_TWIP);
1168 : }
1169 : else
1170 : {
1171 0 : aEd3.SetText(aEmptyStr);
1172 0 : aDistEd2.SetText(aEmptyStr);
1173 : }
1174 : }
1175 : else
1176 : {
1177 0 : aEd1.SetText(aEmptyStr);
1178 0 : aEd2.SetText(aEmptyStr);
1179 0 : aEd3.SetText(aEmptyStr);
1180 0 : aDistEd1.SetText(aEmptyStr);
1181 0 : aDistEd2.SetText(aEmptyStr);
1182 : }
1183 0 : UpdateColMgr(0);
1184 0 : }
1185 :
1186 : /*--------------------------------------------------------------------
1187 : Description: Update Bsp
1188 : --------------------------------------------------------------------*/
1189 0 : void SwColumnPage::ActivatePage(const SfxItemSet& rSet)
1190 : {
1191 0 : if(!bFrm)
1192 : {
1193 0 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_SIZE ))
1194 : {
1195 : const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get(
1196 0 : SID_ATTR_PAGE_SIZE);
1197 : const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rSet.Get(
1198 0 : RES_LR_SPACE );
1199 0 : const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
1200 0 : sal_uInt16 nActWidth = static_cast< sal_uInt16 >(rSize.GetSize().Width()
1201 0 : - rLRSpace.GetLeft() - rLRSpace.GetRight() - rBox.GetDistance());
1202 :
1203 0 : if( pColMgr->GetActualSize() != nActWidth)
1204 : {
1205 0 : pColMgr->SetActualWidth(nActWidth);
1206 0 : ColModify( 0 );
1207 0 : UpdateColMgr( 0 );
1208 : }
1209 : }
1210 0 : aFrmExampleWN.Hide();
1211 0 : aPgeExampleWN.UpdateExample( rSet, pColMgr );
1212 0 : aPgeExampleWN.Show();
1213 :
1214 : }
1215 : else
1216 : {
1217 0 : aPgeExampleWN.Hide();
1218 0 : aFrmExampleWN.Show();
1219 :
1220 : // Size
1221 0 : const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE);
1222 0 : const SvxBoxItem& rBox = (const SvxBoxItem&) rSet.Get(RES_BOX);
1223 :
1224 0 : long nDistance = rBox.GetDistance();
1225 0 : const sal_uInt16 nTotalWish = bFormat ? FRAME_FORMAT_WIDTH : sal_uInt16(rSize.GetWidth() - 2 * nDistance);
1226 :
1227 : // set maximum values of column width
1228 0 : SetPageWidth(nTotalWish);
1229 :
1230 0 : if(pColMgr->GetActualSize() != nTotalWish)
1231 : {
1232 0 : pColMgr->SetActualWidth(nTotalWish);
1233 0 : Init();
1234 : }
1235 : sal_Bool bPercent;
1236 : // only relative data in frame format
1237 0 : if ( bFormat || (rSize.GetWidthPercent() && rSize.GetWidthPercent() != 0xff) )
1238 : {
1239 : // set value for 100%
1240 0 : aEd1.SetRefValue(nTotalWish);
1241 0 : aEd2.SetRefValue(nTotalWish);
1242 0 : aEd3.SetRefValue(nTotalWish);
1243 0 : aDistEd1.SetRefValue(nTotalWish);
1244 0 : aDistEd2.SetRefValue(nTotalWish);
1245 :
1246 : // switch to %-view
1247 0 : bPercent = sal_True;
1248 : }
1249 : else
1250 0 : bPercent = sal_False;
1251 :
1252 0 : aEd1.ShowPercent(bPercent);
1253 0 : aEd2.ShowPercent(bPercent);
1254 0 : aEd3.ShowPercent(bPercent);
1255 0 : aDistEd1.ShowPercent(bPercent);
1256 0 : aDistEd2.ShowPercent(bPercent);
1257 0 : aDistEd1.MetricField::SetMin(0);
1258 0 : aDistEd2.MetricField::SetMin(0);
1259 : }
1260 0 : Update();
1261 0 : }
1262 :
1263 0 : int SwColumnPage::DeactivatePage(SfxItemSet *_pSet)
1264 : {
1265 0 : if(_pSet)
1266 0 : FillItemSet(*_pSet);
1267 :
1268 0 : return sal_True;
1269 : }
1270 :
1271 0 : sal_uInt16* SwColumnPage::GetRanges()
1272 : {
1273 0 : return aPageRg;
1274 : }
1275 :
1276 0 : IMPL_LINK( SwColumnPage, SetDefaultsHdl, ValueSet *, pVS )
1277 : {
1278 0 : sal_uInt16 nItem = pVS->GetSelectItemId();
1279 0 : if( nItem < 4 )
1280 : {
1281 0 : aCLNrEdt.SetValue( nItem );
1282 0 : aAutoWidthBox.Check();
1283 0 : aDistEd1.SetPrcntValue(0);
1284 0 : ColModify(0);
1285 : }
1286 : else
1287 : {
1288 0 : bLockUpdate = sal_True;
1289 0 : aCLNrEdt.SetValue( 2 );
1290 0 : aAutoWidthBox.Check(sal_False);
1291 0 : aDistEd1.SetPrcntValue(0);
1292 0 : ColModify(0);
1293 : // now set the width ratio to 2 : 1 or 1 : 2 respectively
1294 0 : sal_uInt16 nSmall = pColMgr->GetActualSize() / 3;
1295 0 : if(nItem == 4)
1296 : {
1297 0 : aEd2.SetPrcntValue(aEd2.NormalizePercent(long(nSmall)), FUNIT_TWIP);
1298 0 : pModifiedField = &aEd2;
1299 : }
1300 : else
1301 : {
1302 0 : aEd1.SetPrcntValue(aEd1.NormalizePercent(long(nSmall)), FUNIT_TWIP);
1303 0 : pModifiedField = &aEd1;
1304 : }
1305 0 : bLockUpdate = sal_False;
1306 0 : Timeout();
1307 :
1308 : }
1309 0 : return 0;
1310 : }
1311 :
1312 0 : void SwColumnPage::SetFrmMode(sal_Bool bMod)
1313 : {
1314 0 : bFrm = bMod;
1315 0 : }
1316 :
1317 0 : void SwColumnPage::SetInSection(sal_Bool bSet)
1318 : {
1319 0 : if(!SW_MOD()->GetCTLOptions().IsCTLFontEnabled())
1320 0 : return;
1321 :
1322 0 : aTextDirectionFT.Show(bSet);
1323 0 : aTextDirectionLB.Show(bSet);
1324 : }
1325 :
1326 0 : void ColumnValueSet::UserDraw( const UserDrawEvent& rUDEvt )
1327 : {
1328 0 : OutputDevice* pDev = rUDEvt.GetDevice();
1329 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1330 :
1331 0 : Rectangle aRect = rUDEvt.GetRect();
1332 0 : sal_uInt16 nItemId = rUDEvt.GetItemId();
1333 0 : long nRectWidth = aRect.GetWidth();
1334 0 : long nRectHeight = aRect.GetHeight();
1335 :
1336 0 : Point aBLPos = aRect.TopLeft();
1337 0 : Color aFillColor(pDev->GetFillColor());
1338 0 : Color aLineColor(pDev->GetLineColor());
1339 0 : pDev->SetFillColor(rStyleSettings.GetFieldColor());
1340 0 : pDev->SetLineColor(SwViewOption::GetFontColor());
1341 :
1342 0 : long nStep = Abs(Abs(nRectHeight * 95 /100) / 11);
1343 0 : long nTop = (nRectHeight - 11 * nStep ) / 2;
1344 0 : sal_uInt16 nCols = 0;
1345 : long nStarts[3];
1346 : long nEnds[3];
1347 0 : nStarts[0] = nRectWidth * 10 / 100;
1348 0 : switch( nItemId )
1349 : {
1350 : case 1:
1351 0 : nEnds[0] = nRectWidth * 9 / 10;
1352 0 : nCols = 1;
1353 0 : break;
1354 0 : case 2: nCols = 2;
1355 0 : nEnds[0] = nRectWidth * 45 / 100;
1356 0 : nStarts[1] = nEnds[0] + nStep;
1357 0 : nEnds[1] = nRectWidth * 9 / 10;
1358 0 : break;
1359 0 : case 3: nCols = 3;
1360 0 : nEnds[0] = nRectWidth * 30 / 100;
1361 0 : nStarts[1] = nEnds[0] + nStep;
1362 0 : nEnds[1] = nRectWidth * 63 / 100;
1363 0 : nStarts[2] = nEnds[1] + nStep;
1364 0 : nEnds[2] = nRectWidth * 9 / 10;
1365 0 : break;
1366 0 : case 4: nCols = 2;
1367 0 : nEnds[0] = nRectWidth * 63 / 100;
1368 0 : nStarts[1] = nEnds[0] + nStep;
1369 0 : nEnds[1] = nRectWidth * 9 / 10;
1370 0 : break;
1371 0 : case 5: nCols = 2;
1372 0 : nEnds[0] = nRectWidth * 30 / 100;
1373 0 : nStarts[1] = nEnds[0] + nStep;
1374 0 : nEnds[1] = nRectWidth * 9 / 10;
1375 0 : break;
1376 : }
1377 0 : for(sal_uInt16 j = 0; j < nCols; j++ )
1378 : {
1379 0 : Point aStart(aBLPos.X() + nStarts[j], 0);
1380 0 : Point aEnd(aBLPos.X() + nEnds[j], 0);
1381 0 : for( sal_uInt16 i = 0; i < 12; i ++)
1382 : {
1383 0 : aStart.Y() = aEnd.Y() = aBLPos.Y() + nTop + i * nStep;
1384 0 : pDev->DrawLine(aStart, aEnd);
1385 : }
1386 : }
1387 0 : pDev->SetFillColor(aFillColor);
1388 0 : pDev->SetLineColor(aLineColor);
1389 0 : }
1390 :
1391 0 : ColumnValueSet::~ColumnValueSet()
1392 : {
1393 0 : }
1394 :
1395 0 : void ColumnValueSet::DataChanged( const DataChangedEvent& rDCEvt )
1396 : {
1397 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1398 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1399 : {
1400 0 : Format();
1401 : }
1402 0 : ValueSet::DataChanged( rDCEvt );
1403 0 : }
1404 :
1405 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|