xref: /aoo41x/main/basctl/source/basicide/tbxctl.cxx (revision 31598a22)
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_basctl.hxx"
26 
27 
28 #include <ide_pch.hxx>
29 
30 
31 #define _BASIDE_POPUPWINDOWTBX
32 #include <tbxctl.hxx>
33 #include <svx/svxids.hrc>
34 #include <iderid.hxx>
35 #include <tbxctl.hrc>
36 #include <idetemp.hxx>
37 #include <sfx2/imagemgr.hxx>
38 #include <svl/aeitem.hxx>
39 #include <vcl/toolbox.hxx>
40 
41 using namespace ::com::sun::star::uno;
42 
43 
44 static ::rtl::OUString aSubToolBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcontrolsbar" ) );
45 
SFX_IMPL_TOOLBOX_CONTROL(TbxControls,SfxAllEnumItem)46 SFX_IMPL_TOOLBOX_CONTROL( TbxControls, SfxAllEnumItem )
47 
48 /*************************************************************************
49 |*
50 |* WorkWindow Alignment
51 |*
52 \************************************************************************/
53 /*
54 IMPL_LINK( PopupWindowTbx, SelectHdl, void*, EMPTYARG )
55 {
56     if ( IsInPopupMode() )
57 		EndPopupMode();
58 
59 	aSelectLink.Call( &aTbx.GetToolBox() );
60 
61 	return 0;
62 }
63 
64 PopupWindowTbx::PopupWindowTbx( sal_uInt16 nId, WindowAlign eAlign,
65 								ResId aRIdWin, ResId aRIdTbx,
66 								SfxBindings& rBind ) :
67 				SfxPopupWindow	( nId, aRIdWin, rBind ),
68 				aTbx			( this, GetBindings(), aRIdTbx )
69 {
70 	FreeResource();
71 	aTbx.Initialize();
72 
73 	ToolBox& rBox = aTbx.GetToolBox();
74 	rBox.SetAlign( eAlign );
75 	if( eAlign == WINDOWALIGN_LEFT )
76 		SetText( String() );
77 
78 	Size aSize = aTbx.CalcWindowSizePixel();
79 	rBox.SetSizePixel( aSize );
80 	SetOutputSizePixel( aSize );
81 	aSelectLink = rBox.GetSelectHdl();
82 	rBox.SetSelectHdl( LINK( this, PopupWindowTbx, SelectHdl ) );
83 }
84 
85 SfxPopupWindow* PopupWindowTbx::Clone() const
86 {
87 	return new PopupWindowTbx( GetId(), aTbx.GetAlign(),
88 						IDEResId( RID_TBXCONTROLS ),
89 						IDEResId( RID_TOOLBOX ),
90 						(SfxBindings&) GetBindings() );
91 }
92 
93 void PopupWindowTbx::PopupModeEnd()
94 {
95 	aTbx.GetToolBox().EndSelection();
96 	SfxPopupWindow::PopupModeEnd();
97 }
98 
99 void PopupWindowTbx::Update()
100 {
101 	ToolBox *pBox = &aTbx.GetToolBox();
102 	aTbx.Activate( pBox );
103 	aTbx.Deactivate( pBox );
104 }
105 
106 PopupWindowTbx::~PopupWindowTbx()
107 {
108 }
109 */
110 /*************************************************************************
111 |*
112 |* Klasse fuer Toolbox
113 |*
114 \************************************************************************/
115 
116 TbxControls::TbxControls( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
117 		SfxToolBoxControl( nSlotId, nId, rTbx )
118 {
119 	nLastSlot = USHRT_MAX;
120 
121 	rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
122 	rTbx.Invalidate();
123 }
124 
125 /*************************************************************************
126 |*
127 |* Wenn man ein PopupWindow erzeugen will
128 |*
129 \************************************************************************/
GetPopupWindowType() const130 SfxPopupWindowType TbxControls::GetPopupWindowType() const
131 {
132 	if( nLastSlot == USHRT_MAX )
133 		return(SFX_POPUPWINDOW_ONCLICK);
134 	return(SFX_POPUPWINDOW_ONTIMEOUT);
135 }
136 
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)137 void TbxControls::StateChanged( sal_uInt16 nSID, SfxItemState eState,
138   const SfxPoolItem* pState )
139 {
140     if( pState )
141 	{
142 		SfxAllEnumItem* pItem = PTR_CAST(SfxAllEnumItem, pState);
143 		if( pItem )
144 		{
145 			sal_uInt16 nLastEnum = pItem->GetValue();
146 			sal_uInt16 nTemp = 0;
147 			switch( nLastEnum )
148 			{
149 				case SVX_SNAP_PUSHBUTTON:       nTemp = SID_INSERT_PUSHBUTTON; break;
150 				case SVX_SNAP_CHECKBOX:         nTemp = SID_INSERT_CHECKBOX; break;
151 				case SVX_SNAP_RADIOBUTTON:      nTemp = SID_INSERT_RADIOBUTTON; break;
152 				case SVX_SNAP_SPINBUTTON:       nTemp = SID_INSERT_SPINBUTTON; break;
153 				case SVX_SNAP_FIXEDTEXT:        nTemp = SID_INSERT_FIXEDTEXT; break;
154 				case SVX_SNAP_GROUPBOX:         nTemp = SID_INSERT_GROUPBOX; break;
155 				case SVX_SNAP_LISTBOX:          nTemp = SID_INSERT_LISTBOX; break;
156 				case SVX_SNAP_COMBOBOX:         nTemp = SID_INSERT_COMBOBOX; break;
157 				case SVX_SNAP_EDIT:             nTemp = SID_INSERT_EDIT; break;
158 				case SVX_SNAP_HSCROLLBAR:       nTemp = SID_INSERT_HSCROLLBAR; break;
159 				case SVX_SNAP_VSCROLLBAR:       nTemp = SID_INSERT_VSCROLLBAR; break;
160 				case SVX_SNAP_PREVIEW:          nTemp = SID_INSERT_PREVIEW; break;
161 				case SVX_SNAP_URLBUTTON:        nTemp = SID_INSERT_URLBUTTON; break;
162 				case SVX_SNAP_IMAGECONTROL:     nTemp = SID_INSERT_IMAGECONTROL; break;
163 				case SVX_SNAP_PROGRESSBAR:      nTemp = SID_INSERT_PROGRESSBAR; break;
164 				case SVX_SNAP_HFIXEDLINE:       nTemp = SID_INSERT_HFIXEDLINE; break;
165 				case SVX_SNAP_VFIXEDLINE:       nTemp = SID_INSERT_VFIXEDLINE; break;
166 				case SVX_SNAP_DATEFIELD:        nTemp = SID_INSERT_DATEFIELD; break;
167 				case SVX_SNAP_TIMEFIELD:        nTemp = SID_INSERT_TIMEFIELD; break;
168 				case SVX_SNAP_NUMERICFIELD:     nTemp = SID_INSERT_NUMERICFIELD; break;
169 				case SVX_SNAP_CURRENCYFIELD:    nTemp = SID_INSERT_CURRENCYFIELD; break;
170 				case SVX_SNAP_FORMATTEDFIELD:   nTemp = SID_INSERT_FORMATTEDFIELD; break;
171 				case SVX_SNAP_PATTERNFIELD:     nTemp = SID_INSERT_PATTERNFIELD; break;
172 				case SVX_SNAP_FILECONTROL:      nTemp = SID_INSERT_FILECONTROL; break;
173 				case SVX_SNAP_TREECONTROL:      nTemp = SID_INSERT_TREECONTROL; break;
174             }
175 			if( nTemp )
176 			{
177                 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
178                 aSlotURL += rtl::OUString::valueOf( sal_Int32( nTemp ));
179                 Image aImage = GetImage( m_xFrame,
180                                          aSlotURL,
181                                          hasBigImages(),
182                                          GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode() );
183                 ToolBox& rBox = GetToolBox();
184                 rBox.SetItemImage(GetId(), aImage);
185 				nLastSlot = nLastEnum;
186 			}
187 		}
188 	}
189 	SfxToolBoxControl::StateChanged( nSID, eState,pState );
190 }
191 
Select(sal_uInt16 nModifier)192 void TbxControls::Select( sal_uInt16 nModifier )
193 {
194 	(void)nModifier;
195 	SfxAllEnumItem aItem( SID_CHOOSE_CONTROLS, nLastSlot );
196 	SfxViewFrame* pCurFrame = SfxViewFrame::Current();
197 	DBG_ASSERT( pCurFrame != NULL, "No current view frame!" );
198 	SfxDispatcher* pDispatcher = pCurFrame ? pCurFrame->GetDispatcher() : NULL;
199 	if( pDispatcher )
200 	{
201 		pDispatcher->Execute( SID_CHOOSE_CONTROLS, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
202 	}
203 }
204 
205 /*************************************************************************
206 |*
207 |* Hier wird das Fenster erzeugt
208 |* Lage der Toolbox mit GetToolBox() abfragbar
209 |* rItemRect sind die Screen-Koordinaten
210 |*
211 \************************************************************************/
CreatePopupWindow()212 SfxPopupWindow*	TbxControls::CreatePopupWindow()
213 {
214     if ( GetSlotId() == SID_CHOOSE_CONTROLS )
215         createAndPositionSubToolBar( aSubToolBarResName );
216 
217 /*
218     if (GetId() == SID_CHOOSE_CONTROLS)
219 	{
220 		PopupWindowTbx *pWin =
221 			new PopupWindowTbx( GetId(),
222 								GetToolBox().IsHorizontal() ?
223 									WINDOWALIGN_LEFT : WINDOWALIGN_TOP,
224 								IDEResId( RID_TBXCONTROLS ),
225 								IDEResId( RID_TOOLBOX ),
226 								GetBindings() );
227 		pWin->StartPopupMode(&GetToolBox(), sal_True);
228 		pWin->Update();
229 		pWin->StartSelection();
230 		pWin->Show();
231 		return(pWin);
232 	}
233 */
234 	return(0);
235 }
236 
237 
238