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
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.
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.
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/>.
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 $
30
wxsRegisterItem<wxsGrid> Reg(_T("Grid"),wxsTWidget,_T("Advanced"),70);
32
WXS_ST_BEGIN(wxsGridStyles,_T(""))
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)
55
//------------------------------------------------------------------------------
57
wxsGrid::wxsGrid(wxsItemResData* Data):
68
m_LabelRowHeight = -1;
70
m_DefaultRowSize = -1;
71
m_DefaultColSize = -1;
74
//------------------------------------------------------------------------------
76
void wxsGrid::OnBuildCreatingCode()
78
switch ( GetLanguage() )
82
AddHeader(_T("<wx/grid.h>"),GetInfo().ClassName,0);
83
AddHeader(_T("<wx/grid.h>"),_T("wxGridEvent"),0);
85
Codef( _T("%C(%W, %I, %P, %S, %T, %N);\n") );
87
if ( GetPropertiesFlags() & flSource )
89
if ( m_ColsCount>=0 && m_RowsCount>=0 && (m_ColsCount>0 || m_RowsCount>0) )
91
Codef( _T("%ACreateGrid(%d,%d);\n"), m_RowsCount, m_ColsCount );
92
BuildSetupWindowCode();
94
Codef( _T("%AEnableEditing(%b);\n"), !m_ReadOnly);
95
Codef( _T("%AEnableGridLines(%b);\n"), m_GridLines);
97
if (m_LabelRowHeight > 0) Codef(_T("%ASetColLabelSize(%d);\n"), m_LabelRowHeight);
98
if (m_LabelColWidth > 0) Codef(_T("%ASetRowLabelSize(%d);\n"), m_LabelColWidth);
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);
103
wxString ss = m_LabelTextColour.BuildCode( GetCoderContext() );
104
if (ss.Len() > 0) Codef(_T("%ASetLabelTextColour(%s);\n"), ss.wx_str());
106
ss = GetCoderContext()->GetUniqueName( _T("GridLabelFont") );
107
wxString tt = m_LabelFont.BuildFontCode(ss, GetCoderContext());
110
Codef(_T("%s"), tt.wx_str());
111
Codef(_T("%ASetLabelFont(%s);\n"), ss.wx_str());
114
int n = wxMin( (int)m_ColLabels.GetCount(), m_ColsCount );
115
for ( int i=0; i<n; i++ )
117
Codef(_T("%ASetColLabelValue(%d, %t);\n"), i, m_ColLabels[i].wx_str());
120
n = wxMin( (int)m_RowLabels.GetCount(), m_RowsCount );
121
for ( int i=0; i<n; i++)
123
Codef(_T("%ASetRowLabelValue(%d, %t);\n"), i, m_RowLabels[i].wx_str());
126
n = (int)m_CellText.GetCount();
128
for ( int j=0; j<m_RowsCount && i<n; j++ )
130
for ( int k=0; k<m_ColsCount && i<n; k++, i++ )
132
Codef( _T("%ASetCellValue(%d, %d, %t);\n"), j, k, m_CellText[i].wx_str());
136
// default cell font and text colour
138
Codef(_T("%ASetDefaultCellFont( %AGetFont() );\n"));
140
Codef(_T("%ASetDefaultCellTextColour( %AGetForegroundColour() );\n"));
150
wxsCodeMarks::Unknown(_T("wxsGrid::OnBuildCreatingCode"),GetLanguage());
155
//------------------------------------------------------------------------------
157
wxObject* wxsGrid::OnBuildPreview( wxWindow* parent, long flags )
159
wxGrid* preview = new wxGrid( parent, GetId(), Pos(parent), Size(parent), Style() );
161
if ( GetPropertiesFlags() & flSource )
163
if ( m_ColsCount>=0 && m_RowsCount>=0 && (m_ColsCount>0 || m_RowsCount>0) )
165
preview->CreateGrid( m_RowsCount, m_ColsCount );
166
SetupWindow( preview, flags );
168
preview->EnableEditing( !m_ReadOnly);
169
preview->EnableGridLines( m_GridLines );
171
if ( m_LabelRowHeight > 0 ) preview->SetColLabelSize( m_LabelRowHeight );
172
if ( m_LabelColWidth > 0 ) preview->SetRowLabelSize( m_LabelColWidth );
174
if ( m_DefaultRowSize > 0 ) preview->SetDefaultRowSize( m_DefaultRowSize, true );
175
if ( m_DefaultColSize > 0 ) preview->SetDefaultColSize( m_DefaultColSize, true );
177
wxColour cc = m_LabelTextColour.GetColour();
180
preview->SetLabelTextColour(cc);
183
wxFont labelfont = m_LabelFont.BuildFont();
184
if ( labelfont.IsOk() )
186
preview->SetLabelFont( labelfont );
189
int n = wxMin( (int)m_ColLabels.GetCount(), m_ColsCount );
190
for ( int i=0; i<n; i++ )
192
preview->SetColLabelValue( i, m_ColLabels[i] );
195
n = wxMin( (int)m_RowLabels.GetCount(), m_RowsCount );
196
for( int i=0; i<n; i++ )
198
preview->SetRowLabelValue( i, m_RowLabels[i] );
201
n = (int)m_CellText.GetCount();
203
for ( int j=0; j<m_RowsCount && i<n; j++ )
205
for ( int k=0; k<m_ColsCount && i<n; k++, i++ )
207
preview->SetCellValue( j, k, m_CellText[i] );
211
wxFont cellfont = preview->GetFont();
212
if ( cellfont.IsOk() )
214
preview->SetDefaultCellFont(cellfont);
217
cc = preview->GetForegroundColour();
218
preview->SetDefaultCellTextColour(cc);
226
//------------------------------------------------------------------------------
228
void wxsGrid::OnEnumWidgetProperties(long Flags)
230
if ( Flags & flSource )
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"));