xref: /trunk/main/svx/source/stbctrls/zoomctrl.cxx (revision 07662b26dffe2c9fb8fe61592c6a0f86f1b6e728)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <tools/shl.hxx>
27cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen
28cdf0e10cSrcweir #include <vcl/status.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _MENU_HXX //autogen
31cdf0e10cSrcweir #include <vcl/menu.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
34cdf0e10cSrcweir #include <tools/urlobj.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <svx/dialogs.hrc>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "svx/zoomctrl.hxx"
39cdf0e10cSrcweir //CHINA001 #include "zoom.hxx"
40cdf0e10cSrcweir #include <svx/zoomitem.hxx>
41cdf0e10cSrcweir #include "stbctrls.h"
42cdf0e10cSrcweir #include <svx/dialmgr.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // class ZoomPopup_Impl --------------------------------------------------
47cdf0e10cSrcweir 
48cdf0e10cSrcweir class ZoomPopup_Impl : public PopupMenu
49cdf0e10cSrcweir {
50cdf0e10cSrcweir public:
51cdf0e10cSrcweir     ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet );
52cdf0e10cSrcweir 
GetZoom() const53cdf0e10cSrcweir     sal_uInt16          GetZoom() const { return nZoom; }
GetCurId() const54cdf0e10cSrcweir     sal_uInt16          GetCurId() const { return nCurId; }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir private:
57cdf0e10cSrcweir     sal_uInt16          nZoom;
58cdf0e10cSrcweir     sal_uInt16          nCurId;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     virtual void    Select();
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // -----------------------------------------------------------------------
64cdf0e10cSrcweir 
ZoomPopup_Impl(sal_uInt16 nZ,sal_uInt16 nValueSet)65cdf0e10cSrcweir ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet )
66cdf0e10cSrcweir 
67cdf0e10cSrcweir :   PopupMenu( ResId( RID_SVXMNU_ZOOM, DIALOG_MGR() ) ),
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     nZoom( nZ )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     static sal_uInt16 aTable[] =
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         SVX_ZOOM_ENABLE_50,         ZOOM_50,
74cdf0e10cSrcweir         SVX_ZOOM_ENABLE_100,        ZOOM_100,
75cdf0e10cSrcweir         SVX_ZOOM_ENABLE_150,        ZOOM_150,
76cdf0e10cSrcweir         SVX_ZOOM_ENABLE_200,        ZOOM_200,
77cdf0e10cSrcweir         SVX_ZOOM_ENABLE_OPTIMAL,    ZOOM_OPTIMAL,
78cdf0e10cSrcweir         SVX_ZOOM_ENABLE_WHOLEPAGE,  ZOOM_WHOLE_PAGE,
79cdf0e10cSrcweir         SVX_ZOOM_ENABLE_PAGEWIDTH,  ZOOM_PAGE_WIDTH
80cdf0e10cSrcweir     };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     for ( sal_uInt16 nPos = 0; nPos < sizeof(aTable) / sizeof(sal_uInt16); nPos += 2 )
83cdf0e10cSrcweir         if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) )
84cdf0e10cSrcweir             EnableItem( aTable[nPos+1], sal_False );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir // -----------------------------------------------------------------------
88cdf0e10cSrcweir 
Select()89cdf0e10cSrcweir void ZoomPopup_Impl::Select()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     nCurId = GetCurItemId();
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     switch ( nCurId )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         case ZOOM_200:          nZoom = 200; break;
96cdf0e10cSrcweir         case ZOOM_150:          nZoom = 150; break;
97cdf0e10cSrcweir         case ZOOM_100:          nZoom = 100; break;
98cdf0e10cSrcweir         case ZOOM_75:           nZoom =  75; break;
99cdf0e10cSrcweir         case ZOOM_50:           nZoom =  50; break;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         case ZOOM_OPTIMAL:
102cdf0e10cSrcweir         case ZOOM_PAGE_WIDTH:
103cdf0e10cSrcweir         case ZOOM_WHOLE_PAGE:   nZoom = 0; break;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // class SvxZoomStatusBarControl ------------------------------------------
109cdf0e10cSrcweir 
SvxZoomStatusBarControl(sal_uInt16 _nSlotId,sal_uInt16 _nId,StatusBar & rStb)110cdf0e10cSrcweir SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
111cdf0e10cSrcweir                                                   sal_uInt16 _nId,
112cdf0e10cSrcweir                                                   StatusBar& rStb ) :
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     SfxStatusBarControl( _nSlotId, _nId, rStb ),
115cdf0e10cSrcweir     nZoom( 100 ),
116cdf0e10cSrcweir     nValueSet( SVX_ZOOM_ENABLE_ALL )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -----------------------------------------------------------------------
121cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)122cdf0e10cSrcweir void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
123cdf0e10cSrcweir                                             const SfxPoolItem* pState )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     if( SFX_ITEM_AVAILABLE != eState )
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         GetStatusBar().SetItemText( GetId(), String() );
128cdf0e10cSrcweir         nValueSet = 0;
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir     else if ( pState->ISA( SfxUInt16Item) )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         const SfxUInt16Item* pItem = (const SfxUInt16Item*)pState;
133cdf0e10cSrcweir         nZoom = pItem->GetValue();
134cdf0e10cSrcweir         String aStr( String::CreateFromInt32(nZoom) );
1352e94ffdeSTsutomu Uchino         aStr.AppendAscii( " %" );
136cdf0e10cSrcweir         GetStatusBar().SetItemText( GetId(), aStr );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         if ( pState->ISA(SvxZoomItem) )
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir             nValueSet = ((const SvxZoomItem*)pState)->GetValueSet();
141cdf0e10cSrcweir /*!!!
142cdf0e10cSrcweir             SvxZoomType eType = ((const SvxZoomItem*)pState)->GetType();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir             switch ( eType )
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 case SVX_ZOOM_OPTIMAL:
147cdf0e10cSrcweir                     GetStatusBar().SetItemText( GetId(), "Opt." );
148cdf0e10cSrcweir                     break;
149cdf0e10cSrcweir                 case SVX_ZOOM_WHOLEPAGE:
150cdf0e10cSrcweir                     GetStatusBar().SetItemText( GetId(), "Page" );
151cdf0e10cSrcweir                     break;
152cdf0e10cSrcweir                 case SVX_ZOOM_PAGEWIDTH:
153cdf0e10cSrcweir                     GetStatusBar().SetItemText( GetId(), "Width" );
154cdf0e10cSrcweir                     break;
155cdf0e10cSrcweir             }
156cdf0e10cSrcweir */
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir         else
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
161cdf0e10cSrcweir             nValueSet = SVX_ZOOM_ENABLE_ALL;
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir // -----------------------------------------------------------------------
167cdf0e10cSrcweir 
Paint(const UserDrawEvent &)168cdf0e10cSrcweir void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     String aStr( String::CreateFromInt32( nZoom ));
1712e94ffdeSTsutomu Uchino     aStr.AppendAscii( " %" );
172cdf0e10cSrcweir     GetStatusBar().SetItemText( GetId(), aStr );
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // -----------------------------------------------------------------------
176cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)177cdf0e10cSrcweir void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet )
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         CaptureMouse();
182cdf0e10cSrcweir         ZoomPopup_Impl aPop( nZoom, nValueSet );
183cdf0e10cSrcweir         StatusBar& rStatusbar = GetStatusBar();
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir             nZoom = aPop.GetZoom();
188cdf0e10cSrcweir             SvxZoomItem aZoom( SVX_ZOOM_PERCENT, nZoom, GetId() );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             switch( aPop.GetCurId() )
191cdf0e10cSrcweir             {
192cdf0e10cSrcweir             case ZOOM_OPTIMAL:      aZoom.SetType( SVX_ZOOM_OPTIMAL ); break;
193cdf0e10cSrcweir             case ZOOM_PAGE_WIDTH:   aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break;
194cdf0e10cSrcweir             case ZOOM_WHOLE_PAGE:   aZoom.SetType( SVX_ZOOM_WHOLEPAGE ); break;
195cdf0e10cSrcweir             }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir             ::com::sun::star::uno::Any a;
198cdf0e10cSrcweir             INetURLObject aObj( m_aCommandURL );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
201cdf0e10cSrcweir             aArgs[0].Name = aObj.GetURLPath();
202cdf0e10cSrcweir             aZoom.QueryValue( a );
203cdf0e10cSrcweir             aArgs[0].Value = a;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir             execute( aArgs );
206cdf0e10cSrcweir         }
207cdf0e10cSrcweir         ReleaseMouse();
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir     else
210cdf0e10cSrcweir         SfxStatusBarControl::Command( rCEvt );
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
GetDefItemWidth(const StatusBar & rStb)213cdf0e10cSrcweir sal_uIntPtr SvxZoomStatusBarControl::GetDefItemWidth(const StatusBar& rStb)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir     long nWidth1 = rStb.GetTextWidth(String::CreateFromAscii("XXXXX %"));
216cdf0e10cSrcweir     return nWidth1;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219*07662b26Smseidel /* vim: set noet sw=4 ts=4: */
220