LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/dialog - optgrid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 198 3.0 %
Date: 2013-07-09 Functions: 4 24 16.7 %
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 <tools/shl.hxx>
      21             : #include <sfx2/app.hxx>
      22             : #include <sfx2/module.hxx>
      23             : #include <svl/intitem.hxx>
      24             : 
      25             : #include <svx/svxids.hrc>
      26             : #include <svx/dialmgr.hxx>
      27             : #include "svx/optgrid.hxx"
      28             : #include <svx/dialogs.hrc>
      29             : #include "optgrid.hrc"
      30             : #include "svx/dlgutil.hxx"
      31             : 
      32             : // local functions
      33           0 : static void    lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
      34             : {
      35           0 :     nFirst  = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
      36           0 :     nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
      37           0 :     nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
      38           0 :     nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
      39           0 : }
      40             : 
      41           0 : static void    lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
      42             : {
      43           0 :     rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
      44           0 :     rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
      45           0 :     rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
      46           0 :     rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
      47           0 : }
      48             : 
      49        5964 : SvxOptionsGrid::SvxOptionsGrid() :
      50             :     nFldDrawX       ( 100 ),
      51             :     nFldDivisionX   ( 0 ),
      52             :     nFldDrawY       ( 100 ),
      53             :     nFldDivisionY   ( 0 ),
      54             :     nFldSnapX       ( 100 ),
      55             :     nFldSnapY       ( 100 ),
      56             :     bUseGridsnap    ( 0 ),
      57             :     bSynchronize    ( 1 ),
      58             :     bGridVisible    ( 0 ),
      59        5964 :     bEqualGrid      ( 1 )
      60             : {
      61        5964 : }
      62             : 
      63        8013 : SvxOptionsGrid::~SvxOptionsGrid()
      64             : {
      65        8013 : }
      66             : 
      67           0 : SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
      68             : :   SvxOptionsGrid()
      69           0 : ,   SfxPoolItem(rItem)
      70             : {
      71           0 :     bUseGridsnap = rItem.bUseGridsnap ;
      72           0 :     bSynchronize = rItem.bSynchronize ;
      73           0 :     bGridVisible = rItem.bGridVisible ;
      74           0 :     bEqualGrid   = rItem.bEqualGrid   ;
      75           0 :     nFldDrawX    = rItem.nFldDrawX    ;
      76           0 :     nFldDivisionX= rItem.nFldDivisionX;
      77           0 :     nFldDrawY    = rItem.nFldDrawY    ;
      78           0 :     nFldDivisionY= rItem.nFldDivisionY;
      79           0 :     nFldSnapX    = rItem.nFldSnapX    ;
      80           0 :     nFldSnapY    = rItem.nFldSnapY    ;
      81             : 
      82           0 : };
      83             : 
      84           0 : SfxPoolItem*  SvxGridItem::Clone( SfxItemPool* ) const
      85             : {
      86           0 :     return new SvxGridItem( *this );
      87             : }
      88             : 
      89           0 : int SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
      90             : {
      91             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "different types ");
      92             : 
      93           0 :     const SvxGridItem& rItem = (const SvxGridItem&) rAttr;
      94             : 
      95           0 :     return (    bUseGridsnap == rItem.bUseGridsnap &&
      96           0 :                 bSynchronize == rItem.bSynchronize &&
      97           0 :                 bGridVisible == rItem.bGridVisible &&
      98           0 :                 bEqualGrid   == rItem.bEqualGrid   &&
      99           0 :                 nFldDrawX    == rItem.nFldDrawX    &&
     100           0 :                 nFldDivisionX== rItem.nFldDivisionX&&
     101           0 :                 nFldDrawY    == rItem.nFldDrawY    &&
     102           0 :                 nFldDivisionY== rItem.nFldDivisionY&&
     103           0 :                 nFldSnapX    == rItem.nFldSnapX    &&
     104           0 :                 nFldSnapY    == rItem.nFldSnapY     );
     105             : }
     106             : 
     107           0 : SfxItemPresentation  SvxGridItem::GetPresentation
     108             : (
     109             :     SfxItemPresentation ePres,
     110             :     SfxMapUnit          /*eCoreUnit*/,
     111             :     SfxMapUnit          /*ePresUnit*/,
     112             :     OUString&           rText, const IntlWrapper *
     113             : )   const
     114             : {
     115           0 :     switch ( ePres )
     116             :     {
     117             :         case SFX_ITEM_PRESENTATION_NONE:
     118           0 :             rText = OUString();
     119           0 :             return SFX_ITEM_PRESENTATION_NONE;
     120             :         case SFX_ITEM_PRESENTATION_NAMELESS:
     121             :         case SFX_ITEM_PRESENTATION_COMPLETE:
     122           0 :             rText = "SvxGridItem";
     123           0 :             return ePres;
     124             :         default:
     125           0 :             return SFX_ITEM_PRESENTATION_NONE;
     126             :     }
     127             : }
     128             : 
     129             : // TabPage Screen Settings
     130           0 : SvxGridTabPage::SvxGridTabPage( Window* pParent, const SfxItemSet& rCoreSet) :
     131             : 
     132           0 :     SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_GRID ), rCoreSet ),
     133             : 
     134           0 :     aCbxUseGridsnap ( this, SVX_RES( CBX_USE_GRIDSNAP ) ),
     135           0 :     aCbxGridVisible ( this, SVX_RES( CBX_GRID_VISIBLE ) ),
     136             : 
     137           0 :     aFlResolution   ( this, SVX_RES( FL_RESOLUTION ) ),
     138           0 :     aFtDrawX        ( this, SVX_RES( FT_DRAW_X ) ),
     139           0 :     aMtrFldDrawX    ( this, SVX_RES( MTR_FLD_DRAW_X ) ),
     140           0 :     aFtDrawY        ( this, SVX_RES( FT_DRAW_Y ) ),
     141           0 :     aMtrFldDrawY    ( this, SVX_RES( MTR_FLD_DRAW_Y ) ),
     142             : 
     143           0 :     aFlDivision     ( this, SVX_RES( FL_DIVISION ) ),
     144           0 :     aFtDivisionX(     this, SVX_RES( FT_DIVISION_X) ),
     145           0 :     aNumFldDivisionX( this, SVX_RES( NUM_FLD_DIVISION_X ) ),
     146           0 :     aDivisionPointX(  this, SVX_RES( FT_HORZ_POINTS) ),
     147             : 
     148           0 :     aFtDivisionY(     this, SVX_RES( FT_DIVISION_Y) ),
     149           0 :     aNumFldDivisionY( this, SVX_RES( NUM_FLD_DIVISION_Y ) ),
     150           0 :     aDivisionPointY(  this, SVX_RES( FT_VERT_POINTS) ),
     151             : 
     152           0 :     aCbxSynchronize ( this, SVX_RES( CBX_SYNCHRONIZE ) ),
     153           0 :     aGrpDrawGrid    ( this, SVX_RES( GRP_DRAWGRID ) ),
     154             : 
     155           0 :     aGrpSnap            ( this, SVX_RES( GRP_SNAP ) ),
     156           0 :     aCbxSnapHelplines   ( this, SVX_RES( CBX_SNAP_HELPLINES ) ),
     157           0 :     aCbxSnapBorder      ( this, SVX_RES( CBX_SNAP_BORDER ) ),
     158           0 :     aCbxSnapFrame       ( this, SVX_RES( CBX_SNAP_FRAME ) ),
     159           0 :     aCbxSnapPoints      ( this, SVX_RES( CBX_SNAP_POINTS ) ),
     160           0 :     aFtSnapArea         ( this, SVX_RES( FT_SNAP_AREA ) ),
     161           0 :     aMtrFldSnapArea     ( this, SVX_RES( MTR_FLD_SNAP_AREA ) ),
     162             : 
     163           0 :     aSeparatorFL        ( this, SVX_RES( FL_SEPARATOR ) ),
     164             : 
     165           0 :     aGrpOrtho           ( this, SVX_RES( GRP_ORTHO ) ),
     166           0 :     aCbxOrtho           ( this, SVX_RES( CBX_ORTHO ) ),
     167           0 :     aCbxBigOrtho        ( this, SVX_RES( CBX_BIGORTHO ) ),
     168           0 :     aCbxRotate          ( this, SVX_RES( CBX_ROTATE ) ),
     169           0 :     aMtrFldAngle        ( this, SVX_RES( MTR_FLD_ANGLE ) ),
     170           0 :     aFtBezAngle         ( this, SVX_RES( FT_BEZ_ANGLE ) ),
     171           0 :     aMtrFldBezAngle     ( this, SVX_RES( MTR_FLD_BEZ_ANGLE ) ),
     172             : 
     173           0 :     bAttrModified( sal_False )
     174             : {
     175             :     // This page requires exchange Support
     176           0 :     SetExchangeSupport();
     177             : 
     178           0 :     FreeResource();
     179             : 
     180           0 :     aDivisionPointY.SetText(aDivisionPointX.GetText());
     181             :     // Set Metrics
     182           0 :     FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
     183             :     long nFirst, nLast, nMin, nMax;
     184             : 
     185           0 :     lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
     186           0 :     SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
     187           0 :     lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
     188             : 
     189           0 :     lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
     190           0 :     SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
     191           0 :     lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
     192             : 
     193             : 
     194           0 :     aCbxRotate.SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
     195           0 :     Link aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
     196           0 :     aCbxUseGridsnap.SetClickHdl( aLink );
     197           0 :     aCbxSynchronize.SetClickHdl( aLink );
     198           0 :     aCbxGridVisible.SetClickHdl( aLink );
     199             :     aMtrFldDrawX.SetModifyHdl(
     200           0 :         LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
     201             :     aMtrFldDrawY.SetModifyHdl(
     202           0 :         LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
     203             :     aNumFldDivisionX.SetModifyHdl(
     204           0 :         LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
     205             :     aNumFldDivisionY.SetModifyHdl(
     206           0 :         LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
     207             : 
     208           0 :     OUString sFlResolution( aFlResolution.GetDisplayText() );
     209           0 :     OUString sFtDrawX(aFtDrawX.GetDisplayText());
     210           0 :     OUString sFtDrawY(aFtDrawY.GetDisplayText());
     211           0 :     aMtrFldDrawX.SetAccessibleName( sFtDrawX + sFlResolution   );
     212           0 :     aMtrFldDrawY.SetAccessibleName( sFtDrawY + sFlResolution   );
     213           0 :     OUString sFlDivision( aFlDivision.GetDisplayText() );
     214           0 :     OUString sFtDivisionX(aFtDivisionX.GetDisplayText());
     215           0 :     OUString sFtDivisionY(aFtDivisionY.GetDisplayText());
     216           0 :     aNumFldDivisionX.SetAccessibleName(  sFtDivisionX + sFlDivision );
     217           0 :     aNumFldDivisionY.SetAccessibleName(  sFtDivisionY + sFlDivision );
     218           0 : }
     219             : 
     220             : //------------------------------------------------------------------------
     221             : 
     222           0 : SfxTabPage* SvxGridTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
     223             : {
     224           0 :     return ( new SvxGridTabPage( pParent, rAttrSet ) );
     225             : }
     226             : 
     227             : //------------------------------------------------------------------------
     228             : 
     229           0 : sal_Bool SvxGridTabPage::FillItemSet( SfxItemSet& rCoreSet )
     230             : {
     231           0 :     if ( bAttrModified )
     232             :     {
     233           0 :         SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
     234             : 
     235           0 :         aGridItem.bUseGridsnap  = aCbxUseGridsnap.IsChecked();
     236           0 :         aGridItem.bSynchronize  = aCbxSynchronize.IsChecked();
     237           0 :         aGridItem.bGridVisible  = aCbxGridVisible.IsChecked();
     238             : 
     239             :         SfxMapUnit eUnit =
     240           0 :             rCoreSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
     241           0 :         long nX =GetCoreValue(  aMtrFldDrawX, eUnit );
     242           0 :         long nY = GetCoreValue( aMtrFldDrawY, eUnit );
     243             : 
     244           0 :         aGridItem.nFldDrawX    = (sal_uInt32) nX;
     245           0 :         aGridItem.nFldDrawY    = (sal_uInt32) nY;
     246           0 :         aGridItem.nFldDivisionX = static_cast<long>(aNumFldDivisionX.GetValue()-1);
     247           0 :         aGridItem.nFldDivisionY = static_cast<long>(aNumFldDivisionY.GetValue()-1);
     248             : 
     249           0 :         rCoreSet.Put( aGridItem );
     250             :     }
     251           0 :     return bAttrModified;
     252             : }
     253             : 
     254             : //------------------------------------------------------------------------
     255             : 
     256           0 : void SvxGridTabPage::Reset( const SfxItemSet& rSet )
     257             : {
     258           0 :     const SfxPoolItem* pAttr = 0;
     259             : 
     260           0 :     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
     261           0 :                                     (const SfxPoolItem**)&pAttr ))
     262             :     {
     263           0 :         const SvxGridItem* pGridAttr = (SvxGridItem*)pAttr;
     264           0 :         aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
     265           0 :         aCbxSynchronize.Check( pGridAttr->bSynchronize == 1 );
     266           0 :         aCbxGridVisible.Check( pGridAttr->bGridVisible == 1 );
     267             : 
     268             :         SfxMapUnit eUnit =
     269           0 :             rSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
     270           0 :         SetMetricValue( aMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
     271           0 :         SetMetricValue( aMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
     272             : 
     273           0 :         aNumFldDivisionX.SetValue( pGridAttr->nFldDivisionX+1 );
     274           0 :         aNumFldDivisionY.SetValue( pGridAttr->nFldDivisionY+1 );
     275             :     }
     276             : 
     277           0 :     ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
     278           0 :     bAttrModified = sal_False;
     279           0 : }
     280             : 
     281             : // -----------------------------------------------------------------------
     282             : 
     283           0 : void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
     284             : {
     285           0 :     const SfxPoolItem* pAttr = NULL;
     286           0 :     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
     287           0 :                                     (const SfxPoolItem**)&pAttr ))
     288             :     {
     289           0 :         const SvxGridItem* pGridAttr = (SvxGridItem*) pAttr;
     290           0 :         aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
     291             : 
     292           0 :         ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
     293             :     }
     294             : 
     295             :     // Metric Change if necessary (as TabPage is in the dialog, where the
     296             :     // metric can be set
     297           0 :     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC , sal_False,
     298           0 :                                     (const SfxPoolItem**)&pAttr ))
     299             :     {
     300           0 :         const SfxUInt16Item* pItem = (SfxUInt16Item*) pAttr;
     301             : 
     302           0 :         FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
     303             : 
     304           0 :         if( eFUnit != aMtrFldDrawX.GetUnit() )
     305             :         {
     306             :             // Set Metrics
     307             :             long nFirst, nLast, nMin, nMax;
     308           0 :             long nVal = static_cast<long>(aMtrFldDrawX.Denormalize( aMtrFldDrawX.GetValue( FUNIT_TWIP ) ));
     309             : 
     310           0 :             lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
     311           0 :             SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
     312           0 :             lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
     313             : 
     314           0 :             aMtrFldDrawX.SetValue( aMtrFldDrawX.Normalize( nVal ), FUNIT_TWIP );
     315             : 
     316           0 :             nVal = static_cast<long>(aMtrFldDrawY.Denormalize( aMtrFldDrawY.GetValue( FUNIT_TWIP ) ));
     317           0 :             lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
     318           0 :             SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
     319           0 :             lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
     320           0 :             aMtrFldDrawY.SetValue( aMtrFldDrawY.Normalize( nVal ), FUNIT_TWIP );
     321             : 
     322             :         }
     323             :     }
     324           0 : }
     325             : 
     326             : // -----------------------------------------------------------------------
     327           0 : int SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
     328             : {
     329           0 :     if ( _pSet )
     330           0 :         FillItemSet( *_pSet );
     331           0 :     return( LEAVE_PAGE );
     332             : }
     333             : //------------------------------------------------------------------------
     334           0 : IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
     335             : {
     336           0 :     bAttrModified = sal_True;
     337           0 :     if( aCbxSynchronize.IsChecked() )
     338             :     {
     339           0 :         if(pField == &aMtrFldDrawX)
     340           0 :             aMtrFldDrawY.SetValue( aMtrFldDrawX.GetValue() );
     341             :         else
     342           0 :             aMtrFldDrawX.SetValue( aMtrFldDrawY.GetValue() );
     343             :     }
     344           0 :     return 0;
     345             : }
     346             : //------------------------------------------------------------------------
     347             : 
     348           0 : IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl)
     349             : {
     350           0 :     if( aCbxRotate.IsChecked() )
     351           0 :         aMtrFldAngle.Enable();
     352             :     else
     353           0 :         aMtrFldAngle.Disable();
     354             : 
     355           0 :     return( 0L );
     356             : }
     357             : 
     358             : //------------------------------------------------------------------------
     359             : 
     360           0 : IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
     361             : {
     362           0 :     bAttrModified = sal_True;
     363           0 :     if( aCbxSynchronize.IsChecked() )
     364             :     {
     365           0 :         if(&aNumFldDivisionX == pField)
     366           0 :             aNumFldDivisionY.SetValue( aNumFldDivisionX.GetValue() );
     367             :         else
     368           0 :             aNumFldDivisionX.SetValue( aNumFldDivisionY.GetValue() );
     369             :     }
     370           0 :     return 0;
     371             : }
     372             : //------------------------------------------------------------------------
     373             : 
     374           0 : IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl)
     375             : {
     376           0 :     bAttrModified = sal_True;
     377           0 :     return 0;
     378         216 : }
     379             : 
     380             : 
     381             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10