LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/table - tabledlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1020 0.0 %
Date: 2013-07-09 Functions: 0 64 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 <hintids.hxx>
      21             : #include <comphelper/string.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <svl/stritem.hxx>
      24             : #include <svl/intitem.hxx>
      25             : #include <editeng/keepitem.hxx>
      26             : #include <editeng/formatbreakitem.hxx>
      27             : #include <editeng/ulspitem.hxx>
      28             : #include <editeng/frmdiritem.hxx>
      29             : #include <svl/ctloptions.hxx>
      30             : #include <swmodule.hxx>
      31             : #include <fmtornt.hxx>
      32             : #include <fmtpdsc.hxx>
      33             : #include <fmtlsplt.hxx>
      34             : 
      35             : #include <svtools/htmlcfg.hxx>
      36             : #include <fmtrowsplt.hxx>
      37             : #include <sfx2/htmlmode.hxx>
      38             : 
      39             : #include "access.hrc"
      40             : 
      41             : #include <docsh.hxx>
      42             : #include <wrtsh.hxx>
      43             : #include <view.hxx>
      44             : #include <viewopt.hxx>
      45             : #include <uitool.hxx>
      46             : #include <frmatr.hxx>
      47             : #include <tabledlg.hxx>
      48             : #include <tablepg.hxx>
      49             : #include <tablemgr.hxx>
      50             : #include <pagedesc.hxx>
      51             : #include <uiitems.hxx>
      52             : #include <poolfmt.hxx>
      53             : #include <SwStyleNameMapper.hxx>
      54             : 
      55             : #include <cmdid.h>
      56             : #include <table.hrc>
      57             : #include <svx/svxids.hrc>
      58             : #include <svx/dialogs.hrc>
      59             : #include <svx/flagsdef.hxx>
      60             : #include <svx/svxdlg.hxx>
      61             : 
      62             : using namespace ::com::sun::star;
      63             : 
      64             : 
      65           0 : SwFormatTablePage::SwFormatTablePage(Window* pParent, const SfxItemSet& rSet)
      66             :     : SfxTabPage(pParent, "FormatTablePage", "modules/swriter/ui/formattablepage.ui", rSet)
      67             :     , pTblData(0)
      68             :     , nSaveWidth(0)
      69             :     , nMinTableWidth(MINLAY)
      70             :     , bModified(sal_False)
      71             :     , bFull(0)
      72           0 :     , bHtmlMode(sal_False)
      73             : {
      74           0 :     get(m_pNameED, "name");
      75           0 :     get(m_pWidthFT, "widthft");
      76           0 :     m_aWidthMF.set(get<MetricField>("widthmf"));
      77           0 :     m_aLeftMF.set(get<MetricField>("leftmf"));
      78           0 :     m_aRightMF.set(get<MetricField>("rightmf"));
      79           0 :     get(m_pRelWidthCB, "relwidth");
      80           0 :     get(m_pFullBtn, "full");
      81           0 :     get(m_pLeftBtn, "left");
      82           0 :     get(m_pFromLeftBtn, "fromleft");
      83           0 :     get(m_pRightBtn, "right");
      84           0 :     get(m_pCenterBtn, "center");
      85           0 :     get(m_pFreeBtn, "free");
      86           0 :     get(m_pLeftFT, "leftft");
      87           0 :     get(m_pRightFT, "rightft");
      88           0 :     get(m_pTopFT, "aboveft");
      89           0 :     get(m_pTopMF, "abovemf");
      90           0 :     get(m_pBottomFT, "belowft");
      91           0 :     get(m_pBottomMF, "belowmf");
      92           0 :     get(m_pTextDirectionLB, "textdirection");
      93             : 
      94           0 :     SetExchangeSupport();
      95             : 
      96             :     const SfxPoolItem* pItem;
      97           0 :     if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem))
      98           0 :         bHtmlMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
      99             : 
     100           0 :     bool bCTL = SW_MOD()->GetCTLOptions().IsCTLFontEnabled();
     101           0 :     get<VclContainer>("properties")->Show(!bHtmlMode && bCTL);
     102             : 
     103           0 :     Init();
     104           0 : }
     105             : 
     106             : 
     107           0 : void  SwFormatTablePage::Init()
     108             : {
     109           0 :     m_aLeftMF.SetMetricFieldMin(-999999);
     110           0 :     m_aRightMF.SetMetricFieldMin(-999999);
     111             : 
     112             :     // handler
     113           0 :     Link aLk = LINK( this, SwFormatTablePage, AutoClickHdl );
     114           0 :     m_pFullBtn->SetClickHdl( aLk );
     115           0 :     m_pFreeBtn->SetClickHdl( aLk );
     116           0 :     m_pLeftBtn->SetClickHdl( aLk );
     117           0 :     m_pFromLeftBtn->SetClickHdl( aLk );
     118           0 :     m_pRightBtn->SetClickHdl( aLk );
     119           0 :     m_pCenterBtn->SetClickHdl( aLk );
     120             : 
     121           0 :     aLk = LINK( this, SwFormatTablePage, UpDownLoseFocusHdl );
     122           0 :     m_pTopMF->SetUpHdl( aLk );
     123           0 :     m_pBottomMF->SetUpHdl( aLk );
     124           0 :     m_aRightMF.SetUpHdl( aLk );
     125           0 :     m_aLeftMF.SetUpHdl( aLk );
     126           0 :     m_aWidthMF.SetUpHdl( aLk );
     127             : 
     128           0 :     m_pTopMF->SetDownHdl( aLk );
     129           0 :     m_pBottomMF->SetDownHdl( aLk );
     130           0 :     m_aRightMF.SetDownHdl( aLk );
     131           0 :     m_aLeftMF.SetDownHdl( aLk );
     132           0 :     m_aWidthMF.SetDownHdl( aLk );
     133             : 
     134           0 :     m_pTopMF->SetLoseFocusHdl( aLk );
     135           0 :     m_pBottomMF->SetLoseFocusHdl( aLk );
     136           0 :     m_aRightMF.SetLoseFocusHdl( aLk );
     137           0 :     m_aLeftMF.SetLoseFocusHdl( aLk );
     138           0 :     m_aWidthMF.SetLoseFocusHdl( aLk );
     139             : 
     140           0 :     m_pRelWidthCB->SetClickHdl(LINK( this, SwFormatTablePage, RelWidthClickHdl ));
     141           0 : }
     142             : 
     143           0 : IMPL_LINK( SwFormatTablePage, RelWidthClickHdl, CheckBox *, pBtn )
     144             : {
     145             :     OSL_ENSURE(pTblData, "table data not available?");
     146           0 :     sal_Bool bIsChecked = pBtn->IsChecked();
     147           0 :     sal_Int64 nLeft  = m_aLeftMF.DenormalizePercent(m_aLeftMF.GetValue(FUNIT_TWIP ));
     148           0 :     sal_Int64 nRight = m_aRightMF.DenormalizePercent(m_aRightMF.GetValue(FUNIT_TWIP ));
     149           0 :     m_aWidthMF.ShowPercent(bIsChecked);
     150           0 :     m_aLeftMF.ShowPercent(bIsChecked);
     151           0 :     m_aRightMF.ShowPercent(bIsChecked);
     152             : 
     153           0 :     if (bIsChecked)
     154             :     {
     155           0 :         m_aWidthMF.SetRefValue(pTblData->GetSpace());
     156           0 :         m_aLeftMF.SetRefValue(pTblData->GetSpace());
     157           0 :         m_aRightMF.SetRefValue(pTblData->GetSpace());
     158           0 :         m_aLeftMF.SetMetricFieldMin(0); // will be overwritten by the Percentfield
     159           0 :         m_aRightMF.SetMetricFieldMin(0); //                 -""-
     160           0 :         m_aLeftMF.SetMetricFieldMax(99); //
     161           0 :         m_aRightMF.SetMetricFieldMax(99); //
     162           0 :         m_aLeftMF.SetPrcntValue(m_aLeftMF.NormalizePercent(nLeft ), FUNIT_TWIP );
     163           0 :         m_aRightMF.SetPrcntValue(m_aRightMF.NormalizePercent(nRight ), FUNIT_TWIP );
     164             :     }
     165             :     else
     166           0 :         ModifyHdl(m_aLeftMF.get());    // correct values again
     167             : 
     168           0 :     if(m_pFreeBtn->IsChecked())
     169             :     {
     170           0 :         sal_Bool bEnable = !pBtn->IsChecked();
     171           0 :         m_aRightMF.Enable(bEnable);
     172           0 :         m_pRightFT->Enable(bEnable);
     173             :     }
     174           0 :     bModified = sal_True;
     175             : 
     176           0 :     return 0;
     177             : }
     178             : 
     179             : 
     180           0 : IMPL_LINK( SwFormatTablePage, AutoClickHdl, CheckBox *, pBox )
     181             : {
     182           0 :     sal_Bool bRestore = sal_True,
     183           0 :          bLeftEnable = sal_False,
     184           0 :          bRightEnable= sal_False,
     185           0 :          bWidthEnable= sal_False,
     186           0 :          bOthers = sal_True;
     187           0 :     if ((RadioButton *)pBox == m_pFullBtn)
     188             :     {
     189           0 :         m_aLeftMF.SetPrcntValue(0);
     190           0 :         m_aRightMF.SetPrcntValue(0);
     191           0 :         nSaveWidth = static_cast< SwTwips >(m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue(FUNIT_TWIP )));
     192           0 :         m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(pTblData->GetSpace() ), FUNIT_TWIP );
     193           0 :         bFull = sal_True;
     194           0 :         bRestore = sal_False;
     195             :     }
     196           0 :     else if ((RadioButton *)pBox == m_pLeftBtn)
     197             :     {
     198           0 :         bRightEnable = bWidthEnable = sal_True;
     199           0 :         m_aLeftMF.SetPrcntValue(0);
     200             :     }
     201           0 :     else if ((RadioButton *) pBox == m_pFromLeftBtn)
     202             :     {
     203           0 :         bLeftEnable = bWidthEnable = sal_True;
     204           0 :         m_aRightMF.SetPrcntValue(0);
     205             :     }
     206           0 :     else if ((RadioButton *) pBox == m_pRightBtn)
     207             :     {
     208           0 :         bLeftEnable = bWidthEnable = sal_True;
     209           0 :         m_aRightMF.SetPrcntValue(0);
     210             :     }
     211           0 :     else if ((RadioButton *) pBox == m_pCenterBtn)
     212             :     {
     213           0 :         bLeftEnable = bWidthEnable = sal_True;
     214             :     }
     215           0 :     else if ((RadioButton *) pBox == m_pFreeBtn)
     216             :     {
     217           0 :         RightModify();
     218           0 :         bLeftEnable = sal_True;
     219           0 :         bWidthEnable = sal_True;
     220           0 :         bOthers = sal_False;
     221             :     }
     222           0 :     m_aLeftMF.Enable(bLeftEnable);
     223           0 :     m_pLeftFT->Enable(bLeftEnable);
     224           0 :     m_aWidthMF.Enable(bWidthEnable);
     225           0 :     m_pWidthFT->Enable(bWidthEnable);
     226           0 :     if ( bOthers )
     227             :     {
     228           0 :         m_aRightMF.Enable(bRightEnable);
     229           0 :         m_pRightFT->Enable(bRightEnable);
     230           0 :         m_pRelWidthCB->Enable(bWidthEnable);
     231             :     }
     232             : 
     233           0 :     if(bFull && bRestore)
     234             :     {
     235             :         // After being switched on automatic, the width was pinned
     236             :         // in order to restore the width while switching back to.
     237           0 :         bFull = sal_False;
     238           0 :         m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(nSaveWidth ), FUNIT_TWIP );
     239             :     }
     240           0 :     ModifyHdl(m_aWidthMF.get());
     241           0 :     bModified = sal_True;
     242           0 :     return 0;
     243             : }
     244             : 
     245           0 : void SwFormatTablePage::RightModify()
     246             : {
     247           0 :     if(m_pFreeBtn->IsChecked())
     248             :     {
     249           0 :         sal_Bool bEnable = m_aRightMF.GetValue() == 0;
     250           0 :         m_pRelWidthCB->Enable(bEnable);
     251           0 :         if ( !bEnable )
     252             :         {
     253           0 :             m_pRelWidthCB->Check(sal_False);
     254           0 :             RelWidthClickHdl(m_pRelWidthCB);
     255             :         }
     256           0 :         bEnable = m_pRelWidthCB->IsChecked();
     257           0 :         m_aRightMF.Enable(!bEnable);
     258           0 :         m_pRightFT->Enable(!bEnable);
     259             :     }
     260           0 : }
     261             : 
     262             : 
     263           0 : IMPL_LINK_INLINE_START( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
     264             : {
     265           0 :     if( m_aRightMF.get() == pEdit)
     266           0 :         RightModify();
     267           0 :     ModifyHdl( pEdit );
     268           0 :     return 0;
     269             : }
     270           0 : IMPL_LINK_INLINE_END( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
     271             : 
     272           0 : void  SwFormatTablePage::ModifyHdl(const Edit * pEdit)
     273             : {
     274             : 
     275           0 :     SwTwips nCurWidth  = static_cast< SwTwips >(m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue( FUNIT_TWIP )));
     276           0 :     SwTwips nPrevWidth = nCurWidth;
     277           0 :     SwTwips nRight = static_cast< SwTwips >(m_aRightMF.DenormalizePercent(m_aRightMF.GetValue( FUNIT_TWIP )));
     278           0 :     SwTwips nLeft  = static_cast< SwTwips >(m_aLeftMF.DenormalizePercent(m_aLeftMF.GetValue( FUNIT_TWIP )));
     279             :     SwTwips nDiff;
     280             : 
     281           0 :     if (pEdit == m_aWidthMF.get())
     282             :     {
     283           0 :         if( nCurWidth < MINLAY )
     284           0 :             nCurWidth = MINLAY;
     285           0 :         nDiff = nRight + nLeft + nCurWidth - pTblData->GetSpace() ;
     286             :         //right aligned: only change the left margin
     287           0 :         if(m_pRightBtn->IsChecked())
     288           0 :             nLeft -= nDiff;
     289             :         //left aligned: only change the right margin
     290           0 :         else if(m_pLeftBtn->IsChecked())
     291           0 :             nRight -= nDiff;
     292             :         //left margin and width allowed - first right - then left
     293           0 :         else if(m_pFromLeftBtn->IsChecked())
     294             :         {
     295           0 :             if( nRight >= nDiff )
     296           0 :                 nRight -= nDiff;
     297             :             else
     298             :             {
     299           0 :                 nDiff -= nRight;
     300           0 :                 nRight = 0;
     301           0 :                 if(nLeft >= nDiff)
     302           0 :                     nLeft -= nDiff;
     303             :                 else
     304             :                 {
     305           0 :                     nRight += nLeft - nDiff;
     306           0 :                     nLeft = 0;
     307           0 :                     nCurWidth = pTblData->GetSpace();
     308             :                 }
     309             : 
     310             :             }
     311             :         }
     312             :         //centered: change both sides equally
     313           0 :         else if(m_pCenterBtn->IsChecked())
     314             :         {
     315           0 :             if((nLeft != nRight))
     316             :             {
     317           0 :                 nDiff += nLeft + nRight;
     318           0 :                 nLeft = nDiff/2;
     319           0 :                 nRight = nDiff/2;
     320             :             }
     321             :             else
     322             :             {
     323           0 :                     nLeft -= nDiff/2;
     324           0 :                     nRight -= nDiff/2;
     325             :             }
     326             :         }
     327             :         //free alignment: decrease both margins
     328           0 :         else if(m_pFreeBtn->IsChecked())
     329             :         {
     330           0 :             nLeft -= nDiff/2;
     331           0 :             nRight -= nDiff/2;
     332             :         }
     333             :     }
     334           0 :     if (pEdit == m_aRightMF.get())
     335             :     {
     336             : 
     337           0 :         if( nRight + nLeft > pTblData->GetSpace() - MINLAY )
     338           0 :             nRight = pTblData->GetSpace() -nLeft - MINLAY;
     339             : 
     340           0 :         nCurWidth = pTblData->GetSpace() - nLeft - nRight;
     341             :     }
     342           0 :     if (pEdit == m_aLeftMF.get())
     343             :     {
     344           0 :         if(!m_pFromLeftBtn->IsChecked())
     345             :         {
     346           0 :             sal_Bool bCenter = m_pCenterBtn->IsChecked();
     347           0 :             if( bCenter )
     348           0 :                 nRight = nLeft;
     349           0 :             if(nRight + nLeft > pTblData->GetSpace() - MINLAY )
     350             :             {
     351           0 :                 nLeft  = bCenter ?  (pTblData->GetSpace() - MINLAY) /2 :
     352           0 :                                     (pTblData->GetSpace() - MINLAY) - nRight;
     353           0 :                 nRight = bCenter ?  (pTblData->GetSpace() - MINLAY) /2 : nRight;
     354             :             }
     355           0 :             nCurWidth = pTblData->GetSpace() - nLeft - nRight;
     356             :         }
     357             :         else
     358             :         {
     359             :             //Upon changes on the left side the right margin will be changed at first,
     360             :             //thereafter the width.
     361           0 :             nDiff = nRight + nLeft + nCurWidth - pTblData->GetSpace() ;
     362             : 
     363           0 :             nRight -= nDiff;
     364           0 :             nCurWidth = pTblData->GetSpace() - nLeft - nRight;
     365             :         }
     366             :     }
     367           0 :     if (nCurWidth != nPrevWidth )
     368           0 :         m_aWidthMF.SetPrcntValue( m_aWidthMF.NormalizePercent( nCurWidth ), FUNIT_TWIP );
     369           0 :     m_aRightMF.SetPrcntValue( m_aRightMF.NormalizePercent( nRight ), FUNIT_TWIP );
     370           0 :     m_aLeftMF.SetPrcntValue( m_aLeftMF.NormalizePercent( nLeft ), FUNIT_TWIP );
     371           0 :     bModified = sal_True;
     372           0 : }
     373             : 
     374             : 
     375           0 : SfxTabPage*  SwFormatTablePage::Create( Window* pParent,
     376             :                                    const SfxItemSet& rAttrSet)
     377             : {
     378           0 :     return new SwFormatTablePage( pParent, rAttrSet );
     379             : }
     380             : 
     381             : 
     382           0 : sal_Bool  SwFormatTablePage::FillItemSet( SfxItemSet& rCoreSet )
     383             : {
     384             :     // Test if one of the controls still has the focus.
     385           0 :     if (m_aWidthMF.HasFocus())
     386           0 :         ModifyHdl(m_aWidthMF.get());
     387           0 :     else if (m_aLeftMF.HasFocus())
     388           0 :         ModifyHdl(m_aLeftMF.get());
     389           0 :     else if(m_aRightMF.HasFocus())
     390           0 :         ModifyHdl(m_aRightMF.get());
     391           0 :     else if(m_pTopMF->HasFocus())
     392           0 :         ModifyHdl(m_pTopMF);
     393           0 :     else if(m_pBottomMF->HasFocus())
     394           0 :         ModifyHdl(m_pBottomMF);
     395             : 
     396           0 :     if(bModified)
     397             :     {
     398           0 :         if( m_pBottomMF->GetText() != m_pBottomMF->GetSavedValue() ||
     399           0 :             m_pTopMF->GetText() != m_pTopMF->GetSavedValue() )
     400             :         {
     401           0 :             SvxULSpaceItem aULSpace(RES_UL_SPACE);
     402             :             aULSpace.SetUpper( (sal_uInt16) m_pTopMF->Denormalize(
     403           0 :                                         m_pTopMF->GetValue( FUNIT_TWIP )));
     404             :             aULSpace.SetLower( (sal_uInt16) m_pBottomMF->Denormalize(
     405           0 :                                         m_pBottomMF->GetValue( FUNIT_TWIP )));
     406           0 :             rCoreSet.Put(aULSpace);
     407             :         }
     408             : 
     409             :     }
     410           0 :     if(m_pNameED->GetText() != m_pNameED->GetSavedValue())
     411             :     {
     412           0 :         rCoreSet.Put(SfxStringItem( FN_PARAM_TABLE_NAME, m_pNameED->GetText()));
     413           0 :         bModified = sal_True;
     414             :     }
     415             : 
     416             :     sal_uInt16 nPos;
     417           0 :     if( m_pTextDirectionLB->IsVisible() &&
     418           0 :         ( nPos = m_pTextDirectionLB->GetSelectEntryPos() ) !=
     419           0 :                                             m_pTextDirectionLB->GetSavedValue() )
     420             :     {
     421           0 :         sal_uInt32 nDirection = (sal_uInt32)(sal_uIntPtr)m_pTextDirectionLB->GetEntryData( nPos );
     422           0 :         rCoreSet.Put( SvxFrameDirectionItem( (SvxFrameDirection)nDirection, RES_FRAMEDIR));
     423           0 :         bModified = sal_True;
     424             :     }
     425             : 
     426           0 :     return bModified;
     427             : }
     428             : 
     429             : 
     430           0 : void  SwFormatTablePage::Reset( const SfxItemSet& )
     431             : {
     432           0 :     const SfxItemSet& rSet = GetItemSet();
     433             :     const SfxPoolItem*  pItem;
     434             : 
     435           0 :     if(bHtmlMode)
     436             :     {
     437           0 :         m_pNameED->Disable();
     438           0 :         m_pTopFT->Hide();
     439           0 :         m_pTopMF->Hide();
     440           0 :         m_pBottomFT->Hide();
     441           0 :         m_pBottomMF->Hide();
     442           0 :         m_pFreeBtn->Enable(sal_False);
     443             :     }
     444           0 :     FieldUnit aMetric = ::GetDfltMetric(bHtmlMode);
     445           0 :     m_aWidthMF.SetMetric(aMetric);
     446           0 :     m_aRightMF.SetMetric(aMetric);
     447           0 :     m_aLeftMF.SetMetric(aMetric);
     448           0 :     SetMetric(*m_pTopMF, aMetric);
     449           0 :     SetMetric(*m_pBottomMF, aMetric);
     450             : 
     451             :     //Name
     452           0 :     if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_NAME, sal_False, &pItem ))
     453             :     {
     454           0 :         m_pNameED->SetText(((const SfxStringItem*)pItem)->GetValue());
     455           0 :         m_pNameED->SaveValue();
     456             :     }
     457             : 
     458           0 :     if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, sal_False, &pItem ))
     459             :     {
     460           0 :         pTblData = (SwTableRep*)((const SwPtrItem*) pItem)->GetValue();
     461           0 :         nMinTableWidth = pTblData->GetColCount() * MINLAY;
     462             : 
     463           0 :         if(pTblData->GetWidthPercent())
     464             :         {
     465           0 :             m_pRelWidthCB->Check(sal_True);
     466           0 :             RelWidthClickHdl(m_pRelWidthCB);
     467           0 :             m_aWidthMF.SetPrcntValue(pTblData->GetWidthPercent(), FUNIT_CUSTOM);
     468             : 
     469           0 :             m_aWidthMF.SaveValue();
     470           0 :             nSaveWidth = static_cast< SwTwips >(m_aWidthMF.GetValue(FUNIT_CUSTOM));
     471             :         }
     472             :         else
     473             :         {
     474             :             m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(
     475           0 :                     pTblData->GetWidth()), FUNIT_TWIP);
     476           0 :             m_aWidthMF.SaveValue();
     477           0 :             nSaveWidth = pTblData->GetWidth();
     478           0 :             nMinTableWidth = std::min( nSaveWidth, nMinTableWidth );
     479             :         }
     480             : 
     481           0 :         m_aWidthMF.SetRefValue(pTblData->GetSpace());
     482           0 :         m_aWidthMF.SetLast(m_aWidthMF.NormalizePercent( pTblData->GetSpace() ));
     483           0 :         m_aLeftMF.SetLast(m_aLeftMF.NormalizePercent( pTblData->GetSpace() ));
     484           0 :         m_aRightMF.SetLast(m_aRightMF.NormalizePercent( pTblData->GetSpace() ));
     485             : 
     486             :         m_aLeftMF.SetPrcntValue(m_aLeftMF.NormalizePercent(
     487           0 :                     pTblData->GetLeftSpace()), FUNIT_TWIP);
     488             :         m_aRightMF.SetPrcntValue(m_aRightMF.NormalizePercent(
     489           0 :                     pTblData->GetRightSpace()), FUNIT_TWIP);
     490           0 :         m_aLeftMF.SaveValue();
     491           0 :         m_aRightMF.SaveValue();
     492             : 
     493           0 :         nOldAlign = pTblData->GetAlign();
     494             : 
     495           0 :         bool bSetRight = false, bSetLeft = false;
     496           0 :         switch( nOldAlign )
     497             :         {
     498             :             case text::HoriOrientation::NONE:
     499           0 :                 m_pFreeBtn->Check();
     500           0 :                 if(m_pRelWidthCB->IsChecked())
     501           0 :                     bSetRight = true;
     502           0 :             break;
     503             :             case text::HoriOrientation::FULL:
     504             :             {
     505           0 :                 bSetRight = bSetLeft = true;
     506           0 :                 m_pFullBtn->Check();
     507           0 :                 m_aWidthMF.Enable(sal_False);
     508           0 :                 m_pRelWidthCB->Enable(sal_False);
     509           0 :                 m_pWidthFT->Enable(sal_False);
     510             :             }
     511           0 :             break;
     512             :             case text::HoriOrientation::LEFT:
     513             :             {
     514           0 :                 bSetLeft = true;
     515           0 :                 m_pLeftBtn->Check();
     516             :             }
     517           0 :             break;
     518             :             case text::HoriOrientation::LEFT_AND_WIDTH :
     519             :             {
     520           0 :                 bSetRight = true;
     521           0 :                 m_pFromLeftBtn->Check();
     522             :             }
     523           0 :             break;
     524             :             case text::HoriOrientation::RIGHT:
     525             :             {
     526           0 :                 bSetRight = true;
     527           0 :                 m_pRightBtn->Check();
     528             :             }
     529           0 :             break;
     530             :             case text::HoriOrientation::CENTER:
     531             :             {
     532           0 :                 bSetRight = true;
     533           0 :                 m_pCenterBtn->Check();
     534             :             }
     535           0 :             break;
     536             :         }
     537           0 :         if ( bSetRight )
     538             :         {
     539           0 :             m_aRightMF.Enable(sal_False);
     540           0 :             m_pRightFT->Enable(sal_False);
     541             :         }
     542           0 :         if ( bSetLeft )
     543             :         {
     544           0 :             m_aLeftMF.Enable(sal_False);
     545           0 :             m_pLeftFT->Enable(sal_False);
     546             :         }
     547             : 
     548             :     }
     549             : 
     550             :     //Margins
     551           0 :     if(SFX_ITEM_SET == rSet.GetItemState( RES_UL_SPACE, sal_False,&pItem ))
     552             :     {
     553             :         m_pTopMF->SetValue(m_pTopMF->Normalize(
     554           0 :                         ((const SvxULSpaceItem*)pItem)->GetUpper()), FUNIT_TWIP);
     555             :         m_pBottomMF->SetValue(m_pBottomMF->Normalize(
     556           0 :                         ((const SvxULSpaceItem*)pItem)->GetLower()), FUNIT_TWIP);
     557           0 :         m_pTopMF->SaveValue();
     558           0 :         m_pBottomMF->SaveValue();
     559             :     }
     560             : 
     561             :     //text direction
     562           0 :     if( SFX_ITEM_SET == rSet.GetItemState( RES_FRAMEDIR, sal_True, &pItem ) )
     563             :     {
     564           0 :         sal_uIntPtr nVal  = ((SvxFrameDirectionItem*)pItem)->GetValue();
     565           0 :         sal_uInt16 nPos = m_pTextDirectionLB->GetEntryPos( (void*) nVal );
     566           0 :         m_pTextDirectionLB->SelectEntryPos( nPos );
     567           0 :         m_pTextDirectionLB->SaveValue();
     568             :     }
     569             : 
     570           0 :     m_aWidthMF.SetMax( 2*m_aWidthMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
     571           0 :     m_aRightMF.SetMax( m_aRightMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
     572           0 :     m_aLeftMF.SetMax( m_aLeftMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
     573           0 :     m_aWidthMF.SetMin( m_aWidthMF.NormalizePercent( nMinTableWidth ), FUNIT_TWIP );
     574             : 
     575           0 : }
     576             : 
     577             : 
     578           0 : void    SwFormatTablePage::ActivatePage( const SfxItemSet& rSet )
     579             : {
     580             :     OSL_ENSURE(pTblData, "table data not available?");
     581           0 :     if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP ))
     582             :     {
     583           0 :         SwTwips nCurWidth = text::HoriOrientation::FULL != pTblData->GetAlign() ?
     584           0 :                                         pTblData->GetWidth() :
     585           0 :                                             pTblData->GetSpace();
     586           0 :         if(pTblData->GetWidthPercent() == 0 &&
     587           0 :                 nCurWidth != m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue(FUNIT_TWIP )))
     588             :         {
     589             :             m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(
     590           0 :                             nCurWidth), FUNIT_TWIP);
     591           0 :             m_aWidthMF.SaveValue();
     592           0 :             nSaveWidth = nCurWidth;
     593             :             m_aLeftMF.SetPrcntValue(m_aLeftMF.NormalizePercent(
     594           0 :                             pTblData->GetLeftSpace()), FUNIT_TWIP);
     595           0 :             m_aLeftMF.SaveValue();
     596             :             m_aRightMF.SetPrcntValue(m_aRightMF.NormalizePercent(
     597           0 :                             pTblData->GetRightSpace()), FUNIT_TWIP);
     598           0 :             m_aRightMF.SaveValue();
     599             :         }
     600             :     }
     601             : 
     602           0 : }
     603             : 
     604           0 : int  SwFormatTablePage::DeactivatePage( SfxItemSet* _pSet )
     605             : {
     606             :     // os: VCL sorgt nicht dafuer, dass das aktive Control im
     607             :     // dialog bei OK den focus verliert
     608           0 :     m_pNameED->GrabFocus();
     609             :     // Test the table name for spaces
     610           0 :     String sTblName = m_pNameED->GetText();
     611           0 :     if(sTblName.Search(' ') != STRING_NOTFOUND)
     612             :     {
     613           0 :         InfoBox(this, SW_RES(MSG_WRONG_TABLENAME)).Execute();
     614           0 :         m_pNameED->GrabFocus();
     615           0 :         return KEEP_PAGE;
     616             :     }
     617           0 :     if(_pSet)
     618             :     {
     619           0 :         FillItemSet(*_pSet);
     620           0 :         if(bModified)
     621             :         {
     622           0 :             SwTwips lLeft  = static_cast< SwTwips >(m_aLeftMF.DenormalizePercent(m_aLeftMF.GetValue( FUNIT_TWIP )));
     623           0 :             SwTwips lRight = static_cast< SwTwips >(m_aRightMF.DenormalizePercent(m_aRightMF.GetValue( FUNIT_TWIP )));
     624             : 
     625             : 
     626           0 :             if( m_aLeftMF.GetText() != m_aLeftMF.GetSavedValue() ||
     627           0 :                                     m_aRightMF.GetText() != m_aRightMF.GetSavedValue() )
     628             :             {
     629           0 :                 pTblData->SetWidthChanged();
     630           0 :                 pTblData->SetLeftSpace( lLeft);
     631           0 :                 pTblData->SetRightSpace( lRight);
     632             :             }
     633             : 
     634             :             SwTwips lWidth;
     635           0 :             if (m_pRelWidthCB->IsChecked() && m_pRelWidthCB->IsEnabled())
     636             :             {
     637           0 :                 lWidth = pTblData->GetSpace() - lRight - lLeft;
     638           0 :                 sal_uInt16 nPercentWidth = (sal_uInt16)m_aWidthMF.GetValue(FUNIT_CUSTOM);
     639           0 :                 if(pTblData->GetWidthPercent() != nPercentWidth)
     640             :                 {
     641           0 :                     pTblData->SetWidthPercent(nPercentWidth);
     642           0 :                     pTblData->SetWidthChanged();
     643             :                 }
     644             :             }
     645             :             else
     646             :             {
     647           0 :                 pTblData->SetWidthPercent(0);
     648           0 :                 lWidth = static_cast< SwTwips >(m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue( FUNIT_TWIP )));
     649             :             }
     650           0 :             pTblData->SetWidth(lWidth);
     651             : 
     652           0 :             SwTwips nColSum = 0;
     653             :             sal_uInt16 i;
     654             : 
     655           0 :             for( i = 0; i < pTblData->GetColCount(); i++)
     656             :             {
     657           0 :                 nColSum += pTblData->GetColumns()[i].nWidth;
     658             :             }
     659           0 :             if(nColSum != pTblData->GetWidth())
     660             :             {
     661             :                 SwTwips nMinWidth = std::min( (long)MINLAY,
     662           0 :                                     (long) (pTblData->GetWidth() /
     663           0 :                                             pTblData->GetColCount() - 1));
     664           0 :                 SwTwips nDiff = nColSum - pTblData->GetWidth();
     665           0 :                 while ( std::abs(nDiff) > pTblData->GetColCount() + 1 )
     666             :                 {
     667           0 :                     SwTwips nSub = nDiff / pTblData->GetColCount();
     668           0 :                     for( i = 0; i < pTblData->GetColCount(); i++)
     669             :                     {
     670           0 :                         if(pTblData->GetColumns()[i].nWidth - nMinWidth > nSub)
     671             :                         {
     672           0 :                             pTblData->GetColumns()[i].nWidth -= nSub;
     673           0 :                             nDiff -= nSub;
     674             :                         }
     675             :                         else
     676             :                         {
     677           0 :                             nDiff -= pTblData->GetColumns()[i].nWidth - nMinWidth;
     678           0 :                             pTblData->GetColumns()[i].nWidth = nMinWidth;
     679             :                         }
     680             : 
     681             :                     }
     682             :                 }
     683             :             }
     684             : 
     685           0 :             sal_Int16 nAlign = 0;
     686           0 :             if(m_pRightBtn->IsChecked())
     687           0 :                 nAlign = text::HoriOrientation::RIGHT;
     688           0 :             else if(m_pLeftBtn->IsChecked())
     689           0 :                 nAlign = text::HoriOrientation::LEFT;
     690           0 :             else if(m_pFromLeftBtn->IsChecked())
     691           0 :                 nAlign = text::HoriOrientation::LEFT_AND_WIDTH;
     692           0 :             else if(m_pCenterBtn->IsChecked())
     693           0 :                 nAlign = text::HoriOrientation::CENTER;
     694           0 :             else if(m_pFreeBtn->IsChecked())
     695           0 :                 nAlign = text::HoriOrientation::NONE;
     696           0 :             else if(m_pFullBtn->IsChecked())
     697             :             {
     698           0 :                 nAlign = text::HoriOrientation::FULL;
     699           0 :                 lWidth = lAutoWidth;
     700             :             }
     701           0 :             if(nAlign != pTblData->GetAlign())
     702             :             {
     703           0 :                 pTblData->SetWidthChanged();
     704           0 :                 pTblData->SetAlign(nAlign);
     705             :             }
     706             : 
     707           0 :             if(pTblData->GetWidth() != lWidth )
     708             :             {
     709           0 :                 pTblData->SetWidthChanged();
     710             :                 pTblData->SetWidth(
     711           0 :                     nAlign == text::HoriOrientation::FULL ? pTblData->GetSpace() : lWidth );
     712             :             }
     713           0 :             if(pTblData->HasWidthChanged())
     714           0 :                 _pSet->Put(SwPtrItem(FN_TABLE_REP, pTblData));
     715             :         }
     716             :     }
     717           0 :     return sal_True;
     718             : }
     719             : //Description: Page column configuration
     720           0 : SwTableColumnPage::SwTableColumnPage(Window* pParent, const SfxItemSet& rSet)
     721             :     : SfxTabPage(pParent, "TableColumnPage",
     722             :         "modules/swriter/ui/tablecolumnpage.ui", rSet)
     723             :     , nTableWidth(0)
     724             :     , nMinWidth(MINLAY)
     725             :     , nNoOfCols(0)
     726             :     , nNoOfVisibleCols(0)
     727             :     , bModified(false)
     728             :     , bModifyTbl(false)
     729           0 :     , bPercentMode(false)
     730             : {
     731           0 :     get(m_pModifyTableCB, "adaptwidth");
     732           0 :     get(m_pProportionalCB, "adaptcolumns");
     733           0 :     get(m_pSpaceFT, "spaceft");
     734           0 :     get(m_pSpaceED, "space-nospin");
     735           0 :     get(m_pUpBtn, "next");
     736           0 :     get(m_pDownBtn, "back");
     737             : 
     738           0 :     m_aFieldArr[0].set(get<MetricField>("width1"));
     739           0 :     m_aFieldArr[1].set(get<MetricField>("width2"));
     740           0 :     m_aFieldArr[2].set(get<MetricField>("width3"));
     741           0 :     m_aFieldArr[3].set(get<MetricField>("width4"));
     742           0 :     m_aFieldArr[4].set(get<MetricField>("width5"));
     743           0 :     m_aFieldArr[5].set(get<MetricField>("width6"));
     744             : 
     745           0 :     m_pTextArr[0] = get<FixedText>("1");
     746           0 :     m_pTextArr[1] = get<FixedText>("2");
     747           0 :     m_pTextArr[2] = get<FixedText>("3");
     748           0 :     m_pTextArr[3] = get<FixedText>("4");
     749           0 :     m_pTextArr[4] = get<FixedText>("5");
     750           0 :     m_pTextArr[5] = get<FixedText>("6");
     751             : 
     752           0 :     SetExchangeSupport();
     753             : 
     754             :     const SfxPoolItem* pItem;
     755           0 :     Init((SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
     756           0 :         && ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON));
     757             : 
     758           0 : };
     759             : //Description: Page column configuration
     760           0 :  SwTableColumnPage::~SwTableColumnPage()
     761             : {
     762           0 : };
     763             : 
     764             : 
     765           0 : SfxTabPage*   SwTableColumnPage::Create( Window* pParent,
     766             :                                 const SfxItemSet& rAttrSet)
     767             : {
     768           0 :     return new SwTableColumnPage( pParent, rAttrSet );
     769             : };
     770             : 
     771             : 
     772           0 : void  SwTableColumnPage::Reset( const SfxItemSet& )
     773             : {
     774           0 :     const SfxItemSet& rSet = GetItemSet();
     775             : 
     776             :     const SfxPoolItem* pItem;
     777           0 :     if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, sal_False, &pItem ))
     778             :     {
     779           0 :         pTblData = (SwTableRep*)((const SwPtrItem*) pItem)->GetValue();
     780           0 :         nNoOfVisibleCols = pTblData->GetColCount();
     781           0 :         nNoOfCols = pTblData->GetAllColCount();
     782           0 :         nTableWidth = pTblData->GetAlign() != text::HoriOrientation::FULL &&
     783           0 :                             pTblData->GetAlign() != text::HoriOrientation::LEFT_AND_WIDTH?
     784           0 :                         pTblData->GetWidth() : pTblData->GetSpace();
     785             : 
     786             :         sal_uInt16 i;
     787           0 :         for( i = 0; i < nNoOfCols; i++ )
     788             :         {
     789           0 :             if( pTblData->GetColumns()[i].nWidth  < nMinWidth )
     790           0 :                     nMinWidth = pTblData->GetColumns()[i].nWidth;
     791             :         }
     792           0 :         sal_Int64 nMinTwips = m_aFieldArr[0].NormalizePercent( nMinWidth );
     793           0 :         sal_Int64 nMaxTwips = m_aFieldArr[0].NormalizePercent( nTableWidth );
     794           0 :         for( i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
     795             :         {
     796           0 :             m_aFieldArr[i].SetPrcntValue( m_aFieldArr[i].NormalizePercent(
     797           0 :                                                 GetVisibleWidth(i) ), FUNIT_TWIP );
     798           0 :             m_aFieldArr[i].SetMin( nMinTwips , FUNIT_TWIP );
     799           0 :             m_aFieldArr[i].SetMax( nMaxTwips , FUNIT_TWIP );
     800           0 :             m_aFieldArr[i].Enable();
     801           0 :             m_pTextArr[i]->Enable();
     802             :         }
     803             : 
     804           0 :         if( nNoOfVisibleCols > MET_FIELDS )
     805           0 :             m_pUpBtn->Enable();
     806           0 :         i = nNoOfVisibleCols;
     807           0 :         while( i < MET_FIELDS )
     808             :         {
     809           0 :             m_aFieldArr[i].SetText( aEmptyStr );
     810           0 :             m_pTextArr[i]->Disable();
     811           0 :             i++;
     812             :         }
     813             :     }
     814           0 :     ActivatePage(rSet);
     815             : 
     816           0 : };
     817             : 
     818             : 
     819           0 : void  SwTableColumnPage::Init(sal_Bool bWeb)
     820             : {
     821           0 :     FieldUnit aMetric = ::GetDfltMetric(bWeb);
     822           0 :     Link aLkUp = LINK( this, SwTableColumnPage, UpHdl );
     823           0 :     Link aLkDown = LINK( this, SwTableColumnPage, DownHdl );
     824           0 :     Link aLkLF = LINK( this, SwTableColumnPage, LoseFocusHdl );
     825           0 :     for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
     826             :     {
     827           0 :         aValueTbl[i] = i;
     828           0 :         m_aFieldArr[i].SetMetric(aMetric);
     829           0 :         m_aFieldArr[i].SetUpHdl( aLkUp );
     830           0 :         m_aFieldArr[i].SetDownHdl( aLkDown );
     831           0 :         m_aFieldArr[i].SetLoseFocusHdl( aLkLF );
     832             :     }
     833           0 :     SetMetric(*m_pSpaceED, aMetric);
     834             : 
     835           0 :     Link aLk = LINK( this, SwTableColumnPage, AutoClickHdl );
     836           0 :     m_pUpBtn->SetClickHdl( aLk );
     837           0 :     m_pDownBtn->SetClickHdl( aLk );
     838             : 
     839           0 :     aLk = LINK( this, SwTableColumnPage, ModeHdl );
     840           0 :     m_pModifyTableCB->SetClickHdl( aLk );
     841           0 :     m_pProportionalCB->SetClickHdl( aLk );
     842           0 : };
     843             : 
     844             : 
     845           0 : IMPL_LINK( SwTableColumnPage, AutoClickHdl, CheckBox *, pBox )
     846             : {
     847             :     //move display window
     848           0 :     if(pBox == (CheckBox *)m_pDownBtn)
     849             :     {
     850           0 :         if(aValueTbl[0] > 0)
     851             :         {
     852           0 :             for( sal_uInt16 i=0; i < MET_FIELDS; i++ )
     853           0 :                 aValueTbl[i] -= 1;
     854             :         }
     855             :     }
     856           0 :     if (pBox == (CheckBox *)m_pUpBtn)
     857             :     {
     858           0 :         if( aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1  )
     859             :         {
     860           0 :             for(sal_uInt16 i=0;i < MET_FIELDS;i++)
     861           0 :                 aValueTbl[i] += 1;
     862             :         }
     863             :     }
     864           0 :     for( sal_uInt16 i = 0; (i < nNoOfVisibleCols ) && ( i < MET_FIELDS); i++ )
     865             :     {
     866           0 :         String sEntry = OUString('~');
     867           0 :         String sIndex = OUString::number( aValueTbl[i] + 1 );
     868           0 :         sEntry += sIndex;
     869           0 :         m_pTextArr[i]->SetText( sEntry );
     870             : 
     871             :         //added by menghu for SODC_5143,12/12/2006
     872           0 :         OUString sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH);
     873           0 :         sColumnWidth = sColumnWidth.replaceFirst( "%1", sIndex );
     874           0 :         m_aFieldArr[i].SetAccessibleName( sColumnWidth );
     875           0 :     }
     876             : 
     877           0 :     m_pDownBtn->Enable(aValueTbl[0] > 0);
     878           0 :     m_pUpBtn->Enable(aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1 );
     879           0 :     UpdateCols(0);
     880           0 :     return 0;
     881             : };
     882             : 
     883             : 
     884           0 : IMPL_LINK_INLINE_START( SwTableColumnPage, UpHdl, MetricField*, pEdit )
     885             : {
     886           0 :     bModified = sal_True;
     887           0 :     ModifyHdl( pEdit );
     888           0 :     return 0;
     889             : };
     890           0 : IMPL_LINK_INLINE_END( SwTableColumnPage, UpHdl, MetricField*, pEdit )
     891             : 
     892             : 
     893           0 : IMPL_LINK_INLINE_START( SwTableColumnPage, DownHdl, MetricField*, pEdit )
     894             : {
     895           0 :     bModified = sal_True;
     896           0 :     ModifyHdl( pEdit );
     897           0 :     return 0;
     898             : };
     899           0 : IMPL_LINK_INLINE_END( SwTableColumnPage, DownHdl, MetricField*, pEdit )
     900             : 
     901             : 
     902           0 : IMPL_LINK_INLINE_START( SwTableColumnPage, LoseFocusHdl, MetricField*, pEdit )
     903             : {
     904           0 :     if (pEdit->IsModified())
     905             :     {
     906           0 :         bModified = sal_True;
     907           0 :         ModifyHdl( pEdit );
     908             :     }
     909           0 :     return 0;
     910             : };
     911           0 : IMPL_LINK_INLINE_END( SwTableColumnPage, LoseFocusHdl, MetricField*, pEdit )
     912             : 
     913             : 
     914           0 : IMPL_LINK( SwTableColumnPage, ModeHdl, CheckBox*, pBox )
     915             : {
     916           0 :     sal_Bool bCheck = pBox->IsChecked();
     917           0 :     if (pBox == m_pProportionalCB)
     918             :     {
     919           0 :         if(bCheck)
     920           0 :             m_pModifyTableCB->Check();
     921           0 :         m_pModifyTableCB->Enable(!bCheck && bModifyTbl);
     922             :     }
     923           0 :     return 0;
     924             : };
     925             : 
     926             : 
     927           0 : sal_Bool  SwTableColumnPage::FillItemSet( SfxItemSet& )
     928             : {
     929           0 :     for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
     930             :     {
     931           0 :         if (m_aFieldArr[i].HasFocus())
     932             :         {
     933           0 :             LoseFocusHdl(m_aFieldArr[i].get());
     934           0 :             break;
     935             :         }
     936             :     }
     937             : 
     938           0 :     if(bModified)
     939             :     {
     940           0 :         pTblData->SetColsChanged();
     941             :     }
     942           0 :     return bModified;
     943             : };
     944             : 
     945             : 
     946           0 : void   SwTableColumnPage::ModifyHdl( MetricField* pField )
     947             : {
     948           0 :         PercentFieldWrap *pEdit = NULL;
     949             :         sal_uInt16 nAktPos;
     950             :         sal_uInt16 i;
     951             : 
     952           0 :         for( i = 0; i < MET_FIELDS; i++)
     953             :         {
     954           0 :             if (pField == m_aFieldArr[i].get())
     955             :             {
     956           0 :                 pEdit = &m_aFieldArr[i];
     957           0 :                 break;
     958             :             }
     959             :         }
     960             : 
     961           0 :         if (MET_FIELDS <= i || !pEdit)
     962             :         {
     963             :             OSL_ENSURE(false, "cannot happen.");
     964           0 :             return;
     965             :         }
     966             : 
     967           0 :         SetVisibleWidth(aValueTbl[i], static_cast< SwTwips >(pEdit->DenormalizePercent(pEdit->GetValue( FUNIT_TWIP ))) );
     968           0 :         nAktPos = aValueTbl[i];
     969             : 
     970           0 :         UpdateCols( nAktPos );
     971             : };
     972             : 
     973             : 
     974           0 : void   SwTableColumnPage::UpdateCols( sal_uInt16 nAktPos )
     975             : {
     976           0 :     SwTwips nSum = 0;
     977             :     sal_uInt16 i;
     978             : 
     979           0 :     for( i = 0; i < nNoOfCols; i++ )
     980             :     {
     981           0 :         nSum += (pTblData->GetColumns())[i].nWidth;
     982             :     }
     983           0 :     SwTwips nDiff = nSum - nTableWidth;
     984             : 
     985           0 :     sal_Bool bModifyTable = m_pModifyTableCB->IsChecked();
     986           0 :     sal_Bool bProp =    m_pProportionalCB->IsChecked();
     987             : 
     988           0 :     if(!bModifyTable && !bProp )
     989             :     {
     990             : //      the table width is constant, the difference is balanced with the other columns
     991           0 :         sal_uInt16 nLoopCount = 0;
     992           0 :         while( nDiff )
     993             :         {
     994           0 :             if( ++nAktPos == nNoOfVisibleCols)
     995             :             {
     996           0 :                 nAktPos = 0;
     997           0 :                 ++nLoopCount;
     998             :                 //#i101353# in small tables it might not be possible to balance column width
     999           0 :                 if( nLoopCount > 1 )
    1000           0 :                     break;
    1001             :             }
    1002           0 :             if( nDiff < 0 )
    1003             :             {
    1004           0 :                 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
    1005           0 :                 nDiff = 0;
    1006             :             }
    1007           0 :             else if( GetVisibleWidth(nAktPos) >= nDiff + nMinWidth )
    1008             :             {
    1009           0 :                 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
    1010           0 :                 nDiff = 0;
    1011             :             }
    1012           0 :             if( nDiff > 0 && GetVisibleWidth(nAktPos) > nMinWidth )
    1013             :             {
    1014           0 :                 if( nDiff >= (GetVisibleWidth(nAktPos) - nMinWidth) )
    1015             :                 {
    1016           0 :                     nDiff -= (GetVisibleWidth(nAktPos) - nMinWidth);
    1017           0 :                     SetVisibleWidth(nAktPos, nMinWidth);
    1018             :                 }
    1019             :                 else
    1020             :                 {
    1021           0 :                     nDiff = 0;
    1022           0 :                     SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
    1023             :                 }
    1024             :                 OSL_ENSURE(nDiff >= 0, "nDiff < 0 cannot be here!");
    1025             :             }
    1026           0 :         }
    1027             :     }
    1028           0 :     else if(bModifyTable && !bProp)
    1029             :     {
    1030             : //      Difference is balanced by the width of the table,
    1031             : //      other columns remain unchanged.
    1032             :         OSL_ENSURE(nDiff <= pTblData->GetSpace() - nTableWidth, "wrong maximum" );
    1033           0 :         SwTwips nActSpace = pTblData->GetSpace() - nTableWidth;
    1034           0 :         if(nDiff > nActSpace)
    1035             :         {
    1036           0 :             nTableWidth = pTblData->GetSpace();
    1037           0 :             SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nActSpace );
    1038             :         }
    1039             :         else
    1040             :         {
    1041           0 :             nTableWidth += nDiff;
    1042           0 :         }
    1043             :     }
    1044           0 :     else if(bModifyTable & bProp)
    1045             :     {
    1046             : //      All columns will be changed proportionally with,
    1047             : //      the table width is adjusted accordingly.
    1048             :         OSL_ENSURE(nDiff * nNoOfVisibleCols <= pTblData->GetSpace() - nTableWidth, "wrong maximum" );
    1049           0 :         long nAdd = nDiff;
    1050           0 :         if(nDiff * nNoOfVisibleCols > pTblData->GetSpace() - nTableWidth)
    1051             :         {
    1052           0 :             nAdd = (pTblData->GetSpace() - nTableWidth) / nNoOfVisibleCols;
    1053           0 :             SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nAdd );
    1054           0 :             nDiff = nAdd;
    1055             :         }
    1056           0 :         if(nAdd)
    1057           0 :             for(i = 0; i < nNoOfVisibleCols; i++ )
    1058             :             {
    1059           0 :                 if(i == nAktPos)
    1060           0 :                     continue;
    1061             :                 SwTwips nVisWidth;
    1062           0 :                 if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY)
    1063             :                 {
    1064           0 :                     nAdd += nVisWidth - MINLAY;
    1065           0 :                     SetVisibleWidth(i, MINLAY);
    1066             :                 }
    1067             :                 else
    1068             :                 {
    1069           0 :                     SetVisibleWidth(i, nVisWidth + nDiff);
    1070           0 :                     nAdd += nDiff;
    1071             :                 }
    1072             : 
    1073             :             }
    1074           0 :         nTableWidth += nAdd;
    1075             :     }
    1076             : 
    1077           0 :     if(!bPercentMode)
    1078           0 :         m_pSpaceED->SetValue(m_pSpaceED->Normalize( pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
    1079             : 
    1080           0 :     for( i = 0; ( i < nNoOfVisibleCols ) && ( i < MET_FIELDS ); i++)
    1081             :     {
    1082           0 :         m_aFieldArr[i].SetPrcntValue(m_aFieldArr[i].NormalizePercent(
    1083           0 :                         GetVisibleWidth(aValueTbl[i]) ), FUNIT_TWIP);
    1084           0 :         m_aFieldArr[i].ClearModifyFlag();
    1085             :     }
    1086           0 : }
    1087             : 
    1088           0 : void    SwTableColumnPage::ActivatePage( const SfxItemSet& )
    1089             : {
    1090           0 :     bPercentMode = pTblData->GetWidthPercent() != 0;
    1091           0 :     for( sal_uInt16 i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
    1092             :     {
    1093           0 :         m_aFieldArr[i].SetRefValue(pTblData->GetWidth());
    1094           0 :         m_aFieldArr[i].ShowPercent( bPercentMode );
    1095             :     }
    1096             : 
    1097           0 :     sal_uInt16 nTblAlign = pTblData->GetAlign();
    1098           0 :     if((text::HoriOrientation::FULL != nTblAlign && nTableWidth != pTblData->GetWidth()) ||
    1099           0 :     (text::HoriOrientation::FULL == nTblAlign && nTableWidth != pTblData->GetSpace()))
    1100             :     {
    1101             :         nTableWidth = text::HoriOrientation::FULL == nTblAlign ?
    1102           0 :                                     pTblData->GetSpace() :
    1103           0 :                                         pTblData->GetWidth();
    1104           0 :         UpdateCols(0);
    1105             :     }
    1106           0 :     bModifyTbl = sal_True;
    1107           0 :     if(pTblData->GetWidthPercent() ||
    1108           0 :                 text::HoriOrientation::FULL == nTblAlign ||
    1109           0 :                         pTblData->IsLineSelected()  )
    1110           0 :         bModifyTbl = sal_False;
    1111           0 :     if(bPercentMode)
    1112             :     {
    1113           0 :         m_pModifyTableCB->Check(sal_False);
    1114           0 :         m_pProportionalCB->Check(sal_False);
    1115             :     }
    1116           0 :     else if( !bModifyTbl )
    1117             :     {
    1118           0 :         m_pProportionalCB->Check(sal_False);
    1119           0 :         m_pModifyTableCB->Check(sal_False);
    1120             :     }
    1121           0 :     m_pSpaceFT->Enable(!bPercentMode);
    1122           0 :     m_pSpaceED->Enable(!bPercentMode);
    1123           0 :     m_pModifyTableCB->Enable( !bPercentMode && bModifyTbl );
    1124           0 :     m_pProportionalCB->Enable(!bPercentMode && bModifyTbl );
    1125             : 
    1126             :     m_pSpaceED->SetValue(m_pSpaceED->Normalize(
    1127           0 :                 pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
    1128             : 
    1129           0 : }
    1130             : 
    1131             : 
    1132           0 : int  SwTableColumnPage::DeactivatePage( SfxItemSet* _pSet )
    1133             : {
    1134           0 :     if(_pSet)
    1135             :     {
    1136           0 :         FillItemSet(*_pSet);
    1137           0 :         if(text::HoriOrientation::FULL != pTblData->GetAlign() && pTblData->GetWidth() != nTableWidth)
    1138             :         {
    1139           0 :             pTblData->SetWidth(nTableWidth);
    1140           0 :             SwTwips nDiff = pTblData->GetSpace() - pTblData->GetWidth() -
    1141           0 :                             pTblData->GetLeftSpace() - pTblData->GetRightSpace();
    1142           0 :             switch( pTblData->GetAlign()  )
    1143             :             {
    1144             :                 case text::HoriOrientation::RIGHT:
    1145           0 :                     pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff);
    1146           0 :                 break;
    1147             :                 case text::HoriOrientation::LEFT:
    1148           0 :                     pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff);
    1149           0 :                 break;
    1150             :                 case text::HoriOrientation::NONE:
    1151             :                 {
    1152           0 :                     SwTwips nDiff2 = nDiff/2;
    1153           0 :                     if( nDiff > 0 ||
    1154           0 :                         (-nDiff2 < pTblData->GetRightSpace() && - nDiff2 < pTblData->GetLeftSpace()))
    1155             :                     {
    1156           0 :                         pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff2);
    1157           0 :                         pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff2);
    1158             :                     }
    1159             :                     else
    1160             :                     {
    1161           0 :                         if(pTblData->GetRightSpace() > pTblData->GetLeftSpace())
    1162             :                         {
    1163           0 :                             pTblData->SetLeftSpace(0);
    1164           0 :                             pTblData->SetRightSpace(pTblData->GetSpace() - pTblData->GetWidth());
    1165             :                         }
    1166             :                         else
    1167             :                         {
    1168           0 :                             pTblData->SetRightSpace(0);
    1169           0 :                             pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
    1170             :                         }
    1171             :                     }
    1172             :                 }
    1173           0 :                 break;
    1174             :                 case text::HoriOrientation::CENTER:
    1175           0 :                     pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff/2);
    1176           0 :                     pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff/2);
    1177           0 :                 break;
    1178             :                 case text::HoriOrientation::LEFT_AND_WIDTH :
    1179           0 :                     if(nDiff > pTblData->GetRightSpace())
    1180             :                     {
    1181           0 :                         pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
    1182             :                     }
    1183             :                     pTblData->SetRightSpace(
    1184           0 :                         pTblData->GetSpace() - pTblData->GetWidth() - pTblData->GetLeftSpace());
    1185           0 :                 break;
    1186             :             }
    1187           0 :             pTblData->SetWidthChanged();
    1188             :         }
    1189           0 :         _pSet->Put(SwPtrItem( FN_TABLE_REP, pTblData ));
    1190             :     }
    1191           0 :     return sal_True;
    1192             : }
    1193             : 
    1194             : 
    1195           0 : SwTwips  SwTableColumnPage::GetVisibleWidth(sal_uInt16 nPos)
    1196             : {
    1197           0 :     sal_uInt16 i=0;
    1198             : 
    1199           0 :     while( nPos )
    1200             :     {
    1201           0 :         if(pTblData->GetColumns()[i].bVisible && nPos)
    1202           0 :             nPos--;
    1203           0 :         i++;
    1204             :     }
    1205           0 :     SwTwips nReturn = pTblData->GetColumns()[i].nWidth;
    1206             :     OSL_ENSURE(i < nNoOfCols, "Array index out of range");
    1207           0 :     while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
    1208           0 :         nReturn += pTblData->GetColumns()[++i].nWidth;
    1209             : 
    1210           0 :     return nReturn;
    1211             : }
    1212             : 
    1213             : 
    1214           0 : void SwTableColumnPage::SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth)
    1215             : {
    1216           0 :     sal_uInt16 i=0;
    1217           0 :     while( nPos )
    1218             :     {
    1219           0 :         if(pTblData->GetColumns()[i].bVisible && nPos)
    1220           0 :             nPos--;
    1221           0 :         i++;
    1222             :     }
    1223             :     OSL_ENSURE(i < nNoOfCols, "Array index out of range");
    1224           0 :     pTblData->GetColumns()[i].nWidth = nNewWidth;
    1225           0 :     while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
    1226           0 :         pTblData->GetColumns()[++i].nWidth = 0;
    1227             : 
    1228           0 : }
    1229             : 
    1230           0 : SwTableTabDlg::SwTableTabDlg(Window* pParent, SfxItemPool&,
    1231             :     const SfxItemSet* pItemSet, SwWrtShell* pSh)
    1232             :     : SfxTabDialog(0, pParent, "TablePropertiesDialog",
    1233             :         "modules/swriter/ui/tableproperties.ui", pItemSet, 0)
    1234             :     , pShell(pSh)
    1235           0 :     , m_nHtmlMode(::GetHtmlMode(pSh->GetView().GetDocShell()))
    1236             : {
    1237           0 :     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
    1238             :     OSL_ENSURE(pFact, "Dialogdiet fail!");
    1239           0 :     AddTabPage("table", &SwFormatTablePage::Create, 0);
    1240           0 :     m_nTextFlowId = AddTabPage("textflow", &SwTextFlowPage::Create, 0);
    1241           0 :     AddTabPage("columns", &SwTableColumnPage::Create, 0);
    1242           0 :     m_nBackgroundId = AddTabPage("background", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BACKGROUND), 0);
    1243           0 :     m_nBorderId = AddTabPage("borders", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BORDER), 0);
    1244           0 : }
    1245             : 
    1246           0 : void  SwTableTabDlg::PageCreated(sal_uInt16 nId, SfxTabPage& rPage)
    1247             : {
    1248           0 :     SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
    1249           0 :     if (nId == m_nBackgroundId)
    1250             :     {
    1251           0 :         sal_Int32 nFlagType = SVX_SHOW_TBLCTL;
    1252           0 :         if(!( m_nHtmlMode & HTMLMODE_ON ) ||
    1253           0 :             m_nHtmlMode & HTMLMODE_SOME_STYLES)
    1254           0 :             nFlagType |= SVX_SHOW_SELECTOR;
    1255           0 :         aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlagType));
    1256           0 :         rPage.PageCreated(aSet);
    1257             :     }
    1258           0 :     else if (nId == m_nBorderId)
    1259             :     {
    1260           0 :         aSet.Put (SfxUInt16Item(SID_SWMODE_TYPE,SW_BORDER_MODE_TABLE));
    1261           0 :         rPage.PageCreated(aSet);
    1262             :     }
    1263           0 :     else if (nId == m_nTextFlowId)
    1264             :     {
    1265           0 :         ((SwTextFlowPage&)rPage).SetShell(pShell);
    1266           0 :         const sal_uInt16 eType = pShell->GetFrmType(0,sal_True);
    1267           0 :         if( !(FRMTYPE_BODY & eType) )
    1268           0 :             ((SwTextFlowPage&)rPage).DisablePageBreak();
    1269           0 :     }
    1270           0 : }
    1271             : 
    1272           0 : SwTextFlowPage::SwTextFlowPage(Window* pParent, const SfxItemSet& rSet)
    1273             :     : SfxTabPage(pParent, "TableTextFlowPage",
    1274             :         "modules/swriter/ui/tabletextflowpage.ui", rSet)
    1275             :     , pShell(0)
    1276             :     , bPageBreak(true)
    1277           0 :     , bHtmlMode(false)
    1278             : {
    1279           0 :     get(m_pPgBrkCB, "break");
    1280             : 
    1281           0 :     get(m_pPgBrkRB, "page");
    1282           0 :     get(m_pColBrkRB, "column");
    1283             : 
    1284           0 :     get(m_pPgBrkBeforeRB, "before");
    1285           0 :     get(m_pPgBrkAfterRB, "after");
    1286             : 
    1287           0 :     get(m_pPageCollCB, "pagestyle");
    1288           0 :     get(m_pPageCollLB, "pagestylelb");
    1289           0 :     get(m_pPageNoFT, "pagenoft");
    1290           0 :     get(m_pPageNoNF, "pagenonf");
    1291             : 
    1292           0 :     get(m_pSplitCB, "split");
    1293           0 :     get(m_pSplitRowCB, "splitrow");
    1294           0 :     get(m_pKeepCB, "keep");
    1295           0 :     get(m_pHeadLineCB, "headline");
    1296             : 
    1297           0 :     get(m_pRepeatHeaderCombo, "repeatheader");
    1298           0 :     get(m_pRepeatHeaderNF, "repeatheadernf");
    1299             : 
    1300           0 :     get(m_pTextDirectionLB, "textdirection");
    1301           0 :     get(m_pVertOrientLB, "vertorient");
    1302             : 
    1303           0 :     m_pPgBrkRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
    1304           0 :     m_pColBrkRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
    1305           0 :     m_pPgBrkBeforeRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
    1306           0 :     m_pPgBrkAfterRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
    1307           0 :     m_pPageCollLB->SetAccessibleName(m_pPageCollCB->GetText());
    1308             : 
    1309           0 :     m_pPgBrkCB->SetClickHdl(LINK(this, SwTextFlowPage, PageBreakHdl_Impl));
    1310             :     m_pPgBrkBeforeRB->SetClickHdl(
    1311           0 :         LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
    1312             :     m_pPgBrkAfterRB->SetClickHdl(
    1313           0 :         LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
    1314             :     m_pPageCollCB->SetClickHdl(
    1315           0 :         LINK( this, SwTextFlowPage, ApplyCollClickHdl_Impl ) );
    1316             :     m_pColBrkRB->SetClickHdl(
    1317           0 :         LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
    1318             :     m_pPgBrkRB->SetClickHdl(
    1319           0 :         LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
    1320             :     m_pSplitCB->SetClickHdl(
    1321           0 :         LINK( this, SwTextFlowPage, SplitHdl_Impl));
    1322             :     m_pSplitRowCB->SetClickHdl(
    1323           0 :         LINK( this, SwTextFlowPage, SplitRowHdl_Impl));
    1324           0 :     m_pHeadLineCB->SetClickHdl( LINK( this, SwTextFlowPage, HeadLineCBClickHdl ) );
    1325             : 
    1326             : #ifndef SW_FILEFORMAT_40
    1327             :     const SfxPoolItem *pItem;
    1328           0 :     if(SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
    1329           0 :         && ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON)
    1330             : #endif
    1331             :     {
    1332           0 :         m_pKeepCB->Hide();
    1333           0 :         m_pSplitCB->Hide();
    1334           0 :         m_pSplitRowCB->Hide();
    1335             :     }
    1336             : 
    1337           0 :     HeadLineCBClickHdl();
    1338           0 : }
    1339             : 
    1340           0 :  SwTextFlowPage::~SwTextFlowPage()
    1341             : {
    1342           0 : }
    1343             : 
    1344           0 : SfxTabPage*   SwTextFlowPage::Create( Window* pParent,
    1345             :                                 const SfxItemSet& rAttrSet)
    1346             : {
    1347           0 :     return new SwTextFlowPage(pParent, rAttrSet);
    1348             : }
    1349             : 
    1350           0 : sal_Bool  SwTextFlowPage::FillItemSet( SfxItemSet& rSet )
    1351             : {
    1352           0 :     sal_Bool bModified = sal_False;
    1353             : 
    1354             :     // Repeat Heading
    1355           0 :     if(m_pHeadLineCB->IsChecked() != m_pHeadLineCB->GetSavedValue() ||
    1356           0 :         OUString::number( static_cast< sal_Int32 >(m_pRepeatHeaderNF->GetValue()) ) != m_pRepeatHeaderNF->GetSavedValue() )
    1357             :     {
    1358             :         bModified |= 0 != rSet.Put(
    1359           0 :             SfxUInt16Item(FN_PARAM_TABLE_HEADLINE, m_pHeadLineCB->IsChecked()? sal_uInt16(m_pRepeatHeaderNF->GetValue()) : 0 ));
    1360             :     }
    1361           0 :     if(m_pKeepCB->IsChecked() != m_pKeepCB->GetSavedValue())
    1362           0 :         bModified |= 0 != rSet.Put( SvxFmtKeepItem( m_pKeepCB->IsChecked(), RES_KEEP));
    1363             : 
    1364           0 :     if(m_pSplitCB->IsChecked() != m_pSplitCB->GetSavedValue())
    1365           0 :         bModified |= 0 != rSet.Put( SwFmtLayoutSplit( m_pSplitCB->IsChecked()));
    1366             : 
    1367           0 :     if(m_pSplitRowCB->IsChecked() != m_pSplitRowCB->GetSavedValue())
    1368           0 :         bModified |= 0 != rSet.Put( SwFmtRowSplit( m_pSplitRowCB->IsChecked()));
    1369             : 
    1370             : 
    1371           0 :     const SvxFmtBreakItem* pBreak = (const SvxFmtBreakItem*)GetOldItem( rSet, RES_BREAK );
    1372           0 :     const SwFmtPageDesc* pDesc = (const SwFmtPageDesc*) GetOldItem( rSet, RES_PAGEDESC );
    1373             : 
    1374             : 
    1375           0 :     sal_Bool bState = m_pPageCollCB->IsChecked();
    1376             : 
    1377             :     // If we have a page style, then there's no break
    1378           0 :     sal_Bool bPageItemPut = sal_False;
    1379           0 :     if ( bState != m_pPageCollCB->GetSavedValue() ||
    1380           0 :          ( bState &&
    1381           0 :            m_pPageCollLB->GetSelectEntryPos() != m_pPageCollLB->GetSavedValue() )
    1382           0 :            || (m_pPageNoNF->IsEnabled() && m_pPageNoNF->IsValueModified()) )
    1383             :     {
    1384           0 :         String sPage;
    1385             : 
    1386           0 :         if ( bState )
    1387             :         {
    1388           0 :             sPage = m_pPageCollLB->GetSelectEntry();
    1389             :         }
    1390           0 :         sal_uInt16 nPgNum = static_cast< sal_uInt16 >(m_pPageNoNF->GetValue());
    1391           0 :         if ( !pDesc || !pDesc->GetPageDesc() ||
    1392           0 :             ( pDesc->GetPageDesc() && ((pDesc->GetPageDesc()->GetName() != sPage) ||
    1393           0 :                     !comphelper::string::equals(m_pPageNoNF->GetSavedValue(), nPgNum))))
    1394             :         {
    1395           0 :             SwFmtPageDesc aFmt( pShell->FindPageDescByName( sPage, sal_True ) );
    1396           0 :             aFmt.SetNumOffset(bState ? nPgNum : 0);
    1397           0 :             bModified |= 0 != rSet.Put( aFmt );
    1398           0 :             bPageItemPut = bState;
    1399           0 :         }
    1400             :     }
    1401           0 :     sal_Bool bIsChecked = m_pPgBrkCB->IsChecked();
    1402           0 :     if ( !bPageItemPut &&
    1403           0 :         (   bState != m_pPageCollCB->GetSavedValue() ||
    1404           0 :             bIsChecked != m_pPgBrkCB->GetSavedValue()              ||
    1405           0 :             m_pPgBrkBeforeRB->IsChecked() != m_pPgBrkBeforeRB->GetSavedValue()    ||
    1406           0 :             m_pPgBrkRB->IsChecked() != m_pPgBrkRB->GetSavedValue() ))
    1407             :     {
    1408             :         SvxFmtBreakItem aBreak(
    1409           0 :             (const SvxFmtBreakItem&)GetItemSet().Get( RES_BREAK ) );
    1410             : 
    1411           0 :         if(bIsChecked)
    1412             :         {
    1413           0 :             sal_Bool bBefore = m_pPgBrkBeforeRB->IsChecked();
    1414             : 
    1415           0 :             if ( m_pPgBrkRB->IsChecked() )
    1416             :             {
    1417           0 :                 if ( bBefore )
    1418           0 :                     aBreak.SetValue( SVX_BREAK_PAGE_BEFORE );
    1419             :                 else
    1420           0 :                     aBreak.SetValue( SVX_BREAK_PAGE_AFTER );
    1421             :             }
    1422             :             else
    1423             :             {
    1424           0 :                 if ( bBefore )
    1425           0 :                     aBreak.SetValue( SVX_BREAK_COLUMN_BEFORE );
    1426             :                 else
    1427           0 :                     aBreak.SetValue( SVX_BREAK_COLUMN_AFTER );
    1428             :             }
    1429             :         }
    1430             :         else
    1431             :         {
    1432           0 :                 aBreak.SetValue( SVX_BREAK_NONE );
    1433             :         }
    1434             : 
    1435           0 :         if ( !pBreak || !( *(const SvxFmtBreakItem*)pBreak == aBreak ) )
    1436             :         {
    1437           0 :             bModified |= 0 != rSet.Put( aBreak );
    1438           0 :         }
    1439             :     }
    1440             : 
    1441           0 :     if(m_pTextDirectionLB->GetSelectEntryPos() != m_pTextDirectionLB->GetSavedValue())
    1442             :     {
    1443             :           bModified |= 0 != rSet.Put(
    1444             :                     SvxFrameDirectionItem(
    1445           0 :                         (SvxFrameDirection)(sal_uLong)m_pTextDirectionLB->GetEntryData(m_pTextDirectionLB->GetSelectEntryPos())
    1446           0 :                         , FN_TABLE_BOX_TEXTORIENTATION));
    1447             :     }
    1448             : 
    1449           0 :     if(m_pVertOrientLB->GetSelectEntryPos() != m_pVertOrientLB->GetSavedValue())
    1450             :     {
    1451           0 :         sal_uInt16 nOrient = USHRT_MAX;
    1452           0 :         switch(m_pVertOrientLB->GetSelectEntryPos())
    1453             :         {
    1454           0 :             case 0 : nOrient = text::VertOrientation::NONE; break;
    1455           0 :             case 1 : nOrient = text::VertOrientation::CENTER; break;
    1456           0 :             case 2 : nOrient = text::VertOrientation::BOTTOM; break;
    1457             :         }
    1458           0 :         if(nOrient != USHRT_MAX)
    1459           0 :             bModified |= 0 != rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, nOrient));
    1460             :     }
    1461             : 
    1462           0 :     return bModified;
    1463             : 
    1464             : }
    1465             : 
    1466           0 : void   SwTextFlowPage::Reset( const SfxItemSet& rSet )
    1467             : {
    1468             :     const SfxPoolItem* pItem;
    1469           0 :     SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
    1470           0 :     bool bFlowAllowed = !bHtmlMode || rHtmlOpt.IsPrintLayoutExtension();
    1471           0 :     if(bFlowAllowed)
    1472             :     {
    1473             :         // Inserting of the existing page templates in the list box.
    1474           0 :         const sal_uInt16 nCount = pShell->GetPageDescCnt();
    1475             :         sal_uInt16 i;
    1476             : 
    1477           0 :         for( i = 0; i < nCount; ++i)
    1478             :         {
    1479           0 :             const SwPageDesc &rPageDesc = pShell->GetPageDesc(i);
    1480           0 :             m_pPageCollLB->InsertEntry(rPageDesc.GetName());
    1481             :         }
    1482             : 
    1483           0 :         String aFmtName;
    1484           0 :         for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
    1485           0 :             if( LISTBOX_ENTRY_NOTFOUND == m_pPageCollLB->GetEntryPos(
    1486           0 :                     aFmtName = SwStyleNameMapper::GetUIName( i, aFmtName ) ))
    1487           0 :                 m_pPageCollLB->InsertEntry( aFmtName );
    1488             : 
    1489           0 :         if(SFX_ITEM_SET == rSet.GetItemState( RES_KEEP, sal_False, &pItem ))
    1490             :         {
    1491           0 :             m_pKeepCB->Check( ((const SvxFmtKeepItem*)pItem)->GetValue() );
    1492           0 :             m_pKeepCB->SaveValue();
    1493             :         }
    1494           0 :         if(SFX_ITEM_SET == rSet.GetItemState( RES_LAYOUT_SPLIT, sal_False, &pItem ))
    1495             :         {
    1496           0 :             m_pSplitCB->Check( ((const SwFmtLayoutSplit*)pItem)->GetValue() );
    1497             :         }
    1498             :         else
    1499           0 :             m_pSplitCB->Check();
    1500             : 
    1501           0 :         m_pSplitCB->SaveValue();
    1502           0 :         SplitHdl_Impl(m_pSplitCB);
    1503             : 
    1504           0 :         if(SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem ))
    1505             :         {
    1506           0 :             m_pSplitRowCB->Check( ((const SwFmtRowSplit*)pItem)->GetValue() );
    1507             :         }
    1508             :         else
    1509           0 :             m_pSplitRowCB->SetState(STATE_DONTKNOW);
    1510           0 :         m_pSplitRowCB->SaveValue();
    1511             : 
    1512           0 :         if(bPageBreak)
    1513             :         {
    1514           0 :             if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_False, &pItem ))
    1515             :             {
    1516           0 :                 String sPageDesc;
    1517           0 :                 const SwPageDesc* pDesc = ((const SwFmtPageDesc*)pItem)->GetPageDesc();
    1518           0 :                 m_pPageNoNF->SetValue(((const SwFmtPageDesc*)pItem)->GetNumOffset());
    1519           0 :                 if(pDesc)
    1520           0 :                     sPageDesc = pDesc->GetName();
    1521           0 :                 if ( sPageDesc.Len() &&
    1522           0 :                         m_pPageCollLB->GetEntryPos( sPageDesc ) != LISTBOX_ENTRY_NOTFOUND )
    1523             :                 {
    1524           0 :                     m_pPageCollLB->SelectEntry( sPageDesc );
    1525           0 :                     m_pPageCollCB->Check();
    1526             : 
    1527           0 :                     m_pPgBrkCB->Enable();
    1528           0 :                     m_pPgBrkRB->Enable();
    1529           0 :                     m_pColBrkRB->Enable();
    1530           0 :                     m_pPgBrkBeforeRB->Enable();
    1531           0 :                     m_pPgBrkAfterRB->Enable();
    1532           0 :                     m_pPageCollCB->Enable();
    1533           0 :                     m_pPgBrkCB->Check();
    1534             : 
    1535           0 :                     m_pPgBrkCB->Check( sal_True );
    1536           0 :                     m_pColBrkRB->Check( sal_False );
    1537           0 :                     m_pPgBrkBeforeRB->Check( sal_True );
    1538           0 :                     m_pPgBrkAfterRB->Check( sal_False );
    1539             :                 }
    1540             :                 else
    1541             :                 {
    1542           0 :                     m_pPageCollLB->SetNoSelection();
    1543           0 :                     m_pPageCollCB->Check(sal_False);
    1544           0 :                 }
    1545             :             }
    1546             : 
    1547           0 :             if(SFX_ITEM_SET == rSet.GetItemState( RES_BREAK, sal_False, &pItem ))
    1548             :             {
    1549           0 :                 const SvxFmtBreakItem* pPageBreak = (const SvxFmtBreakItem*)pItem;
    1550           0 :                 SvxBreak eBreak = (SvxBreak)pPageBreak->GetValue();
    1551             : 
    1552           0 :                 if ( eBreak != SVX_BREAK_NONE )
    1553             :                 {
    1554           0 :                     m_pPgBrkCB->Check();
    1555           0 :                     m_pPageCollCB->Enable(sal_False);
    1556           0 :                     m_pPageCollLB->Enable(sal_False);
    1557           0 :                     m_pPageNoFT->Enable(sal_False);
    1558           0 :                     m_pPageNoNF->Enable(sal_False);
    1559             :                 }
    1560           0 :                 switch ( eBreak )
    1561             :                 {
    1562             :                     case SVX_BREAK_PAGE_BEFORE:
    1563           0 :                         m_pPgBrkRB->Check( sal_True );
    1564           0 :                         m_pColBrkRB->Check( sal_False );
    1565           0 :                         m_pPgBrkBeforeRB->Check( sal_True );
    1566           0 :                         m_pPgBrkAfterRB->Check( sal_False );
    1567           0 :                         break;
    1568             :                     case SVX_BREAK_PAGE_AFTER:
    1569           0 :                         m_pPgBrkRB->Check( sal_True );
    1570           0 :                         m_pColBrkRB->Check( sal_False );
    1571           0 :                         m_pPgBrkBeforeRB->Check( sal_False );
    1572           0 :                         m_pPgBrkAfterRB->Check( sal_True );
    1573           0 :                         break;
    1574             :                     case SVX_BREAK_COLUMN_BEFORE:
    1575           0 :                         m_pPgBrkRB->Check( sal_False );
    1576           0 :                         m_pColBrkRB->Check( sal_True );
    1577           0 :                         m_pPgBrkBeforeRB->Check( sal_True );
    1578           0 :                         m_pPgBrkAfterRB->Check( sal_False );
    1579           0 :                         break;
    1580             :                     case SVX_BREAK_COLUMN_AFTER:
    1581           0 :                         m_pPgBrkRB->Check( sal_False );
    1582           0 :                         m_pColBrkRB->Check( sal_True );
    1583           0 :                         m_pPgBrkBeforeRB->Check( sal_False );
    1584           0 :                         m_pPgBrkAfterRB->Check( sal_True );
    1585           0 :                         break;
    1586             :                     default:; //prevent warning
    1587             :                 }
    1588             : 
    1589             :             }
    1590           0 :             if ( m_pPgBrkBeforeRB->IsChecked() )
    1591           0 :                 PageBreakPosHdl_Impl(m_pPgBrkBeforeRB);
    1592           0 :             else if ( m_pPgBrkAfterRB->IsChecked() )
    1593           0 :                 PageBreakPosHdl_Impl(m_pPgBrkAfterRB);
    1594           0 :             PageBreakHdl_Impl( m_pPgBrkCB );
    1595           0 :         }
    1596             :     }
    1597             :     else
    1598             :     {
    1599           0 :         m_pPgBrkRB->Enable(sal_False);
    1600           0 :         m_pColBrkRB->Enable(sal_False);
    1601           0 :         m_pPgBrkBeforeRB->Enable(sal_False);
    1602           0 :         m_pPgBrkAfterRB->Enable(sal_False);
    1603           0 :         m_pKeepCB->Enable(sal_False);
    1604           0 :         m_pSplitCB->Enable(sal_False);
    1605           0 :         m_pPgBrkCB->Enable(sal_False);
    1606           0 :         m_pPageCollCB->Enable(sal_False);
    1607           0 :         m_pPageCollLB->Enable(sal_False);
    1608             :     }
    1609             : 
    1610           0 :     if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem ))
    1611             :     {
    1612           0 :         sal_uInt16 nRep = ((const SfxUInt16Item*)pItem)->GetValue();
    1613           0 :         m_pHeadLineCB->Check( nRep > 0 );
    1614           0 :         m_pHeadLineCB->SaveValue();
    1615           0 :         m_pRepeatHeaderNF->SetValue( nRep );
    1616           0 :         m_pRepeatHeaderNF->SaveValue();
    1617             :     }
    1618           0 :     if ( rSet.GetItemState(FN_TABLE_BOX_TEXTORIENTATION) > SFX_ITEM_AVAILABLE )
    1619             :     {
    1620           0 :         sal_uLong nDirection = ((const SvxFrameDirectionItem&)rSet.Get(FN_TABLE_BOX_TEXTORIENTATION)).GetValue();
    1621           0 :         m_pTextDirectionLB->SelectEntryPos(m_pTextDirectionLB->GetEntryPos( (const void*)nDirection ));
    1622             :     }
    1623             : 
    1624           0 :     if ( rSet.GetItemState(FN_TABLE_SET_VERT_ALIGN) > SFX_ITEM_AVAILABLE )
    1625             :     {
    1626           0 :         sal_uInt16 nVert = ((const SfxUInt16Item&)rSet.Get(FN_TABLE_SET_VERT_ALIGN)).GetValue();
    1627           0 :         sal_uInt16 nPos = 0;
    1628           0 :         switch(nVert)
    1629             :         {
    1630           0 :             case text::VertOrientation::NONE:     nPos = 0;   break;
    1631           0 :             case text::VertOrientation::CENTER:   nPos = 1;   break;
    1632           0 :             case text::VertOrientation::BOTTOM:   nPos = 2;   break;
    1633             :         }
    1634           0 :         m_pVertOrientLB->SelectEntryPos(nPos);
    1635             :     }
    1636             : 
    1637           0 :     m_pPageCollCB->SaveValue();
    1638           0 :     m_pPageCollLB->SaveValue();
    1639           0 :     m_pPgBrkCB->SaveValue();
    1640           0 :     m_pPgBrkRB->SaveValue();
    1641           0 :     m_pColBrkRB->SaveValue();
    1642           0 :     m_pPgBrkBeforeRB->SaveValue();
    1643           0 :     m_pPgBrkAfterRB->SaveValue();
    1644           0 :     m_pPageNoNF->SaveValue();
    1645           0 :     m_pTextDirectionLB->SaveValue();
    1646           0 :     m_pVertOrientLB->SaveValue();
    1647             : 
    1648           0 :     HeadLineCBClickHdl();
    1649           0 : }
    1650             : 
    1651           0 : void SwTextFlowPage::SetShell(SwWrtShell* pSh)
    1652             : {
    1653           0 :     pShell = pSh;
    1654           0 :     bHtmlMode = 0 != (::GetHtmlMode(pShell->GetView().GetDocShell()) & HTMLMODE_ON);
    1655           0 :     if(bHtmlMode)
    1656             :     {
    1657           0 :         m_pPageNoNF->Enable(sal_False);
    1658           0 :         m_pPageNoFT->Enable(sal_False);
    1659             :     }
    1660           0 : }
    1661             : 
    1662           0 : IMPL_LINK_NOARG(SwTextFlowPage, PageBreakHdl_Impl)
    1663             : {
    1664           0 :     if( m_pPgBrkCB->IsChecked() )
    1665             :     {
    1666           0 :             m_pPgBrkRB->       Enable();
    1667           0 :             m_pColBrkRB->      Enable();
    1668           0 :             m_pPgBrkBeforeRB-> Enable();
    1669           0 :             m_pPgBrkAfterRB->  Enable();
    1670             : 
    1671           0 :             if ( m_pPgBrkRB->IsChecked() && m_pPgBrkBeforeRB->IsChecked() )
    1672             :             {
    1673           0 :                 m_pPageCollCB->Enable();
    1674             : 
    1675           0 :                 sal_Bool bEnable = m_pPageCollCB->IsChecked() &&
    1676           0 :                                             m_pPageCollLB->GetEntryCount();
    1677           0 :                 m_pPageCollLB->Enable(bEnable);
    1678           0 :                 if(!bHtmlMode)
    1679             :                 {
    1680           0 :                     m_pPageNoFT->Enable(bEnable);
    1681           0 :                     m_pPageNoNF->Enable(bEnable);
    1682             :                 }
    1683             :             }
    1684             :     }
    1685             :     else
    1686             :     {
    1687           0 :             m_pPageCollCB->Check( sal_False );
    1688           0 :             m_pPageCollCB->Enable(sal_False);
    1689           0 :             m_pPageCollLB->Enable(sal_False);
    1690           0 :             m_pPageNoFT->Enable(sal_False);
    1691           0 :             m_pPageNoNF->Enable(sal_False);
    1692           0 :             m_pPgBrkRB->       Enable(sal_False);
    1693           0 :             m_pColBrkRB->      Enable(sal_False);
    1694           0 :             m_pPgBrkBeforeRB-> Enable(sal_False);
    1695           0 :             m_pPgBrkAfterRB->  Enable(sal_False);
    1696             :     }
    1697           0 :     return 0;
    1698             : }
    1699             : 
    1700           0 : IMPL_LINK_NOARG(SwTextFlowPage, ApplyCollClickHdl_Impl)
    1701             : {
    1702           0 :     sal_Bool bEnable = sal_False;
    1703           0 :     if ( m_pPageCollCB->IsChecked() &&
    1704           0 :          m_pPageCollLB->GetEntryCount() )
    1705             :     {
    1706           0 :         bEnable = sal_True;
    1707           0 :         m_pPageCollLB->SelectEntryPos( 0 );
    1708             :     }
    1709             :     else
    1710             :     {
    1711           0 :         m_pPageCollLB->SetNoSelection();
    1712             :     }
    1713           0 :     m_pPageCollLB->Enable(bEnable);
    1714           0 :     if(!bHtmlMode)
    1715             :     {
    1716           0 :         m_pPageNoFT->Enable(bEnable);
    1717           0 :         m_pPageNoNF->Enable(bEnable);
    1718             :     }
    1719           0 :     return 0;
    1720             : }
    1721             : 
    1722           0 : IMPL_LINK( SwTextFlowPage, PageBreakPosHdl_Impl, RadioButton*, pBtn )
    1723             : {
    1724           0 :     if ( m_pPgBrkCB->IsChecked() )
    1725             :     {
    1726           0 :         if ( pBtn == m_pPgBrkBeforeRB && m_pPgBrkRB->IsChecked() )
    1727             :         {
    1728           0 :             m_pPageCollCB->Enable();
    1729             : 
    1730           0 :             sal_Bool bEnable = m_pPageCollCB->IsChecked()  &&
    1731           0 :                                         m_pPageCollLB->GetEntryCount();
    1732             : 
    1733           0 :             m_pPageCollLB->Enable(bEnable);
    1734           0 :             if(!bHtmlMode)
    1735             :             {
    1736           0 :                 m_pPageNoFT->Enable(bEnable);
    1737           0 :                 m_pPageNoNF->Enable(bEnable);
    1738             :             }
    1739             :         }
    1740           0 :         else if (pBtn == m_pPgBrkAfterRB)
    1741             :         {
    1742           0 :             m_pPageCollCB->Check( sal_False );
    1743           0 :             m_pPageCollCB->Enable(sal_False);
    1744           0 :             m_pPageCollLB->Enable(sal_False);
    1745           0 :             m_pPageNoFT->Enable(sal_False);
    1746           0 :             m_pPageNoNF->Enable(sal_False);
    1747             :         }
    1748             :     }
    1749           0 :     return 0;
    1750             : }
    1751             : 
    1752           0 : IMPL_LINK( SwTextFlowPage, PageBreakTypeHdl_Impl, RadioButton*, pBtn )
    1753             : {
    1754           0 :     if ( pBtn == m_pColBrkRB || m_pPgBrkAfterRB->IsChecked() )
    1755             :     {
    1756           0 :         m_pPageCollCB->Check(sal_False);
    1757           0 :         m_pPageCollCB->Enable(sal_False);
    1758           0 :         m_pPageCollLB->Enable(sal_False);
    1759           0 :         m_pPageNoFT->Enable(sal_False);
    1760           0 :         m_pPageNoNF->Enable(sal_False);
    1761             :     }
    1762           0 :     else if ( m_pPgBrkBeforeRB->IsChecked() )
    1763           0 :         PageBreakPosHdl_Impl(m_pPgBrkBeforeRB);
    1764           0 :     return 0;
    1765             : }
    1766             : 
    1767           0 : IMPL_LINK( SwTextFlowPage, SplitHdl_Impl, CheckBox*, pBox )
    1768             : {
    1769           0 :     m_pSplitRowCB->Enable(pBox->IsChecked());
    1770           0 :     return 0;
    1771             : }
    1772             : 
    1773           0 : IMPL_LINK( SwTextFlowPage, SplitRowHdl_Impl, TriStateBox*, pBox )
    1774             : {
    1775           0 :     pBox->EnableTriState(sal_False);
    1776           0 :     return 0;
    1777             : }
    1778             : 
    1779           0 : IMPL_LINK_NOARG(SwTextFlowPage, HeadLineCBClickHdl)
    1780             : {
    1781           0 :     m_pRepeatHeaderCombo->Enable(m_pHeadLineCB->IsChecked());
    1782             : 
    1783           0 :     return 0;
    1784             : }
    1785             : 
    1786           0 : void SwTextFlowPage::DisablePageBreak()
    1787             : {
    1788           0 :     bPageBreak = sal_False;
    1789           0 :     m_pPgBrkCB->Disable();
    1790           0 :     m_pPgBrkRB->Disable();
    1791           0 :     m_pColBrkRB->Disable();
    1792           0 :     m_pPgBrkBeforeRB->Disable();
    1793           0 :     m_pPgBrkAfterRB->Disable();
    1794           0 :     m_pPageCollCB->Disable();
    1795           0 :     m_pPageCollLB->Disable();
    1796           0 :     m_pPageNoFT->Disable();
    1797           0 :     m_pPageNoNF->Disable();
    1798           0 : }
    1799             : 
    1800             : 
    1801             : 
    1802             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10