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