1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: zoomctrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <tools/shl.hxx>
34 #ifndef _STATUS_HXX //autogen
35 #include <vcl/status.hxx>
37 #ifndef _MENU_HXX //autogen
38 #include <vcl/menu.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <tools/urlobj.hxx>
43 #include <svx/dialogs.hrc>
45 #include "zoomctrl.hxx"
46 //CHINA001 #include "zoom.hxx"
47 #include <svx/zoomitem.hxx>
49 #include <svx/dialmgr.hxx>
51 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl
,SvxZoomItem
);
53 // class ZoomPopup_Impl --------------------------------------------------
55 class ZoomPopup_Impl
: public PopupMenu
58 ZoomPopup_Impl( USHORT nZ
, USHORT nValueSet
);
60 USHORT
GetZoom() const { return nZoom
; }
61 USHORT
GetCurId() const { return nCurId
; }
67 virtual void Select();
70 // -----------------------------------------------------------------------
72 ZoomPopup_Impl::ZoomPopup_Impl( USHORT nZ
, USHORT nValueSet
)
74 : PopupMenu( ResId( RID_SVXMNU_ZOOM
, DIALOG_MGR() ) ),
78 static USHORT aTable
[] =
80 SVX_ZOOM_ENABLE_50
, ZOOM_50
,
81 SVX_ZOOM_ENABLE_100
, ZOOM_100
,
82 SVX_ZOOM_ENABLE_150
, ZOOM_150
,
83 SVX_ZOOM_ENABLE_200
, ZOOM_200
,
84 SVX_ZOOM_ENABLE_OPTIMAL
, ZOOM_OPTIMAL
,
85 SVX_ZOOM_ENABLE_WHOLEPAGE
, ZOOM_WHOLE_PAGE
,
86 SVX_ZOOM_ENABLE_PAGEWIDTH
, ZOOM_PAGE_WIDTH
89 for ( USHORT nPos
= 0; nPos
< sizeof(aTable
) / sizeof(USHORT
); nPos
+= 2 )
90 if ( ( aTable
[nPos
] != ( aTable
[nPos
] & nValueSet
) ) )
91 EnableItem( aTable
[nPos
+1], FALSE
);
94 // -----------------------------------------------------------------------
96 void ZoomPopup_Impl::Select()
98 nCurId
= GetCurItemId();
102 case ZOOM_200
: nZoom
= 200; break;
103 case ZOOM_150
: nZoom
= 150; break;
104 case ZOOM_100
: nZoom
= 100; break;
105 case ZOOM_75
: nZoom
= 75; break;
106 case ZOOM_50
: nZoom
= 50; break;
109 case ZOOM_PAGE_WIDTH
:
110 case ZOOM_WHOLE_PAGE
: nZoom
= 0; break;
115 // class SvxZoomStatusBarControl ------------------------------------------
117 SvxZoomStatusBarControl::SvxZoomStatusBarControl( USHORT _nSlotId
,
121 SfxStatusBarControl( _nSlotId
, _nId
, rStb
),
123 nValueSet( SVX_ZOOM_ENABLE_ALL
)
127 // -----------------------------------------------------------------------
129 void SvxZoomStatusBarControl::StateChanged( USHORT
, SfxItemState eState
,
130 const SfxPoolItem
* pState
)
132 if( SFX_ITEM_AVAILABLE
!= eState
)
134 GetStatusBar().SetItemText( GetId(), String() );
137 else if ( pState
->ISA( SfxUInt16Item
) )
139 const SfxUInt16Item
* pItem
= (const SfxUInt16Item
*)pState
;
140 nZoom
= pItem
->GetValue();
141 String
aStr( String::CreateFromInt32(nZoom
) );
143 GetStatusBar().SetItemText( GetId(), aStr
);
145 if ( pState
->ISA(SvxZoomItem
) )
147 nValueSet
= ((const SvxZoomItem
*)pState
)->GetValueSet();
149 SvxZoomType eType = ((const SvxZoomItem*)pState)->GetType();
153 case SVX_ZOOM_OPTIMAL:
154 GetStatusBar().SetItemText( GetId(), "Opt." );
156 case SVX_ZOOM_WHOLEPAGE:
157 GetStatusBar().SetItemText( GetId(), "Page" );
159 case SVX_ZOOM_PAGEWIDTH:
160 GetStatusBar().SetItemText( GetId(), "Width" );
167 DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
168 nValueSet
= SVX_ZOOM_ENABLE_ALL
;
173 // -----------------------------------------------------------------------
175 void SvxZoomStatusBarControl::Paint( const UserDrawEvent
& )
177 String
aStr( String::CreateFromInt32( nZoom
));
179 GetStatusBar().SetItemText( GetId(), aStr
);
182 // -----------------------------------------------------------------------
184 void SvxZoomStatusBarControl::Command( const CommandEvent
& rCEvt
)
186 if ( COMMAND_CONTEXTMENU
& rCEvt
.GetCommand() && 0 != nValueSet
)
189 ZoomPopup_Impl
aPop( nZoom
, nValueSet
);
190 StatusBar
& rStatusbar
= GetStatusBar();
192 if ( aPop
.Execute( &rStatusbar
, rCEvt
.GetMousePosPixel() ) && ( nZoom
!= aPop
.GetZoom() || !nZoom
) )
194 nZoom
= aPop
.GetZoom();
195 SvxZoomItem
aZoom( SVX_ZOOM_PERCENT
, nZoom
, GetId() );
197 switch( aPop
.GetCurId() )
199 case ZOOM_OPTIMAL
: aZoom
.SetType( SVX_ZOOM_OPTIMAL
); break;
200 case ZOOM_PAGE_WIDTH
: aZoom
.SetType( SVX_ZOOM_PAGEWIDTH
); break;
201 case ZOOM_WHOLE_PAGE
: aZoom
.SetType( SVX_ZOOM_WHOLEPAGE
); break;
204 ::com::sun::star::uno::Any a
;
205 INetURLObject
aObj( m_aCommandURL
);
207 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs( 1 );
208 aArgs
[0].Name
= aObj
.GetURLPath();
209 aZoom
.QueryValue( a
);
217 SfxStatusBarControl::Command( rCEvt
);
220 ULONG
SvxZoomStatusBarControl::GetDefItemWidth(const StatusBar
& rStb
)
222 long nWidth1
= rStb
.GetTextWidth(String::CreateFromAscii("XXXXX%"));