1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.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"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
67 // Two pics for the expand / collapse buttons.
68 // Files are not supplied with this project (since it is
69 // recommended to use either custom or native rendering).
70 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
71 // and copy xpm files from archive to wxPropertyGrid src directory
72 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
73 // and set wxPG_USE_RENDERER_NATIVE to 0).
74 #ifndef wxPG_ICON_WIDTH
75 #if defined(__WXMAC__)
76 #include "mac_collapse.xpm"
77 #include "mac_expand.xpm"
78 #elif defined(__WXGTK__)
79 #include "linux_collapse.xpm"
80 #include "linux_expand.xpm"
82 #include "default_collapse.xpm"
83 #include "default_expand.xpm"
88 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
89 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
90 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
91 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
92 #define wxPG_YSPACING_MIN 1
93 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
94 // but causes normal combobox to spill out under MSW
96 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
98 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
99 // Must be larger than largest control border
103 #define wxPG_DEFAULT_CURSOR wxNullCursor
106 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
108 //#define wxPG_HIDER_BUTTON_HEIGHT 25
110 #define wxPG_PIXELS_PER_UNIT m_lineHeight
112 #ifdef wxPG_ICON_WIDTH
113 #define m_iconHeight m_iconWidth
116 //#define wxPG_TOOLTIP_DELAY 1000
118 // This is the number of pixels the expander button inside
119 // property cells (i.e. not in the grey margin area are
121 #define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
123 // -----------------------------------------------------------------------
126 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
128 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
131 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
134 // -----------------------------------------------------------------------
136 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
138 // -----------------------------------------------------------------------
139 // Statics in one class for easy destruction.
140 // -----------------------------------------------------------------------
142 #include "wx/module.h"
144 class wxPGGlobalVarsClassManager
: public wxModule
146 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
148 wxPGGlobalVarsClassManager() {}
149 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
150 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
153 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
156 // When wxPG is loaded dynamically after the application is already running
157 // then the built-in module system won't pick this one up. Add it manually.
158 void wxPGInitResourceModule()
160 wxModule
* module = new wxPGGlobalVarsClassManager
;
162 wxModule::RegisterModule(module);
165 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
168 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
170 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
172 m_boolChoices
.Add(_("False"));
173 m_boolChoices
.Add(_("True"));
175 m_fontFamilyChoices
= NULL
;
177 m_defaultRenderer
= new wxPGDefaultRenderer();
179 m_autoGetTranslation
= false;
187 // Prepare some shared variants
188 m_vEmptyString
= wxString();
190 m_vMinusOne
= (long) -1;
194 // Prepare cached string constants
195 m_strstring
= wxS("string");
196 m_strlong
= wxS("long");
197 m_strbool
= wxS("bool");
198 m_strlist
= wxS("list");
199 m_strDefaultValue
= wxS("DefaultValue");
200 m_strMin
= wxS("Min");
201 m_strMax
= wxS("Max");
202 m_strUnits
= wxS("Units");
203 m_strInlineHelp
= wxS("InlineHelp");
209 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
213 delete m_defaultRenderer
;
215 // This will always have one ref
216 delete m_fontFamilyChoices
;
219 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
220 delete ((wxValidator
*)m_arrValidators
[i
]);
224 // Destroy value type class instances.
225 wxPGHashMapS2P::iterator vt_it
;
227 // Destroy editor class instances.
228 // iterate over all the elements in the class
229 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
231 delete ((wxPGEditor
*)vt_it
->second
);
234 delete wxPGProperty::sm_wxPG_LABEL
;
237 void wxPropertyGridInitGlobalsIfNeeded()
241 // -----------------------------------------------------------------------
243 // -----------------------------------------------------------------------
245 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
247 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
248 EVT_IDLE(wxPropertyGrid::OnIdle
)
249 EVT_PAINT(wxPropertyGrid::OnPaint
)
250 EVT_SIZE(wxPropertyGrid::OnResize
)
251 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
252 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
253 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
254 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
255 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
256 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
257 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
258 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
259 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
260 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
261 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
262 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
263 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
264 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
267 // -----------------------------------------------------------------------
269 wxPropertyGrid::wxPropertyGrid()
275 // -----------------------------------------------------------------------
277 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
282 const wxString
& name
)
286 Create(parent
,id
,pos
,size
,style
,name
);
289 // -----------------------------------------------------------------------
291 bool wxPropertyGrid::Create( wxWindow
*parent
,
296 const wxString
& name
)
299 if (!(style
&wxBORDER_MASK
))
301 style
|= wxBORDER_THEME
;
306 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
307 style
&= ~(wxTAB_TRAVERSAL
);
308 style
|= wxWANTS_CHARS
;
310 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
317 // -----------------------------------------------------------------------
320 // Initialize values to defaults
322 void wxPropertyGrid::Init1()
324 // Register editor classes, if necessary.
325 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
326 wxPropertyGrid::RegisterDefaultEditors();
330 m_wndEditor
= m_wndEditor2
= NULL
;
334 m_labelEditor
= NULL
;
335 m_labelEditorProperty
= NULL
;
336 m_eventObject
= this;
338 m_processedEvent
= NULL
;
339 m_sortFunction
= NULL
;
340 m_inDoPropertyChanged
= 0;
341 m_inCommitChangesFromEditor
= 0;
342 m_inDoSelectProperty
= 0;
343 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
348 // Must set empty but valid data
349 m_unspecifiedAppearance
.SetEmptyData();
352 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
353 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
354 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
355 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
356 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
357 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
358 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
359 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
360 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
362 m_coloursCustomized
= 0;
365 #if wxPG_DOUBLE_BUFFER
366 m_doubleBuffer
= NULL
;
369 #ifndef wxPG_ICON_WIDTH
375 m_iconWidth
= wxPG_ICON_WIDTH
;
380 m_gutterWidth
= wxPG_GUTTER_MIN
;
381 m_subgroup_extramargin
= 10;
385 m_width
= m_height
= 0;
387 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
390 m_chgInfo_changedProperty
= NULL
;
393 // -----------------------------------------------------------------------
396 // Initialize after parent etc. set
398 void wxPropertyGrid::Init2()
400 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
403 // Smaller controls on Mac
404 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
407 // Now create state, if one didn't exist already
408 // (wxPropertyGridManager might have created it for us).
411 m_pState
= CreateState();
412 m_pState
->m_pPropGrid
= this;
413 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
416 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
417 m_pState
->m_dontCenterSplitter
= true;
419 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
421 m_pState
->InitNonCatMode();
423 m_pState
->m_properties
= m_pState
->m_abcArray
;
426 GetClientSize(&m_width
,&m_height
);
428 #ifndef wxPG_ICON_WIDTH
429 // create two bitmap nodes for drawing
430 m_expandbmp
= new wxBitmap(expand_xpm
);
431 m_collbmp
= new wxBitmap(collapse_xpm
);
433 // calculate average font height for bitmap centering
435 m_iconWidth
= m_expandbmp
->GetWidth();
436 m_iconHeight
= m_expandbmp
->GetHeight();
439 m_curcursor
= wxCURSOR_ARROW
;
440 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
442 // adjust bitmap icon y position so they are centered
443 m_vspacing
= wxPG_DEFAULT_VSPACING
;
445 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
447 // Allocate cell datas
448 m_propertyDefaultCell
.SetEmptyData();
449 m_categoryDefaultCell
.SetEmptyData();
453 // This helps with flicker
454 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
456 // Hook the top-level parent
461 // set virtual size to this window size
462 wxSize wndsize
= GetSize();
463 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
465 m_timeCreated
= ::wxGetLocalTimeMillis();
467 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
468 // wxWANTS_CHARS | wxCLIP_CHILDREN);
469 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
471 m_iFlags
|= wxPG_FL_INITIALIZED
;
473 m_ncWidth
= wndsize
.GetWidth();
475 // Need to call OnResize handler or size given in constructor/Create
477 wxSizeEvent
sizeEvent(wndsize
,0);
481 // -----------------------------------------------------------------------
483 wxPropertyGrid::~wxPropertyGrid()
488 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
492 // Remove grid and property pointers from live wxPropertyGridEvents.
493 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
495 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
496 evt
->SetPropertyGrid(NULL
);
497 evt
->SetProperty(NULL
);
499 m_liveEvents
.clear();
501 if ( m_processedEvent
)
503 // All right... we are being deleted while wxPropertyGrid event
504 // is being sent. Make sure that event propagates as little
505 // as possible (although usually this is not enough to prevent
507 m_processedEvent
->Skip(false);
508 m_processedEvent
->StopPropagation();
510 // Let's use wxMessageBox to make the message appear more
511 // reliably (and *before* the crash can happen).
512 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
513 "generated by it. This usually leads to a crash "
514 "so it is recommended to destroy the control "
515 "at idle time instead.");
518 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
520 // This should do prevent things from going too badly wrong
521 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
523 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
526 // Call with NULL to disconnect event handling
527 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
531 wxASSERT_MSG( !IsEditorsValueModified(),
532 wxS("Most recent change in property editor was ")
533 wxS("lost!!! (if you don't want this to happen, ")
534 wxS("close your frames and dialogs using ")
535 wxS("Close(false).)") );
538 #if wxPG_DOUBLE_BUFFER
539 if ( m_doubleBuffer
)
540 delete m_doubleBuffer
;
543 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
546 delete m_cursorSizeWE
;
548 #ifndef wxPG_ICON_WIDTH
553 // Delete common value records
554 for ( i
=0; i
<m_commonValues
.size(); i
++ )
556 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
557 wxPGCommonValue
* value
= m_commonValues
[i
];
562 // -----------------------------------------------------------------------
564 bool wxPropertyGrid::Destroy()
566 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
569 return wxScrolledWindow::Destroy();
572 // -----------------------------------------------------------------------
574 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
576 return new wxPropertyGridPageState();
579 // -----------------------------------------------------------------------
580 // wxPropertyGrid overridden wxWindow methods
581 // -----------------------------------------------------------------------
583 void wxPropertyGrid::SetWindowStyleFlag( long style
)
585 long old_style
= m_windowStyle
;
587 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
589 wxASSERT( m_pState
);
591 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
594 EnableCategories( true );
596 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
598 // Disable categories
599 EnableCategories( false );
601 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
607 PrepareAfterItemsAdded();
609 m_pState
->m_itemsAdded
= 1;
611 #if wxPG_SUPPORT_TOOLTIPS
612 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
618 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
619 SetToolTip ( tooltip );
620 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
623 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
628 wxScrolledWindow::SetToolTip( NULL
);
633 wxScrolledWindow::SetWindowStyleFlag ( style
);
635 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
637 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
639 CalculateFontAndBitmapStuff( m_vspacing
);
645 // -----------------------------------------------------------------------
647 void wxPropertyGrid::Freeze()
651 wxScrolledWindow::Freeze();
656 // -----------------------------------------------------------------------
658 void wxPropertyGrid::Thaw()
664 wxScrolledWindow::Thaw();
665 RecalculateVirtualSize();
666 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
670 // Force property re-selection
671 // NB: We must copy the selection.
672 wxArrayPGProperty selection
= m_pState
->m_selection
;
673 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
677 // -----------------------------------------------------------------------
679 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
681 wxCHECK( prop
, false );
683 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
684 return DoSelectProperty(prop
, selFlags
);
686 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
688 if ( !selection
.size() )
690 return DoSelectProperty(prop
, selFlags
);
694 // For categories, only one can be selected at a time
695 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
698 selection
.push_back(prop
);
700 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
702 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
711 // -----------------------------------------------------------------------
713 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
715 wxCHECK( prop
, false );
718 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
719 if ( selection
.size() <= 1 )
721 res
= DoSelectProperty(NULL
, selFlags
);
725 m_pState
->DoRemoveFromSelection(prop
);
733 // -----------------------------------------------------------------------
735 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
736 unsigned int colIndex
,
737 unsigned int selFlags
)
740 // NB: Enable following if label editor background colour is
741 // ever changed to any other than m_colSelBack.
743 // We use this workaround to prevent visible flicker when editing
744 // a cell. Atleast on wxMSW, there is a difficult to find
745 // (and perhaps prevent) redraw somewhere between making property
746 // selected and enabling label editing.
748 //wxColour prevColSelBack = m_colSelBack;
749 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
755 res
= DoSelectProperty(prop
, selFlags
);
760 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
762 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
764 res
= DoAddToSelection(prop
, selFlags
);
768 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
770 DoBeginLabelEdit(colIndex
, selFlags
);
774 //m_colSelBack = prevColSelBack;
778 // -----------------------------------------------------------------------
780 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
781 unsigned int colIndex
,
782 wxMouseEvent
* mouseEvent
,
785 const wxArrayPGProperty
& selection
= GetSelectedProperties();
786 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
789 // Set to 2 if also add all items in between
790 int addToExistingSelection
= 0;
792 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
796 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
797 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
799 // Allow right-click for context menu without
800 // disturbing the selection.
801 if ( GetSelectedProperties().size() <= 1 ||
803 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
808 if ( mouseEvent
->ControlDown() )
810 addToExistingSelection
= 1;
812 else if ( mouseEvent
->ShiftDown() )
814 if ( selection
.size() > 0 && !prop
->IsCategory() )
815 addToExistingSelection
= 2;
817 addToExistingSelection
= 1;
823 if ( addToExistingSelection
== 1 )
826 if ( !alreadySelected
)
828 res
= DoAddToSelection(prop
, selFlags
);
830 else if ( GetSelectedProperties().size() > 1 )
832 res
= DoRemoveFromSelection(prop
, selFlags
);
835 else if ( addToExistingSelection
== 2 )
837 // Add this, and all in between
839 // Find top selected property
840 wxPGProperty
* topSelProp
= selection
[0];
841 int topSelPropY
= topSelProp
->GetY();
842 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
844 wxPGProperty
* p
= selection
[i
];
846 if ( y
< topSelPropY
)
853 wxPGProperty
* startFrom
;
854 wxPGProperty
* stopAt
;
856 if ( prop
->GetY() <= topSelPropY
)
858 // Property is above selection (or same)
864 // Property is below selection
865 startFrom
= topSelProp
;
869 // Iterate through properties in-between, and select them
870 wxPropertyGridIterator it
;
872 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
876 wxPGProperty
* p
= *it
;
878 if ( !p
->IsCategory() &&
879 !m_pState
->DoIsPropertySelected(p
) )
881 DoAddToSelection(p
, selFlags
);
890 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
896 // -----------------------------------------------------------------------
898 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
901 if ( newSelection
.size() > 0 )
903 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
908 DoClearSelection(false, selFlags
);
911 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
913 DoAddToSelection(newSelection
[i
], selFlags
);
919 // -----------------------------------------------------------------------
921 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
924 wxASSERT( column
!= 1 );
926 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
930 cols
.push_back(column
);
934 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
936 if ( cols
[i
] == (int)column
)
937 cols
.erase( cols
.begin() + i
);
942 // -----------------------------------------------------------------------
944 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
947 wxPGProperty
* selected
= GetSelection();
948 wxCHECK_RET(selected
, wxT("No property selected"));
949 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
951 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
953 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
960 const wxPGCell
* cell
= NULL
;
961 if ( selected
->HasCell(colIndex
) )
963 cell
= &selected
->GetCell(colIndex
);
964 if ( !cell
->HasText() && colIndex
== 0 )
965 text
= selected
->GetLabel();
971 text
= selected
->GetLabel();
973 cell
= &selected
->GetOrCreateCell(colIndex
);
976 if ( cell
&& cell
->HasText() )
977 text
= cell
->GetText();
979 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
981 m_selColumn
= colIndex
;
983 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
985 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
993 wxWindowID id
= tc
->GetId();
994 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
995 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
997 tc
->Connect(id
, wxEVT_KEY_DOWN
,
998 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1003 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1004 m_labelEditorProperty
= selected
;
1007 // -----------------------------------------------------------------------
1010 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1012 DoEndLabelEdit(true);
1015 // -----------------------------------------------------------------------
1017 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1019 int keycode
= event
.GetKeyCode();
1021 if ( keycode
== WXK_ESCAPE
)
1023 DoEndLabelEdit(false);
1031 // -----------------------------------------------------------------------
1033 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1035 if ( !m_labelEditor
)
1038 wxPGProperty
* prop
= m_labelEditorProperty
;
1043 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1045 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1046 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1047 prop
, NULL
, selFlags
,
1052 wxString text
= m_labelEditor
->GetValue();
1053 wxPGCell
* cell
= NULL
;
1054 if ( prop
->HasCell(m_selColumn
) )
1056 cell
= &prop
->GetCell(m_selColumn
);
1060 if ( m_selColumn
== 0 )
1061 prop
->SetLabel(text
);
1063 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1067 cell
->SetText(text
);
1072 DestroyEditorWnd(m_labelEditor
);
1073 m_labelEditor
= NULL
;
1074 m_labelEditorProperty
= NULL
;
1079 // -----------------------------------------------------------------------
1081 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1083 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1084 OnTLPChanging(::wxGetTopLevelParent(this));
1086 OnTLPChanging(NULL
);
1088 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1090 #if defined(__WXMSW__)
1093 // Don't use WS_EX_COMPOSITED just now.
1096 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1097 hWnd = (HWND)GetParent()->GetHWND();
1099 hWnd = (HWND)GetHWND();
1101 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1102 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1105 //#elif defined(__WXGTK20__)
1107 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1108 // truly was double-buffered.
1109 if ( !this->IsDoubleBuffered() )
1111 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1115 #if wxPG_DOUBLE_BUFFER
1116 delete m_doubleBuffer
;
1117 m_doubleBuffer
= NULL
;
1122 wxScrolledWindow::SetExtraStyle( exStyle
);
1124 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1125 m_pState
->InitNonCatMode();
1127 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1128 m_windowStyle
|= wxPG_TOOLTIPS
;
1131 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1134 // -----------------------------------------------------------------------
1136 // returns the best acceptable minimal size
1137 wxSize
wxPropertyGrid::DoGetBestSize() const
1139 int lineHeight
= wxMax(15, m_lineHeight
);
1141 // don't make the grid too tall (limit height to 10 items) but don't
1142 // make it too small neither
1143 int numLines
= wxMin
1145 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1149 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1150 int width
= m_marginWidth
;
1151 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1153 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1156 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1162 // -----------------------------------------------------------------------
1164 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1166 if ( newTLP
== m_tlp
)
1169 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1172 // Parent changed so let's redetermine and re-hook the
1173 // correct top-level window.
1176 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1177 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1179 m_tlpClosed
= m_tlp
;
1180 m_tlpClosedTime
= currentTime
;
1185 // Only accept new tlp if same one was not just dismissed.
1186 if ( newTLP
!= m_tlpClosed
||
1187 m_tlpClosedTime
+250 < currentTime
)
1189 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1190 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1203 // -----------------------------------------------------------------------
1205 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1207 // ClearSelection forces value validation/commit.
1208 if ( event
.CanVeto() && !DoClearSelection() )
1214 // Ok, it can close, set tlp pointer to NULL. Some other event
1215 // handler can of course veto the close, but our OnIdle() should
1216 // then be able to regain the tlp pointer.
1217 OnTLPChanging(NULL
);
1222 // -----------------------------------------------------------------------
1224 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1226 OnTLPChanging((wxWindow
*)newParent
);
1228 bool res
= wxScrolledWindow::Reparent(newParent
);
1233 // -----------------------------------------------------------------------
1234 // wxPropertyGrid Font and Colour Methods
1235 // -----------------------------------------------------------------------
1237 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1241 m_captionFont
= wxScrolledWindow::GetFont();
1243 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1244 m_subgroup_extramargin
= x
+ (x
/2);
1247 #if wxPG_USE_RENDERER_NATIVE
1248 m_iconWidth
= wxPG_ICON_WIDTH
;
1249 #elif wxPG_ICON_WIDTH
1251 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1252 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1253 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1257 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1258 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1259 m_gutterWidth
= wxPG_GUTTER_MIN
;
1262 if ( vspacing
<= 1 ) vdiv
= 12;
1263 else if ( vspacing
>= 3 ) vdiv
= 3;
1265 m_spacingy
= m_fontHeight
/ vdiv
;
1266 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1267 m_spacingy
= wxPG_YSPACING_MIN
;
1270 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1271 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1273 m_captionFont
.SetWeight(wxBOLD
);
1274 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1276 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1279 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1280 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1283 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1285 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1286 RecalculateVirtualSize();
1288 InvalidateBestSize();
1291 // -----------------------------------------------------------------------
1293 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1299 // -----------------------------------------------------------------------
1301 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1302 int ga
= 1000, int ba
= 1000,
1303 bool forceDifferent
= false)
1310 // Recursion guard (allow 2 max)
1311 static int isinside
= 0;
1313 wxCHECK_MSG( isinside
< 3,
1315 wxT("wxPGAdjustColour should not be recursively called more than once") );
1320 int g
= src
.Green();
1323 if ( r2
>255 ) r2
= 255;
1324 else if ( r2
<0) r2
= 0;
1326 if ( g2
>255 ) g2
= 255;
1327 else if ( g2
<0) g2
= 0;
1329 if ( b2
>255 ) b2
= 255;
1330 else if ( b2
<0) b2
= 0;
1332 // Make sure they are somewhat different
1333 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1334 dst
= wxPGAdjustColour(src
,-(ra
*2));
1336 dst
= wxColour(r2
,g2
,b2
);
1338 // Recursion guard (allow 2 max)
1345 static int wxPGGetColAvg( const wxColour
& col
)
1347 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1351 void wxPropertyGrid::RegainColours()
1353 if ( !(m_coloursCustomized
& 0x0002) )
1355 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1357 // Make sure colour is dark enough
1359 int colDec
= wxPGGetColAvg(col
) - 230;
1361 int colDec
= wxPGGetColAvg(col
) - 200;
1364 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1367 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1370 if ( !(m_coloursCustomized
& 0x0001) )
1371 m_colMargin
= m_colCapBack
;
1373 if ( !(m_coloursCustomized
& 0x0004) )
1380 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1381 m_colCapFore
= capForeCol
;
1382 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1385 if ( !(m_coloursCustomized
& 0x0008) )
1387 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1388 m_colPropBack
= bgCol
;
1389 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1390 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1391 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1394 if ( !(m_coloursCustomized
& 0x0010) )
1396 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1397 m_colPropFore
= fgCol
;
1398 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1399 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1400 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1403 if ( !(m_coloursCustomized
& 0x0020) )
1404 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1406 if ( !(m_coloursCustomized
& 0x0040) )
1407 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1409 if ( !(m_coloursCustomized
& 0x0080) )
1410 m_colLine
= m_colCapBack
;
1412 if ( !(m_coloursCustomized
& 0x0100) )
1413 m_colDisPropFore
= m_colCapFore
;
1415 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1418 // -----------------------------------------------------------------------
1420 void wxPropertyGrid::ResetColours()
1422 m_coloursCustomized
= 0;
1429 // -----------------------------------------------------------------------
1431 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1433 // Must disable active editor.
1436 bool res
= wxScrolledWindow::SetFont( font
);
1437 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1439 CalculateFontAndBitmapStuff( m_vspacing
);
1446 // -----------------------------------------------------------------------
1448 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1451 m_coloursCustomized
|= 0x80;
1455 // -----------------------------------------------------------------------
1457 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1460 m_coloursCustomized
|= 0x01;
1464 // -----------------------------------------------------------------------
1466 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1468 m_colPropBack
= col
;
1469 m_coloursCustomized
|= 0x08;
1471 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1472 m_unspecifiedAppearance
.SetBgCol(col
);
1477 // -----------------------------------------------------------------------
1479 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1481 m_colPropFore
= col
;
1482 m_coloursCustomized
|= 0x10;
1484 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1485 m_unspecifiedAppearance
.SetFgCol(col
);
1490 // -----------------------------------------------------------------------
1492 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1494 m_colEmptySpace
= col
;
1499 // -----------------------------------------------------------------------
1501 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1503 m_colDisPropFore
= col
;
1504 m_coloursCustomized
|= 0x100;
1508 // -----------------------------------------------------------------------
1510 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1513 m_coloursCustomized
|= 0x20;
1517 // -----------------------------------------------------------------------
1519 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1522 m_coloursCustomized
|= 0x40;
1526 // -----------------------------------------------------------------------
1528 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1531 m_coloursCustomized
|= 0x02;
1533 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1538 // -----------------------------------------------------------------------
1540 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1543 m_coloursCustomized
|= 0x04;
1545 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1550 // -----------------------------------------------------------------------
1551 // wxPropertyGrid property adding and removal
1552 // -----------------------------------------------------------------------
1554 void wxPropertyGrid::PrepareAfterItemsAdded()
1556 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1558 m_pState
->m_itemsAdded
= 0;
1560 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1561 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1563 RecalculateVirtualSize();
1566 // -----------------------------------------------------------------------
1567 // wxPropertyGrid property operations
1568 // -----------------------------------------------------------------------
1570 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1572 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1576 bool changed
= false;
1578 // Is it inside collapsed section?
1579 if ( !p
->IsVisible() )
1582 wxPGProperty
* parent
= p
->GetParent();
1583 wxPGProperty
* grandparent
= parent
->GetParent();
1585 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1586 Expand( grandparent
);
1594 GetViewStart(&vx
,&vy
);
1595 vy
*=wxPG_PIXELS_PER_UNIT
;
1601 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1602 m_iFlags
|= wxPG_FL_SCROLLED
;
1605 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1607 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1608 m_iFlags
|= wxPG_FL_SCROLLED
;
1618 // -----------------------------------------------------------------------
1619 // wxPropertyGrid helper methods called by properties
1620 // -----------------------------------------------------------------------
1622 // Control font changer helper.
1623 void wxPropertyGrid::SetCurControlBoldFont()
1625 wxASSERT( m_wndEditor
);
1626 m_wndEditor
->SetFont( m_captionFont
);
1629 // -----------------------------------------------------------------------
1631 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1634 #if wxPG_SMALL_SCREEN
1635 // On small-screen devices, always show dialogs with default position and size.
1636 return wxDefaultPosition
;
1638 int splitterX
= GetSplitterPosition();
1642 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1644 ImprovedClientToScreen( &x
, &y
);
1646 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1647 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1654 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1664 new_y
= y
+ m_lineHeight
;
1666 return wxPoint(new_x
,new_y
);
1670 // -----------------------------------------------------------------------
1672 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1674 if ( src_str
.length() == 0 )
1680 bool prev_is_slash
= false;
1682 wxString::const_iterator i
= src_str
.begin();
1686 for ( ; i
!= src_str
.end(); ++i
)
1690 if ( a
!= wxS('\\') )
1692 if ( !prev_is_slash
)
1698 if ( a
== wxS('n') )
1701 dst_str
<< wxS('\n');
1703 dst_str
<< wxS('\n');
1706 else if ( a
== wxS('t') )
1707 dst_str
<< wxS('\t');
1711 prev_is_slash
= false;
1715 if ( prev_is_slash
)
1717 dst_str
<< wxS('\\');
1718 prev_is_slash
= false;
1722 prev_is_slash
= true;
1729 // -----------------------------------------------------------------------
1731 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1733 if ( src_str
.length() == 0 )
1739 wxString::const_iterator i
= src_str
.begin();
1740 wxUniChar prev_a
= wxS('\0');
1744 for ( ; i
!= src_str
.end(); ++i
)
1748 if ( a
>= wxS(' ') )
1750 // This surely is not something that requires an escape sequence.
1755 // This might need...
1756 if ( a
== wxS('\r') )
1758 // DOS style line end.
1759 // Already taken care below
1761 else if ( a
== wxS('\n') )
1762 // UNIX style line end.
1763 dst_str
<< wxS("\\n");
1764 else if ( a
== wxS('\t') )
1766 dst_str
<< wxS('\t');
1769 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1779 // -----------------------------------------------------------------------
1781 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1788 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1791 // -----------------------------------------------------------------------
1792 // wxPropertyGrid graphics related methods
1793 // -----------------------------------------------------------------------
1795 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1800 // Don't paint after destruction has begun
1801 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1804 // Find out where the window is scrolled to
1805 int vx
,vy
; // Top left corner of client
1806 GetViewStart(&vx
,&vy
);
1807 vy
*= wxPG_PIXELS_PER_UNIT
;
1809 // Update everything inside the box
1810 wxRect r
= GetUpdateRegion().GetBox();
1814 // FIXME: This is just a workaround for a bug that causes splitters not
1815 // to paint when other windows are being dragged over the grid.
1817 r
.width
= GetClientSize().x
;
1819 // Repaint this rectangle
1820 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1822 // We assume that the size set when grid is shown
1823 // is what is desired.
1824 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1827 // -----------------------------------------------------------------------
1829 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1830 wxPGProperty
* property
) const
1832 // Prepare rectangle to be used
1834 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1835 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1837 #if (wxPG_USE_RENDERER_NATIVE)
1839 #elif wxPG_ICON_WIDTH
1840 // Drawing expand/collapse button manually
1841 dc
.SetPen(m_colPropFore
);
1842 if ( property
->IsCategory() )
1843 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1845 dc
.SetBrush(m_colPropBack
);
1847 dc
.DrawRectangle( r
);
1848 int _y
= r
.y
+(m_iconWidth
/2);
1849 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1854 if ( property
->IsExpanded() )
1856 // wxRenderer functions are non-mutating in nature, so it
1857 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1858 // Hopefully this does not cause problems.
1859 #if (wxPG_USE_RENDERER_NATIVE)
1860 wxRendererNative::Get().DrawTreeItemButton(
1866 #elif wxPG_ICON_WIDTH
1875 #if (wxPG_USE_RENDERER_NATIVE)
1876 wxRendererNative::Get().DrawTreeItemButton(
1882 #elif wxPG_ICON_WIDTH
1883 int _x
= r
.x
+(m_iconWidth
/2);
1884 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1890 #if (wxPG_USE_RENDERER_NATIVE)
1892 #elif wxPG_ICON_WIDTH
1895 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1899 // -----------------------------------------------------------------------
1902 // This is the one called by OnPaint event handler and others.
1903 // topy and bottomy are already unscrolled (ie. physical)
1905 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1906 unsigned int topItemY
,
1907 unsigned int bottomItemY
,
1908 const wxRect
* drawRect
)
1912 bottomItemY
< topItemY
||
1916 m_pState
->EnsureVirtualHeight();
1918 wxRect tempDrawRect
;
1921 tempDrawRect
= wxRect(0, topItemY
,
1924 drawRect
= &tempDrawRect
;
1927 // items added check
1928 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1930 int paintFinishY
= 0;
1932 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1935 bool isBuffered
= false;
1937 #if wxPG_DOUBLE_BUFFER
1938 wxMemoryDC
* bufferDC
= NULL
;
1940 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1942 if ( !m_doubleBuffer
)
1944 paintFinishY
= drawRect
->y
;
1949 bufferDC
= new wxMemoryDC();
1951 // If nothing was changed, then just copy from double-buffer
1952 bufferDC
->SelectObject( *m_doubleBuffer
);
1962 dc
.SetClippingRegion( *drawRect
);
1963 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1964 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1966 // Clear area beyond last painted property
1967 if ( paintFinishY
< drawBottomY
)
1969 dcPtr
->SetPen(m_colEmptySpace
);
1970 dcPtr
->SetBrush(m_colEmptySpace
);
1971 dcPtr
->DrawRectangle(0, paintFinishY
,
1976 dc
.DestroyClippingRegion();
1979 #if wxPG_DOUBLE_BUFFER
1982 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1984 bufferDC
, 0, 0, wxCOPY
);
1991 // Just clear the area
1992 dc
.SetPen(m_colEmptySpace
);
1993 dc
.SetBrush(m_colEmptySpace
);
1994 dc
.DrawRectangle(*drawRect
);
1998 // -----------------------------------------------------------------------
2000 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2001 const wxRect
* drawRect
,
2002 bool isBuffered
) const
2004 const wxPGProperty
* firstItem
;
2005 const wxPGProperty
* lastItem
;
2007 firstItem
= DoGetItemAtY(drawRect
->y
);
2008 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
2011 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2013 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2016 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
2018 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2020 int lh
= m_lineHeight
;
2023 int lastItemBottomY
;
2025 firstItemTopY
= drawRect
->y
;
2026 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
2028 // Align y coordinates to item boundaries
2029 firstItemTopY
-= firstItemTopY
% lh
;
2030 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2031 lastItemBottomY
-= 1;
2033 // Entire range outside scrolled, visible area?
2034 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2035 lastItemBottomY
<= 0 )
2038 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2040 "invalid y values" );
2043 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2044 "height=%i (ch=%i), drawRect = 0x%lX )",
2045 firstItem->GetLabel().c_str(),
2046 lastItem->GetLabel().c_str(),
2047 (int)(lastItemBottomY - firstItemTopY),
2049 (unsigned long)drawRect );
2054 long windowStyle
= m_windowStyle
;
2059 // With wxPG_DOUBLE_BUFFER, do double buffering
2060 // - buffer's y = 0, so align drawRect and coordinates to that
2062 #if wxPG_DOUBLE_BUFFER
2069 xRelMod
= drawRect
->x
;
2070 yRelMod
= drawRect
->y
;
2073 // drawRect conversion
2078 firstItemTopY
-= yRelMod
;
2079 lastItemBottomY
-= yRelMod
;
2082 wxUnusedVar(isBuffered
);
2085 int x
= m_marginWidth
- xRelMod
;
2087 wxFont normalFont
= GetFont();
2089 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2091 bool isPgEnabled
= IsEnabled();
2094 // Prepare some pens and brushes that are often changed to.
2097 wxBrush
marginBrush(m_colMargin
);
2098 wxPen
marginPen(m_colMargin
);
2099 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2100 wxPen
linepen(m_colLine
,1,wxSOLID
);
2102 wxColour selBackCol
;
2104 selBackCol
= m_colSelBack
;
2106 selBackCol
= m_colMargin
;
2108 // pen that has same colour as text
2109 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2112 // Clear margin with background colour
2114 dc
.SetBrush( marginBrush
);
2115 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2117 dc
.SetPen( *wxTRANSPARENT_PEN
);
2118 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2121 const wxPGProperty
* firstSelected
= GetSelection();
2122 const wxPropertyGridPageState
* state
= m_pState
;
2124 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2125 bool wasSelectedPainted
= false;
2128 // TODO: Only render columns that are within clipping region.
2130 dc
.SetFont(normalFont
);
2132 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2133 int endScanBottomY
= lastItemBottomY
+ lh
;
2134 int y
= firstItemTopY
;
2137 // Pregenerate list of visible properties.
2138 wxArrayPGProperty visPropArray
;
2139 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2141 for ( ; !it
.AtEnd(); it
.Next() )
2143 const wxPGProperty
* p
= *it
;
2145 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2147 visPropArray
.push_back((wxPGProperty
*)p
);
2149 if ( y
> endScanBottomY
)
2156 visPropArray
.push_back(NULL
);
2158 wxPGProperty
* nextP
= visPropArray
[0];
2160 int gridWidth
= state
->m_width
;
2163 for ( unsigned int arrInd
=1;
2164 nextP
&& y
<= lastItemBottomY
;
2167 wxPGProperty
* p
= nextP
;
2168 nextP
= visPropArray
[arrInd
];
2170 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2171 int textMarginHere
= x
;
2172 int renderFlags
= 0;
2174 int greyDepth
= m_marginWidth
;
2175 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2176 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2178 int greyDepthX
= greyDepth
- xRelMod
;
2180 // Use basic depth if in non-categoric mode and parent is base array.
2181 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2183 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2186 // Paint margin area
2187 dc
.SetBrush(marginBrush
);
2188 dc
.SetPen(marginPen
);
2189 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2191 dc
.SetPen( linepen
);
2197 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2198 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2199 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2201 // Is this or its parent themed?
2202 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2203 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2204 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2206 bool suppressMarginEdge
= false;
2208 if (!suppressMarginEdge
)
2209 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2212 // Blank out the margin edge
2213 dc
.SetPen(wxPen(GetBackgroundColour()));
2214 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2215 dc
.SetPen( linepen
);
2222 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2224 sx
+= state
->m_colWidths
[si
];
2225 dc
.DrawLine( sx
, y
, sx
, y2
);
2228 // Horizontal Line, below
2229 // (not if both this and next is category caption)
2230 if ( p
->IsCategory() &&
2231 nextP
&& nextP
->IsCategory() )
2232 dc
.SetPen(m_colCapBack
);
2234 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2237 // Need to override row colours?
2241 bool isSelected
= state
->DoIsPropertySelected(p
);
2245 // Disabled may get different colour.
2246 if ( !p
->IsEnabled() )
2248 renderFlags
|= wxPGCellRenderer::Disabled
|
2249 wxPGCellRenderer::DontUseCellFgCol
;
2250 rowFgCol
= m_colDisPropFore
;
2255 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2256 if ( p
== firstSelected
)
2257 wasSelectedPainted
= true;
2260 renderFlags
|= wxPGCellRenderer::Selected
;
2262 if ( !p
->IsCategory() )
2264 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2265 wxPGCellRenderer::DontUseCellBgCol
;
2267 if ( reallyFocused
&& p
== firstSelected
)
2269 rowFgCol
= m_colSelFore
;
2270 rowBgCol
= selBackCol
;
2272 else if ( isPgEnabled
)
2274 rowFgCol
= m_colPropFore
;
2275 if ( p
== firstSelected
)
2276 rowBgCol
= m_colMargin
;
2278 rowBgCol
= selBackCol
;
2282 rowFgCol
= m_colDisPropFore
;
2283 rowBgCol
= selBackCol
;
2290 if ( rowBgCol
.IsOk() )
2291 rowBgBrush
= wxBrush(rowBgCol
);
2293 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2294 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2297 // Fill additional margin area with background colour of first cell
2298 if ( greyDepthX
< textMarginHere
)
2300 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2302 wxPGCell
& cell
= p
->GetCell(0);
2303 rowBgCol
= cell
.GetBgCol();
2304 rowBgBrush
= wxBrush(rowBgCol
);
2306 dc
.SetBrush(rowBgBrush
);
2307 dc
.SetPen(rowBgCol
);
2308 dc
.DrawRectangle(greyDepthX
+1, y
,
2309 textMarginHere
-greyDepthX
, lh
-1);
2312 bool fontChanged
= false;
2314 // Expander button rectangle
2315 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2320 if ( p
->IsCategory() )
2322 // Captions have their cell areas merged as one
2323 dc
.SetFont(m_captionFont
);
2325 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2327 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2329 dc
.SetBrush(rowBgBrush
);
2330 dc
.SetPen(rowBgCol
);
2333 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2335 dc
.SetTextForeground(rowFgCol
);
2338 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2339 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2342 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2343 DrawExpanderButton( dc
, butRect
, p
);
2347 // Fine tune button rectangle to actually fit the cell
2348 if ( butRect
.x
> 0 )
2349 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2351 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2353 dc
.SetFont(m_captionFont
);
2359 int nextCellWidth
= state
->m_colWidths
[0] -
2360 (greyDepthX
- m_marginWidth
);
2361 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2362 int textXAdd
= textMarginHere
- greyDepthX
;
2364 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2366 cellRect
.width
= nextCellWidth
- 1;
2368 wxWindow
* cellEditor
= NULL
;
2369 int cellRenderFlags
= renderFlags
;
2371 // Tree Item Button (must be drawn before clipping is set up)
2372 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2373 DrawExpanderButton( dc
, butRect
, p
);
2376 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2378 if ( p
== firstSelected
)
2380 if ( ci
== 1 && m_wndEditor
)
2381 cellEditor
= m_wndEditor
;
2382 else if ( ci
== m_selColumn
&& m_labelEditor
)
2383 cellEditor
= m_labelEditor
;
2388 wxColour editorBgCol
=
2389 cellEditor
->GetBackgroundColour();
2390 dc
.SetBrush(editorBgCol
);
2391 dc
.SetPen(editorBgCol
);
2392 dc
.SetTextForeground(m_colPropFore
);
2393 dc
.DrawRectangle(cellRect
);
2395 if ( m_dragStatus
!= 0 ||
2396 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2401 dc
.SetBrush(m_colPropBack
);
2402 dc
.SetPen(m_colPropBack
);
2403 dc
.SetTextForeground(m_colDisPropFore
);
2404 if ( p
->IsEnabled() )
2405 dc
.SetTextForeground(rowFgCol
);
2407 dc
.SetTextForeground(m_colDisPropFore
);
2412 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2414 dc
.SetBrush(rowBgBrush
);
2415 dc
.SetPen(rowBgCol
);
2418 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2420 dc
.SetTextForeground(rowFgCol
);
2424 dc
.SetClippingRegion(cellRect
);
2426 cellRect
.x
+= textXAdd
;
2427 cellRect
.width
-= textXAdd
;
2432 wxPGCellRenderer
* renderer
;
2433 int cmnVal
= p
->GetCommonValue();
2434 if ( cmnVal
== -1 || ci
!= 1 )
2436 renderer
= p
->GetCellRenderer(ci
);
2437 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2442 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2443 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2448 cellX
+= state
->m_colWidths
[ci
];
2449 if ( ci
< (state
->m_colWidths
.size()-1) )
2450 nextCellWidth
= state
->m_colWidths
[ci
+1];
2452 dc
.DestroyClippingRegion(); // Is this really necessary?
2458 dc
.SetFont(normalFont
);
2463 // Refresh editor controls (seems not needed on msw)
2464 // NOTE: This code is mandatory for GTK!
2465 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2466 if ( wasSelectedPainted
)
2469 m_wndEditor
->Refresh();
2471 m_wndEditor2
->Refresh();
2478 // -----------------------------------------------------------------------
2480 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2484 if ( m_width
< 10 || m_height
< 10 ||
2485 !m_pState
->m_properties
->GetChildCount() ||
2487 return wxRect(0,0,0,0);
2492 // Return rect which encloses the given property range
2494 int visTop
= p1
->GetY();
2497 visBottom
= p2
->GetY() + m_lineHeight
;
2499 visBottom
= m_height
+ visTop
;
2501 // If seleced property is inside the range, we'll extend the range to include
2503 wxPGProperty
* selected
= GetSelection();
2506 int selectedY
= selected
->GetY();
2507 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2509 wxWindow
* editor
= GetEditorControl();
2512 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2513 if ( visBottom2
> visBottom
)
2514 visBottom
= visBottom2
;
2519 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2522 // -----------------------------------------------------------------------
2524 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2529 if ( m_pState
->m_itemsAdded
)
2530 PrepareAfterItemsAdded();
2532 wxRect r
= GetPropertyRect(p1
, p2
);
2539 // -----------------------------------------------------------------------
2541 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2543 if ( m_pState
->DoIsPropertySelected(p
) )
2545 // NB: We must copy the selection.
2546 wxArrayPGProperty selection
= m_pState
->m_selection
;
2547 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2550 DrawItemAndChildren(p
);
2553 // -----------------------------------------------------------------------
2555 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2560 // Draw item, children, and parent too, if it is not category
2561 wxPGProperty
* parent
= p
->GetParent();
2564 !parent
->IsCategory() &&
2565 parent
->GetParent() )
2568 parent
= parent
->GetParent();
2571 DrawItemAndChildren(p
);
2574 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2576 wxCHECK_RET( p
, wxT("invalid property id") );
2578 // Do not draw if in non-visible page
2579 if ( p
->GetParentState() != m_pState
)
2582 // do not draw a single item if multiple pending
2583 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2586 // Update child control.
2587 wxPGProperty
* selected
= GetSelection();
2588 if ( selected
&& selected
->GetParent() == p
)
2591 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2593 DrawItems(p
, lastDrawn
);
2596 // -----------------------------------------------------------------------
2598 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2599 const wxRect
*rect
)
2601 PrepareAfterItemsAdded();
2603 wxWindow::Refresh(false, rect
);
2605 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2606 // I think this really helps only GTK+1.2
2607 if ( m_wndEditor
) m_wndEditor
->Refresh();
2608 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2612 // -----------------------------------------------------------------------
2613 // wxPropertyGrid global operations
2614 // -----------------------------------------------------------------------
2616 void wxPropertyGrid::Clear()
2618 m_pState
->DoClear();
2624 RecalculateVirtualSize();
2626 // Need to clear some area at the end
2628 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2631 // -----------------------------------------------------------------------
2633 bool wxPropertyGrid::EnableCategories( bool enable
)
2640 // Enable categories
2643 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2648 // Disable categories
2650 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2653 if ( !m_pState
->EnableCategories(enable
) )
2658 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2660 m_pState
->m_itemsAdded
= 1; // force
2661 PrepareAfterItemsAdded();
2665 m_pState
->m_itemsAdded
= 1;
2667 // No need for RecalculateVirtualSize() here - it is already called in
2668 // wxPropertyGridPageState method above.
2675 // -----------------------------------------------------------------------
2677 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2679 wxASSERT( pNewState
);
2680 wxASSERT( pNewState
->GetGrid() );
2682 if ( pNewState
== m_pState
)
2685 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2687 // Call ClearSelection() instead of DoClearSelection()
2688 // so that selection clear events are not sent.
2691 m_pState
->m_selection
= oldSelection
;
2693 bool orig_mode
= m_pState
->IsInNonCatMode();
2694 bool new_state_mode
= pNewState
->IsInNonCatMode();
2696 m_pState
= pNewState
;
2699 int pgWidth
= GetClientSize().x
;
2700 if ( HasVirtualWidth() )
2702 int minWidth
= pgWidth
;
2703 if ( pNewState
->m_width
< minWidth
)
2705 pNewState
->m_width
= minWidth
;
2706 pNewState
->CheckColumnWidths();
2712 // Just in case, fully re-center splitter
2713 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2714 // pNewState->m_fSplitterX = -1.0;
2716 pNewState
->OnClientWidthChange(pgWidth
,
2717 pgWidth
- pNewState
->m_width
);
2722 // If necessary, convert state to correct mode.
2723 if ( orig_mode
!= new_state_mode
)
2725 // This should refresh as well.
2726 EnableCategories( orig_mode
?false:true );
2728 else if ( !m_frozen
)
2730 // Refresh, if not frozen.
2731 m_pState
->PrepareAfterItemsAdded();
2733 // Reselect (Use SetSelection() instead of Do-variant so that
2734 // events won't be sent).
2735 SetSelection(m_pState
->m_selection
);
2737 RecalculateVirtualSize(0);
2741 m_pState
->m_itemsAdded
= 1;
2744 // -----------------------------------------------------------------------
2746 // Call to SetSplitterPosition will always disable splitter auto-centering
2747 // if parent window is shown.
2748 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2752 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2755 wxPropertyGridPageState
* state
= m_pState
;
2757 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2758 state
->m_dontCenterSplitter
= true;
2760 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2762 if ( flags
& wxPG_SPLITTER_REFRESH
)
2764 if ( GetSelection() )
2765 CorrectEditorWidgetSizeX();
2773 // -----------------------------------------------------------------------
2775 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2777 SetSplitterPosition( m_width
/2 );
2778 if ( enableAutoCentering
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2779 m_pState
->m_dontCenterSplitter
= false;
2782 // -----------------------------------------------------------------------
2783 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2784 // -----------------------------------------------------------------------
2786 // Returns nearest paint visible property (such that will be painted unless
2787 // window is scrolled or resized). If given property is paint visible, then
2788 // it itself will be returned
2789 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2791 int vx
,vy1
;// Top left corner of client
2792 GetViewStart(&vx
,&vy1
);
2793 vy1
*= wxPG_PIXELS_PER_UNIT
;
2795 int vy2
= vy1
+ m_height
;
2796 int propY
= p
->GetY2(m_lineHeight
);
2798 if ( (propY
+ m_lineHeight
) < vy1
)
2801 return DoGetItemAtY( vy1
);
2803 else if ( propY
> vy2
)
2806 return DoGetItemAtY( vy2
);
2809 // Itself paint visible
2814 // -----------------------------------------------------------------------
2815 // Methods related to change in value, value modification and sending events
2816 // -----------------------------------------------------------------------
2818 // commits any changes in editor of selected property
2819 // return true if validation did not fail
2820 // flags are same as with DoSelectProperty
2821 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2823 // Committing already?
2824 if ( m_inCommitChangesFromEditor
)
2827 // Don't do this if already processing editor event. It might
2828 // induce recursive dialogs and crap like that.
2829 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2831 if ( m_inDoPropertyChanged
)
2837 wxPGProperty
* selected
= GetSelection();
2840 IsEditorsValueModified() &&
2841 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2844 m_inCommitChangesFromEditor
= 1;
2846 wxVariant
variant(selected
->GetValueRef());
2847 bool valueIsPending
= false;
2849 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2850 // due to another window getting focus
2851 wxWindow
* oldFocus
= m_curFocused
;
2853 bool validationFailure
= false;
2854 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2856 m_chgInfo_changedProperty
= NULL
;
2858 // If truly modified, schedule value as pending.
2859 if ( selected
->GetEditorClass()->
2860 GetValueFromControl( variant
,
2862 GetEditorControl() ) )
2864 if ( DoEditorValidate() &&
2865 PerformValidation(selected
, variant
) )
2867 valueIsPending
= true;
2871 validationFailure
= true;
2876 EditorsValueWasNotModified();
2881 m_inCommitChangesFromEditor
= 0;
2883 if ( validationFailure
&& !forceSuccess
)
2887 oldFocus
->SetFocus();
2888 m_curFocused
= oldFocus
;
2891 res
= OnValidationFailure(selected
, variant
);
2893 // Now prevent further validation failure messages
2896 EditorsValueWasNotModified();
2897 OnValidationFailureReset(selected
);
2900 else if ( valueIsPending
)
2902 DoPropertyChanged( selected
, flags
);
2903 EditorsValueWasNotModified();
2912 // -----------------------------------------------------------------------
2914 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2918 // Runs all validation functionality.
2919 // Returns true if value passes all tests.
2922 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2925 // Variant list a special value that cannot be validated
2927 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2929 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2934 // Adapt list to child values, if necessary
2935 wxVariant listValue
= pendingValue
;
2936 wxVariant
* pPendingValue
= &pendingValue
;
2937 wxVariant
* pList
= NULL
;
2939 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2940 // string value, then we need treat as it was changed instead
2941 // (or, in addition, as is the case with composite string parent).
2942 // This includes creating list variant for child values.
2944 wxPGProperty
* pwc
= p
->GetParent();
2945 wxPGProperty
* changedProperty
= p
;
2946 wxPGProperty
* baseChangedProperty
= changedProperty
;
2947 wxVariant bcpPendingList
;
2949 listValue
= pendingValue
;
2950 listValue
.SetName(p
->GetBaseName());
2953 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2955 wxVariantList tempList
;
2956 wxVariant
lv(tempList
, pwc
->GetBaseName());
2957 lv
.Append(listValue
);
2959 pPendingValue
= &listValue
;
2961 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2963 baseChangedProperty
= pwc
;
2964 bcpPendingList
= lv
;
2967 changedProperty
= pwc
;
2968 pwc
= pwc
->GetParent();
2972 wxPGProperty
* evtChangingProperty
= changedProperty
;
2974 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2976 value
= *pPendingValue
;
2980 // Convert list to child values
2981 pList
= pPendingValue
;
2982 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2985 wxVariant evtChangingValue
= value
;
2987 if ( flags
& SendEvtChanging
)
2989 // FIXME: After proper ValueToString()s added, remove
2990 // this. It is just a temporary fix, as evt_changing
2991 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2992 // (unless it is selected, and textctrl editor is open).
2993 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2995 evtChangingProperty
= baseChangedProperty
;
2996 if ( evtChangingProperty
!= p
)
2998 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3002 evtChangingValue
= pendingValue
;
3006 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3008 if ( changedProperty
== GetSelection() )
3010 wxWindow
* editor
= GetEditorControl();
3011 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3012 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3016 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3021 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3022 m_chgInfo_changedProperty
= changedProperty
;
3023 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3024 m_chgInfo_pendingValue
= value
;
3027 m_chgInfo_valueList
= *pList
;
3029 m_chgInfo_valueList
.MakeNull();
3031 // If changedProperty is not property which value was edited,
3032 // then call wxPGProperty::ValidateValue() for that as well.
3033 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3035 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3039 if ( flags
& SendEvtChanging
)
3041 // SendEvent returns true if event was vetoed
3042 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3043 &evtChangingValue
) )
3047 if ( flags
& IsStandaloneValidation
)
3049 // If called in 'generic' context, we need to reset
3050 // m_chgInfo_changedProperty and write back translated value.
3051 m_chgInfo_changedProperty
= NULL
;
3052 pendingValue
= value
;
3058 // -----------------------------------------------------------------------
3060 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3062 if ( !msg
.length() )
3066 if ( !wxPGGlobalVars
->m_offline
)
3068 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3071 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3074 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3077 pStatusBar
->SetStatusText(msg
);
3085 ::wxMessageBox(msg
, wxT("Property Error"));
3088 // -----------------------------------------------------------------------
3090 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3091 wxVariant
& invalidValue
)
3093 wxWindow
* editor
= GetEditorControl();
3095 // First call property's handler
3096 property
->OnValidationFailure(invalidValue
);
3098 bool res
= DoOnValidationFailure(property
, invalidValue
);
3101 // For non-wxTextCtrl editors, we do need to revert the value
3102 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3103 property
== GetSelection() )
3105 property
->GetEditorClass()->UpdateControl(property
, editor
);
3108 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3113 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3115 int vfb
= m_validationInfo
.m_failureBehavior
;
3117 if ( vfb
& wxPG_VFB_BEEP
)
3120 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3121 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3123 unsigned int colCount
= m_pState
->GetColumnCount();
3125 // We need backup marked property's cells
3126 m_propCellsBackup
= property
->m_cells
;
3128 wxColour vfbFg
= *wxWHITE
;
3129 wxColour vfbBg
= *wxRED
;
3131 property
->EnsureCells(colCount
);
3133 for ( unsigned int i
=0; i
<colCount
; i
++ )
3135 wxPGCell
& cell
= property
->m_cells
[i
];
3136 cell
.SetFgCol(vfbFg
);
3137 cell
.SetBgCol(vfbBg
);
3140 DrawItemAndChildren(property
);
3142 if ( property
== GetSelection() )
3144 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3146 wxWindow
* editor
= GetEditorControl();
3149 editor
->SetForegroundColour(vfbFg
);
3150 editor
->SetBackgroundColour(vfbBg
);
3155 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3157 wxString msg
= m_validationInfo
.m_failureMessage
;
3159 if ( !msg
.length() )
3160 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3162 DoShowPropertyError(property
, msg
);
3165 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3168 // -----------------------------------------------------------------------
3170 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3172 int vfb
= m_validationInfo
.m_failureBehavior
;
3174 if ( vfb
& wxPG_VFB_MARK_CELL
)
3177 property
->m_cells
= m_propCellsBackup
;
3179 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3181 if ( property
== GetSelection() && GetEditorControl() )
3183 // Calling this will recreate the control, thus resetting its colour
3184 RefreshProperty(property
);
3188 DrawItemAndChildren(property
);
3193 // -----------------------------------------------------------------------
3195 // flags are same as with DoSelectProperty
3196 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3198 if ( m_inDoPropertyChanged
)
3201 wxWindow
* editor
= GetEditorControl();
3202 wxPGProperty
* selected
= GetSelection();
3204 m_pState
->m_anyModified
= 1;
3206 m_inDoPropertyChanged
= 1;
3208 // Maybe need to update control
3209 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3211 // These values were calculated in PerformValidation()
3212 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3213 wxVariant value
= m_chgInfo_pendingValue
;
3215 wxPGProperty
* topPaintedProperty
= changedProperty
;
3217 while ( !topPaintedProperty
->IsCategory() &&
3218 !topPaintedProperty
->IsRoot() )
3220 topPaintedProperty
= topPaintedProperty
->GetParent();
3223 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3225 // Set as Modified (not if dragging just began)
3226 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3228 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3229 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3232 SetCurControlBoldFont();
3238 // Propagate updates to parent(s)
3240 wxPGProperty
* prevPwc
= NULL
;
3242 while ( prevPwc
!= topPaintedProperty
)
3244 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3246 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3249 SetCurControlBoldFont();
3253 pwc
= pwc
->GetParent();
3256 // Draw the actual property
3257 DrawItemAndChildren( topPaintedProperty
);
3260 // If value was set by wxPGProperty::OnEvent, then update the editor
3262 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3268 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3269 if ( m_wndEditor
) m_wndEditor
->Refresh();
3270 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3275 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3277 // If top parent has composite string value, then send to child parents,
3278 // starting from baseChangedProperty.
3279 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3281 pwc
= m_chgInfo_baseChangedProperty
;
3283 while ( pwc
!= changedProperty
)
3285 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3286 pwc
= pwc
->GetParent();
3290 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3292 m_inDoPropertyChanged
= 0;
3297 // -----------------------------------------------------------------------
3299 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3301 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3303 m_chgInfo_changedProperty
= NULL
;
3305 if ( PerformValidation(p
, newValue
) )
3307 DoPropertyChanged(p
);
3312 OnValidationFailure(p
, newValue
);
3318 // -----------------------------------------------------------------------
3320 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3322 wxPGProperty
* prop
= GetSelectedProperty();
3325 return wxNullVariant
;
3327 wxTextCtrl
* tc
= GetEditorTextCtrl();
3328 wxVariant value
= prop
->GetValue();
3330 if ( !tc
|| !IsEditorsValueModified() )
3333 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3336 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3337 return prop
->GetValue();
3342 // -----------------------------------------------------------------------
3344 // Runs wxValidator for the selected property
3345 bool wxPropertyGrid::DoEditorValidate()
3350 // -----------------------------------------------------------------------
3352 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3354 // It is possible that this handler receives event even before
3355 // the control has been properly initialized. Let's skip the
3356 // event handling in that case.
3360 wxPGProperty
* selected
= GetSelection();
3362 // Somehow, event is handled after property has been deselected.
3363 // Possibly, but very rare.
3365 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3366 // Also don't handle editor event if wxEVT_PG_CHANGED or
3367 // similar is currently doing something (showing a
3368 // message box, for instance).
3372 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3375 wxVariant
pendingValue(selected
->GetValueRef());
3376 wxWindow
* wnd
= GetEditorControl();
3377 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3379 bool wasUnspecified
= selected
->IsValueUnspecified();
3380 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3381 bool valueIsPending
= false;
3383 m_chgInfo_changedProperty
= NULL
;
3385 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3388 // Filter out excess wxTextCtrl modified events
3389 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3391 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3393 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3395 wxString newTcValue
= tc
->GetValue();
3396 if ( m_prevTcValue
== newTcValue
)
3398 m_prevTcValue
= newTcValue
;
3400 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3402 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3404 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3405 if ( m_prevTcValue
== newTcValue
)
3407 m_prevTcValue
= newTcValue
;
3411 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3413 bool validationFailure
= false;
3414 bool buttonWasHandled
= false;
3417 // Try common button handling
3418 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3420 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3424 buttonWasHandled
= true;
3425 // Store as res2, as previously (and still currently alternatively)
3426 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3427 // in wxPGProperty::OnEvent().
3428 adapter
->ShowDialog( this, selected
);
3433 if ( !buttonWasHandled
)
3435 if ( wnd
|| m_wndEditor2
)
3437 // First call editor class' event handler.
3438 const wxPGEditor
* editor
= selected
->GetEditorClass();
3440 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3442 // If changes, validate them
3443 if ( DoEditorValidate() )
3445 if ( editor
->GetValueFromControl( pendingValue
,
3448 valueIsPending
= true;
3452 validationFailure
= true;
3457 // Then the property's custom handler (must be always called, unless
3458 // validation failed).
3459 if ( !validationFailure
)
3460 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3463 // SetValueInEvent(), as called in one of the functions referred above
3464 // overrides editor's value.
3465 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3467 valueIsPending
= true;
3468 pendingValue
= m_changeInEventValue
;
3469 selFlags
|= wxPG_SEL_DIALOGVAL
;
3472 if ( !validationFailure
&& valueIsPending
)
3473 if ( !PerformValidation(selected
, pendingValue
) )
3474 validationFailure
= true;
3476 if ( validationFailure
)
3478 OnValidationFailure(selected
, pendingValue
);
3480 else if ( valueIsPending
)
3482 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3484 DoPropertyChanged(selected
, selFlags
);
3485 EditorsValueWasNotModified();
3487 // Regardless of editor type, unfocus editor on
3488 // text-editing related enter press.
3489 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3496 // No value after all
3498 // Regardless of editor type, unfocus editor on
3499 // text-editing related enter press.
3500 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3505 // Let unhandled button click events go to the parent
3506 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3508 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3509 GetEventHandler()->AddPendingEvent(evt
);
3513 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3516 // -----------------------------------------------------------------------
3517 // wxPropertyGrid editor control helper methods
3518 // -----------------------------------------------------------------------
3520 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3522 int itemy
= p
->GetY2(m_lineHeight
);
3523 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3524 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3525 int imageOffset
= 0;
3527 int vx
, vy
; // Top left corner of client
3528 GetViewStart(&vx
, &vy
);
3529 vy
*= wxPG_PIXELS_PER_UNIT
;
3531 // TODO: If custom image detection changes from current, change this.
3532 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3534 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3535 int iw
= p
->OnMeasureImage().x
;
3537 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3538 imageOffset
= p
->GetImageOffset(iw
);
3543 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3545 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3550 // -----------------------------------------------------------------------
3552 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3554 wxSize sz
= GetImageSize(p
, item
);
3555 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3556 wxPG_CUSTOM_IMAGE_SPACINGY
,
3561 // return size of custom paint image
3562 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3564 // If called with NULL property, then return default image
3565 // size for properties that use image.
3567 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3569 wxSize cis
= p
->OnMeasureImage(item
);
3571 int choiceCount
= p
->m_choices
.GetCount();
3572 int comVals
= p
->GetDisplayedCommonValueCount();
3573 if ( item
>= choiceCount
&& comVals
> 0 )
3575 unsigned int cvi
= item
-choiceCount
;
3576 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3578 else if ( item
>= 0 && choiceCount
== 0 )
3579 return wxSize(0, 0);
3584 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3589 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3596 // -----------------------------------------------------------------------
3598 // takes scrolling into account
3599 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3602 GetViewStart(&vx
,&vy
);
3603 vy
*=wxPG_PIXELS_PER_UNIT
;
3604 vx
*=wxPG_PIXELS_PER_UNIT
;
3607 ClientToScreen( px
, py
);
3610 // -----------------------------------------------------------------------
3612 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3615 GetViewStart(&pt2
.x
,&pt2
.y
);
3616 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3617 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3621 return m_pState
->HitTest(pt2
);
3624 // -----------------------------------------------------------------------
3626 // custom set cursor
3627 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3629 if ( type
== m_curcursor
&& !override
) return;
3631 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3633 if ( type
== wxCURSOR_SIZEWE
)
3634 cursor
= m_cursorSizeWE
;
3636 SetCursor( *cursor
);
3641 // -----------------------------------------------------------------------
3644 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3646 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3648 if ( ua
.HasText() &&
3649 !(argFlags
& wxPG_FULL_VALUE
) &&
3650 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3651 return ua
.GetText();
3653 return wxEmptyString
;
3656 // -----------------------------------------------------------------------
3657 // wxPropertyGrid property selection, editor creation
3658 // -----------------------------------------------------------------------
3661 // This class forwards events from property editor controls to wxPropertyGrid.
3662 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3665 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3666 : wxEvtHandler(), m_propGrid(propGrid
)
3670 virtual ~wxPropertyGridEditorEventForwarder()
3675 bool ProcessEvent( wxEvent
& event
)
3680 m_propGrid
->HandleCustomEditorEvent(event
);
3682 return wxEvtHandler::ProcessEvent(event
);
3685 wxPropertyGrid
* m_propGrid
;
3688 // Setups event handling for child control
3689 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3691 wxWindowID id
= argWnd
->GetId();
3693 if ( argWnd
== m_wndEditor
)
3695 argWnd
->Connect(id
, wxEVT_MOTION
,
3696 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3698 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3699 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3701 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3702 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3704 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3705 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3707 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3708 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3710 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3711 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3715 wxPropertyGridEditorEventForwarder
* forwarder
;
3716 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3717 argWnd
->PushEventHandler(forwarder
);
3719 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3720 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3724 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3731 // Do not free editors immediately (for sake of processing events)
3732 wxPendingDelete
.Append(wnd
);
3735 void wxPropertyGrid::FreeEditors()
3738 // Return focus back to canvas from children (this is required at least for
3739 // GTK+, which, unlike Windows, clears focus when control is destroyed
3740 // instead of moving it to closest parent).
3741 wxWindow
* focus
= wxWindow::FindFocus();
3744 wxWindow
* parent
= focus
->GetParent();
3747 if ( parent
== this )
3752 parent
= parent
->GetParent();
3756 // Do not free editors immediately if processing events
3759 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3760 m_wndEditor2
->Hide();
3761 wxPendingDelete
.Append( handler
);
3762 DestroyEditorWnd(m_wndEditor2
);
3763 m_wndEditor2
= NULL
;
3768 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3769 m_wndEditor
->Hide();
3770 wxPendingDelete
.Append( handler
);
3771 DestroyEditorWnd(m_wndEditor
);
3776 // Call with NULL to de-select property
3777 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3782 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3783 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3787 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3791 if ( m_inDoSelectProperty
)
3794 m_inDoSelectProperty
= 1;
3798 m_inDoSelectProperty
= 0;
3802 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3803 wxPGProperty
* prevFirstSel
;
3805 if ( prevSelection
.size() > 0 )
3806 prevFirstSel
= prevSelection
[0];
3808 prevFirstSel
= NULL
;
3810 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3811 prevFirstSel
= NULL
;
3813 // Always send event, as this is indirect call
3814 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3818 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3820 wxPrintf( "None selected\n" );
3823 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3825 wxPrintf( "P = NULL\n" );
3828 // If we are frozen, then just set the values.
3831 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3832 m_editorFocused
= 0;
3833 m_pState
->DoSetSelection(p
);
3835 // If frozen, always free controls. But don't worry, as Thaw will
3836 // recall SelectProperty to recreate them.
3839 // Prevent any further selection measures in this call
3845 if ( prevFirstSel
== p
&&
3846 prevSelection
.size() <= 1 &&
3847 !(flags
& wxPG_SEL_FORCE
) )
3849 // Only set focus if not deselecting
3852 if ( flags
& wxPG_SEL_FOCUS
)
3856 m_wndEditor
->SetFocus();
3857 m_editorFocused
= 1;
3866 m_inDoSelectProperty
= 0;
3871 // First, deactivate previous
3874 OnValidationFailureReset(prevFirstSel
);
3876 // Must double-check if this is an selected in case of forceswitch
3877 if ( p
!= prevFirstSel
)
3879 if ( !CommitChangesFromEditor(flags
) )
3881 // Validation has failed, so we can't exit the previous editor
3882 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3883 // _("Invalid Value"),wxOK|wxICON_ERROR);
3884 m_inDoSelectProperty
= 0;
3891 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3892 EditorsValueWasNotModified();
3895 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3897 m_pState
->DoSetSelection(p
);
3899 // Redraw unselected
3900 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3902 DrawItem(prevSelection
[i
]);
3906 // Then, activate the one given.
3909 int propY
= p
->GetY2(m_lineHeight
);
3911 int splitterX
= GetSplitterPosition();
3912 m_editorFocused
= 0;
3913 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3914 if ( p
!= prevFirstSel
)
3915 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3917 wxASSERT( m_wndEditor
== NULL
);
3920 // Only create editor for non-disabled non-caption
3921 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3923 // do this for non-caption items
3927 // Do we need to paint the custom image, if any?
3928 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3929 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3930 !p
->GetEditorClass()->CanContainCustomImage()
3932 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3934 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3935 wxPoint goodPos
= grect
.GetPosition();
3937 // Editor appearance can now be considered clear
3938 m_editorAppearance
.SetEmptyData();
3940 const wxPGEditor
* editor
= p
->GetEditorClass();
3941 wxCHECK_MSG(editor
, false,
3942 wxT("NULL editor class not allowed"));
3944 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3946 wxPGWindowList wndList
=
3947 editor
->CreateControls(this,
3952 m_wndEditor
= wndList
.m_primary
;
3953 m_wndEditor2
= wndList
.m_secondary
;
3954 wxWindow
* primaryCtrl
= GetEditorControl();
3957 // Essentially, primaryCtrl == m_wndEditor
3960 // NOTE: It is allowed for m_wndEditor to be NULL - in this
3961 // case value is drawn as normal, and m_wndEditor2 is
3962 // assumed to be a right-aligned button that triggers
3963 // a separate editorCtrl window.
3967 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3968 "CreateControls must use result of "
3969 "wxPropertyGrid::GetPanel() as parent "
3972 // Set validator, if any
3973 #if wxUSE_VALIDATORS
3974 wxValidator
* validator
= p
->GetValidator();
3976 primaryCtrl
->SetValidator(*validator
);
3979 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3980 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3982 // If it has modified status, use bold font
3983 // (must be done before capturing m_ctrlXAdjust)
3984 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
3985 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3986 SetCurControlBoldFont();
3988 // Store x relative to splitter (we'll need it).
3989 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3991 // Check if background clear is not necessary
3992 wxPoint pos
= m_wndEditor
->GetPosition();
3993 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3995 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3998 m_wndEditor
->SetSizeHints(3, 3);
4000 SetupChildEventHandling(primaryCtrl
);
4002 // Focus and select all (wxTextCtrl, wxComboBox etc)
4003 if ( flags
& wxPG_SEL_FOCUS
)
4005 primaryCtrl
->SetFocus();
4007 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4011 if ( p
->IsValueUnspecified() )
4012 SetEditorAppearance(m_unspecifiedAppearance
,
4019 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4020 "CreateControls must use result of "
4021 "wxPropertyGrid::GetPanel() as parent "
4024 // Get proper id for wndSecondary
4025 m_wndSecId
= m_wndEditor2
->GetId();
4026 wxWindowList children
= m_wndEditor2
->GetChildren();
4027 wxWindowList::iterator node
= children
.begin();
4028 if ( node
!= children
.end() )
4029 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4031 m_wndEditor2
->SetSizeHints(3,3);
4033 m_wndEditor2
->Show();
4035 SetupChildEventHandling(m_wndEditor2
);
4037 // If no primary editor, focus to button to allow
4038 // it to interprete ENTER etc.
4039 // NOTE: Due to problems focusing away from it, this
4040 // has been disabled.
4042 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4043 m_wndEditor2->SetFocus();
4047 if ( flags
& wxPG_SEL_FOCUS
)
4048 m_editorFocused
= 1;
4053 // Make sure focus is in grid canvas (important for wxGTK,
4058 EditorsValueWasNotModified();
4060 // If it's inside collapsed section, expand parent, scroll, etc.
4061 // Also, if it was partially visible, scroll it into view.
4062 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4067 m_wndEditor
->Show(true);
4070 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4075 // Make sure focus is in grid canvas
4079 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4085 // Show help text in status bar.
4086 // (if found and grid not embedded in manager with help box and
4087 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4090 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4092 wxStatusBar
* statusbar
= NULL
;
4093 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
4095 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
4097 statusbar
= frame
->GetStatusBar();
4102 const wxString
* pHelpString
= (const wxString
*) NULL
;
4106 pHelpString
= &p
->GetHelpString();
4107 if ( pHelpString
->length() )
4109 // Set help box text.
4110 statusbar
->SetStatusText( *pHelpString
);
4111 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4115 if ( (!pHelpString
|| !pHelpString
->length()) &&
4116 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4118 // Clear help box - but only if it was written
4119 // by us at previous time.
4120 statusbar
->SetStatusText( m_emptyString
);
4121 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4127 m_inDoSelectProperty
= 0;
4129 // call wx event handler (here so that it also occurs on deselection)
4130 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4131 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4136 // -----------------------------------------------------------------------
4138 bool wxPropertyGrid::UnfocusEditor()
4140 wxPGProperty
* selected
= GetSelection();
4142 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4145 if ( !CommitChangesFromEditor(0) )
4154 // -----------------------------------------------------------------------
4156 void wxPropertyGrid::RefreshEditor()
4158 wxPGProperty
* p
= GetSelection();
4162 wxWindow
* wnd
= GetEditorControl();
4166 // Set editor font boldness - must do this before
4167 // calling UpdateControl().
4168 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4170 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4171 wnd
->SetFont(GetCaptionFont());
4173 wnd
->SetFont(GetFont());
4176 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4178 editorClass
->UpdateControl(p
, wnd
);
4180 if ( p
->IsValueUnspecified() )
4181 SetEditorAppearance(m_unspecifiedAppearance
, true);
4184 // -----------------------------------------------------------------------
4186 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4188 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4190 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4192 flags
|= wxPG_SEL_FOCUS
;
4194 return DoSelectProperty(p
, flags
);
4197 // -----------------------------------------------------------------------
4198 // wxPropertyGrid expand/collapse state
4199 // -----------------------------------------------------------------------
4201 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4203 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4204 wxPGProperty
* selected
= GetSelection();
4206 // If active editor was inside collapsed section, then disable it
4207 if ( selected
&& selected
->IsSomeParent(p
) )
4212 // Store dont-center-splitter flag 'cause we need to temporarily set it
4213 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4214 m_pState
->m_dontCenterSplitter
= true;
4216 bool res
= m_pState
->DoCollapse(pwc
);
4221 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4223 RecalculateVirtualSize();
4227 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4232 // -----------------------------------------------------------------------
4234 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4236 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4238 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4240 // Store dont-center-splitter flag 'cause we need to temporarily set it
4241 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4242 m_pState
->m_dontCenterSplitter
= true;
4244 bool res
= m_pState
->DoExpand(pwc
);
4249 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4251 RecalculateVirtualSize();
4255 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4260 // -----------------------------------------------------------------------
4262 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4265 return m_pState
->DoHideProperty(p
, hide
, flags
);
4267 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4268 int selRemoveCount
= 0;
4269 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4271 wxPGProperty
* selected
= selection
[i
];
4272 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4274 if ( !DoRemoveFromSelection(p
, flags
) )
4276 selRemoveCount
+= 1;
4280 m_pState
->DoHideProperty(p
, hide
, flags
);
4282 RecalculateVirtualSize();
4289 // -----------------------------------------------------------------------
4290 // wxPropertyGrid size related methods
4291 // -----------------------------------------------------------------------
4293 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4295 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4296 // virtual size calculation may go wrong.
4297 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4303 // If virtual height was changed, then recalculate editor control position(s)
4304 if ( m_pState
->m_vhCalcPending
)
4305 CorrectEditorWidgetPosY();
4307 m_pState
->EnsureVirtualHeight();
4309 wxASSERT_LEVEL_2_MSG(
4310 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4311 "VirtualHeight and ActualVirtualHeight should match"
4314 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4316 int x
= m_pState
->m_width
;
4317 int y
= m_pState
->m_virtualHeight
;
4320 GetClientSize(&width
,&height
);
4322 // Now adjust virtual size.
4323 SetVirtualSize(x
, y
);
4329 // Adjust scrollbars
4330 if ( HasVirtualWidth() )
4332 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4333 xPos
= GetScrollPos( wxHORIZONTAL
);
4336 if ( forceXPos
!= -1 )
4339 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4342 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4343 int yPos
= GetScrollPos( wxVERTICAL
);
4345 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4346 xAmount
, yAmount
, xPos
, yPos
, true );
4348 // Must re-get size now
4349 GetClientSize(&width
,&height
);
4351 if ( !HasVirtualWidth() )
4353 m_pState
->SetVirtualWidth(width
);
4360 m_pState
->CheckColumnWidths();
4362 if ( GetSelection() )
4363 CorrectEditorWidgetSizeX();
4365 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4368 // -----------------------------------------------------------------------
4370 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4372 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4376 GetClientSize(&width
, &height
);
4381 #if wxPG_DOUBLE_BUFFER
4382 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4384 int dblh
= (m_lineHeight
*2);
4385 if ( !m_doubleBuffer
)
4387 // Create double buffer bitmap to draw on, if none
4388 int w
= (width
>250)?width
:250;
4389 int h
= height
+ dblh
;
4391 m_doubleBuffer
= new wxBitmap( w
, h
);
4395 int w
= m_doubleBuffer
->GetWidth();
4396 int h
= m_doubleBuffer
->GetHeight();
4398 // Double buffer must be large enough
4399 if ( w
< width
|| h
< (height
+dblh
) )
4401 if ( w
< width
) w
= width
;
4402 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4403 delete m_doubleBuffer
;
4404 m_doubleBuffer
= new wxBitmap( w
, h
);
4411 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4412 m_ncWidth
= event
.GetSize().x
;
4416 if ( m_pState
->m_itemsAdded
)
4417 PrepareAfterItemsAdded();
4419 // Without this, virtual size (atleast under wxGTK) will be skewed
4420 RecalculateVirtualSize();
4426 // -----------------------------------------------------------------------
4428 void wxPropertyGrid::SetVirtualWidth( int width
)
4432 // Disable virtual width
4433 width
= GetClientSize().x
;
4434 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4438 // Enable virtual width
4439 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4441 m_pState
->SetVirtualWidth( width
);
4444 void wxPropertyGrid::SetFocusOnCanvas()
4446 SetFocusIgnoringChildren();
4447 m_editorFocused
= 0;
4450 // -----------------------------------------------------------------------
4451 // wxPropertyGrid mouse event handling
4452 // -----------------------------------------------------------------------
4454 // selFlags uses same values DoSelectProperty's flags
4455 // Returns true if event was vetoed.
4456 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4458 unsigned int selFlags
,
4459 unsigned int column
)
4461 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4464 // Send property grid event of specific type and with specific property
4465 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4466 evt
.SetPropertyGrid(this);
4467 evt
.SetEventObject(m_eventObject
);
4469 evt
.SetColumn(column
);
4470 if ( eventType
== wxEVT_PG_CHANGING
)
4473 evt
.SetCanVeto(true);
4474 m_validationInfo
.m_pValue
= pValue
;
4475 evt
.SetupValidationInfo();
4480 evt
.SetPropertyValue(p
->GetValue());
4482 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4483 evt
.SetCanVeto(true);
4486 m_processedEvent
= &evt
;
4487 m_eventObject
->HandleWindowEvent(evt
);
4488 m_processedEvent
= NULL
;
4490 return evt
.WasVetoed();
4493 // -----------------------------------------------------------------------
4495 // Return false if should be skipped
4496 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4500 // Need to set focus?
4501 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4506 wxPropertyGridPageState
* state
= m_pState
;
4508 int splitterHitOffset
;
4509 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4511 wxPGProperty
* p
= DoGetItemAtY(y
);
4515 int depth
= (int)p
->GetDepth() - 1;
4517 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4519 if ( x
>= marginEnds
)
4523 if ( p
->IsCategory() )
4525 // This is category.
4526 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4528 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4530 // Expand, collapse, activate etc. if click on text or left of splitter.
4533 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4538 if ( !AddToSelectionFromInputEvent( p
,
4543 // On double-click, expand/collapse.
4544 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4546 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4547 else DoExpand( p
, true );
4551 else if ( splitterHit
== -1 )
4554 unsigned int selFlag
= 0;
4555 if ( columnHit
== 1 )
4557 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4558 selFlag
= wxPG_SEL_FOCUS
;
4560 if ( !AddToSelectionFromInputEvent( p
,
4566 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4568 if ( p
->GetChildCount() && !p
->IsCategory() )
4569 // On double-click, expand/collapse.
4570 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4572 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4573 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4574 else DoExpand( p
, true );
4581 // click on splitter
4582 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4584 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4586 // Double-clicking the splitter causes auto-centering
4587 if ( m_pState
->GetColumnCount() <= 2 )
4589 CenterSplitter( true );
4591 SendEvent(wxEVT_PG_COL_DRAGGING
,
4594 wxPG_SEL_NOVALIDATE
,
4595 (unsigned int)m_draggedSplitter
);
4598 else if ( m_dragStatus
== 0 )
4601 // Begin draggin the splitter
4605 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4607 // Allow application to veto dragging
4608 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4610 (unsigned int)splitterHit
) )
4614 // Changes must be committed here or the
4615 // value won't be drawn correctly
4616 if ( !CommitChangesFromEditor() )
4619 m_wndEditor
->Show ( false );
4622 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4625 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4629 m_draggedSplitter
= splitterHit
;
4630 m_dragOffset
= splitterHitOffset
;
4632 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4633 // Fixes button disappearance bug
4635 m_wndEditor2
->Show ( false );
4638 m_startingSplitterX
= x
- splitterHitOffset
;
4647 if ( p
->GetChildCount() )
4649 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4651 // Fine tune cell button x
4652 if ( !p
->IsCategory() )
4653 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4655 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4657 int y2
= y
% m_lineHeight
;
4658 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4660 // On click on expander button, expand/collapse
4661 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4662 DoCollapse( p
, true );
4664 DoExpand( p
, true );
4673 // -----------------------------------------------------------------------
4675 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4676 unsigned int WXUNUSED(y
),
4677 wxMouseEvent
& event
)
4681 // Select property here as well
4682 wxPGProperty
* p
= m_propHover
;
4683 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4685 // Send right click event.
4686 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4693 // -----------------------------------------------------------------------
4695 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4696 unsigned int WXUNUSED(y
),
4697 wxMouseEvent
& event
)
4701 // Select property here as well
4702 wxPGProperty
* p
= m_propHover
;
4704 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4706 // Send double-click event.
4707 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4714 // -----------------------------------------------------------------------
4716 #if wxPG_SUPPORT_TOOLTIPS
4718 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4720 if ( tipString
.length() )
4722 wxScrolledWindow::SetToolTip(tipString
);
4726 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4727 wxScrolledWindow::SetToolTip( m_emptyString
);
4729 wxScrolledWindow::SetToolTip( NULL
);
4734 #endif // #if wxPG_SUPPORT_TOOLTIPS
4736 // -----------------------------------------------------------------------
4738 // Return false if should be skipped
4739 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4740 wxMouseEvent
&event
)
4742 // Safety check (needed because mouse capturing may
4743 // otherwise freeze the control)
4744 if ( m_dragStatus
> 0 && !event
.Dragging() )
4746 HandleMouseUp(x
, y
, event
);
4749 wxPropertyGridPageState
* state
= m_pState
;
4751 int splitterHitOffset
;
4752 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4753 int splitterX
= x
- splitterHitOffset
;
4755 m_colHover
= columnHit
;
4757 if ( m_dragStatus
> 0 )
4759 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4760 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4763 int newSplitterX
= x
- m_dragOffset
;
4764 int splitterX
= x
- splitterHitOffset
;
4766 // Splitter redraw required?
4767 if ( newSplitterX
!= splitterX
)
4770 DoSetSplitterPosition(newSplitterX
,
4772 wxPG_SPLITTER_REFRESH
|
4773 wxPG_SPLITTER_FROM_EVENT
);
4775 SendEvent(wxEVT_PG_COL_DRAGGING
,
4778 wxPG_SEL_NOVALIDATE
,
4779 (unsigned int)m_draggedSplitter
);
4790 int ih
= m_lineHeight
;
4793 #if wxPG_SUPPORT_TOOLTIPS
4794 wxPGProperty
* prevHover
= m_propHover
;
4795 unsigned char prevSide
= m_mouseSide
;
4797 int curPropHoverY
= y
- (y
% ih
);
4799 // On which item it hovers
4802 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4805 // Mouse moves on another property
4807 m_propHover
= DoGetItemAtY(y
);
4808 m_propHoverY
= curPropHoverY
;
4811 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4814 #if wxPG_SUPPORT_TOOLTIPS
4815 // Store which side we are on
4817 if ( columnHit
== 1 )
4819 else if ( columnHit
== 0 )
4823 // If tooltips are enabled, show label or value as a tip
4824 // in case it doesn't otherwise show in full length.
4826 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4828 wxToolTip
* tooltip
= GetToolTip();
4830 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4832 if ( m_propHover
&& !m_propHover
->IsCategory() )
4835 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4837 // Show help string as a tooltip
4838 wxString tipString
= m_propHover
->GetHelpString();
4840 SetToolTip(tipString
);
4844 // Show cropped value string as a tooltip
4848 if ( m_mouseSide
== 1 )
4850 tipString
= m_propHover
->m_label
;
4851 space
= splitterX
-m_marginWidth
-3;
4853 else if ( m_mouseSide
== 2 )
4855 tipString
= m_propHover
->GetDisplayedString();
4857 space
= m_width
- splitterX
;
4858 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4859 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
4860 wxCC_CUSTOM_IMAGE_MARGIN1
+
4861 wxCC_CUSTOM_IMAGE_MARGIN2
;
4867 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4870 SetToolTip( tipString
);
4877 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4878 SetToolTip( m_emptyString
);
4880 wxScrolledWindow::SetToolTip( NULL
);
4891 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4892 SetToolTip( m_emptyString
);
4894 wxScrolledWindow::SetToolTip( NULL
);
4902 if ( splitterHit
== -1 ||
4904 HasFlag(wxPG_STATIC_SPLITTER
) )
4906 // hovering on something else
4907 if ( m_curcursor
!= wxCURSOR_ARROW
)
4908 CustomSetCursor( wxCURSOR_ARROW
);
4912 // Do not allow splitter cursor on caption items.
4913 // (also not if we were dragging and its started
4914 // outside the splitter region)
4916 if ( !m_propHover
->IsCategory() &&
4920 // hovering on splitter
4922 // NB: Condition disabled since MouseLeave event (from the
4923 // editor control) cannot be reliably detected.
4924 //if ( m_curcursor != wxCURSOR_SIZEWE )
4925 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4931 // hovering on something else
4932 if ( m_curcursor
!= wxCURSOR_ARROW
)
4933 CustomSetCursor( wxCURSOR_ARROW
);
4938 // Multi select by dragging
4940 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
4941 event
.LeftIsDown() &&
4945 !state
->DoIsPropertySelected(m_propHover
) )
4947 // Additional requirement is that the hovered property
4948 // is adjacent to edges of selection.
4949 const wxArrayPGProperty
& selection
= GetSelectedProperties();
4951 // Since categories cannot be selected along with 'other'
4952 // properties, exclude them from iterator flags.
4953 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
4955 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
4957 // TODO: This could be optimized by keeping track of
4958 // which properties are at the edges of selection.
4959 wxPGProperty
* selProp
= selection
[i
];
4960 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
4963 DoAddToSelection(m_propHover
);
4972 // -----------------------------------------------------------------------
4974 // Also handles Leaving event
4975 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4976 wxMouseEvent
&WXUNUSED(event
) )
4978 wxPropertyGridPageState
* state
= m_pState
;
4982 int splitterHitOffset
;
4983 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4985 // No event type check - basicly calling this method should
4986 // just stop dragging.
4987 // Left up after dragged?
4988 if ( m_dragStatus
>= 1 )
4991 // End Splitter Dragging
4993 // DO NOT ENABLE FOLLOWING LINE!
4994 // (it is only here as a reminder to not to do it)
4997 SendEvent(wxEVT_PG_COL_END_DRAG
,
5000 wxPG_SEL_NOVALIDATE
,
5001 (unsigned int)m_draggedSplitter
);
5003 // Disable splitter auto-centering
5004 state
->m_dontCenterSplitter
= true;
5006 // This is necessary to return cursor
5007 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5010 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5013 // Set back the default cursor, if necessary
5014 if ( splitterHit
== -1 ||
5017 CustomSetCursor( wxCURSOR_ARROW
);
5022 // Control background needs to be cleared
5023 wxPGProperty
* selected
= GetSelection();
5024 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5025 DrawItem( selected
);
5029 m_wndEditor
->Show ( true );
5032 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5033 // Fixes button disappearance bug
5035 m_wndEditor2
->Show ( true );
5038 // This clears the focus.
5039 m_editorFocused
= 0;
5045 // -----------------------------------------------------------------------
5047 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5049 int splitterX
= GetSplitterPosition();
5052 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5054 wxWindow
* wnd
= GetEditorControl();
5056 // Hide popup on clicks
5057 if ( event
.GetEventType() != wxEVT_MOTION
)
5058 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5060 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5066 if ( wnd
== NULL
|| m_dragStatus
||
5068 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5069 ux
>= (r
.x
+r
.width
) ||
5071 event
.m_y
>= (r
.y
+r
.height
)
5081 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5086 // -----------------------------------------------------------------------
5088 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5091 if ( OnMouseCommon( event
, &x
, &y
) )
5093 HandleMouseClick(x
,y
,event
);
5098 // -----------------------------------------------------------------------
5100 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5103 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5104 HandleMouseRightClick(x
,y
,event
);
5108 // -----------------------------------------------------------------------
5110 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5112 // Always run standard mouse-down handler as well
5113 OnMouseClick(event
);
5116 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5117 HandleMouseDoubleClick(x
,y
,event
);
5121 // -----------------------------------------------------------------------
5123 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5126 if ( OnMouseCommon( event
, &x
, &y
) )
5128 HandleMouseMove(x
,y
,event
);
5133 // -----------------------------------------------------------------------
5135 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5138 if ( OnMouseCommon( event
, &x
, &y
) )
5140 HandleMouseUp(x
,y
,event
);
5145 // -----------------------------------------------------------------------
5147 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5149 // This may get called from child control as well, so event's
5150 // mouse position cannot be relied on.
5152 if ( event
.Entering() )
5154 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5156 // TODO: Fix this (detect parent and only do
5157 // cursor trick if it is a manager).
5158 wxASSERT( GetParent() );
5159 GetParent()->SetCursor(wxNullCursor
);
5161 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5164 GetParent()->SetCursor(wxNullCursor
);
5166 else if ( event
.Leaving() )
5168 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5169 SetCursor( wxNullCursor
);
5171 // Get real cursor position
5172 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5174 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5177 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5179 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5183 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5191 // -----------------------------------------------------------------------
5193 // Common code used by various OnMouseXXXChild methods.
5194 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5196 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5197 wxASSERT( topCtrlWnd
);
5199 event
.GetPosition(&x
,&y
);
5201 int splitterX
= GetSplitterPosition();
5203 wxRect r
= topCtrlWnd
->GetRect();
5204 if ( !m_dragStatus
&&
5205 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5206 y
>= 0 && y
< r
.height \
5209 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5214 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5221 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5224 if ( OnMouseChildCommon(event
,&x
,&y
) )
5226 bool res
= HandleMouseClick(x
,y
,event
);
5227 if ( !res
) event
.Skip();
5231 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5234 wxASSERT( m_wndEditor
);
5235 // These coords may not be exact (about +-2),
5236 // but that should not matter (right click is about item, not position).
5237 wxPoint pt
= m_wndEditor
->GetPosition();
5238 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5240 // FIXME: Used to set m_propHover to selection here. Was it really
5243 bool res
= HandleMouseRightClick(x
,y
,event
);
5244 if ( !res
) event
.Skip();
5247 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5250 if ( OnMouseChildCommon(event
,&x
,&y
) )
5252 bool res
= HandleMouseMove(x
,y
,event
);
5253 if ( !res
) event
.Skip();
5257 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5260 if ( OnMouseChildCommon(event
,&x
,&y
) )
5262 bool res
= HandleMouseUp(x
,y
,event
);
5263 if ( !res
) event
.Skip();
5267 // -----------------------------------------------------------------------
5268 // wxPropertyGrid keyboard event handling
5269 // -----------------------------------------------------------------------
5271 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5273 // Translates wxKeyEvent to wxPG_ACTION_XXX
5275 int keycode
= event
.GetKeyCode();
5276 int modifiers
= event
.GetModifiers();
5278 wxASSERT( !(modifiers
&~(0xFFFF)) );
5280 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5282 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5284 if ( it
== m_actionTriggers
.end() )
5289 int second
= (it
->second
>>16) & 0xFFFF;
5293 return (it
->second
& 0xFFFF);
5296 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5298 wxASSERT( !(modifiers
&~(0xFFFF)) );
5300 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5302 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5304 if ( it
!= m_actionTriggers
.end() )
5306 // This key combination is already used
5308 // Can add secondary?
5309 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5310 wxT("You can only add up to two separate actions per key combination.") );
5312 action
= it
->second
| (action
<<16);
5315 m_actionTriggers
[hashMapKey
] = action
;
5318 void wxPropertyGrid::ClearActionTriggers( int action
)
5320 wxPGHashMapI2I::iterator it
;
5325 didSomething
= false;
5327 for ( it
= m_actionTriggers
.begin();
5328 it
!= m_actionTriggers
.end();
5331 if ( it
->second
== action
)
5333 m_actionTriggers
.erase(it
);
5334 didSomething
= true;
5339 while ( didSomething
);
5342 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5345 // Handles key event when editor control is not focused.
5348 wxCHECK2(!m_frozen
, return);
5350 // Travelsal between items, collapsing/expanding, etc.
5351 wxPGProperty
* selected
= GetSelection();
5352 int keycode
= event
.GetKeyCode();
5353 bool editorFocused
= IsEditorFocused();
5355 if ( keycode
== WXK_TAB
)
5357 wxWindow
* mainControl
;
5359 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5360 mainControl
= GetParent();
5364 if ( !event
.ShiftDown() )
5366 if ( !editorFocused
&& m_wndEditor
)
5368 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5372 // Tab traversal workaround for platforms on which
5373 // wxWindow::Navigate() may navigate into first child
5374 // instead of next sibling. Does not work perfectly
5375 // in every scenario (for instance, when property grid
5376 // is either first or last control).
5377 #if defined(__WXGTK__)
5378 wxWindow
* sibling
= mainControl
->GetNextSibling();
5380 sibling
->SetFocusFromKbd();
5382 Navigate(wxNavigationKeyEvent::IsForward
);
5388 if ( editorFocused
)
5394 #if defined(__WXGTK__)
5395 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5397 sibling
->SetFocusFromKbd();
5399 Navigate(wxNavigationKeyEvent::IsBackward
);
5407 // Ignore Alt and Control when they are down alone
5408 if ( keycode
== WXK_ALT
||
5409 keycode
== WXK_CONTROL
)
5416 int action
= KeyEventToActions(event
, &secondAction
);
5418 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5421 // Esc cancels any changes
5422 if ( IsEditorsValueModified() )
5424 EditorsValueWasNotModified();
5426 // Update the control as well
5427 selected
->GetEditorClass()->
5428 SetControlStringValue( selected
,
5430 selected
->GetDisplayedString() );
5433 OnValidationFailureReset(selected
);
5439 // Except for TAB and ESC, handle child control events in child control
5442 // Only propagate event if it had modifiers
5443 if ( !event
.HasModifiers() )
5445 event
.StopPropagation();
5451 bool wasHandled
= false;
5456 if ( ButtonTriggerKeyTest(action
, event
) )
5459 wxPGProperty
* p
= selected
;
5461 // Travel and expand/collapse
5464 if ( p
->GetChildCount() )
5466 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5468 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5471 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5473 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5480 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5484 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5490 if ( selectDir
>= -1 )
5492 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5494 DoSelectProperty(p
);
5500 // If nothing was selected, select the first item now
5501 // (or navigate out of tab).
5502 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5504 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5505 if ( p
) DoSelectProperty(p
);
5514 // -----------------------------------------------------------------------
5516 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5518 // If there was editor open and focused, then this event should not
5519 // really be processed here.
5520 if ( IsEditorFocused() )
5522 // However, if event had modifiers, it is probably still best
5524 if ( event
.HasModifiers() )
5527 event
.StopPropagation();
5531 HandleKeyEvent(event
, false);
5534 // -----------------------------------------------------------------------
5536 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5541 action
= KeyEventToActions(event
, &secondAction
);
5544 // Does the keycode trigger button?
5545 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5548 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5549 GetEventHandler()->AddPendingEvent(evt
);
5556 // -----------------------------------------------------------------------
5558 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5560 HandleKeyEvent(event
, true);
5563 // -----------------------------------------------------------------------
5564 // wxPropertyGrid miscellaneous event handling
5565 // -----------------------------------------------------------------------
5567 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5570 // Check if the focus is in this control or one of its children
5571 wxWindow
* newFocused
= wxWindow::FindFocus();
5573 if ( newFocused
!= m_curFocused
)
5574 HandleFocusChange( newFocused
);
5577 // Check if top-level parent has changed
5578 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5580 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5586 bool wxPropertyGrid::IsEditorFocused() const
5588 wxWindow
* focus
= wxWindow::FindFocus();
5590 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5591 focus
== GetEditorControl() )
5597 // Called by focus event handlers. newFocused is the window that becomes focused.
5598 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5600 unsigned int oldFlags
= m_iFlags
;
5601 bool wasEditorFocused
= false;
5602 wxWindow
* wndEditor
= m_wndEditor
;
5604 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5606 wxWindow
* parent
= newFocused
;
5608 // This must be one of nextFocus' parents.
5611 if ( parent
== wndEditor
)
5613 wasEditorFocused
= true;
5615 // Use m_eventObject, which is either wxPropertyGrid or
5616 // wxPropertyGridManager, as appropriate.
5617 else if ( parent
== m_eventObject
)
5619 m_iFlags
|= wxPG_FL_FOCUSED
;
5622 parent
= parent
->GetParent();
5625 // Notify editor control when it receives a focus
5626 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5628 wxPGProperty
* p
= GetSelection();
5631 const wxPGEditor
* editor
= p
->GetEditorClass();
5632 editor
->OnFocus(p
, GetEditorControl());
5636 m_curFocused
= newFocused
;
5638 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5639 (oldFlags
& wxPG_FL_FOCUSED
) )
5641 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5643 // Need to store changed value
5644 CommitChangesFromEditor();
5650 // Preliminary code for tab-order respecting
5651 // tab-traversal (but should be moved to
5654 wxWindow* prevFocus = event.GetWindow();
5655 wxWindow* useThis = this;
5656 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5657 useThis = GetParent();
5660 prevFocus->GetParent() == useThis->GetParent() )
5662 wxList& children = useThis->GetParent()->GetChildren();
5664 wxNode* node = children.Find(prevFocus);
5666 if ( node->GetNext() &&
5667 useThis == node->GetNext()->GetData() )
5668 DoSelectProperty(GetFirst());
5669 else if ( node->GetPrevious () &&
5670 useThis == node->GetPrevious()->GetData() )
5671 DoSelectProperty(GetLastProperty());
5678 wxPGProperty
* selected
= GetSelection();
5679 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5680 DrawItem( selected
);
5684 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5686 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5687 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5688 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5689 //else if ( event.GetWindow() )
5691 HandleFocusChange(event
.GetWindow());
5696 // -----------------------------------------------------------------------
5698 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5700 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5704 // -----------------------------------------------------------------------
5706 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5708 m_iFlags
|= wxPG_FL_SCROLLED
;
5713 // -----------------------------------------------------------------------
5715 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5717 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5719 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5723 // -----------------------------------------------------------------------
5724 // Property editor related functions
5725 // -----------------------------------------------------------------------
5727 // noDefCheck = true prevents infinite recursion.
5728 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5729 const wxString
& editorName
,
5732 wxASSERT( editorClass
);
5734 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5735 RegisterDefaultEditors();
5737 wxString name
= editorName
;
5738 if ( name
.length() == 0 )
5739 name
= editorClass
->GetName();
5741 // Existing editor under this name?
5742 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5744 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5746 // If this name was already used, try class name.
5747 name
= editorClass
->GetClassInfo()->GetClassName();
5748 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5751 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5752 (wxPGEditor
*) vt_it
->second
,
5753 "Editor with given name was already registered" );
5755 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5760 // Use this in RegisterDefaultEditors.
5761 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5762 if ( wxPGEditor_##EDITOR == NULL ) \
5764 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5765 new wxPG##EDITOR##Editor, true ); \
5768 // Registers all default editor classes
5769 void wxPropertyGrid::RegisterDefaultEditors()
5771 wxPGRegisterDefaultEditorClass( TextCtrl
);
5772 wxPGRegisterDefaultEditorClass( Choice
);
5773 wxPGRegisterDefaultEditorClass( ComboBox
);
5774 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5775 #if wxPG_INCLUDE_CHECKBOX
5776 wxPGRegisterDefaultEditorClass( CheckBox
);
5778 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5780 // Register SpinCtrl etc. editors before use
5781 RegisterAdditionalEditors();
5784 // -----------------------------------------------------------------------
5785 // wxPGStringTokenizer
5786 // Needed to handle C-style string lists (e.g. "str1" "str2")
5787 // -----------------------------------------------------------------------
5789 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5790 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5794 wxPGStringTokenizer::~wxPGStringTokenizer()
5798 bool wxPGStringTokenizer::HasMoreTokens()
5800 const wxString
& str
= *m_str
;
5802 wxString::const_iterator i
= m_curPos
;
5804 wxUniChar delim
= m_delimeter
;
5806 wxUniChar prev_a
= wxT('\0');
5808 bool inToken
= false;
5810 while ( i
!= str
.end() )
5819 m_readyToken
.clear();
5824 if ( prev_a
!= wxT('\\') )
5828 if ( a
!= wxT('\\') )
5848 m_curPos
= str
.end();
5856 wxString
wxPGStringTokenizer::GetNextToken()
5858 return m_readyToken
;
5861 // -----------------------------------------------------------------------
5863 // -----------------------------------------------------------------------
5865 wxPGChoiceEntry::wxPGChoiceEntry()
5866 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5870 // -----------------------------------------------------------------------
5872 // -----------------------------------------------------------------------
5874 wxPGChoicesData::wxPGChoicesData()
5878 wxPGChoicesData::~wxPGChoicesData()
5883 void wxPGChoicesData::Clear()
5888 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5890 wxASSERT( m_items
.size() == 0 );
5892 m_items
= data
->m_items
;
5895 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5896 const wxPGChoiceEntry
& item
)
5898 wxVector
<wxPGChoiceEntry
>::iterator it
;
5902 index
= (int) m_items
.size();
5906 it
= m_items
.begin() + index
;
5909 m_items
.insert(it
, item
);
5911 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5913 // Need to fix value?
5914 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5915 ownEntry
.SetValue(index
);
5920 // -----------------------------------------------------------------------
5921 // wxPropertyGridEvent
5922 // -----------------------------------------------------------------------
5924 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5927 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5928 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5929 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5930 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5931 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5932 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5933 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5934 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5935 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5936 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5937 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5938 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
5939 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
5940 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
5942 // -----------------------------------------------------------------------
5944 void wxPropertyGridEvent::Init()
5946 m_validationInfo
= NULL
;
5949 m_wasVetoed
= false;
5952 // -----------------------------------------------------------------------
5954 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5955 : wxCommandEvent(commandType
,id
)
5961 // -----------------------------------------------------------------------
5963 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5964 : wxCommandEvent(event
)
5966 m_eventType
= event
.GetEventType();
5967 m_eventObject
= event
.m_eventObject
;
5969 OnPropertyGridSet();
5970 m_property
= event
.m_property
;
5971 m_validationInfo
= event
.m_validationInfo
;
5972 m_canVeto
= event
.m_canVeto
;
5973 m_wasVetoed
= event
.m_wasVetoed
;
5976 // -----------------------------------------------------------------------
5978 void wxPropertyGridEvent::OnPropertyGridSet()
5984 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
5986 m_pg
->m_liveEvents
.push_back(this);
5989 // -----------------------------------------------------------------------
5991 wxPropertyGridEvent::~wxPropertyGridEvent()
5996 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
5999 // Use iterate from the back since it is more likely that the event
6000 // being desroyed is at the end of the array.
6001 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6003 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6005 if ( liveEvents
[i
] == this )
6007 liveEvents
.erase(liveEvents
.begin() + i
);
6014 // -----------------------------------------------------------------------
6016 wxEvent
* wxPropertyGridEvent::Clone() const
6018 return new wxPropertyGridEvent( *this );
6021 // -----------------------------------------------------------------------
6022 // wxPropertyGridPopulator
6023 // -----------------------------------------------------------------------
6025 wxPropertyGridPopulator::wxPropertyGridPopulator()
6029 wxPGGlobalVars
->m_offline
++;
6032 // -----------------------------------------------------------------------
6034 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6037 m_propHierarchy
.clear();
6040 // -----------------------------------------------------------------------
6042 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6048 // -----------------------------------------------------------------------
6050 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6053 // Free unused sets of choices
6054 wxPGHashMapS2P::iterator it
;
6056 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6058 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6065 m_pg
->GetPanel()->Refresh();
6067 wxPGGlobalVars
->m_offline
--;
6070 // -----------------------------------------------------------------------
6072 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6073 const wxString
& propLabel
,
6074 const wxString
& propName
,
6075 const wxString
* propValue
,
6076 wxPGChoices
* pChoices
)
6078 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6079 wxPGProperty
* parent
= GetCurParent();
6081 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6083 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6087 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6089 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6093 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6095 property
->SetLabel(propLabel
);
6096 property
->DoSetName(propName
);
6098 if ( pChoices
&& pChoices
->IsOk() )
6099 property
->SetChoices(*pChoices
);
6101 m_state
->DoInsert(parent
, -1, property
);
6104 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6105 wxPG_PROGRAMMATIC_VALUE
);
6110 // -----------------------------------------------------------------------
6112 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6114 m_propHierarchy
.push_back(property
);
6115 DoScanForChildren();
6116 m_propHierarchy
.pop_back();
6119 // -----------------------------------------------------------------------
6121 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6122 const wxString
& idString
)
6124 wxPGChoices choices
;
6127 if ( choicesString
[0] == wxT('@') )
6129 wxString ids
= choicesString
.substr(1);
6130 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6131 if ( it
== m_dictIdChoices
.end() )
6132 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6134 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6139 if ( idString
.length() )
6141 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6142 if ( it
!= m_dictIdChoices
.end() )
6144 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6151 // Parse choices string
6152 wxString::const_iterator it
= choicesString
.begin();
6156 bool labelValid
= false;
6158 for ( ; it
!= choicesString
.end(); ++it
)
6164 if ( c
== wxT('"') )
6169 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6170 choices
.Add(label
, l
);
6173 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6178 else if ( c
== wxT('=') )
6185 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6192 if ( c
== wxT('"') )
6205 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6206 choices
.Add(label
, l
);
6209 if ( !choices
.IsOk() )
6211 choices
.EnsureData();
6215 if ( idString
.length() )
6216 m_dictIdChoices
[idString
] = choices
.GetData();
6223 // -----------------------------------------------------------------------
6225 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6227 if ( s
.Last() == wxT('%') )
6229 wxString s2
= s
.substr(0,s
.length()-1);
6231 if ( s2
.ToLong(&val
, 10) )
6233 *pval
= (val
*max
)/100;
6239 return s
.ToLong(pval
, 10);
6242 // -----------------------------------------------------------------------
6244 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6245 const wxString
& type
,
6246 const wxString
& value
)
6248 int l
= m_propHierarchy
.size();
6252 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6253 wxString valuel
= value
.Lower();
6256 if ( type
.length() == 0 )
6261 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6263 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6265 else if ( value
.ToLong(&v
, 0) )
6272 if ( type
== wxT("string") )
6276 else if ( type
== wxT("int") )
6279 value
.ToLong(&v
, 0);
6282 else if ( type
== wxT("bool") )
6284 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6291 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6296 p
->SetAttribute( name
, variant
);
6301 // -----------------------------------------------------------------------
6303 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6305 wxLogError(_("Error in resource: %s"),msg
.c_str());
6308 // -----------------------------------------------------------------------
6310 #endif // wxUSE_PROPGRID