1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_VCL_CUSTOMWELD_HXX
11 #define INCLUDED_VCL_CUSTOMWELD_HXX
13 #include <vcl/weld.hxx>
19 class VCL_DLLPUBLIC CustomWidgetController
23 weld::DrawingArea
* m_pDrawingArea
;
24 DECL_LINK(DragBeginHdl
, weld::DrawingArea
&, bool);
27 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible()
29 return css::uno::Reference
<css::accessibility::XAccessible
>();
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() { Invalidate(); }
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; }
42 virtual tools::Rectangle
GetFocusRect() { return tools::Rectangle(); }
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
; }
54 m_pDrawingArea
->queue_draw();
56 static bool IsUpdateMode() { return true; }
57 void Invalidate(const tools::Rectangle
& rRect
)
61 m_pDrawingArea
->queue_draw_area(rRect
.Left(), rRect
.Top(), rRect
.GetWidth(),
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
79 return m_pDrawingArea
->get_pixel_size(rText
).Width();
81 OUString
GetAccessibleName() const { return m_pDrawingArea
->get_accessible_name(); }
82 OUString
GetAccessibleDescription() const
84 return m_pDrawingArea
->get_accessible_description();
86 OUString
GetAccessibleId() const
89 return m_pDrawingArea
->get_accessible_id();
92 void CaptureMouse() { m_pDrawingArea
->grab_add(); }
93 bool IsMouseCaptured() const { return m_pDrawingArea
->has_grab(); }
94 Point
GetPointerPosPixel() const { return m_pDrawingArea
->get_pointer_position(); }
95 void EnableRTL(bool bEnable
) { m_pDrawingArea
->set_direction(bEnable
); }
96 bool IsRTLEnabled() const { return m_pDrawingArea
->get_direction(); }
97 void ReleaseMouse() { m_pDrawingArea
->grab_remove(); }
98 void SetPointer(PointerStyle ePointerStyle
) { m_pDrawingArea
->set_cursor(ePointerStyle
); }
99 void SetHelpId(const OUString
& rHelpId
) { m_pDrawingArea
->set_help_id(rHelpId
); }
100 void SetAccessibleName(const OUString
& rName
) { m_pDrawingArea
->set_accessible_name(rName
); }
101 void SetInputContext(const InputContext
& rInputContext
)
103 m_pDrawingArea
->set_input_context(rInputContext
);
105 void SetCursorRect(const tools::Rectangle
& rCursorRect
, int nExtTextInputWidth
)
107 m_pDrawingArea
->im_context_set_cursor_location(rCursorRect
, nExtTextInputWidth
);
109 virtual int GetSurroundingText(OUString
& /*rSurrounding*/) { return -1; }
110 virtual bool DeleteSurroundingText(const Selection
& /*rRange*/) { return false; }
111 css::uno::Reference
<css::datatransfer::dnd::XDropTarget
> GetDropTarget()
113 return m_pDrawingArea
->get_drop_target();
115 css::uno::Reference
<css::datatransfer::clipboard::XClipboard
> GetClipboard() const
117 return m_pDrawingArea
->get_clipboard();
119 void SetDragDataTransferable(rtl::Reference
<TransferDataContainer
>& rTransferable
,
120 sal_uInt8 eDNDConstants
)
122 m_pDrawingArea
->enable_drag_source(rTransferable
, eDNDConstants
);
123 m_pDrawingArea
->connect_drag_begin(LINK(this, CustomWidgetController
, DragBeginHdl
));
125 // return true to disallow drag, false to allow
126 virtual bool StartDrag() { return false; }
127 void set_size_request(int nWidth
, int nHeight
)
129 m_pDrawingArea
->set_size_request(nWidth
, nHeight
);
135 m_pDrawingArea
->queue_resize();
137 CustomWidgetController()
138 : m_pDrawingArea(nullptr)
141 virtual ~CustomWidgetController();
143 CustomWidgetController(CustomWidgetController
const&) = default;
144 CustomWidgetController(CustomWidgetController
&&) = default;
145 CustomWidgetController
& operator=(CustomWidgetController
const&) = default;
146 CustomWidgetController
& operator=(CustomWidgetController
&&) = default;
149 class VCL_DLLPUBLIC CustomWeld final
152 weld::CustomWidgetController
& m_rWidgetController
;
153 std::unique_ptr
<weld::DrawingArea
> m_xDrawingArea
;
155 DECL_DLLPRIVATE_LINK(DoResize
, const Size
& rSize
, void);
156 DECL_DLLPRIVATE_LINK(DoPaint
, weld::DrawingArea::draw_args
, void);
157 DECL_DLLPRIVATE_LINK(DoMouseButtonDown
, const MouseEvent
&, bool);
158 DECL_DLLPRIVATE_LINK(DoMouseMove
, const MouseEvent
&, bool);
159 DECL_DLLPRIVATE_LINK(DoMouseButtonUp
, const MouseEvent
&, bool);
160 DECL_DLLPRIVATE_LINK(DoGetFocus
, weld::Widget
&, void);
161 DECL_DLLPRIVATE_LINK(DoLoseFocus
, weld::Widget
&, void);
162 DECL_DLLPRIVATE_LINK(DoKeyPress
, const KeyEvent
&, bool);
163 DECL_DLLPRIVATE_LINK(DoFocusRect
, weld::Widget
&, tools::Rectangle
);
164 DECL_DLLPRIVATE_LINK(DoCommand
, const CommandEvent
&, bool);
165 DECL_DLLPRIVATE_LINK(DoStyleUpdated
, weld::Widget
&, void);
166 DECL_DLLPRIVATE_LINK(DoRequestHelp
, tools::Rectangle
&, OUString
);
167 DECL_DLLPRIVATE_LINK(DoGetSurrounding
, OUString
&, int);
168 DECL_DLLPRIVATE_LINK(DoDeleteSurrounding
, const Selection
&, bool);
171 CustomWeld(weld::Builder
& rBuilder
, const OUString
& rDrawingId
,
172 CustomWidgetController
& rWidgetController
);
173 void queue_draw() { m_xDrawingArea
->queue_draw(); }
174 void queue_draw_area(int x
, int y
, int width
, int height
)
176 m_xDrawingArea
->queue_draw_area(x
, y
, width
, height
);
178 void set_size_request(int nWidth
, int nHeight
)
180 m_xDrawingArea
->set_size_request(nWidth
, nHeight
);
182 void show() { m_xDrawingArea
->show(); }
183 void hide() { m_xDrawingArea
->hide(); }
184 void set_margin_top(int nMargin
) { m_xDrawingArea
->set_margin_top(nMargin
); }
185 void set_margin_bottom(int nMargin
) { m_xDrawingArea
->set_margin_bottom(nMargin
); }
186 void set_sensitive(bool bSensitive
) { m_xDrawingArea
->set_sensitive(bSensitive
); }
187 bool get_sensitive() const { return m_xDrawingArea
->get_sensitive(); }
188 bool get_visible() const { return m_xDrawingArea
->get_visible(); }
189 void set_visible(bool bVisible
) { m_xDrawingArea
->set_visible(bVisible
); }
190 void set_grid_left_attach(int nAttach
) { m_xDrawingArea
->set_grid_left_attach(nAttach
); }
191 int get_grid_left_attach() const { return m_xDrawingArea
->get_grid_left_attach(); }
192 void set_help_id(const OUString
& rHelpId
) { m_xDrawingArea
->set_help_id(rHelpId
); }
193 void set_tooltip_text(const OUString
& rTip
) { m_xDrawingArea
->set_tooltip_text(rTip
); }
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */