/src/libreoffice/include/vcl/weld/customweld.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 <comphelper/OAccessible.hxx> |
13 | | #include <vcl/weld/Builder.hxx> |
14 | | #include <vcl/weld/weld.hxx> |
15 | | |
16 | | class InputContext; |
17 | | |
18 | | namespace weld |
19 | | { |
20 | | class VCL_DLLPUBLIC CustomWidgetController |
21 | | { |
22 | | private: |
23 | | Size m_aSize; |
24 | | weld::DrawingArea* m_pDrawingArea; |
25 | | DECL_LINK(DragBeginHdl, weld::DrawingArea&, bool); |
26 | | |
27 | | public: |
28 | 0 | virtual rtl::Reference<comphelper::OAccessible> CreateAccessible() { return {}; } |
29 | | // rRect is in Logical units rather than Pixels |
30 | | virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) = 0; |
31 | 0 | virtual void Resize() { Invalidate(); } |
32 | 0 | virtual bool MouseButtonDown(const MouseEvent&) { return false; } |
33 | 0 | virtual bool MouseMove(const MouseEvent&) { return false; } |
34 | 0 | virtual bool MouseButtonUp(const MouseEvent&) { return false; } |
35 | 0 | virtual void GetFocus() {} |
36 | 0 | virtual void LoseFocus() {} |
37 | 0 | virtual void StyleUpdated() { Invalidate(); } |
38 | 0 | virtual bool Command(const CommandEvent&) { return false; } |
39 | 0 | virtual bool KeyInput(const KeyEvent&) { return false; } |
40 | 0 | virtual bool KeyUp(const KeyEvent&) { return false; } |
41 | 0 | virtual tools::Rectangle GetFocusRect() { return tools::Rectangle(); } |
42 | 0 | virtual FactoryFunction GetUITestFactory() const { return nullptr; } |
43 | 0 | virtual OUString RequestHelp(tools::Rectangle&) { return OUString(); } |
44 | 0 | OUString GetHelpText() const { return m_pDrawingArea->get_tooltip_text(); } |
45 | 0 | Size const& GetOutputSizePixel() const { return m_aSize; } |
46 | 0 | void SetOutputSizePixel(const Size& rSize) { m_aSize = rSize; } |
47 | 0 | virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) { m_pDrawingArea = pDrawingArea; } |
48 | 0 | weld::DrawingArea* GetDrawingArea() const { return m_pDrawingArea; } |
49 | | void Invalidate() |
50 | 0 | { |
51 | 0 | if (!m_pDrawingArea) |
52 | 0 | return; |
53 | 0 | m_pDrawingArea->queue_draw(); |
54 | 0 | } |
55 | | void Invalidate(const tools::Rectangle& rRect) |
56 | 0 | { |
57 | 0 | if (!m_pDrawingArea) |
58 | 0 | return; |
59 | 0 | m_pDrawingArea->queue_draw_area(rRect.Left(), rRect.Top(), rRect.GetWidth(), |
60 | 0 | rRect.GetHeight()); |
61 | 0 | } |
62 | 0 | virtual void Show() { m_pDrawingArea->show(); } |
63 | 0 | virtual void Hide() { m_pDrawingArea->hide(); } |
64 | 0 | void SetCursor(void* pData) { m_pDrawingArea->set_cursor_data(pData); } |
65 | 0 | void GrabFocus() { m_pDrawingArea->grab_focus(); } |
66 | 0 | bool HasFocus() const { return m_pDrawingArea->has_focus(); } |
67 | 0 | bool HasChildFocus() const { return m_pDrawingArea->has_child_focus(); } |
68 | 0 | bool IsVisible() const { return m_pDrawingArea->get_visible(); } |
69 | 0 | bool IsReallyVisible() const { return m_pDrawingArea->is_visible(); } |
70 | 0 | bool IsEnabled() const { return m_pDrawingArea->get_sensitive(); } |
71 | 0 | void Enable() const { m_pDrawingArea->set_sensitive(true); } |
72 | 0 | void Disable() const { m_pDrawingArea->set_sensitive(false); } |
73 | 0 | int GetTextHeight() const { return m_pDrawingArea->get_text_height(); } |
74 | | int GetTextWidth(const OUString& rText) const |
75 | 0 | { |
76 | 0 | return m_pDrawingArea->get_pixel_size(rText).Width(); |
77 | 0 | } |
78 | 0 | OUString GetAccessibleName() const { return m_pDrawingArea->get_accessible_name(); } |
79 | | OUString GetAccessibleDescription() const |
80 | 0 | { |
81 | 0 | return m_pDrawingArea->get_accessible_description(); |
82 | 0 | } |
83 | | OUString GetAccessibleId() const |
84 | 0 | { |
85 | 0 | if (m_pDrawingArea) |
86 | 0 | return m_pDrawingArea->get_accessible_id(); |
87 | 0 | return OUString(); |
88 | 0 | } |
89 | 0 | void CaptureMouse() { m_pDrawingArea->grab_mouse(); } |
90 | 0 | bool IsMouseCaptured() const { return m_pDrawingArea->has_mouse_grab(); } |
91 | 0 | Point GetPointerPosPixel() const { return m_pDrawingArea->get_pointer_position(); } |
92 | 0 | void EnableRTL(bool bEnable) { m_pDrawingArea->set_direction(bEnable); } |
93 | 0 | bool IsRTLEnabled() const { return m_pDrawingArea->get_direction(); } |
94 | 0 | void ReleaseMouse() { m_pDrawingArea->release_mouse(); } |
95 | 0 | void SetPointer(PointerStyle ePointerStyle) { m_pDrawingArea->set_cursor(ePointerStyle); } |
96 | 0 | void SetHelpId(const OUString& rHelpId) { m_pDrawingArea->set_help_id(rHelpId); } |
97 | 0 | void SetAccessibleName(const OUString& rName) { m_pDrawingArea->set_accessible_name(rName); } |
98 | | void SetInputContext(const InputContext& rInputContext) |
99 | 0 | { |
100 | 0 | m_pDrawingArea->set_input_context(rInputContext); |
101 | 0 | } |
102 | | void SetCursorRect(const tools::Rectangle& rCursorRect, int nExtTextInputWidth) |
103 | 0 | { |
104 | 0 | m_pDrawingArea->im_context_set_cursor_location(rCursorRect, nExtTextInputWidth); |
105 | 0 | } |
106 | 0 | virtual int GetSurroundingText(OUString& /*rSurrounding*/) { return -1; } |
107 | 0 | virtual bool DeleteSurroundingText(const Selection& /*rRange*/) { return false; } |
108 | | css::uno::Reference<css::datatransfer::dnd::XDropTarget> GetDropTarget() |
109 | 0 | { |
110 | 0 | return m_pDrawingArea->get_drop_target(); |
111 | 0 | } |
112 | | css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const |
113 | 0 | { |
114 | 0 | return m_pDrawingArea->get_clipboard(); |
115 | 0 | } |
116 | | void SetDragDataTransferable(rtl::Reference<TransferDataContainer>& rTransferable, |
117 | | sal_uInt8 eDNDConstants) |
118 | 0 | { |
119 | 0 | m_pDrawingArea->enable_drag_source(rTransferable, eDNDConstants); |
120 | 0 | m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl)); |
121 | 0 | } Unexecuted instantiation: weld::CustomWidgetController::SetDragDataTransferable(rtl::Reference<TransferDataContainer>&, unsigned char) Unexecuted instantiation: weld::CustomWidgetController::SetDragDataTransferable(rtl::Reference<TransferDataContainer>&, unsigned char) |
122 | | // return true to disallow drag, false to allow |
123 | 0 | virtual bool StartDrag() { return false; } |
124 | | void set_size_request(int nWidth, int nHeight) |
125 | 0 | { |
126 | 0 | m_pDrawingArea->set_size_request(nWidth, nHeight); |
127 | 0 | } |
128 | | void queue_resize() |
129 | 0 | { |
130 | 0 | if (!m_pDrawingArea) |
131 | 0 | return; |
132 | 0 | m_pDrawingArea->queue_resize(); |
133 | 0 | } |
134 | | CustomWidgetController() |
135 | 0 | : m_pDrawingArea(nullptr) |
136 | 0 | { |
137 | 0 | } |
138 | | virtual ~CustomWidgetController(); |
139 | | |
140 | | CustomWidgetController(CustomWidgetController const&) = default; |
141 | | CustomWidgetController(CustomWidgetController&&) = default; |
142 | | CustomWidgetController& operator=(CustomWidgetController const&) = default; |
143 | | CustomWidgetController& operator=(CustomWidgetController&&) = default; |
144 | | }; |
145 | | |
146 | | class VCL_DLLPUBLIC CustomWeld final |
147 | | { |
148 | | private: |
149 | | weld::CustomWidgetController& m_rWidgetController; |
150 | | std::unique_ptr<weld::DrawingArea> m_xDrawingArea; |
151 | | |
152 | | DECL_DLLPRIVATE_LINK(DoResize, const Size& rSize, void); |
153 | | DECL_DLLPRIVATE_LINK(DoPaint, weld::DrawingArea::draw_args, void); |
154 | | DECL_DLLPRIVATE_LINK(DoMouseButtonDown, const MouseEvent&, bool); |
155 | | DECL_DLLPRIVATE_LINK(DoMouseMove, const MouseEvent&, bool); |
156 | | DECL_DLLPRIVATE_LINK(DoMouseButtonUp, const MouseEvent&, bool); |
157 | | DECL_DLLPRIVATE_LINK(DoGetFocus, weld::Widget&, void); |
158 | | DECL_DLLPRIVATE_LINK(DoLoseFocus, weld::Widget&, void); |
159 | | DECL_DLLPRIVATE_LINK(DoKeyPress, const KeyEvent&, bool); |
160 | | DECL_DLLPRIVATE_LINK(DoKeyRelease, const KeyEvent&, bool); |
161 | | DECL_DLLPRIVATE_LINK(DoFocusRect, weld::Widget&, tools::Rectangle); |
162 | | DECL_DLLPRIVATE_LINK(DoCommand, const CommandEvent&, bool); |
163 | | DECL_DLLPRIVATE_LINK(DoStyleUpdated, weld::Widget&, void); |
164 | | DECL_DLLPRIVATE_LINK(DoRequestHelp, tools::Rectangle&, OUString); |
165 | | DECL_DLLPRIVATE_LINK(DoGetSurrounding, OUString&, int); |
166 | | DECL_DLLPRIVATE_LINK(DoDeleteSurrounding, const Selection&, bool); |
167 | | |
168 | | public: |
169 | | CustomWeld(weld::Builder& rBuilder, const OUString& rDrawingId, |
170 | | CustomWidgetController& rWidgetController); |
171 | 0 | void queue_draw() { m_xDrawingArea->queue_draw(); } |
172 | | void queue_draw_area(int x, int y, int width, int height) |
173 | 0 | { |
174 | 0 | m_xDrawingArea->queue_draw_area(x, y, width, height); |
175 | 0 | } |
176 | | void set_size_request(int nWidth, int nHeight) |
177 | 0 | { |
178 | 0 | m_xDrawingArea->set_size_request(nWidth, nHeight); |
179 | 0 | } |
180 | 0 | void show() { m_xDrawingArea->show(); } |
181 | 0 | void hide() { m_xDrawingArea->hide(); } |
182 | 0 | void set_margin_top(int nMargin) { m_xDrawingArea->set_margin_top(nMargin); } |
183 | 0 | void set_margin_bottom(int nMargin) { m_xDrawingArea->set_margin_bottom(nMargin); } |
184 | 0 | void set_sensitive(bool bSensitive) { m_xDrawingArea->set_sensitive(bSensitive); } |
185 | 0 | bool get_sensitive() const { return m_xDrawingArea->get_sensitive(); } |
186 | 0 | bool get_visible() const { return m_xDrawingArea->get_visible(); } |
187 | 0 | void set_visible(bool bVisible) { m_xDrawingArea->set_visible(bVisible); } |
188 | 0 | void set_help_id(const OUString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); } |
189 | 0 | void set_tooltip_text(const OUString& rTip) { m_xDrawingArea->set_tooltip_text(rTip); } |
190 | | }; |
191 | | } |
192 | | |
193 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |