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 
15 class InputContext;
16 
17 namespace weld
18 {
20 {
21 private:
24  DECL_LINK(DragBeginHdl, weld::DrawingArea&, bool);
25 
26 public:
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; }
50  void Invalidate()
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 IsVisible() const { return m_pDrawingArea->get_visible(); }
69  bool IsReallyVisible() const { return m_pDrawingArea->is_visible(); }
70  bool IsEnabled() const { return m_pDrawingArea->get_sensitive(); }
71  void Enable() const { m_pDrawingArea->set_sensitive(true); }
72  void Disable() const { m_pDrawingArea->set_sensitive(false); }
73  bool IsActive() const { return m_pDrawingArea->is_active(); }
74  int GetTextHeight() const { return m_pDrawingArea->get_text_height(); }
75  int GetTextWidth(const OUString& rText) const
76  {
77  return m_pDrawingArea->get_pixel_size(rText).Width();
78  }
79  OUString GetAccessibleName() const { return m_pDrawingArea->get_accessible_name(); }
80  OUString GetAccessibleDescription() const
81  {
82  return m_pDrawingArea->get_accessible_description();
83  }
84  void CaptureMouse() { m_pDrawingArea->grab_add(); }
85  bool IsMouseCaptured() const { return m_pDrawingArea->has_grab(); }
86  Point GetPointerPosPixel() const { return m_pDrawingArea->get_pointer_position(); }
87  void EnableRTL(bool bEnable) { m_pDrawingArea->set_direction(bEnable); }
88  bool IsRTLEnabled() const { return m_pDrawingArea->get_direction(); }
89  void ReleaseMouse() { m_pDrawingArea->grab_remove(); }
90  void SetPointer(PointerStyle ePointerStyle) { m_pDrawingArea->set_cursor(ePointerStyle); }
91  void SetHelpId(const OString& rHelpId) { m_pDrawingArea->set_help_id(rHelpId); }
92  void SetAccessibleName(const OUString& rName) { m_pDrawingArea->set_accessible_name(rName); }
93  void SetInputContext(const InputContext& rInputContext)
94  {
95  m_pDrawingArea->set_input_context(rInputContext);
96  }
97  void SetCursorRect(const tools::Rectangle& rCursorRect, int nExtTextInputWidth)
98  {
99  m_pDrawingArea->im_context_set_cursor_location(rCursorRect, nExtTextInputWidth);
100  }
101  virtual int GetSurroundingText(OUString& /*rSurrounding*/) { return -1; }
102  virtual bool DeleteSurroundingText(const Selection& /*rRange*/) { return false; }
103  css::uno::Reference<css::datatransfer::dnd::XDropTarget> GetDropTarget()
104  {
105  return m_pDrawingArea->get_drop_target();
106  }
107  css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const
108  {
109  return m_pDrawingArea->get_clipboard();
110  }
112  sal_uInt8 eDNDConstants)
113  {
114  m_pDrawingArea->enable_drag_source(rTransferrable, eDNDConstants);
115  m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl));
116  }
117  // return true to disallow drag, false to allow
118  virtual bool StartDrag() { return false; }
119  void set_size_request(int nWidth, int nHeight)
120  {
121  m_pDrawingArea->set_size_request(nWidth, nHeight);
122  }
124  {
125  if (!m_pDrawingArea)
126  return;
127  m_pDrawingArea->queue_resize();
128  }
130  : m_pDrawingArea(nullptr)
131  {
132  }
133  virtual ~CustomWidgetController();
134 
137  CustomWidgetController& operator=(CustomWidgetController const&) = default;
138  CustomWidgetController& operator=(CustomWidgetController&&) = default;
139 };
140 
142 {
143 private:
145  std::unique_ptr<weld::DrawingArea> m_xDrawingArea;
146 
147  DECL_LINK(DoResize, const Size& rSize, void);
148  DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void);
149  DECL_LINK(DoMouseButtonDown, const MouseEvent&, bool);
150  DECL_LINK(DoMouseMove, const MouseEvent&, bool);
151  DECL_LINK(DoMouseButtonUp, const MouseEvent&, bool);
152  DECL_LINK(DoGetFocus, weld::Widget&, void);
153  DECL_LINK(DoLoseFocus, weld::Widget&, void);
154  DECL_LINK(DoKeyPress, const KeyEvent&, bool);
155  DECL_LINK(DoFocusRect, weld::Widget&, tools::Rectangle);
156  DECL_LINK(DoCommand, const CommandEvent&, bool);
157  DECL_LINK(DoStyleUpdated, weld::Widget&, void);
158  DECL_LINK(DoRequestHelp, tools::Rectangle&, OUString);
159  DECL_LINK(DoGetSurrounding, OUString&, int);
160  DECL_LINK(DoDeleteSurrounding, const Selection&, bool);
161 
162 public:
163  CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId,
164  CustomWidgetController& rWidgetController);
165  void queue_draw() { m_xDrawingArea->queue_draw(); }
166  void queue_draw_area(int x, int y, int width, int height)
167  {
168  m_xDrawingArea->queue_draw_area(x, y, width, height);
169  }
170  void set_size_request(int nWidth, int nHeight)
171  {
172  m_xDrawingArea->set_size_request(nWidth, nHeight);
173  }
174  void show() { m_xDrawingArea->show(); }
175  void hide() { m_xDrawingArea->hide(); }
176  void set_margin_top(int nMargin) { m_xDrawingArea->set_margin_top(nMargin); }
177  void set_margin_bottom(int nMargin) { m_xDrawingArea->set_margin_bottom(nMargin); }
178  void set_sensitive(bool bSensitive) { m_xDrawingArea->set_sensitive(bSensitive); }
179  bool get_sensitive() const { return m_xDrawingArea->get_sensitive(); }
180  bool get_visible() const { return m_xDrawingArea->get_visible(); }
181  void set_visible(bool bVisible) { m_xDrawingArea->set_visible(bVisible); }
182  void set_grid_left_attach(int nAttach) { m_xDrawingArea->set_grid_left_attach(nAttach); }
183  int get_grid_left_attach() const { return m_xDrawingArea->get_grid_left_attach(); }
184  void set_help_id(const OString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); }
185  void set_tooltip_text(const OUString& rTip) { m_xDrawingArea->set_tooltip_text(rTip); }
186 };
187 }
188 #endif
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void queue_draw_area(int x, int y, int width, int height)
Definition: customweld.hxx:166
virtual Point get_pointer_position() const =0
virtual FactoryFunction GetUITestFactory() const
Definition: customweld.hxx:43
virtual OUString RequestHelp(tools::Rectangle &)
Definition: customweld.hxx:44
Point GetPointerPosPixel() const
Definition: customweld.hxx:86
virtual OUString GetHelpText() const
Definition: customweld.hxx:45
virtual void im_context_set_cursor_location(const tools::Rectangle &rCursorRect, int nExtTextInputWidth)=0
void set_help_id(const OString &rHelpId)
Definition: customweld.hxx:184
virtual void hide()=0
void SetHelpId(const OString &rHelpId)
Definition: customweld.hxx:91
virtual css::uno::Reference< css::datatransfer::dnd::XDropTarget > get_drop_target()=0
void set_margin_top(int nMargin)
Definition: customweld.hxx:176
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
std::unique_ptr< weld::DrawingArea > m_xDrawingArea
Definition: customweld.hxx:145
OUString GetAccessibleDescription() const
Definition: customweld.hxx:80
void set_visible(bool bVisible)
Definition: customweld.hxx:181
virtual bool MouseButtonUp(const MouseEvent &)
Definition: customweld.hxx:36
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
void SetDragDataTransferrable(rtl::Reference< TransferDataContainer > &rTransferrable, sal_uInt8 eDNDConstants)
Definition: customweld.hxx:111
virtual css::uno::Reference< css::datatransfer::clipboard::XClipboard > get_clipboard() const =0
virtual bool MouseMove(const MouseEvent &)
Definition: customweld.hxx:35
std::pair< vcl::RenderContext &, const tools::Rectangle & > draw_args
Definition: weld.hxx:2192
virtual bool get_direction() const =0
virtual void queue_draw()=0
Size const & GetOutputSizePixel() const
Definition: customweld.hxx:46
virtual void enable_drag_source(rtl::Reference< TransferDataContainer > &rTransferrable, sal_uInt8 eDNDConstants)=0
constexpr tools::Long Width() const
void Invalidate(const tools::Rectangle &rRect)
Definition: customweld.hxx:57
virtual void show()=0
void set_grid_left_attach(int nAttach)
Definition: customweld.hxx:182
tools::Long Left() const
constexpr tools::Long GetWidth() const
virtual void set_help_id(const OString &rName)=0
virtual bool get_visible() const =0
void set_margin_bottom(int nMargin)
Definition: customweld.hxx:177
void connect_drag_begin(const Link< DrawingArea &, bool > &rLink)
Definition: weld.hxx:2236
void SetCursorRect(const tools::Rectangle &rCursorRect, int nExtTextInputWidth)
Definition: customweld.hxx:97
virtual void set_cursor(PointerStyle ePointerStyle)=0
OUString GetAccessibleName() const
Definition: customweld.hxx:79
virtual bool has_focus() const =0
bool get_sensitive() const
Definition: customweld.hxx:179
virtual void grab_remove()=0
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:162
virtual bool DeleteSurroundingText(const Selection &)
Definition: customweld.hxx:102
virtual void set_direction(bool bRTL)=0
virtual tools::Rectangle GetFocusRect()
Definition: customweld.hxx:42
void SetInputContext(const InputContext &rInputContext)
Definition: customweld.hxx:93
virtual bool KeyInput(const KeyEvent &)
Definition: customweld.hxx:41
tools::Long Top() const
void SetAccessibleName(const OUString &rName)
Definition: customweld.hxx:92
void SetOutputSizePixel(const Size &rSize)
Definition: customweld.hxx:47
virtual bool has_grab() const =0
int GetTextWidth(const OUString &rText) const
Definition: customweld.hxx:75
virtual bool get_sensitive() const =0
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:119
virtual OUString get_tooltip_text() const =0
weld::DrawingArea * GetDrawingArea() const
Definition: customweld.hxx:49
virtual OUString get_accessible_description() const =0
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard() const
Definition: customweld.hxx:107
unsigned char sal_uInt8
virtual bool is_active() const =0
virtual int GetSurroundingText(OUString &)
Definition: customweld.hxx:101
virtual bool MouseButtonDown(const MouseEvent &)
Definition: customweld.hxx:34
virtual void grab_focus()=0
weld::DrawingArea * m_pDrawingArea
Definition: customweld.hxx:23
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:170
css::uno::Reference< css::datatransfer::dnd::XDropTarget > GetDropTarget()
Definition: customweld.hxx:103
virtual int get_text_height() const =0
virtual void grab_add()=0
virtual void set_input_context(const InputContext &rInputContext)=0
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
Definition: customweld.hxx:48
virtual Size get_pixel_size(const OUString &rText) const =0
PointerStyle
Definition: ptrstyle.hxx:25
int get_grid_left_attach() const
Definition: customweld.hxx:183
bool get_visible() const
Definition: customweld.hxx:180
virtual OUString get_accessible_name() const =0
void set_sensitive(bool bSensitive)
Definition: customweld.hxx:178
virtual bool is_visible() const =0
virtual void queue_draw_area(int x, int y, int width, int height)=0
weld::CustomWidgetController & m_rWidgetController
Definition: customweld.hxx:144
virtual void set_accessible_name(const OUString &rName)=0
void set_tooltip_text(const OUString &rTip)
Definition: customweld.hxx:185
virtual void set_size_request(int nWidth, int nHeight)=0
void SetPointer(PointerStyle ePointerStyle)
Definition: customweld.hxx:90
virtual bool Command(const CommandEvent &)
Definition: customweld.hxx:40
virtual void queue_resize()=0
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
Definition: customweld.hxx:27
virtual void set_sensitive(bool sensitive)=0
void EnableRTL(bool bEnable)
Definition: customweld.hxx:87
constexpr tools::Long GetHeight() const