-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
propgrid.cpp
6630 lines (5455 loc) · 191 KB
/
propgrid.cpp
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
/////////////////////////////////////////////////////////////////////////////
// Name: src/propgrid/propgrid.cpp
// Purpose: wxPropertyGrid
// Author: Jaakko Salli
// Created: 2004-09-25
// Copyright: (c) Jaakko Salli
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#if wxUSE_PROPGRID
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/hash.h"
#include "wx/string.h"
#include "wx/log.h"
#include "wx/event.h"
#include "wx/window.h"
#include "wx/panel.h"
#include "wx/dc.h"
#include "wx/dcmemory.h"
#include "wx/button.h"
#include "wx/pen.h"
#include "wx/brush.h"
#include "wx/cursor.h"
#include "wx/dialog.h"
#include "wx/settings.h"
#include "wx/msgdlg.h"
#include "wx/choice.h"
#include "wx/stattext.h"
#include "wx/scrolwin.h"
#include "wx/dirdlg.h"
#include "wx/sizer.h"
#include "wx/textdlg.h"
#include "wx/filedlg.h"
#include "wx/statusbr.h"
#include "wx/intl.h"
#include "wx/frame.h"
#include "wx/textctrl.h"
#include "wx/settings.h"
#endif
#include "wx/propgrid/propgrid.h"
#include "wx/propgrid/editors.h"
#include "wx/propgrid/private.h"
#if wxPG_USE_RENDERER_NATIVE
#include "wx/renderer.h"
#endif
#include "wx/odcombo.h"
#include "wx/timer.h"
#include "wx/dcbuffer.h"
#include "wx/scopeguard.h"
#include "wx/display.h"
// Two pics for the expand / collapse buttons.
// Files are not supplied with this project (since it is
// recommended to use either custom or native rendering).
// If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
// and copy xpm files from archive to wxPropertyGrid src directory
// (and also comment/undef wxPG_ICON_WIDTH in private.h
// and set wxPG_USE_RENDERER_NATIVE to 0).
#ifndef wxPG_ICON_WIDTH
#if defined(__WXMAC__)
#include "mac_collapse.xpm"
#include "mac_expand.xpm"
#elif defined(__WXGTK__)
#include "linux_collapse.xpm"
#include "linux_expand.xpm"
#else
#include "default_collapse.xpm"
#include "default_expand.xpm"
#endif
#endif
#define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
#define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
#define wxPG_YSPACING_MIN 1
#define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
// but causes normal combobox to spill out under MSW
#define wxPG_DEFAULT_CURSOR wxNullCursor
#define wxPG_PIXELS_PER_UNIT m_lineHeight
//#define wxPG_TOOLTIP_DELAY 1000
// This is the number of pixels the expander button inside
// property cells (i.e. not in the grey margin area are
// adjusted.
#define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
#if WXWIN_COMPATIBILITY_3_0
namespace
{
// Hash containing for every active wxPG the list of editors and their event handlers
// to be deleted in the idle event handler.
// It emulates member variable 'm_deletedEditorObjects' in 3.0 compatibility mode.
WX_DECLARE_HASH_MAP(wxPropertyGrid*, wxArrayPGObject*,
wxPointerHash, wxPointerEqual,
DeletedObjects);
DeletedObjects gs_deletedEditorObjects;
} // anonymous namespace
#endif
// -----------------------------------------------------------------------
#if wxUSE_INTL
void wxPropertyGrid::AutoGetTranslation ( bool enable )
{
wxPGGlobalVars->m_autoGetTranslation = enable;
}
#else
void wxPropertyGrid::AutoGetTranslation ( bool ) { }
#endif
// -----------------------------------------------------------------------
const char wxPropertyGridNameStr[] = "wxPropertyGrid";
// -----------------------------------------------------------------------
// Statics in one class for easy destruction.
// -----------------------------------------------------------------------
// This is the real global wxPGGlobalVarsClass object allocated on demand.
static wxPGGlobalVarsClass* g_PGGlobalVars = nullptr;
#include "wx/module.h"
class wxPGGlobalVarsClassManager : public wxModule
{
wxDECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager);
public:
wxPGGlobalVarsClassManager() = default;
virtual bool OnInit() override { return true; }
virtual void OnExit() override { wxDELETE(g_PGGlobalVars); }
};
wxIMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager, wxModule);
// When wxPG is loaded dynamically after the application is already running
// then the built-in module system won't pick this one up. Add it manually.
void wxPGInitResourceModule()
{
wxModule* module = new wxPGGlobalVarsClassManager;
wxModule::RegisterModule(module);
wxModule::InitializeModules();
}
// This object is a proxy that allows us to only create wxPGGlobalVarsClass
// object when it's really needed. Note that we need to use an object for this
// instead of a function for compatibility reasons: a lot of existing code uses
// wxPGGlobalVars directly.
wxPGGlobalVarsPtr wxPGGlobalVars;
wxPGGlobalVarsClass* wxPGGlobalVarsPtr::operator->() const
{
if ( !g_PGGlobalVars )
g_PGGlobalVars = new wxPGGlobalVarsClass();
return g_PGGlobalVars;
}
bool wxPGGlobalVarsPtr::operator!() const
{
return !g_PGGlobalVars;
}
wxPGGlobalVarsPtr::operator bool() const
{
return !!g_PGGlobalVars;
}
wxPGGlobalVarsClass::wxPGGlobalVarsClass()
: m_fontFamilyChoices(nullptr)
, m_defaultRenderer(new wxPGDefaultRenderer())
#if WXWIN_COMPATIBILITY_3_2
// Prepare some shared variants
, m_vEmptyString(wxString())
, m_vZero(0L)
, m_vMinusOne(-1L)
, m_vTrue(true)
, m_vFalse(false)
// Prepare cached string constants
, m_strstring(wxS("string"))
, m_strlong(wxS("long"))
, m_strbool(wxS("bool"))
, m_strlist(wxS("list"))
, m_strDefaultValue(wxS("DefaultValue"))
, m_strMin(wxS("Min"))
, m_strMax(wxS("Max"))
, m_strUnits(wxS("Units"))
, m_strHint(wxS("Hint"))
#endif // WXWIN_COMPATIBILITY_3_2
, m_autoGetTranslation(false)
, m_offline(0)
, m_extraStyle(0)
, m_warnings(0)
{
#if WXWIN_COMPATIBILITY_3_2
wxPGProperty::sm_wxPG_LABEL = new wxString("@!");
#endif // WXWIN_COMPATIBILITY_3_2
/* TRANSLATORS: Name of Boolean false value */
m_boolChoices.Add(_("False"));
/* TRANSLATORS: Name of Boolean true value */
m_boolChoices.Add(_("True"));
}
wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
{
delete m_defaultRenderer;
// This will always have one ref
delete m_fontFamilyChoices;
#if wxUSE_VALIDATORS
for ( wxValidator* val : m_arrValidators )
{
delete val;
}
#endif
// Destroy editor class instances.
// iterate over all the elements in the class
for( const auto& vt_it : m_mapEditorClasses )
{
delete vt_it.second;
}
// Make sure the global pointers have been reset
wxASSERT(wxPG_EDITOR(TextCtrl) == nullptr);
wxASSERT(wxPG_EDITOR(ChoiceAndButton) == nullptr);
#if WXWIN_COMPATIBILITY_3_2
delete wxPGProperty::sm_wxPG_LABEL;
#endif // WXWIN_COMPATIBILITY_3_2
}
void wxPropertyGridInitGlobalsIfNeeded()
{
}
// -----------------------------------------------------------------------
// wxPropertyGrid
// -----------------------------------------------------------------------
#ifndef wxPG_ICON_WIDTH
namespace
{
// create two bitmap nodes for drawing
static wxBitmap s_expandbmp(expand_xpm);
static wxBitmap s_collbmp(collapse_xpm);
}
#endif
wxIMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid, wxControl);
wxBEGIN_EVENT_TABLE(wxPropertyGrid, wxControl)
EVT_IDLE(wxPropertyGrid::OnIdle)
EVT_PAINT(wxPropertyGrid::OnPaint)
EVT_SIZE(wxPropertyGrid::OnResize)
EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry)
EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry)
EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange)
EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent)
EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent)
EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent)
EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent)
EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged)
EVT_DPI_CHANGED(wxPropertyGrid::OnDPIChanged)
EVT_MOTION(wxPropertyGrid::OnMouseMove)
EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick)
EVT_LEFT_UP(wxPropertyGrid::OnMouseUp)
EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick)
EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick)
EVT_KEY_DOWN(wxPropertyGrid::OnKey)
wxEND_EVENT_TABLE()
// -----------------------------------------------------------------------
wxPropertyGrid::wxPropertyGrid()
: wxScrolled<wxControl>()
{
Init1();
}
// -----------------------------------------------------------------------
wxPropertyGrid::wxPropertyGrid( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name )
: wxScrolled<wxControl>()
{
Init1();
Create(parent,id,pos,size,style,name);
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::Create( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name )
{
if (!(style&wxBORDER_MASK))
{
style |= wxBORDER_THEME;
}
style |= wxVSCROLL;
// Filter out wxTAB_TRAVERSAL - we will handle TABs manually
style &= ~(wxTAB_TRAVERSAL);
style |= wxWANTS_CHARS;
wxControl::Create(parent, id, pos, size,
(style & wxWINDOW_STYLE_MASK) | wxScrolledWindowStyle,
wxDefaultValidator,
name);
m_windowStyle |= (style & wxPG_WINDOW_STYLE_MASK);
Init2();
return true;
}
// -----------------------------------------------------------------------
//
// Initialize values to defaults
//
void wxPropertyGrid::Init1()
{
// Register editor classes, if necessary.
if ( wxPGGlobalVars->m_mapEditorClasses.empty() )
wxPropertyGrid::RegisterDefaultEditors();
m_validatingEditor = 0;
m_iFlags = 0;
m_pState = nullptr;
m_wndEditor = m_wndEditor2 = nullptr;
m_selColumn = 1;
m_colHover = 1;
m_propHover = nullptr;
m_labelEditor = nullptr;
m_labelEditorProperty = nullptr;
m_eventObject = this;
m_curFocused = nullptr;
m_processedEvent = nullptr;
m_tlp = nullptr;
m_sortFunction = nullptr;
m_inDoPropertyChanged = false;
m_inCommitChangesFromEditor = false;
m_inDoSelectProperty = false;
m_inOnValidationFailure = false;
m_permanentValidationFailureBehavior = wxPGVFBFlags::Default;
m_dragStatus = 0;
m_editorFocused = false;
// Set up default unspecified value 'colour'
m_unspecifiedAppearance.SetFgCol(*wxLIGHT_GREY);
// Set default keys
AddActionTrigger(wxPGKeyboardAction::NextProperty, WXK_RIGHT);
AddActionTrigger(wxPGKeyboardAction::NextProperty, WXK_DOWN);
AddActionTrigger(wxPGKeyboardAction::PrevProperty, WXK_LEFT);
AddActionTrigger(wxPGKeyboardAction::PrevProperty, WXK_UP);
AddActionTrigger(wxPGKeyboardAction::ExpandProperty, WXK_RIGHT);
AddActionTrigger(wxPGKeyboardAction::CollapseProperty, WXK_LEFT);
AddActionTrigger(wxPGKeyboardAction::CancelEdit, WXK_ESCAPE);
AddActionTrigger(wxPGKeyboardAction::PressButton, WXK_DOWN, wxMOD_ALT);
AddActionTrigger(wxPGKeyboardAction::PressButton, WXK_F4);
m_coloursCustomized = 0;
m_doubleBuffer = nullptr;
#ifndef wxPG_ICON_WIDTH
m_iconWidth = 11;
m_iconHeight = 11;
#else
m_iconWidth = wxPG_ICON_WIDTH;
m_iconHeight = wxPG_ICON_WIDTH;
#endif
m_gutterWidth = wxPG_GUTTER_MIN;
m_subgroup_extramargin = 10;
m_lineHeight = 0;
m_width = m_height = 0;
/* TRANSLATORS: Text displayed for unspecified value */
m_commonValues.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars->m_defaultRenderer) );
m_cvUnspecified = 0;
m_chgInfo_changedProperty = nullptr;
#if WXWIN_COMPATIBILITY_3_0
// Object array for this wxPG shouldn't exist in the hash map.
wxASSERT( gs_deletedEditorObjects.find(this) == gs_deletedEditorObjects.end() );
gs_deletedEditorObjects[this] = new wxArrayPGObject;
#endif
}
// -----------------------------------------------------------------------
//
// Initialize after parent etc. set
//
void wxPropertyGrid::Init2()
{
wxASSERT( !(m_iFlags & wxPG_FL_INITIALIZED ) );
#ifdef __WXMAC__
// Smaller controls on Mac
SetWindowVariant(wxWINDOW_VARIANT_SMALL);
#endif
// Now create state, if one didn't exist already
// (wxPropertyGridManager might have created it for us).
if ( !m_pState )
{
m_pState = CreateState();
m_pState->m_pPropGrid = this;
m_iFlags |= wxPG_FL_CREATEDSTATE;
}
if ( !(m_windowStyle & wxPG_SPLITTER_AUTO_CENTER) )
m_pState->m_dontCenterSplitter = true;
if ( m_windowStyle & wxPG_HIDE_CATEGORIES )
{
m_pState->InitNonCatMode();
m_pState->m_properties = m_pState->m_abcArray;
}
GetClientSize(&m_width,&m_height);
#ifndef wxPG_ICON_WIDTH
// calculate average font height for bitmap centering
m_iconWidth = s_expandbmp.GetWidth();
m_iconHeight = s_expandbmp.GetHeight();
#endif
m_curcursor = wxCURSOR_ARROW;
m_cursorSizeWE = wxCursor(wxCURSOR_SIZEWE);
// adjust bitmap icon y position so they are centered
m_vspacing = FromDIP(wxPG_DEFAULT_VSPACING);
CalculateFontAndBitmapStuff( m_vspacing );
// Allocate cell data
m_propertyDefaultCell.SetEmptyData();
m_categoryDefaultCell.SetEmptyData();
RegainColours();
// This helps with flicker
SetBackgroundStyle( wxBG_STYLE_PAINT );
// Rely on native double-buffering by default.
#if wxALWAYS_NATIVE_DOUBLE_BUFFER
SetExtraStyle(GetExtraStyle() | wxPG_EX_NATIVE_DOUBLE_BUFFERING);
#endif // wxALWAYS_NATIVE_DOUBLE_BUFFER
// Hook the top-level parent
m_tlpClosed = nullptr;
m_tlpClosedTime = 0;
// set virtual size to this window size
wxSize clientSize = GetClientSize();
SetVirtualSize(clientSize);
m_iFlags |= wxPG_FL_INITIALIZED;
wxSize wndsize = GetSize();
m_ncWidth = wndsize.GetWidth();
// Need to call OnResize handler or size given in constructor/Create
// will never work.
wxSizeEvent sizeEvent(wndsize,0);
OnResize(sizeEvent);
}
// -----------------------------------------------------------------------
wxPropertyGrid::~wxPropertyGrid()
{
#if wxUSE_THREADS
wxCriticalSectionLocker lock(wxPGGlobalVars->m_critSect);
#endif
//
// Remove grid and property pointers from live wxPropertyGridEvents.
for ( wxPropertyGridEvent* evt : m_liveEvents )
{
evt->SetPropertyGrid(nullptr);
evt->SetProperty(nullptr);
}
m_liveEvents.clear();
if ( m_processedEvent )
{
// All right... we are being deleted while wxPropertyGrid event
// is being sent. Make sure that event propagates as little
// as possible (although usually this is not enough to prevent
// a crash).
m_processedEvent->Skip(false);
m_processedEvent->StopPropagation();
// Let's use wxMessageBox to make the message appear more
// reliably (and *before* the crash can happen).
::wxMessageBox(wxS("wxPropertyGrid was being destroyed in an event ")
wxS("generated by it. This usually leads to a crash ")
wxS("so it is recommended to destroy the control ")
wxS("at idle time instead."));
}
DoSelectProperty(nullptr, wxPGSelectPropertyFlags::NoValidate| wxPGSelectPropertyFlags::DontSendEvent);
// This should do prevent things from going too badly wrong
m_iFlags &= ~(wxPG_FL_INITIALIZED);
if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
ReleaseMouse();
// Call with nullptr to disconnect event handling
if ( HasExtraStyle(wxPG_EX_ENABLE_TLP_TRACKING) )
{
OnTLPChanging(nullptr);
wxASSERT_MSG( !IsEditorsValueModified(),
wxS("Most recent change in property editor was ")
wxS("lost!!! (if you don't want this to happen, ")
wxS("close your frames and dialogs using ")
wxS("Close(false).)") );
}
if ( m_processedEvent )
{
// We are inside event handler and we cannot delete
// editor objects immediately. They have to be deleted
// later on in the global idle handler.
#if WXWIN_COMPATIBILITY_3_0
// Emulate member variable.
wxArrayPGObject& m_deletedEditorObjects = *gs_deletedEditorObjects[this];
#endif
while ( !m_deletedEditorObjects.empty() )
{
wxObject* obj = m_deletedEditorObjects.back();
m_deletedEditorObjects.pop_back();
wxPendingDelete.Append(obj);
}
}
else
{
// Delete pending editor controls
DeletePendingObjects();
}
if ( m_doubleBuffer )
delete m_doubleBuffer;
if ( m_iFlags & wxPG_FL_CREATEDSTATE )
delete m_pState;
// Delete common value records
for ( wxPGCommonValue* v : m_commonValues )
{
delete v;
}
#if WXWIN_COMPATIBILITY_3_0
wxASSERT( gs_deletedEditorObjects[this]->empty() );
delete gs_deletedEditorObjects[this];
gs_deletedEditorObjects.erase(this);
#endif
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::Destroy()
{
if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
ReleaseMouse();
return wxControl::Destroy();
}
// -----------------------------------------------------------------------
wxPropertyGridPageState* wxPropertyGrid::CreateState() const
{
return new wxPropertyGridPageState();
}
// -----------------------------------------------------------------------
// wxPropertyGrid overridden wxWindow methods
// -----------------------------------------------------------------------
void wxPropertyGrid::SetWindowStyleFlag( long style )
{
long old_style = m_windowStyle;
if ( m_iFlags & wxPG_FL_INITIALIZED )
{
wxASSERT( m_pState );
if ( !(style & wxPG_HIDE_CATEGORIES) && (old_style & wxPG_HIDE_CATEGORIES) )
{
// Enable categories
EnableCategories( true );
}
else if ( (style & wxPG_HIDE_CATEGORIES) && !(old_style & wxPG_HIDE_CATEGORIES) )
{
// Disable categories
EnableCategories( false );
}
if ( !(old_style & wxPG_AUTO_SORT) && (style & wxPG_AUTO_SORT) )
{
//
// Auto sort enabled
//
if ( !IsFrozen() )
PrepareAfterItemsAdded();
else
m_pState->m_itemsAdded = true;
}
#if wxUSE_TOOLTIPS
if ( !(old_style & wxPG_TOOLTIPS) && (style & wxPG_TOOLTIPS) )
{
//
// Tooltips enabled
//
//wxToolTip::SetDelay(wxPG_TOOLTIP_DELAY);
}
else if ( (old_style & wxPG_TOOLTIPS) && !(style & wxPG_TOOLTIPS) )
{
//
// Tooltips disabled
//
UnsetToolTip();
}
#endif // wxUSE_TOOLTIPS
}
wxControl::SetWindowStyleFlag ( style );
if ( m_iFlags & wxPG_FL_INITIALIZED )
{
if ( (old_style & wxPG_HIDE_MARGIN) != (style & wxPG_HIDE_MARGIN) )
{
CalculateFontAndBitmapStuff( m_vspacing );
Refresh();
}
}
}
// -----------------------------------------------------------------------
void wxPropertyGrid::DoThaw()
{
if ( !IsFrozen() )
{
wxControl::DoThaw();
RecalculateVirtualSize();
Refresh();
// Force property re-selection
// NB: We must copy the selection.
wxArrayPGProperty selection = m_pState->m_selection;
DoSetSelection(selection, wxPGSelectPropertyFlags::Force | wxPGSelectPropertyFlags::Nonvisible);
}
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::DoAddToSelection( wxPGProperty* prop, wxPGSelectPropertyFlags selFlags )
{
wxCHECK( prop, false );
if ( !HasExtraStyle(wxPG_EX_MULTIPLE_SELECTION) )
return DoSelectProperty(prop, selFlags);
wxArrayPGProperty& selection = m_pState->m_selection;
if ( selection.empty() )
{
return DoSelectProperty(prop, selFlags);
}
else
{
// For categories, only one can be selected at a time
if ( prop->IsCategory() || selection[0]->IsCategory() )
return true;
selection.push_back(prop);
if ( !(selFlags & wxPGSelectPropertyFlags::DontSendEvent) )
{
SendEvent( wxEVT_PG_SELECTED, prop, nullptr );
}
DrawItem(prop);
}
return true;
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty* prop, wxPGSelectPropertyFlags selFlags )
{
wxCHECK( prop, false );
bool res;
wxArrayPGProperty& selection = m_pState->m_selection;
if ( selection.size() <= 1 )
{
res = DoSelectProperty(nullptr, selFlags);
}
else
{
m_pState->DoRemoveFromSelection(prop);
DrawItem(prop);
res = true;
}
return res;
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty* prop,
unsigned int colIndex,
wxPGSelectPropertyFlags selFlags )
{
//
// NB: Enable following if label editor background colour is
// ever changed to any other than m_colSelBack.
//
// We use this workaround to prevent visible flicker when editing
// a cell. At least on wxMSW, there is a difficult to find
// (and perhaps prevent) redraw somewhere between making property
// selected and enabling label editing.
//
//wxColour prevColSelBack = m_colSelBack;
//m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
bool res;
if ( colIndex == 1 )
{
res = DoSelectProperty(prop, selFlags);
}
else
{
// send event
DoClearSelection(false, wxPGSelectPropertyFlags::NoRefresh);
if ( m_pState->m_editableColumns.find(colIndex) == m_pState->m_editableColumns.end() )
{
res = DoAddToSelection(prop, selFlags);
}
else
{
res = DoAddToSelection(prop, selFlags| wxPGSelectPropertyFlags::NoRefresh);
DoBeginLabelEdit(colIndex, selFlags);
}
}
//m_colSelBack = prevColSelBack;
return res;
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop,
unsigned int colIndex,
wxMouseEvent* mouseEvent,
wxPGSelectPropertyFlags selFlags )
{
const wxArrayPGProperty& selection = GetSelectedProperties();
bool alreadySelected = m_pState->DoIsPropertySelected(prop);
bool res = true;
// Set to 2 if also add all items in between
int addToExistingSelection = 0;
if ( HasExtraStyle(wxPG_EX_MULTIPLE_SELECTION) )
{
if ( mouseEvent )
{
if ( mouseEvent->GetEventType() == wxEVT_RIGHT_DOWN ||
mouseEvent->GetEventType() == wxEVT_RIGHT_UP )
{
// Allow right-click for context menu without
// disturbing the selection.
if ( selection.size() <= 1 ||
!alreadySelected )
return DoSelectAndEdit(prop, colIndex, selFlags);
return true;
}
else
{
if ( mouseEvent->ControlDown() )
{
addToExistingSelection = 1;
}
else if ( mouseEvent->ShiftDown() )
{
if ( !selection.empty() && !prop->IsCategory() )
addToExistingSelection = 2;
else
addToExistingSelection = 1;
}
}
}
}
if ( addToExistingSelection == 1 )
{
// Add/remove one
if ( !alreadySelected )
{
res = DoAddToSelection(prop, selFlags);
}
else if ( selection.size() > 1 )
{
res = DoRemoveFromSelection(prop, selFlags);
}
}
else if ( addToExistingSelection == 2 )
{
// Add this, and all in between
// Find top selected property
wxPGProperty* topSelProp = selection[0];
int topSelPropY = topSelProp->GetY();
for ( unsigned int i=1; i<selection.size(); i++ )
{
wxPGProperty* p = selection[i];
int y = p->GetY();
if ( y < topSelPropY )
{
topSelProp = p;
topSelPropY = y;
}
}
wxPGProperty* startFrom;
wxPGProperty* stopAt;
if ( prop->GetY() <= topSelPropY )
{
// Property is above selection (or same)
startFrom = prop;
stopAt = topSelProp;
}
else
{
// Property is below selection
startFrom = topSelProp;
stopAt = prop;
}
// Iterate through properties in-between, and select them
for ( wxPropertyGridIterator it = GetIterator(wxPG_ITERATE_VISIBLE, startFrom);
!it.AtEnd();
++it )
{
wxPGProperty* p = *it;
if ( !p->IsCategory() &&
!m_pState->DoIsPropertySelected(p) )
{
DoAddToSelection(p, selFlags);
}
if ( p == stopAt )
break;
}
}
else
{
res = DoSelectAndEdit(prop, colIndex, selFlags);
}
return res;
}
// -----------------------------------------------------------------------
void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty& newSelection,
wxPGSelectPropertyFlags selFlags )
{
if ( !newSelection.empty() )
{
if ( !DoSelectProperty(newSelection[0], selFlags) )
return;
}
else
{
DoClearSelection(false, selFlags);
}
for ( unsigned int i = 1; i < newSelection.size(); i++ )
{
DoAddToSelection(newSelection[i], selFlags);
}
Refresh();
}
// -----------------------------------------------------------------------
void wxPropertyGrid::MakeColumnEditable( unsigned int column,
bool editable )
{
// The second column is always editable. To make it read-only is a property
// by property decision by setting its wxPGPropertyFlags::ReadOnly flag.
wxASSERT_MSG
(
column != 1,
wxS("Set wxPGPropertyFlags::ReadOnly property flag instead")
);
if ( editable )
{
m_pState->m_editableColumns.insert(column);
}
else
{
m_pState->m_editableColumns.erase(column);
}
}
// -----------------------------------------------------------------------
void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex,
wxPGSelectPropertyFlags selFlags )
{
wxPGProperty* selected = GetSelection();
wxCHECK_RET(selected, wxS("No property selected"));
wxCHECK_RET(colIndex != 1, wxS("Do not use this for column 1"));
if ( !(selFlags & wxPGSelectPropertyFlags::DontSendEvent) )
{
if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN,
selected, nullptr, wxPGSelectPropertyFlags::Null,
colIndex ) )
return;
}
wxString text;
const wxPGCell* cell = nullptr;
if ( selected->HasCell(colIndex) )
{
cell = &selected->GetCell(colIndex);
if ( !cell->HasText() && colIndex == 0 )
text = selected->GetLabel();
}
if ( !cell )
{
if ( colIndex == 0 )
text = selected->GetLabel();
else
cell = &selected->GetOrCreateCell(colIndex);
}
if ( cell && cell->HasText() )
text = cell->GetText();
DoEndLabelEdit(true, wxPGSelectPropertyFlags::NoValidate); // send event
m_selColumn = colIndex;