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_strHint
= wxS("Hint");
204 #if wxPG_COMPATIBILITY_1_4
205 m_strInlineHelp
= wxS("InlineHelp");
212 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
216 delete m_defaultRenderer
;
218 // This will always have one ref
219 delete m_fontFamilyChoices
;
222 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
223 delete ((wxValidator
*)m_arrValidators
[i
]);
227 // Destroy value type class instances.
228 wxPGHashMapS2P::iterator vt_it
;
230 // Destroy editor class instances.
231 // iterate over all the elements in the class
232 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
234 delete ((wxPGEditor
*)vt_it
->second
);
237 delete wxPGProperty::sm_wxPG_LABEL
;
240 void wxPropertyGridInitGlobalsIfNeeded()
244 // -----------------------------------------------------------------------
246 // -----------------------------------------------------------------------
248 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
250 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
251 EVT_IDLE(wxPropertyGrid::OnIdle
)
252 EVT_PAINT(wxPropertyGrid::OnPaint
)
253 EVT_SIZE(wxPropertyGrid::OnResize
)
254 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
255 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
256 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
257 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
258 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
259 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
260 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
261 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
262 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
263 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
264 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
265 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
266 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
267 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
270 // -----------------------------------------------------------------------
272 wxPropertyGrid::wxPropertyGrid()
278 // -----------------------------------------------------------------------
280 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
285 const wxString
& name
)
289 Create(parent
,id
,pos
,size
,style
,name
);
292 // -----------------------------------------------------------------------
294 bool wxPropertyGrid::Create( wxWindow
*parent
,
299 const wxString
& name
)
302 if (!(style
&wxBORDER_MASK
))
304 style
|= wxBORDER_THEME
;
309 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
310 style
&= ~(wxTAB_TRAVERSAL
);
311 style
|= wxWANTS_CHARS
;
313 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
320 // -----------------------------------------------------------------------
323 // Initialize values to defaults
325 void wxPropertyGrid::Init1()
327 // Register editor classes, if necessary.
328 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
329 wxPropertyGrid::RegisterDefaultEditors();
333 m_wndEditor
= m_wndEditor2
= NULL
;
337 m_labelEditor
= NULL
;
338 m_labelEditorProperty
= NULL
;
339 m_eventObject
= this;
341 m_processedEvent
= NULL
;
342 m_sortFunction
= NULL
;
343 m_inDoPropertyChanged
= 0;
344 m_inCommitChangesFromEditor
= 0;
345 m_inDoSelectProperty
= 0;
346 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
351 // Set up default unspecified value 'colour'
352 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
355 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
356 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
357 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
358 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
359 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
360 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
361 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
362 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
363 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
365 m_coloursCustomized
= 0;
368 #if wxPG_DOUBLE_BUFFER
369 m_doubleBuffer
= NULL
;
372 #ifndef wxPG_ICON_WIDTH
378 m_iconWidth
= wxPG_ICON_WIDTH
;
383 m_gutterWidth
= wxPG_GUTTER_MIN
;
384 m_subgroup_extramargin
= 10;
388 m_width
= m_height
= 0;
390 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
393 m_chgInfo_changedProperty
= NULL
;
396 // -----------------------------------------------------------------------
399 // Initialize after parent etc. set
401 void wxPropertyGrid::Init2()
403 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
406 // Smaller controls on Mac
407 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
410 // Now create state, if one didn't exist already
411 // (wxPropertyGridManager might have created it for us).
414 m_pState
= CreateState();
415 m_pState
->m_pPropGrid
= this;
416 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
419 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
420 m_pState
->m_dontCenterSplitter
= true;
422 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
424 m_pState
->InitNonCatMode();
426 m_pState
->m_properties
= m_pState
->m_abcArray
;
429 GetClientSize(&m_width
,&m_height
);
431 #ifndef wxPG_ICON_WIDTH
432 // create two bitmap nodes for drawing
433 m_expandbmp
= new wxBitmap(expand_xpm
);
434 m_collbmp
= new wxBitmap(collapse_xpm
);
436 // calculate average font height for bitmap centering
438 m_iconWidth
= m_expandbmp
->GetWidth();
439 m_iconHeight
= m_expandbmp
->GetHeight();
442 m_curcursor
= wxCURSOR_ARROW
;
443 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
445 // adjust bitmap icon y position so they are centered
446 m_vspacing
= wxPG_DEFAULT_VSPACING
;
448 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
450 // Allocate cell datas
451 m_propertyDefaultCell
.SetEmptyData();
452 m_categoryDefaultCell
.SetEmptyData();
456 // This helps with flicker
457 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
459 // Hook the top-level parent
464 // set virtual size to this window size
465 wxSize wndsize
= GetSize();
466 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
468 m_timeCreated
= ::wxGetLocalTimeMillis();
470 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
471 // wxWANTS_CHARS | wxCLIP_CHILDREN);
472 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
474 m_iFlags
|= wxPG_FL_INITIALIZED
;
476 m_ncWidth
= wndsize
.GetWidth();
478 // Need to call OnResize handler or size given in constructor/Create
480 wxSizeEvent
sizeEvent(wndsize
,0);
484 // -----------------------------------------------------------------------
486 wxPropertyGrid::~wxPropertyGrid()
491 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
495 // Remove grid and property pointers from live wxPropertyGridEvents.
496 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
498 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
499 evt
->SetPropertyGrid(NULL
);
500 evt
->SetProperty(NULL
);
502 m_liveEvents
.clear();
504 if ( m_processedEvent
)
506 // All right... we are being deleted while wxPropertyGrid event
507 // is being sent. Make sure that event propagates as little
508 // as possible (although usually this is not enough to prevent
510 m_processedEvent
->Skip(false);
511 m_processedEvent
->StopPropagation();
513 // Let's use wxMessageBox to make the message appear more
514 // reliably (and *before* the crash can happen).
515 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
516 "generated by it. This usually leads to a crash "
517 "so it is recommended to destroy the control "
518 "at idle time instead.");
521 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
523 // This should do prevent things from going too badly wrong
524 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
526 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
529 // Call with NULL to disconnect event handling
530 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
534 wxASSERT_MSG( !IsEditorsValueModified(),
535 wxS("Most recent change in property editor was ")
536 wxS("lost!!! (if you don't want this to happen, ")
537 wxS("close your frames and dialogs using ")
538 wxS("Close(false).)") );
541 #if wxPG_DOUBLE_BUFFER
542 if ( m_doubleBuffer
)
543 delete m_doubleBuffer
;
546 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
549 delete m_cursorSizeWE
;
551 #ifndef wxPG_ICON_WIDTH
556 // Delete common value records
557 for ( i
=0; i
<m_commonValues
.size(); i
++ )
559 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
560 wxPGCommonValue
* value
= m_commonValues
[i
];
565 // -----------------------------------------------------------------------
567 bool wxPropertyGrid::Destroy()
569 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
572 return wxScrolledWindow::Destroy();
575 // -----------------------------------------------------------------------
577 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
579 return new wxPropertyGridPageState();
582 // -----------------------------------------------------------------------
583 // wxPropertyGrid overridden wxWindow methods
584 // -----------------------------------------------------------------------
586 void wxPropertyGrid::SetWindowStyleFlag( long style
)
588 long old_style
= m_windowStyle
;
590 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
592 wxASSERT( m_pState
);
594 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
597 EnableCategories( true );
599 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
601 // Disable categories
602 EnableCategories( false );
604 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
610 PrepareAfterItemsAdded();
612 m_pState
->m_itemsAdded
= 1;
614 #if wxPG_SUPPORT_TOOLTIPS
615 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
621 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
622 SetToolTip ( tooltip );
623 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
626 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
631 wxScrolledWindow::SetToolTip( NULL
);
636 wxScrolledWindow::SetWindowStyleFlag ( style
);
638 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
640 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
642 CalculateFontAndBitmapStuff( m_vspacing
);
648 // -----------------------------------------------------------------------
650 void wxPropertyGrid::Freeze()
654 wxScrolledWindow::Freeze();
659 // -----------------------------------------------------------------------
661 void wxPropertyGrid::Thaw()
667 wxScrolledWindow::Thaw();
668 RecalculateVirtualSize();
669 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
673 // Force property re-selection
674 // NB: We must copy the selection.
675 wxArrayPGProperty selection
= m_pState
->m_selection
;
676 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
680 // -----------------------------------------------------------------------
682 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
684 wxCHECK( prop
, false );
686 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
687 return DoSelectProperty(prop
, selFlags
);
689 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
691 if ( !selection
.size() )
693 return DoSelectProperty(prop
, selFlags
);
697 // For categories, only one can be selected at a time
698 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
701 selection
.push_back(prop
);
703 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
705 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
714 // -----------------------------------------------------------------------
716 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
718 wxCHECK( prop
, false );
721 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
722 if ( selection
.size() <= 1 )
724 res
= DoSelectProperty(NULL
, selFlags
);
728 m_pState
->DoRemoveFromSelection(prop
);
736 // -----------------------------------------------------------------------
738 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
739 unsigned int colIndex
,
740 unsigned int selFlags
)
743 // NB: Enable following if label editor background colour is
744 // ever changed to any other than m_colSelBack.
746 // We use this workaround to prevent visible flicker when editing
747 // a cell. Atleast on wxMSW, there is a difficult to find
748 // (and perhaps prevent) redraw somewhere between making property
749 // selected and enabling label editing.
751 //wxColour prevColSelBack = m_colSelBack;
752 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
758 res
= DoSelectProperty(prop
, selFlags
);
763 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
765 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
767 res
= DoAddToSelection(prop
, selFlags
);
771 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
773 DoBeginLabelEdit(colIndex
, selFlags
);
777 //m_colSelBack = prevColSelBack;
781 // -----------------------------------------------------------------------
783 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
784 unsigned int colIndex
,
785 wxMouseEvent
* mouseEvent
,
788 const wxArrayPGProperty
& selection
= GetSelectedProperties();
789 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
792 // Set to 2 if also add all items in between
793 int addToExistingSelection
= 0;
795 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
799 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
800 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
802 // Allow right-click for context menu without
803 // disturbing the selection.
804 if ( GetSelectedProperties().size() <= 1 ||
806 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
811 if ( mouseEvent
->ControlDown() )
813 addToExistingSelection
= 1;
815 else if ( mouseEvent
->ShiftDown() )
817 if ( selection
.size() > 0 && !prop
->IsCategory() )
818 addToExistingSelection
= 2;
820 addToExistingSelection
= 1;
826 if ( addToExistingSelection
== 1 )
829 if ( !alreadySelected
)
831 res
= DoAddToSelection(prop
, selFlags
);
833 else if ( GetSelectedProperties().size() > 1 )
835 res
= DoRemoveFromSelection(prop
, selFlags
);
838 else if ( addToExistingSelection
== 2 )
840 // Add this, and all in between
842 // Find top selected property
843 wxPGProperty
* topSelProp
= selection
[0];
844 int topSelPropY
= topSelProp
->GetY();
845 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
847 wxPGProperty
* p
= selection
[i
];
849 if ( y
< topSelPropY
)
856 wxPGProperty
* startFrom
;
857 wxPGProperty
* stopAt
;
859 if ( prop
->GetY() <= topSelPropY
)
861 // Property is above selection (or same)
867 // Property is below selection
868 startFrom
= topSelProp
;
872 // Iterate through properties in-between, and select them
873 wxPropertyGridIterator it
;
875 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
879 wxPGProperty
* p
= *it
;
881 if ( !p
->IsCategory() &&
882 !m_pState
->DoIsPropertySelected(p
) )
884 DoAddToSelection(p
, selFlags
);
893 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
899 // -----------------------------------------------------------------------
901 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
904 if ( newSelection
.size() > 0 )
906 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
911 DoClearSelection(false, selFlags
);
914 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
916 DoAddToSelection(newSelection
[i
], selFlags
);
922 // -----------------------------------------------------------------------
924 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
927 wxASSERT( column
!= 1 );
929 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
933 cols
.push_back(column
);
937 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
939 if ( cols
[i
] == (int)column
)
940 cols
.erase( cols
.begin() + i
);
945 // -----------------------------------------------------------------------
947 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
950 wxPGProperty
* selected
= GetSelection();
951 wxCHECK_RET(selected
, wxT("No property selected"));
952 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
954 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
956 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
963 const wxPGCell
* cell
= NULL
;
964 if ( selected
->HasCell(colIndex
) )
966 cell
= &selected
->GetCell(colIndex
);
967 if ( !cell
->HasText() && colIndex
== 0 )
968 text
= selected
->GetLabel();
974 text
= selected
->GetLabel();
976 cell
= &selected
->GetOrCreateCell(colIndex
);
979 if ( cell
&& cell
->HasText() )
980 text
= cell
->GetText();
982 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
984 m_selColumn
= colIndex
;
986 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
988 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
996 wxWindowID id
= tc
->GetId();
997 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
998 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1000 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1001 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1006 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1007 m_labelEditorProperty
= selected
;
1010 // -----------------------------------------------------------------------
1013 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1015 DoEndLabelEdit(true);
1018 // -----------------------------------------------------------------------
1020 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1022 int keycode
= event
.GetKeyCode();
1024 if ( keycode
== WXK_ESCAPE
)
1026 DoEndLabelEdit(false);
1034 // -----------------------------------------------------------------------
1036 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1038 if ( !m_labelEditor
)
1041 wxPGProperty
* prop
= m_labelEditorProperty
;
1046 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1048 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1049 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1050 prop
, NULL
, selFlags
,
1055 wxString text
= m_labelEditor
->GetValue();
1056 wxPGCell
* cell
= NULL
;
1057 if ( prop
->HasCell(m_selColumn
) )
1059 cell
= &prop
->GetCell(m_selColumn
);
1063 if ( m_selColumn
== 0 )
1064 prop
->SetLabel(text
);
1066 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1070 cell
->SetText(text
);
1075 DestroyEditorWnd(m_labelEditor
);
1076 m_labelEditor
= NULL
;
1077 m_labelEditorProperty
= NULL
;
1082 // -----------------------------------------------------------------------
1084 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1086 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1087 OnTLPChanging(::wxGetTopLevelParent(this));
1089 OnTLPChanging(NULL
);
1091 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1093 #if defined(__WXMSW__)
1096 // Don't use WS_EX_COMPOSITED just now.
1099 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1100 hWnd = (HWND)GetParent()->GetHWND();
1102 hWnd = (HWND)GetHWND();
1104 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1105 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1108 //#elif defined(__WXGTK20__)
1110 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1111 // truly was double-buffered.
1112 if ( !this->IsDoubleBuffered() )
1114 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1118 #if wxPG_DOUBLE_BUFFER
1119 delete m_doubleBuffer
;
1120 m_doubleBuffer
= NULL
;
1125 wxScrolledWindow::SetExtraStyle( exStyle
);
1127 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1128 m_pState
->InitNonCatMode();
1130 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1131 m_windowStyle
|= wxPG_TOOLTIPS
;
1134 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1137 // -----------------------------------------------------------------------
1139 // returns the best acceptable minimal size
1140 wxSize
wxPropertyGrid::DoGetBestSize() const
1142 int lineHeight
= wxMax(15, m_lineHeight
);
1144 // don't make the grid too tall (limit height to 10 items) but don't
1145 // make it too small neither
1146 int numLines
= wxMin
1148 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1152 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1153 int width
= m_marginWidth
;
1154 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1156 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1159 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1165 // -----------------------------------------------------------------------
1167 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1169 if ( newTLP
== m_tlp
)
1172 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1175 // Parent changed so let's redetermine and re-hook the
1176 // correct top-level window.
1179 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1180 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1182 m_tlpClosed
= m_tlp
;
1183 m_tlpClosedTime
= currentTime
;
1188 // Only accept new tlp if same one was not just dismissed.
1189 if ( newTLP
!= m_tlpClosed
||
1190 m_tlpClosedTime
+250 < currentTime
)
1192 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1193 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1206 // -----------------------------------------------------------------------
1208 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1210 // ClearSelection forces value validation/commit.
1211 if ( event
.CanVeto() && !DoClearSelection() )
1217 // Ok, it can close, set tlp pointer to NULL. Some other event
1218 // handler can of course veto the close, but our OnIdle() should
1219 // then be able to regain the tlp pointer.
1220 OnTLPChanging(NULL
);
1225 // -----------------------------------------------------------------------
1227 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1229 OnTLPChanging((wxWindow
*)newParent
);
1231 bool res
= wxScrolledWindow::Reparent(newParent
);
1236 // -----------------------------------------------------------------------
1237 // wxPropertyGrid Font and Colour Methods
1238 // -----------------------------------------------------------------------
1240 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1244 m_captionFont
= wxScrolledWindow::GetFont();
1246 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1247 m_subgroup_extramargin
= x
+ (x
/2);
1250 #if wxPG_USE_RENDERER_NATIVE
1251 m_iconWidth
= wxPG_ICON_WIDTH
;
1252 #elif wxPG_ICON_WIDTH
1254 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1255 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1256 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1260 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1261 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1262 m_gutterWidth
= wxPG_GUTTER_MIN
;
1265 if ( vspacing
<= 1 ) vdiv
= 12;
1266 else if ( vspacing
>= 3 ) vdiv
= 3;
1268 m_spacingy
= m_fontHeight
/ vdiv
;
1269 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1270 m_spacingy
= wxPG_YSPACING_MIN
;
1273 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1274 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1276 m_captionFont
.SetWeight(wxBOLD
);
1277 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1279 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1282 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1283 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1286 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1288 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1289 RecalculateVirtualSize();
1291 InvalidateBestSize();
1294 // -----------------------------------------------------------------------
1296 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1302 // -----------------------------------------------------------------------
1304 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1305 int ga
= 1000, int ba
= 1000,
1306 bool forceDifferent
= false)
1313 // Recursion guard (allow 2 max)
1314 static int isinside
= 0;
1316 wxCHECK_MSG( isinside
< 3,
1318 wxT("wxPGAdjustColour should not be recursively called more than once") );
1323 int g
= src
.Green();
1326 if ( r2
>255 ) r2
= 255;
1327 else if ( r2
<0) r2
= 0;
1329 if ( g2
>255 ) g2
= 255;
1330 else if ( g2
<0) g2
= 0;
1332 if ( b2
>255 ) b2
= 255;
1333 else if ( b2
<0) b2
= 0;
1335 // Make sure they are somewhat different
1336 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1337 dst
= wxPGAdjustColour(src
,-(ra
*2));
1339 dst
= wxColour(r2
,g2
,b2
);
1341 // Recursion guard (allow 2 max)
1348 static int wxPGGetColAvg( const wxColour
& col
)
1350 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1354 void wxPropertyGrid::RegainColours()
1356 if ( !(m_coloursCustomized
& 0x0002) )
1358 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1360 // Make sure colour is dark enough
1362 int colDec
= wxPGGetColAvg(col
) - 230;
1364 int colDec
= wxPGGetColAvg(col
) - 200;
1367 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1370 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1373 if ( !(m_coloursCustomized
& 0x0001) )
1374 m_colMargin
= m_colCapBack
;
1376 if ( !(m_coloursCustomized
& 0x0004) )
1383 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1384 m_colCapFore
= capForeCol
;
1385 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1388 if ( !(m_coloursCustomized
& 0x0008) )
1390 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1391 m_colPropBack
= bgCol
;
1392 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1393 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1394 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1397 if ( !(m_coloursCustomized
& 0x0010) )
1399 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1400 m_colPropFore
= fgCol
;
1401 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1402 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1403 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1406 if ( !(m_coloursCustomized
& 0x0020) )
1407 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1409 if ( !(m_coloursCustomized
& 0x0040) )
1410 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1412 if ( !(m_coloursCustomized
& 0x0080) )
1413 m_colLine
= m_colCapBack
;
1415 if ( !(m_coloursCustomized
& 0x0100) )
1416 m_colDisPropFore
= m_colCapFore
;
1418 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1421 // -----------------------------------------------------------------------
1423 void wxPropertyGrid::ResetColours()
1425 m_coloursCustomized
= 0;
1432 // -----------------------------------------------------------------------
1434 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1436 // Must disable active editor.
1439 bool res
= wxScrolledWindow::SetFont( font
);
1440 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1442 CalculateFontAndBitmapStuff( m_vspacing
);
1449 // -----------------------------------------------------------------------
1451 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1454 m_coloursCustomized
|= 0x80;
1458 // -----------------------------------------------------------------------
1460 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1463 m_coloursCustomized
|= 0x01;
1467 // -----------------------------------------------------------------------
1469 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1471 m_colPropBack
= col
;
1472 m_coloursCustomized
|= 0x08;
1474 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1475 m_unspecifiedAppearance
.SetBgCol(col
);
1480 // -----------------------------------------------------------------------
1482 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1484 m_colPropFore
= col
;
1485 m_coloursCustomized
|= 0x10;
1487 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1488 m_unspecifiedAppearance
.SetFgCol(col
);
1493 // -----------------------------------------------------------------------
1495 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1497 m_colEmptySpace
= col
;
1502 // -----------------------------------------------------------------------
1504 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1506 m_colDisPropFore
= col
;
1507 m_coloursCustomized
|= 0x100;
1511 // -----------------------------------------------------------------------
1513 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1516 m_coloursCustomized
|= 0x20;
1520 // -----------------------------------------------------------------------
1522 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1525 m_coloursCustomized
|= 0x40;
1529 // -----------------------------------------------------------------------
1531 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1534 m_coloursCustomized
|= 0x02;
1536 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1541 // -----------------------------------------------------------------------
1543 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1546 m_coloursCustomized
|= 0x04;
1548 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1553 // -----------------------------------------------------------------------
1554 // wxPropertyGrid property adding and removal
1555 // -----------------------------------------------------------------------
1557 void wxPropertyGrid::PrepareAfterItemsAdded()
1559 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1561 m_pState
->m_itemsAdded
= 0;
1563 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1564 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1566 RecalculateVirtualSize();
1568 // Fix editor position
1569 CorrectEditorWidgetPosY();
1572 // -----------------------------------------------------------------------
1573 // wxPropertyGrid property operations
1574 // -----------------------------------------------------------------------
1576 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1578 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1582 bool changed
= false;
1584 // Is it inside collapsed section?
1585 if ( !p
->IsVisible() )
1588 wxPGProperty
* parent
= p
->GetParent();
1589 wxPGProperty
* grandparent
= parent
->GetParent();
1591 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1592 Expand( grandparent
);
1600 GetViewStart(&vx
,&vy
);
1601 vy
*=wxPG_PIXELS_PER_UNIT
;
1607 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1608 m_iFlags
|= wxPG_FL_SCROLLED
;
1611 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1613 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1614 m_iFlags
|= wxPG_FL_SCROLLED
;
1624 // -----------------------------------------------------------------------
1625 // wxPropertyGrid helper methods called by properties
1626 // -----------------------------------------------------------------------
1628 // Control font changer helper.
1629 void wxPropertyGrid::SetCurControlBoldFont()
1631 wxASSERT( m_wndEditor
);
1632 m_wndEditor
->SetFont( m_captionFont
);
1635 // -----------------------------------------------------------------------
1637 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1640 #if wxPG_SMALL_SCREEN
1641 // On small-screen devices, always show dialogs with default position and size.
1642 return wxDefaultPosition
;
1644 int splitterX
= GetSplitterPosition();
1648 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1650 ImprovedClientToScreen( &x
, &y
);
1652 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1653 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1660 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1670 new_y
= y
+ m_lineHeight
;
1672 return wxPoint(new_x
,new_y
);
1676 // -----------------------------------------------------------------------
1678 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1680 if ( src_str
.length() == 0 )
1686 bool prev_is_slash
= false;
1688 wxString::const_iterator i
= src_str
.begin();
1692 for ( ; i
!= src_str
.end(); ++i
)
1696 if ( a
!= wxS('\\') )
1698 if ( !prev_is_slash
)
1704 if ( a
== wxS('n') )
1707 dst_str
<< wxS('\n');
1709 dst_str
<< wxS('\n');
1712 else if ( a
== wxS('t') )
1713 dst_str
<< wxS('\t');
1717 prev_is_slash
= false;
1721 if ( prev_is_slash
)
1723 dst_str
<< wxS('\\');
1724 prev_is_slash
= false;
1728 prev_is_slash
= true;
1735 // -----------------------------------------------------------------------
1737 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1739 if ( src_str
.length() == 0 )
1745 wxString::const_iterator i
= src_str
.begin();
1746 wxUniChar prev_a
= wxS('\0');
1750 for ( ; i
!= src_str
.end(); ++i
)
1754 if ( a
>= wxS(' ') )
1756 // This surely is not something that requires an escape sequence.
1761 // This might need...
1762 if ( a
== wxS('\r') )
1764 // DOS style line end.
1765 // Already taken care below
1767 else if ( a
== wxS('\n') )
1768 // UNIX style line end.
1769 dst_str
<< wxS("\\n");
1770 else if ( a
== wxS('\t') )
1772 dst_str
<< wxS('\t');
1775 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1785 // -----------------------------------------------------------------------
1787 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1794 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1797 // -----------------------------------------------------------------------
1798 // wxPropertyGrid graphics related methods
1799 // -----------------------------------------------------------------------
1801 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1806 // Don't paint after destruction has begun
1807 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1810 // Find out where the window is scrolled to
1811 int vx
,vy
; // Top left corner of client
1812 GetViewStart(&vx
,&vy
);
1813 vy
*= wxPG_PIXELS_PER_UNIT
;
1815 // Update everything inside the box
1816 wxRect r
= GetUpdateRegion().GetBox();
1820 // FIXME: This is just a workaround for a bug that causes splitters not
1821 // to paint when other windows are being dragged over the grid.
1823 r
.width
= GetClientSize().x
;
1825 // Repaint this rectangle
1826 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1828 // We assume that the size set when grid is shown
1829 // is what is desired.
1830 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1833 // -----------------------------------------------------------------------
1835 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1836 wxPGProperty
* property
) const
1838 // Prepare rectangle to be used
1840 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1841 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1843 #if (wxPG_USE_RENDERER_NATIVE)
1845 #elif wxPG_ICON_WIDTH
1846 // Drawing expand/collapse button manually
1847 dc
.SetPen(m_colPropFore
);
1848 if ( property
->IsCategory() )
1849 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1851 dc
.SetBrush(m_colPropBack
);
1853 dc
.DrawRectangle( r
);
1854 int _y
= r
.y
+(m_iconWidth
/2);
1855 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1860 if ( property
->IsExpanded() )
1862 // wxRenderer functions are non-mutating in nature, so it
1863 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1864 // Hopefully this does not cause problems.
1865 #if (wxPG_USE_RENDERER_NATIVE)
1866 wxRendererNative::Get().DrawTreeItemButton(
1872 #elif wxPG_ICON_WIDTH
1881 #if (wxPG_USE_RENDERER_NATIVE)
1882 wxRendererNative::Get().DrawTreeItemButton(
1888 #elif wxPG_ICON_WIDTH
1889 int _x
= r
.x
+(m_iconWidth
/2);
1890 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1896 #if (wxPG_USE_RENDERER_NATIVE)
1898 #elif wxPG_ICON_WIDTH
1901 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1905 // -----------------------------------------------------------------------
1908 // This is the one called by OnPaint event handler and others.
1909 // topy and bottomy are already unscrolled (ie. physical)
1911 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1912 unsigned int topItemY
,
1913 unsigned int bottomItemY
,
1914 const wxRect
* drawRect
)
1918 bottomItemY
< topItemY
||
1922 m_pState
->EnsureVirtualHeight();
1924 wxRect tempDrawRect
;
1927 tempDrawRect
= wxRect(0, topItemY
,
1930 drawRect
= &tempDrawRect
;
1933 // items added check
1934 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1936 int paintFinishY
= 0;
1938 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1941 bool isBuffered
= false;
1943 #if wxPG_DOUBLE_BUFFER
1944 wxMemoryDC
* bufferDC
= NULL
;
1946 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1948 if ( !m_doubleBuffer
)
1950 paintFinishY
= drawRect
->y
;
1955 bufferDC
= new wxMemoryDC();
1957 // If nothing was changed, then just copy from double-buffer
1958 bufferDC
->SelectObject( *m_doubleBuffer
);
1968 dc
.SetClippingRegion( *drawRect
);
1969 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1970 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1972 // Clear area beyond last painted property
1973 if ( paintFinishY
< drawBottomY
)
1975 dcPtr
->SetPen(m_colEmptySpace
);
1976 dcPtr
->SetBrush(m_colEmptySpace
);
1977 dcPtr
->DrawRectangle(0, paintFinishY
,
1982 dc
.DestroyClippingRegion();
1985 #if wxPG_DOUBLE_BUFFER
1988 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1990 bufferDC
, 0, 0, wxCOPY
);
1997 // Just clear the area
1998 dc
.SetPen(m_colEmptySpace
);
1999 dc
.SetBrush(m_colEmptySpace
);
2000 dc
.DrawRectangle(*drawRect
);
2004 // -----------------------------------------------------------------------
2006 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2007 const wxRect
* drawRect
,
2008 bool isBuffered
) const
2010 const wxPGProperty
* firstItem
;
2011 const wxPGProperty
* lastItem
;
2013 firstItem
= DoGetItemAtY(drawRect
->y
);
2014 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
2017 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2019 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2022 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
2024 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2026 int lh
= m_lineHeight
;
2029 int lastItemBottomY
;
2031 firstItemTopY
= drawRect
->y
;
2032 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
2034 // Align y coordinates to item boundaries
2035 firstItemTopY
-= firstItemTopY
% lh
;
2036 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2037 lastItemBottomY
-= 1;
2039 // Entire range outside scrolled, visible area?
2040 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2041 lastItemBottomY
<= 0 )
2044 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2046 "invalid y values" );
2049 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2050 "height=%i (ch=%i), drawRect = 0x%lX )",
2051 firstItem->GetLabel().c_str(),
2052 lastItem->GetLabel().c_str(),
2053 (int)(lastItemBottomY - firstItemTopY),
2055 (unsigned long)drawRect );
2060 long windowStyle
= m_windowStyle
;
2065 // With wxPG_DOUBLE_BUFFER, do double buffering
2066 // - buffer's y = 0, so align drawRect and coordinates to that
2068 #if wxPG_DOUBLE_BUFFER
2075 xRelMod
= drawRect
->x
;
2076 yRelMod
= drawRect
->y
;
2079 // drawRect conversion
2084 firstItemTopY
-= yRelMod
;
2085 lastItemBottomY
-= yRelMod
;
2088 wxUnusedVar(isBuffered
);
2091 int x
= m_marginWidth
- xRelMod
;
2093 wxFont normalFont
= GetFont();
2095 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2097 bool isPgEnabled
= IsEnabled();
2100 // Prepare some pens and brushes that are often changed to.
2103 wxBrush
marginBrush(m_colMargin
);
2104 wxPen
marginPen(m_colMargin
);
2105 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2106 wxPen
linepen(m_colLine
,1,wxSOLID
);
2108 wxColour selBackCol
;
2110 selBackCol
= m_colSelBack
;
2112 selBackCol
= m_colMargin
;
2114 // pen that has same colour as text
2115 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2118 // Clear margin with background colour
2120 dc
.SetBrush( marginBrush
);
2121 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2123 dc
.SetPen( *wxTRANSPARENT_PEN
);
2124 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2127 const wxPGProperty
* firstSelected
= GetSelection();
2128 const wxPropertyGridPageState
* state
= m_pState
;
2129 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2131 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2132 bool wasSelectedPainted
= false;
2135 // TODO: Only render columns that are within clipping region.
2137 dc
.SetFont(normalFont
);
2139 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2140 int endScanBottomY
= lastItemBottomY
+ lh
;
2141 int y
= firstItemTopY
;
2144 // Pregenerate list of visible properties.
2145 wxArrayPGProperty visPropArray
;
2146 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2148 for ( ; !it
.AtEnd(); it
.Next() )
2150 const wxPGProperty
* p
= *it
;
2152 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2154 visPropArray
.push_back((wxPGProperty
*)p
);
2156 if ( y
> endScanBottomY
)
2163 visPropArray
.push_back(NULL
);
2165 wxPGProperty
* nextP
= visPropArray
[0];
2167 int gridWidth
= state
->m_width
;
2170 for ( unsigned int arrInd
=1;
2171 nextP
&& y
<= lastItemBottomY
;
2174 wxPGProperty
* p
= nextP
;
2175 nextP
= visPropArray
[arrInd
];
2177 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2178 int textMarginHere
= x
;
2179 int renderFlags
= 0;
2181 int greyDepth
= m_marginWidth
;
2182 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2183 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2185 int greyDepthX
= greyDepth
- xRelMod
;
2187 // Use basic depth if in non-categoric mode and parent is base array.
2188 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2190 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2193 // Paint margin area
2194 dc
.SetBrush(marginBrush
);
2195 dc
.SetPen(marginPen
);
2196 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2198 dc
.SetPen( linepen
);
2204 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2205 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2206 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2208 // Is this or its parent themed?
2209 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2210 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2211 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2213 bool suppressMarginEdge
= false;
2215 if (!suppressMarginEdge
)
2216 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2219 // Blank out the margin edge
2220 dc
.SetPen(wxPen(GetBackgroundColour()));
2221 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2222 dc
.SetPen( linepen
);
2229 for ( si
=0; si
<colWidths
.size(); si
++ )
2231 sx
+= colWidths
[si
];
2232 dc
.DrawLine( sx
, y
, sx
, y2
);
2235 // Horizontal Line, below
2236 // (not if both this and next is category caption)
2237 if ( p
->IsCategory() &&
2238 nextP
&& nextP
->IsCategory() )
2239 dc
.SetPen(m_colCapBack
);
2241 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2244 // Need to override row colours?
2248 bool isSelected
= state
->DoIsPropertySelected(p
);
2252 // Disabled may get different colour.
2253 if ( !p
->IsEnabled() )
2255 renderFlags
|= wxPGCellRenderer::Disabled
|
2256 wxPGCellRenderer::DontUseCellFgCol
;
2257 rowFgCol
= m_colDisPropFore
;
2262 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2263 if ( p
== firstSelected
)
2264 wasSelectedPainted
= true;
2267 renderFlags
|= wxPGCellRenderer::Selected
;
2269 if ( !p
->IsCategory() )
2271 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2272 wxPGCellRenderer::DontUseCellBgCol
;
2274 if ( reallyFocused
&& p
== firstSelected
)
2276 rowFgCol
= m_colSelFore
;
2277 rowBgCol
= selBackCol
;
2279 else if ( isPgEnabled
)
2281 rowFgCol
= m_colPropFore
;
2282 if ( p
== firstSelected
)
2283 rowBgCol
= m_colMargin
;
2285 rowBgCol
= selBackCol
;
2289 rowFgCol
= m_colDisPropFore
;
2290 rowBgCol
= selBackCol
;
2297 if ( rowBgCol
.IsOk() )
2298 rowBgBrush
= wxBrush(rowBgCol
);
2300 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2301 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2304 // Fill additional margin area with background colour of first cell
2305 if ( greyDepthX
< textMarginHere
)
2307 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2309 wxPGCell
& cell
= p
->GetCell(0);
2310 rowBgCol
= cell
.GetBgCol();
2311 rowBgBrush
= wxBrush(rowBgCol
);
2313 dc
.SetBrush(rowBgBrush
);
2314 dc
.SetPen(rowBgCol
);
2315 dc
.DrawRectangle(greyDepthX
+1, y
,
2316 textMarginHere
-greyDepthX
, lh
-1);
2319 bool fontChanged
= false;
2321 // Expander button rectangle
2322 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2327 // Default cell rect fill the entire row
2328 wxRect
cellRect(greyDepthX
, y
,
2329 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2331 bool isCategory
= p
->IsCategory();
2335 dc
.SetFont(m_captionFont
);
2338 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2340 dc
.SetBrush(rowBgBrush
);
2341 dc
.SetPen(rowBgCol
);
2344 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2346 dc
.SetTextForeground(rowFgCol
);
2351 // Fine tune button rectangle to actually fit the cell
2352 if ( butRect
.x
> 0 )
2353 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2355 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2356 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2358 dc
.SetFont(m_captionFont
);
2362 // Magic fine-tuning for non-category rows
2366 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2367 int firstCellX
= cellRect
.x
;
2369 // Calculate cellRect.x for the last cell
2370 unsigned int ci
= 0;
2372 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2373 cellX
+= colWidths
[ci
];
2376 // Draw cells from back to front so that we can easily tell if the
2377 // cell on the right was empty from text
2378 bool prevFilled
= true;
2379 ci
= colWidths
.size();
2388 textXAdd
= textMarginHere
- greyDepthX
;
2389 cellRect
.width
= firstCellWidth
;
2390 cellRect
.x
= firstCellX
;
2394 int colWidth
= colWidths
[ci
];
2395 cellRect
.width
= colWidth
;
2396 cellRect
.x
-= colWidth
;
2399 // Merge with column to the right?
2400 if ( !prevFilled
&& isCategory
)
2402 cellRect
.width
+= colWidths
[ci
+1];
2406 cellRect
.width
-= 1;
2408 wxWindow
* cellEditor
= NULL
;
2409 int cellRenderFlags
= renderFlags
;
2411 // Tree Item Button (must be drawn before clipping is set up)
2412 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2413 DrawExpanderButton( dc
, butRect
, p
);
2416 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2418 if ( p
== firstSelected
)
2420 if ( ci
== 1 && m_wndEditor
)
2421 cellEditor
= m_wndEditor
;
2422 else if ( ci
== m_selColumn
&& m_labelEditor
)
2423 cellEditor
= m_labelEditor
;
2428 wxColour editorBgCol
=
2429 cellEditor
->GetBackgroundColour();
2430 dc
.SetBrush(editorBgCol
);
2431 dc
.SetPen(editorBgCol
);
2432 dc
.SetTextForeground(m_colPropFore
);
2433 dc
.DrawRectangle(cellRect
);
2435 if ( m_dragStatus
!= 0 ||
2436 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2441 dc
.SetBrush(m_colPropBack
);
2442 dc
.SetPen(m_colPropBack
);
2443 if ( p
->IsEnabled() )
2444 dc
.SetTextForeground(m_colPropFore
);
2446 dc
.SetTextForeground(m_colDisPropFore
);
2451 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2453 dc
.SetBrush(rowBgBrush
);
2454 dc
.SetPen(rowBgCol
);
2457 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2459 dc
.SetTextForeground(rowFgCol
);
2463 dc
.SetClippingRegion(cellRect
);
2465 cellRect
.x
+= textXAdd
;
2466 cellRect
.width
-= textXAdd
;
2471 wxPGCellRenderer
* renderer
;
2472 int cmnVal
= p
->GetCommonValue();
2473 if ( cmnVal
== -1 || ci
!= 1 )
2475 renderer
= p
->GetCellRenderer(ci
);
2476 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2482 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2483 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2493 dc
.DestroyClippingRegion(); // Is this really necessary?
2498 dc
.SetFont(normalFont
);
2503 // Refresh editor controls (seems not needed on msw)
2504 // NOTE: This code is mandatory for GTK!
2505 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2506 if ( wasSelectedPainted
)
2509 m_wndEditor
->Refresh();
2511 m_wndEditor2
->Refresh();
2518 // -----------------------------------------------------------------------
2520 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2524 if ( m_width
< 10 || m_height
< 10 ||
2525 !m_pState
->m_properties
->GetChildCount() ||
2527 return wxRect(0,0,0,0);
2532 // Return rect which encloses the given property range
2534 int visTop
= p1
->GetY();
2537 visBottom
= p2
->GetY() + m_lineHeight
;
2539 visBottom
= m_height
+ visTop
;
2541 // If seleced property is inside the range, we'll extend the range to include
2543 wxPGProperty
* selected
= GetSelection();
2546 int selectedY
= selected
->GetY();
2547 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2549 wxWindow
* editor
= GetEditorControl();
2552 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2553 if ( visBottom2
> visBottom
)
2554 visBottom
= visBottom2
;
2559 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2562 // -----------------------------------------------------------------------
2564 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2569 if ( m_pState
->m_itemsAdded
)
2570 PrepareAfterItemsAdded();
2572 wxRect r
= GetPropertyRect(p1
, p2
);
2579 // -----------------------------------------------------------------------
2581 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2583 if ( m_pState
->DoIsPropertySelected(p
) )
2585 // NB: We must copy the selection.
2586 wxArrayPGProperty selection
= m_pState
->m_selection
;
2587 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2590 DrawItemAndChildren(p
);
2593 // -----------------------------------------------------------------------
2595 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2600 // Draw item, children, and parent too, if it is not category
2601 wxPGProperty
* parent
= p
->GetParent();
2604 !parent
->IsCategory() &&
2605 parent
->GetParent() )
2608 parent
= parent
->GetParent();
2611 DrawItemAndChildren(p
);
2614 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2616 wxCHECK_RET( p
, wxT("invalid property id") );
2618 // Do not draw if in non-visible page
2619 if ( p
->GetParentState() != m_pState
)
2622 // do not draw a single item if multiple pending
2623 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2626 // Update child control.
2627 wxPGProperty
* selected
= GetSelection();
2628 if ( selected
&& selected
->GetParent() == p
)
2631 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2633 DrawItems(p
, lastDrawn
);
2636 // -----------------------------------------------------------------------
2638 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2639 const wxRect
*rect
)
2641 PrepareAfterItemsAdded();
2643 wxWindow::Refresh(false, rect
);
2645 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2646 // I think this really helps only GTK+1.2
2647 if ( m_wndEditor
) m_wndEditor
->Refresh();
2648 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2652 // -----------------------------------------------------------------------
2653 // wxPropertyGrid global operations
2654 // -----------------------------------------------------------------------
2656 void wxPropertyGrid::Clear()
2658 m_pState
->DoClear();
2664 RecalculateVirtualSize();
2666 // Need to clear some area at the end
2668 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2671 // -----------------------------------------------------------------------
2673 bool wxPropertyGrid::EnableCategories( bool enable
)
2680 // Enable categories
2683 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2688 // Disable categories
2690 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2693 if ( !m_pState
->EnableCategories(enable
) )
2698 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2700 m_pState
->m_itemsAdded
= 1; // force
2701 PrepareAfterItemsAdded();
2705 m_pState
->m_itemsAdded
= 1;
2707 // No need for RecalculateVirtualSize() here - it is already called in
2708 // wxPropertyGridPageState method above.
2715 // -----------------------------------------------------------------------
2717 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2719 wxASSERT( pNewState
);
2720 wxASSERT( pNewState
->GetGrid() );
2722 if ( pNewState
== m_pState
)
2725 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2727 // Call ClearSelection() instead of DoClearSelection()
2728 // so that selection clear events are not sent.
2731 m_pState
->m_selection
= oldSelection
;
2733 bool orig_mode
= m_pState
->IsInNonCatMode();
2734 bool new_state_mode
= pNewState
->IsInNonCatMode();
2736 m_pState
= pNewState
;
2739 int pgWidth
= GetClientSize().x
;
2740 if ( HasVirtualWidth() )
2742 int minWidth
= pgWidth
;
2743 if ( pNewState
->m_width
< minWidth
)
2745 pNewState
->m_width
= minWidth
;
2746 pNewState
->CheckColumnWidths();
2752 // Just in case, fully re-center splitter
2753 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2754 // pNewState->m_fSplitterX = -1.0;
2756 pNewState
->OnClientWidthChange(pgWidth
,
2757 pgWidth
- pNewState
->m_width
);
2762 // If necessary, convert state to correct mode.
2763 if ( orig_mode
!= new_state_mode
)
2765 // This should refresh as well.
2766 EnableCategories( orig_mode
?false:true );
2768 else if ( !m_frozen
)
2770 // Refresh, if not frozen.
2771 m_pState
->PrepareAfterItemsAdded();
2773 // Reselect (Use SetSelection() instead of Do-variant so that
2774 // events won't be sent).
2775 SetSelection(m_pState
->m_selection
);
2777 RecalculateVirtualSize(0);
2781 m_pState
->m_itemsAdded
= 1;
2784 // -----------------------------------------------------------------------
2786 // Call to SetSplitterPosition will always disable splitter auto-centering
2787 // if parent window is shown.
2788 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2792 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2795 wxPropertyGridPageState
* state
= m_pState
;
2797 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2798 state
->m_dontCenterSplitter
= true;
2800 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2802 if ( flags
& wxPG_SPLITTER_REFRESH
)
2804 if ( GetSelection() )
2805 CorrectEditorWidgetSizeX();
2813 // -----------------------------------------------------------------------
2815 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2817 wxPropertyGridPageState
* state
= m_pState
;
2819 state
->ResetColumnSizes(0);
2821 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2822 m_pState
->m_dontCenterSplitter
= false;
2825 // -----------------------------------------------------------------------
2827 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2829 SetSplitterPosition( m_width
/2 );
2830 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2831 m_pState
->m_dontCenterSplitter
= false;
2834 // -----------------------------------------------------------------------
2835 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2836 // -----------------------------------------------------------------------
2838 // Returns nearest paint visible property (such that will be painted unless
2839 // window is scrolled or resized). If given property is paint visible, then
2840 // it itself will be returned
2841 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2843 int vx
,vy1
;// Top left corner of client
2844 GetViewStart(&vx
,&vy1
);
2845 vy1
*= wxPG_PIXELS_PER_UNIT
;
2847 int vy2
= vy1
+ m_height
;
2848 int propY
= p
->GetY2(m_lineHeight
);
2850 if ( (propY
+ m_lineHeight
) < vy1
)
2853 return DoGetItemAtY( vy1
);
2855 else if ( propY
> vy2
)
2858 return DoGetItemAtY( vy2
);
2861 // Itself paint visible
2866 // -----------------------------------------------------------------------
2867 // Methods related to change in value, value modification and sending events
2868 // -----------------------------------------------------------------------
2870 // commits any changes in editor of selected property
2871 // return true if validation did not fail
2872 // flags are same as with DoSelectProperty
2873 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2875 // Committing already?
2876 if ( m_inCommitChangesFromEditor
)
2879 // Don't do this if already processing editor event. It might
2880 // induce recursive dialogs and crap like that.
2881 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2883 if ( m_inDoPropertyChanged
)
2889 wxPGProperty
* selected
= GetSelection();
2892 IsEditorsValueModified() &&
2893 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2896 m_inCommitChangesFromEditor
= 1;
2898 wxVariant
variant(selected
->GetValueRef());
2899 bool valueIsPending
= false;
2901 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2902 // due to another window getting focus
2903 wxWindow
* oldFocus
= m_curFocused
;
2905 bool validationFailure
= false;
2906 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2908 m_chgInfo_changedProperty
= NULL
;
2910 // If truly modified, schedule value as pending.
2911 if ( selected
->GetEditorClass()->
2912 GetValueFromControl( variant
,
2914 GetEditorControl() ) )
2916 if ( DoEditorValidate() &&
2917 PerformValidation(selected
, variant
) )
2919 valueIsPending
= true;
2923 validationFailure
= true;
2928 EditorsValueWasNotModified();
2933 m_inCommitChangesFromEditor
= 0;
2935 if ( validationFailure
&& !forceSuccess
)
2939 oldFocus
->SetFocus();
2940 m_curFocused
= oldFocus
;
2943 res
= OnValidationFailure(selected
, variant
);
2945 // Now prevent further validation failure messages
2948 EditorsValueWasNotModified();
2949 OnValidationFailureReset(selected
);
2952 else if ( valueIsPending
)
2954 DoPropertyChanged( selected
, flags
);
2955 EditorsValueWasNotModified();
2964 // -----------------------------------------------------------------------
2966 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2970 // Runs all validation functionality.
2971 // Returns true if value passes all tests.
2974 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2977 // Variant list a special value that cannot be validated
2979 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2981 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2986 // Adapt list to child values, if necessary
2987 wxVariant listValue
= pendingValue
;
2988 wxVariant
* pPendingValue
= &pendingValue
;
2989 wxVariant
* pList
= NULL
;
2991 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2992 // string value, then we need treat as it was changed instead
2993 // (or, in addition, as is the case with composite string parent).
2994 // This includes creating list variant for child values.
2996 wxPGProperty
* pwc
= p
->GetParent();
2997 wxPGProperty
* changedProperty
= p
;
2998 wxPGProperty
* baseChangedProperty
= changedProperty
;
2999 wxVariant bcpPendingList
;
3001 listValue
= pendingValue
;
3002 listValue
.SetName(p
->GetBaseName());
3005 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3007 wxVariantList tempList
;
3008 wxVariant
lv(tempList
, pwc
->GetBaseName());
3009 lv
.Append(listValue
);
3011 pPendingValue
= &listValue
;
3013 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3015 baseChangedProperty
= pwc
;
3016 bcpPendingList
= lv
;
3019 changedProperty
= pwc
;
3020 pwc
= pwc
->GetParent();
3024 wxPGProperty
* evtChangingProperty
= changedProperty
;
3026 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3028 value
= *pPendingValue
;
3032 // Convert list to child values
3033 pList
= pPendingValue
;
3034 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3037 wxVariant evtChangingValue
= value
;
3039 if ( flags
& SendEvtChanging
)
3041 // FIXME: After proper ValueToString()s added, remove
3042 // this. It is just a temporary fix, as evt_changing
3043 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3044 // (unless it is selected, and textctrl editor is open).
3045 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3047 evtChangingProperty
= baseChangedProperty
;
3048 if ( evtChangingProperty
!= p
)
3050 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3054 evtChangingValue
= pendingValue
;
3058 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3060 if ( changedProperty
== GetSelection() )
3062 wxWindow
* editor
= GetEditorControl();
3063 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3064 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3068 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3073 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3074 m_chgInfo_changedProperty
= changedProperty
;
3075 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3076 m_chgInfo_pendingValue
= value
;
3079 m_chgInfo_valueList
= *pList
;
3081 m_chgInfo_valueList
.MakeNull();
3083 // If changedProperty is not property which value was edited,
3084 // then call wxPGProperty::ValidateValue() for that as well.
3085 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3087 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3091 if ( flags
& SendEvtChanging
)
3093 // SendEvent returns true if event was vetoed
3094 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3095 &evtChangingValue
) )
3099 if ( flags
& IsStandaloneValidation
)
3101 // If called in 'generic' context, we need to reset
3102 // m_chgInfo_changedProperty and write back translated value.
3103 m_chgInfo_changedProperty
= NULL
;
3104 pendingValue
= value
;
3110 // -----------------------------------------------------------------------
3112 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3114 if ( !msg
.length() )
3118 if ( !wxPGGlobalVars
->m_offline
)
3120 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3123 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3126 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3129 pStatusBar
->SetStatusText(msg
);
3137 ::wxMessageBox(msg
, wxT("Property Error"));
3140 // -----------------------------------------------------------------------
3142 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3143 wxVariant
& invalidValue
)
3145 wxWindow
* editor
= GetEditorControl();
3147 // First call property's handler
3148 property
->OnValidationFailure(invalidValue
);
3150 bool res
= DoOnValidationFailure(property
, invalidValue
);
3153 // For non-wxTextCtrl editors, we do need to revert the value
3154 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3155 property
== GetSelection() )
3157 property
->GetEditorClass()->UpdateControl(property
, editor
);
3160 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3165 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3167 int vfb
= m_validationInfo
.m_failureBehavior
;
3169 if ( vfb
& wxPG_VFB_BEEP
)
3172 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3173 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3175 unsigned int colCount
= m_pState
->GetColumnCount();
3177 // We need backup marked property's cells
3178 m_propCellsBackup
= property
->m_cells
;
3180 wxColour vfbFg
= *wxWHITE
;
3181 wxColour vfbBg
= *wxRED
;
3183 property
->EnsureCells(colCount
);
3185 for ( unsigned int i
=0; i
<colCount
; i
++ )
3187 wxPGCell
& cell
= property
->m_cells
[i
];
3188 cell
.SetFgCol(vfbFg
);
3189 cell
.SetBgCol(vfbBg
);
3192 DrawItemAndChildren(property
);
3194 if ( property
== GetSelection() )
3196 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3198 wxWindow
* editor
= GetEditorControl();
3201 editor
->SetForegroundColour(vfbFg
);
3202 editor
->SetBackgroundColour(vfbBg
);
3207 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3209 wxString msg
= m_validationInfo
.m_failureMessage
;
3211 if ( !msg
.length() )
3212 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3214 DoShowPropertyError(property
, msg
);
3217 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3220 // -----------------------------------------------------------------------
3222 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3224 int vfb
= m_validationInfo
.m_failureBehavior
;
3226 if ( vfb
& wxPG_VFB_MARK_CELL
)
3229 property
->m_cells
= m_propCellsBackup
;
3231 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3233 if ( property
== GetSelection() && GetEditorControl() )
3235 // Calling this will recreate the control, thus resetting its colour
3236 RefreshProperty(property
);
3240 DrawItemAndChildren(property
);
3245 // -----------------------------------------------------------------------
3247 // flags are same as with DoSelectProperty
3248 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3250 if ( m_inDoPropertyChanged
)
3253 wxWindow
* editor
= GetEditorControl();
3254 wxPGProperty
* selected
= GetSelection();
3256 m_pState
->m_anyModified
= 1;
3258 m_inDoPropertyChanged
= 1;
3260 // Maybe need to update control
3261 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3263 // These values were calculated in PerformValidation()
3264 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3265 wxVariant value
= m_chgInfo_pendingValue
;
3267 wxPGProperty
* topPaintedProperty
= changedProperty
;
3269 while ( !topPaintedProperty
->IsCategory() &&
3270 !topPaintedProperty
->IsRoot() )
3272 topPaintedProperty
= topPaintedProperty
->GetParent();
3275 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3277 // Set as Modified (not if dragging just began)
3278 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3280 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3281 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3284 SetCurControlBoldFont();
3290 // Propagate updates to parent(s)
3292 wxPGProperty
* prevPwc
= NULL
;
3294 while ( prevPwc
!= topPaintedProperty
)
3296 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3298 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3301 SetCurControlBoldFont();
3305 pwc
= pwc
->GetParent();
3308 // Draw the actual property
3309 DrawItemAndChildren( topPaintedProperty
);
3312 // If value was set by wxPGProperty::OnEvent, then update the editor
3314 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3320 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3321 if ( m_wndEditor
) m_wndEditor
->Refresh();
3322 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3327 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3329 // If top parent has composite string value, then send to child parents,
3330 // starting from baseChangedProperty.
3331 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3333 pwc
= m_chgInfo_baseChangedProperty
;
3335 while ( pwc
!= changedProperty
)
3337 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3338 pwc
= pwc
->GetParent();
3342 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3344 m_inDoPropertyChanged
= 0;
3349 // -----------------------------------------------------------------------
3351 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3353 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3355 m_chgInfo_changedProperty
= NULL
;
3357 if ( PerformValidation(p
, newValue
) )
3359 DoPropertyChanged(p
);
3364 OnValidationFailure(p
, newValue
);
3370 // -----------------------------------------------------------------------
3372 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3374 wxPGProperty
* prop
= GetSelectedProperty();
3377 return wxNullVariant
;
3379 wxTextCtrl
* tc
= GetEditorTextCtrl();
3380 wxVariant value
= prop
->GetValue();
3382 if ( !tc
|| !IsEditorsValueModified() )
3385 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3388 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3389 return prop
->GetValue();
3394 // -----------------------------------------------------------------------
3396 // Runs wxValidator for the selected property
3397 bool wxPropertyGrid::DoEditorValidate()
3402 // -----------------------------------------------------------------------
3404 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3406 // It is possible that this handler receives event even before
3407 // the control has been properly initialized. Let's skip the
3408 // event handling in that case.
3412 wxPGProperty
* selected
= GetSelection();
3414 // Somehow, event is handled after property has been deselected.
3415 // Possibly, but very rare.
3417 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3418 // Also don't handle editor event if wxEVT_PG_CHANGED or
3419 // similar is currently doing something (showing a
3420 // message box, for instance).
3424 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3427 wxVariant
pendingValue(selected
->GetValueRef());
3428 wxWindow
* wnd
= GetEditorControl();
3429 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3431 bool wasUnspecified
= selected
->IsValueUnspecified();
3432 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3433 bool valueIsPending
= false;
3435 m_chgInfo_changedProperty
= NULL
;
3437 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3440 // Filter out excess wxTextCtrl modified events
3441 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3443 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3445 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3447 wxString newTcValue
= tc
->GetValue();
3448 if ( m_prevTcValue
== newTcValue
)
3450 m_prevTcValue
= newTcValue
;
3452 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3454 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3456 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3457 if ( m_prevTcValue
== newTcValue
)
3459 m_prevTcValue
= newTcValue
;
3463 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3465 bool validationFailure
= false;
3466 bool buttonWasHandled
= false;
3469 // Try common button handling
3470 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3472 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3476 buttonWasHandled
= true;
3477 // Store as res2, as previously (and still currently alternatively)
3478 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3479 // in wxPGProperty::OnEvent().
3480 adapter
->ShowDialog( this, selected
);
3485 if ( !buttonWasHandled
)
3487 if ( wnd
|| m_wndEditor2
)
3489 // First call editor class' event handler.
3490 const wxPGEditor
* editor
= selected
->GetEditorClass();
3492 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3494 // If changes, validate them
3495 if ( DoEditorValidate() )
3497 if ( editor
->GetValueFromControl( pendingValue
,
3500 valueIsPending
= true;
3504 validationFailure
= true;
3509 // Then the property's custom handler (must be always called, unless
3510 // validation failed).
3511 if ( !validationFailure
)
3512 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3515 // SetValueInEvent(), as called in one of the functions referred above
3516 // overrides editor's value.
3517 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3519 valueIsPending
= true;
3520 pendingValue
= m_changeInEventValue
;
3521 selFlags
|= wxPG_SEL_DIALOGVAL
;
3524 if ( !validationFailure
&& valueIsPending
)
3525 if ( !PerformValidation(selected
, pendingValue
) )
3526 validationFailure
= true;
3528 if ( validationFailure
)
3530 OnValidationFailure(selected
, pendingValue
);
3532 else if ( valueIsPending
)
3534 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3536 DoPropertyChanged(selected
, selFlags
);
3537 EditorsValueWasNotModified();
3539 // Regardless of editor type, unfocus editor on
3540 // text-editing related enter press.
3541 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3548 // No value after all
3550 // Regardless of editor type, unfocus editor on
3551 // text-editing related enter press.
3552 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3557 // Let unhandled button click events go to the parent
3558 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3560 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3561 GetEventHandler()->AddPendingEvent(evt
);
3565 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3568 // -----------------------------------------------------------------------
3569 // wxPropertyGrid editor control helper methods
3570 // -----------------------------------------------------------------------
3572 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3574 int itemy
= p
->GetY2(m_lineHeight
);
3575 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3576 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3577 int imageOffset
= 0;
3579 int vx
, vy
; // Top left corner of client
3580 GetViewStart(&vx
, &vy
);
3581 vy
*= wxPG_PIXELS_PER_UNIT
;
3585 // TODO: If custom image detection changes from current, change this.
3586 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3588 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3589 int iw
= p
->OnMeasureImage().x
;
3591 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3592 imageOffset
= p
->GetImageOffset(iw
);
3595 else if ( column
== 0 )
3597 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3602 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3604 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3609 // -----------------------------------------------------------------------
3611 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3613 wxSize sz
= GetImageSize(p
, item
);
3614 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3615 wxPG_CUSTOM_IMAGE_SPACINGY
,
3620 // return size of custom paint image
3621 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3623 // If called with NULL property, then return default image
3624 // size for properties that use image.
3626 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3628 wxSize cis
= p
->OnMeasureImage(item
);
3630 int choiceCount
= p
->m_choices
.GetCount();
3631 int comVals
= p
->GetDisplayedCommonValueCount();
3632 if ( item
>= choiceCount
&& comVals
> 0 )
3634 unsigned int cvi
= item
-choiceCount
;
3635 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3637 else if ( item
>= 0 && choiceCount
== 0 )
3638 return wxSize(0, 0);
3643 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3648 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3655 // -----------------------------------------------------------------------
3657 // takes scrolling into account
3658 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3661 GetViewStart(&vx
,&vy
);
3662 vy
*=wxPG_PIXELS_PER_UNIT
;
3663 vx
*=wxPG_PIXELS_PER_UNIT
;
3666 ClientToScreen( px
, py
);
3669 // -----------------------------------------------------------------------
3671 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3674 GetViewStart(&pt2
.x
,&pt2
.y
);
3675 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3676 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3680 return m_pState
->HitTest(pt2
);
3683 // -----------------------------------------------------------------------
3685 // custom set cursor
3686 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3688 if ( type
== m_curcursor
&& !override
) return;
3690 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3692 if ( type
== wxCURSOR_SIZEWE
)
3693 cursor
= m_cursorSizeWE
;
3695 SetCursor( *cursor
);
3700 // -----------------------------------------------------------------------
3703 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3705 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3707 if ( ua
.HasText() &&
3708 !(argFlags
& wxPG_FULL_VALUE
) &&
3709 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3710 return ua
.GetText();
3712 return wxEmptyString
;
3715 // -----------------------------------------------------------------------
3716 // wxPropertyGrid property selection, editor creation
3717 // -----------------------------------------------------------------------
3720 // This class forwards events from property editor controls to wxPropertyGrid.
3721 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3724 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3725 : wxEvtHandler(), m_propGrid(propGrid
)
3729 virtual ~wxPropertyGridEditorEventForwarder()
3734 bool ProcessEvent( wxEvent
& event
)
3739 m_propGrid
->HandleCustomEditorEvent(event
);
3742 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3743 // may beep annoyingly if that event is skipped
3744 // and passed to parent event handler.
3745 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3748 return wxEvtHandler::ProcessEvent(event
);
3751 wxPropertyGrid
* m_propGrid
;
3754 // Setups event handling for child control
3755 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3757 wxWindowID id
= argWnd
->GetId();
3759 if ( argWnd
== m_wndEditor
)
3761 argWnd
->Connect(id
, wxEVT_MOTION
,
3762 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3764 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3765 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3767 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3768 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3770 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3771 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3773 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3774 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3776 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3777 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3781 wxPropertyGridEditorEventForwarder
* forwarder
;
3782 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3783 argWnd
->PushEventHandler(forwarder
);
3785 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3786 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3790 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3797 // Do not free editors immediately (for sake of processing events)
3798 wxPendingDelete
.Append(wnd
);
3801 void wxPropertyGrid::FreeEditors()
3804 // Return focus back to canvas from children (this is required at least for
3805 // GTK+, which, unlike Windows, clears focus when control is destroyed
3806 // instead of moving it to closest parent).
3807 wxWindow
* focus
= wxWindow::FindFocus();
3810 wxWindow
* parent
= focus
->GetParent();
3813 if ( parent
== this )
3818 parent
= parent
->GetParent();
3822 // Do not free editors immediately if processing events
3825 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3826 m_wndEditor2
->Hide();
3827 wxPendingDelete
.Append( handler
);
3828 DestroyEditorWnd(m_wndEditor2
);
3829 m_wndEditor2
= NULL
;
3834 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3835 m_wndEditor
->Hide();
3836 wxPendingDelete
.Append( handler
);
3837 DestroyEditorWnd(m_wndEditor
);
3842 // Call with NULL to de-select property
3843 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3848 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3849 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3853 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3857 if ( m_inDoSelectProperty
)
3860 m_inDoSelectProperty
= 1;
3864 m_inDoSelectProperty
= 0;
3868 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3869 wxPGProperty
* prevFirstSel
;
3871 if ( prevSelection
.size() > 0 )
3872 prevFirstSel
= prevSelection
[0];
3874 prevFirstSel
= NULL
;
3876 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3877 prevFirstSel
= NULL
;
3879 // Always send event, as this is indirect call
3880 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3884 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3886 wxPrintf( "None selected\n" );
3889 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3891 wxPrintf( "P = NULL\n" );
3894 // If we are frozen, then just set the values.
3897 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3898 m_editorFocused
= 0;
3899 m_pState
->DoSetSelection(p
);
3901 // If frozen, always free controls. But don't worry, as Thaw will
3902 // recall SelectProperty to recreate them.
3905 // Prevent any further selection measures in this call
3911 if ( prevFirstSel
== p
&&
3912 prevSelection
.size() <= 1 &&
3913 !(flags
& wxPG_SEL_FORCE
) )
3915 // Only set focus if not deselecting
3918 if ( flags
& wxPG_SEL_FOCUS
)
3922 m_wndEditor
->SetFocus();
3923 m_editorFocused
= 1;
3932 m_inDoSelectProperty
= 0;
3937 // First, deactivate previous
3940 OnValidationFailureReset(prevFirstSel
);
3942 // Must double-check if this is an selected in case of forceswitch
3943 if ( p
!= prevFirstSel
)
3945 if ( !CommitChangesFromEditor(flags
) )
3947 // Validation has failed, so we can't exit the previous editor
3948 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3949 // _("Invalid Value"),wxOK|wxICON_ERROR);
3950 m_inDoSelectProperty
= 0;
3957 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3958 EditorsValueWasNotModified();
3961 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3963 m_pState
->DoSetSelection(p
);
3965 // Redraw unselected
3966 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3968 DrawItem(prevSelection
[i
]);
3972 // Then, activate the one given.
3975 int propY
= p
->GetY2(m_lineHeight
);
3977 int splitterX
= GetSplitterPosition();
3978 m_editorFocused
= 0;
3979 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3980 if ( p
!= prevFirstSel
)
3981 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3983 wxASSERT( m_wndEditor
== NULL
);
3986 // Only create editor for non-disabled non-caption
3987 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3989 // do this for non-caption items
3993 // Do we need to paint the custom image, if any?
3994 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3995 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3996 !p
->GetEditorClass()->CanContainCustomImage()
3998 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4000 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4001 wxPoint goodPos
= grect
.GetPosition();
4003 // Editor appearance can now be considered clear
4004 m_editorAppearance
.SetEmptyData();
4006 const wxPGEditor
* editor
= p
->GetEditorClass();
4007 wxCHECK_MSG(editor
, false,
4008 wxT("NULL editor class not allowed"));
4010 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4012 wxPGWindowList wndList
=
4013 editor
->CreateControls(this,
4018 m_wndEditor
= wndList
.m_primary
;
4019 m_wndEditor2
= wndList
.m_secondary
;
4020 wxWindow
* primaryCtrl
= GetEditorControl();
4023 // Essentially, primaryCtrl == m_wndEditor
4026 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4027 // case value is drawn as normal, and m_wndEditor2 is
4028 // assumed to be a right-aligned button that triggers
4029 // a separate editorCtrl window.
4033 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4034 "CreateControls must use result of "
4035 "wxPropertyGrid::GetPanel() as parent "
4038 // Set validator, if any
4039 #if wxUSE_VALIDATORS
4040 wxValidator
* validator
= p
->GetValidator();
4042 primaryCtrl
->SetValidator(*validator
);
4045 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4046 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4048 // If it has modified status, use bold font
4049 // (must be done before capturing m_ctrlXAdjust)
4050 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4051 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4052 SetCurControlBoldFont();
4054 // Store x relative to splitter (we'll need it).
4055 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4057 // Check if background clear is not necessary
4058 wxPoint pos
= m_wndEditor
->GetPosition();
4059 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4061 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4064 m_wndEditor
->SetSizeHints(3, 3);
4066 SetupChildEventHandling(primaryCtrl
);
4068 // Focus and select all (wxTextCtrl, wxComboBox etc)
4069 if ( flags
& wxPG_SEL_FOCUS
)
4071 primaryCtrl
->SetFocus();
4073 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4077 if ( p
->IsValueUnspecified() )
4078 SetEditorAppearance(m_unspecifiedAppearance
,
4085 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4086 "CreateControls must use result of "
4087 "wxPropertyGrid::GetPanel() as parent "
4090 // Get proper id for wndSecondary
4091 m_wndSecId
= m_wndEditor2
->GetId();
4092 wxWindowList children
= m_wndEditor2
->GetChildren();
4093 wxWindowList::iterator node
= children
.begin();
4094 if ( node
!= children
.end() )
4095 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4097 m_wndEditor2
->SetSizeHints(3,3);
4099 m_wndEditor2
->Show();
4101 SetupChildEventHandling(m_wndEditor2
);
4103 // If no primary editor, focus to button to allow
4104 // it to interprete ENTER etc.
4105 // NOTE: Due to problems focusing away from it, this
4106 // has been disabled.
4108 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4109 m_wndEditor2->SetFocus();
4113 if ( flags
& wxPG_SEL_FOCUS
)
4114 m_editorFocused
= 1;
4119 // Make sure focus is in grid canvas (important for wxGTK,
4124 EditorsValueWasNotModified();
4126 // If it's inside collapsed section, expand parent, scroll, etc.
4127 // Also, if it was partially visible, scroll it into view.
4128 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4133 m_wndEditor
->Show(true);
4136 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4141 // Make sure focus is in grid canvas
4145 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4151 // Show help text in status bar.
4152 // (if found and grid not embedded in manager with help box and
4153 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4156 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4158 wxStatusBar
* statusbar
= NULL
;
4159 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
4161 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
4163 statusbar
= frame
->GetStatusBar();
4168 const wxString
* pHelpString
= (const wxString
*) NULL
;
4172 pHelpString
= &p
->GetHelpString();
4173 if ( pHelpString
->length() )
4175 // Set help box text.
4176 statusbar
->SetStatusText( *pHelpString
);
4177 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4181 if ( (!pHelpString
|| !pHelpString
->length()) &&
4182 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4184 // Clear help box - but only if it was written
4185 // by us at previous time.
4186 statusbar
->SetStatusText( m_emptyString
);
4187 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4193 m_inDoSelectProperty
= 0;
4195 // call wx event handler (here so that it also occurs on deselection)
4196 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4197 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4202 // -----------------------------------------------------------------------
4204 bool wxPropertyGrid::UnfocusEditor()
4206 wxPGProperty
* selected
= GetSelection();
4208 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4211 if ( !CommitChangesFromEditor(0) )
4220 // -----------------------------------------------------------------------
4222 void wxPropertyGrid::RefreshEditor()
4224 wxPGProperty
* p
= GetSelection();
4228 wxWindow
* wnd
= GetEditorControl();
4232 // Set editor font boldness - must do this before
4233 // calling UpdateControl().
4234 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4236 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4237 wnd
->SetFont(GetCaptionFont());
4239 wnd
->SetFont(GetFont());
4242 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4244 editorClass
->UpdateControl(p
, wnd
);
4246 if ( p
->IsValueUnspecified() )
4247 SetEditorAppearance(m_unspecifiedAppearance
, true);
4250 // -----------------------------------------------------------------------
4252 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4254 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4256 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4258 flags
|= wxPG_SEL_FOCUS
;
4260 return DoSelectProperty(p
, flags
);
4263 // -----------------------------------------------------------------------
4264 // wxPropertyGrid expand/collapse state
4265 // -----------------------------------------------------------------------
4267 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4269 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4270 wxPGProperty
* selected
= GetSelection();
4272 // If active editor was inside collapsed section, then disable it
4273 if ( selected
&& selected
->IsSomeParent(p
) )
4278 // Store dont-center-splitter flag 'cause we need to temporarily set it
4279 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4280 m_pState
->m_dontCenterSplitter
= true;
4282 bool res
= m_pState
->DoCollapse(pwc
);
4287 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4289 RecalculateVirtualSize();
4293 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4298 // -----------------------------------------------------------------------
4300 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4302 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4304 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4306 // Store dont-center-splitter flag 'cause we need to temporarily set it
4307 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4308 m_pState
->m_dontCenterSplitter
= true;
4310 bool res
= m_pState
->DoExpand(pwc
);
4315 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4317 RecalculateVirtualSize();
4321 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4326 // -----------------------------------------------------------------------
4328 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4331 return m_pState
->DoHideProperty(p
, hide
, flags
);
4333 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4334 int selRemoveCount
= 0;
4335 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4337 wxPGProperty
* selected
= selection
[i
];
4338 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4340 if ( !DoRemoveFromSelection(p
, flags
) )
4342 selRemoveCount
+= 1;
4346 m_pState
->DoHideProperty(p
, hide
, flags
);
4348 RecalculateVirtualSize();
4355 // -----------------------------------------------------------------------
4356 // wxPropertyGrid size related methods
4357 // -----------------------------------------------------------------------
4359 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4361 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4362 // virtual size calculation may go wrong.
4363 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4369 // If virtual height was changed, then recalculate editor control position(s)
4370 if ( m_pState
->m_vhCalcPending
)
4371 CorrectEditorWidgetPosY();
4373 m_pState
->EnsureVirtualHeight();
4375 wxASSERT_LEVEL_2_MSG(
4376 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4377 "VirtualHeight and ActualVirtualHeight should match"
4380 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4382 int x
= m_pState
->m_width
;
4383 int y
= m_pState
->m_virtualHeight
;
4386 GetClientSize(&width
,&height
);
4388 // Now adjust virtual size.
4389 SetVirtualSize(x
, y
);
4395 // Adjust scrollbars
4396 if ( HasVirtualWidth() )
4398 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4399 xPos
= GetScrollPos( wxHORIZONTAL
);
4402 if ( forceXPos
!= -1 )
4405 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4408 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4409 int yPos
= GetScrollPos( wxVERTICAL
);
4411 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4412 xAmount
, yAmount
, xPos
, yPos
, true );
4414 // Must re-get size now
4415 GetClientSize(&width
,&height
);
4417 if ( !HasVirtualWidth() )
4419 m_pState
->SetVirtualWidth(width
);
4426 m_pState
->CheckColumnWidths();
4428 if ( GetSelection() )
4429 CorrectEditorWidgetSizeX();
4431 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4434 // -----------------------------------------------------------------------
4436 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4438 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4442 GetClientSize(&width
, &height
);
4447 #if wxPG_DOUBLE_BUFFER
4448 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4450 int dblh
= (m_lineHeight
*2);
4451 if ( !m_doubleBuffer
)
4453 // Create double buffer bitmap to draw on, if none
4454 int w
= (width
>250)?width
:250;
4455 int h
= height
+ dblh
;
4457 m_doubleBuffer
= new wxBitmap( w
, h
);
4461 int w
= m_doubleBuffer
->GetWidth();
4462 int h
= m_doubleBuffer
->GetHeight();
4464 // Double buffer must be large enough
4465 if ( w
< width
|| h
< (height
+dblh
) )
4467 if ( w
< width
) w
= width
;
4468 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4469 delete m_doubleBuffer
;
4470 m_doubleBuffer
= new wxBitmap( w
, h
);
4477 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4478 m_ncWidth
= event
.GetSize().x
;
4482 if ( m_pState
->m_itemsAdded
)
4483 PrepareAfterItemsAdded();
4485 // Without this, virtual size (atleast under wxGTK) will be skewed
4486 RecalculateVirtualSize();
4492 // -----------------------------------------------------------------------
4494 void wxPropertyGrid::SetVirtualWidth( int width
)
4498 // Disable virtual width
4499 width
= GetClientSize().x
;
4500 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4504 // Enable virtual width
4505 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4507 m_pState
->SetVirtualWidth( width
);
4510 void wxPropertyGrid::SetFocusOnCanvas()
4512 SetFocusIgnoringChildren();
4513 m_editorFocused
= 0;
4516 // -----------------------------------------------------------------------
4517 // wxPropertyGrid mouse event handling
4518 // -----------------------------------------------------------------------
4520 // selFlags uses same values DoSelectProperty's flags
4521 // Returns true if event was vetoed.
4522 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4524 unsigned int selFlags
,
4525 unsigned int column
)
4527 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4530 // Send property grid event of specific type and with specific property
4531 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4532 evt
.SetPropertyGrid(this);
4533 evt
.SetEventObject(m_eventObject
);
4535 evt
.SetColumn(column
);
4536 if ( eventType
== wxEVT_PG_CHANGING
)
4539 evt
.SetCanVeto(true);
4540 m_validationInfo
.m_pValue
= pValue
;
4541 evt
.SetupValidationInfo();
4546 evt
.SetPropertyValue(p
->GetValue());
4548 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4549 evt
.SetCanVeto(true);
4552 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4553 m_processedEvent
= &evt
;
4554 m_eventObject
->HandleWindowEvent(evt
);
4555 m_processedEvent
= prevProcessedEvent
;
4557 return evt
.WasVetoed();
4560 // -----------------------------------------------------------------------
4562 // Return false if should be skipped
4563 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4567 // Need to set focus?
4568 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4573 wxPropertyGridPageState
* state
= m_pState
;
4575 int splitterHitOffset
;
4576 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4578 wxPGProperty
* p
= DoGetItemAtY(y
);
4582 int depth
= (int)p
->GetDepth() - 1;
4584 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4586 if ( x
>= marginEnds
)
4590 if ( p
->IsCategory() )
4592 // This is category.
4593 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4595 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4597 // Expand, collapse, activate etc. if click on text or left of splitter.
4600 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4605 if ( !AddToSelectionFromInputEvent( p
,
4610 // On double-click, expand/collapse.
4611 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4613 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4614 else DoExpand( p
, true );
4618 else if ( splitterHit
== -1 )
4621 unsigned int selFlag
= 0;
4622 if ( columnHit
== 1 )
4624 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4625 selFlag
= wxPG_SEL_FOCUS
;
4627 if ( !AddToSelectionFromInputEvent( p
,
4633 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4635 if ( p
->GetChildCount() && !p
->IsCategory() )
4636 // On double-click, expand/collapse.
4637 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4639 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4640 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4641 else DoExpand( p
, true );
4648 // click on splitter
4649 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4651 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4653 // Double-clicking the splitter causes auto-centering
4654 if ( m_pState
->GetColumnCount() <= 2 )
4656 ResetColumnSizes( true );
4658 SendEvent(wxEVT_PG_COL_DRAGGING
,
4661 wxPG_SEL_NOVALIDATE
,
4662 (unsigned int)m_draggedSplitter
);
4665 else if ( m_dragStatus
== 0 )
4668 // Begin draggin the splitter
4672 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4674 // Allow application to veto dragging
4675 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4677 (unsigned int)splitterHit
) )
4681 // Changes must be committed here or the
4682 // value won't be drawn correctly
4683 if ( !CommitChangesFromEditor() )
4686 m_wndEditor
->Show ( false );
4689 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4692 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4696 m_draggedSplitter
= splitterHit
;
4697 m_dragOffset
= splitterHitOffset
;
4699 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4700 // Fixes button disappearance bug
4702 m_wndEditor2
->Show ( false );
4705 m_startingSplitterX
= x
- splitterHitOffset
;
4714 if ( p
->GetChildCount() )
4716 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4718 // Fine tune cell button x
4719 if ( !p
->IsCategory() )
4720 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4722 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4724 int y2
= y
% m_lineHeight
;
4725 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4727 // On click on expander button, expand/collapse
4728 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4729 DoCollapse( p
, true );
4731 DoExpand( p
, true );
4740 // -----------------------------------------------------------------------
4742 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4743 unsigned int WXUNUSED(y
),
4744 wxMouseEvent
& event
)
4748 // Select property here as well
4749 wxPGProperty
* p
= m_propHover
;
4750 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4752 // Send right click event.
4753 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4760 // -----------------------------------------------------------------------
4762 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4763 unsigned int WXUNUSED(y
),
4764 wxMouseEvent
& event
)
4768 // Select property here as well
4769 wxPGProperty
* p
= m_propHover
;
4771 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4773 // Send double-click event.
4774 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4781 // -----------------------------------------------------------------------
4783 #if wxPG_SUPPORT_TOOLTIPS
4785 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4787 if ( tipString
.length() )
4789 wxScrolledWindow::SetToolTip(tipString
);
4793 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4794 wxScrolledWindow::SetToolTip( m_emptyString
);
4796 wxScrolledWindow::SetToolTip( NULL
);
4801 #endif // #if wxPG_SUPPORT_TOOLTIPS
4803 // -----------------------------------------------------------------------
4805 // Return false if should be skipped
4806 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4807 wxMouseEvent
&event
)
4809 // Safety check (needed because mouse capturing may
4810 // otherwise freeze the control)
4811 if ( m_dragStatus
> 0 && !event
.Dragging() )
4813 HandleMouseUp(x
, y
, event
);
4816 wxPropertyGridPageState
* state
= m_pState
;
4818 int splitterHitOffset
;
4819 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4820 int splitterX
= x
- splitterHitOffset
;
4822 m_colHover
= columnHit
;
4824 if ( m_dragStatus
> 0 )
4826 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4827 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4830 int newSplitterX
= x
- m_dragOffset
;
4832 // Splitter redraw required?
4833 if ( newSplitterX
!= splitterX
)
4836 DoSetSplitterPosition(newSplitterX
,
4838 wxPG_SPLITTER_REFRESH
|
4839 wxPG_SPLITTER_FROM_EVENT
);
4841 SendEvent(wxEVT_PG_COL_DRAGGING
,
4844 wxPG_SEL_NOVALIDATE
,
4845 (unsigned int)m_draggedSplitter
);
4856 int ih
= m_lineHeight
;
4859 #if wxPG_SUPPORT_TOOLTIPS
4860 wxPGProperty
* prevHover
= m_propHover
;
4861 unsigned char prevSide
= m_mouseSide
;
4863 int curPropHoverY
= y
- (y
% ih
);
4865 // On which item it hovers
4868 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4871 // Mouse moves on another property
4873 m_propHover
= DoGetItemAtY(y
);
4874 m_propHoverY
= curPropHoverY
;
4877 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4880 #if wxPG_SUPPORT_TOOLTIPS
4881 // Store which side we are on
4883 if ( columnHit
== 1 )
4885 else if ( columnHit
== 0 )
4889 // If tooltips are enabled, show label or value as a tip
4890 // in case it doesn't otherwise show in full length.
4892 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4894 wxToolTip
* tooltip
= GetToolTip();
4896 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4898 if ( m_propHover
&& !m_propHover
->IsCategory() )
4901 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4903 // Show help string as a tooltip
4904 wxString tipString
= m_propHover
->GetHelpString();
4906 SetToolTip(tipString
);
4910 // Show cropped value string as a tooltip
4914 if ( m_mouseSide
== 1 )
4916 tipString
= m_propHover
->m_label
;
4917 space
= splitterX
-m_marginWidth
-3;
4919 else if ( m_mouseSide
== 2 )
4921 tipString
= m_propHover
->GetDisplayedString();
4923 space
= m_width
- splitterX
;
4924 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4925 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
4926 wxCC_CUSTOM_IMAGE_MARGIN1
+
4927 wxCC_CUSTOM_IMAGE_MARGIN2
;
4933 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4936 SetToolTip( tipString
);
4943 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4944 SetToolTip( m_emptyString
);
4946 wxScrolledWindow::SetToolTip( NULL
);
4957 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4958 SetToolTip( m_emptyString
);
4960 wxScrolledWindow::SetToolTip( NULL
);
4968 if ( splitterHit
== -1 ||
4970 HasFlag(wxPG_STATIC_SPLITTER
) )
4972 // hovering on something else
4973 if ( m_curcursor
!= wxCURSOR_ARROW
)
4974 CustomSetCursor( wxCURSOR_ARROW
);
4978 // Do not allow splitter cursor on caption items.
4979 // (also not if we were dragging and its started
4980 // outside the splitter region)
4982 if ( !m_propHover
->IsCategory() &&
4986 // hovering on splitter
4988 // NB: Condition disabled since MouseLeave event (from the
4989 // editor control) cannot be reliably detected.
4990 //if ( m_curcursor != wxCURSOR_SIZEWE )
4991 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4997 // hovering on something else
4998 if ( m_curcursor
!= wxCURSOR_ARROW
)
4999 CustomSetCursor( wxCURSOR_ARROW
);
5004 // Multi select by dragging
5006 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5007 event
.LeftIsDown() &&
5011 !state
->DoIsPropertySelected(m_propHover
) )
5013 // Additional requirement is that the hovered property
5014 // is adjacent to edges of selection.
5015 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5017 // Since categories cannot be selected along with 'other'
5018 // properties, exclude them from iterator flags.
5019 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5021 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5023 // TODO: This could be optimized by keeping track of
5024 // which properties are at the edges of selection.
5025 wxPGProperty
* selProp
= selection
[i
];
5026 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5029 DoAddToSelection(m_propHover
);
5038 // -----------------------------------------------------------------------
5040 // Also handles Leaving event
5041 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5042 wxMouseEvent
&WXUNUSED(event
) )
5044 wxPropertyGridPageState
* state
= m_pState
;
5048 int splitterHitOffset
;
5049 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5051 // No event type check - basicly calling this method should
5052 // just stop dragging.
5053 // Left up after dragged?
5054 if ( m_dragStatus
>= 1 )
5057 // End Splitter Dragging
5059 // DO NOT ENABLE FOLLOWING LINE!
5060 // (it is only here as a reminder to not to do it)
5063 SendEvent(wxEVT_PG_COL_END_DRAG
,
5066 wxPG_SEL_NOVALIDATE
,
5067 (unsigned int)m_draggedSplitter
);
5069 // Disable splitter auto-centering (but only if moved any -
5070 // otherwise we end up disabling auto-center even after a
5071 // recentering double-click).
5072 int posDiff
= abs(m_startingSplitterX
-
5073 GetSplitterPosition(m_draggedSplitter
));
5076 state
->m_dontCenterSplitter
= true;
5078 // This is necessary to return cursor
5079 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5082 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5085 // Set back the default cursor, if necessary
5086 if ( splitterHit
== -1 ||
5089 CustomSetCursor( wxCURSOR_ARROW
);
5094 // Control background needs to be cleared
5095 wxPGProperty
* selected
= GetSelection();
5096 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5097 DrawItem( selected
);
5101 m_wndEditor
->Show ( true );
5104 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5105 // Fixes button disappearance bug
5107 m_wndEditor2
->Show ( true );
5110 // This clears the focus.
5111 m_editorFocused
= 0;
5117 // -----------------------------------------------------------------------
5119 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5121 int splitterX
= GetSplitterPosition();
5124 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5126 wxWindow
* wnd
= GetEditorControl();
5128 // Hide popup on clicks
5129 if ( event
.GetEventType() != wxEVT_MOTION
)
5130 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5132 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5138 if ( wnd
== NULL
|| m_dragStatus
||
5140 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5141 ux
>= (r
.x
+r
.width
) ||
5143 event
.m_y
>= (r
.y
+r
.height
)
5153 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5158 // -----------------------------------------------------------------------
5160 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5163 if ( OnMouseCommon( event
, &x
, &y
) )
5165 HandleMouseClick(x
,y
,event
);
5170 // -----------------------------------------------------------------------
5172 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5175 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5176 HandleMouseRightClick(x
,y
,event
);
5180 // -----------------------------------------------------------------------
5182 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5184 // Always run standard mouse-down handler as well
5185 OnMouseClick(event
);
5188 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5189 HandleMouseDoubleClick(x
,y
,event
);
5193 // -----------------------------------------------------------------------
5195 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5198 if ( OnMouseCommon( event
, &x
, &y
) )
5200 HandleMouseMove(x
,y
,event
);
5205 // -----------------------------------------------------------------------
5207 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5210 if ( OnMouseCommon( event
, &x
, &y
) )
5212 HandleMouseUp(x
,y
,event
);
5217 // -----------------------------------------------------------------------
5219 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5221 // This may get called from child control as well, so event's
5222 // mouse position cannot be relied on.
5224 if ( event
.Entering() )
5226 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5228 // TODO: Fix this (detect parent and only do
5229 // cursor trick if it is a manager).
5230 wxASSERT( GetParent() );
5231 GetParent()->SetCursor(wxNullCursor
);
5233 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5236 GetParent()->SetCursor(wxNullCursor
);
5238 else if ( event
.Leaving() )
5240 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5241 SetCursor( wxNullCursor
);
5243 // Get real cursor position
5244 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5246 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5249 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5251 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5255 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5263 // -----------------------------------------------------------------------
5265 // Common code used by various OnMouseXXXChild methods.
5266 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5268 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5269 wxASSERT( topCtrlWnd
);
5271 event
.GetPosition(&x
,&y
);
5273 int splitterX
= GetSplitterPosition();
5275 wxRect r
= topCtrlWnd
->GetRect();
5276 if ( !m_dragStatus
&&
5277 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5278 y
>= 0 && y
< r
.height \
5281 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5286 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5293 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5296 if ( OnMouseChildCommon(event
,&x
,&y
) )
5298 bool res
= HandleMouseClick(x
,y
,event
);
5299 if ( !res
) event
.Skip();
5303 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5306 wxASSERT( m_wndEditor
);
5307 // These coords may not be exact (about +-2),
5308 // but that should not matter (right click is about item, not position).
5309 wxPoint pt
= m_wndEditor
->GetPosition();
5310 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5312 // FIXME: Used to set m_propHover to selection here. Was it really
5315 bool res
= HandleMouseRightClick(x
,y
,event
);
5316 if ( !res
) event
.Skip();
5319 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5322 if ( OnMouseChildCommon(event
,&x
,&y
) )
5324 bool res
= HandleMouseMove(x
,y
,event
);
5325 if ( !res
) event
.Skip();
5329 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5332 if ( OnMouseChildCommon(event
,&x
,&y
) )
5334 bool res
= HandleMouseUp(x
,y
,event
);
5335 if ( !res
) event
.Skip();
5339 // -----------------------------------------------------------------------
5340 // wxPropertyGrid keyboard event handling
5341 // -----------------------------------------------------------------------
5343 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5345 // Translates wxKeyEvent to wxPG_ACTION_XXX
5347 int keycode
= event
.GetKeyCode();
5348 int modifiers
= event
.GetModifiers();
5350 wxASSERT( !(modifiers
&~(0xFFFF)) );
5352 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5354 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5356 if ( it
== m_actionTriggers
.end() )
5361 int second
= (it
->second
>>16) & 0xFFFF;
5365 return (it
->second
& 0xFFFF);
5368 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5370 wxASSERT( !(modifiers
&~(0xFFFF)) );
5372 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5374 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5376 if ( it
!= m_actionTriggers
.end() )
5378 // This key combination is already used
5380 // Can add secondary?
5381 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5382 wxT("You can only add up to two separate actions per key combination.") );
5384 action
= it
->second
| (action
<<16);
5387 m_actionTriggers
[hashMapKey
] = action
;
5390 void wxPropertyGrid::ClearActionTriggers( int action
)
5392 wxPGHashMapI2I::iterator it
;
5397 didSomething
= false;
5399 for ( it
= m_actionTriggers
.begin();
5400 it
!= m_actionTriggers
.end();
5403 if ( it
->second
== action
)
5405 m_actionTriggers
.erase(it
);
5406 didSomething
= true;
5411 while ( didSomething
);
5414 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5417 // Handles key event when editor control is not focused.
5420 wxCHECK2(!m_frozen
, return);
5422 // Travelsal between items, collapsing/expanding, etc.
5423 wxPGProperty
* selected
= GetSelection();
5424 int keycode
= event
.GetKeyCode();
5425 bool editorFocused
= IsEditorFocused();
5427 if ( keycode
== WXK_TAB
)
5429 wxWindow
* mainControl
;
5431 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5432 mainControl
= GetParent();
5436 if ( !event
.ShiftDown() )
5438 if ( !editorFocused
&& m_wndEditor
)
5440 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5444 // Tab traversal workaround for platforms on which
5445 // wxWindow::Navigate() may navigate into first child
5446 // instead of next sibling. Does not work perfectly
5447 // in every scenario (for instance, when property grid
5448 // is either first or last control).
5449 #if defined(__WXGTK__)
5450 wxWindow
* sibling
= mainControl
->GetNextSibling();
5452 sibling
->SetFocusFromKbd();
5454 Navigate(wxNavigationKeyEvent::IsForward
);
5460 if ( editorFocused
)
5466 #if defined(__WXGTK__)
5467 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5469 sibling
->SetFocusFromKbd();
5471 Navigate(wxNavigationKeyEvent::IsBackward
);
5479 // Ignore Alt and Control when they are down alone
5480 if ( keycode
== WXK_ALT
||
5481 keycode
== WXK_CONTROL
)
5488 int action
= KeyEventToActions(event
, &secondAction
);
5490 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5493 // Esc cancels any changes
5494 if ( IsEditorsValueModified() )
5496 EditorsValueWasNotModified();
5498 // Update the control as well
5499 selected
->GetEditorClass()->
5500 SetControlStringValue( selected
,
5502 selected
->GetDisplayedString() );
5505 OnValidationFailureReset(selected
);
5511 // Except for TAB and ESC, handle child control events in child control
5514 // Only propagate event if it had modifiers
5515 if ( !event
.HasModifiers() )
5517 event
.StopPropagation();
5523 bool wasHandled
= false;
5528 if ( ButtonTriggerKeyTest(action
, event
) )
5531 wxPGProperty
* p
= selected
;
5533 // Travel and expand/collapse
5536 if ( p
->GetChildCount() )
5538 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5540 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5543 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5545 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5552 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5556 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5562 if ( selectDir
>= -1 )
5564 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5566 DoSelectProperty(p
);
5572 // If nothing was selected, select the first item now
5573 // (or navigate out of tab).
5574 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5576 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5577 if ( p
) DoSelectProperty(p
);
5586 // -----------------------------------------------------------------------
5588 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5590 // If there was editor open and focused, then this event should not
5591 // really be processed here.
5592 if ( IsEditorFocused() )
5594 // However, if event had modifiers, it is probably still best
5596 if ( event
.HasModifiers() )
5599 event
.StopPropagation();
5603 HandleKeyEvent(event
, false);
5606 // -----------------------------------------------------------------------
5608 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5613 action
= KeyEventToActions(event
, &secondAction
);
5616 // Does the keycode trigger button?
5617 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5620 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5621 GetEventHandler()->AddPendingEvent(evt
);
5628 // -----------------------------------------------------------------------
5630 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5632 HandleKeyEvent(event
, true);
5635 // -----------------------------------------------------------------------
5636 // wxPropertyGrid miscellaneous event handling
5637 // -----------------------------------------------------------------------
5639 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5642 // Check if the focus is in this control or one of its children
5643 wxWindow
* newFocused
= wxWindow::FindFocus();
5645 if ( newFocused
!= m_curFocused
)
5646 HandleFocusChange( newFocused
);
5649 // Check if top-level parent has changed
5650 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5652 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5658 // Resolve pending property removals
5659 if ( m_deletedProperties
.size() > 0 )
5661 wxArrayPGProperty
& arr
= m_deletedProperties
;
5662 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5664 DeleteProperty(arr
[i
]);
5668 if ( m_removedProperties
.size() > 0 )
5670 wxArrayPGProperty
& arr
= m_removedProperties
;
5671 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5673 RemoveProperty(arr
[i
]);
5679 bool wxPropertyGrid::IsEditorFocused() const
5681 wxWindow
* focus
= wxWindow::FindFocus();
5683 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5684 focus
== GetEditorControl() )
5690 // Called by focus event handlers. newFocused is the window that becomes focused.
5691 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5693 unsigned int oldFlags
= m_iFlags
;
5694 bool wasEditorFocused
= false;
5695 wxWindow
* wndEditor
= m_wndEditor
;
5697 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5699 wxWindow
* parent
= newFocused
;
5701 // This must be one of nextFocus' parents.
5704 if ( parent
== wndEditor
)
5706 wasEditorFocused
= true;
5708 // Use m_eventObject, which is either wxPropertyGrid or
5709 // wxPropertyGridManager, as appropriate.
5710 else if ( parent
== m_eventObject
)
5712 m_iFlags
|= wxPG_FL_FOCUSED
;
5715 parent
= parent
->GetParent();
5718 // Notify editor control when it receives a focus
5719 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5721 wxPGProperty
* p
= GetSelection();
5724 const wxPGEditor
* editor
= p
->GetEditorClass();
5725 ResetEditorAppearance();
5726 editor
->OnFocus(p
, GetEditorControl());
5730 m_curFocused
= newFocused
;
5732 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5733 (oldFlags
& wxPG_FL_FOCUSED
) )
5735 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5737 // Need to store changed value
5738 CommitChangesFromEditor();
5744 // Preliminary code for tab-order respecting
5745 // tab-traversal (but should be moved to
5748 wxWindow* prevFocus = event.GetWindow();
5749 wxWindow* useThis = this;
5750 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5751 useThis = GetParent();
5754 prevFocus->GetParent() == useThis->GetParent() )
5756 wxList& children = useThis->GetParent()->GetChildren();
5758 wxNode* node = children.Find(prevFocus);
5760 if ( node->GetNext() &&
5761 useThis == node->GetNext()->GetData() )
5762 DoSelectProperty(GetFirst());
5763 else if ( node->GetPrevious () &&
5764 useThis == node->GetPrevious()->GetData() )
5765 DoSelectProperty(GetLastProperty());
5772 wxPGProperty
* selected
= GetSelection();
5773 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5774 DrawItem( selected
);
5778 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5780 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5781 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5782 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5783 //else if ( event.GetWindow() )
5785 HandleFocusChange(event
.GetWindow());
5790 // -----------------------------------------------------------------------
5792 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5794 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5798 // -----------------------------------------------------------------------
5800 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5802 m_iFlags
|= wxPG_FL_SCROLLED
;
5807 // -----------------------------------------------------------------------
5809 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5811 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5813 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5817 // -----------------------------------------------------------------------
5818 // Property editor related functions
5819 // -----------------------------------------------------------------------
5821 // noDefCheck = true prevents infinite recursion.
5822 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5823 const wxString
& editorName
,
5826 wxASSERT( editorClass
);
5828 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5829 RegisterDefaultEditors();
5831 wxString name
= editorName
;
5832 if ( name
.length() == 0 )
5833 name
= editorClass
->GetName();
5835 // Existing editor under this name?
5836 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5838 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5840 // If this name was already used, try class name.
5841 name
= editorClass
->GetClassInfo()->GetClassName();
5842 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5845 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5846 (wxPGEditor
*) vt_it
->second
,
5847 "Editor with given name was already registered" );
5849 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5854 // Use this in RegisterDefaultEditors.
5855 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5856 if ( wxPGEditor_##EDITOR == NULL ) \
5858 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5859 new wxPG##EDITOR##Editor, true ); \
5862 // Registers all default editor classes
5863 void wxPropertyGrid::RegisterDefaultEditors()
5865 wxPGRegisterDefaultEditorClass( TextCtrl
);
5866 wxPGRegisterDefaultEditorClass( Choice
);
5867 wxPGRegisterDefaultEditorClass( ComboBox
);
5868 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5869 #if wxPG_INCLUDE_CHECKBOX
5870 wxPGRegisterDefaultEditorClass( CheckBox
);
5872 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5874 // Register SpinCtrl etc. editors before use
5875 RegisterAdditionalEditors();
5878 // -----------------------------------------------------------------------
5879 // wxPGStringTokenizer
5880 // Needed to handle C-style string lists (e.g. "str1" "str2")
5881 // -----------------------------------------------------------------------
5883 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5884 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5888 wxPGStringTokenizer::~wxPGStringTokenizer()
5892 bool wxPGStringTokenizer::HasMoreTokens()
5894 const wxString
& str
= *m_str
;
5896 wxString::const_iterator i
= m_curPos
;
5898 wxUniChar delim
= m_delimeter
;
5900 wxUniChar prev_a
= wxT('\0');
5902 bool inToken
= false;
5904 while ( i
!= str
.end() )
5913 m_readyToken
.clear();
5918 if ( prev_a
!= wxT('\\') )
5922 if ( a
!= wxT('\\') )
5942 m_curPos
= str
.end();
5950 wxString
wxPGStringTokenizer::GetNextToken()
5952 return m_readyToken
;
5955 // -----------------------------------------------------------------------
5957 // -----------------------------------------------------------------------
5959 wxPGChoiceEntry::wxPGChoiceEntry()
5960 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5964 // -----------------------------------------------------------------------
5966 // -----------------------------------------------------------------------
5968 wxPGChoicesData::wxPGChoicesData()
5972 wxPGChoicesData::~wxPGChoicesData()
5977 void wxPGChoicesData::Clear()
5982 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5984 wxASSERT( m_items
.size() == 0 );
5986 m_items
= data
->m_items
;
5989 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5990 const wxPGChoiceEntry
& item
)
5992 wxVector
<wxPGChoiceEntry
>::iterator it
;
5996 index
= (int) m_items
.size();
6000 it
= m_items
.begin() + index
;
6003 m_items
.insert(it
, item
);
6005 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6007 // Need to fix value?
6008 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6009 ownEntry
.SetValue(index
);
6014 // -----------------------------------------------------------------------
6015 // wxPropertyGridEvent
6016 // -----------------------------------------------------------------------
6018 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6021 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6022 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6023 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6024 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6025 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6026 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6027 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6028 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6029 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6030 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6031 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6032 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6033 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6034 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6036 // -----------------------------------------------------------------------
6038 void wxPropertyGridEvent::Init()
6040 m_validationInfo
= NULL
;
6043 m_wasVetoed
= false;
6046 // -----------------------------------------------------------------------
6048 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6049 : wxCommandEvent(commandType
,id
)
6055 // -----------------------------------------------------------------------
6057 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6058 : wxCommandEvent(event
)
6060 m_eventType
= event
.GetEventType();
6061 m_eventObject
= event
.m_eventObject
;
6063 OnPropertyGridSet();
6064 m_property
= event
.m_property
;
6065 m_validationInfo
= event
.m_validationInfo
;
6066 m_canVeto
= event
.m_canVeto
;
6067 m_wasVetoed
= event
.m_wasVetoed
;
6070 // -----------------------------------------------------------------------
6072 void wxPropertyGridEvent::OnPropertyGridSet()
6078 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6080 m_pg
->m_liveEvents
.push_back(this);
6083 // -----------------------------------------------------------------------
6085 wxPropertyGridEvent::~wxPropertyGridEvent()
6090 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6093 // Use iterate from the back since it is more likely that the event
6094 // being desroyed is at the end of the array.
6095 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6097 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6099 if ( liveEvents
[i
] == this )
6101 liveEvents
.erase(liveEvents
.begin() + i
);
6108 // -----------------------------------------------------------------------
6110 wxEvent
* wxPropertyGridEvent::Clone() const
6112 return new wxPropertyGridEvent( *this );
6115 // -----------------------------------------------------------------------
6116 // wxPropertyGridPopulator
6117 // -----------------------------------------------------------------------
6119 wxPropertyGridPopulator::wxPropertyGridPopulator()
6123 wxPGGlobalVars
->m_offline
++;
6126 // -----------------------------------------------------------------------
6128 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6131 m_propHierarchy
.clear();
6134 // -----------------------------------------------------------------------
6136 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6142 // -----------------------------------------------------------------------
6144 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6147 // Free unused sets of choices
6148 wxPGHashMapS2P::iterator it
;
6150 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6152 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6159 m_pg
->GetPanel()->Refresh();
6161 wxPGGlobalVars
->m_offline
--;
6164 // -----------------------------------------------------------------------
6166 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6167 const wxString
& propLabel
,
6168 const wxString
& propName
,
6169 const wxString
* propValue
,
6170 wxPGChoices
* pChoices
)
6172 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6173 wxPGProperty
* parent
= GetCurParent();
6175 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6177 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6181 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6183 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6187 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6189 property
->SetLabel(propLabel
);
6190 property
->DoSetName(propName
);
6192 if ( pChoices
&& pChoices
->IsOk() )
6193 property
->SetChoices(*pChoices
);
6195 m_state
->DoInsert(parent
, -1, property
);
6198 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6199 wxPG_PROGRAMMATIC_VALUE
);
6204 // -----------------------------------------------------------------------
6206 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6208 m_propHierarchy
.push_back(property
);
6209 DoScanForChildren();
6210 m_propHierarchy
.pop_back();
6213 // -----------------------------------------------------------------------
6215 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6216 const wxString
& idString
)
6218 wxPGChoices choices
;
6221 if ( choicesString
[0] == wxT('@') )
6223 wxString ids
= choicesString
.substr(1);
6224 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6225 if ( it
== m_dictIdChoices
.end() )
6226 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6228 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6233 if ( idString
.length() )
6235 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6236 if ( it
!= m_dictIdChoices
.end() )
6238 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6245 // Parse choices string
6246 wxString::const_iterator it
= choicesString
.begin();
6250 bool labelValid
= false;
6252 for ( ; it
!= choicesString
.end(); ++it
)
6258 if ( c
== wxT('"') )
6263 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6264 choices
.Add(label
, l
);
6267 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6272 else if ( c
== wxT('=') )
6279 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6286 if ( c
== wxT('"') )
6299 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6300 choices
.Add(label
, l
);
6303 if ( !choices
.IsOk() )
6305 choices
.EnsureData();
6309 if ( idString
.length() )
6310 m_dictIdChoices
[idString
] = choices
.GetData();
6317 // -----------------------------------------------------------------------
6319 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6321 if ( s
.Last() == wxT('%') )
6323 wxString s2
= s
.substr(0,s
.length()-1);
6325 if ( s2
.ToLong(&val
, 10) )
6327 *pval
= (val
*max
)/100;
6333 return s
.ToLong(pval
, 10);
6336 // -----------------------------------------------------------------------
6338 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6339 const wxString
& type
,
6340 const wxString
& value
)
6342 int l
= m_propHierarchy
.size();
6346 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6347 wxString valuel
= value
.Lower();
6350 if ( type
.length() == 0 )
6355 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6357 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6359 else if ( value
.ToLong(&v
, 0) )
6366 if ( type
== wxT("string") )
6370 else if ( type
== wxT("int") )
6373 value
.ToLong(&v
, 0);
6376 else if ( type
== wxT("bool") )
6378 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6385 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6390 p
->SetAttribute( name
, variant
);
6395 // -----------------------------------------------------------------------
6397 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6399 wxLogError(_("Error in resource: %s"),msg
.c_str());
6402 // -----------------------------------------------------------------------
6404 #endif // wxUSE_PROPGRID