LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - zoom.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 228 0.4 %
Date: 2012-12-27 Functions: 2 21 9.5 %
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 <svl/itemset.hxx>
      22             : #include <svl/itempool.hxx>
      23             : #include <sfx2/objsh.hxx>
      24             : #include <vcl/layout.hxx>
      25             : #include <vcl/msgbox.hxx>
      26             : 
      27             : #define _SVX_ZOOM_CXX
      28             : 
      29             : #include <cuires.hrc>
      30             : #include "zoom.hrc"
      31             : 
      32             : #include "zoom.hxx"
      33             : #include <sfx2/zoomitem.hxx>
      34             : #include <svx/viewlayoutitem.hxx>
      35             : #include <dialmgr.hxx>
      36             : #include <svx/zoom_def.hxx>
      37             : 
      38             : // static ----------------------------------------------------------------
      39             : 
      40             : #define SPECIAL_FACTOR  ((sal_uInt16)0xFFFF)
      41             : 
      42             : // class SvxZoomDialog ---------------------------------------------------
      43             : 
      44           0 : sal_uInt16 SvxZoomDialog::GetFactor() const
      45             : {
      46           0 :     if ( m_p100Btn->IsChecked() )
      47           0 :         return 100;
      48           0 :     if ( m_pUserBtn->IsChecked() )
      49           0 :         return (sal_uInt16)m_pUserEdit->GetValue();
      50             :     else
      51           0 :         return SPECIAL_FACTOR;
      52             : }
      53             : 
      54             : // -----------------------------------------------------------------------
      55             : 
      56           0 : void SvxZoomDialog::SetFactor( sal_uInt16 nNewFactor, sal_uInt16 nBtnId )
      57             : {
      58           0 :     m_pUserEdit->Disable();
      59             : 
      60           0 :     if ( !nBtnId )
      61             :     {
      62           0 :         if ( nNewFactor == 100 )
      63             :         {
      64           0 :             m_p100Btn->Check();
      65           0 :             m_p100Btn->GrabFocus();
      66             :         }
      67             :         else
      68             :         {
      69           0 :             m_pUserBtn->Check();
      70           0 :             m_pUserEdit->Enable();
      71           0 :             m_pUserEdit->SetValue( (long)nNewFactor );
      72           0 :             m_pUserEdit->GrabFocus();
      73             :         }
      74             :     }
      75             :     else
      76             :     {
      77           0 :         m_pUserEdit->SetValue( (long)nNewFactor );
      78             : 
      79           0 :         if ( ZOOMBTN_OPTIMAL == nBtnId )
      80             :         {
      81           0 :             m_pOptimalBtn->Check();
      82           0 :             m_pOptimalBtn->GrabFocus();
      83             :         }
      84           0 :         else if ( ZOOMBTN_PAGEWIDTH == nBtnId )
      85             :         {
      86           0 :             m_pPageWidthBtn->Check();
      87           0 :             m_pPageWidthBtn->GrabFocus();
      88             :         }
      89           0 :         else if ( ZOOMBTN_WHOLEPAGE == nBtnId )
      90             :         {
      91           0 :             m_pWholePageBtn->Check();
      92           0 :             m_pWholePageBtn->GrabFocus();
      93             :         }
      94             :     }
      95           0 : }
      96             : 
      97             : // -----------------------------------------------------------------------
      98             : 
      99           0 : void SvxZoomDialog::HideButton( sal_uInt16 nBtnId )
     100             : {
     101           0 :     switch ( nBtnId )
     102             :     {
     103             :         case ZOOMBTN_OPTIMAL:
     104           0 :             m_pOptimalBtn->Hide();
     105           0 :             break;
     106             : 
     107             :         case ZOOMBTN_PAGEWIDTH:
     108           0 :             m_pPageWidthBtn->Hide();
     109           0 :             break;
     110             : 
     111             :         case ZOOMBTN_WHOLEPAGE:
     112           0 :             m_pWholePageBtn->Hide();
     113           0 :             break;
     114             : 
     115             :         default:
     116             :             OSL_FAIL( "Falsche Button-Nummer!!!" );
     117             :     }
     118           0 : }
     119             : 
     120             : // -----------------------------------------------------------------------
     121             : 
     122           0 : void SvxZoomDialog::SetLimits( sal_uInt16 nMin, sal_uInt16 nMax )
     123             : {
     124             :     DBG_ASSERT( nMin < nMax, "invalid limits" );
     125           0 :     m_pUserEdit->SetMin( nMin );
     126           0 :     m_pUserEdit->SetFirst( nMin );
     127           0 :     m_pUserEdit->SetMax( nMax );
     128           0 :     m_pUserEdit->SetLast( nMax );
     129           0 : }
     130             : 
     131             : // -----------------------------------------------------------------------
     132             : 
     133           0 : SvxZoomDialog::SvxZoomDialog( Window* pParent, const SfxItemSet& rCoreSet )
     134             :     : SfxModalDialog(pParent, "ZoomDialog", "cui/ui/zoomdialog.ui")
     135             :     , rSet(rCoreSet)
     136             :     , pOutSet(NULL)
     137           0 :     , bModified(false)
     138             : 
     139             : {
     140           0 :     get(m_pOptimalBtn, "optimal");
     141           0 :     get(m_pWholePageBtn, "fitwandh");
     142           0 :     get(m_pPageWidthBtn, "fitw");
     143           0 :     get(m_p100Btn, "100pc");
     144           0 :     get(m_pUserBtn, "variable");
     145           0 :     get(m_pUserEdit, "zoomsb");
     146           0 :     get(m_pViewFrame, "viewframe");
     147           0 :     get(m_pAutomaticBtn, "automatic");
     148           0 :     get(m_pSingleBtn, "singlepage");
     149           0 :     get(m_pColumnsBtn, "columns");
     150           0 :     get(m_pColumnsEdit, "columnssb");
     151           0 :     get(m_pBookModeChk, "bookmode");
     152           0 :     get(m_pOKBtn, "ok");
     153           0 :     Link aLink = LINK( this, SvxZoomDialog, UserHdl );
     154           0 :     m_p100Btn->SetClickHdl( aLink );
     155           0 :     m_pOptimalBtn->SetClickHdl( aLink );
     156           0 :     m_pPageWidthBtn->SetClickHdl( aLink );
     157           0 :     m_pWholePageBtn->SetClickHdl( aLink );
     158           0 :     m_pUserBtn->SetClickHdl( aLink );
     159             : 
     160           0 :     Link aViewLayoutLink = LINK( this, SvxZoomDialog, ViewLayoutUserHdl );
     161           0 :     m_pAutomaticBtn->SetClickHdl( aViewLayoutLink );
     162           0 :     m_pSingleBtn->SetClickHdl( aViewLayoutLink );
     163           0 :     m_pColumnsBtn->SetClickHdl( aViewLayoutLink );
     164             : 
     165           0 :     Link aViewLayoutSpinLink = LINK( this, SvxZoomDialog, ViewLayoutSpinHdl );
     166           0 :     m_pColumnsEdit->SetModifyHdl( aViewLayoutSpinLink );
     167             : 
     168           0 :     Link aViewLayoutCheckLink = LINK( this, SvxZoomDialog, ViewLayoutCheckHdl );
     169           0 :     m_pBookModeChk->SetClickHdl( aViewLayoutCheckLink );
     170             : 
     171           0 :     m_pOKBtn->SetClickHdl( LINK( this, SvxZoomDialog, OKHdl ) );
     172           0 :     m_pUserEdit->SetModifyHdl( LINK( this, SvxZoomDialog, SpinHdl ) );
     173             : 
     174             :     // default values
     175           0 :     sal_uInt16 nValue = 100;
     176           0 :     sal_uInt16 nMin = 10;
     177           0 :     sal_uInt16 nMax = 1000;
     178             : 
     179             :     // maybe get the old value first
     180           0 :     const SfxUInt16Item* pOldUserItem = 0;
     181           0 :     SfxObjectShell* pSh = SfxObjectShell::Current();
     182             : 
     183           0 :     if ( pSh )
     184           0 :         pOldUserItem = (const SfxUInt16Item*)pSh->GetItem( SID_ATTR_ZOOM_USER );
     185             : 
     186           0 :     if ( pOldUserItem )
     187           0 :         nValue = pOldUserItem->GetValue();
     188             : 
     189             :     // initialize UserEdit
     190           0 :     if ( nMin > nValue )
     191           0 :         nMin = nValue;
     192           0 :     if ( nMax < nValue )
     193           0 :         nMax = nValue;
     194           0 :     m_pUserEdit->SetMin( nMin );
     195           0 :     m_pUserEdit->SetFirst( nMin );
     196           0 :     m_pUserEdit->SetMax( nMax );
     197           0 :     m_pUserEdit->SetLast( nMax );
     198           0 :     m_pUserEdit->SetValue( nValue );
     199             : 
     200           0 :     m_pUserEdit->SetAccessibleRelationLabeledBy(m_pUserBtn);
     201           0 :     m_pUserEdit->SetAccessibleName(m_pUserBtn->GetText());
     202           0 :     m_pColumnsEdit->SetAccessibleRelationLabeledBy(m_pColumnsBtn);
     203           0 :     m_pColumnsEdit->SetAccessibleName(m_pColumnsBtn->GetText());
     204           0 :     m_pColumnsEdit->SetAccessibleRelationMemberOf(m_pColumnsBtn);
     205           0 :     m_pBookModeChk->SetAccessibleRelationLabeledBy(m_pColumnsBtn);
     206           0 :     m_pBookModeChk->SetAccessibleRelationMemberOf(m_pColumnsBtn);
     207             : 
     208           0 :     const SfxPoolItem& rItem = rSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_ZOOM ) );
     209             : 
     210           0 :     if ( rItem.ISA(SvxZoomItem) )
     211             :     {
     212           0 :         const SvxZoomItem& rZoomItem = (const SvxZoomItem&)rItem;
     213           0 :         const sal_uInt16 nZoom = rZoomItem.GetValue();
     214           0 :         const SvxZoomType eType = rZoomItem.GetType();
     215           0 :         const sal_uInt16 nValSet = rZoomItem.GetValueSet();
     216           0 :         sal_uInt16 nBtnId = 0;
     217             : 
     218           0 :         switch ( eType )
     219             :         {
     220             :             case SVX_ZOOM_OPTIMAL:
     221           0 :                 nBtnId = ZOOMBTN_OPTIMAL;
     222           0 :                 break;
     223             :             case SVX_ZOOM_PAGEWIDTH:
     224           0 :                 nBtnId = ZOOMBTN_PAGEWIDTH;
     225           0 :                 break;
     226             :             case SVX_ZOOM_WHOLEPAGE:
     227           0 :                 nBtnId = ZOOMBTN_WHOLEPAGE;
     228           0 :                 break;
     229             :             case SVX_ZOOM_PERCENT:
     230           0 :                 break;
     231             :             case SVX_ZOOM_PAGEWIDTH_NOBORDER:
     232           0 :                 break;
     233             :         }
     234             : 
     235           0 :         if ( !(SVX_ZOOM_ENABLE_100 & nValSet) )
     236           0 :             m_p100Btn->Disable();
     237           0 :         if ( !(SVX_ZOOM_ENABLE_OPTIMAL & nValSet) )
     238           0 :             m_pOptimalBtn->Disable();
     239           0 :         if ( !(SVX_ZOOM_ENABLE_PAGEWIDTH & nValSet) )
     240           0 :             m_pPageWidthBtn->Disable();
     241           0 :         if ( !(SVX_ZOOM_ENABLE_WHOLEPAGE & nValSet) )
     242           0 :             m_pWholePageBtn->Disable();
     243           0 :         SetFactor( nZoom, nBtnId );
     244             :     }
     245             :     else
     246             :     {
     247           0 :         const sal_uInt16 nZoom = ( (const SfxUInt16Item&)rItem ).GetValue();
     248           0 :         SetFactor( nZoom );
     249             :     }
     250             : 
     251           0 :     const SfxPoolItem* pViewLayoutItem = 0;
     252           0 :     if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_VIEWLAYOUT, sal_False, &pViewLayoutItem ) )
     253             :     {
     254           0 :         const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>(pViewLayoutItem)->GetValue();
     255           0 :         const bool bBookMode  = static_cast<const SvxViewLayoutItem*>(pViewLayoutItem)->IsBookMode();
     256             : 
     257           0 :         if ( 0 == nColumns )
     258             :         {
     259           0 :             m_pAutomaticBtn->Check();
     260           0 :             m_pColumnsEdit->SetValue( 2 );
     261           0 :             m_pColumnsEdit->Disable();
     262           0 :             m_pBookModeChk->Disable();
     263             :         }
     264           0 :         else if ( 1 == nColumns)
     265             :         {
     266           0 :             m_pSingleBtn->Check();
     267           0 :             m_pColumnsEdit->SetValue( 2 );
     268           0 :             m_pColumnsEdit->Disable();
     269           0 :             m_pBookModeChk->Disable();
     270             :         }
     271             :         else
     272             :         {
     273           0 :             m_pColumnsBtn->Check();
     274           0 :             if ( !bBookMode )
     275             :             {
     276           0 :                 m_pColumnsEdit->SetValue( nColumns );
     277           0 :                 if ( 0 != nColumns % 2 )
     278           0 :                     m_pBookModeChk->Disable();
     279             :             }
     280             :             else
     281             :             {
     282           0 :                 m_pColumnsEdit->SetValue( nColumns );
     283           0 :                 m_pBookModeChk->Check();
     284             :             }
     285             :         }
     286             :     }
     287             :     else
     288             :     {
     289             :         // hide view layout related controls:
     290           0 :         m_pViewFrame->Disable();
     291             :     }
     292           0 : }
     293             : 
     294             : // -----------------------------------------------------------------------
     295             : 
     296           0 : SvxZoomDialog::~SvxZoomDialog()
     297             : {
     298           0 :     delete pOutSet;
     299           0 :     pOutSet = 0;
     300           0 : }
     301             : 
     302             : // -----------------------------------------------------------------------
     303             : 
     304           0 : IMPL_LINK( SvxZoomDialog, UserHdl, RadioButton *, pBtn )
     305             : {
     306           0 :     bModified |= sal_True;
     307             : 
     308           0 :     if (pBtn == m_pUserBtn)
     309             :     {
     310           0 :         m_pUserEdit->Enable();
     311           0 :         m_pUserEdit->GrabFocus();
     312             :     }
     313             :     else
     314           0 :         m_pUserEdit->Disable();
     315           0 :     return 0;
     316             : }
     317             : 
     318             : // -----------------------------------------------------------------------
     319             : 
     320           0 : IMPL_LINK_NOARG(SvxZoomDialog, SpinHdl)
     321             : {
     322           0 :     if ( !m_pUserBtn->IsChecked() )
     323           0 :         return 0;
     324           0 :     bModified |= sal_True;
     325           0 :     return 0;
     326             : }
     327             : 
     328             : // -----------------------------------------------------------------------
     329             : 
     330           0 : IMPL_LINK( SvxZoomDialog, ViewLayoutUserHdl, RadioButton *, pBtn )
     331             : {
     332           0 :     bModified |= sal_True;
     333             : 
     334           0 :     if (pBtn == m_pAutomaticBtn)
     335             :     {
     336           0 :         m_pColumnsEdit->Disable();
     337           0 :         m_pBookModeChk->Disable();
     338             :     }
     339           0 :     else if (pBtn == m_pSingleBtn)
     340             :     {
     341           0 :         m_pColumnsEdit->Disable();
     342           0 :         m_pBookModeChk->Disable();
     343             :     }
     344           0 :     else if (pBtn == m_pColumnsBtn)
     345             :     {
     346           0 :         m_pColumnsEdit->Enable();
     347           0 :         m_pColumnsEdit->GrabFocus();
     348           0 :         if ( 0 == m_pColumnsEdit->GetValue() % 2 )
     349           0 :             m_pBookModeChk->Enable();
     350             :     }
     351             :     else
     352             :     {
     353             :         OSL_FAIL( "Wrong Button" );
     354           0 :         return 0;
     355             :     }
     356             : 
     357           0 :     return 0;
     358             : }
     359             : 
     360             : // -----------------------------------------------------------------------
     361             : 
     362           0 : IMPL_LINK( SvxZoomDialog, ViewLayoutSpinHdl, MetricField *, pEdt )
     363             : {
     364           0 :     if ( pEdt == m_pColumnsEdit && !m_pColumnsBtn->IsChecked() )
     365           0 :         return 0;
     366             : 
     367           0 :     if ( 0 == m_pColumnsEdit->GetValue() % 2 )
     368           0 :         m_pBookModeChk->Enable();
     369             :     else
     370             :     {
     371           0 :         m_pBookModeChk->Check( sal_False );
     372           0 :         m_pBookModeChk->Disable();
     373             :     }
     374             : 
     375           0 :     bModified |= sal_True;
     376             : 
     377           0 :     return 0;
     378             : }
     379             : 
     380             : // -----------------------------------------------------------------------
     381             : 
     382           0 : IMPL_LINK( SvxZoomDialog, ViewLayoutCheckHdl, CheckBox *, pChk )
     383             : {
     384           0 :     if (pChk == m_pBookModeChk && !m_pColumnsBtn->IsChecked())
     385           0 :         return 0;
     386             : 
     387           0 :     bModified |= sal_True;
     388             : 
     389           0 :     return 0;
     390             : }
     391             : 
     392             : // -----------------------------------------------------------------------
     393             : 
     394           0 : IMPL_LINK( SvxZoomDialog, OKHdl, Button *, pBtn )
     395             : {
     396           0 :     if ( bModified || m_pOKBtn != pBtn )
     397             :     {
     398           0 :         SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, 0, rSet.GetPool()->GetWhich( SID_ATTR_ZOOM ) );
     399           0 :         SvxViewLayoutItem aViewLayoutItem( 0, false, rSet.GetPool()->GetWhich( SID_ATTR_VIEWLAYOUT ) );
     400             : 
     401           0 :         if ( m_pOKBtn == pBtn )
     402             :         {
     403           0 :             sal_uInt16 nFactor = GetFactor();
     404             : 
     405           0 :             if ( SPECIAL_FACTOR == nFactor )
     406             :             {
     407           0 :                 if ( m_pOptimalBtn->IsChecked() )
     408           0 :                     aZoomItem.SetType( SVX_ZOOM_OPTIMAL );
     409           0 :                 else if ( m_pPageWidthBtn->IsChecked() )
     410           0 :                     aZoomItem.SetType( SVX_ZOOM_PAGEWIDTH );
     411           0 :                 else if ( m_pWholePageBtn->IsChecked() )
     412           0 :                     aZoomItem.SetType( SVX_ZOOM_WHOLEPAGE );
     413             :             }
     414             :             else
     415           0 :                 aZoomItem.SetValue( nFactor );
     416             : 
     417           0 :             if ( m_pAutomaticBtn->IsChecked() )
     418             :             {
     419           0 :                 aViewLayoutItem.SetValue( 0 );
     420           0 :                 aViewLayoutItem.SetBookMode( false );
     421             :             }
     422           0 :             if ( m_pSingleBtn->IsChecked() )
     423             :             {
     424           0 :                 aViewLayoutItem.SetValue( 1 );
     425           0 :                 aViewLayoutItem.SetBookMode( false );
     426             :             }
     427           0 :             else if ( m_pColumnsBtn->IsChecked() )
     428             :             {
     429           0 :                 aViewLayoutItem.SetValue( static_cast<sal_uInt16>(m_pColumnsEdit->GetValue()) );
     430           0 :                 aViewLayoutItem.SetBookMode( m_pBookModeChk->IsChecked() );
     431             :             }
     432             :         }
     433             :         else
     434             :         {
     435             :             OSL_FAIL( "Wrong Button" );
     436           0 :             return 0;
     437             :         }
     438           0 :         pOutSet = new SfxItemSet( rSet );
     439           0 :         pOutSet->Put( aZoomItem );
     440             : 
     441             :         // don't set attribute in case the whole viewlayout stuff is disabled:
     442           0 :         if (m_pViewFrame->IsEnabled())
     443           0 :             pOutSet->Put(aViewLayoutItem);
     444             : 
     445             :         // memorize value from the UserEdit beyond the dialog
     446           0 :         SfxObjectShell* pSh = SfxObjectShell::Current();
     447             : 
     448           0 :         if ( pSh )
     449             :             pSh->PutItem( SfxUInt16Item( SID_ATTR_ZOOM_USER,
     450           0 :                                          (sal_uInt16)m_pUserEdit->GetValue() ) );
     451           0 :         EndDialog( RET_OK );
     452             :     }
     453             :     else
     454           0 :         EndDialog( RET_CANCEL );
     455           0 :     return 0;
     456           3 : }
     457             : 
     458             : 
     459             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10