]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/ogledit/doc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/ogledit/doc.h
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_
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
22 #include "wx/deprecated/wxexpr.h"
25 #include "wx/ogl/ogl.h"
27 #if wxUSE_STD_IOSTREAM
32 * Override a few members for this application
35 class MyDiagram
: public wxDiagram
40 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
41 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
46 * A few new shape classes so we have a 1:1 mapping
47 * between palette symbol and unique class
50 class wxRoundedRectangleShape
: public wxRectangleShape
52 DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape
)
55 wxRoundedRectangleShape(double w
= 0.0, double h
= 0.0);
58 class wxDiamondShape
: public wxPolygonShape
60 DECLARE_DYNAMIC_CLASS(wxDiamondShape
)
63 wxDiamondShape(double w
= 0.0, double h
= 0.0);
67 * All shape event behaviour is routed through this handler, so we don't
68 * have to derive from each shape class. We plug this in to each shape.
71 class MyEvtHandler
: public wxShapeEvtHandler
75 MyEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= wxEmptyString
):wxShapeEvtHandler(prev
, shape
)
82 void OnLeftClick(double x
, double y
, int keys
= 0, int attachment
= 0);
83 void OnBeginDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
84 void OnDragRight(bool draw
, double x
, double y
, int keys
= 0, int attachment
= 0);
85 void OnEndDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
86 void OnEndSize(double x
, double y
);
90 * A diagram document, which contains a diagram.
93 class DiagramDocument
: public wxDocument
95 DECLARE_DYNAMIC_CLASS(DiagramDocument
)
100 DiagramDocument(void);
101 ~DiagramDocument(void);
103 #if wxUSE_STD_IOSTREAM
104 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
105 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
107 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
108 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
111 inline wxDiagram
*GetDiagram() { return &diagram
; }
113 bool OnCloseDocument(void);
117 * Most user interface commands are routed through this, to give us the
118 * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
119 * you will need to add members to 'remember' what the user applied (for 'Do') and what the
120 * previous state was (for 'Undo').
121 * You can have one member for each property to be changed. Assume we also have
122 * a pointer member wxShape *shape, which is set to the shape being changed.
123 * Let's assume we're changing the shape colour. Our member for this is shapeColour.
126 * o Set a temporary variable 'temp' to the current colour for 'shape'.
127 * o Change the colour to the new colour.
128 * o Set shapeColour to the _old_ colour, 'temp'.
130 * o Set a temporary variable 'temp' to the current colour for 'shape'.
131 * o Change the colour to shapeColour (the old colour).
132 * o Set shapeColour to 'temp'.
134 * So, as long as we have a pointer to the shape being changed,
135 * we only need one member variable for each property.
137 * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
138 * Assume, as here, that we keep a pointer to the old shape so we reuse it
142 class DiagramCommand
: public wxCommand
145 DiagramDocument
*doc
;
147 wxShape
*shape
; // Pointer to the shape we're acting on
150 wxClassInfo
*shapeInfo
;
156 // Storage for property commands
157 const wxBrush
*shapeBrush
;
161 // Multi-purpose constructor for creating, deleting shapes
162 DiagramCommand(const wxString
& name
, int cmd
, DiagramDocument
*ddoc
, wxClassInfo
*shapeInfo
= NULL
,
163 double x
= 0.0, double y
= 0.0, bool sel
= false, wxShape
*theShape
= NULL
, wxShape
*fs
= NULL
, wxShape
*ts
= NULL
);
165 // Property-changing command constructors
166 DiagramCommand(const wxString
& name
, int cmd
, DiagramDocument
*ddoc
, wxBrush
*backgroundColour
, wxShape
*theShape
);
167 DiagramCommand(const wxString
& name
, int cmd
, DiagramDocument
*ddoc
, const wxString
& lab
, wxShape
*theShape
);
169 ~DiagramCommand(void);
174 inline void SetShape(wxShape
*s
) { shape
= s
; }
175 inline wxShape
*GetShape(void) { return shape
; }
176 inline wxShape
*GetFromShape(void) { return fromShape
; }
177 inline wxShape
*GetToShape(void) { return toShape
; }
178 inline wxClassInfo
*GetShapeInfo(void) { return shapeInfo
; }
179 inline bool GetSelected(void) { return selected
; }
181 void RemoveLines(wxShape
*shape
);