]>
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_
15 #if defined(__GNUG__) && !defined(__APPLE__)
19 #include <wx/docview.h>
20 #include <wx/cmdproc.h>
21 #include <wx/string.h>
23 #include <wx/deprecated/setup.h>
24 #include <wx/deprecated/wxexpr.h>
26 #include <wx/ogl/ogl.h>
30 * A diagram document, which contains a diagram.
33 class csDiagramDocument
: public wxDocument
35 DECLARE_DYNAMIC_CLASS(csDiagramDocument
)
40 bool OnSaveDocument(const wxString
& file
);
41 bool OnOpenDocument(const wxString
& file
);
43 inline wxDiagram
*GetDiagram() { return &m_diagram
; }
45 bool OnCloseDocument();
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.
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.
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.
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'.
76 class csDiagramCommand
: public wxCommand
78 friend class csCommandState
;
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
89 // Add a state to the end of the list
90 void AddState(csCommandState
* state
);
92 // Insert a state at the beginning of the list
93 void InsertState(csCommandState
* state
);
95 // Schedule all lines connected to the states to be cut.
98 // Find the state that refers to this shape
99 csCommandState
* FindStateByShape(wxShape
* shape
);
101 wxList
& GetStates() const { return (wxList
&) m_states
; }
104 csDiagramDocument
* m_doc
;
108 class csCommandState
: public wxObject
110 friend class csDiagramCommand
;
112 csCommandState(int cmd
, wxShape
* savedState
, wxShape
* shapeOnCanvas
);
118 inline void SetSavedState(wxShape
*s
) { m_savedState
= s
; }
119 inline wxShape
*GetSavedState() const { return m_savedState
; }
121 inline void SetShapeOnCanvas(wxShape
*s
) { m_shapeOnCanvas
= s
; }
122 inline wxShape
*GetShapeOnCanvas() const { return m_shapeOnCanvas
; }
124 wxShape
* m_savedState
; // Previous state, for restoring on Undo
125 wxShape
* m_shapeOnCanvas
; // The actual shape on the canvas
126 csDiagramDocument
* m_doc
;
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
;