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 _VCLLAYOUT_HXX
11 #define _VCLLAYOUT_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/vclmedit.hxx>
19 #include <vcl/window.hxx>
20 #include <boost/multi_array.hpp>
23 class VCL_DLLPUBLIC VclContainer
: public Window
26 VclContainer(Window
*pParent
, WinBits nStyle
= WB_HIDE
);
28 //These take into account the external margins of the rWindow widget
29 //while GetOptimalSize/get_preferred_size and SetPosSizePixel are
31 static Size
getLayoutRequisition(const Window
&rWindow
);
32 static void setLayoutPosSize(Window
&rWindow
, const Point
&rPos
, const Size
&rSize
);
34 //applies the allocation pos and size onto rWindow via setLayoutPosSize taking into account
35 //the rWindows alignment desires within that allocation
36 static void setLayoutAllocation(Window
&rWindow
, const Point
&rPos
, const Size
&rSize
);
38 void markLayoutDirty()
40 m_bLayoutDirty
= true;
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;
51 //you don't want to override these
52 virtual Size
GetOptimalSize() const;
53 virtual void SetPosSizePixel(const Point
& rNewPos
, const Size
& rNewSize
);
54 virtual void SetPosPixel(const Point
& rAllocPos
);
55 virtual void SetSizePixel(const Size
& rAllocation
);
60 class VCL_DLLPUBLIC VclBox
: public VclContainer
64 bool m_bVerticalContainer
;
67 VclBox(Window
*pParent
, bool bHomogeneous
, int nSpacing
)
68 : VclContainer(pParent
)
69 , m_bHomogeneous(bHomogeneous
)
70 , m_nSpacing(nSpacing
)
73 void set_spacing(int nSpacing
)
75 m_nSpacing
= nSpacing
;
77 int get_spacing() const
81 void set_homogeneous(bool bHomogeneous
)
83 m_bHomogeneous
= bHomogeneous
;
85 bool get_homogeneous() const
87 return m_bHomogeneous
;
89 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
91 virtual sal_uInt16
getDefaultAccessibleRole() const;
92 void accumulateMaxes(const Size
&rChildSize
, Size
&rSize
) const;
93 Size
finalizeMaxes(const Size
&rSize
, sal_uInt16 nVisibleChildren
) const;
95 virtual Size
calculateRequisition() const;
96 virtual void setAllocation(const Size
&rAllocation
);
98 virtual long getPrimaryDimension(const Size
&rSize
) const = 0;
99 virtual void setPrimaryDimension(Size
&rSize
, long) const = 0;
100 virtual long getPrimaryCoordinate(const Point
&rPos
) const = 0;
101 virtual void setPrimaryCoordinate(Point
&rPos
, long) const = 0;
102 virtual long getSecondaryDimension(const Size
&rSize
) const = 0;
103 virtual void setSecondaryDimension(Size
&rSize
, long) const = 0;
104 virtual long getSecondaryCoordinate(const Point
&rPos
) const = 0;
105 virtual void setSecondaryCoordinate(Point
&rPos
, long) const = 0;
107 virtual bool getPrimaryDimensionChildExpand(const Window
&rWindow
) const = 0;
110 class VCL_DLLPUBLIC VclVBox
: public VclBox
113 VclVBox(Window
*pParent
, bool bHomogeneous
= false, int nSpacing
= 0)
114 : VclBox(pParent
, bHomogeneous
, nSpacing
)
116 m_bVerticalContainer
= true;
119 virtual long getPrimaryDimension(const Size
&rSize
) const
121 return rSize
.getHeight();
123 virtual void setPrimaryDimension(Size
&rSize
, long nHeight
) const
125 rSize
.setHeight(nHeight
);
127 virtual long getPrimaryCoordinate(const Point
&rPos
) const
131 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const
135 virtual long getSecondaryDimension(const Size
&rSize
) const
137 return rSize
.getWidth();
139 virtual void setSecondaryDimension(Size
&rSize
, long nWidth
) const
141 rSize
.setWidth(nWidth
);
143 virtual long getSecondaryCoordinate(const Point
&rPos
) const
147 virtual void setSecondaryCoordinate(Point
&rPos
, long nPos
) const
151 virtual bool getPrimaryDimensionChildExpand(const Window
&rWindow
) const
153 return rWindow
.get_expand() || rWindow
.get_vexpand();
157 class VCL_DLLPUBLIC VclHBox
: public VclBox
160 VclHBox(Window
*pParent
, bool bHomogeneous
= false, int nSpacing
= 0)
161 : VclBox(pParent
, bHomogeneous
, nSpacing
)
163 m_bVerticalContainer
= false;
166 virtual long getPrimaryDimension(const Size
&rSize
) const
168 return rSize
.getWidth();
170 virtual void setPrimaryDimension(Size
&rSize
, long nWidth
) const
172 rSize
.setWidth(nWidth
);
174 virtual long getPrimaryCoordinate(const Point
&rPos
) const
178 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const
182 virtual long getSecondaryDimension(const Size
&rSize
) const
184 return rSize
.getHeight();
186 virtual void setSecondaryDimension(Size
&rSize
, long nHeight
) const
188 rSize
.setHeight(nHeight
);
190 virtual long getSecondaryCoordinate(const Point
&rPos
) const
194 virtual void setSecondaryCoordinate(Point
&rPos
, long nPos
) const
198 virtual bool getPrimaryDimensionChildExpand(const Window
&rWindow
) const
200 return rWindow
.get_expand() || rWindow
.get_hexpand();
204 enum VclButtonBoxStyle
206 VCL_BUTTONBOX_DEFAULT_STYLE
,
207 VCL_BUTTONBOX_SPREAD
,
214 class VCL_DLLPUBLIC VclButtonBox
: public VclBox
217 VclButtonBox(Window
*pParent
, int nSpacing
)
218 : VclBox(pParent
, false, nSpacing
)
219 , m_eLayoutStyle(VCL_BUTTONBOX_DEFAULT_STYLE
)
222 void set_layout(VclButtonBoxStyle eStyle
)
224 m_eLayoutStyle
= eStyle
;
226 VclButtonBoxStyle
get_layout() const
228 return m_eLayoutStyle
;
230 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
231 void sort_native_button_order();
233 virtual Size
calculateRequisition() const;
234 virtual void setAllocation(const Size
&rAllocation
);
235 Size
addSpacing(const Size
&rSize
, sal_uInt16 nVisibleChildren
) const;
237 VclButtonBoxStyle m_eLayoutStyle
;
240 std::vector
<long> m_aMainGroupDimensions
;
241 std::vector
<long> m_aSubGroupDimensions
;
242 Size m_aMainGroupSize
;
243 Size m_aSubGroupSize
;
245 Requisition
calculatePrimarySecondaryRequisitions() const;
246 Size
addReqGroups(const VclButtonBox::Requisition
&rReq
) const;
249 class VCL_DLLPUBLIC VclVButtonBox
: public VclButtonBox
252 VclVButtonBox(Window
*pParent
, int nSpacing
= 0)
253 : VclButtonBox(pParent
, nSpacing
)
255 m_bVerticalContainer
= true;
258 virtual long getPrimaryDimension(const Size
&rSize
) const
260 return rSize
.getHeight();
262 virtual void setPrimaryDimension(Size
&rSize
, long nHeight
) const
264 rSize
.setHeight(nHeight
);
266 virtual long getPrimaryCoordinate(const Point
&rPos
) const
270 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const
274 virtual long getSecondaryDimension(const Size
&rSize
) const
276 return rSize
.getWidth();
278 virtual void setSecondaryDimension(Size
&rSize
, long nWidth
) const
280 rSize
.setWidth(nWidth
);
282 virtual long getSecondaryCoordinate(const Point
&rPos
) const
286 virtual void setSecondaryCoordinate(Point
&rPos
, long nPos
) const
290 virtual bool getPrimaryDimensionChildExpand(const Window
&rWindow
) const
292 return rWindow
.get_expand() || rWindow
.get_vexpand();
296 class VCL_DLLPUBLIC VclHButtonBox
: public VclButtonBox
299 VclHButtonBox(Window
*pParent
, int nSpacing
= 0)
300 : VclButtonBox(pParent
, nSpacing
)
302 m_bVerticalContainer
= false;
305 virtual long getPrimaryDimension(const Size
&rSize
) const
307 return rSize
.getWidth();
309 virtual void setPrimaryDimension(Size
&rSize
, long nWidth
) const
311 rSize
.setWidth(nWidth
);
313 virtual long getPrimaryCoordinate(const Point
&rPos
) const
317 virtual void setPrimaryCoordinate(Point
&rPos
, long nPos
) const
321 virtual long getSecondaryDimension(const Size
&rSize
) const
323 return rSize
.getHeight();
325 virtual void setSecondaryDimension(Size
&rSize
, long nHeight
) const
327 rSize
.setHeight(nHeight
);
329 virtual long getSecondaryCoordinate(const Point
&rPos
) const
333 virtual void setSecondaryCoordinate(Point
&rPos
, long nPos
) const
337 virtual bool getPrimaryDimensionChildExpand(const Window
&rWindow
) const
339 return rWindow
.get_expand() || rWindow
.get_hexpand();
343 class VCL_DLLPUBLIC VclGrid
: public VclContainer
346 bool m_bRowHomogeneous
;
347 bool m_bColumnHomogeneous
;
349 int m_nColumnSpacing
;
354 sal_Int32 nSpanWidth
;
355 sal_Int32 nSpanHeight
;
364 typedef boost::multi_array
<GridEntry
, 2> array_type
;
366 struct ExtendedGridEntry
: GridEntry
377 typedef boost::multi_array
<ExtendedGridEntry
, 2> ext_array_type
;
379 array_type
assembleGrid() const;
380 bool isNullGrid(const array_type
& A
) const;
386 Value() : m_nValue(0), m_bExpand(false) {}
389 void calcMaxs(const array_type
&A
, std::vector
<Value
> &rWidths
, std::vector
<Value
> &rHeights
) const;
391 Size
calculateRequisitionForSpacings(sal_Int32 nRowSpacing
, sal_Int32 nColSpacing
) const;
392 virtual Size
calculateRequisition() const;
393 virtual void setAllocation(const Size
&rAllocation
);
395 VclGrid(Window
*pParent
)
396 : VclContainer(pParent
)
397 , m_bRowHomogeneous(false), m_bColumnHomogeneous(false)
398 , m_nRowSpacing(0), m_nColumnSpacing(0)
401 void set_row_homogeneous(bool bHomogeneous
)
403 m_bRowHomogeneous
= bHomogeneous
;
405 void set_column_homogeneous(bool bHomogeneous
)
407 m_bColumnHomogeneous
= bHomogeneous
;
409 bool get_row_homogeneous() const
411 return m_bRowHomogeneous
;
413 bool get_column_homogeneous() const
415 return m_bColumnHomogeneous
;
417 void set_row_spacing(int nSpacing
)
419 m_nRowSpacing
= nSpacing
;
421 void set_column_spacing(int nSpacing
)
423 m_nColumnSpacing
= nSpacing
;
425 int get_row_spacing() const
427 return m_nRowSpacing
;
429 int get_column_spacing() const
431 return m_nColumnSpacing
;
433 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
436 VCL_DLLPUBLIC
void setGridAttach(Window
&rWidget
, sal_Int32 nLeft
, sal_Int32 nTop
,
437 sal_Int32 nWidth
= 1, sal_Int32 nHeight
= 1);
439 class VCL_DLLPUBLIC VclBin
: public VclContainer
442 VclBin(Window
*pParent
, WinBits nStyle
= WB_HIDE
)
443 : VclContainer(pParent
, nStyle
)
446 virtual Window
*get_child();
447 virtual const Window
*get_child() const;
448 virtual Size
calculateRequisition() const;
449 virtual void setAllocation(const Size
&rAllocation
);
452 class VCL_DLLPUBLIC VclFrame
: public VclBin
457 friend class VclBuilder
;
458 void designate_label(Window
*pWindow
);
460 VclFrame(Window
*pParent
)
465 void set_label(const OUString
&rLabel
);
466 virtual Window
*get_child();
467 virtual const Window
*get_child() const;
468 Window
*get_label_widget();
469 const Window
*get_label_widget() const;
471 virtual Size
calculateRequisition() const;
472 virtual void setAllocation(const Size
&rAllocation
);
473 virtual OUString
getDefaultAccessibleName() const;
476 class VCL_DLLPUBLIC VclAlignment
: public VclBin
479 VclAlignment(Window
*pParent
)
481 , m_nBottomPadding(0)
491 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
493 virtual Size
calculateRequisition() const;
494 virtual void setAllocation(const Size
&rAllocation
);
496 sal_Int32 m_nBottomPadding
;
497 sal_Int32 m_nLeftPadding
;
498 sal_Int32 m_nRightPadding
;
499 sal_Int32 m_nTopPadding
;
506 class VCL_DLLPUBLIC VclExpander
: public VclBin
509 VclExpander(Window
*pParent
)
511 , m_bResizeTopLevel(true)
512 , m_aDisclosureButton(this)
514 m_aDisclosureButton
.SetToggleHdl(LINK(this, VclExpander
, ClickHdl
));
515 m_aDisclosureButton
.Show();
517 virtual Window
*get_child();
518 virtual const Window
*get_child() const;
519 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
520 bool get_expanded() const
522 return m_aDisclosureButton
.IsChecked();
524 void set_expanded(bool bExpanded
)
526 m_aDisclosureButton
.Check(bExpanded
);
528 void set_label(const OUString
& rLabel
)
530 m_aDisclosureButton
.SetText(rLabel
);
532 OUString
get_label() const
534 return m_aDisclosureButton
.GetText();
536 virtual void StateChanged(StateChangedType nType
);
538 virtual Size
calculateRequisition() const;
539 virtual void setAllocation(const Size
&rAllocation
);
541 bool m_bResizeTopLevel
;
542 DisclosureButton m_aDisclosureButton
;
543 DECL_DLLPRIVATE_LINK(ClickHdl
, DisclosureButton
* pBtn
);
546 //This is a work in progress, so if you want to put something inside a
547 //scrolled window that doesn't handle its own scrolling, then you may need to
548 //implement this fully
549 class VCL_DLLPUBLIC VclScrolledWindow
: public VclBin
552 VclScrolledWindow(Window
*pParent
, WinBits nStyle
= WB_HIDE
| WB_AUTOHSCROLL
| WB_AUTOVSCROLL
)
553 : VclBin(pParent
, nStyle
)
554 , m_aVScroll(this, WB_HIDE
| WB_VERT
)
555 , m_aHScroll(this, WB_HIDE
| WB_HORZ
)
557 SetType(WINDOW_SCROLLWINDOW
);
559 virtual Window
*get_child();
560 virtual const Window
*get_child() const;
561 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
562 ScrollBar
& getVertScrollBar() { return m_aVScroll
; }
563 ScrollBar
& getHorzScrollBar() { return m_aHScroll
; }
564 Size
getVisibleChildSize() const;
566 virtual Size
calculateRequisition() const;
567 virtual void setAllocation(const Size
&rAllocation
);
569 ScrollBar m_aVScroll
;
570 ScrollBar m_aHScroll
;
573 //Enforces that its children are always the same size as itself.
574 //Intercepts any Commands intended for its children.
576 //by default the Commands are discarded, inherit from this
577 //and implement "Command" to get them
578 class VCL_DLLPUBLIC VclEventBox
: public VclBin
581 //Any Commands an EventBoxHelper receives are forwarded to its parent
582 //The VclEventBox ensures that m_aEventBoxHelper is the
583 //first child and is transparent, but covers the rest of the children
584 class EventBoxHelper
: public Window
587 EventBoxHelper(Window
* pParent
)
590 SetSizePixel(pParent
->GetSizePixel());
591 EnableChildTransparentMode();
592 SetPaintTransparent(true);
595 virtual void Command(const CommandEvent
& rCEvt
)
597 GetParent()->Command(rCEvt
);
601 EventBoxHelper m_aEventBoxHelper
;
603 VclEventBox(Window
* pParent
)
605 , m_aEventBoxHelper(this)
607 m_aEventBoxHelper
.Show();
609 virtual Window
*get_child();
610 virtual const Window
*get_child() const;
611 virtual Size
calculateRequisition() const;
612 virtual void setAllocation(const Size
&rAllocation
);
614 virtual void Command(const CommandEvent
& rCEvt
);
617 enum VclSizeGroupMode
620 VCL_SIZE_GROUP_HORIZONTAL
,
621 VCL_SIZE_GROUP_VERTICAL
,
625 class VCL_DLLPUBLIC VclSizeGroup
628 std::set
<Window
*> m_aWindows
;
629 bool m_bIgnoreHidden
;
630 VclSizeGroupMode m_eMode
;
632 void trigger_queue_resize();
635 : m_bIgnoreHidden(false)
636 , m_eMode(VCL_SIZE_GROUP_HORIZONTAL
)
639 void insert(Window
*pWindow
)
641 m_aWindows
.insert(pWindow
);
643 void erase(Window
*pWindow
)
645 m_aWindows
.erase(pWindow
);
647 const std::set
<Window
*>& get_widgets() const
651 std::set
<Window
*>& get_widgets()
655 void set_ignore_hidden(bool bIgnoreHidden
);
656 bool get_ignore_hidden() const
658 return m_bIgnoreHidden
;
660 void set_mode(VclSizeGroupMode eMode
);
661 VclSizeGroupMode
get_mode() const
665 bool set_property(const OString
&rKey
, const OString
&rValue
);
668 class VCL_DLLPUBLIC MessageDialog
: public Dialog
672 FixedImage
* m_pImage
;
673 VclMultiLineEdit
* m_pPrimaryMessage
;
674 VclMultiLineEdit
* m_pSecondaryMessage
;
675 OUString m_sPrimaryString
;
676 OUString m_sSecondaryString
;
677 DECL_DLLPRIVATE_LINK(ButtonHdl
, Button
*);
678 void setButtonHandlers();
680 MessageDialog(Window
* pParent
, WinBits nStyle
);
681 MessageDialog(Window
* pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
);
682 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
683 virtual short Execute();
684 OUString
get_primary_text() const;
685 OUString
get_secondary_text() const;
686 void set_primary_text(const OUString
&rPrimaryString
);
687 void set_secondary_text(const OUString
&rSecondaryString
);
691 VCL_DLLPUBLIC Size
bestmaxFrameSizeForScreenSize(const Size
&rScreenSize
);
693 //Get first window of a pTopLevel window as
694 //if any intermediate layout widgets didn't exist
695 //i.e. acts like pChild = pChild->GetWindow(WINDOW_FIRSTCHILD);
696 //in a flat hierarchy where dialogs only have one layer
698 VCL_DLLPUBLIC Window
* firstLogicalChildOfParent(Window
*pTopLevel
);
700 //Get next window after pChild of a pTopLevel window as
701 //if any intermediate layout widgets didn't exist
702 //i.e. acts like pChild = pChild->GetWindow(WINDOW_NEXT);
703 //in a flat hierarchy where dialogs only have one layer
705 VCL_DLLPUBLIC Window
* nextLogicalChildOfParent(Window
*pTopLevel
, Window
*pChild
);
707 //Get previous window before pChild of a pTopLevel window as
708 //if any intermediate layout widgets didn't exist
709 //i.e. acts like pChild = pChild->GetWindow(WINDOW_PREV);
710 //in a flat hierarchy where dialogs only have one layer
712 VCL_DLLPUBLIC Window
* prevLogicalChildOfParent(Window
*pTopLevel
, Window
*pChild
);
714 //Returns true is the Window has a single child which is a container
715 VCL_DLLPUBLIC
bool isLayoutEnabled(const Window
*pWindow
);
717 VCL_DLLPUBLIC
inline bool isContainerWindow(const Window
&rWindow
)
719 WindowType eType
= rWindow
.GetType();
720 return (eType
== WINDOW_CONTAINER
|| eType
== WINDOW_SCROLLWINDOW
);
723 VCL_DLLPUBLIC
inline bool isContainerWindow(const Window
*pWindow
)
725 return pWindow
&& isContainerWindow(*pWindow
);
728 //Returns true if the containing dialog is doing its initial
729 //layout and isn't visible yet
730 VCL_DLLPUBLIC
bool isInitialLayout(const Window
*pWindow
);
732 // retro-fitting utilities //
734 //Get a Size which is large enough to contain all children with
735 //an equal amount of space at top left and bottom right
736 Size
getLegacyBestSizeForChildren(const Window
&rWindow
);
738 //Get first parent which is not a layout widget
739 Window
* getNonLayoutParent(Window
*pParent
);
741 //Get first real parent which is not a layout widget
742 Window
* getNonLayoutRealParent(Window
*pParent
);
744 //return true if this window and its stack of containers are all shown
745 bool isVisibleInLayout(const Window
*pWindow
);
747 //return true if this window and its stack of containers are all enabled
748 bool isEnabledInLayout(const Window
*pWindow
);
752 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */