File: GridShape.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 (189 lines) | stat: -rw-r--r-- 7,673 bytes parent folder | download | duplicates (6)
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
/***************************************************************
 * Name:      GridShape.h
 * Purpose:   Defines grid shape class
 * Author:    Michal Bližňák (michal.bliznak@tiscali.cz)
 * Created:   2008-08-02
 * Copyright: Michal Bližňák
 * License:   wxWidgets license (www.wxwidgets.org)
 * Notes:
 **************************************************************/

#ifndef _WXSFGRIDSHAPE_H
#define _WXSFGRIDSHAPE_H

#include <wx/wxsf/RectShape.h>

// default values
/*! \brief Default value of wxSFGridShape::m_nRows data member. */
#define sfdvGRIDSHAPE_ROWS 3
/*! \brief Default value of wxSFGridShape::m_nCols data member. */
#define sfdvGRIDSHAPE_COLS 3
/*! \brief Default value of wxSFGridShape::m_nCellSpace data member. */
#define sfdvGRIDSHAPE_CELLSPACE 5

/*!
 * \brief Class encapsulates a rectangular shape derived from wxSFRectShape class which acts as a grid-based
 * container able to manage other assigned child shapes (it can control their position). The managed
 * shapes are aligned into defined grid with a behaviour similar to classic wxWidget's wxGridSizer class.
 */
class WXDLLIMPEXP_SF wxSFGridShape : public wxSFRectShape
{
    public:
        XS_DECLARE_CLONABLE_CLASS(wxSFGridShape);
		
		friend class wxSFDiagramManager;

        /*! \brief Default constructor. */
        wxSFGridShape();
        /*!
         * \brief User constructor.
         * \param pos Initial position
         * \param size Initial size
         * \param rows Number of grid rows
         * \param cols Number of grid columns
         * \param cellspace Additional space between managed shapes
         * \param manager Pointer to parent diagram manager
         */
        wxSFGridShape(const wxRealPoint& pos, const wxRealPoint& size, int rows, int cols, int cellspace, wxSFDiagramManager* manager);
        /*!
        * \brief Copy constructor.
        * \param obj Reference to the source object
        */
        wxSFGridShape(const wxSFGridShape& obj);
        /*! \brief Destructor. */
        virtual ~wxSFGridShape();

        // public member data accessors

        /*!
        * \brief Set grid dimensions.
        * \param rows Number of rows
        * \param cols Number of columns
        */
        void SetDimensions(int rows, int cols);
        /*!
        * \brief Set space between grid cells (managed shapes).
        * \param cellspace Cellspace size
        */
        void SetCellSpace(int cellspace){m_nCellSpace = cellspace;}
        /*!
        * \brief Get grid dimensions.
        * \param rows Pointer to variable where number of rows will be stored
        * \param cols Pointer to variable where number of columns will be stored
        */
        void GetDimensions(int *rows, int *cols);
        /*!
        * \brief Get space between grid cells (managed shapes).
        * \return Cellspace size
        */
        int GetCellSpace(){return m_nCellSpace;}
		
       /*!
        * \brief Get managed shape specified by lexicographic cell index.
        * \param index Lexicographic index of requested shape
        * \return Pointer to shape object of given cell index if exists, otherwise NULL
        */
		wxSFShapeBase *GetManagedShape(size_t index);
       /*!
        * \brief Get managed shape specified by row and column indexes.
        * \param row Zero-base row index
        * \param col Zero-based column index
        * \return Pointer to shape object stored in specified grid cell if exists, otherwise NULL
        */
		wxSFShapeBase *GetManagedShape(int row, int col);

        // public functions

        /*!
         * \brief Clear information about managed shapes and set number of rows and columns to zero.
         *
         * Note that this function doesn't remove managed (child) shapes from the parent grid shape
         * (they are still its child shapes but aren't managed anymore).
         */
        void ClearGrid();
        /*!
        * \brief Append given shape to the grid at the last managed position.
        * \param shape Pointer to appended shape
        */
        bool AppendToGrid(wxSFShapeBase *shape);
        /*!
        * \brief Insert given shape to the grid at the given position.
        *
        * Note that the grid can grow in a vertical direction only, so if the user specify desired
        * horizontal position bigger than the current number of columns is then this function exits with
        * an error (false) return value. If specified vertical position exceeds the number or grid rows than
        * the grid is resized. If the given position (grid cell) is already occupied by some shape then the previous
        * one will be moved to the grid's last lexicographic position.
        * \param row Vertical position
        * \param col Horizontal position
        * \param shape Pointer to inserted shape
        * \return True on success, otherwise False
        */
        bool InsertToGrid(int row, int col, wxSFShapeBase *shape);
        /*!
        * \brief Insert given shape to the grid at the given position.
        *
        * Note that the given index is a lexicographic position of inserted shape. The given shape is inserted before
        * the existing item 'index', thus InsertToGrid(0, something) will insert an item in such way that it will become
        * the first grid element.
        * \param index Lexicographic position of inserted shape
        * \param shape Pointer to inserted shape
        * \return True on successe, otherwise False
        */
        bool InsertToGrid(int index, wxSFShapeBase *shape);
		/**
		 * \brief Remove shape with given ID from the grid.
		 * \param id ID of shape which should be removed
		 */
		void RemoveFromGrid(long id);

        // public virtual functions
        /*! \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 Do layout of assigned child shapes */
        virtual void DoChildrenLayout();

        /*!
         * \brief Event handler called when any shape is dropped above this shape (and the dropped
         * shape is accepted as a child of this shape). The function can be overrided if necessary.
         *
         * The function is called by the framework (by the shape canvas).
         * \param pos Relative position of dropped shape
         * \param child Pointer to dropped shape
         */
        virtual void OnChildDropped(const wxRealPoint& pos, wxSFShapeBase *child);

    protected:
        // protected data members
        /*! \brief Number of grid rows. */
        int m_nRows;
        /*! \brief Number of grid columns. */
        int m_nCols;
        /*! \brief Space additional space between managed shapes. */
        int m_nCellSpace;
        /*! \brief Array containing the IDs of managed shapes. */
        wxXS::IntArray m_arrCells;

        // protected functions
        /*!
         * \brief Move and resize given shape so it will fit the given bounding rectangle.
         *
         * The shape is aligned inside the given bounding rectangle in accordance to the shape's
         * valign and halign flags.
         * \param shape Pointer to modified shape
         * \param rct Bounding rectangle
         * \sa wxSFShapeBase::SetVAlign, wxSFShapeBase::SetHAlign
         */
        void FitShapeToRect( wxSFShapeBase *shape, const wxRect& rct);

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

#endif // _WXSFGRIDSHAPE_H