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"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 #define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 #define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // -----------------------------------------------------------------------
239 // This class is a wxBrush derivative used in the background colour
240 // brush cache. It adds wxPG-type colour-in-long to the class.
241 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
242 // object does), but this is simpler implementation and equally
246 class wxPGBrush
: public wxBrush
249 wxPGBrush( const wxColour
& colour
);
251 virtual ~wxPGBrush() { }
252 void SetColour2( const wxColour
& colour
);
253 inline long GetColourAsLong() const { return m_colAsLong
; }
259 void wxPGBrush::SetColour2( const wxColour
& colour
)
261 wxBrush::SetColour(colour
);
262 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
266 wxPGBrush::wxPGBrush() : wxBrush()
272 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
274 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
278 // -----------------------------------------------------------------------
280 // -----------------------------------------------------------------------
283 // Same as wxPGBrush, but for wxColour instead.
286 class wxPGColour
: public wxColour
289 wxPGColour( const wxColour
& colour
);
291 virtual ~wxPGColour() { }
292 void SetColour2( const wxColour
& colour
);
293 inline long GetColourAsLong() const { return m_colAsLong
; }
299 void wxPGColour::SetColour2( const wxColour
& colour
)
302 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
306 wxPGColour::wxPGColour() : wxColour()
312 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
314 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
318 // -----------------------------------------------------------------------
320 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
321 // and tries to commit property value.
322 // -----------------------------------------------------------------------
324 class wxPGTLWHandler
: public wxEvtHandler
328 wxPGTLWHandler( wxPropertyGrid
* pg
)
336 void OnClose( wxCloseEvent
& event
)
338 // ClearSelection forces value validation/commit.
339 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
349 wxPropertyGrid
* m_pg
;
351 DECLARE_EVENT_TABLE()
354 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
355 EVT_CLOSE(wxPGTLWHandler::OnClose
)
358 // -----------------------------------------------------------------------
360 // -----------------------------------------------------------------------
363 // wxPGCanvas acts as a graphics sub-window of the
364 // wxScrolledWindow that wxPropertyGrid is.
366 class wxPGCanvas
: public wxPanel
369 wxPGCanvas() : wxPanel()
372 virtual ~wxPGCanvas() { }
375 void OnMouseMove( wxMouseEvent
&event
)
377 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
378 pg
->OnMouseMove( event
);
381 void OnMouseClick( wxMouseEvent
&event
)
383 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
384 pg
->OnMouseClick( event
);
387 void OnMouseUp( wxMouseEvent
&event
)
389 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
390 pg
->OnMouseUp( event
);
393 void OnMouseRightClick( wxMouseEvent
&event
)
395 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
396 pg
->OnMouseRightClick( event
);
399 void OnMouseDoubleClick( wxMouseEvent
&event
)
401 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
402 pg
->OnMouseDoubleClick( event
);
405 void OnKey( wxKeyEvent
& event
)
407 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
411 void OnKeyUp( wxKeyEvent
& event
)
413 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
414 pg
->OnKeyUp( event
);
417 void OnPaint( wxPaintEvent
& event
);
419 // Always be focussable, even with child windows
420 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
421 { wxPanel::SetCanFocus(true); }
425 DECLARE_EVENT_TABLE()
426 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
430 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
432 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
433 EVT_MOTION(wxPGCanvas::OnMouseMove
)
434 EVT_PAINT(wxPGCanvas::OnPaint
)
435 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
436 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
437 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
438 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
439 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
440 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
441 EVT_CHAR(wxPGCanvas::OnKey
)
445 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
447 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
448 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
452 // Don't paint after destruction has begun
453 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
456 // Update everything inside the box
457 wxRect r
= GetUpdateRegion().GetBox();
459 // Repaint this rectangle
460 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
462 // We assume that the size set when grid is shown
463 // is what is desired.
464 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
467 // -----------------------------------------------------------------------
469 // -----------------------------------------------------------------------
471 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
473 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
474 EVT_IDLE(wxPropertyGrid::OnIdle
)
475 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
476 EVT_PAINT(wxPropertyGrid::OnPaint
)
477 EVT_SIZE(wxPropertyGrid::OnResize
)
478 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
479 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
480 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
481 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
482 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
483 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
484 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
485 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
489 // -----------------------------------------------------------------------
491 wxPropertyGrid::wxPropertyGrid()
497 // -----------------------------------------------------------------------
499 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
508 Create(parent
,id
,pos
,size
,style
,name
);
511 // -----------------------------------------------------------------------
513 bool wxPropertyGrid::Create( wxWindow
*parent
,
521 if ( !(style
&wxBORDER_MASK
) )
522 style
|= wxSIMPLE_BORDER
;
527 // This prevents crash under Win2K, but still
528 // enables keyboard navigation
529 if ( style
& wxTAB_TRAVERSAL
)
531 style
&= ~(wxTAB_TRAVERSAL
);
532 style
|= wxWANTS_CHARS
;
535 if ( style
& wxTAB_TRAVERSAL
)
536 style
|= wxWANTS_CHARS
;
539 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
546 // -----------------------------------------------------------------------
549 // Initialize values to defaults
551 void wxPropertyGrid::Init1()
553 // Register editor classes, if necessary.
554 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
555 wxPropertyGrid::RegisterDefaultEditors();
558 m_pState
= (wxPropertyGridPageState
*) NULL
;
559 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
560 m_selected
= (wxPGProperty
*) NULL
;
562 m_propHover
= (wxPGProperty
*) NULL
;
563 m_eventObject
= this;
564 m_curFocused
= (wxWindow
*) NULL
;
566 m_inDoPropertyChanged
= 0;
567 m_inCommitChangesFromEditor
= 0;
568 m_inDoSelectProperty
= 0;
569 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
575 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
576 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
577 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
578 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
579 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
580 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
581 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
582 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
583 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
585 m_coloursCustomized
= 0;
590 #if wxPG_DOUBLE_BUFFER
591 m_doubleBuffer
= (wxBitmap
*) NULL
;
594 #ifndef wxPG_ICON_WIDTH
600 m_iconWidth
= wxPG_ICON_WIDTH
;
605 m_gutterWidth
= wxPG_GUTTER_MIN
;
606 m_subgroup_extramargin
= 10;
610 m_width
= m_height
= 0;
612 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
615 m_chgInfo_changedProperty
= NULL
;
618 // -----------------------------------------------------------------------
621 // Initialize after parent etc. set
623 void wxPropertyGrid::Init2()
625 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
628 // Smaller controls on Mac
629 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
632 // Now create state, if one didn't exist already
633 // (wxPropertyGridManager might have created it for us).
636 m_pState
= CreateState();
637 m_pState
->m_pPropGrid
= this;
638 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
641 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
642 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
644 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
646 m_pState
->InitNonCatMode();
648 m_pState
->m_properties
= m_pState
->m_abcArray
;
651 GetClientSize(&m_width
,&m_height
);
653 #ifndef wxPG_ICON_WIDTH
654 // create two bitmap nodes for drawing
655 m_expandbmp
= new wxBitmap(expand_xpm
);
656 m_collbmp
= new wxBitmap(collapse_xpm
);
658 // calculate average font height for bitmap centering
660 m_iconWidth
= m_expandbmp
->GetWidth();
661 m_iconHeight
= m_expandbmp
->GetHeight();
664 m_curcursor
= wxCURSOR_ARROW
;
665 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
667 // adjust bitmap icon y position so they are centered
668 m_vspacing
= wxPG_DEFAULT_VSPACING
;
672 wxFont useFont
= wxScrolledWindow::GetFont();
673 wxScrolledWindow::SetOwnFont( useFont
);
676 // This should be otherwise called by SetOwnFont
677 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
679 // Add base brush item
680 m_arrBgBrushes
.Add((void*)new wxPGBrush());
682 // Add base colour items
683 m_arrFgCols
.Add((void*)new wxPGColour());
684 m_arrFgCols
.Add((void*)new wxPGColour());
688 // This helps with flicker
689 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
692 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
693 m_tlp
= ::wxGetTopLevelParent(this);
694 m_tlwHandler
= handler
;
695 m_tlp
->PushEventHandler(handler
);
697 // set virtual size to this window size
698 wxSize wndsize
= GetSize();
699 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
701 m_timeCreated
= ::wxGetLocalTimeMillis();
703 m_canvas
= new wxPGCanvas();
704 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
705 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
706 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
708 m_iFlags
|= wxPG_FL_INITIALIZED
;
710 m_ncWidth
= wndsize
.GetWidth();
712 // Need to call OnResize handler or size given in constructor/Create
714 wxSizeEvent
sizeEvent(wndsize
,0);
718 // -----------------------------------------------------------------------
720 wxPropertyGrid::~wxPropertyGrid()
724 DoSelectProperty(NULL
);
726 // This should do prevent things from going too badly wrong
727 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
729 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
730 m_canvas
->ReleaseMouse();
732 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
733 m_tlp
->RemoveEventHandler(handler
);
737 if ( IsEditorsValueModified() )
738 ::wxMessageBox(wxS("Most recent change in property editor was lost!!!\n\n(if you don't want this to happen, close your frames and dialogs using Close(false).)"),
739 wxS("wxPropertyGrid Debug Warning") );
742 #if wxPG_DOUBLE_BUFFER
743 if ( m_doubleBuffer
)
744 delete m_doubleBuffer
;
747 //m_selected = (wxPGProperty*) NULL;
749 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
752 delete m_cursorSizeWE
;
754 #ifndef wxPG_ICON_WIDTH
759 // Delete cached text colours.
760 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
762 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
765 // Delete cached brushes.
766 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
768 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
771 // Delete common value records
772 for ( i
=0; i
<m_commonValues
.size(); i
++ )
774 delete GetCommonValue(i
);
778 // -----------------------------------------------------------------------
780 bool wxPropertyGrid::Destroy()
782 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
783 m_canvas
->ReleaseMouse();
785 return wxScrolledWindow::Destroy();
788 // -----------------------------------------------------------------------
790 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
792 return new wxPropertyGridPageState();
795 // -----------------------------------------------------------------------
796 // wxPropertyGrid overridden wxWindow methods
797 // -----------------------------------------------------------------------
799 void wxPropertyGrid::SetWindowStyleFlag( long style
)
801 long old_style
= m_windowStyle
;
803 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
805 wxASSERT( m_pState
);
807 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
810 EnableCategories( true );
812 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
814 // Disable categories
815 EnableCategories( false );
817 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
823 PrepareAfterItemsAdded();
825 m_pState
->m_itemsAdded
= 1;
827 #if wxPG_SUPPORT_TOOLTIPS
828 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
834 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
835 SetToolTip ( tooltip );
836 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
839 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
844 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
849 wxScrolledWindow::SetWindowStyleFlag ( style
);
851 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
853 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
855 CalculateFontAndBitmapStuff( m_vspacing
);
861 // -----------------------------------------------------------------------
863 void wxPropertyGrid::Freeze()
867 wxScrolledWindow::Freeze();
872 // -----------------------------------------------------------------------
874 void wxPropertyGrid::Thaw()
880 wxScrolledWindow::Thaw();
881 RecalculateVirtualSize();
882 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
886 // Force property re-selection
888 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
892 // -----------------------------------------------------------------------
894 void wxPropertyGrid::SetExtraStyle( long exStyle
)
896 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
898 #if defined(__WXMSW__)
901 // Don't use WS_EX_COMPOSITED just now.
904 if ( m_iFlags & wxPG_FL_IN_MANAGER )
905 hWnd = (HWND)GetParent()->GetHWND();
907 hWnd = (HWND)GetHWND();
909 ::SetWindowLong( hWnd, GWL_EXSTYLE,
910 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
913 //#elif defined(__WXGTK20__)
915 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
916 // truly was double-buffered.
917 if ( !this->IsDoubleBuffered() )
919 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
923 #if wxPG_DOUBLE_BUFFER
924 delete m_doubleBuffer
;
925 m_doubleBuffer
= NULL
;
930 wxScrolledWindow::SetExtraStyle( exStyle
);
932 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
933 m_pState
->InitNonCatMode();
935 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
936 m_windowStyle
|= wxPG_TOOLTIPS
;
939 wxPGGlobalVars
->m_extraStyle
= exStyle
;
942 // -----------------------------------------------------------------------
944 // returns the best acceptable minimal size
945 wxSize
wxPropertyGrid::DoGetBestSize() const
948 if ( m_lineHeight
> hei
)
950 wxSize sz
= wxSize( 60, hei
+40 );
956 // -----------------------------------------------------------------------
957 // wxPropertyGrid Font and Colour Methods
958 // -----------------------------------------------------------------------
960 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
964 m_captionFont
= wxScrolledWindow::GetFont();
966 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
967 m_subgroup_extramargin
= x
+ (x
/2);
970 #if wxPG_USE_RENDERER_NATIVE
971 m_iconWidth
= wxPG_ICON_WIDTH
;
972 #elif wxPG_ICON_WIDTH
974 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
975 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
976 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
980 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
981 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
982 m_gutterWidth
= wxPG_GUTTER_MIN
;
985 if ( vspacing
<= 1 ) vdiv
= 12;
986 else if ( vspacing
>= 3 ) vdiv
= 3;
988 m_spacingy
= m_fontHeight
/ vdiv
;
989 if ( m_spacingy
< wxPG_YSPACING_MIN
)
990 m_spacingy
= wxPG_YSPACING_MIN
;
993 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
994 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
996 m_captionFont
.SetWeight(wxBOLD
);
997 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
999 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1002 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1003 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1006 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1008 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1009 RecalculateVirtualSize();
1011 InvalidateBestSize();
1014 // -----------------------------------------------------------------------
1016 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1022 // -----------------------------------------------------------------------
1024 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1025 int ga
= 1000, int ba
= 1000,
1026 bool forceDifferent
= false)
1033 // Recursion guard (allow 2 max)
1034 static int isinside
= 0;
1036 wxCHECK_MSG( isinside
< 3,
1038 wxT("wxPGAdjustColour should not be recursively called more than once") );
1043 int g
= src
.Green();
1046 if ( r2
>255 ) r2
= 255;
1047 else if ( r2
<0) r2
= 0;
1049 if ( g2
>255 ) g2
= 255;
1050 else if ( g2
<0) g2
= 0;
1052 if ( b2
>255 ) b2
= 255;
1053 else if ( b2
<0) b2
= 0;
1055 // Make sure they are somewhat different
1056 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1057 dst
= wxPGAdjustColour(src
,-(ra
*2));
1059 dst
= wxColour(r2
,g2
,b2
);
1061 // Recursion guard (allow 2 max)
1068 static int wxPGGetColAvg( const wxColour
& col
)
1070 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1074 void wxPropertyGrid::RegainColours()
1076 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1078 if ( !(m_coloursCustomized
& 0x0002) )
1080 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1082 // Make sure colour is dark enough
1084 int colDec
= wxPGGetColAvg(col
) - 230;
1086 int colDec
= wxPGGetColAvg(col
) - 200;
1089 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1094 if ( !(m_coloursCustomized
& 0x0001) )
1095 m_colMargin
= m_colCapBack
;
1097 if ( !(m_coloursCustomized
& 0x0004) )
1104 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1105 m_colCapFore
= capForeCol
;
1107 // Set the cached colour as well.
1108 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1111 if ( !(m_coloursCustomized
& 0x0008) )
1113 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1114 m_colPropBack
= bgCol
;
1116 // Set the cached brush as well.
1117 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1120 if ( !(m_coloursCustomized
& 0x0010) )
1122 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1123 m_colPropFore
= fgCol
;
1125 // Set the cached colour as well.
1126 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1129 if ( !(m_coloursCustomized
& 0x0020) )
1130 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1132 if ( !(m_coloursCustomized
& 0x0040) )
1133 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1135 if ( !(m_coloursCustomized
& 0x0080) )
1136 m_colLine
= m_colCapBack
;
1138 if ( !(m_coloursCustomized
& 0x0100) )
1139 m_colDisPropFore
= m_colCapFore
;
1141 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1144 // -----------------------------------------------------------------------
1146 void wxPropertyGrid::ResetColours()
1148 m_coloursCustomized
= 0;
1155 // -----------------------------------------------------------------------
1157 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1159 // Must disable active editor.
1162 bool selRes
= ClearSelection();
1163 wxPG_CHECK_MSG_DBG( selRes
,
1165 wxT("failed to deselect a property (editor probably had invalid value)") );
1168 // TODO: Following code is disabled with wxMac because
1169 // it is reported to fail. I (JMS) cannot debug it
1170 // personally right now.
1171 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1172 #if 1 // !defined(__WXMAC__)
1173 bool res
= wxScrolledWindow::SetFont( font
);
1176 CalculateFontAndBitmapStuff( m_vspacing
);
1179 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1187 // TODO: Remove after SetFont crash fixed.
1188 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1190 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1196 // -----------------------------------------------------------------------
1198 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1201 m_coloursCustomized
|= 0x80;
1205 // -----------------------------------------------------------------------
1207 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1210 m_coloursCustomized
|= 0x01;
1214 // -----------------------------------------------------------------------
1216 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1218 m_colPropBack
= col
;
1219 m_coloursCustomized
|= 0x08;
1221 // Set the cached brush as well.
1222 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1227 // -----------------------------------------------------------------------
1229 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1231 m_colPropFore
= col
;
1232 m_coloursCustomized
|= 0x10;
1234 // Set the cached colour as well.
1235 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1240 // -----------------------------------------------------------------------
1242 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1244 m_colEmptySpace
= col
;
1249 // -----------------------------------------------------------------------
1251 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1253 m_colDisPropFore
= col
;
1254 m_coloursCustomized
|= 0x100;
1258 // -----------------------------------------------------------------------
1260 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1263 m_coloursCustomized
|= 0x20;
1267 // -----------------------------------------------------------------------
1269 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1272 m_coloursCustomized
|= 0x40;
1276 // -----------------------------------------------------------------------
1278 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1281 m_coloursCustomized
|= 0x02;
1285 // -----------------------------------------------------------------------
1287 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1290 m_coloursCustomized
|= 0x04;
1292 // Set the cached colour as well.
1293 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1298 // -----------------------------------------------------------------------
1300 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1302 unsigned char ind
= index
;
1304 p
->m_bgColIndex
= ind
;
1307 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1308 SetBackgroundColourIndex(p
->Item(i
),index
);
1311 // -----------------------------------------------------------------------
1313 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1315 wxPG_PROP_ARG_CALL_PROLOG()
1320 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1322 // As it is most likely that the previous colour is used, start comparison
1324 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1326 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1335 colInd
= m_arrBgBrushes
.size();
1336 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1337 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1341 SetBackgroundColourIndex(p
,colInd
);
1343 // If this was on a visible grid, then draw it.
1344 DrawItemAndChildren(p
);
1347 // -----------------------------------------------------------------------
1349 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1351 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1353 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1356 // -----------------------------------------------------------------------
1358 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1360 unsigned char ind
= index
;
1362 p
->m_fgColIndex
= ind
;
1364 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1367 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1368 SetTextColourIndex( p
->Item(i
), index
, flags
);
1372 // -----------------------------------------------------------------------
1374 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1379 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1381 // As it is most likely that the previous colour is used, start comparison
1383 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1385 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1394 colInd
= m_arrFgCols
.size();
1395 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1396 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1402 // -----------------------------------------------------------------------
1404 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1407 wxPG_PROP_ARG_CALL_PROLOG()
1409 if ( p
->IsCategory() )
1411 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1412 cat
->SetTextColIndex(CacheColour(colour
));
1418 flags
|= wxPG_RECURSE
;
1419 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1421 DrawItemAndChildren(p
);
1424 // -----------------------------------------------------------------------
1426 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1428 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1430 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1433 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1435 wxPG_PROP_ARG_CALL_PROLOG()
1437 SetBackgroundColourIndex( p
, 0 );
1438 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1440 if ( p
->IsCategory() )
1442 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1443 cat
->SetTextColIndex(1);
1447 // -----------------------------------------------------------------------
1448 // wxPropertyGrid property adding and removal
1449 // -----------------------------------------------------------------------
1451 void wxPropertyGrid::PrepareAfterItemsAdded()
1453 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1455 m_pState
->m_itemsAdded
= 0;
1457 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1460 RecalculateVirtualSize();
1463 // -----------------------------------------------------------------------
1464 // wxPropertyGrid property value setting and getting
1465 // -----------------------------------------------------------------------
1467 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1469 m_pState
->DoSetPropertyValueUnspecified(p
);
1470 DrawItemAndChildren(p
);
1472 wxPGProperty
* parent
= p
->GetParent();
1474 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1477 parent
= parent
->GetParent();
1481 // -----------------------------------------------------------------------
1482 // wxPropertyGrid property operations
1483 // -----------------------------------------------------------------------
1485 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1487 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1491 bool changed
= false;
1493 // Is it inside collapsed section?
1494 if ( !p
->IsVisible() )
1497 wxPGProperty
* parent
= p
->GetParent();
1498 wxPGProperty
* grandparent
= parent
->GetParent();
1500 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1501 Expand( grandparent
);
1509 GetViewStart(&vx
,&vy
);
1510 vy
*=wxPG_PIXELS_PER_UNIT
;
1516 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1517 m_iFlags
|= wxPG_FL_SCROLLED
;
1520 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1522 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1523 m_iFlags
|= wxPG_FL_SCROLLED
;
1533 // -----------------------------------------------------------------------
1534 // wxPropertyGrid helper methods called by properties
1535 // -----------------------------------------------------------------------
1537 // Control font changer helper.
1538 void wxPropertyGrid::SetCurControlBoldFont()
1540 wxASSERT( m_wndEditor
);
1541 m_wndEditor
->SetFont( m_captionFont
);
1544 // -----------------------------------------------------------------------
1546 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1549 #if wxPG_SMALL_SCREEN
1550 // On small-screen devices, always show dialogs with default position and size.
1551 return wxDefaultPosition
;
1553 int splitterX
= GetSplitterPosition();
1557 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1559 ImprovedClientToScreen( &x
, &y
);
1561 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1562 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1569 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1579 new_y
= y
+ m_lineHeight
;
1581 return wxPoint(new_x
,new_y
);
1585 // -----------------------------------------------------------------------
1587 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1589 if ( src_str
.length() == 0 )
1595 bool prev_is_slash
= false;
1597 wxString::const_iterator i
= src_str
.begin();
1601 for ( ; i
!= src_str
.end(); i
++ )
1605 if ( a
!= wxS('\\') )
1607 if ( !prev_is_slash
)
1613 if ( a
== wxS('n') )
1616 dst_str
<< wxS('\n');
1618 dst_str
<< wxS('\n');
1621 else if ( a
== wxS('t') )
1622 dst_str
<< wxS('\t');
1626 prev_is_slash
= false;
1630 if ( prev_is_slash
)
1632 dst_str
<< wxS('\\');
1633 prev_is_slash
= false;
1637 prev_is_slash
= true;
1644 // -----------------------------------------------------------------------
1646 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1648 if ( src_str
.length() == 0 )
1654 wxString::const_iterator i
= src_str
.begin();
1655 wxUniChar prev_a
= wxS('\0');
1659 for ( ; i
!= src_str
.end(); i
++ )
1663 if ( a
>= wxS(' ') )
1665 // This surely is not something that requires an escape sequence.
1670 // This might need...
1671 if ( a
== wxS('\r') )
1673 // DOS style line end.
1674 // Already taken care below
1676 else if ( a
== wxS('\n') )
1677 // UNIX style line end.
1678 dst_str
<< wxS("\\n");
1679 else if ( a
== wxS('\t') )
1681 dst_str
<< wxS('\t');
1684 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1694 // -----------------------------------------------------------------------
1696 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1700 return (wxPGProperty
*) NULL
;
1703 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1706 // -----------------------------------------------------------------------
1707 // wxPropertyGrid graphics related methods
1708 // -----------------------------------------------------------------------
1710 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1714 // Update everything inside the box
1715 wxRect r
= GetUpdateRegion().GetBox();
1717 dc
.SetPen(m_colEmptySpace
);
1718 dc
.SetBrush(m_colEmptySpace
);
1719 dc
.DrawRectangle(r
);
1722 // -----------------------------------------------------------------------
1724 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1725 wxPGProperty
* property
) const
1727 // Prepare rectangle to be used
1729 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1730 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1732 #if (wxPG_USE_RENDERER_NATIVE)
1734 #elif wxPG_ICON_WIDTH
1735 // Drawing expand/collapse button manually
1736 dc
.SetPen(m_colPropFore
);
1737 if ( property
->IsCategory() )
1738 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1740 dc
.SetBrush(m_colPropBack
);
1742 dc
.DrawRectangle( r
);
1743 int _y
= r
.y
+(m_iconWidth
/2);
1744 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1749 if ( property
->IsExpanded() )
1751 // wxRenderer functions are non-mutating in nature, so it
1752 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1753 // Hopefully this does not cause problems.
1754 #if (wxPG_USE_RENDERER_NATIVE)
1755 wxRendererNative::Get().DrawTreeItemButton(
1761 #elif wxPG_ICON_WIDTH
1770 #if (wxPG_USE_RENDERER_NATIVE)
1771 wxRendererNative::Get().DrawTreeItemButton(
1777 #elif wxPG_ICON_WIDTH
1778 int _x
= r
.x
+(m_iconWidth
/2);
1779 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1785 #if (wxPG_USE_RENDERER_NATIVE)
1787 #elif wxPG_ICON_WIDTH
1790 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1794 // -----------------------------------------------------------------------
1797 // This is the one called by OnPaint event handler and others.
1798 // topy and bottomy are already unscrolled (ie. physical)
1800 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1802 unsigned int bottomy
,
1803 const wxRect
* clipRect
)
1805 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1807 m_pState
->EnsureVirtualHeight();
1809 wxRect tempClipRect
;
1812 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1813 clipRect
= &tempClipRect
;
1816 // items added check
1817 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1819 int paintFinishY
= 0;
1821 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1824 bool isBuffered
= false;
1826 #if wxPG_DOUBLE_BUFFER
1827 wxMemoryDC
* bufferDC
= NULL
;
1829 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1831 if ( !m_doubleBuffer
)
1833 paintFinishY
= clipRect
->y
;
1838 bufferDC
= new wxMemoryDC();
1840 // If nothing was changed, then just copy from double-buffer
1841 bufferDC
->SelectObject( *m_doubleBuffer
);
1851 dc
.SetClippingRegion( *clipRect
);
1852 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1855 #if wxPG_DOUBLE_BUFFER
1858 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1859 bufferDC
, 0, 0, wxCOPY
);
1860 dc
.DestroyClippingRegion(); // Is this really necessary?
1866 // Clear area beyond bottomY?
1867 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1869 dc
.SetPen(m_colEmptySpace
);
1870 dc
.SetBrush(m_colEmptySpace
);
1871 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1875 // -----------------------------------------------------------------------
1877 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1878 const wxPGProperty
* firstItem
,
1879 const wxPGProperty
* lastItem
,
1880 const wxRect
* clipRect
,
1881 bool isBuffered
) const
1883 // TODO: This should somehow be eliminated.
1884 wxRect tempClipRect
;
1887 wxASSERT(firstItem
);
1889 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1890 clipRect
= &tempClipRect
;
1894 firstItem
= DoGetItemAtY(clipRect
->y
);
1898 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1900 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1903 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1906 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1907 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1909 int lh
= m_lineHeight
;
1912 int lastItemBottomY
;
1914 firstItemTopY
= clipRect
->y
;
1915 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1917 // Align y coordinates to item boundaries
1918 firstItemTopY
-= firstItemTopY
% lh
;
1919 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1920 lastItemBottomY
-= 1;
1922 // Entire range outside scrolled, visible area?
1923 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1926 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1930 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1931 firstItem->GetLabel().c_str(),
1932 lastItem->GetLabel().c_str(),
1933 (int)(lastItemBottomY - firstItemTopY),
1935 (unsigned long)clipRect );
1940 long windowStyle
= m_windowStyle
;
1946 // With wxPG_DOUBLE_BUFFER, do double buffering
1947 // - buffer's y = 0, so align cliprect and coordinates to that
1949 #if wxPG_DOUBLE_BUFFER
1955 xRelMod
= clipRect
->x
;
1956 yRelMod
= clipRect
->y
;
1959 // clipRect conversion
1967 firstItemTopY
-= yRelMod
;
1968 lastItemBottomY
-= yRelMod
;
1971 wxUnusedVar(isBuffered
);
1974 int x
= m_marginWidth
- xRelMod
;
1976 const wxFont
& normalfont
= m_font
;
1978 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1980 bool isEnabled
= IsEnabled();
1983 // Prepare some pens and brushes that are often changed to.
1986 wxBrush
marginBrush(m_colMargin
);
1987 wxPen
marginPen(m_colMargin
);
1988 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1989 wxPen
linepen(m_colLine
,1,wxSOLID
);
1991 // pen that has same colour as text
1992 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1995 // Clear margin with background colour
1997 dc
.SetBrush( marginBrush
);
1998 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2000 dc
.SetPen( *wxTRANSPARENT_PEN
);
2001 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2004 const wxPGProperty
* selected
= m_selected
;
2005 const wxPropertyGridPageState
* state
= m_pState
;
2007 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2008 bool wasSelectedPainted
= false;
2011 // TODO: Only render columns that are within clipping region.
2013 dc
.SetFont(normalfont
);
2015 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2016 int endScanBottomY
= lastItemBottomY
+ lh
;
2017 int y
= firstItemTopY
;
2020 // Pregenerate list of visible properties.
2021 wxArrayPGProperty visPropArray
;
2022 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2024 for ( ; !it
.AtEnd(); it
.Next() )
2026 const wxPGProperty
* p
= *it
;
2028 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2030 visPropArray
.push_back((wxPGProperty
*)p
);
2032 if ( y
> endScanBottomY
)
2039 visPropArray
.push_back(NULL
);
2041 wxPGProperty
* nextP
= visPropArray
[0];
2043 int gridWidth
= state
->m_width
;
2046 for ( unsigned int arrInd
=1;
2047 nextP
&& y
<= lastItemBottomY
;
2050 wxPGProperty
* p
= nextP
;
2051 nextP
= visPropArray
[arrInd
];
2053 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2054 int textMarginHere
= x
;
2055 int renderFlags
= wxPGCellRenderer::Control
;
2057 int greyDepth
= m_marginWidth
;
2058 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2059 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2061 int greyDepthX
= greyDepth
- xRelMod
;
2063 // Use basic depth if in non-categoric mode and parent is base array.
2064 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2066 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2069 // Paint margin area
2070 dc
.SetBrush(marginBrush
);
2071 dc
.SetPen(marginPen
);
2072 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2074 dc
.SetPen( linepen
);
2079 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2085 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2087 sx
+= state
->m_colWidths
[si
];
2088 dc
.DrawLine( sx
, y
, sx
, y2
);
2091 // Horizontal Line, below
2092 // (not if both this and next is category caption)
2093 if ( p
->IsCategory() &&
2094 nextP
&& nextP
->IsCategory() )
2095 dc
.SetPen(m_colCapBack
);
2097 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2099 if ( p
== selected
)
2101 renderFlags
|= wxPGCellRenderer::Selected
;
2102 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2103 wasSelectedPainted
= true;
2111 if ( p
->IsCategory() )
2113 if ( p
->m_fgColIndex
== 0 )
2114 rowFgCol
= m_colCapFore
;
2116 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2117 rowBgBrush
= wxBrush(m_colCapBack
);
2119 else if ( p
!= selected
)
2121 // Disabled may get different colour.
2122 if ( !p
->IsEnabled() )
2123 rowFgCol
= m_colDisPropFore
;
2125 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2127 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2131 // Selected gets different colour.
2132 if ( reallyFocused
)
2134 rowFgCol
= m_colSelFore
;
2135 rowBgBrush
= wxBrush(m_colSelBack
);
2137 else if ( isEnabled
)
2139 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2140 rowBgBrush
= marginBrush
;
2144 rowFgCol
= m_colDisPropFore
;
2145 rowBgBrush
= wxBrush(m_colSelBack
);
2149 bool fontChanged
= false;
2151 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2156 if ( p
->IsCategory() )
2158 // Captions are all cells merged as one
2159 dc
.SetFont(m_captionFont
);
2161 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2163 dc
.SetBrush(rowBgBrush
);
2164 dc
.SetPen(rowBgBrush
.GetColour());
2165 dc
.SetTextForeground(rowFgCol
);
2167 dc
.DrawRectangle(cellRect
);
2170 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2171 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2174 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2175 DrawExpanderButton( dc
, butRect
, p
);
2179 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2181 dc
.SetFont(m_captionFont
);
2187 int nextCellWidth
= state
->m_colWidths
[0];
2188 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2189 int textXAdd
= textMarginHere
- greyDepthX
;
2191 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2193 cellRect
.width
= nextCellWidth
- 1;
2195 bool ctrlCell
= false;
2198 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2200 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2201 dc
.SetBrush(editorBgCol
);
2202 dc
.SetPen(editorBgCol
);
2203 dc
.SetTextForeground(m_colPropFore
);
2205 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2210 dc
.SetBrush(rowBgBrush
);
2211 dc
.SetPen(rowBgBrush
.GetColour());
2212 dc
.SetTextForeground(rowFgCol
);
2215 dc
.DrawRectangle(cellRect
);
2218 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2219 DrawExpanderButton( dc
, butRect
, p
);
2221 dc
.SetClippingRegion(cellRect
);
2223 cellRect
.x
+= textXAdd
;
2224 cellRect
.width
-= textXAdd
;
2229 wxPGCellRenderer
* renderer
;
2230 int cmnVal
= p
->GetCommonValue();
2231 if ( cmnVal
== -1 || ci
!= 1 )
2233 renderer
= p
->GetCellRenderer(ci
);
2234 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2238 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2239 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2243 cellX
+= state
->m_colWidths
[ci
];
2244 if ( ci
< (state
->m_colWidths
.size()-1) )
2245 nextCellWidth
= state
->m_colWidths
[ci
+1];
2247 dc
.DestroyClippingRegion(); // Is this really necessary?
2253 dc
.SetFont(normalfont
);
2258 // Refresh editor controls (seems not needed on msw)
2259 // NOTE: This code is mandatory for GTK!
2260 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2261 if ( wasSelectedPainted
)
2264 m_wndEditor
->Refresh();
2266 m_wndEditor2
->Refresh();
2273 // -----------------------------------------------------------------------
2275 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2279 if ( m_width
< 10 || m_height
< 10 ||
2280 !m_pState
->m_properties
->GetChildCount() ||
2281 p1
== (wxPGProperty
*) NULL
)
2282 return wxRect(0,0,0,0);
2287 // Return rect which encloses the given property range
2289 int visTop
= p1
->GetY();
2292 visBottom
= p2
->GetY() + m_lineHeight
;
2294 visBottom
= m_height
+ visTop
;
2296 // If seleced property is inside the range, we'll extend the range to include
2298 wxPGProperty
* selected
= m_selected
;
2301 int selectedY
= selected
->GetY();
2302 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2304 wxWindow
* editor
= GetEditorControl();
2307 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2308 if ( visBottom2
> visBottom
)
2309 visBottom
= visBottom2
;
2314 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2317 // -----------------------------------------------------------------------
2319 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2324 if ( m_pState
->m_itemsAdded
)
2325 PrepareAfterItemsAdded();
2327 wxRect r
= GetPropertyRect(p1
, p2
);
2330 m_canvas
->RefreshRect(r
);
2334 // -----------------------------------------------------------------------
2336 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2338 if ( p
== m_selected
)
2339 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2341 DrawItemAndChildren(p
);
2344 // -----------------------------------------------------------------------
2346 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2351 // Draw item, children, and parent too, if it is not category
2352 wxPGProperty
* parent
= p
->GetParent();
2355 !parent
->IsCategory() &&
2356 parent
->GetParent() )
2359 parent
= parent
->GetParent();
2362 DrawItemAndChildren(p
);
2365 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2367 wxCHECK_RET( p
, wxT("invalid property id") );
2369 // Do not draw if in non-visible page
2370 if ( p
->GetParentState() != m_pState
)
2373 // do not draw a single item if multiple pending
2374 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2377 wxWindow
* wndPrimary
= GetEditorControl();
2379 // Update child control.
2380 if ( m_selected
&& m_selected
->GetParent() == p
)
2381 m_selected
->UpdateControl(wndPrimary
);
2383 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2385 DrawItems(p
, lastDrawn
);
2388 // -----------------------------------------------------------------------
2390 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2391 const wxRect
*rect
)
2393 PrepareAfterItemsAdded();
2395 wxWindow::Refresh(false);
2397 // TODO: Coordinate translation
2398 m_canvas
->Refresh(false, rect
);
2400 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2401 // I think this really helps only GTK+1.2
2402 if ( m_wndEditor
) m_wndEditor
->Refresh();
2403 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2407 // -----------------------------------------------------------------------
2408 // wxPropertyGrid global operations
2409 // -----------------------------------------------------------------------
2411 void wxPropertyGrid::Clear()
2415 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2416 wxPG_CHECK_RET_DBG( selRes
,
2417 wxT("failed to deselect a property (editor probably had invalid value)") );
2420 m_pState
->DoClear();
2426 RecalculateVirtualSize();
2428 // Need to clear some area at the end
2430 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2433 // -----------------------------------------------------------------------
2435 bool wxPropertyGrid::EnableCategories( bool enable
)
2437 if ( !ClearSelection() )
2443 // Enable categories
2446 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2451 // Disable categories
2453 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2456 if ( !m_pState
->EnableCategories(enable
) )
2461 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2463 m_pState
->m_itemsAdded
= 1; // force
2464 PrepareAfterItemsAdded();
2468 m_pState
->m_itemsAdded
= 1;
2470 // No need for RecalculateVirtualSize() here - it is already called in
2471 // wxPropertyGridPageState method above.
2478 // -----------------------------------------------------------------------
2480 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2482 wxASSERT( pNewState
);
2483 wxASSERT( pNewState
->GetGrid() );
2485 if ( pNewState
== m_pState
)
2488 wxPGProperty
* oldSelection
= m_selected
;
2493 bool selRes
= ClearSelection();
2494 wxPG_CHECK_RET_DBG( selRes
,
2495 wxT("failed to deselect a property (editor probably had invalid value)") );
2498 m_pState
->m_selected
= oldSelection
;
2500 bool orig_mode
= m_pState
->IsInNonCatMode();
2501 bool new_state_mode
= pNewState
->IsInNonCatMode();
2503 m_pState
= pNewState
;
2506 int pgWidth
= GetClientSize().x
;
2507 if ( HasVirtualWidth() )
2509 int minWidth
= pgWidth
;
2510 if ( pNewState
->m_width
< minWidth
)
2512 pNewState
->m_width
= minWidth
;
2513 pNewState
->CheckColumnWidths();
2519 // Just in case, fully re-center splitter
2520 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2521 pNewState
->m_fSplitterX
= -1.0;
2523 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2526 m_propHover
= (wxPGProperty
*) NULL
;
2528 // If necessary, convert state to correct mode.
2529 if ( orig_mode
!= new_state_mode
)
2531 // This should refresh as well.
2532 EnableCategories( orig_mode
?false:true );
2534 else if ( !m_frozen
)
2536 // Refresh, if not frozen.
2537 if ( m_pState
->m_itemsAdded
)
2538 PrepareAfterItemsAdded();
2541 if ( m_pState
->m_selected
)
2542 DoSelectProperty( m_pState
->m_selected
);
2544 RecalculateVirtualSize(0);
2548 m_pState
->m_itemsAdded
= 1;
2551 // -----------------------------------------------------------------------
2553 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2555 wxPG_PROP_ARG_CALL_PROLOG()
2557 m_pState
->SortChildren( p
);
2560 // -----------------------------------------------------------------------
2562 void wxPropertyGrid::Sort()
2564 bool selRes
= ClearSelection(); // This must be before state clear
2565 wxPG_CHECK_RET_DBG( selRes
,
2566 wxT("failed to deselect a property (editor probably had invalid value)") );
2571 // -----------------------------------------------------------------------
2573 // Call to SetSplitterPosition will always disable splitter auto-centering
2574 // if parent window is shown.
2575 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2577 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2580 wxPropertyGridPageState
* state
= m_pState
;
2582 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2587 CorrectEditorWidgetSizeX();
2593 // -----------------------------------------------------------------------
2595 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2597 SetSplitterPosition( m_width
/2, true );
2598 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2599 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2602 // -----------------------------------------------------------------------
2603 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2604 // -----------------------------------------------------------------------
2606 // Returns nearest paint visible property (such that will be painted unless
2607 // window is scrolled or resized). If given property is paint visible, then
2608 // it itself will be returned
2609 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2611 int vx
,vy1
;// Top left corner of client
2612 GetViewStart(&vx
,&vy1
);
2613 vy1
*= wxPG_PIXELS_PER_UNIT
;
2615 int vy2
= vy1
+ m_height
;
2616 int propY
= p
->GetY2(m_lineHeight
);
2618 if ( (propY
+ m_lineHeight
) < vy1
)
2621 return DoGetItemAtY( vy1
);
2623 else if ( propY
> vy2
)
2626 return DoGetItemAtY( vy2
);
2629 // Itself paint visible
2634 // -----------------------------------------------------------------------
2635 // Methods related to change in value, value modification and sending events
2636 // -----------------------------------------------------------------------
2638 // commits any changes in editor of selected property
2639 // return true if validation did not fail
2640 // flags are same as with DoSelectProperty
2641 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2643 // Committing already?
2644 if ( m_inCommitChangesFromEditor
)
2647 // Don't do this if already processing editor event. It might
2648 // induce recursive dialogs and crap like that.
2649 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2651 if ( m_inDoPropertyChanged
)
2658 IsEditorsValueModified() &&
2659 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2662 m_inCommitChangesFromEditor
= 1;
2664 wxVariant
variant(m_selected
->GetValueRef());
2665 bool valueIsPending
= false;
2667 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2668 // due to another window getting focus
2669 wxWindow
* oldFocus
= m_curFocused
;
2671 bool validationFailure
= false;
2672 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2674 m_chgInfo_changedProperty
= NULL
;
2676 // If truly modified, schedule value as pending.
2677 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2679 if ( DoEditorValidate() &&
2680 PerformValidation(m_selected
, variant
) )
2682 valueIsPending
= true;
2686 validationFailure
= true;
2691 EditorsValueWasNotModified();
2696 m_inCommitChangesFromEditor
= 0;
2698 if ( validationFailure
&& !forceSuccess
)
2702 oldFocus
->SetFocus();
2703 m_curFocused
= oldFocus
;
2706 res
= OnValidationFailure(m_selected
, variant
);
2708 // Now prevent further validation failure messages
2711 EditorsValueWasNotModified();
2712 OnValidationFailureReset(m_selected
);
2715 else if ( valueIsPending
)
2717 DoPropertyChanged( m_selected
, flags
);
2718 EditorsValueWasNotModified();
2727 // -----------------------------------------------------------------------
2729 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2733 // Runs all validation functionality.
2734 // Returns true if value passes all tests.
2737 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2739 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2741 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2746 // Adapt list to child values, if necessary
2747 wxVariant listValue
= pendingValue
;
2748 wxVariant
* pPendingValue
= &pendingValue
;
2749 wxVariant
* pList
= NULL
;
2751 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2752 // string value, then we need treat as it was changed instead
2753 // (or, in addition, as is the case with composite string parent).
2754 // This includes creating list variant for child values.
2756 wxPGProperty
* pwc
= p
->GetParent();
2757 wxPGProperty
* changedProperty
= p
;
2758 wxPGProperty
* baseChangedProperty
= changedProperty
;
2759 wxVariant bcpPendingList
;
2761 listValue
= pendingValue
;
2762 listValue
.SetName(p
->GetBaseName());
2765 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2767 wxVariantList tempList
;
2768 wxVariant
lv(tempList
, pwc
->GetBaseName());
2769 lv
.Append(listValue
);
2771 pPendingValue
= &listValue
;
2773 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2775 baseChangedProperty
= pwc
;
2776 bcpPendingList
= lv
;
2779 changedProperty
= pwc
;
2780 pwc
= pwc
->GetParent();
2784 wxPGProperty
* evtChangingProperty
= changedProperty
;
2786 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2788 value
= *pPendingValue
;
2792 // Convert list to child values
2793 pList
= pPendingValue
;
2794 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2797 wxVariant evtChangingValue
= value
;
2799 if ( flags
& SendEvtChanging
)
2801 // FIXME: After proper ValueToString()s added, remove
2802 // this. It is just a temporary fix, as evt_changing
2803 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2804 // (unless it is selected, and textctrl editor is open).
2805 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2807 evtChangingProperty
= baseChangedProperty
;
2808 if ( evtChangingProperty
!= p
)
2810 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2814 evtChangingValue
= pendingValue
;
2818 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2820 if ( changedProperty
== m_selected
)
2822 wxWindow
* editor
= GetEditorControl();
2823 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2824 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2828 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2833 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2834 m_chgInfo_changedProperty
= changedProperty
;
2835 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2836 m_chgInfo_pendingValue
= value
;
2839 m_chgInfo_valueList
= *pList
;
2841 m_chgInfo_valueList
.MakeNull();
2843 // If changedProperty is not property which value was edited,
2844 // then call wxPGProperty::ValidateValue() for that as well.
2845 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2847 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2851 if ( flags
& SendEvtChanging
)
2853 // SendEvent returns true if event was vetoed
2854 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2858 if ( flags
& IsStandaloneValidation
)
2860 // If called in 'generic' context, we need to reset
2861 // m_chgInfo_changedProperty and write back translated value.
2862 m_chgInfo_changedProperty
= NULL
;
2863 pendingValue
= value
;
2869 // -----------------------------------------------------------------------
2871 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2873 if ( !msg
.length() )
2877 if ( !wxPGGlobalVars
->m_offline
)
2879 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2882 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2885 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2888 pStatusBar
->SetStatusText(msg
);
2896 ::wxMessageBox(msg
, _T("Property Error"));
2899 // -----------------------------------------------------------------------
2901 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2903 int vfb
= m_validationInfo
.m_failureBehavior
;
2905 if ( vfb
& wxPG_VFB_BEEP
)
2908 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2909 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2911 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2912 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2914 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2916 wxColour vfbFg
= *wxWHITE
;
2917 wxColour vfbBg
= *wxRED
;
2918 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2919 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2921 DrawItemAndChildren(property
);
2923 if ( property
== m_selected
)
2925 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2927 wxWindow
* editor
= GetEditorControl();
2930 editor
->SetForegroundColour(vfbFg
);
2931 editor
->SetBackgroundColour(vfbBg
);
2937 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2939 wxString msg
= m_validationInfo
.m_failureMessage
;
2941 if ( !msg
.length() )
2942 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2944 DoShowPropertyError(property
, msg
);
2947 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2950 // -----------------------------------------------------------------------
2952 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2954 int vfb
= m_validationInfo
.m_failureBehavior
;
2956 if ( vfb
& wxPG_VFB_MARK_CELL
)
2958 property
->SetCell(0, NULL
);
2959 property
->SetCell(1, NULL
);
2961 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2963 if ( property
== m_selected
&& GetEditorControl() )
2965 // Calling this will recreate the control, thus resetting its colour
2966 RefreshProperty(property
);
2970 DrawItemAndChildren(property
);
2975 // -----------------------------------------------------------------------
2977 // flags are same as with DoSelectProperty
2978 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2980 if ( m_inDoPropertyChanged
)
2983 wxWindow
* editor
= GetEditorControl();
2985 m_pState
->m_anyModified
= 1;
2987 m_inDoPropertyChanged
= 1;
2989 // Maybe need to update control
2990 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2992 // These values were calculated in PerformValidation()
2993 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2994 wxVariant value
= m_chgInfo_pendingValue
;
2996 wxPGProperty
* topPaintedProperty
= changedProperty
;
2998 while ( !topPaintedProperty
->IsCategory() &&
2999 !topPaintedProperty
->IsRoot() )
3001 topPaintedProperty
= topPaintedProperty
->GetParent();
3004 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3006 // Set as Modified (not if dragging just began)
3007 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3009 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3010 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3013 SetCurControlBoldFont();
3019 // Propagate updates to parent(s)
3021 wxPGProperty
* prevPwc
= NULL
;
3023 while ( prevPwc
!= topPaintedProperty
)
3025 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3027 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3030 SetCurControlBoldFont();
3034 pwc
= pwc
->GetParent();
3037 // Draw the actual property
3038 DrawItemAndChildren( topPaintedProperty
);
3041 // If value was set by wxPGProperty::OnEvent, then update the editor
3043 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3046 p
->GetEditorClass()->UpdateControl(p
, editor
);
3050 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3051 if ( m_wndEditor
) m_wndEditor
->Refresh();
3052 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3057 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3059 // If top parent has composite string value, then send to child parents,
3060 // starting from baseChangedProperty.
3061 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3063 pwc
= m_chgInfo_baseChangedProperty
;
3065 while ( pwc
!= changedProperty
)
3067 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3068 pwc
= pwc
->GetParent();
3072 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3074 m_inDoPropertyChanged
= 0;
3079 // -----------------------------------------------------------------------
3081 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3083 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3085 m_chgInfo_changedProperty
= NULL
;
3087 if ( PerformValidation(p
, newValue
) )
3089 DoPropertyChanged(p
);
3094 OnValidationFailure(p
, newValue
);
3100 // -----------------------------------------------------------------------
3102 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3104 wxPGProperty
* prop
= GetSelectedProperty();
3107 return wxNullVariant
;
3109 wxTextCtrl
* tc
= GetEditorTextCtrl();
3110 wxVariant value
= prop
->GetValue();
3112 if ( !tc
|| !IsEditorsValueModified() )
3115 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3118 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3119 return prop
->GetValue();
3124 // -----------------------------------------------------------------------
3126 // Runs wxValidator for the selected property
3127 bool wxPropertyGrid::DoEditorValidate()
3132 // -----------------------------------------------------------------------
3134 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3136 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3137 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3139 wxWindow
* parent
= wnd
->GetParent();
3142 (parent
== m_canvas
||
3143 parent
->GetParent() == m_canvas
) )
3145 OnCustomEditorEvent((wxCommandEvent
&)event
);
3149 return wxPanel::ProcessEvent(event
);
3152 // -----------------------------------------------------------------------
3154 // NB: It may really not be wxCommandEvent - must check if necessary
3156 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3158 wxPGProperty
* selected
= m_selected
;
3160 // Somehow, event is handled after property has been deselected.
3161 // Possibly, but very rare.
3165 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3168 wxVariant
pendingValue(selected
->GetValueRef());
3169 wxWindow
* wnd
= GetEditorControl();
3171 bool wasUnspecified
= selected
->IsValueUnspecified();
3172 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3174 bool valueIsPending
= false;
3176 m_chgInfo_changedProperty
= NULL
;
3178 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3181 // Filter out excess wxTextCtrl modified events
3182 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3184 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3186 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3188 wxString newTcValue
= tc
->GetValue();
3189 if ( m_prevTcValue
== newTcValue
)
3192 m_prevTcValue
= newTcValue
;
3195 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3197 bool validationFailure
= false;
3198 bool buttonWasHandled
= false;
3201 // Try common button handling
3202 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3204 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3208 buttonWasHandled
= true;
3209 // Store as res2, as previously (and still currently alternatively)
3210 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3211 // in wxPGProperty::OnEvent().
3212 adapter
->ShowDialog( this, selected
);
3217 if ( !buttonWasHandled
)
3221 // First call editor class' event handler.
3222 const wxPGEditor
* editor
= selected
->GetEditorClass();
3224 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3226 // If changes, validate them
3227 if ( DoEditorValidate() )
3229 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3230 valueIsPending
= true;
3234 validationFailure
= true;
3239 // Then the property's custom handler (must be always called, unless
3240 // validation failed).
3241 if ( !validationFailure
)
3242 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3245 // SetValueInEvent(), as called in one of the functions referred above
3246 // overrides editor's value.
3247 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3249 valueIsPending
= true;
3250 pendingValue
= m_changeInEventValue
;
3251 selFlags
|= wxPG_SEL_DIALOGVAL
;
3254 if ( !validationFailure
&& valueIsPending
)
3255 if ( !PerformValidation(m_selected
, pendingValue
) )
3256 validationFailure
= true;
3258 if ( validationFailure
)
3260 OnValidationFailure(selected
, pendingValue
);
3262 else if ( valueIsPending
)
3264 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3266 DoPropertyChanged(selected
, selFlags
);
3267 EditorsValueWasNotModified();
3269 // Regardless of editor type, unfocus editor on
3270 // text-editing related enter press.
3271 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3278 // No value after all
3280 // Regardless of editor type, unfocus editor on
3281 // text-editing related enter press.
3282 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3287 // Let unhandled button click events go to the parent
3288 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3290 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3291 GetEventHandler()->AddPendingEvent(evt
);
3295 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3298 // -----------------------------------------------------------------------
3299 // wxPropertyGrid editor control helper methods
3300 // -----------------------------------------------------------------------
3302 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3304 int itemy
= p
->GetY2(m_lineHeight
);
3306 int cust_img_space
= 0;
3307 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3308 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3310 // TODO: If custom image detection changes from current, change this.
3311 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3313 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3314 int imwid
= p
->OnMeasureImage().x
;
3315 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3316 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3321 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3323 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3328 // -----------------------------------------------------------------------
3330 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3332 wxSize sz
= GetImageSize(p
, item
);
3333 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3334 wxPG_CUSTOM_IMAGE_SPACINGY
,
3339 // return size of custom paint image
3340 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3342 // If called with NULL property, then return default image
3343 // size for properties that use image.
3345 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3347 wxSize cis
= p
->OnMeasureImage(item
);
3349 int choiceCount
= p
->m_choices
.GetCount();
3350 int comVals
= p
->GetDisplayedCommonValueCount();
3351 if ( item
>= choiceCount
&& comVals
> 0 )
3353 unsigned int cvi
= item
-choiceCount
;
3354 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3356 else if ( item
>= 0 && choiceCount
== 0 )
3357 return wxSize(0, 0);
3362 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3367 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3374 // -----------------------------------------------------------------------
3376 // takes scrolling into account
3377 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3380 GetViewStart(&vx
,&vy
);
3381 vy
*=wxPG_PIXELS_PER_UNIT
;
3382 vx
*=wxPG_PIXELS_PER_UNIT
;
3385 ClientToScreen( px
, py
);
3388 // -----------------------------------------------------------------------
3390 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3393 GetViewStart(&pt2
.x
,&pt2
.y
);
3394 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3395 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3399 return m_pState
->HitTest(pt2
);
3402 // -----------------------------------------------------------------------
3404 // custom set cursor
3405 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3407 if ( type
== m_curcursor
&& !override
) return;
3409 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3411 if ( type
== wxCURSOR_SIZEWE
)
3412 cursor
= m_cursorSizeWE
;
3414 m_canvas
->SetCursor( *cursor
);
3419 // -----------------------------------------------------------------------
3420 // wxPropertyGrid property selection
3421 // -----------------------------------------------------------------------
3423 // Setups event handling for child control
3424 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3426 wxWindowID id
= argWnd
->GetId();
3428 if ( argWnd
== m_wndEditor
)
3430 argWnd
->Connect(id
, wxEVT_MOTION
,
3431 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3433 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3434 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3436 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3437 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3439 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3440 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3442 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3443 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3445 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3446 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3448 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3449 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3454 void wxPropertyGrid::FreeEditors()
3457 // Return focus back to canvas from children (this is required at least for
3458 // GTK+, which, unlike Windows, clears focus when control is destroyed
3459 // instead of moving it to closest parent).
3460 wxWindow
* focus
= wxWindow::FindFocus();
3463 wxWindow
* parent
= focus
->GetParent();
3466 if ( parent
== m_canvas
)
3471 parent
= parent
->GetParent();
3475 // Do not free editors immediately if processing events
3478 m_wndEditor2
->Hide();
3479 wxPendingDelete
.Append( m_wndEditor2
);
3480 m_wndEditor2
= (wxWindow
*) NULL
;
3485 m_wndEditor
->Hide();
3486 wxPendingDelete
.Append( m_wndEditor
);
3487 m_wndEditor
= (wxWindow
*) NULL
;
3491 // Call with NULL to de-select property
3492 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3494 wxPanel
* canvas
= GetPanel();
3498 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3499 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3501 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3504 if ( m_inDoSelectProperty
)
3507 m_inDoSelectProperty
= 1;
3509 wxPGProperty
* prev
= m_selected
;
3513 m_inDoSelectProperty
= 0;
3519 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3521 wxPrintf( "None selected\n" );
3524 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3526 wxPrintf( "P = NULL\n" );
3529 // If we are frozen, then just set the values.
3532 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3533 m_editorFocused
= 0;
3536 m_pState
->m_selected
= p
;
3538 // If frozen, always free controls. But don't worry, as Thaw will
3539 // recall SelectProperty to recreate them.
3542 // Prevent any further selection measures in this call
3543 p
= (wxPGProperty
*) NULL
;
3548 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3550 // Only set focus if not deselecting
3553 if ( flags
& wxPG_SEL_FOCUS
)
3557 m_wndEditor
->SetFocus();
3558 m_editorFocused
= 1;
3567 m_inDoSelectProperty
= 0;
3572 // First, deactivate previous
3576 OnValidationFailureReset(m_selected
);
3578 // Must double-check if this is an selected in case of forceswitch
3581 if ( !CommitChangesFromEditor(flags
) )
3583 // Validation has failed, so we can't exit the previous editor
3584 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3585 // _("Invalid Value"),wxOK|wxICON_ERROR);
3586 m_inDoSelectProperty
= 0;
3594 m_selected
= (wxPGProperty
*) NULL
;
3595 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3597 // We need to always fully refresh the grid here
3600 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3601 EditorsValueWasNotModified();
3604 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3607 // Then, activate the one given.
3610 int propY
= p
->GetY2(m_lineHeight
);
3612 int splitterX
= GetSplitterPosition();
3613 m_editorFocused
= 0;
3615 m_pState
->m_selected
= p
;
3616 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3618 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3620 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3622 // Do we need OnMeasureCalls?
3623 wxSize imsz
= p
->OnMeasureImage();
3626 // Only create editor for non-disabled non-caption
3627 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3629 // do this for non-caption items
3633 // Do we need to paint the custom image, if any?
3634 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3635 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3636 !p
->GetEditorClass()->CanContainCustomImage()
3638 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3640 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3641 wxPoint goodPos
= grect
.GetPosition();
3642 #if wxPG_CREATE_CONTROLS_HIDDEN
3643 int coord_adjust
= m_height
- goodPos
.y
;
3644 goodPos
.y
+= coord_adjust
;
3647 const wxPGEditor
* editor
= p
->GetEditorClass();
3648 wxCHECK_MSG(editor
, false,
3649 wxT("NULL editor class not allowed"));
3651 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3653 wxPGWindowList wndList
= editor
->CreateControls(this,
3658 m_wndEditor
= wndList
.m_primary
;
3659 m_wndEditor2
= wndList
.m_secondary
;
3660 wxWindow
* primaryCtrl
= GetEditorControl();
3663 // Essentially, primaryCtrl == m_wndEditor
3666 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3667 // value is drawn as normal, and m_wndEditor2 is assumed
3668 // to be a right-aligned button that triggers a separate editorCtrl
3673 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3674 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3676 // Set validator, if any
3677 #if wxUSE_VALIDATORS
3678 wxValidator
* validator
= p
->GetValidator();
3680 primaryCtrl
->SetValidator(*validator
);
3683 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3684 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3686 // If it has modified status, use bold font
3687 // (must be done before capturing m_ctrlXAdjust)
3688 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3689 SetCurControlBoldFont();
3692 // Fix TextCtrl indentation
3693 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3694 wxTextCtrl
* tc
= NULL
;
3695 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3696 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3698 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3700 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3703 // Store x relative to splitter (we'll need it).
3704 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3706 // Check if background clear is not necessary
3707 wxPoint pos
= m_wndEditor
->GetPosition();
3708 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3710 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3713 m_wndEditor
->SetSizeHints(3, 3);
3715 #if wxPG_CREATE_CONTROLS_HIDDEN
3716 m_wndEditor
->Show(false);
3717 m_wndEditor
->Freeze();
3719 goodPos
= m_wndEditor
->GetPosition();
3720 goodPos
.y
-= coord_adjust
;
3721 m_wndEditor
->Move( goodPos
);
3724 SetupChildEventHandling(primaryCtrl
);
3726 // Focus and select all (wxTextCtrl, wxComboBox etc)
3727 if ( flags
& wxPG_SEL_FOCUS
)
3729 primaryCtrl
->SetFocus();
3731 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3737 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3738 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3740 // Get proper id for wndSecondary
3741 m_wndSecId
= m_wndEditor2
->GetId();
3742 wxWindowList children
= m_wndEditor2
->GetChildren();
3743 wxWindowList::iterator node
= children
.begin();
3744 if ( node
!= children
.end() )
3745 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3747 m_wndEditor2
->SetSizeHints(3,3);
3749 #if wxPG_CREATE_CONTROLS_HIDDEN
3750 wxRect sec_rect
= m_wndEditor2
->GetRect();
3751 sec_rect
.y
-= coord_adjust
;
3753 // Fine tuning required to fix "oversized"
3754 // button disappearance bug.
3755 if ( sec_rect
.y
< 0 )
3757 sec_rect
.height
+= sec_rect
.y
;
3760 m_wndEditor2
->SetSize( sec_rect
);
3762 m_wndEditor2
->Show();
3764 SetupChildEventHandling(m_wndEditor2
);
3766 // If no primary editor, focus to button to allow
3767 // it to interprete ENTER etc.
3768 // NOTE: Due to problems focusing away from it, this
3769 // has been disabled.
3771 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3772 m_wndEditor2->SetFocus();
3776 if ( flags
& wxPG_SEL_FOCUS
)
3777 m_editorFocused
= 1;
3782 // Make sure focus is in grid canvas (important for wxGTK, at least)
3786 EditorsValueWasNotModified();
3788 // If it's inside collapsed section, expand parent, scroll, etc.
3789 // Also, if it was partially visible, scroll it into view.
3790 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3795 #if wxPG_CREATE_CONTROLS_HIDDEN
3796 m_wndEditor
->Thaw();
3798 m_wndEditor
->Show(true);
3805 // Make sure focus is in grid canvas
3809 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3815 // Show help text in status bar.
3816 // (if found and grid not embedded in manager with help box and
3817 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3820 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3822 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3823 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3825 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3827 statusbar
= frame
->GetStatusBar();
3832 const wxString
* pHelpString
= (const wxString
*) NULL
;
3836 pHelpString
= &p
->GetHelpString();
3837 if ( pHelpString
->length() )
3839 // Set help box text.
3840 statusbar
->SetStatusText( *pHelpString
);
3841 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3845 if ( (!pHelpString
|| !pHelpString
->length()) &&
3846 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3848 // Clear help box - but only if it was written
3849 // by us at previous time.
3850 statusbar
->SetStatusText( m_emptyString
);
3851 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3857 m_inDoSelectProperty
= 0;
3859 // call wx event handler (here so that it also occurs on deselection)
3860 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3865 // -----------------------------------------------------------------------
3867 bool wxPropertyGrid::UnfocusEditor()
3869 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3872 if ( !CommitChangesFromEditor(0) )
3876 DrawItem(m_selected
);
3881 // -----------------------------------------------------------------------
3883 // This method is not inline because it called dozens of times
3884 // (i.e. two-arg function calls create smaller code size).
3885 bool wxPropertyGrid::DoClearSelection()
3887 return DoSelectProperty((wxPGProperty
*)NULL
);
3890 // -----------------------------------------------------------------------
3891 // wxPropertyGrid expand/collapse state
3892 // -----------------------------------------------------------------------
3894 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3896 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3898 // If active editor was inside collapsed section, then disable it
3899 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3901 if ( !ClearSelection() )
3905 // Store dont-center-splitter flag 'cause we need to temporarily set it
3906 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3907 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3909 bool res
= m_pState
->DoCollapse(pwc
);
3914 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3916 RecalculateVirtualSize();
3918 // Redraw etc. only if collapsed was visible.
3919 if (pwc
->IsVisible() &&
3921 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3923 // When item is collapsed so that scrollbar would move,
3924 // graphics mess is about (unless we redraw everything).
3929 // Clear dont-center-splitter flag if it wasn't set
3930 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3935 // -----------------------------------------------------------------------
3937 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3939 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3941 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3943 // Store dont-center-splitter flag 'cause we need to temporarily set it
3944 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3945 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3947 bool res
= m_pState
->DoExpand(pwc
);
3952 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3954 RecalculateVirtualSize();
3956 // Redraw etc. only if expanded was visible.
3957 if ( pwc
->IsVisible() && !m_frozen
&&
3958 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3962 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3965 DrawItems(pwc
, NULL
);
3970 // Clear dont-center-splitter flag if it wasn't set
3971 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3976 // -----------------------------------------------------------------------
3978 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3981 return m_pState
->DoHideProperty(p
, hide
, flags
);
3984 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3987 if ( !ClearSelection() )
3991 m_pState
->DoHideProperty(p
, hide
, flags
);
3993 RecalculateVirtualSize();
4000 // -----------------------------------------------------------------------
4001 // wxPropertyGrid size related methods
4002 // -----------------------------------------------------------------------
4004 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4006 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4010 // If virtual height was changed, then recalculate editor control position(s)
4011 if ( m_pState
->m_vhCalcPending
)
4012 CorrectEditorWidgetPosY();
4014 m_pState
->EnsureVirtualHeight();
4017 int by1
= m_pState
->GetVirtualHeight();
4018 int by2
= m_pState
->GetActualVirtualHeight();
4021 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4022 wxASSERT_MSG( false,
4028 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4030 int x
= m_pState
->m_width
;
4031 int y
= m_pState
->m_virtualHeight
;
4034 GetClientSize(&width
,&height
);
4036 // Now adjust virtual size.
4037 SetVirtualSize(x
, y
);
4043 // Adjust scrollbars
4044 if ( HasVirtualWidth() )
4046 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4047 xPos
= GetScrollPos( wxHORIZONTAL
);
4050 if ( forceXPos
!= -1 )
4053 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4056 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4057 int yPos
= GetScrollPos( wxVERTICAL
);
4059 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4060 xAmount
, yAmount
, xPos
, yPos
, true );
4062 // Must re-get size now
4063 GetClientSize(&width
,&height
);
4065 if ( !HasVirtualWidth() )
4067 m_pState
->SetVirtualWidth(width
);
4074 m_canvas
->SetSize( x
, y
);
4076 m_pState
->CheckColumnWidths();
4079 CorrectEditorWidgetSizeX();
4081 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4084 // -----------------------------------------------------------------------
4086 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4088 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4092 GetClientSize(&width
,&height
);
4097 #if wxPG_DOUBLE_BUFFER
4098 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4100 int dblh
= (m_lineHeight
*2);
4101 if ( !m_doubleBuffer
)
4103 // Create double buffer bitmap to draw on, if none
4104 int w
= (width
>250)?width
:250;
4105 int h
= height
+ dblh
;
4107 m_doubleBuffer
= new wxBitmap( w
, h
);
4111 int w
= m_doubleBuffer
->GetWidth();
4112 int h
= m_doubleBuffer
->GetHeight();
4114 // Double buffer must be large enough
4115 if ( w
< width
|| h
< (height
+dblh
) )
4117 if ( w
< width
) w
= width
;
4118 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4119 delete m_doubleBuffer
;
4120 m_doubleBuffer
= new wxBitmap( w
, h
);
4127 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4128 m_ncWidth
= event
.GetSize().x
;
4132 if ( m_pState
->m_itemsAdded
)
4133 PrepareAfterItemsAdded();
4135 // Without this, virtual size (atleast under wxGTK) will be skewed
4136 RecalculateVirtualSize();
4142 // -----------------------------------------------------------------------
4144 void wxPropertyGrid::SetVirtualWidth( int width
)
4148 // Disable virtual width
4149 width
= GetClientSize().x
;
4150 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4154 // Enable virtual width
4155 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4157 m_pState
->SetVirtualWidth( width
);
4160 void wxPropertyGrid::SetFocusOnCanvas()
4162 m_canvas
->SetFocusIgnoringChildren();
4163 m_editorFocused
= 0;
4166 // -----------------------------------------------------------------------
4167 // wxPropertyGrid mouse event handling
4168 // -----------------------------------------------------------------------
4170 // selFlags uses same values DoSelectProperty's flags
4171 // Returns true if event was vetoed.
4172 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4174 // Send property grid event of specific type and with specific property
4175 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4176 evt
.SetPropertyGrid(this);
4177 evt
.SetEventObject(m_eventObject
);
4181 evt
.SetCanVeto(true);
4182 evt
.SetupValidationInfo();
4183 m_validationInfo
.m_pValue
= pValue
;
4185 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4187 evtHandler
->ProcessEvent(evt
);
4189 return evt
.WasVetoed();
4192 // -----------------------------------------------------------------------
4194 // Return false if should be skipped
4195 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4199 // Need to set focus?
4200 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4205 wxPropertyGridPageState
* state
= m_pState
;
4207 int splitterHitOffset
;
4208 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4210 wxPGProperty
* p
= DoGetItemAtY(y
);
4214 int depth
= (int)p
->GetDepth() - 1;
4216 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4218 if ( x
>= marginEnds
)
4222 if ( p
->IsCategory() )
4224 // This is category.
4225 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4227 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4229 // Expand, collapse, activate etc. if click on text or left of splitter.
4232 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4237 if ( !DoSelectProperty( p
) )
4240 // On double-click, expand/collapse.
4241 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4243 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4244 else DoExpand( p
, true );
4248 else if ( splitterHit
== -1 )
4251 unsigned int selFlag
= 0;
4252 if ( columnHit
== 1 )
4254 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4255 selFlag
= wxPG_SEL_FOCUS
;
4257 if ( !DoSelectProperty( p
, selFlag
) )
4260 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4262 if ( p
->GetChildCount() && !p
->IsCategory() )
4263 // On double-click, expand/collapse.
4264 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4266 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4267 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4268 else DoExpand( p
, true );
4275 // click on splitter
4276 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4278 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4280 // Double-clicking the splitter causes auto-centering
4281 CenterSplitter( true );
4283 else if ( m_dragStatus
== 0 )
4286 // Begin draggin the splitter
4290 // Changes must be committed here or the
4291 // value won't be drawn correctly
4292 if ( !CommitChangesFromEditor() )
4295 m_wndEditor
->Show ( false );
4298 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4300 m_canvas
->CaptureMouse();
4301 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4305 m_draggedSplitter
= splitterHit
;
4306 m_dragOffset
= splitterHitOffset
;
4308 wxClientDC
dc(m_canvas
);
4310 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4311 // Fixes button disappearance bug
4313 m_wndEditor2
->Show ( false );
4316 m_startingSplitterX
= x
- splitterHitOffset
;
4324 if ( p
->GetChildCount() )
4326 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4328 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4330 int y2
= y
% m_lineHeight
;
4331 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4333 // On click on expander button, expand/collapse
4334 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4335 DoCollapse( p
, true );
4337 DoExpand( p
, true );
4346 // -----------------------------------------------------------------------
4348 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4349 wxMouseEvent
& WXUNUSED(event
) )
4353 // Select property here as well
4354 wxPGProperty
* p
= m_propHover
;
4355 if ( p
!= m_selected
)
4356 DoSelectProperty( p
);
4358 // Send right click event.
4359 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4366 // -----------------------------------------------------------------------
4368 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4369 wxMouseEvent
& WXUNUSED(event
) )
4373 // Select property here as well
4374 wxPGProperty
* p
= m_propHover
;
4376 if ( p
!= m_selected
)
4377 DoSelectProperty( p
);
4379 // Send double-click event.
4380 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4387 // -----------------------------------------------------------------------
4389 #if wxPG_SUPPORT_TOOLTIPS
4391 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4393 if ( tipString
.length() )
4395 m_canvas
->SetToolTip(tipString
);
4399 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4400 m_canvas
->SetToolTip( m_emptyString
);
4402 m_canvas
->SetToolTip( NULL
);
4407 #endif // #if wxPG_SUPPORT_TOOLTIPS
4409 // -----------------------------------------------------------------------
4411 // Return false if should be skipped
4412 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4414 // Safety check (needed because mouse capturing may
4415 // otherwise freeze the control)
4416 if ( m_dragStatus
> 0 && !event
.Dragging() )
4418 HandleMouseUp(x
,y
,event
);
4421 wxPropertyGridPageState
* state
= m_pState
;
4423 int splitterHitOffset
;
4424 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4425 int splitterX
= x
- splitterHitOffset
;
4427 if ( m_dragStatus
> 0 )
4429 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4430 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4433 int newSplitterX
= x
- m_dragOffset
;
4434 int splitterX
= x
- splitterHitOffset
;
4436 // Splitter redraw required?
4437 if ( newSplitterX
!= splitterX
)
4440 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4441 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4442 state
->m_fSplitterX
= (float) newSplitterX
;
4445 CorrectEditorWidgetSizeX();
4459 int ih
= m_lineHeight
;
4462 #if wxPG_SUPPORT_TOOLTIPS
4463 wxPGProperty
* prevHover
= m_propHover
;
4464 unsigned char prevSide
= m_mouseSide
;
4466 int curPropHoverY
= y
- (y
% ih
);
4468 // On which item it hovers
4469 if ( ( !m_propHover
)
4471 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4474 // Mouse moves on another property
4476 m_propHover
= DoGetItemAtY(y
);
4477 m_propHoverY
= curPropHoverY
;
4480 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4483 #if wxPG_SUPPORT_TOOLTIPS
4484 // Store which side we are on
4486 if ( columnHit
== 1 )
4488 else if ( columnHit
== 0 )
4492 // If tooltips are enabled, show label or value as a tip
4493 // in case it doesn't otherwise show in full length.
4495 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4497 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4499 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4501 if ( m_propHover
&& !m_propHover
->IsCategory() )
4504 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4506 // Show help string as a tooltip
4507 wxString tipString
= m_propHover
->GetHelpString();
4509 SetToolTip(tipString
);
4513 // Show cropped value string as a tooltip
4517 if ( m_mouseSide
== 1 )
4519 tipString
= m_propHover
->m_label
;
4520 space
= splitterX
-m_marginWidth
-3;
4522 else if ( m_mouseSide
== 2 )
4524 tipString
= m_propHover
->GetDisplayedString();
4526 space
= m_width
- splitterX
;
4527 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4528 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4534 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4537 SetToolTip( tipString
);
4544 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4545 m_canvas
->SetToolTip( m_emptyString
);
4547 m_canvas
->SetToolTip( NULL
);
4558 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4559 m_canvas
->SetToolTip( m_emptyString
);
4561 m_canvas
->SetToolTip( NULL
);
4569 if ( splitterHit
== -1 ||
4571 HasFlag(wxPG_STATIC_SPLITTER
) )
4573 // hovering on something else
4574 if ( m_curcursor
!= wxCURSOR_ARROW
)
4575 CustomSetCursor( wxCURSOR_ARROW
);
4579 // Do not allow splitter cursor on caption items.
4580 // (also not if we were dragging and its started
4581 // outside the splitter region)
4584 !m_propHover
->IsCategory() &&
4588 // hovering on splitter
4590 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4591 // reliably detected.
4592 //if ( m_curcursor != wxCURSOR_SIZEWE )
4593 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4599 // hovering on something else
4600 if ( m_curcursor
!= wxCURSOR_ARROW
)
4601 CustomSetCursor( wxCURSOR_ARROW
);
4608 // -----------------------------------------------------------------------
4610 // Also handles Leaving event
4611 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4612 wxMouseEvent
&WXUNUSED(event
) )
4614 wxPropertyGridPageState
* state
= m_pState
;
4618 int splitterHitOffset
;
4619 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4621 // No event type check - basicly calling this method should
4622 // just stop dragging.
4623 // Left up after dragged?
4624 if ( m_dragStatus
>= 1 )
4627 // End Splitter Dragging
4629 // DO NOT ENABLE FOLLOWING LINE!
4630 // (it is only here as a reminder to not to do it)
4633 // Disable splitter auto-centering
4634 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4636 // This is necessary to return cursor
4637 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4639 m_canvas
->ReleaseMouse();
4640 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4643 // Set back the default cursor, if necessary
4644 if ( splitterHit
== -1 ||
4647 CustomSetCursor( wxCURSOR_ARROW
);
4652 // Control background needs to be cleared
4653 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4654 DrawItem( m_selected
);
4658 m_wndEditor
->Show ( true );
4661 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4662 // Fixes button disappearance bug
4664 m_wndEditor2
->Show ( true );
4667 // This clears the focus.
4668 m_editorFocused
= 0;
4674 // -----------------------------------------------------------------------
4676 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4678 int splitterX
= GetSplitterPosition();
4681 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4685 wxWindow
* wnd
= GetEditorControl();
4687 // Hide popup on clicks
4688 if ( event
.GetEventType() != wxEVT_MOTION
)
4689 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4691 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4697 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4699 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4700 ux
>= (r
.x
+r
.width
) ||
4702 event
.m_y
>= (r
.y
+r
.height
)
4712 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4717 // -----------------------------------------------------------------------
4719 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4722 if ( OnMouseCommon( event
, &x
, &y
) )
4724 HandleMouseClick(x
,y
,event
);
4729 // -----------------------------------------------------------------------
4731 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4734 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4735 HandleMouseRightClick(x
,y
,event
);
4739 // -----------------------------------------------------------------------
4741 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4743 // Always run standard mouse-down handler as well
4744 OnMouseClick(event
);
4747 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4748 HandleMouseDoubleClick(x
,y
,event
);
4752 // -----------------------------------------------------------------------
4754 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4757 if ( OnMouseCommon( event
, &x
, &y
) )
4759 HandleMouseMove(x
,y
,event
);
4764 // -----------------------------------------------------------------------
4766 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4768 // Called when mouse moves in the empty space below the properties.
4769 CustomSetCursor( wxCURSOR_ARROW
);
4772 // -----------------------------------------------------------------------
4774 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4777 if ( OnMouseCommon( event
, &x
, &y
) )
4779 HandleMouseUp(x
,y
,event
);
4784 // -----------------------------------------------------------------------
4786 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4788 // This may get called from child control as well, so event's
4789 // mouse position cannot be relied on.
4791 if ( event
.Entering() )
4793 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4795 // TODO: Fix this (detect parent and only do
4796 // cursor trick if it is a manager).
4797 wxASSERT( GetParent() );
4798 GetParent()->SetCursor(wxNullCursor
);
4800 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4803 GetParent()->SetCursor(wxNullCursor
);
4805 else if ( event
.Leaving() )
4807 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4808 m_canvas
->SetCursor( wxNullCursor
);
4810 // Get real cursor position
4811 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4813 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4816 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4818 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4822 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4830 // -----------------------------------------------------------------------
4832 // Common code used by various OnMouseXXXChild methods.
4833 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4835 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4836 wxASSERT( topCtrlWnd
);
4838 event
.GetPosition(&x
,&y
);
4840 int splitterX
= GetSplitterPosition();
4842 wxRect r
= topCtrlWnd
->GetRect();
4843 if ( !m_dragStatus
&&
4844 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4845 y
>= 0 && y
< r
.height \
4848 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4853 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4860 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4863 if ( OnMouseChildCommon(event
,&x
,&y
) )
4865 bool res
= HandleMouseClick(x
,y
,event
);
4866 if ( !res
) event
.Skip();
4870 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4873 wxASSERT( m_wndEditor
);
4874 // These coords may not be exact (about +-2),
4875 // but that should not matter (right click is about item, not position).
4876 wxPoint pt
= m_wndEditor
->GetPosition();
4877 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4878 wxASSERT( m_selected
);
4879 m_propHover
= m_selected
;
4880 bool res
= HandleMouseRightClick(x
,y
,event
);
4881 if ( !res
) event
.Skip();
4884 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4887 if ( OnMouseChildCommon(event
,&x
,&y
) )
4889 bool res
= HandleMouseMove(x
,y
,event
);
4890 if ( !res
) event
.Skip();
4894 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4897 if ( OnMouseChildCommon(event
,&x
,&y
) )
4899 bool res
= HandleMouseUp(x
,y
,event
);
4900 if ( !res
) event
.Skip();
4904 // -----------------------------------------------------------------------
4905 // wxPropertyGrid keyboard event handling
4906 // -----------------------------------------------------------------------
4908 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4910 // Translates wxKeyEvent to wxPG_ACTION_XXX
4912 int keycode
= event
.GetKeyCode();
4913 int modifiers
= event
.GetModifiers();
4915 wxASSERT( !(modifiers
&~(0xFFFF)) );
4917 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4919 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4921 if ( it
== m_actionTriggers
.end() )
4926 int second
= (it
->second
>>16) & 0xFFFF;
4930 return (it
->second
& 0xFFFF);
4933 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4935 wxASSERT( !(modifiers
&~(0xFFFF)) );
4937 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4939 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4941 if ( it
!= m_actionTriggers
.end() )
4943 // This key combination is already used
4945 // Can add secondary?
4946 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4947 wxT("You can only add up to two separate actions per key combination.") );
4949 action
= it
->second
| (action
<<16);
4952 m_actionTriggers
[hashMapKey
] = action
;
4955 void wxPropertyGrid::ClearActionTriggers( int action
)
4957 wxPGHashMapI2I::iterator it
;
4959 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4961 if ( it
->second
== action
)
4963 m_actionTriggers
.erase(it
);
4968 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4971 // Handles key event when editor control is not focused.
4974 wxASSERT( !m_frozen
);
4978 // Travelsal between items, collapsing/expanding, etc.
4979 int keycode
= event
.GetKeyCode();
4981 if ( keycode
== WXK_TAB
)
4984 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4988 // Ignore Alt and Control when they are down alone
4989 if ( keycode
== WXK_ALT
||
4990 keycode
== WXK_CONTROL
)
4997 int action
= KeyEventToActions(event
, &secondAction
);
5003 if ( ButtonTriggerKeyTest(action
, event
) )
5006 wxPGProperty
* p
= m_selected
;
5008 // Travel and expand/collapse
5011 if ( p
->GetChildCount() &&
5012 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5015 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5017 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5020 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5022 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5029 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5033 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5044 if ( selectDir
>= -1 )
5046 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5048 DoSelectProperty(p
);
5053 // If nothing was selected, select the first item now
5054 // (or navigate out of tab).
5055 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5057 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5058 if ( p
) DoSelectProperty(p
);
5063 // -----------------------------------------------------------------------
5065 // Potentially handles a keyboard event for editor controls.
5066 // Returns false if event should *not* be skipped (on true it can
5067 // be optionally skipped).
5068 // Basicly, false means that SelectProperty was called (or was about
5069 // to be called, if canDestroy was false).
5070 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5074 if ( !m_selected
|| !m_wndEditor
)
5079 int action
= KeyEventToAction(event
);
5082 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5085 // Esc cancels any changes
5086 if ( IsEditorsValueModified() )
5088 EditorsValueWasNotModified();
5090 // Update the control as well
5091 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5093 m_selected
->GetDisplayedString() );
5096 OnValidationFailureReset(m_selected
);
5105 // -----------------------------------------------------------------------
5107 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5109 HandleKeyEvent( event
);
5112 // -----------------------------------------------------------------------
5114 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5119 // -----------------------------------------------------------------------
5121 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5126 action
= KeyEventToActions(event
, &secondAction
);
5129 // Does the keycode trigger button?
5130 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5133 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5134 GetEventHandler()->AddPendingEvent(evt
);
5141 // -----------------------------------------------------------------------
5143 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5145 int keycode
= event
.GetKeyCode();
5147 // Ignore Alt and Control when they are down alone
5148 if ( keycode
== WXK_ALT
||
5149 keycode
== WXK_CONTROL
)
5155 if ( ButtonTriggerKeyTest(-1, event
) )
5158 if ( HandleChildKey(event
) == true )
5161 GetEventHandler()->AddPendingEvent(event
);
5164 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5166 GetEventHandler()->AddPendingEvent(event
);
5171 // -----------------------------------------------------------------------
5172 // wxPropertyGrid miscellaneous event handling
5173 // -----------------------------------------------------------------------
5175 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5178 // Check if the focus is in this control or one of its children
5179 wxWindow
* newFocused
= wxWindow::FindFocus();
5181 if ( newFocused
!= m_curFocused
)
5182 HandleFocusChange( newFocused
);
5185 // Called by focus event handlers. newFocused is the window that becomes focused.
5186 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5188 unsigned int oldFlags
= m_iFlags
;
5190 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5192 wxWindow
* parent
= newFocused
;
5194 // This must be one of nextFocus' parents.
5197 // Use m_eventObject, which is either wxPropertyGrid or
5198 // wxPropertyGridManager, as appropriate.
5199 if ( parent
== m_eventObject
)
5201 m_iFlags
|= wxPG_FL_FOCUSED
;
5204 parent
= parent
->GetParent();
5207 m_curFocused
= newFocused
;
5209 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5210 (oldFlags
& wxPG_FL_FOCUSED
) )
5212 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5214 // Need to store changed value
5215 CommitChangesFromEditor();
5221 // Preliminary code for tab-order respecting
5222 // tab-traversal (but should be moved to
5225 wxWindow* prevFocus = event.GetWindow();
5226 wxWindow* useThis = this;
5227 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5228 useThis = GetParent();
5231 prevFocus->GetParent() == useThis->GetParent() )
5233 wxList& children = useThis->GetParent()->GetChildren();
5235 wxNode* node = children.Find(prevFocus);
5237 if ( node->GetNext() &&
5238 useThis == node->GetNext()->GetData() )
5239 DoSelectProperty(GetFirst());
5240 else if ( node->GetPrevious () &&
5241 useThis == node->GetPrevious()->GetData() )
5242 DoSelectProperty(GetLastProperty());
5249 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5250 DrawItem( m_selected
);
5254 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5256 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5257 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5258 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5259 //else if ( event.GetWindow() )
5261 HandleFocusChange(event
.GetWindow());
5266 // -----------------------------------------------------------------------
5268 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5270 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5273 // event.Skip() being commented out is aworkaround for bug reported
5274 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5278 // -----------------------------------------------------------------------
5280 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5282 m_iFlags
|= wxPG_FL_SCROLLED
;
5287 // -----------------------------------------------------------------------
5289 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5291 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5293 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5297 // -----------------------------------------------------------------------
5298 // Property editor related functions
5299 // -----------------------------------------------------------------------
5301 // noDefCheck = true prevents infinite recursion.
5302 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5305 wxASSERT( editorClass
);
5307 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5308 RegisterDefaultEditors();
5310 wxString name
= editorClass
->GetName();
5312 // Existing editor under this name?
5313 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5315 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5317 // If this name was already used, try class name.
5318 name
= editorClass
->GetClassInfo()->GetClassName();
5319 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5322 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5323 (wxPGEditor
*) vt_it
->second
,
5324 "Editor with given name was already registered" );
5326 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5331 // Use this in RegisterDefaultEditors.
5332 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5333 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5335 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5336 new wxPG##EDITOR##Editor, true ); \
5339 // Registers all default editor classes
5340 void wxPropertyGrid::RegisterDefaultEditors()
5342 wxPGRegisterDefaultEditorClass( TextCtrl
);
5343 wxPGRegisterDefaultEditorClass( Choice
);
5344 wxPGRegisterDefaultEditorClass( ComboBox
);
5345 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5346 #if wxPG_INCLUDE_CHECKBOX
5347 wxPGRegisterDefaultEditorClass( CheckBox
);
5349 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5351 // Register SpinCtrl etc. editors before use
5352 RegisterAdditionalEditors();
5355 // -----------------------------------------------------------------------
5356 // wxPGStringTokenizer
5357 // Needed to handle C-style string lists (e.g. "str1" "str2")
5358 // -----------------------------------------------------------------------
5360 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5361 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5365 wxPGStringTokenizer::~wxPGStringTokenizer()
5369 bool wxPGStringTokenizer::HasMoreTokens()
5371 const wxString
& str
= *m_str
;
5373 wxString::const_iterator i
= m_curPos
;
5375 wxUniChar delim
= m_delimeter
;
5377 wxUniChar prev_a
= wxT('\0');
5379 bool inToken
= false;
5381 while ( i
!= str
.end() )
5390 m_readyToken
.clear();
5395 if ( prev_a
!= wxT('\\') )
5399 if ( a
!= wxT('\\') )
5419 m_curPos
= str
.end();
5427 wxString
wxPGStringTokenizer::GetNextToken()
5429 return m_readyToken
;
5432 // -----------------------------------------------------------------------
5434 // -----------------------------------------------------------------------
5436 wxPGChoiceEntry::wxPGChoiceEntry()
5437 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5441 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5442 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5443 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5447 // -----------------------------------------------------------------------
5449 // -----------------------------------------------------------------------
5451 wxPGChoicesData::wxPGChoicesData()
5456 wxPGChoicesData::~wxPGChoicesData()
5461 void wxPGChoicesData::Clear()
5465 for ( i
=0; i
<m_items
.size(); i
++ )
5473 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5475 wxASSERT( m_items
.size() == 0 );
5479 for ( i
=0; i
<data
->GetCount(); i
++ )
5480 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5483 // -----------------------------------------------------------------------
5485 // -----------------------------------------------------------------------
5487 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5491 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5492 m_data
->Insert( -1, p
);
5496 // -----------------------------------------------------------------------
5498 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5502 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5503 p
->SetBitmap(bitmap
);
5504 m_data
->Insert( -1, p
);
5508 // -----------------------------------------------------------------------
5510 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5514 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5515 m_data
->Insert(index
, p
);
5519 // -----------------------------------------------------------------------
5521 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5525 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5526 m_data
->Insert( index
, p
);
5530 // -----------------------------------------------------------------------
5532 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5538 while ( index
< GetCount() )
5540 int cmpRes
= GetLabel(index
).Cmp(label
);
5546 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5547 m_data
->Insert( index
, p
);
5551 // -----------------------------------------------------------------------
5553 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5557 unsigned int itemcount
= 0;
5558 const wxChar
** p
= &labels
[0];
5559 while ( *p
) { p
++; itemcount
++; }
5562 for ( i
= 0; i
< itemcount
; i
++ )
5564 int value
= wxPG_INVALID_VALUE
;
5567 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5571 // -----------------------------------------------------------------------
5573 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5578 unsigned int itemcount
= arr
.size();
5580 for ( i
= 0; i
< itemcount
; i
++ )
5582 int value
= wxPG_INVALID_VALUE
;
5585 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5589 // -----------------------------------------------------------------------
5591 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5596 unsigned int itemcount
= arr
.size();
5598 for ( i
= 0; i
< itemcount
; i
++ )
5600 int value
= wxPG_INVALID_VALUE
;
5601 if ( &arrint
&& arrint
.size() )
5603 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5607 // -----------------------------------------------------------------------
5609 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5611 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5613 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5614 delete m_data
->Item(i
);
5615 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5616 m_data
->m_items
.begin()+nIndex
+count
);
5619 // -----------------------------------------------------------------------
5621 int wxPGChoices::Index( const wxString
& str
) const
5626 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5628 if ( m_data
->Item(i
)->GetText() == str
)
5635 // -----------------------------------------------------------------------
5637 int wxPGChoices::Index( int val
) const
5642 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5644 if ( m_data
->Item(i
)->GetValue() == val
)
5651 // -----------------------------------------------------------------------
5653 wxArrayString
wxPGChoices::GetLabels() const
5658 if ( this && IsOk() )
5659 for ( i
=0; i
<GetCount(); i
++ )
5660 arr
.push_back(GetLabel(i
));
5665 // -----------------------------------------------------------------------
5667 bool wxPGChoices::HasValues() const
5672 // -----------------------------------------------------------------------
5674 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5681 for ( i
=0; i
< strings
.size(); i
++ )
5683 int index
= Index(strings
[i
]);
5685 arr
.Add(GetValue(index
));
5687 arr
.Add(wxPG_INVALID_VALUE
);
5694 // -----------------------------------------------------------------------
5696 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5697 wxArrayString
* unmatched
) const
5704 for ( i
=0; i
< strings
.size(); i
++ )
5706 const wxString
& str
= strings
[i
];
5707 int index
= Index(str
);
5710 else if ( unmatched
)
5711 unmatched
->Add(str
);
5718 // -----------------------------------------------------------------------
5720 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5724 if ( data
!= wxPGChoicesEmptyData
)
5731 // -----------------------------------------------------------------------
5733 void wxPGChoices::Init()
5735 m_data
= wxPGChoicesEmptyData
;
5738 // -----------------------------------------------------------------------
5740 void wxPGChoices::Free()
5742 if ( m_data
!= wxPGChoicesEmptyData
)
5745 m_data
= wxPGChoicesEmptyData
;
5749 // -----------------------------------------------------------------------
5750 // wxPropertyGridEvent
5751 // -----------------------------------------------------------------------
5753 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5756 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5757 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5758 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5759 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5760 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5761 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5762 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5763 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5764 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5767 // -----------------------------------------------------------------------
5769 void wxPropertyGridEvent::Init()
5771 m_validationInfo
= NULL
;
5773 m_wasVetoed
= false;
5776 // -----------------------------------------------------------------------
5778 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5779 : wxCommandEvent(commandType
,id
)
5785 // -----------------------------------------------------------------------
5787 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5788 : wxCommandEvent(event
)
5790 m_eventType
= event
.GetEventType();
5791 m_eventObject
= event
.m_eventObject
;
5793 m_property
= event
.m_property
;
5794 m_validationInfo
= event
.m_validationInfo
;
5795 m_canVeto
= event
.m_canVeto
;
5796 m_wasVetoed
= event
.m_wasVetoed
;
5799 // -----------------------------------------------------------------------
5801 wxPropertyGridEvent::~wxPropertyGridEvent()
5805 // -----------------------------------------------------------------------
5807 wxEvent
* wxPropertyGridEvent::Clone() const
5809 return new wxPropertyGridEvent( *this );
5812 // -----------------------------------------------------------------------
5813 // wxPropertyGridPopulator
5814 // -----------------------------------------------------------------------
5816 wxPropertyGridPopulator::wxPropertyGridPopulator()
5820 wxPGGlobalVars
->m_offline
++;
5823 // -----------------------------------------------------------------------
5825 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5828 m_propHierarchy
.clear();
5831 // -----------------------------------------------------------------------
5833 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5839 // -----------------------------------------------------------------------
5841 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5844 // Free unused sets of choices
5845 wxPGHashMapS2P::iterator it
;
5847 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5849 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5856 m_pg
->GetPanel()->Refresh();
5858 wxPGGlobalVars
->m_offline
--;
5861 // -----------------------------------------------------------------------
5863 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5864 const wxString
& propLabel
,
5865 const wxString
& propName
,
5866 const wxString
* propValue
,
5867 wxPGChoices
* pChoices
)
5869 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5870 wxPGProperty
* parent
= GetCurParent();
5872 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5874 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5878 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5880 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5884 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5886 property
->SetLabel(propLabel
);
5887 property
->DoSetName(propName
);
5889 if ( pChoices
&& pChoices
->IsOk() )
5890 property
->SetChoices(*pChoices
);
5892 m_state
->DoInsert(parent
, -1, property
);
5895 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
5900 // -----------------------------------------------------------------------
5902 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5904 m_propHierarchy
.push_back(property
);
5905 DoScanForChildren();
5906 m_propHierarchy
.pop_back();
5909 // -----------------------------------------------------------------------
5911 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5912 const wxString
& idString
)
5914 wxPGChoices choices
;
5917 if ( choicesString
[0] == wxT('@') )
5919 wxString ids
= choicesString
.substr(1);
5920 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5921 if ( it
== m_dictIdChoices
.end() )
5922 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5924 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5929 if ( idString
.length() )
5931 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5932 if ( it
!= m_dictIdChoices
.end() )
5934 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5941 // Parse choices string
5942 wxString::const_iterator it
= choicesString
.begin();
5946 bool labelValid
= false;
5948 for ( ; it
!= choicesString
.end(); it
++ )
5954 if ( c
== wxT('"') )
5959 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5960 choices
.Add(label
, l
);
5963 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5968 else if ( c
== wxT('=') )
5975 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5982 if ( c
== wxT('"') )
5995 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5996 choices
.Add(label
, l
);
5999 if ( !choices
.IsOk() )
6001 choices
.EnsureData();
6005 if ( idString
.length() )
6006 m_dictIdChoices
[idString
] = choices
.GetData();
6013 // -----------------------------------------------------------------------
6015 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6017 if ( s
.Last() == wxT('%') )
6019 wxString s2
= s
.substr(0,s
.length()-1);
6021 if ( s2
.ToLong(&val
, 10) )
6023 *pval
= (val
*max
)/100;
6029 return s
.ToLong(pval
, 10);
6032 // -----------------------------------------------------------------------
6034 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6035 const wxString
& type
,
6036 const wxString
& value
)
6038 int l
= m_propHierarchy
.size();
6042 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6043 wxString valuel
= value
.Lower();
6046 if ( type
.length() == 0 )
6051 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6053 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6055 else if ( value
.ToLong(&v
, 0) )
6062 if ( type
== wxT("string") )
6066 else if ( type
== wxT("int") )
6069 value
.ToLong(&v
, 0);
6072 else if ( type
== wxT("bool") )
6074 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6081 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6086 p
->SetAttribute( name
, variant
);
6091 // -----------------------------------------------------------------------
6093 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6095 wxLogError(_("Error in resource: %s"),msg
.c_str());
6098 // -----------------------------------------------------------------------
6100 #endif // wxUSE_PROPGRID