forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.cpp
More file actions
1131 lines (914 loc) · 28.8 KB
/
Copy pathGrid.cpp
File metadata and controls
1131 lines (914 loc) · 28.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
Audacity: A Digital Audio Editor
Grid.cpp
Leland Lucius
*******************************************************************//**
\class Grid
\brief Supplies an accessible grid based on wxGrid.
*//*******************************************************************/
#include "../Audacity.h"
#include "Grid.h"
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/defs.h>
#include <wx/choice.h>
#include <wx/clipbrd.h>
#include <wx/dc.h>
#include <wx/grid.h>
#include <wx/intl.h>
#include <wx/settings.h>
#include <wx/toplevel.h>
#include "../SelectedRegion.h"
#if wxUSE_ACCESSIBILITY
#include "WindowAccessible.h"
/**********************************************************************//**
\class GridAx
\brief wxAccessible object providing grid information for Grid.
**************************************************************************/
class GridAx final : public WindowAccessible
{
public:
GridAx(Grid *grid);
void SetCurrentCell(int row, int col);
void TableUpdated();
bool GetRowCol(int childId, int & row, int & col);
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
wxAccStatus GetChild(int childId, wxAccessible **child) override;
// Gets the number of children.
wxAccStatus GetChildCount(int *childCount) override;
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
// Returns the description for this object or a child.
wxAccStatus GetDescription(int childId, wxString *description) override;
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
// Returns help text for this object or a child, similar to tooltip text.
wxAccStatus GetHelpText(int childId, wxString *helpText) override;
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
wxAccStatus GetLocation(wxRect & rect, int elementId) override;
// Gets the name of the specified object.
wxAccStatus GetName(int childId, wxString *name) override;
// Gets the parent, or NULL.
wxAccStatus GetParent(wxAccessible **parent) override;
// Returns a role constant.
wxAccStatus GetRole(int childId, wxAccRole *role) override;
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
wxAccStatus GetSelections(wxVariant *selections) override;
// Returns a state constant.
wxAccStatus GetState(int childId, long* state) override;
// Returns a localized string representing the value for the object
// or child.
wxAccStatus GetValue(int childId, wxString* strValue) override;
#if defined(__WXMAC__)
// Selects the object or child.
wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags) override;
#endif
Grid *mGrid;
int mLastId;
};
#endif
NumericEditor::NumericEditor
(NumericConverter::Type type, const NumericFormatSymbol &format, double rate)
{
mType = type;
mFormat = format;
mRate = rate;
mOld = 0.0;
}
NumericEditor::~NumericEditor()
{
}
void NumericEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler)
{
wxASSERT(parent); // to justify safenew
auto control = safenew NumericTextCtrl(
parent, wxID_ANY,
mType,
mFormat,
mOld,
mRate,
NumericTextCtrl::Options{}
.AutoPos(true)
.InvalidValue(mType == NumericTextCtrl::FREQUENCY,
SelectedRegion::UndefinedFrequency)
);
m_control = control;
wxGridCellEditor::Create(parent, id, handler);
}
void NumericEditor::SetSize(const wxRect &rect)
{
wxSize size = m_control->GetSize();
// Always center...looks bad otherwise
int x = rect.x + ((rect.width / 2) - (size.x / 2)) + 1;
int y = rect.y + ((rect.height / 2) - (size.y / 2)) + 1;
m_control->Move(x, y);
}
void NumericEditor::BeginEdit(int row, int col, wxGrid *grid)
{
wxGridTableBase *table = grid->GetTable();
mOldString = table->GetValue(row, col);
mOldString.ToDouble(&mOld);
auto control = GetNumericTextControl();
control->SetValue(mOld);
control->EnableMenu();
control->SetFocus();
}
bool NumericEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col), const wxGrid *WXUNUSED(grid), const wxString &WXUNUSED(oldval), wxString *newval)
{
double newtime = GetNumericTextControl()->GetValue();
bool changed = newtime != mOld;
if (changed) {
mValueAsString = wxString::Format(wxT("%g"), newtime);
*newval = mValueAsString;
}
return changed;
}
void NumericEditor::ApplyEdit(int row, int col, wxGrid *grid)
{
grid->GetTable()->SetValue(row, col, mValueAsString);
}
void NumericEditor::Reset()
{
GetNumericTextControl()->SetValue(mOld);
}
bool NumericEditor::IsAcceptedKey(wxKeyEvent &event)
{
if (wxGridCellEditor::IsAcceptedKey(event)) {
if (event.GetKeyCode() == WXK_RETURN) {
return true;
}
}
return false;
}
// Clone is required by wxwidgets; implemented via copy constructor
wxGridCellEditor *NumericEditor::Clone() const
{
return safenew NumericEditor{ mType, mFormat, mRate };
}
wxString NumericEditor::GetValue() const
{
return wxString::Format(wxT("%g"), GetNumericTextControl()->GetValue());
}
NumericFormatSymbol NumericEditor::GetFormat() const
{
return mFormat;
}
double NumericEditor::GetRate() const
{
return mRate;
}
void NumericEditor::SetFormat(const NumericFormatSymbol &format)
{
mFormat = format;
}
void NumericEditor::SetRate(double rate)
{
mRate = rate;
}
NumericRenderer::~NumericRenderer()
{
}
void NumericRenderer::Draw(wxGrid &grid,
wxGridCellAttr &attr,
wxDC &dc,
const wxRect &rect,
int row,
int col,
bool isSelected)
{
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
wxGridTableBase *table = grid.GetTable();
NumericEditor *ne =
static_cast<NumericEditor *>(grid.GetCellEditor(row, col));
wxString tstr;
if (ne) {
double value;
table->GetValue(row, col).ToDouble(&value);
NumericTextCtrl tt(&grid, wxID_ANY,
mType,
ne->GetFormat(),
value,
ne->GetRate(),
NumericTextCtrl::Options{}.AutoPos(true),
wxPoint(10000, 10000)); // create offscreen
tstr = tt.GetString();
ne->DecRef();
}
dc.SetBackgroundMode(wxTRANSPARENT);
if (grid.IsEnabled())
{
if (isSelected)
{
dc.SetTextBackground(grid.GetSelectionBackground());
dc.SetTextForeground(grid.GetSelectionForeground());
}
else
{
dc.SetTextBackground(attr.GetBackgroundColour());
dc.SetTextForeground(attr.GetTextColour());
}
}
else
{
dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
}
dc.SetFont(attr.GetFont());
int hAlign, vAlign;
attr.GetAlignment(&hAlign, &vAlign);
grid.DrawTextRectangle(dc, tstr, rect, hAlign, vAlign);
}
wxSize NumericRenderer::GetBestSize(wxGrid &grid,
wxGridCellAttr & WXUNUSED(attr),
wxDC & WXUNUSED(dc),
int row,
int col)
{
wxGridTableBase *table = grid.GetTable();
NumericEditor *ne =
static_cast<NumericEditor *>(grid.GetCellEditor(row, col));
wxSize sz;
if (ne) {
double value;
table->GetValue(row, col).ToDouble(&value);
NumericTextCtrl tt(&grid, wxID_ANY,
mType,
ne->GetFormat(),
value,
ne->GetRate(),
NumericTextCtrl::Options{}.AutoPos(true),
wxPoint(10000, 10000)); // create offscreen
sz = tt.GetSize();
ne->DecRef();
}
return sz;
}
// Clone is required by wxwidgets; implemented via copy constructor
wxGridCellRenderer *NumericRenderer::Clone() const
{
return safenew NumericRenderer{ mType };
}
ChoiceEditor::ChoiceEditor(size_t count, const wxString choices[])
{
if (count) {
mChoices.reserve(count);
for (size_t n = 0; n < count; n++) {
mChoices.push_back(choices[n]);
}
}
}
ChoiceEditor::ChoiceEditor(const wxArrayString &choices)
{
mChoices = choices;
}
ChoiceEditor::~ChoiceEditor()
{
if (m_control)
mHandler.DisconnectEvent(m_control);
}
// Clone is required by wxwidgets; implemented via copy constructor
wxGridCellEditor *ChoiceEditor::Clone() const
{
return safenew ChoiceEditor(mChoices);
}
void ChoiceEditor::Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler)
{
m_control = safenew wxChoice(parent,
id,
wxDefaultPosition,
wxDefaultSize,
mChoices);
wxGridCellEditor::Create(parent, id, evtHandler);
mHandler.ConnectEvent(m_control);
}
void ChoiceEditor::SetSize(const wxRect &rect)
{
wxSize size = m_control->GetSize();
// Always center...looks bad otherwise
int x = rect.x + ((rect.width / 2) - (size.x / 2)) + 1;
int y = rect.y + ((rect.height / 2) - (size.y / 2)) + 1;
m_control->Move(x, y);
}
void ChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
{
if (!m_control)
return;
mOld = grid->GetTable()->GetValue(row, col);
Choice()->Clear();
Choice()->Append(mChoices);
Choice()->SetSelection( make_iterator_range( mChoices ).index( mOld ) );
Choice()->SetFocus();
}
bool ChoiceEditor::EndEdit(int row, int col, wxGrid *grid)
{
wxString newvalue;
bool changed = EndEdit(row, col, grid, mOld, &newvalue);
if (changed) {
ApplyEdit(row, col, grid);
}
return changed;
}
bool ChoiceEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col),
const wxGrid* WXUNUSED(grid),
const wxString &WXUNUSED(oldval), wxString *newval)
{
int sel = Choice()->GetSelection();
// This can happen if the wxChoice control is displayed and the list of choices get changed
if ((sel < 0) || (sel >= (int)(mChoices.size())))
{
return false;
}
wxString val = mChoices[sel];
bool changed = val != mOld;
if (changed)
{
mValueAsString = val;
*newval = val;
}
return changed;
}
void ChoiceEditor::ApplyEdit(int row, int col, wxGrid *grid)
{
grid->GetTable()->SetValue(row, col, mValueAsString);
}
void ChoiceEditor::Reset()
{
Choice()->SetSelection( make_iterator_range( mChoices ).index( mOld ) );
}
void ChoiceEditor::SetChoices(const wxArrayString &choices)
{
mChoices = choices;
}
wxString ChoiceEditor::GetValue() const
{
return mChoices[Choice()->GetSelection()];
}
///
///
///
BEGIN_EVENT_TABLE(Grid, wxGrid)
EVT_SET_FOCUS(Grid::OnSetFocus)
EVT_KEY_DOWN(Grid::OnKeyDown)
EVT_GRID_SELECT_CELL(Grid::OnSelectCell)
EVT_GRID_EDITOR_SHOWN(Grid::OnEditorShown)
END_EVENT_TABLE()
Grid::Grid(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
: wxGrid(parent, id, pos, size, style | wxWANTS_CHARS, name)
{
#if wxUSE_ACCESSIBILITY
GetGridWindow()->SetAccessible(mAx = safenew GridAx(this));
#endif
// RegisterDataType takes ownership of renderer and editor
RegisterDataType(GRID_VALUE_TIME,
safenew NumericRenderer{ NumericConverter::TIME },
safenew NumericEditor
{ NumericTextCtrl::TIME,
NumericConverter::SecondsFormat(), 44100.0 });
RegisterDataType(GRID_VALUE_FREQUENCY,
safenew NumericRenderer{ NumericConverter::FREQUENCY },
safenew NumericEditor
{ NumericTextCtrl::FREQUENCY,
NumericConverter::HertzFormat(), 44100.0 });
RegisterDataType(GRID_VALUE_CHOICE,
safenew wxGridCellStringRenderer,
safenew ChoiceEditor);
// Bug #2803:
// Ensure selection doesn't show up.
SetSelectionForeground(GetDefaultCellTextColour());
SetSelectionBackground(GetDefaultCellBackgroundColour());
}
Grid::~Grid()
{
#if wxUSE_ACCESSIBILITY
int cnt = mChildren.size();
while (cnt--) {
// PRL: I found this loop destroying right-to-left.
// Is the sequence of destruction important?
mChildren.pop_back();
}
#endif
}
void Grid::OnSetFocus(wxFocusEvent &event)
{
event.Skip();
#if wxUSE_ACCESSIBILITY
mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
#endif
}
void Grid::OnSelectCell(wxGridEvent &event)
{
event.Skip();
MakeCellVisible(event.GetRow(), event.GetCol());
#if wxUSE_ACCESSIBILITY
mAx->SetCurrentCell(event.GetRow(), event.GetCol());
#endif
}
void Grid::OnEditorShown(wxGridEvent &event)
{
event.Skip();
// Bug #2803 (comment 7):
// Select row whenever an editor is displayed
SelectRow(GetGridCursorRow());
}
void Grid::OnKeyDown(wxKeyEvent &event)
{
auto keyCode = event.GetKeyCode();
int crow = GetGridCursorRow();
int ccol = GetGridCursorCol();
if (event.CmdDown() && crow != wxGridNoCellCoords.GetRow() && ccol != wxGridNoCellCoords.GetCol())
{
wxClipboardLocker cb;
switch (keyCode)
{
case 'C': // Copy
{
wxTextDataObject *data = safenew wxTextDataObject(GetCellValue(crow, ccol));
wxClipboard::Get()->SetData(data);
return;
}
break;
case 'X': // Cut
{
wxTextDataObject *data = safenew wxTextDataObject(GetCellValue(crow, ccol));
wxClipboard::Get()->SetData(data);
SetCellValue(crow, ccol, "" );
return;
}
break;
case 'V': // Paste
{
if (wxClipboard::Get()->IsSupported(wxDF_UNICODETEXT))
{
wxTextDataObject data;
if (wxClipboard::Get()->GetData(data))
{
SetCellValue(crow, ccol, data.GetText());
return;
}
}
}
break;
}
}
switch (keyCode)
{
case WXK_LEFT:
case WXK_RIGHT:
{
int rows = GetNumberRows();
int cols = GetNumberCols();
const bool has_cells = rows > 0 && cols > 0;
if (has_cells) {
int crow = GetGridCursorRow();
int ccol = GetGridCursorCol();
const bool has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
if (has_no_selection) {
SetGridCursor(0, 0);
}
else if (event.GetKeyCode() == WXK_LEFT) {
if (crow == 0 && ccol == 0) {
// do nothing
}
else if (ccol == 0) {
SetGridCursor(crow - 1, cols - 1);
}
else {
SetGridCursor(crow, ccol - 1);
}
}
else {
if (crow == rows - 1 && ccol == cols - 1) {
// do nothing
}
else if (ccol == cols - 1) {
SetGridCursor(crow + 1, 0);
}
else {
SetGridCursor(crow, ccol + 1);
}
}
}
#if wxUSE_ACCESSIBILITY
// Make sure the NEW cell is made available to the screen reader
mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
#endif
}
break;
case WXK_TAB:
{
if (event.ControlDown()) {
int flags = wxNavigationKeyEvent::FromTab |
( event.ShiftDown() ?
wxNavigationKeyEvent::IsBackward :
wxNavigationKeyEvent::IsForward );
Navigate(flags);
return;
}
int rows = GetNumberRows();
int cols = GetNumberCols();
int crow = GetGridCursorRow();
int ccol = GetGridCursorCol();
const auto is_empty = rows <= 0 || cols <= 0;
const auto has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
if (event.ShiftDown()) {
if (is_empty) {
Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
return;
}
if (crow == 0 && ccol == 0) {
Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
return;
}
if (has_no_selection) {
SetGridCursor(rows -1, cols - 1);
}
else if (ccol == 0) {
SetGridCursor(crow - 1, cols - 1);
}
else {
SetGridCursor(crow, ccol - 1);
}
}
else {
if (is_empty) {
Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
return;
}
if (crow == rows - 1 && ccol == cols - 1) {
Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
return;
}
if (has_no_selection) {
SetGridCursor(0, 0);
}
else if (ccol == cols - 1) {
SetGridCursor(crow + 1, 0);
}
else {
SetGridCursor(crow, ccol + 1);
}
}
MakeCellVisible(GetGridCursorRow(), GetGridCursorCol());
#if wxUSE_ACCESSIBILITY
// Make sure the NEW cell is made available to the screen reader
mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
#endif
}
break;
case WXK_RETURN:
case WXK_NUMPAD_ENTER:
{
if (!IsCellEditControlShown()) {
wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxWindow *def = tlw->GetDefaultItem();
if (def && def->IsEnabled()) {
wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED,
def->GetId());
GetParent()->GetEventHandler()->ProcessEvent(cevent);
}
}
else {
wxGrid::OnKeyDown(event);
// This looks strange, but what it does is selects the cell when
// enter is pressed after editing. Without it, Jaws and Window-Eyes
// do not speak the NEW cell contents (the one below the edited one).
SetGridCursor(GetGridCursorRow(), GetGridCursorCol());
}
break;
}
default:
wxGrid::OnKeyDown(event);
break;
}
}
#if wxUSE_ACCESSIBILITY
void Grid::ClearGrid()
{
wxGrid::ClearGrid();
mAx->TableUpdated();
return;
}
bool Grid::InsertRows(int pos, int numRows, bool updateLabels)
{
bool res = wxGrid::InsertRows(pos, numRows, updateLabels);
mAx->TableUpdated();
return res;
}
bool Grid::AppendRows(int numRows, bool updateLabels)
{
bool res = wxGrid::AppendRows(numRows, updateLabels);
mAx->TableUpdated();
return res;
}
bool Grid::DeleteRows(int pos, int numRows, bool updateLabels)
{
bool res = wxGrid::DeleteRows(pos, numRows, updateLabels);
mAx->TableUpdated();
return res;
}
bool Grid::InsertCols(int pos, int numCols, bool updateLabels)
{
bool res = wxGrid::InsertCols(pos, numCols, updateLabels);
mAx->TableUpdated();
return res;
}
bool Grid::AppendCols(int numCols, bool updateLabels)
{
bool res = wxGrid::AppendCols(numCols, updateLabels);
mAx->TableUpdated();
return res;
}
bool Grid::DeleteCols(int pos, int numCols, bool updateLabels)
{
bool res = wxGrid::DeleteCols(pos, numCols, updateLabels);
mAx->TableUpdated();
return res;
}
GridAx::GridAx(Grid *grid)
: WindowAccessible(grid->GetGridWindow())
{
mGrid = grid;
mLastId = -1;
}
void GridAx::TableUpdated()
{
NotifyEvent(wxACC_EVENT_OBJECT_REORDER,
mGrid->GetGridWindow(),
wxOBJID_CLIENT,
0);
}
void GridAx::SetCurrentCell(int row, int col)
{
int id = (((row * mGrid->GetNumberCols()) + col) + 1);
if (mLastId != -1) {
NotifyEvent(wxACC_EVENT_OBJECT_SELECTIONREMOVE,
mGrid->GetGridWindow(),
wxOBJID_CLIENT,
mLastId);
}
if (mGrid == wxWindow::FindFocus()) {
NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
mGrid->GetGridWindow(),
wxOBJID_CLIENT,
id);
}
NotifyEvent(wxACC_EVENT_OBJECT_SELECTION,
mGrid->GetGridWindow(),
wxOBJID_CLIENT,
id);
mLastId = id;
}
bool GridAx::GetRowCol(int childId, int & row, int & col)
{
if (childId == wxACC_SELF) {
return false;
}
int cols = mGrid->GetNumberCols();
int id = childId - 1;
row = id / cols;
col = id % cols;
return true;
}
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
wxAccStatus GridAx::GetChild(int childId, wxAccessible** child)
{
if (childId == wxACC_SELF) {
*child = this;
}
else {
*child = NULL;
}
return wxACC_OK;
}
// Gets the number of children.
wxAccStatus GridAx::GetChildCount(int *childCount)
{
*childCount = mGrid->GetNumberRows() * mGrid->GetNumberCols();
return wxACC_OK;
}
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
wxAccStatus GridAx::GetDefaultAction(int WXUNUSED(childId), wxString *actionName)
{
actionName->clear();
return wxACC_OK;
}
// Returns the description for this object or a child.
wxAccStatus GridAx::GetDescription(int WXUNUSED(childId), wxString *description)
{
description->clear();
return wxACC_OK;
}
// Returns help text for this object or a child, similar to tooltip text.
wxAccStatus GridAx::GetHelpText(int WXUNUSED(childId), wxString *helpText)
{
helpText->clear();
return wxACC_OK;
}
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
wxAccStatus GridAx::GetKeyboardShortcut(int WXUNUSED(childId), wxString *shortcut)
{
shortcut->clear();
return wxACC_OK;
}
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
wxAccStatus GridAx::GetLocation(wxRect & rect, int elementId)
{
wxRect r;
int row;
int col;
if (GetRowCol(elementId, row, col)) {
rect = mGrid->CellToRect(row, col);
rect.SetPosition(mGrid->CalcScrolledPosition(rect.GetPosition()));
rect.SetPosition(mGrid->GetGridWindow()->ClientToScreen(rect.GetPosition()));
}
else {
rect = mGrid->GetRect();
rect.SetPosition(mGrid->GetParent()->ClientToScreen(rect.GetPosition()));
}
return wxACC_OK;
}
// Gets the name of the specified object.
wxAccStatus GridAx::GetName(int childId, wxString *name)
{
int row;
int col;
if (GetRowCol(childId, row, col)) {
wxString n = mGrid->GetColLabelValue(col);
wxString v = mGrid->GetCellValue(row, col);
if (v.empty()) {
v = _("Empty");
}
// Hack to provide a more intelligible response
NumericEditor *dt =
static_cast<NumericEditor *>(mGrid->GetDefaultEditorForType(GRID_VALUE_TIME));
NumericEditor *df =
static_cast<NumericEditor *>(mGrid->GetDefaultEditorForType(GRID_VALUE_FREQUENCY));
NumericEditor *c =
static_cast<NumericEditor *>(mGrid->GetCellEditor(row, col));
if (c && dt && df && ( c == dt || c == df)) {
double value;
v.ToDouble(&value);
NumericConverter converter(c == dt ? NumericConverter::TIME : NumericConverter::FREQUENCY,
c->GetFormat(),
value,
c->GetRate() );
v = converter.GetString();
}
if (c)
c->DecRef();
if (dt)
dt->DecRef();
if (df)
df->DecRef();
*name = n + wxT(" ") + v;
}
return wxACC_OK;
}
wxAccStatus GridAx::GetParent(wxAccessible ** WXUNUSED(parent))
{
return wxACC_NOT_IMPLEMENTED;
}
// Returns a role constant.
wxAccStatus GridAx::GetRole(int childId, wxAccRole *role)
{
if (childId == wxACC_SELF) {