]>
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>
26 #include <wx/deprecated/wxexpr.h>
29 #include <wx/ogl/ogl.h>
31 #if wxUSE_STD_IOSTREAM
36 * Override a few members for this application
39 class MyDiagram
: public wxDiagram
44 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
45 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
50 * A few new shape classes so we have a 1:1 mapping
51 * between palette symbol and unique class
54 class wxRoundedRectangleShape
: public wxRectangleShape
56 DECLARE_DYNAMIC_CLASS(wxRoundedRectangleShape
)
59 wxRoundedRectangleShape(double w
= 0.0, double h
= 0.0);
62 class wxDiamondShape
: public wxPolygonShape
64 DECLARE_DYNAMIC_CLASS(wxDiamondShape
)
67 wxDiamondShape(double w
= 0.0, double h
= 0.0);
71 * All shape event behaviour is routed through this handler, so we don't
72 * have to derive from each shape class. We plug this in to each shape.
75 class MyEvtHandler
: public wxShapeEvtHandler
79 MyEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= ""):wxShapeEvtHandler(prev
, shape
)
86 void OnLeftClick(double x
, double y
, int keys
= 0, int attachment
= 0);
87 void OnBeginDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
88 void OnDragRight(bool draw
, double x
, double y
, int keys
= 0, int attachment
= 0);
89 void OnEndDragRight(double x
, double y
, int keys
= 0, int attachment
= 0);
90 void OnEndSize(double x
, double y
);
94 * A diagram document, which contains a diagram.
97 class DiagramDocument
: public wxDocument
99 DECLARE_DYNAMIC_CLASS(DiagramDocument
)
104 DiagramDocument(void);
105 ~DiagramDocument(void);
107 #if wxUSE_STD_IOSTREAM
108 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
109 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
111 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
112 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
115 inline wxDiagram
*GetDiagram() { return &diagram
; }
117 bool OnCloseDocument(void);
121 * Most user interface commands are routed through this, to give us the
122 * Undo/Redo mechanism. If you add more commands, such as changing the shape colour,
123 * you will need to add members to 'remember' what the user applied (for 'Do') and what the
124 * previous state was (for 'Undo').
125 * You can have one member for each property to be changed. Assume we also have
126 * a pointer member wxShape *shape, which is set to the shape being changed.
127 * Let's assume we're changing the shape colour. Our member for this is shapeColour.
130 * o Set a temporary variable 'temp' to the current colour for 'shape'.
131 * o Change the colour to the new colour.
132 * o Set shapeColour to the _old_ colour, 'temp'.
134 * o Set a temporary variable 'temp' to the current colour for 'shape'.
135 * o Change the colour to shapeColour (the old colour).
136 * o Set shapeColour to 'temp'.
138 * So, as long as we have a pointer to the shape being changed,
139 * we only need one member variable for each property.
141 * PROBLEM: when an Add shape command is redone, the 'shape' pointer changes.
142 * Assume, as here, that we keep a pointer to the old shape so we reuse it
146 class DiagramCommand
: public wxCommand
149 DiagramDocument
*doc
;
151 wxShape
*shape
; // Pointer to the shape we're acting on
154 wxClassInfo
*shapeInfo
;
160 // Storage for property commands
165 // Multi-purpose constructor for creating, deleting shapes
166 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxClassInfo
*shapeInfo
= NULL
,
167 double x
= 0.0, double y
= 0.0, bool sel
= FALSE
, wxShape
*theShape
= NULL
, wxShape
*fs
= NULL
, wxShape
*ts
= NULL
);
169 // Property-changing command constructors
170 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, wxBrush
*backgroundColour
, wxShape
*theShape
);
171 DiagramCommand(char *name
, int cmd
, DiagramDocument
*ddoc
, const wxString
& lab
, wxShape
*theShape
);
173 ~DiagramCommand(void);
178 inline void SetShape(wxShape
*s
) { shape
= s
; }
179 inline wxShape
*GetShape(void) { return shape
; }
180 inline wxShape
*GetFromShape(void) { return fromShape
; }
181 inline wxShape
*GetToShape(void) { return toShape
; }
182 inline wxClassInfo
*GetShapeInfo(void) { return shapeInfo
; }
183 inline bool GetSelected(void) { return selected
; }
185 void RemoveLines(wxShape
*shape
);