]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/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/cmdproc.h>
21 #include <wx/string.h>
22 #include <wx/wxexpr.h>
24 #include <wx/ogl/ogl.h>
26 #if wxUSE_STD_IOSTREAM
31 * Override a few members for this application
34 class MyDiagram
: public wxDiagram
38 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
39 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
43 * A few new shape classes so we have a 1:1 mapping
44 * between palette symbol and unique class
47 class wxRoundedRectangleShape
: public wxRectangleShape
49 DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape
)
52 wxRoundedRectangleShape(double w
= 0.0, double h
= 0.0);
55 class wxDiamondShape
: public wxPolygonShape
57 DECLARE_DYNAMIC_CLASS(wxDiamondShape
)
60 wxDiamondShape(double w
= 0.0, double h
= 0.0);
64 * All shape event behaviour is routed through this handler, so we don't
65 * have to derive from each shape class. We plug this in to each shape.
68 class MyEvtHandler
: public wxShapeEvtHandler
72 MyEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= ""):wxShapeEvtHandler(prev
, shape
)
79 void OnLeftClick(double x
, double y
, int keys
= 0, int attachment
= 0);
80 void OnBeginDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
81 void OnDragRight(bool draw
, double x
, double y
, int keys
= 0, int attachment
= 0);
82 void OnEndDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
83 void OnEndSize(double x
, double y
);
87 * A diagram document, which contains a diagram.
90 class DiagramDocument
: public wxDocument
92 DECLARE_DYNAMIC_CLASS(DiagramDocument
)
97 DiagramDocument(void);
98 ~DiagramDocument(void);
100 #if wxUSE_STD_IOSTREAM
101 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
102 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
104 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
105 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
108 inline wxDiagram
*GetDiagram() { return &diagram
; }
110 bool OnCloseDocument(void);
114 * Most user interface commands are routed through this, to give us the
115 * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
116 * you will need to add members to 'remember' what the user applied (for 'Do') and what the
117 * previous state was (for 'Undo').
118 * You can have one member for each property to be changed. Assume we also have
119 * a pointer member wxShape *shape, which is set to the shape being changed.
120 * Let's assume we're changing the shape colour. Our member for this is shapeColour.
123 * o Set a temporary variable 'temp' to the current colour for 'shape'.
124 * o Change the colour to the new colour.
125 * o Set shapeColour to the _old_ colour, 'temp'.
127 * o Set a temporary variable 'temp' to the current colour for 'shape'.
128 * o Change the colour to shapeColour (the old colour).
129 * o Set shapeColour to 'temp'.
131 * So, as long as we have a pointer to the shape being changed,
132 * we only need one member variable for each property.
134 * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
135 * Assume, as here, that we keep a pointer to the old shape so we reuse it
139 class DiagramCommand
: public wxCommand
142 DiagramDocument
*doc
;
144 wxShape
*shape
; // Pointer to the shape we're acting on
147 wxClassInfo
*shapeInfo
;
153 // Storage for property commands
158 // Multi-purpose constructor for creating, deleting shapes
159 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxClassInfo
*shapeInfo
= NULL
,
160 double x
= 0.0, double y
= 0.0, bool sel
= FALSE
, wxShape
*theShape
= NULL
, wxShape
*fs
= NULL
, wxShape
*ts
= NULL
);
162 // Property-changing command constructors
163 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxBrush
*backgroundColour
, wxShape
*theShape
);
164 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, const wxString
& lab
, wxShape
*theShape
);
166 ~DiagramCommand(void);
171 inline void SetShape(wxShape
*s
) { shape
= s
; }
172 inline wxShape
*GetShape(void) { return shape
; }
173 inline wxShape
*GetFromShape(void) { return fromShape
; }
174 inline wxShape
*GetToShape(void) { return toShape
; }
175 inline wxClassInfo
*GetShapeInfo(void) { return shapeInfo
; }
176 inline bool GetSelected(void) { return selected
; }
178 void RemoveLines(wxShape
*shape
);