]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: samples/docview/view.h | |
3 | // Purpose: View classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Julian Smart | |
9 | // (c) 2008 Vadim Zeitlin | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifndef _WX_SAMPLES_DOCVIEW_VIEW_H_ | |
14 | #define _WX_SAMPLES_DOCVIEW_VIEW_H_ | |
15 | ||
16 | #include "wx/docview.h" | |
17 | ||
18 | // ---------------------------------------------------------------------------- | |
19 | // Drawing view classes | |
20 | // ---------------------------------------------------------------------------- | |
21 | ||
22 | // The window showing the drawing itself | |
23 | class MyCanvas : public wxScrolledWindow | |
24 | { | |
25 | public: | |
26 | // view may be NULL if we're not associated with one yet, but parent must | |
27 | // be a valid pointer | |
28 | MyCanvas(wxView *view, wxWindow *parent); | |
29 | virtual ~MyCanvas(); | |
30 | ||
31 | virtual void OnDraw(wxDC& dc); | |
32 | ||
33 | // in a normal multiple document application a canvas is associated with | |
34 | // one view from the beginning until the end, but to support the single | |
35 | // document mode in which all documents reuse the same MyApp::GetCanvas() | |
36 | // we need to allow switching the canvas from one view to another one | |
37 | ||
38 | void SetView(wxView *view) | |
39 | { | |
40 | wxASSERT_MSG( !m_view, "shouldn't be already associated with a view" ); | |
41 | ||
42 | m_view = view; | |
43 | } | |
44 | ||
45 | void ResetView() | |
46 | { | |
47 | wxASSERT_MSG( m_view, "should be associated with a view" ); | |
48 | ||
49 | m_view = NULL; | |
50 | } | |
51 | ||
52 | private: | |
53 | void OnMouseEvent(wxMouseEvent& event); | |
54 | ||
55 | wxView *m_view; | |
56 | ||
57 | // the segment being currently drawn or NULL if none | |
58 | DoodleSegment *m_currentSegment; | |
59 | ||
60 | // the last mouse press position | |
61 | wxPoint m_lastMousePos; | |
62 | ||
63 | DECLARE_EVENT_TABLE() | |
64 | }; | |
65 | ||
66 | // The view using MyCanvas to show its contents | |
67 | class DrawingView : public wxView | |
68 | { | |
69 | public: | |
70 | DrawingView() { m_canvas = NULL; m_frame = NULL; } | |
71 | ||
72 | virtual bool OnCreate(wxDocument *doc, long flags); | |
73 | virtual void OnDraw(wxDC *dc); | |
74 | virtual void OnUpdate(wxView *sender, wxObject *hint = NULL); | |
75 | virtual bool OnClose(bool deleteWindow = true); | |
76 | ||
77 | DrawingDocument* GetDocument(); | |
78 | ||
79 | private: | |
80 | void OnCut(wxCommandEvent& event); | |
81 | ||
82 | wxFrame *m_frame; | |
83 | MyCanvas *m_canvas; | |
84 | ||
85 | DECLARE_EVENT_TABLE() | |
86 | DECLARE_DYNAMIC_CLASS(DrawingView) | |
87 | }; | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // Text view classes | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | // The view using a standard wxTextCtrl to show its contents | |
94 | class TextEditView : public wxView | |
95 | { | |
96 | public: | |
97 | TextEditView() : wxView() { m_frame = NULL; m_text = NULL; } | |
98 | ||
99 | virtual bool OnCreate(wxDocument *doc, long flags); | |
100 | virtual void OnDraw(wxDC *dc); | |
101 | virtual bool OnClose(bool deleteWindow = true); | |
102 | ||
103 | wxTextCtrl *GetText() const { return m_text; } | |
104 | ||
105 | private: | |
106 | void OnCopy(wxCommandEvent& WXUNUSED(event)) { m_text->Copy(); } | |
107 | void OnPaste(wxCommandEvent& WXUNUSED(event)) { m_text->Paste(); } | |
108 | void OnSelectAll(wxCommandEvent& WXUNUSED(event)) { m_text->SelectAll(); } | |
109 | ||
110 | wxFrame *m_frame; | |
111 | wxTextCtrl *m_text; | |
112 | ||
113 | DECLARE_EVENT_TABLE() | |
114 | DECLARE_DYNAMIC_CLASS(TextEditView) | |
115 | }; | |
116 | ||
117 | // ---------------------------------------------------------------------------- | |
118 | // ImageCanvas | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | class ImageCanvas : public wxScrolledWindow | |
122 | { | |
123 | public: | |
124 | ImageCanvas(wxView*, wxWindow* parent); | |
125 | ||
126 | virtual void OnDraw(wxDC& dc); | |
127 | ||
128 | // in a normal multiple document application a canvas is associated with | |
129 | // one view from the beginning until the end, but to support the single | |
130 | // document mode in which all documents reuse the same MyApp::GetCanvas() | |
131 | // we need to allow switching the canvas from one view to another one | |
132 | ||
133 | void SetView(wxView* view) | |
134 | { | |
135 | wxASSERT_MSG( !m_view, "shouldn't be already associated with a view" ); | |
136 | ||
137 | m_view = view; | |
138 | } | |
139 | ||
140 | void ResetView() | |
141 | { | |
142 | wxASSERT_MSG( m_view, "should be associated with a view" ); | |
143 | ||
144 | m_view = NULL; | |
145 | } | |
146 | ||
147 | private: | |
148 | wxView *m_view; | |
149 | }; | |
150 | ||
151 | // ---------------------------------------------------------------------------- | |
152 | // ImageView | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
155 | class ImageView : public wxView | |
156 | { | |
157 | public: | |
158 | ImageView() : wxView(), m_frame(NULL) {} | |
159 | ||
160 | virtual bool OnCreate(wxDocument*, long flags); | |
161 | virtual void OnDraw(wxDC*); | |
162 | virtual bool OnClose(bool deleteWindow = true); | |
163 | virtual void OnUpdate(wxView *sender, wxObject *hint = NULL); | |
164 | ||
165 | ImageDocument* GetDocument(); | |
166 | ||
167 | private: | |
168 | wxFrame* m_frame; | |
169 | ImageCanvas* m_canvas; | |
170 | ||
171 | DECLARE_DYNAMIC_CLASS(ImageView) | |
172 | }; | |
173 | ||
174 | #endif // _WX_SAMPLES_DOCVIEW_VIEW_H_ |