merge the formfield patch from ooo-build
[ooovba.git] / svx / source / stbctrls / selctrl.cxx
blobc2f34c9c20bf88a6f915c0037f8c99953156380d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: selctrl.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/shl.hxx>
36 #ifndef _STATUS_HXX //autogen
37 #include <vcl/status.hxx>
38 #endif
39 #include <svtools/intitem.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <tools/urlobj.hxx>
43 #define _SVX_SELCTRL_CXX
45 #include "selctrl.hxx"
46 #include <svx/dialmgr.hxx>
48 #include <svx/dialogs.hrc>
50 #define PAINT_OFFSET 5
52 SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);
54 // class SvxSelectionModeControl -----------------------------------------
56 SvxSelectionModeControl::SvxSelectionModeControl( USHORT _nSlotId,
57 USHORT _nId,
58 StatusBar& rStb ) :
59 SfxStatusBarControl( _nSlotId, _nId, rStb ),
60 nState( 0 )
64 // -----------------------------------------------------------------------
66 void SvxSelectionModeControl::StateChanged( USHORT, SfxItemState eState,
67 const SfxPoolItem* pState )
69 if ( SFX_ITEM_AVAILABLE != eState )
70 GetStatusBar().SetItemText( GetId(), String() );
71 else
73 DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
74 SfxUInt16Item* pItem = (SfxUInt16Item*)pState;
75 nState = pItem->GetValue();
76 DrawItemText_Impl();
80 // -----------------------------------------------------------------------
82 void SvxSelectionModeControl::Click()
84 if ( !GetStatusBar().GetItemText( GetId() ).Len() )
85 return;
86 nState++;
87 if ( nState > 3 )
88 nState = 0;
90 ::com::sun::star::uno::Any a;
91 SfxUInt16Item aState( GetSlotId(), nState );
92 INetURLObject aObj( m_aCommandURL );
94 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
95 aArgs[0].Name = aObj.GetURLPath();
96 aState.QueryValue( a );
97 aArgs[0].Value = a;
99 execute( aArgs );
102 // -----------------------------------------------------------------------
104 void SvxSelectionModeControl::Paint( const UserDrawEvent& )
106 DrawItemText_Impl();
109 // -----------------------------------------------------------------------
111 void SvxSelectionModeControl::DrawItemText_Impl()
113 String sTxt;
114 USHORT _nId = 0;
116 switch ( nState )
118 case 0:
119 _nId = RID_SVXSTR_SELMODE_STD;
120 break;
121 case 1:
122 _nId = RID_SVXSTR_SELMODE_ER;
123 break;
124 case 2:
125 _nId = RID_SVXSTR_SELMODE_ERG;
126 break;
127 case 3:
128 _nId = RID_SVXSTR_SELMODE_BLK;
129 break;
130 default: DBG_ERROR( "invalid selection mode!" );
133 if ( _nId )
134 sTxt = SVX_RESSTR( _nId );
135 GetStatusBar().SetItemText( GetId(), sTxt );
138 ULONG SvxSelectionModeControl::GetDefItemWidth(const StatusBar& rStb)
140 long nWidth1 = rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_STD));
141 long nWidth2 = rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_ER));
142 long nWidth3 = rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_ERG));
143 long nWidth4 = rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_BLK));
145 if(nWidth1<nWidth2)
146 nWidth1=nWidth2;
148 if(nWidth1<nWidth3)
149 nWidth1=nWidth3;
151 if(nWidth1<nWidth4)
152 nWidth1=nWidth4;
154 return nWidth1+PAINT_OFFSET;