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