]>
git.saurik.com Git - wxWidgets.git/blob - utils/ogl/samples/ogledit/doc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _OGLSAMPLE_DOC_H_
13 #define _OGLSAMPLE_DOC_H_
19 #include <wx/docview.h>
20 #include <wx/string.h>
21 #include <wx/wxexpr.h>
26 * Override a few members for this application
29 class MyDiagram
: public wxDiagram
33 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
34 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
38 * A few new shape classes so we have a 1:1 mapping
39 * between palette symbol and unique class
42 class wxRoundedRectangleShape
: public wxRectangleShape
44 DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape
)
47 wxRoundedRectangleShape(double w
= 0.0, double h
= 0.0);
50 class wxDiamondShape
: public wxPolygonShape
52 DECLARE_DYNAMIC_CLASS(wxDiamondShape
)
55 wxDiamondShape(double w
= 0.0, double h
= 0.0);
59 * All shape event behaviour is routed through this handler, so we don't
60 * have to derive from each shape class. We plug this in to each shape.
63 class MyEvtHandler
: public wxShapeEvtHandler
67 MyEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= ""):wxShapeEvtHandler(prev
, shape
)
74 void OnLeftClick(double x
, double y
, int keys
= 0, int attachment
= 0);
75 void OnBeginDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
76 void OnDragRight(bool draw
, double x
, double y
, int keys
= 0, int attachment
= 0);
77 void OnEndDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
78 void OnEndSize(double x
, double y
);
82 * A diagram document, which contains a diagram.
85 class DiagramDocument
: public wxDocument
87 DECLARE_DYNAMIC_CLASS(DiagramDocument
)
92 DiagramDocument(void);
93 ~DiagramDocument(void);
95 ostream
& SaveObject(ostream
& stream
);
96 istream
& LoadObject(istream
& stream
);
98 inline wxDiagram
*GetDiagram() { return &diagram
; }
100 bool OnCloseDocument(void);
104 * Most user interface commands are routed through this, to give us the
105 * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
106 * you will need to add members to 'remember' what the user applied (for 'Do') and what the
107 * previous state was (for 'Undo').
108 * You can have one member for each property to be changed. Assume we also have
109 * a pointer member wxShape *shape, which is set to the shape being changed.
110 * Let's assume we're changing the shape colour. Our member for this is shapeColour.
113 * o Set a temporary variable 'temp' to the current colour for 'shape'.
114 * o Change the colour to the new colour.
115 * o Set shapeColour to the _old_ colour, 'temp'.
117 * o Set a temporary variable 'temp' to the current colour for 'shape'.
118 * o Change the colour to shapeColour (the old colour).
119 * o Set shapeColour to 'temp'.
121 * So, as long as we have a pointer to the shape being changed,
122 * we only need one member variable for each property.
124 * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
125 * Assume, as here, that we keep a pointer to the old shape so we reuse it
129 class DiagramCommand
: public wxCommand
132 DiagramDocument
*doc
;
134 wxShape
*shape
; // Pointer to the shape we're acting on
137 wxClassInfo
*shapeInfo
;
143 // Storage for property commands
148 // Multi-purpose constructor for creating, deleting shapes
149 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxClassInfo
*shapeInfo
= NULL
,
150 double x
= 0.0, double y
= 0.0, bool sel
= FALSE
, wxShape
*theShape
= NULL
, wxShape
*fs
= NULL
, wxShape
*ts
= NULL
);
152 // Property-changing command constructors
153 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxBrush
*backgroundColour
, wxShape
*theShape
);
154 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, const wxString
& lab
, wxShape
*theShape
);
156 ~DiagramCommand(void);
161 inline void SetShape(wxShape
*s
) { shape
= s
; }
162 inline wxShape
*GetShape(void) { return shape
; }
163 inline wxShape
*GetFromShape(void) { return fromShape
; }
164 inline wxShape
*GetToShape(void) { return toShape
; }
165 inline wxClassInfo
*GetShapeInfo(void) { return shapeInfo
; }
166 inline bool GetSelected(void) { return selected
; }
168 void RemoveLines(wxShape
*shape
);