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