scrthumb.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/scrthumb.h
  3. // Purpose: wxScrollThumb class
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 12.02.01
  7. // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_SCRTHUMB_H_
  11. #define _WX_UNIV_SCRTHUMB_H_
  12. // ----------------------------------------------------------------------------
  13. // wxScrollThumb is not a control but just a class containing the common
  14. // functionality of scroll thumb such as used by scrollbars, sliders and maybe
  15. // other (user) controls
  16. //
  17. // This class is similar to wxScrollThumb.
  18. // ----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_FWD_CORE wxControlWithThumb;
  20. class WXDLLIMPEXP_FWD_CORE wxMouseEvent;
  21. class WXDLLIMPEXP_FWD_CORE wxRect;
  22. class WXDLLIMPEXP_FWD_CORE wxScrollTimer;
  23. #include "wx/timer.h"
  24. // ----------------------------------------------------------------------------
  25. // wxScrollThumb: an abstraction of scrollbar thumb
  26. // ----------------------------------------------------------------------------
  27. class WXDLLIMPEXP_CORE wxScrollThumb
  28. {
  29. public:
  30. enum Shaft
  31. {
  32. Shaft_None = -1,
  33. Shaft_Above, // or to the left of the thumb
  34. Shaft_Below, // or to the right of the thumb
  35. Shaft_Thumb, // on the thumb
  36. Shaft_Max
  37. };
  38. // ctor requires a back pointer to wxControlWithThumb
  39. wxScrollThumb(wxControlWithThumb *control);
  40. // process a mouse click: will capture the mouse if the button was pressed
  41. // on either the thumb (start dragging it then) or the shaft (start
  42. // scrolling)
  43. bool HandleMouse(const wxMouseEvent& event) const;
  44. // process a mouse move
  45. bool HandleMouseMove(const wxMouseEvent& event) const;
  46. // dtor
  47. ~wxScrollThumb();
  48. private:
  49. // do we have the mouse capture?
  50. bool HasCapture() const { return m_captureData != NULL; }
  51. // get the coord of this event in the direction we're interested in (y for
  52. // vertical shaft or x for horizontal ones)
  53. wxCoord GetMouseCoord(const wxMouseEvent& event) const;
  54. // get the position of the thumb corresponding to the current mouse
  55. // position (can only be called while we're dragging the thumb!)
  56. int GetThumbPos(const wxMouseEvent& event) const;
  57. // the main control
  58. wxControlWithThumb *m_control;
  59. // the part of it where the mouse currently is
  60. Shaft m_shaftPart;
  61. // the data for the mouse capture
  62. struct WXDLLIMPEXP_FWD_CORE wxScrollThumbCaptureData *m_captureData;
  63. };
  64. // ----------------------------------------------------------------------------
  65. // wxControlWithThumb: interface implemented by controls using wxScrollThumb
  66. // ----------------------------------------------------------------------------
  67. class WXDLLIMPEXP_CORE wxControlWithThumb
  68. {
  69. public:
  70. virtual ~wxControlWithThumb() {}
  71. // simple accessors
  72. // ----------------
  73. // get the controls window (used for mouse capturing)
  74. virtual wxWindow *GetWindow() = 0;
  75. // get the orientation of the shaft (vertical or horizontal)
  76. virtual bool IsVertical() const = 0;
  77. // geometry functions
  78. // ------------------
  79. // hit testing: return part of the shaft the point is in (or Shaft_None)
  80. virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const = 0;
  81. // get the current position in pixels of the thumb
  82. virtual wxCoord ThumbPosToPixel() const = 0;
  83. // transform from pixel offset to the thumb logical position
  84. virtual int PixelToThumbPos(wxCoord x) const = 0;
  85. // callbacks
  86. // ---------
  87. // set or clear the specified flag in the arrow state: this function is
  88. // responsible for refreshing the control
  89. virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart,
  90. int flag,
  91. bool set = true) = 0;
  92. // called when the user starts dragging the thumb
  93. virtual void OnThumbDragStart(int pos) = 0;
  94. // called while the user drags the thumb
  95. virtual void OnThumbDrag(int pos) = 0;
  96. // called when the user stops dragging the thumb
  97. virtual void OnThumbDragEnd(int pos) = 0;
  98. // called before starting to call OnPageScroll() - gives the control the
  99. // possibility to remember its current state
  100. virtual void OnPageScrollStart() = 0;
  101. // called while the user keeps the mouse pressed above/below the thumb,
  102. // return true to continue scrollign and false to stop it (e.g. because the
  103. // scrollbar has reached the top/bottom)
  104. virtual bool OnPageScroll(int pageInc) = 0;
  105. };
  106. #endif // _WX_UNIV_SCRTHUMB_H_