xref: /aoo42x/main/svx/source/stbctrls/selctrl.cxx (revision cdf0e10c)
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/intitem.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <tools/urlobj.hxx>
39 
40 #define _SVX_SELCTRL_CXX
41 
42 #include "svx/selctrl.hxx"
43 #include <svx/dialmgr.hxx>
44 
45 #include <svx/dialogs.hrc>
46 
47 #define PAINT_OFFSET	5
48 
49 SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);
50 
51 // class SvxSelectionModeControl -----------------------------------------
52 
53 SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
54 												  sal_uInt16 _nId,
55 												  StatusBar& rStb ) :
56 	SfxStatusBarControl( _nSlotId, _nId, rStb ),
57 	nState( 0 )
58 {
59 }
60 
61 // -----------------------------------------------------------------------
62 
63 void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
64 											const SfxPoolItem* pState )
65 {
66 	if ( SFX_ITEM_AVAILABLE != eState )
67 		GetStatusBar().SetItemText( GetId(), String() );
68 	else
69 	{
70 		DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
71 		SfxUInt16Item* pItem = (SfxUInt16Item*)pState;
72 		nState = pItem->GetValue();
73 		DrawItemText_Impl();
74 	}
75 }
76 
77 // -----------------------------------------------------------------------
78 
79 void SvxSelectionModeControl::Click()
80 {
81 	if ( !GetStatusBar().GetItemText( GetId() ).Len() )
82 		return;
83 	nState++;
84 	if ( nState > 3 )
85 		nState = 0;
86 
87     ::com::sun::star::uno::Any a;
88     SfxUInt16Item aState( GetSlotId(), nState );
89     INetURLObject aObj( m_aCommandURL );
90 
91     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
92     aArgs[0].Name  = aObj.GetURLPath();
93     aState.QueryValue( a );
94     aArgs[0].Value = a;
95 
96     execute( aArgs );
97 }
98 
99 // -----------------------------------------------------------------------
100 
101 void SvxSelectionModeControl::Paint( const UserDrawEvent& )
102 {
103 	DrawItemText_Impl();
104 }
105 
106 // -----------------------------------------------------------------------
107 
108 void SvxSelectionModeControl::DrawItemText_Impl()
109 {
110 	String sTxt;
111 	sal_uInt16 _nId = 0;
112 
113 	switch ( nState )
114 	{
115 		case 0:
116 			_nId = RID_SVXSTR_SELMODE_STD;
117 			break;
118 		case 1:
119 			_nId = RID_SVXSTR_SELMODE_ER;
120 			break;
121 		case 2:
122 			_nId = RID_SVXSTR_SELMODE_ERG;
123 			break;
124 		case 3:
125 			_nId = RID_SVXSTR_SELMODE_BLK;
126 			break;
127 		default: DBG_ERROR( "invalid selection mode!" );
128 	}
129 
130 	if ( _nId )
131 		sTxt = SVX_RESSTR( _nId );
132 	GetStatusBar().SetItemText( GetId(), sTxt );
133 }
134 
135 sal_uIntPtr SvxSelectionModeControl::GetDefItemWidth(const StatusBar& rStb)
136 {
137 	long nWidth1 =  rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_STD));
138 	long nWidth2 =  rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_ER));
139 	long nWidth3 =  rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_ERG));
140 	long nWidth4 =  rStb.GetTextWidth(SVX_RESSTR(RID_SVXSTR_SELMODE_BLK));
141 
142 	if(nWidth1<nWidth2)
143 		nWidth1=nWidth2;
144 
145 	if(nWidth1<nWidth3)
146 		nWidth1=nWidth3;
147 
148     if(nWidth1<nWidth4)
149 		nWidth1=nWidth4;
150 
151 	return nWidth1+PAINT_OFFSET;
152 }
153 
154 
155