Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / vcl / weld.hxx
blob3a58608e190230acac608de7d8570533ba7dfa2b
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_WELD_HXX
11 #define INCLUDED_VCL_WELD_HXX
13 #include <basegfx/range/b2irange.hxx>
14 #include <rtl/ustring.hxx>
15 #include <tools/color.hxx>
16 #include <tools/date.hxx>
17 #include <tools/fldunit.hxx>
18 #include <tools/gen.hxx>
19 #include <tools/link.hxx>
20 #include <vcl/dllapi.h>
21 #include <utility>
22 #include <vcl/vclenum.hxx>
23 #include <vcl/font.hxx>
24 #include <vcl/vclptr.hxx>
25 #include <vcl/uitest/factory.hxx>
26 #include <vcl/windowstate.hxx>
28 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
29 #include <com/sun/star/accessibility/XAccessible.hpp>
31 #include <assert.h>
32 #include <memory>
33 #include <vector>
35 namespace com::sun::star::awt
37 class XWindow;
39 namespace com::sun::star::datatransfer::clipboard
41 class XClipboard;
43 namespace com::sun::star::datatransfer::dnd
45 class XDropTarget;
47 namespace com::sun::star::graphic
49 class XGraphic;
51 typedef css::uno::Reference<css::accessibility::XAccessible> a11yref;
52 typedef css::uno::Reference<css::accessibility::XAccessibleRelationSet> a11yrelationset;
53 enum class PointerStyle;
54 class CommandEvent;
55 class Formatter;
56 class InputContext;
57 class KeyEvent;
58 class MouseEvent;
59 class SvNumberFormatter;
60 class TransferDataContainer;
61 class OutputDevice;
62 class VirtualDevice;
63 struct SystemEnvData;
65 namespace vcl
67 class ILibreOfficeKitNotifier;
68 typedef OutputDevice RenderContext;
70 namespace tools
72 class JsonWriter;
75 class LOKTrigger;
77 namespace weld
79 class Container;
80 class DialogController;
82 class VCL_DLLPUBLIC Widget
84 friend class ::LOKTrigger;
86 protected:
87 Link<Widget&, void> m_aFocusInHdl;
88 Link<Widget&, void> m_aFocusOutHdl;
89 Link<Widget&, bool> m_aMnemonicActivateHdl;
90 Link<Widget&, void> m_aStyleUpdatedHdl;
91 Link<const Size&, void> m_aSizeAllocateHdl;
92 Link<const KeyEvent&, bool> m_aKeyPressHdl;
93 Link<const KeyEvent&, bool> m_aKeyReleaseHdl;
94 Link<const MouseEvent&, bool> m_aMousePressHdl;
95 Link<const MouseEvent&, bool> m_aMouseMotionHdl;
96 Link<const MouseEvent&, bool> m_aMouseReleaseHdl;
98 public:
99 virtual void set_sensitive(bool sensitive) = 0;
100 virtual bool get_sensitive() const = 0;
102 /* visibility */
104 virtual void show() = 0;
105 virtual void hide() = 0;
107 // This function simply calls show() or hide() but is convenient when the
108 // visibility depends on some condition
109 virtual void set_visible(bool visible)
111 if (visible)
112 show();
113 else
114 hide();
117 // return if this widget's visibility is true
118 virtual bool get_visible() const = 0;
120 // return if this widget's visibility and that of all its parents is true
121 virtual bool is_visible() const = 0;
123 /* focus */
125 // sets if this widget can own the keyboard focus
126 virtual void set_can_focus(bool bCanFocus) = 0;
128 // causes this widget to have the keyboard focus
129 virtual void grab_focus() = 0;
131 // returns if this widget has the keyboard focus
132 virtual bool has_focus() const = 0;
134 // if the widget that has focus is a child, which includes toplevel popup
135 // children, of this widget. So an Entry with an active popup (or dialog)
136 // has has_child_focus of true, but has_focus of false, while its popup is
137 // shown
138 virtual bool has_child_focus() const = 0;
140 // return if this widget has the keyboard focus within the active window
141 // TODO: review if this has any practical difference from has_focus()
142 virtual bool is_active() const = 0;
144 /* size */
145 virtual void set_size_request(int nWidth, int nHeight) = 0;
146 virtual Size get_size_request() const = 0;
147 virtual Size get_preferred_size() const = 0;
149 /* measure */
150 virtual float get_approximate_digit_width() const = 0;
151 virtual int get_text_height() const = 0;
152 virtual Size get_pixel_size(const OUString& rText) const = 0;
154 // The name of the widget in the GtkBuilder UI definition used to construct it.
155 virtual OUString get_buildable_name() const = 0;
157 Typically there is no need to change the buildable name at runtime, changing
158 the id in .ui file itself is preferred.
160 But for ui-testing purposes it can sometimes be useful to rename
161 different widgets, that were loaded from the same .ui, to unique names
162 in order to distinguish between them
164 virtual void set_buildable_name(const OUString& rName) = 0;
167 The help id of the widget used to identify help for this widget.
169 By default the help id of a widget is a path-like sequence of (load-time)
170 buildable-names from the widgets UI definition ancestor to this widget,
171 e.g. grandparent/parent/widget.
173 The default can be overwritten with set_help_id
175 virtual OUString get_help_id() const = 0;
176 virtual void set_help_id(const OUString& rName) = 0;
178 virtual void set_grid_left_attach(int nAttach) = 0;
179 virtual int get_grid_left_attach() const = 0;
180 virtual void set_grid_width(int nCols) = 0;
181 virtual void set_grid_top_attach(int nAttach) = 0;
182 virtual int get_grid_top_attach() const = 0;
184 virtual void set_hexpand(bool bExpand) = 0;
185 virtual bool get_hexpand() const = 0;
186 virtual void set_vexpand(bool bExpand) = 0;
187 virtual bool get_vexpand() const = 0;
189 virtual void set_margin_top(int nMargin) = 0;
190 virtual void set_margin_bottom(int nMargin) = 0;
191 virtual void set_margin_start(int nMargin) = 0;
192 virtual void set_margin_end(int nMargin) = 0;
194 virtual int get_margin_top() const = 0;
195 virtual int get_margin_bottom() const = 0;
196 virtual int get_margin_start() const = 0;
197 virtual int get_margin_end() const = 0;
200 * Report the extents of this widget relative to the rRelative target widget.
202 * To succeed, both widgets must be realized, and must share a common toplevel.
204 * returns false if the relative extents could not be determined, e.g. if
205 * either widget was not realized, or there was no common ancestor.
206 * Otherwise true.
208 virtual bool get_extents_relative_to(const Widget& rRelative, int& x, int& y, int& width,
209 int& height) const = 0;
211 virtual void set_accessible_name(const OUString& rName) = 0;
212 virtual void set_accessible_description(const OUString& rDescription) = 0;
213 virtual OUString get_accessible_name() const = 0;
215 virtual OUString get_accessible_description() const = 0;
217 // After this call this widget is only accessibility labelled by pLabel and
218 // pLabel only accessibility labels this widget
219 virtual void set_accessible_relation_labeled_by(weld::Widget* pLabel) = 0;
221 virtual void set_tooltip_text(const OUString& rTip) = 0;
222 virtual OUString get_tooltip_text() const = 0;
224 virtual void set_cursor_data(void* pData) = 0;
226 virtual void connect_focus_in(const Link<Widget&, void>& rLink)
228 assert(!m_aFocusInHdl.IsSet() || !rLink.IsSet());
229 m_aFocusInHdl = rLink;
232 virtual void connect_focus_out(const Link<Widget&, void>& rLink)
234 assert(!m_aFocusOutHdl.IsSet() || !rLink.IsSet());
235 m_aFocusOutHdl = rLink;
238 // rLink is called when the mnemonic for the Widget is called.
239 // If rLink returns true the Widget will not automatically gain
240 // focus as normally occurs
241 virtual void connect_mnemonic_activate(const Link<Widget&, bool>& rLink)
243 assert(!m_aMnemonicActivateHdl.IsSet() || !rLink.IsSet());
244 m_aMnemonicActivateHdl = rLink;
247 virtual void connect_size_allocate(const Link<const Size&, void>& rLink)
249 assert(!m_aSizeAllocateHdl.IsSet() || !rLink.IsSet());
250 m_aSizeAllocateHdl = rLink;
253 virtual void connect_key_press(const Link<const KeyEvent&, bool>& rLink)
255 assert(!m_aKeyPressHdl.IsSet() || !rLink.IsSet());
256 m_aKeyPressHdl = rLink;
259 virtual void connect_key_release(const Link<const KeyEvent&, bool>& rLink)
261 assert(!m_aKeyReleaseHdl.IsSet() || !rLink.IsSet());
262 m_aKeyReleaseHdl = rLink;
265 virtual void connect_mouse_press(const Link<const MouseEvent&, bool>& rLink)
267 assert(!m_aMousePressHdl.IsSet() || !rLink.IsSet());
268 m_aMousePressHdl = rLink;
271 virtual void connect_mouse_move(const Link<const MouseEvent&, bool>& rLink)
273 assert(!m_aMouseMotionHdl.IsSet() || !rLink.IsSet());
274 m_aMouseMotionHdl = rLink;
277 virtual void connect_mouse_release(const Link<const MouseEvent&, bool>& rLink)
279 assert(!m_aMouseReleaseHdl.IsSet() || !rLink.IsSet());
280 m_aMouseReleaseHdl = rLink;
283 virtual void connect_style_updated(const Link<Widget&, void>& rLink)
285 assert(!m_aStyleUpdatedHdl.IsSet() || !rLink.IsSet());
286 m_aStyleUpdatedHdl = rLink;
289 virtual void grab_add() = 0;
290 virtual bool has_grab() const = 0;
291 virtual void grab_remove() = 0;
293 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
294 virtual vcl::Font get_font() = 0;
296 //true for rtl, false otherwise
297 virtual bool get_direction() const = 0;
298 virtual void set_direction(bool bRTL) = 0;
300 /* Increases the freeze count on widget.
302 If the freeze count is non-zero, emission of the widget's notifications
303 is stopped. The notifications are queued until the freeze count is
304 decreased to zero. Duplicate notifications may be squashed together.
306 virtual void freeze() = 0;
308 /* Reverts the effect of a previous call to freeze.
310 The freeze count is decreased on the widget and when it reaches zero,
311 queued notifications are emitted.
313 virtual void thaw() = 0;
315 /* push/pop busy mouse cursor state
317 bBusy of true to push a busy state onto the stack and false
318 to pop it off, calls to this should balance.
320 see weld::WaitObject */
321 virtual void set_busy_cursor(bool bBusy) = 0;
323 virtual void queue_resize() = 0;
325 virtual std::unique_ptr<Container> weld_parent() const = 0;
327 //iterate upwards through the hierarchy starting at this widgets parent,
328 //calling func with their helpid until func returns true or we run out of
329 //parents
330 virtual void help_hierarchy_foreach(const std::function<bool(const OUString&)>& func) = 0;
332 virtual OUString strip_mnemonic(const OUString& rLabel) const = 0;
334 virtual VclPtr<VirtualDevice> create_virtual_device() const = 0;
336 //do something transient to attract the attention of the user to the widget
337 virtual void call_attention_to() = 0;
339 //make this widget look like a page in a notebook
340 virtual void set_stack_background() = 0;
341 //make this widget look like it has a highlighted background
342 virtual void set_highlight_background() = 0;
343 //make this widget suitable as parent for a title
344 virtual void set_title_background() = 0;
345 //make this widget suitable for use in a toolbar
346 virtual void set_toolbar_background() = 0;
347 //trying to use a custom color for a background is generally a bad idea. If your need
348 //fits one of the above categories then that's a somewhat better choice
349 virtual void set_background(const Color& rBackColor) = 0;
351 virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget> get_drop_target() = 0;
352 virtual css::uno::Reference<css::datatransfer::clipboard::XClipboard> get_clipboard() const = 0;
354 virtual void connect_get_property_tree(const Link<tools::JsonWriter&, void>& rLink) = 0;
355 virtual void get_property_tree(tools::JsonWriter& rJsonWriter) = 0;
357 // render the widget to an output device
358 virtual void draw(OutputDevice& rOutput, const Point& rPos, const Size& rSizePixel) = 0;
360 virtual ~Widget() {}
363 class VCL_DLLPUBLIC Container : virtual public Widget
365 Link<Container&, void> m_aContainerFocusChangedHdl;
367 protected:
368 void signal_container_focus_changed() { m_aContainerFocusChangedHdl.Call(*this); }
370 public:
371 // remove from old container and add to new container in one go
372 // new container can be null to just remove from old container
373 virtual void move(weld::Widget* pWidget, weld::Container* pNewParent) = 0;
374 // create an XWindow as a child of this container. The XWindow is
375 // suitable to contain css::awt::XControl items
376 virtual css::uno::Reference<css::awt::XWindow> CreateChildFrame() = 0;
377 // rLink is called when the focus transitions from a widget outside the container
378 // to a widget inside the container or vice versa
379 virtual void connect_container_focus_changed(const Link<Container&, void>& rLink)
381 m_aContainerFocusChangedHdl = rLink;
383 // causes a child of the container to have the keyboard focus
384 virtual void child_grab_focus() = 0;
387 class VCL_DLLPUBLIC Box : virtual public Container
389 public:
390 // Moves child to a new position in the list of children
391 virtual void reorder_child(weld::Widget* pWidget, int position) = 0;
392 // Sort ok/cancel etc buttons in platform order
393 virtual void sort_native_button_order() = 0;
396 class VCL_DLLPUBLIC Paned : virtual public Container
398 public:
399 // set pixel position of divider
400 virtual void set_position(int nPos) = 0;
401 // get pixel position of divider
402 virtual int get_position() const = 0;
405 class VCL_DLLPUBLIC ScrolledWindow : virtual public Container
407 friend class ::LOKTrigger;
409 Link<ScrolledWindow&, void> m_aVChangeHdl;
410 Link<ScrolledWindow&, void> m_aHChangeHdl;
412 protected:
413 void signal_vadjustment_changed() { m_aVChangeHdl.Call(*this); }
414 void signal_hadjustment_changed() { m_aHChangeHdl.Call(*this); }
416 public:
417 virtual void hadjustment_configure(int value, int lower, int upper, int step_increment,
418 int page_increment, int page_size)
419 = 0;
420 virtual int hadjustment_get_value() const = 0;
421 virtual void hadjustment_set_value(int value) = 0;
422 virtual int hadjustment_get_upper() const = 0;
423 virtual void hadjustment_set_upper(int upper) = 0;
424 virtual int hadjustment_get_page_size() const = 0;
425 virtual void hadjustment_set_page_size(int size) = 0;
426 virtual void hadjustment_set_page_increment(int size) = 0;
427 virtual void hadjustment_set_step_increment(int size) = 0;
428 virtual void set_hpolicy(VclPolicyType eHPolicy) = 0;
429 virtual VclPolicyType get_hpolicy() const = 0;
430 void connect_hadjustment_changed(const Link<ScrolledWindow&, void>& rLink)
432 m_aHChangeHdl = rLink;
435 virtual void vadjustment_configure(int value, int lower, int upper, int step_increment,
436 int page_increment, int page_size)
437 = 0;
438 virtual int vadjustment_get_value() const = 0;
439 virtual void vadjustment_set_value(int value) = 0;
440 virtual int vadjustment_get_upper() const = 0;
441 virtual void vadjustment_set_upper(int upper) = 0;
442 virtual int vadjustment_get_page_size() const = 0;
443 virtual void vadjustment_set_page_size(int size) = 0;
444 virtual void vadjustment_set_page_increment(int size) = 0;
445 virtual void vadjustment_set_step_increment(int size) = 0;
446 virtual int vadjustment_get_lower() const = 0;
447 virtual void vadjustment_set_lower(int upper) = 0;
448 virtual void set_vpolicy(VclPolicyType eVPolicy) = 0;
449 virtual VclPolicyType get_vpolicy() const = 0;
450 void connect_vadjustment_changed(const Link<ScrolledWindow&, void>& rLink)
452 m_aVChangeHdl = rLink;
454 virtual int get_scroll_thickness() const = 0;
455 virtual void set_scroll_thickness(int nThickness) = 0;
457 //trying to use custom color for a scrollbar is generally a bad idea.
458 virtual void customize_scrollbars(const Color& rBackgroundColor, const Color& rShadowColor,
459 const Color& rFaceColor)
460 = 0;
463 class Label;
465 class VCL_DLLPUBLIC Frame : virtual public Container
467 public:
468 virtual void set_label(const OUString& rText) = 0;
469 virtual OUString get_label() const = 0;
470 virtual std::unique_ptr<Label> weld_label_widget() const = 0;
473 class VCL_DLLPUBLIC Notebook : virtual public Widget
475 friend class ::LOKTrigger;
477 protected:
478 Link<const OUString&, bool> m_aLeavePageHdl;
479 Link<const OUString&, void> m_aEnterPageHdl;
481 public:
482 virtual int get_current_page() const = 0;
483 virtual int get_page_index(const OUString& rIdent) const = 0;
484 virtual OUString get_page_ident(int nPage) const = 0;
485 virtual OUString get_current_page_ident() const = 0;
486 virtual void set_current_page(int nPage) = 0;
487 virtual void set_current_page(const OUString& rIdent) = 0;
488 virtual void remove_page(const OUString& rIdent) = 0;
489 virtual void insert_page(const OUString& rIdent, const OUString& rLabel, int nPos) = 0;
490 void append_page(const OUString& rIdent, const OUString& rLabel)
492 insert_page(rIdent, rLabel, -1);
494 virtual void set_tab_label_text(const OUString& rIdent, const OUString& rLabel) = 0;
495 virtual OUString get_tab_label_text(const OUString& rIdent) const = 0;
496 virtual void set_show_tabs(bool bShow) = 0;
497 virtual int get_n_pages() const = 0;
498 virtual weld::Container* get_page(const OUString& rIdent) const = 0;
500 void connect_leave_page(const Link<const OUString&, bool>& rLink) { m_aLeavePageHdl = rLink; }
501 void connect_enter_page(const Link<const OUString&, void>& rLink) { m_aEnterPageHdl = rLink; }
504 class VCL_DLLPUBLIC ScreenShotEntry
506 public:
507 ScreenShotEntry(OUString aHelpId, const basegfx::B2IRange& rB2IRange)
508 : msHelpId(std::move(aHelpId))
509 , maB2IRange(rB2IRange)
513 const basegfx::B2IRange& getB2IRange() const { return maB2IRange; }
515 const OUString& GetHelpId() const { return msHelpId; }
517 private:
518 OUString msHelpId;
519 basegfx::B2IRange maB2IRange;
522 typedef std::vector<ScreenShotEntry> ScreenShotCollection;
524 class VCL_DLLPUBLIC Window : virtual public Container
526 protected:
527 Link<Widget&, bool> m_aHelpRequestHdl;
529 public:
530 virtual void set_title(const OUString& rTitle) = 0;
531 virtual OUString get_title() const = 0;
532 virtual void window_move(int x, int y) = 0;
533 virtual void set_modal(bool bModal) = 0;
534 virtual bool get_modal() const = 0;
535 virtual bool get_resizable() const = 0;
536 virtual Size get_size() const = 0;
537 virtual Point get_position() const = 0;
538 virtual AbsoluteScreenPixelRectangle get_monitor_workarea() const = 0;
539 // center window on is parent
541 // bTrackGeometryRequests set to true tries to ensure the window will end
542 // up still centered on its parent windows final size, taking into account
543 // that there may currently be pending geometry requests for the parent not
544 // yet processed by the underlying toolkit
546 // for e.g gtk this will means the window is always centered even when
547 // resized, calling set_centered_on_parent with false will turn this
548 // off again.
549 virtual void set_centered_on_parent(bool bTrackGeometryRequests) = 0;
550 // returns whether the widget that has focus is within this Window
551 // (its very possible to move this to weld::Container if that becomes
552 // desirable)
553 virtual bool has_toplevel_focus() const = 0;
554 virtual void present() = 0;
556 // with pOld of null, automatically find the old default widget and unset
557 // it, otherwise use as hint to the old default
558 virtual void change_default_widget(weld::Widget* pOld, weld::Widget* pNew) = 0;
559 virtual bool is_default_widget(const weld::Widget* pCandidate) const = 0;
561 virtual void set_window_state(const OUString& rStr) = 0;
562 virtual OUString get_window_state(vcl::WindowDataMask nMask) const = 0;
564 virtual css::uno::Reference<css::awt::XWindow> GetXWindow() = 0;
566 void connect_help(const Link<Widget&, bool>& rLink) { m_aHelpRequestHdl = rLink; }
568 virtual SystemEnvData get_system_data() const = 0;
570 virtual void resize_to_request() = 0;
572 // collect positions of widgets and their help ids for screenshot purposes
573 virtual ScreenShotCollection collect_screenshot_data() = 0;
575 // render the widget to an output device
576 virtual VclPtr<VirtualDevice> screenshot() = 0;
578 virtual const vcl::ILibreOfficeKitNotifier* GetLOKNotifier() = 0;
581 class VCL_DLLPUBLIC WaitObject
583 private:
584 weld::Widget* m_pWindow;
586 public:
587 WaitObject(weld::Widget* pWindow)
588 : m_pWindow(pWindow)
590 if (m_pWindow)
591 m_pWindow->set_busy_cursor(true);
593 ~WaitObject()
595 if (m_pWindow)
596 m_pWindow->set_busy_cursor(false);
600 class Button;
602 class VCL_DLLPUBLIC Dialog : virtual public Window
604 private:
605 friend DialogController;
606 virtual bool runAsync(std::shared_ptr<DialogController>,
607 const std::function<void(sal_Int32)>& func)
608 = 0;
610 public:
611 virtual int run() = 0;
612 // Run async without a controller
613 // @param self - must point to this, to enforce that the dialog was created/held by a shared_ptr
614 virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
615 const std::function<void(sal_Int32)>& func)
616 = 0;
617 virtual void response(int response) = 0;
618 virtual void add_button(const OUString& rText, int response, const OUString& rHelpId = {}) = 0;
619 virtual void set_default_response(int response) = 0;
620 virtual Button* weld_widget_for_response(int response) = 0;
621 virtual Container* weld_content_area() = 0;
623 // shrink the dialog down to shown just these widgets
624 virtual void collapse(weld::Widget* pEdit, weld::Widget* pButton) = 0;
625 // undo previous dialog collapse
626 virtual void undo_collapse() = 0;
628 virtual void SetInstallLOKNotifierHdl(const Link<void*, vcl::ILibreOfficeKitNotifier*>& rLink)
629 = 0;
632 class VCL_DLLPUBLIC MessageDialog : virtual public Dialog
634 public:
635 virtual void set_primary_text(const OUString& rText) = 0;
636 virtual OUString get_primary_text() const = 0;
637 virtual void set_secondary_text(const OUString& rText) = 0;
638 virtual OUString get_secondary_text() const = 0;
639 virtual Container* weld_message_area() = 0;
642 class VCL_DLLPUBLIC Assistant : virtual public Dialog
644 Link<const OUString&, bool> m_aJumpPageHdl;
646 protected:
647 bool signal_jump_page(const OUString& rIdent) { return m_aJumpPageHdl.Call(rIdent); }
649 public:
650 virtual int get_current_page() const = 0;
651 virtual int get_n_pages() const = 0;
652 virtual OUString get_page_ident(int nPage) const = 0;
653 virtual OUString get_current_page_ident() const = 0;
654 virtual void set_current_page(int nPage) = 0;
655 virtual void set_current_page(const OUString& rIdent) = 0;
656 // move the page rIdent to position nIndex
657 virtual void set_page_index(const OUString& rIdent, int nIndex) = 0;
658 virtual void set_page_title(const OUString& rIdent, const OUString& rTitle) = 0;
659 virtual OUString get_page_title(const OUString& rIdent) const = 0;
660 virtual void set_page_sensitive(const OUString& rIdent, bool bSensitive) = 0;
661 virtual weld::Container* append_page(const OUString& rIdent) = 0;
663 virtual void set_page_side_help_id(const OUString& rHelpId) = 0;
665 virtual void set_page_side_image(const OUString& rImage) = 0;
667 void connect_jump_page(const Link<const OUString&, bool>& rLink) { m_aJumpPageHdl = rLink; }
670 inline OUString toId(const void* pValue)
672 return OUString::number(reinterpret_cast<sal_uIntPtr>(pValue));
675 template <typename T> T fromId(const OUString& rValue)
677 return reinterpret_cast<T>(rValue.toUInt64());
680 struct VCL_DLLPUBLIC ComboBoxEntry
682 OUString sString;
683 OUString sId;
684 OUString sImage;
685 ComboBoxEntry(OUString _aString)
686 : sString(std::move(_aString))
689 ComboBoxEntry(OUString _aString, OUString _aId)
690 : sString(std::move(_aString))
691 , sId(std::move(_aId))
694 ComboBoxEntry(OUString _aString, OUString _aId, OUString _aImage)
695 : sString(std::move(_aString))
696 , sId(std::move(_aId))
697 , sImage(std::move(_aImage))
702 enum class EntryMessageType
704 Normal,
705 Warning,
706 Error,
709 class Menu;
711 /// A widget used to choose from a list of items.
712 class VCL_DLLPUBLIC ComboBox : virtual public Widget
714 private:
715 OUString m_sSavedValue;
716 std::vector<OUString> m_aSavedValues;
718 public:
719 // OUString is the id of the row, it may be null to measure the height of a generic line
720 typedef std::tuple<vcl::RenderContext&, const tools::Rectangle&, bool, const OUString&>
721 render_args;
723 protected:
724 Link<ComboBox&, void> m_aChangeHdl;
725 Link<ComboBox&, void> m_aPopupToggledHdl;
726 Link<ComboBox&, bool> m_aEntryActivateHdl;
727 Link<OUString&, bool> m_aEntryInsertTextHdl;
729 friend class ::LOKTrigger;
731 void signal_changed() { m_aChangeHdl.Call(*this); }
733 virtual void signal_popup_toggled() { m_aPopupToggledHdl.Call(*this); }
735 Link<render_args, void> m_aRenderHdl;
736 void signal_custom_render(vcl::RenderContext& rDevice, const tools::Rectangle& rRect,
737 bool bSelected, const OUString& rId)
739 m_aRenderHdl.Call(render_args(rDevice, rRect, bSelected, rId));
742 Link<vcl::RenderContext&, Size> m_aGetSizeHdl;
743 Size signal_custom_get_size(vcl::RenderContext& rDevice) { return m_aGetSizeHdl.Call(rDevice); }
745 public:
746 virtual void insert(int pos, const OUString& rStr, const OUString* pId,
747 const OUString* pIconName, VirtualDevice* pImageSurface)
748 = 0;
749 virtual void insert_vector(const std::vector<weld::ComboBoxEntry>& rItems, bool bKeepExisting)
750 = 0;
751 void insert(int pos, const weld::ComboBoxEntry& rItem)
753 insert(pos, rItem.sString, rItem.sId.isEmpty() ? nullptr : &rItem.sId,
754 rItem.sImage.isEmpty() ? nullptr : &rItem.sImage, nullptr);
756 void insert_text(int pos, const OUString& rStr)
758 insert(pos, rStr, nullptr, nullptr, nullptr);
760 void append(const weld::ComboBoxEntry& rItem) { insert(-1, rItem); }
761 void append_text(const OUString& rStr) { insert(-1, rStr, nullptr, nullptr, nullptr); }
762 void append(const OUString& rId, const OUString& rStr)
764 insert(-1, rStr, &rId, nullptr, nullptr);
766 void append(const OUString& rId, const OUString& rStr, const OUString& rImage)
768 insert(-1, rStr, &rId, &rImage, nullptr);
770 void append(const OUString& rId, const OUString& rStr, VirtualDevice& rImage)
772 insert(-1, rStr, &rId, nullptr, &rImage);
774 void append(int pos, const OUString& rId, const OUString& rStr)
776 insert(pos, rStr, &rId, nullptr, nullptr);
778 virtual void insert_separator(int pos, const OUString& rId) = 0;
779 void append_separator(const OUString& rId) { insert_separator(-1, rId); }
781 virtual int get_count() const = 0;
782 virtual void make_sorted() = 0;
783 virtual void clear() = 0;
785 //by index
786 virtual int get_active() const = 0;
787 virtual void set_active(int pos) = 0;
788 virtual void remove(int pos) = 0;
790 //by text
791 virtual OUString get_active_text() const = 0;
792 void set_active_text(const OUString& rStr) { set_active(find_text(rStr)); }
793 virtual OUString get_text(int pos) const = 0;
794 virtual int find_text(const OUString& rStr) const = 0;
795 void remove_text(const OUString& rText) { remove(find_text(rText)); }
797 //by id
798 virtual OUString get_active_id() const = 0;
799 virtual void set_active_id(const OUString& rStr) = 0;
800 virtual OUString get_id(int pos) const = 0;
801 virtual void set_id(int row, const OUString& rId) = 0;
802 virtual int find_id(const OUString& rId) const = 0;
803 void remove_id(const OUString& rId) { remove(find_id(rId)); }
805 /* m_aChangeHdl is called when the active item is changed. The can be due
806 to the user selecting a different item from the list or while typing
807 into the entry of a combo box with an entry.
809 Use changed_by_direct_pick() to discover whether an item was actually explicitly
810 selected, e.g. from the menu.
812 void connect_changed(const Link<ComboBox&, void>& rLink) { m_aChangeHdl = rLink; }
814 virtual bool changed_by_direct_pick() const = 0;
816 virtual void connect_popup_toggled(const Link<ComboBox&, void>& rLink)
818 m_aPopupToggledHdl = rLink;
821 //entry related
822 virtual bool has_entry() const = 0;
823 virtual void set_entry_message_type(EntryMessageType eType) = 0;
824 virtual void set_entry_text(const OUString& rStr) = 0;
825 virtual void set_entry_width_chars(int nChars) = 0;
826 virtual void set_entry_max_length(int nChars) = 0;
827 virtual void select_entry_region(int nStartPos, int nEndPos) = 0;
828 virtual bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) = 0;
829 virtual void set_entry_completion(bool bEnable, bool bCaseSensitive = false) = 0;
830 virtual void set_entry_placeholder_text(const OUString& rText) = 0;
831 virtual void set_entry_editable(bool bEditable) = 0;
832 virtual void cut_entry_clipboard() = 0;
833 virtual void copy_entry_clipboard() = 0;
834 virtual void paste_entry_clipboard() = 0;
836 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
837 virtual void set_font(const vcl::Font& rFont) = 0;
839 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
840 virtual void set_entry_font(const vcl::Font& rFont) = 0;
841 virtual vcl::Font get_entry_font() = 0;
843 virtual bool get_popup_shown() const = 0;
845 void connect_entry_insert_text(const Link<OUString&, bool>& rLink)
847 m_aEntryInsertTextHdl = rLink;
850 // callback returns true to indicated no further processing of activate wanted
851 void connect_entry_activate(const Link<ComboBox&, bool>& rLink) { m_aEntryActivateHdl = rLink; }
853 void save_value() { m_sSavedValue = get_active_text(); }
855 void save_values_by_id(const OUString& rId)
857 m_aSavedValues.push_back(get_text(find_id(rId)));
860 OUString const& get_saved_value() const { return m_sSavedValue; }
861 OUString const& get_saved_values(int pos) const { return m_aSavedValues[pos]; }
862 bool get_value_changed_from_saved() const { return m_sSavedValue != get_active_text(); }
863 bool get_values_changed_from_saved() const
865 return !m_aSavedValues.empty()
866 && std::find(m_aSavedValues.begin(), m_aSavedValues.end(), get_active_text())
867 == m_aSavedValues.end();
870 void removeSavedValues() { m_aSavedValues.clear(); }
872 // for custom rendering a row
873 void connect_custom_get_size(const Link<vcl::RenderContext&, Size>& rLink)
875 m_aGetSizeHdl = rLink;
877 void connect_custom_render(const Link<render_args, void>& rLink) { m_aRenderHdl = rLink; }
878 // call set_custom_renderer after setting custom callbacks
879 virtual void set_custom_renderer(bool bOn) = 0;
880 // create a virtual device compatible with the device passed in render_args wrt alpha
881 virtual VclPtr<VirtualDevice> create_render_virtual_device() const = 0;
882 // set a sub menu for a entry, only works with custom rendering
883 virtual void set_item_menu(const OUString& rIdent, weld::Menu* pMenu) = 0;
884 // get the width needed to show the menu launcher in a custom row
885 virtual int get_menu_button_width() const = 0;
887 // for mru support
888 virtual int get_max_mru_count() const = 0;
889 virtual void set_max_mru_count(int nCount) = 0;
890 virtual OUString get_mru_entries() const = 0;
891 virtual void set_mru_entries(const OUString& rEntries) = 0;
894 enum class ColumnToggleType
896 Check,
897 Radio
900 class VCL_DLLPUBLIC TreeIter
902 private:
903 TreeIter(const TreeIter&) = delete;
904 TreeIter& operator=(const TreeIter&) = delete;
906 public:
907 TreeIter() {}
908 virtual bool equal(const TreeIter& rOther) const = 0;
909 virtual ~TreeIter() {}
912 /* Model column indexes are considered to begin at 0, but with special columns
913 before index 0. A expander image column (and an additional optional toggle
914 button column when enable_toggle_buttons is used). Column index -1 is
915 reserved to access those columns.
917 class VCL_DLLPUBLIC TreeView : virtual public Widget
919 friend class ::LOKTrigger;
921 public:
922 typedef std::pair<const TreeIter&, int> iter_col;
923 typedef std::pair<const TreeIter&, OUString> iter_string;
924 // OUString is the id of the row, it may be null to measure the height of a generic line
925 typedef std::pair<vcl::RenderContext&, const OUString&> get_size_args;
926 typedef std::tuple<vcl::RenderContext&, const tools::Rectangle&, bool, const OUString&>
927 render_args;
929 private:
930 OUString m_sSavedValue;
932 protected:
933 Link<TreeView&, void> m_aChangeHdl;
934 Link<TreeView&, bool> m_aRowActivatedHdl;
935 Link<int, void> m_aColumnClickedHdl;
936 Link<const iter_col&, void> m_aRadioToggleHdl;
937 Link<const TreeIter&, bool> m_aEditingStartedHdl;
938 Link<const iter_string&, bool> m_aEditingDoneHdl;
939 // if handler returns false, the expansion of the row is refused
940 Link<const TreeIter&, bool> m_aExpandingHdl;
941 // if handler returns false, the collapse of the row is refused
942 Link<const TreeIter&, bool> m_aCollapsingHdl;
943 Link<TreeView&, void> m_aVisibleRangeChangedHdl;
944 Link<TreeView&, void> m_aModelChangedHdl;
945 // if handler returns true, then menu has been show and event is consumed
946 Link<const CommandEvent&, bool> m_aPopupMenuHdl;
947 // if handler returns true, drag is disallowed, consumer can change bool
948 // arg to false to disable the treeview default dnd icon
949 Link<bool&, bool> m_aDragBeginHdl;
950 std::function<int(const weld::TreeIter&, const weld::TreeIter&)> m_aCustomSort;
952 protected:
953 void signal_changed() { m_aChangeHdl.Call(*this); }
954 bool signal_row_activated() { return m_aRowActivatedHdl.Call(*this); }
955 void signal_column_clicked(int nColumn) { m_aColumnClickedHdl.Call(nColumn); }
956 bool signal_expanding(const TreeIter& rIter)
958 return !m_aExpandingHdl.IsSet() || m_aExpandingHdl.Call(rIter);
960 bool signal_collapsing(const TreeIter& rIter)
962 return !m_aCollapsingHdl.IsSet() || m_aCollapsingHdl.Call(rIter);
964 void signal_visible_range_changed() { m_aVisibleRangeChangedHdl.Call(*this); }
965 void signal_model_changed() { m_aModelChangedHdl.Call(*this); }
967 void signal_toggled(const iter_col& rIterCol) { m_aRadioToggleHdl.Call(rIterCol); }
969 bool signal_editing_started(const TreeIter& rIter) { return m_aEditingStartedHdl.Call(rIter); }
971 bool signal_editing_done(const iter_string& rIterText)
973 return m_aEditingDoneHdl.Call(rIterText);
976 Link<const TreeIter&, OUString> m_aQueryTooltipHdl;
977 OUString signal_query_tooltip(const TreeIter& rIter) { return m_aQueryTooltipHdl.Call(rIter); }
979 Link<render_args, void> m_aRenderHdl;
980 void signal_custom_render(vcl::RenderContext& rDevice, const tools::Rectangle& rRect,
981 bool bSelected, const OUString& rId)
983 m_aRenderHdl.Call(render_args(rDevice, rRect, bSelected, rId));
986 Link<get_size_args, Size> m_aGetSizeHdl;
987 Size signal_custom_get_size(vcl::RenderContext& rDevice, const OUString& rId)
989 return m_aGetSizeHdl.Call(get_size_args(rDevice, rId));
992 public:
993 virtual void connect_query_tooltip(const Link<const TreeIter&, OUString>& rLink)
995 assert(!m_aQueryTooltipHdl.IsSet() || !rLink.IsSet());
996 m_aQueryTooltipHdl = rLink;
999 // see 'expanding on-demand node details' for bChildrenOnDemand of true
1000 virtual void insert(const TreeIter* pParent, int pos, const OUString* pStr, const OUString* pId,
1001 const OUString* pIconName, VirtualDevice* pImageSurface,
1002 bool bChildrenOnDemand, TreeIter* pRet)
1003 = 0;
1005 void insert(int nRow, TreeIter* pRet = nullptr)
1007 insert(nullptr, nRow, nullptr, nullptr, nullptr, nullptr, false, pRet);
1010 void append(TreeIter* pRet = nullptr) { insert(-1, pRet); }
1012 void insert(int pos, const OUString& rStr, const OUString* pId, const OUString* pIconName,
1013 VirtualDevice* pImageSurface)
1015 insert(nullptr, pos, &rStr, pId, pIconName, pImageSurface, false, nullptr);
1017 void insert_text(int pos, const OUString& rStr)
1019 insert(nullptr, pos, &rStr, nullptr, nullptr, nullptr, false, nullptr);
1021 void append_text(const OUString& rStr)
1023 insert(nullptr, -1, &rStr, nullptr, nullptr, nullptr, false, nullptr);
1025 void append(const OUString& rId, const OUString& rStr)
1027 insert(nullptr, -1, &rStr, &rId, nullptr, nullptr, false, nullptr);
1029 void append(const OUString& rId, const OUString& rStr, const OUString& rImage)
1031 insert(nullptr, -1, &rStr, &rId, &rImage, nullptr, false, nullptr);
1033 void append(const TreeIter* pParent, const OUString& rStr)
1035 insert(pParent, -1, &rStr, nullptr, nullptr, nullptr, false, nullptr);
1038 virtual void insert_separator(int pos, const OUString& rId) = 0;
1039 void append_separator(const OUString& rId) { insert_separator(-1, rId); }
1041 void connect_changed(const Link<TreeView&, void>& rLink) { m_aChangeHdl = rLink; }
1043 /* A row is "activated" when the user double clicks a treeview row. It may
1044 also be emitted when a row is selected and Space or Enter is pressed.
1046 a return of "true" means the activation has been handled, a "false" propagates
1047 the activation to the default handler which expands/collapses the row, if possible.
1049 void connect_row_activated(const Link<TreeView&, bool>& rLink) { m_aRowActivatedHdl = rLink; }
1051 // Argument is a pair of iter, col describing the toggled node
1052 void connect_toggled(const Link<const iter_col&, void>& rLink) { m_aRadioToggleHdl = rLink; }
1054 void connect_column_clicked(const Link<int, void>& rLink) { m_aColumnClickedHdl = rLink; }
1055 void connect_model_changed(const Link<TreeView&, void>& rLink) { m_aModelChangedHdl = rLink; }
1057 virtual OUString get_selected_text() const = 0;
1058 virtual OUString get_selected_id() const = 0;
1060 // call before inserting any content and connecting to toggle signals,
1061 // an pre-inserted checkbutton column will exist at the start of every row
1062 // inserted after this call which can be accessed with col index -1
1063 virtual void enable_toggle_buttons(ColumnToggleType eType) = 0;
1065 virtual void set_clicks_to_toggle(int nToggleBehavior) = 0;
1067 //by index
1068 virtual int get_selected_index() const = 0;
1069 //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1070 virtual void select(int pos) = 0;
1071 virtual void unselect(int pos) = 0;
1072 virtual void remove(int pos) = 0;
1073 // col index -1 gets the first text column
1074 virtual OUString get_text(int row, int col = -1) const = 0;
1075 // col index -1 sets the first text column
1076 virtual void set_text(int row, const OUString& rText, int col = -1) = 0;
1077 // col index -1 sets all columns
1078 virtual void set_sensitive(int row, bool bSensitive, int col = -1) = 0;
1079 virtual bool get_sensitive(int row, int col) const = 0;
1080 virtual void set_id(int row, const OUString& rId) = 0;
1081 // col index -1 sets the expander toggle, enable_toggle_buttons must have been called to create that column
1082 virtual void set_toggle(int row, TriState eState, int col = -1) = 0;
1083 // col index -1 gets the expander toggle, enable_toggle_buttons must have been called to create that column
1084 virtual TriState get_toggle(int row, int col = -1) const = 0;
1085 // col index -1 sets the expander image
1086 virtual void set_image(int row, const OUString& rImage, int col = -1) = 0;
1087 // col index -1 sets the expander image
1088 virtual void set_image(int row, VirtualDevice& rImage, int col = -1) = 0;
1089 // col index -1 sets the expander image
1090 virtual void set_image(int row, const css::uno::Reference<css::graphic::XGraphic>& rImage,
1091 int col = -1)
1092 = 0;
1093 virtual void set_text_emphasis(int row, bool bOn, int col) = 0;
1094 virtual bool get_text_emphasis(int row, int col) const = 0;
1095 virtual void set_text_align(int row, double fAlign, int col) = 0;
1096 virtual void swap(int pos1, int pos2) = 0;
1097 virtual std::vector<int> get_selected_rows() const = 0;
1098 virtual void set_font_color(int pos, const Color& rColor) = 0;
1099 // scroll to make 'row' visible, this will also expand all parent rows of 'row' as necessary to
1100 // make 'row' visible
1101 virtual void scroll_to_row(int row) = 0;
1102 virtual bool is_selected(int pos) const = 0;
1103 virtual int get_cursor_index() const = 0;
1104 virtual void set_cursor(int pos) = 0;
1106 //by text
1107 virtual int find_text(const OUString& rText) const = 0;
1108 //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1109 void select_text(const OUString& rText) { select(find_text(rText)); }
1110 void remove_text(const OUString& rText) { remove(find_text(rText)); }
1111 std::vector<OUString> get_selected_rows_text() const
1113 std::vector<int> aRows(get_selected_rows());
1114 std::vector<OUString> aRet;
1115 aRet.reserve(aRows.size());
1116 for (auto a : aRows)
1117 aRet.push_back(get_text(a));
1118 return aRet;
1121 //by id
1122 virtual OUString get_id(int pos) const = 0;
1123 virtual int find_id(const OUString& rId) const = 0;
1124 //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1125 void select_id(const OUString& rId) { select(find_id(rId)); }
1126 void remove_id(const OUString& rText) { remove(find_id(rText)); }
1128 //via iter
1129 virtual std::unique_ptr<TreeIter> make_iterator(const TreeIter* pOrig = nullptr) const = 0;
1130 virtual void copy_iterator(const TreeIter& rSource, TreeIter& rDest) const = 0;
1131 virtual bool get_selected(TreeIter* pIter) const = 0;
1132 virtual bool get_cursor(TreeIter* pIter) const = 0;
1133 virtual void set_cursor(const TreeIter& rIter) = 0;
1134 virtual bool get_iter_first(TreeIter& rIter) const = 0;
1135 // set iter to point to next node at the current level
1136 virtual bool iter_next_sibling(TreeIter& rIter) const = 0;
1137 // set iter to point to previous node at the current level
1138 virtual bool iter_previous_sibling(TreeIter& rIter) const = 0;
1139 // set iter to point to next node, depth first, then sibling
1140 virtual bool iter_next(TreeIter& rIter) const = 0;
1141 // set iter to point to previous node, sibling first then depth
1142 virtual bool iter_previous(TreeIter& rIter) const = 0;
1143 // set iter to point to first child node
1144 virtual bool iter_children(TreeIter& rIter) const = 0;
1145 bool iter_nth_sibling(TreeIter& rIter, int nChild) const
1147 bool bRet = true;
1148 for (int i = 0; i < nChild && bRet; ++i)
1149 bRet = iter_next_sibling(rIter);
1150 return bRet;
1152 bool iter_nth_child(TreeIter& rIter, int nChild) const
1154 if (!iter_children(rIter))
1155 return false;
1156 return iter_nth_sibling(rIter, nChild);
1158 virtual bool iter_parent(TreeIter& rIter) const = 0;
1159 virtual int get_iter_depth(const TreeIter& rIter) const = 0;
1160 virtual int get_iter_index_in_parent(const TreeIter& rIter) const = 0;
1161 /* Compares two paths. If a appears before b in a tree, then -1 is returned.
1162 If b appears before a , then 1 is returned. If the two nodes are equal,
1163 then 0 is returned.
1165 virtual int iter_compare(const TreeIter& a, const TreeIter& b) const = 0;
1166 virtual bool iter_has_child(const TreeIter& rIter) const = 0;
1167 // returns the number of direct children rIter has
1168 virtual int iter_n_children(const TreeIter& rIter) const = 0;
1169 virtual void remove(const TreeIter& rIter) = 0;
1170 //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1171 virtual void select(const TreeIter& rIter) = 0;
1172 virtual void unselect(const TreeIter& rIter) = 0;
1173 //visually indent this row as if it was at get_iter_depth() + nIndentLevel
1174 virtual void set_extra_row_indent(const TreeIter& rIter, int nIndentLevel) = 0;
1175 // col index -1 sets the first text column
1176 virtual void set_text(const TreeIter& rIter, const OUString& rStr, int col = -1) = 0;
1177 // col index -1 sets all columns
1178 virtual void set_sensitive(const TreeIter& rIter, bool bSensitive, int col = -1) = 0;
1179 virtual bool get_sensitive(const TreeIter& rIter, int col) const = 0;
1180 virtual void set_text_emphasis(const TreeIter& rIter, bool bOn, int col) = 0;
1181 virtual bool get_text_emphasis(const TreeIter& rIter, int col) const = 0;
1182 virtual void set_text_align(const TreeIter& rIter, double fAlign, int col) = 0;
1183 // col index -1 sets the expander toggle, enable_toggle_buttons must have been called to create that column
1184 virtual void set_toggle(const TreeIter& rIter, TriState bOn, int col = -1) = 0;
1185 // col index -1 gets the expander toggle, enable_toggle_buttons must have been called to create that column
1186 virtual TriState get_toggle(const TreeIter& rIter, int col = -1) const = 0;
1187 // col index -1 gets the first text column
1188 virtual OUString get_text(const TreeIter& rIter, int col = -1) const = 0;
1189 virtual void set_id(const TreeIter& rIter, const OUString& rId) = 0;
1190 virtual OUString get_id(const TreeIter& rIter) const = 0;
1191 // col index -1 sets the expander image
1192 virtual void set_image(const TreeIter& rIter, const OUString& rImage, int col = -1) = 0;
1193 // col index -1 sets the expander image
1194 virtual void set_image(const TreeIter& rIter, VirtualDevice& rImage, int col = -1) = 0;
1195 // col index -1 sets the expander image
1196 virtual void set_image(const TreeIter& rIter,
1197 const css::uno::Reference<css::graphic::XGraphic>& rImage, int col = -1)
1198 = 0;
1199 virtual void set_font_color(const TreeIter& rIter, const Color& rColor) = 0;
1200 // scroll to make rIter visible, this will also expand all parent rows of rIter as necessary to
1201 // make rIter visible
1202 virtual void scroll_to_row(const TreeIter& rIter) = 0;
1203 virtual bool is_selected(const TreeIter& rIter) const = 0;
1205 virtual void move_subtree(TreeIter& rNode, const TreeIter* pNewParent, int nIndexInNewParent)
1206 = 0;
1208 // call func on each element until func returns true or we run out of elements
1209 virtual void all_foreach(const std::function<bool(TreeIter&)>& func) = 0;
1210 // call func on each selected element until func returns true or we run out of elements
1211 virtual void selected_foreach(const std::function<bool(TreeIter&)>& func) = 0;
1212 // call func on each visible element until func returns true or we run out of elements
1213 virtual void visible_foreach(const std::function<bool(TreeIter&)>& func) = 0;
1214 // clear the children of pParent (whole tree if nullptr),
1215 // then add nSourceCount rows under pParent, call func on each row
1216 // inserted with an arg of the index that this row will be when bulk insert
1217 // ends.
1219 // this enables inserting the entries backwards in models where that is faster,
1221 // pFixedWidths is optional, when present each matching entry col text
1222 // width will not be measured, and the fixed width used instead. Use
1223 // sparingly because wider text than the fixed width is clipped and cannot
1224 // be scrolled into view horizontally.
1225 virtual void bulk_insert_for_each(int nSourceCount,
1226 const std::function<void(TreeIter&, int nSourceIndex)>& func,
1227 const weld::TreeIter* pParent = nullptr,
1228 const std::vector<int>* pFixedWidths = nullptr)
1229 = 0;
1231 /* expanding on-demand node details
1233 When a node is added with children-on-demand (typically via 'insert' with
1234 bChildrenOnDemand of true), then initially in reality the
1235 children-on-demand node is given a 'placeholder' child entry to indicate
1236 the load-on-demand state.
1238 The 'placeholder' needs to be there for the expander indicator to be
1239 drawn/shown even when there are no "real" entries yet. This child doesn't
1240 exist for the purposes of any of the iterator methods, e.g. iter_has_child
1241 on an on-demand node which hasn't been expanded yet is false. Likewise the
1242 rest of the iterator methods skip over or otherwise ignore that node.
1244 Normal usage is the user clicks on the expander, the expansion mechanism
1245 removes the 'placeholder' entry (set_children_on_demand(false)) and calls
1246 any installed expanding-callback (installable via connect_expanding) which
1247 has the opportunity to populate the node with children.
1249 If you decide to directly populate the children of an on-demand node
1250 outside of the expanding-callback then you also need to explicitly remove
1251 the 'placeholder' with set_children_on_demand(false) otherwise the treeview
1252 is in an inconsistent state. */
1254 virtual bool get_row_expanded(const TreeIter& rIter) const = 0;
1255 // expand row will first trigger the callback set via connect_expanding before expanding
1256 virtual void expand_row(const TreeIter& rIter) = 0;
1257 // collapse row will first trigger the callback set via connect_collapsing before collapsing
1258 virtual void collapse_row(const TreeIter& rIter) = 0;
1259 // set the empty node to appear as if it has children, true is equivalent
1260 // to 'insert' with a bChildrenOnDemand of true. See notes above.
1261 virtual void set_children_on_demand(const TreeIter& rIter, bool bChildrenOnDemand) = 0;
1262 // return if the node is configured to be populated on-demand
1263 virtual bool get_children_on_demand(const TreeIter& rIter) const = 0;
1264 // set if the expanders are shown or not
1265 virtual void set_show_expanders(bool bShow) = 0;
1267 void connect_expanding(const Link<const TreeIter&, bool>& rLink) { m_aExpandingHdl = rLink; }
1268 void connect_collapsing(const Link<const TreeIter&, bool>& rLink) { m_aCollapsingHdl = rLink; }
1270 // rStartLink returns true to allow editing, false to disallow
1271 // rEndLink returns true to accept the edit, false to reject
1272 virtual void connect_editing(const Link<const TreeIter&, bool>& rStartLink,
1273 const Link<const iter_string&, bool>& rEndLink)
1275 assert(rStartLink.IsSet() == rEndLink.IsSet() && "should be both on or both off");
1276 m_aEditingStartedHdl = rStartLink;
1277 m_aEditingDoneHdl = rEndLink;
1280 virtual void start_editing(const weld::TreeIter& rEntry) = 0;
1281 virtual void end_editing() = 0;
1283 virtual void connect_visible_range_changed(const Link<TreeView&, void>& rLink)
1285 assert(!m_aVisibleRangeChangedHdl.IsSet() || !rLink.IsSet());
1286 m_aVisibleRangeChangedHdl = rLink;
1289 virtual void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink)
1291 m_aPopupMenuHdl = rLink;
1294 virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& rTransferable,
1295 sal_uInt8 eDNDConstants)
1296 = 0;
1298 void connect_drag_begin(const Link<bool&, bool>& rLink) { m_aDragBeginHdl = rLink; }
1300 //all of them. Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1301 void select_all() { unselect(-1); }
1302 void unselect_all() { select(-1); }
1304 // return the number of toplevel nodes
1305 virtual int n_children() const = 0;
1307 // afterwards, entries will be in default ascending sort order
1308 virtual void make_sorted() = 0;
1309 virtual void make_unsorted() = 0;
1310 virtual bool get_sort_order() const = 0;
1311 virtual void set_sort_order(bool bAscending) = 0;
1313 // TRUE ascending, FALSE, descending, INDET, neither (off)
1314 virtual void set_sort_indicator(TriState eState, int nColumn) = 0;
1315 virtual TriState get_sort_indicator(int nColumn) const = 0;
1317 virtual int get_sort_column() const = 0;
1318 virtual void set_sort_column(int nColumn) = 0;
1320 virtual void
1321 set_sort_func(const std::function<int(const weld::TreeIter&, const weld::TreeIter&)>& func)
1323 m_aCustomSort = func;
1326 virtual void clear() = 0;
1327 virtual int get_height_rows(int nRows) const = 0;
1329 virtual void columns_autosize() = 0;
1330 virtual void set_column_fixed_widths(const std::vector<int>& rWidths) = 0;
1331 virtual void set_column_editables(const std::vector<bool>& rEditables) = 0;
1332 virtual int get_column_width(int nCol) const = 0;
1333 virtual void set_centered_column(int nCol) = 0;
1334 virtual OUString get_column_title(int nColumn) const = 0;
1335 virtual void set_column_title(int nColumn, const OUString& rTitle) = 0;
1337 int get_checkbox_column_width() const { return get_approximate_digit_width() * 3 + 6; }
1339 virtual void set_selection_mode(SelectionMode eMode) = 0;
1340 virtual int count_selected_rows() const = 0;
1341 // remove the selected nodes
1342 virtual void remove_selection() = 0;
1344 // only meaningful is call this from a "changed" callback, true if the change
1345 // was due to mouse hovering over the entry
1346 virtual bool changed_by_hover() const = 0;
1348 virtual void vadjustment_set_value(int value) = 0;
1349 virtual int vadjustment_get_value() const = 0;
1351 void save_value() { m_sSavedValue = get_selected_text(); }
1352 OUString const& get_saved_value() const { return m_sSavedValue; }
1353 bool get_value_changed_from_saved() const { return m_sSavedValue != get_selected_text(); }
1355 // for custom rendering a cell
1356 void connect_custom_get_size(const Link<get_size_args, Size>& rLink) { m_aGetSizeHdl = rLink; }
1357 void connect_custom_render(const Link<render_args, void>& rLink) { m_aRenderHdl = rLink; }
1358 // call set_column_custom_renderer after setting custom callbacks
1359 virtual void set_column_custom_renderer(int nColumn, bool bEnable) = 0;
1360 // redraw all rows, typically only useful with custom rendering to redraw due to external
1361 // state change
1362 virtual void queue_draw() = 0;
1364 /* with bDnDMode false simply return the row under the point
1366 * with bDnDMode true:
1367 * a) return the row which should be dropped on, which may
1368 * be different from the row the mouse is over in some backends where
1369 * positioning the mouse on the bottom half of a row indicates to drop
1370 * after the row
1371 * b) dnd highlight the dest row
1373 virtual bool get_dest_row_at_pos(const Point& rPos, weld::TreeIter* pResult, bool bDnDMode,
1374 bool bAutoScroll = true)
1375 = 0;
1376 virtual void unset_drag_dest_row() = 0;
1377 virtual tools::Rectangle get_row_area(const weld::TreeIter& rIter) const = 0;
1378 // for dragging and dropping between TreeViews, return the active source
1379 virtual TreeView* get_drag_source() const = 0;
1381 using Widget::set_sensitive;
1382 using Widget::get_sensitive;
1385 typedef std::tuple<tools::JsonWriter&, const TreeIter&, std::string_view> json_prop_query;
1387 class VCL_DLLPUBLIC IconView : virtual public Widget
1389 friend class ::LOKTrigger;
1391 private:
1392 OUString m_sSavedValue;
1394 protected:
1395 Link<IconView&, void> m_aSelectionChangeHdl;
1396 Link<IconView&, bool> m_aItemActivatedHdl;
1397 Link<const CommandEvent&, bool> m_aCommandHdl;
1398 Link<const TreeIter&, OUString> m_aQueryTooltipHdl;
1399 Link<const json_prop_query&, bool> m_aGetPropertyTreeElemHdl;
1401 void signal_selection_changed() { m_aSelectionChangeHdl.Call(*this); }
1402 bool signal_item_activated() { return m_aItemActivatedHdl.Call(*this); }
1403 OUString signal_query_tooltip(const TreeIter& rIter) const
1405 return m_aQueryTooltipHdl.Call(rIter);
1408 public:
1409 virtual int get_item_width() const = 0;
1410 virtual void set_item_width(int width) = 0;
1412 virtual void insert(int pos, const OUString* pStr, const OUString* pId,
1413 const OUString* pIconName, TreeIter* pRet)
1414 = 0;
1416 virtual void insert(int pos, const OUString* pStr, const OUString* pId,
1417 const VirtualDevice* pIcon, TreeIter* pRet)
1418 = 0;
1420 virtual void insert_separator(int pos, const OUString* pId) = 0;
1422 void append(const OUString& rId, const OUString& rStr, const OUString& rImage)
1424 insert(-1, &rStr, &rId, &rImage, nullptr);
1427 void append(const OUString& rId, const OUString& rStr, const VirtualDevice* pImage)
1429 insert(-1, &rStr, &rId, pImage, nullptr);
1432 void append_separator(const OUString& rId) { insert_separator(-1, &rId); }
1434 void connect_selection_changed(const Link<IconView&, void>& rLink)
1436 m_aSelectionChangeHdl = rLink;
1439 /* A row is "activated" when the user double clicks a treeview row. It may
1440 also be emitted when a row is selected and Space or Enter is pressed.
1442 a return of "true" means the activation has been handled, a "false" propagates
1443 the activation to the default handler which expands/collapses the row, if possible.
1445 void connect_item_activated(const Link<IconView&, bool>& rLink) { m_aItemActivatedHdl = rLink; }
1447 void connect_command(const Link<const CommandEvent&, bool>& rLink) { m_aCommandHdl = rLink; }
1449 virtual void connect_query_tooltip(const Link<const TreeIter&, OUString>& rLink)
1451 m_aQueryTooltipHdl = rLink;
1454 // 0: json writer, 1: TreeIter, 2: property. returns true if supported
1455 virtual void connect_get_property_tree_elem(const Link<const json_prop_query&, bool>& rLink)
1457 m_aGetPropertyTreeElemHdl = rLink;
1460 virtual OUString get_selected_id() const = 0;
1462 virtual void clear() = 0;
1464 virtual int count_selected_items() const = 0;
1466 virtual OUString get_selected_text() const = 0;
1468 //by index. Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1469 virtual void select(int pos) = 0;
1470 virtual void unselect(int pos) = 0;
1472 //via iter
1473 virtual std::unique_ptr<TreeIter> make_iterator(const TreeIter* pOrig = nullptr) const = 0;
1474 virtual bool get_selected(TreeIter* pIter) const = 0;
1475 virtual bool get_cursor(TreeIter* pIter) const = 0;
1476 virtual void set_cursor(const TreeIter& rIter) = 0;
1477 virtual bool get_iter_first(TreeIter& rIter) const = 0;
1478 virtual OUString get_id(const TreeIter& rIter) const = 0;
1479 virtual OUString get_text(const TreeIter& rIter) const = 0;
1480 virtual void scroll_to_item(const TreeIter& rIter) = 0;
1482 // call func on each selected element until func returns true or we run out of elements
1483 virtual void selected_foreach(const std::function<bool(TreeIter&)>& func) = 0;
1485 //all of them. Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
1486 void select_all() { unselect(-1); }
1487 void unselect_all() { select(-1); }
1489 // return the number of toplevel nodes
1490 virtual int n_children() const = 0;
1492 void save_value() { m_sSavedValue = get_selected_text(); }
1493 OUString const& get_saved_value() const { return m_sSavedValue; }
1494 bool get_value_changed_from_saved() const { return m_sSavedValue != get_selected_text(); }
1497 class VCL_DLLPUBLIC Button : virtual public Widget
1499 friend class ::LOKTrigger;
1501 protected:
1502 Link<Button&, void> m_aClickHdl;
1504 void signal_clicked() { m_aClickHdl.Call(*this); }
1506 public:
1507 virtual void set_label(const OUString& rText) = 0;
1508 // pDevice, the image for the button, or nullptr to unset
1509 virtual void set_image(VirtualDevice* pDevice) = 0;
1510 virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage) = 0;
1511 virtual void set_from_icon_name(const OUString& rIconName) = 0;
1512 virtual OUString get_label() const = 0;
1513 void clicked() { signal_clicked(); }
1514 bool is_custom_handler_set() { return m_aClickHdl.IsSet(); }
1516 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
1517 virtual void set_font(const vcl::Font& rFont) = 0;
1519 /* Sometimes, a widget should behave like a button (activate on click,
1520 accept keyboard focus, etc), but look entirely different.
1522 pDevice, the custom look to use, or nullptr to unset.
1524 Typically doing this is ill advised. Consider using
1525 set_accessible_name if you do. */
1526 virtual void set_custom_button(VirtualDevice* pDevice) = 0;
1528 void connect_clicked(const Link<Button&, void>& rLink) { m_aClickHdl = rLink; }
1531 class VCL_DLLPUBLIC Toggleable : virtual public Widget
1533 friend class ::LOKTrigger;
1535 protected:
1536 Link<Toggleable&, void> m_aToggleHdl;
1537 TriState m_eSavedValue = TRISTATE_FALSE;
1539 void signal_toggled() { m_aToggleHdl.Call(*this); }
1541 public:
1542 virtual void set_active(bool active) = 0;
1543 virtual bool get_active() const = 0;
1545 virtual void set_inconsistent(bool inconsistent) = 0;
1546 virtual bool get_inconsistent() const = 0;
1548 TriState get_state() const
1550 if (get_inconsistent())
1551 return TRISTATE_INDET;
1552 else if (get_active())
1553 return TRISTATE_TRUE;
1554 return TRISTATE_FALSE;
1557 void set_state(TriState eState)
1559 switch (eState)
1561 case TRISTATE_INDET:
1562 set_inconsistent(true);
1563 break;
1564 case TRISTATE_TRUE:
1565 set_inconsistent(false);
1566 set_active(true);
1567 break;
1568 case TRISTATE_FALSE:
1569 set_inconsistent(false);
1570 set_active(false);
1571 break;
1575 void save_state() { m_eSavedValue = get_state(); }
1576 TriState get_saved_state() const { return m_eSavedValue; }
1577 bool get_state_changed_from_saved() const { return m_eSavedValue != get_state(); }
1579 virtual void connect_toggled(const Link<Toggleable&, void>& rLink) { m_aToggleHdl = rLink; }
1582 class VCL_DLLPUBLIC ToggleButton : virtual public Button, virtual public Toggleable
1584 friend class ::LOKTrigger;
1587 struct VCL_DLLPUBLIC TriStateEnabled
1589 TriState eState;
1590 bool bTriStateEnabled;
1591 TriStateEnabled()
1592 : eState(TRISTATE_INDET)
1593 , bTriStateEnabled(true)
1596 void ButtonToggled(Toggleable& rToggle);
1599 class VCL_DLLPUBLIC MenuButton : virtual public ToggleButton
1601 friend class ::LOKTrigger;
1603 Link<const OUString&, void> m_aSelectHdl;
1605 protected:
1606 void signal_selected(const OUString& rIdent) { m_aSelectHdl.Call(rIdent); }
1608 public:
1609 void connect_selected(const Link<const OUString&, void>& rLink) { m_aSelectHdl = rLink; }
1611 virtual void insert_item(int pos, const OUString& rId, const OUString& rStr,
1612 const OUString* pIconName, VirtualDevice* pImageSurface,
1613 TriState eCheckRadioFalse)
1614 = 0;
1615 void append_item(const OUString& rId, const OUString& rStr)
1617 insert_item(-1, rId, rStr, nullptr, nullptr, TRISTATE_INDET);
1619 void append_item_check(const OUString& rId, const OUString& rStr)
1621 insert_item(-1, rId, rStr, nullptr, nullptr, TRISTATE_TRUE);
1623 void append_item_radio(const OUString& rId, const OUString& rStr)
1625 insert_item(-1, rId, rStr, nullptr, nullptr, TRISTATE_FALSE);
1627 void append_item(const OUString& rId, const OUString& rStr, const OUString& rImage)
1629 insert_item(-1, rId, rStr, &rImage, nullptr, TRISTATE_INDET);
1631 void append_item(const OUString& rId, const OUString& rStr, VirtualDevice& rImage)
1633 insert_item(-1, rId, rStr, nullptr, &rImage, TRISTATE_INDET);
1635 virtual void insert_separator(int pos, const OUString& rId) = 0;
1636 void append_separator(const OUString& rId) { insert_separator(-1, rId); }
1637 virtual void remove_item(const OUString& rId) = 0;
1638 virtual void clear() = 0;
1639 virtual void set_item_sensitive(const OUString& rIdent, bool bSensitive) = 0;
1640 virtual void set_item_active(const OUString& rIdent, bool bActive) = 0;
1641 virtual void set_item_label(const OUString& rIdent, const OUString& rLabel) = 0;
1642 virtual OUString get_item_label(const OUString& rIdent) const = 0;
1643 virtual void set_item_visible(const OUString& rIdent, bool bVisible) = 0;
1645 virtual void set_popover(weld::Widget* pPopover) = 0;
1648 // Similar to a MenuButton except it is split into two parts, a toggle
1649 // button at the start and a menubutton at the end
1650 class VCL_DLLPUBLIC MenuToggleButton : virtual public MenuButton
1654 class VCL_DLLPUBLIC CheckButton : virtual public Toggleable
1656 public:
1657 virtual void set_label(const OUString& rText) = 0;
1658 virtual OUString get_label() const = 0;
1659 virtual void set_label_wrap(bool wrap) = 0;
1662 class VCL_DLLPUBLIC RadioButton : virtual public CheckButton
1666 class VCL_DLLPUBLIC LinkButton : virtual public Widget
1668 friend class ::LOKTrigger;
1670 Link<LinkButton&, bool> m_aActivateLinkHdl;
1672 protected:
1673 bool signal_activate_link() { return m_aActivateLinkHdl.Call(*this); }
1675 public:
1676 virtual void set_label(const OUString& rText) = 0;
1677 virtual OUString get_label() const = 0;
1678 virtual void set_label_wrap(bool wrap) = 0;
1679 virtual void set_uri(const OUString& rUri) = 0;
1680 virtual OUString get_uri() const = 0;
1682 void connect_activate_link(const Link<LinkButton&, bool>& rLink) { m_aActivateLinkHdl = rLink; }
1685 class VCL_DLLPUBLIC Scale : virtual public Widget
1687 Link<Scale&, void> m_aValueChangedHdl;
1689 protected:
1690 void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
1692 public:
1693 virtual void set_value(int value) = 0;
1694 virtual int get_value() const = 0;
1695 virtual void set_range(int min, int max) = 0;
1697 virtual void set_increments(int step, int page) = 0;
1698 virtual void get_increments(int& step, int& page) const = 0;
1700 void connect_value_changed(const Link<Scale&, void>& rLink) { m_aValueChangedHdl = rLink; }
1703 class VCL_DLLPUBLIC Spinner : virtual public Widget
1705 public:
1706 virtual void start() = 0;
1707 virtual void stop() = 0;
1710 class VCL_DLLPUBLIC ProgressBar : virtual public Widget
1712 public:
1713 //0-100
1714 virtual void set_percentage(int value) = 0;
1715 virtual OUString get_text() const = 0;
1716 virtual void set_text(const OUString& rText) = 0;
1719 class VCL_DLLPUBLIC LevelBar : virtual public Widget
1721 public:
1722 /// Sets LevelBar fill percentage.
1723 /// @param fPercentage bar's fill percentage, [0.0, 100.0]
1724 virtual void set_percentage(double fPercentage) = 0;
1727 class VCL_DLLPUBLIC Entry : virtual public Widget
1729 private:
1730 OUString m_sSavedValue;
1732 protected:
1733 Link<Entry&, void> m_aChangeHdl;
1734 Link<OUString&, bool> m_aInsertTextHdl;
1735 Link<Entry&, void> m_aCursorPositionHdl;
1736 Link<Entry&, bool> m_aActivateHdl;
1738 friend class ::LOKTrigger;
1740 void signal_changed() { m_aChangeHdl.Call(*this); }
1741 void signal_cursor_position() { m_aCursorPositionHdl.Call(*this); }
1743 public:
1744 virtual void set_text(const OUString& rText) = 0;
1745 virtual OUString get_text() const = 0;
1746 virtual void set_width_chars(int nChars) = 0;
1747 virtual int get_width_chars() const = 0;
1748 // The maximum length of the entry. Use 0 for no maximum
1749 virtual void set_max_length(int nChars) = 0;
1750 // nEndPos can be -1 in order to select all text
1751 virtual void select_region(int nStartPos, int nEndPos) = 0;
1752 // returns true if the selection has nonzero length
1753 virtual bool get_selection_bounds(int& rStartPos, int& rEndPos) = 0;
1754 virtual void replace_selection(const OUString& rText) = 0;
1755 // nCursorPos can be -1 to set to the end
1756 virtual void set_position(int nCursorPos) = 0;
1757 virtual int get_position() const = 0;
1758 virtual void set_editable(bool bEditable) = 0;
1759 virtual bool get_editable() const = 0;
1760 virtual void set_message_type(EntryMessageType eType) = 0;
1761 virtual void set_placeholder_text(const OUString& rText) = 0;
1763 virtual void set_overwrite_mode(bool bOn) = 0;
1764 virtual bool get_overwrite_mode() const = 0;
1766 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
1767 virtual void set_font(const vcl::Font& rFont) = 0;
1770 If you want to set a warning or error state, see set_message_type
1771 instead where, if the toolkit supports it, a specific warning/error
1772 indicator is shown.
1774 This explicit text color method exists to support rendering the
1775 SvNumberformat color feature.
1777 virtual void set_font_color(const Color& rColor) = 0;
1779 virtual void connect_changed(const Link<Entry&, void>& rLink) { m_aChangeHdl = rLink; }
1780 void connect_insert_text(const Link<OUString&, bool>& rLink) { m_aInsertTextHdl = rLink; }
1781 // callback returns true to indicated no further processing of activate wanted
1782 void connect_activate(const Link<Entry&, bool>& rLink) { m_aActivateHdl = rLink; }
1783 virtual void connect_cursor_position(const Link<Entry&, void>& rLink)
1785 m_aCursorPositionHdl = rLink;
1788 virtual void cut_clipboard() = 0;
1789 virtual void copy_clipboard() = 0;
1790 virtual void paste_clipboard() = 0;
1792 virtual void set_alignment(TxtAlign eXAlign) = 0;
1794 void save_value() { m_sSavedValue = get_text(); }
1795 OUString const& get_saved_value() const { return m_sSavedValue; }
1796 bool get_value_changed_from_saved() const { return m_sSavedValue != get_text(); }
1799 class VCL_DLLPUBLIC SpinButton : virtual public Entry
1801 friend class ::LOKTrigger;
1803 Link<SpinButton&, void> m_aValueChangedHdl;
1804 Link<SpinButton&, void> m_aOutputHdl;
1805 Link<int*, bool> m_aInputHdl;
1807 protected:
1808 void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
1810 bool signal_output()
1812 if (!m_aOutputHdl.IsSet())
1813 return false;
1814 m_aOutputHdl.Call(*this);
1815 return true;
1818 TriState signal_input(int* result)
1820 if (!m_aInputHdl.IsSet())
1821 return TRISTATE_INDET;
1822 return m_aInputHdl.Call(result) ? TRISTATE_TRUE : TRISTATE_FALSE;
1825 public:
1826 virtual void set_value(sal_Int64 value) = 0;
1827 virtual sal_Int64 get_value() const = 0;
1828 virtual void set_range(sal_Int64 min, sal_Int64 max) = 0;
1829 virtual void get_range(sal_Int64& min, sal_Int64& max) const = 0;
1830 void set_min(sal_Int64 min)
1832 sal_Int64 dummy, max;
1833 get_range(dummy, max);
1834 set_range(min, max);
1836 void set_max(sal_Int64 max)
1838 sal_Int64 min, dummy;
1839 get_range(min, dummy);
1840 set_range(min, max);
1842 sal_Int64 get_min() const
1844 sal_Int64 min, dummy;
1845 get_range(min, dummy);
1846 return min;
1848 sal_Int64 get_max() const
1850 sal_Int64 dummy, max;
1851 get_range(dummy, max);
1852 return max;
1854 virtual void set_increments(int step, int page) = 0;
1855 virtual void get_increments(int& step, int& page) const = 0;
1856 virtual void set_digits(unsigned int digits) = 0;
1857 virtual unsigned int get_digits() const = 0;
1859 void connect_value_changed(const Link<SpinButton&, void>& rLink) { m_aValueChangedHdl = rLink; }
1861 void connect_output(const Link<SpinButton&, void>& rLink) { m_aOutputHdl = rLink; }
1862 void connect_input(const Link<int*, bool>& rLink) { m_aInputHdl = rLink; }
1864 sal_Int64 normalize(sal_Int64 nValue) const { return (nValue * Power10(get_digits())); }
1866 sal_Int64 denormalize(sal_Int64 nValue) const;
1868 static unsigned int Power10(unsigned int n);
1871 class EntryFormatter;
1873 // Similar to a SpinButton, but input and output formatting and range/value
1874 // are managed by a more complex Formatter which can support doubles.
1875 class VCL_DLLPUBLIC FormattedSpinButton : virtual public Entry
1877 friend class ::LOKTrigger;
1879 Link<FormattedSpinButton&, void> m_aValueChangedHdl;
1881 protected:
1882 void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
1884 public:
1885 virtual Formatter& GetFormatter() = 0;
1886 // does not take ownership, and so must be deregistered if pFormatter
1887 // is destroyed
1888 virtual void SetFormatter(weld::EntryFormatter* pFormatter) = 0;
1890 void connect_value_changed(const Link<FormattedSpinButton&, void>& rLink)
1892 m_aValueChangedHdl = rLink;
1895 private:
1896 friend class EntryFormatter;
1897 virtual void sync_range_from_formatter() = 0;
1898 virtual void sync_value_from_formatter() = 0;
1899 virtual void sync_increments_from_formatter() = 0;
1902 class VCL_DLLPUBLIC Image : virtual public Widget
1904 public:
1905 virtual void set_from_icon_name(const OUString& rIconName) = 0;
1906 virtual void set_image(VirtualDevice* pDevice) = 0;
1907 virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage) = 0;
1910 class VCL_DLLPUBLIC Calendar : virtual public Widget
1912 friend class ::LOKTrigger;
1914 Link<Calendar&, void> m_aSelectedHdl;
1915 Link<Calendar&, void> m_aActivatedHdl;
1917 protected:
1918 void signal_selected() { m_aSelectedHdl.Call(*this); }
1919 void signal_activated() { m_aActivatedHdl.Call(*this); }
1921 public:
1922 void connect_selected(const Link<Calendar&, void>& rLink) { m_aSelectedHdl = rLink; }
1923 void connect_activated(const Link<Calendar&, void>& rLink) { m_aActivatedHdl = rLink; }
1925 virtual void set_date(const Date& rDate) = 0;
1926 virtual Date get_date() const = 0;
1929 // an entry + treeview pair, where the entry autocompletes from the
1930 // treeview list, and selecting something in the list sets the
1931 // entry to that text, i.e. a visually exploded ComboBox
1932 class VCL_DLLPUBLIC EntryTreeView : virtual public ComboBox
1934 private:
1935 DECL_DLLPRIVATE_LINK(ClickHdl, weld::TreeView&, void);
1936 DECL_DLLPRIVATE_LINK(ModifyHdl, weld::Entry&, void);
1937 void EntryModifyHdl(const weld::Entry& rEntry);
1939 protected:
1940 std::unique_ptr<Entry> m_xEntry;
1941 std::unique_ptr<TreeView> m_xTreeView;
1943 public:
1944 EntryTreeView(std::unique_ptr<Entry> xEntry, std::unique_ptr<TreeView> xTreeView);
1946 virtual void insert_vector(const std::vector<weld::ComboBoxEntry>& rItems,
1947 bool bKeepExisting) override
1949 m_xTreeView->freeze();
1950 if (!bKeepExisting)
1951 m_xTreeView->clear();
1952 for (const auto& rItem : rItems)
1953 append(rItem);
1954 m_xTreeView->thaw();
1957 virtual void insert(int pos, const OUString& rStr, const OUString* pId,
1958 const OUString* pIconName, VirtualDevice* pImageSurface) override
1960 m_xTreeView->insert(pos, rStr, pId, pIconName, pImageSurface);
1963 virtual int get_count() const override { return m_xTreeView->n_children(); }
1964 virtual void clear() override { m_xTreeView->clear(); }
1966 //by index
1967 virtual int get_active() const override { return m_xTreeView->get_selected_index(); }
1968 virtual void set_active(int pos) override
1970 m_xTreeView->set_cursor(pos);
1971 m_xTreeView->select(pos);
1972 m_xEntry->set_text(m_xTreeView->get_selected_text());
1974 virtual void remove(int pos) override { m_xTreeView->remove(pos); }
1976 //by text
1977 virtual OUString get_active_text() const override { return m_xEntry->get_text(); }
1978 virtual OUString get_text(int pos) const override { return m_xTreeView->get_text(pos); }
1979 virtual int find_text(const OUString& rStr) const override
1981 return m_xTreeView->find_text(rStr);
1984 //by id
1985 virtual OUString get_active_id() const override { return m_xTreeView->get_selected_id(); }
1986 virtual void set_active_id(const OUString& rStr) override
1988 m_xTreeView->select_id(rStr);
1989 m_xEntry->set_text(m_xTreeView->get_selected_text());
1991 virtual OUString get_id(int pos) const override { return m_xTreeView->get_id(pos); }
1992 virtual void set_id(int pos, const OUString& rId) override { m_xTreeView->set_id(pos, rId); }
1993 virtual int find_id(const OUString& rId) const override { return m_xTreeView->find_id(rId); }
1995 //entry related
1996 virtual bool has_entry() const override { return true; }
1997 virtual void set_entry_message_type(EntryMessageType eType) override
1999 m_xEntry->set_message_type(eType);
2001 virtual void set_entry_text(const OUString& rStr) override { m_xEntry->set_text(rStr); }
2002 virtual void set_entry_width_chars(int nChars) override { m_xEntry->set_width_chars(nChars); }
2003 virtual void set_entry_max_length(int nChars) override { m_xEntry->set_max_length(nChars); }
2004 virtual void select_entry_region(int nStartPos, int nEndPos) override
2006 m_xEntry->select_region(nStartPos, nEndPos);
2008 //if no text was selected, both rStartPos and rEndPos will be identical
2009 //and false will be returned
2010 virtual bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) override
2012 return m_xEntry->get_selection_bounds(rStartPos, rEndPos);
2014 void connect_row_activated(const Link<TreeView&, bool>& rLink)
2016 m_xTreeView->connect_row_activated(rLink);
2019 virtual bool get_popup_shown() const override { return false; }
2021 void set_height_request_by_rows(int nRows);
2024 class VCL_DLLPUBLIC MetricSpinButton final
2026 FieldUnit m_eSrcUnit;
2027 std::unique_ptr<weld::SpinButton> m_xSpinButton;
2028 Link<MetricSpinButton&, void> m_aValueChangedHdl;
2030 DECL_LINK(spin_button_value_changed, weld::SpinButton&, void);
2031 DECL_LINK(spin_button_output, weld::SpinButton&, void);
2032 DECL_LINK(spin_button_input, int* result, bool);
2034 void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
2036 sal_Int64 ConvertValue(sal_Int64 nValue, FieldUnit eInUnit, FieldUnit eOutUnit) const;
2037 OUString format_number(sal_Int64 nValue) const;
2038 void update_width_chars();
2040 public:
2041 MetricSpinButton(std::unique_ptr<SpinButton> pSpinButton, FieldUnit eSrcUnit)
2042 : m_eSrcUnit(eSrcUnit)
2043 , m_xSpinButton(std::move(pSpinButton))
2045 update_width_chars();
2046 m_xSpinButton->connect_output(LINK(this, MetricSpinButton, spin_button_output));
2047 m_xSpinButton->connect_input(LINK(this, MetricSpinButton, spin_button_input));
2048 m_xSpinButton->connect_value_changed(
2049 LINK(this, MetricSpinButton, spin_button_value_changed));
2050 spin_button_output(*m_xSpinButton);
2053 static OUString MetricToString(FieldUnit rUnit);
2055 FieldUnit get_unit() const { return m_eSrcUnit; }
2057 void set_unit(FieldUnit eUnit);
2059 sal_Int64 convert_value_to(sal_Int64 nValue, FieldUnit eValueUnit) const
2061 return ConvertValue(nValue, m_eSrcUnit, eValueUnit);
2064 sal_Int64 convert_value_from(sal_Int64 nValue, FieldUnit eValueUnit) const
2066 return ConvertValue(nValue, eValueUnit, m_eSrcUnit);
2069 void set_value(sal_Int64 nValue, FieldUnit eValueUnit)
2071 m_xSpinButton->set_value(convert_value_from(nValue, eValueUnit));
2074 sal_Int64 get_value(FieldUnit eDestUnit) const
2076 return convert_value_to(m_xSpinButton->get_value(), eDestUnit);
2079 // typically you only need to call this if set_text (e.g. with "") was
2080 // previously called to display some arbitrary text instead of the
2081 // formatted value and now you want to show it as formatted again
2082 void reformat() { spin_button_output(*m_xSpinButton); }
2084 void set_range(sal_Int64 min, sal_Int64 max, FieldUnit eValueUnit)
2086 min = convert_value_from(min, eValueUnit);
2087 max = convert_value_from(max, eValueUnit);
2088 m_xSpinButton->set_range(min, max);
2089 update_width_chars();
2092 void get_range(sal_Int64& min, sal_Int64& max, FieldUnit eDestUnit) const
2094 m_xSpinButton->get_range(min, max);
2095 min = convert_value_to(min, eDestUnit);
2096 max = convert_value_to(max, eDestUnit);
2099 void set_min(sal_Int64 min, FieldUnit eValueUnit)
2101 sal_Int64 dummy, max;
2102 get_range(dummy, max, eValueUnit);
2103 set_range(min, max, eValueUnit);
2106 void set_max(sal_Int64 max, FieldUnit eValueUnit)
2108 sal_Int64 min, dummy;
2109 get_range(min, dummy, eValueUnit);
2110 set_range(min, max, eValueUnit);
2113 sal_Int64 get_min(FieldUnit eValueUnit) const
2115 sal_Int64 min, dummy;
2116 get_range(min, dummy, eValueUnit);
2117 return min;
2120 sal_Int64 get_max(FieldUnit eValueUnit) const
2122 sal_Int64 dummy, max;
2123 get_range(dummy, max, eValueUnit);
2124 return max;
2127 void set_increments(int step, int page, FieldUnit eValueUnit)
2129 step = convert_value_from(step, eValueUnit);
2130 page = convert_value_from(page, eValueUnit);
2131 m_xSpinButton->set_increments(step, page);
2134 void get_increments(int& step, int& page, FieldUnit eDestUnit) const
2136 m_xSpinButton->get_increments(step, page);
2137 step = convert_value_to(step, eDestUnit);
2138 page = convert_value_to(page, eDestUnit);
2141 void connect_value_changed(const Link<MetricSpinButton&, void>& rLink)
2143 m_aValueChangedHdl = rLink;
2146 sal_Int64 normalize(sal_Int64 nValue) const { return m_xSpinButton->normalize(nValue); }
2147 sal_Int64 denormalize(sal_Int64 nValue) const { return m_xSpinButton->denormalize(nValue); }
2148 void set_sensitive(bool sensitive) { m_xSpinButton->set_sensitive(sensitive); }
2149 bool get_sensitive() const { return m_xSpinButton->get_sensitive(); }
2150 bool get_visible() const { return m_xSpinButton->get_visible(); }
2151 void grab_focus() { m_xSpinButton->grab_focus(); }
2152 bool has_focus() const { return m_xSpinButton->has_focus(); }
2153 void show() { m_xSpinButton->show(); }
2154 void set_visible(bool bShow) { m_xSpinButton->set_visible(bShow); }
2155 void hide() { m_xSpinButton->hide(); }
2156 void set_digits(unsigned int digits);
2157 void set_accessible_name(const OUString& rName) { m_xSpinButton->set_accessible_name(rName); }
2158 unsigned int get_digits() const { return m_xSpinButton->get_digits(); }
2159 void save_value() { m_xSpinButton->save_value(); }
2160 bool get_value_changed_from_saved() const
2162 return m_xSpinButton->get_value_changed_from_saved();
2164 void set_text(const OUString& rText) { m_xSpinButton->set_text(rText); }
2165 OUString get_text() const { return m_xSpinButton->get_text(); }
2166 void set_size_request(int nWidth, int nHeight)
2168 m_xSpinButton->set_size_request(nWidth, nHeight);
2170 Size get_size_request() const { return m_xSpinButton->get_size_request(); }
2171 Size get_preferred_size() const { return m_xSpinButton->get_preferred_size(); }
2172 void connect_focus_in(const Link<Widget&, void>& rLink)
2174 m_xSpinButton->connect_focus_in(rLink);
2176 void connect_focus_out(const Link<Widget&, void>& rLink)
2178 m_xSpinButton->connect_focus_out(rLink);
2180 OUString get_buildable_name() const { return m_xSpinButton->get_buildable_name(); }
2181 void set_help_id(const OUString& rName) { m_xSpinButton->set_help_id(rName); }
2182 void set_position(int nCursorPos) { m_xSpinButton->set_position(nCursorPos); }
2183 // set the width of the underlying widget in characters, this setting is
2184 // invalidated when changing the units, range or digits, so to have effect
2185 // must come after changing those values
2186 void set_width_chars(int nChars) { m_xSpinButton->set_width_chars(nChars); }
2187 int get_width_chars() const { return m_xSpinButton->get_width_chars(); }
2188 weld::SpinButton& get_widget() { return *m_xSpinButton; }
2191 enum class LabelType
2193 Normal,
2194 Warning,
2195 Error,
2196 Title, // this is intended to be used against the background set by set_title_background
2199 class VCL_DLLPUBLIC Label : virtual public Widget
2201 public:
2202 virtual void set_label(const OUString& rText) = 0;
2203 virtual OUString get_label() const = 0;
2204 virtual void set_mnemonic_widget(Widget* pTarget) = 0;
2205 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
2206 virtual void set_font(const vcl::Font& rFont) = 0;
2207 virtual void set_label_type(LabelType eType) = 0;
2209 If you want to set a warning or error state, see set_label_type
2210 instead.
2212 virtual void set_font_color(const Color& rColor) = 0;
2215 class VCL_DLLPUBLIC TextView : virtual public Widget
2217 friend class ::LOKTrigger;
2219 private:
2220 OUString m_sSavedValue;
2222 protected:
2223 Link<TextView&, void> m_aChangeHdl;
2224 Link<TextView&, void> m_aVChangeHdl;
2225 Link<TextView&, void> m_aCursorPositionHdl;
2227 void signal_changed() { m_aChangeHdl.Call(*this); }
2228 void signal_cursor_position() { m_aCursorPositionHdl.Call(*this); }
2229 void signal_vadjustment_changed() { m_aVChangeHdl.Call(*this); }
2231 public:
2232 virtual void set_text(const OUString& rText) = 0;
2233 virtual OUString get_text() const = 0;
2234 // if nStartPos or nEndPos is -1 the max available text pos will be used
2235 virtual void select_region(int nStartPos, int nEndPos) = 0;
2236 // returns true if the selection has nonzero length
2237 virtual bool get_selection_bounds(int& rStartPos, int& rEndPos) = 0;
2238 virtual void replace_selection(const OUString& rText) = 0;
2239 virtual void set_editable(bool bEditable) = 0;
2240 virtual bool get_editable() const = 0;
2241 virtual void set_monospace(bool bMonospace) = 0;
2242 // The maximum length of the entry. Use 0 for no maximum
2243 virtual void set_max_length(int nChars) = 0;
2244 int get_height_rows(int nRows) const
2246 //can improve this if needed
2247 return get_text_height() * nRows;
2250 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
2251 virtual void set_font(const vcl::Font& rFont) = 0;
2254 Typically you want to avoid the temptation of customizing
2255 font colors
2257 virtual void set_font_color(const Color& rColor) = 0;
2259 void save_value() { m_sSavedValue = get_text(); }
2260 bool get_value_changed_from_saved() const { return m_sSavedValue != get_text(); }
2262 void connect_changed(const Link<TextView&, void>& rLink) { m_aChangeHdl = rLink; }
2263 virtual void connect_cursor_position(const Link<TextView&, void>& rLink)
2265 m_aCursorPositionHdl = rLink;
2268 // returns true if pressing up would move the cursor
2269 // doesn't matter if that move is to a previous line or to the start of the
2270 // current line just so long as the cursor would move
2271 virtual bool can_move_cursor_with_up() const = 0;
2273 // returns true if pressing down would move the cursor
2274 // doesn't matter if that move is to a next line or to the end of the
2275 // current line just so long as the cursor would move
2276 virtual bool can_move_cursor_with_down() const = 0;
2278 virtual void cut_clipboard() = 0;
2279 virtual void copy_clipboard() = 0;
2280 virtual void paste_clipboard() = 0;
2282 virtual void set_alignment(TxtAlign eXAlign) = 0;
2284 virtual int vadjustment_get_value() const = 0;
2285 virtual int vadjustment_get_upper() const = 0;
2286 virtual int vadjustment_get_lower() const = 0;
2287 virtual int vadjustment_get_page_size() const = 0;
2288 virtual void vadjustment_set_value(int value) = 0;
2289 void connect_vadjustment_changed(const Link<TextView&, void>& rLink) { m_aVChangeHdl = rLink; }
2292 class VCL_DLLPUBLIC Expander : virtual public Widget
2294 Link<Expander&, void> m_aExpandedHdl;
2296 protected:
2297 void signal_expanded() { m_aExpandedHdl.Call(*this); }
2299 public:
2300 virtual void set_label(const OUString& rText) = 0;
2301 virtual OUString get_label() const = 0;
2302 virtual bool get_expanded() const = 0;
2303 virtual void set_expanded(bool bExpand) = 0;
2305 void connect_expanded(const Link<Expander&, void>& rLink) { m_aExpandedHdl = rLink; }
2308 class VCL_DLLPUBLIC DrawingArea : virtual public Widget
2310 public:
2311 typedef std::pair<vcl::RenderContext&, const tools::Rectangle&> draw_args;
2313 protected:
2314 Link<draw_args, void> m_aDrawHdl;
2315 Link<const CommandEvent&, bool> m_aCommandHdl;
2316 Link<Widget&, tools::Rectangle> m_aGetFocusRectHdl;
2317 Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;
2318 // if handler returns true, drag is disallowed
2319 Link<DrawingArea&, bool> m_aDragBeginHdl;
2320 // return position of cursor, fill OUString& with surrounding text
2321 Link<OUString&, int> m_aGetSurroundingHdl;
2322 // attempt to delete the range, return true if successful
2323 Link<const Selection&, bool> m_aDeleteSurroundingHdl;
2325 OUString signal_query_tooltip(tools::Rectangle& rHelpArea)
2327 return m_aQueryTooltipHdl.Call(rHelpArea);
2330 int signal_im_context_get_surrounding(OUString& rSurroundingText)
2332 if (!m_aGetSurroundingHdl.IsSet())
2333 return -1;
2334 return m_aGetSurroundingHdl.Call(rSurroundingText);
2337 bool signal_im_context_delete_surrounding(const Selection& rRange)
2339 return m_aDeleteSurroundingHdl.Call(rRange);
2342 public:
2343 void connect_draw(const Link<draw_args, void>& rLink) { m_aDrawHdl = rLink; }
2344 void connect_command(const Link<const CommandEvent&, bool>& rLink) { m_aCommandHdl = rLink; }
2345 void connect_focus_rect(const Link<Widget&, tools::Rectangle>& rLink)
2347 m_aGetFocusRectHdl = rLink;
2349 void connect_query_tooltip(const Link<tools::Rectangle&, OUString>& rLink)
2351 m_aQueryTooltipHdl = rLink;
2353 void connect_drag_begin(const Link<DrawingArea&, bool>& rLink) { m_aDragBeginHdl = rLink; }
2354 void connect_im_context_get_surrounding(const Link<OUString&, int>& rLink)
2356 m_aGetSurroundingHdl = rLink;
2358 void connect_im_context_delete_surrounding(const Link<const Selection&, bool>& rLink)
2360 m_aDeleteSurroundingHdl = rLink;
2362 virtual void queue_draw() = 0;
2363 virtual void queue_draw_area(int x, int y, int width, int height) = 0;
2365 virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& rTransferable,
2366 sal_uInt8 eDNDConstants)
2367 = 0;
2369 virtual void set_cursor(PointerStyle ePointerStyle) = 0;
2371 virtual Point get_pointer_position() const = 0;
2373 virtual void set_input_context(const InputContext& rInputContext) = 0;
2374 virtual void im_context_set_cursor_location(const tools::Rectangle& rCursorRect,
2375 int nExtTextInputWidth)
2376 = 0;
2378 // use return here just to generate matching VirtualDevices
2379 virtual OutputDevice& get_ref_device() = 0;
2381 virtual a11yref get_accessible_parent() = 0;
2382 virtual a11yrelationset get_accessible_relation_set() = 0;
2383 virtual AbsoluteScreenPixelPoint get_accessible_location_on_screen() = 0;
2385 private:
2386 friend class ::LOKTrigger;
2388 virtual void click(const Point&) = 0;
2390 virtual void dblclick(const Point&){};
2392 virtual void mouse_up(const Point&){};
2394 virtual void mouse_down(const Point&){};
2396 virtual void mouse_move(const Point&){};
2399 enum class Placement
2401 Under,
2405 class VCL_DLLPUBLIC Menu
2407 Link<const OUString&, void> m_aActivateHdl;
2409 protected:
2410 void signal_activate(const OUString& rIdent) { m_aActivateHdl.Call(rIdent); }
2412 public:
2413 virtual OUString popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect,
2414 Placement ePlace = Placement::Under)
2415 = 0;
2417 void connect_activate(const Link<const OUString&, void>& rLink) { m_aActivateHdl = rLink; }
2419 virtual void set_sensitive(const OUString& rIdent, bool bSensitive) = 0;
2420 virtual bool get_sensitive(const OUString& rIdent) const = 0;
2421 virtual void set_label(const OUString& rIdent, const OUString& rLabel) = 0;
2422 virtual OUString get_label(const OUString& rIdent) const = 0;
2423 virtual void set_active(const OUString& rIdent, bool bActive) = 0;
2424 virtual bool get_active(const OUString& rIdent) const = 0;
2425 virtual void set_visible(const OUString& rIdent, bool bVisible) = 0;
2427 virtual void insert(int pos, const OUString& rId, const OUString& rStr,
2428 const OUString* pIconName, VirtualDevice* pImageSurface,
2429 const css::uno::Reference<css::graphic::XGraphic>& rImage,
2430 TriState eCheckRadioFalse)
2431 = 0;
2433 virtual void set_item_help_id(const OUString& rIdent, const OUString& rHelpId) = 0;
2434 virtual void remove(const OUString& rId) = 0;
2436 virtual void clear() = 0;
2438 virtual void insert_separator(int pos, const OUString& rId) = 0;
2439 void append_separator(const OUString& rId) { insert_separator(-1, rId); }
2441 void append(const OUString& rId, const OUString& rStr)
2443 insert(-1, rId, rStr, nullptr, nullptr, nullptr, TRISTATE_INDET);
2445 void append_check(const OUString& rId, const OUString& rStr)
2447 insert(-1, rId, rStr, nullptr, nullptr, nullptr, TRISTATE_TRUE);
2449 void append_radio(const OUString& rId, const OUString& rStr)
2451 insert(-1, rId, rStr, nullptr, nullptr, nullptr, TRISTATE_FALSE);
2453 void append(const OUString& rId, const OUString& rStr, const OUString& rImage)
2455 insert(-1, rId, rStr, &rImage, nullptr, nullptr, TRISTATE_INDET);
2457 void append(const OUString& rId, const OUString& rStr, VirtualDevice& rImage)
2459 insert(-1, rId, rStr, nullptr, &rImage, nullptr, TRISTATE_INDET);
2462 // return the number of toplevel nodes
2463 virtual int n_children() const = 0;
2465 virtual OUString get_id(int pos) const = 0;
2467 virtual ~Menu() {}
2470 class VCL_DLLPUBLIC Popover : virtual public Container
2472 friend class ::LOKTrigger;
2474 private:
2475 Link<weld::Popover&, void> m_aCloseHdl;
2477 protected:
2478 void signal_closed() { m_aCloseHdl.Call(*this); }
2480 public:
2481 virtual void popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect,
2482 Placement ePlace = Placement::Under)
2483 = 0;
2484 virtual void popdown() = 0;
2486 virtual void resize_to_request() = 0;
2488 void connect_closed(const Link<weld::Popover&, void>& rLink) { m_aCloseHdl = rLink; }
2491 class VCL_DLLPUBLIC Toolbar : virtual public Widget
2493 Link<const OUString&, void> m_aClickHdl;
2494 Link<const OUString&, void> m_aToggleMenuHdl;
2496 protected:
2497 friend class ::LOKTrigger;
2499 void signal_clicked(const OUString& rIdent) { m_aClickHdl.Call(rIdent); }
2500 void signal_toggle_menu(const OUString& rIdent) { m_aToggleMenuHdl.Call(rIdent); }
2502 public:
2503 virtual void set_item_sensitive(const OUString& rIdent, bool bSensitive) = 0;
2504 virtual bool get_item_sensitive(const OUString& rIdent) const = 0;
2505 virtual void set_item_active(const OUString& rIdent, bool bActive) = 0;
2506 virtual bool get_item_active(const OUString& rIdent) const = 0;
2507 virtual void set_menu_item_active(const OUString& rIdent, bool bActive) = 0;
2508 virtual bool get_menu_item_active(const OUString& rIdent) const = 0;
2509 virtual void set_item_menu(const OUString& rIdent, weld::Menu* pMenu) = 0;
2510 virtual void set_item_popover(const OUString& rIdent, weld::Widget* pPopover) = 0;
2511 virtual void set_item_visible(const OUString& rIdent, bool bVisible) = 0;
2512 virtual void set_item_help_id(const OUString& rIdent, const OUString& rHelpId) = 0;
2513 virtual bool get_item_visible(const OUString& rIdent) const = 0;
2514 virtual void set_item_label(const OUString& rIdent, const OUString& rLabel) = 0;
2515 virtual OUString get_item_label(const OUString& rIdent) const = 0;
2516 virtual void set_item_tooltip_text(const OUString& rIdent, const OUString& rTip) = 0;
2517 virtual OUString get_item_tooltip_text(const OUString& rIdent) const = 0;
2518 virtual void set_item_icon_name(const OUString& rIdent, const OUString& rIconName) = 0;
2519 virtual void set_item_image_mirrored(const OUString& rIdent, bool bMirrored) = 0;
2520 virtual void set_item_image(const OUString& rIdent,
2521 const css::uno::Reference<css::graphic::XGraphic>& rIcon)
2522 = 0;
2523 virtual void set_item_image(const OUString& rIdent, VirtualDevice* pDevice) = 0;
2525 virtual void insert_item(int pos, const OUString& rId) = 0;
2526 virtual void insert_separator(int pos, const OUString& rId) = 0;
2527 void append_separator(const OUString& rId) { insert_separator(-1, rId); }
2529 virtual int get_n_items() const = 0;
2530 virtual OUString get_item_ident(int nIndex) const = 0;
2531 virtual void set_item_ident(int nIndex, const OUString& rIdent) = 0;
2532 virtual void set_item_label(int nIndex, const OUString& rLabel) = 0;
2533 virtual void set_item_image(int nIndex,
2534 const css::uno::Reference<css::graphic::XGraphic>& rIcon)
2535 = 0;
2536 virtual void set_item_tooltip_text(int nIndex, const OUString& rTip) = 0;
2538 virtual vcl::ImageType get_icon_size() const = 0;
2539 virtual void set_icon_size(vcl::ImageType eType) = 0;
2541 // return what modifiers are held
2542 virtual sal_uInt16 get_modifier_state() const = 0;
2544 // This function returns the position a new item should be inserted if dnd
2545 // is dropped at rPoint
2546 virtual int get_drop_index(const Point& rPoint) const = 0;
2548 void connect_clicked(const Link<const OUString&, void>& rLink) { m_aClickHdl = rLink; }
2549 void connect_menu_toggled(const Link<const OUString&, void>& rLink)
2551 m_aToggleMenuHdl = rLink;
2555 class VCL_DLLPUBLIC Scrollbar : virtual public Widget
2557 Link<Scrollbar&, void> m_aChangeHdl;
2559 protected:
2560 void signal_adjustment_changed() { m_aChangeHdl.Call(*this); }
2562 public:
2563 virtual void adjustment_configure(int value, int lower, int upper, int step_increment,
2564 int page_increment, int page_size)
2565 = 0;
2566 virtual int adjustment_get_value() const = 0;
2567 virtual void adjustment_set_value(int value) = 0;
2568 virtual int adjustment_get_upper() const = 0;
2569 virtual void adjustment_set_upper(int upper) = 0;
2570 virtual int adjustment_get_page_size() const = 0;
2571 virtual void adjustment_set_page_size(int size) = 0;
2572 virtual int adjustment_get_page_increment() const = 0;
2573 virtual void adjustment_set_page_increment(int size) = 0;
2574 virtual int adjustment_get_step_increment() const = 0;
2575 virtual void adjustment_set_step_increment(int size) = 0;
2576 virtual int adjustment_get_lower() const = 0;
2577 virtual void adjustment_set_lower(int upper) = 0;
2579 virtual int get_scroll_thickness() const = 0;
2580 virtual void set_scroll_thickness(int nThickness) = 0;
2581 virtual void set_scroll_swap_arrows(bool bSwap) = 0;
2583 virtual ScrollType get_scroll_type() const = 0;
2585 void connect_adjustment_changed(const Link<Scrollbar&, void>& rLink) { m_aChangeHdl = rLink; }
2588 class VCL_DLLPUBLIC SizeGroup
2590 public:
2591 virtual void add_widget(weld::Widget* pWidget) = 0;
2592 // the default mode is VclSizeGroupMode::Horizontal
2593 virtual void set_mode(VclSizeGroupMode eMode) = 0;
2594 virtual ~SizeGroup() {}
2597 class VCL_DLLPUBLIC Builder
2599 public:
2600 virtual std::unique_ptr<MessageDialog> weld_message_dialog(const OUString& id) = 0;
2601 virtual std::unique_ptr<Dialog> weld_dialog(const OUString& id) = 0;
2602 virtual std::unique_ptr<Assistant> weld_assistant(const OUString& id) = 0;
2603 virtual std::unique_ptr<Widget> weld_widget(const OUString& id) = 0;
2604 virtual std::unique_ptr<Container> weld_container(const OUString& id) = 0;
2605 virtual std::unique_ptr<Box> weld_box(const OUString& id) = 0;
2606 virtual std::unique_ptr<Paned> weld_paned(const OUString& id) = 0;
2607 virtual std::unique_ptr<Button> weld_button(const OUString& id) = 0;
2608 virtual std::unique_ptr<MenuButton> weld_menu_button(const OUString& id) = 0;
2609 virtual std::unique_ptr<MenuToggleButton> weld_menu_toggle_button(const OUString& id) = 0;
2610 virtual std::unique_ptr<Frame> weld_frame(const OUString& id) = 0;
2611 /* bUserManagedScrolling of true means that the automatic scrolling of the window is disabled
2612 and the owner must specifically listen to adjustment changes and react appropriately to them.
2614 virtual std::unique_ptr<ScrolledWindow> weld_scrolled_window(const OUString& id,
2615 bool bUserManagedScrolling = false)
2616 = 0;
2617 virtual std::unique_ptr<Notebook> weld_notebook(const OUString& id) = 0;
2618 virtual std::unique_ptr<ToggleButton> weld_toggle_button(const OUString& id) = 0;
2619 virtual std::unique_ptr<RadioButton> weld_radio_button(const OUString& id) = 0;
2620 virtual std::unique_ptr<CheckButton> weld_check_button(const OUString& id) = 0;
2621 virtual std::unique_ptr<LinkButton> weld_link_button(const OUString& id) = 0;
2622 virtual std::unique_ptr<SpinButton> weld_spin_button(const OUString& id) = 0;
2623 virtual std::unique_ptr<MetricSpinButton> weld_metric_spin_button(const OUString& id,
2624 FieldUnit eUnit)
2625 = 0;
2626 virtual std::unique_ptr<FormattedSpinButton> weld_formatted_spin_button(const OUString& id) = 0;
2627 virtual std::unique_ptr<ComboBox> weld_combo_box(const OUString& id) = 0;
2628 virtual std::unique_ptr<TreeView> weld_tree_view(const OUString& id) = 0;
2629 virtual std::unique_ptr<IconView> weld_icon_view(const OUString& id) = 0;
2630 virtual std::unique_ptr<Label> weld_label(const OUString& id) = 0;
2631 virtual std::unique_ptr<TextView> weld_text_view(const OUString& id) = 0;
2632 virtual std::unique_ptr<Expander> weld_expander(const OUString& id) = 0;
2633 virtual std::unique_ptr<Entry> weld_entry(const OUString& id) = 0;
2634 virtual std::unique_ptr<Scale> weld_scale(const OUString& id) = 0;
2635 virtual std::unique_ptr<ProgressBar> weld_progress_bar(const OUString& id) = 0;
2636 virtual std::unique_ptr<LevelBar> weld_level_bar(const OUString& id) = 0;
2637 virtual std::unique_ptr<Spinner> weld_spinner(const OUString& id) = 0;
2638 virtual std::unique_ptr<Image> weld_image(const OUString& id) = 0;
2639 virtual std::unique_ptr<Calendar> weld_calendar(const OUString& id) = 0;
2640 virtual std::unique_ptr<DrawingArea>
2641 weld_drawing_area(const OUString& id, const a11yref& rA11yImpl = nullptr,
2642 FactoryFunction pUITestFactoryFunction = nullptr, void* pUserData = nullptr)
2643 = 0;
2644 virtual std::unique_ptr<EntryTreeView> weld_entry_tree_view(const OUString& containerid,
2645 const OUString& entryid,
2646 const OUString& treeviewid)
2647 = 0;
2648 virtual std::unique_ptr<Menu> weld_menu(const OUString& id) = 0;
2649 virtual std::unique_ptr<Popover> weld_popover(const OUString& id) = 0;
2650 virtual std::unique_ptr<Toolbar> weld_toolbar(const OUString& id) = 0;
2651 virtual std::unique_ptr<Scrollbar> weld_scrollbar(const OUString& id) = 0;
2652 virtual std::unique_ptr<SizeGroup> create_size_group() = 0;
2653 /* return a Dialog suitable to take a screenshot of containing the contents of the .ui file.
2655 If the toplevel element is a dialog, that will be returned
2656 If the toplevel is not a dialog, a dialog will be created and the contents of the .ui
2657 inserted into it
2659 virtual std::unique_ptr<Window> create_screenshot_window() = 0;
2660 virtual ~Builder() {}
2663 class VCL_DLLPUBLIC DialogController : public std::enable_shared_from_this<DialogController>
2665 public:
2666 virtual Dialog* getDialog() = 0;
2667 const Dialog* getConstDialog() const
2669 return const_cast<DialogController*>(this)->getDialog();
2671 virtual short run() { return getDialog()->run(); }
2672 static bool runAsync(const std::shared_ptr<DialogController>& rController,
2673 const std::function<void(sal_Int32)>&);
2674 void set_title(const OUString& rTitle) { getDialog()->set_title(rTitle); }
2675 OUString get_title() const { return getConstDialog()->get_title(); }
2676 void set_help_id(const OUString& rHelpId) { getDialog()->set_help_id(rHelpId); }
2677 OUString get_help_id() const { return getConstDialog()->get_help_id(); }
2678 void response(int nResponse) { getDialog()->response(nResponse); }
2679 virtual ~DialogController() COVERITY_NOEXCEPT_FALSE;
2682 class VCL_DLLPUBLIC GenericDialogController : public DialogController
2684 protected:
2685 std::unique_ptr<weld::Builder> m_xBuilder;
2686 std::shared_ptr<weld::Dialog> m_xDialog;
2688 public:
2689 GenericDialogController(weld::Widget* pParent, const OUString& rUIFile,
2690 const OUString& rDialogId, bool bMobile = false);
2691 virtual Dialog* getDialog() override;
2692 virtual ~GenericDialogController() COVERITY_NOEXCEPT_FALSE override;
2695 class VCL_DLLPUBLIC MessageDialogController : public DialogController
2697 protected:
2698 std::unique_ptr<weld::Builder> m_xBuilder;
2699 std::unique_ptr<weld::MessageDialog> m_xDialog;
2700 std::unique_ptr<weld::Container> m_xContentArea;
2701 std::unique_ptr<weld::Widget> m_xRelocate;
2702 std::unique_ptr<weld::Container> m_xOrigParent;
2704 public:
2705 /* @param rRelocateId - optional argument of the name of a widget in the .ui file
2706 which should be relocated into the content area of the dialog.
2708 e.g. a checkbox for a "Never show this again" option.
2710 This results in the named widget relocating to the same container
2711 as the messages. This enables aligning the extra widget with the
2712 message labels in the content area container which doesn't
2713 explicitly exist in the ui description, but is only implied.
2715 MessageDialogController(weld::Widget* pParent, const OUString& rUIFile,
2716 const OUString& rDialogId, const OUString& rRelocateId = {});
2717 virtual Dialog* getDialog() override;
2718 virtual ~MessageDialogController() override;
2719 void set_primary_text(const OUString& rText) { m_xDialog->set_primary_text(rText); }
2720 OUString get_primary_text() const { return m_xDialog->get_primary_text(); }
2721 void set_secondary_text(const OUString& rText) { m_xDialog->set_secondary_text(rText); }
2722 OUString get_secondary_text() const { return m_xDialog->get_secondary_text(); }
2723 void set_default_response(int nResponse) { m_xDialog->set_default_response(nResponse); }
2726 class VCL_DLLPUBLIC AssistantController : public DialogController
2728 protected:
2729 std::unique_ptr<weld::Builder> m_xBuilder;
2730 std::unique_ptr<weld::Assistant> m_xAssistant;
2732 public:
2733 AssistantController(weld::Widget* pParent, const OUString& rUIFile, const OUString& rDialogId);
2734 virtual Dialog* getDialog() override;
2735 virtual ~AssistantController() override;
2738 #endif
2740 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */