]> git.saurik.com Git - wxWidgets.git/blob - samples/docview/view.h
fixed the error 'macro parameters must be comma-separated' reported by running gcc...
[wxWidgets.git] / samples / docview / view.h
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 #endif // _WX_SAMPLES_DOCVIEW_VIEW_H_