]> git.saurik.com Git - wxWidgets.git/blame - src/propgrid/propgrid.cpp
Make m_idleMutex an object instead of a pointer. Use bool for hook-installed flag...
[wxWidgets.git] / src / propgrid / propgrid.cpp
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/propgrid/propgrid.cpp
3// Purpose: wxPropertyGrid
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2004-09-25
ea5af9c5 7// RCS-ID: $Id$
1c4293cb
VZ
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
f4bc1aa2
JS
19#if wxUSE_PROPGRID
20
1c4293cb
VZ
21#ifndef WX_PRECOMP
22 #include "wx/defs.h"
23 #include "wx/object.h"
24 #include "wx/hash.h"
25 #include "wx/string.h"
26 #include "wx/log.h"
27 #include "wx/event.h"
28 #include "wx/window.h"
29 #include "wx/panel.h"
30 #include "wx/dc.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
33 #include "wx/pen.h"
34 #include "wx/brush.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
1c4293cb
VZ
43 #include "wx/sizer.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/intl.h"
48 #include "wx/frame.h"
49#endif
50
51
52// This define is necessary to prevent macro clearing
53#define __wxPG_SOURCE_FILE__
54
3b211af1
SC
55#include "wx/propgrid/propgrid.h"
56#include "wx/propgrid/editors.h"
1c4293cb
VZ
57
58#if wxPG_USE_RENDERER_NATIVE
3b211af1 59 #include "wx/renderer.h"
1c4293cb
VZ
60#endif
61
3b211af1 62#include "wx/odcombo.h"
1c4293cb
VZ
63
64#include "wx/timer.h"
65#include "wx/dcbuffer.h"
1c4293cb 66
1c4293cb
VZ
67// Two pics for the expand / collapse buttons.
68// Files are not supplied with this project (since it is
69// recommended to use either custom or native rendering).
70// If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
71// and copy xpm files from archive to wxPropertyGrid src directory
72// (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
73// and set wxPG_USE_RENDERER_NATIVE to 0).
74#ifndef wxPG_ICON_WIDTH
75 #if defined(__WXMAC__)
76 #include "mac_collapse.xpm"
77 #include "mac_expand.xpm"
78 #elif defined(__WXGTK__)
79 #include "linux_collapse.xpm"
80 #include "linux_expand.xpm"
81 #else
82 #include "default_collapse.xpm"
83 #include "default_expand.xpm"
84 #endif
85#endif
86
87
88//#define wxPG_TEXT_INDENT 4 // For the wxComboControl
b7bc9d80 89//#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
1c4293cb
VZ
90#define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
91#define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
92#define wxPG_YSPACING_MIN 1
93#define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
94 // but causes normal combobox to spill out under MSW
95
b7bc9d80 96//#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
1c4293cb 97
b7bc9d80 98//#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
1c4293cb
VZ
99 // Must be larger than largest control border
100 // width * 2.
101
102
103#define wxPG_DEFAULT_CURSOR wxNullCursor
104
105
106//#define wxPG_NAT_CHOICE_BORDER_ANY 0
107
b7bc9d80 108//#define wxPG_HIDER_BUTTON_HEIGHT 25
1c4293cb
VZ
109
110#define wxPG_PIXELS_PER_UNIT m_lineHeight
111
112#ifdef wxPG_ICON_WIDTH
113 #define m_iconHeight m_iconWidth
114#endif
115
b7bc9d80 116//#define wxPG_TOOLTIP_DELAY 1000
1c4293cb
VZ
117
118// -----------------------------------------------------------------------
119
120#if wxUSE_INTL
121void wxPropertyGrid::AutoGetTranslation ( bool enable )
122{
123 wxPGGlobalVars->m_autoGetTranslation = enable;
124}
125#else
126void wxPropertyGrid::AutoGetTranslation ( bool ) { }
127#endif
128
129// -----------------------------------------------------------------------
130
23318a53 131const char wxPropertyGridNameStr[] = "wxPropertyGrid";
1c4293cb
VZ
132
133// -----------------------------------------------------------------------
134// Statics in one class for easy destruction.
1c4293cb
VZ
135// -----------------------------------------------------------------------
136
3b211af1 137#include "wx/module.h"
1c4293cb
VZ
138
139class wxPGGlobalVarsClassManager : public wxModule
140{
141 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager)
142public:
143 wxPGGlobalVarsClassManager() {}
144 virtual bool OnInit() { wxPGGlobalVars = new wxPGGlobalVarsClass(); return true; }
145 virtual void OnExit() { delete wxPGGlobalVars; wxPGGlobalVars = NULL; }
146};
147
148IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager, wxModule)
149
1c4293cb 150
b512ed93
JS
151// When wxPG is loaded dynamically after the application is already running
152// then the built-in module system won't pick this one up. Add it manually.
153void wxPGInitResourceModule()
154{
155 wxModule* module = new wxPGGlobalVarsClassManager;
156 module->Init();
157 wxModule::RegisterModule(module);
158}
159
d3b9f782 160wxPGGlobalVarsClass* wxPGGlobalVars = NULL;
1c4293cb
VZ
161
162
163wxPGGlobalVarsClass::wxPGGlobalVarsClass()
164{
165 wxPGProperty::sm_wxPG_LABEL = new wxString(wxPG_LABEL_STRING);
166
167 m_boolChoices.Add(_("False"));
168 m_boolChoices.Add(_("True"));
169
d3b9f782 170 m_fontFamilyChoices = NULL;
1c4293cb
VZ
171
172 m_defaultRenderer = new wxPGDefaultRenderer();
173
174 m_autoGetTranslation = false;
175
176 m_offline = 0;
177
178 m_extraStyle = 0;
179
180 wxVariant v;
181
657a8a35 182 // Prepare some shared variants
1c4293cb
VZ
183 m_vEmptyString = wxString();
184 m_vZero = (long) 0;
185 m_vMinusOne = (long) -1;
186 m_vTrue = true;
187 m_vFalse = false;
188
189 // Prepare cached string constants
0372d42e
JS
190 m_strstring = wxS("string");
191 m_strlong = wxS("long");
192 m_strbool = wxS("bool");
193 m_strlist = wxS("list");
0ce8e27f 194 m_strDefaultValue = wxS("DefaultValue");
1c4293cb
VZ
195 m_strMin = wxS("Min");
196 m_strMax = wxS("Max");
197 m_strUnits = wxS("Units");
198 m_strInlineHelp = wxS("InlineHelp");
199
1c4293cb 200 m_warnings = 0;
1c4293cb
VZ
201}
202
203
204wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
205{
206 size_t i;
207
208 delete m_defaultRenderer;
209
210 // This will always have one ref
211 delete m_fontFamilyChoices;
212
213#if wxUSE_VALIDATORS
214 for ( i=0; i<m_arrValidators.size(); i++ )
215 delete ((wxValidator*)m_arrValidators[i]);
216#endif
217
218 //
219 // Destroy value type class instances.
220 wxPGHashMapS2P::iterator vt_it;
221
222 // Destroy editor class instances.
223 // iterate over all the elements in the class
224 for( vt_it = m_mapEditorClasses.begin(); vt_it != m_mapEditorClasses.end(); ++vt_it )
225 {
226 delete ((wxPGEditor*)vt_it->second);
227 }
228
229 delete wxPGProperty::sm_wxPG_LABEL;
230}
231
c8074be0
JS
232void wxPropertyGridInitGlobalsIfNeeded()
233{
234}
235
1c4293cb
VZ
236// -----------------------------------------------------------------------
237// wxPropertyGrid
238// -----------------------------------------------------------------------
239
240IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid, wxScrolledWindow)
241
242BEGIN_EVENT_TABLE(wxPropertyGrid, wxScrolledWindow)
243 EVT_IDLE(wxPropertyGrid::OnIdle)
1c4293cb
VZ
244 EVT_PAINT(wxPropertyGrid::OnPaint)
245 EVT_SIZE(wxPropertyGrid::OnResize)
246 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry)
247 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry)
248 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange)
249 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent)
250 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent)
251 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent)
252 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent)
1c4293cb 253 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged)
39e4e221
JS
254 EVT_MOTION(wxPropertyGrid::OnMouseMove)
255 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick)
256 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp)
257 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick)
258 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick)
259 EVT_KEY_DOWN(wxPropertyGrid::OnKey)
1c4293cb
VZ
260END_EVENT_TABLE()
261
1c4293cb
VZ
262// -----------------------------------------------------------------------
263
264wxPropertyGrid::wxPropertyGrid()
265 : wxScrolledWindow()
266{
267 Init1();
268}
269
270// -----------------------------------------------------------------------
271
272wxPropertyGrid::wxPropertyGrid( wxWindow *parent,
273 wxWindowID id,
274 const wxPoint& pos,
275 const wxSize& size,
276 long style,
23318a53 277 const wxString& name )
1c4293cb
VZ
278 : wxScrolledWindow()
279{
280 Init1();
281 Create(parent,id,pos,size,style,name);
282}
283
284// -----------------------------------------------------------------------
285
286bool wxPropertyGrid::Create( wxWindow *parent,
287 wxWindowID id,
288 const wxPoint& pos,
289 const wxSize& size,
290 long style,
23318a53 291 const wxString& name )
1c4293cb
VZ
292{
293
521f1d83
JS
294 if (!(style&wxBORDER_MASK))
295 {
296 style |= wxBORDER_THEME;
297 }
1c4293cb
VZ
298
299 style |= wxVSCROLL;
300
68f9e025
JS
301 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
302 style &= ~(wxTAB_TRAVERSAL);
303 style |= wxWANTS_CHARS;
1c4293cb
VZ
304
305 wxScrolledWindow::Create(parent,id,pos,size,style,name);
306
307 Init2();
308
309 return true;
310}
311
312// -----------------------------------------------------------------------
313
314//
315// Initialize values to defaults
316//
317void wxPropertyGrid::Init1()
318{
1c4293cb
VZ
319 // Register editor classes, if necessary.
320 if ( wxPGGlobalVars->m_mapEditorClasses.empty() )
c8074be0 321 wxPropertyGrid::RegisterDefaultEditors();
1c4293cb
VZ
322
323 m_iFlags = 0;
d3b9f782
VZ
324 m_pState = NULL;
325 m_wndEditor = m_wndEditor2 = NULL;
58935d4a
JS
326 m_selColumn = 1;
327 m_colHover = 1;
d3b9f782 328 m_propHover = NULL;
58935d4a
JS
329 m_labelEditor = NULL;
330 m_labelEditorProperty = NULL;
1c4293cb 331 m_eventObject = this;
d3b9f782 332 m_curFocused = NULL;
e84e5ba3 333 m_processedEvent = NULL;
43396981 334 m_sortFunction = NULL;
1c4293cb
VZ
335 m_inDoPropertyChanged = 0;
336 m_inCommitChangesFromEditor = 0;
337 m_inDoSelectProperty = 0;
338 m_permanentValidationFailureBehavior = wxPG_VFB_DEFAULT;
339 m_dragStatus = 0;
340 m_mouseSide = 16;
341 m_editorFocused = 0;
342
343 // Set default keys
344 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RIGHT );
345 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
346 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_LEFT );
347 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
348 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY, WXK_RIGHT);
349 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY, WXK_LEFT);
350 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT, WXK_ESCAPE );
1766bf34 351 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_DOWN, wxMOD_ALT );
cfb97361 352 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_F4 );
1c4293cb
VZ
353
354 m_coloursCustomized = 0;
355 m_frozen = 0;
356
1c4293cb 357#if wxPG_DOUBLE_BUFFER
d3b9f782 358 m_doubleBuffer = NULL;
1c4293cb
VZ
359#endif
360
1c4293cb 361#ifndef wxPG_ICON_WIDTH
657a8a35
VZ
362 m_expandbmp = NULL;
363 m_collbmp = NULL;
364 m_iconWidth = 11;
365 m_iconHeight = 11;
1c4293cb
VZ
366#else
367 m_iconWidth = wxPG_ICON_WIDTH;
368#endif
369
370 m_prevVY = -1;
371
372 m_gutterWidth = wxPG_GUTTER_MIN;
373 m_subgroup_extramargin = 10;
374
375 m_lineHeight = 0;
376
377 m_width = m_height = 0;
378
1c4293cb
VZ
379 m_commonValues.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars->m_defaultRenderer) );
380 m_cvUnspecified = 0;
381
382 m_chgInfo_changedProperty = NULL;
383}
384
385// -----------------------------------------------------------------------
386
387//
388// Initialize after parent etc. set
389//
390void wxPropertyGrid::Init2()
391{
392 wxASSERT( !(m_iFlags & wxPG_FL_INITIALIZED ) );
393
394#ifdef __WXMAC__
395 // Smaller controls on Mac
396 SetWindowVariant(wxWINDOW_VARIANT_SMALL);
23318a53 397#endif
1c4293cb
VZ
398
399 // Now create state, if one didn't exist already
400 // (wxPropertyGridManager might have created it for us).
401 if ( !m_pState )
402 {
403 m_pState = CreateState();
404 m_pState->m_pPropGrid = this;
405 m_iFlags |= wxPG_FL_CREATEDSTATE;
406 }
407
408 if ( !(m_windowStyle & wxPG_SPLITTER_AUTO_CENTER) )
0da1f1c4 409 m_pState->m_dontCenterSplitter = true;
1c4293cb
VZ
410
411 if ( m_windowStyle & wxPG_HIDE_CATEGORIES )
412 {
413 m_pState->InitNonCatMode();
414
415 m_pState->m_properties = m_pState->m_abcArray;
416 }
417
418 GetClientSize(&m_width,&m_height);
419
420#ifndef wxPG_ICON_WIDTH
421 // create two bitmap nodes for drawing
657a8a35
VZ
422 m_expandbmp = new wxBitmap(expand_xpm);
423 m_collbmp = new wxBitmap(collapse_xpm);
1c4293cb 424
657a8a35 425 // calculate average font height for bitmap centering
1c4293cb 426
657a8a35
VZ
427 m_iconWidth = m_expandbmp->GetWidth();
428 m_iconHeight = m_expandbmp->GetHeight();
1c4293cb
VZ
429#endif
430
431 m_curcursor = wxCURSOR_ARROW;
432 m_cursorSizeWE = new wxCursor( wxCURSOR_SIZEWE );
433
657a8a35 434 // adjust bitmap icon y position so they are centered
1c4293cb
VZ
435 m_vspacing = wxPG_DEFAULT_VSPACING;
436
2197ec80 437 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING );
1c4293cb 438
d7e2b522
JS
439 // Allocate cell datas indirectly by calling setter
440 m_propertyDefaultCell.SetBgCol(*wxBLACK);
441 m_categoryDefaultCell.SetBgCol(*wxBLACK);
1c4293cb
VZ
442
443 RegainColours();
444
445 // This helps with flicker
446 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
447
27c1f235
JS
448 // Hook the top-level parent
449 m_tlp = NULL;
6edd8829
JS
450 m_tlpClosed = NULL;
451 m_tlpClosedTime = 0;
1c4293cb 452
657a8a35 453 // set virtual size to this window size
1c4293cb 454 wxSize wndsize = GetSize();
657a8a35 455 SetVirtualSize(wndsize.GetWidth(), wndsize.GetWidth());
1c4293cb
VZ
456
457 m_timeCreated = ::wxGetLocalTimeMillis();
458
39e4e221
JS
459 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
460 // wxWANTS_CHARS | wxCLIP_CHILDREN);
461 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
1c4293cb
VZ
462
463 m_iFlags |= wxPG_FL_INITIALIZED;
464
465 m_ncWidth = wndsize.GetWidth();
466
467 // Need to call OnResize handler or size given in constructor/Create
468 // will never work.
469 wxSizeEvent sizeEvent(wndsize,0);
470 OnResize(sizeEvent);
471}
472
473// -----------------------------------------------------------------------
474
475wxPropertyGrid::~wxPropertyGrid()
476{
477 size_t i;
478
9370ec6a 479#if wxUSE_THREADS
644b283d
JS
480 wxCriticalSectionLocker(wxPGGlobalVars->m_critSect);
481#endif
482
483 //
484 // Remove grid and property pointers from live wxPropertyGridEvents.
485 for ( i=0; i<m_liveEvents.size(); i++ )
486 {
487 wxPropertyGridEvent* evt = m_liveEvents[i];
488 evt->SetPropertyGrid(NULL);
489 evt->SetProperty(NULL);
490 }
491 m_liveEvents.clear();
492
e84e5ba3
JS
493 if ( m_processedEvent )
494 {
495 // All right... we are being deleted while wxPropertyGrid event
496 // is being sent. Make sure that event propagates as little
497 // as possible (although usually this is not enough to prevent
498 // a crash).
499 m_processedEvent->Skip(false);
500 m_processedEvent->StopPropagation();
501
502 // Let's use wxMessageBox to make the message appear more
644b283d 503 // reliably (and *before* the crash can happen).
e84e5ba3
JS
504 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
505 "generated by it. This usually leads to a crash "
506 "so it is recommended to destroy the control "
507 "at idle time instead.");
508 }
509
fc72fab6 510 DoSelectProperty(NULL, wxPG_SEL_NOVALIDATE|wxPG_SEL_DONT_SEND_EVENT);
1c4293cb
VZ
511
512 // This should do prevent things from going too badly wrong
513 m_iFlags &= ~(wxPG_FL_INITIALIZED);
514
515 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
39e4e221 516 ReleaseMouse();
1c4293cb 517
6edd8829 518 // Call with NULL to disconnect event handling
08c1613f
JS
519 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING )
520 {
521 OnTLPChanging(NULL);
1c4293cb 522
08c1613f
JS
523 wxASSERT_MSG( !IsEditorsValueModified(),
524 wxS("Most recent change in property editor was ")
525 wxS("lost!!! (if you don't want this to happen, ")
526 wxS("close your frames and dialogs using ")
527 wxS("Close(false).)") );
528 }
1c4293cb
VZ
529
530#if wxPG_DOUBLE_BUFFER
531 if ( m_doubleBuffer )
532 delete m_doubleBuffer;
533#endif
534
1c4293cb
VZ
535 if ( m_iFlags & wxPG_FL_CREATEDSTATE )
536 delete m_pState;
537
538 delete m_cursorSizeWE;
539
540#ifndef wxPG_ICON_WIDTH
657a8a35
VZ
541 delete m_expandbmp;
542 delete m_collbmp;
1c4293cb
VZ
543#endif
544
1c4293cb
VZ
545 // Delete common value records
546 for ( i=0; i<m_commonValues.size(); i++ )
547 {
521f1d83
JS
548 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
549 wxPGCommonValue* value = m_commonValues[i];
550 delete value;
1c4293cb
VZ
551 }
552}
553
554// -----------------------------------------------------------------------
555
556bool wxPropertyGrid::Destroy()
557{
558 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
39e4e221 559 ReleaseMouse();
1c4293cb
VZ
560
561 return wxScrolledWindow::Destroy();
562}
563
564// -----------------------------------------------------------------------
565
566wxPropertyGridPageState* wxPropertyGrid::CreateState() const
567{
568 return new wxPropertyGridPageState();
569}
570
571// -----------------------------------------------------------------------
572// wxPropertyGrid overridden wxWindow methods
573// -----------------------------------------------------------------------
574
575void wxPropertyGrid::SetWindowStyleFlag( long style )
576{
577 long old_style = m_windowStyle;
578
579 if ( m_iFlags & wxPG_FL_INITIALIZED )
580 {
581 wxASSERT( m_pState );
582
583 if ( !(style & wxPG_HIDE_CATEGORIES) && (old_style & wxPG_HIDE_CATEGORIES) )
584 {
585 // Enable categories
586 EnableCategories( true );
587 }
588 else if ( (style & wxPG_HIDE_CATEGORIES) && !(old_style & wxPG_HIDE_CATEGORIES) )
589 {
590 // Disable categories
591 EnableCategories( false );
592 }
593 if ( !(old_style & wxPG_AUTO_SORT) && (style & wxPG_AUTO_SORT) )
594 {
595 //
596 // Autosort enabled
597 //
598 if ( !m_frozen )
599 PrepareAfterItemsAdded();
600 else
601 m_pState->m_itemsAdded = 1;
602 }
603 #if wxPG_SUPPORT_TOOLTIPS
604 if ( !(old_style & wxPG_TOOLTIPS) && (style & wxPG_TOOLTIPS) )
605 {
606 //
607 // Tooltips enabled
608 //
609 /*
610 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
611 SetToolTip ( tooltip );
612 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
613 */
614 }
615 else if ( (old_style & wxPG_TOOLTIPS) && !(style & wxPG_TOOLTIPS) )
616 {
617 //
618 // Tooltips disabled
619 //
39e4e221 620 wxScrolledWindow::SetToolTip( NULL );
1c4293cb
VZ
621 }
622 #endif
623 }
624
625 wxScrolledWindow::SetWindowStyleFlag ( style );
626
627 if ( m_iFlags & wxPG_FL_INITIALIZED )
628 {
629 if ( (old_style & wxPG_HIDE_MARGIN) != (style & wxPG_HIDE_MARGIN) )
630 {
631 CalculateFontAndBitmapStuff( m_vspacing );
632 Refresh();
633 }
634 }
635}
636
637// -----------------------------------------------------------------------
638
639void wxPropertyGrid::Freeze()
640{
641 if ( !m_frozen )
642 {
643 wxScrolledWindow::Freeze();
644 }
645 m_frozen++;
646}
647
648// -----------------------------------------------------------------------
649
650void wxPropertyGrid::Thaw()
651{
652 m_frozen--;
653
654 if ( !m_frozen )
655 {
656 wxScrolledWindow::Thaw();
657 RecalculateVirtualSize();
658 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
39e4e221 659 Refresh();
1c4293cb
VZ
660 #endif
661
662 // Force property re-selection
fc72fab6
JS
663 // NB: We must copy the selection.
664 wxArrayPGProperty selection = m_pState->m_selection;
665 DoSetSelection(selection, wxPG_SEL_FORCE);
666 }
667}
668
669// -----------------------------------------------------------------------
670
671bool wxPropertyGrid::DoAddToSelection( wxPGProperty* prop, int selFlags )
672{
673 wxCHECK( prop, false );
674
675 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION) )
676 return DoSelectProperty(prop, selFlags);
677
678 wxArrayPGProperty& selection = m_pState->m_selection;
679
680 if ( !selection.size() )
681 {
682 return DoSelectProperty(prop, selFlags);
683 }
684 else
685 {
686 // For categories, only one can be selected at a time
687 if ( prop->IsCategory() || selection[0]->IsCategory() )
688 return true;
689
690 selection.push_back(prop);
691
692 if ( !(selFlags & wxPG_SEL_DONT_SEND_EVENT) )
693 {
58935d4a 694 SendEvent( wxEVT_PG_SELECTED, prop, NULL );
fc72fab6
JS
695 }
696
58935d4a 697 DrawItem(prop);
fc72fab6
JS
698 }
699
700 return true;
701}
702
703// -----------------------------------------------------------------------
704
705bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty* prop, int selFlags )
706{
707 wxCHECK( prop, false );
708 bool res;
709
710 wxArrayPGProperty& selection = m_pState->m_selection;
711 if ( selection.size() <= 1 )
712 {
713 res = DoSelectProperty(NULL, selFlags);
714 }
715 else
716 {
7f3f8f1e 717 m_pState->DoRemoveFromSelection(prop);
58935d4a 718 DrawItem(prop);
fc72fab6
JS
719 res = true;
720 }
721
722 return res;
723}
724
725// -----------------------------------------------------------------------
726
58935d4a
JS
727bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty* prop,
728 unsigned int colIndex,
729 unsigned int selFlags )
730{
731 //
732 // NB: Enable following if label editor background colour is
733 // ever changed to any other than m_colSelBack.
734 //
735 // We use this workaround to prevent visible flicker when editing
736 // a cell. Atleast on wxMSW, there is a difficult to find
737 // (and perhaps prevent) redraw somewhere between making property
738 // selected and enabling label editing.
739 //
740 //wxColour prevColSelBack = m_colSelBack;
741 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
742
743 bool res;
744
745 if ( colIndex == 1 )
746 {
747 res = DoSelectProperty(prop, selFlags);
748 }
749 else
750 {
751 // send event
752 DoClearSelection(false, wxPG_SEL_NO_REFRESH);
753
754 if ( m_pState->m_editableColumns.Index(colIndex) == wxNOT_FOUND )
755 {
756 res = DoAddToSelection(prop, selFlags);
757 }
758 else
759 {
760 res = DoAddToSelection(prop, selFlags|wxPG_SEL_NO_REFRESH);
761
762 DoBeginLabelEdit(colIndex, selFlags);
763 }
764 }
765
766 //m_colSelBack = prevColSelBack;
767 return res;
768}
769
770// -----------------------------------------------------------------------
771
fc72fab6 772bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop,
58935d4a 773 unsigned int colIndex,
fc72fab6
JS
774 wxMouseEvent* mouseEvent,
775 int selFlags )
776{
777 bool alreadySelected = m_pState->DoIsPropertySelected(prop);
778 bool res = true;
779 bool addToExistingSelection;
780
781 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION )
782 {
783 if ( mouseEvent )
784 {
785 if ( mouseEvent->GetEventType() == wxEVT_RIGHT_DOWN ||
786 mouseEvent->GetEventType() == wxEVT_RIGHT_UP )
787 {
788 // Allow right-click for context menu without
789 // disturbing the selection.
790 if ( GetSelectedProperties().size() <= 1 ||
791 !alreadySelected )
58935d4a 792 return DoSelectAndEdit(prop, colIndex, selFlags);
fc72fab6
JS
793 return true;
794 }
795 else
796 {
797 addToExistingSelection = mouseEvent->ShiftDown();
798 }
799 }
800 else
801 {
802 addToExistingSelection = false;
803 }
804 }
805 else
806 {
807 addToExistingSelection = false;
808 }
809
810 if ( addToExistingSelection )
811 {
812 if ( !alreadySelected )
813 {
814 res = DoAddToSelection(prop, selFlags);
815 }
816 else if ( GetSelectedProperties().size() > 1 )
817 {
818 res = DoRemoveFromSelection(prop, selFlags);
819 }
820 }
821 else
822 {
58935d4a 823 res = DoSelectAndEdit(prop, colIndex, selFlags);
fc72fab6
JS
824 }
825
826 return res;
827}
828
829// -----------------------------------------------------------------------
830
831void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty& newSelection,
832 int selFlags )
833{
834 if ( newSelection.size() > 0 )
835 {
836 if ( !DoSelectProperty(newSelection[0], selFlags) )
837 return;
838 }
839 else
840 {
841 DoClearSelection(false, selFlags);
842 }
843
844 for ( unsigned int i = 1; i < newSelection.size(); i++ )
845 {
846 DoAddToSelection(newSelection[i], selFlags);
1c4293cb 847 }
fc72fab6
JS
848
849 Refresh();
1c4293cb
VZ
850}
851
852// -----------------------------------------------------------------------
853
e9fb1910
JS
854void wxPropertyGrid::MakeColumnEditable( unsigned int column,
855 bool editable )
856{
857 wxASSERT( column != 1 );
858
859 wxArrayInt& cols = m_pState->m_editableColumns;
860
861 if ( editable )
862 {
863 cols.push_back(column);
864 }
865 else
866 {
867 for ( int i = cols.size() - 1; i > 0; i-- )
868 {
869 if ( cols[i] == (int)column )
870 cols.erase( cols.begin() + i );
871 }
872 }
873}
874
875// -----------------------------------------------------------------------
876
58935d4a
JS
877void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex,
878 int selFlags )
879{
880 wxPGProperty* selected = GetSelection();
881 wxCHECK_RET(selected, wxT("No property selected"));
882 wxCHECK_RET(colIndex != 1, wxT("Do not use this for column 1"));
883
884 if ( !(selFlags & wxPG_SEL_DONT_SEND_EVENT) )
885 {
886 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN,
887 selected, NULL, 0,
888 colIndex ) )
889 return;
890 }
891
892 wxString text;
893 const wxPGCell* cell = NULL;
894 if ( selected->HasCell(colIndex) )
895 {
896 cell = &selected->GetCell(colIndex);
897 if ( !cell->HasText() && colIndex == 0 )
898 text = selected->GetLabel();
899 }
900
901 if ( !cell )
902 {
903 if ( colIndex == 0 )
904 text = selected->GetLabel();
905 else
906 cell = &selected->GetOrCreateCell(colIndex);
907 }
908
909 if ( cell && cell->HasText() )
910 text = cell->GetText();
911
912 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE); // send event
913
914 m_selColumn = colIndex;
915
916 wxRect r = GetEditorWidgetRect(selected, m_selColumn);
917
918 wxWindow* tc = GenerateEditorTextCtrl(r.GetPosition(),
919 r.GetSize(),
920 text,
921 NULL,
922 wxTE_PROCESS_ENTER,
923 0,
924 colIndex);
925
926 wxWindowID id = tc->GetId();
927 tc->Connect(id, wxEVT_COMMAND_TEXT_ENTER,
928 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress),
929 NULL, this);
930 tc->Connect(id, wxEVT_KEY_DOWN,
931 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress),
932 NULL, this);
933
934 tc->SetFocus();
935
936 m_labelEditor = wxStaticCast(tc, wxTextCtrl);
937 m_labelEditorProperty = selected;
938}
939
940// -----------------------------------------------------------------------
941
942void
943wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent& WXUNUSED(event) )
944{
945 DoEndLabelEdit(true);
946}
947
948// -----------------------------------------------------------------------
949
950void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent& event )
951{
952 int keycode = event.GetKeyCode();
953
954 if ( keycode == WXK_ESCAPE )
955 {
956 DoEndLabelEdit(false);
957 }
958 else
959 {
960 event.Skip();
961 }
962}
963
964// -----------------------------------------------------------------------
965
966void wxPropertyGrid::DoEndLabelEdit( bool commit, int selFlags )
967{
968 if ( !m_labelEditor )
969 return;
970
971 wxPGProperty* prop = m_labelEditorProperty;
972 wxASSERT(prop);
973
974 if ( commit )
975 {
976 if ( !(selFlags & wxPG_SEL_DONT_SEND_EVENT) )
977 {
978 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
979 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING,
980 prop, NULL, selFlags,
981 m_selColumn ) )
982 return;
983 }
984
985 wxString text = m_labelEditor->GetValue();
986 wxPGCell* cell = NULL;
987 if ( prop->HasCell(m_selColumn) )
988 {
989 cell = &prop->GetCell(m_selColumn);
990 }
991 else
992 {
993 if ( m_selColumn == 0 )
994 prop->SetLabel(text);
995 else
996 cell = &prop->GetOrCreateCell(m_selColumn);
997 }
998
999 if ( cell )
1000 cell->SetText(text);
1001 }
1002
1003 m_selColumn = 1;
1004
1005 DestroyEditorWnd(m_labelEditor);
1006 m_labelEditor = NULL;
1007 m_labelEditorProperty = NULL;
1008
1009 DrawItem(prop);
1010}
1011
1012// -----------------------------------------------------------------------
1013
1c4293cb
VZ
1014void wxPropertyGrid::SetExtraStyle( long exStyle )
1015{
08c1613f
JS
1016 if ( exStyle & wxPG_EX_ENABLE_TLP_TRACKING )
1017 OnTLPChanging(::wxGetTopLevelParent(this));
1018 else
1019 OnTLPChanging(NULL);
1020
1c4293cb
VZ
1021 if ( exStyle & wxPG_EX_NATIVE_DOUBLE_BUFFERING )
1022 {
1023#if defined(__WXMSW__)
1024
1025 /*
1026 // Don't use WS_EX_COMPOSITED just now.
1027 HWND hWnd;
1028
1029 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1030 hWnd = (HWND)GetParent()->GetHWND();
1031 else
1032 hWnd = (HWND)GetHWND();
1033
1034 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1035 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1036 */
1037
1038//#elif defined(__WXGTK20__)
1039#endif
1040 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1041 // truly was double-buffered.
1042 if ( !this->IsDoubleBuffered() )
1043 {
1044 exStyle &= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING);
1045 }
1046 else
1047 {
1048 #if wxPG_DOUBLE_BUFFER
1049 delete m_doubleBuffer;
1050 m_doubleBuffer = NULL;
1051 #endif
1052 }
1053 }
1054
1055 wxScrolledWindow::SetExtraStyle( exStyle );
1056
1057 if ( exStyle & wxPG_EX_INIT_NOCAT )
1058 m_pState->InitNonCatMode();
1059
1060 if ( exStyle & wxPG_EX_HELP_AS_TOOLTIPS )
1061 m_windowStyle |= wxPG_TOOLTIPS;
1062
1063 // Set global style
1064 wxPGGlobalVars->m_extraStyle = exStyle;
1065}
1066
1067// -----------------------------------------------------------------------
1068
1069// returns the best acceptable minimal size
1070wxSize wxPropertyGrid::DoGetBestSize() const
1071{
916533c0 1072 int lineHeight = wxMax(15, m_lineHeight);
1c4293cb 1073
916533c0
VZ
1074 // don't make the grid too tall (limit height to 10 items) but don't
1075 // make it too small neither
1076 int numLines = wxMin
1077 (
1078 wxMax(m_pState->m_properties->GetChildCount(), 3),
1079 10
1080 );
1081
890defb4
VZ
1082 wxClientDC dc(const_cast<wxPropertyGrid *>(this));
1083 int width = m_marginWidth;
1084 for ( unsigned int i = 0; i < m_pState->m_colWidths.size(); i++ )
1085 {
1086 width += m_pState->GetColumnFitWidth(dc, m_pState->DoGetRoot(), i, true);
1087 }
1088
1089 const wxSize sz = wxSize(width, lineHeight*numLines + 40);
1090
1c4293cb
VZ
1091 CacheBestSize(sz);
1092 return sz;
1093}
1094
6edd8829 1095// -----------------------------------------------------------------------
27c1f235
JS
1096
1097void wxPropertyGrid::OnTLPChanging( wxWindow* newTLP )
1098{
08c1613f
JS
1099 if ( newTLP == m_tlp )
1100 return;
1101
6edd8829
JS
1102 wxLongLong currentTime = ::wxGetLocalTimeMillis();
1103
27c1f235
JS
1104 //
1105 // Parent changed so let's redetermine and re-hook the
1106 // correct top-level window.
1107 if ( m_tlp )
1108 {
27c1f235
JS
1109 m_tlp->Disconnect( wxEVT_CLOSE_WINDOW,
1110 wxCloseEventHandler(wxPropertyGrid::OnTLPClose),
1111 NULL, this );
6edd8829
JS
1112 m_tlpClosed = m_tlp;
1113 m_tlpClosedTime = currentTime;
27c1f235
JS
1114 }
1115
6edd8829
JS
1116 if ( newTLP )
1117 {
1118 // Only accept new tlp if same one was not just dismissed.
1119 if ( newTLP != m_tlpClosed ||
1120 m_tlpClosedTime+250 < currentTime )
1121 {
1122 newTLP->Connect( wxEVT_CLOSE_WINDOW,
1123 wxCloseEventHandler(wxPropertyGrid::OnTLPClose),
1124 NULL, this );
1125 m_tlpClosed = NULL;
1126 }
1127 else
1128 {
1129 newTLP = NULL;
1130 }
1131 }
27c1f235
JS
1132
1133 m_tlp = newTLP;
27c1f235
JS
1134}
1135
1136// -----------------------------------------------------------------------
1137
1138void wxPropertyGrid::OnTLPClose( wxCloseEvent& event )
1139{
1140 // ClearSelection forces value validation/commit.
01b5ad3b 1141 if ( event.CanVeto() && !DoClearSelection() )
27c1f235
JS
1142 {
1143 event.Veto();
1144 return;
1145 }
1146
6edd8829
JS
1147 // Ok, it can close, set tlp pointer to NULL. Some other event
1148 // handler can of course veto the close, but our OnIdle() should
1149 // then be able to regain the tlp pointer.
1150 OnTLPChanging(NULL);
1151
27c1f235
JS
1152 event.Skip();
1153}
1154
1155// -----------------------------------------------------------------------
1156
1157bool wxPropertyGrid::Reparent( wxWindowBase *newParent )
1158{
1159 OnTLPChanging((wxWindow*)newParent);
1160
1161 bool res = wxScrolledWindow::Reparent(newParent);
1162
1163 return res;
1164}
1165
1c4293cb
VZ
1166// -----------------------------------------------------------------------
1167// wxPropertyGrid Font and Colour Methods
1168// -----------------------------------------------------------------------
1169
1170void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing )
1171{
657a8a35 1172 int x = 0, y = 0;
1c4293cb
VZ
1173
1174 m_captionFont = wxScrolledWindow::GetFont();
1175
657a8a35 1176 GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
1c4293cb 1177 m_subgroup_extramargin = x + (x/2);
657a8a35 1178 m_fontHeight = y;
1c4293cb
VZ
1179
1180#if wxPG_USE_RENDERER_NATIVE
1181 m_iconWidth = wxPG_ICON_WIDTH;
1182#elif wxPG_ICON_WIDTH
1183 // scale icon
1184 m_iconWidth = (m_fontHeight * wxPG_ICON_WIDTH) / 13;
1185 if ( m_iconWidth < 5 ) m_iconWidth = 5;
1186 else if ( !(m_iconWidth & 0x01) ) m_iconWidth++; // must be odd
1187
1188#endif
1189
1190 m_gutterWidth = m_iconWidth / wxPG_GUTTER_DIV;
1191 if ( m_gutterWidth < wxPG_GUTTER_MIN )
1192 m_gutterWidth = wxPG_GUTTER_MIN;
1193
1194 int vdiv = 6;
1195 if ( vspacing <= 1 ) vdiv = 12;
1196 else if ( vspacing >= 3 ) vdiv = 3;
1197
1198 m_spacingy = m_fontHeight / vdiv;
1199 if ( m_spacingy < wxPG_YSPACING_MIN )
1200 m_spacingy = wxPG_YSPACING_MIN;
1201
1202 m_marginWidth = 0;
1203 if ( !(m_windowStyle & wxPG_HIDE_MARGIN) )
1204 m_marginWidth = m_gutterWidth*2 + m_iconWidth;
1205
1206 m_captionFont.SetWeight(wxBOLD);
657a8a35 1207 GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
1c4293cb
VZ
1208
1209 m_lineHeight = m_fontHeight+(2*m_spacingy)+1;
1c4293cb
VZ
1210
1211 // button spacing
1212 m_buttonSpacingY = (m_lineHeight - m_iconHeight) / 2;
1213 if ( m_buttonSpacingY < 0 ) m_buttonSpacingY = 0;
1214
1215 if ( m_pState )
1216 m_pState->CalculateFontAndBitmapStuff(vspacing);
1217
1218 if ( m_iFlags & wxPG_FL_INITIALIZED )
1219 RecalculateVirtualSize();
1220
1221 InvalidateBestSize();
1222}
1223
1224// -----------------------------------------------------------------------
1225
1226void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) )
1227{
1228 RegainColours();
1229 Refresh();
1230}
1231
1232// -----------------------------------------------------------------------
1233
1234static wxColour wxPGAdjustColour(const wxColour& src, int ra,
1235 int ga = 1000, int ba = 1000,
1236 bool forceDifferent = false)
1237{
1238 if ( ga >= 1000 )
1239 ga = ra;
1240 if ( ba >= 1000 )
1241 ba = ra;
1242
1243 // Recursion guard (allow 2 max)
1244 static int isinside = 0;
1245 isinside++;
1246 wxCHECK_MSG( isinside < 3,
1247 *wxBLACK,
1248 wxT("wxPGAdjustColour should not be recursively called more than once") );
1249
1250 wxColour dst;
1251
1252 int r = src.Red();
1253 int g = src.Green();
1254 int b = src.Blue();
1255 int r2 = r + ra;
1256 if ( r2>255 ) r2 = 255;
1257 else if ( r2<0) r2 = 0;
1258 int g2 = g + ga;
1259 if ( g2>255 ) g2 = 255;
1260 else if ( g2<0) g2 = 0;
1261 int b2 = b + ba;
1262 if ( b2>255 ) b2 = 255;
1263 else if ( b2<0) b2 = 0;
1264
1265 // Make sure they are somewhat different
1266 if ( forceDifferent && (abs((r+g+b)-(r2+g2+b2)) < abs(ra/2)) )
1267 dst = wxPGAdjustColour(src,-(ra*2));
1268 else
1269 dst = wxColour(r2,g2,b2);
1270
1271 // Recursion guard (allow 2 max)
1272 isinside--;
1273
1274 return dst;
1275}
1276
1277
1278static int wxPGGetColAvg( const wxColour& col )
1279{
1280 return (col.Red() + col.Green() + col.Blue()) / 3;
1281}
1282
1283
1284void wxPropertyGrid::RegainColours()
1285{
1c4293cb
VZ
1286 if ( !(m_coloursCustomized & 0x0002) )
1287 {
1288 wxColour col = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
1289
1290 // Make sure colour is dark enough
1291 #ifdef __WXGTK__
1292 int colDec = wxPGGetColAvg(col) - 230;
1293 #else
1294 int colDec = wxPGGetColAvg(col) - 200;
1295 #endif
1296 if ( colDec > 0 )
1297 m_colCapBack = wxPGAdjustColour(col,-colDec);
1298 else
1299 m_colCapBack = col;
d7e2b522 1300 m_categoryDefaultCell.GetData()->SetBgCol(m_colCapBack);
1c4293cb
VZ
1301 }
1302
1303 if ( !(m_coloursCustomized & 0x0001) )
1304 m_colMargin = m_colCapBack;
1305
1306 if ( !(m_coloursCustomized & 0x0004) )
1307 {
1308 #ifdef __WXGTK__
1309 int colDec = -90;
1310 #else
1311 int colDec = -72;
1312 #endif
1313 wxColour capForeCol = wxPGAdjustColour(m_colCapBack,colDec,5000,5000,true);
1314 m_colCapFore = capForeCol;
d7e2b522 1315 m_categoryDefaultCell.GetData()->SetFgCol(capForeCol);
1c4293cb
VZ
1316 }
1317
1318 if ( !(m_coloursCustomized & 0x0008) )
1319 {
1320 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
1321 m_colPropBack = bgCol;
d7e2b522 1322 m_propertyDefaultCell.GetData()->SetBgCol(bgCol);
1c4293cb
VZ
1323 }
1324
1325 if ( !(m_coloursCustomized & 0x0010) )
1326 {
1327 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
1328 m_colPropFore = fgCol;
d7e2b522 1329 m_propertyDefaultCell.GetData()->SetFgCol(fgCol);
1c4293cb
VZ
1330 }
1331
1332 if ( !(m_coloursCustomized & 0x0020) )
1333 m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
1334
1335 if ( !(m_coloursCustomized & 0x0040) )
1336 m_colSelFore = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
1337
1338 if ( !(m_coloursCustomized & 0x0080) )
1339 m_colLine = m_colCapBack;
1340
1341 if ( !(m_coloursCustomized & 0x0100) )
1342 m_colDisPropFore = m_colCapFore;
1343
1344 m_colEmptySpace = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
1345}
1346
1347// -----------------------------------------------------------------------
1348
1349void wxPropertyGrid::ResetColours()
1350{
1351 m_coloursCustomized = 0;
1352
1353 RegainColours();
1354
1355 Refresh();
1356}
1357
1358// -----------------------------------------------------------------------
1359
1360bool wxPropertyGrid::SetFont( const wxFont& font )
1361{
1362 // Must disable active editor.
01b5ad3b 1363 DoClearSelection();
1c4293cb 1364
1c4293cb 1365 bool res = wxScrolledWindow::SetFont( font );
521f1d83 1366 if ( res && GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1c4293cb
VZ
1367 {
1368 CalculateFontAndBitmapStuff( m_vspacing );
1c4293cb
VZ
1369 Refresh();
1370 }
1371
1372 return res;
1c4293cb
VZ
1373}
1374
1375// -----------------------------------------------------------------------
1376
1377void wxPropertyGrid::SetLineColour( const wxColour& col )
1378{
1379 m_colLine = col;
1380 m_coloursCustomized |= 0x80;
1381 Refresh();
1382}
1383
1384// -----------------------------------------------------------------------
1385
1386void wxPropertyGrid::SetMarginColour( const wxColour& col )
1387{
1388 m_colMargin = col;
1389 m_coloursCustomized |= 0x01;
1390 Refresh();
1391}
1392
1393// -----------------------------------------------------------------------
1394
1395void wxPropertyGrid::SetCellBackgroundColour( const wxColour& col )
1396{
1397 m_colPropBack = col;
1398 m_coloursCustomized |= 0x08;
1399
d7e2b522 1400 m_propertyDefaultCell.GetData()->SetBgCol(col);
1c4293cb
VZ
1401
1402 Refresh();
1403}
1404
1405// -----------------------------------------------------------------------
1406
1407void wxPropertyGrid::SetCellTextColour( const wxColour& col )
1408{
1409 m_colPropFore = col;
1410 m_coloursCustomized |= 0x10;
1411
d7e2b522 1412 m_propertyDefaultCell.GetData()->SetFgCol(col);
1c4293cb
VZ
1413
1414 Refresh();
1415}
1416
1417// -----------------------------------------------------------------------
1418
1419void wxPropertyGrid::SetEmptySpaceColour( const wxColour& col )
1420{
1421 m_colEmptySpace = col;
1422
1423 Refresh();
1424}
1425
1426// -----------------------------------------------------------------------
1427
1428void wxPropertyGrid::SetCellDisabledTextColour( const wxColour& col )
1429{
1430 m_colDisPropFore = col;
1431 m_coloursCustomized |= 0x100;
1432 Refresh();
1433}
1434
1435// -----------------------------------------------------------------------
1436
1437void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour& col )
1438{
1439 m_colSelBack = col;
1440 m_coloursCustomized |= 0x20;
1441 Refresh();
1442}
1443
1444// -----------------------------------------------------------------------
1445
1446void wxPropertyGrid::SetSelectionTextColour( const wxColour& col )
1447{
1448 m_colSelFore = col;
1449 m_coloursCustomized |= 0x40;
1450 Refresh();
1451}
1452
1453// -----------------------------------------------------------------------
1454
1455void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour& col )
1456{
1457 m_colCapBack = col;
1458 m_coloursCustomized |= 0x02;
d7e2b522
JS
1459
1460 m_categoryDefaultCell.GetData()->SetBgCol(col);
1461
1c4293cb
VZ
1462 Refresh();
1463}
1464
1465// -----------------------------------------------------------------------
1466
1467void wxPropertyGrid::SetCaptionTextColour( const wxColour& col )
1468{
1469 m_colCapFore = col;
1470 m_coloursCustomized |= 0x04;
1471
d7e2b522 1472 m_categoryDefaultCell.GetData()->SetFgCol(col);
1c4293cb
VZ
1473
1474 Refresh();
1475}
1476
1c4293cb
VZ
1477// -----------------------------------------------------------------------
1478// wxPropertyGrid property adding and removal
1479// -----------------------------------------------------------------------
1480
1481void wxPropertyGrid::PrepareAfterItemsAdded()
1482{
1483 if ( !m_pState || !m_pState->m_itemsAdded ) return;
1484
1485 m_pState->m_itemsAdded = 0;
1486
1487 if ( m_windowStyle & wxPG_AUTO_SORT )
0eb877f2 1488 Sort(wxPG_SORT_TOP_LEVEL_ONLY);
1c4293cb
VZ
1489
1490 RecalculateVirtualSize();
1491}
1492
1c4293cb
VZ
1493// -----------------------------------------------------------------------
1494// wxPropertyGrid property operations
1495// -----------------------------------------------------------------------
1496
1c4293cb
VZ
1497bool wxPropertyGrid::EnsureVisible( wxPGPropArg id )
1498{
1499 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1500
1501 Update();
1502
1503 bool changed = false;
1504
1505 // Is it inside collapsed section?
1506 if ( !p->IsVisible() )
1507 {
1508 // expand parents
1509 wxPGProperty* parent = p->GetParent();
1510 wxPGProperty* grandparent = parent->GetParent();
1511
1512 if ( grandparent && grandparent != m_pState->m_properties )
1513 Expand( grandparent );
1514
1515 Expand( parent );
1516 changed = true;
1517 }
1518
1519 // Need to scroll?
1520 int vx, vy;
1521 GetViewStart(&vx,&vy);
1522 vy*=wxPG_PIXELS_PER_UNIT;
1523
1524 int y = p->GetY();
1525
1526 if ( y < vy )
1527 {
1528 Scroll(vx, y/wxPG_PIXELS_PER_UNIT );
1529 m_iFlags |= wxPG_FL_SCROLLED;
1530 changed = true;
1531 }
1532 else if ( (y+m_lineHeight) > (vy+m_height) )
1533 {
1534 Scroll(vx, (y-m_height+(m_lineHeight*2))/wxPG_PIXELS_PER_UNIT );
1535 m_iFlags |= wxPG_FL_SCROLLED;
1536 changed = true;
1537 }
1538
1539 if ( changed )
1540 DrawItems( p, p );
1541
1542 return changed;
1543}
1544
1545// -----------------------------------------------------------------------
1546// wxPropertyGrid helper methods called by properties
1547// -----------------------------------------------------------------------
1548
1549// Control font changer helper.
1550void wxPropertyGrid::SetCurControlBoldFont()
1551{
1552 wxASSERT( m_wndEditor );
1553 m_wndEditor->SetFont( m_captionFont );
1554}
1555
1556// -----------------------------------------------------------------------
1557
1558wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p,
1559 const wxSize& sz )
1560{
1561#if wxPG_SMALL_SCREEN
1562 // On small-screen devices, always show dialogs with default position and size.
1563 return wxDefaultPosition;
1564#else
1565 int splitterX = GetSplitterPosition();
1566 int x = splitterX;
1567 int y = p->GetY();
1568
1569 wxCHECK_MSG( y >= 0, wxPoint(-1,-1), wxT("invalid y?") );
1570
1571 ImprovedClientToScreen( &x, &y );
1572
1573 int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X );
1574 int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y );
1575
1576 int new_x;
1577 int new_y;
1578
1579 if ( x > (sw/2) )
1580 // left
1581 new_x = x + (m_width-splitterX) - sz.x;
1582 else
1583 // right
1584 new_x = x;
1585
1586 if ( y > (sh/2) )
1587 // above
1588 new_y = y - sz.y;
1589 else
1590 // below
1591 new_y = y + m_lineHeight;
1592
1593 return wxPoint(new_x,new_y);
1594#endif
1595}
1596
1597// -----------------------------------------------------------------------
1598
1599wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, wxString& src_str )
1600{
1601 if ( src_str.length() == 0 )
1602 {
1603 dst_str = src_str;
1604 return src_str;
1605 }
1606
1607 bool prev_is_slash = false;
1608
1609 wxString::const_iterator i = src_str.begin();
1610
1611 dst_str.clear();
1612
b7bc9d80 1613 for ( ; i != src_str.end(); ++i )
1c4293cb
VZ
1614 {
1615 wxUniChar a = *i;
1616
1617 if ( a != wxS('\\') )
1618 {
1619 if ( !prev_is_slash )
1620 {
1621 dst_str << a;
1622 }
1623 else
1624 {
1625 if ( a == wxS('n') )
1626 {
1627 #ifdef __WXMSW__
1628 dst_str << wxS('\n');
1629 #else
1630 dst_str << wxS('\n');
1631 #endif
1632 }
1633 else if ( a == wxS('t') )
1634 dst_str << wxS('\t');
1635 else
1636 dst_str << a;
1637 }
1638 prev_is_slash = false;
1639 }
1640 else
1641 {
1642 if ( prev_is_slash )
1643 {
1644 dst_str << wxS('\\');
1645 prev_is_slash = false;
1646 }
1647 else
1648 {
1649 prev_is_slash = true;
1650 }
1651 }
1652 }
1653 return dst_str;
1654}
1655
1656// -----------------------------------------------------------------------
1657
1658wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, wxString& src_str )
1659{
1660 if ( src_str.length() == 0 )
1661 {
1662 dst_str = src_str;
1663 return src_str;
1664 }
1665
1666 wxString::const_iterator i = src_str.begin();
1667 wxUniChar prev_a = wxS('\0');
1668
1669 dst_str.clear();
1670
b7bc9d80 1671 for ( ; i != src_str.end(); ++i )
1c4293cb
VZ
1672 {
1673 wxChar a = *i;
1674
1675 if ( a >= wxS(' ') )
1676 {
1677 // This surely is not something that requires an escape sequence.
1678 dst_str << a;
1679 }
1680 else
1681 {
1682 // This might need...
1683 if ( a == wxS('\r') )
1684 {
1685 // DOS style line end.
1686 // Already taken care below
1687 }
1688 else if ( a == wxS('\n') )
1689 // UNIX style line end.
1690 dst_str << wxS("\\n");
1691 else if ( a == wxS('\t') )
1692 // Tab.
1693 dst_str << wxS('\t');
1694 else
1695 {
1696 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1697 dst_str << a;
1698 }
1699 }
1700
1701 prev_a = a;
1702 }
1703 return dst_str;
1704}
1705
1706// -----------------------------------------------------------------------
1707
1708wxPGProperty* wxPropertyGrid::DoGetItemAtY( int y ) const
1709{
1710 // Outside?
1711 if ( y < 0 )
d3b9f782 1712 return NULL;
1c4293cb
VZ
1713
1714 unsigned int a = 0;
1715 return m_pState->m_properties->GetItemAtY(y, m_lineHeight, &a);
1716}
1717
1718// -----------------------------------------------------------------------
1719// wxPropertyGrid graphics related methods
1720// -----------------------------------------------------------------------
1721
1722void wxPropertyGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
1723{
1724 wxPaintDC dc(this);
39e4e221
JS
1725 PrepareDC(dc);
1726
1727 // Don't paint after destruction has begun
1728 if ( !HasInternalFlag(wxPG_FL_INITIALIZED) )
1729 return;
1730
1731 // Find out where the window is scrolled to
1732 int vx,vy; // Top left corner of client
1733 GetViewStart(&vx,&vy);
1734 vy *= wxPG_PIXELS_PER_UNIT;
1c4293cb
VZ
1735
1736 // Update everything inside the box
1737 wxRect r = GetUpdateRegion().GetBox();
1738
39e4e221
JS
1739 r.y += vy;
1740
1741 // FIXME: This is just a workaround for a bug that causes splitters not
1742 // to paint when other windows are being dragged over the grid.
1743 wxRect fullRect = GetRect();
1744 r.x = fullRect.x;
1745 r.width = fullRect.width;
1746
1747 // Repaint this rectangle
1748 DrawItems( dc, r.y, r.y + r.height, &r );
1749
1750 // We assume that the size set when grid is shown
1751 // is what is desired.
1752 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET);
1c4293cb
VZ
1753}
1754
1755// -----------------------------------------------------------------------
1756
1757void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect,
1758 wxPGProperty* property ) const
1759{
1760 // Prepare rectangle to be used
1761 wxRect r(rect);
1762 r.x += m_gutterWidth; r.y += m_buttonSpacingY;
1763 r.width = m_iconWidth; r.height = m_iconHeight;
1764
1765#if (wxPG_USE_RENDERER_NATIVE)
1766 //
1767#elif wxPG_ICON_WIDTH
1768 // Drawing expand/collapse button manually
1769 dc.SetPen(m_colPropFore);
1770 if ( property->IsCategory() )
1771 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1772 else
1773 dc.SetBrush(m_colPropBack);
1774
1775 dc.DrawRectangle( r );
1776 int _y = r.y+(m_iconWidth/2);
1777 dc.DrawLine(r.x+2,_y,r.x+m_iconWidth-2,_y);
1778#else
1779 wxBitmap* bmp;
1780#endif
1781
1782 if ( property->IsExpanded() )
1783 {
1784 // wxRenderer functions are non-mutating in nature, so it
1785 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1786 // Hopefully this does not cause problems.
1787 #if (wxPG_USE_RENDERER_NATIVE)
1788 wxRendererNative::Get().DrawTreeItemButton(
1789 (wxWindow*)this,
1790 dc,
1791 r,
1792 wxCONTROL_EXPANDED
1793 );
1794 #elif wxPG_ICON_WIDTH
1795 //
1796 #else
1797 bmp = m_collbmp;
1798 #endif
1799
1800 }
1801 else
1802 {
1803 #if (wxPG_USE_RENDERER_NATIVE)
1804 wxRendererNative::Get().DrawTreeItemButton(
1805 (wxWindow*)this,
1806 dc,
1807 r,
1808 0
1809 );
1810 #elif wxPG_ICON_WIDTH
1811 int _x = r.x+(m_iconWidth/2);
1812 dc.DrawLine(_x,r.y+2,_x,r.y+m_iconWidth-2);
1813 #else
1814 bmp = m_expandbmp;
1815 #endif
1816 }
1817
1818#if (wxPG_USE_RENDERER_NATIVE)
1819 //
1820#elif wxPG_ICON_WIDTH
1821 //
1822#else
1823 dc.DrawBitmap( *bmp, r.x, r.y, true );
1824#endif
1825}
1826
1827// -----------------------------------------------------------------------
1828
1829//
1830// This is the one called by OnPaint event handler and others.
1831// topy and bottomy are already unscrolled (ie. physical)
1832//
1833void wxPropertyGrid::DrawItems( wxDC& dc,
b5e184c6
JS
1834 unsigned int topItemY,
1835 unsigned int bottomItemY,
0b6a0a72 1836 const wxRect* drawRect )
1c4293cb 1837{
b5e184c6
JS
1838 if ( m_frozen ||
1839 m_height < 1 ||
1840 bottomItemY < topItemY ||
1841 !m_pState )
39e4e221 1842 return;
1c4293cb
VZ
1843
1844 m_pState->EnsureVirtualHeight();
1845
0b6a0a72
JS
1846 wxRect tempDrawRect;
1847 if ( !drawRect )
1c4293cb 1848 {
b5e184c6 1849 tempDrawRect = wxRect(0, topItemY,
0b6a0a72 1850 m_pState->m_width,
b5e184c6 1851 bottomItemY);
0b6a0a72 1852 drawRect = &tempDrawRect;
1c4293cb
VZ
1853 }
1854
1855 // items added check
1856 if ( m_pState->m_itemsAdded ) PrepareAfterItemsAdded();
1857
1858 int paintFinishY = 0;
1859
1860 if ( m_pState->m_properties->GetChildCount() > 0 )
1861 {
1862 wxDC* dcPtr = &dc;
1863 bool isBuffered = false;
1864
1865 #if wxPG_DOUBLE_BUFFER
1866 wxMemoryDC* bufferDC = NULL;
1867
1868 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) )
1869 {
1870 if ( !m_doubleBuffer )
1871 {
0b6a0a72 1872 paintFinishY = drawRect->y;
1c4293cb
VZ
1873 dcPtr = NULL;
1874 }
1875 else
1876 {
1877 bufferDC = new wxMemoryDC();
1878
1879 // If nothing was changed, then just copy from double-buffer
1880 bufferDC->SelectObject( *m_doubleBuffer );
1881 dcPtr = bufferDC;
1882
1883 isBuffered = true;
1884 }
1885 }
1886 #endif
1887
1888 if ( dcPtr )
1889 {
0b6a0a72
JS
1890 dc.SetClippingRegion( *drawRect );
1891 paintFinishY = DoDrawItems( *dcPtr, drawRect, isBuffered );
1892 int drawBottomY = drawRect->y + drawRect->height;
39e4e221 1893
b5e184c6 1894 // Clear area beyond last painted property
0b6a0a72 1895 if ( paintFinishY < drawBottomY )
39e4e221
JS
1896 {
1897 dcPtr->SetPen(m_colEmptySpace);
1898 dcPtr->SetBrush(m_colEmptySpace);
0b6a0a72
JS
1899 dcPtr->DrawRectangle(0, paintFinishY,
1900 m_width,
1901 drawBottomY );
39e4e221 1902 }
0b6a0a72
JS
1903
1904 dc.DestroyClippingRegion();
1c4293cb
VZ
1905 }
1906
1907 #if wxPG_DOUBLE_BUFFER
1908 if ( bufferDC )
1909 {
0b6a0a72
JS
1910 dc.Blit( drawRect->x, drawRect->y, drawRect->width,
1911 drawRect->height,
39e4e221 1912 bufferDC, 0, 0, wxCOPY );
1c4293cb
VZ
1913 delete bufferDC;
1914 }
1915 #endif
1916 }
39e4e221 1917 else
1c4293cb 1918 {
39e4e221 1919 // Just clear the area
1c4293cb
VZ
1920 dc.SetPen(m_colEmptySpace);
1921 dc.SetBrush(m_colEmptySpace);
0b6a0a72 1922 dc.DrawRectangle(*drawRect);
1c4293cb
VZ
1923 }
1924}
1925
1926// -----------------------------------------------------------------------
1927
1928int wxPropertyGrid::DoDrawItems( wxDC& dc,
b5e184c6 1929 const wxRect* drawRect,
1c4293cb
VZ
1930 bool isBuffered ) const
1931{
bcf324be
JS
1932 const wxPGProperty* firstItem;
1933 const wxPGProperty* lastItem;
1c4293cb 1934
b5e184c6
JS
1935 firstItem = DoGetItemAtY(drawRect->y);
1936 lastItem = DoGetItemAtY(drawRect->y+drawRect->height-1);
1c4293cb
VZ
1937
1938 if ( !lastItem )
bcf324be 1939 lastItem = GetLastItem( wxPG_ITERATE_VISIBLE );
1c4293cb
VZ
1940
1941 if ( m_frozen || m_height < 1 || firstItem == NULL )
b5e184c6 1942 return drawRect->y;
1c4293cb 1943
b5e184c6
JS
1944 wxCHECK_MSG( !m_pState->m_itemsAdded, drawRect->y,
1945 "no items added" );
1c4293cb
VZ
1946 wxASSERT( m_pState->m_properties->GetChildCount() );
1947
1948 int lh = m_lineHeight;
1949
1950 int firstItemTopY;
1951 int lastItemBottomY;
1952
b5e184c6
JS
1953 firstItemTopY = drawRect->y;
1954 lastItemBottomY = drawRect->y + drawRect->height;
1c4293cb
VZ
1955
1956 // Align y coordinates to item boundaries
1957 firstItemTopY -= firstItemTopY % lh;
1958 lastItemBottomY += lh - (lastItemBottomY % lh);
1959 lastItemBottomY -= 1;
1960
1961 // Entire range outside scrolled, visible area?
b5e184c6
JS
1962 if ( firstItemTopY >= (int)m_pState->GetVirtualHeight() ||
1963 lastItemBottomY <= 0 )
1964 return drawRect->y;
1c4293cb 1965
b5e184c6
JS
1966 wxCHECK_MSG( firstItemTopY < lastItemBottomY,
1967 drawRect->y,
1968 "invalid y values" );
1c4293cb
VZ
1969
1970 /*
b5e184c6
JS
1971 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
1972 "height=%i (ch=%i), drawRect = 0x%lX )",
1c4293cb
VZ
1973 firstItem->GetLabel().c_str(),
1974 lastItem->GetLabel().c_str(),
1975 (int)(lastItemBottomY - firstItemTopY),
1976 (int)m_height,
b5e184c6 1977 (unsigned long)drawRect );
1c4293cb
VZ
1978 */
1979
1980 wxRect r;
1981
1982 long windowStyle = m_windowStyle;
1983
1984 int xRelMod = 0;
1985 int yRelMod = 0;
1986
1987 //
1988 // With wxPG_DOUBLE_BUFFER, do double buffering
b5e184c6 1989 // - buffer's y = 0, so align drawRect and coordinates to that
1c4293cb
VZ
1990 //
1991#if wxPG_DOUBLE_BUFFER
1992
1993 wxRect cr2;
1994
1995 if ( isBuffered )
1996 {
b5e184c6
JS
1997 xRelMod = drawRect->x;
1998 yRelMod = drawRect->y;
1c4293cb
VZ
1999
2000 //
b5e184c6
JS
2001 // drawRect conversion
2002 cr2 = *drawRect;
b7bc9d80
PC
2003 cr2.x -= xRelMod;
2004 cr2.y -= yRelMod;
b5e184c6 2005 drawRect = &cr2;
1c4293cb
VZ
2006 firstItemTopY -= yRelMod;
2007 lastItemBottomY -= yRelMod;
2008 }
2009#else
2010 wxUnusedVar(isBuffered);
2011#endif
2012
2013 int x = m_marginWidth - xRelMod;
2014
2197ec80 2015 wxFont normalFont = GetFont();
1c4293cb 2016
b7bc9d80 2017 bool reallyFocused = (m_iFlags & wxPG_FL_FOCUSED) != 0;
1c4293cb 2018
fc72fab6 2019 bool isPgEnabled = IsEnabled();
1c4293cb
VZ
2020
2021 //
2022 // Prepare some pens and brushes that are often changed to.
2023 //
2024
2025 wxBrush marginBrush(m_colMargin);
2026 wxPen marginPen(m_colMargin);
2027 wxBrush capbgbrush(m_colCapBack,wxSOLID);
2028 wxPen linepen(m_colLine,1,wxSOLID);
2029
fc72fab6
JS
2030 wxColour selBackCol;
2031 if ( isPgEnabled )
2032 selBackCol = m_colSelBack;
2033 else
2034 selBackCol = m_colMargin;
2035
1c4293cb
VZ
2036 // pen that has same colour as text
2037 wxPen outlinepen(m_colPropFore,1,wxSOLID);
2038
2039 //
2040 // Clear margin with background colour
2041 //
2042 dc.SetBrush( marginBrush );
2043 if ( !(windowStyle & wxPG_HIDE_MARGIN) )
2044 {
2045 dc.SetPen( *wxTRANSPARENT_PEN );
2046 dc.DrawRectangle(-1-xRelMod,firstItemTopY-1,x+2,lastItemBottomY-firstItemTopY+2);
2047 }
2048
fc72fab6 2049 const wxPGProperty* firstSelected = GetSelection();
1c4293cb
VZ
2050 const wxPropertyGridPageState* state = m_pState;
2051
2052#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2053 bool wasSelectedPainted = false;
2054#endif
2055
2056 // TODO: Only render columns that are within clipping region.
2057
2197ec80 2058 dc.SetFont(normalFont);
1c4293cb
VZ
2059
2060 wxPropertyGridConstIterator it( state, wxPG_ITERATE_VISIBLE, firstItem );
2061 int endScanBottomY = lastItemBottomY + lh;
2062 int y = firstItemTopY;
23b4f320
JS
2063
2064 //
2065 // Pregenerate list of visible properties.
2066 wxArrayPGProperty visPropArray;
2067 visPropArray.reserve((m_height/m_lineHeight)+6);
1c4293cb
VZ
2068
2069 for ( ; !it.AtEnd(); it.Next() )
2070 {
2071 const wxPGProperty* p = *it;
2072
2073 if ( !p->HasFlag(wxPG_PROP_HIDDEN) )
2074 {
23b4f320 2075 visPropArray.push_back((wxPGProperty*)p);
1c4293cb
VZ
2076
2077 if ( y > endScanBottomY )
2078 break;
2079
2080 y += lh;
2081 }
2082 }
2083
23b4f320
JS
2084 visPropArray.push_back(NULL);
2085
2086 wxPGProperty* nextP = visPropArray[0];
1c4293cb
VZ
2087
2088 int gridWidth = state->m_width;
2089
2090 y = firstItemTopY;
23b4f320
JS
2091 for ( unsigned int arrInd=1;
2092 nextP && y <= lastItemBottomY;
1c4293cb
VZ
2093 arrInd++ )
2094 {
23b4f320
JS
2095 wxPGProperty* p = nextP;
2096 nextP = visPropArray[arrInd];
1c4293cb
VZ
2097
2098 int rowHeight = m_fontHeight+(m_spacingy*2)+1;
2099 int textMarginHere = x;
d7e2b522 2100 int renderFlags = 0;
1c4293cb
VZ
2101
2102 int greyDepth = m_marginWidth;
2103 if ( !(windowStyle & wxPG_HIDE_CATEGORIES) )
2104 greyDepth = (((int)p->m_depthBgCol)-1) * m_subgroup_extramargin + m_marginWidth;
2105
2106 int greyDepthX = greyDepth - xRelMod;
2107
2108 // Use basic depth if in non-categoric mode and parent is base array.
2109 if ( !(windowStyle & wxPG_HIDE_CATEGORIES) || p->GetParent() != m_pState->m_properties )
2110 {
2111 textMarginHere += ((unsigned int)((p->m_depth-1)*m_subgroup_extramargin));
2112 }
2113
2114 // Paint margin area
2115 dc.SetBrush(marginBrush);
2116 dc.SetPen(marginPen);
2117 dc.DrawRectangle( -xRelMod, y, greyDepth, lh );
2118
2119 dc.SetPen( linepen );
2120
2121 int y2 = y + lh;
2122
521f1d83 2123#ifdef __WXMSW__
1c4293cb 2124 // Margin Edge
521f1d83
JS
2125 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2126 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2127 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2128
2129 // Is this or its parent themed?
2130 bool suppressMarginEdge = (GetWindowStyle() & wxPG_HIDE_MARGIN) &&
2131 (((GetWindowStyle() & wxBORDER_MASK) == wxBORDER_THEME) ||
2132 (((GetWindowStyle() & wxBORDER_MASK) == wxBORDER_NONE) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK) == wxBORDER_THEME)));
2133#else
2134 bool suppressMarginEdge = false;
2135#endif
2136 if (!suppressMarginEdge)
2137 dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
2138 else
2139 {
2140 // Blank out the margin edge
2141 dc.SetPen(wxPen(GetBackgroundColour()));
2142 dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
2143 dc.SetPen( linepen );
2144 }
1c4293cb
VZ
2145
2146 // Splitters
2147 unsigned int si;
2148 int sx = x;
2149
2150 for ( si=0; si<state->m_colWidths.size(); si++ )
2151 {
2152 sx += state->m_colWidths[si];
2153 dc.DrawLine( sx, y, sx, y2 );
2154 }
2155
2156 // Horizontal Line, below
2157 // (not if both this and next is category caption)
2158 if ( p->IsCategory() &&
2159 nextP && nextP->IsCategory() )
2160 dc.SetPen(m_colCapBack);
2161
2162 dc.DrawLine( greyDepthX, y2-1, gridWidth-xRelMod, y2-1 );
2163
d7e2b522
JS
2164 //
2165 // Need to override row colours?
1c4293cb 2166 wxColour rowFgCol;
d7e2b522 2167 wxColour rowBgCol;
1c4293cb 2168
fc72fab6
JS
2169 bool isSelected = state->DoIsPropertySelected(p);
2170
2171 if ( !isSelected )
1c4293cb
VZ
2172 {
2173 // Disabled may get different colour.
2174 if ( !p->IsEnabled() )
d7e2b522
JS
2175 {
2176 renderFlags |= wxPGCellRenderer::Disabled |
2177 wxPGCellRenderer::DontUseCellFgCol;
1c4293cb 2178 rowFgCol = m_colDisPropFore;
d7e2b522 2179 }
1c4293cb
VZ
2180 }
2181 else
2182 {
fc72fab6
JS
2183#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2184 if ( p == firstSelected )
2185 wasSelectedPainted = true;
2186#endif
2187
b7bc9d80 2188 renderFlags |= wxPGCellRenderer::Selected;
d7e2b522 2189
b7bc9d80
PC
2190 if ( !p->IsCategory() )
2191 {
d7e2b522
JS
2192 renderFlags |= wxPGCellRenderer::DontUseCellFgCol |
2193 wxPGCellRenderer::DontUseCellBgCol;
2194
fc72fab6 2195 if ( reallyFocused && p == firstSelected )
d7e2b522
JS
2196 {
2197 rowFgCol = m_colSelFore;
fc72fab6 2198 rowBgCol = selBackCol;
d7e2b522 2199 }
fc72fab6 2200 else if ( isPgEnabled )
d7e2b522
JS
2201 {
2202 rowFgCol = m_colPropFore;
fc72fab6
JS
2203 if ( p == firstSelected )
2204 rowBgCol = m_colMargin;
2205 else
2206 rowBgCol = selBackCol;
d7e2b522
JS
2207 }
2208 else
2209 {
2210 rowFgCol = m_colDisPropFore;
fc72fab6 2211 rowBgCol = selBackCol;
d7e2b522 2212 }
1c4293cb 2213 }
d7e2b522
JS
2214 }
2215
2216 wxBrush rowBgBrush;
2217
2218 if ( rowBgCol.IsOk() )
2219 rowBgBrush = wxBrush(rowBgCol);
2220
2221 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL) )
2222 renderFlags = renderFlags & ~wxPGCellRenderer::DontUseCellColours;
2223
2224 //
2225 // Fill additional margin area with background colour of first cell
2226 if ( greyDepthX < textMarginHere )
2227 {
2228 if ( !(renderFlags & wxPGCellRenderer::DontUseCellBgCol) )
1c4293cb 2229 {
d7e2b522
JS
2230 wxPGCell& cell = p->GetCell(0);
2231 rowBgCol = cell.GetBgCol();
2232 rowBgBrush = wxBrush(rowBgCol);
1c4293cb 2233 }
d7e2b522
JS
2234 dc.SetBrush(rowBgBrush);
2235 dc.SetPen(rowBgCol);
2236 dc.DrawRectangle(greyDepthX+1, y,
2237 textMarginHere-greyDepthX, lh-1);
1c4293cb
VZ
2238 }
2239
2240 bool fontChanged = false;
2241
d7e2b522 2242 // Expander button rectangle
1c4293cb
VZ
2243 wxRect butRect( ((p->m_depth - 1) * m_subgroup_extramargin) - xRelMod,
2244 y,
2245 m_marginWidth,
2246 lh );
2247
2248 if ( p->IsCategory() )
2249 {
d7e2b522 2250 // Captions have their cell areas merged as one
1c4293cb
VZ
2251 dc.SetFont(m_captionFont);
2252 fontChanged = true;
2253 wxRect cellRect(greyDepthX, y, gridWidth - greyDepth + 2, rowHeight-1 );
2254
d7e2b522
JS
2255 if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
2256 {
2257 dc.SetBrush(rowBgBrush);
2258 dc.SetPen(rowBgCol);
2259 }
1c4293cb 2260
d7e2b522
JS
2261 if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol )
2262 {
2263 dc.SetTextForeground(rowFgCol);
2264 }
1c4293cb 2265
1c4293cb
VZ
2266 wxPGCellRenderer* renderer = p->GetCellRenderer(0);
2267 renderer->Render( dc, cellRect, this, p, 0, -1, renderFlags );
2268
2269 // Tree Item Button
2270 if ( !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
2271 DrawExpanderButton( dc, butRect, p );
2272 }
2273 else
2274 {
2275 if ( p->m_flags & wxPG_PROP_MODIFIED && (windowStyle & wxPG_BOLD_MODIFIED) )
2276 {
2277 dc.SetFont(m_captionFont);
2278 fontChanged = true;
2279 }
2280
2281 unsigned int ci;
2282 int cellX = x + 1;
9667d393
JS
2283 int nextCellWidth = state->m_colWidths[0] -
2284 (greyDepthX - m_marginWidth);
1c4293cb
VZ
2285 wxRect cellRect(greyDepthX+1, y, 0, rowHeight-1);
2286 int textXAdd = textMarginHere - greyDepthX;
2287
2288 for ( ci=0; ci<state->m_colWidths.size(); ci++ )
2289 {
2290 cellRect.width = nextCellWidth - 1;
2291
58935d4a 2292 wxWindow* cellEditor = NULL;
d7e2b522
JS
2293 int cellRenderFlags = renderFlags;
2294
58935d4a 2295 // Tree Item Button (must be drawn before clipping is set up)
d7e2b522
JS
2296 if ( ci == 0 && !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
2297 DrawExpanderButton( dc, butRect, p );
1c4293cb
VZ
2298
2299 // Background
58935d4a 2300 if ( isSelected && (ci == 1 || ci == m_selColumn) )
1c4293cb 2301 {
58935d4a
JS
2302 if ( p == firstSelected )
2303 {
2304 if ( ci == 1 && m_wndEditor )
2305 cellEditor = m_wndEditor;
2306 else if ( ci == m_selColumn && m_labelEditor )
2307 cellEditor = m_labelEditor;
2308 }
2309
2310 if ( cellEditor )
fc72fab6
JS
2311 {
2312 wxColour editorBgCol =
58935d4a 2313 cellEditor->GetBackgroundColour();
fc72fab6
JS
2314 dc.SetBrush(editorBgCol);
2315 dc.SetPen(editorBgCol);
2316 dc.SetTextForeground(m_colPropFore);
2317 dc.DrawRectangle(cellRect);
2318
58935d4a
JS
2319 if ( m_dragStatus != 0 ||
2320 (m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE) )
2321 cellEditor = NULL;
fc72fab6
JS
2322 }
2323 else
2324 {
2325 dc.SetBrush(m_colPropBack);
2326 dc.SetPen(m_colPropBack);
2327 dc.SetTextForeground(m_colDisPropFore);
2328 if ( p->IsEnabled() )
2329 dc.SetTextForeground(rowFgCol);
2330 else
2331 dc.SetTextForeground(m_colDisPropFore);
2332 }
1c4293cb
VZ
2333 }
2334 else
2335 {
d7e2b522
JS
2336 if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
2337 {
2338 dc.SetBrush(rowBgBrush);
2339 dc.SetPen(rowBgCol);
2340 }
1c4293cb 2341
d7e2b522
JS
2342 if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol )
2343 {
2344 dc.SetTextForeground(rowFgCol);
2345 }
2346 }
1c4293cb
VZ
2347
2348 dc.SetClippingRegion(cellRect);
2349
2350 cellRect.x += textXAdd;
2351 cellRect.width -= textXAdd;
2352
2353 // Foreground
58935d4a 2354 if ( !cellEditor )
1c4293cb
VZ
2355 {
2356 wxPGCellRenderer* renderer;
2357 int cmnVal = p->GetCommonValue();
2358 if ( cmnVal == -1 || ci != 1 )
2359 {
2360 renderer = p->GetCellRenderer(ci);
d7e2b522
JS
2361 renderer->Render( dc, cellRect, this, p, ci, -1,
2362 cellRenderFlags );
1c4293cb
VZ
2363 }
2364 else
2365 {
2366 renderer = GetCommonValue(cmnVal)->GetRenderer();
d7e2b522
JS
2367 renderer->Render( dc, cellRect, this, p, ci, -1,
2368 cellRenderFlags );
1c4293cb
VZ
2369 }
2370 }
2371
2372 cellX += state->m_colWidths[ci];
2373 if ( ci < (state->m_colWidths.size()-1) )
2374 nextCellWidth = state->m_colWidths[ci+1];
23318a53 2375 cellRect.x = cellX;
1c4293cb
VZ
2376 dc.DestroyClippingRegion(); // Is this really necessary?
2377 textXAdd = 0;
2378 }
2379 }
2380
2381 if ( fontChanged )
2197ec80 2382 dc.SetFont(normalFont);
1c4293cb
VZ
2383
2384 y += rowHeight;
2385 }
2386
2387 // Refresh editor controls (seems not needed on msw)
2388 // NOTE: This code is mandatory for GTK!
2389#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2390 if ( wasSelectedPainted )
2391 {
2392 if ( m_wndEditor )
2393 m_wndEditor->Refresh();
2394 if ( m_wndEditor2 )
2395 m_wndEditor2->Refresh();
2396 }
2397#endif
2398
0b6a0a72 2399 return y;
1c4293cb
VZ
2400}
2401
2402// -----------------------------------------------------------------------
2403
2404wxRect wxPropertyGrid::GetPropertyRect( const wxPGProperty* p1, const wxPGProperty* p2 ) const
2405{
2406 wxRect r;
2407
2408 if ( m_width < 10 || m_height < 10 ||
2409 !m_pState->m_properties->GetChildCount() ||
d3b9f782 2410 p1 == NULL )
1c4293cb
VZ
2411 return wxRect(0,0,0,0);
2412
2413 int vy = 0;
2414
2415 //
2416 // Return rect which encloses the given property range
2417
2418 int visTop = p1->GetY();
2419 int visBottom;
2420 if ( p2 )
2421 visBottom = p2->GetY() + m_lineHeight;
2422 else
2423 visBottom = m_height + visTop;
2424
2425 // If seleced property is inside the range, we'll extend the range to include
2426 // control's size.
fc72fab6 2427 wxPGProperty* selected = GetSelection();
1c4293cb
VZ
2428 if ( selected )
2429 {
2430 int selectedY = selected->GetY();
2431 if ( selectedY >= visTop && selectedY < visBottom )
2432 {
2433 wxWindow* editor = GetEditorControl();
2434 if ( editor )
2435 {
2436 int visBottom2 = selectedY + editor->GetSize().y;
2437 if ( visBottom2 > visBottom )
2438 visBottom = visBottom2;
2439 }
2440 }
2441 }
2442
2443 return wxRect(0,visTop-vy,m_pState->m_width,visBottom-visTop);
2444}
2445
2446// -----------------------------------------------------------------------
2447
2448void wxPropertyGrid::DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 )
2449{
2450 if ( m_frozen )
2451 return;
2452
2453 if ( m_pState->m_itemsAdded )
2454 PrepareAfterItemsAdded();
2455
2456 wxRect r = GetPropertyRect(p1, p2);
2457 if ( r.width > 0 )
2458 {
39e4e221 2459 RefreshRect(r);
1c4293cb
VZ
2460 }
2461}
2462
2463// -----------------------------------------------------------------------
2464
2465void wxPropertyGrid::RefreshProperty( wxPGProperty* p )
2466{
fc72fab6
JS
2467 if ( m_pState->DoIsPropertySelected(p) )
2468 {
2469 // NB: We must copy the selection.
2470 wxArrayPGProperty selection = m_pState->m_selection;
2471 DoSetSelection(selection, wxPG_SEL_FORCE);
2472 }
1c4293cb
VZ
2473
2474 DrawItemAndChildren(p);
2475}
2476
2477// -----------------------------------------------------------------------
2478
2479void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty* p )
2480{
2481 if ( m_frozen )
2482 return;
2483
2484 // Draw item, children, and parent too, if it is not category
2485 wxPGProperty* parent = p->GetParent();
2486
2487 while ( parent &&
2488 !parent->IsCategory() &&
2489 parent->GetParent() )
2490 {
2491 DrawItem(parent);
2492 parent = parent->GetParent();
2493 }
2494
2495 DrawItemAndChildren(p);
2496}
2497
2498void wxPropertyGrid::DrawItemAndChildren( wxPGProperty* p )
2499{
2500 wxCHECK_RET( p, wxT("invalid property id") );
2501
2502 // Do not draw if in non-visible page
2503 if ( p->GetParentState() != m_pState )
2504 return;
2505
2506 // do not draw a single item if multiple pending
2507 if ( m_pState->m_itemsAdded || m_frozen )
2508 return;
2509
1c4293cb 2510 // Update child control.
fc72fab6
JS
2511 wxPGProperty* selected = GetSelection();
2512 if ( selected && selected->GetParent() == p )
a6353fe8 2513 RefreshEditor();
1c4293cb
VZ
2514
2515 const wxPGProperty* lastDrawn = p->GetLastVisibleSubItem();
2516
2517 DrawItems(p, lastDrawn);
2518}
2519
2520// -----------------------------------------------------------------------
2521
2522void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground),
2523 const wxRect *rect )
2524{
2525 PrepareAfterItemsAdded();
2526
39e4e221 2527 wxWindow::Refresh(false, rect);
1c4293cb
VZ
2528
2529#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2530 // I think this really helps only GTK+1.2
2531 if ( m_wndEditor ) m_wndEditor->Refresh();
2532 if ( m_wndEditor2 ) m_wndEditor2->Refresh();
2533#endif
2534}
2535
2536// -----------------------------------------------------------------------
2537// wxPropertyGrid global operations
2538// -----------------------------------------------------------------------
2539
2540void wxPropertyGrid::Clear()
2541{
1c4293cb
VZ
2542 m_pState->DoClear();
2543
2544 m_propHover = NULL;
2545
2546 m_prevVY = 0;
2547
2548 RecalculateVirtualSize();
2549
2550 // Need to clear some area at the end
2551 if ( !m_frozen )
2552 RefreshRect(wxRect(0, 0, m_width, m_height));
2553}
2554
2555// -----------------------------------------------------------------------
2556
2557bool wxPropertyGrid::EnableCategories( bool enable )
2558{
01b5ad3b 2559 DoClearSelection();
1c4293cb
VZ
2560
2561 if ( enable )
2562 {
2563 //
2564 // Enable categories
2565 //
2566
2567 m_windowStyle &= ~(wxPG_HIDE_CATEGORIES);
2568 }
2569 else
2570 {
2571 //
2572 // Disable categories
2573 //
2574 m_windowStyle |= wxPG_HIDE_CATEGORIES;
2575 }
2576
2577 if ( !m_pState->EnableCategories(enable) )
2578 return false;
2579
2580 if ( !m_frozen )
2581 {
2582 if ( m_windowStyle & wxPG_AUTO_SORT )
2583 {
2584 m_pState->m_itemsAdded = 1; // force
2585 PrepareAfterItemsAdded();
2586 }
2587 }
2588 else
2589 m_pState->m_itemsAdded = 1;
2590
2591 // No need for RecalculateVirtualSize() here - it is already called in
2592 // wxPropertyGridPageState method above.
2593
2594 Refresh();
2595
2596 return true;
2597}
2598
2599// -----------------------------------------------------------------------
2600
2601void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState )
2602{
2603 wxASSERT( pNewState );
2604 wxASSERT( pNewState->GetGrid() );
2605
2606 if ( pNewState == m_pState )
2607 return;
2608
fc72fab6 2609 wxArrayPGProperty oldSelection = m_pState->m_selection;
1c4293cb 2610
fc72fab6
JS
2611 // Call ClearSelection() instead of DoClearSelection()
2612 // so that selection clear events are not sent.
2613 ClearSelection();
1c4293cb 2614
fc72fab6 2615 m_pState->m_selection = oldSelection;
1c4293cb
VZ
2616
2617 bool orig_mode = m_pState->IsInNonCatMode();
2618 bool new_state_mode = pNewState->IsInNonCatMode();
2619
2620 m_pState = pNewState;
2621
2622 // Validate width
2623 int pgWidth = GetClientSize().x;
2624 if ( HasVirtualWidth() )
2625 {
2626 int minWidth = pgWidth;
2627 if ( pNewState->m_width < minWidth )
2628 {
2629 pNewState->m_width = minWidth;
2630 pNewState->CheckColumnWidths();
2631 }
2632 }
2633 else
2634 {
2635 //
2636 // Just in case, fully re-center splitter
0da1f1c4
JS
2637 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2638 // pNewState->m_fSplitterX = -1.0;
1c4293cb 2639
0da1f1c4
JS
2640 pNewState->OnClientWidthChange(pgWidth,
2641 pgWidth - pNewState->m_width);
1c4293cb
VZ
2642 }
2643
d3b9f782 2644 m_propHover = NULL;
1c4293cb
VZ
2645
2646 // If necessary, convert state to correct mode.
2647 if ( orig_mode != new_state_mode )
2648 {
2649 // This should refresh as well.
2650 EnableCategories( orig_mode?false:true );
2651 }
2652 else if ( !m_frozen )
2653 {
2654 // Refresh, if not frozen.
0eb877f2 2655 m_pState->PrepareAfterItemsAdded();
1c4293cb 2656
fc72fab6
JS
2657 // Reselect (Use SetSelection() instead of Do-variant so that
2658 // events won't be sent).
2659 SetSelection(m_pState->m_selection);
1c4293cb
VZ
2660
2661 RecalculateVirtualSize(0);
2662 Refresh();
2663 }
2664 else
2665 m_pState->m_itemsAdded = 1;
2666}
2667
2668// -----------------------------------------------------------------------
2669
1c4293cb
VZ
2670// Call to SetSplitterPosition will always disable splitter auto-centering
2671// if parent window is shown.
0da1f1c4
JS
2672void wxPropertyGrid::DoSetSplitterPosition_( int newxpos, bool refresh,
2673 int splitterIndex,
2674 bool allPages )
1c4293cb
VZ
2675{
2676 if ( ( newxpos < wxPG_DRAG_MARGIN ) )
2677 return;
2678
2679 wxPropertyGridPageState* state = m_pState;
2680
2681 state->DoSetSplitterPosition( newxpos, splitterIndex, allPages );
2682
2683 if ( refresh )
2684 {
fc72fab6 2685 if ( GetSelection() )
1c4293cb
VZ
2686 CorrectEditorWidgetSizeX();
2687
2688 Refresh();
2689 }
2690}
2691
2692// -----------------------------------------------------------------------
2693
2694void wxPropertyGrid::CenterSplitter( bool enableAutoCentering )
2695{
0da1f1c4
JS
2696 SetSplitterPosition( m_width/2 );
2697 if ( enableAutoCentering && HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
2698 m_pState->m_dontCenterSplitter = false;
1c4293cb
VZ
2699}
2700
2701// -----------------------------------------------------------------------
2702// wxPropertyGrid item iteration (GetNextProperty etc.) methods
2703// -----------------------------------------------------------------------
2704
2705// Returns nearest paint visible property (such that will be painted unless
2706// window is scrolled or resized). If given property is paint visible, then
2707// it itself will be returned
2708wxPGProperty* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty* p ) const
2709{
2710 int vx,vy1;// Top left corner of client
2711 GetViewStart(&vx,&vy1);
2712 vy1 *= wxPG_PIXELS_PER_UNIT;
2713
2714 int vy2 = vy1 + m_height;
2715 int propY = p->GetY2(m_lineHeight);
2716
2717 if ( (propY + m_lineHeight) < vy1 )
2718 {
2719 // Too high
2720 return DoGetItemAtY( vy1 );
2721 }
2722 else if ( propY > vy2 )
2723 {
2724 // Too low
2725 return DoGetItemAtY( vy2 );
2726 }
2727
2728 // Itself paint visible
2729 return p;
2730
2731}
2732
1c4293cb
VZ
2733// -----------------------------------------------------------------------
2734// Methods related to change in value, value modification and sending events
2735// -----------------------------------------------------------------------
2736
2737// commits any changes in editor of selected property
2738// return true if validation did not fail
2739// flags are same as with DoSelectProperty
2740bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags )
2741{
2742 // Committing already?
2743 if ( m_inCommitChangesFromEditor )
2744 return true;
2745
2746 // Don't do this if already processing editor event. It might
2747 // induce recursive dialogs and crap like that.
b0996c3d 2748 if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
1c4293cb
VZ
2749 {
2750 if ( m_inDoPropertyChanged )
2751 return true;
2752
2753 return false;
2754 }
2755
fc72fab6
JS
2756 wxPGProperty* selected = GetSelection();
2757
1c4293cb
VZ
2758 if ( m_wndEditor &&
2759 IsEditorsValueModified() &&
2760 (m_iFlags & wxPG_FL_INITIALIZED) &&
fc72fab6 2761 selected )
1c4293cb
VZ
2762 {
2763 m_inCommitChangesFromEditor = 1;
2764
fc72fab6 2765 wxVariant variant(selected->GetValueRef());
1c4293cb
VZ
2766 bool valueIsPending = false;
2767
2768 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2769 // due to another window getting focus
2770 wxWindow* oldFocus = m_curFocused;
2771
2772 bool validationFailure = false;
2773 bool forceSuccess = (flags & (wxPG_SEL_NOVALIDATE|wxPG_SEL_FORCE)) ? true : false;
2774
2775 m_chgInfo_changedProperty = NULL;
2776
2777 // If truly modified, schedule value as pending.
fc72fab6
JS
2778 if ( selected->GetEditorClass()->
2779 GetValueFromControl( variant,
2780 selected,
2781 GetEditorControl() ) )
1c4293cb
VZ
2782 {
2783 if ( DoEditorValidate() &&
fc72fab6 2784 PerformValidation(selected, variant) )
1c4293cb
VZ
2785 {
2786 valueIsPending = true;
2787 }
2788 else
2789 {
2790 validationFailure = true;
2791 }
2792 }
2793 else
2794 {
2795 EditorsValueWasNotModified();
2796 }
2797
2798 bool res = true;
2799
2800 m_inCommitChangesFromEditor = 0;
2801
2802 if ( validationFailure && !forceSuccess )
2803 {
2804 if (oldFocus)
2805 {
2806 oldFocus->SetFocus();
2807 m_curFocused = oldFocus;
2808 }
2809
fc72fab6 2810 res = OnValidationFailure(selected, variant);
1c4293cb
VZ
2811
2812 // Now prevent further validation failure messages
2813 if ( res )
2814 {
2815 EditorsValueWasNotModified();
fc72fab6 2816 OnValidationFailureReset(selected);
1c4293cb
VZ
2817 }
2818 }
2819 else if ( valueIsPending )
2820 {
fc72fab6 2821 DoPropertyChanged( selected, flags );
1c4293cb
VZ
2822 EditorsValueWasNotModified();
2823 }
2824
2825 return res;
2826 }
2827
2828 return true;
2829}
2830
2831// -----------------------------------------------------------------------
2832
9b5bafcf
JS
2833bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue,
2834 int flags )
1c4293cb
VZ
2835{
2836 //
2837 // Runs all validation functionality.
2838 // Returns true if value passes all tests.
2839 //
2840
2841 m_validationInfo.m_failureBehavior = m_permanentValidationFailureBehavior;
2842
c579ac62
JS
2843 //
2844 // Variant list a special value that cannot be validated
2845 // by normal means.
2846 if ( pendingValue.GetType() != wxPG_VARIANT_TYPE_LIST )
1c4293cb
VZ
2847 {
2848 if ( !p->ValidateValue(pendingValue, m_validationInfo) )
2849 return false;
2850 }
2851
2852 //
2853 // Adapt list to child values, if necessary
2854 wxVariant listValue = pendingValue;
2855 wxVariant* pPendingValue = &pendingValue;
2856 wxVariant* pList = NULL;
2857
2858 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2859 // string value, then we need treat as it was changed instead
2860 // (or, in addition, as is the case with composite string parent).
2861 // This includes creating list variant for child values.
2862
2863 wxPGProperty* pwc = p->GetParent();
2864 wxPGProperty* changedProperty = p;
2865 wxPGProperty* baseChangedProperty = changedProperty;
2866 wxVariant bcpPendingList;
2867
2868 listValue = pendingValue;
d665918b 2869 listValue.SetName(p->GetBaseName());
1c4293cb
VZ
2870
2871 while ( pwc &&
2872 (pwc->HasFlag(wxPG_PROP_AGGREGATE) || pwc->HasFlag(wxPG_PROP_COMPOSED_VALUE)) )
2873 {
2874 wxVariantList tempList;
d665918b 2875 wxVariant lv(tempList, pwc->GetBaseName());
1c4293cb
VZ
2876 lv.Append(listValue);
2877 listValue = lv;
2878 pPendingValue = &listValue;
2879
2880 if ( pwc->HasFlag(wxPG_PROP_AGGREGATE) )
2881 {
2882 baseChangedProperty = pwc;
2883 bcpPendingList = lv;
2884 }
2885
2886 changedProperty = pwc;
2887 pwc = pwc->GetParent();
2888 }
2889
2890 wxVariant value;
2891 wxPGProperty* evtChangingProperty = changedProperty;
2892
0372d42e 2893 if ( pPendingValue->GetType() != wxPG_VARIANT_TYPE_LIST )
1c4293cb
VZ
2894 {
2895 value = *pPendingValue;
2896 }
2897 else
2898 {
2899 // Convert list to child values
2900 pList = pPendingValue;
2901 changedProperty->AdaptListToValue( *pPendingValue, &value );
2902 }
2903
2904 wxVariant evtChangingValue = value;
2905
9b5bafcf 2906 if ( flags & SendEvtChanging )
1c4293cb 2907 {
9b5bafcf
JS
2908 // FIXME: After proper ValueToString()s added, remove
2909 // this. It is just a temporary fix, as evt_changing
2910 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2911 // (unless it is selected, and textctrl editor is open).
2912 if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
1c4293cb 2913 {
9b5bafcf
JS
2914 evtChangingProperty = baseChangedProperty;
2915 if ( evtChangingProperty != p )
2916 {
2917 evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
2918 }
2919 else
2920 {
2921 evtChangingValue = pendingValue;
2922 }
1c4293cb 2923 }
1c4293cb 2924
9b5bafcf 2925 if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
1c4293cb 2926 {
fc72fab6 2927 if ( changedProperty == GetSelection() )
9b5bafcf
JS
2928 {
2929 wxWindow* editor = GetEditorControl();
2930 wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
2931 evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
2932 }
2933 else
2934 {
2935 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2936 }
1c4293cb
VZ
2937 }
2938 }
2939
2940 wxASSERT( m_chgInfo_changedProperty == NULL );
2941 m_chgInfo_changedProperty = changedProperty;
2942 m_chgInfo_baseChangedProperty = baseChangedProperty;
2943 m_chgInfo_pendingValue = value;
2944
2945 if ( pList )
2946 m_chgInfo_valueList = *pList;
2947 else
2948 m_chgInfo_valueList.MakeNull();
2949
2950 // If changedProperty is not property which value was edited,
2951 // then call wxPGProperty::ValidateValue() for that as well.
0372d42e 2952 if ( p != changedProperty && value.GetType() != wxPG_VARIANT_TYPE_LIST )
1c4293cb
VZ
2953 {
2954 if ( !changedProperty->ValidateValue(value, m_validationInfo) )
2955 return false;
2956 }
2957
9b5bafcf
JS
2958 if ( flags & SendEvtChanging )
2959 {
2960 // SendEvent returns true if event was vetoed
58935d4a
JS
2961 if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty,
2962 &evtChangingValue ) )
9b5bafcf
JS
2963 return false;
2964 }
2965
2966 if ( flags & IsStandaloneValidation )
2967 {
2968 // If called in 'generic' context, we need to reset
2969 // m_chgInfo_changedProperty and write back translated value.
2970 m_chgInfo_changedProperty = NULL;
2971 pendingValue = value;
2972 }
1c4293cb
VZ
2973
2974 return true;
2975}
2976
2977// -----------------------------------------------------------------------
2978
2979void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), const wxString& msg )
2980{
2981 if ( !msg.length() )
2982 return;
2983
2984#if wxUSE_STATUSBAR
2985 if ( !wxPGGlobalVars->m_offline )
2986 {
2987 wxWindow* topWnd = ::wxGetTopLevelParent(this);
2988 if ( topWnd )
2989 {
2990 wxFrame* pFrame = wxDynamicCast(topWnd, wxFrame);
2991 if ( pFrame )
2992 {
2993 wxStatusBar* pStatusBar = pFrame->GetStatusBar();
2994 if ( pStatusBar )
2995 {
2996 pStatusBar->SetStatusText(msg);
2997 return;
2998 }
2999 }
3000 }
3001 }
3002#endif
3003
9a83f860 3004 ::wxMessageBox(msg, wxT("Property Error"));
1c4293cb
VZ
3005}
3006
3007// -----------------------------------------------------------------------
3008
d8812c6e
JS
3009bool wxPropertyGrid::OnValidationFailure( wxPGProperty* property,
3010 wxVariant& invalidValue )
3011{
3012 wxWindow* editor = GetEditorControl();
3013
3014 // First call property's handler
3015 property->OnValidationFailure(invalidValue);
3016
3017 bool res = DoOnValidationFailure(property, invalidValue);
3018
3019 //
3020 // For non-wxTextCtrl editors, we do need to revert the value
3021 if ( !editor->IsKindOf(CLASSINFO(wxTextCtrl)) &&
fc72fab6 3022 property == GetSelection() )
d8812c6e
JS
3023 {
3024 property->GetEditorClass()->UpdateControl(property, editor);
3025 }
3026
3027 property->SetFlag(wxPG_PROP_INVALID_VALUE);
3028
3029 return res;
3030}
3031
1c4293cb
VZ
3032bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) )
3033{
3034 int vfb = m_validationInfo.m_failureBehavior;
3035
3036 if ( vfb & wxPG_VFB_BEEP )
3037 ::wxBell();
3038
3039 if ( (vfb & wxPG_VFB_MARK_CELL) &&
3040 !property->HasFlag(wxPG_PROP_INVALID_VALUE) )
3041 {
d7e2b522 3042 unsigned int colCount = m_pState->GetColumnCount();
1c4293cb 3043
d7e2b522
JS
3044 // We need backup marked property's cells
3045 m_propCellsBackup = property->m_cells;
3046
3047 wxColour vfbFg = *wxWHITE;
3048 wxColour vfbBg = *wxRED;
3049
3050 property->EnsureCells(colCount);
3051
3052 for ( unsigned int i=0; i<colCount; i++ )
1c4293cb 3053 {
d7e2b522
JS
3054 wxPGCell& cell = property->m_cells[i];
3055 cell.SetFgCol(vfbFg);
3056 cell.SetBgCol(vfbBg);
3057 }
1c4293cb 3058
d7e2b522 3059 DrawItemAndChildren(property);
1c4293cb 3060
fc72fab6 3061 if ( property == GetSelection() )
d7e2b522
JS
3062 {
3063 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL);
1c4293cb 3064
d7e2b522
JS
3065 wxWindow* editor = GetEditorControl();
3066 if ( editor )
3067 {
3068 editor->SetForegroundColour(vfbFg);
3069 editor->SetBackgroundColour(vfbBg);
1c4293cb
VZ
3070 }
3071 }
3072 }
3073
3074 if ( vfb & wxPG_VFB_SHOW_MESSAGE )
3075 {
3076 wxString msg = m_validationInfo.m_failureMessage;
3077
3078 if ( !msg.length() )
9a83f860 3079 msg = wxT("You have entered invalid value. Press ESC to cancel editing.");
1c4293cb
VZ
3080
3081 DoShowPropertyError(property, msg);
3082 }
3083
3084 return (vfb & wxPG_VFB_STAY_IN_PROPERTY) ? false : true;
3085}
3086
3087// -----------------------------------------------------------------------
3088
3089void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty* property )
3090{
3091 int vfb = m_validationInfo.m_failureBehavior;
3092
3093 if ( vfb & wxPG_VFB_MARK_CELL )
3094 {
d7e2b522
JS
3095 // Revert cells
3096 property->m_cells = m_propCellsBackup;
1c4293cb
VZ
3097
3098 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL);
3099
fc72fab6 3100 if ( property == GetSelection() && GetEditorControl() )
1c4293cb
VZ
3101 {
3102 // Calling this will recreate the control, thus resetting its colour
3103 RefreshProperty(property);
3104 }
3105 else
3106 {
3107 DrawItemAndChildren(property);
3108 }
3109 }
3110}
3111
3112// -----------------------------------------------------------------------
3113
3114// flags are same as with DoSelectProperty
3115bool wxPropertyGrid::DoPropertyChanged( wxPGProperty* p, unsigned int selFlags )
3116{
3117 if ( m_inDoPropertyChanged )
3118 return true;
3119
f9189014 3120 wxWindow* editor = GetEditorControl();
fc72fab6 3121 wxPGProperty* selected = GetSelection();
f9189014 3122
1c4293cb
VZ
3123 m_pState->m_anyModified = 1;
3124
3125 m_inDoPropertyChanged = 1;
3126
3127 // Maybe need to update control
3128 wxASSERT( m_chgInfo_changedProperty != NULL );
3129
3130 // These values were calculated in PerformValidation()
3131 wxPGProperty* changedProperty = m_chgInfo_changedProperty;
3132 wxVariant value = m_chgInfo_pendingValue;
3133
3134 wxPGProperty* topPaintedProperty = changedProperty;
3135
3136 while ( !topPaintedProperty->IsCategory() &&
3137 !topPaintedProperty->IsRoot() )
3138 {
3139 topPaintedProperty = topPaintedProperty->GetParent();
3140 }
3141
8f18b252 3142 changedProperty->SetValue(value, &m_chgInfo_valueList, wxPG_SETVAL_BY_USER);
1c4293cb
VZ
3143
3144 // Set as Modified (not if dragging just began)
3145 if ( !(p->m_flags & wxPG_PROP_MODIFIED) )
3146 {
3147 p->m_flags |= wxPG_PROP_MODIFIED;
fc72fab6 3148 if ( p == selected && (m_windowStyle & wxPG_BOLD_MODIFIED) )
1c4293cb 3149 {
f9189014 3150 if ( editor )
1c4293cb
VZ
3151 SetCurControlBoldFont();
3152 }
3153 }
3154
3155 wxPGProperty* pwc;
3156
3157 // Propagate updates to parent(s)
3158 pwc = p;
3159 wxPGProperty* prevPwc = NULL;
3160
3161 while ( prevPwc != topPaintedProperty )
3162 {
3163 pwc->m_flags |= wxPG_PROP_MODIFIED;
3164
fc72fab6 3165 if ( pwc == selected && (m_windowStyle & wxPG_BOLD_MODIFIED) )
1c4293cb 3166 {
f9189014 3167 if ( editor )
1c4293cb
VZ
3168 SetCurControlBoldFont();
3169 }
3170
3171 prevPwc = pwc;
3172 pwc = pwc->GetParent();
3173 }
3174
3175 // Draw the actual property
3176 DrawItemAndChildren( topPaintedProperty );
3177
3178 //
3179 // If value was set by wxPGProperty::OnEvent, then update the editor
3180 // control.
3181 if ( selFlags & wxPG_SEL_DIALOGVAL )
3182 {
a6353fe8 3183 RefreshEditor();
1c4293cb
VZ
3184 }
3185 else
3186 {
3187#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3188 if ( m_wndEditor ) m_wndEditor->Refresh();
3189 if ( m_wndEditor2 ) m_wndEditor2->Refresh();
3190#endif
3191 }
3192
3193 // Sanity check
3194 wxASSERT( !changedProperty->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) );
3195
3196 // If top parent has composite string value, then send to child parents,
3197 // starting from baseChangedProperty.
3198 if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
3199 {
3200 pwc = m_chgInfo_baseChangedProperty;
3201
3202 while ( pwc != changedProperty )
3203 {
58935d4a 3204 SendEvent( wxEVT_PG_CHANGED, pwc, NULL );
1c4293cb
VZ
3205 pwc = pwc->GetParent();
3206 }
3207 }
3208
58935d4a 3209 SendEvent( wxEVT_PG_CHANGED, changedProperty, NULL );
1c4293cb
VZ
3210
3211 m_inDoPropertyChanged = 0;
3212
3213 return true;
3214}
3215
3216// -----------------------------------------------------------------------
3217
3218bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id, wxVariant newValue )
3219{
3220 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3221
3222 m_chgInfo_changedProperty = NULL;
3223
3224 if ( PerformValidation(p, newValue) )
3225 {
3226 DoPropertyChanged(p);
3227 return true;
3228 }
3229 else
3230 {
3231 OnValidationFailure(p, newValue);
3232 }
3233
3234 return false;
3235}
3236
3237// -----------------------------------------------------------------------
9b5bafcf 3238
703ee9f5 3239wxVariant wxPropertyGrid::GetUncommittedPropertyValue()
9b5bafcf
JS
3240{
3241 wxPGProperty* prop = GetSelectedProperty();
3242
3243 if ( !prop )
3244 return wxNullVariant;
3245
3246 wxTextCtrl* tc = GetEditorTextCtrl();
3247 wxVariant value = prop->GetValue();
3248
3249 if ( !tc || !IsEditorsValueModified() )
3250 return value;
3251
3252 if ( !prop->StringToValue(value, tc->GetValue()) )
3253 return value;
3254
3255 if ( !PerformValidation(prop, value, IsStandaloneValidation) )
3256 return prop->GetValue();
3257
3258 return value;
3259}
3260
3261// -----------------------------------------------------------------------
1c4293cb
VZ
3262
3263// Runs wxValidator for the selected property
3264bool wxPropertyGrid::DoEditorValidate()
3265{
1c4293cb
VZ
3266 return true;
3267}
3268
3269// -----------------------------------------------------------------------
3270
b0996c3d 3271void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event )
1c4293cb 3272{
fc72fab6 3273 wxPGProperty* selected = GetSelection();
1c4293cb 3274
1c4293cb
VZ
3275 // Somehow, event is handled after property has been deselected.
3276 // Possibly, but very rare.
cd4b15e5
JS
3277 if ( !selected ||
3278 selected->HasFlag(wxPG_PROP_BEING_DELETED) ||
3279 // Also don't handle editor event if wxEVT_PG_CHANGED or
3280 // similar is currently doing something (showing a
3281 // message box, for instance).
3282 m_processedEvent )
1c4293cb
VZ
3283 return;
3284
b0996c3d 3285 if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
1c4293cb
VZ
3286 return;
3287
3288 wxVariant pendingValue(selected->GetValueRef());
3289 wxWindow* wnd = GetEditorControl();
6086bcc8 3290 wxWindow* editorWnd = wxDynamicCast(event.GetEventObject(), wxWindow);
1c4293cb
VZ
3291 int selFlags = 0;
3292 bool wasUnspecified = selected->IsValueUnspecified();
3293 int usesAutoUnspecified = selected->UsesAutoUnspecified();
1c4293cb
VZ
3294 bool valueIsPending = false;
3295
3296 m_chgInfo_changedProperty = NULL;
3297
3298 m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED|wxPG_FL_VALUE_CHANGE_IN_EVENT);
3299
3300 //
3301 // Filter out excess wxTextCtrl modified events
3302 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED &&
3303 wnd &&
3304 wnd->IsKindOf(CLASSINFO(wxTextCtrl)) )
3305 {
3306 wxTextCtrl* tc = (wxTextCtrl*) wnd;
3307
3308 wxString newTcValue = tc->GetValue();
3309 if ( m_prevTcValue == newTcValue )
3310 return;
3311
3312 m_prevTcValue = newTcValue;
3313 }
3314
b0996c3d 3315 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
1c4293cb
VZ
3316
3317 bool validationFailure = false;
3318 bool buttonWasHandled = false;
3319
3320 //
3321 // Try common button handling
3322 if ( m_wndEditor2 && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
3323 {
3324 wxPGEditorDialogAdapter* adapter = selected->GetEditorDialog();
3325
3326 if ( adapter )
3327 {
3328 buttonWasHandled = true;
3329 // Store as res2, as previously (and still currently alternatively)
3330 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3331 // in wxPGProperty::OnEvent().
3332 adapter->ShowDialog( this, selected );
3333 delete adapter;
3334 }
3335 }
3336
7de050ad 3337 if ( !buttonWasHandled )
1c4293cb 3338 {
6086bcc8 3339 if ( wnd || m_wndEditor2 )
1c4293cb 3340 {
7de050ad
JS
3341 // First call editor class' event handler.
3342 const wxPGEditor* editor = selected->GetEditorClass();
3343
6086bcc8 3344 if ( editor->OnEvent( this, selected, editorWnd, event ) )
1c4293cb 3345 {
7de050ad
JS
3346 // If changes, validate them
3347 if ( DoEditorValidate() )
3348 {
6086bcc8 3349 if ( editor->GetValueFromControl( pendingValue,
fc72fab6 3350 selected,
6086bcc8 3351 wnd ) )
7de050ad
JS
3352 valueIsPending = true;
3353 }
3354 else
3355 {
3356 validationFailure = true;
3357 }
1c4293cb
VZ
3358 }
3359 }
3360
3361 // Then the property's custom handler (must be always called, unless
3362 // validation failed).
3363 if ( !validationFailure )
6086bcc8 3364 buttonWasHandled = selected->OnEvent( this, editorWnd, event );
1c4293cb
VZ
3365 }
3366
3367 // SetValueInEvent(), as called in one of the functions referred above
3368 // overrides editor's value.
3369 if ( m_iFlags & wxPG_FL_VALUE_CHANGE_IN_EVENT )
3370 {
3371 valueIsPending = true;
3372 pendingValue = m_changeInEventValue;
3373 selFlags |= wxPG_SEL_DIALOGVAL;
3374 }
3375
3376 if ( !validationFailure && valueIsPending )
fc72fab6 3377 if ( !PerformValidation(selected, pendingValue) )
1c4293cb
VZ
3378 validationFailure = true;
3379
a5d56762 3380 if ( validationFailure)
1c4293cb
VZ
3381 {
3382 OnValidationFailure(selected, pendingValue);
3383 }
3384 else if ( valueIsPending )
3385 {
3386 selFlags |= ( !wasUnspecified && selected->IsValueUnspecified() && usesAutoUnspecified ) ? wxPG_SEL_SETUNSPEC : 0;
3387
3388 DoPropertyChanged(selected, selFlags);
3389 EditorsValueWasNotModified();
0d4884cb 3390
0d4884cb
JS
3391 // Regardless of editor type, unfocus editor on
3392 // text-editing related enter press.
3393 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
3394 {
3395 SetFocusOnCanvas();
3396 }
1c4293cb
VZ
3397 }
3398 else
3399 {
3400 // No value after all
23318a53 3401
a5d56762
RR
3402 // Regardless of editor type, unfocus editor on
3403 // text-editing related enter press.
3404 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
3405 {
3406 SetFocusOnCanvas();
3407 }
1c4293cb
VZ
3408
3409 // Let unhandled button click events go to the parent
3410 if ( !buttonWasHandled && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
3411 {
3412 wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED,GetId());
3413 GetEventHandler()->AddPendingEvent(evt);
3414 }
3415 }
3416
b0996c3d 3417 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
1c4293cb
VZ
3418}
3419
3420// -----------------------------------------------------------------------
3421// wxPropertyGrid editor control helper methods
3422// -----------------------------------------------------------------------
3423
3424wxRect wxPropertyGrid::GetEditorWidgetRect( wxPGProperty* p, int column ) const
3425{
3426 int itemy = p->GetY2(m_lineHeight);
1c4293cb
VZ
3427 int splitterX = m_pState->DoGetSplitterPosition(column-1);
3428 int colEnd = splitterX + m_pState->m_colWidths[column];
4aee8334 3429 int imageOffset = 0;
1c4293cb 3430
39e4e221
JS
3431 int vx, vy; // Top left corner of client
3432 GetViewStart(&vx, &vy);
3433 vy *= wxPG_PIXELS_PER_UNIT;
3434
1c4293cb 3435 // TODO: If custom image detection changes from current, change this.
4aee8334 3436 if ( m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE )
1c4293cb
VZ
3437 {
3438 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
4aee8334
JS
3439 int iw = p->OnMeasureImage().x;
3440 if ( iw < 1 )
3441 iw = wxPG_CUSTOM_IMAGE_WIDTH;
3442 imageOffset = p->GetImageOffset(iw);
1c4293cb
VZ
3443 }
3444
3445 return wxRect
3446 (
4aee8334 3447 splitterX+imageOffset+wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1,
1c4293cb 3448 itemy-vy,
4aee8334 3449 colEnd-splitterX-wxPG_XBEFOREWIDGET-wxPG_CONTROL_MARGIN-imageOffset-1,
1c4293cb
VZ
3450 m_lineHeight-1
3451 );
3452}
3453
3454// -----------------------------------------------------------------------
3455
3456wxRect wxPropertyGrid::GetImageRect( wxPGProperty* p, int item ) const
3457{
3458 wxSize sz = GetImageSize(p, item);
3459 return wxRect(wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
3460 wxPG_CUSTOM_IMAGE_SPACINGY,
3461 sz.x,
3462 sz.y);
3463}
3464
3465// return size of custom paint image
3466wxSize wxPropertyGrid::GetImageSize( wxPGProperty* p, int item ) const
3467{
3468 // If called with NULL property, then return default image
3469 // size for properties that use image.
3470 if ( !p )
3471 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight));
3472
3473 wxSize cis = p->OnMeasureImage(item);
3474
939d9364 3475 int choiceCount = p->m_choices.GetCount();
1c4293cb
VZ
3476 int comVals = p->GetDisplayedCommonValueCount();
3477 if ( item >= choiceCount && comVals > 0 )
3478 {
3479 unsigned int cvi = item-choiceCount;
3480 cis = GetCommonValue(cvi)->GetRenderer()->GetImageSize(NULL, 1, cvi);
3481 }
3482 else if ( item >= 0 && choiceCount == 0 )
3483 return wxSize(0, 0);
3484
3485 if ( cis.x < 0 )
3486 {
3487 if ( cis.x <= -1 )
3488 cis.x = wxPG_CUSTOM_IMAGE_WIDTH;
3489 }
3490 if ( cis.y <= 0 )
3491 {
3492 if ( cis.y >= -1 )
3493 cis.y = wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight);
3494 else
3495 cis.y = -cis.y;
3496 }
3497 return cis;
3498}
3499
3500// -----------------------------------------------------------------------
3501
3502// takes scrolling into account
3503void wxPropertyGrid::ImprovedClientToScreen( int* px, int* py )
3504{
3505 int vx, vy;
3506 GetViewStart(&vx,&vy);
3507 vy*=wxPG_PIXELS_PER_UNIT;
3508 vx*=wxPG_PIXELS_PER_UNIT;
3509 *px -= vx;
3510 *py -= vy;
3511 ClientToScreen( px, py );
3512}
3513
3514// -----------------------------------------------------------------------
3515
3516wxPropertyGridHitTestResult wxPropertyGrid::HitTest( const wxPoint& pt ) const
3517{
3518 wxPoint pt2;
3519 GetViewStart(&pt2.x,&pt2.y);
3520 pt2.x *= wxPG_PIXELS_PER_UNIT;
3521 pt2.y *= wxPG_PIXELS_PER_UNIT;
3522 pt2.x += pt.x;
3523 pt2.y += pt.y;
3524
3525 return m_pState->HitTest(pt2);
3526}
3527
3528// -----------------------------------------------------------------------
3529
3530// custom set cursor
3531void wxPropertyGrid::CustomSetCursor( int type, bool override )
3532{
3533 if ( type == m_curcursor && !override ) return;
3534
3535 wxCursor* cursor = &wxPG_DEFAULT_CURSOR;
3536
3537 if ( type == wxCURSOR_SIZEWE )
3538 cursor = m_cursorSizeWE;
3539
39e4e221 3540 SetCursor( *cursor );
1c4293cb
VZ
3541
3542 m_curcursor = type;
3543}
3544
3545// -----------------------------------------------------------------------
b0996c3d 3546// wxPropertyGrid property selection, editor creation
1c4293cb
VZ
3547// -----------------------------------------------------------------------
3548
b0996c3d
JS
3549//
3550// This class forwards events from property editor controls to wxPropertyGrid.
3551class wxPropertyGridEditorEventForwarder : public wxEvtHandler
3552{
3553public:
3554 wxPropertyGridEditorEventForwarder( wxPropertyGrid* propGrid )
3555 : wxEvtHandler(), m_propGrid(propGrid)
3556 {
3557 }
3558
3559 virtual ~wxPropertyGridEditorEventForwarder()
3560 {
3561 }
3562
3563private:
3564 bool ProcessEvent( wxEvent& event )
3565 {
3566 // Always skip
3567 event.Skip();
3568
3569 m_propGrid->HandleCustomEditorEvent(event);
3570
3571 return wxEvtHandler::ProcessEvent(event);
3572 }
3573
3574 wxPropertyGrid* m_propGrid;
3575};
3576
1c4293cb 3577// Setups event handling for child control
28fb19ef 3578void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd )
1c4293cb 3579{
28fb19ef
JS
3580 wxWindowID id = argWnd->GetId();
3581
1c4293cb
VZ
3582 if ( argWnd == m_wndEditor )
3583 {
6d24f9a9
JS
3584 argWnd->Connect(id, wxEVT_MOTION,
3585 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild),
3586 NULL, this);
3587 argWnd->Connect(id, wxEVT_LEFT_UP,
3588 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild),
3589 NULL, this);
3590 argWnd->Connect(id, wxEVT_LEFT_DOWN,
3591 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild),
3592 NULL, this);
3593 argWnd->Connect(id, wxEVT_RIGHT_UP,
3594 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild),
3595 NULL, this);
3596 argWnd->Connect(id, wxEVT_ENTER_WINDOW,
3597 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry),
3598 NULL, this);
3599 argWnd->Connect(id, wxEVT_LEAVE_WINDOW,
3600 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry),
3601 NULL, this);
1c4293cb 3602 }
2cbd2892 3603
b0996c3d
JS
3604 wxPropertyGridEditorEventForwarder* forwarder;
3605 forwarder = new wxPropertyGridEditorEventForwarder(this);
3606 argWnd->PushEventHandler(forwarder);
3607
2cbd2892
JS
3608 argWnd->Connect(id, wxEVT_KEY_DOWN,
3609 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown),
3610 NULL, this);
1c4293cb
VZ
3611}
3612
58935d4a
JS
3613void wxPropertyGrid::DestroyEditorWnd( wxWindow* wnd )
3614{
3615 if ( !wnd )
3616 return;
3617
3618 wnd->Hide();
3619
3620 // Do not free editors immediately (for sake of processing events)
3621 wxPendingDelete.Append(wnd);
3622}
3623
1c4293cb
VZ
3624void wxPropertyGrid::FreeEditors()
3625{
d35947a2
JS
3626 //
3627 // Return focus back to canvas from children (this is required at least for
3628 // GTK+, which, unlike Windows, clears focus when control is destroyed
3629 // instead of moving it to closest parent).
3630 wxWindow* focus = wxWindow::FindFocus();
3631 if ( focus )
3632 {
3633 wxWindow* parent = focus->GetParent();
3634 while ( parent )
3635 {
39e4e221 3636 if ( parent == this )
d35947a2
JS
3637 {
3638 SetFocusOnCanvas();
3639 break;
3640 }
3641 parent = parent->GetParent();
3642 }
3643 }
3644
1c4293cb 3645 // Do not free editors immediately if processing events
1c4293cb
VZ
3646 if ( m_wndEditor2 )
3647 {
17ba2086 3648 wxEvtHandler* handler = m_wndEditor2->PopEventHandler(false);
1c4293cb 3649 m_wndEditor2->Hide();
17ba2086 3650 wxPendingDelete.Append( handler );
58935d4a 3651 DestroyEditorWnd(m_wndEditor2);
d3b9f782 3652 m_wndEditor2 = NULL;
1c4293cb
VZ
3653 }
3654
3655 if ( m_wndEditor )
3656 {
17ba2086 3657 wxEvtHandler* handler = m_wndEditor->PopEventHandler(false);
1c4293cb 3658 m_wndEditor->Hide();
17ba2086 3659 wxPendingDelete.Append( handler );
58935d4a 3660 DestroyEditorWnd(m_wndEditor);
d3b9f782 3661 m_wndEditor = NULL;
1c4293cb
VZ
3662 }
3663}
3664
3665// Call with NULL to de-select property
3666bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags )
3667{
3668 /*
3669 if (p)
43b2d5e7 3670 {
1c4293cb
VZ
3671 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3672 p->m_parent->m_label.c_str(),p->GetIndexInParent());
43b2d5e7 3673 }
1c4293cb 3674 else
43b2d5e7 3675 {
1c4293cb 3676 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
43b2d5e7 3677 }
1c4293cb
VZ
3678 */
3679
3680 if ( m_inDoSelectProperty )
3681 return true;
3682
3683 m_inDoSelectProperty = 1;
3684
1c4293cb
VZ
3685 if ( !m_pState )
3686 {
3687 m_inDoSelectProperty = 0;
3688 return false;
3689 }
3690
fc72fab6
JS
3691 wxArrayPGProperty prevSelection = m_pState->m_selection;
3692 wxPGProperty* prevFirstSel;
3693
3694 if ( prevSelection.size() > 0 )
3695 prevFirstSel = prevSelection[0];
3696 else
3697 prevFirstSel = NULL;
3698
3699 if ( prevFirstSel && prevFirstSel->HasFlag(wxPG_PROP_BEING_DELETED) )
3700 prevFirstSel = NULL;
3701
58935d4a
JS
3702 // Always send event, as this is indirect call
3703 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE);
3704
a5d56762 3705/*
fc72fab6
JS
3706 if ( prevFirstSel )
3707 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
a5d56762
RR
3708 else
3709 wxPrintf( "None selected\n" );
23318a53 3710
a5d56762
RR
3711 if (p)
3712 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3713 else
3714 wxPrintf( "P = NULL\n" );
3715*/
23318a53 3716
1c4293cb
VZ
3717 // If we are frozen, then just set the values.
3718 if ( m_frozen )
3719 {
3720 m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR);
3721 m_editorFocused = 0;
fc72fab6 3722 m_pState->DoSetSelection(p);
1c4293cb
VZ
3723
3724 // If frozen, always free controls. But don't worry, as Thaw will
3725 // recall SelectProperty to recreate them.
3726 FreeEditors();
3727
3728 // Prevent any further selection measures in this call
d3b9f782 3729 p = NULL;
1c4293cb
VZ
3730 }
3731 else
3732 {
3733 // Is it the same?
fc72fab6
JS
3734 if ( prevFirstSel == p &&
3735 prevSelection.size() <= 1 &&
3736 !(flags & wxPG_SEL_FORCE) )
1c4293cb
VZ
3737 {
3738 // Only set focus if not deselecting
3739 if ( p )
3740 {
3741 if ( flags & wxPG_SEL_FOCUS )
3742 {
3743 if ( m_wndEditor )
3744 {
3745 m_wndEditor->SetFocus();
3746 m_editorFocused = 1;
3747 }
3748 }
3749 else
3750 {
c29e714c 3751 SetFocusOnCanvas();
1c4293cb
VZ
3752 }
3753 }
3754
3755 m_inDoSelectProperty = 0;
3756 return true;
3757 }
3758
3759 //
3760 // First, deactivate previous
fc72fab6 3761 if ( prevFirstSel )
1c4293cb 3762 {
fc72fab6 3763 OnValidationFailureReset(prevFirstSel);
1c4293cb
VZ
3764
3765 // Must double-check if this is an selected in case of forceswitch
fc72fab6 3766 if ( p != prevFirstSel )
1c4293cb
VZ
3767 {
3768 if ( !CommitChangesFromEditor(flags) )
3769 {
3770 // Validation has failed, so we can't exit the previous editor
3771 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3772 // _("Invalid Value"),wxOK|wxICON_ERROR);
3773 m_inDoSelectProperty = 0;
3774 return false;
3775 }
3776 }
3777
3778 FreeEditors();
1c4293cb
VZ
3779
3780 m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR);
3781 EditorsValueWasNotModified();
3782 }
3783
3784 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY);
3785
fc72fab6
JS
3786 m_pState->DoSetSelection(p);
3787
58935d4a
JS
3788 // Redraw unselected
3789 for ( unsigned int i=0; i<prevSelection.size(); i++ )
3790 {
3791 DrawItem(prevSelection[i]);
3792 }
3793
1c4293cb
VZ
3794 //
3795 // Then, activate the one given.
3796 if ( p )
3797 {
3798 int propY = p->GetY2(m_lineHeight);
3799
3800 int splitterX = GetSplitterPosition();
3801 m_editorFocused = 0;
1c4293cb 3802 m_iFlags |= wxPG_FL_PRIMARY_FILLS_ENTIRE;
fc72fab6 3803 if ( p != prevFirstSel )
1c4293cb
VZ
3804 m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED);
3805
d3b9f782 3806 wxASSERT( m_wndEditor == NULL );
1c4293cb 3807
1c4293cb
VZ
3808 //
3809 // Only create editor for non-disabled non-caption
3810 if ( !p->IsCategory() && !(p->m_flags & wxPG_PROP_DISABLED) )
3811 {
3812 // do this for non-caption items
3813
3814 m_selColumn = 1;
3815
3816 // Do we need to paint the custom image, if any?
3817 m_iFlags &= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE);
3818 if ( (p->m_flags & wxPG_PROP_CUSTOMIMAGE) &&
3819 !p->GetEditorClass()->CanContainCustomImage()
3820 )
3821 m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3822
3823 wxRect grect = GetEditorWidgetRect(p, m_selColumn);
3824 wxPoint goodPos = grect.GetPosition();
1c4293cb
VZ
3825
3826 const wxPGEditor* editor = p->GetEditorClass();
3827 wxCHECK_MSG(editor, false,
3828 wxT("NULL editor class not allowed"));
3829
3830 m_iFlags &= ~wxPG_FL_FIXED_WIDTH_EDITOR;
3831
39e4e221
JS
3832 wxPGWindowList wndList =
3833 editor->CreateControls(this,
3834 p,
3835 goodPos,
3836 grect.GetSize());
1c4293cb
VZ
3837
3838 m_wndEditor = wndList.m_primary;
3839 m_wndEditor2 = wndList.m_secondary;
0fd5c401 3840 wxWindow* primaryCtrl = GetEditorControl();
1c4293cb 3841
14c14060
JS
3842 //
3843 // Essentially, primaryCtrl == m_wndEditor
3844 //
3845
39e4e221
JS
3846 // NOTE: It is allowed for m_wndEditor to be NULL - in this
3847 // case value is drawn as normal, and m_wndEditor2 is
3848 // assumed to be a right-aligned button that triggers
3849 // a separate editorCtrl window.
1c4293cb
VZ
3850
3851 if ( m_wndEditor )
3852 {
b0f0eda8 3853 wxASSERT_MSG( m_wndEditor->GetParent() == GetPanel(),
39e4e221
JS
3854 "CreateControls must use result of "
3855 "wxPropertyGrid::GetPanel() as parent "
3856 "of controls." );
1c4293cb
VZ
3857
3858 // Set validator, if any
3859 #if wxUSE_VALIDATORS
704ceca8
JS
3860 wxValidator* validator = p->GetValidator();
3861 if ( validator )
0fd5c401 3862 primaryCtrl->SetValidator(*validator);
1c4293cb
VZ
3863 #endif
3864
3865 if ( m_wndEditor->GetSize().y > (m_lineHeight+6) )
3866 m_iFlags |= wxPG_FL_ABNORMAL_EDITOR;
3867
3868 // If it has modified status, use bold font
3869 // (must be done before capturing m_ctrlXAdjust)
39e4e221
JS
3870 if ( (p->m_flags & wxPG_PROP_MODIFIED) &&
3871 (m_windowStyle & wxPG_BOLD_MODIFIED) )
1c4293cb
VZ
3872 SetCurControlBoldFont();
3873
1c4293cb
VZ
3874 // Store x relative to splitter (we'll need it).
3875 m_ctrlXAdjust = m_wndEditor->GetPosition().x - splitterX;
3876
3877 // Check if background clear is not necessary
3878 wxPoint pos = m_wndEditor->GetPosition();
3879 if ( pos.x > (splitterX+1) || pos.y > propY )
3880 {
3881 m_iFlags &= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE);
3882 }
3883
3884 m_wndEditor->SetSizeHints(3, 3);
3885
28fb19ef 3886 SetupChildEventHandling(primaryCtrl);
1c4293cb
VZ
3887
3888 // Focus and select all (wxTextCtrl, wxComboBox etc)
3889 if ( flags & wxPG_SEL_FOCUS )
3890 {
3891 primaryCtrl->SetFocus();
3892
3893 p->GetEditorClass()->OnFocus(p, primaryCtrl);
3894 }
3895 }
3896
3897 if ( m_wndEditor2 )
3898 {
b0f0eda8 3899 wxASSERT_MSG( m_wndEditor2->GetParent() == GetPanel(),
39e4e221
JS
3900 "CreateControls must use result of "
3901 "wxPropertyGrid::GetPanel() as parent "
3902 "of controls." );
1c4293cb
VZ
3903
3904 // Get proper id for wndSecondary
3905 m_wndSecId = m_wndEditor2->GetId();
3906 wxWindowList children = m_wndEditor2->GetChildren();
3907 wxWindowList::iterator node = children.begin();
3908 if ( node != children.end() )
3909 m_wndSecId = ((wxWindow*)*node)->GetId();
3910
3911 m_wndEditor2->SetSizeHints(3,3);
3912
1c4293cb
VZ
3913 m_wndEditor2->Show();
3914
28fb19ef 3915 SetupChildEventHandling(m_wndEditor2);
1c4293cb
VZ
3916
3917 // If no primary editor, focus to button to allow
3918 // it to interprete ENTER etc.
3919 // NOTE: Due to problems focusing away from it, this
3920 // has been disabled.
3921 /*
3922 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3923 m_wndEditor2->SetFocus();
3924 */
3925 }
3926
3927 if ( flags & wxPG_SEL_FOCUS )
3928 m_editorFocused = 1;
3929
3930 }
3931 else
3932 {
39e4e221
JS
3933 // Make sure focus is in grid canvas (important for wxGTK,
3934 // at least)
c29e714c 3935 SetFocusOnCanvas();
1c4293cb
VZ
3936 }
3937
3938 EditorsValueWasNotModified();
3939
3940 // If it's inside collapsed section, expand parent, scroll, etc.
3941 // Also, if it was partially visible, scroll it into view.
3942 if ( !(flags & wxPG_SEL_NONVISIBLE) )
3943 EnsureVisible( p );
3944
3945 if ( m_wndEditor )
3946 {
1c4293cb
VZ
3947 m_wndEditor->Show(true);
3948 }
3949
58935d4a
JS
3950 if ( !(flags & wxPG_SEL_NO_REFRESH) )
3951 DrawItem(p);
1c4293cb 3952 }
e213da24
JS
3953 else
3954 {
c29e714c
JS
3955 // Make sure focus is in grid canvas
3956 SetFocusOnCanvas();
e213da24 3957 }
1c4293cb
VZ
3958
3959 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY);
3960 }
3961
3962#if wxUSE_STATUSBAR
3963
3964 //
3965 // Show help text in status bar.
3966 // (if found and grid not embedded in manager with help box and
3967 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3968 //
3969
3970 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS) )
3971 {
d3b9f782 3972 wxStatusBar* statusbar = NULL;
1c4293cb
VZ
3973 if ( !(m_iFlags & wxPG_FL_NOSTATUSBARHELP) )
3974 {
3975 wxFrame* frame = wxDynamicCast(::wxGetTopLevelParent(this),wxFrame);
3976 if ( frame )
3977 statusbar = frame->GetStatusBar();
3978 }
3979
3980 if ( statusbar )
3981 {
3982 const wxString* pHelpString = (const wxString*) NULL;
3983
3984 if ( p )
3985 {
3986 pHelpString = &p->GetHelpString();
3987 if ( pHelpString->length() )
3988 {
3989 // Set help box text.
3990 statusbar->SetStatusText( *pHelpString );
3991 m_iFlags |= wxPG_FL_STRING_IN_STATUSBAR;
3992 }
3993 }
3994
3995 if ( (!pHelpString || !pHelpString->length()) &&
3996 (m_iFlags & wxPG_FL_STRING_IN_STATUSBAR) )
3997 {
3998 // Clear help box - but only if it was written
3999 // by us at previous time.
4000 statusbar->SetStatusText( m_emptyString );
4001 m_iFlags &= ~(wxPG_FL_STRING_IN_STATUSBAR);
4002 }
4003 }
4004 }
4005#endif
4006
4007 m_inDoSelectProperty = 0;
4008
4009 // call wx event handler (here so that it also occurs on deselection)
01b5ad3b 4010 if ( !(flags & wxPG_SEL_DONT_SEND_EVENT) )
58935d4a 4011 SendEvent( wxEVT_PG_SELECTED, p, NULL );
1c4293cb
VZ
4012
4013 return true;
4014}
4015
4016// -----------------------------------------------------------------------
4017
4018bool wxPropertyGrid::UnfocusEditor()
4019{
fc72fab6
JS
4020 wxPGProperty* selected = GetSelection();
4021
4022 if ( !selected || !m_wndEditor || m_frozen )
1c4293cb
VZ
4023 return true;
4024
4025 if ( !CommitChangesFromEditor(0) )
4026 return false;
4027
c29e714c 4028 SetFocusOnCanvas();
fc72fab6 4029 DrawItem(selected);
1c4293cb
VZ
4030
4031 return true;
4032}
4033
4034// -----------------------------------------------------------------------
4035
f521bae6
JS
4036void wxPropertyGrid::RefreshEditor()
4037{
fc72fab6 4038 wxPGProperty* p = GetSelection();
03647350 4039 if ( !p )
a6353fe8
JS
4040 return;
4041
4042 wxWindow* wnd = GetEditorControl();
4043 if ( !wnd )
f521bae6 4044 return;
a6353fe8
JS
4045
4046 // Set editor font boldness - must do this before
4047 // calling UpdateControl().
4048 if ( HasFlag(wxPG_BOLD_MODIFIED) )
4049 {
4050 if ( p->HasFlag(wxPG_PROP_MODIFIED) )
4051 wnd->SetFont(GetCaptionFont());
4052 else
4053 wnd->SetFont(GetFont());
4054 }
4055
daeb4e4d
JS
4056 const wxPGEditor* editorClass = p->GetEditorClass();
4057
4058 editorClass->UpdateControl(p, wnd);
4059
4060 if ( p->IsValueUnspecified() )
4061 editorClass ->SetValueToUnspecified(p, wnd);
f521bae6
JS
4062}
4063
4064// -----------------------------------------------------------------------
4065
01b5ad3b
JS
4066bool wxPropertyGrid::SelectProperty( wxPGPropArg id, bool focus )
4067{
4068 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4069
4070 int flags = wxPG_SEL_DONT_SEND_EVENT;
4071 if ( focus )
4072 flags |= wxPG_SEL_FOCUS;
4073
4074 return DoSelectProperty(p, flags);
4075}
4076
1c4293cb
VZ
4077// -----------------------------------------------------------------------
4078// wxPropertyGrid expand/collapse state
4079// -----------------------------------------------------------------------
4080
4081bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents )
4082{
4083 wxPGProperty* pwc = wxStaticCast(p, wxPGProperty);
fc72fab6 4084 wxPGProperty* selected = GetSelection();
1c4293cb
VZ
4085
4086 // If active editor was inside collapsed section, then disable it
fc72fab6 4087 if ( selected && selected->IsSomeParent(p) )
1c4293cb 4088 {
01b5ad3b 4089 DoClearSelection();
1c4293cb
VZ
4090 }
4091
4092 // Store dont-center-splitter flag 'cause we need to temporarily set it
0da1f1c4
JS
4093 bool prevDontCenterSplitter = m_pState->m_dontCenterSplitter;
4094 m_pState->m_dontCenterSplitter = true;
1c4293cb
VZ
4095
4096 bool res = m_pState->DoCollapse(pwc);
4097
4098 if ( res )
4099 {
4100 if ( sendEvents )
4101 SendEvent( wxEVT_PG_ITEM_COLLAPSED, p );
4102
4103 RecalculateVirtualSize();
aff6c20a 4104 Refresh();
1c4293cb
VZ
4105 }
4106
0da1f1c4 4107 m_pState->m_dontCenterSplitter = prevDontCenterSplitter;
1c4293cb
VZ
4108
4109 return res;
4110}
4111
4112// -----------------------------------------------------------------------
4113
4114bool wxPropertyGrid::DoExpand( wxPGProperty* p, bool sendEvents )
4115{
4116 wxCHECK_MSG( p, false, wxT("invalid property id") );
4117
4118 wxPGProperty* pwc = (wxPGProperty*)p;
4119
4120 // Store dont-center-splitter flag 'cause we need to temporarily set it
0da1f1c4
JS
4121 bool prevDontCenterSplitter = m_pState->m_dontCenterSplitter;
4122 m_pState->m_dontCenterSplitter = true;
1c4293cb
VZ
4123
4124 bool res = m_pState->DoExpand(pwc);
4125
4126 if ( res )
4127 {
4128 if ( sendEvents )
4129 SendEvent( wxEVT_PG_ITEM_EXPANDED, p );
4130
4131 RecalculateVirtualSize();
aff6c20a 4132 Refresh();
1c4293cb
VZ
4133 }
4134
0da1f1c4 4135 m_pState->m_dontCenterSplitter = prevDontCenterSplitter;
1c4293cb
VZ
4136
4137 return res;
4138}
4139
4140// -----------------------------------------------------------------------
4141
4142bool wxPropertyGrid::DoHideProperty( wxPGProperty* p, bool hide, int flags )
4143{
4144 if ( m_frozen )
4145 return m_pState->DoHideProperty(p, hide, flags);
4146
fc72fab6
JS
4147 wxArrayPGProperty selection = m_pState->m_selection; // Must use a copy
4148 int selRemoveCount = 0;
4149 for ( unsigned int i=0; i<selection.size(); i++ )
4150 {
4151 wxPGProperty* selected = selection[i];
4152 if ( selected == p || selected->IsSomeParent(p) )
1c4293cb 4153 {
fc72fab6
JS
4154 if ( !DoRemoveFromSelection(p, flags) )
4155 return false;
4156 selRemoveCount += 1;
1c4293cb 4157 }
fc72fab6 4158 }
1c4293cb
VZ
4159
4160 m_pState->DoHideProperty(p, hide, flags);
4161
4162 RecalculateVirtualSize();
4163 Refresh();
4164
4165 return true;
4166}
4167
4168
4169// -----------------------------------------------------------------------
4170// wxPropertyGrid size related methods
4171// -----------------------------------------------------------------------
4172
4173void wxPropertyGrid::RecalculateVirtualSize( int forceXPos )
4174{
4175 if ( (m_iFlags & wxPG_FL_RECALCULATING_VIRTUAL_SIZE) || m_frozen )
4176 return;
4177
4178 //
4179 // If virtual height was changed, then recalculate editor control position(s)
4180 if ( m_pState->m_vhCalcPending )
4181 CorrectEditorWidgetPosY();
4182
4183 m_pState->EnsureVirtualHeight();
4184
4b6a582b
VZ
4185 wxASSERT_LEVEL_2_MSG(
4186 m_pState->GetVirtualHeight() == m_pState->GetActualVirtualHeight(),
4187 "VirtualHeight and ActualVirtualHeight should match"
4188 );
1c4293cb
VZ
4189
4190 m_iFlags |= wxPG_FL_RECALCULATING_VIRTUAL_SIZE;
4191
4192 int x = m_pState->m_width;
4193 int y = m_pState->m_virtualHeight;
4194
4195 int width, height;
4196 GetClientSize(&width,&height);
4197
4198 // Now adjust virtual size.
657a8a35 4199 SetVirtualSize(x, y);
1c4293cb
VZ
4200
4201 int xAmount = 0;
4202 int xPos = 0;
4203
4204 //
4205 // Adjust scrollbars
4206 if ( HasVirtualWidth() )
4207 {
4208 xAmount = x/wxPG_PIXELS_PER_UNIT;
4209 xPos = GetScrollPos( wxHORIZONTAL );
4210 }
4211
4212 if ( forceXPos != -1 )
4213 xPos = forceXPos;
4214 // xPos too high?
4215 else if ( xPos > (xAmount-(width/wxPG_PIXELS_PER_UNIT)) )
4216 xPos = 0;
4217
bb2e05cf 4218 int yAmount = y / wxPG_PIXELS_PER_UNIT;
1c4293cb
VZ
4219 int yPos = GetScrollPos( wxVERTICAL );
4220
4221 SetScrollbars( wxPG_PIXELS_PER_UNIT, wxPG_PIXELS_PER_UNIT,
4222 xAmount, yAmount, xPos, yPos, true );
4223
4224 // Must re-get size now
4225 GetClientSize(&width,&height);
4226
4227 if ( !HasVirtualWidth() )
4228 {
4229 m_pState->SetVirtualWidth(width);
4230 x = width;
4231 }
4232
4233 m_width = width;
4234 m_height = height;
4235
1c4293cb
VZ
4236 m_pState->CheckColumnWidths();
4237
fc72fab6 4238 if ( GetSelection() )
1c4293cb
VZ
4239 CorrectEditorWidgetSizeX();
4240
4241 m_iFlags &= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE;
4242}
4243
4244// -----------------------------------------------------------------------
4245
4246void wxPropertyGrid::OnResize( wxSizeEvent& event )
4247{
4248 if ( !(m_iFlags & wxPG_FL_INITIALIZED) )
4249 return;
4250
4251 int width, height;
39e4e221 4252 GetClientSize(&width, &height);
1c4293cb
VZ
4253
4254 m_width = width;
4255 m_height = height;
4256
1c4293cb
VZ
4257#if wxPG_DOUBLE_BUFFER
4258 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) )
4259 {
4260 int dblh = (m_lineHeight*2);
4261 if ( !m_doubleBuffer )
4262 {
4263 // Create double buffer bitmap to draw on, if none
4264 int w = (width>250)?width:250;
4265 int h = height + dblh;
4266 h = (h>400)?h:400;
4267 m_doubleBuffer = new wxBitmap( w, h );
4268 }
4269 else
4270 {
4271 int w = m_doubleBuffer->GetWidth();
4272 int h = m_doubleBuffer->GetHeight();
4273
4274 // Double buffer must be large enough
4275 if ( w < width || h < (height+dblh) )
4276 {
4277 if ( w < width ) w = width;
4278 if ( h < (height+dblh) ) h = height + dblh;
4279 delete m_doubleBuffer;
4280 m_doubleBuffer = new wxBitmap( w, h );
4281 }
4282 }
4283 }
4284
4285#endif
4286
4287 m_pState->OnClientWidthChange( width, event.GetSize().x - m_ncWidth, true );
4288 m_ncWidth = event.GetSize().x;
4289
4290 if ( !m_frozen )
4291 {
4292 if ( m_pState->m_itemsAdded )
4293 PrepareAfterItemsAdded();
4294 else
4295 // Without this, virtual size (atleast under wxGTK) will be skewed
4296 RecalculateVirtualSize();
4297
4298 Refresh();
4299 }
4300}
4301
4302// -----------------------------------------------------------------------
4303
4304void wxPropertyGrid::SetVirtualWidth( int width )
4305{
4306 if ( width == -1 )
4307 {
4308 // Disable virtual width
4309 width = GetClientSize().x;
4310 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH);
4311 }
4312 else
4313 {
4314 // Enable virtual width
4315 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH);
4316 }
4317 m_pState->SetVirtualWidth( width );
4318}
4319
0ca422ef
RR
4320void wxPropertyGrid::SetFocusOnCanvas()
4321{
39e4e221 4322 SetFocusIgnoringChildren();
0ca422ef
RR
4323 m_editorFocused = 0;
4324}
4325
1c4293cb
VZ
4326// -----------------------------------------------------------------------
4327// wxPropertyGrid mouse event handling
4328// -----------------------------------------------------------------------
4329
4330// selFlags uses same values DoSelectProperty's flags
4331// Returns true if event was vetoed.
58935d4a
JS
4332bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p,
4333 wxVariant* pValue,
4334 unsigned int selFlags,
4335 unsigned int column )
1c4293cb
VZ
4336{
4337 // Send property grid event of specific type and with specific property
4338 wxPropertyGridEvent evt( eventType, m_eventObject->GetId() );
4339 evt.SetPropertyGrid(this);
4340 evt.SetEventObject(m_eventObject);
4341 evt.SetProperty(p);
58935d4a 4342 evt.SetColumn(column);
644b283d 4343 if ( eventType == wxEVT_PG_CHANGING )
1c4293cb 4344 {
644b283d 4345 wxASSERT( pValue );
1c4293cb 4346 evt.SetCanVeto(true);
1c4293cb 4347 m_validationInfo.m_pValue = pValue;
644b283d 4348 evt.SetupValidationInfo();
1c4293cb 4349 }
644b283d 4350 else
58935d4a 4351 {
644b283d
JS
4352 if ( p )
4353 evt.SetPropertyValue(p->GetValue());
4354
4355 if ( !(selFlags & wxPG_SEL_NOVALIDATE) )
4356 evt.SetCanVeto(true);
58935d4a
JS
4357 }
4358
e84e5ba3 4359 m_processedEvent = &evt;
644b283d 4360 m_eventObject->HandleWindowEvent(evt);
e84e5ba3
JS
4361 m_processedEvent = NULL;
4362
1c4293cb
VZ
4363 return evt.WasVetoed();
4364}
4365
4366// -----------------------------------------------------------------------
4367
4368// Return false if should be skipped
4369bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &event )
4370{
4371 bool res = true;
4372
4373 // Need to set focus?
4374 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
4375 {
c29e714c 4376 SetFocusOnCanvas();
1c4293cb
VZ
4377 }
4378
4379 wxPropertyGridPageState* state = m_pState;
4380 int splitterHit;
4381 int splitterHitOffset;
4382 int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
4383
4384 wxPGProperty* p = DoGetItemAtY(y);
4385
4386 if ( p )
4387 {
4388 int depth = (int)p->GetDepth() - 1;
4389
4390 int marginEnds = m_marginWidth + ( depth * m_subgroup_extramargin );
4391
4392 if ( x >= marginEnds )
4393 {
4394 // Outside margin.
4395
4396 if ( p->IsCategory() )
4397 {
4398 // This is category.
4399 wxPropertyCategory* pwc = (wxPropertyCategory*)p;
4400
4401 int textX = m_marginWidth + ((unsigned int)((pwc->m_depth-1)*m_subgroup_extramargin));
4402
4403 // Expand, collapse, activate etc. if click on text or left of splitter.
4404 if ( x >= textX
4405 &&
4406 ( x < (textX+pwc->GetTextExtent(this, m_captionFont)+(wxPG_CAPRECTXMARGIN*2)) ||
4407 columnHit == 0
4408 )
4409 )
4410 {
58935d4a
JS
4411 if ( !AddToSelectionFromInputEvent( p,
4412 columnHit,
4413 &event ) )
1c4293cb
VZ
4414 return res;
4415
4416 // On double-click, expand/collapse.
4417 if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) )
4418 {
4419 if ( pwc->IsExpanded() ) DoCollapse( p, true );
4420 else DoExpand( p, true );
4421 }
4422 }
4423 }
4424 else if ( splitterHit == -1 )
4425 {
4426 // Click on value.
4427 unsigned int selFlag = 0;
4428 if ( columnHit == 1 )
4429 {
4430 m_iFlags |= wxPG_FL_ACTIVATION_BY_CLICK;
4431 selFlag = wxPG_SEL_FOCUS;
4432 }
58935d4a
JS
4433 if ( !AddToSelectionFromInputEvent( p,
4434 columnHit,
4435 &event,
4436 selFlag ) )
1c4293cb
VZ
4437 return res;
4438
4439 m_iFlags &= ~(wxPG_FL_ACTIVATION_BY_CLICK);
4440
4441 if ( p->GetChildCount() && !p->IsCategory() )
4442 // On double-click, expand/collapse.
4443 if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) )
4444 {
4445 wxPGProperty* pwc = (wxPGProperty*)p;
4446 if ( pwc->IsExpanded() ) DoCollapse( p, true );
4447 else DoExpand( p, true );
4448 }
4449
4450 res = false;
4451 }
4452 else
4453 {
4454 // click on splitter
4455 if ( !(m_windowStyle & wxPG_STATIC_SPLITTER) )
4456 {
4457 if ( event.GetEventType() == wxEVT_LEFT_DCLICK )
4458 {
4459 // Double-clicking the splitter causes auto-centering
4460 CenterSplitter( true );
4461 }
4462 else if ( m_dragStatus == 0 )
4463 {
58935d4a
JS
4464 //
4465 // Begin draggin the splitter
4466 //
4467
4468 // send event
4469 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE);
4470
1c4293cb
VZ
4471 if ( m_wndEditor )
4472 {
4473 // Changes must be committed here or the
4474 // value won't be drawn correctly
4475 if ( !CommitChangesFromEditor() )
4476 return res;
4477
4478 m_wndEditor->Show ( false );
4479 }
4480
4481 if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) )
4482 {
39e4e221 4483 CaptureMouse();
1c4293cb
VZ
4484 m_iFlags |= wxPG_FL_MOUSE_CAPTURED;
4485 }
4486
4487 m_dragStatus = 1;
4488 m_draggedSplitter = splitterHit;
4489 m_dragOffset = splitterHitOffset;
4490
1c4293cb
VZ
4491 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4492 // Fixes button disappearance bug
4493 if ( m_wndEditor2 )
4494 m_wndEditor2->Show ( false );
4495 #endif
4496
4497 m_startingSplitterX = x - splitterHitOffset;
4498 }
4499 }
4500 }
4501 }
4502 else
4503 {
4504 // Click on margin.
4505 if ( p->GetChildCount() )
4506 {
4507 int nx = x + m_marginWidth - marginEnds; // Normalize x.
4508
4509 if ( (nx >= m_gutterWidth && nx < (m_gutterWidth+m_iconWidth)) )
4510 {
4511 int y2 = y % m_lineHeight;
4512 if ( (y2 >= m_buttonSpacingY && y2 < (m_buttonSpacingY+m_iconHeight)) )
4513 {
4514 // On click on expander button, expand/collapse
4515 if ( ((wxPGProperty*)p)->IsExpanded() )
4516 DoCollapse( p, true );
4517 else
4518 DoExpand( p, true );
4519 }
4520 }
4521 }
4522 }
4523 }
4524 return res;
4525}
4526
4527// -----------------------------------------------------------------------
4528
fc72fab6
JS
4529bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x),
4530 unsigned int WXUNUSED(y),
4531 wxMouseEvent& event )
1c4293cb
VZ
4532{
4533 if ( m_propHover )
4534 {
4535 // Select property here as well
4536 wxPGProperty* p = m_propHover;
58935d4a 4537 AddToSelectionFromInputEvent(p, m_colHover, &event);
1c4293cb
VZ
4538
4539 // Send right click event.
4540 SendEvent( wxEVT_PG_RIGHT_CLICK, p );
4541
4542 return true;
4543 }
4544 return false;
4545}
4546
4547// -----------------------------------------------------------------------
4548
fc72fab6
JS
4549bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x),
4550 unsigned int WXUNUSED(y),
4551 wxMouseEvent& event )
1c4293cb
VZ
4552{
4553 if ( m_propHover )
4554 {
4555 // Select property here as well
4556 wxPGProperty* p = m_propHover;
4557
58935d4a 4558 AddToSelectionFromInputEvent(p, m_colHover, &event);
1c4293cb
VZ
4559
4560 // Send double-click event.
4561 SendEvent( wxEVT_PG_DOUBLE_CLICK, m_propHover );
4562
4563 return true;
4564 }
4565 return false;
4566}
4567
4568// -----------------------------------------------------------------------
4569
4570#if wxPG_SUPPORT_TOOLTIPS
4571
4572void wxPropertyGrid::SetToolTip( const wxString& tipString )
4573{
4574 if ( tipString.length() )
4575 {
39e4e221 4576 wxScrolledWindow::SetToolTip(tipString);
1c4293cb
VZ
4577 }
4578 else
4579 {
4580 #if wxPG_ALLOW_EMPTY_TOOLTIPS
39e4e221 4581 wxScrolledWindow::SetToolTip( m_emptyString );
1c4293cb 4582 #else
39e4e221 4583 wxScrolledWindow::SetToolTip( NULL );
1c4293cb
VZ
4584 #endif
4585 }
4586}
4587
4588#endif // #if wxPG_SUPPORT_TOOLTIPS
4589
4590// -----------------------------------------------------------------------
4591
4592// Return false if should be skipped
39e4e221
JS
4593bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y,
4594 wxMouseEvent &event )
1c4293cb
VZ
4595{
4596 // Safety check (needed because mouse capturing may
4597 // otherwise freeze the control)
4598 if ( m_dragStatus > 0 && !event.Dragging() )
4599 {
39e4e221 4600 HandleMouseUp(x, y, event);
1c4293cb
VZ
4601 }
4602
4603 wxPropertyGridPageState* state = m_pState;
4604 int splitterHit;
4605 int splitterHitOffset;
4606 int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
4607 int splitterX = x - splitterHitOffset;
4608
58935d4a
JS
4609 m_colHover = columnHit;
4610
1c4293cb
VZ
4611 if ( m_dragStatus > 0 )
4612 {
4613 if ( x > (m_marginWidth + wxPG_DRAG_MARGIN) &&
4614 x < (m_pState->m_width - wxPG_DRAG_MARGIN) )
4615 {
4616
4617 int newSplitterX = x - m_dragOffset;
4618 int splitterX = x - splitterHitOffset;
4619
4620 // Splitter redraw required?
4621 if ( newSplitterX != splitterX )
4622 {
4623 // Move everything
0da1f1c4 4624 state->m_dontCenterSplitter = true;
39e4e221
JS
4625 state->DoSetSplitterPosition(newSplitterX,
4626 m_draggedSplitter,
4627 false);
1c4293cb
VZ
4628 state->m_fSplitterX = (float) newSplitterX;
4629
fc72fab6 4630 if ( GetSelection() )
1c4293cb
VZ
4631 CorrectEditorWidgetSizeX();
4632
4633 Update();
4634 Refresh();
4635 }
4636
4637 m_dragStatus = 2;
4638 }
4639
4640 return false;
4641 }
4642 else
4643 {
4644
4645 int ih = m_lineHeight;
4646 int sy = y;
4647
4648 #if wxPG_SUPPORT_TOOLTIPS
4649 wxPGProperty* prevHover = m_propHover;
4650 unsigned char prevSide = m_mouseSide;
4651 #endif
4652 int curPropHoverY = y - (y % ih);
4653
4654 // On which item it hovers
b7bc9d80 4655 if ( !m_propHover
1c4293cb 4656 ||
b7bc9d80 4657 ( sy < m_propHoverY || sy >= (m_propHoverY+ih) )
1c4293cb
VZ
4658 )
4659 {
4660 // Mouse moves on another property
4661
4662 m_propHover = DoGetItemAtY(y);
4663 m_propHoverY = curPropHoverY;
4664
4665 // Send hover event
4666 SendEvent( wxEVT_PG_HIGHLIGHTED, m_propHover );
4667 }
4668
4669 #if wxPG_SUPPORT_TOOLTIPS
4670 // Store which side we are on
4671 m_mouseSide = 0;
4672 if ( columnHit == 1 )
4673 m_mouseSide = 2;
4674 else if ( columnHit == 0 )
4675 m_mouseSide = 1;
4676
4677 //
4678 // If tooltips are enabled, show label or value as a tip
4679 // in case it doesn't otherwise show in full length.
4680 //
4681 if ( m_windowStyle & wxPG_TOOLTIPS )
4682 {
39e4e221 4683 wxToolTip* tooltip = GetToolTip();
1c4293cb
VZ
4684
4685 if ( m_propHover != prevHover || prevSide != m_mouseSide )
4686 {
4687 if ( m_propHover && !m_propHover->IsCategory() )
4688 {
4689
4690 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS )
4691 {
4692 // Show help string as a tooltip
4693 wxString tipString = m_propHover->GetHelpString();
4694
4695 SetToolTip(tipString);
4696 }
4697 else
4698 {
4699 // Show cropped value string as a tooltip
4700 wxString tipString;
4701 int space = 0;
4702
4703 if ( m_mouseSide == 1 )
4704 {
4705 tipString = m_propHover->m_label;
4706 space = splitterX-m_marginWidth-3;
4707 }
4708 else if ( m_mouseSide == 2 )
4709 {
4710 tipString = m_propHover->GetDisplayedString();
4711
4712 space = m_width - splitterX;
4713 if ( m_propHover->m_flags & wxPG_PROP_CUSTOMIMAGE )
39e4e221
JS
4714 space -= wxPG_CUSTOM_IMAGE_WIDTH +
4715 wxCC_CUSTOM_IMAGE_MARGIN1 +
4716 wxCC_CUSTOM_IMAGE_MARGIN2;
1c4293cb
VZ
4717 }
4718
4719 if ( space )
4720 {
4721 int tw, th;
657a8a35 4722 GetTextExtent( tipString, &tw, &th, 0, 0 );
1c4293cb
VZ
4723 if ( tw > space )
4724 {
4725 SetToolTip( tipString );
4726 }
4727 }
4728 else
4729 {
4730 if ( tooltip )
4731 {
4732 #if wxPG_ALLOW_EMPTY_TOOLTIPS
39e4e221 4733 SetToolTip( m_emptyString );
1c4293cb 4734 #else
39e4e221 4735 wxScrolledWindow::SetToolTip( NULL );
1c4293cb
VZ
4736 #endif
4737 }
4738 }
4739
4740 }
4741 }
4742 else
4743 {
4744 if ( tooltip )
4745 {
4746 #if wxPG_ALLOW_EMPTY_TOOLTIPS
39e4e221 4747 SetToolTip( m_emptyString );
1c4293cb 4748 #else
39e4e221 4749 wxScrolledWindow::SetToolTip( NULL );
1c4293cb
VZ
4750 #endif
4751 }
4752 }
4753 }
4754 }
4755 #endif
4756
4757 if ( splitterHit == -1 ||
4758 !m_propHover ||
4759 HasFlag(wxPG_STATIC_SPLITTER) )
4760 {
4761 // hovering on something else
4762 if ( m_curcursor != wxCURSOR_ARROW )
4763 CustomSetCursor( wxCURSOR_ARROW );
4764 }
4765 else
4766 {
4767 // Do not allow splitter cursor on caption items.
4768 // (also not if we were dragging and its started
4769 // outside the splitter region)
4770
b7bc9d80 4771 if ( !m_propHover->IsCategory() &&
1c4293cb
VZ
4772 !event.Dragging() )
4773 {
4774
4775 // hovering on splitter
4776
39e4e221
JS
4777 // NB: Condition disabled since MouseLeave event (from the
4778 // editor control) cannot be reliably detected.
1c4293cb
VZ
4779 //if ( m_curcursor != wxCURSOR_SIZEWE )
4780 CustomSetCursor( wxCURSOR_SIZEWE, true );
4781
4782 return false;
4783 }
4784 else
4785 {
4786 // hovering on something else
4787 if ( m_curcursor != wxCURSOR_ARROW )
4788 CustomSetCursor( wxCURSOR_ARROW );
4789 }
4790 }
fc72fab6
JS
4791
4792 //
4793 // Multi select by dragging
4794 //
169dc975 4795 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION) &&
fc72fab6
JS
4796 event.LeftIsDown() &&
4797 m_propHover &&
4798 GetSelection() &&
37e188ea 4799 columnHit != 1 &&
fc72fab6
JS
4800 !state->DoIsPropertySelected(m_propHover) )
4801 {
169dc975
JS
4802 // Additional requirement is that the hovered property
4803 // is adjacent to edges of selection.
4804 const wxArrayPGProperty& selection = GetSelectedProperties();
4805
4806 // Since categories cannot be selected along with 'other'
4807 // properties, exclude them from iterator flags.
4808 int iterFlags = wxPG_ITERATE_VISIBLE & (~wxPG_PROP_CATEGORY);
4809
4810 for ( int i=(selection.size()-1); i>=0; i-- )
4811 {
4812 // TODO: This could be optimized by keeping track of
4813 // which properties are at the edges of selection.
4814 wxPGProperty* selProp = selection[i];
4815 if ( state->ArePropertiesAdjacent(m_propHover, selProp,
4816 iterFlags) )
4817 {
4818 DoAddToSelection(m_propHover);
4819 break;
4820 }
4821 }
fc72fab6 4822 }
1c4293cb
VZ
4823 }
4824 return true;
4825}
4826
4827// -----------------------------------------------------------------------
4828
4829// Also handles Leaving event
4830bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y),
4831 wxMouseEvent &WXUNUSED(event) )
4832{
4833 wxPropertyGridPageState* state = m_pState;
4834 bool res = false;
4835
4836 int splitterHit;
4837 int splitterHitOffset;
4838 state->HitTestH( x, &splitterHit, &splitterHitOffset );
4839
4840 // No event type check - basicly calling this method should
4841 // just stop dragging.
4842 // Left up after dragged?
4843 if ( m_dragStatus >= 1 )
4844 {
4845 //
4846 // End Splitter Dragging
4847 //
4848 // DO NOT ENABLE FOLLOWING LINE!
4849 // (it is only here as a reminder to not to do it)
4850 //splitterX = x;
4851
4852 // Disable splitter auto-centering
0da1f1c4 4853 state->m_dontCenterSplitter = true;
1c4293cb
VZ
4854
4855 // This is necessary to return cursor
4856 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
4857 {
39e4e221 4858 ReleaseMouse();
1c4293cb
VZ
4859 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
4860 }
4861
4862 // Set back the default cursor, if necessary
4863 if ( splitterHit == -1 ||
4864 !m_propHover )
4865 {
4866 CustomSetCursor( wxCURSOR_ARROW );
4867 }
4868
4869 m_dragStatus = 0;
4870
4871 // Control background needs to be cleared
fc72fab6
JS
4872 wxPGProperty* selected = GetSelection();
4873 if ( !(m_iFlags & wxPG_FL_PRIMARY_FILLS_ENTIRE) && selected )
4874 DrawItem( selected );
1c4293cb
VZ
4875
4876 if ( m_wndEditor )
4877 {
4878 m_wndEditor->Show ( true );
4879 }
4880
4881 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4882 // Fixes button disappearance bug
4883 if ( m_wndEditor2 )
4884 m_wndEditor2->Show ( true );
4885 #endif
4886
4887 // This clears the focus.
4888 m_editorFocused = 0;
4889
4890 }
4891 return res;
4892}
4893
4894// -----------------------------------------------------------------------
4895
4896bool wxPropertyGrid::OnMouseCommon( wxMouseEvent& event, int* px, int* py )
4897{
4898 int splitterX = GetSplitterPosition();
4899
39e4e221
JS
4900 int ux, uy;
4901 CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
1c4293cb 4902
0fd5c401 4903 wxWindow* wnd = GetEditorControl();
1c4293cb
VZ
4904
4905 // Hide popup on clicks
4906 if ( event.GetEventType() != wxEVT_MOTION )
4907 if ( wnd && wnd->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
4908 {
0fd5c401 4909 ((wxOwnerDrawnComboBox*)wnd)->HidePopup();
1c4293cb
VZ
4910 }
4911
4912 wxRect r;
4913 if ( wnd )
4914 r = wnd->GetRect();
d3b9f782 4915 if ( wnd == NULL || m_dragStatus ||
1c4293cb
VZ
4916 (
4917 ux <= (splitterX + wxPG_SPLITTERX_DETECTMARGIN2) ||
4918 ux >= (r.x+r.width) ||
4919 event.m_y < r.y ||
4920 event.m_y >= (r.y+r.height)
4921 )
4922 )
4923 {
4924 *px = ux;
4925 *py = uy;
4926 return true;
4927 }
4928 else
4929 {
4930 if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW );
4931 }
4932 return false;
4933}
4934
4935// -----------------------------------------------------------------------
4936
4937void wxPropertyGrid::OnMouseClick( wxMouseEvent &event )
4938{
4939 int x, y;
4940 if ( OnMouseCommon( event, &x, &y ) )
4941 {
4942 HandleMouseClick(x,y,event);
4943 }
4944 event.Skip();
4945}
4946
4947// -----------------------------------------------------------------------
4948
4949void wxPropertyGrid::OnMouseRightClick( wxMouseEvent &event )
4950{
4951 int x, y;
4952 CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y );
4953 HandleMouseRightClick(x,y,event);
4954 event.Skip();
4955}
4956
4957// -----------------------------------------------------------------------
4958
4959void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent &event )
4960{
4961 // Always run standard mouse-down handler as well
4962 OnMouseClick(event);
4963
4964 int x, y;
4965 CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y );
4966 HandleMouseDoubleClick(x,y,event);
4967 event.Skip();
4968}
4969
4970// -----------------------------------------------------------------------
4971
4972void wxPropertyGrid::OnMouseMove( wxMouseEvent &event )
4973{
4974 int x, y;
4975 if ( OnMouseCommon( event, &x, &y ) )
4976 {
4977 HandleMouseMove(x,y,event);
4978 }
4979 event.Skip();
4980}
4981
4982// -----------------------------------------------------------------------
4983
1c4293cb
VZ
4984void wxPropertyGrid::OnMouseUp( wxMouseEvent &event )
4985{
4986 int x, y;
4987 if ( OnMouseCommon( event, &x, &y ) )
4988 {
4989 HandleMouseUp(x,y,event);
4990 }
4991 event.Skip();
4992}
4993
4994// -----------------------------------------------------------------------
4995
4996void wxPropertyGrid::OnMouseEntry( wxMouseEvent &event )
4997{
4998 // This may get called from child control as well, so event's
4999 // mouse position cannot be relied on.
5000
5001 if ( event.Entering() )
5002 {
5003 if ( !(m_iFlags & wxPG_FL_MOUSE_INSIDE) )
5004 {
5005 // TODO: Fix this (detect parent and only do
5006 // cursor trick if it is a manager).
5007 wxASSERT( GetParent() );
5008 GetParent()->SetCursor(wxNullCursor);
5009
5010 m_iFlags |= wxPG_FL_MOUSE_INSIDE;
5011 }
5012 else
5013 GetParent()->SetCursor(wxNullCursor);
5014 }
5015 else if ( event.Leaving() )
5016 {
5017 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
39e4e221 5018 SetCursor( wxNullCursor );
1c4293cb
VZ
5019
5020 // Get real cursor position
5021 wxPoint pt = ScreenToClient(::wxGetMousePosition());
5022
5023 if ( ( pt.x <= 0 || pt.y <= 0 || pt.x >= m_width || pt.y >= m_height ) )
5024 {
5025 {
5026 if ( (m_iFlags & wxPG_FL_MOUSE_INSIDE) )
5027 {
5028 m_iFlags &= ~(wxPG_FL_MOUSE_INSIDE);
5029 }
5030
5031 if ( m_dragStatus )
5032 wxPropertyGrid::HandleMouseUp ( -1, 10000, event );
5033 }
5034 }
5035 }
5036
5037 event.Skip();
5038}
5039
5040// -----------------------------------------------------------------------
5041
5042// Common code used by various OnMouseXXXChild methods.
5043bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent &event, int* px, int *py )
5044{
5045 wxWindow* topCtrlWnd = (wxWindow*)event.GetEventObject();
5046 wxASSERT( topCtrlWnd );
5047 int x, y;
5048 event.GetPosition(&x,&y);
5049
1c4293cb
VZ
5050 int splitterX = GetSplitterPosition();
5051
5052 wxRect r = topCtrlWnd->GetRect();
5053 if ( !m_dragStatus &&
5054 x > (splitterX-r.x+wxPG_SPLITTERX_DETECTMARGIN2) &&
5055 y >= 0 && y < r.height \
5056 )
5057 {
5058 if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW );
5059 event.Skip();
5060 }
5061 else
5062 {
5063 CalcUnscrolledPosition( event.m_x + r.x, event.m_y + r.y, \
5064 px, py );
5065 return true;
5066 }
5067 return false;
5068}
5069
5070void wxPropertyGrid::OnMouseClickChild( wxMouseEvent &event )
5071{
5072 int x,y;
5073 if ( OnMouseChildCommon(event,&x,&y) )
5074 {
5075 bool res = HandleMouseClick(x,y,event);
5076 if ( !res ) event.Skip();
5077 }
5078}
5079
5080void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent &event )
5081{
5082 int x,y;
5083 wxASSERT( m_wndEditor );
5084 // These coords may not be exact (about +-2),
5085 // but that should not matter (right click is about item, not position).
5086 wxPoint pt = m_wndEditor->GetPosition();
5087 CalcUnscrolledPosition( event.m_x + pt.x, event.m_y + pt.y, &x, &y );
fc72fab6
JS
5088
5089 // FIXME: Used to set m_propHover to selection here. Was it really
5090 // necessary?
5091
1c4293cb
VZ
5092 bool res = HandleMouseRightClick(x,y,event);
5093 if ( !res ) event.Skip();
5094}
5095
5096void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent &event )
5097{
5098 int x,y;
5099 if ( OnMouseChildCommon(event,&x,&y) )
5100 {
5101 bool res = HandleMouseMove(x,y,event);
5102 if ( !res ) event.Skip();
5103 }
5104}
5105
5106void wxPropertyGrid::OnMouseUpChild( wxMouseEvent &event )
5107{
5108 int x,y;
5109 if ( OnMouseChildCommon(event,&x,&y) )
5110 {
5111 bool res = HandleMouseUp(x,y,event);
5112 if ( !res ) event.Skip();
5113 }
5114}
5115
5116// -----------------------------------------------------------------------
5117// wxPropertyGrid keyboard event handling
5118// -----------------------------------------------------------------------
5119
1c4293cb
VZ
5120int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const
5121{
5122 // Translates wxKeyEvent to wxPG_ACTION_XXX
5123
5124 int keycode = event.GetKeyCode();
5125 int modifiers = event.GetModifiers();
5126
5127 wxASSERT( !(modifiers&~(0xFFFF)) );
5128
5129 int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16);
5130
5131 wxPGHashMapI2I::const_iterator it = m_actionTriggers.find(hashMapKey);
5132
5133 if ( it == m_actionTriggers.end() )
5134 return 0;
5135
5136 if ( pSecond )
5137 {
5138 int second = (it->second>>16) & 0xFFFF;
5139 *pSecond = second;
5140 }
5141
5142 return (it->second & 0xFFFF);
5143}
5144
5145void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers )
5146{
5147 wxASSERT( !(modifiers&~(0xFFFF)) );
5148
5149 int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16);
5150
5151 wxPGHashMapI2I::iterator it = m_actionTriggers.find(hashMapKey);
5152
5153 if ( it != m_actionTriggers.end() )
5154 {
5155 // This key combination is already used
5156
5157 // Can add secondary?
5158 wxASSERT_MSG( !(it->second&~(0xFFFF)),
5159 wxT("You can only add up to two separate actions per key combination.") );
5160
5161 action = it->second | (action<<16);
5162 }
5163
5164 m_actionTriggers[hashMapKey] = action;
5165}
5166
5167void wxPropertyGrid::ClearActionTriggers( int action )
5168{
5169 wxPGHashMapI2I::iterator it;
36a2b429 5170 bool didSomething;
1c4293cb 5171
36a2b429 5172 do
1c4293cb 5173 {
36a2b429
JS
5174 didSomething = false;
5175
5176 for ( it = m_actionTriggers.begin();
5177 it != m_actionTriggers.end();
5178 it++ )
1c4293cb 5179 {
36a2b429
JS
5180 if ( it->second == action )
5181 {
5182 m_actionTriggers.erase(it);
5183 didSomething = true;
5184 break;
5185 }
1c4293cb
VZ
5186 }
5187 }
36a2b429 5188 while ( didSomething );
1c4293cb
VZ
5189}
5190
68f9e025 5191void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
1c4293cb
VZ
5192{
5193 //
5194 // Handles key event when editor control is not focused.
5195 //
5196
b7bc9d80 5197 wxCHECK2(!m_frozen, return);
1c4293cb
VZ
5198
5199 // Travelsal between items, collapsing/expanding, etc.
fc72fab6 5200 wxPGProperty* selected = GetSelection();
1c4293cb 5201 int keycode = event.GetKeyCode();
68f9e025 5202 bool editorFocused = IsEditorFocused();
1c4293cb
VZ
5203
5204 if ( keycode == WXK_TAB )
5205 {
b50e81c6
JS
5206 wxWindow* mainControl;
5207
5208 if ( HasInternalFlag(wxPG_FL_IN_MANAGER) )
5209 mainControl = GetParent();
5210 else
5211 mainControl = this;
5212
68f9e025
JS
5213 if ( !event.ShiftDown() )
5214 {
5215 if ( !editorFocused && m_wndEditor )
b50e81c6 5216 {
fc72fab6 5217 DoSelectProperty( selected, wxPG_SEL_FOCUS );
b50e81c6 5218 }
68f9e025 5219 else
b50e81c6
JS
5220 {
5221 // Tab traversal workaround for platforms on which
5222 // wxWindow::Navigate() may navigate into first child
5223 // instead of next sibling. Does not work perfectly
5224 // in every scenario (for instance, when property grid
5225 // is either first or last control).
5226 #if defined(__WXGTK__)
5227 wxWindow* sibling = mainControl->GetNextSibling();
5228 if ( sibling )
5229 sibling->SetFocusFromKbd();
5230 #else
68f9e025 5231 Navigate(wxNavigationKeyEvent::IsForward);
b50e81c6
JS
5232 #endif
5233 }
68f9e025
JS
5234 }
5235 else
5236 {
5237 if ( editorFocused )
b50e81c6 5238 {
68f9e025 5239 UnfocusEditor();
b50e81c6 5240 }
68f9e025 5241 else
b50e81c6
JS
5242 {
5243 #if defined(__WXGTK__)
5244 wxWindow* sibling = mainControl->GetPrevSibling();
5245 if ( sibling )
5246 sibling->SetFocusFromKbd();
5247 #else
68f9e025 5248 Navigate(wxNavigationKeyEvent::IsBackward);
b50e81c6
JS
5249 #endif
5250 }
68f9e025
JS
5251 }
5252
1c4293cb
VZ
5253 return;
5254 }
5255
5256 // Ignore Alt and Control when they are down alone
5257 if ( keycode == WXK_ALT ||
5258 keycode == WXK_CONTROL )
5259 {
5260 event.Skip();
5261 return;
5262 }
5263
5264 int secondAction;
5265 int action = KeyEventToActions(event, &secondAction);
5266
68f9e025 5267 if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT )
1c4293cb 5268 {
68f9e025
JS
5269 //
5270 // Esc cancels any changes
5271 if ( IsEditorsValueModified() )
5272 {
5273 EditorsValueWasNotModified();
1c4293cb 5274
68f9e025 5275 // Update the control as well
fc72fab6
JS
5276 selected->GetEditorClass()->
5277 SetControlStringValue( selected,
5278 GetEditorControl(),
5279 selected->GetDisplayedString() );
68f9e025
JS
5280 }
5281
fc72fab6 5282 OnValidationFailureReset(selected);
68f9e025
JS
5283
5284 UnfocusEditor();
5285 return;
5286 }
5287
5288 // Except for TAB and ESC, handle child control events in child control
5289 if ( fromChild )
4d11369d 5290 {
c12822fe
JS
5291 // Only propagate event if it had modifiers
5292 if ( !event.HasModifiers() )
5293 {
5294 event.StopPropagation();
5295 }
4d11369d 5296 event.Skip();
68f9e025 5297 return;
4d11369d
JS
5298 }
5299
5300 bool wasHandled = false;
68f9e025 5301
fc72fab6 5302 if ( selected )
68f9e025 5303 {
1c4293cb 5304 // Show dialog?
1766bf34 5305 if ( ButtonTriggerKeyTest(action, event) )
1c4293cb
VZ
5306 return;
5307
fc72fab6 5308 wxPGProperty* p = selected;
1c4293cb 5309
174b59ac
JS
5310 // Travel and expand/collapse
5311 int selectDir = -2;
5312
48f0334d 5313 if ( p->GetChildCount() )
1c4293cb 5314 {
174b59ac
JS
5315 if ( action == wxPG_ACTION_COLLAPSE_PROPERTY || secondAction == wxPG_ACTION_COLLAPSE_PROPERTY )
5316 {
5317 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Collapse(p) )
4d11369d 5318 wasHandled = true;
174b59ac
JS
5319 }
5320 else if ( action == wxPG_ACTION_EXPAND_PROPERTY || secondAction == wxPG_ACTION_EXPAND_PROPERTY )
5321 {
5322 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Expand(p) )
4d11369d 5323 wasHandled = true;
174b59ac 5324 }
1c4293cb 5325 }
1c4293cb 5326
4d11369d 5327 if ( !wasHandled )
174b59ac
JS
5328 {
5329 if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY )
1c4293cb 5330 {
174b59ac 5331 selectDir = -1;
1c4293cb 5332 }
174b59ac 5333 else if ( action == wxPG_ACTION_NEXT_PROPERTY || secondAction == wxPG_ACTION_NEXT_PROPERTY )
1c4293cb 5334 {
174b59ac 5335 selectDir = 1;
1c4293cb 5336 }
174b59ac
JS
5337 }
5338
5339 if ( selectDir >= -1 )
5340 {
5341 p = wxPropertyGridIterator::OneStep( m_pState, wxPG_ITERATE_VISIBLE, p, selectDir );
5342 if ( p )
5343 DoSelectProperty(p);
4d11369d 5344 wasHandled = true;
1c4293cb
VZ
5345 }
5346 }
5347 else
5348 {
5349 // If nothing was selected, select the first item now
5350 // (or navigate out of tab).
5351 if ( action != wxPG_ACTION_CANCEL_EDIT && secondAction != wxPG_ACTION_CANCEL_EDIT )
5352 {
5353 wxPGProperty* p = wxPropertyGridInterface::GetFirst();
5354 if ( p ) DoSelectProperty(p);
4d11369d 5355 wasHandled = true;
1c4293cb
VZ
5356 }
5357 }
4d11369d
JS
5358
5359 if ( !wasHandled )
5360 event.Skip();
1c4293cb
VZ
5361}
5362
5363// -----------------------------------------------------------------------
5364
1c4293cb
VZ
5365void wxPropertyGrid::OnKey( wxKeyEvent &event )
5366{
c12822fe
JS
5367 // If there was editor open and focused, then this event should not
5368 // really be processed here.
5369 if ( IsEditorFocused() )
5370 {
5371 // However, if event had modifiers, it is probably still best
5372 // to skip it.
5373 if ( event.HasModifiers() )
5374 event.Skip();
5375 else
5376 event.StopPropagation();
5377 return;
5378 }
5379
68f9e025 5380 HandleKeyEvent(event, false);
1c4293cb
VZ
5381}
5382
5383// -----------------------------------------------------------------------
5384
1766bf34 5385bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event )
1c4293cb 5386{
1766bf34
JS
5387 if ( action == -1 )
5388 {
5389 int secondAction;
5390 action = KeyEventToActions(event, &secondAction);
5391 }
1c4293cb
VZ
5392
5393 // Does the keycode trigger button?
1766bf34
JS
5394 if ( action == wxPG_ACTION_PRESS_BUTTON &&
5395 m_wndEditor2 )
1c4293cb 5396 {
1766bf34 5397 wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, m_wndEditor2->GetId());
1c4293cb
VZ
5398 GetEventHandler()->AddPendingEvent(evt);
5399 return true;
5400 }
5401
5402 return false;
5403}
5404
5405// -----------------------------------------------------------------------
5406
5407void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
5408{
68f9e025 5409 HandleKeyEvent(event, true);
1c4293cb
VZ
5410}
5411
5412// -----------------------------------------------------------------------
5413// wxPropertyGrid miscellaneous event handling
5414// -----------------------------------------------------------------------
5415
5416void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) )
5417{
5418 //
5419 // Check if the focus is in this control or one of its children
5420 wxWindow* newFocused = wxWindow::FindFocus();
5421
5422 if ( newFocused != m_curFocused )
5423 HandleFocusChange( newFocused );
6edd8829
JS
5424
5425 //
5426 // Check if top-level parent has changed
08c1613f 5427 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING )
6edd8829 5428 {
08c1613f
JS
5429 wxWindow* tlp = ::wxGetTopLevelParent(this);
5430 if ( tlp != m_tlp )
5431 OnTLPChanging(tlp);
6edd8829 5432 }
1c4293cb
VZ
5433}
5434
68f9e025
JS
5435bool wxPropertyGrid::IsEditorFocused() const
5436{
5437 wxWindow* focus = wxWindow::FindFocus();
5438
5439 if ( focus == m_wndEditor || focus == m_wndEditor2 ||
5440 focus == GetEditorControl() )
5441 return true;
5442
5443 return false;
5444}
5445
1c4293cb
VZ
5446// Called by focus event handlers. newFocused is the window that becomes focused.
5447void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
5448{
5449 unsigned int oldFlags = m_iFlags;
5450
5451 m_iFlags &= ~(wxPG_FL_FOCUSED);
5452
5453 wxWindow* parent = newFocused;
5454
5455 // This must be one of nextFocus' parents.
5456 while ( parent )
5457 {
5458 // Use m_eventObject, which is either wxPropertyGrid or
5459 // wxPropertyGridManager, as appropriate.
5460 if ( parent == m_eventObject )
5461 {
5462 m_iFlags |= wxPG_FL_FOCUSED;
5463 break;
5464 }
5465 parent = parent->GetParent();
5466 }
5467
5468 m_curFocused = newFocused;
5469
5470 if ( (m_iFlags & wxPG_FL_FOCUSED) !=
5471 (oldFlags & wxPG_FL_FOCUSED) )
5472 {
1c4293cb
VZ
5473 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
5474 {
1c4293cb
VZ
5475 // Need to store changed value
5476 CommitChangesFromEditor();
5477 }
5478 else
5479 {
5480 /*
5481 //
5482 // Preliminary code for tab-order respecting
5483 // tab-traversal (but should be moved to
5484 // OnNav handler)
5485 //
5486 wxWindow* prevFocus = event.GetWindow();
5487 wxWindow* useThis = this;
5488 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5489 useThis = GetParent();
5490
5491 if ( prevFocus &&
5492 prevFocus->GetParent() == useThis->GetParent() )
5493 {
5494 wxList& children = useThis->GetParent()->GetChildren();
5495
5496 wxNode* node = children.Find(prevFocus);
5497
5498 if ( node->GetNext() &&
5499 useThis == node->GetNext()->GetData() )
5500 DoSelectProperty(GetFirst());
5501 else if ( node->GetPrevious () &&
5502 useThis == node->GetPrevious()->GetData() )
5503 DoSelectProperty(GetLastProperty());
5504
5505 }
5506 */
1c4293cb
VZ
5507 }
5508
5509 // Redraw selected
fc72fab6
JS
5510 wxPGProperty* selected = GetSelection();
5511 if ( selected && (m_iFlags & wxPG_FL_INITIALIZED) )
5512 DrawItem( selected );
1c4293cb
VZ
5513 }
5514}
5515
5516void wxPropertyGrid::OnFocusEvent( wxFocusEvent& event )
5517{
5518 if ( event.GetEventType() == wxEVT_SET_FOCUS )
5519 HandleFocusChange((wxWindow*)event.GetEventObject());
5520 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5521 //else if ( event.GetWindow() )
5522 else
5523 HandleFocusChange(event.GetWindow());
5524
5525 event.Skip();
5526}
5527
5528// -----------------------------------------------------------------------
5529
5530void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent& event )
5531{
5532 HandleFocusChange((wxWindow*)event.GetEventObject());
8c5c56e2 5533 event.Skip();
1c4293cb
VZ
5534}
5535
5536// -----------------------------------------------------------------------
5537
5538void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent &event )
5539{
5540 m_iFlags |= wxPG_FL_SCROLLED;
5541
5542 event.Skip();
5543}
5544
5545// -----------------------------------------------------------------------
5546
5547void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent& WXUNUSED(event) )
5548{
5549 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
5550 {
5551 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
5552 }
5553}
5554
5555// -----------------------------------------------------------------------
5556// Property editor related functions
5557// -----------------------------------------------------------------------
5558
5559// noDefCheck = true prevents infinite recursion.
b7d19850
JS
5560wxPGEditor* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor* editorClass,
5561 const wxString& editorName,
5562 bool noDefCheck )
1c4293cb 5563{
7a344f1b 5564 wxASSERT( editorClass );
1c4293cb
VZ
5565
5566 if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() )
5567 RegisterDefaultEditors();
5568
b7d19850
JS
5569 wxString name = editorName;
5570 if ( name.length() == 0 )
5571 name = editorClass->GetName();
614fbbad
JS
5572
5573 // Existing editor under this name?
5574 wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5575
5a45dd6f
JS
5576 if ( vt_it != wxPGGlobalVars->m_mapEditorClasses.end() )
5577 {
5578 // If this name was already used, try class name.
5579 name = editorClass->GetClassInfo()->GetClassName();
5580 vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5581 }
5582
614fbbad
JS
5583 wxCHECK_MSG( vt_it == wxPGGlobalVars->m_mapEditorClasses.end(),
5584 (wxPGEditor*) vt_it->second,
5585 "Editor with given name was already registered" );
5586
7a344f1b 5587 wxPGGlobalVars->m_mapEditorClasses[name] = (void*)editorClass;
1c4293cb 5588
7a344f1b 5589 return editorClass;
1c4293cb
VZ
5590}
5591
52cefafe
JS
5592// Use this in RegisterDefaultEditors.
5593#define wxPGRegisterDefaultEditorClass(EDITOR) \
d3b9f782 5594 if ( wxPGEditor_##EDITOR == NULL ) \
52cefafe
JS
5595 { \
5596 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5597 new wxPG##EDITOR##Editor, true ); \
5598 }
5599
1c4293cb
VZ
5600// Registers all default editor classes
5601void wxPropertyGrid::RegisterDefaultEditors()
5602{
5603 wxPGRegisterDefaultEditorClass( TextCtrl );
5604 wxPGRegisterDefaultEditorClass( Choice );
5605 wxPGRegisterDefaultEditorClass( ComboBox );
5606 wxPGRegisterDefaultEditorClass( TextCtrlAndButton );
5607#if wxPG_INCLUDE_CHECKBOX
5608 wxPGRegisterDefaultEditorClass( CheckBox );
5609#endif
5610 wxPGRegisterDefaultEditorClass( ChoiceAndButton );
5611
5612 // Register SpinCtrl etc. editors before use
5613 RegisterAdditionalEditors();
5614}
5615
5616// -----------------------------------------------------------------------
5617// wxPGStringTokenizer
5618// Needed to handle C-style string lists (e.g. "str1" "str2")
5619// -----------------------------------------------------------------------
5620
5621wxPGStringTokenizer::wxPGStringTokenizer( const wxString& str, wxChar delimeter )
5622 : m_str(&str), m_curPos(str.begin()), m_delimeter(delimeter)
5623{
5624}
5625
5626wxPGStringTokenizer::~wxPGStringTokenizer()
5627{
5628}
5629
5630bool wxPGStringTokenizer::HasMoreTokens()
5631{
5632 const wxString& str = *m_str;
5633
5634 wxString::const_iterator i = m_curPos;
5635
5636 wxUniChar delim = m_delimeter;
5637 wxUniChar a;
5638 wxUniChar prev_a = wxT('\0');
5639
5640 bool inToken = false;
5641
5642 while ( i != str.end() )
5643 {
5644 a = *i;
5645
5646 if ( !inToken )
5647 {
5648 if ( a == delim )
5649 {
5650 inToken = true;
5651 m_readyToken.clear();
5652 }
5653 }
5654 else
5655 {
5656 if ( prev_a != wxT('\\') )
5657 {
5658 if ( a != delim )
5659 {
5660 if ( a != wxT('\\') )
5661 m_readyToken << a;
5662 }
5663 else
5664 {
b7bc9d80 5665 ++i;
1c4293cb
VZ
5666 m_curPos = i;
5667 return true;
5668 }
5669 prev_a = a;
5670 }
5671 else
5672 {
5673 m_readyToken << a;
5674 prev_a = wxT('\0');
5675 }
5676 }
b7bc9d80 5677 ++i;
1c4293cb
VZ
5678 }
5679
5680 m_curPos = str.end();
5681
5682 if ( inToken )
5683 return true;
5684
5685 return false;
5686}
5687
5688wxString wxPGStringTokenizer::GetNextToken()
5689{
5690 return m_readyToken;
5691}
5692
5693// -----------------------------------------------------------------------
5694// wxPGChoiceEntry
5695// -----------------------------------------------------------------------
5696
5697wxPGChoiceEntry::wxPGChoiceEntry()
5698 : wxPGCell(), m_value(wxPG_INVALID_VALUE)
5699{
5700}
5701
1c4293cb
VZ
5702// -----------------------------------------------------------------------
5703// wxPGChoicesData
5704// -----------------------------------------------------------------------
5705
5706wxPGChoicesData::wxPGChoicesData()
5707{
1c4293cb
VZ
5708}
5709
5710wxPGChoicesData::~wxPGChoicesData()
5711{
5712 Clear();
5713}
5714
5715void wxPGChoicesData::Clear()
5716{
f7a094e1 5717 m_items.clear();
1c4293cb
VZ
5718}
5719
5720void wxPGChoicesData::CopyDataFrom( wxPGChoicesData* data )
5721{
5722 wxASSERT( m_items.size() == 0 );
5723
d7e2b522
JS
5724 m_items = data->m_items;
5725}
1c4293cb 5726
d7e2b522
JS
5727wxPGChoiceEntry& wxPGChoicesData::Insert( int index,
5728 const wxPGChoiceEntry& item )
5729{
5730 wxVector<wxPGChoiceEntry>::iterator it;
5731 if ( index == -1 )
5732 {
5733 it = m_items.end();
5734 index = (int) m_items.size();
5735 }
5736 else
5737 {
5738 it = m_items.begin() + index;
5739 }
5740
5741 m_items.insert(it, item);
5742
5743 wxPGChoiceEntry& ownEntry = m_items[index];
5744
5745 // Need to fix value?
5746 if ( ownEntry.GetValue() == wxPG_INVALID_VALUE )
5747 ownEntry.SetValue(index);
5748
5749 return ownEntry;
1c4293cb
VZ
5750}
5751
1c4293cb
VZ
5752// -----------------------------------------------------------------------
5753// wxPropertyGridEvent
5754// -----------------------------------------------------------------------
5755
5756IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent, wxCommandEvent)
5757
5758
9b11752c
VZ
5759wxDEFINE_EVENT( wxEVT_PG_SELECTED, wxPropertyGridEvent );
5760wxDEFINE_EVENT( wxEVT_PG_CHANGING, wxPropertyGridEvent );
5761wxDEFINE_EVENT( wxEVT_PG_CHANGED, wxPropertyGridEvent );
5762wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED, wxPropertyGridEvent );
5763wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK, wxPropertyGridEvent );
5764wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED, wxPropertyGridEvent );
5765wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED, wxPropertyGridEvent );
5766wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent );
5767wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent );
58935d4a
JS
5768wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent );
5769wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent );
1c4293cb
VZ
5770
5771// -----------------------------------------------------------------------
5772
5773void wxPropertyGridEvent::Init()
5774{
5775 m_validationInfo = NULL;
58935d4a 5776 m_column = 1;
1c4293cb
VZ
5777 m_canVeto = false;
5778 m_wasVetoed = false;
5779}
5780
5781// -----------------------------------------------------------------------
5782
5783wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType, int id)
5784 : wxCommandEvent(commandType,id)
5785{
5786 m_property = NULL;
5787 Init();
5788}
5789
5790// -----------------------------------------------------------------------
5791
5792wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event)
5793 : wxCommandEvent(event)
5794{
5795 m_eventType = event.GetEventType();
5796 m_eventObject = event.m_eventObject;
5797 m_pg = event.m_pg;
644b283d 5798 OnPropertyGridSet();
1c4293cb
VZ
5799 m_property = event.m_property;
5800 m_validationInfo = event.m_validationInfo;
5801 m_canVeto = event.m_canVeto;
5802 m_wasVetoed = event.m_wasVetoed;
5803}
5804
5805// -----------------------------------------------------------------------
5806
644b283d
JS
5807void wxPropertyGridEvent::OnPropertyGridSet()
5808{
5809 if ( !m_pg )
5810 return;
5811
9370ec6a 5812#if wxUSE_THREADS
644b283d
JS
5813 wxCriticalSectionLocker(wxPGGlobalVars->m_critSect);
5814#endif
5815 m_pg->m_liveEvents.push_back(this);
5816}
5817
5818// -----------------------------------------------------------------------
5819
1c4293cb
VZ
5820wxPropertyGridEvent::~wxPropertyGridEvent()
5821{
644b283d
JS
5822 if ( m_pg )
5823 {
9370ec6a 5824 #if wxUSE_THREADS
644b283d
JS
5825 wxCriticalSectionLocker(wxPGGlobalVars->m_critSect);
5826 #endif
5827
5828 // Use iterate from the back since it is more likely that the event
5829 // being desroyed is at the end of the array.
5830 wxVector<wxPropertyGridEvent*>& liveEvents = m_pg->m_liveEvents;
5831
5832 for ( int i = liveEvents.size()-1; i >= 0; i-- )
5833 {
5834 if ( liveEvents[i] == this )
5835 {
5836 liveEvents.erase(liveEvents.begin() + i);
5837 break;
5838 }
5839 }
5840 }
1c4293cb
VZ
5841}
5842
5843// -----------------------------------------------------------------------
5844
5845wxEvent* wxPropertyGridEvent::Clone() const
5846{
5847 return new wxPropertyGridEvent( *this );
5848}
5849
1c4293cb
VZ
5850// -----------------------------------------------------------------------
5851// wxPropertyGridPopulator
5852// -----------------------------------------------------------------------
5853
5854wxPropertyGridPopulator::wxPropertyGridPopulator()
5855{
5856 m_state = NULL;
5857 m_pg = NULL;
5858 wxPGGlobalVars->m_offline++;
5859}
5860
5861// -----------------------------------------------------------------------
5862
5863void wxPropertyGridPopulator::SetState( wxPropertyGridPageState* state )
5864{
5865 m_state = state;
5866 m_propHierarchy.clear();
5867}
5868
5869// -----------------------------------------------------------------------
5870
5871void wxPropertyGridPopulator::SetGrid( wxPropertyGrid* pg )
5872{
5873 m_pg = pg;
5874 pg->Freeze();
5875}
5876
5877// -----------------------------------------------------------------------
5878
5879wxPropertyGridPopulator::~wxPropertyGridPopulator()
5880{
5881 //
5882 // Free unused sets of choices
5883 wxPGHashMapS2P::iterator it;
5884
5885 for( it = m_dictIdChoices.begin(); it != m_dictIdChoices.end(); ++it )
5886 {
5887 wxPGChoicesData* data = (wxPGChoicesData*) it->second;
5888 data->DecRef();
5889 }
5890
5891 if ( m_pg )
5892 {
5893 m_pg->Thaw();
5894 m_pg->GetPanel()->Refresh();
5895 }
5896 wxPGGlobalVars->m_offline--;
5897}
5898
5899// -----------------------------------------------------------------------
5900
5901wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass,
5902 const wxString& propLabel,
5903 const wxString& propName,
5904 const wxString* propValue,
5905 wxPGChoices* pChoices )
5906{
5907 wxClassInfo* classInfo = wxClassInfo::FindClass(propClass);
5908 wxPGProperty* parent = GetCurParent();
5909
5910 if ( parent->HasFlag(wxPG_PROP_AGGREGATE) )
5911 {
5912 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent->GetName().c_str()));
5913 return NULL;
5914 }
5915
5916 if ( !classInfo || !classInfo->IsKindOf(CLASSINFO(wxPGProperty)) )
5917 {
5918 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass.c_str()));
5919 return NULL;
5920 }
5921
5922 wxPGProperty* property = (wxPGProperty*) classInfo->CreateObject();
5923
5924 property->SetLabel(propLabel);
5925 property->DoSetName(propName);
5926
5927 if ( pChoices && pChoices->IsOk() )
5928 property->SetChoices(*pChoices);
5929
5930 m_state->DoInsert(parent, -1, property);
5931
5932 if ( propValue )
f275b5db
JS
5933 property->SetValueFromString( *propValue, wxPG_FULL_VALUE|
5934 wxPG_PROGRAMMATIC_VALUE );
1c4293cb
VZ
5935
5936 return property;
5937}
5938
5939// -----------------------------------------------------------------------
5940
5941void wxPropertyGridPopulator::AddChildren( wxPGProperty* property )
5942{
5943 m_propHierarchy.push_back(property);
5944 DoScanForChildren();
5945 m_propHierarchy.pop_back();
5946}
5947
5948// -----------------------------------------------------------------------
5949
5950wxPGChoices wxPropertyGridPopulator::ParseChoices( const wxString& choicesString,
5951 const wxString& idString )
5952{
5953 wxPGChoices choices;
5954
5955 // Using id?
5956 if ( choicesString[0] == wxT('@') )
5957 {
5958 wxString ids = choicesString.substr(1);
5959 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(ids);
5960 if ( it == m_dictIdChoices.end() )
5961 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids.c_str()));
5962 else
5963 choices.AssignData((wxPGChoicesData*)it->second);
5964 }
5965 else
5966 {
5967 bool found = false;
5968 if ( idString.length() )
5969 {
5970 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(idString);
5971 if ( it != m_dictIdChoices.end() )
5972 {
5973 choices.AssignData((wxPGChoicesData*)it->second);
5974 found = true;
5975 }
5976 }
5977
5978 if ( !found )
5979 {
5980 // Parse choices string
5981 wxString::const_iterator it = choicesString.begin();
5982 wxString label;
5983 wxString value;
5984 int state = 0;
5985 bool labelValid = false;
5986
b7bc9d80 5987 for ( ; it != choicesString.end(); ++it )
1c4293cb
VZ
5988 {
5989 wxChar c = *it;
5990
5991 if ( state != 1 )
5992 {
5993 if ( c == wxT('"') )
5994 {
5995 if ( labelValid )
5996 {
5997 long l;
5998 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5999 choices.Add(label, l);
6000 }
6001 labelValid = false;
6002 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6003 value.clear();
6004 label.clear();
6005 state = 1;
6006 }
6007 else if ( c == wxT('=') )
6008 {
6009 if ( labelValid )
6010 {
6011 state = 2;
6012 }
6013 }
6014 else if ( state == 2 && (wxIsalnum(c) || c == wxT('x')) )
6015 {
6016 value << c;
6017 }
6018 }
6019 else
6020 {
6021 if ( c == wxT('"') )
6022 {
6023 state = 0;
6024 labelValid = true;
6025 }
6026 else
6027 label << c;
6028 }
6029 }
6030
6031 if ( labelValid )
6032 {
6033 long l;
6034 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
6035 choices.Add(label, l);
6036 }
6037
6038 if ( !choices.IsOk() )
6039 {
6040 choices.EnsureData();
6041 }
6042
6043 // Assign to id
6044 if ( idString.length() )
6045 m_dictIdChoices[idString] = choices.GetData();
6046 }
6047 }
6048
6049 return choices;
6050}
6051
6052// -----------------------------------------------------------------------
6053
6054bool wxPropertyGridPopulator::ToLongPCT( const wxString& s, long* pval, long max )
6055{
6056 if ( s.Last() == wxT('%') )
6057 {
6058 wxString s2 = s.substr(0,s.length()-1);
6059 long val;
6060 if ( s2.ToLong(&val, 10) )
6061 {
6062 *pval = (val*max)/100;
6063 return true;
6064 }
6065 return false;
6066 }
6067
6068 return s.ToLong(pval, 10);
6069}
6070
6071// -----------------------------------------------------------------------
6072
6073bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
6074 const wxString& type,
6075 const wxString& value )
6076{
6077 int l = m_propHierarchy.size();
6078 if ( !l )
6079 return false;
6080
6081 wxPGProperty* p = m_propHierarchy[l-1];
6082 wxString valuel = value.Lower();
6083 wxVariant variant;
6084
6085 if ( type.length() == 0 )
6086 {
6087 long v;
6088
6089 // Auto-detect type
6090 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
6091 variant = true;
6092 else if ( valuel == wxT("false") || valuel == wxT("no") || valuel == wxT("0") )
6093 variant = false;
6094 else if ( value.ToLong(&v, 0) )
6095 variant = v;
6096 else
6097 variant = value;
6098 }
6099 else
6100 {
6101 if ( type == wxT("string") )
6102 {
6103 variant = value;
6104 }
6105 else if ( type == wxT("int") )
6106 {
6107 long v = 0;
6108 value.ToLong(&v, 0);
6109 variant = v;
6110 }
6111 else if ( type == wxT("bool") )
6112 {
6113 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
6114 variant = true;
6115 else
6116 variant = false;
6117 }
6118 else
6119 {
6120 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type.c_str()));
6121 return false;
6122 }
6123 }
6124
6125 p->SetAttribute( name, variant );
6126
6127 return true;
6128}
6129
6130// -----------------------------------------------------------------------
6131
6132void wxPropertyGridPopulator::ProcessError( const wxString& msg )
6133{
6134 wxLogError(_("Error in resource: %s"),msg.c_str());
6135}
6136
6137// -----------------------------------------------------------------------
f4bc1aa2
JS
6138
6139#endif // wxUSE_PROPGRID