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 namespace weld
16 {
18 {
19 private:
22  DECL_LINK(DragBeginHdl, weld::DrawingArea&, bool);
23 
24 public:
25  virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible()
26  {
27  return css::uno::Reference<css::accessibility::XAccessible>();
28  }
29  virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) = 0;
30  virtual void Resize() {}
31  virtual bool MouseButtonDown(const MouseEvent&) { return false; }
32  virtual bool MouseMove(const MouseEvent&) { return false; }
33  virtual bool MouseButtonUp(const MouseEvent&) { return false; }
34  virtual void GetFocus() {}
35  virtual void LoseFocus() {}
36  virtual void StyleUpdated() { Invalidate(); }
37  virtual bool Command(const CommandEvent&) { return false; }
38  virtual bool KeyInput(const KeyEvent&) { return false; }
40  virtual FactoryFunction GetUITestFactory() const { return nullptr; }
41  virtual OUString RequestHelp(tools::Rectangle&) { return OUString(); }
42  virtual OUString GetHelpText() const { return m_pDrawingArea->get_tooltip_text(); }
43  Size const& GetOutputSizePixel() const { return m_aSize; }
44  void SetOutputSizePixel(const Size& rSize) { m_aSize = rSize; }
45  virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) { m_pDrawingArea = pDrawingArea; }
46  weld::DrawingArea* GetDrawingArea() const { return m_pDrawingArea; }
47  void Invalidate() { m_pDrawingArea->queue_draw(); }
48  static bool IsUpdateMode() { return true; }
49  void Invalidate(const tools::Rectangle& rRect)
50  {
51  m_pDrawingArea->queue_draw_area(rRect.Left(), rRect.Top(), rRect.GetWidth(),
52  rRect.GetHeight());
53  }
54  virtual void Show() { m_pDrawingArea->show(); }
55  virtual void Hide() { m_pDrawingArea->hide(); }
56  void GrabFocus() { m_pDrawingArea->grab_focus(); }
57  bool HasFocus() const { return m_pDrawingArea->has_focus(); }
58  bool IsVisible() const { return m_pDrawingArea->get_visible(); }
59  bool IsReallyVisible() const { return m_pDrawingArea->is_visible(); }
60  bool IsEnabled() const { return m_pDrawingArea->get_sensitive(); }
61  void Enable() const { m_pDrawingArea->set_sensitive(true); }
62  void Disable() const { m_pDrawingArea->set_sensitive(false); }
63  bool IsActive() const { return m_pDrawingArea->is_active(); }
64  int GetTextHeight() const { return m_pDrawingArea->get_text_height(); }
65  OUString GetAccessibleName() const { return m_pDrawingArea->get_accessible_name(); }
66  OUString GetAccessibleDescription() const
67  {
68  return m_pDrawingArea->get_accessible_description();
69  }
70  void CaptureMouse() { m_pDrawingArea->grab_add(); }
71  bool IsMouseCaptured() const { return m_pDrawingArea->has_grab(); }
72  void EnableRTL(bool bEnable) { m_pDrawingArea->set_direction(bEnable); }
73  bool IsRTLEnabled() const { return m_pDrawingArea->get_direction(); }
74  void ReleaseMouse() { m_pDrawingArea->grab_remove(); }
75  void SetPointer(PointerStyle ePointerStyle) { m_pDrawingArea->set_cursor(ePointerStyle); }
76  void SetHelpId(const OString& rHelpId) { m_pDrawingArea->set_help_id(rHelpId); }
77  void SetAccessibleName(const OUString& rName) { m_pDrawingArea->set_accessible_name(rName); }
79  sal_uInt8 eDNDConstants)
80  {
81  m_pDrawingArea->enable_drag_source(rTransferrable, eDNDConstants);
82  m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl));
83  }
84  // return true to disallow drag, false to allow
85  virtual bool StartDrag() { return false; }
86  void set_size_request(int nWidth, int nHeight)
87  {
88  m_pDrawingArea->set_size_request(nWidth, nHeight);
89  }
90  void queue_resize() { m_pDrawingArea->queue_resize(); }
92  : m_pDrawingArea(nullptr)
93  {
94  }
95  virtual ~CustomWidgetController();
96 
99  CustomWidgetController& operator=(CustomWidgetController const&) = default;
100  CustomWidgetController& operator=(CustomWidgetController&&) = default;
101 };
102 
104 {
105 private:
107  std::unique_ptr<weld::DrawingArea> m_xDrawingArea;
108 
109  DECL_LINK(DoResize, const Size& rSize, void);
110  DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void);
111  DECL_LINK(DoMouseButtonDown, const MouseEvent&, bool);
112  DECL_LINK(DoMouseMove, const MouseEvent&, bool);
113  DECL_LINK(DoMouseButtonUp, const MouseEvent&, bool);
114  DECL_LINK(DoGetFocus, weld::Widget&, void);
115  DECL_LINK(DoLoseFocus, weld::Widget&, void);
116  DECL_LINK(DoKeyPress, const KeyEvent&, bool);
117  DECL_LINK(DoFocusRect, weld::Widget&, tools::Rectangle);
118  DECL_LINK(DoCommand, const CommandEvent&, bool);
119  DECL_LINK(DoStyleUpdated, weld::Widget&, void);
120  DECL_LINK(DoRequestHelp, tools::Rectangle&, OUString);
121 
122 public:
123  CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId,
124  CustomWidgetController& rWidgetController);
125  void queue_draw() { m_xDrawingArea->queue_draw(); }
126  void queue_draw_area(int x, int y, int width, int height)
127  {
128  m_xDrawingArea->queue_draw_area(x, y, width, height);
129  }
130  void set_size_request(int nWidth, int nHeight)
131  {
132  m_xDrawingArea->set_size_request(nWidth, nHeight);
133  }
134  void show() { m_xDrawingArea->show(); }
135  void hide() { m_xDrawingArea->hide(); }
136  void set_margin_top(int nMargin) { m_xDrawingArea->set_margin_top(nMargin); }
137  void set_margin_bottom(int nMargin) { m_xDrawingArea->set_margin_bottom(nMargin); }
138  void set_sensitive(bool bSensitive) { m_xDrawingArea->set_sensitive(bSensitive); }
139  bool get_sensitive() const { return m_xDrawingArea->get_sensitive(); }
140  bool get_visible() const { return m_xDrawingArea->get_visible(); }
141  void set_visible(bool bVisible) { m_xDrawingArea->set_visible(bVisible); }
142  void set_grid_left_attach(int nAttach) { m_xDrawingArea->set_grid_left_attach(nAttach); }
143  int get_grid_left_attach() const { return m_xDrawingArea->get_grid_left_attach(); }
144  void set_help_id(const OString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); }
145 };
146 }
147 #endif
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void queue_draw_area(int x, int y, int width, int height)
Definition: customweld.hxx:126
virtual FactoryFunction GetUITestFactory() const
Definition: customweld.hxx:40
long GetWidth() const
virtual OUString RequestHelp(tools::Rectangle &)
Definition: customweld.hxx:41
virtual OUString GetHelpText() const
Definition: customweld.hxx:42
long GetHeight() const
void set_help_id(const OString &rHelpId)
Definition: customweld.hxx:144
virtual void hide()=0
void SetHelpId(const OString &rHelpId)
Definition: customweld.hxx:76
void set_margin_top(int nMargin)
Definition: customweld.hxx:136
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
std::unique_ptr< weld::DrawingArea > m_xDrawingArea
Definition: customweld.hxx:107
OUString GetAccessibleDescription() const
Definition: customweld.hxx:66
void set_visible(bool bVisible)
Definition: customweld.hxx:141
virtual bool MouseButtonUp(const MouseEvent &)
Definition: customweld.hxx:33
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
void SetDragDataTransferrable(rtl::Reference< TransferDataContainer > &rTransferrable, sal_uInt8 eDNDConstants)
Definition: customweld.hxx:78
virtual bool MouseMove(const MouseEvent &)
Definition: customweld.hxx:32
std::pair< vcl::RenderContext &, const tools::Rectangle & > draw_args
Definition: weld.hxx:2005
virtual bool get_direction() const =0
virtual void queue_draw()=0
Size const & GetOutputSizePixel() const
Definition: customweld.hxx:43
virtual void enable_drag_source(rtl::Reference< TransferDataContainer > &rTransferrable, sal_uInt8 eDNDConstants)=0
void Invalidate(const tools::Rectangle &rRect)
Definition: customweld.hxx:49
virtual void show()=0
void set_grid_left_attach(int nAttach)
Definition: customweld.hxx:142
virtual void set_help_id(const OString &rName)=0
long Top() const
virtual bool get_visible() const =0
void set_margin_bottom(int nMargin)
Definition: customweld.hxx:137
void connect_drag_begin(const Link< DrawingArea &, bool > &rLink)
Definition: weld.hxx:2033
virtual void set_cursor(PointerStyle ePointerStyle)=0
virtual void queue_resize()=0
OUString GetAccessibleName() const
Definition: customweld.hxx:65
virtual bool has_focus() const =0
bool get_sensitive() const
Definition: customweld.hxx:139
virtual void grab_remove()=0
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
virtual void set_direction(bool bRTL)=0
virtual tools::Rectangle GetFocusRect()
Definition: customweld.hxx:39
virtual bool KeyInput(const KeyEvent &)
Definition: customweld.hxx:38
void SetAccessibleName(const OUString &rName)
Definition: customweld.hxx:77
void SetOutputSizePixel(const Size &rSize)
Definition: customweld.hxx:44
virtual bool has_grab() const =0
virtual bool get_sensitive() const =0
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:86
virtual OUString get_tooltip_text() const =0
weld::DrawingArea * GetDrawingArea() const
Definition: customweld.hxx:46
virtual OUString get_accessible_description() const =0
unsigned char sal_uInt8
virtual bool is_active() const =0
virtual bool MouseButtonDown(const MouseEvent &)
Definition: customweld.hxx:31
virtual void grab_focus()=0
weld::DrawingArea * m_pDrawingArea
Definition: customweld.hxx:21
void set_size_request(int nWidth, int nHeight)
Definition: customweld.hxx:130
virtual int get_text_height() const =0
virtual void grab_add()=0
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
Definition: customweld.hxx:45
long Left() const
PointerStyle
Definition: ptrstyle.hxx:25
int get_grid_left_attach() const
Definition: customweld.hxx:143
bool get_visible() const
Definition: customweld.hxx:140
virtual OUString get_accessible_name() const =0
void set_sensitive(bool bSensitive)
Definition: customweld.hxx:138
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:106
virtual void set_accessible_name(const OUString &rName)=0
virtual void set_size_request(int nWidth, int nHeight)=0
void SetPointer(PointerStyle ePointerStyle)
Definition: customweld.hxx:75
virtual bool Command(const CommandEvent &)
Definition: customweld.hxx:37
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
Definition: customweld.hxx:25
virtual void set_sensitive(bool sensitive)=0
void EnableRTL(bool bEnable)
Definition: customweld.hxx:72