update dev300-m58
[ooovba.git] / svx / source / form / tbxform.cxx
blobc5a5eb2391832672057824330b7f5d78db6ebc42
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbxform.cxx,v $
10 * $Revision: 1.27 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
34 #include <tools/ref.hxx>
35 #include <tools/shl.hxx>
36 #include <svtools/intitem.hxx>
37 #include <svtools/eitem.hxx>
38 #include <svtools/stritem.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <vcl/toolbox.hxx>
41 #include <vcl/fixed.hxx>
42 #include "fmitems.hxx"
43 #include "formtoolbars.hxx"
46 #include <vcl/sound.hxx>
47 #include <svx/dialmgr.hxx>
48 #ifndef _SVX_DIALOGS_HRC
49 #include <svx/dialogs.hrc>
50 #endif
51 #include "tbxctl.hxx"
52 #include "tbxdraw.hxx"
53 #include "tbxform.hxx"
54 #ifndef _SVX_FMRESIDS_HRC
55 #include "fmresids.hrc"
56 #endif
57 #include "fmitems.hxx"
58 #ifndef _SVX_FMHELP_HRC
59 #include "fmhelp.hrc"
60 #endif
61 #include <sfx2/viewfrm.hxx>
62 #include <sfx2/viewsh.hxx>
63 #include <sfx2/imagemgr.hxx>
64 #include <com/sun/star/beans/XPropertySet.hpp>
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::beans;
68 using namespace ::com::sun::star::frame;
69 using ::com::sun::star::beans::XPropertySet;
72 //========================================================================
73 // class SvxFmAbsRecWin
74 //========================================================================
76 // -----------------------------------------------------------------------
77 SvxFmAbsRecWin::SvxFmAbsRecWin( Window* _pParent, SfxToolBoxControl* _pController )
78 :NumericField( _pParent, WB_BORDER )
79 ,m_pController(_pController)
81 SetMin(1);
82 SetFirst(1);
83 SetSpinSize(1);
84 SetSizePixel( Size(70,19) );
86 SetDecimalDigits(0);
87 SetStrictFormat(TRUE);
90 // -----------------------------------------------------------------------
91 SvxFmAbsRecWin::~SvxFmAbsRecWin()
95 // -----------------------------------------------------------------------
96 void SvxFmAbsRecWin::FirePosition( sal_Bool _bForce )
98 if ( _bForce || ( GetText() != GetSavedValue() ) )
100 sal_Int64 nRecord = GetValue();
101 if (nRecord < GetMin() || nRecord > GetMax())
103 Sound::Beep();
104 return;
107 SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<INT32>(nRecord) );
109 Any a;
110 Sequence< PropertyValue > aArgs( 1 );
111 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Position" ));
112 aPositionParam.QueryValue( a );
113 aArgs[0].Value = a;
114 m_pController->Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AbsoluteRecord" )),
115 aArgs );
116 m_pController->updateStatus();
118 SaveValue();
122 // -----------------------------------------------------------------------
123 void SvxFmAbsRecWin::LoseFocus()
125 FirePosition( sal_False );
128 // -----------------------------------------------------------------------
129 void SvxFmAbsRecWin::KeyInput( const KeyEvent& rKeyEvent )
131 if( rKeyEvent.GetKeyCode() == KEY_RETURN && GetText().Len() )
132 FirePosition( sal_True );
133 else
134 NumericField::KeyInput( rKeyEvent );
137 //========================================================================
138 // class SvxFmTbxCtlConfig
139 //========================================================================
141 struct MapSlotToCmd
143 USHORT nSlotId;
144 const char* pCommand;
147 static MapSlotToCmd SlotToCommands[] =
149 { SID_FM_PUSHBUTTON, ".uno:Pushbutton" },
150 { SID_FM_RADIOBUTTON, ".uno:RadioButton" },
151 { SID_FM_CHECKBOX, ".uno:CheckBox" },
152 { SID_FM_FIXEDTEXT, ".uno:Label" },
153 { SID_FM_GROUPBOX, ".uno:GroupBox" },
154 { SID_FM_LISTBOX, ".uno:ListBox" },
155 { SID_FM_COMBOBOX, ".uno:ComboBox" },
156 { SID_FM_EDIT, ".uno:Edit" },
157 { SID_FM_DBGRID, ".uno:Grid" },
158 { SID_FM_IMAGEBUTTON, ".uno:Imagebutton" },
159 { SID_FM_IMAGECONTROL, ".uno:ImageControl" },
160 { SID_FM_FILECONTROL, ".uno:FileControl" },
161 { SID_FM_DATEFIELD, ".uno:DateField" },
162 { SID_FM_TIMEFIELD, ".uno:TimeField" },
163 { SID_FM_NUMERICFIELD, ".uno:NumericField" },
164 { SID_FM_CURRENCYFIELD, ".uno:CurrencyField" },
165 { SID_FM_PATTERNFIELD, ".uno:PatternField" },
166 { SID_FM_DESIGN_MODE, ".uno:SwitchControlDesignMode" },
167 { SID_FM_FORMATTEDFIELD, ".uno:FormattedField" },
168 { SID_FM_SCROLLBAR, ".uno:ScrollBar" },
169 { SID_FM_SPINBUTTON, ".uno:SpinButton" },
170 { 0, "" }
173 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlConfig, SfxUInt16Item );
175 //-----------------------------------------------------------------------
176 SvxFmTbxCtlConfig::SvxFmTbxCtlConfig( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
177 : SfxToolBoxControl( nSlotId, nId, rTbx )
178 ,nLastSlot( 0 )
180 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
183 //-----------------------------------------------------------------------
184 void SvxFmTbxCtlConfig::StateChanged(USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
186 if (nSID == SID_FM_CONFIG)
188 UINT16 nSlot = 0;
189 if (eState >= SFX_ITEM_AVAILABLE)
190 nSlot = ((SfxUInt16Item*)pState)->GetValue();
192 switch( nSlot )
194 case SID_FM_PUSHBUTTON:
195 case SID_FM_RADIOBUTTON:
196 case SID_FM_CHECKBOX:
197 case SID_FM_FIXEDTEXT:
198 case SID_FM_GROUPBOX:
199 case SID_FM_LISTBOX:
200 case SID_FM_COMBOBOX:
201 case SID_FM_NAVIGATIONBAR:
202 case SID_FM_EDIT:
203 case SID_FM_DBGRID:
204 case SID_FM_IMAGEBUTTON:
205 case SID_FM_IMAGECONTROL:
206 case SID_FM_FILECONTROL:
207 case SID_FM_DATEFIELD:
208 case SID_FM_TIMEFIELD:
209 case SID_FM_NUMERICFIELD:
210 case SID_FM_CURRENCYFIELD:
211 case SID_FM_PATTERNFIELD:
212 case SID_FM_DESIGN_MODE:
213 case SID_FM_FORMATTEDFIELD:
214 case SID_FM_SCROLLBAR:
215 case SID_FM_SPINBUTTON:
216 { // set a new image, matching to this slot
217 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
218 aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlot ));
219 Image aImage = GetImage( m_xFrame,
220 aSlotURL,
221 hasBigImages(),
222 GetToolBox().GetDisplayBackground().GetColor().IsDark() );
224 GetToolBox().SetItemImage( GetId(), aImage );
225 nLastSlot = nSlot;
227 break;
230 SfxToolBoxControl::StateChanged( nSID, eState,pState );
233 //-----------------------------------------------------------------------
234 SfxPopupWindowType SvxFmTbxCtlConfig::GetPopupWindowType() const
236 return( nLastSlot == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT );
239 //-----------------------------------------------------------------------
240 SfxPopupWindow* SvxFmTbxCtlConfig::CreatePopupWindow()
242 if ( GetSlotId() == SID_FM_CONFIG )
244 ::svxform::FormToolboxes aToolboxes( m_xFrame );
245 createAndPositionSubToolBar( aToolboxes.getToolboxResourceName( SID_FM_CONFIG ) );
247 return NULL;
250 //-----------------------------------------------------------------------
251 void SvxFmTbxCtlConfig::Select( USHORT /*nModifier*/ )
253 //////////////////////////////////////////////////////////////////////
254 // Click auf den Button SID_FM_CONFIG in der ObjectBar
255 if ( nLastSlot )
257 USHORT n = 0;
258 while( SlotToCommands[n].nSlotId > 0 )
260 if ( SlotToCommands[n].nSlotId == nLastSlot )
261 break;
262 n++;
265 if ( SlotToCommands[n].nSlotId > 0 )
267 Sequence< PropertyValue > aArgs;
268 Dispatch( rtl::OUString::createFromAscii( SlotToCommands[n].pCommand ),
269 aArgs );
275 //========================================================================
276 // class SvxFmTbxCtlAbsRec
277 //========================================================================
279 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlAbsRec, SfxInt32Item );
280 DBG_NAME(SvxFmTbxCtlAbsRec);
281 //-----------------------------------------------------------------------
282 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
283 :SfxToolBoxControl( nSlotId, nId, rTbx )
285 DBG_CTOR(SvxFmTbxCtlAbsRec,NULL);
288 //-----------------------------------------------------------------------
289 SvxFmTbxCtlAbsRec::~SvxFmTbxCtlAbsRec()
291 DBG_DTOR(SvxFmTbxCtlAbsRec,NULL);
294 //-----------------------------------------------------------------------
295 void SvxFmTbxCtlAbsRec::StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
297 USHORT nId = GetId();
298 ToolBox* pToolBox = &GetToolBox();
299 SvxFmAbsRecWin* pWin = (SvxFmAbsRecWin*)( pToolBox->GetItemWindow(nId) );
301 DBG_ASSERT( pWin, "Control not found!" );
303 if (pState)
305 const SfxInt32Item* pItem = PTR_CAST( SfxInt32Item, pState );
306 DBG_ASSERT( pItem, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" );
307 pWin->SetValue( pItem ? pItem->GetValue() : -1 );
310 BOOL bEnable = SFX_ITEM_DISABLED != eState && pState;
311 if (!bEnable)
312 pWin->SetText(String());
314 //////////////////////////////////////////////////////////////////////
315 // Enablen/disablen des Fensters
316 pToolBox->EnableItem(nId, bEnable);
317 SfxToolBoxControl::StateChanged( nSID, eState,pState );
320 //-----------------------------------------------------------------------
321 Window* SvxFmTbxCtlAbsRec::CreateItemWindow( Window* pParent )
323 SvxFmAbsRecWin* pWin = new SvxFmAbsRecWin( pParent, this );
324 pWin->SetUniqueId( UID_ABSOLUTE_RECORD_WINDOW );
325 return pWin;
329 //========================================================================
330 // SvxFmTbxCtlRecText
331 //========================================================================
333 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecText, SfxBoolItem );
334 DBG_NAME(SvxFmTbxCtlRecText);
335 //-----------------------------------------------------------------------
336 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
337 :SfxToolBoxControl( nSlotId, nId, rTbx )
339 DBG_CTOR(SvxFmTbxCtlRecText,NULL);
342 //-----------------------------------------------------------------------
343 SvxFmTbxCtlRecText::~SvxFmTbxCtlRecText()
345 DBG_DTOR(SvxFmTbxCtlRecText,NULL);
348 //-----------------------------------------------------------------------
349 Window* SvxFmTbxCtlRecText::CreateItemWindow( Window* pParent )
351 XubString aText( SVX_RES(RID_STR_REC_TEXT) );
352 FixedText* pFixedText = new FixedText( pParent );
353 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) );
354 pFixedText->SetText( aText );
355 aSize.Width() += 6;
356 pFixedText->SetSizePixel( aSize );
357 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
359 return pFixedText;
363 //========================================================================
364 // SvxFmTbxCtlRecFromText
365 //========================================================================
367 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecFromText, SfxBoolItem );
368 DBG_NAME(SvxFmTbxCtlRecFromText);
369 //-----------------------------------------------------------------------
370 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
371 :SfxToolBoxControl( nSlotId, nId, rTbx )
373 DBG_CTOR(SvxFmTbxCtlRecFromText,NULL);
376 //-----------------------------------------------------------------------
377 SvxFmTbxCtlRecFromText::~SvxFmTbxCtlRecFromText()
379 DBG_DTOR(SvxFmTbxCtlRecFromText,NULL);
382 //-----------------------------------------------------------------------
383 Window* SvxFmTbxCtlRecFromText::CreateItemWindow( Window* pParent )
385 XubString aText( SVX_RES(RID_STR_REC_FROM_TEXT) );
386 FixedText* pFixedText = new FixedText( pParent, WB_CENTER );
387 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) );
388 aSize.Width() += 12;
389 pFixedText->SetText( aText );
390 pFixedText->SetSizePixel( aSize );
391 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
392 return pFixedText;
396 //========================================================================
397 // SvxFmTbxCtlRecTotal
398 //========================================================================
399 DBG_NAME(SvxFmTbxCtlRecTotal);
400 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecTotal, SfxStringItem );
402 //-----------------------------------------------------------------------
403 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
404 :SfxToolBoxControl( nSlotId, nId, rTbx )
405 ,pFixedText( NULL )
407 DBG_CTOR(SvxFmTbxCtlRecTotal,NULL);
410 //-----------------------------------------------------------------------
411 SvxFmTbxCtlRecTotal::~SvxFmTbxCtlRecTotal()
413 DBG_DTOR(SvxFmTbxCtlRecTotal,NULL);
416 //-----------------------------------------------------------------------
417 Window* SvxFmTbxCtlRecTotal::CreateItemWindow( Window* pParent )
419 pFixedText = new FixedText( pParent );
420 String aSample( "123456", sizeof( "123456" ) - 1 );
421 Size aSize( pFixedText->GetTextWidth( aSample ), pFixedText->GetTextHeight( ) );
422 aSize.Width() += 12;
423 pFixedText->SetSizePixel( aSize );
424 pFixedText->SetBackground();
425 pFixedText->SetPaintTransparent(TRUE);
426 return pFixedText;
429 //-----------------------------------------------------------------------
430 void SvxFmTbxCtlRecTotal::StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
432 //////////////////////////////////////////////////////////////////////
433 // Setzen des FixedTextes
434 if (GetSlotId() != SID_FM_RECORD_TOTAL)
435 return;
437 XubString aText;
438 if (pState)
439 aText = ((SfxStringItem*)pState)->GetValue();
440 else
441 aText = '?';
443 pFixedText->SetText( aText );
444 pFixedText->Update();
445 pFixedText->Flush();
447 SfxToolBoxControl::StateChanged( nSID, eState,pState );
450 //========================================================================
451 // SvxFmTbxNextRec
452 //========================================================================
453 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxNextRec, SfxBoolItem );
455 //-----------------------------------------------------------------------
456 SvxFmTbxNextRec::SvxFmTbxNextRec( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
457 :SfxToolBoxControl( nSlotId, nId, rTbx )
459 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | TIB_REPEAT);
461 AllSettings aSettings = rTbx.GetSettings();
462 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
463 aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4);
464 aSettings.SetMouseSettings(aMouseSettings);
465 rTbx.SetSettings(aSettings, TRUE);
468 //========================================================================
469 // SvxFmTbxPrevRec
470 //========================================================================
471 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxPrevRec, SfxBoolItem );
473 //-----------------------------------------------------------------------
474 SvxFmTbxPrevRec::SvxFmTbxPrevRec( USHORT nSlotId, USHORT nId, ToolBox& rTbx )
475 :SfxToolBoxControl( nSlotId, nId, rTbx )
477 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | TIB_REPEAT);