Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/shl.hxx>
30 : : #include <vcl/status.hxx>
31 : : #include <vcl/menu.hxx>
32 : : #include <sfx2/dispatch.hxx>
33 : : #include <tools/urlobj.hxx>
34 : :
35 : : #include <svx/dialogs.hrc>
36 : :
37 : : #include "svx/zoomctrl.hxx"
38 : : #include <sfx2/zoomitem.hxx>
39 : : #include "stbctrls.h"
40 : : #include <svx/dialmgr.hxx>
41 : :
42 [ + - ]: 465 : SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
43 : :
44 : : // class ZoomPopup_Impl --------------------------------------------------
45 : :
46 [ # # ]: 0 : class ZoomPopup_Impl : public PopupMenu
47 : : {
48 : : public:
49 : : ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet );
50 : :
51 : 0 : sal_uInt16 GetZoom() const { return nZoom; }
52 : 0 : sal_uInt16 GetCurId() const { return nCurId; }
53 : :
54 : : private:
55 : : sal_uInt16 nZoom;
56 : : sal_uInt16 nCurId;
57 : :
58 : : virtual void Select();
59 : : };
60 : :
61 : : // -----------------------------------------------------------------------
62 : :
63 : 0 : ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet )
64 : :
65 : 0 : : PopupMenu( ResId( RID_SVXMNU_ZOOM, DIALOG_MGR() ) ),
66 : :
67 [ # # ]: 0 : nZoom( nZ )
68 : : {
69 : : static sal_uInt16 aTable[] =
70 : : {
71 : : SVX_ZOOM_ENABLE_50, ZOOM_50,
72 : : SVX_ZOOM_ENABLE_100, ZOOM_100,
73 : : SVX_ZOOM_ENABLE_150, ZOOM_150,
74 : : SVX_ZOOM_ENABLE_200, ZOOM_200,
75 : : SVX_ZOOM_ENABLE_OPTIMAL, ZOOM_OPTIMAL,
76 : : SVX_ZOOM_ENABLE_WHOLEPAGE, ZOOM_WHOLE_PAGE,
77 : : SVX_ZOOM_ENABLE_PAGEWIDTH, ZOOM_PAGE_WIDTH
78 : : };
79 : :
80 [ # # ]: 0 : for ( sal_uInt16 nPos = 0; nPos < SAL_N_ELEMENTS(aTable); nPos += 2 )
81 [ # # ]: 0 : if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) )
82 [ # # ]: 0 : EnableItem( aTable[nPos+1], sal_False );
83 : 0 : }
84 : :
85 : : // -----------------------------------------------------------------------
86 : :
87 : 0 : void ZoomPopup_Impl::Select()
88 : : {
89 : 0 : nCurId = GetCurItemId();
90 : :
91 [ # # # # : 0 : switch ( nCurId )
# # # ]
92 : : {
93 : 0 : case ZOOM_200: nZoom = 200; break;
94 : 0 : case ZOOM_150: nZoom = 150; break;
95 : 0 : case ZOOM_100: nZoom = 100; break;
96 : 0 : case ZOOM_75: nZoom = 75; break;
97 : 0 : case ZOOM_50: nZoom = 50; break;
98 : :
99 : : case ZOOM_OPTIMAL:
100 : : case ZOOM_PAGE_WIDTH:
101 : 0 : case ZOOM_WHOLE_PAGE: nZoom = 0; break;
102 : :
103 : : }
104 : 0 : }
105 : :
106 : : // class SvxZoomStatusBarControl ------------------------------------------
107 : :
108 : 1143 : SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
109 : : sal_uInt16 _nId,
110 : : StatusBar& rStb ) :
111 : :
112 : : SfxStatusBarControl( _nSlotId, _nId, rStb ),
113 : : nZoom( 100 ),
114 : 1143 : nValueSet( SVX_ZOOM_ENABLE_ALL )
115 : : {
116 : 1143 : }
117 : :
118 : : // -----------------------------------------------------------------------
119 : :
120 : 1829 : void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
121 : : const SfxPoolItem* pState )
122 : : {
123 [ - + ]: 1829 : if( SFX_ITEM_AVAILABLE != eState )
124 : : {
125 [ # # ]: 0 : GetStatusBar().SetItemText( GetId(), String() );
126 : 0 : nValueSet = 0;
127 : : }
128 [ + - ]: 1829 : else if ( pState->ISA( SfxUInt16Item) )
129 : : {
130 : 1829 : const SfxUInt16Item* pItem = (const SfxUInt16Item*)pState;
131 : 1829 : nZoom = pItem->GetValue();
132 [ + - ]: 1829 : String aStr( String::CreateFromInt32(nZoom) );
133 [ + - ]: 1829 : aStr += '%';
134 [ + - ]: 1829 : GetStatusBar().SetItemText( GetId(), aStr );
135 : :
136 [ + - ][ + - ]: 1829 : if ( pState->ISA(SvxZoomItem) )
[ + - ]
137 : : {
138 : 1829 : nValueSet = ((const SvxZoomItem*)pState)->GetValueSet();
139 : : }
140 : : else
141 : : {
142 : : DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
143 : 0 : nValueSet = SVX_ZOOM_ENABLE_ALL;
144 [ + - ]: 1829 : }
145 : : }
146 : 1829 : }
147 : :
148 : : // -----------------------------------------------------------------------
149 : :
150 : 0 : void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
151 : : {
152 [ # # ]: 0 : String aStr( String::CreateFromInt32( nZoom ));
153 [ # # ]: 0 : aStr += '%';
154 [ # # ][ # # ]: 0 : GetStatusBar().SetItemText( GetId(), aStr );
155 : 0 : }
156 : :
157 : : // -----------------------------------------------------------------------
158 : :
159 : 0 : void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
160 : : {
161 [ # # ][ # # ]: 0 : if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet )
[ # # ]
162 : : {
163 [ # # ]: 0 : CaptureMouse();
164 [ # # ]: 0 : ZoomPopup_Impl aPop( nZoom, nValueSet );
165 : 0 : StatusBar& rStatusbar = GetStatusBar();
166 : :
167 [ # # ][ # # ]: 0 : if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
[ # # ][ # # ]
[ # # ]
168 : : {
169 : 0 : nZoom = aPop.GetZoom();
170 [ # # ]: 0 : SvxZoomItem aZoom( SVX_ZOOM_PERCENT, nZoom, GetId() );
171 : :
172 [ # # # # ]: 0 : switch( aPop.GetCurId() )
173 : : {
174 : 0 : case ZOOM_OPTIMAL: aZoom.SetType( SVX_ZOOM_OPTIMAL ); break;
175 : 0 : case ZOOM_PAGE_WIDTH: aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break;
176 : 0 : case ZOOM_WHOLE_PAGE: aZoom.SetType( SVX_ZOOM_WHOLEPAGE ); break;
177 : : }
178 : :
179 : 0 : ::com::sun::star::uno::Any a;
180 [ # # ]: 0 : INetURLObject aObj( m_aCommandURL );
181 : :
182 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
183 [ # # ][ # # ]: 0 : aArgs[0].Name = aObj.GetURLPath();
184 [ # # ]: 0 : aZoom.QueryValue( a );
185 [ # # ]: 0 : aArgs[0].Value = a;
186 : :
187 [ # # ][ # # ]: 0 : execute( aArgs );
[ # # ][ # # ]
188 : : }
189 [ # # ][ # # ]: 0 : ReleaseMouse();
190 : : }
191 : : else
192 : 0 : SfxStatusBarControl::Command( rCEvt );
193 : 0 : }
194 : :
195 : :
196 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|