]>
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_
15 #if defined(__GNUG__) && !defined(__APPLE__)
19 #include <wx/docview.h>
20 #include <wx/cmdproc.h>
21 #include <wx/string.h>
23 #include <wx/deprecated/setup.h>
24 #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
39 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
40 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
44 * A few new shape classes so we have a 1:1 mapping
45 * between palette symbol and unique class
48 class wxRoundedRectangleShape
: public wxRectangleShape
50 DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape
)
53 wxRoundedRectangleShape(double w
= 0.0, double h
= 0.0);
56 class wxDiamondShape
: public wxPolygonShape
58 DECLARE_DYNAMIC_CLASS(wxDiamondShape
)
61 wxDiamondShape(double w
= 0.0, double h
= 0.0);
65 * All shape event behaviour is routed through this handler, so we don't
66 * have to derive from each shape class. We plug this in to each shape.
69 class MyEvtHandler
: public wxShapeEvtHandler
73 MyEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= ""):wxShapeEvtHandler(prev
, shape
)
80 void OnLeftClick(double x
, double y
, int keys
= 0, int attachment
= 0);
81 void OnBeginDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
82 void OnDragRight(bool draw
, double x
, double y
, int keys
= 0, int attachment
= 0);
83 void OnEndDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
84 void OnEndSize(double x
, double y
);
88 * A diagram document, which contains a diagram.
91 class DiagramDocument
: public wxDocument
93 DECLARE_DYNAMIC_CLASS(DiagramDocument
)
98 DiagramDocument(void);
99 ~DiagramDocument(void);
101 #if wxUSE_STD_IOSTREAM
102 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
103 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
105 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
106 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
109 inline wxDiagram
*GetDiagram() { return &diagram
; }
111 bool OnCloseDocument(void);
115 * Most user interface commands are routed through this, to give us the
116 * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
117 * you will need to add members to 'remember' what the user applied (for 'Do') and what the
118 * previous state was (for 'Undo').
119 * You can have one member for each property to be changed. Assume we also have
120 * a pointer member wxShape *shape, which is set to the shape being changed.
121 * Let's assume we're changing the shape colour. Our member for this is shapeColour.
124 * o Set a temporary variable 'temp' to the current colour for 'shape'.
125 * o Change the colour to the new colour.
126 * o Set shapeColour to the _old_ colour, 'temp'.
128 * o Set a temporary variable 'temp' to the current colour for 'shape'.
129 * o Change the colour to shapeColour (the old colour).
130 * o Set shapeColour to 'temp'.
132 * So, as long as we have a pointer to the shape being changed,
133 * we only need one member variable for each property.
135 * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
136 * Assume, as here, that we keep a pointer to the old shape so we reuse it
140 class DiagramCommand
: public wxCommand
143 DiagramDocument
*doc
;
145 wxShape
*shape
; // Pointer to the shape we're acting on
148 wxClassInfo
*shapeInfo
;
154 // Storage for property commands
159 // Multi-purpose constructor for creating, deleting shapes
160 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxClassInfo
*shapeInfo
= NULL
,
161 double x
= 0.0, double y
= 0.0, bool sel
= FALSE
, wxShape
*theShape
= NULL
, wxShape
*fs
= NULL
, wxShape
*ts
= NULL
);
163 // Property-changing command constructors
164 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxBrush
*backgroundColour
, wxShape
*theShape
);
165 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, const wxString
& lab
, wxShape
*theShape
);
167 ~DiagramCommand(void);
172 inline void SetShape(wxShape
*s
) { shape
= s
; }
173 inline wxShape
*GetShape(void) { return shape
; }
174 inline wxShape
*GetFromShape(void) { return fromShape
; }
175 inline wxShape
*GetToShape(void) { return toShape
; }
176 inline wxClassInfo
*GetShapeInfo(void) { return shapeInfo
; }
177 inline bool GetSelected(void) { return selected
; }
179 void RemoveLines(wxShape
*shape
);