sashwin.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/sashwin.h
  3. // Purpose: wxSashWindow implementation. A sash window has an optional
  4. // sash on each edge, allowing it to be dragged. An event
  5. // is generated when the sash is released.
  6. // Author: Julian Smart
  7. // Modified by:
  8. // Created: 01/02/97
  9. // Copyright: (c) Julian Smart
  10. // Licence: wxWindows licence
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef _WX_SASHWIN_H_G_
  13. #define _WX_SASHWIN_H_G_
  14. #if wxUSE_SASH
  15. #include "wx/defs.h"
  16. #include "wx/window.h"
  17. #include "wx/string.h"
  18. #define wxSASH_DRAG_NONE 0
  19. #define wxSASH_DRAG_DRAGGING 1
  20. #define wxSASH_DRAG_LEFT_DOWN 2
  21. enum wxSashEdgePosition {
  22. wxSASH_TOP = 0,
  23. wxSASH_RIGHT,
  24. wxSASH_BOTTOM,
  25. wxSASH_LEFT,
  26. wxSASH_NONE = 100
  27. };
  28. /*
  29. * wxSashEdge represents one of the four edges of a window.
  30. */
  31. class WXDLLIMPEXP_ADV wxSashEdge
  32. {
  33. public:
  34. wxSashEdge()
  35. { m_show = false;
  36. #if WXWIN_COMPATIBILITY_2_6
  37. m_border = false;
  38. #endif
  39. m_margin = 0; }
  40. bool m_show; // Is the sash showing?
  41. #if WXWIN_COMPATIBILITY_2_6
  42. bool m_border; // Do we draw a border?
  43. #endif
  44. int m_margin; // The margin size
  45. };
  46. /*
  47. * wxSashWindow flags
  48. */
  49. #define wxSW_NOBORDER 0x0000
  50. //#define wxSW_3D 0x0010
  51. #define wxSW_BORDER 0x0020
  52. #define wxSW_3DSASH 0x0040
  53. #define wxSW_3DBORDER 0x0080
  54. #define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER)
  55. /*
  56. * wxSashWindow allows any of its edges to have a sash which can be dragged
  57. * to resize the window. The actual content window will be created as a child
  58. * of wxSashWindow.
  59. */
  60. class WXDLLIMPEXP_ADV wxSashWindow: public wxWindow
  61. {
  62. public:
  63. // Default constructor
  64. wxSashWindow()
  65. {
  66. Init();
  67. }
  68. // Normal constructor
  69. wxSashWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
  70. const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("sashWindow"))
  71. {
  72. Init();
  73. Create(parent, id, pos, size, style, name);
  74. }
  75. virtual ~wxSashWindow();
  76. bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
  77. const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("sashWindow"));
  78. // Set whether there's a sash in this position
  79. void SetSashVisible(wxSashEdgePosition edge, bool sash);
  80. // Get whether there's a sash in this position
  81. bool GetSashVisible(wxSashEdgePosition edge) const { return m_sashes[edge].m_show; }
  82. #if WXWIN_COMPATIBILITY_2_6
  83. // Set whether there's a border in this position
  84. // This value is unused in wxSashWindow.
  85. void SetSashBorder(wxSashEdgePosition edge, bool border) { m_sashes[edge].m_border = border; }
  86. // Get whether there's a border in this position
  87. // This value is unused in wxSashWindow.
  88. bool HasBorder(wxSashEdgePosition edge) const { return m_sashes[edge].m_border; }
  89. #endif
  90. // Get border size
  91. int GetEdgeMargin(wxSashEdgePosition edge) const { return m_sashes[edge].m_margin; }
  92. // Sets the default sash border size
  93. void SetDefaultBorderSize(int width) { m_borderSize = width; }
  94. // Gets the default sash border size
  95. int GetDefaultBorderSize() const { return m_borderSize; }
  96. // Sets the addition border size between child and sash window
  97. void SetExtraBorderSize(int width) { m_extraBorderSize = width; }
  98. // Gets the addition border size between child and sash window
  99. int GetExtraBorderSize() const { return m_extraBorderSize; }
  100. virtual void SetMinimumSizeX(int min) { m_minimumPaneSizeX = min; }
  101. virtual void SetMinimumSizeY(int min) { m_minimumPaneSizeY = min; }
  102. virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX; }
  103. virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY; }
  104. virtual void SetMaximumSizeX(int max) { m_maximumPaneSizeX = max; }
  105. virtual void SetMaximumSizeY(int max) { m_maximumPaneSizeY = max; }
  106. virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX; }
  107. virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY; }
  108. ////////////////////////////////////////////////////////////////////////////
  109. // Implementation
  110. // Paints the border and sash
  111. void OnPaint(wxPaintEvent& event);
  112. // Handles mouse events
  113. void OnMouseEvent(wxMouseEvent& ev);
  114. // Adjusts the panes
  115. void OnSize(wxSizeEvent& event);
  116. #if defined(__WXMSW__) || defined(__WXMAC__)
  117. // Handle cursor correctly
  118. void OnSetCursor(wxSetCursorEvent& event);
  119. #endif // wxMSW
  120. // Draws borders
  121. void DrawBorders(wxDC& dc);
  122. // Draws the sashes
  123. void DrawSash(wxSashEdgePosition edge, wxDC& dc);
  124. // Draws the sashes
  125. void DrawSashes(wxDC& dc);
  126. // Draws the sash tracker (for whilst moving the sash)
  127. void DrawSashTracker(wxSashEdgePosition edge, int x, int y);
  128. // Tests for x, y over sash
  129. wxSashEdgePosition SashHitTest(int x, int y, int tolerance = 2);
  130. // Resizes subwindows
  131. void SizeWindows();
  132. // Initialize colours
  133. void InitColours();
  134. private:
  135. void Init();
  136. wxSashEdge m_sashes[4];
  137. int m_dragMode;
  138. wxSashEdgePosition m_draggingEdge;
  139. int m_oldX;
  140. int m_oldY;
  141. int m_borderSize;
  142. int m_extraBorderSize;
  143. int m_firstX;
  144. int m_firstY;
  145. int m_minimumPaneSizeX;
  146. int m_minimumPaneSizeY;
  147. int m_maximumPaneSizeX;
  148. int m_maximumPaneSizeY;
  149. wxCursor* m_sashCursorWE;
  150. wxCursor* m_sashCursorNS;
  151. wxColour m_lightShadowColour;
  152. wxColour m_mediumShadowColour;
  153. wxColour m_darkShadowColour;
  154. wxColour m_hilightColour;
  155. wxColour m_faceColour;
  156. bool m_mouseCaptured;
  157. wxCursor* m_currentCursor;
  158. private:
  159. DECLARE_DYNAMIC_CLASS(wxSashWindow)
  160. DECLARE_EVENT_TABLE()
  161. wxDECLARE_NO_COPY_CLASS(wxSashWindow);
  162. };
  163. class WXDLLIMPEXP_FWD_ADV wxSashEvent;
  164. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_SASH_DRAGGED, wxSashEvent );
  165. enum wxSashDragStatus
  166. {
  167. wxSASH_STATUS_OK,
  168. wxSASH_STATUS_OUT_OF_RANGE
  169. };
  170. class WXDLLIMPEXP_ADV wxSashEvent: public wxCommandEvent
  171. {
  172. public:
  173. wxSashEvent(int id = 0, wxSashEdgePosition edge = wxSASH_NONE)
  174. {
  175. m_eventType = (wxEventType) wxEVT_SASH_DRAGGED;
  176. m_id = id;
  177. m_edge = edge;
  178. }
  179. wxSashEvent(const wxSashEvent& event)
  180. : wxCommandEvent(event),
  181. m_edge(event.m_edge),
  182. m_dragRect(event.m_dragRect),
  183. m_dragStatus(event.m_dragStatus) { }
  184. void SetEdge(wxSashEdgePosition edge) { m_edge = edge; }
  185. wxSashEdgePosition GetEdge() const { return m_edge; }
  186. //// The rectangle formed by the drag operation
  187. void SetDragRect(const wxRect& rect) { m_dragRect = rect; }
  188. wxRect GetDragRect() const { return m_dragRect; }
  189. //// Whether the drag caused the rectangle to be reversed (e.g.
  190. //// dragging the top below the bottom)
  191. void SetDragStatus(wxSashDragStatus status) { m_dragStatus = status; }
  192. wxSashDragStatus GetDragStatus() const { return m_dragStatus; }
  193. virtual wxEvent *Clone() const { return new wxSashEvent(*this); }
  194. private:
  195. wxSashEdgePosition m_edge;
  196. wxRect m_dragRect;
  197. wxSashDragStatus m_dragStatus;
  198. private:
  199. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSashEvent)
  200. };
  201. typedef void (wxEvtHandler::*wxSashEventFunction)(wxSashEvent&);
  202. #define wxSashEventHandler(func) \
  203. wxEVENT_HANDLER_CAST(wxSashEventFunction, func)
  204. #define EVT_SASH_DRAGGED(id, fn) \
  205. wx__DECLARE_EVT1(wxEVT_SASH_DRAGGED, id, wxSashEventHandler(fn))
  206. #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \
  207. wx__DECLARE_EVT2(wxEVT_SASH_DRAGGED, id1, id2, wxSashEventHandler(fn))
  208. #endif // wxUSE_SASH
  209. #endif
  210. // _WX_SASHWIN_H_G_