bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / form / tbxform.cxx
blob64baa4f85f89e887b0430c4e1302d219859383d9
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 <svl/intitem.hxx>
22 #include <svl/eitem.hxx>
23 #include <svl/stritem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <vcl/toolbox.hxx>
26 #include <vcl/fixed.hxx>
27 #include <vcl/settings.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 "tbxform.hxx"
36 #include "svx/fmresids.hrc"
37 #include "fmhelp.hrc"
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/viewsh.hxx>
40 #include <sfx2/imagemgr.hxx>
41 #include <com/sun/star/beans/XPropertySet.hpp>
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::frame;
46 using ::com::sun::star::beans::XPropertySet;
48 SvxFmAbsRecWin::SvxFmAbsRecWin( vcl::Window* _pParent, SfxToolBoxControl* _pController )
49 :NumericField( _pParent, WB_BORDER )
50 ,m_pController(_pController)
52 SetMin(1);
53 SetFirst(1);
54 SetSpinSize(1);
55 SetSizePixel( Size(70,19) );
57 SetDecimalDigits(0);
58 SetStrictFormat(true);
62 void SvxFmAbsRecWin::FirePosition( bool _bForce )
64 if ( _bForce || IsValueChangedFromSaved() )
66 sal_Int64 nRecord = GetValue();
67 if (nRecord < GetMin() || nRecord > GetMax())
69 return;
72 SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<sal_Int32>(nRecord) );
74 Any a;
75 Sequence< PropertyValue > aArgs( 1 );
76 aArgs[0].Name = "Position";
77 aPositionParam.QueryValue( a );
78 aArgs[0].Value = a;
79 m_pController->Dispatch( OUString( ".uno:AbsoluteRecord" ),
80 aArgs );
81 m_pController->updateStatus();
83 SaveValue();
88 void SvxFmAbsRecWin::LoseFocus()
90 FirePosition( false );
94 void SvxFmAbsRecWin::KeyInput( const KeyEvent& rKeyEvent )
96 if( rKeyEvent.GetKeyCode() == KEY_RETURN && !GetText().isEmpty() )
97 FirePosition( true );
98 else
99 NumericField::KeyInput( rKeyEvent );
103 // class SvxFmTbxCtlConfig
106 struct MapSlotToCmd
108 sal_uInt16 nSlotId;
109 const char* pCommand;
112 static const MapSlotToCmd SlotToCommands[] =
114 { SID_FM_PUSHBUTTON, ".uno:Pushbutton" },
115 { SID_FM_RADIOBUTTON, ".uno:RadioButton" },
116 { SID_FM_CHECKBOX, ".uno:CheckBox" },
117 { SID_FM_FIXEDTEXT, ".uno:Label" },
118 { SID_FM_GROUPBOX, ".uno:GroupBox" },
119 { SID_FM_LISTBOX, ".uno:ListBox" },
120 { SID_FM_COMBOBOX, ".uno:ComboBox" },
121 { SID_FM_EDIT, ".uno:Edit" },
122 { SID_FM_DBGRID, ".uno:Grid" },
123 { SID_FM_IMAGEBUTTON, ".uno:Imagebutton" },
124 { SID_FM_IMAGECONTROL, ".uno:ImageControl" },
125 { SID_FM_FILECONTROL, ".uno:FileControl" },
126 { SID_FM_DATEFIELD, ".uno:DateField" },
127 { SID_FM_TIMEFIELD, ".uno:TimeField" },
128 { SID_FM_NUMERICFIELD, ".uno:NumericField" },
129 { SID_FM_CURRENCYFIELD, ".uno:CurrencyField" },
130 { SID_FM_PATTERNFIELD, ".uno:PatternField" },
131 { SID_FM_DESIGN_MODE, ".uno:SwitchControlDesignMode" },
132 { SID_FM_FORMATTEDFIELD, ".uno:FormattedField" },
133 { SID_FM_SCROLLBAR, ".uno:ScrollBar" },
134 { SID_FM_SPINBUTTON, ".uno:SpinButton" },
135 { 0, "" }
138 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlConfig, SfxUInt16Item );
141 SvxFmTbxCtlConfig::SvxFmTbxCtlConfig( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
142 : SfxToolBoxControl( nSlotId, nId, rTbx )
143 ,nLastSlot( 0 )
145 rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
149 void SvxFmTbxCtlConfig::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
151 if (nSID == SID_FM_CONFIG)
153 sal_uInt16 nSlot = 0;
154 if (eState >= SfxItemState::DEFAULT)
155 nSlot = static_cast<const SfxUInt16Item*>(pState)->GetValue();
157 switch( nSlot )
159 case SID_FM_PUSHBUTTON:
160 case SID_FM_RADIOBUTTON:
161 case SID_FM_CHECKBOX:
162 case SID_FM_FIXEDTEXT:
163 case SID_FM_GROUPBOX:
164 case SID_FM_LISTBOX:
165 case SID_FM_COMBOBOX:
166 case SID_FM_NAVIGATIONBAR:
167 case SID_FM_EDIT:
168 case SID_FM_DBGRID:
169 case SID_FM_IMAGEBUTTON:
170 case SID_FM_IMAGECONTROL:
171 case SID_FM_FILECONTROL:
172 case SID_FM_DATEFIELD:
173 case SID_FM_TIMEFIELD:
174 case SID_FM_NUMERICFIELD:
175 case SID_FM_CURRENCYFIELD:
176 case SID_FM_PATTERNFIELD:
177 case SID_FM_DESIGN_MODE:
178 case SID_FM_FORMATTEDFIELD:
179 case SID_FM_SCROLLBAR:
180 case SID_FM_SPINBUTTON:
181 { // set a new image, matching to this slot
182 OUString aSlotURL = "slot:" + OUString::number( nSlot);
183 Image aImage = GetImage( m_xFrame, aSlotURL, hasBigImages() );
184 GetToolBox().SetItemImage( GetId(), aImage );
185 nLastSlot = nSlot;
187 break;
190 SfxToolBoxControl::StateChanged( nSID, eState,pState );
194 SfxPopupWindowType SvxFmTbxCtlConfig::GetPopupWindowType() const
196 return( nLastSlot == 0 ? SfxPopupWindowType::ONCLICK : SfxPopupWindowType::ONTIMEOUT );
200 VclPtr<SfxPopupWindow> SvxFmTbxCtlConfig::CreatePopupWindow()
202 if ( GetSlotId() == SID_FM_CONFIG )
204 ::svxform::FormToolboxes aToolboxes( m_xFrame );
205 createAndPositionSubToolBar( aToolboxes.getToolboxResourceName( SID_FM_CONFIG ) );
207 return NULL;
211 void SvxFmTbxCtlConfig::Select( sal_uInt16 /*nSelectModifier*/ )
214 // Click auf den Button SID_FM_CONFIG in der ObjectBar
215 if ( nLastSlot )
217 sal_uInt16 n = 0;
218 while( SlotToCommands[n].nSlotId > 0 )
220 if ( SlotToCommands[n].nSlotId == nLastSlot )
221 break;
222 n++;
225 if ( SlotToCommands[n].nSlotId > 0 )
227 Sequence< PropertyValue > aArgs;
228 Dispatch( OUString::createFromAscii( SlotToCommands[n].pCommand ),
229 aArgs );
234 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlAbsRec, SfxInt32Item );
236 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
237 :SfxToolBoxControl( nSlotId, nId, rTbx )
242 SvxFmTbxCtlAbsRec::~SvxFmTbxCtlAbsRec()
247 void SvxFmTbxCtlAbsRec::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
249 sal_uInt16 nId = GetId();
250 ToolBox* pToolBox = &GetToolBox();
251 SvxFmAbsRecWin* pWin = static_cast<SvxFmAbsRecWin*>( pToolBox->GetItemWindow(nId) );
253 assert(pWin && "Control not found!");
255 if (pState)
257 const SfxInt32Item* pItem = PTR_CAST( SfxInt32Item, pState );
258 DBG_ASSERT( pItem, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" );
259 pWin->SetValue( pItem ? pItem->GetValue() : -1 );
262 bool bEnable = SfxItemState::DISABLED != eState && pState;
263 if (!bEnable)
264 pWin->SetText(OUString());
267 // Enablen/disablen des Fensters
268 pToolBox->EnableItem(nId, bEnable);
269 SfxToolBoxControl::StateChanged( nSID, eState,pState );
273 VclPtr<vcl::Window> SvxFmTbxCtlAbsRec::CreateItemWindow( vcl::Window* pParent )
275 VclPtrInstance<SvxFmAbsRecWin> pWin( pParent, this );
276 pWin->SetUniqueId( UID_ABSOLUTE_RECORD_WINDOW );
277 return pWin.get();
280 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecText, SfxBoolItem );
282 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
283 :SfxToolBoxControl( nSlotId, nId, rTbx )
288 SvxFmTbxCtlRecText::~SvxFmTbxCtlRecText()
293 VclPtr<vcl::Window> SvxFmTbxCtlRecText::CreateItemWindow( vcl::Window* pParent )
295 OUString aText(SVX_RESSTR(RID_STR_REC_TEXT));
296 VclPtrInstance<FixedText> pFixedText( pParent );
297 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) );
298 pFixedText->SetText( aText );
299 aSize.Width() += 6;
300 pFixedText->SetSizePixel( aSize );
301 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
303 return pFixedText;
306 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecFromText, SfxBoolItem );
308 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
309 :SfxToolBoxControl( nSlotId, nId, rTbx )
314 SvxFmTbxCtlRecFromText::~SvxFmTbxCtlRecFromText()
319 VclPtr<vcl::Window> SvxFmTbxCtlRecFromText::CreateItemWindow( vcl::Window* pParent )
321 OUString aText(SVX_RESSTR(RID_STR_REC_FROM_TEXT));
322 VclPtrInstance<FixedText> pFixedText( pParent, WB_CENTER );
323 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) );
324 aSize.Width() += 12;
325 pFixedText->SetText( aText );
326 pFixedText->SetSizePixel( aSize );
327 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
328 return pFixedText.get();
331 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecTotal, SfxStringItem );
334 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
335 :SfxToolBoxControl( nSlotId, nId, rTbx )
336 ,pFixedText( NULL )
341 SvxFmTbxCtlRecTotal::~SvxFmTbxCtlRecTotal()
346 VclPtr<vcl::Window> SvxFmTbxCtlRecTotal::CreateItemWindow( vcl::Window* pParent )
348 pFixedText.reset(VclPtr<FixedText>::Create( pParent ));
349 OUString aSample("123456");
350 Size aSize( pFixedText->GetTextWidth( aSample ), pFixedText->GetTextHeight( ) );
351 aSize.Width() += 12;
352 pFixedText->SetSizePixel( aSize );
353 pFixedText->SetBackground();
354 pFixedText->SetPaintTransparent(true);
355 return pFixedText;
359 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
362 // Setzen des FixedTextes
363 if (GetSlotId() != SID_FM_RECORD_TOTAL)
364 return;
366 OUString aText;
367 if (pState)
368 aText = static_cast<const SfxStringItem*>(pState)->GetValue();
369 else
370 aText = "?";
372 pFixedText->SetText( aText );
373 pFixedText->Update();
374 pFixedText->Flush();
376 SfxToolBoxControl::StateChanged( nSID, eState,pState );
379 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxNextRec, SfxBoolItem );
382 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
383 :SfxToolBoxControl( nSlotId, nId, rTbx )
385 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
387 AllSettings aSettings = rTbx.GetSettings();
388 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
389 aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4);
390 aSettings.SetMouseSettings(aMouseSettings);
391 rTbx.SetSettings(aSettings, true);
394 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxPrevRec, SfxBoolItem );
397 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
398 :SfxToolBoxControl( nSlotId, nId, rTbx )
400 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */