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

Generated by: LCOV version 1.10