1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sw.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // include --------------------------------------------------------------- 32*cdf0e10cSrcweir #include <viewlayoutctrl.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen 35*cdf0e10cSrcweir #include <vcl/status.hxx> 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #include <vcl/image.hxx> 38*cdf0e10cSrcweir #include <svl/eitem.hxx> 39*cdf0e10cSrcweir #include <svx/viewlayoutitem.hxx> 40*cdf0e10cSrcweir #ifndef _UTLUI_HRC 41*cdf0e10cSrcweir #include <utlui.hrc> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <swtypes.hxx> // fuer Pathfinder 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // STATIC DATA ----------------------------------------------------------- 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( SwViewLayoutControl, SvxViewLayoutItem ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir // ----------------------------------------------------------------------- 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir const long nImageWidthSingle = 15; 52*cdf0e10cSrcweir const long nImageWidthAuto = 25; 53*cdf0e10cSrcweir const long nImageWidthBook = 23; 54*cdf0e10cSrcweir const long nImageWidthSum = 63; 55*cdf0e10cSrcweir const long nImageHeight = 11; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // ----------------------------------------------------------------------- 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir struct SwViewLayoutControl::SwViewLayoutControl_Impl 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir sal_uInt16 mnState; // 0 = single, 1 = auto, 2 = book, 3 = none 62*cdf0e10cSrcweir Image maImageSingleColumn; 63*cdf0e10cSrcweir Image maImageSingleColumn_Active; 64*cdf0e10cSrcweir Image maImageAutomatic; 65*cdf0e10cSrcweir Image maImageAutomatic_Active; 66*cdf0e10cSrcweir Image maImageBookMode; 67*cdf0e10cSrcweir Image maImageBookMode_Active; 68*cdf0e10cSrcweir }; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // class SwViewLayoutControl ------------------------------------------ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) : 73*cdf0e10cSrcweir SfxStatusBarControl( _nSlotId, _nId, rStb ), 74*cdf0e10cSrcweir mpImpl( new SwViewLayoutControl_Impl ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir mpImpl->mnState = 0; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir const sal_Bool bHC = GetStatusBar().GetSettings().GetStyleSettings().GetHighContrastMode(); 79*cdf0e10cSrcweir mpImpl->maImageSingleColumn = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_HC) : SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN) ); 80*cdf0e10cSrcweir mpImpl->maImageSingleColumn_Active = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_SINGLECOLUMN_ACTIVE) ); 81*cdf0e10cSrcweir mpImpl->maImageAutomatic = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_HC) : SW_RES(IMG_VIEWLAYOUT_AUTOMATIC) ); 82*cdf0e10cSrcweir mpImpl->maImageAutomatic_Active = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_AUTOMATIC_ACTIVE) ); 83*cdf0e10cSrcweir mpImpl->maImageBookMode = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_BOOKMODE_HC) : SW_RES(IMG_VIEWLAYOUT_BOOKMODE) ); 84*cdf0e10cSrcweir mpImpl->maImageBookMode_Active = Image( bHC ? SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE_HC) : SW_RES(IMG_VIEWLAYOUT_BOOKMODE_ACTIVE) ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // ----------------------------------------------------------------------- 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir SwViewLayoutControl::~SwViewLayoutControl() 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir delete mpImpl; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // ----------------------------------------------------------------------- 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void SwViewLayoutControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) ) 99*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() ); 100*cdf0e10cSrcweir else 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir DBG_ASSERT( pState->ISA( SvxViewLayoutItem ), "invalid item type" ); 103*cdf0e10cSrcweir const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue(); 104*cdf0e10cSrcweir const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode(); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // SingleColumn Mode 107*cdf0e10cSrcweir if ( 1 == nColumns ) 108*cdf0e10cSrcweir mpImpl->mnState = 0; 109*cdf0e10cSrcweir // Automatic Mode 110*cdf0e10cSrcweir else if ( 0 == nColumns ) 111*cdf0e10cSrcweir mpImpl->mnState = 1; 112*cdf0e10cSrcweir // Book Mode 113*cdf0e10cSrcweir else if ( bBookMode && 2 == nColumns ) 114*cdf0e10cSrcweir mpImpl->mnState = 2; 115*cdf0e10cSrcweir else 116*cdf0e10cSrcweir mpImpl->mnState = 3; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if ( GetStatusBar().AreItemsVisible() ) 120*cdf0e10cSrcweir GetStatusBar().SetItemData( GetId(), 0 ); // force repaint 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // ----------------------------------------------------------------------- 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir void SwViewLayoutControl::Paint( const UserDrawEvent& rUsrEvt ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir OutputDevice* pDev = rUsrEvt.GetDevice(); 128*cdf0e10cSrcweir Rectangle aRect = rUsrEvt.GetRect(); 129*cdf0e10cSrcweir Color aOldLineColor = pDev->GetLineColor(); 130*cdf0e10cSrcweir Color aOldFillColor = pDev->GetFillColor(); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir //pDev->SetLineColor(); 133*cdf0e10cSrcweir //pDev->SetFillColor( pDev->GetBackground().GetColor() ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir const bool bSingleColumn = 0 == mpImpl->mnState; 136*cdf0e10cSrcweir const bool bAutomatic = 1 == mpImpl->mnState; 137*cdf0e10cSrcweir const bool bBookMode = 2 == mpImpl->mnState; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2; 140*cdf0e10cSrcweir const long nYOffset = (aRect.GetHeight() - nImageHeight)/2; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir aRect.Left() = aRect.Left() + nXOffset; 143*cdf0e10cSrcweir aRect.Top() = aRect.Top() + nYOffset; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // draw single column image: 146*cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir // draw automatic image: 149*cdf0e10cSrcweir aRect.Left() += nImageWidthSingle; 150*cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // draw bookmode image: 153*cdf0e10cSrcweir aRect.Left() += nImageWidthAuto; 154*cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // draw separators 157*cdf0e10cSrcweir //aRect = rUsrEvt.GetRect(); 158*cdf0e10cSrcweir //aRect.Left() += nImageWidth; 159*cdf0e10cSrcweir //aRect.setWidth( 1 ); 160*cdf0e10cSrcweir //pDev->DrawRect( aRect ); 161*cdf0e10cSrcweir //aRect.Left() += nImageWidth; 162*cdf0e10cSrcweir //pDev->DrawRect( aRect ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //pDev->SetLineColor( aOldLineColor ); 165*cdf0e10cSrcweir //pDev->SetFillColor( aOldFillColor ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir sal_Bool SwViewLayoutControl::MouseButtonDown( const MouseEvent & rEvt ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir const Rectangle aRect = getControlRect(); 171*cdf0e10cSrcweir const Point aPoint = rEvt.GetPosPixel(); 172*cdf0e10cSrcweir const long nXDiff = aPoint.X() - aRect.Left(); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir sal_uInt16 nColumns = 1; 175*cdf0e10cSrcweir bool bBookMode = false; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir const long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir if ( nXDiff < nXOffset + nImageWidthSingle ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir mpImpl->mnState = 0; // single 182*cdf0e10cSrcweir nColumns = 1; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir mpImpl->mnState = 1; // auto 187*cdf0e10cSrcweir nColumns = 0; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir else 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir mpImpl->mnState = 2; // book 192*cdf0e10cSrcweir nColumns = 2; 193*cdf0e10cSrcweir bBookMode = true; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // commit state change 197*cdf0e10cSrcweir SvxViewLayoutItem aViewLayout( nColumns, bBookMode ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir ::com::sun::star::uno::Any a; 200*cdf0e10cSrcweir aViewLayout.QueryValue( a ); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 203*cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ViewLayout" )); 204*cdf0e10cSrcweir aArgs[0].Value = a; 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir execute( aArgs ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir return sal_True; 209*cdf0e10cSrcweir } 210