1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/scrolwin.h
3 // Purpose: wxScrolledWindow class
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GTK_SCROLLWIN_H_
13 #define _WX_GTK_SCROLLWIN_H_
15 // ----------------------------------------------------------------------------
16 // headers and constants
17 // ----------------------------------------------------------------------------
19 #include "wx/window.h"
22 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
24 // default scrolled window style
25 #ifndef wxScrolledWindowStyle
26 #define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class WXDLLEXPORT wxScrolledWindow
: public wxPanel
39 wxScrolledWindow(wxWindow
*parent
,
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
); }
49 bool Create(wxWindow
*parent
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
53 long style
= wxScrolledWindowStyle
,
54 const wxString
& name
= wxPanelNameStr
);
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
61 virtual void SetTargetWindow( wxWindow
*target
, bool pushEventHandler
= FALSE
);
62 virtual wxWindow
*GetTargetWindow() const;
64 // Set the scrolled area of the window.
65 virtual void DoSetVirtualSize( int x
, int y
);
67 // wxWindow's GetBestVirtualSize returns the actual window size,
68 // whereas we want to return the virtual size
69 virtual wxSize
GetBestVirtualSize() const;
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;
75 // Set the x, y scrolling increments.
76 void SetScrollRate( int xstep
, int ystep
);
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
83 virtual void SetScrollbars(int pixelsPerUnitX
, int pixelsPerUnitY
,
84 int noUnitsX
, int noUnitsY
,
85 int xPos
= 0, int yPos
= 0,
86 bool noRefresh
= FALSE
);
88 // Physically scroll the window
89 virtual void Scroll(int x_pos
, int y_pos
);
91 int GetScrollPageSize(int orient
) const;
92 void SetScrollPageSize(int orient
, int pageSize
);
94 virtual void GetScrollPixelsPerUnit(int *x_unit
, int *y_unit
) const;
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
);
104 // Get the view start
105 virtual void GetViewStart(int *x
, int *y
) const;
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
113 DoCalcScrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
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
122 DoCalcUnscrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
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;
129 // Override this function to draw the graphic (or just process EVT_PAINT)
130 virtual void OnDraw(wxDC
& WXUNUSED(dc
)) {}
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
); }
136 // lay out the window and its children
137 virtual bool Layout();
139 // Adjust the scrollbars
140 virtual void AdjustScrollbars();
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
; }
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
);
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();
160 // Calculate scroll increment
161 virtual int CalcScrollInc(wxScrollWinEvent
& event
);
163 // Overridden from wxWidgets due callback being static
164 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
166 #if WXWIN_COMPATIBILITY_2_2
168 void ViewStart(int *x
, int *y
) const { GetViewStart( x
, y
); }
169 #endif // WXWIN_COMPATIBILITY_2_2
171 virtual void DoPrepareDC(wxDC
& dc
);
174 wxWindow
*m_targetWindow
;
175 int m_xScrollPixelsPerLine
;
176 int m_yScrollPixelsPerLine
;
177 bool m_xScrollingEnabled
;
178 bool m_yScrollingEnabled
;
180 // FIXME: these next four members are duplicated in the GtkAdjustment
181 // members of wxWindow. Can they be safely removed from here?
183 int m_xScrollPosition
;
184 int m_yScrollPosition
;
185 int m_xScrollLinesPerPage
;
186 int m_yScrollLinesPerPage
;
188 double m_scaleY
,m_scaleX
;
191 DECLARE_EVENT_TABLE()
192 DECLARE_DYNAMIC_CLASS(wxScrolledWindow
)
196 // _WX_GTK_SCROLLWIN_H_