File: ControlShape.h

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (311 lines) | stat: -rw-r--r-- 11,054 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/***************************************************************
 * Name:      ControlShape.h
 * Purpose:   Defines GUI control shape class
 * Author:    Michal Bližňák (michal.bliznak@tiscali.cz)
 * Created:   2008-04-30
 * Copyright: Michal Bližňák
 * License:   wxWidgets license (www.wxwidgets.org)
 * Notes:
 **************************************************************/

#ifndef _WXSFCONTROLSHAPE_H
#define _WXSFCONTROLSHAPE_H

#include <wx/wxsf/RectShape.h>

#define sfFIT_SHAPE_TO_CONTROL true
#define sfFIT_CONTROL_TO_SHAPE false

#define sfdvCONTROLSHAPE_CONTROLOFFSET 0
#define sfdvCONTROLSHAPE_PROCESSEVENTS wxSFControlShape::evtKEY2CANVAS | wxSFControlShape::evtMOUSE2CANVAS
#define sfdvCONTROLSHAPE_MODFILL wxBrush(*wxBLUE, wxBRUSHSTYLE_BDIAGONAL_HATCH)
#define sfdvCONTROLSHAPE_MODBORDER wxPen(*wxBLUE, 1, wxPENSTYLE_SOLID)

class WXDLLIMPEXP_SF wxSFControlShape;

/*!
 * \brief Auxiliary class used by wxSFControlShape. All events generated by a GUI control (widget)
 * managed by parent control shape are redirected to this event sink which invokes a default event handler
 * or send a copy of the event to shape canvas if requested.
 */
class EventSink : public wxEvtHandler
{
public:
    /*! \brief Default constructor. */
    EventSink();
    /*!
     * \brief User constructor.
     * \param parent Pointer to parent control shape
     */
    EventSink(wxSFControlShape *parent);
    /*! \brief Destructor. */
    virtual ~EventSink();

    // public functions
	/*!
     * \brief Event handler used for delayed processing of a mouse button events.
	 * The handler creates new key event instance and sends it to a shape canvas for further processing.
	 * \param event Mouse event
	 */
	void _OnMouseButton(wxMouseEvent &event);
	/*!
     * \brief Event handler used for delayed processing of a mouse event (mouse movement).
	 * The handler creates new key event instance and sends it to a shape canvas for further processing.
	 * \param event Mouse event
	 */
	void _OnMouseMove(wxMouseEvent &event);
	/*!
	 * \brief Event handler used for delayed processing of a key event.
	 * The handler creates new key event instance and sends it to a shape canvas for further processing.
	 * \param event Keyboard event
	 */
	void _OnKeyDown(wxKeyEvent &event);

    /*! \brief Event handler used for adjusting the parent shape's size in accordance to size of managed GUI control. */
	void _OnSize(wxSizeEvent &event);

protected:
    // protected data members
    /*! \brief Poineter to parent contol shape. */
    wxSFControlShape *m_pParentShape;

    // protected functions
	/*!
	 * \brief Send copy of incomming event to a shape canvas.
	 * \param event Event to be send
	 */
    void SendEvent(wxEvent &event);
	/*!
	 * \brief Modify given mouse event (recalculate the event's position in accordance to parent control
	 * shape's position.
	 * \param event Mouse event to be updated;
	 */
    void UpdateMouseEvent(wxMouseEvent &event);
};

/*!
 * \brief Class encapsulates a special shape able to manage assigned GUI controls (widgets). The GUI control's
 * position and size can by modified via parent control shape. User can also specify how events incoming from the
 * managed GUI control are processed.
 *
 * Note that the managed controls use a shape canvas as their parent window so these shapes cannot be used
 * without existing and properly initialized shape canvas. Moreover, managed GUI controls are not serialized in any
 * way internaly so it is completely up to the user to provide this functionality if needed.
 */
class WXDLLIMPEXP_SF wxSFControlShape : public wxSFRectShape
{
public:
    friend class EventSink;

    XS_DECLARE_CLONABLE_CLASS(wxSFControlShape)

    /*! \brief Way of processing of GUI control's events. */
    enum EVTPROCESSING
    {
        /*! \brief Event isn't processed. */
        evtNONE = 0,
        /*! \brief Keyboard events are processed by the GUI control. */
        evtKEY2GUI = 1,
        /*! \brief Keyboard events are send to a shape canvas. */
        evtKEY2CANVAS = 2,
        /*! \brief Mouse events are processed by the GUI control. */
        evtMOUSE2GUI = 4,
        /*! \brief Mouse events are send to a shape canvas. */
        evtMOUSE2CANVAS = 8
    };

    /*! \brief Default constructor. */
    wxSFControlShape();
    /*!
     * \brief User constructor.
     * \param ctrl Pointer to managed GUI control
     * \param pos Initial position
     * \param size Initial size
     * \param manager Pointer to parent diagram manager
     */
    wxSFControlShape(wxWindow *ctrl, const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager);
    /*!
     * \brief Copy constructor.
     * \param obj Object to copy from
     */
    wxSFControlShape(const wxSFControlShape& obj);
    /*! \brief Default destructor. */
    virtual ~wxSFControlShape();

    // member data accessors
    /*!
     * \brief Set managed GUI control.
     * \param ctrl Pointer to existing manager GUI control
     * \param fit TRUE if the control shape should be resized in accordance to the given GUI control
     */
    void SetControl(wxWindow * ctrl, bool fit = sfFIT_SHAPE_TO_CONTROL);
    /*!
     * \brief Get pointer to managed GUI control.
     * \return Pointer to the GUI control
     */
    wxWindow * GetControl() { return m_pControl; }
    /*!
     * \brief Set a way how GUI control's events are processed.
     * \param mask Event processing
     * \sa EVTPROCESSING
     */
    void SetEventProcessing(int mask){m_nProcessEvents = mask;}
    /*!
     * \brief Get a way how GUI control's events are processed.
     * \return Combination of EVTPROCESSING flags
     * \sa EVTPROCESSING
     */
    int GetEventProcessing(){return m_nProcessEvents;}
    /*!
     * \brief Set control shape's background style used during its modification.
     * \param brush Reference to used brush
     */
    void SetModFill(const wxBrush& brush){m_ModFill = brush;}
    /*!
     * \brief Get control shape's background style used during its modification.
     * \return Used brush
     */
    wxBrush GetModFill(){return m_ModFill;}
    /*!
     * \brief Set control shape's border styl used during its modification.
     * \param pen Reference to used pen
     */
    void SetModBorder(const wxPen& pen){m_ModBorder = pen;}
    /*!
     * \brief Get control shape's border styl used during its modification.
     * \return Used pen
     */
    wxPen GetModBorder(){return m_ModBorder;}
    /*!
     * \brief Set control shape's offset (a gap between the shape's border and managed GUI control).
     * \param offset Offset size
     */
    void SetControlOffset(int offset){m_nControlOffset = offset;}
    /*!
     * \brief Get control shape's offset (a gap between the shape's border and managed GUI control).
     * \return Offset size
     */
    int GetControlOffset(){return m_nControlOffset;}
	
	// public functions
    /*! \brief Update size and position of the managed control according to the parent shape. */
    void UpdateControl();
    /*! \brief Update size of the shape position according to the managed control. */
    void UpdateShape();

    // public virtual functions

    /*!
	 * \brief Scale the shape size by in both directions. The function can be overrided if necessary
     * (new implementation should call default one ore scale shape's children manualy if neccesary).
     * \param x Horizontal scale factor
     * \param y Vertical scale factor
     * \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
     */
	virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
	/*!
	 * \brief Move the shape to the given absolute position. The function can be overrided if necessary.
	 * \param x X coordinate
	 * \param y Y coordinate
	 */
	virtual void MoveTo(double x, double y);
	/*!
	 * \brief Move the shape by the given offset. The function can be overrided if neccessary.
	 * \param x X offset
	 * \param y Y offset
	 */
	virtual void MoveBy(double x, double y);
	
	/*! \brief Upate shape (align all child shapes an resize it to fit them) */
	virtual void Update();

    /*! \brief Resize the shape to bound all child shapes. The function can be overrided if neccessary. */
	virtual void FitToChildren();

	/*!
	 * \brief Event handler called at the beginning of the shape dragging process.
	 * The function can be overrided if necessary.
	 *
	 * The function is called by the framework (by the shape canvas).
	 * Default implementation does nothing.
	 * \sa wxSFShapeCanvas
	 */
	virtual void OnBeginDrag(const wxPoint& pos);
	/*!
	 * \brief Event handler called at the end of the shape dragging process.
	 * The function can be overrided if necessary.
	 *
	 * The function is called by the framework (by the shape canvas).
	 * Default implementation does nothing.
	 * \param pos Current mouse position
	 * \sa wxSFShapeCanvas
	 */
	virtual void OnEndDrag(const wxPoint& pos);
	/*!
	 * \brief Event handler called when the user started to drag the shape handle.
	 * The function can be overrided if necessary.
	 *
	 * The function is called by the framework (by the shape canvas).
	 * Default implementation does nothing.
	 * \param handle Reference to dragged handle
	 */
	virtual void OnBeginHandle(wxSFShapeHandle& handle);
	/*!
	 * \brief Event handler called during dragging of the shape handle.
	 * The function can be overrided if necessary.
	 *
	 * The function is called by the framework (by the shape canvas).
	 * Default implementation does nothing.
	 * \param handle Reference to dragged handle
	 */
	virtual void OnHandle(wxSFShapeHandle& handle);
	/*!
	 * \brief Event handler called when the user finished dragging of the shape handle.
	 * The function can be overrided if necessary.
	 *
	 * The function is called by the framework (by the shape canvas).
	 * Default implementation does nothing.
	 * \param handle Reference to dragged handle
	 */
	virtual void OnEndHandle(wxSFShapeHandle& handle);

protected:

    // protected data members

    /*! \brief Pointer to manager data control. */
    wxWindow * m_pControl;
    /*! \brief Events processing mask */
    int m_nProcessEvents;

    /*! \brief Brush used during the shape's modification. */
    wxBrush m_ModFill;
    /*! \brief Pen used during the shape's modification. */
    wxPen m_ModBorder;
    /*! \brief Offset between the shape and managed GUI control. */
    int m_nControlOffset;

    // protected functions

private:

    // private data members

    /*! \brief Pointer to parent window. */
    wxWindow * m_pPrevParent;
    /*! \brief Pointer to event sink.*/
    EventSink * m_pEventSink;
    /*! \brief Previous canvas style. */
    long m_nPrevStyle;
    /*! \brief Previously used shape's brush. */
    wxBrush m_PrevFill;
    /*! \brief Previously used shape's pen. */
    wxPen m_PrevBorder;

    // private functions
	 /*! \brief Initialize serializable properties. */
	void MarkSerializableDataMembers();

};

#endif //_WXSFCONTROLSHAPE_H