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 
27 #include <svx/dialmgr.hxx>
28 #include <svx/labelitemwindow.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 
161 {
162  OUString aText(SvxResId(RID_STR_REC_TEXT));
163  VclPtrInstance<LabelItemWindow> xFixedText(pParent, aText);
164 
165  xFixedText->Show();
166 
167  return xFixedText;
168 }
169 
171 
172 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
173  :SfxToolBoxControl( nSlotId, nId, rTbx )
174 {
175  rTbx.SetItemWindowNonInteractive(nId, true);
176 }
177 
179 {
180 }
181 
183 {
184  OUString aText(SvxResId(RID_STR_REC_FROM_TEXT));
185  VclPtrInstance<LabelItemWindow> xFixedText(pParent, aText);
186 
187  xFixedText->Show();
188 
189  return xFixedText;
190 }
191 
193 
194 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
195  : SfxToolBoxControl( nSlotId, nId, rTbx )
196 {
197  rTbx.SetItemWindowNonInteractive(nId, true);
198 }
199 
201 {
202 }
203 
205 {
207  m_xFixedText->set_label("");
208 
209  m_xFixedText->Show();
210 
211  return m_xFixedText;
212 }
213 
214 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
215 {
216  // setting the FixedText
217  if (GetSlotId() != SID_FM_RECORD_TOTAL)
218  return;
219 
220  OUString aText;
221  if (pState)
222  aText = static_cast<const SfxStringItem*>(pState)->GetValue();
223  else
224  aText = "?";
225 
226  m_xFixedText->set_label(aText);
227 
228  SfxToolBoxControl::StateChanged( nSID, eState,pState );
229 }
230 
232 
233 
234 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
235  :SfxToolBoxControl( nSlotId, nId, rTbx )
236 {
237  rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
238 
239  AllSettings aSettings = rTbx.GetSettings();
240  MouseSettings aMouseSettings = aSettings.GetMouseSettings();
241  aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4);
242  aSettings.SetMouseSettings(aMouseSettings);
243  rTbx.SetSettings(aSettings, true);
244 }
245 
247 
248 
249 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
250  :SfxToolBoxControl( nSlotId, nId, rTbx )
251 {
252  rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | ToolBoxItemBits::REPEAT);
253 }
254 
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 GetValue() const
SvxFmTbxCtlAbsRec(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:108
VclPtr< LabelItemWindow > m_xFixedText
Definition: tbxform.hxx:88
std::string GetValue
ToolBox & GetToolBox() const
virtual ~SvxFmTbxCtlRecFromText() override
Definition: tbxform.cxx:178
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
SvxFmAbsRecWin(vcl::Window *_pParent, SfxToolBoxControl *_pController)
Definition: tbxform.cxx:36
virtual void SetSizePixel(const Size &rNewSize)
SvxFmTbxCtlRecFromText(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxform.cxx:172
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:214
virtual void SetSettings(const AllSettings &rSettings) override
virtual ~SvxFmTbxCtlAbsRec() override
Definition: tbxform.cxx:114
virtual ~SvxFmTbxCtlRecTotal() override
Definition: tbxform.cxx:200
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SfxToolBoxControl * m_pController
Definition: tbxform.hxx:45
void SetItemWindowNonInteractive(sal_uInt16 nItemId, bool bNonInteractive)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:182
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:143
std::unique_ptr< weld::Entry > m_xWidget
Definition: tbxform.hxx:37
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:194
void SetMouseSettings(const MouseSettings &rSet)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:160
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
void set_text(const OUString &rText)
Definition: tbxform.hxx:32
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: tbxform.cxx:204
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:249
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:234
unsigned short GetSlotId() const
SFX_IMPL_TOOLBOX_CONTROL(SvxFmTbxCtlAbsRec, SfxInt32Item)
const MouseSettings & GetMouseSettings() const
void SetButtonRepeat(sal_uLong nRepeat)
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
void set_label(const OUString &rLabel)