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