]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wrapsizer.h
Make wxRichTextRectArray usable by other parts of wxRTC
[wxWidgets.git] / include / wx / wrapsizer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wrapsizer.h
3 // Purpose: provide wrapping sizer for layout (wxWrapSizer)
4 // Author: Arne Steinarson
5 // Created: 2008-05-08
6 // Copyright: (c) Arne Steinarson
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_WRAPSIZER_H_
11 #define _WX_WRAPSIZER_H_
12
13 #include "wx/sizer.h"
14
15 // flags for wxWrapSizer
16 enum
17 {
18 wxEXTEND_LAST_ON_EACH_LINE = 1,
19 // don't leave spacers in the beginning of a new row
20 wxREMOVE_LEADING_SPACES = 2,
21
22 wxWRAPSIZER_DEFAULT_FLAGS = wxEXTEND_LAST_ON_EACH_LINE |
23 wxREMOVE_LEADING_SPACES
24 };
25
26 // ----------------------------------------------------------------------------
27 // A box sizer that can wrap items on several lines when sum of widths exceed
28 // available line width.
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxWrapSizer : public wxBoxSizer
32 {
33 public:
34 wxWrapSizer(int orient = wxHORIZONTAL, int flags = wxWRAPSIZER_DEFAULT_FLAGS);
35 virtual ~wxWrapSizer();
36
37 // override base class virtual methods
38 virtual wxSize CalcMin();
39 virtual void RecalcSizes();
40
41 virtual bool InformFirstDirection(int direction,
42 int size,
43 int availableOtherDir);
44
45 protected:
46 // This method is called to decide if an item represents empty space or
47 // not. We do this to avoid having space-only items first or last on a
48 // wrapped line (left alignment).
49 //
50 // By default only spacers are considered to be empty items but a derived
51 // class may override this item if some other kind of sizer elements should
52 // be also considered empty for some reason.
53 virtual bool IsSpaceItem(wxSizerItem *item) const
54 {
55 return item->IsSpacer();
56 }
57
58 // helpers of CalcMin()
59 void CalcMinFromMinor(int totMinor);
60 void CalcMinFromMajor(int totMajor);
61 void CalcMinUsingCurrentLayout();
62 void CalcMinFittingSize(const wxSize& szBoundary);
63 void CalcMaxSingleItemSize();
64
65 // temporarily change the proportion of the last item of the N-th row to
66 // extend to the end of line if the appropriate flag is set
67 void AdjustLastRowItemProp(size_t n, wxSizerItem *itemLast);
68
69 // remove all the items from m_rows
70 void ClearRows();
71
72 // return the N-th row sizer from m_rows creating it if necessary
73 wxSizer *GetRowSizer(size_t n);
74
75 // should be called after completion of each row
76 void FinishRow(size_t n, int rowMajor, int rowMinor, wxSizerItem *itemLast);
77
78
79 const int m_flags; // Flags specified in the ctor
80
81 int m_dirInform; // Direction for size information
82 int m_availSize; // Size available in m_dirInform direction
83 int m_availableOtherDir; // Size available in the other direction
84 bool m_lastUsed; // Indicates whether value from InformFirst... has
85 // been used yet
86
87 // The sizes below are computed by RecalcSizes(), i.e. they don't have
88 // valid values during the initial call to CalcMin() and they are only
89 // valid for the current layout (i.e. the current number of rows)
90 int m_minSizeMinor; // Min size in minor direction
91 int m_maxSizeMajor; // Size of longest row
92 int m_minItemMajor; // Size of smallest item in major direction
93
94 wxBoxSizer m_rows; // Sizer containing multiple rows of our items
95
96 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWrapSizer)
97 };
98
99 #endif // _WX_WRAPSIZER_H_