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 // -----------------------------------------------------------------------
121 void wxPropertyGrid
::AutoGetTranslation ( bool enable
)
123 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
126 void wxPropertyGrid
::AutoGetTranslation ( bool ) { }
129 // -----------------------------------------------------------------------
131 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
133 // -----------------------------------------------------------------------
134 // Statics in one class for easy destruction.
135 // -----------------------------------------------------------------------
137 #include "wx/module.h"
139 class wxPGGlobalVarsClassManager
: public wxModule
141 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
143 wxPGGlobalVarsClassManager() {}
144 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
145 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
148 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
151 // When wxPG is loaded dynamically after the application is already running
152 // then the built-in module system won't pick this one up. Add it manually.
153 void wxPGInitResourceModule()
155 wxModule
* module
= new wxPGGlobalVarsClassManager
;
157 wxModule
::RegisterModule(module
);
160 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
163 wxPGGlobalVarsClass
::wxPGGlobalVarsClass()
165 wxPGProperty
::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
167 m_boolChoices
.Add(_("False"));
168 m_boolChoices
.Add(_("True"));
170 m_fontFamilyChoices
= NULL
;
172 m_defaultRenderer
= new wxPGDefaultRenderer();
174 m_autoGetTranslation
= false;
182 // Prepare some shared variants
183 m_vEmptyString
= wxString();
185 m_vMinusOne
= (long) -1;
189 // Prepare cached string constants
190 m_strstring
= wxS("string");
191 m_strlong
= wxS("long");
192 m_strbool
= wxS("bool");
193 m_strlist
= wxS("list");
194 m_strDefaultValue
= wxS("DefaultValue");
195 m_strMin
= wxS("Min");
196 m_strMax
= wxS("Max");
197 m_strUnits
= wxS("Units");
198 m_strInlineHelp
= wxS("InlineHelp");
204 wxPGGlobalVarsClass
::~wxPGGlobalVarsClass()
208 delete m_defaultRenderer
;
210 // This will always have one ref
211 delete m_fontFamilyChoices
;
214 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
215 delete ((wxValidator
*)m_arrValidators
[i
]);
219 // Destroy value type class instances.
220 wxPGHashMapS2P
::iterator vt_it
;
222 // Destroy editor class instances.
223 // iterate over all the elements in the class
224 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
226 delete ((wxPGEditor
*)vt_it
->second
);
229 delete wxPGProperty
::sm_wxPG_LABEL
;
232 void wxPropertyGridInitGlobalsIfNeeded()
236 // -----------------------------------------------------------------------
238 // -----------------------------------------------------------------------
241 // wxPGCanvas acts as a graphics sub-window of the
242 // wxScrolledWindow that wxPropertyGrid is.
244 class wxPGCanvas
: public wxPanel
247 wxPGCanvas() : wxPanel()
250 virtual ~wxPGCanvas() { }
253 void OnMouseMove( wxMouseEvent
&event
)
255 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
256 pg
->OnMouseMove( event
);
259 void OnMouseClick( wxMouseEvent
&event
)
261 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
262 pg
->OnMouseClick( event
);
265 void OnMouseUp( wxMouseEvent
&event
)
267 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
268 pg
->OnMouseUp( event
);
271 void OnMouseRightClick( wxMouseEvent
&event
)
273 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
274 pg
->OnMouseRightClick( event
);
277 void OnMouseDoubleClick( wxMouseEvent
&event
)
279 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
280 pg
->OnMouseDoubleClick( event
);
283 void OnKey( wxKeyEvent
& event
)
285 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
289 void OnPaint( wxPaintEvent
& event
);
291 // Always be focussable, even with child windows
292 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
293 { wxPanel
::SetCanFocus(true); }
297 DECLARE_EVENT_TABLE()
298 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
302 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
304 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
305 EVT_MOTION(wxPGCanvas
::OnMouseMove
)
306 EVT_PAINT(wxPGCanvas
::OnPaint
)
307 EVT_LEFT_DOWN(wxPGCanvas
::OnMouseClick
)
308 EVT_LEFT_UP(wxPGCanvas
::OnMouseUp
)
309 EVT_RIGHT_UP(wxPGCanvas
::OnMouseRightClick
)
310 EVT_LEFT_DCLICK(wxPGCanvas
::OnMouseDoubleClick
)
311 EVT_KEY_DOWN(wxPGCanvas
::OnKey
)
315 void wxPGCanvas
::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
322 // Don't paint after destruction has begun
323 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
326 // Update everything inside the box
327 wxRect r
= GetUpdateRegion().GetBox();
329 // FIXME: This is just a workaround for a bug that causes splitters not
330 // to paint when other windows are being dragged over the grid.
331 wxRect fullRect
= GetRect();
333 r
.width
= fullRect
.width
;
335 // Repaint this rectangle
336 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
338 // We assume that the size set when grid is shown
339 // is what is desired.
340 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
343 // -----------------------------------------------------------------------
345 // -----------------------------------------------------------------------
347 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
349 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
350 EVT_IDLE(wxPropertyGrid
::OnIdle
)
351 EVT_MOTION(wxPropertyGrid
::OnMouseMoveBottom
)
352 EVT_PAINT(wxPropertyGrid
::OnPaint
)
353 EVT_SIZE(wxPropertyGrid
::OnResize
)
354 EVT_ENTER_WINDOW(wxPropertyGrid
::OnMouseEntry
)
355 EVT_LEAVE_WINDOW(wxPropertyGrid
::OnMouseEntry
)
356 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid
::OnCaptureChange
)
357 EVT_SCROLLWIN(wxPropertyGrid
::OnScrollEvent
)
358 EVT_CHILD_FOCUS(wxPropertyGrid
::OnChildFocusEvent
)
359 EVT_SET_FOCUS(wxPropertyGrid
::OnFocusEvent
)
360 EVT_KILL_FOCUS(wxPropertyGrid
::OnFocusEvent
)
361 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid
::OnSysColourChanged
)
365 // -----------------------------------------------------------------------
367 wxPropertyGrid
::wxPropertyGrid()
373 // -----------------------------------------------------------------------
375 wxPropertyGrid
::wxPropertyGrid( wxWindow
*parent
,
380 const wxString
& name
)
384 Create(parent
,id
,pos
,size
,style
,name
);
387 // -----------------------------------------------------------------------
389 bool wxPropertyGrid
::Create( wxWindow
*parent
,
394 const wxString
& name
)
397 if ( !(style
&wxBORDER_MASK
) )
398 style
|= wxSIMPLE_BORDER
;
402 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
403 style
&= ~(wxTAB_TRAVERSAL
);
404 style
|= wxWANTS_CHARS
;
406 wxScrolledWindow
::Create(parent
,id
,pos
,size
,style
,name
);
413 // -----------------------------------------------------------------------
416 // Initialize values to defaults
418 void wxPropertyGrid
::Init1()
420 // Register editor classes, if necessary.
421 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
422 wxPropertyGrid
::RegisterDefaultEditors();
426 m_wndEditor
= m_wndEditor2
= NULL
;
430 m_labelEditor
= NULL
;
431 m_labelEditorProperty
= NULL
;
432 m_eventObject
= this;
434 m_processedEvent
= NULL
;
435 m_sortFunction
= NULL
;
436 m_inDoPropertyChanged
= 0;
437 m_inCommitChangesFromEditor
= 0;
438 m_inDoSelectProperty
= 0;
439 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
445 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
446 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
447 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
448 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
449 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
450 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
451 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
452 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
453 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
455 m_coloursCustomized
= 0;
460 #if wxPG_DOUBLE_BUFFER
461 m_doubleBuffer
= NULL
;
464 #ifndef wxPG_ICON_WIDTH
470 m_iconWidth
= wxPG_ICON_WIDTH
;
475 m_gutterWidth
= wxPG_GUTTER_MIN
;
476 m_subgroup_extramargin
= 10;
480 m_width
= m_height
= 0;
482 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
485 m_chgInfo_changedProperty
= NULL
;
488 // -----------------------------------------------------------------------
491 // Initialize after parent etc. set
493 void wxPropertyGrid
::Init2()
495 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
498 // Smaller controls on Mac
499 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
502 // Now create state, if one didn't exist already
503 // (wxPropertyGridManager might have created it for us).
506 m_pState
= CreateState();
507 m_pState
->m_pPropGrid
= this;
508 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
511 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
512 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
514 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
516 m_pState
->InitNonCatMode();
518 m_pState
->m_properties
= m_pState
->m_abcArray
;
521 GetClientSize(&m_width
,&m_height
);
523 #ifndef wxPG_ICON_WIDTH
524 // create two bitmap nodes for drawing
525 m_expandbmp
= new wxBitmap(expand_xpm
);
526 m_collbmp
= new wxBitmap(collapse_xpm
);
528 // calculate average font height for bitmap centering
530 m_iconWidth
= m_expandbmp
->GetWidth();
531 m_iconHeight
= m_expandbmp
->GetHeight();
534 m_curcursor
= wxCURSOR_ARROW
;
535 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
537 // adjust bitmap icon y position so they are centered
538 m_vspacing
= wxPG_DEFAULT_VSPACING
;
540 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
542 // Allocate cell datas indirectly by calling setter
543 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
544 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
548 // This helps with flicker
549 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
551 // Hook the top-level parent
556 // set virtual size to this window size
557 wxSize wndsize
= GetSize();
558 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
560 m_timeCreated
= ::wxGetLocalTimeMillis();
562 m_canvas
= new wxPGCanvas();
563 m_canvas
->Create(this, wxID_ANY
, wxPoint(0, 0), GetClientSize(),
564 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
565 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
567 m_iFlags
|= wxPG_FL_INITIALIZED
;
569 m_ncWidth
= wndsize
.GetWidth();
571 // Need to call OnResize handler or size given in constructor/Create
573 wxSizeEvent
sizeEvent(wndsize
,0);
577 // -----------------------------------------------------------------------
579 wxPropertyGrid
::~wxPropertyGrid()
583 if ( m_processedEvent
)
585 // All right... we are being deleted while wxPropertyGrid event
586 // is being sent. Make sure that event propagates as little
587 // as possible (although usually this is not enough to prevent
589 m_processedEvent
->Skip(false);
590 m_processedEvent
->StopPropagation();
592 // Let's use wxMessageBox to make the message appear more
593 // reliably (and *before* the crash can happend).
594 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
595 "generated by it. This usually leads to a crash "
596 "so it is recommended to destroy the control "
597 "at idle time instead.");
600 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
602 // This should do prevent things from going too badly wrong
603 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
605 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
606 m_canvas
->ReleaseMouse();
608 // Call with NULL to disconnect event handling
609 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
613 wxASSERT_MSG( !IsEditorsValueModified(),
614 wxS("Most recent change in property editor was ")
615 wxS("lost!!! (if you don't want this to happen, ")
616 wxS("close your frames and dialogs using ")
617 wxS("Close(false).)") );
620 #if wxPG_DOUBLE_BUFFER
621 if ( m_doubleBuffer
)
622 delete m_doubleBuffer
;
625 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
628 delete m_cursorSizeWE
;
630 #ifndef wxPG_ICON_WIDTH
635 // Delete common value records
636 for ( i
=0; i
<m_commonValues
.size(); i
++ )
638 delete GetCommonValue(i
);
642 // -----------------------------------------------------------------------
644 bool wxPropertyGrid
::Destroy()
646 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
647 m_canvas
->ReleaseMouse();
649 return wxScrolledWindow
::Destroy();
652 // -----------------------------------------------------------------------
654 wxPropertyGridPageState
* wxPropertyGrid
::CreateState() const
656 return new wxPropertyGridPageState();
659 // -----------------------------------------------------------------------
660 // wxPropertyGrid overridden wxWindow methods
661 // -----------------------------------------------------------------------
663 void wxPropertyGrid
::SetWindowStyleFlag( long style
)
665 long old_style
= m_windowStyle
;
667 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
669 wxASSERT( m_pState
);
671 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
674 EnableCategories( true );
676 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
678 // Disable categories
679 EnableCategories( false );
681 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
687 PrepareAfterItemsAdded();
689 m_pState
->m_itemsAdded
= 1;
691 #if wxPG_SUPPORT_TOOLTIPS
692 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
698 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
699 SetToolTip ( tooltip );
700 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
703 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
708 m_canvas
->SetToolTip( NULL
);
713 wxScrolledWindow
::SetWindowStyleFlag ( style
);
715 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
717 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
719 CalculateFontAndBitmapStuff( m_vspacing
);
725 // -----------------------------------------------------------------------
727 void wxPropertyGrid
::Freeze()
731 wxScrolledWindow
::Freeze();
736 // -----------------------------------------------------------------------
738 void wxPropertyGrid
::Thaw()
744 wxScrolledWindow
::Thaw();
745 RecalculateVirtualSize();
746 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
750 // Force property re-selection
751 // NB: We must copy the selection.
752 wxArrayPGProperty selection
= m_pState
->m_selection
;
753 DoSetSelection(selection
, wxPG_SEL_FORCE
);
757 // -----------------------------------------------------------------------
759 bool wxPropertyGrid
::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
761 wxCHECK( prop
, false );
763 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
764 return DoSelectProperty(prop
, selFlags
);
766 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
768 if ( !selection
.size() )
770 return DoSelectProperty(prop
, selFlags
);
774 // For categories, only one can be selected at a time
775 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
778 selection
.push_back(prop
);
780 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
782 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
791 // -----------------------------------------------------------------------
793 bool wxPropertyGrid
::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
795 wxCHECK( prop
, false );
798 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
799 if ( selection
.size() <= 1 )
801 res
= DoSelectProperty(NULL
, selFlags
);
805 m_pState
->DoRemoveFromSelection(prop
);
813 // -----------------------------------------------------------------------
815 bool wxPropertyGrid
::DoSelectAndEdit( wxPGProperty
* prop
,
816 unsigned int colIndex
,
817 unsigned int selFlags
)
820 // NB: Enable following if label editor background colour is
821 // ever changed to any other than m_colSelBack.
823 // We use this workaround to prevent visible flicker when editing
824 // a cell. Atleast on wxMSW, there is a difficult to find
825 // (and perhaps prevent) redraw somewhere between making property
826 // selected and enabling label editing.
828 //wxColour prevColSelBack = m_colSelBack;
829 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
835 res
= DoSelectProperty(prop
, selFlags
);
840 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
842 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
844 res
= DoAddToSelection(prop
, selFlags
);
848 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
850 DoBeginLabelEdit(colIndex
, selFlags
);
854 //m_colSelBack = prevColSelBack;
858 // -----------------------------------------------------------------------
860 bool wxPropertyGrid
::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
861 unsigned int colIndex
,
862 wxMouseEvent
* mouseEvent
,
865 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
867 bool addToExistingSelection
;
869 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
873 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
874 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
876 // Allow right-click for context menu without
877 // disturbing the selection.
878 if ( GetSelectedProperties().size() <= 1 ||
880 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
885 addToExistingSelection
= mouseEvent
->ShiftDown();
890 addToExistingSelection
= false;
895 addToExistingSelection
= false;
898 if ( addToExistingSelection
)
900 if ( !alreadySelected
)
902 res
= DoAddToSelection(prop
, selFlags
);
904 else if ( GetSelectedProperties().size() > 1 )
906 res
= DoRemoveFromSelection(prop
, selFlags
);
911 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
917 // -----------------------------------------------------------------------
919 void wxPropertyGrid
::DoSetSelection( const wxArrayPGProperty
& newSelection
,
922 if ( newSelection
.size() > 0 )
924 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
929 DoClearSelection(false, selFlags
);
932 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
934 DoAddToSelection(newSelection
[i
], selFlags
);
940 // -----------------------------------------------------------------------
942 void wxPropertyGrid
::MakeColumnEditable( unsigned int column
,
945 wxASSERT( column
!= 1 );
947 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
951 cols
.push_back(column
);
955 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
957 if ( cols
[i
] == (int)column
)
958 cols
.erase( cols
.begin() + i
);
963 // -----------------------------------------------------------------------
965 void wxPropertyGrid
::DoBeginLabelEdit( unsigned int colIndex
,
968 wxPGProperty
* selected
= GetSelection();
969 wxCHECK_RET(selected
, wxT("No property selected"));
970 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
972 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
974 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
981 const wxPGCell
* cell
= NULL
;
982 if ( selected
->HasCell(colIndex
) )
984 cell
= &selected
->GetCell(colIndex
);
985 if ( !cell
->HasText() && colIndex
== 0 )
986 text
= selected
->GetLabel();
992 text
= selected
->GetLabel();
994 cell
= &selected
->GetOrCreateCell(colIndex
);
997 if ( cell
&& cell
->HasText() )
998 text
= cell
->GetText();
1000 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
1002 m_selColumn
= colIndex
;
1004 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
1006 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
1014 wxWindowID id
= tc
->GetId();
1015 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1016 wxCommandEventHandler(wxPropertyGrid
::OnLabelEditorEnterPress
),
1018 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1019 wxKeyEventHandler(wxPropertyGrid
::OnLabelEditorKeyPress
),
1024 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1025 m_labelEditorProperty
= selected
;
1028 // -----------------------------------------------------------------------
1031 wxPropertyGrid
::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1033 DoEndLabelEdit(true);
1036 // -----------------------------------------------------------------------
1038 void wxPropertyGrid
::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1040 int keycode
= event
.GetKeyCode();
1042 if ( keycode
== WXK_ESCAPE
)
1044 DoEndLabelEdit(false);
1052 // -----------------------------------------------------------------------
1054 void wxPropertyGrid
::DoEndLabelEdit( bool commit
, int selFlags
)
1056 if ( !m_labelEditor
)
1059 wxPGProperty
* prop
= m_labelEditorProperty
;
1064 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1066 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1067 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1068 prop
, NULL
, selFlags
,
1073 wxString text
= m_labelEditor
->GetValue();
1074 wxPGCell
* cell
= NULL
;
1075 if ( prop
->HasCell(m_selColumn
) )
1077 cell
= &prop
->GetCell(m_selColumn
);
1081 if ( m_selColumn
== 0 )
1082 prop
->SetLabel(text
);
1084 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1088 cell
->SetText(text
);
1093 DestroyEditorWnd(m_labelEditor
);
1094 m_labelEditor
= NULL
;
1095 m_labelEditorProperty
= NULL
;
1100 // -----------------------------------------------------------------------
1102 void wxPropertyGrid
::SetExtraStyle( long exStyle
)
1104 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1105 OnTLPChanging(::wxGetTopLevelParent(this));
1107 OnTLPChanging(NULL
);
1109 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1111 #if defined(__WXMSW__)
1114 // Don't use WS_EX_COMPOSITED just now.
1117 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1118 hWnd = (HWND)GetParent()->GetHWND();
1120 hWnd = (HWND)GetHWND();
1122 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1123 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1126 //#elif defined(__WXGTK20__)
1128 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1129 // truly was double-buffered.
1130 if ( !this->IsDoubleBuffered() )
1132 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1136 #if wxPG_DOUBLE_BUFFER
1137 delete m_doubleBuffer
;
1138 m_doubleBuffer
= NULL
;
1143 wxScrolledWindow
::SetExtraStyle( exStyle
);
1145 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1146 m_pState
->InitNonCatMode();
1148 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1149 m_windowStyle
|= wxPG_TOOLTIPS
;
1152 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1155 // -----------------------------------------------------------------------
1157 // returns the best acceptable minimal size
1158 wxSize wxPropertyGrid
::DoGetBestSize() const
1160 int lineHeight
= wxMax(15, m_lineHeight
);
1162 // don't make the grid too tall (limit height to 10 items) but don't
1163 // make it too small neither
1164 int numLines
= wxMin
1166 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1170 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1171 int width
= m_marginWidth
;
1172 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1174 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1177 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1183 // -----------------------------------------------------------------------
1185 void wxPropertyGrid
::OnTLPChanging( wxWindow
* newTLP
)
1187 if ( newTLP
== m_tlp
)
1190 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1193 // Parent changed so let's redetermine and re-hook the
1194 // correct top-level window.
1197 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1198 wxCloseEventHandler(wxPropertyGrid
::OnTLPClose
),
1200 m_tlpClosed
= m_tlp
;
1201 m_tlpClosedTime
= currentTime
;
1206 // Only accept new tlp if same one was not just dismissed.
1207 if ( newTLP
!= m_tlpClosed
||
1208 m_tlpClosedTime
+250 < currentTime
)
1210 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1211 wxCloseEventHandler(wxPropertyGrid
::OnTLPClose
),
1224 // -----------------------------------------------------------------------
1226 void wxPropertyGrid
::OnTLPClose( wxCloseEvent
& event
)
1228 // ClearSelection forces value validation/commit.
1229 if ( event
.CanVeto() && !DoClearSelection() )
1235 // Ok, it can close, set tlp pointer to NULL. Some other event
1236 // handler can of course veto the close, but our OnIdle() should
1237 // then be able to regain the tlp pointer.
1238 OnTLPChanging(NULL
);
1243 // -----------------------------------------------------------------------
1245 bool wxPropertyGrid
::Reparent( wxWindowBase
*newParent
)
1247 OnTLPChanging((wxWindow
*)newParent
);
1249 bool res
= wxScrolledWindow
::Reparent(newParent
);
1254 // -----------------------------------------------------------------------
1255 // wxPropertyGrid Font and Colour Methods
1256 // -----------------------------------------------------------------------
1258 void wxPropertyGrid
::CalculateFontAndBitmapStuff( int vspacing
)
1262 m_captionFont
= wxScrolledWindow
::GetFont();
1264 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1265 m_subgroup_extramargin
= x
+ (x
/2);
1268 #if wxPG_USE_RENDERER_NATIVE
1269 m_iconWidth
= wxPG_ICON_WIDTH
;
1270 #elif wxPG_ICON_WIDTH
1272 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1273 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1274 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1278 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1279 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1280 m_gutterWidth
= wxPG_GUTTER_MIN
;
1283 if ( vspacing
<= 1 ) vdiv
= 12;
1284 else if ( vspacing
>= 3 ) vdiv
= 3;
1286 m_spacingy
= m_fontHeight
/ vdiv
;
1287 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1288 m_spacingy
= wxPG_YSPACING_MIN
;
1291 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1292 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1294 m_captionFont
.SetWeight(wxBOLD
);
1295 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1297 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1300 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1301 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1304 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1306 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1307 RecalculateVirtualSize();
1309 InvalidateBestSize();
1312 // -----------------------------------------------------------------------
1314 void wxPropertyGrid
::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1320 // -----------------------------------------------------------------------
1322 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1323 int ga
= 1000, int ba
= 1000,
1324 bool forceDifferent
= false)
1331 // Recursion guard (allow 2 max)
1332 static int isinside
= 0;
1334 wxCHECK_MSG( isinside
< 3,
1336 wxT("wxPGAdjustColour should not be recursively called more than once") );
1341 int g
= src
.Green();
1344 if ( r2
>255 ) r2
= 255;
1345 else if ( r2
<0) r2
= 0;
1347 if ( g2
>255 ) g2
= 255;
1348 else if ( g2
<0) g2
= 0;
1350 if ( b2
>255 ) b2
= 255;
1351 else if ( b2
<0) b2
= 0;
1353 // Make sure they are somewhat different
1354 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1355 dst
= wxPGAdjustColour(src
,-(ra
*2));
1357 dst
= wxColour(r2
,g2
,b2
);
1359 // Recursion guard (allow 2 max)
1366 static int wxPGGetColAvg( const wxColour
& col
)
1368 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1372 void wxPropertyGrid
::RegainColours()
1374 if ( !(m_coloursCustomized
& 0x0002) )
1376 wxColour col
= wxSystemSettings
::GetColour( wxSYS_COLOUR_BTNFACE
);
1378 // Make sure colour is dark enough
1380 int colDec
= wxPGGetColAvg(col
) - 230;
1382 int colDec
= wxPGGetColAvg(col
) - 200;
1385 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1388 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1391 if ( !(m_coloursCustomized
& 0x0001) )
1392 m_colMargin
= m_colCapBack
;
1394 if ( !(m_coloursCustomized
& 0x0004) )
1401 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1402 m_colCapFore
= capForeCol
;
1403 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1406 if ( !(m_coloursCustomized
& 0x0008) )
1408 wxColour bgCol
= wxSystemSettings
::GetColour( wxSYS_COLOUR_WINDOW
);
1409 m_colPropBack
= bgCol
;
1410 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1413 if ( !(m_coloursCustomized
& 0x0010) )
1415 wxColour fgCol
= wxSystemSettings
::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1416 m_colPropFore
= fgCol
;
1417 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1420 if ( !(m_coloursCustomized
& 0x0020) )
1421 m_colSelBack
= wxSystemSettings
::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1423 if ( !(m_coloursCustomized
& 0x0040) )
1424 m_colSelFore
= wxSystemSettings
::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1426 if ( !(m_coloursCustomized
& 0x0080) )
1427 m_colLine
= m_colCapBack
;
1429 if ( !(m_coloursCustomized
& 0x0100) )
1430 m_colDisPropFore
= m_colCapFore
;
1432 m_colEmptySpace
= wxSystemSettings
::GetColour( wxSYS_COLOUR_WINDOW
);
1435 // -----------------------------------------------------------------------
1437 void wxPropertyGrid
::ResetColours()
1439 m_coloursCustomized
= 0;
1446 // -----------------------------------------------------------------------
1448 bool wxPropertyGrid
::SetFont( const wxFont
& font
)
1450 // Must disable active editor.
1453 bool res
= wxScrolledWindow
::SetFont( font
);
1454 if ( res
&& GetParent()) // may not have been Create()ed yet
1456 CalculateFontAndBitmapStuff( m_vspacing
);
1463 // -----------------------------------------------------------------------
1465 void wxPropertyGrid
::SetLineColour( const wxColour
& col
)
1468 m_coloursCustomized
|= 0x80;
1472 // -----------------------------------------------------------------------
1474 void wxPropertyGrid
::SetMarginColour( const wxColour
& col
)
1477 m_coloursCustomized
|= 0x01;
1481 // -----------------------------------------------------------------------
1483 void wxPropertyGrid
::SetCellBackgroundColour( const wxColour
& col
)
1485 m_colPropBack
= col
;
1486 m_coloursCustomized
|= 0x08;
1488 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1493 // -----------------------------------------------------------------------
1495 void wxPropertyGrid
::SetCellTextColour( const wxColour
& col
)
1497 m_colPropFore
= col
;
1498 m_coloursCustomized
|= 0x10;
1500 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1505 // -----------------------------------------------------------------------
1507 void wxPropertyGrid
::SetEmptySpaceColour( const wxColour
& col
)
1509 m_colEmptySpace
= col
;
1514 // -----------------------------------------------------------------------
1516 void wxPropertyGrid
::SetCellDisabledTextColour( const wxColour
& col
)
1518 m_colDisPropFore
= col
;
1519 m_coloursCustomized
|= 0x100;
1523 // -----------------------------------------------------------------------
1525 void wxPropertyGrid
::SetSelectionBackgroundColour( const wxColour
& col
)
1528 m_coloursCustomized
|= 0x20;
1532 // -----------------------------------------------------------------------
1534 void wxPropertyGrid
::SetSelectionTextColour( const wxColour
& col
)
1537 m_coloursCustomized
|= 0x40;
1541 // -----------------------------------------------------------------------
1543 void wxPropertyGrid
::SetCaptionBackgroundColour( const wxColour
& col
)
1546 m_coloursCustomized
|= 0x02;
1548 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1553 // -----------------------------------------------------------------------
1555 void wxPropertyGrid
::SetCaptionTextColour( const wxColour
& col
)
1558 m_coloursCustomized
|= 0x04;
1560 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1565 // -----------------------------------------------------------------------
1566 // wxPropertyGrid property adding and removal
1567 // -----------------------------------------------------------------------
1569 void wxPropertyGrid
::PrepareAfterItemsAdded()
1571 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1573 m_pState
->m_itemsAdded
= 0;
1575 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1576 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1578 RecalculateVirtualSize();
1581 // -----------------------------------------------------------------------
1582 // wxPropertyGrid property operations
1583 // -----------------------------------------------------------------------
1585 bool wxPropertyGrid
::EnsureVisible( wxPGPropArg id
)
1587 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1591 bool changed
= false;
1593 // Is it inside collapsed section?
1594 if ( !p
->IsVisible() )
1597 wxPGProperty
* parent
= p
->GetParent();
1598 wxPGProperty
* grandparent
= parent
->GetParent();
1600 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1601 Expand( grandparent
);
1609 GetViewStart(&vx
,&vy
);
1610 vy
*=wxPG_PIXELS_PER_UNIT
;
1616 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1617 m_iFlags
|= wxPG_FL_SCROLLED
;
1620 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1622 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1623 m_iFlags
|= wxPG_FL_SCROLLED
;
1633 // -----------------------------------------------------------------------
1634 // wxPropertyGrid helper methods called by properties
1635 // -----------------------------------------------------------------------
1637 // Control font changer helper.
1638 void wxPropertyGrid
::SetCurControlBoldFont()
1640 wxASSERT( m_wndEditor
);
1641 m_wndEditor
->SetFont( m_captionFont
);
1644 // -----------------------------------------------------------------------
1646 wxPoint wxPropertyGrid
::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1649 #if wxPG_SMALL_SCREEN
1650 // On small-screen devices, always show dialogs with default position and size.
1651 return wxDefaultPosition
;
1653 int splitterX
= GetSplitterPosition();
1657 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1659 ImprovedClientToScreen( &x
, &y
);
1661 int sw
= wxSystemSettings
::GetMetric( ::wxSYS_SCREEN_X
);
1662 int sh
= wxSystemSettings
::GetMetric( ::wxSYS_SCREEN_Y
);
1669 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1679 new_y
= y
+ m_lineHeight
;
1681 return wxPoint(new_x
,new_y
);
1685 // -----------------------------------------------------------------------
1687 wxString
& wxPropertyGrid
::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1689 if ( src_str
.length() == 0 )
1695 bool prev_is_slash
= false;
1697 wxString
::const_iterator i
= src_str
.begin();
1701 for ( ; i
!= src_str
.end(); ++i
)
1705 if ( a
!= wxS('\\') )
1707 if ( !prev_is_slash
)
1713 if ( a
== wxS('n') )
1716 dst_str
<< wxS('\n');
1718 dst_str
<< wxS('\n');
1721 else if ( a
== wxS('t') )
1722 dst_str
<< wxS('\t');
1726 prev_is_slash
= false;
1730 if ( prev_is_slash
)
1732 dst_str
<< wxS('\\');
1733 prev_is_slash
= false;
1737 prev_is_slash
= true;
1744 // -----------------------------------------------------------------------
1746 wxString
& wxPropertyGrid
::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1748 if ( src_str
.length() == 0 )
1754 wxString
::const_iterator i
= src_str
.begin();
1755 wxUniChar prev_a
= wxS('\0');
1759 for ( ; i
!= src_str
.end(); ++i
)
1763 if ( a
>= wxS(' ') )
1765 // This surely is not something that requires an escape sequence.
1770 // This might need...
1771 if ( a
== wxS('\r') )
1773 // DOS style line end.
1774 // Already taken care below
1776 else if ( a
== wxS('\n') )
1777 // UNIX style line end.
1778 dst_str
<< wxS("\\n");
1779 else if ( a
== wxS('\t') )
1781 dst_str
<< wxS('\t');
1784 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1794 // -----------------------------------------------------------------------
1796 wxPGProperty
* wxPropertyGrid
::DoGetItemAtY( int y
) const
1803 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1806 // -----------------------------------------------------------------------
1807 // wxPropertyGrid graphics related methods
1808 // -----------------------------------------------------------------------
1810 void wxPropertyGrid
::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1814 // Update everything inside the box
1815 wxRect r
= GetUpdateRegion().GetBox();
1817 dc
.SetPen(m_colEmptySpace
);
1818 dc
.SetBrush(m_colEmptySpace
);
1819 dc
.DrawRectangle(r
);
1822 // -----------------------------------------------------------------------
1824 void wxPropertyGrid
::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1825 wxPGProperty
* property
) const
1827 // Prepare rectangle to be used
1829 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1830 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1832 #if (wxPG_USE_RENDERER_NATIVE)
1834 #elif wxPG_ICON_WIDTH
1835 // Drawing expand/collapse button manually
1836 dc
.SetPen(m_colPropFore
);
1837 if ( property
->IsCategory() )
1838 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1840 dc
.SetBrush(m_colPropBack
);
1842 dc
.DrawRectangle( r
);
1843 int _y
= r
.y
+(m_iconWidth
/2);
1844 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1849 if ( property
->IsExpanded() )
1851 // wxRenderer functions are non-mutating in nature, so it
1852 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1853 // Hopefully this does not cause problems.
1854 #if (wxPG_USE_RENDERER_NATIVE)
1855 wxRendererNative
::Get().DrawTreeItemButton(
1861 #elif wxPG_ICON_WIDTH
1870 #if (wxPG_USE_RENDERER_NATIVE)
1871 wxRendererNative
::Get().DrawTreeItemButton(
1877 #elif wxPG_ICON_WIDTH
1878 int _x
= r
.x
+(m_iconWidth
/2);
1879 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1885 #if (wxPG_USE_RENDERER_NATIVE)
1887 #elif wxPG_ICON_WIDTH
1890 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1894 // -----------------------------------------------------------------------
1897 // This is the one called by OnPaint event handler and others.
1898 // topy and bottomy are already unscrolled (ie. physical)
1900 void wxPropertyGrid
::DrawItems( wxDC
& dc
,
1902 unsigned int bottomy
,
1903 const wxRect
* clipRect
)
1905 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1907 m_pState
->EnsureVirtualHeight();
1909 wxRect tempClipRect
;
1912 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1913 clipRect
= &tempClipRect
;
1916 // items added check
1917 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1919 int paintFinishY
= 0;
1921 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1924 bool isBuffered
= false;
1926 #if wxPG_DOUBLE_BUFFER
1927 wxMemoryDC
* bufferDC
= NULL
;
1929 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1931 if ( !m_doubleBuffer
)
1933 paintFinishY
= clipRect
->y
;
1938 bufferDC
= new wxMemoryDC();
1940 // If nothing was changed, then just copy from double-buffer
1941 bufferDC
->SelectObject( *m_doubleBuffer
);
1951 dc
.SetClippingRegion( *clipRect
);
1952 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1955 #if wxPG_DOUBLE_BUFFER
1958 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1959 bufferDC
, 0, 0, wxCOPY
);
1960 dc
.DestroyClippingRegion(); // Is this really necessary?
1966 // Clear area beyond bottomY?
1967 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1969 dc
.SetPen(m_colEmptySpace
);
1970 dc
.SetBrush(m_colEmptySpace
);
1971 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1975 // -----------------------------------------------------------------------
1977 int wxPropertyGrid
::DoDrawItems( wxDC
& dc
,
1978 const wxRect
* clipRect
,
1979 bool isBuffered
) const
1981 const wxPGProperty
* firstItem
;
1982 const wxPGProperty
* lastItem
;
1984 firstItem
= DoGetItemAtY(clipRect
->y
);
1985 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1988 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1990 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1993 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1994 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1996 int lh
= m_lineHeight
;
1999 int lastItemBottomY
;
2001 firstItemTopY
= clipRect
->y
;
2002 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
2004 // Align y coordinates to item boundaries
2005 firstItemTopY
-= firstItemTopY
% lh
;
2006 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2007 lastItemBottomY
-= 1;
2009 // Entire range outside scrolled, visible area?
2010 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
2013 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
2017 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
2018 firstItem->GetLabel().c_str(),
2019 lastItem->GetLabel().c_str(),
2020 (int)(lastItemBottomY - firstItemTopY),
2022 (unsigned long)clipRect );
2027 long windowStyle
= m_windowStyle
;
2033 // With wxPG_DOUBLE_BUFFER, do double buffering
2034 // - buffer's y = 0, so align cliprect and coordinates to that
2036 #if wxPG_DOUBLE_BUFFER
2042 xRelMod
= clipRect
->x
;
2043 yRelMod
= clipRect
->y
;
2046 // clipRect conversion
2051 firstItemTopY
-= yRelMod
;
2052 lastItemBottomY
-= yRelMod
;
2055 wxUnusedVar(isBuffered
);
2058 int x
= m_marginWidth
- xRelMod
;
2060 wxFont normalFont
= GetFont();
2062 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2064 bool isPgEnabled
= IsEnabled();
2067 // Prepare some pens and brushes that are often changed to.
2070 wxBrush
marginBrush(m_colMargin
);
2071 wxPen
marginPen(m_colMargin
);
2072 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2073 wxPen
linepen(m_colLine
,1,wxSOLID
);
2075 wxColour selBackCol
;
2077 selBackCol
= m_colSelBack
;
2079 selBackCol
= m_colMargin
;
2081 // pen that has same colour as text
2082 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2085 // Clear margin with background colour
2087 dc
.SetBrush( marginBrush
);
2088 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2090 dc
.SetPen( *wxTRANSPARENT_PEN
);
2091 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2094 const wxPGProperty
* firstSelected
= GetSelection();
2095 const wxPropertyGridPageState
* state
= m_pState
;
2097 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2098 bool wasSelectedPainted
= false;
2101 // TODO: Only render columns that are within clipping region.
2103 dc
.SetFont(normalFont
);
2105 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2106 int endScanBottomY
= lastItemBottomY
+ lh
;
2107 int y
= firstItemTopY
;
2110 // Pregenerate list of visible properties.
2111 wxArrayPGProperty visPropArray
;
2112 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2114 for ( ; !it
.AtEnd(); it
.Next() )
2116 const wxPGProperty
* p
= *it
;
2118 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2120 visPropArray
.push_back((wxPGProperty
*)p
);
2122 if ( y
> endScanBottomY
)
2129 visPropArray
.push_back(NULL
);
2131 wxPGProperty
* nextP
= visPropArray
[0];
2133 int gridWidth
= state
->m_width
;
2136 for ( unsigned int arrInd
=1;
2137 nextP
&& y
<= lastItemBottomY
;
2140 wxPGProperty
* p
= nextP
;
2141 nextP
= visPropArray
[arrInd
];
2143 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2144 int textMarginHere
= x
;
2145 int renderFlags
= 0;
2147 int greyDepth
= m_marginWidth
;
2148 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2149 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2151 int greyDepthX
= greyDepth
- xRelMod
;
2153 // Use basic depth if in non-categoric mode and parent is base array.
2154 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2156 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2159 // Paint margin area
2160 dc
.SetBrush(marginBrush
);
2161 dc
.SetPen(marginPen
);
2162 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2164 dc
.SetPen( linepen
);
2169 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2175 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2177 sx
+= state
->m_colWidths
[si
];
2178 dc
.DrawLine( sx
, y
, sx
, y2
);
2181 // Horizontal Line, below
2182 // (not if both this and next is category caption)
2183 if ( p
->IsCategory() &&
2184 nextP
&& nextP
->IsCategory() )
2185 dc
.SetPen(m_colCapBack
);
2187 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2190 // Need to override row colours?
2194 bool isSelected
= state
->DoIsPropertySelected(p
);
2198 // Disabled may get different colour.
2199 if ( !p
->IsEnabled() )
2201 renderFlags
|= wxPGCellRenderer
::Disabled
|
2202 wxPGCellRenderer
::DontUseCellFgCol
;
2203 rowFgCol
= m_colDisPropFore
;
2208 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2209 if ( p
== firstSelected
)
2210 wasSelectedPainted
= true;
2213 renderFlags
|= wxPGCellRenderer
::Selected
;
2215 if ( !p
->IsCategory() )
2217 renderFlags
|= wxPGCellRenderer
::DontUseCellFgCol
|
2218 wxPGCellRenderer
::DontUseCellBgCol
;
2220 if ( reallyFocused
&& p
== firstSelected
)
2222 rowFgCol
= m_colSelFore
;
2223 rowBgCol
= selBackCol
;
2225 else if ( isPgEnabled
)
2227 rowFgCol
= m_colPropFore
;
2228 if ( p
== firstSelected
)
2229 rowBgCol
= m_colMargin
;
2231 rowBgCol
= selBackCol
;
2235 rowFgCol
= m_colDisPropFore
;
2236 rowBgCol
= selBackCol
;
2243 if ( rowBgCol
.IsOk() )
2244 rowBgBrush
= wxBrush(rowBgCol
);
2246 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2247 renderFlags
= renderFlags
& ~wxPGCellRenderer
::DontUseCellColours
;
2250 // Fill additional margin area with background colour of first cell
2251 if ( greyDepthX
< textMarginHere
)
2253 if ( !(renderFlags
& wxPGCellRenderer
::DontUseCellBgCol
) )
2255 wxPGCell
& cell
= p
->GetCell(0);
2256 rowBgCol
= cell
.GetBgCol();
2257 rowBgBrush
= wxBrush(rowBgCol
);
2259 dc
.SetBrush(rowBgBrush
);
2260 dc
.SetPen(rowBgCol
);
2261 dc
.DrawRectangle(greyDepthX
+1, y
,
2262 textMarginHere
-greyDepthX
, lh
-1);
2265 bool fontChanged
= false;
2267 // Expander button rectangle
2268 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2273 if ( p
->IsCategory() )
2275 // Captions have their cell areas merged as one
2276 dc
.SetFont(m_captionFont
);
2278 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2280 if ( renderFlags
& wxPGCellRenderer
::DontUseCellBgCol
)
2282 dc
.SetBrush(rowBgBrush
);
2283 dc
.SetPen(rowBgCol
);
2286 if ( renderFlags
& wxPGCellRenderer
::DontUseCellFgCol
)
2288 dc
.SetTextForeground(rowFgCol
);
2291 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2292 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2295 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2296 DrawExpanderButton( dc
, butRect
, p
);
2300 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2302 dc
.SetFont(m_captionFont
);
2308 int nextCellWidth
= state
->m_colWidths
[0] -
2309 (greyDepthX
- m_marginWidth
);
2310 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2311 int textXAdd
= textMarginHere
- greyDepthX
;
2313 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2315 cellRect
.width
= nextCellWidth
- 1;
2317 wxWindow
* cellEditor
= NULL
;
2318 int cellRenderFlags
= renderFlags
;
2320 // Tree Item Button (must be drawn before clipping is set up)
2321 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2322 DrawExpanderButton( dc
, butRect
, p
);
2325 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2327 if ( p
== firstSelected
)
2329 if ( ci
== 1 && m_wndEditor
)
2330 cellEditor
= m_wndEditor
;
2331 else if ( ci
== m_selColumn
&& m_labelEditor
)
2332 cellEditor
= m_labelEditor
;
2337 wxColour editorBgCol
=
2338 cellEditor
->GetBackgroundColour();
2339 dc
.SetBrush(editorBgCol
);
2340 dc
.SetPen(editorBgCol
);
2341 dc
.SetTextForeground(m_colPropFore
);
2342 dc
.DrawRectangle(cellRect
);
2344 if ( m_dragStatus
!= 0 ||
2345 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2350 dc
.SetBrush(m_colPropBack
);
2351 dc
.SetPen(m_colPropBack
);
2352 dc
.SetTextForeground(m_colDisPropFore
);
2353 if ( p
->IsEnabled() )
2354 dc
.SetTextForeground(rowFgCol
);
2356 dc
.SetTextForeground(m_colDisPropFore
);
2361 if ( renderFlags
& wxPGCellRenderer
::DontUseCellBgCol
)
2363 dc
.SetBrush(rowBgBrush
);
2364 dc
.SetPen(rowBgCol
);
2367 if ( renderFlags
& wxPGCellRenderer
::DontUseCellFgCol
)
2369 dc
.SetTextForeground(rowFgCol
);
2373 dc
.SetClippingRegion(cellRect
);
2375 cellRect
.x
+= textXAdd
;
2376 cellRect
.width
-= textXAdd
;
2381 wxPGCellRenderer
* renderer
;
2382 int cmnVal
= p
->GetCommonValue();
2383 if ( cmnVal
== -1 || ci
!= 1 )
2385 renderer
= p
->GetCellRenderer(ci
);
2386 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2391 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2392 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2397 cellX
+= state
->m_colWidths
[ci
];
2398 if ( ci
< (state
->m_colWidths
.size()-1) )
2399 nextCellWidth
= state
->m_colWidths
[ci
+1];
2401 dc
.DestroyClippingRegion(); // Is this really necessary?
2407 dc
.SetFont(normalFont
);
2412 // Refresh editor controls (seems not needed on msw)
2413 // NOTE: This code is mandatory for GTK!
2414 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2415 if ( wasSelectedPainted
)
2418 m_wndEditor
->Refresh();
2420 m_wndEditor2
->Refresh();
2427 // -----------------------------------------------------------------------
2429 wxRect wxPropertyGrid
::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2433 if ( m_width
< 10 || m_height
< 10 ||
2434 !m_pState
->m_properties
->GetChildCount() ||
2436 return wxRect(0,0,0,0);
2441 // Return rect which encloses the given property range
2443 int visTop
= p1
->GetY();
2446 visBottom
= p2
->GetY() + m_lineHeight
;
2448 visBottom
= m_height
+ visTop
;
2450 // If seleced property is inside the range, we'll extend the range to include
2452 wxPGProperty
* selected
= GetSelection();
2455 int selectedY
= selected
->GetY();
2456 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2458 wxWindow
* editor
= GetEditorControl();
2461 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2462 if ( visBottom2
> visBottom
)
2463 visBottom
= visBottom2
;
2468 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2471 // -----------------------------------------------------------------------
2473 void wxPropertyGrid
::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2478 if ( m_pState
->m_itemsAdded
)
2479 PrepareAfterItemsAdded();
2481 wxRect r
= GetPropertyRect(p1
, p2
);
2484 m_canvas
->RefreshRect(r
);
2488 // -----------------------------------------------------------------------
2490 void wxPropertyGrid
::RefreshProperty( wxPGProperty
* p
)
2492 if ( m_pState
->DoIsPropertySelected(p
) )
2494 // NB: We must copy the selection.
2495 wxArrayPGProperty selection
= m_pState
->m_selection
;
2496 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2499 DrawItemAndChildren(p
);
2502 // -----------------------------------------------------------------------
2504 void wxPropertyGrid
::DrawItemAndValueRelated( wxPGProperty
* p
)
2509 // Draw item, children, and parent too, if it is not category
2510 wxPGProperty
* parent
= p
->GetParent();
2513 !parent
->IsCategory() &&
2514 parent
->GetParent() )
2517 parent
= parent
->GetParent();
2520 DrawItemAndChildren(p
);
2523 void wxPropertyGrid
::DrawItemAndChildren( wxPGProperty
* p
)
2525 wxCHECK_RET( p
, wxT("invalid property id") );
2527 // Do not draw if in non-visible page
2528 if ( p
->GetParentState() != m_pState
)
2531 // do not draw a single item if multiple pending
2532 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2535 // Update child control.
2536 wxPGProperty
* selected
= GetSelection();
2537 if ( selected
&& selected
->GetParent() == p
)
2540 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2542 DrawItems(p
, lastDrawn
);
2545 // -----------------------------------------------------------------------
2547 void wxPropertyGrid
::Refresh( bool WXUNUSED(eraseBackground
),
2548 const wxRect
*rect
)
2550 PrepareAfterItemsAdded();
2552 wxWindow
::Refresh(false);
2554 // TODO: Coordinate translation
2555 m_canvas
->Refresh(false, rect
);
2557 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2558 // I think this really helps only GTK+1.2
2559 if ( m_wndEditor
) m_wndEditor
->Refresh();
2560 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2564 // -----------------------------------------------------------------------
2565 // wxPropertyGrid global operations
2566 // -----------------------------------------------------------------------
2568 void wxPropertyGrid
::Clear()
2570 m_pState
->DoClear();
2576 RecalculateVirtualSize();
2578 // Need to clear some area at the end
2580 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2583 // -----------------------------------------------------------------------
2585 bool wxPropertyGrid
::EnableCategories( bool enable
)
2592 // Enable categories
2595 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2600 // Disable categories
2602 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2605 if ( !m_pState
->EnableCategories(enable
) )
2610 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2612 m_pState
->m_itemsAdded
= 1; // force
2613 PrepareAfterItemsAdded();
2617 m_pState
->m_itemsAdded
= 1;
2619 // No need for RecalculateVirtualSize() here - it is already called in
2620 // wxPropertyGridPageState method above.
2627 // -----------------------------------------------------------------------
2629 void wxPropertyGrid
::SwitchState( wxPropertyGridPageState
* pNewState
)
2631 wxASSERT( pNewState
);
2632 wxASSERT( pNewState
->GetGrid() );
2634 if ( pNewState
== m_pState
)
2637 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2639 // Call ClearSelection() instead of DoClearSelection()
2640 // so that selection clear events are not sent.
2643 m_pState
->m_selection
= oldSelection
;
2645 bool orig_mode
= m_pState
->IsInNonCatMode();
2646 bool new_state_mode
= pNewState
->IsInNonCatMode();
2648 m_pState
= pNewState
;
2651 int pgWidth
= GetClientSize().x
;
2652 if ( HasVirtualWidth() )
2654 int minWidth
= pgWidth
;
2655 if ( pNewState
->m_width
< minWidth
)
2657 pNewState
->m_width
= minWidth
;
2658 pNewState
->CheckColumnWidths();
2664 // Just in case, fully re-center splitter
2665 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2666 pNewState
->m_fSplitterX
= -1.0;
2668 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2673 // If necessary, convert state to correct mode.
2674 if ( orig_mode
!= new_state_mode
)
2676 // This should refresh as well.
2677 EnableCategories( orig_mode?
false:true );
2679 else if ( !m_frozen
)
2681 // Refresh, if not frozen.
2682 m_pState
->PrepareAfterItemsAdded();
2684 // Reselect (Use SetSelection() instead of Do-variant so that
2685 // events won't be sent).
2686 SetSelection(m_pState
->m_selection
);
2688 RecalculateVirtualSize(0);
2692 m_pState
->m_itemsAdded
= 1;
2695 // -----------------------------------------------------------------------
2697 // Call to SetSplitterPosition will always disable splitter auto-centering
2698 // if parent window is shown.
2699 void wxPropertyGrid
::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2701 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2704 wxPropertyGridPageState
* state
= m_pState
;
2706 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2710 if ( GetSelection() )
2711 CorrectEditorWidgetSizeX();
2717 // -----------------------------------------------------------------------
2719 void wxPropertyGrid
::CenterSplitter( bool enableAutoCentering
)
2721 SetSplitterPosition( m_width
/2, true );
2722 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2723 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2726 // -----------------------------------------------------------------------
2727 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2728 // -----------------------------------------------------------------------
2730 // Returns nearest paint visible property (such that will be painted unless
2731 // window is scrolled or resized). If given property is paint visible, then
2732 // it itself will be returned
2733 wxPGProperty
* wxPropertyGrid
::GetNearestPaintVisible( wxPGProperty
* p
) const
2735 int vx
,vy1
;// Top left corner of client
2736 GetViewStart(&vx
,&vy1
);
2737 vy1
*= wxPG_PIXELS_PER_UNIT
;
2739 int vy2
= vy1
+ m_height
;
2740 int propY
= p
->GetY2(m_lineHeight
);
2742 if ( (propY
+ m_lineHeight
) < vy1
)
2745 return DoGetItemAtY( vy1
);
2747 else if ( propY
> vy2
)
2750 return DoGetItemAtY( vy2
);
2753 // Itself paint visible
2758 // -----------------------------------------------------------------------
2759 // Methods related to change in value, value modification and sending events
2760 // -----------------------------------------------------------------------
2762 // commits any changes in editor of selected property
2763 // return true if validation did not fail
2764 // flags are same as with DoSelectProperty
2765 bool wxPropertyGrid
::CommitChangesFromEditor( wxUint32 flags
)
2767 // Committing already?
2768 if ( m_inCommitChangesFromEditor
)
2771 // Don't do this if already processing editor event. It might
2772 // induce recursive dialogs and crap like that.
2773 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2775 if ( m_inDoPropertyChanged
)
2781 wxPGProperty
* selected
= GetSelection();
2784 IsEditorsValueModified() &&
2785 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2788 m_inCommitChangesFromEditor
= 1;
2790 wxVariant
variant(selected
->GetValueRef());
2791 bool valueIsPending
= false;
2793 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2794 // due to another window getting focus
2795 wxWindow
* oldFocus
= m_curFocused
;
2797 bool validationFailure
= false;
2798 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ?
true : false;
2800 m_chgInfo_changedProperty
= NULL
;
2802 // If truly modified, schedule value as pending.
2803 if ( selected
->GetEditorClass()->
2804 GetValueFromControl( variant
,
2806 GetEditorControl() ) )
2808 if ( DoEditorValidate() &&
2809 PerformValidation(selected
, variant
) )
2811 valueIsPending
= true;
2815 validationFailure
= true;
2820 EditorsValueWasNotModified();
2825 m_inCommitChangesFromEditor
= 0;
2827 if ( validationFailure
&& !forceSuccess
)
2831 oldFocus
->SetFocus();
2832 m_curFocused
= oldFocus
;
2835 res
= OnValidationFailure(selected
, variant
);
2837 // Now prevent further validation failure messages
2840 EditorsValueWasNotModified();
2841 OnValidationFailureReset(selected
);
2844 else if ( valueIsPending
)
2846 DoPropertyChanged( selected
, flags
);
2847 EditorsValueWasNotModified();
2856 // -----------------------------------------------------------------------
2858 bool wxPropertyGrid
::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2862 // Runs all validation functionality.
2863 // Returns true if value passes all tests.
2866 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2868 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2870 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2875 // Adapt list to child values, if necessary
2876 wxVariant listValue
= pendingValue
;
2877 wxVariant
* pPendingValue
= &pendingValue
;
2878 wxVariant
* pList
= NULL
;
2880 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2881 // string value, then we need treat as it was changed instead
2882 // (or, in addition, as is the case with composite string parent).
2883 // This includes creating list variant for child values.
2885 wxPGProperty
* pwc
= p
->GetParent();
2886 wxPGProperty
* changedProperty
= p
;
2887 wxPGProperty
* baseChangedProperty
= changedProperty
;
2888 wxVariant bcpPendingList
;
2890 listValue
= pendingValue
;
2891 listValue
.SetName(p
->GetBaseName());
2894 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2896 wxVariantList tempList
;
2897 wxVariant
lv(tempList
, pwc
->GetBaseName());
2898 lv
.Append(listValue
);
2900 pPendingValue
= &listValue
;
2902 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2904 baseChangedProperty
= pwc
;
2905 bcpPendingList
= lv
;
2908 changedProperty
= pwc
;
2909 pwc
= pwc
->GetParent();
2913 wxPGProperty
* evtChangingProperty
= changedProperty
;
2915 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2917 value
= *pPendingValue
;
2921 // Convert list to child values
2922 pList
= pPendingValue
;
2923 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2926 wxVariant evtChangingValue
= value
;
2928 if ( flags
& SendEvtChanging
)
2930 // FIXME: After proper ValueToString()s added, remove
2931 // this. It is just a temporary fix, as evt_changing
2932 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2933 // (unless it is selected, and textctrl editor is open).
2934 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2936 evtChangingProperty
= baseChangedProperty
;
2937 if ( evtChangingProperty
!= p
)
2939 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2943 evtChangingValue
= pendingValue
;
2947 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2949 if ( changedProperty
== GetSelection() )
2951 wxWindow
* editor
= GetEditorControl();
2952 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2953 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2957 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2962 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2963 m_chgInfo_changedProperty
= changedProperty
;
2964 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2965 m_chgInfo_pendingValue
= value
;
2968 m_chgInfo_valueList
= *pList
;
2970 m_chgInfo_valueList
.MakeNull();
2972 // If changedProperty is not property which value was edited,
2973 // then call wxPGProperty::ValidateValue() for that as well.
2974 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2976 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2980 if ( flags
& SendEvtChanging
)
2982 // SendEvent returns true if event was vetoed
2983 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
2984 &evtChangingValue
) )
2988 if ( flags
& IsStandaloneValidation
)
2990 // If called in 'generic' context, we need to reset
2991 // m_chgInfo_changedProperty and write back translated value.
2992 m_chgInfo_changedProperty
= NULL
;
2993 pendingValue
= value
;
2999 // -----------------------------------------------------------------------
3001 void wxPropertyGrid
::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3003 if ( !msg
.length() )
3007 if ( !wxPGGlobalVars
->m_offline
)
3009 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3012 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3015 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3018 pStatusBar
->SetStatusText(msg
);
3026 ::wxMessageBox(msg
, wxT("Property Error"));
3029 // -----------------------------------------------------------------------
3031 bool wxPropertyGrid
::OnValidationFailure( wxPGProperty
* property
,
3032 wxVariant
& invalidValue
)
3034 wxWindow
* editor
= GetEditorControl();
3036 // First call property's handler
3037 property
->OnValidationFailure(invalidValue
);
3039 bool res
= DoOnValidationFailure(property
, invalidValue
);
3042 // For non-wxTextCtrl editors, we do need to revert the value
3043 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3044 property
== GetSelection() )
3046 property
->GetEditorClass()->UpdateControl(property
, editor
);
3049 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3054 bool wxPropertyGrid
::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3056 int vfb
= m_validationInfo
.m_failureBehavior
;
3058 if ( vfb
& wxPG_VFB_BEEP
)
3061 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3062 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3064 unsigned int colCount
= m_pState
->GetColumnCount();
3066 // We need backup marked property's cells
3067 m_propCellsBackup
= property
->m_cells
;
3069 wxColour vfbFg
= *wxWHITE
;
3070 wxColour vfbBg
= *wxRED
;
3072 property
->EnsureCells(colCount
);
3074 for ( unsigned int i
=0; i
<colCount
; i
++ )
3076 wxPGCell
& cell
= property
->m_cells
[i
];
3077 cell
.SetFgCol(vfbFg
);
3078 cell
.SetBgCol(vfbBg
);
3081 DrawItemAndChildren(property
);
3083 if ( property
== GetSelection() )
3085 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3087 wxWindow
* editor
= GetEditorControl();
3090 editor
->SetForegroundColour(vfbFg
);
3091 editor
->SetBackgroundColour(vfbBg
);
3096 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3098 wxString msg
= m_validationInfo
.m_failureMessage
;
3100 if ( !msg
.length() )
3101 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3103 DoShowPropertyError(property
, msg
);
3106 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ?
false : true;
3109 // -----------------------------------------------------------------------
3111 void wxPropertyGrid
::DoOnValidationFailureReset( wxPGProperty
* property
)
3113 int vfb
= m_validationInfo
.m_failureBehavior
;
3115 if ( vfb
& wxPG_VFB_MARK_CELL
)
3118 property
->m_cells
= m_propCellsBackup
;
3120 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3122 if ( property
== GetSelection() && GetEditorControl() )
3124 // Calling this will recreate the control, thus resetting its colour
3125 RefreshProperty(property
);
3129 DrawItemAndChildren(property
);
3134 // -----------------------------------------------------------------------
3136 // flags are same as with DoSelectProperty
3137 bool wxPropertyGrid
::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3139 if ( m_inDoPropertyChanged
)
3142 wxWindow
* editor
= GetEditorControl();
3143 wxPGProperty
* selected
= GetSelection();
3145 m_pState
->m_anyModified
= 1;
3147 m_inDoPropertyChanged
= 1;
3149 // Maybe need to update control
3150 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3152 // These values were calculated in PerformValidation()
3153 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3154 wxVariant value
= m_chgInfo_pendingValue
;
3156 wxPGProperty
* topPaintedProperty
= changedProperty
;
3158 while ( !topPaintedProperty
->IsCategory() &&
3159 !topPaintedProperty
->IsRoot() )
3161 topPaintedProperty
= topPaintedProperty
->GetParent();
3164 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3166 // Set as Modified (not if dragging just began)
3167 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3169 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3170 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3173 SetCurControlBoldFont();
3179 // Propagate updates to parent(s)
3181 wxPGProperty
* prevPwc
= NULL
;
3183 while ( prevPwc
!= topPaintedProperty
)
3185 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3187 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3190 SetCurControlBoldFont();
3194 pwc
= pwc
->GetParent();
3197 // Draw the actual property
3198 DrawItemAndChildren( topPaintedProperty
);
3201 // If value was set by wxPGProperty::OnEvent, then update the editor
3203 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3209 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3210 if ( m_wndEditor
) m_wndEditor
->Refresh();
3211 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3216 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3218 // If top parent has composite string value, then send to child parents,
3219 // starting from baseChangedProperty.
3220 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3222 pwc
= m_chgInfo_baseChangedProperty
;
3224 while ( pwc
!= changedProperty
)
3226 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3227 pwc
= pwc
->GetParent();
3231 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3233 m_inDoPropertyChanged
= 0;
3238 // -----------------------------------------------------------------------
3240 bool wxPropertyGrid
::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3242 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3244 m_chgInfo_changedProperty
= NULL
;
3246 if ( PerformValidation(p
, newValue
) )
3248 DoPropertyChanged(p
);
3253 OnValidationFailure(p
, newValue
);
3259 // -----------------------------------------------------------------------
3261 wxVariant wxPropertyGrid
::GetUncommittedPropertyValue()
3263 wxPGProperty
* prop
= GetSelectedProperty();
3266 return wxNullVariant
;
3268 wxTextCtrl
* tc
= GetEditorTextCtrl();
3269 wxVariant value
= prop
->GetValue();
3271 if ( !tc
|| !IsEditorsValueModified() )
3274 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3277 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3278 return prop
->GetValue();
3283 // -----------------------------------------------------------------------
3285 // Runs wxValidator for the selected property
3286 bool wxPropertyGrid
::DoEditorValidate()
3291 // -----------------------------------------------------------------------
3293 void wxPropertyGrid
::HandleCustomEditorEvent( wxEvent
&event
)
3295 wxPGProperty
* selected
= GetSelection();
3297 // Somehow, event is handled after property has been deselected.
3298 // Possibly, but very rare.
3299 if ( !selected
|| selected
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3302 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3305 wxVariant
pendingValue(selected
->GetValueRef());
3306 wxWindow
* wnd
= GetEditorControl();
3307 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3309 bool wasUnspecified
= selected
->IsValueUnspecified();
3310 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3311 bool valueIsPending
= false;
3313 m_chgInfo_changedProperty
= NULL
;
3315 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3318 // Filter out excess wxTextCtrl modified events
3319 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3321 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3323 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3325 wxString newTcValue
= tc
->GetValue();
3326 if ( m_prevTcValue
== newTcValue
)
3329 m_prevTcValue
= newTcValue
;
3332 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3334 bool validationFailure
= false;
3335 bool buttonWasHandled
= false;
3338 // Try common button handling
3339 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3341 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3345 buttonWasHandled
= true;
3346 // Store as res2, as previously (and still currently alternatively)
3347 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3348 // in wxPGProperty::OnEvent().
3349 adapter
->ShowDialog( this, selected
);
3354 if ( !buttonWasHandled
)
3356 if ( wnd
|| m_wndEditor2
)
3358 // First call editor class' event handler.
3359 const wxPGEditor
* editor
= selected
->GetEditorClass();
3361 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3363 // If changes, validate them
3364 if ( DoEditorValidate() )
3366 if ( editor
->GetValueFromControl( pendingValue
,
3369 valueIsPending
= true;
3373 validationFailure
= true;
3378 // Then the property's custom handler (must be always called, unless
3379 // validation failed).
3380 if ( !validationFailure
)
3381 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3384 // SetValueInEvent(), as called in one of the functions referred above
3385 // overrides editor's value.
3386 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3388 valueIsPending
= true;
3389 pendingValue
= m_changeInEventValue
;
3390 selFlags
|= wxPG_SEL_DIALOGVAL
;
3393 if ( !validationFailure
&& valueIsPending
)
3394 if ( !PerformValidation(selected
, pendingValue
) )
3395 validationFailure
= true;
3397 if ( validationFailure
)
3399 OnValidationFailure(selected
, pendingValue
);
3401 else if ( valueIsPending
)
3403 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3405 DoPropertyChanged(selected
, selFlags
);
3406 EditorsValueWasNotModified();
3408 // Regardless of editor type, unfocus editor on
3409 // text-editing related enter press.
3410 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3417 // No value after all
3419 // Regardless of editor type, unfocus editor on
3420 // text-editing related enter press.
3421 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3426 // Let unhandled button click events go to the parent
3427 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3429 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3430 GetEventHandler()->AddPendingEvent(evt
);
3434 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3437 // -----------------------------------------------------------------------
3438 // wxPropertyGrid editor control helper methods
3439 // -----------------------------------------------------------------------
3441 wxRect wxPropertyGrid
::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3443 int itemy
= p
->GetY2(m_lineHeight
);
3445 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3446 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3447 int imageOffset
= 0;
3449 // TODO: If custom image detection changes from current, change this.
3450 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3452 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3453 int iw
= p
->OnMeasureImage().x
;
3455 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3456 imageOffset
= p
->GetImageOffset(iw
);
3461 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3463 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3468 // -----------------------------------------------------------------------
3470 wxRect wxPropertyGrid
::GetImageRect( wxPGProperty
* p
, int item
) const
3472 wxSize sz
= GetImageSize(p
, item
);
3473 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3474 wxPG_CUSTOM_IMAGE_SPACINGY
,
3479 // return size of custom paint image
3480 wxSize wxPropertyGrid
::GetImageSize( wxPGProperty
* p
, int item
) const
3482 // If called with NULL property, then return default image
3483 // size for properties that use image.
3485 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3487 wxSize cis
= p
->OnMeasureImage(item
);
3489 int choiceCount
= p
->m_choices
.GetCount();
3490 int comVals
= p
->GetDisplayedCommonValueCount();
3491 if ( item
>= choiceCount
&& comVals
> 0 )
3493 unsigned int cvi
= item
-choiceCount
;
3494 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3496 else if ( item
>= 0 && choiceCount
== 0 )
3497 return wxSize(0, 0);
3502 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3507 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3514 // -----------------------------------------------------------------------
3516 // takes scrolling into account
3517 void wxPropertyGrid
::ImprovedClientToScreen( int* px
, int* py
)
3520 GetViewStart(&vx
,&vy
);
3521 vy
*=wxPG_PIXELS_PER_UNIT
;
3522 vx
*=wxPG_PIXELS_PER_UNIT
;
3525 ClientToScreen( px
, py
);
3528 // -----------------------------------------------------------------------
3530 wxPropertyGridHitTestResult wxPropertyGrid
::HitTest( const wxPoint
& pt
) const
3533 GetViewStart(&pt2
.x
,&pt2
.y
);
3534 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3535 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3539 return m_pState
->HitTest(pt2
);
3542 // -----------------------------------------------------------------------
3544 // custom set cursor
3545 void wxPropertyGrid
::CustomSetCursor( int type
, bool override
)
3547 if ( type
== m_curcursor
&& !override
) return;
3549 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3551 if ( type
== wxCURSOR_SIZEWE
)
3552 cursor
= m_cursorSizeWE
;
3554 m_canvas
->SetCursor( *cursor
);
3559 // -----------------------------------------------------------------------
3560 // wxPropertyGrid property selection, editor creation
3561 // -----------------------------------------------------------------------
3564 // This class forwards events from property editor controls to wxPropertyGrid.
3565 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3568 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3569 : wxEvtHandler(), m_propGrid(propGrid
)
3573 virtual ~wxPropertyGridEditorEventForwarder()
3578 bool ProcessEvent( wxEvent
& event
)
3583 m_propGrid
->HandleCustomEditorEvent(event
);
3585 return wxEvtHandler
::ProcessEvent(event
);
3588 wxPropertyGrid
* m_propGrid
;
3591 // Setups event handling for child control
3592 void wxPropertyGrid
::SetupChildEventHandling( wxWindow
* argWnd
)
3594 wxWindowID id
= argWnd
->GetId();
3596 if ( argWnd
== m_wndEditor
)
3598 argWnd
->Connect(id
, wxEVT_MOTION
,
3599 wxMouseEventHandler(wxPropertyGrid
::OnMouseMoveChild
),
3601 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3602 wxMouseEventHandler(wxPropertyGrid
::OnMouseUpChild
),
3604 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3605 wxMouseEventHandler(wxPropertyGrid
::OnMouseClickChild
),
3607 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3608 wxMouseEventHandler(wxPropertyGrid
::OnMouseRightClickChild
),
3610 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3611 wxMouseEventHandler(wxPropertyGrid
::OnMouseEntry
),
3613 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3614 wxMouseEventHandler(wxPropertyGrid
::OnMouseEntry
),
3618 wxPropertyGridEditorEventForwarder
* forwarder
;
3619 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3620 argWnd
->PushEventHandler(forwarder
);
3622 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3623 wxCharEventHandler(wxPropertyGrid
::OnChildKeyDown
),
3627 void wxPropertyGrid
::DestroyEditorWnd( wxWindow
* wnd
)
3634 // Do not free editors immediately (for sake of processing events)
3635 wxPendingDelete
.Append(wnd
);
3638 void wxPropertyGrid
::FreeEditors()
3641 // Return focus back to canvas from children (this is required at least for
3642 // GTK+, which, unlike Windows, clears focus when control is destroyed
3643 // instead of moving it to closest parent).
3644 wxWindow
* focus
= wxWindow
::FindFocus();
3647 wxWindow
* parent
= focus
->GetParent();
3650 if ( parent
== m_canvas
)
3655 parent
= parent
->GetParent();
3659 // Do not free editors immediately if processing events
3662 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3663 m_wndEditor2
->Hide();
3664 wxPendingDelete
.Append( handler
);
3665 DestroyEditorWnd(m_wndEditor2
);
3666 m_wndEditor2
= NULL
;
3671 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3672 m_wndEditor
->Hide();
3673 wxPendingDelete
.Append( handler
);
3674 DestroyEditorWnd(m_wndEditor
);
3679 // Call with NULL to de-select property
3680 bool wxPropertyGrid
::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3685 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3686 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3690 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3694 if ( m_inDoSelectProperty
)
3697 m_inDoSelectProperty
= 1;
3701 m_inDoSelectProperty
= 0;
3705 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3706 wxPGProperty
* prevFirstSel
;
3708 if ( prevSelection
.size() > 0 )
3709 prevFirstSel
= prevSelection
[0];
3711 prevFirstSel
= NULL
;
3713 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3714 prevFirstSel
= NULL
;
3716 // Always send event, as this is indirect call
3717 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3721 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3723 wxPrintf( "None selected\n" );
3726 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3728 wxPrintf( "P = NULL\n" );
3731 // If we are frozen, then just set the values.
3734 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3735 m_editorFocused
= 0;
3736 m_pState
->DoSetSelection(p
);
3738 // If frozen, always free controls. But don't worry, as Thaw will
3739 // recall SelectProperty to recreate them.
3742 // Prevent any further selection measures in this call
3748 if ( prevFirstSel
== p
&&
3749 prevSelection
.size() <= 1 &&
3750 !(flags
& wxPG_SEL_FORCE
) )
3752 // Only set focus if not deselecting
3755 if ( flags
& wxPG_SEL_FOCUS
)
3759 m_wndEditor
->SetFocus();
3760 m_editorFocused
= 1;
3769 m_inDoSelectProperty
= 0;
3774 // First, deactivate previous
3777 OnValidationFailureReset(prevFirstSel
);
3779 // Must double-check if this is an selected in case of forceswitch
3780 if ( p
!= prevFirstSel
)
3782 if ( !CommitChangesFromEditor(flags
) )
3784 // Validation has failed, so we can't exit the previous editor
3785 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3786 // _("Invalid Value"),wxOK|wxICON_ERROR);
3787 m_inDoSelectProperty
= 0;
3794 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3795 EditorsValueWasNotModified();
3798 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3800 m_pState
->DoSetSelection(p
);
3802 // Redraw unselected
3803 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3805 DrawItem(prevSelection
[i
]);
3809 // Then, activate the one given.
3812 int propY
= p
->GetY2(m_lineHeight
);
3814 int splitterX
= GetSplitterPosition();
3815 m_editorFocused
= 0;
3816 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3817 if ( p
!= prevFirstSel
)
3818 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3820 wxASSERT( m_wndEditor
== NULL
);
3823 // Only create editor for non-disabled non-caption
3824 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3826 // do this for non-caption items
3830 // Do we need to paint the custom image, if any?
3831 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3832 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3833 !p
->GetEditorClass()->CanContainCustomImage()
3835 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3837 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3838 wxPoint goodPos
= grect
.GetPosition();
3840 const wxPGEditor
* editor
= p
->GetEditorClass();
3841 wxCHECK_MSG(editor
, false,
3842 wxT("NULL editor class not allowed"));
3844 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3846 wxPGWindowList wndList
= editor
->CreateControls(this,
3851 m_wndEditor
= wndList
.m_primary
;
3852 m_wndEditor2
= wndList
.m_secondary
;
3853 wxWindow
* primaryCtrl
= GetEditorControl();
3856 // Essentially, primaryCtrl == m_wndEditor
3859 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3860 // value is drawn as normal, and m_wndEditor2 is assumed
3861 // to be a right-aligned button that triggers a separate editorCtrl
3866 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3867 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3869 // Set validator, if any
3870 #if wxUSE_VALIDATORS
3871 wxValidator
* validator
= p
->GetValidator();
3873 primaryCtrl
->SetValidator(*validator
);
3876 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3877 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3879 // If it has modified status, use bold font
3880 // (must be done before capturing m_ctrlXAdjust)
3881 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3882 SetCurControlBoldFont();
3884 // Store x relative to splitter (we'll need it).
3885 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3887 // Check if background clear is not necessary
3888 wxPoint pos
= m_wndEditor
->GetPosition();
3889 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3891 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3894 m_wndEditor
->SetSizeHints(3, 3);
3896 SetupChildEventHandling(primaryCtrl
);
3898 // Focus and select all (wxTextCtrl, wxComboBox etc)
3899 if ( flags
& wxPG_SEL_FOCUS
)
3901 primaryCtrl
->SetFocus();
3903 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3909 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3910 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3912 // Get proper id for wndSecondary
3913 m_wndSecId
= m_wndEditor2
->GetId();
3914 wxWindowList children
= m_wndEditor2
->GetChildren();
3915 wxWindowList
::iterator node
= children
.begin();
3916 if ( node
!= children
.end() )
3917 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3919 m_wndEditor2
->SetSizeHints(3,3);
3921 m_wndEditor2
->Show();
3923 SetupChildEventHandling(m_wndEditor2
);
3925 // If no primary editor, focus to button to allow
3926 // it to interprete ENTER etc.
3927 // NOTE: Due to problems focusing away from it, this
3928 // has been disabled.
3930 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3931 m_wndEditor2->SetFocus();
3935 if ( flags
& wxPG_SEL_FOCUS
)
3936 m_editorFocused
= 1;
3941 // Make sure focus is in grid canvas (important for wxGTK, at least)
3945 EditorsValueWasNotModified();
3947 // If it's inside collapsed section, expand parent, scroll, etc.
3948 // Also, if it was partially visible, scroll it into view.
3949 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3954 m_wndEditor
->Show(true);
3957 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
3962 // Make sure focus is in grid canvas
3966 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3972 // Show help text in status bar.
3973 // (if found and grid not embedded in manager with help box and
3974 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3977 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3979 wxStatusBar
* statusbar
= NULL
;
3980 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3982 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3984 statusbar
= frame
->GetStatusBar();
3989 const wxString
* pHelpString
= (const wxString
*) NULL
;
3993 pHelpString
= &p
->GetHelpString();
3994 if ( pHelpString
->length() )
3996 // Set help box text.
3997 statusbar
->SetStatusText( *pHelpString
);
3998 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4002 if ( (!pHelpString
|| !pHelpString
->length()) &&
4003 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4005 // Clear help box - but only if it was written
4006 // by us at previous time.
4007 statusbar
->SetStatusText( m_emptyString
);
4008 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4014 m_inDoSelectProperty
= 0;
4016 // call wx event handler (here so that it also occurs on deselection)
4017 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4018 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4023 // -----------------------------------------------------------------------
4025 bool wxPropertyGrid
::UnfocusEditor()
4027 wxPGProperty
* selected
= GetSelection();
4029 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4032 if ( !CommitChangesFromEditor(0) )
4041 // -----------------------------------------------------------------------
4043 void wxPropertyGrid
::RefreshEditor()
4045 wxPGProperty
* p
= GetSelection();
4049 wxWindow
* wnd
= GetEditorControl();
4053 // Set editor font boldness - must do this before
4054 // calling UpdateControl().
4055 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4057 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4058 wnd
->SetFont(GetCaptionFont());
4060 wnd
->SetFont(GetFont());
4063 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4065 editorClass
->UpdateControl(p
, wnd
);
4067 if ( p
->IsValueUnspecified() )
4068 editorClass
->SetValueToUnspecified(p
, wnd
);
4071 // -----------------------------------------------------------------------
4073 bool wxPropertyGrid
::SelectProperty( wxPGPropArg id
, bool focus
)
4075 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4077 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4079 flags
|= wxPG_SEL_FOCUS
;
4081 return DoSelectProperty(p
, flags
);
4084 // -----------------------------------------------------------------------
4085 // wxPropertyGrid expand/collapse state
4086 // -----------------------------------------------------------------------
4088 bool wxPropertyGrid
::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4090 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4091 wxPGProperty
* selected
= GetSelection();
4093 // If active editor was inside collapsed section, then disable it
4094 if ( selected
&& selected
->IsSomeParent(p
) )
4099 // Store dont-center-splitter flag 'cause we need to temporarily set it
4100 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4101 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4103 bool res
= m_pState
->DoCollapse(pwc
);
4108 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4110 RecalculateVirtualSize();
4112 // Redraw etc. only if collapsed was visible.
4113 if (pwc
->IsVisible() &&
4115 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
4117 // When item is collapsed so that scrollbar would move,
4118 // graphics mess is about (unless we redraw everything).
4123 // Clear dont-center-splitter flag if it wasn't set
4124 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4129 // -----------------------------------------------------------------------
4131 bool wxPropertyGrid
::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4133 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4135 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4137 // Store dont-center-splitter flag 'cause we need to temporarily set it
4138 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4139 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4141 bool res
= m_pState
->DoExpand(pwc
);
4146 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4148 RecalculateVirtualSize();
4150 // Redraw etc. only if expanded was visible.
4151 if ( pwc
->IsVisible() && !m_frozen
&&
4152 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4156 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4159 DrawItems(pwc
, NULL
);
4164 // Clear dont-center-splitter flag if it wasn't set
4165 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4170 // -----------------------------------------------------------------------
4172 bool wxPropertyGrid
::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4175 return m_pState
->DoHideProperty(p
, hide
, flags
);
4177 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4178 int selRemoveCount
= 0;
4179 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4181 wxPGProperty
* selected
= selection
[i
];
4182 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4184 if ( !DoRemoveFromSelection(p
, flags
) )
4186 selRemoveCount
+= 1;
4190 m_pState
->DoHideProperty(p
, hide
, flags
);
4192 RecalculateVirtualSize();
4199 // -----------------------------------------------------------------------
4200 // wxPropertyGrid size related methods
4201 // -----------------------------------------------------------------------
4203 void wxPropertyGrid
::RecalculateVirtualSize( int forceXPos
)
4205 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4209 // If virtual height was changed, then recalculate editor control position(s)
4210 if ( m_pState
->m_vhCalcPending
)
4211 CorrectEditorWidgetPosY();
4213 m_pState
->EnsureVirtualHeight();
4215 wxASSERT_LEVEL_2_MSG(
4216 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4217 "VirtualHeight and ActualVirtualHeight should match"
4220 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4222 int x
= m_pState
->m_width
;
4223 int y
= m_pState
->m_virtualHeight
;
4226 GetClientSize(&width
,&height
);
4228 // Now adjust virtual size.
4229 SetVirtualSize(x
, y
);
4235 // Adjust scrollbars
4236 if ( HasVirtualWidth() )
4238 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4239 xPos
= GetScrollPos( wxHORIZONTAL
);
4242 if ( forceXPos
!= -1 )
4245 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4248 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4249 int yPos
= GetScrollPos( wxVERTICAL
);
4251 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4252 xAmount
, yAmount
, xPos
, yPos
, true );
4254 // Must re-get size now
4255 GetClientSize(&width
,&height
);
4257 if ( !HasVirtualWidth() )
4259 m_pState
->SetVirtualWidth(width
);
4266 m_canvas
->SetSize( x
, y
);
4268 m_pState
->CheckColumnWidths();
4270 if ( GetSelection() )
4271 CorrectEditorWidgetSizeX();
4273 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4276 // -----------------------------------------------------------------------
4278 void wxPropertyGrid
::OnResize( wxSizeEvent
& event
)
4280 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4284 GetClientSize(&width
,&height
);
4289 #if wxPG_DOUBLE_BUFFER
4290 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4292 int dblh
= (m_lineHeight
*2);
4293 if ( !m_doubleBuffer
)
4295 // Create double buffer bitmap to draw on, if none
4296 int w
= (width
>250)?width
:250;
4297 int h
= height
+ dblh
;
4299 m_doubleBuffer
= new wxBitmap( w
, h
);
4303 int w
= m_doubleBuffer
->GetWidth();
4304 int h
= m_doubleBuffer
->GetHeight();
4306 // Double buffer must be large enough
4307 if ( w
< width
|| h
< (height
+dblh
) )
4309 if ( w
< width
) w
= width
;
4310 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4311 delete m_doubleBuffer
;
4312 m_doubleBuffer
= new wxBitmap( w
, h
);
4319 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4320 m_ncWidth
= event
.GetSize().x
;
4324 if ( m_pState
->m_itemsAdded
)
4325 PrepareAfterItemsAdded();
4327 // Without this, virtual size (atleast under wxGTK) will be skewed
4328 RecalculateVirtualSize();
4334 // -----------------------------------------------------------------------
4336 void wxPropertyGrid
::SetVirtualWidth( int width
)
4340 // Disable virtual width
4341 width
= GetClientSize().x
;
4342 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4346 // Enable virtual width
4347 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4349 m_pState
->SetVirtualWidth( width
);
4352 void wxPropertyGrid
::SetFocusOnCanvas()
4354 m_canvas
->SetFocusIgnoringChildren();
4355 m_editorFocused
= 0;
4358 // -----------------------------------------------------------------------
4359 // wxPropertyGrid mouse event handling
4360 // -----------------------------------------------------------------------
4362 // selFlags uses same values DoSelectProperty's flags
4363 // Returns true if event was vetoed.
4364 bool wxPropertyGrid
::SendEvent( int eventType
, wxPGProperty
* p
,
4366 unsigned int selFlags
,
4367 unsigned int column
)
4369 // Send property grid event of specific type and with specific property
4370 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4371 evt
.SetPropertyGrid(this);
4372 evt
.SetEventObject(m_eventObject
);
4374 evt
.SetColumn(column
);
4377 evt
.SetCanVeto(true);
4378 evt
.SetupValidationInfo();
4379 m_validationInfo
.m_pValue
= pValue
;
4381 else if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4383 evt
.SetCanVeto(true);
4386 m_processedEvent
= &evt
;
4388 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4390 m_processedEvent
= NULL
;
4392 evtHandler
->ProcessEvent(evt
);
4394 return evt
.WasVetoed();
4397 // -----------------------------------------------------------------------
4399 // Return false if should be skipped
4400 bool wxPropertyGrid
::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4404 // Need to set focus?
4405 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4410 wxPropertyGridPageState
* state
= m_pState
;
4412 int splitterHitOffset
;
4413 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4415 wxPGProperty
* p
= DoGetItemAtY(y
);
4419 int depth
= (int)p
->GetDepth() - 1;
4421 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4423 if ( x
>= marginEnds
)
4427 if ( p
->IsCategory() )
4429 // This is category.
4430 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4432 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4434 // Expand, collapse, activate etc. if click on text or left of splitter.
4437 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4442 if ( !AddToSelectionFromInputEvent( p
,
4447 // On double-click, expand/collapse.
4448 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4450 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4451 else DoExpand( p
, true );
4455 else if ( splitterHit
== -1 )
4458 unsigned int selFlag
= 0;
4459 if ( columnHit
== 1 )
4461 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4462 selFlag
= wxPG_SEL_FOCUS
;
4464 if ( !AddToSelectionFromInputEvent( p
,
4470 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4472 if ( p
->GetChildCount() && !p
->IsCategory() )
4473 // On double-click, expand/collapse.
4474 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4476 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4477 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4478 else DoExpand( p
, true );
4485 // click on splitter
4486 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4488 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4490 // Double-clicking the splitter causes auto-centering
4491 CenterSplitter( true );
4493 else if ( m_dragStatus
== 0 )
4496 // Begin draggin the splitter
4500 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4504 // Changes must be committed here or the
4505 // value won't be drawn correctly
4506 if ( !CommitChangesFromEditor() )
4509 m_wndEditor
->Show ( false );
4512 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4514 m_canvas
->CaptureMouse();
4515 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4519 m_draggedSplitter
= splitterHit
;
4520 m_dragOffset
= splitterHitOffset
;
4522 wxClientDC
dc(m_canvas
);
4524 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4525 // Fixes button disappearance bug
4527 m_wndEditor2
->Show ( false );
4530 m_startingSplitterX
= x
- splitterHitOffset
;
4538 if ( p
->GetChildCount() )
4540 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4542 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4544 int y2
= y
% m_lineHeight
;
4545 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4547 // On click on expander button, expand/collapse
4548 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4549 DoCollapse( p
, true );
4551 DoExpand( p
, true );
4560 // -----------------------------------------------------------------------
4562 bool wxPropertyGrid
::HandleMouseRightClick( int WXUNUSED(x
),
4563 unsigned int WXUNUSED(y
),
4564 wxMouseEvent
& event
)
4568 // Select property here as well
4569 wxPGProperty
* p
= m_propHover
;
4570 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4572 // Send right click event.
4573 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4580 // -----------------------------------------------------------------------
4582 bool wxPropertyGrid
::HandleMouseDoubleClick( int WXUNUSED(x
),
4583 unsigned int WXUNUSED(y
),
4584 wxMouseEvent
& event
)
4588 // Select property here as well
4589 wxPGProperty
* p
= m_propHover
;
4591 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4593 // Send double-click event.
4594 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4601 // -----------------------------------------------------------------------
4603 #if wxPG_SUPPORT_TOOLTIPS
4605 void wxPropertyGrid
::SetToolTip( const wxString
& tipString
)
4607 if ( tipString
.length() )
4609 m_canvas
->SetToolTip(tipString
);
4613 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4614 m_canvas
->SetToolTip( m_emptyString
);
4616 m_canvas
->SetToolTip( NULL
);
4621 #endif // #if wxPG_SUPPORT_TOOLTIPS
4623 // -----------------------------------------------------------------------
4625 // Return false if should be skipped
4626 bool wxPropertyGrid
::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4628 // Safety check (needed because mouse capturing may
4629 // otherwise freeze the control)
4630 if ( m_dragStatus
> 0 && !event
.Dragging() )
4632 HandleMouseUp(x
,y
,event
);
4635 wxPropertyGridPageState
* state
= m_pState
;
4637 int splitterHitOffset
;
4638 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4639 int splitterX
= x
- splitterHitOffset
;
4641 m_colHover
= columnHit
;
4643 if ( m_dragStatus
> 0 )
4645 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4646 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4649 int newSplitterX
= x
- m_dragOffset
;
4650 int splitterX
= x
- splitterHitOffset
;
4652 // Splitter redraw required?
4653 if ( newSplitterX
!= splitterX
)
4656 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4657 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4658 state
->m_fSplitterX
= (float) newSplitterX
;
4660 if ( GetSelection() )
4661 CorrectEditorWidgetSizeX();
4675 int ih
= m_lineHeight
;
4678 #if wxPG_SUPPORT_TOOLTIPS
4679 wxPGProperty
* prevHover
= m_propHover
;
4680 unsigned char prevSide
= m_mouseSide
;
4682 int curPropHoverY
= y
- (y
% ih
);
4684 // On which item it hovers
4687 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4690 // Mouse moves on another property
4692 m_propHover
= DoGetItemAtY(y
);
4693 m_propHoverY
= curPropHoverY
;
4696 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4699 #if wxPG_SUPPORT_TOOLTIPS
4700 // Store which side we are on
4702 if ( columnHit
== 1 )
4704 else if ( columnHit
== 0 )
4708 // If tooltips are enabled, show label or value as a tip
4709 // in case it doesn't otherwise show in full length.
4711 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4713 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4715 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4717 if ( m_propHover
&& !m_propHover
->IsCategory() )
4720 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4722 // Show help string as a tooltip
4723 wxString tipString
= m_propHover
->GetHelpString();
4725 SetToolTip(tipString
);
4729 // Show cropped value string as a tooltip
4733 if ( m_mouseSide
== 1 )
4735 tipString
= m_propHover
->m_label
;
4736 space
= splitterX
-m_marginWidth
-3;
4738 else if ( m_mouseSide
== 2 )
4740 tipString
= m_propHover
->GetDisplayedString();
4742 space
= m_width
- splitterX
;
4743 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4744 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4750 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4753 SetToolTip( tipString
);
4760 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4761 m_canvas
->SetToolTip( m_emptyString
);
4763 m_canvas
->SetToolTip( NULL
);
4774 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4775 m_canvas
->SetToolTip( m_emptyString
);
4777 m_canvas
->SetToolTip( NULL
);
4785 if ( splitterHit
== -1 ||
4787 HasFlag(wxPG_STATIC_SPLITTER
) )
4789 // hovering on something else
4790 if ( m_curcursor
!= wxCURSOR_ARROW
)
4791 CustomSetCursor( wxCURSOR_ARROW
);
4795 // Do not allow splitter cursor on caption items.
4796 // (also not if we were dragging and its started
4797 // outside the splitter region)
4799 if ( !m_propHover
->IsCategory() &&
4803 // hovering on splitter
4805 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4806 // reliably detected.
4807 //if ( m_curcursor != wxCURSOR_SIZEWE )
4808 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4814 // hovering on something else
4815 if ( m_curcursor
!= wxCURSOR_ARROW
)
4816 CustomSetCursor( wxCURSOR_ARROW
);
4821 // Multi select by dragging
4823 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
4824 event
.LeftIsDown() &&
4828 !state
->DoIsPropertySelected(m_propHover
) )
4830 // Additional requirement is that the hovered property
4831 // is adjacent to edges of selection.
4832 const wxArrayPGProperty
& selection
= GetSelectedProperties();
4834 // Since categories cannot be selected along with 'other'
4835 // properties, exclude them from iterator flags.
4836 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
4838 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
4840 // TODO: This could be optimized by keeping track of
4841 // which properties are at the edges of selection.
4842 wxPGProperty
* selProp
= selection
[i
];
4843 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
4846 DoAddToSelection(m_propHover
);
4855 // -----------------------------------------------------------------------
4857 // Also handles Leaving event
4858 bool wxPropertyGrid
::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4859 wxMouseEvent
&WXUNUSED(event
) )
4861 wxPropertyGridPageState
* state
= m_pState
;
4865 int splitterHitOffset
;
4866 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4868 // No event type check - basicly calling this method should
4869 // just stop dragging.
4870 // Left up after dragged?
4871 if ( m_dragStatus
>= 1 )
4874 // End Splitter Dragging
4876 // DO NOT ENABLE FOLLOWING LINE!
4877 // (it is only here as a reminder to not to do it)
4880 // Disable splitter auto-centering
4881 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4883 // This is necessary to return cursor
4884 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4886 m_canvas
->ReleaseMouse();
4887 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4890 // Set back the default cursor, if necessary
4891 if ( splitterHit
== -1 ||
4894 CustomSetCursor( wxCURSOR_ARROW
);
4899 // Control background needs to be cleared
4900 wxPGProperty
* selected
= GetSelection();
4901 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4902 DrawItem( selected
);
4906 m_wndEditor
->Show ( true );
4909 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4910 // Fixes button disappearance bug
4912 m_wndEditor2
->Show ( true );
4915 // This clears the focus.
4916 m_editorFocused
= 0;
4922 // -----------------------------------------------------------------------
4924 bool wxPropertyGrid
::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4926 int splitterX
= GetSplitterPosition();
4929 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4933 wxWindow
* wnd
= GetEditorControl();
4935 // Hide popup on clicks
4936 if ( event
.GetEventType() != wxEVT_MOTION
)
4937 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4939 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4945 if ( wnd
== NULL
|| m_dragStatus
||
4947 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4948 ux
>= (r
.x
+r
.width
) ||
4950 event
.m_y
>= (r
.y
+r
.height
)
4960 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4965 // -----------------------------------------------------------------------
4967 void wxPropertyGrid
::OnMouseClick( wxMouseEvent
&event
)
4970 if ( OnMouseCommon( event
, &x
, &y
) )
4972 HandleMouseClick(x
,y
,event
);
4977 // -----------------------------------------------------------------------
4979 void wxPropertyGrid
::OnMouseRightClick( wxMouseEvent
&event
)
4982 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4983 HandleMouseRightClick(x
,y
,event
);
4987 // -----------------------------------------------------------------------
4989 void wxPropertyGrid
::OnMouseDoubleClick( wxMouseEvent
&event
)
4991 // Always run standard mouse-down handler as well
4992 OnMouseClick(event
);
4995 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4996 HandleMouseDoubleClick(x
,y
,event
);
5000 // -----------------------------------------------------------------------
5002 void wxPropertyGrid
::OnMouseMove( wxMouseEvent
&event
)
5005 if ( OnMouseCommon( event
, &x
, &y
) )
5007 HandleMouseMove(x
,y
,event
);
5012 // -----------------------------------------------------------------------
5014 void wxPropertyGrid
::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
5016 // Called when mouse moves in the empty space below the properties.
5017 CustomSetCursor( wxCURSOR_ARROW
);
5020 // -----------------------------------------------------------------------
5022 void wxPropertyGrid
::OnMouseUp( wxMouseEvent
&event
)
5025 if ( OnMouseCommon( event
, &x
, &y
) )
5027 HandleMouseUp(x
,y
,event
);
5032 // -----------------------------------------------------------------------
5034 void wxPropertyGrid
::OnMouseEntry( wxMouseEvent
&event
)
5036 // This may get called from child control as well, so event's
5037 // mouse position cannot be relied on.
5039 if ( event
.Entering() )
5041 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5043 // TODO: Fix this (detect parent and only do
5044 // cursor trick if it is a manager).
5045 wxASSERT( GetParent() );
5046 GetParent()->SetCursor(wxNullCursor
);
5048 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5051 GetParent()->SetCursor(wxNullCursor
);
5053 else if ( event
.Leaving() )
5055 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5056 m_canvas
->SetCursor( wxNullCursor
);
5058 // Get real cursor position
5059 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5061 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5064 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5066 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5070 wxPropertyGrid
::HandleMouseUp ( -1, 10000, event
);
5078 // -----------------------------------------------------------------------
5080 // Common code used by various OnMouseXXXChild methods.
5081 bool wxPropertyGrid
::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5083 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5084 wxASSERT( topCtrlWnd
);
5086 event
.GetPosition(&x
,&y
);
5088 int splitterX
= GetSplitterPosition();
5090 wxRect r
= topCtrlWnd
->GetRect();
5091 if ( !m_dragStatus
&&
5092 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5093 y
>= 0 && y
< r
.height \
5096 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5101 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5108 void wxPropertyGrid
::OnMouseClickChild( wxMouseEvent
&event
)
5111 if ( OnMouseChildCommon(event
,&x
,&y
) )
5113 bool res
= HandleMouseClick(x
,y
,event
);
5114 if ( !res
) event
.Skip();
5118 void wxPropertyGrid
::OnMouseRightClickChild( wxMouseEvent
&event
)
5121 wxASSERT( m_wndEditor
);
5122 // These coords may not be exact (about +-2),
5123 // but that should not matter (right click is about item, not position).
5124 wxPoint pt
= m_wndEditor
->GetPosition();
5125 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5127 // FIXME: Used to set m_propHover to selection here. Was it really
5130 bool res
= HandleMouseRightClick(x
,y
,event
);
5131 if ( !res
) event
.Skip();
5134 void wxPropertyGrid
::OnMouseMoveChild( wxMouseEvent
&event
)
5137 if ( OnMouseChildCommon(event
,&x
,&y
) )
5139 bool res
= HandleMouseMove(x
,y
,event
);
5140 if ( !res
) event
.Skip();
5144 void wxPropertyGrid
::OnMouseUpChild( wxMouseEvent
&event
)
5147 if ( OnMouseChildCommon(event
,&x
,&y
) )
5149 bool res
= HandleMouseUp(x
,y
,event
);
5150 if ( !res
) event
.Skip();
5154 // -----------------------------------------------------------------------
5155 // wxPropertyGrid keyboard event handling
5156 // -----------------------------------------------------------------------
5158 int wxPropertyGrid
::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5160 // Translates wxKeyEvent to wxPG_ACTION_XXX
5162 int keycode
= event
.GetKeyCode();
5163 int modifiers
= event
.GetModifiers();
5165 wxASSERT( !(modifiers
&~(0xFFFF)) );
5167 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5169 wxPGHashMapI2I
::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5171 if ( it
== m_actionTriggers
.end() )
5176 int second
= (it
->second
>>16) & 0xFFFF;
5180 return (it
->second
& 0xFFFF);
5183 void wxPropertyGrid
::AddActionTrigger( int action
, int keycode
, int modifiers
)
5185 wxASSERT( !(modifiers
&~(0xFFFF)) );
5187 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5189 wxPGHashMapI2I
::iterator it
= m_actionTriggers
.find(hashMapKey
);
5191 if ( it
!= m_actionTriggers
.end() )
5193 // This key combination is already used
5195 // Can add secondary?
5196 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5197 wxT("You can only add up to two separate actions per key combination.") );
5199 action
= it
->second
| (action
<<16);
5202 m_actionTriggers
[hashMapKey
] = action
;
5205 void wxPropertyGrid
::ClearActionTriggers( int action
)
5207 wxPGHashMapI2I
::iterator it
;
5209 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
5211 if ( it
->second
== action
)
5213 m_actionTriggers
.erase(it
);
5218 void wxPropertyGrid
::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5221 // Handles key event when editor control is not focused.
5224 wxCHECK2(!m_frozen
, return);
5226 // Travelsal between items, collapsing/expanding, etc.
5227 wxPGProperty
* selected
= GetSelection();
5228 int keycode
= event
.GetKeyCode();
5229 bool editorFocused
= IsEditorFocused();
5231 if ( keycode
== WXK_TAB
)
5233 wxWindow
* mainControl
;
5235 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5236 mainControl
= GetParent();
5240 if ( !event
.ShiftDown() )
5242 if ( !editorFocused
&& m_wndEditor
)
5244 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5248 // Tab traversal workaround for platforms on which
5249 // wxWindow::Navigate() may navigate into first child
5250 // instead of next sibling. Does not work perfectly
5251 // in every scenario (for instance, when property grid
5252 // is either first or last control).
5253 #if defined(__WXGTK__)
5254 wxWindow
* sibling
= mainControl
->GetNextSibling();
5256 sibling
->SetFocusFromKbd();
5258 Navigate(wxNavigationKeyEvent
::IsForward
);
5264 if ( editorFocused
)
5270 #if defined(__WXGTK__)
5271 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5273 sibling
->SetFocusFromKbd();
5275 Navigate(wxNavigationKeyEvent
::IsBackward
);
5283 // Ignore Alt and Control when they are down alone
5284 if ( keycode
== WXK_ALT
||
5285 keycode
== WXK_CONTROL
)
5292 int action
= KeyEventToActions(event
, &secondAction
);
5294 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5297 // Esc cancels any changes
5298 if ( IsEditorsValueModified() )
5300 EditorsValueWasNotModified();
5302 // Update the control as well
5303 selected
->GetEditorClass()->
5304 SetControlStringValue( selected
,
5306 selected
->GetDisplayedString() );
5309 OnValidationFailureReset(selected
);
5315 // Except for TAB and ESC, handle child control events in child control
5318 // Only propagate event if it had modifiers
5319 if ( !event
.HasModifiers() )
5321 event
.StopPropagation();
5327 bool wasHandled
= false;
5332 if ( ButtonTriggerKeyTest(action
, event
) )
5335 wxPGProperty
* p
= selected
;
5337 // Travel and expand/collapse
5340 if ( p
->GetChildCount() )
5342 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5344 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5347 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5349 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5356 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5360 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5366 if ( selectDir
>= -1 )
5368 p
= wxPropertyGridIterator
::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5370 DoSelectProperty(p
);
5376 // If nothing was selected, select the first item now
5377 // (or navigate out of tab).
5378 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5380 wxPGProperty
* p
= wxPropertyGridInterface
::GetFirst();
5381 if ( p
) DoSelectProperty(p
);
5390 // -----------------------------------------------------------------------
5392 void wxPropertyGrid
::OnKey( wxKeyEvent
&event
)
5394 // If there was editor open and focused, then this event should not
5395 // really be processed here.
5396 if ( IsEditorFocused() )
5398 // However, if event had modifiers, it is probably still best
5400 if ( event
.HasModifiers() )
5403 event
.StopPropagation();
5407 HandleKeyEvent(event
, false);
5410 // -----------------------------------------------------------------------
5412 bool wxPropertyGrid
::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5417 action
= KeyEventToActions(event
, &secondAction
);
5420 // Does the keycode trigger button?
5421 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5424 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5425 GetEventHandler()->AddPendingEvent(evt
);
5432 // -----------------------------------------------------------------------
5434 void wxPropertyGrid
::OnChildKeyDown( wxKeyEvent
&event
)
5436 HandleKeyEvent(event
, true);
5439 // -----------------------------------------------------------------------
5440 // wxPropertyGrid miscellaneous event handling
5441 // -----------------------------------------------------------------------
5443 void wxPropertyGrid
::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5446 // Check if the focus is in this control or one of its children
5447 wxWindow
* newFocused
= wxWindow
::FindFocus();
5449 if ( newFocused
!= m_curFocused
)
5450 HandleFocusChange( newFocused
);
5453 // Check if top-level parent has changed
5454 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5456 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5462 bool wxPropertyGrid
::IsEditorFocused() const
5464 wxWindow
* focus
= wxWindow
::FindFocus();
5466 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5467 focus
== GetEditorControl() )
5473 // Called by focus event handlers. newFocused is the window that becomes focused.
5474 void wxPropertyGrid
::HandleFocusChange( wxWindow
* newFocused
)
5476 unsigned int oldFlags
= m_iFlags
;
5478 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5480 wxWindow
* parent
= newFocused
;
5482 // This must be one of nextFocus' parents.
5485 // Use m_eventObject, which is either wxPropertyGrid or
5486 // wxPropertyGridManager, as appropriate.
5487 if ( parent
== m_eventObject
)
5489 m_iFlags
|= wxPG_FL_FOCUSED
;
5492 parent
= parent
->GetParent();
5495 m_curFocused
= newFocused
;
5497 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5498 (oldFlags
& wxPG_FL_FOCUSED
) )
5500 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5502 // Need to store changed value
5503 CommitChangesFromEditor();
5509 // Preliminary code for tab-order respecting
5510 // tab-traversal (but should be moved to
5513 wxWindow* prevFocus = event.GetWindow();
5514 wxWindow* useThis = this;
5515 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5516 useThis = GetParent();
5519 prevFocus->GetParent() == useThis->GetParent() )
5521 wxList& children = useThis->GetParent()->GetChildren();
5523 wxNode* node = children.Find(prevFocus);
5525 if ( node->GetNext() &&
5526 useThis == node->GetNext()->GetData() )
5527 DoSelectProperty(GetFirst());
5528 else if ( node->GetPrevious () &&
5529 useThis == node->GetPrevious()->GetData() )
5530 DoSelectProperty(GetLastProperty());
5537 wxPGProperty
* selected
= GetSelection();
5538 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5539 DrawItem( selected
);
5543 void wxPropertyGrid
::OnFocusEvent( wxFocusEvent
& event
)
5545 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5546 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5547 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5548 //else if ( event.GetWindow() )
5550 HandleFocusChange(event
.GetWindow());
5555 // -----------------------------------------------------------------------
5557 void wxPropertyGrid
::OnChildFocusEvent( wxChildFocusEvent
& event
)
5559 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5563 // -----------------------------------------------------------------------
5565 void wxPropertyGrid
::OnScrollEvent( wxScrollWinEvent
&event
)
5567 m_iFlags
|= wxPG_FL_SCROLLED
;
5572 // -----------------------------------------------------------------------
5574 void wxPropertyGrid
::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5576 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5578 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5582 // -----------------------------------------------------------------------
5583 // Property editor related functions
5584 // -----------------------------------------------------------------------
5586 // noDefCheck = true prevents infinite recursion.
5587 wxPGEditor
* wxPropertyGrid
::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5588 const wxString
& editorName
,
5591 wxASSERT( editorClass
);
5593 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5594 RegisterDefaultEditors();
5596 wxString name
= editorName
;
5597 if ( name
.length() == 0 )
5598 name
= editorClass
->GetName();
5600 // Existing editor under this name?
5601 wxPGHashMapS2P
::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5603 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5605 // If this name was already used, try class name.
5606 name
= editorClass
->GetClassInfo()->GetClassName();
5607 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5610 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5611 (wxPGEditor
*) vt_it
->second
,
5612 "Editor with given name was already registered" );
5614 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5619 // Use this in RegisterDefaultEditors.
5620 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5621 if ( wxPGEditor_##EDITOR == NULL ) \
5623 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5624 new wxPG##EDITOR##Editor, true ); \
5627 // Registers all default editor classes
5628 void wxPropertyGrid
::RegisterDefaultEditors()
5630 wxPGRegisterDefaultEditorClass( TextCtrl
);
5631 wxPGRegisterDefaultEditorClass( Choice
);
5632 wxPGRegisterDefaultEditorClass( ComboBox
);
5633 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5634 #if wxPG_INCLUDE_CHECKBOX
5635 wxPGRegisterDefaultEditorClass( CheckBox
);
5637 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5639 // Register SpinCtrl etc. editors before use
5640 RegisterAdditionalEditors();
5643 // -----------------------------------------------------------------------
5644 // wxPGStringTokenizer
5645 // Needed to handle C-style string lists (e.g. "str1" "str2")
5646 // -----------------------------------------------------------------------
5648 wxPGStringTokenizer
::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5649 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5653 wxPGStringTokenizer
::~wxPGStringTokenizer()
5657 bool wxPGStringTokenizer
::HasMoreTokens()
5659 const wxString
& str
= *m_str
;
5661 wxString
::const_iterator i
= m_curPos
;
5663 wxUniChar delim
= m_delimeter
;
5665 wxUniChar prev_a
= wxT('\0');
5667 bool inToken
= false;
5669 while ( i
!= str
.end() )
5678 m_readyToken
.clear();
5683 if ( prev_a
!= wxT('\\') )
5687 if ( a
!= wxT('\\') )
5707 m_curPos
= str
.end();
5715 wxString wxPGStringTokenizer
::GetNextToken()
5717 return m_readyToken
;
5720 // -----------------------------------------------------------------------
5722 // -----------------------------------------------------------------------
5724 wxPGChoiceEntry
::wxPGChoiceEntry()
5725 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5729 // -----------------------------------------------------------------------
5731 // -----------------------------------------------------------------------
5733 wxPGChoicesData
::wxPGChoicesData()
5737 wxPGChoicesData
::~wxPGChoicesData()
5742 void wxPGChoicesData
::Clear()
5747 void wxPGChoicesData
::CopyDataFrom( wxPGChoicesData
* data
)
5749 wxASSERT( m_items
.size() == 0 );
5751 m_items
= data
->m_items
;
5754 wxPGChoiceEntry
& wxPGChoicesData
::Insert( int index
,
5755 const wxPGChoiceEntry
& item
)
5757 wxVector
<wxPGChoiceEntry
>::iterator it
;
5761 index
= (int) m_items
.size();
5765 it
= m_items
.begin() + index
;
5768 m_items
.insert(it
, item
);
5770 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5772 // Need to fix value?
5773 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5774 ownEntry
.SetValue(index
);
5779 // -----------------------------------------------------------------------
5780 // wxPropertyGridEvent
5781 // -----------------------------------------------------------------------
5783 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5786 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5787 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5788 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5789 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5790 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5791 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5792 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5793 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5794 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5795 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5796 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5798 // -----------------------------------------------------------------------
5800 void wxPropertyGridEvent
::Init()
5802 m_validationInfo
= NULL
;
5805 m_wasVetoed
= false;
5808 // -----------------------------------------------------------------------
5810 wxPropertyGridEvent
::wxPropertyGridEvent(wxEventType commandType
, int id
)
5811 : wxCommandEvent(commandType
,id
)
5817 // -----------------------------------------------------------------------
5819 wxPropertyGridEvent
::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5820 : wxCommandEvent(event
)
5822 m_eventType
= event
.GetEventType();
5823 m_eventObject
= event
.m_eventObject
;
5825 m_property
= event
.m_property
;
5826 m_validationInfo
= event
.m_validationInfo
;
5827 m_canVeto
= event
.m_canVeto
;
5828 m_wasVetoed
= event
.m_wasVetoed
;
5831 // -----------------------------------------------------------------------
5833 wxPropertyGridEvent
::~wxPropertyGridEvent()
5837 // -----------------------------------------------------------------------
5839 wxEvent
* wxPropertyGridEvent
::Clone() const
5841 return new wxPropertyGridEvent( *this );
5844 // -----------------------------------------------------------------------
5845 // wxPropertyGridPopulator
5846 // -----------------------------------------------------------------------
5848 wxPropertyGridPopulator
::wxPropertyGridPopulator()
5852 wxPGGlobalVars
->m_offline
++;
5855 // -----------------------------------------------------------------------
5857 void wxPropertyGridPopulator
::SetState( wxPropertyGridPageState
* state
)
5860 m_propHierarchy
.clear();
5863 // -----------------------------------------------------------------------
5865 void wxPropertyGridPopulator
::SetGrid( wxPropertyGrid
* pg
)
5871 // -----------------------------------------------------------------------
5873 wxPropertyGridPopulator
::~wxPropertyGridPopulator()
5876 // Free unused sets of choices
5877 wxPGHashMapS2P
::iterator it
;
5879 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5881 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5888 m_pg
->GetPanel()->Refresh();
5890 wxPGGlobalVars
->m_offline
--;
5893 // -----------------------------------------------------------------------
5895 wxPGProperty
* wxPropertyGridPopulator
::Add( const wxString
& propClass
,
5896 const wxString
& propLabel
,
5897 const wxString
& propName
,
5898 const wxString
* propValue
,
5899 wxPGChoices
* pChoices
)
5901 wxClassInfo
* classInfo
= wxClassInfo
::FindClass(propClass
);
5902 wxPGProperty
* parent
= GetCurParent();
5904 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5906 ProcessError(wxString
::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5910 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5912 ProcessError(wxString
::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5916 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5918 property
->SetLabel(propLabel
);
5919 property
->DoSetName(propName
);
5921 if ( pChoices
&& pChoices
->IsOk() )
5922 property
->SetChoices(*pChoices
);
5924 m_state
->DoInsert(parent
, -1, property
);
5927 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5928 wxPG_PROGRAMMATIC_VALUE
);
5933 // -----------------------------------------------------------------------
5935 void wxPropertyGridPopulator
::AddChildren( wxPGProperty
* property
)
5937 m_propHierarchy
.push_back(property
);
5938 DoScanForChildren();
5939 m_propHierarchy
.pop_back();
5942 // -----------------------------------------------------------------------
5944 wxPGChoices wxPropertyGridPopulator
::ParseChoices( const wxString
& choicesString
,
5945 const wxString
& idString
)
5947 wxPGChoices choices
;
5950 if ( choicesString
[0] == wxT('@') )
5952 wxString ids
= choicesString
.substr(1);
5953 wxPGHashMapS2P
::iterator it
= m_dictIdChoices
.find(ids
);
5954 if ( it
== m_dictIdChoices
.end() )
5955 ProcessError(wxString
::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5957 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5962 if ( idString
.length() )
5964 wxPGHashMapS2P
::iterator it
= m_dictIdChoices
.find(idString
);
5965 if ( it
!= m_dictIdChoices
.end() )
5967 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5974 // Parse choices string
5975 wxString
::const_iterator it
= choicesString
.begin();
5979 bool labelValid
= false;
5981 for ( ; it
!= choicesString
.end(); ++it
)
5987 if ( c
== wxT('"') )
5992 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5993 choices
.Add(label
, l
);
5996 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6001 else if ( c
== wxT('=') )
6008 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6015 if ( c
== wxT('"') )
6028 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6029 choices
.Add(label
, l
);
6032 if ( !choices
.IsOk() )
6034 choices
.EnsureData();
6038 if ( idString
.length() )
6039 m_dictIdChoices
[idString
] = choices
.GetData();
6046 // -----------------------------------------------------------------------
6048 bool wxPropertyGridPopulator
::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6050 if ( s
.Last() == wxT('%') )
6052 wxString s2
= s
.substr(0,s
.length()-1);
6054 if ( s2
.ToLong(&val
, 10) )
6056 *pval
= (val
*max
)/100;
6062 return s
.ToLong(pval
, 10);
6065 // -----------------------------------------------------------------------
6067 bool wxPropertyGridPopulator
::AddAttribute( const wxString
& name
,
6068 const wxString
& type
,
6069 const wxString
& value
)
6071 int l
= m_propHierarchy
.size();
6075 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6076 wxString valuel
= value
.Lower();
6079 if ( type
.length() == 0 )
6084 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6086 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6088 else if ( value
.ToLong(&v
, 0) )
6095 if ( type
== wxT("string") )
6099 else if ( type
== wxT("int") )
6102 value
.ToLong(&v
, 0);
6105 else if ( type
== wxT("bool") )
6107 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6114 ProcessError(wxString
::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6119 p
->SetAttribute( name
, variant
);
6124 // -----------------------------------------------------------------------
6126 void wxPropertyGridPopulator
::ProcessError( const wxString
& msg
)
6128 wxLogError(_("Error in resource: %s"),msg
.c_str());
6131 // -----------------------------------------------------------------------
6133 #endif // wxUSE_PROPGRID