wxArt2D
canwidget.h
Go to the documentation of this file.
1 /*! \file wx/canvas/canwidget.h
2 
3  \brief widget like objects like buttons and sliders go here.
4 
5  \author Michael Sögtrop
6  \date Created 11/19/2003
7 
8  Copyright: 2003-2004 (c) Michael Sögtrop
9 
10  Licence: wxWidgets Licence
11 
12  RCS-ID: $Id: canwidget.h,v 1.20 2008/10/21 21:48:30 titato Exp $
13 */
14 
15 #ifndef __WXCANSELECT_H__
16 #define __WXCANSELECT_H__
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/canvas/candefs.h"
23 #include "wx/canvas/canobj.h"
24 #include "wx/canvas/canprim.h"
25 #include "wx/canvas/rectangle.h"
26 
27 //!a2dWidgetButton is a a2dCanvasObject based button in a canvas
28 /*!
29 a2dWidgetButton implements a a2dCanvasObject based button.
30 This is usefull for selecting objects from a a2dCanvas that is used
31 as a palette of objects, styles or tools.
32 If the object is selected, it is drawn with the styles set by SetSelectedStroke
33 and SetSelectedFill. Otherwise it is drawn by the usual style for this object.
34 The default selected style is a one pixel black line and white fill.
35 The default non-selected style is transparent stroke and fill.
36 
37 a2dWidgetButton does not need a tool. It processes Mouse events.
38 Events are first processed by the class itself, and if not handled, redirected to m_parent.
39 You can also connect dynamically to the wxEvtHandler which is a base class.
40 
41 \ingroup canvasobject
42 */
43 class A2DCANVASDLLEXP a2dWidgetButton: public a2dWindowMM
44 {
45 
46 public:
47 
49  {
50  Boundingbox, /*!< The width and height is the boundingbox of the m_content OR-ed with the button and children.*/
51  BoundingboxSize, /*!< Like Boundingbox, but objects with negative extend are shifted positive.*/
52  ScaledContent, /*!< The width and height button, m_content are scaled to fit in.*/
53  ScaledContentKeepAspect, /*!< like ScaledContent, but keep aspect ratio.*/
54  };
55 
56  //! Standard constructor
57  a2dWidgetButton( a2dCanvasObject* parent, int buttonId, double x, double y, double w, double h, WidgetMode mode = Boundingbox );
58 
59  a2dWidgetButton( const a2dWidgetButton& other, CloneOptions options, a2dRefMap* refs );
60 
61  //! destructor
62  ~a2dWidgetButton();
63 
64  //! set parent object, this is where events are sent if not handled in this.
65  virtual void SetParent( a2dCanvasObject* parent ) { m_parent = parent; }
66 
67  //! get parent object as event handler.
68  virtual wxEvtHandler* GetParentEvtHandler() { return m_parent; }
69 
70  //! Set the content object.
71  /*!
72  child objects can be added to a button, but they will always be drawn unscaled, independent
73  of WidgetMode. Therefore one can not fit the children inside of the boundingbox of the button.
74  It is important to be able to split normalized content from child objects, for example when
75  object tips that are added to the button. Such an object tip should never be scaled, when the
76  button itself is resized. So the prefered manner of setting the drawing for a button is using
77  SetContentObject(). Children should be used for decorating the button itself, not for
78  fitting/scaling the inside drawing of the button.
79  */
80  void SetContentObject( a2dCanvasObject* content ) { m_content = content; }
81 
82  //! Get the content object, \see SetContentObject()
83  a2dCanvasObject* GetContentObject() { return m_content; }
84 
85  //! Set the border width around the content
86  void SetContentBorder( double contentBorder ) { m_contentBorder = contentBorder; }
87 
88  //! Get the border width around the content
89  double GetContentBorder() { return m_contentBorder; }
90 
91  //! Set the selected stroke style for the button
92  void SetSelectedStroke( const a2dStroke& selectedStroke ) { m_selectedStroke = selectedStroke; }
93  //! Set the selected fill style for the button
94  void SetSelectedFill( const a2dFill& selectedFill ) { m_selectedFill = selectedFill; }
95 
96  //! Set the selected stroke style for the button
97  void SetHighLightStroke( const a2dStroke& highLightStroke ) { m_highLightStroke = highLightStroke; }
98 
99  //! Set the selected fill style for the button
100  void SetHighLightFill( const a2dFill& highLightFill ) { m_highLightFill = highLightFill; }
101 
102  //! id used for button event.
103  int GetButtonId() { return m_buttonId; }
104 
105 // overrides from base class a2dCanvasObject
106 protected:
107 
108  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
109  void DoWalker( wxObject* parent, a2dWalkerIOHandler& handler );
110 
111  virtual void DrawHighLighted( a2dIterC& ic );
112 
113  virtual void Render( a2dIterC& ic, OVERLAP clipparent );
114  virtual bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
115  virtual a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
116  virtual void DoRender( a2dIterC& ic, OVERLAP clipparent );
117 
118  bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
119 
120  // event handlers
121  DECLARE_CLASS( a2dWidgetButton )
122  DECLARE_EVENT_TABLE()
123 
124  //! handler for EVT_CANVASOBJECT_ENTER_EVENT
125  void OnEnterObject( a2dCanvasObjectMouseEvent& event );
126 
127  //! handler for EVT_CANVASOBJECT_LEAVE_EVENT
128  void OnLeaveObject( a2dCanvasObjectMouseEvent& event );
129 
130  //! handler for EVT_CANVASOBJECT_MOUSE_EVENT
131  void OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event );
132 
133 // member variables
134 protected:
135 
136  //! \see SetSelectedStroke
137  a2dStroke m_selectedStroke;
138 
139  //! \see SetSelectedFill
140  a2dFill m_selectedFill;
141 
142  //! \see SetSelectedStroke
143  a2dStroke m_highLightStroke;
144 
145  //! \see SetSelectedFill
146  a2dFill m_highLightFill;
147 
148  //! event id used when sending events
149  int m_buttonId;
150 
151  //! type of button rendering of the m_content object.
152  WidgetMode m_mode;
153 
154  //! here a border between the button and the content can be given
155  double m_contentBorder;
156 
157  //! the button its graphics, which will be scaled in WidgetMode::ScaleChildren
159 
160  //! events are sent from the button to this object, if not handled by the button itself.
161  //* This is intentionally not a smart pointer to remove a reference loop */
162  a2dCanvasObject* m_parent;
163 
164  //! for scaling/translating the m_content
165  a2dAffineMatrix m_contentWorld;
166 };
167 
168 
169 //! Holds several a2dWidgetButton and othere a2dCanvasObject's
170 /*!
171  For a2dWidgetButton childs, the EVT_CANVASOBJECT_BUTTON_ANY is intercepted,
172  and the wxEVT_COMMAND_CHOICE_SELECTED is sent to that a2dWidgetButton to process it.
173 */
174 class A2DCANVASDLLEXP a2dWidgetButtonGroup: public a2dCanvasObject
175 {
176 public:
177 
178  //! Standard constructor
179  a2dWidgetButtonGroup( a2dCanvasObject* parent, double x, double y, float extra = 0 );
180  //! destructor
182 
183  virtual wxEvtHandler* GetParentEvtHandler() { return m_parent.Get(); }
184 
185  //! If set to true (default), only a single object can be selected
186  void SetSingleSelect( bool singleSelect ) { m_singleSelect = singleSelect; }
187 
188  //! set parent object of the pin or some other objects that needs a parent
189  virtual void SetParent( a2dCanvasObject* parent ) { m_parent = parent; }
190 
191  // overrides from base class a2dCanvasObject
192 protected:
193 
194  virtual void DoRender( a2dIterC& ic, OVERLAP clipparent );
195 
196  // event handlers
197  DECLARE_CLASS( a2dWidgetButtonGroup )
198  DECLARE_EVENT_TABLE()
199 
200  void OnAnyButton( wxCommandEvent& event );
201 
202  // member variables
203 protected:
204 
205  //! \see SetSingleSelect
206  bool m_singleSelect;
207 
208  a2dCanvasObjectPtr m_parent;
209 };
210 
211 //!specialized a2dWidgetButton which processes a given a2dCommand
212 /*!
213  /! rodo what is m_event doing?
214 */
215 class A2DCANVASDLLEXP a2dWidgetButtonCommand: public a2dWidgetButton
216 {
217 public:
218 
219  //! Standard constructor
220  a2dWidgetButtonCommand( a2dCanvasObject* parent, int buttonId, double x, double y, double w, double h, WidgetMode mode = Boundingbox );
221  //! destructor
223 
224  //! If set this command will be executed when the object is selected
225  /*! If the document has a command processor, the command is sent to this
226  command processor. Otherwise it is sent to the global a2dDocumentCommandProcessor */
227  void SetCanvasCommand( class a2dCommand* command );
228 
229  //! If set this event will be triggered when the object is selected
230  /*! The event is owned and deleted by the widget.
231  If the top level window of the app is a MDI frame, the command is sent
232  to the active child windows of the MDI frane.
233  Otherwise the command is sent to the top level window itself. */
234  void SetEvent( wxEvent* event );
235 
236  //! Set a client data object owned by the command buton
237  /*! This is used for events that need a wxClientData object.
238  The event won't own or delete such an object but as the event is owned
239  by the command button, the command button must take care of this also.
240  The command button does not use this in any way, it simply deletes
241  it, when it deletes the event.
242  */
243  void SetClientData( wxClientData* clientData ) { m_clientData = clientData; }
244 
245  // overrides from base class a2dCanvasObject
246 protected:
247 
248  // event handlers
249  DECLARE_CLASS( a2dWidgetButtonCommand )
250  DECLARE_EVENT_TABLE()
251 
252  void OnAnyChoice( wxCommandEvent& event );
253 
254  // member variables
255 protected:
256 
257  //! \see SetCanvasCommand
258  class a2dCommand* m_docviewCommand;
259  //! \see SetEvent
260  wxEvent* m_event;
261  //! Client data (usually used for the event)
262  wxClientData* m_clientData;
263 };
264 
265 #endif
266 
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: rectangle.cpp:723
virtual void Render(a2dIterC &ic, OVERLAP clipparent)
Render this object to the active a2dDrawingPart.
Definition: canobj.cpp:4712
all basic primitives derived from a2dCanvasObject
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
mouse event sent from a2dCanvasObject to itself
Definition: canglob.h:223
a2dBoundingBox DoGetUnTransformedBbox(a2dBboxFlags flags=a2dCANOBJ_BBOX_NON) const
In derived object this should be overriden to calculate the boundingbox of the object without its chi...
Definition: rectangle.cpp:507
Holds several a2dWidgetButton and othere a2dCanvasObject&#39;s.
Definition: canwidget.h:174
void SetHighLightFill(const a2dFill &highLightFill)
Set the selected fill style for the button.
Definition: canwidget.h:100
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: rectangle.cpp:590
Ref Counted base object.
Definition: gen.h:1045
double GetContentBorder()
Get the border width around the content.
Definition: canwidget.h:89
void SetClientData(wxClientData *clientData)
Set a client data object owned by the command buton.
Definition: canwidget.h:243
virtual void SetParent(a2dCanvasObject *parent)
set parent object of the pin or some other objects that needs a parent
Definition: canwidget.h:189
OVERLAP
Result of a a2dBoundingBox intersection or hittest.
Definition: bbox.h:24
virtual wxEvtHandler * GetParentEvtHandler()
get parent object as event handler.
Definition: canwidget.h:68
The base class for all drawable objects in a a2dCanvasDocument.
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
bool DoUpdate(UpdateMode mode, const a2dBoundingBox &childbox, const a2dBoundingBox &clipbox, const a2dBoundingBox &propbox)
Update derived Object specific things ( mainly boundingbox)
Definition: rectangle.cpp:885
defenitions an no more
specialized a2dWidgetButton which processes a given a2dCommand
Definition: canwidget.h:215
virtual void SetParent(a2dCanvasObject *parent)
set parent object, this is where events are sent if not handled in this.
Definition: canwidget.h:65
Io handler to iterate through a a2dDocument.
Definition: gen.h:3911
void SetContentBorder(double contentBorder)
Set the border width around the content.
Definition: canwidget.h:86
rectangular shapes derived from a2dCanvasObject
int GetButtonId()
id used for button event.
Definition: canwidget.h:103
void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
Definition: rectangle.cpp:756
void SetContentObject(a2dCanvasObject *content)
Set the content object.
Definition: canwidget.h:80
void SetHighLightStroke(const a2dStroke &highLightStroke)
Set the selected stroke style for the button.
Definition: canwidget.h:97
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
virtual void DrawHighLighted(a2dIterC &ic)
called by Render() if m_flags.m_HighLight is set
Definition: canobj.cpp:5020
a2dCanvasObject * GetContentObject()
Get the content object,.
Definition: canwidget.h:83
void SetSelectedFill(const a2dFill &selectedFill)
Set the selected fill style for the button.
Definition: canwidget.h:94
void SetSingleSelect(bool singleSelect)
If set to true (default), only a single object can be selected.
Definition: canwidget.h:186
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
a2dWidgetButton is a a2dCanvasObject based button in a canvas
Definition: canwidget.h:43
a2dWindowMM
Definition: rectangle.h:186
void SetSelectedStroke(const a2dStroke &selectedStroke)
Set the selected stroke style for the button.
Definition: canwidget.h:92
structure to give as parameter to member functions of a2dCanvasObject
Definition: canobj.h:252
virtual void DoWalker(wxObject *parent, a2dWalkerIOHandler &handler)
iterate over this object and its children
Definition: canobj.cpp:5504
a base command for the a2dCommandProcessor
Definition: comevt.h:140
canwidget.h Source File -- Sun Oct 12 2014 17:04:15 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation