]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/doc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/studio/doc.h
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 #include "wx/docview.h"
16 #include "wx/cmdproc.h"
17 #include "wx/string.h"
19 #include "wx/ogl/ogl.h" // base header of OGL, includes and adjusts wx/deprecated/setup.h
24 * A diagram document, which contains a diagram.
27 class csDiagramDocument
: public wxDocument
29 DECLARE_DYNAMIC_CLASS(csDiagramDocument
)
35 bool OnSaveDocument(const wxString
& file
);
36 bool OnOpenDocument(const wxString
& file
);
37 #endif // wxUSE_PROLOGIO
39 inline wxDiagram
*GetDiagram() { return &m_diagram
; }
41 bool OnCloseDocument();
50 1) We have a csCommandState, and in csDiagramCommand you have a list of
51 these. This allows undo to work with several shapes at once.
53 2) Instead of storing info about each operation, e.g. separate pens, colours,
54 etc., we simply use a copy of the shape.
55 In csCommandState, we have a pointer to the actual shape in the canvas, m_currentShape.
56 We also have wxShape* m_shapeState which stores the requested or previous state
57 (depending on whether it's before the Do or after the Do.
59 - In Do: save a temp copy of the old m_currentShape (i.e. the state just before it's changed).
60 Change the data pointed to by m_currentShape to the new attributes stored in m_shapeState.
61 Now assign the temp copy to m_shapeState, for use in Undo.
63 wxShape* temp = m_currentShape->Copy(); // Take a copy of the current state
64 m_currentShape->Set(m_shapeState); // Apply the new state (e.g. moving, changing colour etc.)
65 delete m_shapeState; // Delete the previous 'old state'.
66 m_shapeState = temp; // Remember the new 'old state'.
72 class csDiagramCommand
: public wxCommand
74 friend class csCommandState
;
76 // Multi-purpose constructor for creating, deleting shapes
77 csDiagramCommand(const wxString
& name
, csDiagramDocument
*doc
,
78 csCommandState
* onlyState
= NULL
); // Allow for the common case of just one state to change
85 // Add a state to the end of the list
86 void AddState(csCommandState
* state
);
88 // Insert a state at the beginning of the list
89 void InsertState(csCommandState
* state
);
91 // Schedule all lines connected to the states to be cut.
94 // Find the state that refers to this shape
95 csCommandState
* FindStateByShape(wxShape
* shape
);
97 wxList
& GetStates() const { return (wxList
&) m_states
; }
100 csDiagramDocument
* m_doc
;
104 class csCommandState
: public wxObject
106 friend class csDiagramCommand
;
108 csCommandState(int cmd
, wxShape
* savedState
, wxShape
* shapeOnCanvas
);
114 inline void SetSavedState(wxShape
*s
) { m_savedState
= s
; }
115 inline wxShape
*GetSavedState() const { return m_savedState
; }
117 inline void SetShapeOnCanvas(wxShape
*s
) { m_shapeOnCanvas
= s
; }
118 inline wxShape
*GetShapeOnCanvas() const { return m_shapeOnCanvas
; }
120 wxShape
* m_savedState
; // Previous state, for restoring on Undo
121 wxShape
* m_shapeOnCanvas
; // The actual shape on the canvas
122 csDiagramDocument
* m_doc
;
125 // These store the line ordering for the shapes at either end,
126 // so an un-cut line can restore the ordering properly. Otherwise
127 // it just adds the line at an arbitrary position.
128 int m_linePositionFrom
;
129 int m_linePositionTo
;