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 31 // include --------------------------------------------------------------- 32 #include <tools/shl.hxx> 33 #ifndef _STATUS_HXX //autogen 34 #include <vcl/status.hxx> 35 #endif 36 #include <svl/eitem.hxx> 37 #include <sfx2/app.hxx> 38 #include <sfx2/dispatch.hxx> 39 40 #define _SVX_INSCTRL_CXX 41 42 #include <svx/dialogs.hrc> 43 44 #include "svx/insctrl.hxx" 45 #include <svx/dialmgr.hxx> 46 47 #define PAINT_OFFSET 5 48 49 SFX_IMPL_STATUSBAR_CONTROL(SvxInsertStatusBarControl, SfxBoolItem); 50 51 // class SvxInsertStatusBarControl --------------------------------------- 52 53 SvxInsertStatusBarControl::SvxInsertStatusBarControl( sal_uInt16 _nSlotId, 54 sal_uInt16 _nId, 55 StatusBar& rStb ) : 56 57 SfxStatusBarControl( _nSlotId, _nId, rStb ), 58 bInsert( sal_True ) 59 { 60 } 61 62 // ----------------------------------------------------------------------- 63 64 SvxInsertStatusBarControl::~SvxInsertStatusBarControl() 65 { 66 } 67 68 // ----------------------------------------------------------------------- 69 70 void SvxInsertStatusBarControl::StateChanged( sal_uInt16 , SfxItemState eState, 71 const SfxPoolItem* pState ) 72 { 73 if ( SFX_ITEM_AVAILABLE != eState ) 74 GetStatusBar().SetItemText( GetId(), String() ); 75 else 76 { 77 DBG_ASSERT( pState->ISA( SfxBoolItem ), "invalid item type" ); 78 SfxBoolItem* pItem = (SfxBoolItem*)pState; 79 bInsert = pItem->GetValue(); 80 DrawItemText_Impl(); 81 } 82 } 83 84 // ----------------------------------------------------------------------- 85 86 void SvxInsertStatusBarControl::Click() 87 { 88 if ( !GetStatusBar().GetItemText( GetId() ).Len() ) 89 return; 90 bInsert = !bInsert; 91 SfxBoolItem aIns( GetSlotId(), bInsert ); 92 93 ::com::sun::star::uno::Any a; 94 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 95 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InsertMode" )); 96 aIns.QueryValue( a ); 97 aArgs[0].Value = a; 98 99 execute( aArgs ); 100 } 101 102 // ----------------------------------------------------------------------- 103 104 void SvxInsertStatusBarControl::Paint( const UserDrawEvent& ) 105 { 106 DrawItemText_Impl(); 107 } 108 109 // ----------------------------------------------------------------------- 110 111 void SvxInsertStatusBarControl::DrawItemText_Impl() 112 { 113 sal_uInt16 _nId = RID_SVXSTR_OVERWRITE_TEXT; 114 115 if ( bInsert ) 116 _nId = RID_SVXSTR_INSERT_TEXT; 117 GetStatusBar().SetItemText( GetId(), SVX_RESSTR( _nId ) ); 118 } 119 120 sal_uIntPtr SvxInsertStatusBarControl::GetDefItemWidth(const StatusBar& rStb) 121 { 122 long nWidth1 = rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_OVERWRITE_TEXT)); 123 long nWidth2 = rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_INSERT_TEXT)); 124 125 if(nWidth1<nWidth2) 126 nWidth1=nWidth2; 127 128 return nWidth1+PAINT_OFFSET; 129 } 130 131 132