]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/doc.h
Use 'wx/' for contrib samples and make wxTinderbox properly rebuilded after commits...
[wxWidgets.git] / contrib / samples / ogl / studio / doc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/studio/doc.h
3 // Purpose: Document classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 12/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _STUDIO_DOC_H_
13 #define _STUDIO_DOC_H_
14
15 #include "wx/docview.h"
16 #include "wx/cmdproc.h"
17 #include "wx/string.h"
18
19 #include "wx/ogl/ogl.h" // base header of OGL, includes and adjusts wx/deprecated/setup.h
20
21 #include "shapes.h"
22
23 /*
24 * A diagram document, which contains a diagram.
25 */
26
27 class csDiagramDocument: public wxDocument
28 {
29 DECLARE_DYNAMIC_CLASS(csDiagramDocument)
30 public:
31 csDiagramDocument();
32 ~csDiagramDocument();
33
34 #if wxUSE_PROLOGIO
35 bool OnSaveDocument(const wxString& file);
36 bool OnOpenDocument(const wxString& file);
37 #endif // wxUSE_PROLOGIO
38
39 inline wxDiagram *GetDiagram() { return &m_diagram; }
40
41 bool OnCloseDocument();
42
43 protected:
44 csDiagram m_diagram;
45 };
46
47 /*
48 Do/Undo 30/7/98
49
50 1) We have a csCommandState, and in csDiagramCommand you have a list of
51 these. This allows undo to work with several shapes at once.
52
53 2) Instead of storing info about each operation, e.g. separate pens, colours,
54 etc., we simply use a copy of the shape.
55 In csCommandState, we have a pointer to the actual shape in the canvas, m_currentShape.
56 We also have wxShape* m_shapeState which stores the requested or previous state
57 (depending on whether it's before the Do or after the Do.
58
59 - In Do: save a temp copy of the old m_currentShape (i.e. the state just before it's changed).
60 Change the data pointed to by m_currentShape to the new attributes stored in m_shapeState.
61 Now assign the temp copy to m_shapeState, for use in Undo.
62
63 wxShape* temp = m_currentShape->Copy(); // Take a copy of the current state
64 m_currentShape->Set(m_shapeState); // Apply the new state (e.g. moving, changing colour etc.)
65 delete m_shapeState; // Delete the previous 'old state'.
66 m_shapeState = temp; // Remember the new 'old state'.
67
68 */
69
70
71 class csCommandState;
72 class csDiagramCommand: public wxCommand
73 {
74 friend class csCommandState;
75 public:
76 // Multi-purpose constructor for creating, deleting shapes
77 csDiagramCommand(const wxString& name, csDiagramDocument *doc,
78 csCommandState* onlyState = NULL); // Allow for the common case of just one state to change
79
80 ~csDiagramCommand();
81
82 bool Do();
83 bool Undo();
84
85 // Add a state to the end of the list
86 void AddState(csCommandState* state);
87
88 // Insert a state at the beginning of the list
89 void InsertState(csCommandState* state);
90
91 // Schedule all lines connected to the states to be cut.
92 void RemoveLines();
93
94 // Find the state that refers to this shape
95 csCommandState* FindStateByShape(wxShape* shape);
96
97 wxList& GetStates() const { return (wxList&) m_states; }
98
99 protected:
100 csDiagramDocument* m_doc;
101 wxList m_states;
102 };
103
104 class csCommandState: public wxObject
105 {
106 friend class csDiagramCommand;
107 public:
108 csCommandState(int cmd, wxShape* savedState, wxShape* shapeOnCanvas);
109 ~csCommandState();
110
111 bool Do();
112 bool Undo();
113
114 inline void SetSavedState(wxShape *s) { m_savedState = s; }
115 inline wxShape *GetSavedState() const { return m_savedState; }
116
117 inline void SetShapeOnCanvas(wxShape *s) { m_shapeOnCanvas = s; }
118 inline wxShape *GetShapeOnCanvas() const { return m_shapeOnCanvas; }
119 protected:
120 wxShape* m_savedState; // Previous state, for restoring on Undo
121 wxShape* m_shapeOnCanvas; // The actual shape on the canvas
122 csDiagramDocument* m_doc;
123 int m_cmd;
124
125 // These store the line ordering for the shapes at either end,
126 // so an un-cut line can restore the ordering properly. Otherwise
127 // it just adds the line at an arbitrary position.
128 int m_linePositionFrom;
129 int m_linePositionTo;
130 };
131
132 #endif
133 // _STUDIO_DOC_H_