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