![]() |
wxIScan
|
00001 ///////////////////////////////////////////////////////////////////////////// 00002 // Project: wxIView 00003 // Purpose: Complex wxWidgets sample 00004 // Name: wxiviewcanvas.h 00005 // Author: Daniel Nell 00006 // Created: 2005/10/18 00007 // Copyright: (c) Daniel Nell 00008 // License: wxWindows license 00009 // Modified by: 00010 ///////////////////////////////////////////////////////////////////////////// 00011 00012 #ifndef __WXIVIEWCANVAS_H 00013 #define __WXIVIEWCANVAS_H 00014 00015 ///////////////////////////////////////////////////////////////////////////// 00016 // Constants 00017 // 00018 #define WXIVIEWCANVASDELAY 50 00019 00020 00021 ///////////////////////////////////////////////////////////////////////////// 00022 // ... 00023 // 00024 BEGIN_DECLARE_EVENT_TYPES() 00025 DECLARE_LOCAL_EVENT_TYPE( wxEVT_IVIEWCANVASSIZE, 0 ) 00026 DECLARE_LOCAL_EVENT_TYPE( wxEVT_IVIEWCANVASSELECTED, 0 ) 00027 END_DECLARE_EVENT_TYPES() 00028 00029 00030 ///////////////////////////////////////////////////////////////////////////// 00031 // Class wxIViewCanvasSizeEvent 00032 // 00033 /// \brief The canvas size changing event. 00034 /// 00035 /// ... 00036 class wxIViewCanvasSizeEvent : public wxEvent 00037 { 00038 public: 00039 /// Constructor 00040 wxIViewCanvasSizeEvent( wxEventType oType= wxEVT_IVIEWCANVASSIZE ) 00041 : wxEvent( 0, oType ) 00042 { 00043 // Propagate event to the next event handling window. 00044 m_propagationLevel= wxEVENT_PROPAGATE_MAX; 00045 } 00046 00047 /// Return a copy ot this event. 00048 wxEvent *Clone() const 00049 { 00050 return new wxIViewCanvasSizeEvent( *this ); 00051 } 00052 }; 00053 00054 typedef void (wxEvtHandler::*wxIViewCanvasSizeEventEventFunction)( wxIViewCanvasSizeEvent& ); 00055 00056 #define wxIViewCanvasSizeEventEventHandler(func) \ 00057 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( wxIViewCanvasSizeEventEventFunction, &func ) 00058 00059 #define EVT_IVIEWCANVASSIZE(func) \ 00060 wx__DECLARE_EVT0( wxEVT_IVIEWCANVASSIZE, wxIViewCanvasSizeEventEventHandler( func ) ) 00061 00062 00063 ///////////////////////////////////////////////////////////////////////////// 00064 // Class wxIViewCanvasSelectedEvent 00065 // 00066 /// \brief The canvas selection event. 00067 /// 00068 /// ... 00069 class wxIViewCanvasSelectedEvent : public wxEvent 00070 { 00071 public: 00072 /// Constructor 00073 wxIViewCanvasSelectedEvent( wxEventType oType= wxEVT_IVIEWCANVASSELECTED ) 00074 : wxEvent( 0, oType ), m_bShift( false ), m_bAlt( false ), m_bCtrl( false ), m_bMeta( false ) 00075 { 00076 // Propagate event to the next event handling window. 00077 m_propagationLevel= wxEVENT_PROPAGATE_MAX; 00078 } 00079 00080 /// Return a copy ot this event. 00081 wxEvent *Clone() const 00082 { 00083 return new wxIViewCanvasSelectedEvent( *this ); 00084 } 00085 00086 public: 00087 bool m_bShift; ///< Was the SHIFT key pressed while selecting? 00088 bool m_bAlt; ///< Was the ALT key pressed while selecting? 00089 bool m_bCtrl; ///< Was the CTRL key pressed while selecting? 00090 bool m_bMeta; ///< Was the META key pressed while selecting? 00091 wxRect m_oSelection; ///< Holds the selection. 00092 }; 00093 00094 typedef void (wxEvtHandler::*wxIViewCanvasSelectedEventEventFunction)( wxIViewCanvasSelectedEvent& ); 00095 00096 #define wxIViewCanvasSelectedEventEventHandler(func) \ 00097 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( wxIViewCanvasSelectedEventEventFunction, &func ) 00098 00099 #define EVT_IVIEWCANVASSELECTED(func) \ 00100 wx__DECLARE_EVT0( wxEVT_IVIEWCANVASSELECTED, wxIViewCanvasSelectedEventEventHandler( func ) ) 00101 00102 00103 ///////////////////////////////////////////////////////////////////////////// 00104 // class wxIViewCanvas 00105 // 00106 /// \brief The canvas window. 00107 /// 00108 /// ... 00109 class wxIViewCanvas: public wxScrolledWindow 00110 { 00111 public: 00112 /// \brief Standard constructor 00113 /// 00114 /// \param poParent a pointer to the dialog windows's parent window. 00115 /// \param nId the window id, default: 1 00116 /// \param oPos the window position, default: wxDefaultPosition 00117 /// \param oSize the window size, default: wxDefaultSize 00118 /// \param nStyle window style (default: wxHSCROLL | wxVSCROLL | wxSUNKEN_BORDER) 00119 /// \param strName class name (default: wxT( "wxIViewCanvas" )) 00120 wxIViewCanvas( wxWindow *poParent, 00121 wxWindowID nId= wxID_ANY, 00122 const wxPoint &oPos= wxDefaultPosition, 00123 const wxSize &oSize= wxDefaultSize, 00124 long nStyle= wxHSCROLL | wxVSCROLL | wxSUNKEN_BORDER, 00125 const wxString& strName= wxT( "wxIViewCanvas" ) 00126 ); 00127 00128 /// Virtual destructor 00129 virtual ~wxIViewCanvas(){} 00130 00131 // Event handlers 00132 // 00133 /// \brief Handler for window (re)painting. 00134 /// 00135 /// Creates and prepares a device context and calls Paint( wxDC& oDc ). 00136 void OnPaint( wxPaintEvent &oEvent ); 00137 00138 /// Repaints the image (using an internal bitmap). 00139 virtual void Paint( wxDC& oDc ); 00140 00141 /// Returns the internal bitmap. 00142 virtual wxBitmap& GetBitmap(){ return m_oBitmap; } 00143 00144 /// Sets the internal bitmap. 00145 virtual void SetBitmap( const wxBitmap& oBitmap ); 00146 00147 /// Handle resizing. 00148 void OnSize( wxSizeEvent& oEvent ); 00149 00150 /// Handle timer events. 00151 void OnTimer( wxTimerEvent& oEvent ); 00152 00153 /// \brief Handle mouse events (non virtual part, only calls the 00154 /// virtual part, see OnMouse() instead). 00155 /// 00156 /// \param oEvent Contains the mouse event to handle. 00157 void OnMouse_( wxMouseEvent& oEvent ){ OnMouse( oEvent ); } 00158 00159 /// \brief Handle mouse events (the virtual, customizable part). 00160 /// 00161 /// \param oEvent Contains the mouse event to handle. 00162 /// 00163 /// OnMouse() handles the following events depending on the 00164 /// options set by a previous call to SetOptions(): 00165 /// - Scrolling while moving the mouse keeping the right mouse 00166 /// button pressed (wxICANVAS_MOUSE_SCROLL). 00167 /// - Scrolling vertically using the mouse wheel. 00168 /// (wxICANVAS_MOUSEWHEEL_SCROLL) 00169 /// - Setting a selection rectangle by using a rubber band while 00170 /// keeping the left mouse button pressed. 00171 /// (wxICANVAS_MOUSE_SELECTION) 00172 virtual void OnMouse( wxMouseEvent& oEvent ); 00173 00174 /// Set options for the wxIViewCanvas. 00175 virtual void SetOptions( int nOptions){ m_nOptions= nOptions; } 00176 00177 /// Clears up (deletes) the current selection. 00178 virtual void ClearSelection() 00179 { 00180 // RefreshRect( m_oSelection ); 00181 Refresh(); 00182 m_oSelection= wxRect( -1, -1, 0, 0 ); 00183 } 00184 00185 /// Gets the selection rectangle. 00186 virtual wxRect& GetSelection(){ return m_oSelection; }; 00187 00188 /// Checks if a selection area exists. 00189 virtual bool IsSelected() 00190 { 00191 return ( m_oSelection.x >= 0 ) 00192 && ( m_oSelection.y >= 0 ) 00193 && ( m_oSelection.width > 1 ) 00194 && ( m_oSelection.height > 1 ); 00195 } 00196 00197 public: 00198 /// wxIViewCanvas options (use SetOptions() function to set). 00199 enum 00200 { 00201 wxICANVAS_MOUSE_SELECTION= 1, ///< Enable selecting a rectangular image region. (Default is OFF.) 00202 wxICANVAS_MOUSE_SCROLL= 2, ///< Enable scrolling following mouse cursor on right mouse key pressed. (Default is ON.) 00203 wxICANVAS_MOUSEWHEEL_SCROLL= 4 ///< Enable selecting a rectangular image region. (Default is ON) 00204 }; 00205 00206 protected: 00207 // Member variables 00208 int m_nOptions; ///< Holds extended style info (options). 00209 wxBitmap m_oBitmap; ///< Internal bitmap object for repainting. 00210 wxTimer m_oTimer; ///< Timer for delay before sending resizing event to parent window. 00211 wxPoint m_oMousePosBegin; ///< Save the starting point of a mouse movement. 00212 wxPoint m_oMousePosOld; ///< Save former mouse position. 00213 wxRect m_oSelection; ///< Holds the selection. 00214 00215 private: 00216 // Any class wishing to process wxWindows events must use this macro 00217 DECLARE_EVENT_TABLE() 00218 }; 00219 00220 #endif // __WXIVIEWCANVAS_H