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 <svl/intitem.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/stritem.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/toolbox.hxx>
25 #include <vcl/settings.hxx>
26 #include <labelitemwindow.hxx>
27 
28 #include <svx/dialmgr.hxx>
29 #include <svx/svxids.hrc>
30 #include <svx/strings.hrc>
31 #include <tbxform.hxx>
32 
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 
37  : InterimItemWindow(pParent, "svx/ui/absrecbox.ui", "AbsRecBox")
38  , m_xWidget(m_xBuilder->weld_entry("entry"))
39  , m_pController(pController)
40 {
41  m_xWidget->connect_key_press(LINK(this, SvxFmAbsRecWin, KeyInputHdl));
42  m_xWidget->connect_activate(LINK(this, SvxFmAbsRecWin, ActivatedHdl));
43  m_xWidget->connect_focus_out(LINK(this, SvxFmAbsRecWin, FocusOutHdl));
44 
45  SetSizePixel(m_xWidget->get_preferred_size());
46 }
47 
49 {
50  m_xWidget.reset();
52 }
53 
55 {
56  if (m_xWidget)
57  m_xWidget->grab_focus();
59 }
60 
62 {
63  disposeOnce();
64 }
65 
66 void SvxFmAbsRecWin::FirePosition( bool _bForce )
67 {
68  if (!_bForce && !m_xWidget->get_value_changed_from_saved())
69  return;
70 
71  sal_Int64 nRecord = m_xWidget->get_text().toInt64();
72  if (nRecord < 1)
73  nRecord = 1;
74 
75  SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<sal_Int32>(nRecord) );
76 
77  Any a;
78  Sequence< PropertyValue > aArgs( 1 );
79  aArgs[0].Name = "Position";
80  aPositionParam.QueryValue( a );
81  aArgs[0].Value = a;
82  m_pController->Dispatch( ".uno:AbsoluteRecord",
83  aArgs );
84  m_pController->updateStatus();
85 
86  m_xWidget->save_value();
87 }
88 
90 {
91  FirePosition( false );
92 }
93 
94 IMPL_LINK(SvxFmAbsRecWin, KeyInputHdl, const KeyEvent&, rKEvt, bool)
95 {
96  return ChildKeyInput(rKEvt);
97 }
98 
100 {
101  if (!m_xWidget->get_text().isEmpty())
102  FirePosition( true );
103  return true;
104 }
105 
107 
108 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
109  :SfxToolBoxControl( nSlotId, nId, rTbx )
110 {
111 }
112 
113 
115 {
116 }
117 
118 void SvxFmTbxCtlAbsRec::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
119 {
120  sal_uInt16 nId = GetId();
121  ToolBox* pToolBox = &GetToolBox();
122  SvxFmAbsRecWin* pWin = static_cast<SvxFmAbsRecWin*>( pToolBox->GetItemWindow(nId) );
123 
124  assert(pWin && "Control not found!");
125 
126  if (pState)
127  {
128  const SfxInt32Item* pItem = dynamic_cast< const SfxInt32Item* >( pState );
129  DBG_ASSERT( pItem, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" );
130  pWin->set_text(OUString::number(pItem ? pItem->GetValue() : -1));
131  }
132 
133  bool bEnable = SfxItemState::DISABLED != eState && pState;
134  if (!bEnable)
135  pWin->set_text(OUString());
136 
137 
138  // enabling/disabling of the window
139  pToolBox->EnableItem(nId, bEnable);
140  SfxToolBoxControl::StateChanged( nSID, eState,pState );
141 }
142 
144 {
145  return VclPtrInstance<SvxFmAbsRecWin>(pParent, this);
146 }
147 
149 
150 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
151  :SfxToolBoxControl( nSlotId, nId, rTbx )
152 {
153  rTbx.SetItemWindowNonInteractive(nId, true);
154 }
155 
157 {
158 }
159 
160 LabelItemWindow::LabelItemWindow(vcl::Window *pParent, const OUString& rLabel)
161  : InterimItemWindow(pParent, "svx/ui/labelbox.ui", "LabelBox")
162  , m_xLabel(m_xBuilder->weld_label("label"))
163 {
164  m_xLabel->set_label(rLabel);
165 
166  SetOptimalSize();
167 
168  m_xLabel->set_toolbar_background();
169 }
170 
172 {
173  Size aSize(m_xLabel->get_preferred_size());
174  aSize.AdjustWidth(12);
175 
176  SetSizePixel(aSize);
177 }
178 
179 void LabelItemWindow::set_label(const OUString& rLabel)
180 {
181  m_xLabel->set_label(rLabel);
182 }
183 
185 {
186  return m_xLabel->get_label();
187 }
188 
190 {
191  m_xLabel.reset();
193 }
194 
196 {
197  disposeOnce();
198 }
199 
201 {
202  OUString aText(SvxResId(RID_STR_REC_TEXT));
203  VclPtrInstance<LabelItemWindow> xFixedText(pParent, aText);
204 
205  xFixedText->Show();
206 
207  return xFixedText;
208 }
209 
211 
212 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
213  :SfxToolBoxControl( nSlotId, nId, rTbx )
214 {
215  rTbx.SetItemWindowNonInteractive(nId, true);
216 }
217 
219 {
220 }
221 
223 {
224  OUString aText(SvxResId(RID_STR_REC_FROM_TEXT));
225  VclPtrInstance<LabelItemWindow> xFixedText(pParent, aText);
226 
227  xFixedText->Show();
228 
229  return xFixedText;
230 }
231 
233 
234 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
235  : SfxToolBoxControl( nSlotId, nId, rTbx )
236 {
237  rTbx.SetItemWindowNonInteractive(nId, true);
238 }
239 
241 {
242 }
243 
245 {
246  OUString const aSample("123456");
248  m_xFixedText->set_label("");
249 
250  m_xFixedText->Show();
251 
252  return m_xFixedText;
253 }
254 
255 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
256 {
257  // setting the FixedText
258  if (GetSlotId() != SID_FM_RECORD_TOTAL)
259  return;
260 
261  OUString aText;
262  if (pState)
263  aText = static_cast<const SfxStringItem*>(pState)->GetValue();
264  else
265  aText = "?";
266 
267  m_xFixedText->set_label(aText);
268 
269  SfxToolBoxControl::StateChanged( nSID, eState,pState );
270 }
271 
273 
274 
275 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
276  :SfxToolBoxControl( nSlotId, nId, rTbx )
277 {
278  rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
279 
280  AllSettings aSettings = rTbx.GetSettings();
281  MouseSettings aMouseSettings = aSettings.GetMouseSettings();
282  aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4);
283  aSettings.SetMouseSettings(aMouseSettings);
284  rTbx.SetSettings(aSettings, true);
285 }
286 
288 
289 
290 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
291  :SfxToolBoxControl( nSlotId, nId, rTbx )
292 {
293  rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
294 }
295 
296 
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 GetValue() const
SvxFmTbxCtlAbsRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:108
long AdjustWidth(long n)
VclPtr< LabelItemWindow > m_xFixedText
Definition: tbxform.hxx:88
std::string GetValue
ToolBox & GetToolBox() const
virtual ~SvxFmTbxCtlRecFromText() override
Definition: tbxform.cxx:218
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
virtual void dispose() override
Definition: tbxform.cxx:189
SvxFmAbsRecWin(vcl::Window *_pParent, SfxToolBoxControl *_pController)
Definition: tbxform.cxx:36
SvxFmTbxCtlRecFromText(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:212
sal_Int16 nId
virtual ~SvxFmTbxCtlRecText() override
Definition: tbxform.cxx:156
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tbxform.cxx:255
virtual void SetSettings(const AllSettings &rSettings) override
std::unique_ptr< weld::Label > m_xLabel
virtual ~SvxFmTbxCtlAbsRec() override
Definition: tbxform.cxx:114
virtual ~SvxFmTbxCtlRecTotal() override
Definition: tbxform.cxx:240
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SfxToolBoxControl * m_pController
Definition: tbxform.hxx:45
virtual ~LabelItemWindow() override
Definition: tbxform.cxx:195
void SetItemWindowNonInteractive(sal_uInt16 nItemId, bool bNonInteractive)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
sal_uLong GetButtonRepeat() const
virtual void GetFocus() override
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tbxform.cxx:118
IMPL_LINK(SvxFmAbsRecWin, KeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: tbxform.cxx:94
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:244
LabelItemWindow(vcl::Window *pParent, const OUString &rLabel)
Definition: tbxform.cxx:160
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:200
std::unique_ptr< weld::Entry > m_xWidget
Definition: tbxform.hxx:37
std::unique_ptr< weld::Label > m_xLabel
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState)
virtual void GetFocus() override
Definition: tbxform.cxx:54
IMPL_LINK_NOARG(SvxFmAbsRecWin, FocusOutHdl, weld::Widget &, void)
Definition: tbxform.cxx:89
SvxFmTbxCtlRecText(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:150
#define DBG_ASSERT(sCon, aError)
uno_Any a
SvxFmTbxCtlRecTotal(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:234
void SetMouseSettings(const MouseSettings &rSet)
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
void set_text(const OUString &rText)
Definition: tbxform.hxx:32
vcl::Window * GetItemWindow(sal_uInt16 nItemId) const
virtual ~SvxFmAbsRecWin() override
Definition: tbxform.cxx:61
const AllSettings & GetSettings() const
virtual void dispose() override
Definition: tbxform.cxx:48
SvxFmTbxPrevRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:290
void reset(reference_type *pBody)
void FirePosition(bool _bForce)
Definition: tbxform.cxx:66
SfxItemState
virtual void dispose() override
unsigned short GetId() const
SvxFmTbxNextRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:275
unsigned short GetSlotId() const
SFX_IMPL_TOOLBOX_CONTROL(SvxFmTbxCtlAbsRec, SfxInt32Item)
const MouseSettings & GetMouseSettings() const
OUString get_label() const
Definition: tbxform.cxx:184
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:143
void SetButtonRepeat(sal_uLong nRepeat)
void SetOptimalSize()
Definition: tbxform.cxx:171
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:222
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
void set_label(const OUString &rLabel)
Definition: tbxform.cxx:179