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