]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/gridtest.cpp
Add back WINVER check to fix VC6 compilation of wxMSW.
[wxWidgets.git] / tests / controls / gridtest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/gridtest.cpp
3// Purpose: wxGrid unit test
4// Author: Steven Lamerton
5// Created: 2010-06-25
6// RCS-ID: $Id$
7// Copyright: (c) 2010 Steven Lamerton
8///////////////////////////////////////////////////////////////////////////////
9
10#include "testprec.h"
11
12#if wxUSE_GRID
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20#endif // WX_PRECOMP
21
22#include "wx/grid.h"
23#include "testableframe.h"
24#include "asserthelper.h"
25#include "wx/uiaction.h"
26
784130d2
VZ
27// FIXME: A lot of mouse-related tests sporadically fail in wxGTK. This happens
28// almost all the time but sometimes the tests do pass and the failure
29// doesn't happen when debugging so this looks like some kind of event
30// dispatching/simulating problem rather than a real problem in wxGrid.
31//
32// Just disable these tests for now but it would be really great to
33// really fix the problem.
34#ifdef __WXGTK__
35 #define NONGTK_TEST(test)
36#else
37 #define NONGTK_TEST(test) WXUISIM_TEST(test)
38#endif
39
40
232fdc63
VZ
41class GridTestCase : public CppUnit::TestCase
42{
43public:
44 GridTestCase() { }
45
46 virtual void setUp();
47 virtual void tearDown();
48
49private:
50 CPPUNIT_TEST_SUITE( GridTestCase );
51 WXUISIM_TEST( CellEdit );
784130d2
VZ
52 NONGTK_TEST( CellClick );
53 NONGTK_TEST( CellSelect );
54 NONGTK_TEST( LabelClick );
55 NONGTK_TEST( SortClick );
232fdc63 56 WXUISIM_TEST( Size );
784130d2 57 NONGTK_TEST( RangeSelect );
232fdc63
VZ
58 CPPUNIT_TEST( Cursor );
59 CPPUNIT_TEST( Selection );
60 CPPUNIT_TEST( AddRowCol );
61 CPPUNIT_TEST( ColumnOrder );
62 CPPUNIT_TEST( LineFormatting );
63 CPPUNIT_TEST( SortSupport );
64 CPPUNIT_TEST( Labels );
65 CPPUNIT_TEST( SelectionMode );
66 CPPUNIT_TEST( CellFormatting );
67 WXUISIM_TEST( Editable );
68 WXUISIM_TEST( ReadOnly );
69 CPPUNIT_TEST( PseudoTest_NativeHeader );
784130d2
VZ
70 NONGTK_TEST( LabelClick );
71 NONGTK_TEST( SortClick );
232fdc63
VZ
72 CPPUNIT_TEST( ColumnOrder );
73 CPPUNIT_TEST( PseudoTest_NativeLabels );
784130d2
VZ
74 NONGTK_TEST( LabelClick );
75 NONGTK_TEST( SortClick );
232fdc63
VZ
76 CPPUNIT_TEST( ColumnOrder );
77 CPPUNIT_TEST_SUITE_END();
78
79 void CellEdit();
80 void CellClick();
81 void CellSelect();
82 void LabelClick();
83 void SortClick();
84 void Size();
85 void RangeSelect();
86 void Cursor();
87 void Selection();
88 void AddRowCol();
89 void ColumnOrder();
90 void LineFormatting();
91 void SortSupport();
92 void Labels();
93 void SelectionMode();
94 void CellFormatting();
95 void Editable();
96 void ReadOnly();
97 void PseudoTest_NativeHeader() { ms_nativeheader = true; }
98 void PseudoTest_NativeLabels() { ms_nativeheader = false;
99 ms_nativelabels = true; }
100
101 static bool ms_nativeheader;
102 static bool ms_nativelabels;
103
104 wxGrid *m_grid;
105
106 DECLARE_NO_COPY_CLASS(GridTestCase)
107};
108
109// register in the unnamed registry so that these tests are run by default
110CPPUNIT_TEST_SUITE_REGISTRATION( GridTestCase );
111
e3778b4d 112// also include in its own registry so that these tests can be run alone
232fdc63
VZ
113CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GridTestCase, "GridTestCase" );
114
115//initialise the static variable
116bool GridTestCase::ms_nativeheader = false;
117bool GridTestCase::ms_nativelabels = false;
118
119void GridTestCase::setUp()
120{
121 m_grid = new wxGrid(wxTheApp->GetTopWindow(), wxID_ANY);
122 m_grid->CreateGrid(10, 2);
123 m_grid->SetSize(400, 200);
124
125 if( ms_nativeheader )
126 m_grid->UseNativeColHeader();
127
128 if( ms_nativelabels )
129 m_grid->SetUseNativeColLabels();
130
131 m_grid->Refresh();
132 m_grid->Update();
133}
134
135void GridTestCase::tearDown()
136{
7c7bd972
VZ
137 // This is just a hack to continue the rest of the tests to run: if we
138 // destroy the header control while it has capture, this results in an
139 // assert failure and while handling an exception from it more bad things
140 // happen (as it's thrown from a dtor), resulting in simply aborting
141 // everything. So ensure that it doesn't have capture in any case.
142 //
143 // Of course, the right thing to do would be to understand why does it
144 // still have capture when the grid is destroyed sometimes.
145 wxWindow* const win = wxWindow::GetCapture();
146 if ( win )
147 win->ReleaseMouse();
148
232fdc63
VZ
149 wxDELETE(m_grid);
150}
151
152void GridTestCase::CellEdit()
153{
154#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
155 EventCounter changing(m_grid, wxEVT_GRID_CELL_CHANGING);
156 EventCounter changed(m_grid, wxEVT_GRID_CELL_CHANGED);
157 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
232fdc63
VZ
158
159 wxUIActionSimulator sim;
160
161 m_grid->SetFocus();
162 m_grid->SetGridCursor(1, 1);
163 m_grid->ShowCellEditControl();
164
165 sim.Text("abab");
166 sim.Char(WXK_RETURN);
167
168 wxYield();
169
744d91d4
SL
170 CPPUNIT_ASSERT_EQUAL(1, created.GetCount());
171 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
172 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
232fdc63
VZ
173#endif
174}
175
176void GridTestCase::CellClick()
177{
178#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
179 EventCounter lclick(m_grid, wxEVT_GRID_CELL_LEFT_CLICK);
180 EventCounter ldclick(m_grid, wxEVT_GRID_CELL_LEFT_DCLICK);
181 EventCounter rclick(m_grid, wxEVT_GRID_CELL_RIGHT_CLICK);
182 EventCounter rdclick(m_grid, wxEVT_GRID_CELL_RIGHT_DCLICK);
232fdc63
VZ
183
184
185 wxUIActionSimulator sim;
186
187 wxRect rect = m_grid->CellToRect(0, 0);
188 wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
744d91d4
SL
189 point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
190 m_grid->GetColLabelSize())
191 + wxPoint(2, 2));
232fdc63
VZ
192
193 sim.MouseMove(point);
194 wxYield();
195
196 sim.MouseClick();
197 wxYield();
198
744d91d4
SL
199 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
200 lclick.Clear();
232fdc63
VZ
201
202 sim.MouseDblClick();
203 wxYield();
204
205 //A double click event sends a single click event first
206 //test to ensure this still happens in the future
744d91d4
SL
207 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
208 CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
232fdc63
VZ
209
210 sim.MouseClick(wxMOUSE_BTN_RIGHT);
211 wxYield();
212
744d91d4
SL
213 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
214 rclick.Clear();
232fdc63
VZ
215
216 sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
217 wxYield();
218
744d91d4
SL
219 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
220 CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
232fdc63
VZ
221#endif
222}
223
224void GridTestCase::CellSelect()
225{
226#if wxUSE_UIACTIONSIMULATOR
744d91d4 227 EventCounter cell(m_grid, wxEVT_GRID_SELECT_CELL);
232fdc63
VZ
228
229 wxUIActionSimulator sim;
230
231 wxRect rect = m_grid->CellToRect(0, 0);
232 wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
744d91d4
SL
233 point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
234 m_grid->GetColLabelSize())
235 + wxPoint(4, 4));
232fdc63
VZ
236
237 sim.MouseMove(point);
238 wxYield();
239
240 sim.MouseClick();
241 wxYield();
242
744d91d4
SL
243 CPPUNIT_ASSERT_EQUAL(1, cell.GetCount());
244
245 cell.Clear();
232fdc63
VZ
246
247 m_grid->SetGridCursor(1, 1);
248 m_grid->GoToCell(1, 0);
249
250 sim.MouseMove(point);
251 wxYield();
252
253 sim.MouseDblClick();
254 wxYield();
255
744d91d4 256 CPPUNIT_ASSERT_EQUAL(3, cell.GetCount());
232fdc63
VZ
257#endif
258}
259
260void GridTestCase::LabelClick()
261{
da7ae357 262#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
263 EventCounter lclick(m_grid, wxEVT_GRID_LABEL_LEFT_CLICK);
264 EventCounter ldclick(m_grid, wxEVT_GRID_LABEL_LEFT_DCLICK);
265 EventCounter rclick(m_grid, wxEVT_GRID_LABEL_RIGHT_CLICK);
266 EventCounter rdclick(m_grid, wxEVT_GRID_LABEL_RIGHT_DCLICK);
232fdc63
VZ
267
268 wxUIActionSimulator sim;
269
270 wxPoint pos(m_grid->GetRowLabelSize() + 2, 2);
271 pos = m_grid->ClientToScreen(pos);
272
273 sim.MouseMove(pos);
274 wxYield();
275
276 sim.MouseClick();
277 wxYield();
278
744d91d4 279 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
232fdc63
VZ
280
281 sim.MouseDblClick();
282 wxYield();
283
744d91d4 284 CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
232fdc63
VZ
285
286 sim.MouseClick(wxMOUSE_BTN_RIGHT);
287 wxYield();
288
744d91d4
SL
289 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
290 rclick.Clear();
232fdc63
VZ
291
292 sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
293 wxYield();
294
295 if( ms_nativeheader )
296 {
297 //Right double click not supported with native headers so we get two
298 //right click events
744d91d4 299 CPPUNIT_ASSERT_EQUAL(2, rclick.GetCount());
232fdc63
VZ
300 }
301 else
302 {
744d91d4
SL
303 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
304 CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
232fdc63
VZ
305 }
306#endif
307}
308
309void GridTestCase::SortClick()
310{
da7ae357 311#if wxUSE_UIACTIONSIMULATOR
232fdc63
VZ
312 m_grid->SetSortingColumn(0);
313
744d91d4 314 EventCounter sort(m_grid, wxEVT_GRID_COL_SORT);
232fdc63
VZ
315
316 wxUIActionSimulator sim;
317
318 wxPoint pos(m_grid->GetRowLabelSize() + 4, 4);
319 pos = m_grid->ClientToScreen(pos);
320
321 sim.MouseMove(pos);
322 wxYield();
323
324 sim.MouseClick();
325 wxYield();
326
744d91d4 327 CPPUNIT_ASSERT_EQUAL(1, sort.GetCount());
232fdc63
VZ
328#endif
329}
330
331void GridTestCase::Size()
332{
333#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
744d91d4
SL
334 EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE);
335 EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE);
232fdc63
VZ
336
337 wxUIActionSimulator sim;
338
339 wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() +
340 m_grid->GetColSize(0), 5));
341
342 sim.MouseMove(pt);
343 wxYield();
344
345 sim.MouseDown();
346 wxYield();
347
348 sim.MouseMove(pt.x + 50, pt.y);
349 wxYield();
350
351 sim.MouseUp();
352 wxYield();
353
744d91d4 354 CPPUNIT_ASSERT_EQUAL(1, colsize.GetCount());
232fdc63
VZ
355
356 pt = m_grid->ClientToScreen(wxPoint(5, m_grid->GetColLabelSize() +
357 m_grid->GetRowSize(0)));
358
359 sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50);
360 wxYield();
361
744d91d4 362 CPPUNIT_ASSERT_EQUAL(1, rowsize.GetCount());
232fdc63
VZ
363#endif
364}
365
366void GridTestCase::RangeSelect()
367{
368#if wxUSE_UIACTIONSIMULATOR
744d91d4 369 EventCounter select(m_grid, wxEVT_GRID_RANGE_SELECT);
232fdc63
VZ
370
371 wxUIActionSimulator sim;
372
373 //We add the extra 10 to ensure that we are inside the cell
374 wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() + 10,
375 m_grid->GetColLabelSize() + 10)
376 );
377
378 sim.MouseMove(pt);
379 wxYield();
380
381 sim.MouseDown();
382 wxYield();
383
384 sim.MouseMove(pt.x + 50, pt.y + 50);
385 wxYield();
386
387 sim.MouseUp();
388 wxYield();
389
744d91d4 390 CPPUNIT_ASSERT_EQUAL(1, select.GetCount());
232fdc63
VZ
391#endif
392}
393
394void GridTestCase::Cursor()
395{
396 m_grid->SetGridCursor(1, 1);
397
398 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
399 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorRow());
400
401 m_grid->MoveCursorDown(false);
402 m_grid->MoveCursorLeft(false);
403 m_grid->MoveCursorUp(false);
404 m_grid->MoveCursorUp(false);
405 m_grid->MoveCursorRight(false);
406
407 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
408 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
409
410 m_grid->SetCellValue(0, 0, "some text");
411 m_grid->SetCellValue(3, 0, "other text");
412 m_grid->SetCellValue(0, 1, "more text");
413 m_grid->SetCellValue(3, 1, "extra text");
414
415 m_grid->Update();
416 m_grid->Refresh();
417
418 m_grid->MoveCursorLeftBlock(false);
419
420 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol());
421 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
422
423 m_grid->MoveCursorDownBlock(false);
424
425 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol());
426 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow());
427
428 m_grid->MoveCursorRightBlock(false);
429
430 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
431 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow());
432
433 m_grid->MoveCursorUpBlock(false);
434
435 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
436 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
437}
438
439void GridTestCase::Selection()
440{
441 m_grid->SelectAll();
442
443 CPPUNIT_ASSERT(m_grid->IsSelection());
444 CPPUNIT_ASSERT(m_grid->IsInSelection(0, 0));
445 CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1));
446
447 m_grid->SelectBlock(1, 0, 3, 1);
448
449 wxGridCellCoordsArray topleft = m_grid->GetSelectionBlockTopLeft();
450 wxGridCellCoordsArray bottomright = m_grid->GetSelectionBlockBottomRight();
451
452 CPPUNIT_ASSERT_EQUAL(1, topleft.Count());
453 CPPUNIT_ASSERT_EQUAL(1, bottomright.Count());
454
455 CPPUNIT_ASSERT_EQUAL(0, topleft.Item(0).GetCol());
456 CPPUNIT_ASSERT_EQUAL(1, topleft.Item(0).GetRow());
457 CPPUNIT_ASSERT_EQUAL(1, bottomright.Item(0).GetCol());
458 CPPUNIT_ASSERT_EQUAL(3, bottomright.Item(0).GetRow());
459
460 m_grid->SelectCol(1);
461
462 CPPUNIT_ASSERT(m_grid->IsInSelection(0, 1));
463 CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1));
464 CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0));
465
466 m_grid->SelectRow(4);
467
468 CPPUNIT_ASSERT(m_grid->IsInSelection(4, 0));
469 CPPUNIT_ASSERT(m_grid->IsInSelection(4, 1));
470 CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0));
471}
472
473void GridTestCase::AddRowCol()
474{
475 CPPUNIT_ASSERT_EQUAL(10, m_grid->GetNumberRows());
476 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetNumberCols());
477
478 m_grid->AppendCols();
479 m_grid->AppendRows();
480
481 CPPUNIT_ASSERT_EQUAL(11, m_grid->GetNumberRows());
482 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetNumberCols());
483
484 m_grid->AppendCols(2);
485 m_grid->AppendRows(2);
486
487 CPPUNIT_ASSERT_EQUAL(13, m_grid->GetNumberRows());
488 CPPUNIT_ASSERT_EQUAL(5, m_grid->GetNumberCols());
489
490 m_grid->InsertCols(1, 2);
491 m_grid->InsertRows(2, 3);
492
493 CPPUNIT_ASSERT_EQUAL(16, m_grid->GetNumberRows());
494 CPPUNIT_ASSERT_EQUAL(7, m_grid->GetNumberCols());
495}
496
497void GridTestCase::ColumnOrder()
498{
499 m_grid->AppendCols(2);
500
501 CPPUNIT_ASSERT_EQUAL(4, m_grid->GetNumberCols());
502
503 wxArrayInt neworder;
504 neworder.push_back(1);
505 neworder.push_back(3);
506 neworder.push_back(2);
507 neworder.push_back(0);
508
509 m_grid->SetColumnsOrder(neworder);
510
511 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(1));
512 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(3));
513 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2));
514 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(0));
515
516 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColAt(0));
517 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColAt(1));
518 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColAt(2));
519 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColAt(3));
520
521 m_grid->ResetColPos();
522
523 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(0));
524 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(1));
525 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2));
526 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(3));
527}
528
529void GridTestCase::LineFormatting()
530{
531 CPPUNIT_ASSERT(m_grid->GridLinesEnabled());
532
533 m_grid->EnableGridLines(false);
534
535 CPPUNIT_ASSERT(!m_grid->GridLinesEnabled());
536
537 m_grid->EnableGridLines();
538
539 m_grid->SetGridLineColour(*wxRED);
540
541 CPPUNIT_ASSERT_EQUAL(m_grid->GetGridLineColour(), *wxRED);
542}
543
544void GridTestCase::SortSupport()
545{
546 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_grid->GetSortingColumn());
547
548 m_grid->SetSortingColumn(1);
549
550 CPPUNIT_ASSERT(!m_grid->IsSortingBy(0));
551 CPPUNIT_ASSERT(m_grid->IsSortingBy(1));
552 CPPUNIT_ASSERT(m_grid->IsSortOrderAscending());
553
554 m_grid->SetSortingColumn(0, false);
555
556 CPPUNIT_ASSERT(m_grid->IsSortingBy(0));
557 CPPUNIT_ASSERT(!m_grid->IsSortingBy(1));
558 CPPUNIT_ASSERT(!m_grid->IsSortOrderAscending());
559
560 m_grid->UnsetSortingColumn();
561
562 CPPUNIT_ASSERT(!m_grid->IsSortingBy(0));
563 CPPUNIT_ASSERT(!m_grid->IsSortingBy(1));
564}
565
566void GridTestCase::Labels()
567{
568 CPPUNIT_ASSERT_EQUAL("A", m_grid->GetColLabelValue(0));
569 CPPUNIT_ASSERT_EQUAL("1", m_grid->GetRowLabelValue(0));
570
571 m_grid->SetColLabelValue(0, "Column 1");
572 m_grid->SetRowLabelValue(0, "Row 1");
573
574 CPPUNIT_ASSERT_EQUAL("Column 1", m_grid->GetColLabelValue(0));
575 CPPUNIT_ASSERT_EQUAL("Row 1", m_grid->GetRowLabelValue(0));
576
577 m_grid->SetLabelTextColour(*wxGREEN);
578 m_grid->SetLabelBackgroundColour(*wxRED);
579
580 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetLabelTextColour());
581 CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetLabelBackgroundColour());
582
583 m_grid->SetColLabelTextOrientation(wxVERTICAL);
584
585 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxVERTICAL),
586 static_cast<int>(m_grid->GetColLabelTextOrientation()));
587}
588
589void GridTestCase::SelectionMode()
590{
591 //We already test this mode in Select
592 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectCells,
593 m_grid->GetSelectionMode());
594
595 //Test row selection be selecting a single cell and checking the whole
596 //row is selected
597 m_grid->SetSelectionMode(wxGrid::wxGridSelectRows);
598 m_grid->SelectBlock(3, 1, 3, 1);
599
e4aadc2f
VZ
600 wxArrayInt selectedRows = m_grid->GetSelectedRows();
601 CPPUNIT_ASSERT_EQUAL(1, selectedRows.Count());
602 CPPUNIT_ASSERT_EQUAL(3, selectedRows[0]);
232fdc63
VZ
603
604 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectRows,
605 m_grid->GetSelectionMode());
606
607
608 //Test column selection be selecting a single cell and checking the whole
609 //column is selected
610 m_grid->SetSelectionMode(wxGrid::wxGridSelectColumns);
611 m_grid->SelectBlock(3, 1, 3, 1);
612
e4aadc2f
VZ
613 wxArrayInt selectedCols = m_grid->GetSelectedCols();
614 CPPUNIT_ASSERT_EQUAL(1, selectedCols.Count());
615 CPPUNIT_ASSERT_EQUAL(1, selectedCols[0]);
232fdc63
VZ
616
617 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectColumns,
618 m_grid->GetSelectionMode());
619}
620
621void GridTestCase::CellFormatting()
622{
623 //Check that initial alignment is default
624 int horiz, cellhoriz, vert, cellvert;
625
626 m_grid->GetDefaultCellAlignment(&horiz, &vert);
627 m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
628
629 CPPUNIT_ASSERT_EQUAL(cellhoriz, horiz);
630 CPPUNIT_ASSERT_EQUAL(cellvert, vert);
631
632 //Check initial text colour and background colour are default
633 wxColour text, back;
634
635 back = m_grid->GetDefaultCellBackgroundColour();
636
637 CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellBackgroundColour(0, 0));
638
639 back = m_grid->GetDefaultCellTextColour();
640
641 CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellTextColour(0, 0));
642
4a04898f
VZ
643#if WXWIN_COMPATIBILITY_2_8
644 m_grid->SetCellAlignment(wxALIGN_CENTRE, 0, 0);
232fdc63
VZ
645 m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
646
647 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellhoriz);
648 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellvert);
4a04898f 649#endif // WXWIN_COMPATIBILITY_2_8
232fdc63
VZ
650
651 m_grid->SetCellAlignment(0, 0, wxALIGN_LEFT, wxALIGN_BOTTOM);
652 m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
653
654 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_LEFT), cellhoriz);
655 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_BOTTOM), cellvert);
656
4a04898f
VZ
657#if WXWIN_COMPATIBILITY_2_8
658 m_grid->SetCellTextColour(*wxRED, 0, 0);
232fdc63 659 CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetCellTextColour(0, 0));
4a04898f 660#endif // WXWIN_COMPATIBILITY_2_8
232fdc63
VZ
661
662 m_grid->SetCellTextColour(0, 0, *wxGREEN);
232fdc63
VZ
663 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetCellTextColour(0, 0));
664}
665
666void GridTestCase::Editable()
667{
668#if wxUSE_UIACTIONSIMULATOR
232fdc63 669 //As the grid is not editable we shouldn't create an editor
744d91d4 670 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
232fdc63
VZ
671
672 wxUIActionSimulator sim;
673
674 CPPUNIT_ASSERT(m_grid->IsEditable());
675
676 m_grid->EnableEditing(false);
677
678 CPPUNIT_ASSERT(!m_grid->IsEditable());
679
680 m_grid->SetFocus();
681 m_grid->SetGridCursor(1, 1);
682 m_grid->ShowCellEditControl();
683
684 sim.Text("abab");
685 wxYield();
686
687 sim.Char(WXK_RETURN);
688 wxYield();
689
744d91d4 690 CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
232fdc63
VZ
691#endif
692}
693
694void GridTestCase::ReadOnly()
695{
696#if wxUSE_UIACTIONSIMULATOR
232fdc63 697 //As the cell is readonly we shouldn't create an editor
744d91d4 698 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
232fdc63
VZ
699
700 wxUIActionSimulator sim;
701
702 CPPUNIT_ASSERT(!m_grid->IsReadOnly(1, 1));
703
704 m_grid->SetReadOnly(1, 1);
705
706 CPPUNIT_ASSERT(m_grid->IsReadOnly(1, 1));
707
708 m_grid->SetFocus();
709 m_grid->SetGridCursor(1, 1);
710
711 CPPUNIT_ASSERT(m_grid->IsCurrentCellReadOnly());
712
713 m_grid->ShowCellEditControl();
714
715 sim.Text("abab");
716 wxYield();
717
718 sim.Char(WXK_RETURN);
719 wxYield();
720
744d91d4 721 CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
232fdc63
VZ
722#endif
723}
724
725#endif //wxUSE_GRID