1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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/dialog.hxx>
16 #include <vcl/fixed.hxx>
17 #include <vcl/scrbar.hxx>
18 #include <vcl/split.hxx>
19 #include <vcl/vclmedit.hxx>
20 #include <vcl/window.hxx>
21 #include <vcl/vclptr.hxx>
22 #include <vcl/IContext.hxx>
25 class VCL_DLLPUBLIC VclContainer
: public vcl::Window
,
29 VclContainer(vcl::Window
*pParent
, WinBits nStyle
= WB_HIDE
| WB_CLIPCHILDREN
);
31 //These take into account the external margins of the rWindow widget
32 //while GetOptimalSize/get_preferred_size and SetPosSizePixel are
34 static Size
getLayoutRequisition(const vcl::Window
&rWindow
);
35 static void setLayoutPosSize(vcl::Window
&rWindow
, const Point
&rPos
, const Size
&rSize
);
37 //applies the allocation pos and size onto rWindow via setLayoutPosSize taking into account
38 //the rWindows alignment desires within that allocation
39 static void setLayoutAllocation(vcl::Window
&rWindow
, const Point
&rPos
, const Size
&rSize
);
41 virtual void queue_resize(StateChangedType eReason
= StateChangedType::Layout
) override
;
43 //these are the two that need to be implemented by
44 //containers, figure out how much space you want...
45 virtual Size
calculateRequisition() const = 0;
46 //..and decide what to do when set to this size
47 virtual void setAllocation(const Size
&rAllocation
) = 0;
49 virtual sal_uInt16
getDefaultAccessibleRole() const override
;
51 // evtl. support for screenshot context menu
52 virtual void Command(const CommandEvent
& rCEvt
) override
;
55 //you don't want to override these
56 virtual Size
GetOptimalSize() const override
;
57 virtual void SetPosSizePixel(const Point
& rNewPos
, const Size
& rNewSize
) override
;
58 virtual void SetPosPixel(const Point
& rAllocPos
) override
;
59 virtual void SetSizePixel(const Size
& rAllocation
) override
;
64 class VCL_DLLPUBLIC VclBox
: public VclContainer
68 bool m_bVerticalContainer
;
71 VclBox(vcl::Window
*pParent
, bool bHomogeneous
, int nSpacing
)
72 : VclContainer(pParent
)
73 , m_bHomogeneous(bHomogeneous
)
74 , m_bVerticalContainer(false)
75 , m_nSpacing(nSpacing
)
78 void set_spacing(int nSpacing
)
80 m_nSpacing
= nSpacing
;
82 int get_spacing() const
86 void set_homogeneous(bool bHomogeneous
)
88 m_bHomogeneous
= bHomogeneous
;
90 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
92 virtual sal_uInt16
getDefaultAccessibleRole() const override
;
93 void accumulateMaxes(const Size
&rChildSize
, Size
&rSize
) const;
94 Size
finalizeMaxes(const Size
&rSize
, sal_uInt16 nVisibleChildren
) const;
96 virtual Size
calculateRequisition() const override
;
97 virtual void setAllocation(const Size
&rAllocation
) override
;
99 virtual long getPrimaryDimension(const Size
&rSize
) const = 0;
100 virtual void setPrimaryDimension(Size
&rSize
, long) const = 0;
101 virtual long getPrimaryCoordinate(const Point
&rPos
) const = 0;
102 virtual void setPrimaryCoordinate(Point
&rPos
, long) const = 0;
103 virtual long getSecondaryDimension(const Size
&rSize
) const = 0;
104 virtual void setSecondaryDimension(Size
&rSize
, long) const = 0;
106 virtual bool getPrimaryDimensionChildExpand(const vcl::Window
&rWindow
) const = 0;
109 class VCL_DLLPUBLIC VclVBox
: public VclBox
112 VclVBox(vcl::Window
*pParent
, bool bHomogeneous
= false, int nSpacing
= 0)
113 : VclBox(pParent
, bHomogeneous
, nSpacing
)
115 m_bVerticalContainer
= true;
118 virtual long getPrimaryDimension(const Size
&rSize
) const override
120 return rSize
.getHeight();
122 virtual void setPrimaryDimension(Size
&rSize
, long nHeight
) const override
124 rSize
.setHeight(nHeight
);
126 virtual long getPrimaryCoordinate(const Point
&rPos
) const override
130 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const override
134 virtual long getSecondaryDimension(const Size
&rSize
) const override
136 return rSize
.getWidth();
138 virtual void setSecondaryDimension(Size
&rSize
, long nWidth
) const override
140 rSize
.setWidth(nWidth
);
142 virtual bool getPrimaryDimensionChildExpand(const vcl::Window
&rWindow
) const override
144 return rWindow
.get_expand() || rWindow
.get_vexpand();
148 class VCL_DLLPUBLIC VclHBox
: public VclBox
151 VclHBox(vcl::Window
*pParent
, bool bHomogeneous
= false, int nSpacing
= 0)
152 : VclBox(pParent
, bHomogeneous
, nSpacing
)
154 m_bVerticalContainer
= false;
157 virtual long getPrimaryDimension(const Size
&rSize
) const override
159 return rSize
.getWidth();
161 virtual void setPrimaryDimension(Size
&rSize
, long nWidth
) const override
163 rSize
.setWidth(nWidth
);
165 virtual long getPrimaryCoordinate(const Point
&rPos
) const override
169 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const override
173 virtual long getSecondaryDimension(const Size
&rSize
) const override
175 return rSize
.getHeight();
177 virtual void setSecondaryDimension(Size
&rSize
, long nHeight
) const override
179 rSize
.setHeight(nHeight
);
181 virtual bool getPrimaryDimensionChildExpand(const vcl::Window
&rWindow
) const override
183 return rWindow
.get_expand() || rWindow
.get_hexpand();
187 enum class VclButtonBoxStyle
197 class VCL_DLLPUBLIC VclButtonBox
: public VclBox
200 VclButtonBox(vcl::Window
*pParent
)
201 : VclBox(pParent
, false, 0/*nSpacing*/)
202 , m_eLayoutStyle(VclButtonBoxStyle::Default
)
205 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
206 void sort_native_button_order();
208 virtual Size
calculateRequisition() const override
;
209 virtual void setAllocation(const Size
&rAllocation
) override
;
210 Size
addSpacing(const Size
&rSize
, sal_uInt16 nVisibleChildren
) const;
212 VclButtonBoxStyle m_eLayoutStyle
;
215 std::vector
<long> m_aMainGroupDimensions
;
216 std::vector
<long> m_aSubGroupDimensions
;
217 Size m_aMainGroupSize
;
218 Size m_aSubGroupSize
;
220 Requisition
calculatePrimarySecondaryRequisitions() const;
221 Size
addReqGroups(const VclButtonBox::Requisition
&rReq
) const;
224 class VCL_DLLPUBLIC VclVButtonBox
: public VclButtonBox
227 VclVButtonBox(vcl::Window
*pParent
)
228 : VclButtonBox(pParent
)
230 m_bVerticalContainer
= true;
233 virtual long getPrimaryDimension(const Size
&rSize
) const override
235 return rSize
.getHeight();
237 virtual void setPrimaryDimension(Size
&rSize
, long nHeight
) const override
239 rSize
.setHeight(nHeight
);
241 virtual long getPrimaryCoordinate(const Point
&rPos
) const override
245 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const override
249 virtual long getSecondaryDimension(const Size
&rSize
) const override
251 return rSize
.getWidth();
253 virtual void setSecondaryDimension(Size
&rSize
, long nWidth
) const override
255 rSize
.setWidth(nWidth
);
257 virtual bool getPrimaryDimensionChildExpand(const vcl::Window
&rWindow
) const override
259 return rWindow
.get_expand() || rWindow
.get_vexpand();
263 class VCL_DLLPUBLIC VclHButtonBox
: public VclButtonBox
266 VclHButtonBox(vcl::Window
*pParent
)
267 : VclButtonBox(pParent
)
269 m_bVerticalContainer
= false;
272 virtual long getPrimaryDimension(const Size
&rSize
) const override
274 return rSize
.getWidth();
276 virtual void setPrimaryDimension(Size
&rSize
, long nWidth
) const override
278 rSize
.setWidth(nWidth
);
280 virtual long getPrimaryCoordinate(const Point
&rPos
) const override
284 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const override
288 virtual long getSecondaryDimension(const Size
&rSize
) const override
290 return rSize
.getHeight();
292 virtual void setSecondaryDimension(Size
&rSize
, long nHeight
) const override
294 rSize
.setHeight(nHeight
);
296 virtual bool getPrimaryDimensionChildExpand(const vcl::Window
&rWindow
) const override
298 return rWindow
.get_expand() || rWindow
.get_hexpand();
302 class VCL_DLLPUBLIC VclGrid
: public VclContainer
305 bool m_bRowHomogeneous
;
306 bool m_bColumnHomogeneous
;
308 int m_nColumnSpacing
;
315 Value() : m_nValue(0), m_bExpand(false) {}
319 Size
calculateRequisitionForSpacings(sal_Int32 nRowSpacing
, sal_Int32 nColSpacing
) const;
320 virtual Size
calculateRequisition() const override
;
321 virtual void setAllocation(const Size
&rAllocation
) override
;
323 VclGrid(vcl::Window
*pParent
)
324 : VclContainer(pParent
)
325 , m_bRowHomogeneous(false), m_bColumnHomogeneous(false)
326 , m_nRowSpacing(0), m_nColumnSpacing(0)
329 bool get_row_homogeneous() const
331 return m_bRowHomogeneous
;
333 bool get_column_homogeneous() const
335 return m_bColumnHomogeneous
;
337 void set_row_spacing(int nSpacing
)
339 m_nRowSpacing
= nSpacing
;
341 void set_column_spacing(int nSpacing
)
343 m_nColumnSpacing
= nSpacing
;
345 int get_row_spacing() const
347 return m_nRowSpacing
;
349 int get_column_spacing() const
351 return m_nColumnSpacing
;
353 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
356 class VCL_DLLPUBLIC VclBin
: public VclContainer
359 VclBin(vcl::Window
*pParent
, WinBits nStyle
= WB_HIDE
| WB_CLIPCHILDREN
)
360 : VclContainer(pParent
, nStyle
)
363 virtual vcl::Window
*get_child();
364 virtual const vcl::Window
*get_child() const;
365 virtual Size
calculateRequisition() const override
;
366 virtual void setAllocation(const Size
&rAllocation
) override
;
369 class VCL_DLLPUBLIC VclVPaned
: public VclContainer
372 VclPtr
<Splitter
> m_pSplitter
;
374 DECL_LINK(SplitHdl
, Splitter
*, void);
375 void arrange(const Size
& rAllocation
, long nFirstHeight
, long nSecondHeight
);
377 VclVPaned(vcl::Window
*pParent
);
378 virtual ~VclVPaned() override
{ disposeOnce(); }
379 virtual void dispose() override
;
380 virtual Size
calculateRequisition() const override
;
381 virtual void setAllocation(const Size
&rAllocation
) override
;
382 long get_position() const { return m_nPosition
; }
383 void set_position(long nPosition
) { m_nPosition
= nPosition
; }
386 class VCL_DLLPUBLIC VclFrame
: public VclBin
389 VclPtr
<vcl::Window
> m_pLabel
;
391 friend class VclBuilder
;
392 void designate_label(vcl::Window
*pWindow
);
393 DECL_LINK(WindowEventListener
, VclWindowEvent
&, void);
395 VclFrame(vcl::Window
*pParent
)
400 virtual ~VclFrame() override
;
401 virtual void dispose() override
;
402 void set_label(const OUString
&rLabel
);
403 OUString
get_label() const;
404 virtual vcl::Window
*get_child() override
;
405 virtual const vcl::Window
*get_child() const override
;
406 vcl::Window
*get_label_widget();
407 const vcl::Window
*get_label_widget() const;
409 virtual Size
calculateRequisition() const override
;
410 virtual void setAllocation(const Size
&rAllocation
) override
;
411 virtual OUString
getDefaultAccessibleName() const override
;
414 class VCL_DLLPUBLIC VclAlignment
: public VclBin
417 VclAlignment(vcl::Window
*pParent
)
419 , m_nBottomPadding(0)
429 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
431 virtual Size
calculateRequisition() const override
;
432 virtual void setAllocation(const Size
&rAllocation
) override
;
434 sal_Int32 m_nBottomPadding
;
435 sal_Int32 m_nLeftPadding
;
436 sal_Int32 m_nRightPadding
;
437 sal_Int32 m_nTopPadding
;
444 class VCL_DLLPUBLIC VclExpander
: public VclBin
447 VclExpander(vcl::Window
*pParent
)
449 , m_bResizeTopLevel(true)
450 , m_pDisclosureButton(VclPtr
<DisclosureButton
>::Create(this))
452 m_pDisclosureButton
->SetToggleHdl(LINK(this, VclExpander
, ClickHdl
));
453 m_pDisclosureButton
->Show();
455 virtual ~VclExpander() override
{ disposeOnce(); }
456 virtual void dispose() override
;
457 virtual vcl::Window
*get_child() override
;
458 virtual const vcl::Window
*get_child() const override
;
459 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
460 bool get_expanded() const
462 return m_pDisclosureButton
->IsChecked();
464 void set_expanded(bool bExpanded
)
466 m_pDisclosureButton
->Check(bExpanded
);
468 void set_label(const OUString
& rLabel
)
470 m_pDisclosureButton
->SetText(rLabel
);
472 virtual void StateChanged(StateChangedType nType
) override
;
473 void SetExpandedHdl( const Link
<VclExpander
&,void>& rLink
) { maExpandedHdl
= rLink
; }
475 virtual Size
calculateRequisition() const override
;
476 virtual void setAllocation(const Size
&rAllocation
) override
;
478 bool m_bResizeTopLevel
;
479 VclPtr
<DisclosureButton
> m_pDisclosureButton
;
480 Link
<VclExpander
&,void> maExpandedHdl
;
481 DECL_DLLPRIVATE_LINK(ClickHdl
, CheckBox
&, void);
484 class VCL_DLLPUBLIC VclScrolledWindow
: public VclBin
487 VclScrolledWindow(vcl::Window
*pParent
);
488 virtual ~VclScrolledWindow() override
{ disposeOnce(); }
489 virtual void dispose() override
;
490 virtual vcl::Window
*get_child() override
;
491 virtual const vcl::Window
*get_child() const override
;
492 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
493 ScrollBar
& getVertScrollBar() { return *m_pVScroll
; }
494 ScrollBar
& getHorzScrollBar() { return *m_pHScroll
; }
495 Size
getVisibleChildSize() const;
496 //set to true to disable the built-in scrolling callbacks to allow the user
498 void setUserManagedScrolling(bool bUserManagedScrolling
) { m_bUserManagedScrolling
= bUserManagedScrolling
;}
500 virtual Size
calculateRequisition() const override
;
501 virtual void setAllocation(const Size
&rAllocation
) override
;
502 DECL_LINK(ScrollBarHdl
, ScrollBar
*, void);
503 void InitScrollBars(const Size
&rRequest
);
504 virtual bool EventNotify(NotifyEvent
& rNEvt
) override
;
506 bool m_bUserManagedScrolling
;
507 VclPtr
<ScrollBar
> m_pVScroll
;
508 VclPtr
<ScrollBar
> m_pHScroll
;
509 VclPtr
<ScrollBarBox
> m_aScrollBarBox
;
512 class VCL_DLLPUBLIC VclViewport
: public VclBin
515 VclViewport(vcl::Window
*pParent
)
516 : VclBin(pParent
, WB_HIDE
| WB_CLIPCHILDREN
)
520 virtual void setAllocation(const Size
&rAllocation
) override
;
523 //Enforces that its children are always the same size as itself.
524 //Intercepts any Commands intended for its children.
526 //by default the Commands are discarded, inherit from this
527 //and implement "Command" to get them
528 class VCL_DLLPUBLIC VclEventBox
: public VclBin
531 //Any Commands an EventBoxHelper receives are forwarded to its parent
532 //The VclEventBox ensures that m_aEventBoxHelper is the
533 //first child and is transparent, but covers the rest of the children
534 class EventBoxHelper
: public vcl::Window
537 EventBoxHelper(vcl::Window
* pParent
)
540 SetSizePixel(pParent
->GetSizePixel());
541 EnableChildTransparentMode();
542 SetPaintTransparent(true);
545 virtual void Command(const CommandEvent
& rCEvt
) override
547 GetParent()->Command(rCEvt
);
551 VclPtr
<EventBoxHelper
> m_aEventBoxHelper
;
553 virtual void dispose() override
;
554 virtual ~VclEventBox() override
;
556 VclEventBox(vcl::Window
* pParent
)
558 , m_aEventBoxHelper(VclPtr
<EventBoxHelper
>::Create(this))
560 m_aEventBoxHelper
->Show();
562 virtual vcl::Window
*get_child() override
;
563 virtual const vcl::Window
*get_child() const override
;
564 virtual Size
calculateRequisition() const override
;
565 virtual void setAllocation(const Size
&rAllocation
) override
;
567 virtual void Command(const CommandEvent
& rCEvt
) override
;
570 enum class VclSizeGroupMode
578 class VCL_DLLPUBLIC VclSizeGroup
581 std::set
< VclPtr
<vcl::Window
> > m_aWindows
;
582 bool m_bIgnoreHidden
;
583 VclSizeGroupMode m_eMode
;
585 void trigger_queue_resize();
588 : m_bIgnoreHidden(false)
589 , m_eMode(VclSizeGroupMode::Horizontal
)
592 void insert(vcl::Window
*pWindow
)
594 m_aWindows
.insert(VclPtr
<vcl::Window
>(pWindow
));
596 void erase(vcl::Window
*pWindow
)
598 m_aWindows
.erase(VclPtr
<vcl::Window
>(pWindow
));
600 const std::set
< VclPtr
<vcl::Window
> >& get_widgets() const
604 std::set
< VclPtr
<vcl::Window
> >& get_widgets()
608 void set_ignore_hidden(bool bIgnoreHidden
);
609 bool get_ignore_hidden() const
611 return m_bIgnoreHidden
;
613 void set_mode(VclSizeGroupMode eMode
);
614 VclSizeGroupMode
get_mode() const
618 bool set_property(const OString
&rKey
, const OUString
&rValue
);
621 enum class VclButtonsType
631 enum class VclMessageType
639 class VCL_DLLPUBLIC MessageDialog
: public Dialog
642 VclButtonsType m_eButtonsType
;
643 VclMessageType m_eMessageType
;
644 VclPtr
<VclBox
> m_pOwnedContentArea
;
645 VclPtr
<VclButtonBox
> m_pOwnedActionArea
;
646 VclPtr
<VclGrid
> m_pGrid
;
647 VclPtr
<FixedImage
> m_pImage
;
648 VclPtr
<VclMultiLineEdit
> m_pPrimaryMessage
;
649 VclPtr
<VclMultiLineEdit
> m_pSecondaryMessage
;
650 std::vector
<VclPtr
<PushButton
> > m_aOwnedButtons
;
651 std::map
< VclPtr
<const vcl::Window
>, short> m_aResponses
;
652 OUString m_sPrimaryString
;
653 OUString m_sSecondaryString
;
654 DECL_DLLPRIVATE_LINK(ButtonHdl
, Button
*, void);
655 void setButtonHandlers(VclButtonBox
*pButtonBox
);
656 short get_response(const vcl::Window
*pWindow
) const;
657 void create_owned_areas();
659 friend class VclPtr
<MessageDialog
>;
660 MessageDialog(vcl::Window
* pParent
, WinBits nStyle
);
663 MessageDialog(vcl::Window
* pParent
,
664 const OUString
&rMessage
,
665 VclMessageType eMessageType
= VclMessageType::Error
,
666 VclButtonsType eButtonsType
= VclButtonsType::Ok
);
667 MessageDialog(vcl::Window
* pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
);
668 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
669 virtual short Execute() override
;
670 ///Emitted when an action widget is clicked
671 virtual void response(short nResponseId
);
672 OUString
const & get_primary_text() const;
673 OUString
const & get_secondary_text() const;
674 void set_primary_text(const OUString
&rPrimaryString
);
675 void set_secondary_text(const OUString
&rSecondaryString
);
676 virtual ~MessageDialog() override
;
677 virtual void dispose() override
;
679 static void SetMessagesWidths(vcl::Window
*pParent
, VclMultiLineEdit
*pPrimaryMessage
,
680 VclMultiLineEdit
*pSecondaryMessage
);
683 VCL_DLLPUBLIC Size
bestmaxFrameSizeForScreenSize(const Size
&rScreenSize
);
685 //Get first window of a pTopLevel window as
686 //if any intermediate layout widgets didn't exist
687 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::FirstChild);
688 //in a flat hierarchy where dialogs only have one layer
690 VCL_DLLPUBLIC
vcl::Window
* firstLogicalChildOfParent(vcl::Window
*pTopLevel
);
692 //Get next window after pChild of a pTopLevel window as
693 //if any intermediate layout widgets didn't exist
694 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::Next);
695 //in a flat hierarchy where dialogs only have one layer
697 VCL_DLLPUBLIC
vcl::Window
* nextLogicalChildOfParent(vcl::Window
*pTopLevel
, vcl::Window
*pChild
);
699 //Get previous window before pChild of a pTopLevel window as
700 //if any intermediate layout widgets didn't exist
701 //i.e. acts like pChild = pChild->GetWindow(GetWindowType::Prev);
702 //in a flat hierarchy where dialogs only have one layer
704 VCL_DLLPUBLIC
vcl::Window
* prevLogicalChildOfParent(vcl::Window
*pTopLevel
, vcl::Window
*pChild
);
706 //Returns true is the Window has a single child which is a container
707 VCL_DLLPUBLIC
bool isLayoutEnabled(const vcl::Window
*pWindow
);
709 inline bool isContainerWindow(const vcl::Window
&rWindow
)
711 WindowType eType
= rWindow
.GetType();
712 return eType
== WindowType::CONTAINER
|| eType
== WindowType::SCROLLWINDOW
||
713 (eType
== WindowType::DOCKINGWINDOW
&& ::isLayoutEnabled(&rWindow
));
716 inline bool isContainerWindow(const vcl::Window
*pWindow
)
718 return pWindow
&& isContainerWindow(*pWindow
);
721 //Returns true if the containing dialog is doing its initial
722 //layout and isn't visible yet
723 VCL_DLLPUBLIC
bool isInitialLayout(const vcl::Window
*pWindow
);
725 // retro-fitting utilities
727 //Get a Size which is large enough to contain all children with
728 //an equal amount of space at top left and bottom right
729 Size
getLegacyBestSizeForChildren(const vcl::Window
&rWindow
);
731 //Get first parent which is not a layout widget
732 VCL_DLLPUBLIC
vcl::Window
* getNonLayoutParent(vcl::Window
*pParent
);
734 //return true if this window and its stack of containers are all shown
735 bool isVisibleInLayout(const vcl::Window
*pWindow
);
737 //return true if this window and its stack of containers are all enabled
738 bool isEnabledInLayout(const vcl::Window
*pWindow
);
742 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */