scrollview.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/cocoa/private/scrollview.h
  3. // Purpose: wxWindowCocoaScrollView
  4. // Author: David Elliott
  5. // Modified by:
  6. // Created: 2008/02/14
  7. // Copyright: (c) 2003- David Elliott
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_COCOA_SCROLLVIEW_H__
  11. #define _WX_COCOA_SCROLLVIEW_H__
  12. @class NSScroller;
  13. // ========================================================================
  14. // wxWindowCocoaScrollView
  15. // ========================================================================
  16. class wxWindowCocoaScrollView: protected wxCocoaNSView
  17. {
  18. wxDECLARE_NO_COPY_CLASS(wxWindowCocoaScrollView);
  19. public:
  20. wxWindowCocoaScrollView(wxWindow *owner);
  21. virtual ~wxWindowCocoaScrollView();
  22. inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
  23. void ClientSizeToSize(int &width, int &height);
  24. void DoGetClientSize(int *x, int *y) const;
  25. void Encapsulate();
  26. void Unencapsulate();
  27. // wxWindow calls this to do the work. Note that we don't have the refresh parameter
  28. // because wxWindow handles that itself.
  29. void SetScrollbar(int orientation, int position, int thumbSize, int range);
  30. int GetScrollPos(wxOrientation orient);
  31. void SetScrollPos(wxOrientation orient, int position);
  32. int GetScrollRange(wxOrientation orient);
  33. int GetScrollThumb(wxOrientation orient);
  34. void ScrollWindow(int dx, int dy, const wxRect*);
  35. void UpdateSizes();
  36. void _wx_doScroller(NSScroller *sender);
  37. protected:
  38. wxWindowCocoa *m_owner;
  39. WX_NSScrollView m_cocoaNSScrollView;
  40. virtual void Cocoa_FrameChanged(void);
  41. virtual void Cocoa_synthesizeMouseMoved(void) {}
  42. /*!
  43. Flag as to whether we're scrolling for a native view or a custom
  44. wxWindow. This controls the scrolling behaviour. When providing
  45. scrolling for a native view we don't catch scroller action messages
  46. and thus don't send scroll events and we don't actually scroll the
  47. window when the application calls ScrollWindow.
  48. When providing scrolling for a custom wxWindow, we make the NSScroller
  49. send their action messages to us which we in turn package as wx window
  50. scrolling events. At this point, the window will not physically be
  51. scrolled. The application will most likely handle the event by calling
  52. ScrollWindow which will do the real scrolling. On the other hand,
  53. the application may instead not call ScrollWindow until some threshold
  54. is reached. This causes the window to only scroll in steps which is
  55. what, for instance, wxScrolledWindow does.
  56. */
  57. bool m_isNativeView;
  58. /*!
  59. The range as the application code wishes to see it. That is, the
  60. range from the last SetScrollbar call for the appropriate dimension.
  61. The horizontal dimension is the first [0] element and the vertical
  62. dimension the second [1] element.
  63. In wxMSW, a SCROLLINFO with nMin=0 and nMax=range-1 is used which
  64. gives exactly range possible positions so long as nPage (which is
  65. the thumb size) is less than or equal to 1.
  66. */
  67. int m_scrollRange[2];
  68. /*!
  69. The thumb size is intended to reflect the size of the visible portion
  70. of the scrolled document. As the document size increases, the thumb
  71. visible thumb size decreases. As document size decreases, the visible
  72. thumb size increases. However, the thumb size on wx is defined in
  73. terms of scroll units (which are effectively defined by the scroll
  74. range) and so increasing the number of scroll units to reflect increased
  75. document size will have the effect of decreasing the visible thumb
  76. size even though the number doesn't change.
  77. It's also important to note that subtracting the thumb size from the
  78. full range gives you the real range that can be used. Microsoft
  79. defines nPos (the current scrolling position) to be within the range
  80. from nMin to nMax - max(nPage - 1, 0). We know that wxMSW code always
  81. sets nMin = 0 and nMax = range -1. So let's algebraically reduce the
  82. definition of the maximum allowed position:
  83. Begin:
  84. = nMax - max(nPage - 1, 0)
  85. Substitute (range - 1) for nMax and thumbSize for nPage:
  86. = range - 1 - max(thumbSize - 1, 0)
  87. Add one inside the max conditional and subtract one outside of it:
  88. = range - 1 - (max(thumbSize - 1 + 1, 1) - 1)
  89. Reduce some constants:
  90. = range - 1 - (max(thumbSize, 1) - 1)
  91. Distribute the negative across the parenthesis:
  92. = range - 1 - max(thumbSize, 1) + 1
  93. Reduce the constants:
  94. = range - max(thumbSize, 1)
  95. Also keep in mind that thumbSize may never be greater than range but
  96. can be equal to it. Thus for the smallest possible thumbSize there
  97. are exactly range possible scroll positions (numbered from 0 to
  98. range - 1) and for the largest possible thumbSize there is exactly
  99. one possible scroll position (numbered 0).
  100. */
  101. int m_scrollThumb[2];
  102. /*!
  103. The origin of the virtual coordinate space expressed in terms of client
  104. coordinates. Starts at (0,0) and each call to ScrollWindow accumulates
  105. into it. Thus if the user scrolls the window right (thus causing the
  106. contents to move left with respect to the client origin, the
  107. application code (typically wxScrolledWindow) will be called with
  108. dx of -something, for example -20. This is added to m_virtualOrigin
  109. and thus m_virtualOrigin will be (-20,0) in this example.
  110. */
  111. wxPoint m_virtualOrigin;
  112. private:
  113. wxWindowCocoaScrollView();
  114. };
  115. #endif //ndef _WX_COCOA_SCROLLVIEW_H__