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