~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/defitems/wxsgrid.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**  \file wxsgrid.cpp
 
2
*
 
3
* This file is part of wxSmith plugin for Code::Blocks Studio
 
4
* Copyright (C) 2006-2008  Bartlomiej Swiecki
 
5
* Copyright (C) 2008 Ron Collins
 
6
*
 
7
* wxSmith is free software; you can redistribute it and/or modify
 
8
* it under the terms of the GNU General Public License as published by
 
9
* the Free Software Foundation; either version 3 of the License, or
 
10
* (at your option) any later version.
 
11
*
 
12
* wxSmith is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
* GNU General Public License for more details.
 
16
*
 
17
* You should have received a copy of the GNU General Public License
 
18
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
 
19
*
 
20
* $Revision: 8335 $
 
21
* $Id: wxsgrid.cpp 8335 2012-09-03 07:43:04Z ollydbg $
 
22
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/src/plugins/contrib/wxSmith/wxwidgets/defitems/wxsgrid.cpp $
 
23
*/
 
24
 
 
25
#include "wxsgrid.h"
 
26
#include <wx/grid.h>
 
27
 
 
28
namespace
 
29
{
 
30
    wxsRegisterItem<wxsGrid> Reg(_T("Grid"),wxsTWidget,_T("Advanced"),70);
 
31
 
 
32
    WXS_ST_BEGIN(wxsGridStyles,_T(""))
 
33
        WXS_ST_DEFAULTS()
 
34
    WXS_ST_END()
 
35
 
 
36
    WXS_EV_BEGIN(wxsGridEvents)
 
37
        WXS_EVI(EVT_CMD_GRID_CELL_LEFT_CLICK,wxEVT_GRID_CELL_LEFT_CLICK,wxGridEvent,CellLeftClick)
 
38
        WXS_EVI(EVT_CMD_GRID_CELL_RIGHT_CLICK,wxEVT_GRID_CELL_RIGHT_CLICK,wxGridEvent,CellRightClick)
 
39
        WXS_EVI(EVT_CMD_GRID_CELL_LEFT_DCLICK,wxEVT_GRID_CELL_LEFT_DCLICK,wxGridEvent,CellLeftDClick)
 
40
        WXS_EVI(EVT_CMD_GRID_CELL_RIGHT_DCLICK,wxEVT_GRID_CELL_RIGHT_DCLICK,wxGridEvent,CellRightDClick)
 
41
        WXS_EVI(EVT_CMD_GRID_LABEL_LEFT_CLICK,wxEVT_GRID_LABEL_LEFT_CLICK,wxGridEvent,LabelLeftClick)
 
42
        WXS_EVI(EVT_CMD_GRID_LABEL_RIGHT_CLICK,wxEVT_GRID_LABEL_RIGHT_CLICK,wxGridEvent,LabelRightClick)
 
43
        WXS_EVI(EVT_CMD_GRID_LABEL_LEFT_DCLICK,wxEVT_GRID_LABEL_LEFT_DCLICK,wxGridEvent,LabelLeftDClick)
 
44
        WXS_EVI(EVT_CMD_GRID_LABEL_RIGHT_DCLICK,wxEVT_GRID_LABEL_RIGHT_DCLICK,wxGridEvent,LabelRightDClick)
 
45
        WXS_EVI(EVT_CMD_GRID_CELL_CHANGE,wxEVT_GRID_CELL_CHANGE,wxGridEvent,CellChange)
 
46
        WXS_EVI(EVT_CMD_GRID_SELECT_CELL,wxEVT_GRID_SELECT_CELL,wxGridEvent,CellSelect)
 
47
        WXS_EVI(EVT_CMD_GRID_EDITOR_HIDDEN,wxEVT_GRID_EDITOR_HIDDEN,wxGridEvent,EditorHidden)
 
48
        WXS_EVI(EVT_CMD_GRID_EDITOR_SHOWN,wxEVT_GRID_EDITOR_SHOWN,wxGridEvent,EditorShown)
 
49
 
 
50
        WXS_EV_DEFAULTS()
 
51
    WXS_EV_END()
 
52
 
 
53
}
 
54
 
 
55
//------------------------------------------------------------------------------
 
56
 
 
57
wxsGrid::wxsGrid(wxsItemResData* Data):
 
58
    wxsWidget(
 
59
        Data,
 
60
        &Reg.Info,
 
61
        wxsGridEvents,
 
62
        wxsGridStyles),
 
63
    m_ColsCount(0),
 
64
    m_RowsCount(0)
 
65
{
 
66
    m_ReadOnly       = false;
 
67
    m_GridLines      = true;
 
68
    m_LabelRowHeight = -1;
 
69
    m_LabelColWidth  = -1;
 
70
    m_DefaultRowSize = -1;
 
71
    m_DefaultColSize = -1;
 
72
}
 
73
 
 
74
//------------------------------------------------------------------------------
 
75
 
 
76
void wxsGrid::OnBuildCreatingCode()
 
77
{
 
78
    switch ( GetLanguage() )
 
79
    {
 
80
        case wxsCPP:
 
81
        {
 
82
            AddHeader(_T("<wx/grid.h>"),GetInfo().ClassName,0);
 
83
            AddHeader(_T("<wx/grid.h>"),_T("wxGridEvent"),0);
 
84
 
 
85
            Codef( _T("%C(%W, %I, %P, %S, %T, %N);\n") );
 
86
 
 
87
            if ( GetPropertiesFlags() & flSource )
 
88
            {
 
89
                if ( m_ColsCount>=0 && m_RowsCount>=0 && (m_ColsCount>0 || m_RowsCount>0) )
 
90
                {
 
91
                    Codef( _T("%ACreateGrid(%d,%d);\n"), m_RowsCount, m_ColsCount );
 
92
                    BuildSetupWindowCode();
 
93
 
 
94
                    Codef( _T("%AEnableEditing(%b);\n"),  !m_ReadOnly);
 
95
                    Codef( _T("%AEnableGridLines(%b);\n"), m_GridLines);
 
96
 
 
97
                    if (m_LabelRowHeight > 0) Codef(_T("%ASetColLabelSize(%d);\n"), m_LabelRowHeight);
 
98
                    if (m_LabelColWidth  > 0) Codef(_T("%ASetRowLabelSize(%d);\n"), m_LabelColWidth);
 
99
 
 
100
                    if (m_DefaultRowSize  > 0) Codef(_T("%ASetDefaultRowSize(%d, %b);\n"), m_DefaultRowSize, true);
 
101
                    if (m_DefaultColSize  > 0) Codef(_T("%ASetDefaultColSize(%d, %b);\n"), m_DefaultColSize, true);
 
102
 
 
103
                    wxString ss = m_LabelTextColour.BuildCode( GetCoderContext() );
 
104
                    if (ss.Len() > 0) Codef(_T("%ASetLabelTextColour(%s);\n"), ss.wx_str());
 
105
 
 
106
                    ss = GetCoderContext()->GetUniqueName( _T("GridLabelFont") );
 
107
                    wxString tt = m_LabelFont.BuildFontCode(ss, GetCoderContext());
 
108
                    if (tt.Len() > 0)
 
109
                    {
 
110
                        Codef(_T("%s"), tt.wx_str());
 
111
                        Codef(_T("%ASetLabelFont(%s);\n"), ss.wx_str());
 
112
                    }
 
113
 
 
114
                    int n = wxMin( (int)m_ColLabels.GetCount(), m_ColsCount );
 
115
                    for ( int i=0; i<n; i++ )
 
116
                    {
 
117
                        Codef(_T("%ASetColLabelValue(%d, %t);\n"), i, m_ColLabels[i].wx_str());
 
118
                    }
 
119
 
 
120
                    n = wxMin( (int)m_RowLabels.GetCount(), m_RowsCount );
 
121
                    for ( int i=0; i<n; i++)
 
122
                    {
 
123
                        Codef(_T("%ASetRowLabelValue(%d, %t);\n"), i, m_RowLabels[i].wx_str());
 
124
                    }
 
125
 
 
126
                    n = (int)m_CellText.GetCount();
 
127
                    int i = 0;
 
128
                    for ( int j=0; j<m_RowsCount && i<n; j++ )
 
129
                    {
 
130
                        for ( int k=0; k<m_ColsCount && i<n; k++, i++ )
 
131
                        {
 
132
                            Codef( _T("%ASetCellValue(%d, %d, %t);\n"), j, k, m_CellText[i].wx_str());
 
133
                        }
 
134
                    }
 
135
 
 
136
                    // default cell font and text colour
 
137
 
 
138
                    Codef(_T("%ASetDefaultCellFont( %AGetFont() );\n"));
 
139
 
 
140
                    Codef(_T("%ASetDefaultCellTextColour( %AGetForegroundColour() );\n"));
 
141
 
 
142
                }
 
143
            }
 
144
 
 
145
            return;
 
146
        }
 
147
 
 
148
        default:
 
149
        {
 
150
            wxsCodeMarks::Unknown(_T("wxsGrid::OnBuildCreatingCode"),GetLanguage());
 
151
        }
 
152
    }
 
153
}
 
154
 
 
155
//------------------------------------------------------------------------------
 
156
 
 
157
wxObject* wxsGrid::OnBuildPreview( wxWindow* parent, long flags )
 
158
{
 
159
    wxGrid* preview = new wxGrid( parent, GetId(), Pos(parent), Size(parent), Style() );
 
160
 
 
161
    if ( GetPropertiesFlags() & flSource )
 
162
    {
 
163
        if ( m_ColsCount>=0 && m_RowsCount>=0 && (m_ColsCount>0 || m_RowsCount>0) )
 
164
        {
 
165
            preview->CreateGrid( m_RowsCount, m_ColsCount );
 
166
            SetupWindow( preview, flags );
 
167
 
 
168
            preview->EnableEditing( !m_ReadOnly);
 
169
            preview->EnableGridLines( m_GridLines );
 
170
 
 
171
            if ( m_LabelRowHeight > 0 ) preview->SetColLabelSize( m_LabelRowHeight );
 
172
            if ( m_LabelColWidth  > 0 ) preview->SetRowLabelSize( m_LabelColWidth );
 
173
 
 
174
            if ( m_DefaultRowSize > 0 ) preview->SetDefaultRowSize( m_DefaultRowSize, true );
 
175
            if ( m_DefaultColSize > 0 ) preview->SetDefaultColSize( m_DefaultColSize, true );
 
176
 
 
177
            wxColour cc = m_LabelTextColour.GetColour();
 
178
            if ( cc.IsOk() )
 
179
            {
 
180
                preview->SetLabelTextColour(cc);
 
181
            }
 
182
 
 
183
            wxFont labelfont = m_LabelFont.BuildFont();
 
184
            if ( labelfont.IsOk() )
 
185
            {
 
186
                preview->SetLabelFont( labelfont );
 
187
            }
 
188
 
 
189
            int n = wxMin( (int)m_ColLabels.GetCount(), m_ColsCount );
 
190
            for ( int i=0; i<n; i++ )
 
191
            {
 
192
                preview->SetColLabelValue( i, m_ColLabels[i] );
 
193
            }
 
194
 
 
195
            n = wxMin( (int)m_RowLabels.GetCount(), m_RowsCount );
 
196
            for( int i=0; i<n; i++ )
 
197
            {
 
198
                preview->SetRowLabelValue( i, m_RowLabels[i] );
 
199
            }
 
200
 
 
201
            n = (int)m_CellText.GetCount();
 
202
            int i = 0;
 
203
            for ( int j=0; j<m_RowsCount && i<n; j++ )
 
204
            {
 
205
                for ( int k=0; k<m_ColsCount && i<n; k++, i++ )
 
206
                {
 
207
                    preview->SetCellValue( j, k, m_CellText[i] );
 
208
                }
 
209
            }
 
210
 
 
211
            wxFont cellfont = preview->GetFont();
 
212
            if ( cellfont.IsOk() )
 
213
            {
 
214
                preview->SetDefaultCellFont(cellfont);
 
215
            }
 
216
 
 
217
            cc = preview->GetForegroundColour();
 
218
            preview->SetDefaultCellTextColour(cc);
 
219
 
 
220
        }
 
221
    }
 
222
 
 
223
    return preview;
 
224
}
 
225
 
 
226
//------------------------------------------------------------------------------
 
227
 
 
228
void wxsGrid::OnEnumWidgetProperties(long Flags)
 
229
{
 
230
    if ( Flags & flSource )
 
231
    {
 
232
        WXS_LONG       ( wxsGrid, m_ColsCount,       _("Number of columns"),    _T("cols"),            0);
 
233
        WXS_LONG       ( wxsGrid, m_RowsCount,       _("Number of rows"),       _T("rows"),            0);
 
234
        WXS_BOOL       ( wxsGrid, m_ReadOnly,        _("Read Only"),            _T("readonly"),       false);
 
235
        WXS_BOOL       ( wxsGrid, m_GridLines,       _("Grid Lines"),           _T("gridlines"),      true);
 
236
        WXS_LONG       ( wxsGrid, m_LabelRowHeight,  _("Label Row Height"),     _T("labelrowheight"), -1);
 
237
        WXS_LONG       ( wxsGrid, m_LabelColWidth,   _("Label Column Width"),   _T("labelcolwidth"),  -1);
 
238
        WXS_LONG       ( wxsGrid, m_DefaultRowSize,  _("Default Row Height"),   _T("defaultrowsize"), -1);
 
239
        WXS_LONG       ( wxsGrid, m_DefaultColSize,  _("Default Column Width"), _T("defaultcolsize"), -1);
 
240
        WXS_COLOUR     ( wxsGrid, m_LabelTextColour, _("Label Text Colour"),    _T("labeltextcolour") );
 
241
        WXS_FONT       ( wxsGrid, m_LabelFont,       _("Label Text Font"),      _T("labelfont") );
 
242
        WXS_ARRAYSTRING( wxsGrid, m_ColLabels,       _("Column Labels"),        _T("collabels"), _T("item"));
 
243
        WXS_ARRAYSTRING( wxsGrid, m_RowLabels,       _("Row Labels"),           _T("rowlabels"), _T("item"));
 
244
        WXS_ARRAYSTRING( wxsGrid, m_CellText,        _("Cell Data"),            _T("celltext"),  _T("item"));
 
245
    }
 
246
}