workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / vcl / customweld.hxx
blobc7504fb94d95cda797d3a585054369b63f3339b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #ifndef INCLUDED_VCL_CUSTOMWELD_HXX
11 #define INCLUDED_VCL_CUSTOMWELD_HXX
13 #include <vcl/weld.hxx>
15 class InputContext;
17 namespace weld
19 class VCL_DLLPUBLIC CustomWidgetController
21 private:
22 Size m_aSize;
23 weld::DrawingArea* m_pDrawingArea;
24 DECL_LINK(DragBeginHdl, weld::DrawingArea&, bool);
26 public:
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; }
50 void Invalidate()
52 if (!m_pDrawingArea)
53 return;
54 m_pDrawingArea->queue_draw();
56 static bool IsUpdateMode() { return true; }
57 void Invalidate(const tools::Rectangle& rRect)
59 if (!m_pDrawingArea)
60 return;
61 m_pDrawingArea->queue_draw_area(rRect.Left(), rRect.Top(), rRect.GetWidth(),
62 rRect.GetHeight());
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 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 OUString& 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)
97 m_pDrawingArea->set_input_context(rInputContext);
99 void SetCursorRect(const tools::Rectangle& rCursorRect, int nExtTextInputWidth)
101 m_pDrawingArea->im_context_set_cursor_location(rCursorRect, nExtTextInputWidth);
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()
107 return m_pDrawingArea->get_drop_target();
109 css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const
111 return m_pDrawingArea->get_clipboard();
113 void SetDragDataTransferable(rtl::Reference<TransferDataContainer>& rTransferable,
114 sal_uInt8 eDNDConstants)
116 m_pDrawingArea->enable_drag_source(rTransferable, eDNDConstants);
117 m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl));
119 // return true to disallow drag, false to allow
120 virtual bool StartDrag() { return false; }
121 void set_size_request(int nWidth, int nHeight)
123 m_pDrawingArea->set_size_request(nWidth, nHeight);
125 void queue_resize()
127 if (!m_pDrawingArea)
128 return;
129 m_pDrawingArea->queue_resize();
131 CustomWidgetController()
132 : m_pDrawingArea(nullptr)
135 virtual ~CustomWidgetController();
137 CustomWidgetController(CustomWidgetController const&) = default;
138 CustomWidgetController(CustomWidgetController&&) = default;
139 CustomWidgetController& operator=(CustomWidgetController const&) = default;
140 CustomWidgetController& operator=(CustomWidgetController&&) = default;
143 class VCL_DLLPUBLIC CustomWeld final
145 private:
146 weld::CustomWidgetController& m_rWidgetController;
147 std::unique_ptr<weld::DrawingArea> m_xDrawingArea;
149 DECL_DLLPRIVATE_LINK(DoResize, const Size& rSize, void);
150 DECL_DLLPRIVATE_LINK(DoPaint, weld::DrawingArea::draw_args, 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);
154 DECL_DLLPRIVATE_LINK(DoGetFocus, weld::Widget&, void);
155 DECL_DLLPRIVATE_LINK(DoLoseFocus, weld::Widget&, void);
156 DECL_DLLPRIVATE_LINK(DoKeyPress, const KeyEvent&, bool);
157 DECL_DLLPRIVATE_LINK(DoFocusRect, weld::Widget&, tools::Rectangle);
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);
164 public:
165 CustomWeld(weld::Builder& rBuilder, const OUString& 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)
170 m_xDrawingArea->queue_draw_area(x, y, width, height);
172 void set_size_request(int nWidth, int nHeight)
174 m_xDrawingArea->set_size_request(nWidth, nHeight);
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 OUString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); }
187 void set_tooltip_text(const OUString& rTip) { m_xDrawingArea->set_tooltip_text(rTip); }
190 #endif
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */