LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/frmdlg - column.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 767 0.0 %
Date: 2013-07-09 Functions: 0 49 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10