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