]> git.saurik.com Git - wxWidgets.git/blame - samples/docview/doc.h
fix vertical mouse wheel event rotation value, sign was reversed in r74805
[wxWidgets.git] / samples / docview / doc.h
CommitLineData
457814b5 1/////////////////////////////////////////////////////////////////////////////
2d1df0fc 2// Name: samples/docview/doc.h
457814b5
JS
3// Purpose: Document classes
4// Author: Julian Smart
2d1df0fc 5// Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup
457814b5 6// Created: 04/01/98
2d1df0fc
VZ
7// Copyright: (c) 1998 Julian Smart
8// (c) 2008 Vadim Zeitlin
526954c5 9// Licence: wxWindows licence
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
2d1df0fc
VZ
12#ifndef _WX_SAMPLES_DOCVIEW_DOC_H_
13#define _WX_SAMPLES_DOCVIEW_DOC_H_
457814b5
JS
14
15#include "wx/docview.h"
606b005f 16#include "wx/cmdproc.h"
2d1df0fc 17#include "wx/vector.h"
f37f49b6 18#include "wx/image.h"
2d1df0fc
VZ
19
20// This sample is written to build both with wxUSE_STD_IOSTREAM==0 and 1, which
21// somewhat complicates its code but is necessary in order to support building
22// it under all platforms and in all build configurations
23//
24// In your own code you would normally use std::stream classes only and so
25// wouldn't need these typedefs
26#if wxUSE_STD_IOSTREAM
27 typedef wxSTD istream DocumentIstream;
28 typedef wxSTD ostream DocumentOstream;
29#else // !wxUSE_STD_IOSTREAM
30 typedef wxInputStream DocumentIstream;
31 typedef wxOutputStream DocumentOstream;
32#endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
33
34// ----------------------------------------------------------------------------
35// The document class and its helpers
36// ----------------------------------------------------------------------------
37
38// Represents a line from one point to the other
39struct DoodleLine
457814b5 40{
2d1df0fc
VZ
41 DoodleLine() { /* leave fields uninitialized */ }
42
43 DoodleLine(const wxPoint& pt1, const wxPoint& pt2)
44 : x1(pt1.x), y1(pt1.y), x2(pt2.x), y2(pt2.y)
45 {
46 }
47
f6bcfd97
BP
48 wxInt32 x1;
49 wxInt32 y1;
50 wxInt32 x2;
51 wxInt32 y2;
457814b5
JS
52};
53
2d1df0fc
VZ
54typedef wxVector<DoodleLine> DoodleLines;
55
457814b5 56// Contains a list of lines: represents a mouse-down doodle
2d1df0fc 57class DoodleSegment
457814b5 58{
f6bcfd97 59public:
2d1df0fc
VZ
60 DocumentOstream& SaveObject(DocumentOstream& stream);
61 DocumentIstream& LoadObject(DocumentIstream& stream);
958d3a7e 62
2d1df0fc
VZ
63 bool IsEmpty() const { return m_lines.empty(); }
64 void AddLine(const wxPoint& pt1, const wxPoint& pt2)
65 {
66 m_lines.push_back(DoodleLine(pt1, pt2));
67 }
68 const DoodleLines& GetLines() const { return m_lines; }
958d3a7e 69
2d1df0fc
VZ
70private:
71 DoodleLines m_lines;
457814b5
JS
72};
73
2d1df0fc
VZ
74typedef wxVector<DoodleSegment> DoodleSegments;
75
76
77// The drawing document (model) class itself
6bdf5153 78class DrawingDocument : public wxDocument
457814b5 79{
f6bcfd97 80public:
2d1df0fc 81 DrawingDocument() : wxDocument() { }
958d3a7e 82
2d1df0fc
VZ
83 DocumentOstream& SaveObject(DocumentOstream& stream);
84 DocumentIstream& LoadObject(DocumentIstream& stream);
958d3a7e 85
2d1df0fc
VZ
86 // add a new segment to the document
87 void AddDoodleSegment(const DoodleSegment& segment);
88
89 // remove the last segment, if any, and copy it in the provided pointer if
90 // not NULL and return true or return false and do nothing if there are no
91 // segments
92 bool PopLastSegment(DoodleSegment *segment);
93
94 // get direct access to our segments (for DrawingView)
95 const DoodleSegments& GetSegments() const { return m_doodleSegments; }
96
97private:
98 void DoUpdate();
99
100 DoodleSegments m_doodleSegments;
101
102 DECLARE_DYNAMIC_CLASS(DrawingDocument)
457814b5
JS
103};
104
457814b5 105
2d1df0fc
VZ
106// ----------------------------------------------------------------------------
107// Some operations (which can be done and undone by the view) on the document:
108// ----------------------------------------------------------------------------
109
110// Base class for all operations on DrawingDocument
6bdf5153 111class DrawingCommand : public wxCommand
457814b5 112{
2d1df0fc
VZ
113public:
114 DrawingCommand(DrawingDocument *doc,
115 const wxString& name,
116 const DoodleSegment& segment = DoodleSegment())
117 : wxCommand(true, name),
118 m_doc(doc),
119 m_segment(segment)
120 {
121 }
122
f6bcfd97 123protected:
2d1df0fc
VZ
124 bool DoAdd() { m_doc->AddDoodleSegment(m_segment); return true; }
125 bool DoRemove() { return m_doc->PopLastSegment(&m_segment); }
126
127private:
128 DrawingDocument * const m_doc;
129 DoodleSegment m_segment;
130};
131
132// The command for adding a new segment
133class DrawingAddSegmentCommand : public DrawingCommand
134{
135public:
136 DrawingAddSegmentCommand(DrawingDocument *doc, const DoodleSegment& segment)
137 : DrawingCommand(doc, "Add new segment", segment)
138 {
139 }
140
141 virtual bool Do() { return DoAdd(); }
142 virtual bool Undo() { return DoRemove(); }
143};
144
145// The command for removing the last segment
146class DrawingRemoveSegmentCommand : public DrawingCommand
147{
f6bcfd97 148public:
2d1df0fc
VZ
149 DrawingRemoveSegmentCommand(DrawingDocument *doc)
150 : DrawingCommand(doc, "Remove last segment")
151 {
152 }
958d3a7e 153
2d1df0fc
VZ
154 virtual bool Do() { return DoRemove(); }
155 virtual bool Undo() { return DoAdd(); }
457814b5
JS
156};
157
2d1df0fc
VZ
158
159// ----------------------------------------------------------------------------
828c8f98 160// wxTextDocument: wxDocument and wxTextCtrl married
2d1df0fc
VZ
161// ----------------------------------------------------------------------------
162
828c8f98 163class wxTextDocument : public wxDocument
457814b5 164{
f6bcfd97 165public:
828c8f98 166 wxTextDocument() : wxDocument() { }
112d941f 167
ce00f59b 168 virtual bool OnCreate(const wxString& path, long flags);
112d941f 169
828c8f98 170 virtual wxTextCtrl* GetTextCtrl() const = 0;
6bdf5153 171
2d1df0fc 172 virtual bool IsModified() const;
f6bcfd97 173 virtual void Modify(bool mod);
457814b5 174
828c8f98
FM
175protected:
176 virtual bool DoSaveDocument(const wxString& filename);
177 virtual bool DoOpenDocument(const wxString& filename);
178
112d941f
VZ
179 void OnTextChange(wxCommandEvent& event);
180
c0c133e1 181 wxDECLARE_NO_COPY_CLASS(wxTextDocument);
828c8f98
FM
182 DECLARE_CLASS(wxTextDocument)
183};
184
185// ----------------------------------------------------------------------------
186// A very simple text document class
187// ----------------------------------------------------------------------------
188
189class TextEditDocument : public wxTextDocument
190{
191public:
192 TextEditDocument() : wxTextDocument() { }
193 virtual wxTextCtrl* GetTextCtrl() const;
194
c0c133e1 195 wxDECLARE_NO_COPY_CLASS(TextEditDocument);
2d1df0fc
VZ
196 DECLARE_DYNAMIC_CLASS(TextEditDocument)
197};
457814b5 198
f37f49b6 199// ----------------------------------------------------------------------------
4db97e24 200// Image and image details document classes (both are read-only for simplicity)
f37f49b6
JS
201// ----------------------------------------------------------------------------
202
4db97e24
VZ
203// This is a normal document containing an image, just like TextEditDocument
204// above contains some text. It can be created from an image file on disk as
205// usual.
2d4a03f8 206class ImageDocument : public wxDocument
f37f49b6 207{
f37f49b6 208public:
2d4a03f8 209 ImageDocument() : wxDocument() { }
f37f49b6 210
4db97e24
VZ
211 virtual bool OnOpenDocument(const wxString& file);
212
2d4a03f8 213 wxImage GetImage() const { return m_image; }
f37f49b6 214
2d4a03f8 215protected:
f37f49b6 216 virtual bool DoOpenDocument(const wxString& file);
f37f49b6 217
2d4a03f8
VZ
218private:
219 wxImage m_image;
f37f49b6 220
2d4a03f8
VZ
221 wxDECLARE_NO_COPY_CLASS(ImageDocument);
222 DECLARE_DYNAMIC_CLASS(ImageDocument)
f37f49b6
JS
223};
224
4db97e24
VZ
225// This is a child document of ImageDocument: this document doesn't
226// correspond to any file on disk, it's part of ImageDocument and can't be
227// instantiated independently of it.
228class ImageDetailsDocument : public wxDocument
229{
230public:
231 ImageDetailsDocument(ImageDocument *parent);
232
233 // accessors for ImageDetailsView
234 wxSize GetSize() const { return m_size; }
235 unsigned long GetNumColours() const { return m_numColours; }
236 wxBitmapType GetType() const { return m_type; }
237 bool HasAlpha() const { return m_hasAlpha; }
238
239private:
240 // some information about the image we choose to show to the user
241 wxSize m_size;
242 unsigned long m_numColours;
243 wxBitmapType m_type;
244 bool m_hasAlpha;
245
246 wxDECLARE_NO_COPY_CLASS(ImageDetailsDocument);
247};
248
2d1df0fc 249#endif // _WX_SAMPLES_DOCVIEW_DOC_H_