LibreOffice Module vcl (master)  1
weldutils.hxx
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 
10 #ifndef INCLUDED_VCL_WELDUTILS_HXX
11 #define INCLUDED_VCL_WELDUTILS_HXX
12 
13 #include <com/sun/star/awt/XWindow.hpp>
14 #include <com/sun/star/frame/XDispatch.hpp>
15 #include <com/sun/star/frame/XFrame.hpp>
16 #include <com/sun/star/frame/XStatusListener.hpp>
17 #include <com/sun/star/uno/Reference.hxx>
19 #include <cppuhelper/compbase.hxx>
20 #include <tools/time.hxx>
21 #include <vcl/dllapi.h>
22 #include <vcl/formatter.hxx>
23 #include <vcl/weld.hxx>
24 
25 class CalendarWrapper;
26 
27 namespace weld
28 {
29 typedef cppu::WeakComponentImplHelper<css::awt::XWindow> TransportAsXWindow_Base;
30 
31 class VCL_DLLPUBLIC TransportAsXWindow : public TransportAsXWindow_Base
32 {
33 private:
34  osl::Mutex m_aHelperMtx;
37 
44 
45 public:
46  TransportAsXWindow(weld::Widget* pWeldWidget, weld::Builder* pWeldWidgetBuilder = nullptr)
47  : TransportAsXWindow_Base(m_aHelperMtx)
48  , m_pWeldWidget(pWeldWidget)
49  , m_pWeldWidgetBuilder(pWeldWidgetBuilder)
50  , m_aWindowListeners(m_aHelperMtx)
51  , m_aKeyListeners(m_aHelperMtx)
52  , m_aFocusListeners(m_aHelperMtx)
53  , m_aMouseListeners(m_aHelperMtx)
54  , m_aMotionListeners(m_aHelperMtx)
55  , m_aPaintListeners(m_aHelperMtx)
56  {
57  }
58 
59  weld::Widget* getWidget() const { return m_pWeldWidget; }
60 
61  weld::Builder* getBuilder() const { return m_pWeldWidgetBuilder; }
62 
63  virtual void clear()
64  {
65  m_pWeldWidget = nullptr;
66  m_pWeldWidgetBuilder = nullptr;
67  }
68 
69  // css::awt::XWindow
70  void SAL_CALL setPosSize(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int16) override
71  {
72  throw css::uno::RuntimeException("not implemented");
73  }
74 
75  css::awt::Rectangle SAL_CALL getPosSize() override
76  {
77  throw css::uno::RuntimeException("not implemented");
78  }
79 
80  void SAL_CALL setVisible(sal_Bool bVisible) override { m_pWeldWidget->set_visible(bVisible); }
81 
82  void SAL_CALL setEnable(sal_Bool bSensitive) override
83  {
84  m_pWeldWidget->set_sensitive(bSensitive);
85  }
86 
87  void SAL_CALL setFocus() override { m_pWeldWidget->grab_focus(); }
88 
89  void SAL_CALL
90  addWindowListener(const css::uno::Reference<css::awt::XWindowListener>& rListener) override
91  {
92  m_aWindowListeners.addInterface(rListener);
93  }
94 
95  void SAL_CALL
96  removeWindowListener(const css::uno::Reference<css::awt::XWindowListener>& rListener) override
97  {
98  m_aWindowListeners.removeInterface(rListener);
99  }
100 
101  void SAL_CALL
102  addFocusListener(const css::uno::Reference<css::awt::XFocusListener>& rListener) override
103  {
104  m_aFocusListeners.addInterface(rListener);
105  }
106 
107  void SAL_CALL
108  removeFocusListener(const css::uno::Reference<css::awt::XFocusListener>& rListener) override
109  {
110  m_aFocusListeners.removeInterface(rListener);
111  }
112 
113  void SAL_CALL
114  addKeyListener(const css::uno::Reference<css::awt::XKeyListener>& rListener) override
115  {
116  m_aKeyListeners.addInterface(rListener);
117  }
118 
119  void SAL_CALL
120  removeKeyListener(const css::uno::Reference<css::awt::XKeyListener>& rListener) override
121  {
122  m_aKeyListeners.removeInterface(rListener);
123  }
124 
125  void SAL_CALL
126  addMouseListener(const css::uno::Reference<css::awt::XMouseListener>& rListener) override
127  {
128  m_aMouseListeners.addInterface(rListener);
129  }
130 
131  void SAL_CALL
132  removeMouseListener(const css::uno::Reference<css::awt::XMouseListener>& rListener) override
133  {
134  m_aMouseListeners.removeInterface(rListener);
135  }
136 
137  void SAL_CALL addMouseMotionListener(
138  const css::uno::Reference<css::awt::XMouseMotionListener>& rListener) override
139  {
140  m_aMotionListeners.addInterface(rListener);
141  }
142 
144  const css::uno::Reference<css::awt::XMouseMotionListener>& rListener) override
145  {
146  m_aMotionListeners.removeInterface(rListener);
147  }
148 
149  void SAL_CALL
150  addPaintListener(const css::uno::Reference<css::awt::XPaintListener>& rListener) override
151  {
152  m_aPaintListeners.addInterface(rListener);
153  }
154 
155  void SAL_CALL
156  removePaintListener(const css::uno::Reference<css::awt::XPaintListener>& rListener) override
157  {
158  m_aPaintListeners.removeInterface(rListener);
159  }
160 };
161 
162 // don't export to avoid duplicate WeakImplHelper definitions with MSVC
163 class SAL_DLLPUBLIC_TEMPLATE WidgetStatusListener_Base
164  : public cppu::WeakImplHelper<css::frame::XStatusListener>
165 {
166 };
167 
169 {
170 public:
171  WidgetStatusListener(weld::Widget* widget, const OUString& rCommand);
172 
173 private:
177  css::uno::Reference<css::frame::XDispatch> mxDispatch;
178  css::util::URL maCommandURL;
179  css::uno::Reference<css::frame::XFrame> mxFrame;
180 
181 public:
182  void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override;
183 
184  void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) override;
185 
186  const css::uno::Reference<css::frame::XFrame>& getFrame() const { return mxFrame; }
187 
188  void startListening();
189 
190  void dispose();
191 };
192 
194 {
195 public:
196  EntryFormatter(weld::Entry& rEntry);
198 
199  weld::Entry& get_widget() { return m_rEntry; }
200 
201  // public Formatter overrides, drives interactions with the Entry
202  virtual Selection GetEntrySelection() const override;
203  virtual OUString GetEntryText() const override;
204  virtual void SetEntryText(const OUString& rText, const Selection& rSel) override;
205  virtual void SetEntryTextColor(const Color* pColor) override;
206  virtual SelectionOptions GetEntrySelectionOptions() const override;
207  virtual void FieldModified() override;
208 
209  // public Formatter overrides, drives optional SpinButton settings
210  virtual void ClearMinValue() override;
211  virtual void SetMinValue(double dMin) override;
212  virtual void ClearMaxValue() override;
213  virtual void SetMaxValue(double dMin) override;
214 
215  virtual void SetSpinSize(double dStep) override;
216 
217  void SetEntrySelectionOptions(SelectionOptions eOptions) { m_eOptions = eOptions; }
218 
219  /* EntryFormatter will set listeners to "changed" and "focus-out" of the
220  Entry so users that want to add their own listeners to those must set
221  them through this formatter and not directly on that entry.
222 
223  If EntryFormatter is used with a weld::FormattedSpinButton this is
224  handled transparently by the FormattedSpinButton for the user and the
225  handlers can be set on the FormattedSpinButton
226  */
227  void connect_changed(const Link<weld::Entry&, void>& rLink) { m_aModifyHdl = rLink; }
228  void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_aFocusOutHdl = rLink; }
229 
230  virtual ~EntryFormatter() override;
231 
232 private:
238  DECL_DLLPRIVATE_LINK(ModifyHdl, weld::Entry&, void);
239  DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void);
240  void Init();
241 
242  // private Formatter overrides
243  virtual void UpdateCurrentValue(double dCurrentValue) override;
244 };
245 
247 {
248 public:
251 
252  virtual ~DoubleNumericFormatter() override;
253 
254 private:
255  virtual bool CheckText(const OUString& sText) const override;
256 
257  virtual void FormatChanged(FORMAT_CHANGE_TYPE nWhat) override;
258  void ResetConformanceTester();
259 
260  std::unique_ptr<validation::NumberValidator> m_pNumberValidator;
261 };
262 
264 {
265 public:
268 
269  void SetUseThousandSep(bool b);
270  void SetCurrencySymbol(const OUString& rStr);
271 
272  virtual ~LongCurrencyFormatter() override;
273 
274 private:
275  DECL_LINK(FormatOutputHdl, LinkParamNone*, bool);
276  DECL_LINK(ParseInputHdl, sal_Int64*, TriState);
277 
278  void Init();
279 
282 };
283 
285 {
286 public:
287  TimeFormatter(weld::Entry& rEntry);
289 
290  void SetExtFormat(ExtTimeFieldFormat eFormat);
291  void SetDuration(bool bDuration);
292  void SetTimeFormat(TimeFieldFormat eTimeFormat);
293 
294  void SetMin(const tools::Time& rNewMin);
295  void SetMax(const tools::Time& rNewMax);
296 
297  void SetTime(const tools::Time& rNewTime);
299 
300  virtual ~TimeFormatter() override;
301 
302 private:
303  DECL_LINK(FormatOutputHdl, LinkParamNone*, bool);
304  DECL_LINK(ParseInputHdl, sal_Int64*, TriState);
305  DECL_LINK(CursorChangedHdl, weld::Entry&, void);
306 
307  void Init();
308 
309  static tools::Time ConvertValue(int nValue);
310  static int ConvertValue(const tools::Time& rTime);
311 
312  OUString FormatNumber(int nValue) const;
313 
317 };
318 
320 {
321 public:
322  DateFormatter(weld::Entry& rEntry);
323 
324  void SetMin(const Date& rNewMin);
325  void SetMax(const Date& rNewMax);
326 
327  void SetDate(const Date& rNewDate);
328  Date GetDate();
329 
330  void SetExtDateFormat(ExtDateFieldFormat eFormat);
331  void SetShowDateCentury(bool bShowCentury);
332 
333  virtual ~DateFormatter() override;
334 
335 private:
336  DECL_LINK(FormatOutputHdl, LinkParamNone*, bool);
337  DECL_LINK(ParseInputHdl, sal_Int64*, TriState);
338  DECL_LINK(CursorChangedHdl, weld::Entry&, void);
339 
340  void Init();
341  CalendarWrapper& GetCalendarWrapper() const;
342 
343  OUString FormatNumber(int nValue) const;
344 
346  mutable std::unique_ptr<CalendarWrapper> m_xCalendarWrapper;
347 };
348 
350 {
351 public:
352  PatternFormatter(weld::Entry& rEntry);
353  ~PatternFormatter();
354 
355  weld::Entry& get_widget() { return m_rEntry; }
356 
357  void SetMask(const OString& rEditMask, const OUString& rLiteralMask);
358  void SetStrictFormat(bool bStrict);
359  void ReformatAll();
360 
361  /* PatternFormatter will set listeners to "changed", "focus-out", "focus-in"
362  and "key-press" of the Entry so users that want to add their own listeners
363  to those must set them through this formatter and not directly on that entry.
364  */
365  void connect_changed(const Link<weld::Entry&, void>& rLink) { m_aModifyHdl = rLink; }
366  void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_aFocusOutHdl = rLink; }
367  void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_aFocusInHdl = rLink; }
368  void connect_key_press(const Link<const KeyEvent&, bool>& rLink) { m_aKeyPressHdl = rLink; }
369 
370  void Modify();
371 
372 private:
382  OString m_aEditMask;
383  OUString m_aLiteralMask;
384 
385  void EntryGainFocus();
386  void EntryLostFocus();
387  DECL_DLLPRIVATE_LINK(ModifyHdl, weld::Entry&, void);
388  DECL_DLLPRIVATE_LINK(FocusInHdl, weld::Widget&, void);
389  DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void);
390  DECL_DLLPRIVATE_LINK(KeyInputHdl, const KeyEvent&, bool);
391 };
392 
393 // get the row the iterator is on
394 VCL_DLLPUBLIC size_t GetAbsPos(const weld::TreeView& rTreeView, const weld::TreeIter& rIter);
395 
396 // an entry is visible if all parents are expanded
397 VCL_DLLPUBLIC bool IsEntryVisible(const weld::TreeView& rTreeView, const weld::TreeIter& rIter);
398 
399 // A Parent's Children are turned into Children of the Parent which comes next in hierarchy
401 
402 // return the min height of a weld::Entry
404 }
405 
406 #endif
407 
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
comphelper::OInterfaceContainerHelper2 m_aMouseListeners
Definition: weldutils.hxx:41
Link< const KeyEvent &, bool > m_aKeyPressHdl
Definition: weldutils.hxx:377
weld::Builder * getBuilder() const
Definition: weldutils.hxx:61
void Init()
weld::Widget * m_pWeldWidget
Definition: weldutils.hxx:35
ExtTimeFieldFormat
Definition: vclenum.hxx:148
comphelper::OInterfaceContainerHelper2 m_aPaintListeners
Definition: weldutils.hxx:43
TimeFieldFormat
Definition: vclenum.hxx:28
TransportAsXWindow(weld::Widget *pWeldWidget, weld::Builder *pWeldWidgetBuilder=nullptr)
Definition: weldutils.hxx:46
size_t GetAbsPos(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:394
void SAL_CALL addFocusListener(const css::uno::Reference< css::awt::XFocusListener > &rListener) override
Definition: weldutils.hxx:102
SelectionOptions
Definition: settings.hxx:181
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void SAL_CALL addMouseMotionListener(const css::uno::Reference< css::awt::XMouseMotionListener > &rListener) override
Definition: weldutils.hxx:137
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
FORMAT_CHANGE_TYPE
Definition: formatter.hxx:74
Any GetTime(const OUString &val)
Link< weld::Entry &, void > m_aModifyHdl
Definition: weldutils.hxx:235
void RemoveParentKeepChildren(weld::TreeView &rTreeView, weld::TreeIter &rParent)
Definition: weldutils.cxx:114
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
comphelper::OInterfaceContainerHelper2 m_aMotionListeners
Definition: weldutils.hxx:42
TimeFormat m_eTimeFormat
Definition: weldutils.hxx:315
void SAL_CALL removeMouseListener(const css::uno::Reference< css::awt::XMouseListener > &rListener) override
Definition: weldutils.hxx:132
void SAL_CALL removeKeyListener(const css::uno::Reference< css::awt::XKeyListener > &rListener) override
Definition: weldutils.hxx:120
virtual void clear()
Definition: weldutils.hxx:63
void connect_changed(const Link< weld::Entry &, void > &rLink)
Definition: weldutils.hxx:227
void connect_focus_out(const Link< weld::Widget &, void > &rLink)
Definition: weldutils.hxx:366
TimeFormat
Definition: vclenum.hxx:143
void SAL_CALL addPaintListener(const css::uno::Reference< css::awt::XPaintListener > &rListener) override
Definition: weldutils.hxx:150
Link< weld::Widget &, void > m_aFocusOutHdl
Definition: weldutils.hxx:236
css::uno::Reference< css::frame::XDispatch > mxDispatch
The widget on which actions are performed.
Definition: weldutils.hxx:177
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
void SAL_CALL addKeyListener(const css::uno::Reference< css::awt::XKeyListener > &rListener) override
Definition: weldutils.hxx:114
css::util::URL maCommandURL
Definition: weldutils.hxx:178
void SAL_CALL removePaintListener(const css::uno::Reference< css::awt::XPaintListener > &rListener) override
Definition: weldutils.hxx:156
ExtDateFieldFormat m_eFormat
Definition: weldutils.hxx:345
weld::Entry & m_rEntry
Definition: weldutils.hxx:233
Link< weld::Widget &, void > m_aFocusInHdl
Definition: weldutils.hxx:375
void connect_focus_out(const Link< weld::Widget &, void > &rLink)
Definition: weldutils.hxx:228
void connect_focus_in(const Link< weld::Widget &, void > &rLink)
Definition: weldutils.hxx:367
cppu::WeakComponentImplHelper< css::awt::XWindow > TransportAsXWindow_Base
Definition: weldutils.hxx:29
void SAL_CALL setEnable(sal_Bool bSensitive) override
Definition: weldutils.hxx:82
void SAL_CALL setFocus() override
Definition: weldutils.hxx:87
comphelper::OInterfaceContainerHelper2 m_aKeyListeners
Definition: weldutils.hxx:39
unsigned char sal_Bool
Link< weld::Entry &, void > m_aModifyHdl
Definition: weldutils.hxx:374
comphelper::OInterfaceContainerHelper2 m_aFocusListeners
Definition: weldutils.hxx:40
TimeFieldFormat m_eFormat
Definition: weldutils.hxx:314
void SAL_CALL setVisible(sal_Bool bVisible) override
Definition: weldutils.hxx:80
weld::Entry & get_widget()
Definition: weldutils.hxx:199
void SAL_CALL removeFocusListener(const css::uno::Reference< css::awt::XFocusListener > &rListener) override
Definition: weldutils.hxx:108
Link< weld::Widget &, void > m_aFocusOutHdl
Definition: weldutils.hxx:376
void SAL_CALL addWindowListener(const css::uno::Reference< css::awt::XWindowListener > &rListener) override
Definition: weldutils.hxx:90
ExtDateFieldFormat
Definition: vclenum.hxx:156
weld::Entry & get_widget()
Definition: weldutils.hxx:355
weld::Builder * m_pWeldWidgetBuilder
Definition: weldutils.hxx:36
std::unique_ptr< CalendarWrapper > m_xCalendarWrapper
Definition: weldutils.hxx:346
std::unique_ptr< validation::NumberValidator > m_pNumberValidator
Definition: weldutils.hxx:260
virtual void grab_focus()=0
void SAL_CALL removeMouseMotionListener(const css::uno::Reference< css::awt::XMouseMotionListener > &rListener) override
Definition: weldutils.hxx:143
void connect_key_press(const Link< const KeyEvent &, bool > &rLink)
Definition: weldutils.hxx:368
css::uno::Reference< css::frame::XFrame > mxFrame
Definition: weldutils.hxx:179
comphelper::OInterfaceContainerHelper2 m_aWindowListeners
Definition: weldutils.hxx:38
void SAL_CALL addMouseListener(const css::uno::Reference< css::awt::XMouseListener > &rListener) override
Definition: weldutils.hxx:126
sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
Definition: field.cxx:1047
weld::Entry & m_rEntry
Definition: weldutils.hxx:373
void SAL_CALL removeWindowListener(const css::uno::Reference< css::awt::XWindowListener > &rListener) override
Definition: weldutils.hxx:96
SelectionOptions m_eOptions
Definition: weldutils.hxx:237
void dispose()
TriState
void connect_changed(const Link< weld::Entry &, void > &rLink)
Definition: weldutils.hxx:365
void SetEntrySelectionOptions(SelectionOptions eOptions)
Definition: weldutils.hxx:217
const css::uno::Reference< css::frame::XFrame > & getFrame() const
Definition: weldutils.hxx:186
int GetMinimumEditHeight()
Definition: weldutils.cxx:486
bool IsEntryVisible(const weld::TreeView &rTreeView, const weld::TreeIter &rIter)
Definition: builder.cxx:412
void SAL_CALL setPosSize(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int16) override
Definition: weldutils.hxx:70
virtual void set_visible(bool visible)
Definition: weld.hxx:96
weld::Widget * getWidget() const
Definition: weldutils.hxx:59
virtual void set_sensitive(bool sensitive)=0
sal_Int16 nValue
css::awt::Rectangle SAL_CALL getPosSize() override
Definition: weldutils.hxx:75
weld::FormattedSpinButton * m_pSpinButton
Definition: weldutils.hxx:234