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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "scrolwin.h"
19 // ----------------------------------------------------------------------------
20 // headers and constants
21 // ----------------------------------------------------------------------------
23 #include "wx/window.h"
26 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
28 // default scrolled window style
29 #ifndef wxScrolledWindowStyle
30 #define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxScrolledWindow
: public wxPanel
43 wxScrolledWindow(wxWindow
*parent
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
,
47 long style
= wxScrolledWindowStyle
,
48 const wxString
& name
= wxPanelNameStr
)
49 { Create(parent
, id
, pos
, size
, style
, name
); }
53 bool Create(wxWindow
*parent
,
55 const wxPoint
& pos
= wxDefaultPosition
,
56 const wxSize
& size
= wxDefaultSize
,
57 long style
= wxScrolledWindowStyle
,
58 const wxString
& name
= wxPanelNameStr
);
60 // Normally the wxScrolledWindow will scroll itself, but in
61 // some rare occasions you might want it to scroll another
62 // window (e.g. a child of it in order to scroll only a portion
63 // the area between the scrollbars (spreadsheet: only cell area
65 virtual void SetTargetWindow( wxWindow
*target
, bool pushEventHandler
= FALSE
);
66 virtual wxWindow
*GetTargetWindow() const;
68 // Set the scrolled area of the window.
69 virtual void DoSetVirtualSize( int x
, int y
);
71 // Set the x, y scrolling increments.
72 void SetScrollRate( int xstep
, int ystep
);
74 // Number of pixels per user unit (0 or -1 for no scrollbar)
75 // Length of virtual canvas in user units
76 // Length of page in user units
77 // Default action is to set the virtual size and alter scrollbars
79 virtual void SetScrollbars(int pixelsPerUnitX
, int pixelsPerUnitY
,
80 int noUnitsX
, int noUnitsY
,
81 int xPos
= 0, int yPos
= 0,
82 bool noRefresh
= FALSE
);
84 // Physically scroll the window
85 virtual void Scroll(int x_pos
, int y_pos
);
87 int GetScrollPageSize(int orient
) const;
88 void SetScrollPageSize(int orient
, int pageSize
);
90 virtual void GetScrollPixelsPerUnit(int *x_unit
, int *y_unit
) const;
92 // Enable/disable Windows scrolling in either direction.
93 // If TRUE, wxWindows scrolls the canvas and only a bit of
94 // the canvas is invalidated; no Clear() is necessary.
95 // If FALSE, the whole canvas is invalidated and a Clear() is
96 // necessary. Disable for when the scroll increment is used
97 // to actually scroll a non-constant distance
98 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
100 // Get the view start
101 virtual void GetViewStart(int *x
, int *y
) const;
103 // translate between scrolled and unscrolled coordinates
104 void CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
105 { DoCalcScrolledPosition(x
, y
, xx
, yy
); }
106 wxPoint
CalcScrolledPosition(const wxPoint
& pt
) const
109 DoCalcScrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
113 void CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
114 { DoCalcUnscrolledPosition(x
, y
, xx
, yy
); }
115 wxPoint
CalcUnscrolledPosition(const wxPoint
& pt
) const
118 DoCalcUnscrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
122 virtual void DoCalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const;
123 virtual void DoCalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const;
125 // Override this function to draw the graphic (or just process EVT_PAINT)
126 virtual void OnDraw(wxDC
& WXUNUSED(dc
)) {}
128 // Override this function if you don't want to have wxScrolledWindow
129 // automatically change the origin according to the scroll position.
130 virtual void PrepareDC(wxDC
& dc
);
132 // lay out the window and its children
133 virtual bool Layout();
135 // Adjust the scrollbars
136 virtual void AdjustScrollbars();
138 // Set the scale factor, used in PrepareDC
139 void SetScale(double xs
, double ys
) { m_scaleX
= xs
; m_scaleY
= ys
; }
140 double GetScaleX() const { return m_scaleX
; }
141 double GetScaleY() const { return m_scaleY
; }
143 // implementation from now on
144 void OnScroll(wxScrollWinEvent
& event
);
145 void OnSize(wxSizeEvent
& event
);
146 void OnPaint(wxPaintEvent
& event
);
147 void OnChar(wxKeyEvent
& event
);
149 void GtkVScroll( float value
, unsigned int scroll_type
);
150 void GtkHScroll( float value
, unsigned int scroll_type
);
151 void GtkVConnectEvent();
152 void GtkHConnectEvent();
153 void GtkVDisconnectEvent();
154 void GtkHDisconnectEvent();
156 // Calculate scroll increment
157 virtual int CalcScrollInc(wxScrollWinEvent
& event
);
159 // Overridden from wxWindows due callback being static
160 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
162 #if WXWIN_COMPATIBILITY_2_2
164 void ViewStart(int *x
, int *y
) const { GetViewStart( x
, y
); }
165 #endif // WXWIN_COMPATIBILITY_2_2
168 wxWindow
*m_targetWindow
;
169 int m_xScrollPixelsPerLine
;
170 int m_yScrollPixelsPerLine
;
171 bool m_xScrollingEnabled
;
172 bool m_yScrollingEnabled
;
174 // FIXME: these next four members are duplicated in the GtkAdjustment
175 // members of wxWindow. Can they be safely removed from here?
177 int m_xScrollPosition
;
178 int m_yScrollPosition
;
179 int m_xScrollLinesPerPage
;
180 int m_yScrollLinesPerPage
;
182 double m_scaleY
,m_scaleX
;
185 DECLARE_EVENT_TABLE()
186 DECLARE_ABSTRACT_CLASS(wxScrolledWindow
)
190 // _WX_GTK_SCROLLWIN_H_