Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/weld/Widget.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#pragma once
11
12
#include <rtl/ustring.hxx>
13
#include <tools/gen.hxx>
14
#include <tools/link.hxx>
15
#include <vcl/vclptr.hxx>
16
#include <vcl/dllapi.h>
17
18
#include <assert.h>
19
#include <memory>
20
21
namespace com::sun::star::datatransfer::clipboard
22
{
23
class XClipboard;
24
}
25
namespace com::sun::star::datatransfer::dnd
26
{
27
class XDropTarget;
28
}
29
class Color;
30
class CommandEvent;
31
class KeyEvent;
32
class MouseEvent;
33
class TransferDataContainer;
34
class OutputDevice;
35
class VirtualDevice;
36
37
namespace vcl
38
{
39
class ILibreOfficeKitNotifier;
40
class Font;
41
}
42
template <class reference_type> class VclPtr;
43
44
namespace weld
45
{
46
class Container;
47
48
class VCL_DLLPUBLIC Widget
49
{
50
    int m_nBlockNotify = 0;
51
52
    Link<const CommandEvent&, bool> m_aCommandHdl;
53
54
protected:
55
    Link<Widget&, void> m_aFocusInHdl;
56
    Link<Widget&, void> m_aFocusOutHdl;
57
    Link<Widget&, bool> m_aMnemonicActivateHdl;
58
    Link<Widget&, void> m_aStyleUpdatedHdl;
59
    Link<const Size&, void> m_aSizeAllocateHdl;
60
    Link<const KeyEvent&, bool> m_aKeyPressHdl;
61
    Link<const KeyEvent&, bool> m_aKeyReleaseHdl;
62
    Link<const MouseEvent&, bool> m_aMousePressHdl;
63
    Link<const MouseEvent&, bool> m_aMouseMotionHdl;
64
    Link<const MouseEvent&, bool> m_aMouseReleaseHdl;
65
66
0
    void disable_notify_events() { ++m_nBlockNotify; }
67
0
    bool notify_events_disabled() const { return m_nBlockNotify != 0; }
68
0
    void enable_notify_events() { --m_nBlockNotify; }
69
70
0
    virtual bool signal_command(const CommandEvent& rCEvt) { return m_aCommandHdl.Call(rCEvt); }
71
0
    void signal_focus_in() { m_aFocusInHdl.Call(*this); }
72
0
    void signal_focus_out() { m_aFocusOutHdl.Call(*this); }
73
0
    bool signal_mnemonic_activate() { return m_aMnemonicActivateHdl.Call(*this); }
74
0
    void signal_style_updated() { m_aStyleUpdatedHdl.Call(*this); }
75
0
    void signal_size_allocate(const Size& rSize) { m_aSizeAllocateHdl.Call(rSize); }
76
0
    bool signal_key_press(const KeyEvent& rKeyEvent) { return m_aKeyPressHdl.Call(rKeyEvent); }
77
0
    bool signal_key_release(const KeyEvent& rKeyEvent) { return m_aKeyReleaseHdl.Call(rKeyEvent); }
78
    bool signal_mouse_press(const MouseEvent& rMouseEvent)
79
0
    {
80
0
        return m_aMousePressHdl.Call(rMouseEvent);
81
0
    }
82
    bool signal_mouse_motion(const MouseEvent& rMouseEvent)
83
0
    {
84
0
        return m_aMouseMotionHdl.Call(rMouseEvent);
85
0
    }
86
    bool signal_mouse_release(const MouseEvent& rMouseEvent)
87
0
    {
88
0
        return m_aMouseReleaseHdl.Call(rMouseEvent);
89
0
    }
90
91
public:
92
    virtual void set_sensitive(bool sensitive) = 0;
93
    virtual bool get_sensitive() const = 0;
94
95
    /* visibility */
96
97
    virtual void show() = 0;
98
    virtual void hide() = 0;
99
100
    // This function simply calls show() or hide() but is convenient when the
101
    // visibility depends on some condition
102
    void set_visible(bool visible)
103
0
    {
104
0
        if (visible)
105
0
            show();
106
0
        else
107
0
            hide();
108
0
    }
109
110
    // return if this widget's visibility is true
111
    virtual bool get_visible() const = 0;
112
113
    // return if this widget's visibility and that of all its parents is true
114
    virtual bool is_visible() const = 0;
115
116
    /* focus */
117
118
    // sets if this widget can own the keyboard focus
119
    virtual void set_can_focus(bool bCanFocus) = 0;
120
121
    // causes this widget to have the keyboard focus
122
    virtual void grab_focus() = 0;
123
124
    // returns if this widget has the keyboard focus
125
    virtual bool has_focus() const = 0;
126
127
    // if the widget that has focus is a child, which includes toplevel popup
128
    // children, of this widget. So an Entry with an active popup (or dialog)
129
    // has has_child_focus of true, but has_focus of false, while its popup is
130
    // shown
131
    virtual bool has_child_focus() const = 0;
132
133
    /* size */
134
    virtual void set_size_request(int nWidth, int nHeight) = 0;
135
    virtual Size get_size_request() const = 0;
136
    virtual Size get_preferred_size() const = 0;
137
138
    /* measure */
139
    virtual float get_approximate_digit_width() const = 0;
140
    virtual int get_text_height() const = 0;
141
    virtual Size get_pixel_size(const OUString& rText) const = 0;
142
143
    // The name of the widget in the GtkBuilder UI definition used to construct it.
144
    virtual OUString get_buildable_name() const = 0;
145
    /*
146
       Typically there is no need to change the buildable name at runtime, changing
147
       the id in .ui file itself is preferred.
148
149
       But for ui-testing purposes it can sometimes be useful to rename
150
       different widgets, that were loaded from the same .ui, to unique names
151
       in order to distinguish between them
152
    */
153
    virtual void set_buildable_name(const OUString& rName) = 0;
154
155
    /*
156
      The help id of the widget used to identify help for this widget.
157
158
      By default the help id of a widget is a path-like sequence of (load-time)
159
      buildable-names from the widgets UI definition ancestor to this widget,
160
      e.g. grandparent/parent/widget.
161
162
      The default can be overwritten with set_help_id
163
    */
164
    virtual OUString get_help_id() const = 0;
165
    virtual void set_help_id(const OUString& rName) = 0;
166
167
    virtual void set_hexpand(bool bExpand) = 0;
168
    virtual void set_vexpand(bool bExpand) = 0;
169
170
    virtual void set_margin_top(int nMargin) = 0;
171
    virtual void set_margin_bottom(int nMargin) = 0;
172
    virtual void set_margin_start(int nMargin) = 0;
173
    virtual void set_margin_end(int nMargin) = 0;
174
175
    virtual int get_margin_start() const = 0;
176
    virtual int get_margin_end() const = 0;
177
178
    /*
179
     * Report the extents of this widget relative to the rRelative target widget.
180
     *
181
     * To succeed, both widgets must be realized, and must share a common toplevel.
182
     *
183
     * returns false if the relative extents could not be determined, e.g. if
184
     * either widget was not realized, or there was no common ancestor.
185
     * Otherwise true.
186
     */
187
    virtual bool get_extents_relative_to(const Widget& rRelative, int& x, int& y, int& width,
188
                                         int& height) const = 0;
189
190
    virtual void set_accessible_name(const OUString& rName) = 0;
191
    virtual void set_accessible_description(const OUString& rDescription) = 0;
192
    virtual OUString get_accessible_name() const = 0;
193
194
    virtual OUString get_accessible_description() const = 0;
195
196
    virtual OUString get_accessible_id() const = 0;
197
198
    // After this call this widget is only accessibility labelled by pLabel and
199
    // pLabel only accessibility labels this widget
200
    virtual void set_accessible_relation_labeled_by(weld::Widget* pLabel) = 0;
201
202
    virtual void set_tooltip_text(const OUString& rTip) = 0;
203
    virtual OUString get_tooltip_text() const = 0;
204
205
    virtual void set_cursor_data(void* pData) = 0;
206
207
    virtual void connect_command(const Link<const CommandEvent&, bool>& rLink)
208
0
    {
209
0
        m_aCommandHdl = rLink;
210
0
    }
211
212
    virtual void connect_focus_in(const Link<Widget&, void>& rLink)
213
0
    {
214
0
        assert(!m_aFocusInHdl.IsSet() || !rLink.IsSet());
215
0
        m_aFocusInHdl = rLink;
216
0
    }
217
218
    virtual void connect_focus_out(const Link<Widget&, void>& rLink)
219
0
    {
220
0
        assert(!m_aFocusOutHdl.IsSet() || !rLink.IsSet());
221
0
        m_aFocusOutHdl = rLink;
222
0
    }
223
224
    // rLink is called when the mnemonic for the Widget is called.
225
    // If rLink returns true the Widget will not automatically gain
226
    // focus as normally occurs
227
    virtual void connect_mnemonic_activate(const Link<Widget&, bool>& rLink)
228
0
    {
229
0
        assert(!m_aMnemonicActivateHdl.IsSet() || !rLink.IsSet());
230
0
        m_aMnemonicActivateHdl = rLink;
231
0
    }
232
233
    virtual void connect_size_allocate(const Link<const Size&, void>& rLink)
234
0
    {
235
0
        assert(!m_aSizeAllocateHdl.IsSet() || !rLink.IsSet());
236
0
        m_aSizeAllocateHdl = rLink;
237
0
    }
238
239
    virtual void connect_key_press(const Link<const KeyEvent&, bool>& rLink)
240
0
    {
241
0
        assert(!m_aKeyPressHdl.IsSet() || !rLink.IsSet());
242
0
        m_aKeyPressHdl = rLink;
243
0
    }
244
245
    virtual void connect_key_release(const Link<const KeyEvent&, bool>& rLink)
246
0
    {
247
0
        assert(!m_aKeyReleaseHdl.IsSet() || !rLink.IsSet());
248
0
        m_aKeyReleaseHdl = rLink;
249
0
    }
250
251
    virtual void connect_mouse_press(const Link<const MouseEvent&, bool>& rLink)
252
0
    {
253
0
        assert(!m_aMousePressHdl.IsSet() || !rLink.IsSet());
254
0
        m_aMousePressHdl = rLink;
255
0
    }
256
257
    virtual void connect_mouse_move(const Link<const MouseEvent&, bool>& rLink)
258
0
    {
259
0
        assert(!m_aMouseMotionHdl.IsSet() || !rLink.IsSet());
260
0
        m_aMouseMotionHdl = rLink;
261
0
    }
262
263
    virtual void connect_mouse_release(const Link<const MouseEvent&, bool>& rLink)
264
0
    {
265
0
        assert(!m_aMouseReleaseHdl.IsSet() || !rLink.IsSet());
266
0
        m_aMouseReleaseHdl = rLink;
267
0
    }
268
269
    virtual void connect_style_updated(const Link<Widget&, void>& rLink)
270
0
    {
271
0
        assert(!m_aStyleUpdatedHdl.IsSet() || !rLink.IsSet());
272
0
        m_aStyleUpdatedHdl = rLink;
273
0
    }
274
275
    virtual void grab_mouse() = 0;
276
    virtual bool has_mouse_grab() const = 0;
277
    virtual void release_mouse() = 0;
278
279
    // font size is in points, not pixels, e.g. see Window::[G]etPointFont
280
    virtual vcl::Font get_font() = 0;
281
282
    //true for rtl, false otherwise
283
    virtual bool get_direction() const = 0;
284
    virtual void set_direction(bool bRTL) = 0;
285
286
    /* Increases the freeze count on widget.
287
288
       If the freeze count is non-zero, emission of the widget's notifications
289
       is stopped. The notifications are queued until the freeze count is
290
       decreased to zero. Duplicate notifications may be squashed together.
291
    */
292
    virtual void freeze() = 0;
293
294
    /* Reverts the effect of a previous call to freeze.
295
296
       The freeze count is decreased on the widget and when it reaches zero,
297
       queued notifications are emitted.
298
    */
299
    virtual void thaw() = 0;
300
301
    /* push/pop busy mouse cursor state
302
303
      bBusy of true to push a busy state onto the stack and false
304
      to pop it off, calls to this should balance.
305
306
      see weld::WaitObject */
307
    virtual void set_busy_cursor(bool bBusy) = 0;
308
309
    virtual void queue_resize() = 0;
310
311
    virtual std::unique_ptr<Container> weld_parent() const = 0;
312
313
    virtual OUString strip_mnemonic(const OUString& rLabel) const = 0;
314
315
    /* Escapes string contents which are interpreted by the UI.
316
317
       Should be overwritten by each VCL implementation to account for the
318
       string contents which are interpreted by its ui.
319
    */
320
    virtual OUString escape_ui_str(const OUString& rLabel) const = 0;
321
322
    virtual ScopedVclPtr<VirtualDevice> create_virtual_device() const = 0;
323
324
    //do something transient to attract the attention of the user to the widget
325
    virtual void call_attention_to() = 0;
326
327
    //make this widget look like a page in a notebook
328
    virtual void set_stack_background() = 0;
329
    //make this widget look like it has a highlighted background
330
    virtual void set_highlight_background() = 0;
331
    //make this widget suitable as parent for a title
332
    virtual void set_title_background() = 0;
333
    //make this widget suitable for use in a toolbar
334
    virtual void set_toolbar_background() = 0;
335
    //trying to use a custom color for a background is generally a bad idea. If your need
336
    //fits one of the above categories then that's a somewhat better choice
337
    virtual void set_background(const Color& rBackColor) = 0;
338
    // reset to default background
339
    virtual void set_background() = 0;
340
341
    virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget> get_drop_target() = 0;
342
    virtual css::uno::Reference<css::datatransfer::clipboard::XClipboard> get_clipboard() const = 0;
343
344
    // render the widget to an output device
345
    virtual void draw(OutputDevice& rOutput, const Point& rPos, const Size& rSizePixel) = 0;
346
347
83
    virtual ~Widget() {}
348
};
349
}
350
351
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */