Removed WXWIN_COMPATIBILITY_2_2 together with code guarded by it.
[wxWidgets.git] / include / wx / gtk / scrolwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/scrolwin.h
3 // Purpose: wxScrolledWindow class
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GTK_SCROLLWIN_H_
13 #define _WX_GTK_SCROLLWIN_H_
14
15 // ----------------------------------------------------------------------------
16 // headers and constants
17 // ----------------------------------------------------------------------------
18
19 #include "wx/window.h"
20 #include "wx/panel.h"
21
22 WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
23
24 // default scrolled window style
25 #ifndef wxScrolledWindowStyle
26 #define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
27 #endif
28
29 // ----------------------------------------------------------------------------
30 // wxScrolledWindow
31 // ----------------------------------------------------------------------------
32
33 class WXDLLEXPORT wxScrolledWindow : public wxPanel
34 {
35 public:
36 wxScrolledWindow()
37 { Init(); }
38
39 wxScrolledWindow(wxWindow *parent,
40 wxWindowID id = -1,
41 const wxPoint& pos = wxDefaultPosition,
42 const wxSize& size = wxDefaultSize,
43 long style = wxScrolledWindowStyle,
44 const wxString& name = wxPanelNameStr)
45 { Create(parent, id, pos, size, style, name); }
46
47 void Init();
48
49 bool Create(wxWindow *parent,
50 wxWindowID id,
51 const wxPoint& pos = wxDefaultPosition,
52 const wxSize& size = wxDefaultSize,
53 long style = wxScrolledWindowStyle,
54 const wxString& name = wxPanelNameStr);
55
56 // Normally the wxScrolledWindow will scroll itself, but in
57 // some rare occasions you might want it to scroll another
58 // window (e.g. a child of it in order to scroll only a portion
59 // the area between the scrollbars (spreadsheet: only cell area
60 // will move).
61 virtual void SetTargetWindow( wxWindow *target, bool pushEventHandler = FALSE );
62 virtual wxWindow *GetTargetWindow() const;
63
64 // Set the scrolled area of the window.
65 virtual void DoSetVirtualSize( int x, int y );
66
67 // wxWindow's GetBestVirtualSize returns the actual window size,
68 // whereas we want to return the virtual size
69 virtual wxSize GetBestVirtualSize() const;
70
71 // Return the size best suited for the current window
72 // (this isn't a virtual size, this is a sensible size for the window)
73 virtual wxSize DoGetBestSize() const;
74
75 // Set the x, y scrolling increments.
76 void SetScrollRate( int xstep, int ystep );
77
78 // Number of pixels per user unit (0 or -1 for no scrollbar)
79 // Length of virtual canvas in user units
80 // Length of page in user units
81 // Default action is to set the virtual size and alter scrollbars
82 // accordingly.
83 virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
84 int noUnitsX, int noUnitsY,
85 int xPos = 0, int yPos = 0,
86 bool noRefresh = FALSE );
87
88 // Physically scroll the window
89 virtual void Scroll(int x_pos, int y_pos);
90
91 int GetScrollPageSize(int orient) const;
92 void SetScrollPageSize(int orient, int pageSize);
93
94 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
95
96 // Enable/disable Windows scrolling in either direction.
97 // If TRUE, wxWidgets scrolls the canvas and only a bit of
98 // the canvas is invalidated; no Clear() is necessary.
99 // If FALSE, the whole canvas is invalidated and a Clear() is
100 // necessary. Disable for when the scroll increment is used
101 // to actually scroll a non-constant distance
102 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
103
104 // Get the view start
105 virtual void GetViewStart(int *x, int *y) const;
106
107 // translate between scrolled and unscrolled coordinates
108 void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
109 { DoCalcScrolledPosition(x, y, xx, yy); }
110 wxPoint CalcScrolledPosition(const wxPoint& pt) const
111 {
112 wxPoint p2;
113 DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
114 return p2;
115 }
116
117 void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
118 { DoCalcUnscrolledPosition(x, y, xx, yy); }
119 wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
120 {
121 wxPoint p2;
122 DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
123 return p2;
124 }
125
126 virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
127 virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
128
129 // Override this function to draw the graphic (or just process EVT_PAINT)
130 virtual void OnDraw(wxDC& WXUNUSED(dc)) {}
131
132 // Override this function if you don't want to have wxScrolledWindow
133 // automatically change the origin according to the scroll position.
134 void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
135
136 // lay out the window and its children
137 virtual bool Layout();
138
139 // Adjust the scrollbars
140 virtual void AdjustScrollbars();
141
142 // Set the scale factor, used in PrepareDC
143 void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
144 double GetScaleX() const { return m_scaleX; }
145 double GetScaleY() const { return m_scaleY; }
146
147 // implementation from now on
148 void OnScroll(wxScrollWinEvent& event);
149 void OnSize(wxSizeEvent& event);
150 void OnPaint(wxPaintEvent& event);
151 void OnChar(wxKeyEvent& event);
152
153 void GtkVScroll( float value, unsigned int scroll_type );
154 void GtkHScroll( float value, unsigned int scroll_type );
155 void GtkVConnectEvent();
156 void GtkHConnectEvent();
157 void GtkVDisconnectEvent();
158 void GtkHDisconnectEvent();
159
160 // Calculate scroll increment
161 virtual int CalcScrollInc(wxScrollWinEvent& event);
162
163 // Overridden from wxWidgets due callback being static
164 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
165
166 virtual void DoPrepareDC(wxDC& dc);
167
168 protected:
169 wxWindow *m_targetWindow;
170 int m_xScrollPixelsPerLine;
171 int m_yScrollPixelsPerLine;
172 bool m_xScrollingEnabled;
173 bool m_yScrollingEnabled;
174
175 // FIXME: these next four members are duplicated in the GtkAdjustment
176 // members of wxWindow. Can they be safely removed from here?
177
178 int m_xScrollPosition;
179 int m_yScrollPosition;
180 int m_xScrollLinesPerPage;
181 int m_yScrollLinesPerPage;
182
183 double m_scaleY,m_scaleX;
184
185 private:
186 DECLARE_EVENT_TABLE()
187 DECLARE_DYNAMIC_CLASS(wxScrolledWindow)
188 };
189
190 #endif
191 // _WX_GTK_SCROLLWIN_H_
192
193 // vi:sts=4:sw=4:et