]>
Commit | Line | Data |
---|---|---|
457814b5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
2d1df0fc | 2 | // Name: samples/docview/view.h |
457814b5 JS |
3 | // Purpose: View classes |
4 | // Author: Julian Smart | |
2d1df0fc | 5 | // Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup |
457814b5 JS |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
2d1df0fc VZ |
8 | // Copyright: (c) 1998 Julian Smart |
9 | // (c) 2008 Vadim Zeitlin | |
2f6c54eb | 10 | // Licence: wxWindows license |
457814b5 JS |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
2d1df0fc VZ |
13 | #ifndef _WX_SAMPLES_DOCVIEW_VIEW_H_ |
14 | #define _WX_SAMPLES_DOCVIEW_VIEW_H_ | |
457814b5 JS |
15 | |
16 | #include "wx/docview.h" | |
17 | ||
2d1df0fc VZ |
18 | // ---------------------------------------------------------------------------- |
19 | // Drawing view classes | |
20 | // ---------------------------------------------------------------------------- | |
21 | ||
22 | // The window showing the drawing itself | |
6bdf5153 | 23 | class MyCanvas : public wxScrolledWindow |
457814b5 | 24 | { |
f6bcfd97 | 25 | public: |
2d1df0fc VZ |
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(); | |
6bdf5153 | 30 | |
457814b5 | 31 | virtual void OnDraw(wxDC& dc); |
6bdf5153 | 32 | |
2d1df0fc VZ |
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: | |
457814b5 | 53 | void OnMouseEvent(wxMouseEvent& event); |
457814b5 | 54 | |
2d1df0fc VZ |
55 | wxView *m_view; |
56 | ||
57 | // the segment being currently drawn or NULL if none | |
58 | DoodleSegment *m_currentSegment; | |
6bdf5153 | 59 | |
2d1df0fc VZ |
60 | // the last mouse press position |
61 | wxPoint m_lastMousePos; | |
62 | ||
63 | DECLARE_EVENT_TABLE() | |
457814b5 JS |
64 | }; |
65 | ||
2d1df0fc | 66 | // The view using MyCanvas to show its contents |
6bdf5153 | 67 | class DrawingView : public wxView |
457814b5 | 68 | { |
f6bcfd97 | 69 | public: |
2d1df0fc | 70 | DrawingView() { m_canvas = NULL; m_frame = NULL; } |
6bdf5153 VZ |
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 | ||
2d1df0fc | 79 | private: |
f6bcfd97 | 80 | void OnCut(wxCommandEvent& event); |
6bdf5153 | 81 | |
2d1df0fc VZ |
82 | wxFrame *m_frame; |
83 | MyCanvas *m_canvas; | |
84 | ||
f6bcfd97 | 85 | DECLARE_EVENT_TABLE() |
6bdf5153 | 86 | DECLARE_DYNAMIC_CLASS(DrawingView) |
457814b5 JS |
87 | }; |
88 | ||
2d1df0fc VZ |
89 | // ---------------------------------------------------------------------------- |
90 | // Text view classes | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | // The view using a standard wxTextCtrl to show its contents | |
6bdf5153 | 94 | class TextEditView : public wxView |
457814b5 | 95 | { |
f6bcfd97 | 96 | public: |
2d1df0fc | 97 | TextEditView() : wxView() { m_frame = NULL; m_text = NULL; } |
6bdf5153 VZ |
98 | |
99 | virtual bool OnCreate(wxDocument *doc, long flags); | |
100 | virtual void OnDraw(wxDC *dc); | |
6bdf5153 | 101 | virtual bool OnClose(bool deleteWindow = true); |
6bdf5153 | 102 | |
2d1df0fc VZ |
103 | wxTextCtrl *GetText() const { return m_text; } |
104 | ||
6bdf5153 | 105 | private: |
2d1df0fc VZ |
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; | |
4e553af1 VZ |
112 | |
113 | DECLARE_EVENT_TABLE() | |
6bdf5153 | 114 | DECLARE_DYNAMIC_CLASS(TextEditView) |
457814b5 JS |
115 | }; |
116 | ||
2d1df0fc | 117 | #endif // _WX_SAMPLES_DOCVIEW_VIEW_H_ |