laywin.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/laywin.h
  3. // Purpose: Implements a simple layout algorithm, plus
  4. // wxSashLayoutWindow which is an example of a window with
  5. // layout-awareness (via event handlers). This is suited to
  6. // IDE-style window layout.
  7. // Author: Julian Smart
  8. // Modified by:
  9. // Created: 04/01/98
  10. // Copyright: (c) Julian Smart
  11. // Licence: wxWindows licence
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef _WX_LAYWIN_H_G_
  14. #define _WX_LAYWIN_H_G_
  15. #if wxUSE_SASH
  16. #include "wx/sashwin.h"
  17. #endif // wxUSE_SASH
  18. #include "wx/event.h"
  19. class WXDLLIMPEXP_FWD_ADV wxQueryLayoutInfoEvent;
  20. class WXDLLIMPEXP_FWD_ADV wxCalculateLayoutEvent;
  21. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_QUERY_LAYOUT_INFO, wxQueryLayoutInfoEvent );
  22. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALCULATE_LAYOUT, wxCalculateLayoutEvent );
  23. enum wxLayoutOrientation
  24. {
  25. wxLAYOUT_HORIZONTAL,
  26. wxLAYOUT_VERTICAL
  27. };
  28. enum wxLayoutAlignment
  29. {
  30. wxLAYOUT_NONE,
  31. wxLAYOUT_TOP,
  32. wxLAYOUT_LEFT,
  33. wxLAYOUT_RIGHT,
  34. wxLAYOUT_BOTTOM
  35. };
  36. // Not sure this is necessary
  37. // Tell window which dimension we're sizing on
  38. #define wxLAYOUT_LENGTH_Y 0x0008
  39. #define wxLAYOUT_LENGTH_X 0x0000
  40. // Use most recently used length
  41. #define wxLAYOUT_MRU_LENGTH 0x0010
  42. // Only a query, so don't actually move it.
  43. #define wxLAYOUT_QUERY 0x0100
  44. /*
  45. * This event is used to get information about window alignment,
  46. * orientation and size.
  47. */
  48. class WXDLLIMPEXP_ADV wxQueryLayoutInfoEvent: public wxEvent
  49. {
  50. public:
  51. wxQueryLayoutInfoEvent(wxWindowID id = 0)
  52. {
  53. SetEventType(wxEVT_QUERY_LAYOUT_INFO);
  54. m_requestedLength = 0;
  55. m_flags = 0;
  56. m_id = id;
  57. m_alignment = wxLAYOUT_TOP;
  58. m_orientation = wxLAYOUT_HORIZONTAL;
  59. }
  60. // Read by the app
  61. void SetRequestedLength(int length) { m_requestedLength = length; }
  62. int GetRequestedLength() const { return m_requestedLength; }
  63. void SetFlags(int flags) { m_flags = flags; }
  64. int GetFlags() const { return m_flags; }
  65. // Set by the app
  66. void SetSize(const wxSize& size) { m_size = size; }
  67. wxSize GetSize() const { return m_size; }
  68. void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }
  69. wxLayoutOrientation GetOrientation() const { return m_orientation; }
  70. void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }
  71. wxLayoutAlignment GetAlignment() const { return m_alignment; }
  72. virtual wxEvent *Clone() const { return new wxQueryLayoutInfoEvent(*this); }
  73. protected:
  74. int m_flags;
  75. int m_requestedLength;
  76. wxSize m_size;
  77. wxLayoutOrientation m_orientation;
  78. wxLayoutAlignment m_alignment;
  79. private:
  80. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryLayoutInfoEvent)
  81. };
  82. typedef void (wxEvtHandler::*wxQueryLayoutInfoEventFunction)(wxQueryLayoutInfoEvent&);
  83. #define wxQueryLayoutInfoEventHandler( func ) \
  84. wxEVENT_HANDLER_CAST( wxQueryLayoutInfoEventFunction, func )
  85. #define EVT_QUERY_LAYOUT_INFO(func) \
  86. wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_LAYOUT_INFO, wxID_ANY, wxID_ANY, wxQueryLayoutInfoEventHandler( func ), NULL ),
  87. /*
  88. * This event is used to take a bite out of the available client area.
  89. */
  90. class WXDLLIMPEXP_ADV wxCalculateLayoutEvent: public wxEvent
  91. {
  92. public:
  93. wxCalculateLayoutEvent(wxWindowID id = 0)
  94. {
  95. SetEventType(wxEVT_CALCULATE_LAYOUT);
  96. m_flags = 0;
  97. m_id = id;
  98. }
  99. // Read by the app
  100. void SetFlags(int flags) { m_flags = flags; }
  101. int GetFlags() const { return m_flags; }
  102. // Set by the app
  103. void SetRect(const wxRect& rect) { m_rect = rect; }
  104. wxRect GetRect() const { return m_rect; }
  105. virtual wxEvent *Clone() const { return new wxCalculateLayoutEvent(*this); }
  106. protected:
  107. int m_flags;
  108. wxRect m_rect;
  109. private:
  110. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalculateLayoutEvent)
  111. };
  112. typedef void (wxEvtHandler::*wxCalculateLayoutEventFunction)(wxCalculateLayoutEvent&);
  113. #define wxCalculateLayoutEventHandler( func ) wxEVENT_HANDLER_CAST(wxCalculateLayoutEventFunction, func)
  114. #define EVT_CALCULATE_LAYOUT(func) \
  115. wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_CALCULATE_LAYOUT, wxID_ANY, wxID_ANY, wxCalculateLayoutEventHandler( func ), NULL ),
  116. #if wxUSE_SASH
  117. // This is window that can remember alignment/orientation, does its own layout,
  118. // and can provide sashes too. Useful for implementing docked windows with sashes in
  119. // an IDE-style interface.
  120. class WXDLLIMPEXP_ADV wxSashLayoutWindow: public wxSashWindow
  121. {
  122. public:
  123. wxSashLayoutWindow()
  124. {
  125. Init();
  126. }
  127. wxSashLayoutWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
  128. const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow"))
  129. {
  130. Create(parent, id, pos, size, style, name);
  131. }
  132. bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
  133. const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("layoutWindow"));
  134. // Accessors
  135. inline wxLayoutAlignment GetAlignment() const { return m_alignment; }
  136. inline wxLayoutOrientation GetOrientation() const { return m_orientation; }
  137. inline void SetAlignment(wxLayoutAlignment align) { m_alignment = align; }
  138. inline void SetOrientation(wxLayoutOrientation orient) { m_orientation = orient; }
  139. // Give the window default dimensions
  140. inline void SetDefaultSize(const wxSize& size) { m_defaultSize = size; }
  141. // Event handlers
  142. // Called by layout algorithm to allow window to take a bit out of the
  143. // client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
  144. void OnCalculateLayout(wxCalculateLayoutEvent& event);
  145. // Called by layout algorithm to retrieve information about the window.
  146. void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
  147. private:
  148. void Init();
  149. wxLayoutAlignment m_alignment;
  150. wxLayoutOrientation m_orientation;
  151. wxSize m_defaultSize;
  152. private:
  153. DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashLayoutWindow)
  154. DECLARE_EVENT_TABLE()
  155. };
  156. #endif // wxUSE_SASH
  157. class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame;
  158. class WXDLLIMPEXP_FWD_CORE wxFrame;
  159. // This class implements the layout algorithm
  160. class WXDLLIMPEXP_ADV wxLayoutAlgorithm: public wxObject
  161. {
  162. public:
  163. wxLayoutAlgorithm() {}
  164. #if wxUSE_MDI_ARCHITECTURE
  165. // The MDI client window is sized to whatever's left over.
  166. bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = NULL);
  167. #endif // wxUSE_MDI_ARCHITECTURE
  168. // mainWindow is sized to whatever's left over. This function for backward
  169. // compatibility; use LayoutWindow.
  170. bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = NULL);
  171. // mainWindow is sized to whatever's left over.
  172. bool LayoutWindow(wxWindow* frame, wxWindow* mainWindow = NULL);
  173. };
  174. #endif
  175. // _WX_LAYWIN_H_G_