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

Generated by: LCOV version 1.10