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