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 GrabFocus() { m_pDrawingArea->grab_focus(); }
67 bool HasFocus() const { return m_pDrawingArea->has_focus(); }
68 bool HasChildFocus() const { return m_pDrawingArea->has_child_focus(); }
69 bool IsVisible() const { return m_pDrawingArea->get_visible(); }
70 bool IsReallyVisible() const { return m_pDrawingArea->is_visible(); }
71 bool IsEnabled() const { return m_pDrawingArea->get_sensitive(); }
72 void Enable() const { m_pDrawingArea->set_sensitive(true); }
73 void Disable() const { m_pDrawingArea->set_sensitive(false); }
74 bool IsActive() const { return m_pDrawingArea->is_active(); }
75 int GetTextHeight() const { return m_pDrawingArea->get_text_height(); }
76 int GetTextWidth(const OUString& rText) const
77 {
78 return m_pDrawingArea->get_pixel_size(rText).Width();
79 }
80 OUString GetAccessibleName() const { return m_pDrawingArea->get_accessible_name(); }
81 OUString GetAccessibleDescription() const
82 {
83 return m_pDrawingArea->get_accessible_description();
84 }
85 void CaptureMouse() { m_pDrawingArea->grab_add(); }
86 bool IsMouseCaptured() const { return m_pDrawingArea->has_grab(); }
87 Point GetPointerPosPixel() const { return m_pDrawingArea->get_pointer_position(); }
88 void EnableRTL(bool bEnable) { m_pDrawingArea->set_direction(bEnable); }
89 bool IsRTLEnabled() const { return m_pDrawingArea->get_direction(); }
90 void ReleaseMouse() { m_pDrawingArea->grab_remove(); }
91 void SetPointer(PointerStyle ePointerStyle) { m_pDrawingArea->set_cursor(ePointerStyle); }
92 void SetHelpId(const OString& rHelpId) { m_pDrawingArea->set_help_id(rHelpId); }
93 void SetAccessibleName(const OUString& rName) { m_pDrawingArea->set_accessible_name(rName); }
94 void SetInputContext(const InputContext& rInputContext)
95 {
96 m_pDrawingArea->set_input_context(rInputContext);
97 }
98 void SetCursorRect(const tools::Rectangle& rCursorRect, int nExtTextInputWidth)
99 {
100 m_pDrawingArea->im_context_set_cursor_location(rCursorRect, nExtTextInputWidth);
101 }
102 virtual int GetSurroundingText(OUString& /*rSurrounding*/) { return -1; }
103 virtual bool DeleteSurroundingText(const Selection& /*rRange*/) { return false; }
104 css::uno::Reference<css::datatransfer::dnd::XDropTarget> GetDropTarget()
105 {
106 return m_pDrawingArea->get_drop_target();
107 }
108 css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const
109 {
110 return m_pDrawingArea->get_clipboard();
111 }
113 sal_uInt8 eDNDConstants)
114 {
115 m_pDrawingArea->enable_drag_source(rTransferrable, eDNDConstants);
116 m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl));
117 }
118 // return true to disallow drag, false to allow
119 virtual bool StartDrag() { return false; }
120 void set_size_request(int nWidth, int nHeight)
121 {
122 m_pDrawingArea->set_size_request(nWidth, nHeight);
123 }
125 {
126 if (!m_pDrawingArea)
127 return;
128 m_pDrawingArea->queue_resize();
129 }
131 : m_pDrawingArea(nullptr)
132 {
133 }
134 virtual ~CustomWidgetController();
135
140};
141
143{
144private:
146 std::unique_ptr<weld::DrawingArea> m_xDrawingArea;
147
148 DECL_DLLPRIVATE_LINK(DoResize, const Size& rSize, void);
150 DECL_DLLPRIVATE_LINK(DoMouseButtonDown, const MouseEvent&, bool);
151 DECL_DLLPRIVATE_LINK(DoMouseMove, const MouseEvent&, bool);
152 DECL_DLLPRIVATE_LINK(DoMouseButtonUp, const MouseEvent&, bool);
154 DECL_DLLPRIVATE_LINK(DoLoseFocus, weld::Widget&, void);
155 DECL_DLLPRIVATE_LINK(DoKeyPress, const KeyEvent&, bool);
157 DECL_DLLPRIVATE_LINK(DoCommand, const CommandEvent&, bool);
158 DECL_DLLPRIVATE_LINK(DoStyleUpdated, weld::Widget&, void);
159 DECL_DLLPRIVATE_LINK(DoRequestHelp, tools::Rectangle&, OUString);
160 DECL_DLLPRIVATE_LINK(DoGetSurrounding, OUString&, int);
161 DECL_DLLPRIVATE_LINK(DoDeleteSurrounding, const Selection&, bool);
162
163public:
164 CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId,
165 CustomWidgetController& rWidgetController);
166 void queue_draw() { m_xDrawingArea->queue_draw(); }
167 void queue_draw_area(int x, int y, int width, int height)
168 {
169 m_xDrawingArea->queue_draw_area(x, y, width, height);
170 }
171 void set_size_request(int nWidth, int nHeight)
172 {
173 m_xDrawingArea->set_size_request(nWidth, nHeight);
174 }
175 void show() { m_xDrawingArea->show(); }
176 void hide() { m_xDrawingArea->hide(); }
177 void set_margin_top(int nMargin) { m_xDrawingArea->set_margin_top(nMargin); }
178 void set_margin_bottom(int nMargin) { m_xDrawingArea->set_margin_bottom(nMargin); }
179 void set_sensitive(bool bSensitive) { m_xDrawingArea->set_sensitive(bSensitive); }
180 bool get_sensitive() const { return m_xDrawingArea->get_sensitive(); }
181 bool get_visible() const { return m_xDrawingArea->get_visible(); }
182 void set_visible(bool bVisible) { m_xDrawingArea->set_visible(bVisible); }
183 void set_grid_left_attach(int nAttach) { m_xDrawingArea->set_grid_left_attach(nAttach); }
184 int get_grid_left_attach() const { return m_xDrawingArea->get_grid_left_attach(); }
185 void set_help_id(const OString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); }
186 void set_tooltip_text(const OUString& rTip) { m_xDrawingArea->set_tooltip_text(rTip); }
187};
188}
189#endif
190
191/* 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:176
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:145
DECL_DLLPRIVATE_LINK(DoGetSurrounding, OUString &, int)
DECL_DLLPRIVATE_LINK(DoRequestHelp, tools::Rectangle &, OUString)
bool get_visible() const
Definition: customweld.hxx:181
DECL_DLLPRIVATE_LINK(DoResize, const Size &rSize, void)
void set_sensitive(bool bSensitive)
Definition: customweld.hxx:179
DECL_DLLPRIVATE_LINK(DoDeleteSurrounding, const Selection &, bool)
DECL_DLLPRIVATE_LINK(DoPaint, weld::DrawingArea::draw_args, void)
bool get_sensitive() const
Definition: customweld.hxx:180
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:185
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:178
void set_tooltip_text(const OUString &rTip)
Definition: customweld.hxx:186
int get_grid_left_attach() const
Definition: customweld.hxx:184
DECL_DLLPRIVATE_LINK(DoCommand, const CommandEvent &, bool)
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:171
void set_grid_left_attach(int nAttach)
Definition: customweld.hxx:183
void set_margin_top(int nMargin)
Definition: customweld.hxx:177
DECL_DLLPRIVATE_LINK(DoKeyPress, const KeyEvent &, bool)
void set_visible(bool bVisible)
Definition: customweld.hxx:182
std::unique_ptr< weld::DrawingArea > m_xDrawingArea
Definition: customweld.hxx:146
void queue_draw_area(int x, int y, int width, int height)
Definition: customweld.hxx:167
weld::DrawingArea * m_pDrawingArea
Definition: customweld.hxx:23
void SetPointer(PointerStyle ePointerStyle)
Definition: customweld.hxx:91
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:120
virtual bool KeyInput(const KeyEvent &)
Definition: customweld.hxx:41
css::uno::Reference< css::datatransfer::dnd::XDropTarget > GetDropTarget()
Definition: customweld.hxx:104
Point GetPointerPosPixel() const
Definition: customweld.hxx:87
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
Definition: customweld.hxx:48
OUString GetAccessibleName() const
Definition: customweld.hxx:80
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:76
weld::DrawingArea * GetDrawingArea() const
Definition: customweld.hxx:49
virtual OUString RequestHelp(tools::Rectangle &)
Definition: customweld.hxx:44
virtual int GetSurroundingText(OUString &)
Definition: customweld.hxx:102
CustomWidgetController(CustomWidgetController const &)=default
void EnableRTL(bool bEnable)
Definition: customweld.hxx:88
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:103
DECL_LINK(DragBeginHdl, weld::DrawingArea &, bool)
virtual OUString GetHelpText() const
Definition: customweld.hxx:45
void SetAccessibleName(const OUString &rName)
Definition: customweld.hxx:93
virtual tools::Rectangle GetFocusRect()
Definition: customweld.hxx:42
void SetHelpId(const OString &rHelpId)
Definition: customweld.hxx:92
void SetCursorRect(const tools::Rectangle &rCursorRect, int nExtTextInputWidth)
Definition: customweld.hxx:98
OUString GetAccessibleDescription() const
Definition: customweld.hxx:81
void Invalidate(const tools::Rectangle &rRect)
Definition: customweld.hxx:57
void SetInputContext(const InputContext &rInputContext)
Definition: customweld.hxx:94
virtual bool Command(const CommandEvent &)
Definition: customweld.hxx:40
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard() const
Definition: customweld.hxx:108
void SetDragDataTransferrable(rtl::Reference< TransferDataContainer > &rTransferrable, sal_uInt8 eDNDConstants)
Definition: customweld.hxx:112
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:2237
virtual void queue_draw_area(int x, int y, int width, int height)=0
virtual void enable_drag_source(rtl::Reference< TransferDataContainer > &rTransferrable, sal_uInt8 eDNDConstants)=0
virtual void set_cursor(PointerStyle ePointerStyle)=0
void connect_drag_begin(const Link< DrawingArea &, bool > &rLink)
Definition: weld.hxx:2281
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_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
PointerStyle
Definition: ptrstyle.hxx:26
bool bVisible
unsigned char sal_uInt8