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
)
86 EVT_MENU( ID_SELCELLS
, GridFrame::SelectCells
)
87 EVT_MENU( ID_SELROWS
, GridFrame::SelectRows
)
88 EVT_MENU( ID_SELCOLS
, GridFrame::SelectCols
)
90 EVT_MENU( ID_SET_CELL_FG_COLOUR
, GridFrame::SetCellFgColour
)
91 EVT_MENU( ID_SET_CELL_BG_COLOUR
, GridFrame::SetCellBgColour
)
93 EVT_MENU( ID_ABOUT
, GridFrame::About
)
94 EVT_MENU( wxID_EXIT
, GridFrame::OnQuit
)
95 EVT_MENU( ID_VTABLE
, GridFrame::OnVTable
)
96 EVT_MENU( ID_BUGS_TABLE
, GridFrame::OnBugsTable
)
98 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick
)
99 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick
)
100 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize
)
101 EVT_GRID_COL_SIZE( GridFrame::OnColSize
)
102 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell
)
103 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected
)
104 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged
)
106 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown
)
107 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden
)
111 GridFrame::GridFrame()
112 : wxFrame( (wxFrame
*)NULL
, -1, "wxWindows grid class demo",
116 int gridW
= 600, gridH
= 300;
117 int logW
= gridW
, logH
= 100;
119 wxMenu
*fileMenu
= new wxMenu
;
120 fileMenu
->Append( ID_VTABLE
, "&Virtual table test\tCtrl-V");
121 fileMenu
->Append( ID_BUGS_TABLE
, "&Bugs table test\tCtrl-B");
122 fileMenu
->AppendSeparator();
123 fileMenu
->Append( wxID_EXIT
, "E&xit\tAlt-X" );
125 wxMenu
*viewMenu
= new wxMenu
;
126 viewMenu
->Append( ID_TOGGLEROWLABELS
, "&Row labels", "", TRUE
);
127 viewMenu
->Append( ID_TOGGLECOLLABELS
, "&Col labels", "", TRUE
);
128 viewMenu
->Append( ID_TOGGLEEDIT
, "&Editable", "", TRUE
);
129 viewMenu
->Append( ID_TOGGLEROWSIZING
, "Ro&w drag-resize", "", TRUE
);
130 viewMenu
->Append( ID_TOGGLECOLSIZING
, "C&ol drag-resize", "", TRUE
);
131 viewMenu
->Append( ID_TOGGLEGRIDSIZING
, "&Grid drag-resize", "", TRUE
);
133 wxMenu
*rowLabelMenu
= new wxMenu
;
135 viewMenu
->Append( ID_ROWLABELALIGN
, "R&ow label alignment",
137 "Change alignment of row labels" );
139 rowLabelMenu
->Append( ID_ROWLABELHORIZALIGN
, "&Horizontal" );
140 rowLabelMenu
->Append( ID_ROWLABELVERTALIGN
, "&Vertical" );
142 wxMenu
*colLabelMenu
= new wxMenu
;
144 viewMenu
->Append( ID_COLLABELALIGN
, "Col l&abel alignment",
146 "Change alignment of col labels" );
148 colLabelMenu
->Append( ID_COLLABELHORIZALIGN
, "&Horizontal" );
149 colLabelMenu
->Append( ID_COLLABELVERTALIGN
, "&Vertical" );
151 wxMenu
*colMenu
= new wxMenu
;
152 colMenu
->Append( ID_SETLABELCOLOUR
, "Set &label colour" );
153 colMenu
->Append( ID_SETLABELTEXTCOLOUR
, "Set label &text colour" );
154 colMenu
->Append( ID_GRIDLINECOLOUR
, "&Grid line colour" );
155 colMenu
->Append( ID_SET_CELL_FG_COLOUR
, "Set cell &foreground colour" );
156 colMenu
->Append( ID_SET_CELL_BG_COLOUR
, "Set cell &background colour" );
158 wxMenu
*editMenu
= new wxMenu
;
159 editMenu
->Append( ID_INSERTROW
, "Insert &row" );
160 editMenu
->Append( ID_INSERTCOL
, "Insert &column" );
161 editMenu
->Append( ID_DELETEROW
, "Delete selected ro&ws" );
162 editMenu
->Append( ID_DELETECOL
, "Delete selected co&ls" );
163 editMenu
->Append( ID_CLEARGRID
, "Cl&ear grid cell contents" );
165 wxMenu
*selectionMenu
= new wxMenu
;
167 editMenu
->Append( ID_CHANGESEL
, "Change &selection mode",
169 "Change selection mode" );
171 selectionMenu
->Append( ID_SELCELLS
, "Select &Cells" );
172 selectionMenu
->Append( ID_SELROWS
, "Select &Rows" );
173 selectionMenu
->Append( ID_SELCOLS
, "Select C&ols" );
175 wxMenu
*helpMenu
= new wxMenu
;
176 helpMenu
->Append( ID_ABOUT
, "&About wxGrid demo" );
178 wxMenuBar
*menuBar
= new wxMenuBar
;
179 menuBar
->Append( fileMenu
, "&File" );
180 menuBar
->Append( viewMenu
, "&View" );
181 menuBar
->Append( colMenu
, "&Colours" );
182 menuBar
->Append( editMenu
, "&Edit" );
183 menuBar
->Append( helpMenu
, "&Help" );
185 SetMenuBar( menuBar
);
187 grid
= new wxGrid( this,
190 wxSize( 400, 300 ) );
192 logWin
= new wxTextCtrl( this,
195 wxPoint( 0, gridH
+ 20 ),
196 wxSize( logW
, logH
),
199 logger
= new wxLogTextCtrl( logWin
);
200 m_logOld
= logger
->SetActiveTarget( logger
);
201 logger
->SetTimestamp( NULL
);
203 // this will create a grid and, by default, an associated grid
205 grid
->CreateGrid( 100, 100 );
207 grid
->SetRowSize( 0, 60 );
208 grid
->SetCellValue( 0, 0, "Ctrl+Home\nwill go to\nthis cell" );
210 grid
->SetCellValue( 0, 1, "Blah" );
211 grid
->SetCellValue( 0, 2, "Blah" );
212 grid
->SetCellValue( 0, 3, "Read only" );
213 grid
->SetReadOnly( 0, 3 );
215 grid
->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
217 grid
->SetRowSize( 99, 60 );
218 grid
->SetCellValue( 99, 99, "Ctrl+End\nwill go to\nthis cell" );
220 grid
->SetCellValue(2, 2, "red");
222 grid
->SetCellTextColour(2, 2, *wxRED
);
223 grid
->SetCellValue(3, 3, "green on grey");
224 grid
->SetCellTextColour(3, 3, *wxGREEN
);
225 grid
->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY
);
227 grid
->SetCellValue(4, 4, "a weird looking cell");
228 grid
->SetCellAlignment(4, 4, wxCENTRE
, wxCENTRE
);
229 grid
->SetCellRenderer(4, 4, new MyGridCellRenderer
);
231 grid
->SetCellValue(3, 0, "1");
232 grid
->SetCellRenderer(3, 0, new wxGridCellBoolRenderer
);
233 grid
->SetCellEditor(3, 0, new wxGridCellBoolEditor
);
235 wxGridCellAttr
*attr
;
236 attr
= new wxGridCellAttr
;
237 attr
->SetTextColour(*wxBLUE
);
238 grid
->SetColAttr(5, attr
);
239 attr
= new wxGridCellAttr
;
240 attr
->SetBackgroundColour(*wxBLUE
);
241 grid
->SetRowAttr(5, attr
);
243 grid
->SetCellValue(2, 4, "a wider column");
244 grid
->SetColSize(4, 120);
245 grid
->SetColMinimalWidth(4, 120);
247 grid
->SetColFormatFloat(5);
248 grid
->SetCellValue(0, 5, "3.1415");
249 grid
->SetCellValue(1, 5, "1415");
250 grid
->SetCellValue(2, 5, "12345.67890");
252 grid
->SetColFormatFloat(6, 6, 2);
253 grid
->SetCellValue(0, 6, "3.1415");
254 grid
->SetCellValue(1, 6, "1415");
255 grid
->SetCellValue(2, 6, "12345.67890");
257 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
262 topSizer
->Add( logWin
,
266 SetAutoLayout( TRUE
);
267 SetSizer( topSizer
);
269 topSizer
->Fit( this );
270 topSizer
->SetSizeHints( this );
277 GridFrame::~GridFrame()
279 delete wxLog::SetActiveTarget(m_logOld
);
283 void GridFrame::SetDefaults()
285 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, TRUE
);
286 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, TRUE
);
287 GetMenuBar()->Check( ID_TOGGLEEDIT
, TRUE
);
288 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, TRUE
);
289 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, TRUE
);
290 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, TRUE
);
294 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
296 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
298 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
302 grid
->SetRowLabelSize( 0 );
307 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
309 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
311 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
315 grid
->SetColLabelSize( 0 );
320 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
323 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
327 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
329 grid
->EnableDragRowSize(
330 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
334 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
336 grid
->EnableDragColSize(
337 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
340 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
342 grid
->EnableDragGridSize(
343 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
347 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
349 wxColourDialog
dlg( NULL
);
350 if ( dlg
.ShowModal() == wxID_OK
)
352 wxColourData retData
;
353 retData
= dlg
.GetColourData();
354 wxColour colour
= retData
.GetColour();
356 grid
->SetLabelBackgroundColour( colour
);
361 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
363 wxColourDialog
dlg( NULL
);
364 if ( dlg
.ShowModal() == wxID_OK
)
366 wxColourData retData
;
367 retData
= dlg
.GetColourData();
368 wxColour colour
= retData
.GetColour();
370 grid
->SetLabelTextColour( colour
);
375 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
378 grid
->GetRowLabelAlignment( &horiz
, &vert
);
395 grid
->SetRowLabelAlignment( horiz
, -1 );
398 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
401 grid
->GetRowLabelAlignment( &horiz
, &vert
);
418 grid
->SetRowLabelAlignment( -1, vert
);
422 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
425 grid
->GetColLabelAlignment( &horiz
, &vert
);
442 grid
->SetColLabelAlignment( horiz
, -1 );
446 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
449 grid
->GetColLabelAlignment( &horiz
, &vert
);
466 grid
->SetColLabelAlignment( -1, vert
);
470 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
472 wxColourDialog
dlg( NULL
);
473 if ( dlg
.ShowModal() == wxID_OK
)
475 wxColourData retData
;
476 retData
= dlg
.GetColourData();
477 wxColour colour
= retData
.GetColour();
479 grid
->SetGridLineColour( colour
);
484 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
486 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
490 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
492 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
496 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
498 if ( grid
->IsSelection() )
500 for ( int n
= 0; n
< grid
->GetNumberRows(); n
++ )
501 if ( grid
->IsInSelection( n
, 0 ) )
502 grid
->DeleteRows( n
, 1 );
507 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
509 if ( grid
->IsSelection() )
511 for ( int n
= 0; n
< grid
->GetNumberCols(); n
++ )
512 if ( grid
->IsInSelection( 0 , n
) )
513 grid
->DeleteCols( n
, 1 );
518 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
523 void GridFrame::SelectCells( wxCommandEvent
& WXUNUSED(ev
) )
525 grid
->SetSelectionMode( wxGrid::wxGridSelectCells
);
528 void GridFrame::SelectRows( wxCommandEvent
& WXUNUSED(ev
) )
530 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
533 void GridFrame::SelectCols( wxCommandEvent
& WXUNUSED(ev
) )
535 grid
->SetSelectionMode( wxGrid::wxGridSelectColumns
);
538 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
540 wxColour col
= wxGetColourFromUser(this);
543 grid
->SetDefaultCellTextColour(col
);
548 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
550 wxColour col
= wxGetColourFromUser(this);
553 grid
->SetDefaultCellBackgroundColour(col
);
558 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
561 if ( ev
.GetRow() != -1 )
563 logBuf
<< "Left click on row label " << ev
.GetRow();
565 else if ( ev
.GetCol() != -1 )
567 logBuf
<< "Left click on col label " << ev
.GetCol();
571 logBuf
<< "Left click on corner label";
574 if ( ev
.ShiftDown() ) logBuf
<< " (shift down)";
575 if ( ev
.ControlDown() ) logBuf
<< " (control down)";
576 wxLogMessage( "%s", logBuf
.c_str() );
578 // you must call event skip if you want default grid processing
584 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
587 logBuf
<< "Left click at row " << ev
.GetRow()
588 << " col " << ev
.GetCol();
589 wxLogMessage( "%s", logBuf
.c_str() );
591 // you must call event skip if you want default grid processing
592 // (cell highlighting etc.)
598 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
601 logBuf
<< "Resized row " << ev
.GetRowOrCol();
602 wxLogMessage( "%s", logBuf
.c_str() );
608 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
611 logBuf
<< "Resized col " << ev
.GetRowOrCol();
612 wxLogMessage( "%s", logBuf
.c_str() );
618 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
621 if ( ev
.Selecting() )
622 logBuf
<< "Selected ";
624 logBuf
<< "Deselected ";
625 logBuf
<< "cell at row " << ev
.GetRow()
626 << " col " << ev
.GetCol()
627 << " ( ControlDown: "<< (ev
.ControlDown() ? 'T':'F')
628 << ", ShiftDown: "<< (ev
.ShiftDown() ? 'T':'F')
629 << ", AltDown: "<< (ev
.AltDown() ? 'T':'F')
630 << ", MetaDown: "<< (ev
.MetaDown() ? 'T':'F') << " )";
631 wxLogMessage( "%s", logBuf
.c_str() );
633 // you must call Skip() if you want the default processing
634 // to occur in wxGrid
638 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
641 if ( ev
.Selecting() )
642 logBuf
<< "Selected ";
644 logBuf
<< "Deselected ";
645 logBuf
<< "cells from row " << ev
.GetTopRow()
646 << " col " << ev
.GetLeftCol()
647 << " to row " << ev
.GetBottomRow()
648 << " col " << ev
.GetRightCol()
649 << " ( ControlDown: "<< (ev
.ControlDown() ? 'T':'F')
650 << ", ShiftDown: "<< (ev
.ShiftDown() ? 'T':'F')
651 << ", AltDown: "<< (ev
.AltDown() ? 'T':'F')
652 << ", MetaDown: "<< (ev
.MetaDown() ? 'T':'F') << " )";
653 wxLogMessage( "%s", logBuf
.c_str() );
658 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
661 logBuf
<< "Value changed for cell at"
662 << " row " << ev
.GetRow()
663 << " col " << ev
.GetCol();
665 wxLogMessage( "%s", logBuf
.c_str() );
670 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
672 wxLogMessage( "Cell editor shown." );
677 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
679 wxLogMessage( "Cell editor hidden." );
684 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
686 (void)wxMessageBox( "\n\nwxGrid demo \n\n"
688 "mbedward@ozemail.com.au \n\n",
694 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
699 void GridFrame::OnBugsTable(wxCommandEvent
& )
701 BugsGridFrame
*frame
= new BugsGridFrame
;
705 void GridFrame::OnVTable(wxCommandEvent
& )
707 static long s_sizeGrid
= 10000;
710 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
713 s
= wxGetTextFromUser( "Size of the table to create",
717 s
.ToLong( &s_sizeGrid
);
720 s_sizeGrid
= wxGetNumberFromUser("Size of the table to create",
722 "wxGridDemo question",
727 if ( s_sizeGrid
!= -1 )
729 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
734 // ----------------------------------------------------------------------------
735 // MyGridCellRenderer
736 // ----------------------------------------------------------------------------
738 // do something that the default renderer doesn't here just to show that it is
739 // possible to alter the appearance of the cell beyond what the attributes
741 void MyGridCellRenderer::Draw(wxGrid
& grid
,
742 wxGridCellAttr
& attr
,
748 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
750 dc
.SetPen(*wxGREEN_PEN
);
751 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
752 dc
.DrawEllipse(rect
);
755 // ----------------------------------------------------------------------------
756 // MyGridCellAttrProvider
757 // ----------------------------------------------------------------------------
759 MyGridCellAttrProvider::MyGridCellAttrProvider()
761 m_attrForOddRows
= new wxGridCellAttr
;
762 m_attrForOddRows
->SetBackgroundColour(*wxLIGHT_GREY
);
765 MyGridCellAttrProvider::~MyGridCellAttrProvider()
767 m_attrForOddRows
->DecRef();
770 wxGridCellAttr
*MyGridCellAttrProvider::GetAttr(int row
, int col
) const
772 wxGridCellAttr
*attr
= wxGridCellAttrProvider::GetAttr(row
, col
);
778 attr
= m_attrForOddRows
;
783 if ( !attr
->HasBackgroundColour() )
785 wxGridCellAttr
*attrNew
= attr
->Clone();
788 attr
->SetBackgroundColour(*wxLIGHT_GREY
);
796 // ============================================================================
797 // BigGridFrame and BigGridTable: Sample of a non-standard table
798 // ============================================================================
800 BigGridFrame::BigGridFrame(long sizeGrid
)
801 : wxFrame(NULL
, -1, "Plugin Virtual Table",
802 wxDefaultPosition
, wxSize(500, 450))
804 m_grid
= new wxGrid(this, -1, wxDefaultPosition
, wxDefaultSize
);
805 m_table
= new BigGridTable(sizeGrid
);
807 // VZ: I don't understand why this slows down the display that much,
808 // must profile it...
809 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
811 m_grid
->SetTable(m_table
, TRUE
);
813 #if defined __WXMOTIF__
814 // MB: the grid isn't getting a sensible default size under wxMotif
816 GetClientSize( &cw
, &ch
);
817 m_grid
->SetSize( cw
, ch
);
821 // ============================================================================
822 // BugsGridFrame: a "realistic" table
823 // ============================================================================
825 // ----------------------------------------------------------------------------
827 // ----------------------------------------------------------------------------
850 static const wxChar
* severities
[] =
859 static struct BugsGridData
867 } gs_dataBugsGrid
[] =
869 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), TRUE
},
870 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), FALSE
},
871 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), TRUE
},
872 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), FALSE
},
875 static const wxChar
*headers
[Col_Max
] =
885 // ----------------------------------------------------------------------------
887 // ----------------------------------------------------------------------------
889 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
895 return wxGRID_VALUE_NUMBER
;;
898 // fall thorugh (TODO should be a list)
901 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING
);
904 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE
);
907 return wxGRID_VALUE_BOOL
;
910 wxFAIL_MSG(_T("unknown column"));
912 return wxEmptyString
;
915 int BugsGridTable::GetNumberRows()
917 return WXSIZEOF(gs_dataBugsGrid
);
920 int BugsGridTable::GetNumberCols()
925 bool BugsGridTable::IsEmptyCell( int row
, int col
)
930 wxString
BugsGridTable::GetValue( int row
, int col
)
932 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
939 wxFAIL_MSG(_T("unexpected column"));
943 return severities
[gd
.severity
];
952 return wxEmptyString
;
955 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
957 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
964 wxFAIL_MSG(_T("unexpected column"));
970 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
972 if ( severities
[n
] == value
)
974 gd
.severity
= (Severity
)n
;
979 if ( n
== WXSIZEOF(severities
) )
981 wxLogWarning(_T("Invalid severity value '%s'."),
983 gd
.severity
= Sev_Normal
;
989 wxStrncpy(gd
.summary
, value
, WXSIZEOF(gd
.summary
));
993 wxStrncpy(gd
.platform
, value
, WXSIZEOF(gd
.platform
));
998 bool BugsGridTable::CanGetValueAs( int WXUNUSED(row
), int col
, const wxString
& typeName
)
1000 if ( typeName
== wxGRID_VALUE_STRING
)
1004 else if ( typeName
== wxGRID_VALUE_BOOL
)
1006 return col
== Col_Opened
;
1008 else if ( typeName
== wxGRID_VALUE_NUMBER
)
1010 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
1018 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1020 return CanGetValueAs(row
, col
, typeName
);
1023 long BugsGridTable::GetValueAsLong( int row
, int col
)
1025 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1039 wxFAIL_MSG(_T("unexpected column"));
1044 bool BugsGridTable::GetValueAsBool( int row
, int col
)
1046 if ( col
== Col_Opened
)
1048 return gs_dataBugsGrid
[row
].opened
;
1052 wxFAIL_MSG(_T("unexpected column"));
1058 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
1060 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1069 wxFAIL_MSG(_T("unexpected column"));
1073 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
1075 if ( col
== Col_Opened
)
1077 gs_dataBugsGrid
[row
].opened
= value
;
1081 wxFAIL_MSG(_T("unexpected column"));
1085 wxString
BugsGridTable::GetColLabelValue( int col
)
1087 return headers
[col
];
1090 BugsGridTable::BugsGridTable()
1094 // ----------------------------------------------------------------------------
1096 // ----------------------------------------------------------------------------
1098 BugsGridFrame::BugsGridFrame()
1099 : wxFrame(NULL
, -1, "Bugs table",
1100 wxDefaultPosition
, wxSize(500, 300))
1102 wxGrid
*grid
= new wxGrid(this, -1, wxDefaultPosition
);
1103 wxGridTableBase
*table
= new BugsGridTable();
1104 table
->SetAttrProvider(new MyGridCellAttrProvider
);
1105 grid
->SetTable(table
, TRUE
);
1107 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
1108 *attrRangeEditor
= new wxGridCellAttr
,
1109 *attrCombo
= new wxGridCellAttr
;
1111 attrRO
->SetReadOnly();
1112 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
1113 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
1116 grid
->SetColAttr(Col_Id
, attrRO
);
1117 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
1118 grid
->SetColAttr(Col_Severity
, attrCombo
);
1120 grid
->SetMargins(0, 0);
1123 wxSize size
= grid
->GetSize();
1126 SetClientSize(size
);