]>
git.saurik.com Git - wxWidgets.git/blob - utils/ogl/samples/studio/doc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _STUDIO_DOC_H_
13 #define _STUDIO_DOC_H_
19 #include <wx/docview.h>
20 #include <wx/string.h>
21 #include <wx/wxexpr.h>
27 * A diagram document, which contains a diagram.
30 class csDiagramDocument
: public wxDocument
32 DECLARE_DYNAMIC_CLASS(csDiagramDocument
)
37 bool OnSaveDocument(const wxString
& file
);
38 bool OnOpenDocument(const wxString
& file
);
40 inline wxDiagram
*GetDiagram() { return &m_diagram
; }
42 bool OnCloseDocument();
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.
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.
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.
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'.
73 class csDiagramCommand
: public wxCommand
75 friend class csCommandState
;
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
86 // Add a state to the end of the list
87 void AddState(csCommandState
* state
);
89 // Insert a state at the beginning of the list
90 void InsertState(csCommandState
* state
);
92 // Schedule all lines connected to the states to be cut.
95 // Find the state that refers to this shape
96 csCommandState
* FindStateByShape(wxShape
* shape
);
98 wxList
& GetStates() const { return (wxList
&) m_states
; }
101 csDiagramDocument
* m_doc
;
105 class csCommandState
: public wxObject
107 friend class csDiagramCommand
;
109 csCommandState(int cmd
, wxShape
* savedState
, wxShape
* shapeOnCanvas
);
115 inline void SetSavedState(wxShape
*s
) { m_savedState
= s
; }
116 inline wxShape
*GetSavedState() const { return m_savedState
; }
118 inline void SetShapeOnCanvas(wxShape
*s
) { m_shapeOnCanvas
= s
; }
119 inline wxShape
*GetShapeOnCanvas() const { return m_shapeOnCanvas
; }
121 wxShape
* m_savedState
; // Previous state, for restoring on Undo
122 wxShape
* m_shapeOnCanvas
; // The actual shape on the canvas
123 csDiagramDocument
* m_doc
;
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
;