LibreOffice Module svx (master)  1
tbxform.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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/event.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/settings.hxx>
29 #include <formtoolbars.hxx>
30 
31 
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>
39 
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 
44  :NumericField( _pParent, WB_BORDER )
45  ,m_pController(_pController)
46 {
47  SetMin(1);
48  SetFirst(1);
49  SetSpinSize(1);
50  SetSizePixel( Size(70,19) );
51 
53  SetStrictFormat(true);
54 }
55 
56 
57 void SvxFmAbsRecWin::FirePosition( bool _bForce )
58 {
59  if ( !_bForce && !IsValueChangedFromSaved() )
60  return;
61 
62  sal_Int64 nRecord = GetValue();
63  if (nRecord < GetMin() || nRecord > GetMax())
64  {
65  return;
66  }
67 
68  SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<sal_Int32>(nRecord) );
69 
70  Any a;
71  Sequence< PropertyValue > aArgs( 1 );
72  aArgs[0].Name = "Position";
73  aPositionParam.QueryValue( a );
74  aArgs[0].Value = a;
75  m_pController->Dispatch( ".uno:AbsoluteRecord",
76  aArgs );
77  m_pController->updateStatus();
78 
79  SaveValue();
80 }
81 
82 
84 {
85  FirePosition( false );
86 }
87 
88 
89 void SvxFmAbsRecWin::KeyInput( const KeyEvent& rKeyEvent )
90 {
91  if( rKeyEvent.GetKeyCode() == KEY_RETURN && !GetText().isEmpty() )
92  FirePosition( true );
93  else
94  NumericField::KeyInput( rKeyEvent );
95 }
96 
97 
99 
100 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
101  :SfxToolBoxControl( nSlotId, nId, rTbx )
102 {
103 }
104 
105 
107 {
108 }
109 
110 
111 void SvxFmTbxCtlAbsRec::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
112 {
113  sal_uInt16 nId = GetId();
114  ToolBox* pToolBox = &GetToolBox();
115  SvxFmAbsRecWin* pWin = static_cast<SvxFmAbsRecWin*>( pToolBox->GetItemWindow(nId) );
116 
117  assert(pWin && "Control not found!");
118 
119  if (pState)
120  {
121  const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >( pState );
122  DBG_ASSERT( pItem, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" );
123  pWin->SetValue( pItem ? pItem->GetValue() : -1 );
124  }
125 
126  bool bEnable = SfxItemState::DISABLED != eState && pState;
127  if (!bEnable)
128  pWin->SetText(OUString());
129 
130 
131  // enabling/disabling of the window
132  pToolBox->EnableItem(nId, bEnable);
133  SfxToolBoxControl::StateChanged( nSID, eState,pState );
134 }
135 
137 {
138  return VclPtrInstance<SvxFmAbsRecWin>(pParent, this);
139 }
140 
142 
143 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
144  :SfxToolBoxControl( nSlotId, nId, rTbx )
145 {
146 }
147 
149 {
150 }
151 
153 {
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 );
161 
162  return pFixedText;
163 }
164 
166 
167 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
168  :SfxToolBoxControl( nSlotId, nId, rTbx )
169 {
170 }
171 
172 
174 {
175 }
176 
177 
179 {
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 );
187  return pFixedText.get();
188 }
189 
191 
192 
193 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
194  :SfxToolBoxControl( nSlotId, nId, rTbx )
195  ,pFixedText( nullptr )
196 {
197 }
198 
199 
201 {
202 }
203 
204 
206 {
208  OUString const aSample("123456");
209  Size aSize( pFixedText->GetTextWidth( aSample ), pFixedText->GetTextHeight( ) );
210  aSize.AdjustWidth(12 );
211  pFixedText->SetSizePixel( aSize );
214  return pFixedText;
215 }
216 
217 
218 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
219 {
220 
221  // setting the FixedText
222  if (GetSlotId() != SID_FM_RECORD_TOTAL)
223  return;
224 
225  OUString aText;
226  if (pState)
227  aText = static_cast<const SfxStringItem*>(pState)->GetValue();
228  else
229  aText = "?";
230 
231  pFixedText->SetText( aText );
232  pFixedText->Update();
233  pFixedText->Flush();
234 
235  SfxToolBoxControl::StateChanged( nSID, eState,pState );
236 }
237 
239 
240 
241 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
242  :SfxToolBoxControl( nSlotId, nId, rTbx )
243 {
244  rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
245 
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);
251 }
252 
254 
255 
256 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
257  :SfxToolBoxControl( nSlotId, nId, rTbx )
258 {
259  rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
260 }
261 
262 
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 GetValue() const
SvxFmTbxCtlAbsRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:100
long AdjustWidth(long n)
std::string GetValue
ToolBox & GetToolBox() const
virtual ~SvxFmTbxCtlRecFromText() override
Definition: tbxform.cxx:173
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
SvxFmAbsRecWin(vcl::Window *_pParent, SfxToolBoxControl *_pController)
Definition: tbxform.cxx:43
void SaveValue()
void Flush() override
virtual void SetSizePixel(const Size &rNewSize)
SvxFmTbxCtlRecFromText(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:167
sal_Int16 nId
virtual ~SvxFmTbxCtlRecText() override
Definition: tbxform.cxx:148
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tbxform.cxx:218
virtual void SetSettings(const AllSettings &rSettings) override
sal_Int64 GetValue() const
void SetStrictFormat(bool bStrict)
virtual ~SvxFmTbxCtlAbsRec() override
Definition: tbxform.cxx:106
virtual ~SvxFmTbxCtlRecTotal() override
Definition: tbxform.cxx:200
void SetSpinSize(sal_Int64 nNewSize)
void SetMin(sal_Int64 nNewMin)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SfxToolBoxControl * m_pController
Definition: tbxform.hxx:36
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
void SetBackground()
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
sal_uLong GetButtonRepeat() const
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tbxform.cxx:111
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
sal_Int64 GetMin() const
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:205
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:152
void Update()
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState)
SvxFmTbxCtlRecText(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:143
#define DBG_ASSERT(sCon, aError)
uno_Any a
SvxFmTbxCtlRecTotal(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:193
virtual void SetText(const OUString &rStr) override
void SetMouseSettings(const MouseSettings &rSet)
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
virtual OUString GetText() const override
vcl::Window * GetItemWindow(sal_uInt16 nItemId) const
const AllSettings & GetSettings() const
void SetPaintTransparent(bool bTransparent)
long GetTextHeight() const
virtual void KeyInput(const KeyEvent &rKEvt) override
SvxFmTbxPrevRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:256
void reset(FixedText *pBody)
#define KEY_RETURN
const vcl::KeyCode & GetKeyCode() const
void FirePosition(bool _bForce)
Definition: tbxform.cxx:57
VclPtr< FixedText > pFixedText
Definition: tbxform.hxx:83
SfxItemState
sal_Int64 GetMax() const
WinBits const WB_BORDER
void SetFirst(sal_Int64 nNewFirst)
unsigned short GetId() const
SvxFmTbxNextRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:241
unsigned short GetSlotId() const
SFX_IMPL_TOOLBOX_CONTROL(SvxFmTbxCtlAbsRec, SfxInt32Item)
const MouseSettings & GetMouseSettings() const
void SetDecimalDigits(sal_uInt16 nDigits)
virtual void LoseFocus() override
Definition: tbxform.cxx:83
long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
virtual void KeyInput(const KeyEvent &rKeyEvt) override
Definition: tbxform.cxx:89
WinBits const WB_CENTER
reference_type * get() const
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:136
virtual void SetText(const OUString &rStr) override
void SetButtonRepeat(sal_uLong nRepeat)
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:178
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
virtual void SetValue(sal_Int64 nNewValue)
bool IsValueChangedFromSaved() const