1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <svl/intitem.hxx>
22 #include <svl/eitem.hxx>
23 #include <svl/stritem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/settings.hxx>
29 #include <formtoolbars.hxx>
32 #include <svx/dialmgr.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/strings.hrc>
35 #include <svx/tbxctl.hxx>
36 #include <tbxform.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <sfx2/viewsh.hxx>
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::beans
;
43 SvxFmAbsRecWin::SvxFmAbsRecWin( vcl::Window
* _pParent
, SfxToolBoxControl
* _pController
)
44 :NumericField( _pParent
, WB_BORDER
)
45 ,m_pController(_pController
)
50 SetSizePixel( Size(70,19) );
53 SetStrictFormat(true);
57 void SvxFmAbsRecWin::FirePosition( bool _bForce
)
59 if ( !_bForce
&& !IsValueChangedFromSaved() )
62 sal_Int64 nRecord
= GetValue();
63 if (nRecord
< GetMin() || nRecord
> GetMax())
68 SfxInt32Item
aPositionParam( FN_PARAM_1
, static_cast<sal_Int32
>(nRecord
) );
71 Sequence
< PropertyValue
> aArgs( 1 );
72 aArgs
[0].Name
= "Position";
73 aPositionParam
.QueryValue( a
);
75 m_pController
->Dispatch( ".uno:AbsoluteRecord",
77 m_pController
->updateStatus();
83 void SvxFmAbsRecWin::LoseFocus()
85 FirePosition( false );
89 void SvxFmAbsRecWin::KeyInput( const KeyEvent
& rKeyEvent
)
91 if( rKeyEvent
.GetKeyCode() == KEY_RETURN
&& !GetText().isEmpty() )
94 NumericField::KeyInput( rKeyEvent
);
98 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlAbsRec
, SfxInt32Item
);
100 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
101 :SfxToolBoxControl( nSlotId
, nId
, rTbx
)
106 SvxFmTbxCtlAbsRec::~SvxFmTbxCtlAbsRec()
111 void SvxFmTbxCtlAbsRec::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
113 sal_uInt16 nId
= GetId();
114 ToolBox
* pToolBox
= &GetToolBox();
115 SvxFmAbsRecWin
* pWin
= static_cast<SvxFmAbsRecWin
*>( pToolBox
->GetItemWindow(nId
) );
117 assert(pWin
&& "Control not found!");
121 const SfxInt32Item
* pItem
= dynamic_cast< const SfxInt32Item
* >( pState
);
122 DBG_ASSERT( pItem
, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" );
123 pWin
->SetValue( pItem
? pItem
->GetValue() : -1 );
126 bool bEnable
= SfxItemState::DISABLED
!= eState
&& pState
;
128 pWin
->SetText(OUString());
131 // enabling/disabling of the window
132 pToolBox
->EnableItem(nId
, bEnable
);
133 SfxToolBoxControl::StateChanged( nSID
, eState
,pState
);
136 VclPtr
<vcl::Window
> SvxFmTbxCtlAbsRec::CreateItemWindow( vcl::Window
* pParent
)
138 return VclPtrInstance
<SvxFmAbsRecWin
>(pParent
, this);
141 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecText
, SfxBoolItem
);
143 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
144 :SfxToolBoxControl( nSlotId
, nId
, rTbx
)
148 SvxFmTbxCtlRecText::~SvxFmTbxCtlRecText()
152 VclPtr
<vcl::Window
> SvxFmTbxCtlRecText::CreateItemWindow( vcl::Window
* pParent
)
154 OUString
aText(SvxResId(RID_STR_REC_TEXT
));
155 VclPtrInstance
<FixedText
> pFixedText( pParent
);
156 Size
aSize( pFixedText
->GetTextWidth( aText
), pFixedText
->GetTextHeight( ) );
157 pFixedText
->SetText( aText
);
158 aSize
.AdjustWidth(6 );
159 pFixedText
->SetSizePixel( aSize
);
160 pFixedText
->SetBackground(Wallpaper(COL_TRANSPARENT
));
165 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecFromText
, SfxBoolItem
);
167 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
168 :SfxToolBoxControl( nSlotId
, nId
, rTbx
)
173 SvxFmTbxCtlRecFromText::~SvxFmTbxCtlRecFromText()
178 VclPtr
<vcl::Window
> SvxFmTbxCtlRecFromText::CreateItemWindow( vcl::Window
* pParent
)
180 OUString
aText(SvxResId(RID_STR_REC_FROM_TEXT
));
181 VclPtrInstance
<FixedText
> pFixedText( pParent
, WB_CENTER
);
182 Size
aSize( pFixedText
->GetTextWidth( aText
), pFixedText
->GetTextHeight( ) );
183 aSize
.AdjustWidth(12 );
184 pFixedText
->SetText( aText
);
185 pFixedText
->SetSizePixel( aSize
);
186 pFixedText
->SetBackground(Wallpaper(COL_TRANSPARENT
));
187 return pFixedText
.get();
190 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecTotal
, SfxStringItem
);
193 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
194 :SfxToolBoxControl( nSlotId
, nId
, rTbx
)
195 ,pFixedText( nullptr )
200 SvxFmTbxCtlRecTotal::~SvxFmTbxCtlRecTotal()
205 VclPtr
<vcl::Window
> SvxFmTbxCtlRecTotal::CreateItemWindow( vcl::Window
* pParent
)
207 pFixedText
.reset(VclPtr
<FixedText
>::Create( pParent
));
208 OUString
const aSample("123456");
209 Size
aSize( pFixedText
->GetTextWidth( aSample
), pFixedText
->GetTextHeight( ) );
210 aSize
.AdjustWidth(12 );
211 pFixedText
->SetSizePixel( aSize
);
212 pFixedText
->SetBackground();
213 pFixedText
->SetPaintTransparent(true);
218 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
221 // setting the FixedText
222 if (GetSlotId() != SID_FM_RECORD_TOTAL
)
227 aText
= static_cast<const SfxStringItem
*>(pState
)->GetValue();
231 pFixedText
->SetText( aText
);
232 pFixedText
->Update();
235 SfxToolBoxControl::StateChanged( nSID
, eState
,pState
);
238 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxNextRec
, SfxBoolItem
);
241 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
242 :SfxToolBoxControl( nSlotId
, nId
, rTbx
)
244 rTbx
.SetItemBits(nId
, rTbx
.GetItemBits(nId
) | ToolBoxItemBits::REPEAT
);
246 AllSettings aSettings
= rTbx
.GetSettings();
247 MouseSettings aMouseSettings
= aSettings
.GetMouseSettings();
248 aMouseSettings
.SetButtonRepeat(aMouseSettings
.GetButtonRepeat() / 4);
249 aSettings
.SetMouseSettings(aMouseSettings
);
250 rTbx
.SetSettings(aSettings
, true);
253 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxPrevRec
, SfxBoolItem
);
256 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
257 :SfxToolBoxControl( nSlotId
, nId
, rTbx
)
259 rTbx
.SetItemBits(nId
, rTbx
.GetItemBits(nId
) | ToolBoxItemBits::REPEAT
);
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */