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 OnNavigationKey( wxNavigationKeyEvent
& event
)
419 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
420 pg
->OnNavigationKey( event
);
423 void OnPaint( wxPaintEvent
& event
);
425 // Always be focussable, even with child windows
426 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
427 { wxPanel::SetCanFocus(true); }
431 DECLARE_EVENT_TABLE()
432 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
436 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
438 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
439 EVT_MOTION(wxPGCanvas::OnMouseMove
)
440 EVT_PAINT(wxPGCanvas::OnPaint
)
441 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
442 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
443 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
444 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
445 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
446 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
447 EVT_CHAR(wxPGCanvas::OnKey
)
448 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
452 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
454 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
455 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
459 // Don't paint after destruction has begun
460 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
463 // Update everything inside the box
464 wxRect r
= GetUpdateRegion().GetBox();
466 // Repaint this rectangle
467 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
469 // We assume that the size set when grid is shown
470 // is what is desired.
471 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
474 // -----------------------------------------------------------------------
476 // -----------------------------------------------------------------------
478 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
480 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
481 EVT_IDLE(wxPropertyGrid::OnIdle
)
482 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
483 EVT_PAINT(wxPropertyGrid::OnPaint
)
484 EVT_SIZE(wxPropertyGrid::OnResize
)
485 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
486 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
487 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
488 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
489 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
490 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
491 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
492 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
496 // -----------------------------------------------------------------------
498 wxPropertyGrid::wxPropertyGrid()
504 // -----------------------------------------------------------------------
506 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
515 Create(parent
,id
,pos
,size
,style
,name
);
518 // -----------------------------------------------------------------------
520 bool wxPropertyGrid::Create( wxWindow
*parent
,
528 if ( !(style
&wxBORDER_MASK
) )
529 style
|= wxSIMPLE_BORDER
;
534 // This prevents crash under Win2K, but still
535 // enables keyboard navigation
536 if ( style
& wxTAB_TRAVERSAL
)
538 style
&= ~(wxTAB_TRAVERSAL
);
539 style
|= wxWANTS_CHARS
;
542 if ( style
& wxTAB_TRAVERSAL
)
543 style
|= wxWANTS_CHARS
;
546 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
553 // -----------------------------------------------------------------------
556 // Initialize values to defaults
558 void wxPropertyGrid::Init1()
560 // Register editor classes, if necessary.
561 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
562 wxPropertyGrid::RegisterDefaultEditors();
565 m_pState
= (wxPropertyGridPageState
*) NULL
;
566 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
567 m_selected
= (wxPGProperty
*) NULL
;
569 m_propHover
= (wxPGProperty
*) NULL
;
570 m_eventObject
= this;
571 m_curFocused
= (wxWindow
*) NULL
;
573 m_inDoPropertyChanged
= 0;
574 m_inCommitChangesFromEditor
= 0;
575 m_inDoSelectProperty
= 0;
576 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
582 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
583 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
584 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
585 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
586 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
587 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
588 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
589 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
590 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
591 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
592 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
593 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
594 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
595 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
597 m_coloursCustomized
= 0;
602 #if wxPG_DOUBLE_BUFFER
603 m_doubleBuffer
= (wxBitmap
*) NULL
;
606 #ifndef wxPG_ICON_WIDTH
612 m_iconWidth
= wxPG_ICON_WIDTH
;
617 m_gutterWidth
= wxPG_GUTTER_MIN
;
618 m_subgroup_extramargin
= 10;
622 m_width
= m_height
= 0;
624 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
627 m_chgInfo_changedProperty
= NULL
;
630 // -----------------------------------------------------------------------
633 // Initialize after parent etc. set
635 void wxPropertyGrid::Init2()
637 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
640 // Smaller controls on Mac
641 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
644 // Now create state, if one didn't exist already
645 // (wxPropertyGridManager might have created it for us).
648 m_pState
= CreateState();
649 m_pState
->m_pPropGrid
= this;
650 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
653 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
654 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
656 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
658 m_pState
->InitNonCatMode();
660 m_pState
->m_properties
= m_pState
->m_abcArray
;
663 GetClientSize(&m_width
,&m_height
);
665 #ifndef wxPG_ICON_WIDTH
666 // create two bitmap nodes for drawing
667 m_expandbmp
= new wxBitmap(expand_xpm
);
668 m_collbmp
= new wxBitmap(collapse_xpm
);
670 // calculate average font height for bitmap centering
672 m_iconWidth
= m_expandbmp
->GetWidth();
673 m_iconHeight
= m_expandbmp
->GetHeight();
676 m_curcursor
= wxCURSOR_ARROW
;
677 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
679 // adjust bitmap icon y position so they are centered
680 m_vspacing
= wxPG_DEFAULT_VSPACING
;
684 wxFont useFont
= wxScrolledWindow::GetFont();
685 wxScrolledWindow::SetOwnFont( useFont
);
688 // This should be otherwise called by SetOwnFont
689 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
691 // Add base brush item
692 m_arrBgBrushes
.Add((void*)new wxPGBrush());
694 // Add base colour items
695 m_arrFgCols
.Add((void*)new wxPGColour());
696 m_arrFgCols
.Add((void*)new wxPGColour());
700 // This helps with flicker
701 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
704 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
705 m_tlp
= ::wxGetTopLevelParent(this);
706 m_tlwHandler
= handler
;
707 m_tlp
->PushEventHandler(handler
);
709 // set virtual size to this window size
710 wxSize wndsize
= GetSize();
711 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
713 m_timeCreated
= ::wxGetLocalTimeMillis();
715 m_canvas
= new wxPGCanvas();
716 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
717 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
718 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
720 m_iFlags
|= wxPG_FL_INITIALIZED
;
722 m_ncWidth
= wndsize
.GetWidth();
724 // Need to call OnResize handler or size given in constructor/Create
726 wxSizeEvent
sizeEvent(wndsize
,0);
730 // -----------------------------------------------------------------------
732 wxPropertyGrid::~wxPropertyGrid()
736 DoSelectProperty(NULL
);
738 // This should do prevent things from going too badly wrong
739 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
741 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
742 m_canvas
->ReleaseMouse();
744 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
745 m_tlp
->RemoveEventHandler(handler
);
749 if ( IsEditorsValueModified() )
750 ::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).)"),
751 wxS("wxPropertyGrid Debug Warning") );
754 #if wxPG_DOUBLE_BUFFER
755 if ( m_doubleBuffer
)
756 delete m_doubleBuffer
;
759 //m_selected = (wxPGProperty*) NULL;
761 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
764 delete m_cursorSizeWE
;
766 #ifndef wxPG_ICON_WIDTH
771 // Delete cached text colours.
772 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
774 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
777 // Delete cached brushes.
778 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
780 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
783 // Delete common value records
784 for ( i
=0; i
<m_commonValues
.size(); i
++ )
786 delete GetCommonValue(i
);
790 // -----------------------------------------------------------------------
792 bool wxPropertyGrid::Destroy()
794 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
795 m_canvas
->ReleaseMouse();
797 return wxScrolledWindow::Destroy();
800 // -----------------------------------------------------------------------
802 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
804 return new wxPropertyGridPageState();
807 // -----------------------------------------------------------------------
808 // wxPropertyGrid overridden wxWindow methods
809 // -----------------------------------------------------------------------
811 void wxPropertyGrid::SetWindowStyleFlag( long style
)
813 long old_style
= m_windowStyle
;
815 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
817 wxASSERT( m_pState
);
819 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
822 EnableCategories( true );
824 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
826 // Disable categories
827 EnableCategories( false );
829 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
835 PrepareAfterItemsAdded();
837 m_pState
->m_itemsAdded
= 1;
839 #if wxPG_SUPPORT_TOOLTIPS
840 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
846 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
847 SetToolTip ( tooltip );
848 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
851 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
856 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
861 wxScrolledWindow::SetWindowStyleFlag ( style
);
863 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
865 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
867 CalculateFontAndBitmapStuff( m_vspacing
);
873 // -----------------------------------------------------------------------
875 void wxPropertyGrid::Freeze()
879 wxScrolledWindow::Freeze();
884 // -----------------------------------------------------------------------
886 void wxPropertyGrid::Thaw()
892 wxScrolledWindow::Thaw();
893 RecalculateVirtualSize();
894 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
898 // Force property re-selection
900 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
904 // -----------------------------------------------------------------------
906 void wxPropertyGrid::SetExtraStyle( long exStyle
)
908 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
910 #if defined(__WXMSW__)
913 // Don't use WS_EX_COMPOSITED just now.
916 if ( m_iFlags & wxPG_FL_IN_MANAGER )
917 hWnd = (HWND)GetParent()->GetHWND();
919 hWnd = (HWND)GetHWND();
921 ::SetWindowLong( hWnd, GWL_EXSTYLE,
922 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
925 //#elif defined(__WXGTK20__)
927 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
928 // truly was double-buffered.
929 if ( !this->IsDoubleBuffered() )
931 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
935 #if wxPG_DOUBLE_BUFFER
936 delete m_doubleBuffer
;
937 m_doubleBuffer
= NULL
;
942 wxScrolledWindow::SetExtraStyle( exStyle
);
944 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
945 m_pState
->InitNonCatMode();
947 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
948 m_windowStyle
|= wxPG_TOOLTIPS
;
951 wxPGGlobalVars
->m_extraStyle
= exStyle
;
954 // -----------------------------------------------------------------------
956 // returns the best acceptable minimal size
957 wxSize
wxPropertyGrid::DoGetBestSize() const
960 if ( m_lineHeight
> hei
)
962 wxSize sz
= wxSize( 60, hei
+40 );
968 // -----------------------------------------------------------------------
969 // wxPropertyGrid Font and Colour Methods
970 // -----------------------------------------------------------------------
972 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
976 m_captionFont
= wxScrolledWindow::GetFont();
978 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
979 m_subgroup_extramargin
= x
+ (x
/2);
982 #if wxPG_USE_RENDERER_NATIVE
983 m_iconWidth
= wxPG_ICON_WIDTH
;
984 #elif wxPG_ICON_WIDTH
986 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
987 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
988 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
992 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
993 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
994 m_gutterWidth
= wxPG_GUTTER_MIN
;
997 if ( vspacing
<= 1 ) vdiv
= 12;
998 else if ( vspacing
>= 3 ) vdiv
= 3;
1000 m_spacingy
= m_fontHeight
/ vdiv
;
1001 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1002 m_spacingy
= wxPG_YSPACING_MIN
;
1005 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1006 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1008 m_captionFont
.SetWeight(wxBOLD
);
1009 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1011 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1014 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1015 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1018 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1020 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1021 RecalculateVirtualSize();
1023 InvalidateBestSize();
1026 // -----------------------------------------------------------------------
1028 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1034 // -----------------------------------------------------------------------
1036 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1037 int ga
= 1000, int ba
= 1000,
1038 bool forceDifferent
= false)
1045 // Recursion guard (allow 2 max)
1046 static int isinside
= 0;
1048 wxCHECK_MSG( isinside
< 3,
1050 wxT("wxPGAdjustColour should not be recursively called more than once") );
1055 int g
= src
.Green();
1058 if ( r2
>255 ) r2
= 255;
1059 else if ( r2
<0) r2
= 0;
1061 if ( g2
>255 ) g2
= 255;
1062 else if ( g2
<0) g2
= 0;
1064 if ( b2
>255 ) b2
= 255;
1065 else if ( b2
<0) b2
= 0;
1067 // Make sure they are somewhat different
1068 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1069 dst
= wxPGAdjustColour(src
,-(ra
*2));
1071 dst
= wxColour(r2
,g2
,b2
);
1073 // Recursion guard (allow 2 max)
1080 static int wxPGGetColAvg( const wxColour
& col
)
1082 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1086 void wxPropertyGrid::RegainColours()
1088 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1090 if ( !(m_coloursCustomized
& 0x0002) )
1092 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1094 // Make sure colour is dark enough
1096 int colDec
= wxPGGetColAvg(col
) - 230;
1098 int colDec
= wxPGGetColAvg(col
) - 200;
1101 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1106 if ( !(m_coloursCustomized
& 0x0001) )
1107 m_colMargin
= m_colCapBack
;
1109 if ( !(m_coloursCustomized
& 0x0004) )
1116 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1117 m_colCapFore
= capForeCol
;
1119 // Set the cached colour as well.
1120 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1123 if ( !(m_coloursCustomized
& 0x0008) )
1125 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1126 m_colPropBack
= bgCol
;
1128 // Set the cached brush as well.
1129 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1132 if ( !(m_coloursCustomized
& 0x0010) )
1134 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1135 m_colPropFore
= fgCol
;
1137 // Set the cached colour as well.
1138 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1141 if ( !(m_coloursCustomized
& 0x0020) )
1142 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1144 if ( !(m_coloursCustomized
& 0x0040) )
1145 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1147 if ( !(m_coloursCustomized
& 0x0080) )
1148 m_colLine
= m_colCapBack
;
1150 if ( !(m_coloursCustomized
& 0x0100) )
1151 m_colDisPropFore
= m_colCapFore
;
1153 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1156 // -----------------------------------------------------------------------
1158 void wxPropertyGrid::ResetColours()
1160 m_coloursCustomized
= 0;
1167 // -----------------------------------------------------------------------
1169 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1171 // Must disable active editor.
1174 bool selRes
= ClearSelection();
1175 wxPG_CHECK_MSG_DBG( selRes
,
1177 wxT("failed to deselect a property (editor probably had invalid value)") );
1180 // TODO: Following code is disabled with wxMac because
1181 // it is reported to fail. I (JMS) cannot debug it
1182 // personally right now.
1183 #if !defined(__WXMAC__)
1184 bool res
= wxScrolledWindow::SetFont( font
);
1187 CalculateFontAndBitmapStuff( m_vspacing
);
1190 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1198 // TODO: Remove after SetFont crash fixed.
1199 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1201 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."));
1207 // -----------------------------------------------------------------------
1209 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1212 m_coloursCustomized
|= 0x80;
1216 // -----------------------------------------------------------------------
1218 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1221 m_coloursCustomized
|= 0x01;
1225 // -----------------------------------------------------------------------
1227 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1229 m_colPropBack
= col
;
1230 m_coloursCustomized
|= 0x08;
1232 // Set the cached brush as well.
1233 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1238 // -----------------------------------------------------------------------
1240 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1242 m_colPropFore
= col
;
1243 m_coloursCustomized
|= 0x10;
1245 // Set the cached colour as well.
1246 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1251 // -----------------------------------------------------------------------
1253 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1255 m_colEmptySpace
= col
;
1260 // -----------------------------------------------------------------------
1262 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1264 m_colDisPropFore
= col
;
1265 m_coloursCustomized
|= 0x100;
1269 // -----------------------------------------------------------------------
1271 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1274 m_coloursCustomized
|= 0x20;
1278 // -----------------------------------------------------------------------
1280 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1283 m_coloursCustomized
|= 0x40;
1287 // -----------------------------------------------------------------------
1289 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1292 m_coloursCustomized
|= 0x02;
1296 // -----------------------------------------------------------------------
1298 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1301 m_coloursCustomized
|= 0x04;
1303 // Set the cached colour as well.
1304 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1309 // -----------------------------------------------------------------------
1311 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1313 unsigned char ind
= index
;
1315 p
->m_bgColIndex
= ind
;
1318 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1319 SetBackgroundColourIndex(p
->Item(i
),index
);
1322 // -----------------------------------------------------------------------
1324 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1326 wxPG_PROP_ARG_CALL_PROLOG()
1331 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1333 // As it is most likely that the previous colour is used, start comparison
1335 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1337 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1346 colInd
= m_arrBgBrushes
.size();
1347 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1348 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1352 SetBackgroundColourIndex(p
,colInd
);
1354 // If this was on a visible grid, then draw it.
1355 DrawItemAndChildren(p
);
1358 // -----------------------------------------------------------------------
1360 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1362 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1364 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1367 // -----------------------------------------------------------------------
1369 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1371 unsigned char ind
= index
;
1373 p
->m_fgColIndex
= ind
;
1375 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1378 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1379 SetTextColourIndex( p
->Item(i
), index
, flags
);
1383 // -----------------------------------------------------------------------
1385 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1390 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1392 // As it is most likely that the previous colour is used, start comparison
1394 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1396 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1405 colInd
= m_arrFgCols
.size();
1406 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1407 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1413 // -----------------------------------------------------------------------
1415 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1418 wxPG_PROP_ARG_CALL_PROLOG()
1420 if ( p
->IsCategory() )
1422 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1423 cat
->SetTextColIndex(CacheColour(colour
));
1429 flags
|= wxPG_RECURSE
;
1430 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1432 DrawItemAndChildren(p
);
1435 // -----------------------------------------------------------------------
1437 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1439 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1441 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1444 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1446 wxPG_PROP_ARG_CALL_PROLOG()
1448 SetBackgroundColourIndex( p
, 0 );
1449 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1451 if ( p
->IsCategory() )
1453 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1454 cat
->SetTextColIndex(1);
1458 // -----------------------------------------------------------------------
1459 // wxPropertyGrid property adding and removal
1460 // -----------------------------------------------------------------------
1462 void wxPropertyGrid::PrepareAfterItemsAdded()
1464 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1466 m_pState
->m_itemsAdded
= 0;
1468 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1471 RecalculateVirtualSize();
1474 // -----------------------------------------------------------------------
1475 // wxPropertyGrid property value setting and getting
1476 // -----------------------------------------------------------------------
1478 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1480 m_pState
->DoSetPropertyValueUnspecified(p
);
1481 DrawItemAndChildren(p
);
1483 wxPGProperty
* parent
= p
->GetParent();
1484 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1487 parent
= parent
->GetParent();
1491 // -----------------------------------------------------------------------
1492 // wxPropertyGrid property operations
1493 // -----------------------------------------------------------------------
1495 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1497 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1501 bool changed
= false;
1503 // Is it inside collapsed section?
1504 if ( !p
->IsVisible() )
1507 wxPGProperty
* parent
= p
->GetParent();
1508 wxPGProperty
* grandparent
= parent
->GetParent();
1510 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1511 Expand( grandparent
);
1519 GetViewStart(&vx
,&vy
);
1520 vy
*=wxPG_PIXELS_PER_UNIT
;
1526 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1527 m_iFlags
|= wxPG_FL_SCROLLED
;
1530 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1532 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1533 m_iFlags
|= wxPG_FL_SCROLLED
;
1543 // -----------------------------------------------------------------------
1544 // wxPropertyGrid helper methods called by properties
1545 // -----------------------------------------------------------------------
1547 // Control font changer helper.
1548 void wxPropertyGrid::SetCurControlBoldFont()
1550 wxASSERT( m_wndEditor
);
1551 m_wndEditor
->SetFont( m_captionFont
);
1554 // -----------------------------------------------------------------------
1556 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1559 #if wxPG_SMALL_SCREEN
1560 // On small-screen devices, always show dialogs with default position and size.
1561 return wxDefaultPosition
;
1563 int splitterX
= GetSplitterPosition();
1567 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1569 ImprovedClientToScreen( &x
, &y
);
1571 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1572 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1579 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1589 new_y
= y
+ m_lineHeight
;
1591 return wxPoint(new_x
,new_y
);
1595 // -----------------------------------------------------------------------
1597 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1599 if ( src_str
.length() == 0 )
1605 bool prev_is_slash
= false;
1607 wxString::const_iterator i
= src_str
.begin();
1611 for ( ; i
!= src_str
.end(); i
++ )
1615 if ( a
!= wxS('\\') )
1617 if ( !prev_is_slash
)
1623 if ( a
== wxS('n') )
1626 dst_str
<< wxS('\n');
1628 dst_str
<< wxS('\n');
1631 else if ( a
== wxS('t') )
1632 dst_str
<< wxS('\t');
1636 prev_is_slash
= false;
1640 if ( prev_is_slash
)
1642 dst_str
<< wxS('\\');
1643 prev_is_slash
= false;
1647 prev_is_slash
= true;
1654 // -----------------------------------------------------------------------
1656 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1658 if ( src_str
.length() == 0 )
1664 wxString::const_iterator i
= src_str
.begin();
1665 wxUniChar prev_a
= wxS('\0');
1669 for ( ; i
!= src_str
.end(); i
++ )
1673 if ( a
>= wxS(' ') )
1675 // This surely is not something that requires an escape sequence.
1680 // This might need...
1681 if ( a
== wxS('\r') )
1683 // DOS style line end.
1684 // Already taken care below
1686 else if ( a
== wxS('\n') )
1687 // UNIX style line end.
1688 dst_str
<< wxS("\\n");
1689 else if ( a
== wxS('\t') )
1691 dst_str
<< wxS('\t');
1694 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1704 // -----------------------------------------------------------------------
1706 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1710 return (wxPGProperty
*) NULL
;
1713 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1716 // -----------------------------------------------------------------------
1717 // wxPropertyGrid graphics related methods
1718 // -----------------------------------------------------------------------
1720 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1724 // Update everything inside the box
1725 wxRect r
= GetUpdateRegion().GetBox();
1727 dc
.SetPen(m_colEmptySpace
);
1728 dc
.SetBrush(m_colEmptySpace
);
1729 dc
.DrawRectangle(r
);
1732 // -----------------------------------------------------------------------
1734 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1735 wxPGProperty
* property
) const
1737 // Prepare rectangle to be used
1739 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1740 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1742 #if (wxPG_USE_RENDERER_NATIVE)
1744 #elif wxPG_ICON_WIDTH
1745 // Drawing expand/collapse button manually
1746 dc
.SetPen(m_colPropFore
);
1747 if ( property
->IsCategory() )
1748 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1750 dc
.SetBrush(m_colPropBack
);
1752 dc
.DrawRectangle( r
);
1753 int _y
= r
.y
+(m_iconWidth
/2);
1754 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1759 if ( property
->IsExpanded() )
1761 // wxRenderer functions are non-mutating in nature, so it
1762 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1763 // Hopefully this does not cause problems.
1764 #if (wxPG_USE_RENDERER_NATIVE)
1765 wxRendererNative::Get().DrawTreeItemButton(
1771 #elif wxPG_ICON_WIDTH
1780 #if (wxPG_USE_RENDERER_NATIVE)
1781 wxRendererNative::Get().DrawTreeItemButton(
1787 #elif wxPG_ICON_WIDTH
1788 int _x
= r
.x
+(m_iconWidth
/2);
1789 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1795 #if (wxPG_USE_RENDERER_NATIVE)
1797 #elif wxPG_ICON_WIDTH
1800 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1804 // -----------------------------------------------------------------------
1807 // This is the one called by OnPaint event handler and others.
1808 // topy and bottomy are already unscrolled (ie. physical)
1810 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1812 unsigned int bottomy
,
1813 const wxRect
* clipRect
)
1815 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1817 m_pState
->EnsureVirtualHeight();
1819 wxRect tempClipRect
;
1822 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1823 clipRect
= &tempClipRect
;
1826 // items added check
1827 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1829 int paintFinishY
= 0;
1831 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1834 bool isBuffered
= false;
1836 #if wxPG_DOUBLE_BUFFER
1837 wxMemoryDC
* bufferDC
= NULL
;
1839 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1841 if ( !m_doubleBuffer
)
1843 paintFinishY
= clipRect
->y
;
1848 bufferDC
= new wxMemoryDC();
1850 // If nothing was changed, then just copy from double-buffer
1851 bufferDC
->SelectObject( *m_doubleBuffer
);
1861 dc
.SetClippingRegion( *clipRect
);
1862 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1865 #if wxPG_DOUBLE_BUFFER
1868 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1869 bufferDC
, 0, 0, wxCOPY
);
1870 dc
.DestroyClippingRegion(); // Is this really necessary?
1876 // Clear area beyond bottomY?
1877 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1879 dc
.SetPen(m_colEmptySpace
);
1880 dc
.SetBrush(m_colEmptySpace
);
1881 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1885 // -----------------------------------------------------------------------
1887 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1888 const wxPGProperty
* firstItem
,
1889 const wxPGProperty
* lastItem
,
1890 const wxRect
* clipRect
,
1891 bool isBuffered
) const
1893 // TODO: This should somehow be eliminated.
1894 wxRect tempClipRect
;
1897 wxASSERT(firstItem
);
1899 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1900 clipRect
= &tempClipRect
;
1904 firstItem
= DoGetItemAtY(clipRect
->y
);
1908 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1910 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1913 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1916 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1917 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1919 int lh
= m_lineHeight
;
1922 int lastItemBottomY
;
1924 firstItemTopY
= clipRect
->y
;
1925 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1927 // Align y coordinates to item boundaries
1928 firstItemTopY
-= firstItemTopY
% lh
;
1929 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1930 lastItemBottomY
-= 1;
1932 // Entire range outside scrolled, visible area?
1933 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1936 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1940 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1941 firstItem->GetLabel().c_str(),
1942 lastItem->GetLabel().c_str(),
1943 (int)(lastItemBottomY - firstItemTopY),
1945 (unsigned long)clipRect );
1950 long windowStyle
= m_windowStyle
;
1956 // With wxPG_DOUBLE_BUFFER, do double buffering
1957 // - buffer's y = 0, so align cliprect and coordinates to that
1959 #if wxPG_DOUBLE_BUFFER
1965 xRelMod
= clipRect
->x
;
1966 yRelMod
= clipRect
->y
;
1969 // clipRect conversion
1977 firstItemTopY
-= yRelMod
;
1978 lastItemBottomY
-= yRelMod
;
1981 wxUnusedVar(isBuffered
);
1984 int x
= m_marginWidth
- xRelMod
;
1986 const wxFont
& normalfont
= m_font
;
1988 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1990 bool isEnabled
= IsEnabled();
1993 // Prepare some pens and brushes that are often changed to.
1996 wxBrush
marginBrush(m_colMargin
);
1997 wxPen
marginPen(m_colMargin
);
1998 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1999 wxPen
linepen(m_colLine
,1,wxSOLID
);
2001 // pen that has same colour as text
2002 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2005 // Clear margin with background colour
2007 dc
.SetBrush( marginBrush
);
2008 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2010 dc
.SetPen( *wxTRANSPARENT_PEN
);
2011 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2014 const wxPGProperty
* selected
= m_selected
;
2015 const wxPropertyGridPageState
* state
= m_pState
;
2017 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2018 bool wasSelectedPainted
= false;
2021 // TODO: Only render columns that are within clipping region.
2023 dc
.SetFont(normalfont
);
2025 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2026 int endScanBottomY
= lastItemBottomY
+ lh
;
2027 int y
= firstItemTopY
;
2030 // Pregenerate list of visible properties.
2031 wxArrayPGProperty visPropArray
;
2032 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2034 for ( ; !it
.AtEnd(); it
.Next() )
2036 const wxPGProperty
* p
= *it
;
2038 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2040 visPropArray
.push_back((wxPGProperty
*)p
);
2042 if ( y
> endScanBottomY
)
2049 visPropArray
.push_back(NULL
);
2051 wxPGProperty
* nextP
= visPropArray
[0];
2053 int gridWidth
= state
->m_width
;
2056 for ( unsigned int arrInd
=1;
2057 nextP
&& y
<= lastItemBottomY
;
2060 wxPGProperty
* p
= nextP
;
2061 nextP
= visPropArray
[arrInd
];
2063 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2064 int textMarginHere
= x
;
2065 int renderFlags
= wxPGCellRenderer::Control
;
2067 int greyDepth
= m_marginWidth
;
2068 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2069 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2071 int greyDepthX
= greyDepth
- xRelMod
;
2073 // Use basic depth if in non-categoric mode and parent is base array.
2074 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2076 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2079 // Paint margin area
2080 dc
.SetBrush(marginBrush
);
2081 dc
.SetPen(marginPen
);
2082 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2084 dc
.SetPen( linepen
);
2089 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2095 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2097 sx
+= state
->m_colWidths
[si
];
2098 dc
.DrawLine( sx
, y
, sx
, y2
);
2101 // Horizontal Line, below
2102 // (not if both this and next is category caption)
2103 if ( p
->IsCategory() &&
2104 nextP
&& nextP
->IsCategory() )
2105 dc
.SetPen(m_colCapBack
);
2107 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2109 if ( p
== selected
)
2111 renderFlags
|= wxPGCellRenderer::Selected
;
2112 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2113 wasSelectedPainted
= true;
2121 if ( p
->IsCategory() )
2123 if ( p
->m_fgColIndex
== 0 )
2124 rowFgCol
= m_colCapFore
;
2126 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2127 rowBgBrush
= wxBrush(m_colCapBack
);
2129 else if ( p
!= selected
)
2131 // Disabled may get different colour.
2132 if ( !p
->IsEnabled() )
2133 rowFgCol
= m_colDisPropFore
;
2135 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2137 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2141 // Selected gets different colour.
2142 if ( reallyFocused
)
2144 rowFgCol
= m_colSelFore
;
2145 rowBgBrush
= wxBrush(m_colSelBack
);
2147 else if ( isEnabled
)
2149 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2150 rowBgBrush
= marginBrush
;
2154 rowFgCol
= m_colDisPropFore
;
2155 rowBgBrush
= wxBrush(m_colSelBack
);
2159 bool fontChanged
= false;
2161 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2166 if ( p
->IsCategory() )
2168 // Captions are all cells merged as one
2169 dc
.SetFont(m_captionFont
);
2171 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2173 dc
.SetBrush(rowBgBrush
);
2174 dc
.SetPen(rowBgBrush
.GetColour());
2175 dc
.SetTextForeground(rowFgCol
);
2177 dc
.DrawRectangle(cellRect
);
2180 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2181 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2184 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2185 DrawExpanderButton( dc
, butRect
, p
);
2189 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2191 dc
.SetFont(m_captionFont
);
2197 int nextCellWidth
= state
->m_colWidths
[0];
2198 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2199 int textXAdd
= textMarginHere
- greyDepthX
;
2201 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2203 cellRect
.width
= nextCellWidth
- 1;
2205 bool ctrlCell
= false;
2208 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2210 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2211 dc
.SetBrush(editorBgCol
);
2212 dc
.SetPen(editorBgCol
);
2213 dc
.SetTextForeground(m_colPropFore
);
2215 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2220 dc
.SetBrush(rowBgBrush
);
2221 dc
.SetPen(rowBgBrush
.GetColour());
2222 dc
.SetTextForeground(rowFgCol
);
2225 dc
.DrawRectangle(cellRect
);
2228 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2229 DrawExpanderButton( dc
, butRect
, p
);
2231 dc
.SetClippingRegion(cellRect
);
2233 cellRect
.x
+= textXAdd
;
2234 cellRect
.width
-= textXAdd
;
2239 wxPGCellRenderer
* renderer
;
2240 int cmnVal
= p
->GetCommonValue();
2241 if ( cmnVal
== -1 || ci
!= 1 )
2243 renderer
= p
->GetCellRenderer(ci
);
2244 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2248 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2249 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2253 cellX
+= state
->m_colWidths
[ci
];
2254 if ( ci
< (state
->m_colWidths
.size()-1) )
2255 nextCellWidth
= state
->m_colWidths
[ci
+1];
2257 dc
.DestroyClippingRegion(); // Is this really necessary?
2263 dc
.SetFont(normalfont
);
2268 // Refresh editor controls (seems not needed on msw)
2269 // NOTE: This code is mandatory for GTK!
2270 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2271 if ( wasSelectedPainted
)
2274 m_wndEditor
->Refresh();
2276 m_wndEditor2
->Refresh();
2283 // -----------------------------------------------------------------------
2285 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2289 if ( m_width
< 10 || m_height
< 10 ||
2290 !m_pState
->m_properties
->GetChildCount() ||
2291 p1
== (wxPGProperty
*) NULL
)
2292 return wxRect(0,0,0,0);
2297 // Return rect which encloses the given property range
2299 int visTop
= p1
->GetY();
2302 visBottom
= p2
->GetY() + m_lineHeight
;
2304 visBottom
= m_height
+ visTop
;
2306 // If seleced property is inside the range, we'll extend the range to include
2308 wxPGProperty
* selected
= m_selected
;
2311 int selectedY
= selected
->GetY();
2312 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2314 wxWindow
* editor
= GetEditorControl();
2317 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2318 if ( visBottom2
> visBottom
)
2319 visBottom
= visBottom2
;
2324 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2327 // -----------------------------------------------------------------------
2329 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2334 if ( m_pState
->m_itemsAdded
)
2335 PrepareAfterItemsAdded();
2337 wxRect r
= GetPropertyRect(p1
, p2
);
2340 m_canvas
->RefreshRect(r
);
2344 // -----------------------------------------------------------------------
2346 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2348 if ( p
== m_selected
)
2349 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2351 DrawItemAndChildren(p
);
2354 // -----------------------------------------------------------------------
2356 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2361 // Draw item, children, and parent too, if it is not category
2362 wxPGProperty
* parent
= p
->GetParent();
2365 !parent
->IsCategory() &&
2366 parent
->GetParent() )
2369 parent
= parent
->GetParent();
2372 DrawItemAndChildren(p
);
2375 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2377 wxCHECK_RET( p
, wxT("invalid property id") );
2379 // Do not draw if in non-visible page
2380 if ( p
->GetParentState() != m_pState
)
2383 // do not draw a single item if multiple pending
2384 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2387 wxWindow
* wndPrimary
= GetEditorControl();
2389 // Update child control.
2390 if ( m_selected
&& m_selected
->GetParent() == p
)
2391 m_selected
->UpdateControl(wndPrimary
);
2393 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2395 DrawItems(p
, lastDrawn
);
2398 // -----------------------------------------------------------------------
2400 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2401 const wxRect
*rect
)
2403 PrepareAfterItemsAdded();
2405 wxWindow::Refresh(false);
2407 // TODO: Coordinate translation
2408 m_canvas
->Refresh(false, rect
);
2410 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2411 // I think this really helps only GTK+1.2
2412 if ( m_wndEditor
) m_wndEditor
->Refresh();
2413 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2417 // -----------------------------------------------------------------------
2418 // wxPropertyGrid global operations
2419 // -----------------------------------------------------------------------
2421 void wxPropertyGrid::Clear()
2425 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2426 wxPG_CHECK_RET_DBG( selRes
,
2427 wxT("failed to deselect a property (editor probably had invalid value)") );
2430 m_pState
->DoClear();
2436 RecalculateVirtualSize();
2438 // Need to clear some area at the end
2440 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2443 // -----------------------------------------------------------------------
2445 bool wxPropertyGrid::EnableCategories( bool enable
)
2447 if ( !ClearSelection() )
2453 // Enable categories
2456 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2461 // Disable categories
2463 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2466 if ( !m_pState
->EnableCategories(enable
) )
2471 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2473 m_pState
->m_itemsAdded
= 1; // force
2474 PrepareAfterItemsAdded();
2478 m_pState
->m_itemsAdded
= 1;
2480 // No need for RecalculateVirtualSize() here - it is already called in
2481 // wxPropertyGridPageState method above.
2488 // -----------------------------------------------------------------------
2490 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2492 wxASSERT( pNewState
);
2493 wxASSERT( pNewState
->GetGrid() );
2495 if ( pNewState
== m_pState
)
2498 wxPGProperty
* oldSelection
= m_selected
;
2503 bool selRes
= ClearSelection();
2504 wxPG_CHECK_RET_DBG( selRes
,
2505 wxT("failed to deselect a property (editor probably had invalid value)") );
2508 m_pState
->m_selected
= oldSelection
;
2510 bool orig_mode
= m_pState
->IsInNonCatMode();
2511 bool new_state_mode
= pNewState
->IsInNonCatMode();
2513 m_pState
= pNewState
;
2516 int pgWidth
= GetClientSize().x
;
2517 if ( HasVirtualWidth() )
2519 int minWidth
= pgWidth
;
2520 if ( pNewState
->m_width
< minWidth
)
2522 pNewState
->m_width
= minWidth
;
2523 pNewState
->CheckColumnWidths();
2529 // Just in case, fully re-center splitter
2530 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2531 pNewState
->m_fSplitterX
= -1.0;
2533 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2536 m_propHover
= (wxPGProperty
*) NULL
;
2538 // If necessary, convert state to correct mode.
2539 if ( orig_mode
!= new_state_mode
)
2541 // This should refresh as well.
2542 EnableCategories( orig_mode
?false:true );
2544 else if ( !m_frozen
)
2546 // Refresh, if not frozen.
2547 if ( m_pState
->m_itemsAdded
)
2548 PrepareAfterItemsAdded();
2551 if ( m_pState
->m_selected
)
2552 DoSelectProperty( m_pState
->m_selected
);
2554 RecalculateVirtualSize(0);
2558 m_pState
->m_itemsAdded
= 1;
2561 // -----------------------------------------------------------------------
2563 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2565 wxPG_PROP_ARG_CALL_PROLOG()
2567 m_pState
->SortChildren( p
);
2570 // -----------------------------------------------------------------------
2572 void wxPropertyGrid::Sort()
2574 bool selRes
= ClearSelection(); // This must be before state clear
2575 wxPG_CHECK_RET_DBG( selRes
,
2576 wxT("failed to deselect a property (editor probably had invalid value)") );
2581 // -----------------------------------------------------------------------
2583 // Call to SetSplitterPosition will always disable splitter auto-centering
2584 // if parent window is shown.
2585 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2587 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2590 wxPropertyGridPageState
* state
= m_pState
;
2592 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2597 CorrectEditorWidgetSizeX();
2603 // -----------------------------------------------------------------------
2605 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2607 SetSplitterPosition( m_width
/2, true );
2608 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2609 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2612 // -----------------------------------------------------------------------
2613 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2614 // -----------------------------------------------------------------------
2616 // Returns nearest paint visible property (such that will be painted unless
2617 // window is scrolled or resized). If given property is paint visible, then
2618 // it itself will be returned
2619 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2621 int vx
,vy1
;// Top left corner of client
2622 GetViewStart(&vx
,&vy1
);
2623 vy1
*= wxPG_PIXELS_PER_UNIT
;
2625 int vy2
= vy1
+ m_height
;
2626 int propY
= p
->GetY2(m_lineHeight
);
2628 if ( (propY
+ m_lineHeight
) < vy1
)
2631 return DoGetItemAtY( vy1
);
2633 else if ( propY
> vy2
)
2636 return DoGetItemAtY( vy2
);
2639 // Itself paint visible
2644 // -----------------------------------------------------------------------
2645 // Methods related to change in value, value modification and sending events
2646 // -----------------------------------------------------------------------
2648 // commits any changes in editor of selected property
2649 // return true if validation did not fail
2650 // flags are same as with DoSelectProperty
2651 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2653 // Committing already?
2654 if ( m_inCommitChangesFromEditor
)
2657 // Don't do this if already processing editor event. It might
2658 // induce recursive dialogs and crap like that.
2659 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2661 if ( m_inDoPropertyChanged
)
2668 IsEditorsValueModified() &&
2669 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2672 m_inCommitChangesFromEditor
= 1;
2674 wxVariant
variant(m_selected
->GetValueRef());
2675 bool valueIsPending
= false;
2677 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2678 // due to another window getting focus
2679 wxWindow
* oldFocus
= m_curFocused
;
2681 bool validationFailure
= false;
2682 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2684 m_chgInfo_changedProperty
= NULL
;
2686 // If truly modified, schedule value as pending.
2687 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2689 if ( DoEditorValidate() &&
2690 PerformValidation(m_selected
, variant
) )
2692 valueIsPending
= true;
2696 validationFailure
= true;
2701 EditorsValueWasNotModified();
2706 m_inCommitChangesFromEditor
= 0;
2708 if ( validationFailure
&& !forceSuccess
)
2712 oldFocus
->SetFocus();
2713 m_curFocused
= oldFocus
;
2716 res
= OnValidationFailure(m_selected
, variant
);
2718 // Now prevent further validation failure messages
2721 EditorsValueWasNotModified();
2722 OnValidationFailureReset(m_selected
);
2725 else if ( valueIsPending
)
2727 DoPropertyChanged( m_selected
, flags
);
2728 EditorsValueWasNotModified();
2737 // -----------------------------------------------------------------------
2739 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2742 // Runs all validation functionality.
2743 // Returns true if value passes all tests.
2746 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2748 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2750 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2755 // Adapt list to child values, if necessary
2756 wxVariant listValue
= pendingValue
;
2757 wxVariant
* pPendingValue
= &pendingValue
;
2758 wxVariant
* pList
= NULL
;
2760 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2761 // string value, then we need treat as it was changed instead
2762 // (or, in addition, as is the case with composite string parent).
2763 // This includes creating list variant for child values.
2765 wxPGProperty
* pwc
= p
->GetParent();
2766 wxPGProperty
* changedProperty
= p
;
2767 wxPGProperty
* baseChangedProperty
= changedProperty
;
2768 wxVariant bcpPendingList
;
2770 listValue
= pendingValue
;
2771 listValue
.SetName(p
->GetBaseName());
2774 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2776 wxVariantList tempList
;
2777 wxVariant
lv(tempList
, pwc
->GetBaseName());
2778 lv
.Append(listValue
);
2780 pPendingValue
= &listValue
;
2782 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2784 baseChangedProperty
= pwc
;
2785 bcpPendingList
= lv
;
2788 changedProperty
= pwc
;
2789 pwc
= pwc
->GetParent();
2793 wxPGProperty
* evtChangingProperty
= changedProperty
;
2795 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2797 value
= *pPendingValue
;
2801 // Convert list to child values
2802 pList
= pPendingValue
;
2803 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2806 wxVariant evtChangingValue
= value
;
2808 // FIXME: After proper ValueToString()s added, remove
2809 // this. It is just a temporary fix, as evt_changing
2810 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2811 // (unless it is selected, and textctrl editor is open).
2812 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2814 evtChangingProperty
= baseChangedProperty
;
2815 if ( evtChangingProperty
!= p
)
2817 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2821 evtChangingValue
= pendingValue
;
2825 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2827 if ( changedProperty
== m_selected
)
2829 wxWindow
* editor
= GetEditorControl();
2830 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2831 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2835 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2839 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2840 m_chgInfo_changedProperty
= changedProperty
;
2841 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2842 m_chgInfo_pendingValue
= value
;
2845 m_chgInfo_valueList
= *pList
;
2847 m_chgInfo_valueList
.MakeNull();
2849 // If changedProperty is not property which value was edited,
2850 // then call wxPGProperty::ValidateValue() for that as well.
2851 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2853 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2857 // SendEvent returns true if event was vetoed
2858 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2864 // -----------------------------------------------------------------------
2866 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2868 if ( !msg
.length() )
2872 if ( !wxPGGlobalVars
->m_offline
)
2874 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2877 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2880 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2883 pStatusBar
->SetStatusText(msg
);
2891 ::wxMessageBox(msg
, _T("Property Error"));
2894 // -----------------------------------------------------------------------
2896 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2898 int vfb
= m_validationInfo
.m_failureBehavior
;
2900 if ( vfb
& wxPG_VFB_BEEP
)
2903 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2904 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2906 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2907 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2909 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2911 wxColour vfbFg
= *wxWHITE
;
2912 wxColour vfbBg
= *wxRED
;
2913 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2914 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2916 DrawItemAndChildren(property
);
2918 if ( property
== m_selected
)
2920 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2922 wxWindow
* editor
= GetEditorControl();
2925 editor
->SetForegroundColour(vfbFg
);
2926 editor
->SetBackgroundColour(vfbBg
);
2932 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2934 wxString msg
= m_validationInfo
.m_failureMessage
;
2936 if ( !msg
.length() )
2937 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2939 DoShowPropertyError(property
, msg
);
2942 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2945 // -----------------------------------------------------------------------
2947 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2949 int vfb
= m_validationInfo
.m_failureBehavior
;
2951 if ( vfb
& wxPG_VFB_MARK_CELL
)
2953 property
->SetCell(0, NULL
);
2954 property
->SetCell(1, NULL
);
2956 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2958 if ( property
== m_selected
&& GetEditorControl() )
2960 // Calling this will recreate the control, thus resetting its colour
2961 RefreshProperty(property
);
2965 DrawItemAndChildren(property
);
2970 // -----------------------------------------------------------------------
2972 // flags are same as with DoSelectProperty
2973 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2975 if ( m_inDoPropertyChanged
)
2978 wxWindow
* editor
= GetEditorControl();
2980 m_pState
->m_anyModified
= 1;
2982 m_inDoPropertyChanged
= 1;
2984 // Maybe need to update control
2985 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2987 // These values were calculated in PerformValidation()
2988 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2989 wxVariant value
= m_chgInfo_pendingValue
;
2991 wxPGProperty
* topPaintedProperty
= changedProperty
;
2993 while ( !topPaintedProperty
->IsCategory() &&
2994 !topPaintedProperty
->IsRoot() )
2996 topPaintedProperty
= topPaintedProperty
->GetParent();
2999 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3001 // Set as Modified (not if dragging just began)
3002 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3004 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3005 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3008 SetCurControlBoldFont();
3014 // Propagate updates to parent(s)
3016 wxPGProperty
* prevPwc
= NULL
;
3018 while ( prevPwc
!= topPaintedProperty
)
3020 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3022 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3025 SetCurControlBoldFont();
3029 pwc
= pwc
->GetParent();
3032 // Draw the actual property
3033 DrawItemAndChildren( topPaintedProperty
);
3036 // If value was set by wxPGProperty::OnEvent, then update the editor
3038 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3041 p
->GetEditorClass()->UpdateControl(p
, editor
);
3045 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3046 if ( m_wndEditor
) m_wndEditor
->Refresh();
3047 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3052 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3054 // If top parent has composite string value, then send to child parents,
3055 // starting from baseChangedProperty.
3056 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3058 pwc
= m_chgInfo_baseChangedProperty
;
3060 while ( pwc
!= changedProperty
)
3062 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3063 pwc
= pwc
->GetParent();
3067 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3069 m_inDoPropertyChanged
= 0;
3074 // -----------------------------------------------------------------------
3076 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3078 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3080 m_chgInfo_changedProperty
= NULL
;
3082 if ( PerformValidation(p
, newValue
) )
3084 DoPropertyChanged(p
);
3089 OnValidationFailure(p
, newValue
);
3095 // -----------------------------------------------------------------------
3097 // Runs wxValidator for the selected property
3098 bool wxPropertyGrid::DoEditorValidate()
3103 // -----------------------------------------------------------------------
3105 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3107 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3108 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3110 wxWindow
* parent
= wnd
->GetParent();
3113 (parent
== m_canvas
||
3114 parent
->GetParent() == m_canvas
) )
3116 OnCustomEditorEvent((wxCommandEvent
&)event
);
3120 return wxPanel::ProcessEvent(event
);
3123 // -----------------------------------------------------------------------
3125 // NB: It may really not be wxCommandEvent - must check if necessary
3127 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3129 wxPGProperty
* selected
= m_selected
;
3132 // Somehow, event is handled after property has been deselected.
3133 // Possibly, but very rare.
3137 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3140 wxVariant
pendingValue(selected
->GetValueRef());
3141 wxWindow
* wnd
= GetEditorControl();
3143 bool wasUnspecified
= selected
->IsValueUnspecified();
3144 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3146 bool valueIsPending
= false;
3148 m_chgInfo_changedProperty
= NULL
;
3150 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3153 // Filter out excess wxTextCtrl modified events
3154 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3156 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3158 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3160 wxString newTcValue
= tc
->GetValue();
3161 if ( m_prevTcValue
== newTcValue
)
3164 m_prevTcValue
= newTcValue
;
3167 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3169 bool validationFailure
= false;
3170 bool buttonWasHandled
= false;
3173 // Try common button handling
3174 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3176 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3180 buttonWasHandled
= true;
3181 // Store as res2, as previously (and still currently alternatively)
3182 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3183 // in wxPGProperty::OnEvent().
3184 adapter
->ShowDialog( this, selected
);
3189 if ( !buttonWasHandled
)
3193 // First call editor class' event handler.
3194 const wxPGEditor
* editor
= selected
->GetEditorClass();
3196 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3198 // If changes, validate them
3199 if ( DoEditorValidate() )
3201 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3202 valueIsPending
= true;
3206 validationFailure
= true;
3211 // Then the property's custom handler (must be always called, unless
3212 // validation failed).
3213 if ( !validationFailure
)
3214 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3217 // SetValueInEvent(), as called in one of the functions referred above
3218 // overrides editor's value.
3219 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3221 valueIsPending
= true;
3222 pendingValue
= m_changeInEventValue
;
3223 selFlags
|= wxPG_SEL_DIALOGVAL
;
3226 if ( !validationFailure
&& valueIsPending
)
3227 if ( !PerformValidation(m_selected
, pendingValue
) )
3228 validationFailure
= true;
3230 if ( validationFailure
)
3232 OnValidationFailure(selected
, pendingValue
);
3234 else if ( valueIsPending
)
3236 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3238 DoPropertyChanged(selected
, selFlags
);
3239 EditorsValueWasNotModified();
3242 // Regardless of editor type, unfocus editor on
3243 // text-editing related enter press.
3244 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3251 // No value after all
3253 // Let unhandled button click events go to the parent
3254 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3256 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3257 GetEventHandler()->AddPendingEvent(evt
);
3261 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3264 // -----------------------------------------------------------------------
3265 // wxPropertyGrid editor control helper methods
3266 // -----------------------------------------------------------------------
3268 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3270 int itemy
= p
->GetY2(m_lineHeight
);
3272 int cust_img_space
= 0;
3273 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3274 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3276 // TODO: If custom image detection changes from current, change this.
3277 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3279 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3280 int imwid
= p
->OnMeasureImage().x
;
3281 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3282 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3287 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3289 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3294 // -----------------------------------------------------------------------
3296 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3298 wxSize sz
= GetImageSize(p
, item
);
3299 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3300 wxPG_CUSTOM_IMAGE_SPACINGY
,
3305 // return size of custom paint image
3306 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3308 // If called with NULL property, then return default image
3309 // size for properties that use image.
3311 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3313 wxSize cis
= p
->OnMeasureImage(item
);
3315 int choiceCount
= p
->m_choices
.GetCount();
3316 int comVals
= p
->GetDisplayedCommonValueCount();
3317 if ( item
>= choiceCount
&& comVals
> 0 )
3319 unsigned int cvi
= item
-choiceCount
;
3320 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3322 else if ( item
>= 0 && choiceCount
== 0 )
3323 return wxSize(0, 0);
3328 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3333 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3340 // -----------------------------------------------------------------------
3342 // takes scrolling into account
3343 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3346 GetViewStart(&vx
,&vy
);
3347 vy
*=wxPG_PIXELS_PER_UNIT
;
3348 vx
*=wxPG_PIXELS_PER_UNIT
;
3351 ClientToScreen( px
, py
);
3354 // -----------------------------------------------------------------------
3356 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3359 GetViewStart(&pt2
.x
,&pt2
.y
);
3360 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3361 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3365 return m_pState
->HitTest(pt2
);
3368 // -----------------------------------------------------------------------
3370 // custom set cursor
3371 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3373 if ( type
== m_curcursor
&& !override
) return;
3375 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3377 if ( type
== wxCURSOR_SIZEWE
)
3378 cursor
= m_cursorSizeWE
;
3380 m_canvas
->SetCursor( *cursor
);
3385 // -----------------------------------------------------------------------
3386 // wxPropertyGrid property selection
3387 // -----------------------------------------------------------------------
3389 // Setups event handling for child control
3390 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3392 wxWindowID id
= argWnd
->GetId();
3394 if ( argWnd
== m_wndEditor
)
3396 argWnd
->Connect(id
, wxEVT_MOTION
,
3397 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3399 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3400 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3402 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3403 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3405 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3406 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3408 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3409 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3411 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3412 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3417 argWnd
->Connect(id
, wxEVT_NAVIGATION_KEY
,
3418 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3421 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3422 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
),
3424 argWnd
->Connect(id
, wxEVT_KEY_UP
,
3425 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
),
3427 argWnd
->Connect(id
, wxEVT_KILL_FOCUS
,
3428 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
),
3432 void wxPropertyGrid::FreeEditors()
3434 // Do not free editors immediately if processing events
3437 m_wndEditor2
->Hide();
3438 wxPendingDelete
.Append( m_wndEditor2
);
3439 m_wndEditor2
= (wxWindow
*) NULL
;
3444 m_wndEditor
->Hide();
3445 wxPendingDelete
.Append( m_wndEditor
);
3446 m_wndEditor
= (wxWindow
*) NULL
;
3450 // Call with NULL to de-select property
3451 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3453 wxPanel
* canvas
= GetPanel();
3457 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3458 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3460 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3463 if ( m_inDoSelectProperty
)
3466 m_inDoSelectProperty
= 1;
3468 wxPGProperty
* prev
= m_selected
;
3472 m_inDoSelectProperty
= 0;
3477 // If we are frozen, then just set the values.
3480 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3481 m_editorFocused
= 0;
3484 m_pState
->m_selected
= p
;
3486 // If frozen, always free controls. But don't worry, as Thaw will
3487 // recall SelectProperty to recreate them.
3490 // Prevent any further selection measures in this call
3491 p
= (wxPGProperty
*) NULL
;
3496 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3498 // Only set focus if not deselecting
3501 if ( flags
& wxPG_SEL_FOCUS
)
3505 m_wndEditor
->SetFocus();
3506 m_editorFocused
= 1;
3515 m_inDoSelectProperty
= 0;
3520 // First, deactivate previous
3524 OnValidationFailureReset(m_selected
);
3526 // Must double-check if this is an selected in case of forceswitch
3529 if ( !CommitChangesFromEditor(flags
) )
3531 // Validation has failed, so we can't exit the previous editor
3532 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3533 // _("Invalid Value"),wxOK|wxICON_ERROR);
3534 m_inDoSelectProperty
= 0;
3542 m_selected
= (wxPGProperty
*) NULL
;
3543 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3545 // We need to always fully refresh the grid here
3548 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3549 EditorsValueWasNotModified();
3552 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3555 // Then, activate the one given.
3558 int propY
= p
->GetY2(m_lineHeight
);
3560 int splitterX
= GetSplitterPosition();
3561 m_editorFocused
= 0;
3563 m_pState
->m_selected
= p
;
3564 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3566 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3568 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3570 // Do we need OnMeasureCalls?
3571 wxSize imsz
= p
->OnMeasureImage();
3574 // Only create editor for non-disabled non-caption
3575 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3577 // do this for non-caption items
3581 // Do we need to paint the custom image, if any?
3582 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3583 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3584 !p
->GetEditorClass()->CanContainCustomImage()
3586 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3588 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3589 wxPoint goodPos
= grect
.GetPosition();
3590 #if wxPG_CREATE_CONTROLS_HIDDEN
3591 int coord_adjust
= m_height
- goodPos
.y
;
3592 goodPos
.y
+= coord_adjust
;
3595 const wxPGEditor
* editor
= p
->GetEditorClass();
3596 wxCHECK_MSG(editor
, false,
3597 wxT("NULL editor class not allowed"));
3599 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3601 wxPGWindowList wndList
= editor
->CreateControls(this,
3606 m_wndEditor
= wndList
.m_primary
;
3607 m_wndEditor2
= wndList
.m_secondary
;
3608 wxWindow
* primaryCtrl
= GetEditorControl();
3611 // Essentially, primaryCtrl == m_wndEditor
3614 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3615 // value is drawn as normal, and m_wndEditor2 is assumed
3616 // to be a right-aligned button that triggers a separate editorCtrl
3621 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3622 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3624 // Set validator, if any
3625 #if wxUSE_VALIDATORS
3626 wxValidator
* validator
= p
->GetValidator();
3628 primaryCtrl
->SetValidator(*validator
);
3631 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3632 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3634 // If it has modified status, use bold font
3635 // (must be done before capturing m_ctrlXAdjust)
3636 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3637 SetCurControlBoldFont();
3640 // Fix TextCtrl indentation
3641 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3642 wxTextCtrl
* tc
= NULL
;
3643 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3644 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3646 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3648 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3651 // Store x relative to splitter (we'll need it).
3652 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3654 // Check if background clear is not necessary
3655 wxPoint pos
= m_wndEditor
->GetPosition();
3656 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3658 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3661 m_wndEditor
->SetSizeHints(3, 3);
3663 #if wxPG_CREATE_CONTROLS_HIDDEN
3664 m_wndEditor
->Show(false);
3665 m_wndEditor
->Freeze();
3667 goodPos
= m_wndEditor
->GetPosition();
3668 goodPos
.y
-= coord_adjust
;
3669 m_wndEditor
->Move( goodPos
);
3672 SetupChildEventHandling(primaryCtrl
);
3674 // Focus and select all (wxTextCtrl, wxComboBox etc)
3675 if ( flags
& wxPG_SEL_FOCUS
)
3677 primaryCtrl
->SetFocus();
3679 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3685 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3686 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3688 // Get proper id for wndSecondary
3689 m_wndSecId
= m_wndEditor2
->GetId();
3690 wxWindowList children
= m_wndEditor2
->GetChildren();
3691 wxWindowList::iterator node
= children
.begin();
3692 if ( node
!= children
.end() )
3693 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3695 m_wndEditor2
->SetSizeHints(3,3);
3697 #if wxPG_CREATE_CONTROLS_HIDDEN
3698 wxRect sec_rect
= m_wndEditor2
->GetRect();
3699 sec_rect
.y
-= coord_adjust
;
3701 // Fine tuning required to fix "oversized"
3702 // button disappearance bug.
3703 if ( sec_rect
.y
< 0 )
3705 sec_rect
.height
+= sec_rect
.y
;
3708 m_wndEditor2
->SetSize( sec_rect
);
3710 m_wndEditor2
->Show();
3712 SetupChildEventHandling(m_wndEditor2
);
3714 // If no primary editor, focus to button to allow
3715 // it to interprete ENTER etc.
3716 // NOTE: Due to problems focusing away from it, this
3717 // has been disabled.
3719 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3720 m_wndEditor2->SetFocus();
3724 if ( flags
& wxPG_SEL_FOCUS
)
3725 m_editorFocused
= 1;
3730 // Make sure focus is in grid canvas (important for wxGTK, at least)
3734 EditorsValueWasNotModified();
3736 // If it's inside collapsed section, expand parent, scroll, etc.
3737 // Also, if it was partially visible, scroll it into view.
3738 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3743 #if wxPG_CREATE_CONTROLS_HIDDEN
3744 m_wndEditor
->Thaw();
3746 m_wndEditor
->Show(true);
3753 // Make sure focus is in grid canvas
3757 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3763 // Show help text in status bar.
3764 // (if found and grid not embedded in manager with help box and
3765 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3768 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3770 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3771 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3773 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3775 statusbar
= frame
->GetStatusBar();
3780 const wxString
* pHelpString
= (const wxString
*) NULL
;
3784 pHelpString
= &p
->GetHelpString();
3785 if ( pHelpString
->length() )
3787 // Set help box text.
3788 statusbar
->SetStatusText( *pHelpString
);
3789 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3793 if ( (!pHelpString
|| !pHelpString
->length()) &&
3794 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3796 // Clear help box - but only if it was written
3797 // by us at previous time.
3798 statusbar
->SetStatusText( m_emptyString
);
3799 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3805 m_inDoSelectProperty
= 0;
3807 // call wx event handler (here so that it also occurs on deselection)
3808 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3813 // -----------------------------------------------------------------------
3815 bool wxPropertyGrid::UnfocusEditor()
3817 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3820 if ( !CommitChangesFromEditor(0) )
3824 DrawItem(m_selected
);
3829 // -----------------------------------------------------------------------
3831 // This method is not inline because it called dozens of times
3832 // (i.e. two-arg function calls create smaller code size).
3833 bool wxPropertyGrid::DoClearSelection()
3835 return DoSelectProperty((wxPGProperty
*)NULL
);
3838 // -----------------------------------------------------------------------
3839 // wxPropertyGrid expand/collapse state
3840 // -----------------------------------------------------------------------
3842 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3844 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3846 // If active editor was inside collapsed section, then disable it
3847 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3849 if ( !ClearSelection() )
3853 // Store dont-center-splitter flag 'cause we need to temporarily set it
3854 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3855 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3857 bool res
= m_pState
->DoCollapse(pwc
);
3862 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3864 RecalculateVirtualSize();
3866 // Redraw etc. only if collapsed was visible.
3867 if (pwc
->IsVisible() &&
3869 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3871 // When item is collapsed so that scrollbar would move,
3872 // graphics mess is about (unless we redraw everything).
3877 // Clear dont-center-splitter flag if it wasn't set
3878 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3883 // -----------------------------------------------------------------------
3885 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3887 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3889 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3891 // Store dont-center-splitter flag 'cause we need to temporarily set it
3892 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3893 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3895 bool res
= m_pState
->DoExpand(pwc
);
3900 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3902 RecalculateVirtualSize();
3904 // Redraw etc. only if expanded was visible.
3905 if ( pwc
->IsVisible() && !m_frozen
&&
3906 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3910 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3913 DrawItems(pwc
, NULL
);
3918 // Clear dont-center-splitter flag if it wasn't set
3919 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3924 // -----------------------------------------------------------------------
3926 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3929 return m_pState
->DoHideProperty(p
, hide
, flags
);
3932 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3935 if ( !ClearSelection() )
3939 m_pState
->DoHideProperty(p
, hide
, flags
);
3941 RecalculateVirtualSize();
3948 // -----------------------------------------------------------------------
3949 // wxPropertyGrid size related methods
3950 // -----------------------------------------------------------------------
3952 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3954 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3958 // If virtual height was changed, then recalculate editor control position(s)
3959 if ( m_pState
->m_vhCalcPending
)
3960 CorrectEditorWidgetPosY();
3962 m_pState
->EnsureVirtualHeight();
3965 int by1
= m_pState
->GetVirtualHeight();
3966 int by2
= m_pState
->GetActualVirtualHeight();
3969 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3970 wxASSERT_MSG( false,
3976 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3978 int x
= m_pState
->m_width
;
3979 int y
= m_pState
->m_virtualHeight
;
3982 GetClientSize(&width
,&height
);
3984 // Now adjust virtual size.
3985 SetVirtualSize(x
, y
);
3991 // Adjust scrollbars
3992 if ( HasVirtualWidth() )
3994 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3995 xPos
= GetScrollPos( wxHORIZONTAL
);
3998 if ( forceXPos
!= -1 )
4001 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4004 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4005 int yPos
= GetScrollPos( wxVERTICAL
);
4007 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4008 xAmount
, yAmount
, xPos
, yPos
, true );
4010 // Must re-get size now
4011 GetClientSize(&width
,&height
);
4013 if ( !HasVirtualWidth() )
4015 m_pState
->SetVirtualWidth(width
);
4022 m_canvas
->SetSize( x
, y
);
4024 m_pState
->CheckColumnWidths();
4027 CorrectEditorWidgetSizeX();
4029 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4032 // -----------------------------------------------------------------------
4034 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4036 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4040 GetClientSize(&width
,&height
);
4045 #if wxPG_DOUBLE_BUFFER
4046 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4048 int dblh
= (m_lineHeight
*2);
4049 if ( !m_doubleBuffer
)
4051 // Create double buffer bitmap to draw on, if none
4052 int w
= (width
>250)?width
:250;
4053 int h
= height
+ dblh
;
4055 m_doubleBuffer
= new wxBitmap( w
, h
);
4059 int w
= m_doubleBuffer
->GetWidth();
4060 int h
= m_doubleBuffer
->GetHeight();
4062 // Double buffer must be large enough
4063 if ( w
< width
|| h
< (height
+dblh
) )
4065 if ( w
< width
) w
= width
;
4066 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4067 delete m_doubleBuffer
;
4068 m_doubleBuffer
= new wxBitmap( w
, h
);
4075 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4076 m_ncWidth
= event
.GetSize().x
;
4080 if ( m_pState
->m_itemsAdded
)
4081 PrepareAfterItemsAdded();
4083 // Without this, virtual size (atleast under wxGTK) will be skewed
4084 RecalculateVirtualSize();
4090 // -----------------------------------------------------------------------
4092 void wxPropertyGrid::SetVirtualWidth( int width
)
4096 // Disable virtual width
4097 width
= GetClientSize().x
;
4098 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4102 // Enable virtual width
4103 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4105 m_pState
->SetVirtualWidth( width
);
4108 void wxPropertyGrid::SetFocusOnCanvas()
4110 m_canvas
->SetFocusIgnoringChildren();
4111 m_editorFocused
= 0;
4114 // -----------------------------------------------------------------------
4115 // wxPropertyGrid mouse event handling
4116 // -----------------------------------------------------------------------
4118 // selFlags uses same values DoSelectProperty's flags
4119 // Returns true if event was vetoed.
4120 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4122 // Send property grid event of specific type and with specific property
4123 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4124 evt
.SetPropertyGrid(this);
4125 evt
.SetEventObject(m_eventObject
);
4129 evt
.SetCanVeto(true);
4130 evt
.SetupValidationInfo();
4131 m_validationInfo
.m_pValue
= pValue
;
4133 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4135 evtHandler
->ProcessEvent(evt
);
4137 return evt
.WasVetoed();
4140 // -----------------------------------------------------------------------
4142 // Return false if should be skipped
4143 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4147 // Need to set focus?
4148 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4153 wxPropertyGridPageState
* state
= m_pState
;
4155 int splitterHitOffset
;
4156 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4158 wxPGProperty
* p
= DoGetItemAtY(y
);
4162 int depth
= (int)p
->GetDepth() - 1;
4164 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4166 if ( x
>= marginEnds
)
4170 if ( p
->IsCategory() )
4172 // This is category.
4173 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4175 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4177 // Expand, collapse, activate etc. if click on text or left of splitter.
4180 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4185 if ( !DoSelectProperty( p
) )
4188 // On double-click, expand/collapse.
4189 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4191 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4192 else DoExpand( p
, true );
4196 else if ( splitterHit
== -1 )
4199 unsigned int selFlag
= 0;
4200 if ( columnHit
== 1 )
4202 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4203 selFlag
= wxPG_SEL_FOCUS
;
4205 if ( !DoSelectProperty( p
, selFlag
) )
4208 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4210 if ( p
->GetChildCount() && !p
->IsCategory() )
4211 // On double-click, expand/collapse.
4212 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4214 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4215 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4216 else DoExpand( p
, true );
4223 // click on splitter
4224 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4226 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4228 // Double-clicking the splitter causes auto-centering
4229 CenterSplitter( true );
4231 else if ( m_dragStatus
== 0 )
4234 // Begin draggin the splitter
4238 // Changes must be committed here or the
4239 // value won't be drawn correctly
4240 if ( !CommitChangesFromEditor() )
4243 m_wndEditor
->Show ( false );
4246 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4248 m_canvas
->CaptureMouse();
4249 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4253 m_draggedSplitter
= splitterHit
;
4254 m_dragOffset
= splitterHitOffset
;
4256 wxClientDC
dc(m_canvas
);
4258 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4259 // Fixes button disappearance bug
4261 m_wndEditor2
->Show ( false );
4264 m_startingSplitterX
= x
- splitterHitOffset
;
4272 if ( p
->GetChildCount() )
4274 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4276 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4278 int y2
= y
% m_lineHeight
;
4279 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4281 // On click on expander button, expand/collapse
4282 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4283 DoCollapse( p
, true );
4285 DoExpand( p
, true );
4294 // -----------------------------------------------------------------------
4296 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4297 wxMouseEvent
& WXUNUSED(event
) )
4301 // Select property here as well
4302 wxPGProperty
* p
= m_propHover
;
4303 if ( p
!= m_selected
)
4304 DoSelectProperty( p
);
4306 // Send right click event.
4307 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4314 // -----------------------------------------------------------------------
4316 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4317 wxMouseEvent
& WXUNUSED(event
) )
4321 // Select property here as well
4322 wxPGProperty
* p
= m_propHover
;
4324 if ( p
!= m_selected
)
4325 DoSelectProperty( p
);
4327 // Send double-click event.
4328 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4335 // -----------------------------------------------------------------------
4337 #if wxPG_SUPPORT_TOOLTIPS
4339 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4341 if ( tipString
.length() )
4343 m_canvas
->SetToolTip(tipString
);
4347 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4348 m_canvas
->SetToolTip( m_emptyString
);
4350 m_canvas
->SetToolTip( NULL
);
4355 #endif // #if wxPG_SUPPORT_TOOLTIPS
4357 // -----------------------------------------------------------------------
4359 // Return false if should be skipped
4360 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4362 // Safety check (needed because mouse capturing may
4363 // otherwise freeze the control)
4364 if ( m_dragStatus
> 0 && !event
.Dragging() )
4366 HandleMouseUp(x
,y
,event
);
4369 wxPropertyGridPageState
* state
= m_pState
;
4371 int splitterHitOffset
;
4372 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4373 int splitterX
= x
- splitterHitOffset
;
4375 if ( m_dragStatus
> 0 )
4377 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4378 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4381 int newSplitterX
= x
- m_dragOffset
;
4382 int splitterX
= x
- splitterHitOffset
;
4384 // Splitter redraw required?
4385 if ( newSplitterX
!= splitterX
)
4388 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4389 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4390 state
->m_fSplitterX
= (float) newSplitterX
;
4393 CorrectEditorWidgetSizeX();
4407 int ih
= m_lineHeight
;
4410 #if wxPG_SUPPORT_TOOLTIPS
4411 wxPGProperty
* prevHover
= m_propHover
;
4412 unsigned char prevSide
= m_mouseSide
;
4414 int curPropHoverY
= y
- (y
% ih
);
4416 // On which item it hovers
4417 if ( ( !m_propHover
)
4419 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4422 // Mouse moves on another property
4424 m_propHover
= DoGetItemAtY(y
);
4425 m_propHoverY
= curPropHoverY
;
4428 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4431 #if wxPG_SUPPORT_TOOLTIPS
4432 // Store which side we are on
4434 if ( columnHit
== 1 )
4436 else if ( columnHit
== 0 )
4440 // If tooltips are enabled, show label or value as a tip
4441 // in case it doesn't otherwise show in full length.
4443 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4445 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4447 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4449 if ( m_propHover
&& !m_propHover
->IsCategory() )
4452 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4454 // Show help string as a tooltip
4455 wxString tipString
= m_propHover
->GetHelpString();
4457 SetToolTip(tipString
);
4461 // Show cropped value string as a tooltip
4465 if ( m_mouseSide
== 1 )
4467 tipString
= m_propHover
->m_label
;
4468 space
= splitterX
-m_marginWidth
-3;
4470 else if ( m_mouseSide
== 2 )
4472 tipString
= m_propHover
->GetDisplayedString();
4474 space
= m_width
- splitterX
;
4475 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4476 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4482 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4485 SetToolTip( tipString
);
4492 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4493 m_canvas
->SetToolTip( m_emptyString
);
4495 m_canvas
->SetToolTip( NULL
);
4506 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4507 m_canvas
->SetToolTip( m_emptyString
);
4509 m_canvas
->SetToolTip( NULL
);
4517 if ( splitterHit
== -1 ||
4519 HasFlag(wxPG_STATIC_SPLITTER
) )
4521 // hovering on something else
4522 if ( m_curcursor
!= wxCURSOR_ARROW
)
4523 CustomSetCursor( wxCURSOR_ARROW
);
4527 // Do not allow splitter cursor on caption items.
4528 // (also not if we were dragging and its started
4529 // outside the splitter region)
4532 !m_propHover
->IsCategory() &&
4536 // hovering on splitter
4538 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4539 // reliably detected.
4540 //if ( m_curcursor != wxCURSOR_SIZEWE )
4541 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4547 // hovering on something else
4548 if ( m_curcursor
!= wxCURSOR_ARROW
)
4549 CustomSetCursor( wxCURSOR_ARROW
);
4556 // -----------------------------------------------------------------------
4558 // Also handles Leaving event
4559 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4560 wxMouseEvent
&WXUNUSED(event
) )
4562 wxPropertyGridPageState
* state
= m_pState
;
4566 int splitterHitOffset
;
4567 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4569 // No event type check - basicly calling this method should
4570 // just stop dragging.
4571 // Left up after dragged?
4572 if ( m_dragStatus
>= 1 )
4575 // End Splitter Dragging
4577 // DO NOT ENABLE FOLLOWING LINE!
4578 // (it is only here as a reminder to not to do it)
4581 // Disable splitter auto-centering
4582 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4584 // This is necessary to return cursor
4585 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4587 m_canvas
->ReleaseMouse();
4588 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4591 // Set back the default cursor, if necessary
4592 if ( splitterHit
== -1 ||
4595 CustomSetCursor( wxCURSOR_ARROW
);
4600 // Control background needs to be cleared
4601 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4602 DrawItem( m_selected
);
4606 m_wndEditor
->Show ( true );
4609 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4610 // Fixes button disappearance bug
4612 m_wndEditor2
->Show ( true );
4615 // This clears the focus.
4616 m_editorFocused
= 0;
4622 // -----------------------------------------------------------------------
4624 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4626 int splitterX
= GetSplitterPosition();
4629 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4633 wxWindow
* wnd
= GetEditorControl();
4635 // Hide popup on clicks
4636 if ( event
.GetEventType() != wxEVT_MOTION
)
4637 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4639 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4645 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4647 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4648 ux
>= (r
.x
+r
.width
) ||
4650 event
.m_y
>= (r
.y
+r
.height
)
4660 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4665 // -----------------------------------------------------------------------
4667 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4670 if ( OnMouseCommon( event
, &x
, &y
) )
4672 HandleMouseClick(x
,y
,event
);
4677 // -----------------------------------------------------------------------
4679 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4682 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4683 HandleMouseRightClick(x
,y
,event
);
4687 // -----------------------------------------------------------------------
4689 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4691 // Always run standard mouse-down handler as well
4692 OnMouseClick(event
);
4695 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4696 HandleMouseDoubleClick(x
,y
,event
);
4700 // -----------------------------------------------------------------------
4702 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4705 if ( OnMouseCommon( event
, &x
, &y
) )
4707 HandleMouseMove(x
,y
,event
);
4712 // -----------------------------------------------------------------------
4714 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4716 // Called when mouse moves in the empty space below the properties.
4717 CustomSetCursor( wxCURSOR_ARROW
);
4720 // -----------------------------------------------------------------------
4722 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4725 if ( OnMouseCommon( event
, &x
, &y
) )
4727 HandleMouseUp(x
,y
,event
);
4732 // -----------------------------------------------------------------------
4734 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4736 // This may get called from child control as well, so event's
4737 // mouse position cannot be relied on.
4739 if ( event
.Entering() )
4741 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4743 // TODO: Fix this (detect parent and only do
4744 // cursor trick if it is a manager).
4745 wxASSERT( GetParent() );
4746 GetParent()->SetCursor(wxNullCursor
);
4748 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4751 GetParent()->SetCursor(wxNullCursor
);
4753 else if ( event
.Leaving() )
4755 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4756 m_canvas
->SetCursor( wxNullCursor
);
4758 // Get real cursor position
4759 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4761 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4764 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4766 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4770 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4778 // -----------------------------------------------------------------------
4780 // Common code used by various OnMouseXXXChild methods.
4781 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4783 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4784 wxASSERT( topCtrlWnd
);
4786 event
.GetPosition(&x
,&y
);
4788 int splitterX
= GetSplitterPosition();
4790 wxRect r
= topCtrlWnd
->GetRect();
4791 if ( !m_dragStatus
&&
4792 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4793 y
>= 0 && y
< r
.height \
4796 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4801 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4808 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4811 if ( OnMouseChildCommon(event
,&x
,&y
) )
4813 bool res
= HandleMouseClick(x
,y
,event
);
4814 if ( !res
) event
.Skip();
4818 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4821 wxASSERT( m_wndEditor
);
4822 // These coords may not be exact (about +-2),
4823 // but that should not matter (right click is about item, not position).
4824 wxPoint pt
= m_wndEditor
->GetPosition();
4825 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4826 wxASSERT( m_selected
);
4827 m_propHover
= m_selected
;
4828 bool res
= HandleMouseRightClick(x
,y
,event
);
4829 if ( !res
) event
.Skip();
4832 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4835 if ( OnMouseChildCommon(event
,&x
,&y
) )
4837 bool res
= HandleMouseMove(x
,y
,event
);
4838 if ( !res
) event
.Skip();
4842 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4845 if ( OnMouseChildCommon(event
,&x
,&y
) )
4847 bool res
= HandleMouseUp(x
,y
,event
);
4848 if ( !res
) event
.Skip();
4852 // -----------------------------------------------------------------------
4853 // wxPropertyGrid keyboard event handling
4854 // -----------------------------------------------------------------------
4856 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4858 wxNavigationKeyEvent evt
;
4859 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4860 (dir
?wxNavigationKeyEvent::IsForward
:
4861 wxNavigationKeyEvent::IsBackward
));
4862 evt
.SetEventObject(this);
4863 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4867 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4869 // Translates wxKeyEvent to wxPG_ACTION_XXX
4871 int keycode
= event
.GetKeyCode();
4872 int modifiers
= event
.GetModifiers();
4874 wxASSERT( !(modifiers
&~(0xFFFF)) );
4876 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4878 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4880 if ( it
== m_actionTriggers
.end() )
4885 int second
= (it
->second
>>16) & 0xFFFF;
4889 return (it
->second
& 0xFFFF);
4892 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4894 wxASSERT( !(modifiers
&~(0xFFFF)) );
4896 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4898 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4900 if ( it
!= m_actionTriggers
.end() )
4902 // This key combination is already used
4904 // Can add secondary?
4905 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4906 wxT("You can only add up to two separate actions per key combination.") );
4908 action
= it
->second
| (action
<<16);
4911 m_actionTriggers
[hashMapKey
] = action
;
4914 void wxPropertyGrid::ClearActionTriggers( int action
)
4916 wxPGHashMapI2I::iterator it
;
4918 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4920 if ( it
->second
== action
)
4922 m_actionTriggers
.erase(it
);
4927 static void CopyTextToClipboard( const wxString
& text
)
4929 if ( wxTheClipboard
->Open() )
4931 // This data objects are held by the clipboard,
4932 // so do not delete them in the app.
4933 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4934 wxTheClipboard
->Close();
4938 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4941 // Handles key event when editor control is not focused.
4944 wxASSERT( !m_frozen
);
4948 // Travelsal between items, collapsing/expanding, etc.
4949 int keycode
= event
.GetKeyCode();
4951 if ( keycode
== WXK_TAB
)
4953 if ( HasFlag(wxTAB_TRAVERSAL
) )
4954 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
4960 // Ignore Alt and Control when they are down alone
4961 if ( keycode
== WXK_ALT
||
4962 keycode
== WXK_CONTROL
)
4969 int action
= KeyEventToActions(event
, &secondAction
);
4975 if ( ButtonTriggerKeyTest(action
, event
) )
4978 wxPGProperty
* p
= m_selected
;
4980 if ( action
== wxPG_ACTION_COPY
)
4982 CopyTextToClipboard(p
->GetDisplayedString());
4986 // Travel and expand/collapse
4989 if ( p
->GetChildCount() &&
4990 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4993 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4995 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4998 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5000 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5007 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5011 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5022 if ( selectDir
>= -1 )
5024 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5026 DoSelectProperty(p
);
5032 // If nothing was selected, select the first item now
5033 // (or navigate out of tab).
5034 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5036 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5037 if ( p
) DoSelectProperty(p
);
5042 // -----------------------------------------------------------------------
5044 // Potentially handles a keyboard event for editor controls.
5045 // Returns false if event should *not* be skipped (on true it can
5046 // be optionally skipped).
5047 // Basicly, false means that SelectProperty was called (or was about
5048 // to be called, if canDestroy was false).
5049 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5053 if ( !m_selected
|| !m_wndEditor
)
5058 int action
= KeyEventToAction(event
);
5061 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5064 // Esc cancels any changes
5065 if ( IsEditorsValueModified() )
5067 EditorsValueWasNotModified();
5069 // Update the control as well
5070 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5072 m_selected
->GetDisplayedString() );
5075 OnValidationFailureReset(m_selected
);
5081 else if ( action
== wxPG_ACTION_COPY
)
5083 // NB: There is some problem with getting native cut-copy-paste keys to go through
5084 // for embedded editor wxTextCtrl. This is why we emulate.
5086 wxTextCtrl
* tc
= GetEditorTextCtrl();
5089 wxString sel
= tc
->GetStringSelection();
5091 CopyTextToClipboard(sel
);
5095 CopyTextToClipboard(m_selected
->GetDisplayedString());
5098 else if ( action
== wxPG_ACTION_CUT
)
5100 wxTextCtrl
* tc
= GetEditorTextCtrl();
5104 tc
->GetSelection(&from
, &to
);
5107 CopyTextToClipboard(tc
->GetStringSelection());
5108 tc
->Remove(from
, to
);
5112 else if ( action
== wxPG_ACTION_PASTE
)
5114 wxTextCtrl
* tc
= GetEditorTextCtrl();
5117 if (wxTheClipboard
->Open())
5119 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5121 wxTextDataObject data
;
5122 wxTheClipboard
->GetData( data
);
5124 tc
->GetSelection(&from
, &to
);
5127 tc
->Remove(from
, to
);
5128 tc
->WriteText(data
.GetText());
5132 tc
->WriteText(data
.GetText());
5135 wxTheClipboard
->Close();
5143 // -----------------------------------------------------------------------
5145 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5149 // Events to editor controls should get relayed here.
5151 wxWindow
* focused
= wxWindow::FindFocus();
5153 wxWindow
* primaryCtrl
= GetEditorControl();
5156 (focused
==primaryCtrl
5157 || m_editorFocused
) )
5159 // Child key must be processed here, since it can
5160 // destroy the control which is referred by its own
5162 HandleChildKey( event
);
5165 HandleKeyEvent( event
);
5168 // -----------------------------------------------------------------------
5170 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5175 // -----------------------------------------------------------------------
5177 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5179 // Ignore events that occur very close to focus set
5180 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5182 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5187 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5189 int dir
= event
.GetDirection()?1:-1;
5193 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5195 wxWindow
* focused
= wxWindow::FindFocus();
5197 wxWindow
* wndToCheck
= GetEditorControl();
5199 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5200 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5202 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5203 if ( comboTextCtrl
)
5204 wndToCheck
= comboTextCtrl
;
5208 // Because of problems navigating from wxButton, do not go to it.
5211 // No primary, use secondary
5212 wndToCheck = m_wndEditor2;
5214 // If it has editor button, focus to it after the primary editor.
5215 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5216 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5217 // have somewhat debugged in window.cpp itself).
5218 else if ( focused == wndToCheck &&
5220 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5222 wndToCheck = m_wndEditor2;
5223 wxLogDebug(wxT("Exp1"));
5227 if ( focused
!= wndToCheck
&&
5230 wndToCheck
->SetFocus();
5232 // Select all text in wxTextCtrl etc.
5233 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5234 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5236 m_editorFocused
= 1;
5243 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5247 // This allows preventing NavigateOut to occur
5248 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5257 // -----------------------------------------------------------------------
5259 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5264 action
= KeyEventToActions(event
, &secondAction
);
5267 // Does the keycode trigger button?
5268 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5271 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5272 GetEventHandler()->AddPendingEvent(evt
);
5279 // -----------------------------------------------------------------------
5281 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5283 int keycode
= event
.GetKeyCode();
5285 // Ignore Alt and Control when they are down alone
5286 if ( keycode
== WXK_ALT
||
5287 keycode
== WXK_CONTROL
)
5293 if ( ButtonTriggerKeyTest(-1, event
) )
5296 if ( HandleChildKey(event
) == true )
5299 GetEventHandler()->AddPendingEvent(event
);
5302 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5304 GetEventHandler()->AddPendingEvent(event
);
5309 // -----------------------------------------------------------------------
5310 // wxPropertyGrid miscellaneous event handling
5311 // -----------------------------------------------------------------------
5313 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5316 // Check if the focus is in this control or one of its children
5317 wxWindow
* newFocused
= wxWindow::FindFocus();
5319 if ( newFocused
!= m_curFocused
)
5320 HandleFocusChange( newFocused
);
5323 // Called by focus event handlers. newFocused is the window that becomes focused.
5324 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5326 unsigned int oldFlags
= m_iFlags
;
5328 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5330 wxWindow
* parent
= newFocused
;
5332 // This must be one of nextFocus' parents.
5335 // Use m_eventObject, which is either wxPropertyGrid or
5336 // wxPropertyGridManager, as appropriate.
5337 if ( parent
== m_eventObject
)
5339 m_iFlags
|= wxPG_FL_FOCUSED
;
5342 parent
= parent
->GetParent();
5345 m_curFocused
= newFocused
;
5347 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5348 (oldFlags
& wxPG_FL_FOCUSED
) )
5350 // On each focus kill, mark the next nav key event
5351 // to be ignored (can't do on set focus since the
5352 // event would occur before it).
5353 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5355 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5357 // Need to store changed value
5358 CommitChangesFromEditor();
5364 // Preliminary code for tab-order respecting
5365 // tab-traversal (but should be moved to
5368 wxWindow* prevFocus = event.GetWindow();
5369 wxWindow* useThis = this;
5370 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5371 useThis = GetParent();
5374 prevFocus->GetParent() == useThis->GetParent() )
5376 wxList& children = useThis->GetParent()->GetChildren();
5378 wxNode* node = children.Find(prevFocus);
5380 if ( node->GetNext() &&
5381 useThis == node->GetNext()->GetData() )
5382 DoSelectProperty(GetFirst());
5383 else if ( node->GetPrevious () &&
5384 useThis == node->GetPrevious()->GetData() )
5385 DoSelectProperty(GetLastProperty());
5390 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5394 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5395 DrawItem( m_selected
);
5399 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5401 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5402 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5403 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5404 //else if ( event.GetWindow() )
5406 HandleFocusChange(event
.GetWindow());
5411 // -----------------------------------------------------------------------
5413 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5415 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5418 // event.Skip() being commented out is aworkaround for bug reported
5419 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5423 // -----------------------------------------------------------------------
5425 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5427 m_iFlags
|= wxPG_FL_SCROLLED
;
5432 // -----------------------------------------------------------------------
5434 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5436 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5438 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5442 // -----------------------------------------------------------------------
5443 // Property editor related functions
5444 // -----------------------------------------------------------------------
5446 // noDefCheck = true prevents infinite recursion.
5447 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5450 wxASSERT( editorClass
);
5452 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5453 RegisterDefaultEditors();
5455 wxString name
= editorClass
->GetName();
5457 // Existing editor under this name?
5458 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5460 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5461 (wxPGEditor
*) vt_it
->second
,
5462 "Editor with given name was already registered" );
5464 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5469 // Registers all default editor classes
5470 void wxPropertyGrid::RegisterDefaultEditors()
5472 wxPGRegisterDefaultEditorClass( TextCtrl
);
5473 wxPGRegisterDefaultEditorClass( Choice
);
5474 wxPGRegisterDefaultEditorClass( ComboBox
);
5475 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5476 #if wxPG_INCLUDE_CHECKBOX
5477 wxPGRegisterDefaultEditorClass( CheckBox
);
5479 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5481 // Register SpinCtrl etc. editors before use
5482 RegisterAdditionalEditors();
5485 // -----------------------------------------------------------------------
5486 // wxPGStringTokenizer
5487 // Needed to handle C-style string lists (e.g. "str1" "str2")
5488 // -----------------------------------------------------------------------
5490 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5491 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5495 wxPGStringTokenizer::~wxPGStringTokenizer()
5499 bool wxPGStringTokenizer::HasMoreTokens()
5501 const wxString
& str
= *m_str
;
5503 wxString::const_iterator i
= m_curPos
;
5505 wxUniChar delim
= m_delimeter
;
5507 wxUniChar prev_a
= wxT('\0');
5509 bool inToken
= false;
5511 while ( i
!= str
.end() )
5520 m_readyToken
.clear();
5525 if ( prev_a
!= wxT('\\') )
5529 if ( a
!= wxT('\\') )
5549 m_curPos
= str
.end();
5557 wxString
wxPGStringTokenizer::GetNextToken()
5559 return m_readyToken
;
5562 // -----------------------------------------------------------------------
5564 // -----------------------------------------------------------------------
5566 wxPGChoiceEntry::wxPGChoiceEntry()
5567 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5571 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5572 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5573 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5577 // -----------------------------------------------------------------------
5579 // -----------------------------------------------------------------------
5581 wxPGChoicesData::wxPGChoicesData()
5586 wxPGChoicesData::~wxPGChoicesData()
5591 void wxPGChoicesData::Clear()
5595 for ( i
=0; i
<m_items
.size(); i
++ )
5603 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5605 wxASSERT( m_items
.size() == 0 );
5609 for ( i
=0; i
<data
->GetCount(); i
++ )
5610 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5613 // -----------------------------------------------------------------------
5615 // -----------------------------------------------------------------------
5617 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5621 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5622 m_data
->Insert( -1, p
);
5626 // -----------------------------------------------------------------------
5628 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5632 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5633 p
->SetBitmap(bitmap
);
5634 m_data
->Insert( -1, p
);
5638 // -----------------------------------------------------------------------
5640 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5644 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5645 m_data
->Insert(index
, p
);
5649 // -----------------------------------------------------------------------
5651 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5655 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5656 m_data
->Insert( index
, p
);
5660 // -----------------------------------------------------------------------
5662 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5668 while ( index
< GetCount() )
5670 int cmpRes
= GetLabel(index
).Cmp(label
);
5676 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5677 m_data
->Insert( index
, p
);
5681 // -----------------------------------------------------------------------
5683 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5687 unsigned int itemcount
= 0;
5688 const wxChar
** p
= &labels
[0];
5689 while ( *p
) { p
++; itemcount
++; }
5692 for ( i
= 0; i
< itemcount
; i
++ )
5694 int value
= wxPG_INVALID_VALUE
;
5697 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5701 // -----------------------------------------------------------------------
5703 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5708 unsigned int itemcount
= arr
.size();
5710 for ( i
= 0; i
< itemcount
; i
++ )
5712 int value
= wxPG_INVALID_VALUE
;
5715 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5719 // -----------------------------------------------------------------------
5721 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5726 unsigned int itemcount
= arr
.size();
5728 for ( i
= 0; i
< itemcount
; i
++ )
5730 int value
= wxPG_INVALID_VALUE
;
5731 if ( &arrint
&& arrint
.size() )
5733 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5737 // -----------------------------------------------------------------------
5739 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5741 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5743 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5744 delete m_data
->Item(i
);
5745 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5746 m_data
->m_items
.begin()+nIndex
+count
-1);
5749 // -----------------------------------------------------------------------
5751 int wxPGChoices::Index( const wxString
& str
) const
5756 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5758 if ( m_data
->Item(i
)->GetText() == str
)
5765 // -----------------------------------------------------------------------
5767 int wxPGChoices::Index( int val
) const
5772 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5774 if ( m_data
->Item(i
)->GetValue() == val
)
5781 // -----------------------------------------------------------------------
5783 wxArrayString
wxPGChoices::GetLabels() const
5788 if ( this && IsOk() )
5789 for ( i
=0; i
<GetCount(); i
++ )
5790 arr
.push_back(GetLabel(i
));
5795 // -----------------------------------------------------------------------
5797 bool wxPGChoices::HasValues() const
5802 // -----------------------------------------------------------------------
5804 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5811 for ( i
=0; i
< strings
.size(); i
++ )
5813 int index
= Index(strings
[i
]);
5815 arr
.Add(GetValue(index
));
5817 arr
.Add(wxPG_INVALID_VALUE
);
5824 // -----------------------------------------------------------------------
5826 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5827 wxArrayString
* unmatched
) const
5834 for ( i
=0; i
< strings
.size(); i
++ )
5836 const wxString
& str
= strings
[i
];
5837 int index
= Index(str
);
5840 else if ( unmatched
)
5841 unmatched
->Add(str
);
5848 // -----------------------------------------------------------------------
5850 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5854 if ( data
!= wxPGChoicesEmptyData
)
5861 // -----------------------------------------------------------------------
5863 void wxPGChoices::Init()
5865 m_data
= wxPGChoicesEmptyData
;
5868 // -----------------------------------------------------------------------
5870 void wxPGChoices::Free()
5872 if ( m_data
!= wxPGChoicesEmptyData
)
5875 m_data
= wxPGChoicesEmptyData
;
5879 // -----------------------------------------------------------------------
5880 // wxPropertyGridEvent
5881 // -----------------------------------------------------------------------
5883 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5886 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5887 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5888 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5889 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5890 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5891 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5892 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5893 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5894 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5897 // -----------------------------------------------------------------------
5899 void wxPropertyGridEvent::Init()
5901 m_validationInfo
= NULL
;
5903 m_wasVetoed
= false;
5906 // -----------------------------------------------------------------------
5908 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5909 : wxCommandEvent(commandType
,id
)
5915 // -----------------------------------------------------------------------
5917 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5918 : wxCommandEvent(event
)
5920 m_eventType
= event
.GetEventType();
5921 m_eventObject
= event
.m_eventObject
;
5923 m_property
= event
.m_property
;
5924 m_validationInfo
= event
.m_validationInfo
;
5925 m_canVeto
= event
.m_canVeto
;
5926 m_wasVetoed
= event
.m_wasVetoed
;
5929 // -----------------------------------------------------------------------
5931 wxPropertyGridEvent::~wxPropertyGridEvent()
5935 // -----------------------------------------------------------------------
5937 wxEvent
* wxPropertyGridEvent::Clone() const
5939 return new wxPropertyGridEvent( *this );
5942 // -----------------------------------------------------------------------
5943 // wxPropertyGridPopulator
5944 // -----------------------------------------------------------------------
5946 wxPropertyGridPopulator::wxPropertyGridPopulator()
5950 wxPGGlobalVars
->m_offline
++;
5953 // -----------------------------------------------------------------------
5955 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5958 m_propHierarchy
.clear();
5961 // -----------------------------------------------------------------------
5963 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5969 // -----------------------------------------------------------------------
5971 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5974 // Free unused sets of choices
5975 wxPGHashMapS2P::iterator it
;
5977 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5979 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5986 m_pg
->GetPanel()->Refresh();
5988 wxPGGlobalVars
->m_offline
--;
5991 // -----------------------------------------------------------------------
5993 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5994 const wxString
& propLabel
,
5995 const wxString
& propName
,
5996 const wxString
* propValue
,
5997 wxPGChoices
* pChoices
)
5999 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6000 wxPGProperty
* parent
= GetCurParent();
6002 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6004 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6008 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6010 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6014 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6016 property
->SetLabel(propLabel
);
6017 property
->DoSetName(propName
);
6019 if ( pChoices
&& pChoices
->IsOk() )
6020 property
->SetChoices(*pChoices
);
6022 m_state
->DoInsert(parent
, -1, property
);
6025 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6030 // -----------------------------------------------------------------------
6032 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6034 m_propHierarchy
.push_back(property
);
6035 DoScanForChildren();
6036 m_propHierarchy
.pop_back();
6039 // -----------------------------------------------------------------------
6041 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6042 const wxString
& idString
)
6044 wxPGChoices choices
;
6047 if ( choicesString
[0] == wxT('@') )
6049 wxString ids
= choicesString
.substr(1);
6050 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6051 if ( it
== m_dictIdChoices
.end() )
6052 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6054 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6059 if ( idString
.length() )
6061 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6062 if ( it
!= m_dictIdChoices
.end() )
6064 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6071 // Parse choices string
6072 wxString::const_iterator it
= choicesString
.begin();
6076 bool labelValid
= false;
6078 for ( ; it
!= choicesString
.end(); it
++ )
6084 if ( c
== wxT('"') )
6089 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6090 choices
.Add(label
, l
);
6093 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6098 else if ( c
== wxT('=') )
6105 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6112 if ( c
== wxT('"') )
6125 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6126 choices
.Add(label
, l
);
6129 if ( !choices
.IsOk() )
6131 choices
.EnsureData();
6135 if ( idString
.length() )
6136 m_dictIdChoices
[idString
] = choices
.GetData();
6143 // -----------------------------------------------------------------------
6145 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6147 if ( s
.Last() == wxT('%') )
6149 wxString s2
= s
.substr(0,s
.length()-1);
6151 if ( s2
.ToLong(&val
, 10) )
6153 *pval
= (val
*max
)/100;
6159 return s
.ToLong(pval
, 10);
6162 // -----------------------------------------------------------------------
6164 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6165 const wxString
& type
,
6166 const wxString
& value
)
6168 int l
= m_propHierarchy
.size();
6172 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6173 wxString valuel
= value
.Lower();
6176 if ( type
.length() == 0 )
6181 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6183 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6185 else if ( value
.ToLong(&v
, 0) )
6192 if ( type
== wxT("string") )
6196 else if ( type
== wxT("int") )
6199 value
.ToLong(&v
, 0);
6202 else if ( type
== wxT("bool") )
6204 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6211 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6216 p
->SetAttribute( name
, variant
);
6221 // -----------------------------------------------------------------------
6223 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6225 wxLogError(_("Error in resource: %s"),msg
.c_str());
6228 // -----------------------------------------------------------------------
6230 #endif // wxUSE_PROPGRID