1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: ecScrolledWindow class
4 // Used here to avoid any harmful changes in the equivalent wxWindows class
5 // Author: Julian Smart
8 // RCS-ID: $Id: ecscrolwin.h,v 1.2 2002/02/28 18:30:35 julians Exp $
9 // Copyright: (c) Julian Smart and Markus Holzem
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _EC_SCROLLWIN_H_
14 #define _EC_SCROLLWIN_H_
17 #pragma interface "ecscrolwin.h"
20 // ----------------------------------------------------------------------------
21 // headers and constants
22 // ----------------------------------------------------------------------------
24 #include "wx/window.h"
27 // 1 to use our own scroled window to insulate us from
30 #if wxRELEASE_NUMBER < 2302
31 #define ecUSE_OWN_SCROLLED_WINDOW 1
33 #define ecUSE_OWN_SCROLLED_WINDOW 0
36 #if !ecUSE_OWN_SCROLLED_WINDOW
37 #include "wx/scrolwin.h"
40 WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
42 // default scrolled window style
43 #ifndef wxScrolledWindowStyle
44 #define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 #if ecUSE_OWN_SCROLLED_WINDOW
53 class ecScrolledWindow : public wxPanel
57 ecScrolledWindow(wxWindow *parent,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = wxScrolledWindowStyle,
62 const wxString& name = wxPanelNameStr)
64 Create(parent, id, pos, size, style, name);
69 bool Create(wxWindow *parent,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = wxScrolledWindowStyle,
74 const wxString& name = wxPanelNameStr);
76 // Normally the ecScrolledWindow will scroll itself, but in
77 // some rare occasions you might want it to scroll another
78 // window (e.g. a child of it in order to scroll only a portion
79 // the area between the scrollbars (spreadsheet: only cell area
81 virtual void SetTargetWindow( wxWindow *target );
82 virtual wxWindow *GetTargetWindow();
84 // Number of pixels per user unit (0 or -1 for no scrollbar)
85 // Length of virtual canvas in user units
86 // Length of page in user units
87 virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
88 int noUnitsX, int noUnitsY,
89 int xPos = 0, int yPos = 0,
90 bool noRefresh = FALSE );
92 // Physically scroll the window
93 virtual void Scroll(int x_pos, int y_pos);
95 #if WXWIN_COMPATIBILITY
96 virtual void GetScrollUnitsPerPage(int *x_page, int *y_page) const;
97 virtual void CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const;
100 int GetScrollPageSize(int orient) const;
101 void SetScrollPageSize(int orient, int pageSize);
103 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
105 // Enable/disable Windows scrolling in either direction.
106 // If TRUE, wxWindows scrolls the canvas and only a bit of
107 // the canvas is invalidated; no Clear() is necessary.
108 // If FALSE, the whole canvas is invalidated and a Clear() is
109 // necessary. Disable for when the scroll increment is used
110 // to actually scroll a non-constant distance
111 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
113 // Get the view start
114 virtual void GetViewStart(int *x, int *y) const;
116 void ViewStart(int *x, int *y) const
117 { GetViewStart( x, y ); }
119 // Actual size in pixels when scrolling is taken into account
120 virtual void GetVirtualSize(int *x, int *y) const;
122 // Set the scale factor, used in PrepareDC
123 void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
124 double GetScaleX() const { return m_scaleX; }
125 double GetScaleY() const { return m_scaleY; }
127 virtual void CalcScrolledPosition(int x, int y, int *xx, int *yy) const;
128 virtual void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
130 // Adjust the scrollbars
131 virtual void AdjustScrollbars(void);
133 // Override this function to draw the graphic (or just process EVT_PAINT)
134 virtual void OnDraw(wxDC& WXUNUSED(dc)) {};
136 // Override this function if you don't want to have ecScrolledWindow
137 // automatically change the origin according to the scroll position.
138 virtual void PrepareDC(wxDC& dc);
140 // implementation from now on
141 void OnScroll(wxScrollWinEvent& event);
142 void OnSize(wxSizeEvent& event);
143 void OnPaint(wxPaintEvent& event);
144 void OnChar(wxKeyEvent& event);
146 // Calculate scroll increment
147 virtual int CalcScrollInc(wxScrollWinEvent& event);
150 wxWindow *m_targetWindow;
151 int m_xScrollPixelsPerLine;
152 int m_yScrollPixelsPerLine;
153 bool m_xScrollingEnabled;
154 bool m_yScrollingEnabled;
155 int m_xScrollPosition;
156 int m_yScrollPosition;
159 int m_xScrollLinesPerPage;
160 int m_yScrollLinesPerPage;
165 DECLARE_EVENT_TABLE()
166 DECLARE_ABSTRACT_CLASS(ecScrolledWindow)
170 class ecScrolledWindow : public wxScrolledWindow
173 ecScrolledWindow(wxWindow *parent,
175 const wxPoint& pos = wxDefaultPosition,
176 const wxSize& size = wxDefaultSize,
177 long style = wxScrolledWindowStyle,
178 const wxString& name = wxPanelNameStr)
180 Create(parent, id, pos, size, style, name);
182 DECLARE_CLASS(ecScrolledWindow)