]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/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/cmdproc.h>
21 #include <wx/string.h>
22 #include <wx/wxexpr.h>
24 #include <wx/ogl/ogl.h>
28 * A diagram document, which contains a diagram.
31 class csDiagramDocument
: public wxDocument
33 DECLARE_DYNAMIC_CLASS(csDiagramDocument
)
38 bool OnSaveDocument(const wxString
& file
);
39 bool OnOpenDocument(const wxString
& file
);
41 inline wxDiagram
*GetDiagram() { return &m_diagram
; }
43 bool OnCloseDocument();
52 1) We have a csCommandState, and in csDiagramCommand you have a list of
53 these. This allows undo to work with several shapes at once.
55 2) Instead of storing info about each operation, e.g. separate pens, colours,
56 etc., we simply use a copy of the shape.
57 In csCommandState, we have a pointer to the actual shape in the canvas, m_currentShape.
58 We also have wxShape* m_shapeState which stores the requested or previous state
59 (depending on whether it's before the Do or after the Do.
61 - In Do: save a temp copy of the old m_currentShape (i.e. the state just before it's changed).
62 Change the data pointed to by m_currentShape to the new attributes stored in m_shapeState.
63 Now assign the temp copy to m_shapeState, for use in Undo.
65 wxShape* temp = m_currentShape->Copy(); // Take a copy of the current state
66 m_currentShape->Set(m_shapeState); // Apply the new state (e.g. moving, changing colour etc.)
67 delete m_shapeState; // Delete the previous 'old state'.
68 m_shapeState = temp; // Remember the new 'old state'.
74 class csDiagramCommand
: public wxCommand
76 friend class csCommandState
;
78 // Multi-purpose constructor for creating, deleting shapes
79 csDiagramCommand(const wxString
& name
, csDiagramDocument
*doc
,
80 csCommandState
* onlyState
= NULL
); // Allow for the common case of just one state to change
87 // Add a state to the end of the list
88 void AddState(csCommandState
* state
);
90 // Insert a state at the beginning of the list
91 void InsertState(csCommandState
* state
);
93 // Schedule all lines connected to the states to be cut.
96 // Find the state that refers to this shape
97 csCommandState
* FindStateByShape(wxShape
* shape
);
99 wxList
& GetStates() const { return (wxList
&) m_states
; }
102 csDiagramDocument
* m_doc
;
106 class csCommandState
: public wxObject
108 friend class csDiagramCommand
;
110 csCommandState(int cmd
, wxShape
* savedState
, wxShape
* shapeOnCanvas
);
116 inline void SetSavedState(wxShape
*s
) { m_savedState
= s
; }
117 inline wxShape
*GetSavedState() const { return m_savedState
; }
119 inline void SetShapeOnCanvas(wxShape
*s
) { m_shapeOnCanvas
= s
; }
120 inline wxShape
*GetShapeOnCanvas() const { return m_shapeOnCanvas
; }
122 wxShape
* m_savedState
; // Previous state, for restoring on Undo
123 wxShape
* m_shapeOnCanvas
; // The actual shape on the canvas
124 csDiagramDocument
* m_doc
;
127 // These store the line ordering for the shapes at either end,
128 // so an un-cut line can restore the ordering properly. Otherwise
129 // it just adds the line at an arbitrary position.
130 int m_linePositionFrom
;
131 int m_linePositionTo
;