LibreOffice Module vcl (master) 1
customweld.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef INCLUDED_VCL_CUSTOMWELD_HXX
11#define INCLUDED_VCL_CUSTOMWELD_HXX
12
13#include <vcl/weld.hxx>
14
15class InputContext;
16
17namespace weld
18{
20{
21private:
24 DECL_LINK(DragBeginHdl, weld::DrawingArea&, bool);
25
26public:
27 virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible()
28 {
29 return css::uno::Reference<css::accessibility::XAccessible>();
30 }
31 // rRect is in Logical units rather than Pixels
32 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) = 0;
33 virtual void Resize() {}
34 virtual bool MouseButtonDown(const MouseEvent&) { return false; }
35 virtual bool MouseMove(const MouseEvent&) { return false; }
36 virtual bool MouseButtonUp(const MouseEvent&) { return false; }
37 virtual void GetFocus() {}
38 virtual void LoseFocus() {}
39 virtual void StyleUpdated() { Invalidate(); }
40 virtual bool Command(const CommandEvent&) { return false; }
41 virtual bool KeyInput(const KeyEvent&) { return false; }
43 virtual FactoryFunction GetUITestFactory() const { return nullptr; }
44 virtual OUString RequestHelp(tools::Rectangle&) { return OUString(); }
45 virtual OUString GetHelpText() const { return m_pDrawingArea->get_tooltip_text(); }
46 Size const& GetOutputSizePixel() const { return m_aSize; }
47 void SetOutputSizePixel(const Size& rSize) { m_aSize = rSize; }
48 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) { m_pDrawingArea = pDrawingArea; }
49 weld::DrawingArea* GetDrawingArea() const { return m_pDrawingArea; }
51 {
52 if (!m_pDrawingArea)
53 return;
54 m_pDrawingArea->queue_draw();
55 }
56 static bool IsUpdateMode() { return true; }
57 void Invalidate(const tools::Rectangle& rRect)
58 {
59 if (!m_pDrawingArea)
60 return;
61 m_pDrawingArea->queue_draw_area(rRect.Left(), rRect.Top(), rRect.GetWidth(),
62 rRect.GetHeight());
63 }
64 virtual void Show() { m_pDrawingArea->show(); }
65 virtual void Hide() { m_pDrawingArea->hide(); }
66 void SetCursor(void* pData) { m_pDrawingArea->set_cursor_data(pData); }
67 void GrabFocus() { m_pDrawingArea->grab_focus(); }
68 bool HasFocus() const { return m_pDrawingArea->has_focus(); }
69 bool HasChildFocus() const { return m_pDrawingArea->has_child_focus(); }
70 bool IsVisible() const { return m_pDrawingArea->get_visible(); }
71 bool IsReallyVisible() const { return m_pDrawingArea->is_visible(); }
72 bool IsEnabled() const { return m_pDrawingArea->get_sensitive(); }
73 void Enable() const { m_pDrawingArea->set_sensitive(true); }
74 void Disable() const { m_pDrawingArea->set_sensitive(false); }
75 bool IsActive() const { return m_pDrawingArea->is_active(); }
76 int GetTextHeight() const { return m_pDrawingArea->get_text_height(); }
77 int GetTextWidth(const OUString& rText) const
78 {
79 return m_pDrawingArea->get_pixel_size(rText).Width();
80 }
81 OUString GetAccessibleName() const { return m_pDrawingArea->get_accessible_name(); }
82 OUString GetAccessibleDescription() const
83 {
84 return m_pDrawingArea->get_accessible_description();
85 }
86 void CaptureMouse() { m_pDrawingArea->grab_add(); }
87 bool IsMouseCaptured() const { return m_pDrawingArea->has_grab(); }
88 Point GetPointerPosPixel() const { return m_pDrawingArea->get_pointer_position(); }
89 void EnableRTL(bool bEnable) { m_pDrawingArea->set_direction(bEnable); }
90 bool IsRTLEnabled() const { return m_pDrawingArea->get_direction(); }
91 void ReleaseMouse() { m_pDrawingArea->grab_remove(); }
92 void SetPointer(PointerStyle ePointerStyle) { m_pDrawingArea->set_cursor(ePointerStyle); }
93 void SetHelpId(const OString& rHelpId) { m_pDrawingArea->set_help_id(rHelpId); }
94 void SetAccessibleName(const OUString& rName) { m_pDrawingArea->set_accessible_name(rName); }
95 void SetInputContext(const InputContext& rInputContext)
96 {
97 m_pDrawingArea->set_input_context(rInputContext);
98 }
99 void SetCursorRect(const tools::Rectangle& rCursorRect, int nExtTextInputWidth)
100 {
101 m_pDrawingArea->im_context_set_cursor_location(rCursorRect, nExtTextInputWidth);
102 }
103 virtual int GetSurroundingText(OUString& /*rSurrounding*/) { return -1; }
104 virtual bool DeleteSurroundingText(const Selection& /*rRange*/) { return false; }
105 css::uno::Reference<css::datatransfer::dnd::XDropTarget> GetDropTarget()
106 {
107 return m_pDrawingArea->get_drop_target();
108 }
109 css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const
110 {
111 return m_pDrawingArea->get_clipboard();
112 }
114 sal_uInt8 eDNDConstants)
115 {
116 m_pDrawingArea->enable_drag_source(rTransferable, eDNDConstants);
117 m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl));
118 }
119 // return true to disallow drag, false to allow
120 virtual bool StartDrag() { return false; }
121 void set_size_request(int nWidth, int nHeight)
122 {
123 m_pDrawingArea->set_size_request(nWidth, nHeight);
124 }
126 {
127 if (!m_pDrawingArea)
128 return;
129 m_pDrawingArea->queue_resize();
130 }
132 : m_pDrawingArea(nullptr)
133 {
134 }
135 virtual ~CustomWidgetController();
136
141};
142
144{
145private:
147 std::unique_ptr<weld::DrawingArea> m_xDrawingArea;
148
149 DECL_DLLPRIVATE_LINK(DoResize, const Size& rSize, void);
151 DECL_DLLPRIVATE_LINK(DoMouseButtonDown, const MouseEvent&, bool);
152 DECL_DLLPRIVATE_LINK(DoMouseMove, const MouseEvent&, bool);
153 DECL_DLLPRIVATE_LINK(DoMouseButtonUp, const MouseEvent&, bool);
155 DECL_DLLPRIVATE_LINK(DoLoseFocus, weld::Widget&, void);
156 DECL_DLLPRIVATE_LINK(DoKeyPress, const KeyEvent&, bool);
158 DECL_DLLPRIVATE_LINK(DoCommand, const CommandEvent&, bool);
159 DECL_DLLPRIVATE_LINK(DoStyleUpdated, weld::Widget&, void);
160 DECL_DLLPRIVATE_LINK(DoRequestHelp, tools::Rectangle&, OUString);
161 DECL_DLLPRIVATE_LINK(DoGetSurrounding, OUString&, int);
162 DECL_DLLPRIVATE_LINK(DoDeleteSurrounding, const Selection&, bool);
163
164public:
165 CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId,
166 CustomWidgetController& rWidgetController);
167 void queue_draw() { m_xDrawingArea->queue_draw(); }
168 void queue_draw_area(int x, int y, int width, int height)
169 {
170 m_xDrawingArea->queue_draw_area(x, y, width, height);
171 }
172 void set_size_request(int nWidth, int nHeight)
173 {
174 m_xDrawingArea->set_size_request(nWidth, nHeight);
175 }
176 void show() { m_xDrawingArea->show(); }
177 void hide() { m_xDrawingArea->hide(); }
178 void set_margin_top(int nMargin) { m_xDrawingArea->set_margin_top(nMargin); }
179 void set_margin_bottom(int nMargin) { m_xDrawingArea->set_margin_bottom(nMargin); }
180 void set_sensitive(bool bSensitive) { m_xDrawingArea->set_sensitive(bSensitive); }
181 bool get_sensitive() const { return m_xDrawingArea->get_sensitive(); }
182 bool get_visible() const { return m_xDrawingArea->get_visible(); }
183 void set_visible(bool bVisible) { m_xDrawingArea->set_visible(bVisible); }
184 void set_grid_left_attach(int nAttach) { m_xDrawingArea->set_grid_left_attach(nAttach); }
185 int get_grid_left_attach() const { return m_xDrawingArea->get_grid_left_attach(); }
186 void set_help_id(const OString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); }
187 void set_tooltip_text(const OUString& rTip) { m_xDrawingArea->set_tooltip_text(rTip); }
188};
189}
190#endif
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:171
constexpr tools::Long Width() const
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
DECL_DLLPRIVATE_LINK(DoLoseFocus, weld::Widget &, void)
DECL_DLLPRIVATE_LINK(DoMouseButtonUp, const MouseEvent &, bool)
weld::CustomWidgetController & m_rWidgetController
Definition: customweld.hxx:146
DECL_DLLPRIVATE_LINK(DoGetSurrounding, OUString &, int)
DECL_DLLPRIVATE_LINK(DoRequestHelp, tools::Rectangle &, OUString)
bool get_visible() const
Definition: customweld.hxx:182
DECL_DLLPRIVATE_LINK(DoResize, const Size &rSize, void)
void set_sensitive(bool bSensitive)
Definition: customweld.hxx:180
DECL_DLLPRIVATE_LINK(DoDeleteSurrounding, const Selection &, bool)
DECL_DLLPRIVATE_LINK(DoPaint, weld::DrawingArea::draw_args, void)
bool get_sensitive() const
Definition: customweld.hxx:181
DECL_DLLPRIVATE_LINK(DoMouseMove, const MouseEvent &, bool)
DECL_DLLPRIVATE_LINK(DoFocusRect, weld::Widget &, tools::Rectangle)
void set_help_id(const OString &rHelpId)
Definition: customweld.hxx:186
DECL_DLLPRIVATE_LINK(DoStyleUpdated, weld::Widget &, void)
DECL_DLLPRIVATE_LINK(DoGetFocus, weld::Widget &, void)
DECL_DLLPRIVATE_LINK(DoMouseButtonDown, const MouseEvent &, bool)
void set_margin_bottom(int nMargin)
Definition: customweld.hxx:179
void set_tooltip_text(const OUString &rTip)
Definition: customweld.hxx:187
int get_grid_left_attach() const
Definition: customweld.hxx:185
DECL_DLLPRIVATE_LINK(DoCommand, const CommandEvent &, bool)
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:172
void set_grid_left_attach(int nAttach)
Definition: customweld.hxx:184
void set_margin_top(int nMargin)
Definition: customweld.hxx:178
DECL_DLLPRIVATE_LINK(DoKeyPress, const KeyEvent &, bool)
void set_visible(bool bVisible)
Definition: customweld.hxx:183
std::unique_ptr< weld::DrawingArea > m_xDrawingArea
Definition: customweld.hxx:147
void queue_draw_area(int x, int y, int width, int height)
Definition: customweld.hxx:168
weld::DrawingArea * m_pDrawingArea
Definition: customweld.hxx:23
void SetPointer(PointerStyle ePointerStyle)
Definition: customweld.hxx:92
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:121
virtual bool KeyInput(const KeyEvent &)
Definition: customweld.hxx:41
void SetDragDataTransferable(rtl::Reference< TransferDataContainer > &rTransferable, sal_uInt8 eDNDConstants)
Definition: customweld.hxx:113
css::uno::Reference< css::datatransfer::dnd::XDropTarget > GetDropTarget()
Definition: customweld.hxx:105
Point GetPointerPosPixel() const
Definition: customweld.hxx:88
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
Definition: customweld.hxx:48
OUString GetAccessibleName() const
Definition: customweld.hxx:81
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
virtual bool MouseMove(const MouseEvent &)
Definition: customweld.hxx:35
virtual FactoryFunction GetUITestFactory() const
Definition: customweld.hxx:43
virtual bool MouseButtonDown(const MouseEvent &)
Definition: customweld.hxx:34
CustomWidgetController(CustomWidgetController &&)=default
int GetTextWidth(const OUString &rText) const
Definition: customweld.hxx:77
weld::DrawingArea * GetDrawingArea() const
Definition: customweld.hxx:49
virtual OUString RequestHelp(tools::Rectangle &)
Definition: customweld.hxx:44
virtual int GetSurroundingText(OUString &)
Definition: customweld.hxx:103
CustomWidgetController(CustomWidgetController const &)=default
void EnableRTL(bool bEnable)
Definition: customweld.hxx:89
virtual bool MouseButtonUp(const MouseEvent &)
Definition: customweld.hxx:36
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
Definition: customweld.hxx:27
void SetOutputSizePixel(const Size &rSize)
Definition: customweld.hxx:47
virtual bool DeleteSurroundingText(const Selection &)
Definition: customweld.hxx:104
DECL_LINK(DragBeginHdl, weld::DrawingArea &, bool)
virtual OUString GetHelpText() const
Definition: customweld.hxx:45
void SetAccessibleName(const OUString &rName)
Definition: customweld.hxx:94
virtual tools::Rectangle GetFocusRect()
Definition: customweld.hxx:42
void SetHelpId(const OString &rHelpId)
Definition: customweld.hxx:93
void SetCursorRect(const tools::Rectangle &rCursorRect, int nExtTextInputWidth)
Definition: customweld.hxx:99
OUString GetAccessibleDescription() const
Definition: customweld.hxx:82
void Invalidate(const tools::Rectangle &rRect)
Definition: customweld.hxx:57
void SetInputContext(const InputContext &rInputContext)
Definition: customweld.hxx:95
virtual bool Command(const CommandEvent &)
Definition: customweld.hxx:40
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard() const
Definition: customweld.hxx:109
void SetCursor(void *pData)
Definition: customweld.hxx:66
CustomWidgetController & operator=(CustomWidgetController &&)=default
CustomWidgetController & operator=(CustomWidgetController const &)=default
Size const & GetOutputSizePixel() const
Definition: customweld.hxx:46
virtual void im_context_set_cursor_location(const tools::Rectangle &rCursorRect, int nExtTextInputWidth)=0
virtual Point get_pointer_position() const =0
std::pair< vcl::RenderContext &, const tools::Rectangle & > draw_args
Definition: weld.hxx:2265
virtual void queue_draw_area(int x, int y, int width, int height)=0
virtual void set_cursor(PointerStyle ePointerStyle)=0
virtual void enable_drag_source(rtl::Reference< TransferDataContainer > &rTransferable, sal_uInt8 eDNDConstants)=0
void connect_drag_begin(const Link< DrawingArea &, bool > &rLink)
Definition: weld.hxx:2309
virtual void set_input_context(const InputContext &rInputContext)=0
virtual void queue_draw()=0
virtual int get_text_height() const =0
virtual void show()=0
virtual void grab_focus()=0
virtual void hide()=0
virtual void set_accessible_name(const OUString &rName)=0
virtual OUString get_accessible_name() const =0
virtual void set_help_id(const OString &rName)=0
virtual void set_sensitive(bool sensitive)=0
virtual css::uno::Reference< css::datatransfer::dnd::XDropTarget > get_drop_target()=0
virtual bool is_visible() const =0
virtual Size get_pixel_size(const OUString &rText) const =0
virtual void set_size_request(int nWidth, int nHeight)=0
virtual OUString get_accessible_description() const =0
virtual bool has_grab() const =0
virtual bool is_active() const =0
virtual void grab_remove()=0
virtual void queue_resize()=0
virtual OUString get_tooltip_text() const =0
virtual void grab_add()=0
virtual css::uno::Reference< css::datatransfer::clipboard::XClipboard > get_clipboard() const =0
virtual bool has_focus() const =0
virtual bool get_visible() const =0
virtual bool get_sensitive() const =0
virtual bool get_direction() const =0
virtual bool has_child_focus() const =0
virtual void set_cursor_data(void *pData)=0
virtual void set_direction(bool bRTL)=0
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
float y
float x
awt::Size m_aSize
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
std::unique_ptr< sal_Int32[]> pData
PointerStyle
Definition: ptrstyle.hxx:26
bool bVisible
unsigned char sal_uInt8