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
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 grid
->SetColFormatFloat(5);
235 grid
->SetCellValue(0, 5, "3.1415");
236 grid
->SetCellValue(1, 5, "1415");
237 grid
->SetCellValue(2, 5, "12345.67890");
239 grid
->SetColFormatFloat(6, 6, 2);
240 grid
->SetCellValue(0, 6, "3.1415");
241 grid
->SetCellValue(1, 6, "1415");
242 grid
->SetCellValue(2, 6, "12345.67890");
244 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
249 topSizer
->Add( logWin
,
253 SetAutoLayout( TRUE
);
254 SetSizer( topSizer
);
256 topSizer
->Fit( this );
257 topSizer
->SetSizeHints( this );
264 GridFrame::~GridFrame()
266 delete wxLog::SetActiveTarget(m_logOld
);
270 void GridFrame::SetDefaults()
272 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, TRUE
);
273 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, TRUE
);
274 GetMenuBar()->Check( ID_TOGGLEEDIT
, TRUE
);
275 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, TRUE
);
276 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, TRUE
);
277 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, TRUE
);
281 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
283 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
285 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
289 grid
->SetRowLabelSize( 0 );
294 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
296 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
298 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
302 grid
->SetColLabelSize( 0 );
307 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
310 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
314 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
316 grid
->EnableDragRowSize(
317 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
321 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
323 grid
->EnableDragColSize(
324 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
327 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
329 grid
->EnableDragGridSize(
330 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
334 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
336 wxColourDialog
dlg( NULL
);
337 if ( dlg
.ShowModal() == wxID_OK
)
339 wxColourData retData
;
340 retData
= dlg
.GetColourData();
341 wxColour colour
= retData
.GetColour();
343 grid
->SetLabelBackgroundColour( colour
);
348 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
350 wxColourDialog
dlg( NULL
);
351 if ( dlg
.ShowModal() == wxID_OK
)
353 wxColourData retData
;
354 retData
= dlg
.GetColourData();
355 wxColour colour
= retData
.GetColour();
357 grid
->SetLabelTextColour( colour
);
362 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
365 grid
->GetRowLabelAlignment( &horiz
, &vert
);
382 grid
->SetRowLabelAlignment( horiz
, -1 );
385 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
388 grid
->GetRowLabelAlignment( &horiz
, &vert
);
405 grid
->SetRowLabelAlignment( -1, vert
);
409 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
412 grid
->GetColLabelAlignment( &horiz
, &vert
);
429 grid
->SetColLabelAlignment( horiz
, -1 );
433 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
436 grid
->GetColLabelAlignment( &horiz
, &vert
);
453 grid
->SetColLabelAlignment( -1, vert
);
457 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
459 wxColourDialog
dlg( NULL
);
460 if ( dlg
.ShowModal() == wxID_OK
)
462 wxColourData retData
;
463 retData
= dlg
.GetColourData();
464 wxColour colour
= retData
.GetColour();
466 grid
->SetGridLineColour( colour
);
471 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
473 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
477 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
479 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
483 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
485 if ( grid
->IsSelection() )
487 int topRow
, bottomRow
, leftCol
, rightCol
;
488 grid
->GetSelection( &topRow
, &leftCol
, &bottomRow
, &rightCol
);
489 grid
->DeleteRows( topRow
, bottomRow
- topRow
+ 1 );
494 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
496 if ( grid
->IsSelection() )
498 int topRow
, bottomRow
, leftCol
, rightCol
;
499 grid
->GetSelection( &topRow
, &leftCol
, &bottomRow
, &rightCol
);
500 grid
->DeleteCols( leftCol
, rightCol
- leftCol
+ 1 );
505 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
510 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
512 wxColour col
= wxGetColourFromUser(this);
515 grid
->SetDefaultCellTextColour(col
);
520 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
522 wxColour col
= wxGetColourFromUser(this);
525 grid
->SetDefaultCellBackgroundColour(col
);
530 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
533 if ( ev
.GetRow() != -1 )
535 logBuf
<< "Left click on row label " << ev
.GetRow();
537 else if ( ev
.GetCol() != -1 )
539 logBuf
<< "Left click on col label " << ev
.GetCol();
543 logBuf
<< "Left click on corner label";
546 if ( ev
.ShiftDown() ) logBuf
<< " (shift down)";
547 wxLogMessage( "%s", logBuf
.c_str() );
549 // you must call event skip if you want default grid processing
555 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
558 logBuf
<< "Left click at row " << ev
.GetRow()
559 << " col " << ev
.GetCol();
560 wxLogMessage( "%s", logBuf
.c_str() );
562 // you must call event skip if you want default grid processing
563 // (cell highlighting etc.)
569 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
572 logBuf
<< "Resized row " << ev
.GetRowOrCol();
573 wxLogMessage( "%s", logBuf
.c_str() );
579 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
582 logBuf
<< "Resized col " << ev
.GetRowOrCol();
583 wxLogMessage( "%s", logBuf
.c_str() );
589 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
592 logBuf
<< "Selected cell at row " << ev
.GetRow()
593 << " col " << ev
.GetCol();
594 wxLogMessage( "%s", logBuf
.c_str() );
596 // you must call Skip() if you want the default processing
597 // to occur in wxGrid
601 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
604 logBuf
<< "Selected cells from row " << ev
.GetTopRow()
605 << " col " << ev
.GetLeftCol()
606 << " to row " << ev
.GetBottomRow()
607 << " col " << ev
.GetRightCol();
609 wxLogMessage( "%s", logBuf
.c_str() );
614 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
617 logBuf
<< "Value changed for cell at"
618 << " row " << ev
.GetRow()
619 << " col " << ev
.GetCol();
621 wxLogMessage( "%s", logBuf
.c_str() );
626 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
628 wxLogMessage( "Cell editor shown." );
633 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
635 wxLogMessage( "Cell editor hidden." );
640 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
642 (void)wxMessageBox( "\n\nwxGrid demo \n\n"
644 "mbedward@ozemail.com.au \n\n",
650 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
655 void GridFrame::OnBugsTable(wxCommandEvent
& )
657 BugsGridFrame
*frame
= new BugsGridFrame
;
661 void GridFrame::OnVTable(wxCommandEvent
& )
663 static long s_sizeGrid
= 10000;
666 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
669 s
= wxGetTextFromUser( "Size of the table to create",
673 s
.ToLong( &s_sizeGrid
);
676 s_sizeGrid
= wxGetNumberFromUser("Size of the table to create",
678 "wxGridDemo question",
683 if ( s_sizeGrid
!= -1 )
685 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
690 // ----------------------------------------------------------------------------
691 // MyGridCellRenderer
692 // ----------------------------------------------------------------------------
694 // do something that the default renderer doesn't here just to show that it is
695 // possible to alter the appearance of the cell beyond what the attributes
697 void MyGridCellRenderer::Draw(wxGrid
& grid
,
698 wxGridCellAttr
& attr
,
704 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
706 dc
.SetPen(*wxGREEN_PEN
);
707 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
708 dc
.DrawEllipse(rect
);
711 // ----------------------------------------------------------------------------
712 // MyGridCellAttrProvider
713 // ----------------------------------------------------------------------------
715 MyGridCellAttrProvider::MyGridCellAttrProvider()
717 m_attrForOddRows
= new wxGridCellAttr
;
718 m_attrForOddRows
->SetBackgroundColour(*wxLIGHT_GREY
);
721 MyGridCellAttrProvider::~MyGridCellAttrProvider()
723 m_attrForOddRows
->DecRef();
726 wxGridCellAttr
*MyGridCellAttrProvider::GetAttr(int row
, int col
) const
728 wxGridCellAttr
*attr
= wxGridCellAttrProvider::GetAttr(row
, col
);
734 attr
= m_attrForOddRows
;
739 if ( !attr
->HasBackgroundColour() )
741 wxGridCellAttr
*attrNew
= attr
->Clone();
744 attr
->SetBackgroundColour(*wxLIGHT_GREY
);
752 // ============================================================================
753 // BigGridFrame and BigGridTable: Sample of a non-standard table
754 // ============================================================================
756 BigGridFrame::BigGridFrame(long sizeGrid
)
757 : wxFrame(NULL
, -1, "Plugin Virtual Table",
758 wxDefaultPosition
, wxSize(500, 450))
760 m_grid
= new wxGrid(this, -1, wxDefaultPosition
, wxDefaultSize
);
761 m_table
= new BigGridTable(sizeGrid
);
763 // VZ: I don't understand why this slows down the display that much,
764 // must profile it...
765 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
767 m_grid
->SetTable(m_table
, TRUE
);
769 #if defined __WXMOTIF__
770 // MB: the grid isn't getting a sensible default size under wxMotif
772 GetClientSize( &cw
, &ch
);
773 m_grid
->SetSize( cw
, ch
);
777 // ============================================================================
778 // BugsGridFrame: a "realistic" table
779 // ============================================================================
781 // ----------------------------------------------------------------------------
783 // ----------------------------------------------------------------------------
806 static const wxChar
* severities
[] =
815 static struct BugsGridData
823 } gs_dataBugsGrid
[] =
825 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), TRUE
},
826 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), FALSE
},
827 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), TRUE
},
828 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), FALSE
},
831 static const wxChar
*headers
[Col_Max
] =
841 // ----------------------------------------------------------------------------
843 // ----------------------------------------------------------------------------
845 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
851 return wxGRID_VALUE_NUMBER
;;
854 // fall thorugh (TODO should be a list)
857 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING
);
860 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE
);
863 return wxGRID_VALUE_BOOL
;
866 wxFAIL_MSG(_T("unknown column"));
868 return wxEmptyString
;
871 long BugsGridTable::GetNumberRows()
873 return WXSIZEOF(gs_dataBugsGrid
);
876 long BugsGridTable::GetNumberCols()
881 bool BugsGridTable::IsEmptyCell( int row
, int col
)
886 wxString
BugsGridTable::GetValue( int row
, int col
)
888 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
895 wxFAIL_MSG(_T("unexpected column"));
899 return severities
[gd
.severity
];
908 return wxEmptyString
;
911 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
913 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
920 wxFAIL_MSG(_T("unexpected column"));
926 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
928 if ( severities
[n
] == value
)
930 gd
.severity
= (Severity
)n
;
935 if ( n
== WXSIZEOF(severities
) )
937 wxLogWarning(_T("Invalid severity value '%s'."),
939 gd
.severity
= Sev_Normal
;
945 wxStrncpy(gd
.summary
, value
, WXSIZEOF(gd
.summary
));
949 wxStrncpy(gd
.platform
, value
, WXSIZEOF(gd
.platform
));
954 bool BugsGridTable::CanGetValueAs( int WXUNUSED(row
), int col
, const wxString
& typeName
)
956 if ( typeName
== wxGRID_VALUE_STRING
)
960 else if ( typeName
== wxGRID_VALUE_BOOL
)
962 return col
== Col_Opened
;
964 else if ( typeName
== wxGRID_VALUE_NUMBER
)
966 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
974 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
976 return CanGetValueAs(row
, col
, typeName
);
979 long BugsGridTable::GetValueAsLong( int row
, int col
)
981 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
995 wxFAIL_MSG(_T("unexpected column"));
1000 bool BugsGridTable::GetValueAsBool( int row
, int col
)
1002 if ( col
== Col_Opened
)
1004 return gs_dataBugsGrid
[row
].opened
;
1008 wxFAIL_MSG(_T("unexpected column"));
1014 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
1016 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1025 wxFAIL_MSG(_T("unexpected column"));
1029 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
1031 if ( col
== Col_Opened
)
1033 gs_dataBugsGrid
[row
].opened
= value
;
1037 wxFAIL_MSG(_T("unexpected column"));
1041 wxString
BugsGridTable::GetColLabelValue( int col
)
1043 return headers
[col
];
1046 BugsGridTable::BugsGridTable()
1050 // ----------------------------------------------------------------------------
1052 // ----------------------------------------------------------------------------
1054 BugsGridFrame::BugsGridFrame()
1055 : wxFrame(NULL
, -1, "Bugs table",
1056 wxDefaultPosition
, wxSize(500, 300))
1058 wxGrid
*grid
= new wxGrid(this, -1, wxDefaultPosition
);
1059 wxGridTableBase
*table
= new BugsGridTable();
1060 table
->SetAttrProvider(new MyGridCellAttrProvider
);
1061 grid
->SetTable(table
, TRUE
);
1063 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
1064 *attrRangeEditor
= new wxGridCellAttr
,
1065 *attrCombo
= new wxGridCellAttr
;
1067 attrRO
->SetReadOnly();
1068 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
1069 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
1072 grid
->SetColAttr(Col_Id
, attrRO
);
1073 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
1074 grid
->SetColAttr(Col_Severity
, attrCombo
);
1076 grid
->SetMargins(0, 0);
1079 wxSize size
= grid
->GetSize();
1082 SetClientSize(size
);