1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWindows sample
4 // Author: Michael Bedward
7 // Copyright: (c) Michael Bedward, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma implementation
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/colordlg.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 IMPLEMENT_APP( GridApp
)
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 bool GridApp::OnInit()
57 GridFrame
*frame
= new GridFrame
;
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 BEGIN_EVENT_TABLE( GridFrame
, wxFrame
)
68 EVT_MENU( ID_TOGGLEROWLABELS
, GridFrame::ToggleRowLabels
)
69 EVT_MENU( ID_TOGGLECOLLABELS
, GridFrame::ToggleColLabels
)
70 EVT_MENU( ID_TOGGLEEDIT
, GridFrame::ToggleEditing
)
71 EVT_MENU( ID_TOGGLEROWSIZING
, GridFrame::ToggleRowSizing
)
72 EVT_MENU( ID_TOGGLECOLSIZING
, GridFrame::ToggleColSizing
)
73 EVT_MENU( ID_TOGGLEGRIDSIZING
, GridFrame::ToggleGridSizing
)
74 EVT_MENU( ID_SETLABELCOLOUR
, GridFrame::SetLabelColour
)
75 EVT_MENU( ID_SETLABELTEXTCOLOUR
, GridFrame::SetLabelTextColour
)
76 EVT_MENU( ID_ROWLABELHORIZALIGN
, GridFrame::SetRowLabelHorizAlignment
)
77 EVT_MENU( ID_ROWLABELVERTALIGN
, GridFrame::SetRowLabelVertAlignment
)
78 EVT_MENU( ID_COLLABELHORIZALIGN
, GridFrame::SetColLabelHorizAlignment
)
79 EVT_MENU( ID_COLLABELVERTALIGN
, GridFrame::SetColLabelVertAlignment
)
80 EVT_MENU( ID_GRIDLINECOLOUR
, GridFrame::SetGridLineColour
)
81 EVT_MENU( ID_INSERTROW
, GridFrame::InsertRow
)
82 EVT_MENU( ID_INSERTCOL
, GridFrame::InsertCol
)
83 EVT_MENU( ID_DELETEROW
, GridFrame::DeleteSelectedRows
)
84 EVT_MENU( ID_DELETECOL
, GridFrame::DeleteSelectedCols
)
85 EVT_MENU( ID_CLEARGRID
, GridFrame::ClearGrid
)
87 EVT_MENU( ID_SET_CELL_FG_COLOUR
, GridFrame::SetCellFgColour
)
88 EVT_MENU( ID_SET_CELL_BG_COLOUR
, GridFrame::SetCellBgColour
)
90 EVT_MENU( ID_ABOUT
, GridFrame::About
)
91 EVT_MENU( wxID_EXIT
, GridFrame::OnQuit
)
92 EVT_MENU( ID_VTABLE
, GridFrame::OnVTable
)
93 EVT_MENU( ID_BUGS_TABLE
, GridFrame::OnBugsTable
)
95 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick
)
96 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick
)
97 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize
)
98 EVT_GRID_COL_SIZE( GridFrame::OnColSize
)
99 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell
)
100 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected
)
101 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged
)
103 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown
)
104 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden
)
108 GridFrame::GridFrame()
109 : wxFrame( (wxFrame
*)NULL
, -1, "wxWindows grid class demo",
113 int gridW
= 600, gridH
= 300;
114 int logW
= gridW
, logH
= 100;
116 wxMenu
*fileMenu
= new wxMenu
;
117 fileMenu
->Append( ID_VTABLE
, "&Virtual table test\tCtrl-V");
118 fileMenu
->Append( ID_BUGS_TABLE
, "&Bugs table test\tCtrl-B");
119 fileMenu
->AppendSeparator();
120 fileMenu
->Append( wxID_EXIT
, "E&xit\tAlt-X" );
122 wxMenu
*viewMenu
= new wxMenu
;
123 viewMenu
->Append( ID_TOGGLEROWLABELS
, "&Row labels", "", TRUE
);
124 viewMenu
->Append( ID_TOGGLECOLLABELS
, "&Col labels", "", TRUE
);
125 viewMenu
->Append( ID_TOGGLEEDIT
, "&Editable", "", TRUE
);
126 viewMenu
->Append( ID_TOGGLEROWSIZING
, "Ro&w drag-resize", "", TRUE
);
127 viewMenu
->Append( ID_TOGGLECOLSIZING
, "C&ol drag-resize", "", TRUE
);
128 viewMenu
->Append( ID_TOGGLEGRIDSIZING
, "&Grid drag-resize", "", TRUE
);
130 wxMenu
*rowLabelMenu
= new wxMenu
;
132 viewMenu
->Append( ID_ROWLABELALIGN
, "R&ow label alignment",
134 "Change alignment of row labels" );
136 rowLabelMenu
->Append( ID_ROWLABELHORIZALIGN
, "&Horizontal" );
137 rowLabelMenu
->Append( ID_ROWLABELVERTALIGN
, "&Vertical" );
139 wxMenu
*colLabelMenu
= new wxMenu
;
141 viewMenu
->Append( ID_COLLABELALIGN
, "Col l&abel alignment",
143 "Change alignment of col labels" );
145 colLabelMenu
->Append( ID_COLLABELHORIZALIGN
, "&Horizontal" );
146 colLabelMenu
->Append( ID_COLLABELVERTALIGN
, "&Vertical" );
148 wxMenu
*colMenu
= new wxMenu
;
149 colMenu
->Append( ID_SETLABELCOLOUR
, "Set &label colour" );
150 colMenu
->Append( ID_SETLABELTEXTCOLOUR
, "Set label &text colour" );
151 colMenu
->Append( ID_GRIDLINECOLOUR
, "&Grid line colour" );
152 colMenu
->Append( ID_SET_CELL_FG_COLOUR
, "Set cell &foreground colour" );
153 colMenu
->Append( ID_SET_CELL_BG_COLOUR
, "Set cell &background colour" );
155 wxMenu
*editMenu
= new wxMenu
;
156 editMenu
->Append( ID_INSERTROW
, "Insert &row" );
157 editMenu
->Append( ID_INSERTCOL
, "Insert &column" );
158 editMenu
->Append( ID_DELETEROW
, "Delete selected ro&ws" );
159 editMenu
->Append( ID_DELETECOL
, "Delete selected co&ls" );
160 editMenu
->Append( ID_CLEARGRID
, "Cl&ear grid cell contents" );
162 wxMenu
*helpMenu
= new wxMenu
;
163 helpMenu
->Append( ID_ABOUT
, "&About wxGrid demo" );
165 wxMenuBar
*menuBar
= new wxMenuBar
;
166 menuBar
->Append( fileMenu
, "&File" );
167 menuBar
->Append( viewMenu
, "&View" );
168 menuBar
->Append( colMenu
, "&Colours" );
169 menuBar
->Append( editMenu
, "&Edit" );
170 menuBar
->Append( helpMenu
, "&Help" );
172 SetMenuBar( menuBar
);
174 grid
= new wxGrid( this,
177 wxSize( 400, 300 ) );
179 logWin
= new wxTextCtrl( this,
182 wxPoint( 0, gridH
+ 20 ),
183 wxSize( logW
, logH
),
186 logger
= new wxLogTextCtrl( logWin
);
187 m_logOld
= logger
->SetActiveTarget( logger
);
188 logger
->SetTimestamp( NULL
);
190 // this will create a grid and, by default, an associated grid
191 // table for string gs_dataBugsGrid
192 grid
->CreateGrid( 100, 100 );
194 grid
->SetRowSize( 0, 60 );
195 grid
->SetCellValue( 0, 0, "Ctrl+Home\nwill go to\nthis cell" );
197 grid
->SetCellValue( 0, 1, "Blah" );
198 grid
->SetCellValue( 0, 2, "Blah" );
199 grid
->SetCellValue( 0, 3, "Read only" );
200 grid
->SetReadOnly( 0, 3 );
202 grid
->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
204 grid
->SetRowSize( 99, 60 );
205 grid
->SetCellValue( 99, 99, "Ctrl+End\nwill go to\nthis cell" );
207 grid
->SetCellValue(2, 2, "red");
209 grid
->SetCellTextColour(2, 2, *wxRED
);
210 grid
->SetCellValue(3, 3, "green on grey");
211 grid
->SetCellTextColour(3, 3, *wxGREEN
);
212 grid
->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY
);
214 grid
->SetCellValue(4, 4, "a weird looking cell");
215 grid
->SetCellAlignment(4, 4, wxCENTRE
, wxCENTRE
);
216 grid
->SetCellRenderer(4, 4, new MyGridCellRenderer
);
218 grid
->SetCellValue(3, 0, "1");
219 grid
->SetCellRenderer(3, 0, new wxGridCellBoolRenderer
);
220 grid
->SetCellEditor(3, 0, new wxGridCellBoolEditor
);
222 wxGridCellAttr
*attr
;
223 attr
= new wxGridCellAttr
;
224 attr
->SetTextColour(*wxBLUE
);
225 grid
->SetColAttr(5, attr
);
226 attr
= new wxGridCellAttr
;
227 attr
->SetBackgroundColour(*wxBLUE
);
228 grid
->SetRowAttr(5, attr
);
230 grid
->SetCellValue(2, 4, "a wider column");
231 grid
->SetColSize(4, 120);
232 grid
->SetColMinimalWidth(4, 120);
234 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
239 topSizer
->Add( logWin
,
243 SetAutoLayout( TRUE
);
244 SetSizer( topSizer
);
246 topSizer
->Fit( this );
247 topSizer
->SetSizeHints( this );
254 GridFrame::~GridFrame()
256 delete wxLog::SetActiveTarget(m_logOld
);
260 void GridFrame::SetDefaults()
262 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, TRUE
);
263 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, TRUE
);
264 GetMenuBar()->Check( ID_TOGGLEEDIT
, TRUE
);
265 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, TRUE
);
266 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, TRUE
);
267 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, TRUE
);
271 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
273 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
275 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
279 grid
->SetRowLabelSize( 0 );
284 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
286 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
288 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
292 grid
->SetColLabelSize( 0 );
297 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
300 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
304 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
306 grid
->EnableDragRowSize(
307 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
311 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
313 grid
->EnableDragColSize(
314 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
317 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
319 grid
->EnableDragGridSize(
320 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
324 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
326 wxColourDialog
dlg( NULL
);
327 if ( dlg
.ShowModal() == wxID_OK
)
329 wxColourData retData
;
330 retData
= dlg
.GetColourData();
331 wxColour colour
= retData
.GetColour();
333 grid
->SetLabelBackgroundColour( colour
);
338 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
340 wxColourDialog
dlg( NULL
);
341 if ( dlg
.ShowModal() == wxID_OK
)
343 wxColourData retData
;
344 retData
= dlg
.GetColourData();
345 wxColour colour
= retData
.GetColour();
347 grid
->SetLabelTextColour( colour
);
352 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
355 grid
->GetRowLabelAlignment( &horiz
, &vert
);
372 grid
->SetRowLabelAlignment( horiz
, -1 );
375 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
378 grid
->GetRowLabelAlignment( &horiz
, &vert
);
395 grid
->SetRowLabelAlignment( -1, vert
);
399 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
402 grid
->GetColLabelAlignment( &horiz
, &vert
);
419 grid
->SetColLabelAlignment( horiz
, -1 );
423 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
426 grid
->GetColLabelAlignment( &horiz
, &vert
);
443 grid
->SetColLabelAlignment( -1, vert
);
447 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
449 wxColourDialog
dlg( NULL
);
450 if ( dlg
.ShowModal() == wxID_OK
)
452 wxColourData retData
;
453 retData
= dlg
.GetColourData();
454 wxColour colour
= retData
.GetColour();
456 grid
->SetGridLineColour( colour
);
461 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
463 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
467 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
469 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
473 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
475 if ( grid
->IsSelection() )
477 int topRow
, bottomRow
, leftCol
, rightCol
;
478 grid
->GetSelection( &topRow
, &leftCol
, &bottomRow
, &rightCol
);
479 grid
->DeleteRows( topRow
, bottomRow
- topRow
+ 1 );
484 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
486 if ( grid
->IsSelection() )
488 int topRow
, bottomRow
, leftCol
, rightCol
;
489 grid
->GetSelection( &topRow
, &leftCol
, &bottomRow
, &rightCol
);
490 grid
->DeleteCols( leftCol
, rightCol
- leftCol
+ 1 );
495 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
500 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
502 wxColour col
= wxGetColourFromUser(this);
505 grid
->SetDefaultCellTextColour(col
);
510 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
512 wxColour col
= wxGetColourFromUser(this);
515 grid
->SetDefaultCellBackgroundColour(col
);
520 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
523 if ( ev
.GetRow() != -1 )
525 logBuf
<< "Left click on row label " << ev
.GetRow();
527 else if ( ev
.GetCol() != -1 )
529 logBuf
<< "Left click on col label " << ev
.GetCol();
533 logBuf
<< "Left click on corner label";
536 if ( ev
.ShiftDown() ) logBuf
<< " (shift down)";
537 wxLogMessage( "%s", logBuf
.c_str() );
539 // you must call event skip if you want default grid processing
545 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
548 logBuf
<< "Left click at row " << ev
.GetRow()
549 << " col " << ev
.GetCol();
550 wxLogMessage( "%s", logBuf
.c_str() );
552 // you must call event skip if you want default grid processing
553 // (cell highlighting etc.)
559 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
562 logBuf
<< "Resized row " << ev
.GetRowOrCol();
563 wxLogMessage( "%s", logBuf
.c_str() );
569 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
572 logBuf
<< "Resized col " << ev
.GetRowOrCol();
573 wxLogMessage( "%s", logBuf
.c_str() );
579 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
582 logBuf
<< "Selected cell at row " << ev
.GetRow()
583 << " col " << ev
.GetCol();
584 wxLogMessage( "%s", logBuf
.c_str() );
586 // you must call Skip() if you want the default processing
587 // to occur in wxGrid
591 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
594 logBuf
<< "Selected cells from row " << ev
.GetTopRow()
595 << " col " << ev
.GetLeftCol()
596 << " to row " << ev
.GetBottomRow()
597 << " col " << ev
.GetRightCol();
599 wxLogMessage( "%s", logBuf
.c_str() );
604 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
607 logBuf
<< "Value changed for cell at"
608 << " row " << ev
.GetRow()
609 << " col " << ev
.GetCol();
611 wxLogMessage( "%s", logBuf
.c_str() );
616 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
618 wxLogMessage( "Cell editor shown." );
623 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
625 wxLogMessage( "Cell editor hidden." );
630 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
632 (void)wxMessageBox( "\n\nwxGrid demo \n\n"
634 "mbedward@ozemail.com.au \n\n",
640 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
645 void GridFrame::OnBugsTable(wxCommandEvent
& )
647 BugsGridFrame
*frame
= new BugsGridFrame
;
651 void GridFrame::OnVTable(wxCommandEvent
& )
653 static long s_sizeGrid
= 10000;
655 s_sizeGrid
= wxGetNumberFromUser("Size of the table to create",
657 "wxGridDemo question",
660 if ( s_sizeGrid
!= -1 )
662 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
667 // ----------------------------------------------------------------------------
668 // MyGridCellRenderer
669 // ----------------------------------------------------------------------------
671 // do something that the default renderer doesn't here just to show that it is
672 // possible to alter the appearance of the cell beyond what the attributes
674 void MyGridCellRenderer::Draw(wxGrid
& grid
,
675 wxGridCellAttr
& attr
,
681 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
683 dc
.SetPen(*wxGREEN_PEN
);
684 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
685 dc
.DrawEllipse(rect
);
689 // ----------------------------------------------------------------------------
690 // BigGridFrame and BigGridTable: Sample of a non-standard table
691 // ----------------------------------------------------------------------------
693 BigGridFrame::BigGridFrame(long sizeGrid
)
694 : wxFrame(NULL
, -1, "Plugin Virtual Table",
695 wxDefaultPosition
, wxSize(500, 450))
697 m_grid
= new wxGrid(this, -1, wxDefaultPosition
, wxDefaultSize
);
698 m_table
= new BigGridTable(sizeGrid
);
699 m_grid
->SetTable(m_table
, TRUE
);
702 // ----------------------------------------------------------------------------
703 // BugsGridFrame: a "realistic" table
704 // ----------------------------------------------------------------------------
727 static const wxChar
* severities
[] =
736 static struct BugsGridData
739 const wxChar
*summary
;
742 const wxChar
*platform
;
744 } gs_dataBugsGrid
[] =
746 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), TRUE
},
747 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), FALSE
},
748 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), TRUE
},
749 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), FALSE
},
752 static const wxChar
*headers
[Col_Max
] =
762 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
768 return wxGRID_VALUE_NUMBER
;;
771 // fall thorugh (TODO should be a list)
775 return wxGRID_VALUE_STRING
;
778 return wxGRID_VALUE_BOOL
;
781 wxFAIL_MSG(_T("unknown column"));
783 return wxEmptyString
;
786 long BugsGridTable::GetNumberRows()
788 return WXSIZEOF(gs_dataBugsGrid
);
791 long BugsGridTable::GetNumberCols()
796 bool BugsGridTable::IsEmptyCell( int row
, int col
)
801 wxString
BugsGridTable::GetValue( int row
, int col
)
803 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
810 wxFAIL_MSG(_T("unexpected column"));
814 return severities
[gd
.severity
];
823 return wxEmptyString
;
826 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
828 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
835 wxFAIL_MSG(_T("unexpected column"));
841 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
843 if ( severities
[n
] == value
)
845 gd
.severity
= (Severity
)n
;
850 if ( n
== WXSIZEOF(severities
) )
852 wxLogWarning(_T("Invalid severity value '%s'."),
854 gd
.severity
= Sev_Normal
;
868 bool BugsGridTable::CanGetValueAs( int WXUNUSED(row
), int col
, const wxString
& typeName
)
870 if ( typeName
== wxGRID_VALUE_STRING
)
874 else if ( typeName
== wxGRID_VALUE_BOOL
)
876 return col
== Col_Opened
;
878 else if ( typeName
== wxGRID_VALUE_NUMBER
)
880 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
888 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
890 return CanGetValueAs(row
, col
, typeName
);
893 long BugsGridTable::GetValueAsLong( int row
, int col
)
895 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
909 wxFAIL_MSG(_T("unexpected column"));
914 bool BugsGridTable::GetValueAsBool( int row
, int col
)
916 if ( col
== Col_Opened
)
918 return gs_dataBugsGrid
[row
].opened
;
922 wxFAIL_MSG(_T("unexpected column"));
928 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
930 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
939 wxFAIL_MSG(_T("unexpected column"));
943 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
945 if ( col
== Col_Opened
)
947 gs_dataBugsGrid
[row
].opened
= value
;
951 wxFAIL_MSG(_T("unexpected column"));
955 wxString
BugsGridTable::GetColLabelValue( int col
)
960 BugsGridTable::BugsGridTable()
964 BugsGridFrame::BugsGridFrame()
965 : wxFrame(NULL
, -1, "Bugs table",
966 wxDefaultPosition
, wxSize(500, 300))
968 wxGrid
*grid
= new wxGrid(this, -1, wxDefaultPosition
);
969 wxGridTableBase
*table
= new BugsGridTable();
970 grid
->SetTable(table
, TRUE
);
972 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
973 *attrRangeEditor
= new wxGridCellAttr
,
974 *attrCombo
= new wxGridCellAttr
;
976 attrRO
->SetReadOnly();
977 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
978 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
981 grid
->SetColAttr(Col_Id
, attrRO
);
982 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
983 grid
->SetColAttr(Col_Severity
, attrCombo
);
985 grid
->AutoSizeColumns();