Bump version to 6.4-15
[LibreOffice.git] / include / vcl / layout.hxx
blobd1f675a3be07d2818c1822220ded9fbb5c141c6e
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_LAYOUT_HXX
11 #define INCLUDED_VCL_LAYOUT_HXX
13 #include <vcl/dllapi.h>
14 #include <vcl/button.hxx>
15 #include <vcl/help.hxx>
16 #include <vcl/scrbar.hxx>
17 #include <vcl/split.hxx>
18 #include <vcl/svapp.hxx>
19 #include <vcl/window.hxx>
20 #include <vcl/settings.hxx>
21 #include <vcl/event.hxx>
22 #include <vcl/vclptr.hxx>
23 #include <vcl/IContext.hxx>
24 #include <vcl/commandevent.hxx>
25 #include <tools/stream.hxx>
26 #include <vcl/cvtgrf.hxx>
27 #include <comphelper/base64.hxx>
28 #include <vcl/virdev.hxx>
29 #include <set>
30 #include <boost/property_tree/json_parser.hpp>
32 class VCL_DLLPUBLIC VclContainer : public vcl::Window,
33 public vcl::IContext
35 public:
36 VclContainer(vcl::Window *pParent, WinBits nStyle = WB_HIDE | WB_CLIPCHILDREN);
38 //These take into account the external margins of the rWindow widget
39 //while GetOptimalSize/get_preferred_size and SetPosSizePixel are
40 //oblivious to them
41 static Size getLayoutRequisition(const vcl::Window &rWindow);
42 static void setLayoutPosSize(vcl::Window &rWindow, const Point &rPos, const Size &rSize);
44 //applies the allocation pos and size onto rWindow via setLayoutPosSize taking into account
45 //the rWindows alignment desires within that allocation
46 static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize);
48 virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
49 protected:
50 //these are the two that need to be implemented by
51 //containers, figure out how much space you want...
52 virtual Size calculateRequisition() const = 0;
53 //..and decide what to do when set to this size
54 virtual void setAllocation(const Size &rAllocation) = 0;
56 virtual sal_uInt16 getDefaultAccessibleRole() const override;
58 // support for screenshot context menu
59 virtual void Command(const CommandEvent& rCEvt) override;
61 public:
62 //you don't want to override these
63 virtual Size GetOptimalSize() const override;
64 virtual void SetPosSizePixel(const Point& rNewPos, const Size& rNewSize) override;
65 virtual void SetPosPixel(const Point& rAllocPos) override;
66 virtual void SetSizePixel(const Size& rAllocation) override;
67 private:
68 bool m_bLayoutDirty;
71 class VCL_DLLPUBLIC VclBox : public VclContainer
73 protected:
74 bool m_bHomogeneous;
75 bool m_bVerticalContainer;
76 int m_nSpacing;
77 public:
78 VclBox(vcl::Window *pParent, bool bHomogeneous, int nSpacing)
79 : VclContainer(pParent)
80 , m_bHomogeneous(bHomogeneous)
81 , m_bVerticalContainer(false)
82 , m_nSpacing(nSpacing)
85 void set_spacing(int nSpacing)
87 m_nSpacing = nSpacing;
89 int get_spacing() const
91 return m_nSpacing;
93 void set_homogeneous(bool bHomogeneous)
95 m_bHomogeneous = bHomogeneous;
97 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
98 virtual boost::property_tree::ptree DumpAsPropertyTree() override;
99 protected:
100 virtual sal_uInt16 getDefaultAccessibleRole() const override;
101 void accumulateMaxes(const Size &rChildSize, Size &rSize) const;
102 Size finalizeMaxes(const Size &rSize, sal_uInt16 nVisibleChildren) const;
104 virtual Size calculateRequisition() const override;
105 virtual void setAllocation(const Size &rAllocation) override;
107 virtual long getPrimaryDimension(const Size &rSize) const = 0;
108 virtual void setPrimaryDimension(Size &rSize, long) const = 0;
109 virtual long getPrimaryCoordinate(const Point &rPos) const = 0;
110 virtual void setPrimaryCoordinate(Point &rPos, long) const = 0;
111 virtual long getSecondaryDimension(const Size &rSize) const = 0;
112 virtual void setSecondaryDimension(Size &rSize, long) const = 0;
114 virtual bool getPrimaryDimensionChildExpand(const vcl::Window &rWindow) const = 0;
117 class VCL_DLLPUBLIC VclVBox : public VclBox
119 public:
120 VclVBox(vcl::Window *pParent, bool bHomogeneous = false, int nSpacing = 0)
121 : VclBox(pParent, bHomogeneous, nSpacing)
123 m_bVerticalContainer = true;
125 protected:
126 virtual long getPrimaryDimension(const Size &rSize) const override
128 return rSize.getHeight();
130 virtual void setPrimaryDimension(Size &rSize, long nHeight) const override
132 rSize.setHeight(nHeight);
134 virtual long getPrimaryCoordinate(const Point &rPos) const override
136 return rPos.getY();
138 virtual void setPrimaryCoordinate(Point &rPos, long nPos) const override
140 rPos.setY(nPos);
142 virtual long getSecondaryDimension(const Size &rSize) const override
144 return rSize.getWidth();
146 virtual void setSecondaryDimension(Size &rSize, long nWidth) const override
148 rSize.setWidth(nWidth);
150 virtual bool getPrimaryDimensionChildExpand(const vcl::Window &rWindow) const override
152 return rWindow.get_expand() || rWindow.get_vexpand();
156 class VCL_DLLPUBLIC VclHBox : public VclBox
158 public:
159 VclHBox(vcl::Window *pParent, bool bHomogeneous = false, int nSpacing = 0)
160 : VclBox(pParent, bHomogeneous, nSpacing)
162 m_bVerticalContainer = false;
164 protected:
165 virtual long getPrimaryDimension(const Size &rSize) const override
167 return rSize.getWidth();
169 virtual void setPrimaryDimension(Size &rSize, long nWidth) const override
171 rSize.setWidth(nWidth);
173 virtual long getPrimaryCoordinate(const Point &rPos) const override
175 return rPos.getX();
177 virtual void setPrimaryCoordinate(Point &rPos, long nPos) const override
179 rPos.setX(nPos);
181 virtual long getSecondaryDimension(const Size &rSize) const override
183 return rSize.getHeight();
185 virtual void setSecondaryDimension(Size &rSize, long nHeight) const override
187 rSize.setHeight(nHeight);
189 virtual bool getPrimaryDimensionChildExpand(const vcl::Window &rWindow) const override
191 return rWindow.get_expand() || rWindow.get_hexpand();
195 enum class VclButtonBoxStyle
197 Default,
198 Spread,
199 Edge,
200 Start,
201 End,
202 Center
205 class VCL_DLLPUBLIC VclButtonBox : public VclBox
207 public:
208 VclButtonBox(vcl::Window *pParent)
209 : VclBox(pParent, false, Application::GetSettings().GetStyleSettings().GetDialogStyle().button_spacing)
210 , m_eLayoutStyle(VclButtonBoxStyle::Default)
213 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
214 void sort_native_button_order();
215 protected:
216 virtual Size calculateRequisition() const override;
217 virtual void setAllocation(const Size &rAllocation) override;
218 Size addSpacing(const Size &rSize, sal_uInt16 nVisibleChildren) const;
219 private:
220 VclButtonBoxStyle m_eLayoutStyle;
221 struct Requisition
223 std::vector<long> m_aMainGroupDimensions;
224 std::vector<long> m_aSubGroupDimensions;
225 Size m_aMainGroupSize;
226 Size m_aSubGroupSize;
228 Requisition calculatePrimarySecondaryRequisitions() const;
229 Size addReqGroups(const VclButtonBox::Requisition &rReq) const;
232 class VCL_DLLPUBLIC VclVButtonBox : public VclButtonBox
234 public:
235 VclVButtonBox(vcl::Window *pParent)
236 : VclButtonBox(pParent)
238 m_bVerticalContainer = true;
240 protected:
241 virtual long getPrimaryDimension(const Size &rSize) const override
243 return rSize.getHeight();
245 virtual void setPrimaryDimension(Size &rSize, long nHeight) const override
247 rSize.setHeight(nHeight);
249 virtual long getPrimaryCoordinate(const Point &rPos) const override
251 return rPos.getY();
253 virtual void setPrimaryCoordinate(Point &rPos, long nPos) const override
255 rPos.setY(nPos);
257 virtual long getSecondaryDimension(const Size &rSize) const override
259 return rSize.getWidth();
261 virtual void setSecondaryDimension(Size &rSize, long nWidth) const override
263 rSize.setWidth(nWidth);
265 virtual bool getPrimaryDimensionChildExpand(const vcl::Window &rWindow) const override
267 return rWindow.get_expand() || rWindow.get_vexpand();
271 class VCL_DLLPUBLIC VclHButtonBox final : public VclButtonBox
273 public:
274 VclHButtonBox(vcl::Window *pParent)
275 : VclButtonBox(pParent)
277 m_bVerticalContainer = false;
279 private:
280 virtual long getPrimaryDimension(const Size &rSize) const override
282 return rSize.getWidth();
284 virtual void setPrimaryDimension(Size &rSize, long nWidth) const override
286 rSize.setWidth(nWidth);
288 virtual long getPrimaryCoordinate(const Point &rPos) const override
290 return rPos.getX();
292 virtual void setPrimaryCoordinate(Point &rPos, long nPos) const override
294 rPos.setX(nPos);
296 virtual long getSecondaryDimension(const Size &rSize) const override
298 return rSize.getHeight();
300 virtual void setSecondaryDimension(Size &rSize, long nHeight) const override
302 rSize.setHeight(nHeight);
304 virtual bool getPrimaryDimensionChildExpand(const vcl::Window &rWindow) const override
306 return rWindow.get_expand() || rWindow.get_hexpand();
310 class VCL_DLLPUBLIC VclGrid final : public VclContainer
312 private:
313 bool m_bRowHomogeneous;
314 bool m_bColumnHomogeneous;
315 int m_nRowSpacing;
316 int m_nColumnSpacing;
318 public:
319 struct Value
321 long m_nValue;
322 bool m_bExpand;
323 Value() : m_nValue(0), m_bExpand(false) {}
325 private:
327 Size calculateRequisitionForSpacings(sal_Int32 nRowSpacing, sal_Int32 nColSpacing) const;
328 virtual Size calculateRequisition() const override;
329 virtual void setAllocation(const Size &rAllocation) override;
330 virtual boost::property_tree::ptree DumpAsPropertyTree() override;
331 public:
332 VclGrid(vcl::Window *pParent)
333 : VclContainer(pParent)
334 , m_bRowHomogeneous(false), m_bColumnHomogeneous(false)
335 , m_nRowSpacing(0), m_nColumnSpacing(0)
338 bool get_row_homogeneous() const
340 return m_bRowHomogeneous;
342 bool get_column_homogeneous() const
344 return m_bColumnHomogeneous;
346 void set_row_spacing(int nSpacing)
348 m_nRowSpacing = nSpacing;
350 void set_column_spacing(int nSpacing)
352 m_nColumnSpacing = nSpacing;
354 int get_row_spacing() const
356 return m_nRowSpacing;
358 int get_column_spacing() const
360 return m_nColumnSpacing;
362 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
365 class VCL_DLLPUBLIC VclBin : public VclContainer
367 public:
368 VclBin(vcl::Window *pParent, WinBits nStyle = WB_HIDE | WB_CLIPCHILDREN)
369 : VclContainer(pParent, nStyle)
372 virtual vcl::Window *get_child();
373 virtual const vcl::Window *get_child() const;
374 virtual Size calculateRequisition() const override;
375 virtual void setAllocation(const Size &rAllocation) override;
378 class VCL_DLLPUBLIC VclPaned : public VclContainer
380 protected:
381 VclPtr<Splitter> m_pSplitter;
382 long m_nPosition;
384 VclPaned(vcl::Window *pParent, bool bVertical);
385 public:
386 virtual ~VclPaned() override { disposeOnce(); }
387 virtual void dispose() override;
388 long get_position() const { return m_nPosition; }
389 void set_position(long nPosition) { m_nPosition = nPosition; }
392 class VCL_DLLPUBLIC VclVPaned final : public VclPaned
394 private:
395 DECL_LINK(SplitHdl, Splitter*, void);
396 void arrange(const Size& rAllocation, long nFirstHeight, long nSecondHeight);
398 public:
399 VclVPaned(vcl::Window *pParent);
400 virtual Size calculateRequisition() const override;
401 virtual void setAllocation(const Size &rAllocation) override;
404 class VCL_DLLPUBLIC VclHPaned final : public VclPaned
406 private:
407 DECL_LINK(SplitHdl, Splitter*, void);
408 void arrange(const Size& rAllocation, long nFirstHeight, long nSecondHeight);
410 public:
411 VclHPaned(vcl::Window *pParent);
412 virtual Size calculateRequisition() const override;
413 virtual void setAllocation(const Size &rAllocation) override;
416 class VCL_DLLPUBLIC VclFrame final : public VclBin
418 private:
419 VclPtr<vcl::Window> m_pLabel;
420 private:
421 friend class VclBuilder;
422 void designate_label(vcl::Window *pWindow);
423 DECL_LINK(WindowEventListener, VclWindowEvent&, void);
424 public:
425 VclFrame(vcl::Window *pParent)
426 : VclBin(pParent)
427 , m_pLabel(nullptr)
430 virtual ~VclFrame() override;
431 virtual void dispose() override;
432 void set_label(const OUString &rLabel);
433 OUString get_label() const;
434 virtual vcl::Window *get_child() override;
435 virtual const vcl::Window *get_child() const override;
436 vcl::Window *get_label_widget();
437 const vcl::Window *get_label_widget() const;
438 virtual boost::property_tree::ptree DumpAsPropertyTree() override;
439 private:
440 virtual Size calculateRequisition() const override;
441 virtual void setAllocation(const Size &rAllocation) override;
442 virtual OUString getDefaultAccessibleName() const override;
445 class VCL_DLLPUBLIC VclAlignment final : public VclBin
447 public:
448 VclAlignment(vcl::Window *pParent)
449 : VclBin(pParent)
450 , m_nBottomPadding(0)
451 , m_nLeftPadding(0)
452 , m_nRightPadding(0)
453 , m_nTopPadding(0)
456 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
457 private:
458 virtual Size calculateRequisition() const override;
459 virtual void setAllocation(const Size &rAllocation) override;
460 sal_Int32 m_nBottomPadding;
461 sal_Int32 m_nLeftPadding;
462 sal_Int32 m_nRightPadding;
463 sal_Int32 m_nTopPadding;
466 class VCL_DLLPUBLIC VclExpander final : public VclBin
468 public:
469 VclExpander(vcl::Window *pParent)
470 : VclBin(pParent)
471 , m_bResizeTopLevel(true)
472 , m_pDisclosureButton(VclPtr<DisclosureButton>::Create(this))
474 m_pDisclosureButton->SetToggleHdl(LINK(this, VclExpander, ClickHdl));
475 m_pDisclosureButton->Show();
477 virtual ~VclExpander() override { disposeOnce(); }
478 virtual void dispose() override;
479 virtual vcl::Window *get_child() override;
480 virtual const vcl::Window *get_child() const override;
481 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
482 bool get_expanded() const
484 return m_pDisclosureButton->IsChecked();
486 void set_expanded(bool bExpanded)
488 m_pDisclosureButton->Check(bExpanded);
490 void set_label(const OUString& rLabel)
492 m_pDisclosureButton->SetText(rLabel);
494 virtual void StateChanged(StateChangedType nType) override;
495 void SetExpandedHdl( const Link<VclExpander&,void>& rLink ) { maExpandedHdl = rLink; }
496 private:
497 virtual Size calculateRequisition() const override;
498 virtual void setAllocation(const Size &rAllocation) override;
499 bool m_bResizeTopLevel;
500 VclPtr<DisclosureButton> m_pDisclosureButton;
501 Link<VclExpander&,void> maExpandedHdl;
502 DECL_DLLPRIVATE_LINK(ClickHdl, CheckBox&, void);
505 class VCL_DLLPUBLIC VclScrolledWindow final : public VclBin
507 public:
508 VclScrolledWindow(vcl::Window *pParent );
509 virtual ~VclScrolledWindow() override { disposeOnce(); }
510 virtual void dispose() override;
511 virtual vcl::Window *get_child() override;
512 virtual const vcl::Window *get_child() const override;
513 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
514 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
515 ScrollBar& getVertScrollBar() { return *m_pVScroll; }
516 ScrollBar& getHorzScrollBar() { return *m_pHScroll; }
517 Size getVisibleChildSize() const;
518 //set to true to disable the built-in scrolling callbacks to allow the user
519 //to override it
520 void setUserManagedScrolling(bool bUserManagedScrolling) { m_bUserManagedScrolling = bUserManagedScrolling;}
521 void doSetAllocation(const Size &rAllocation, bool bRetryOnFailure);
522 private:
523 virtual Size calculateRequisition() const override;
524 virtual void setAllocation(const Size &rAllocation) override;
525 DECL_LINK(ScrollBarHdl, ScrollBar*, void);
526 void InitScrollBars(const Size &rRequest);
527 virtual bool EventNotify(NotifyEvent& rNEvt) override;
528 bool m_bUserManagedScrolling;
529 VclPtr<ScrollBar> m_pVScroll;
530 VclPtr<ScrollBar> m_pHScroll;
531 VclPtr<ScrollBarBox> m_aScrollBarBox;
534 class VCL_DLLPUBLIC VclViewport final : public VclBin
536 public:
537 VclViewport(vcl::Window *pParent)
538 : VclBin(pParent, WB_HIDE | WB_CLIPCHILDREN)
539 , m_bInitialAllocation(true)
542 private:
543 virtual void setAllocation(const Size &rAllocation) override;
544 bool m_bInitialAllocation;
547 //Enforces that its children are always the same size as itself.
548 //Intercepts any Commands intended for its children.
550 //by default the Commands are discarded, inherit from this
551 //and implement "Command" to get them
552 class VCL_DLLPUBLIC VclEventBox final : public VclBin
554 private:
555 //Any Commands an EventBoxHelper receives are forwarded to its parent
556 //The VclEventBox ensures that m_aEventBoxHelper is the
557 //first child and is transparent, but covers the rest of the children
558 class EventBoxHelper : public vcl::Window
560 public:
561 EventBoxHelper(vcl::Window* pParent)
562 : Window(pParent, 0)
564 SetSizePixel(pParent->GetSizePixel());
565 EnableChildTransparentMode();
566 SetPaintTransparent(true);
567 SetBackground();
569 virtual void Command(const CommandEvent& rCEvt) override
571 GetParent()->Command(rCEvt);
575 VclPtr<EventBoxHelper> m_aEventBoxHelper;
576 virtual void dispose() override;
577 virtual ~VclEventBox() override;
578 public:
579 VclEventBox(vcl::Window* pParent)
580 : VclBin(pParent)
581 , m_aEventBoxHelper(VclPtr<EventBoxHelper>::Create(this))
583 m_aEventBoxHelper->Show();
585 virtual vcl::Window *get_child() override;
586 virtual const vcl::Window *get_child() const override;
587 virtual Size calculateRequisition() const override;
588 virtual void setAllocation(const Size &rAllocation) override;
590 virtual void Command(const CommandEvent& rCEvt) override;
593 class VCL_DLLPUBLIC VclSizeGroup
595 private:
596 std::set< VclPtr<vcl::Window> > m_aWindows;
597 bool m_bIgnoreHidden;
598 VclSizeGroupMode m_eMode;
600 void trigger_queue_resize();
601 public:
602 VclSizeGroup()
603 : m_bIgnoreHidden(false)
604 , m_eMode(VclSizeGroupMode::Horizontal)
607 void insert(vcl::Window *pWindow)
609 m_aWindows.insert(VclPtr<vcl::Window>(pWindow));
611 void erase(vcl::Window *pWindow)
613 m_aWindows.erase(VclPtr<vcl::Window>(pWindow));
615 const std::set< VclPtr<vcl::Window> >& get_widgets() const
617 return m_aWindows;
619 std::set< VclPtr<vcl::Window> >& get_widgets()
621 return m_aWindows;
623 void set_ignore_hidden(bool bIgnoreHidden);
624 bool get_ignore_hidden() const
626 return m_bIgnoreHidden;
628 void set_mode(VclSizeGroupMode eMode);
629 VclSizeGroupMode get_mode() const
631 return m_eMode;
633 void set_property(const OString &rKey, const OUString &rValue);
636 class VCL_DLLPUBLIC VclDrawingArea final : public Control
638 private:
639 FactoryFunction m_pFactoryFunction;
640 void* m_pUserData;
641 Link<std::pair<vcl::RenderContext&, const tools::Rectangle&>, void> m_aPaintHdl;
642 Link<const Size&, void> m_aResizeHdl;
643 Link<const MouseEvent&, bool> m_aMousePressHdl;
644 Link<const MouseEvent&, bool> m_aMouseMotionHdl;
645 Link<const MouseEvent&, bool> m_aMouseReleaseHdl;
646 Link<const KeyEvent&, bool> m_aKeyPressHdl;
647 Link<const KeyEvent&, bool> m_aKeyReleaseHdl;
648 Link<VclDrawingArea&, void> m_aStyleUpdatedHdl;
649 Link<const CommandEvent&, bool> m_aCommandHdl;
650 Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;
652 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override
654 m_aPaintHdl.Call(std::pair<vcl::RenderContext&, const tools::Rectangle&>(rRenderContext, rRect));
656 virtual void Resize() override
658 m_aResizeHdl.Call(GetOutputSizePixel());
660 virtual void MouseMove(const MouseEvent& rMEvt) override
662 if (!m_aMouseMotionHdl.Call(rMEvt))
663 Control::MouseMove(rMEvt);
665 virtual void KeyInput(const KeyEvent& rKEvt) override
667 if (!m_aKeyPressHdl.Call(rKEvt))
668 Control::KeyInput(rKEvt);
671 virtual void KeyUp(const KeyEvent& rKEvt) override
673 if (!m_aKeyReleaseHdl.Call(rKEvt))
674 Control::KeyUp(rKEvt);
676 virtual void StateChanged(StateChangedType nType) override
678 Control::StateChanged(nType);
679 if (nType == StateChangedType::ControlForeground || nType == StateChangedType::ControlBackground)
681 m_aStyleUpdatedHdl.Call(*this);
682 Invalidate();
685 virtual void DataChanged(const DataChangedEvent& rDCEvt) override
687 Control::DataChanged(rDCEvt);
688 if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
690 m_aStyleUpdatedHdl.Call(*this);
691 Invalidate();
694 virtual void Command(const CommandEvent& rEvent) override
696 if (m_aCommandHdl.Call(rEvent))
697 return;
698 Control::Command(rEvent);
700 virtual void RequestHelp(const HelpEvent& rHelpEvent) override
702 if (rHelpEvent.GetMode() & (HelpEventMode::QUICK | HelpEventMode::BALLOON))
704 Point aPos(ScreenToOutputPixel(rHelpEvent.GetMousePosPixel()));
705 tools::Rectangle aHelpArea(aPos.X(), aPos.Y());
706 OUString sHelpTip = m_aQueryTooltipHdl.Call(aHelpArea);
707 if (sHelpTip.isEmpty())
708 return;
709 Point aPt = OutputToScreenPixel(aHelpArea.TopLeft());
710 aHelpArea.SetLeft(aPt.X());
711 aHelpArea.SetTop(aPt.Y());
712 aPt = OutputToScreenPixel(aHelpArea.BottomRight());
713 aHelpArea.SetRight(aPt.X());
714 aHelpArea.SetBottom(aPt.Y());
715 // tdf#125369 recover newline support of tdf#101779
716 QuickHelpFlags eHelpWinStyle = sHelpTip.indexOf('\n') != -1 ? QuickHelpFlags::TipStyleBalloon : QuickHelpFlags::NONE;
717 Help::ShowQuickHelp(this, aHelpArea, sHelpTip, eHelpWinStyle);
720 virtual FactoryFunction GetUITestFactory() const override
722 if (m_pFactoryFunction)
723 return m_pFactoryFunction;
724 return Control::GetUITestFactory();
727 public:
728 VclDrawingArea(vcl::Window *pParent, WinBits nStyle)
729 : Control(pParent, nStyle)
730 , m_pFactoryFunction(nullptr)
731 , m_pUserData(nullptr)
733 SetBackground();
735 virtual void MouseButtonDown(const MouseEvent& rMEvt) override
737 if (!m_aMousePressHdl.Call(rMEvt))
738 Control::MouseButtonDown(rMEvt);
740 virtual void MouseButtonUp(const MouseEvent& rMEvt) override
742 if (!m_aMouseReleaseHdl.Call(rMEvt))
743 Control::MouseButtonUp(rMEvt);
745 void SetUITestFactory(FactoryFunction pFactoryFunction, void* pUserData)
747 m_pFactoryFunction = pFactoryFunction;
748 m_pUserData = pUserData;
750 void* GetUserData() const
752 return m_pUserData;
754 void SetPaintHdl(const Link<std::pair<vcl::RenderContext&, const tools::Rectangle&>, void>& rLink)
756 m_aPaintHdl = rLink;
758 void SetResizeHdl(const Link<const Size&, void>& rLink)
760 m_aResizeHdl = rLink;
762 void SetMousePressHdl(const Link<const MouseEvent&, bool>& rLink)
764 m_aMousePressHdl = rLink;
766 void SetMouseMoveHdl(const Link<const MouseEvent&, bool>& rLink)
768 m_aMouseMotionHdl = rLink;
770 void SetMouseReleaseHdl(const Link<const MouseEvent&, bool>& rLink)
772 m_aMouseReleaseHdl = rLink;
774 void SetKeyPressHdl(const Link<const KeyEvent&, bool>& rLink)
776 m_aKeyPressHdl = rLink;
778 void SetKeyReleaseHdl(const Link<const KeyEvent&, bool>& rLink)
780 m_aKeyReleaseHdl = rLink;
782 void SetStyleUpdatedHdl(const Link<VclDrawingArea&, void>& rLink)
784 m_aStyleUpdatedHdl = rLink;
786 void SetCommandHdl(const Link<const CommandEvent&, bool>& rLink)
788 m_aCommandHdl = rLink;
790 void SetQueryTooltipHdl(const Link<tools::Rectangle&, OUString>& rLink)
792 m_aQueryTooltipHdl = rLink;
794 boost::property_tree::ptree DumpAsPropertyTree() override
796 boost::property_tree::ptree aTree(Control::DumpAsPropertyTree());
797 aTree.put("type", "drawingarea");
798 ScopedVclPtrInstance<VirtualDevice> pDevice;
799 pDevice->SetOutputSize( GetSizePixel() );
800 tools::Rectangle aRect(Point(0,0), GetSizePixel());
801 Paint(*pDevice, aRect);
802 BitmapEx aImage = pDevice->GetBitmapEx( Point(0,0), GetSizePixel() );
803 SvMemoryStream aOStm(65535, 65535);
805 if(GraphicConverter::Export(aOStm, aImage, ConvertDataFormat::PNG) == ERRCODE_NONE)
807 css::uno::Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aOStm.GetData()), aOStm.Tell());
808 OUStringBuffer aBuffer("data:image/png;base64,");
809 ::comphelper::Base64::encode(aBuffer, aSeq);
810 aTree.put("image", aBuffer.makeStringAndClear());
812 aTree.put("text", GetQuickHelpText());
813 return aTree;
817 //Get first window of a pTopLevel window as
818 //if any intermediate layout widgets didn't exist
819 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::FirstChild);
820 //in a flat hierarchy where dialogs only have one layer
821 //of children
822 vcl::Window* firstLogicalChildOfParent(const vcl::Window *pTopLevel);
824 //Get last window of a pTopLevel window as
825 //if any intermediate layout widgets didn't exist
826 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::LastChild);
827 //in a flat hierarchy where dialogs only have one layer
828 //of children
829 vcl::Window* lastLogicalChildOfParent(const vcl::Window *pTopLevel);
831 //Get next window after pChild of a pTopLevel window as
832 //if any intermediate layout widgets didn't exist
833 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::Next);
834 //in a flat hierarchy where dialogs only have one layer
835 //of children
836 vcl::Window* nextLogicalChildOfParent(const vcl::Window *pTopLevel, const vcl::Window *pChild);
838 //Get previous window before pChild of a pTopLevel window as
839 //if any intermediate layout widgets didn't exist
840 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::Prev);
841 //in a flat hierarchy where dialogs only have one layer
842 //of children
843 vcl::Window* prevLogicalChildOfParent(const vcl::Window *pTopLevel, const vcl::Window *pChild);
845 //Returns true is the Window has a single child which is a container
846 VCL_DLLPUBLIC bool isLayoutEnabled(const vcl::Window *pWindow);
848 inline bool isContainerWindow(const vcl::Window &rWindow)
850 WindowType eType = rWindow.GetType();
851 return eType == WindowType::CONTAINER || eType == WindowType::SCROLLWINDOW ||
852 (eType == WindowType::DOCKINGWINDOW && ::isLayoutEnabled(&rWindow));
855 inline bool isContainerWindow(const vcl::Window *pWindow)
857 return pWindow && isContainerWindow(*pWindow);
860 // retro-fitting utilities
862 //Get a Size which is large enough to contain all children with
863 //an equal amount of space at top left and bottom right
864 Size getLegacyBestSizeForChildren(const vcl::Window &rWindow);
866 //Get first parent which is not a layout widget
867 vcl::Window* getNonLayoutParent(vcl::Window *pParent);
869 #endif
871 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */