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