wrapsizer.h 3.6 KB

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