bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / form / tbxform.cxx
blob8819e80677811d76254e6f28d79d538619620f5d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <string>
21 #include <tools/shl.hxx>
22 #include <svl/intitem.hxx>
23 #include <svl/eitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/fixed.hxx>
28 #include "fmitems.hxx"
29 #include "formtoolbars.hxx"
32 #include <svx/dialmgr.hxx>
33 #include <svx/dialogs.hrc>
34 #include "svx/tbxctl.hxx"
35 #include "svx/tbxdraw.hxx"
36 #include "tbxform.hxx"
37 #include "svx/fmresids.hrc"
38 #include "fmhelp.hrc"
39 #include <sfx2/viewfrm.hxx>
40 #include <sfx2/viewsh.hxx>
41 #include <sfx2/imagemgr.hxx>
42 #include <com/sun/star/beans/XPropertySet.hpp>
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::frame;
47 using ::com::sun::star::beans::XPropertySet;
50 //========================================================================
51 // class SvxFmAbsRecWin
52 //========================================================================
54 // -----------------------------------------------------------------------
55 SvxFmAbsRecWin::SvxFmAbsRecWin( Window* _pParent, SfxToolBoxControl* _pController )
56 :NumericField( _pParent, WB_BORDER )
57 ,m_pController(_pController)
59 SetMin(1);
60 SetFirst(1);
61 SetSpinSize(1);
62 SetSizePixel( Size(70,19) );
64 SetDecimalDigits(0);
65 SetStrictFormat(sal_True);
68 // -----------------------------------------------------------------------
69 SvxFmAbsRecWin::~SvxFmAbsRecWin()
73 // -----------------------------------------------------------------------
74 void SvxFmAbsRecWin::FirePosition( sal_Bool _bForce )
76 if ( _bForce || ( GetText() != GetSavedValue() ) )
78 sal_Int64 nRecord = GetValue();
79 if (nRecord < GetMin() || nRecord > GetMax())
81 return;
84 SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<sal_Int32>(nRecord) );
86 Any a;
87 Sequence< PropertyValue > aArgs( 1 );
88 aArgs[0].Name = OUString( "Position" );
89 aPositionParam.QueryValue( a );
90 aArgs[0].Value = a;
91 m_pController->Dispatch( OUString( ".uno:AbsoluteRecord" ),
92 aArgs );
93 m_pController->updateStatus();
95 SaveValue();
99 // -----------------------------------------------------------------------
100 void SvxFmAbsRecWin::LoseFocus()
102 FirePosition( sal_False );
105 // -----------------------------------------------------------------------
106 void SvxFmAbsRecWin::KeyInput( const KeyEvent& rKeyEvent )
108 if( rKeyEvent.GetKeyCode() == KEY_RETURN && !GetText().isEmpty() )
109 FirePosition( sal_True );
110 else
111 NumericField::KeyInput( rKeyEvent );
114 //========================================================================
115 // class SvxFmTbxCtlConfig
116 //========================================================================
118 struct MapSlotToCmd
120 sal_uInt16 nSlotId;
121 const char* pCommand;
124 static MapSlotToCmd SlotToCommands[] =
126 { SID_FM_PUSHBUTTON, ".uno:Pushbutton" },
127 { SID_FM_RADIOBUTTON, ".uno:RadioButton" },
128 { SID_FM_CHECKBOX, ".uno:CheckBox" },
129 { SID_FM_FIXEDTEXT, ".uno:Label" },
130 { SID_FM_GROUPBOX, ".uno:GroupBox" },
131 { SID_FM_LISTBOX, ".uno:ListBox" },
132 { SID_FM_COMBOBOX, ".uno:ComboBox" },
133 { SID_FM_EDIT, ".uno:Edit" },
134 { SID_FM_DBGRID, ".uno:Grid" },
135 { SID_FM_IMAGEBUTTON, ".uno:Imagebutton" },
136 { SID_FM_IMAGECONTROL, ".uno:ImageControl" },
137 { SID_FM_FILECONTROL, ".uno:FileControl" },
138 { SID_FM_DATEFIELD, ".uno:DateField" },
139 { SID_FM_TIMEFIELD, ".uno:TimeField" },
140 { SID_FM_NUMERICFIELD, ".uno:NumericField" },
141 { SID_FM_CURRENCYFIELD, ".uno:CurrencyField" },
142 { SID_FM_PATTERNFIELD, ".uno:PatternField" },
143 { SID_FM_DESIGN_MODE, ".uno:SwitchControlDesignMode" },
144 { SID_FM_FORMATTEDFIELD, ".uno:FormattedField" },
145 { SID_FM_SCROLLBAR, ".uno:ScrollBar" },
146 { SID_FM_SPINBUTTON, ".uno:SpinButton" },
147 { 0, "" }
150 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlConfig, SfxUInt16Item );
152 //-----------------------------------------------------------------------
153 SvxFmTbxCtlConfig::SvxFmTbxCtlConfig( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
154 : SfxToolBoxControl( nSlotId, nId, rTbx )
155 ,nLastSlot( 0 )
157 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
160 //-----------------------------------------------------------------------
161 void SvxFmTbxCtlConfig::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
163 if (nSID == SID_FM_CONFIG)
165 sal_uInt16 nSlot = 0;
166 if (eState >= SFX_ITEM_AVAILABLE)
167 nSlot = ((SfxUInt16Item*)pState)->GetValue();
169 switch( nSlot )
171 case SID_FM_PUSHBUTTON:
172 case SID_FM_RADIOBUTTON:
173 case SID_FM_CHECKBOX:
174 case SID_FM_FIXEDTEXT:
175 case SID_FM_GROUPBOX:
176 case SID_FM_LISTBOX:
177 case SID_FM_COMBOBOX:
178 case SID_FM_NAVIGATIONBAR:
179 case SID_FM_EDIT:
180 case SID_FM_DBGRID:
181 case SID_FM_IMAGEBUTTON:
182 case SID_FM_IMAGECONTROL:
183 case SID_FM_FILECONTROL:
184 case SID_FM_DATEFIELD:
185 case SID_FM_TIMEFIELD:
186 case SID_FM_NUMERICFIELD:
187 case SID_FM_CURRENCYFIELD:
188 case SID_FM_PATTERNFIELD:
189 case SID_FM_DESIGN_MODE:
190 case SID_FM_FORMATTEDFIELD:
191 case SID_FM_SCROLLBAR:
192 case SID_FM_SPINBUTTON:
193 { // set a new image, matching to this slot
194 OUString aSlotURL( "slot:" );
195 aSlotURL += OUString::valueOf( sal_Int32( nSlot ));
196 Image aImage = GetImage( m_xFrame, aSlotURL, hasBigImages() );
197 GetToolBox().SetItemImage( GetId(), aImage );
198 nLastSlot = nSlot;
200 break;
203 SfxToolBoxControl::StateChanged( nSID, eState,pState );
206 //-----------------------------------------------------------------------
207 SfxPopupWindowType SvxFmTbxCtlConfig::GetPopupWindowType() const
209 return( nLastSlot == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT );
212 //-----------------------------------------------------------------------
213 SfxPopupWindow* SvxFmTbxCtlConfig::CreatePopupWindow()
215 if ( GetSlotId() == SID_FM_CONFIG )
217 ::svxform::FormToolboxes aToolboxes( m_xFrame );
218 createAndPositionSubToolBar( aToolboxes.getToolboxResourceName( SID_FM_CONFIG ) );
220 return NULL;
223 //-----------------------------------------------------------------------
224 void SvxFmTbxCtlConfig::Select( sal_uInt16 /*nModifier*/ )
226 //////////////////////////////////////////////////////////////////////
227 // Click auf den Button SID_FM_CONFIG in der ObjectBar
228 if ( nLastSlot )
230 sal_uInt16 n = 0;
231 while( SlotToCommands[n].nSlotId > 0 )
233 if ( SlotToCommands[n].nSlotId == nLastSlot )
234 break;
235 n++;
238 if ( SlotToCommands[n].nSlotId > 0 )
240 Sequence< PropertyValue > aArgs;
241 Dispatch( OUString::createFromAscii( SlotToCommands[n].pCommand ),
242 aArgs );
248 //========================================================================
249 // class SvxFmTbxCtlAbsRec
250 //========================================================================
252 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlAbsRec, SfxInt32Item );
253 DBG_NAME(SvxFmTbxCtlAbsRec);
254 //-----------------------------------------------------------------------
255 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
256 :SfxToolBoxControl( nSlotId, nId, rTbx )
258 DBG_CTOR(SvxFmTbxCtlAbsRec,NULL);
261 //-----------------------------------------------------------------------
262 SvxFmTbxCtlAbsRec::~SvxFmTbxCtlAbsRec()
264 DBG_DTOR(SvxFmTbxCtlAbsRec,NULL);
267 //-----------------------------------------------------------------------
268 void SvxFmTbxCtlAbsRec::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
270 sal_uInt16 nId = GetId();
271 ToolBox* pToolBox = &GetToolBox();
272 SvxFmAbsRecWin* pWin = (SvxFmAbsRecWin*)( pToolBox->GetItemWindow(nId) );
274 DBG_ASSERT( pWin, "Control not found!" );
276 if (pState)
278 const SfxInt32Item* pItem = PTR_CAST( SfxInt32Item, pState );
279 DBG_ASSERT( pItem, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" );
280 pWin->SetValue( pItem ? pItem->GetValue() : -1 );
283 sal_Bool bEnable = SFX_ITEM_DISABLED != eState && pState;
284 if (!bEnable)
285 pWin->SetText(String());
287 //////////////////////////////////////////////////////////////////////
288 // Enablen/disablen des Fensters
289 pToolBox->EnableItem(nId, bEnable);
290 SfxToolBoxControl::StateChanged( nSID, eState,pState );
293 //-----------------------------------------------------------------------
294 Window* SvxFmTbxCtlAbsRec::CreateItemWindow( Window* pParent )
296 SvxFmAbsRecWin* pWin = new SvxFmAbsRecWin( pParent, this );
297 pWin->SetUniqueId( UID_ABSOLUTE_RECORD_WINDOW );
298 return pWin;
302 //========================================================================
303 // SvxFmTbxCtlRecText
304 //========================================================================
306 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecText, SfxBoolItem );
307 DBG_NAME(SvxFmTbxCtlRecText);
308 //-----------------------------------------------------------------------
309 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
310 :SfxToolBoxControl( nSlotId, nId, rTbx )
312 DBG_CTOR(SvxFmTbxCtlRecText,NULL);
315 //-----------------------------------------------------------------------
316 SvxFmTbxCtlRecText::~SvxFmTbxCtlRecText()
318 DBG_DTOR(SvxFmTbxCtlRecText,NULL);
321 //-----------------------------------------------------------------------
322 Window* SvxFmTbxCtlRecText::CreateItemWindow( Window* pParent )
324 XubString aText( SVX_RES(RID_STR_REC_TEXT) );
325 FixedText* pFixedText = new FixedText( pParent );
326 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) );
327 pFixedText->SetText( aText );
328 aSize.Width() += 6;
329 pFixedText->SetSizePixel( aSize );
330 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
332 return pFixedText;
336 //========================================================================
337 // SvxFmTbxCtlRecFromText
338 //========================================================================
340 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecFromText, SfxBoolItem );
341 DBG_NAME(SvxFmTbxCtlRecFromText);
342 //-----------------------------------------------------------------------
343 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
344 :SfxToolBoxControl( nSlotId, nId, rTbx )
346 DBG_CTOR(SvxFmTbxCtlRecFromText,NULL);
349 //-----------------------------------------------------------------------
350 SvxFmTbxCtlRecFromText::~SvxFmTbxCtlRecFromText()
352 DBG_DTOR(SvxFmTbxCtlRecFromText,NULL);
355 //-----------------------------------------------------------------------
356 Window* SvxFmTbxCtlRecFromText::CreateItemWindow( Window* pParent )
358 XubString aText( SVX_RES(RID_STR_REC_FROM_TEXT) );
359 FixedText* pFixedText = new FixedText( pParent, WB_CENTER );
360 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) );
361 aSize.Width() += 12;
362 pFixedText->SetText( aText );
363 pFixedText->SetSizePixel( aSize );
364 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
365 return pFixedText;
369 //========================================================================
370 // SvxFmTbxCtlRecTotal
371 //========================================================================
372 DBG_NAME(SvxFmTbxCtlRecTotal);
373 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecTotal, SfxStringItem );
375 //-----------------------------------------------------------------------
376 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
377 :SfxToolBoxControl( nSlotId, nId, rTbx )
378 ,pFixedText( NULL )
380 DBG_CTOR(SvxFmTbxCtlRecTotal,NULL);
383 //-----------------------------------------------------------------------
384 SvxFmTbxCtlRecTotal::~SvxFmTbxCtlRecTotal()
386 DBG_DTOR(SvxFmTbxCtlRecTotal,NULL);
389 //-----------------------------------------------------------------------
390 Window* SvxFmTbxCtlRecTotal::CreateItemWindow( Window* pParent )
392 pFixedText = new FixedText( pParent );
393 String aSample(RTL_CONSTASCII_USTRINGPARAM("123456"));
394 Size aSize( pFixedText->GetTextWidth( aSample ), pFixedText->GetTextHeight( ) );
395 aSize.Width() += 12;
396 pFixedText->SetSizePixel( aSize );
397 pFixedText->SetBackground();
398 pFixedText->SetPaintTransparent(sal_True);
399 return pFixedText;
402 //-----------------------------------------------------------------------
403 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
405 //////////////////////////////////////////////////////////////////////
406 // Setzen des FixedTextes
407 if (GetSlotId() != SID_FM_RECORD_TOTAL)
408 return;
410 XubString aText;
411 if (pState)
412 aText = ((SfxStringItem*)pState)->GetValue();
413 else
414 aText = '?';
416 pFixedText->SetText( aText );
417 pFixedText->Update();
418 pFixedText->Flush();
420 SfxToolBoxControl::StateChanged( nSID, eState,pState );
423 //========================================================================
424 // SvxFmTbxNextRec
425 //========================================================================
426 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxNextRec, SfxBoolItem );
428 //-----------------------------------------------------------------------
429 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
430 :SfxToolBoxControl( nSlotId, nId, rTbx )
432 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | TIB_REPEAT);
434 AllSettings aSettings = rTbx.GetSettings();
435 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
436 aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4);
437 aSettings.SetMouseSettings(aMouseSettings);
438 rTbx.SetSettings(aSettings, sal_True);
441 //========================================================================
442 // SvxFmTbxPrevRec
443 //========================================================================
444 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxPrevRec, SfxBoolItem );
446 //-----------------------------------------------------------------------
447 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
448 :SfxToolBoxControl( nSlotId, nId, rTbx )
450 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | TIB_REPEAT);
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */