LCOV - code coverage report
Current view: top level - svx/source/dialog - optgrid.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 6 168 3.6 %
Date: 2014-11-03 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 <sfx2/app.hxx>
      21             : #include <sfx2/module.hxx>
      22             : #include <svl/intitem.hxx>
      23             : 
      24             : #include <svx/svxids.hrc>
      25             : #include <svx/dialmgr.hxx>
      26             : #include "svx/optgrid.hxx"
      27             : #include <svx/dialogs.hrc>
      28             : #include "svx/dlgutil.hxx"
      29             : 
      30             : // local functions
      31           0 : static void    lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
      32             : {
      33           0 :     nFirst  = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
      34           0 :     nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
      35           0 :     nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
      36           0 :     nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
      37           0 : }
      38             : 
      39           0 : static void    lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
      40             : {
      41           0 :     rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
      42           0 :     rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
      43           0 :     rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
      44           0 :     rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
      45           0 : }
      46             : 
      47       18640 : SvxOptionsGrid::SvxOptionsGrid() :
      48             :     nFldDrawX       ( 100 ),
      49             :     nFldDivisionX   ( 0 ),
      50             :     nFldDrawY       ( 100 ),
      51             :     nFldDivisionY   ( 0 ),
      52             :     nFldSnapX       ( 100 ),
      53             :     nFldSnapY       ( 100 ),
      54             :     bUseGridsnap    ( false ),
      55             :     bSynchronize    ( true ),
      56             :     bGridVisible    ( false ),
      57       18640 :     bEqualGrid      ( true )
      58             : {
      59       18640 : }
      60             : 
      61       24720 : SvxOptionsGrid::~SvxOptionsGrid()
      62             : {
      63       24720 : }
      64             : 
      65           0 : SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
      66             : :   SvxOptionsGrid()
      67           0 : ,   SfxPoolItem(rItem)
      68             : {
      69           0 :     bUseGridsnap = rItem.bUseGridsnap ;
      70           0 :     bSynchronize = rItem.bSynchronize ;
      71           0 :     bGridVisible = rItem.bGridVisible ;
      72           0 :     bEqualGrid   = rItem.bEqualGrid   ;
      73           0 :     nFldDrawX    = rItem.nFldDrawX    ;
      74           0 :     nFldDivisionX= rItem.nFldDivisionX;
      75           0 :     nFldDrawY    = rItem.nFldDrawY    ;
      76           0 :     nFldDivisionY= rItem.nFldDivisionY;
      77           0 :     nFldSnapX    = rItem.nFldSnapX    ;
      78           0 :     nFldSnapY    = rItem.nFldSnapY    ;
      79             : 
      80           0 : };
      81             : 
      82           0 : SfxPoolItem*  SvxGridItem::Clone( SfxItemPool* ) const
      83             : {
      84           0 :     return new SvxGridItem( *this );
      85             : }
      86             : 
      87           0 : bool SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
      88             : {
      89             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "different types ");
      90             : 
      91           0 :     const SvxGridItem& rItem = static_cast<const SvxGridItem&>(rAttr);
      92             : 
      93           0 :     return (    bUseGridsnap == rItem.bUseGridsnap &&
      94           0 :                 bSynchronize == rItem.bSynchronize &&
      95           0 :                 bGridVisible == rItem.bGridVisible &&
      96           0 :                 bEqualGrid   == rItem.bEqualGrid   &&
      97           0 :                 nFldDrawX    == rItem.nFldDrawX    &&
      98           0 :                 nFldDivisionX== rItem.nFldDivisionX&&
      99           0 :                 nFldDrawY    == rItem.nFldDrawY    &&
     100           0 :                 nFldDivisionY== rItem.nFldDivisionY&&
     101           0 :                 nFldSnapX    == rItem.nFldSnapX    &&
     102           0 :                 nFldSnapY    == rItem.nFldSnapY     );
     103             : }
     104             : 
     105           0 : bool  SvxGridItem::GetPresentation
     106             : (
     107             :     SfxItemPresentation /*ePres*/,
     108             :     SfxMapUnit          /*eCoreUnit*/,
     109             :     SfxMapUnit          /*ePresUnit*/,
     110             :     OUString&           rText, const IntlWrapper *
     111             : )   const
     112             : {
     113           0 :     rText = "SvxGridItem";
     114           0 :     return true;
     115             : }
     116             : 
     117             : // TabPage Screen Settings
     118           0 : SvxGridTabPage::SvxGridTabPage( vcl::Window* pParent, const SfxItemSet& rCoreSet) :
     119             : 
     120             :     SfxTabPage( pParent, "OptGridPage" , "svx/ui/optgridpage.ui", &rCoreSet ),
     121           0 :     bAttrModified( false )
     122             : {
     123           0 :     get(pCbxUseGridsnap,"usegridsnap");
     124           0 :     get(pCbxGridVisible,"gridvisible");
     125           0 :     get(pMtrFldDrawX,"mtrflddrawx");
     126           0 :     get(pMtrFldDrawY,"mtrflddrawy");
     127           0 :     get(pNumFldDivisionX,"numflddivisionx");
     128           0 :     get(pNumFldDivisionY,"numflddivisiony");
     129           0 :     get(pCbxSynchronize,"synchronize");
     130             : 
     131           0 :     get(pSnapFrames,"snapframes");
     132           0 :     get(pCbxSnapHelplines,"snaphelplines");
     133           0 :     get(pCbxSnapBorder,"snapborder");
     134           0 :     get(pCbxSnapFrame,"snapframe");
     135           0 :     get(pCbxSnapPoints,"snappoints");
     136           0 :     get(pMtrFldSnapArea,"mtrfldsnaparea");
     137           0 :     get(pCbxOrtho,"ortho");
     138           0 :     get(pCbxBigOrtho,"bigortho");
     139           0 :     get(pCbxRotate,"rotate");
     140           0 :     get(pMtrFldAngle,"mtrfldangle");
     141           0 :     get(pMtrFldBezAngle,"mtrfldbezangle");
     142             : 
     143             :     // This page requires exchange Support
     144           0 :     SetExchangeSupport();
     145             : 
     146             :     // Set Metrics
     147           0 :     FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
     148             :     long nFirst, nLast, nMin, nMax;
     149             : 
     150           0 :     lcl_GetMinMax(*pMtrFldDrawX , nFirst, nLast, nMin, nMax);
     151           0 :     SetFieldUnit( *pMtrFldDrawX , eFUnit, true );
     152           0 :     lcl_SetMinMax(*pMtrFldDrawX , nFirst, nLast, nMin, nMax);
     153             : 
     154           0 :     lcl_GetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
     155           0 :     SetFieldUnit( *pMtrFldDrawY, eFUnit, true );
     156           0 :     lcl_SetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
     157             : 
     158             : 
     159           0 :     pCbxRotate->SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
     160           0 :     Link aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
     161           0 :     pCbxUseGridsnap->SetClickHdl( aLink );
     162           0 :     pCbxSynchronize->SetClickHdl( aLink );
     163           0 :     pCbxGridVisible->SetClickHdl( aLink );
     164             :     pMtrFldDrawX->SetModifyHdl(
     165           0 :         LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
     166             :     pMtrFldDrawY->SetModifyHdl(
     167           0 :         LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
     168             :     pNumFldDivisionX->SetModifyHdl(
     169           0 :         LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
     170             :     pNumFldDivisionY->SetModifyHdl(
     171           0 :         LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
     172           0 : }
     173             : 
     174             : 
     175             : 
     176           0 : SfxTabPage* SvxGridTabPage::Create( vcl::Window* pParent, const SfxItemSet& rAttrSet )
     177             : {
     178           0 :     return ( new SvxGridTabPage( pParent, rAttrSet ) );
     179             : }
     180             : 
     181             : 
     182             : 
     183           0 : bool SvxGridTabPage::FillItemSet( SfxItemSet* rCoreSet )
     184             : {
     185           0 :     if ( bAttrModified )
     186             :     {
     187           0 :         SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
     188             : 
     189           0 :         aGridItem.bUseGridsnap  = pCbxUseGridsnap->IsChecked();
     190           0 :         aGridItem.bSynchronize  = pCbxSynchronize->IsChecked();
     191           0 :         aGridItem.bGridVisible  = pCbxGridVisible->IsChecked();
     192             : 
     193             :         SfxMapUnit eUnit =
     194           0 :             rCoreSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
     195           0 :         long nX =GetCoreValue(  *pMtrFldDrawX, eUnit );
     196           0 :         long nY = GetCoreValue( *pMtrFldDrawY, eUnit );
     197             : 
     198           0 :         aGridItem.nFldDrawX    = (sal_uInt32) nX;
     199           0 :         aGridItem.nFldDrawY    = (sal_uInt32) nY;
     200           0 :         aGridItem.nFldDivisionX = static_cast<long>(pNumFldDivisionX->GetValue()-1);
     201           0 :         aGridItem.nFldDivisionY = static_cast<long>(pNumFldDivisionY->GetValue()-1);
     202             : 
     203           0 :         rCoreSet->Put( aGridItem );
     204             :     }
     205           0 :     return bAttrModified;
     206             : }
     207             : 
     208             : 
     209             : 
     210           0 : void SvxGridTabPage::Reset( const SfxItemSet* rSet )
     211             : {
     212           0 :     const SfxPoolItem* pAttr = 0;
     213             : 
     214           0 :     if( SfxItemState::SET == rSet->GetItemState( SID_ATTR_GRID_OPTIONS , false,
     215           0 :                                     (const SfxPoolItem**)&pAttr ))
     216             :     {
     217           0 :         const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
     218           0 :         pCbxUseGridsnap->Check( pGridAttr->bUseGridsnap );
     219           0 :         pCbxSynchronize->Check( pGridAttr->bSynchronize );
     220           0 :         pCbxGridVisible->Check( pGridAttr->bGridVisible );
     221             : 
     222             :         SfxMapUnit eUnit =
     223           0 :             rSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
     224           0 :         SetMetricValue( *pMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
     225           0 :         SetMetricValue( *pMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
     226             : 
     227           0 :         pNumFldDivisionX->SetValue( pGridAttr->nFldDivisionX+1 );
     228           0 :         pNumFldDivisionY->SetValue( pGridAttr->nFldDivisionY+1 );
     229             :     }
     230             : 
     231           0 :     ChangeGridsnapHdl_Impl( pCbxUseGridsnap );
     232           0 :     bAttrModified = false;
     233           0 : }
     234             : 
     235             : 
     236             : 
     237           0 : void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
     238             : {
     239           0 :     const SfxPoolItem* pAttr = NULL;
     240           0 :     if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , false,
     241           0 :                                     (const SfxPoolItem**)&pAttr ))
     242             :     {
     243           0 :         const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
     244           0 :         pCbxUseGridsnap->Check( pGridAttr->bUseGridsnap );
     245             : 
     246           0 :         ChangeGridsnapHdl_Impl( pCbxUseGridsnap );
     247             :     }
     248             : 
     249             :     // Metric Change if necessary (as TabPage is in the dialog, where the
     250             :     // metric can be set
     251           0 :     if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_METRIC , false,
     252           0 :                                     (const SfxPoolItem**)&pAttr ))
     253             :     {
     254           0 :         const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr);
     255             : 
     256           0 :         FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
     257             : 
     258           0 :         if( eFUnit != pMtrFldDrawX->GetUnit() )
     259             :         {
     260             :             // Set Metrics
     261             :             long nFirst, nLast, nMin, nMax;
     262           0 :             long nVal = static_cast<long>(pMtrFldDrawX->Denormalize( pMtrFldDrawX->GetValue( FUNIT_TWIP ) ));
     263             : 
     264           0 :             lcl_GetMinMax(*pMtrFldDrawX, nFirst, nLast, nMin, nMax);
     265           0 :             SetFieldUnit( *pMtrFldDrawX, eFUnit, true );
     266           0 :             lcl_SetMinMax(*pMtrFldDrawX, nFirst, nLast, nMin, nMax);
     267             : 
     268           0 :             pMtrFldDrawX->SetValue( pMtrFldDrawX->Normalize( nVal ), FUNIT_TWIP );
     269             : 
     270           0 :             nVal = static_cast<long>(pMtrFldDrawY->Denormalize( pMtrFldDrawY->GetValue( FUNIT_TWIP ) ));
     271           0 :             lcl_GetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
     272           0 :             SetFieldUnit(*pMtrFldDrawY, eFUnit, true );
     273           0 :             lcl_SetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
     274           0 :             pMtrFldDrawY->SetValue( pMtrFldDrawY->Normalize( nVal ), FUNIT_TWIP );
     275             : 
     276             :         }
     277             :     }
     278           0 : }
     279             : 
     280             : 
     281           0 : int SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
     282             : {
     283           0 :     if ( _pSet )
     284           0 :         FillItemSet( _pSet );
     285           0 :     return( LEAVE_PAGE );
     286             : }
     287             : 
     288           0 : IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
     289             : {
     290           0 :     bAttrModified = true;
     291           0 :     if( pCbxSynchronize->IsChecked() )
     292             :     {
     293           0 :         if(pField == pMtrFldDrawX)
     294           0 :             pMtrFldDrawY->SetValue( pMtrFldDrawX->GetValue() );
     295             :         else
     296           0 :             pMtrFldDrawX->SetValue( pMtrFldDrawY->GetValue() );
     297             :     }
     298           0 :     return 0;
     299             : }
     300             : 
     301             : 
     302           0 : IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl)
     303             : {
     304           0 :     if( pCbxRotate->IsChecked() )
     305           0 :         pMtrFldAngle->Enable();
     306             :     else
     307           0 :         pMtrFldAngle->Disable();
     308             : 
     309           0 :     return( 0L );
     310             : }
     311             : 
     312             : 
     313             : 
     314           0 : IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
     315             : {
     316           0 :     bAttrModified = true;
     317           0 :     if( pCbxSynchronize->IsChecked() )
     318             :     {
     319           0 :         if(pNumFldDivisionX == pField)
     320           0 :             pNumFldDivisionY->SetValue( pNumFldDivisionX->GetValue() );
     321             :         else
     322           0 :             pNumFldDivisionX->SetValue( pNumFldDivisionY->GetValue() );
     323             :     }
     324           0 :     return 0;
     325             : }
     326             : 
     327             : 
     328           0 : IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl)
     329             : {
     330           0 :     bAttrModified = true;
     331           0 :     return 0;
     332         594 : }
     333             : 
     334             : 
     335             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10