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