]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/studio/doc.h
wxHtmlHistoryItem needs not be wxObject
[wxWidgets.git] / contrib / samples / ogl / studio / doc.h
CommitLineData
1fc25a89
JS
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>
606b005f 20#include <wx/cmdproc.h>
1fc25a89
JS
21#include <wx/string.h>
22#include <wx/wxexpr.h>
23
24#include <wx/ogl/ogl.h>
25#include "shapes.h"
26
27/*
28 * A diagram document, which contains a diagram.
29 */
30
31class csDiagramDocument: public wxDocument
32{
33 DECLARE_DYNAMIC_CLASS(csDiagramDocument)
34public:
35 csDiagramDocument();
36 ~csDiagramDocument();
37
38 bool OnSaveDocument(const wxString& file);
39 bool OnOpenDocument(const wxString& file);
40
41 inline wxDiagram *GetDiagram() { return &m_diagram; }
42
43 bool OnCloseDocument();
44
45protected:
46 csDiagram m_diagram;
47};
48
49/*
50 Do/Undo 30/7/98
51
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.
54
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.
60
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.
64
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'.
69
70 */
71
72
73class csCommandState;
74class csDiagramCommand: public wxCommand
75{
76 friend class csCommandState;
77 public:
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
81
82 ~csDiagramCommand();
83
84 bool Do();
85 bool Undo();
86
87 // Add a state to the end of the list
88 void AddState(csCommandState* state);
89
90 // Insert a state at the beginning of the list
91 void InsertState(csCommandState* state);
92
93 // Schedule all lines connected to the states to be cut.
94 void RemoveLines();
95
96 // Find the state that refers to this shape
97 csCommandState* FindStateByShape(wxShape* shape);
98
99 wxList& GetStates() const { return (wxList&) m_states; }
100
101 protected:
102 csDiagramDocument* m_doc;
103 wxList m_states;
104};
105
106class csCommandState: public wxObject
107{
108 friend class csDiagramCommand;
109public:
110 csCommandState(int cmd, wxShape* savedState, wxShape* shapeOnCanvas);
111 ~csCommandState();
112
113 bool Do();
114 bool Undo();
115
116 inline void SetSavedState(wxShape *s) { m_savedState = s; }
117 inline wxShape *GetSavedState() const { return m_savedState; }
118
119 inline void SetShapeOnCanvas(wxShape *s) { m_shapeOnCanvas = s; }
120 inline wxShape *GetShapeOnCanvas() const { return m_shapeOnCanvas; }
121protected:
122 wxShape* m_savedState; // Previous state, for restoring on Undo
123 wxShape* m_shapeOnCanvas; // The actual shape on the canvas
124 csDiagramDocument* m_doc;
125 int m_cmd;
126
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;
132};
133
134#endif
135 // _STUDIO_DOC_H_