nss: upgrade to release 3.73
[LibreOffice.git] / include / vcl / weldutils.hxx
blob9a29e89d7b5f456422477175831177cb549f9b63
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #ifndef INCLUDED_VCL_WELDUTILS_HXX
11 #define INCLUDED_VCL_WELDUTILS_HXX
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>
18 #include <comphelper/interfacecontainer2.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>
25 class CalendarWrapper;
27 namespace weld
29 typedef cppu::WeakComponentImplHelper<css::awt::XWindow> TransportAsXWindow_Base;
31 class VCL_DLLPUBLIC TransportAsXWindow : public TransportAsXWindow_Base
33 private:
34 osl::Mutex m_aHelperMtx;
35 weld::Widget* m_pWeldWidget;
36 weld::Builder* m_pWeldWidgetBuilder;
38 comphelper::OInterfaceContainerHelper2 m_aWindowListeners;
39 comphelper::OInterfaceContainerHelper2 m_aKeyListeners;
40 comphelper::OInterfaceContainerHelper2 m_aFocusListeners;
41 comphelper::OInterfaceContainerHelper2 m_aMouseListeners;
42 comphelper::OInterfaceContainerHelper2 m_aMotionListeners;
43 comphelper::OInterfaceContainerHelper2 m_aPaintListeners;
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)
59 weld::Widget* getWidget() const { return m_pWeldWidget; }
61 weld::Builder* getBuilder() const { return m_pWeldWidgetBuilder; }
63 virtual void clear()
65 m_pWeldWidget = nullptr;
66 m_pWeldWidgetBuilder = nullptr;
69 // css::awt::XWindow
70 void SAL_CALL setPosSize(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int16) override
72 throw css::uno::RuntimeException("not implemented");
75 css::awt::Rectangle SAL_CALL getPosSize() override
77 throw css::uno::RuntimeException("not implemented");
80 void SAL_CALL setVisible(sal_Bool bVisible) override { m_pWeldWidget->set_visible(bVisible); }
82 void SAL_CALL setEnable(sal_Bool bSensitive) override
84 m_pWeldWidget->set_sensitive(bSensitive);
87 void SAL_CALL setFocus() override { m_pWeldWidget->grab_focus(); }
89 void SAL_CALL
90 addWindowListener(const css::uno::Reference<css::awt::XWindowListener>& rListener) override
92 m_aWindowListeners.addInterface(rListener);
95 void SAL_CALL
96 removeWindowListener(const css::uno::Reference<css::awt::XWindowListener>& rListener) override
98 m_aWindowListeners.removeInterface(rListener);
101 void SAL_CALL
102 addFocusListener(const css::uno::Reference<css::awt::XFocusListener>& rListener) override
104 m_aFocusListeners.addInterface(rListener);
107 void SAL_CALL
108 removeFocusListener(const css::uno::Reference<css::awt::XFocusListener>& rListener) override
110 m_aFocusListeners.removeInterface(rListener);
113 void SAL_CALL
114 addKeyListener(const css::uno::Reference<css::awt::XKeyListener>& rListener) override
116 m_aKeyListeners.addInterface(rListener);
119 void SAL_CALL
120 removeKeyListener(const css::uno::Reference<css::awt::XKeyListener>& rListener) override
122 m_aKeyListeners.removeInterface(rListener);
125 void SAL_CALL
126 addMouseListener(const css::uno::Reference<css::awt::XMouseListener>& rListener) override
128 m_aMouseListeners.addInterface(rListener);
131 void SAL_CALL
132 removeMouseListener(const css::uno::Reference<css::awt::XMouseListener>& rListener) override
134 m_aMouseListeners.removeInterface(rListener);
137 void SAL_CALL addMouseMotionListener(
138 const css::uno::Reference<css::awt::XMouseMotionListener>& rListener) override
140 m_aMotionListeners.addInterface(rListener);
143 void SAL_CALL removeMouseMotionListener(
144 const css::uno::Reference<css::awt::XMouseMotionListener>& rListener) override
146 m_aMotionListeners.removeInterface(rListener);
149 void SAL_CALL
150 addPaintListener(const css::uno::Reference<css::awt::XPaintListener>& rListener) override
152 m_aPaintListeners.addInterface(rListener);
155 void SAL_CALL
156 removePaintListener(const css::uno::Reference<css::awt::XPaintListener>& rListener) override
158 m_aPaintListeners.removeInterface(rListener);
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>
168 class VCL_DLLPUBLIC WidgetStatusListener final : public WidgetStatusListener_Base
170 public:
171 WidgetStatusListener(weld::Widget* widget, const OUString& rCommand);
173 private:
174 weld::Widget* mWidget; /** The widget on which actions are performed */
176 /** Dispatcher. Need to keep a reference to it as long as this StatusListener exists. */
177 css::uno::Reference<css::frame::XDispatch> mxDispatch;
178 css::util::URL maCommandURL;
179 css::uno::Reference<css::frame::XFrame> mxFrame;
181 public:
182 void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override;
184 void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) override;
186 const css::uno::Reference<css::frame::XFrame>& getFrame() const { return mxFrame; }
188 void startListening();
190 void dispose();
193 class VCL_DLLPUBLIC EntryFormatter : public Formatter
195 public:
196 EntryFormatter(weld::Entry& rEntry);
197 EntryFormatter(weld::FormattedSpinButton& rSpinButton);
199 weld::Entry& get_widget() { return m_rEntry; }
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;
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;
215 virtual void SetSpinSize(double dStep) override;
217 void SetEntrySelectionOptions(SelectionOptions eOptions) { m_eOptions = eOptions; }
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.
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
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; }
230 virtual ~EntryFormatter() override;
232 private:
233 weld::Entry& m_rEntry;
234 weld::FormattedSpinButton* m_pSpinButton;
235 Link<weld::Entry&, void> m_aModifyHdl;
236 Link<weld::Widget&, void> m_aFocusOutHdl;
237 SelectionOptions m_eOptions;
238 DECL_DLLPRIVATE_LINK(ModifyHdl, weld::Entry&, void);
239 DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void);
240 void Init();
242 // private Formatter overrides
243 virtual void UpdateCurrentValue(double dCurrentValue) override;
246 class VCL_DLLPUBLIC DoubleNumericFormatter final : public EntryFormatter
248 public:
249 DoubleNumericFormatter(weld::Entry& rEntry);
250 DoubleNumericFormatter(weld::FormattedSpinButton& rSpinButton);
252 virtual ~DoubleNumericFormatter() override;
254 private:
255 virtual bool CheckText(const OUString& sText) const override;
257 virtual void FormatChanged(FORMAT_CHANGE_TYPE nWhat) override;
258 void ResetConformanceTester();
260 std::unique_ptr<validation::NumberValidator> m_pNumberValidator;
263 class VCL_DLLPUBLIC LongCurrencyFormatter final : public EntryFormatter
265 public:
266 LongCurrencyFormatter(weld::Entry& rEntry);
267 LongCurrencyFormatter(weld::FormattedSpinButton& rSpinButton);
269 void SetUseThousandSep(bool b);
270 void SetCurrencySymbol(const OUString& rStr);
272 virtual ~LongCurrencyFormatter() override;
274 private:
275 DECL_LINK(FormatOutputHdl, LinkParamNone*, bool);
276 DECL_LINK(ParseInputHdl, sal_Int64*, TriState);
278 void Init();
280 OUString m_aCurrencySymbol;
281 bool m_bThousandSep;
284 class VCL_DLLPUBLIC TimeFormatter final : public EntryFormatter
286 public:
287 TimeFormatter(weld::Entry& rEntry);
288 TimeFormatter(weld::FormattedSpinButton& rSpinButton);
290 void SetExtFormat(ExtTimeFieldFormat eFormat);
291 void SetDuration(bool bDuration);
292 void SetTimeFormat(TimeFieldFormat eTimeFormat);
294 void SetMin(const tools::Time& rNewMin);
295 void SetMax(const tools::Time& rNewMax);
297 void SetTime(const tools::Time& rNewTime);
298 tools::Time GetTime();
300 virtual ~TimeFormatter() override;
302 private:
303 DECL_LINK(FormatOutputHdl, LinkParamNone*, bool);
304 DECL_LINK(ParseInputHdl, sal_Int64*, TriState);
305 DECL_LINK(CursorChangedHdl, weld::Entry&, void);
307 void Init();
309 static tools::Time ConvertValue(int nValue);
310 static int ConvertValue(const tools::Time& rTime);
312 OUString FormatNumber(int nValue) const;
314 TimeFieldFormat m_eFormat;
315 TimeFormat m_eTimeFormat;
316 bool m_bDuration;
319 class VCL_DLLPUBLIC DateFormatter final : public EntryFormatter
321 public:
322 DateFormatter(weld::Entry& rEntry);
324 void SetMin(const Date& rNewMin);
325 void SetMax(const Date& rNewMax);
327 void SetDate(const Date& rNewDate);
328 Date GetDate();
330 void SetExtDateFormat(ExtDateFieldFormat eFormat);
331 void SetShowDateCentury(bool bShowCentury);
333 virtual ~DateFormatter() override;
335 private:
336 DECL_LINK(FormatOutputHdl, LinkParamNone*, bool);
337 DECL_LINK(ParseInputHdl, sal_Int64*, TriState);
338 DECL_LINK(CursorChangedHdl, weld::Entry&, void);
340 void Init();
341 CalendarWrapper& GetCalendarWrapper() const;
343 OUString FormatNumber(int nValue) const;
345 ExtDateFieldFormat m_eFormat;
346 mutable std::unique_ptr<CalendarWrapper> m_xCalendarWrapper;
349 class VCL_DLLPUBLIC PatternFormatter final
351 public:
352 PatternFormatter(weld::Entry& rEntry);
353 ~PatternFormatter();
355 weld::Entry& get_widget() { return m_rEntry; }
357 void SetMask(const OString& rEditMask, const OUString& rLiteralMask);
358 void SetStrictFormat(bool bStrict);
359 void ReformatAll();
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.
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; }
370 void Modify();
372 private:
373 weld::Entry& m_rEntry;
374 Link<weld::Entry&, void> m_aModifyHdl;
375 Link<weld::Widget&, void> m_aFocusInHdl;
376 Link<weld::Widget&, void> m_aFocusOutHdl;
377 Link<const KeyEvent&, bool> m_aKeyPressHdl;
378 bool m_bStrictFormat;
379 bool m_bSameMask;
380 bool m_bReformat;
381 bool m_bInPattKeyInput;
382 OString m_aEditMask;
383 OUString m_aLiteralMask;
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);
393 // get the row the iterator is on
394 VCL_DLLPUBLIC size_t GetAbsPos(const weld::TreeView& rTreeView, const weld::TreeIter& rIter);
396 // an entry is visible if all parents are expanded
397 VCL_DLLPUBLIC bool IsEntryVisible(const weld::TreeView& rTreeView, const weld::TreeIter& rIter);
399 // A Parent's Children are turned into Children of the Parent which comes next in hierarchy
400 VCL_DLLPUBLIC void RemoveParentKeepChildren(weld::TreeView& rTreeView, weld::TreeIter& rParent);
402 // return the min height of a weld::Entry
403 VCL_DLLPUBLIC int GetMinimumEditHeight();
406 #endif
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */