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