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
);
426 DECLARE_EVENT_TABLE()
427 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
431 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
433 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
434 EVT_MOTION(wxPGCanvas::OnMouseMove
)
435 EVT_PAINT(wxPGCanvas::OnPaint
)
436 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
437 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
438 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
439 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
440 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
441 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
442 EVT_CHAR(wxPGCanvas::OnKey
)
443 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
447 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
449 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
450 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
454 // Don't paint after destruction has begun
455 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
458 // Update everything inside the box
459 wxRect r
= GetUpdateRegion().GetBox();
461 // Repaint this rectangle
462 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
464 // We assume that the size set when grid is shown
465 // is what is desired.
466 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
469 // -----------------------------------------------------------------------
471 // -----------------------------------------------------------------------
473 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
475 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
476 EVT_IDLE(wxPropertyGrid::OnIdle
)
477 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
478 EVT_PAINT(wxPropertyGrid::OnPaint
)
479 EVT_SIZE(wxPropertyGrid::OnResize
)
480 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
481 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
482 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
483 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
484 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
485 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
486 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
487 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
491 // -----------------------------------------------------------------------
493 wxPropertyGrid::wxPropertyGrid()
499 // -----------------------------------------------------------------------
501 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
510 Create(parent
,id
,pos
,size
,style
,name
);
513 // -----------------------------------------------------------------------
515 bool wxPropertyGrid::Create( wxWindow
*parent
,
523 if ( !(style
&wxBORDER_MASK
) )
524 style
|= wxSIMPLE_BORDER
;
529 // This prevents crash under Win2K, but still
530 // enables keyboard navigation
531 if ( style
& wxTAB_TRAVERSAL
)
533 style
&= ~(wxTAB_TRAVERSAL
);
534 style
|= wxWANTS_CHARS
;
537 if ( style
& wxTAB_TRAVERSAL
)
538 style
|= wxWANTS_CHARS
;
541 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
548 // -----------------------------------------------------------------------
551 // Initialize values to defaults
553 void wxPropertyGrid::Init1()
555 // Register editor classes, if necessary.
556 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
557 wxPropertyGrid::RegisterDefaultEditors();
560 m_pState
= (wxPropertyGridPageState
*) NULL
;
561 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
562 m_selected
= (wxPGProperty
*) NULL
;
564 m_propHover
= (wxPGProperty
*) NULL
;
565 m_eventObject
= this;
566 m_curFocused
= (wxWindow
*) NULL
;
568 m_inDoPropertyChanged
= 0;
569 m_inCommitChangesFromEditor
= 0;
570 m_inDoSelectProperty
= 0;
571 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
577 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
578 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
579 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
580 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
581 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
582 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
583 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
584 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
585 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
586 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
587 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
588 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
589 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
591 m_coloursCustomized
= 0;
596 #if wxPG_DOUBLE_BUFFER
597 m_doubleBuffer
= (wxBitmap
*) NULL
;
600 m_windowsToDelete
= NULL
;
602 #ifndef wxPG_ICON_WIDTH
608 m_iconWidth
= wxPG_ICON_WIDTH
;
613 m_gutterWidth
= wxPG_GUTTER_MIN
;
614 m_subgroup_extramargin
= 10;
618 m_width
= m_height
= 0;
620 SetButtonShortcut(0);
622 m_keyComboConsumed
= 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 delete m_windowsToDelete
;
761 //m_selected = (wxPGProperty*) NULL;
763 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
766 delete m_cursorSizeWE
;
768 #ifndef wxPG_ICON_WIDTH
773 // Delete cached text colours.
774 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
776 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
779 // Delete cached brushes.
780 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
782 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
785 // Delete common value records
786 for ( i
=0; i
<m_commonValues
.size(); i
++ )
788 delete GetCommonValue(i
);
792 // -----------------------------------------------------------------------
794 bool wxPropertyGrid::Destroy()
796 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
797 m_canvas
->ReleaseMouse();
799 return wxScrolledWindow::Destroy();
802 // -----------------------------------------------------------------------
804 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
806 return new wxPropertyGridPageState();
809 // -----------------------------------------------------------------------
810 // wxPropertyGrid overridden wxWindow methods
811 // -----------------------------------------------------------------------
813 void wxPropertyGrid::SetWindowStyleFlag( long style
)
815 long old_style
= m_windowStyle
;
817 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
819 wxASSERT( m_pState
);
821 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
824 EnableCategories( true );
826 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
828 // Disable categories
829 EnableCategories( false );
831 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
837 PrepareAfterItemsAdded();
839 m_pState
->m_itemsAdded
= 1;
841 #if wxPG_SUPPORT_TOOLTIPS
842 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
848 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
849 SetToolTip ( tooltip );
850 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
853 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
858 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
863 wxScrolledWindow::SetWindowStyleFlag ( style
);
865 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
867 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
869 CalculateFontAndBitmapStuff( m_vspacing
);
875 // -----------------------------------------------------------------------
877 void wxPropertyGrid::Freeze()
881 wxScrolledWindow::Freeze();
886 // -----------------------------------------------------------------------
888 void wxPropertyGrid::Thaw()
894 wxScrolledWindow::Thaw();
895 RecalculateVirtualSize();
896 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
900 // Force property re-selection
902 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
906 // -----------------------------------------------------------------------
908 void wxPropertyGrid::SetExtraStyle( long exStyle
)
910 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
912 #if defined(__WXMSW__)
915 // Don't use WS_EX_COMPOSITED just now.
918 if ( m_iFlags & wxPG_FL_IN_MANAGER )
919 hWnd = (HWND)GetParent()->GetHWND();
921 hWnd = (HWND)GetHWND();
923 ::SetWindowLong( hWnd, GWL_EXSTYLE,
924 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
927 //#elif defined(__WXGTK20__)
929 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
930 // truly was double-buffered.
931 if ( !this->IsDoubleBuffered() )
933 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
937 #if wxPG_DOUBLE_BUFFER
938 delete m_doubleBuffer
;
939 m_doubleBuffer
= NULL
;
944 wxScrolledWindow::SetExtraStyle( exStyle
);
946 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
947 m_pState
->InitNonCatMode();
949 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
950 m_windowStyle
|= wxPG_TOOLTIPS
;
953 wxPGGlobalVars
->m_extraStyle
= exStyle
;
956 // -----------------------------------------------------------------------
958 // returns the best acceptable minimal size
959 wxSize
wxPropertyGrid::DoGetBestSize() const
962 if ( m_lineHeight
> hei
)
964 wxSize sz
= wxSize( 60, hei
+40 );
970 // -----------------------------------------------------------------------
971 // wxPropertyGrid Font and Colour Methods
972 // -----------------------------------------------------------------------
974 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
978 m_captionFont
= wxScrolledWindow::GetFont();
980 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
981 m_subgroup_extramargin
= x
+ (x
/2);
984 #if wxPG_USE_RENDERER_NATIVE
985 m_iconWidth
= wxPG_ICON_WIDTH
;
986 #elif wxPG_ICON_WIDTH
988 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
989 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
990 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
994 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
995 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
996 m_gutterWidth
= wxPG_GUTTER_MIN
;
999 if ( vspacing
<= 1 ) vdiv
= 12;
1000 else if ( vspacing
>= 3 ) vdiv
= 3;
1002 m_spacingy
= m_fontHeight
/ vdiv
;
1003 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1004 m_spacingy
= wxPG_YSPACING_MIN
;
1007 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1008 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1010 m_captionFont
.SetWeight(wxBOLD
);
1011 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1013 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1016 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1017 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1020 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1022 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1023 RecalculateVirtualSize();
1025 InvalidateBestSize();
1028 // -----------------------------------------------------------------------
1030 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1036 // -----------------------------------------------------------------------
1038 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1039 int ga
= 1000, int ba
= 1000,
1040 bool forceDifferent
= false)
1047 // Recursion guard (allow 2 max)
1048 static int isinside
= 0;
1050 wxCHECK_MSG( isinside
< 3,
1052 wxT("wxPGAdjustColour should not be recursively called more than once") );
1057 int g
= src
.Green();
1060 if ( r2
>255 ) r2
= 255;
1061 else if ( r2
<0) r2
= 0;
1063 if ( g2
>255 ) g2
= 255;
1064 else if ( g2
<0) g2
= 0;
1066 if ( b2
>255 ) b2
= 255;
1067 else if ( b2
<0) b2
= 0;
1069 // Make sure they are somewhat different
1070 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1071 dst
= wxPGAdjustColour(src
,-(ra
*2));
1073 dst
= wxColour(r2
,g2
,b2
);
1075 // Recursion guard (allow 2 max)
1082 static int wxPGGetColAvg( const wxColour
& col
)
1084 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1088 void wxPropertyGrid::RegainColours()
1090 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1092 if ( !(m_coloursCustomized
& 0x0002) )
1094 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1096 // Make sure colour is dark enough
1098 int colDec
= wxPGGetColAvg(col
) - 230;
1100 int colDec
= wxPGGetColAvg(col
) - 200;
1103 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1108 if ( !(m_coloursCustomized
& 0x0001) )
1109 m_colMargin
= m_colCapBack
;
1111 if ( !(m_coloursCustomized
& 0x0004) )
1118 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1119 m_colCapFore
= capForeCol
;
1121 // Set the cached colour as well.
1122 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1125 if ( !(m_coloursCustomized
& 0x0008) )
1127 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1128 m_colPropBack
= bgCol
;
1130 // Set the cached brush as well.
1131 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1134 if ( !(m_coloursCustomized
& 0x0010) )
1136 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1137 m_colPropFore
= fgCol
;
1139 // Set the cached colour as well.
1140 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1143 if ( !(m_coloursCustomized
& 0x0020) )
1144 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1146 if ( !(m_coloursCustomized
& 0x0040) )
1147 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1149 if ( !(m_coloursCustomized
& 0x0080) )
1150 m_colLine
= m_colCapBack
;
1152 if ( !(m_coloursCustomized
& 0x0100) )
1153 m_colDisPropFore
= m_colCapFore
;
1155 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1158 // -----------------------------------------------------------------------
1160 void wxPropertyGrid::ResetColours()
1162 m_coloursCustomized
= 0;
1169 // -----------------------------------------------------------------------
1171 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1173 // Must disable active editor.
1176 bool selRes
= ClearSelection();
1177 wxPG_CHECK_MSG_DBG( selRes
,
1179 wxT("failed to deselect a property (editor probably had invalid value)") );
1182 // TODO: Following code is disabled with wxMac because
1183 // it is reported to fail. I (JMS) cannot debug it
1184 // personally right now.
1185 #if !defined(__WXMAC__)
1186 bool res
= wxScrolledWindow::SetFont( font
);
1189 CalculateFontAndBitmapStuff( m_vspacing
);
1192 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1200 // TODO: Remove after SetFont crash fixed.
1201 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1203 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."));
1209 // -----------------------------------------------------------------------
1211 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1214 m_coloursCustomized
|= 0x80;
1218 // -----------------------------------------------------------------------
1220 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1223 m_coloursCustomized
|= 0x01;
1227 // -----------------------------------------------------------------------
1229 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1231 m_colPropBack
= col
;
1232 m_coloursCustomized
|= 0x08;
1234 // Set the cached brush as well.
1235 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1240 // -----------------------------------------------------------------------
1242 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1244 m_colPropFore
= col
;
1245 m_coloursCustomized
|= 0x10;
1247 // Set the cached colour as well.
1248 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1253 // -----------------------------------------------------------------------
1255 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1257 m_colEmptySpace
= col
;
1262 // -----------------------------------------------------------------------
1264 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1266 m_colDisPropFore
= col
;
1267 m_coloursCustomized
|= 0x100;
1271 // -----------------------------------------------------------------------
1273 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1276 m_coloursCustomized
|= 0x20;
1280 // -----------------------------------------------------------------------
1282 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1285 m_coloursCustomized
|= 0x40;
1289 // -----------------------------------------------------------------------
1291 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1294 m_coloursCustomized
|= 0x02;
1298 // -----------------------------------------------------------------------
1300 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1303 m_coloursCustomized
|= 0x04;
1305 // Set the cached colour as well.
1306 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1311 // -----------------------------------------------------------------------
1313 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1315 unsigned char ind
= index
;
1317 p
->m_bgColIndex
= ind
;
1320 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1321 SetBackgroundColourIndex(p
->Item(i
),index
);
1324 // -----------------------------------------------------------------------
1326 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1328 wxPG_PROP_ARG_CALL_PROLOG()
1333 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1335 // As it is most likely that the previous colour is used, start comparison
1337 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1339 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1348 colInd
= m_arrBgBrushes
.size();
1349 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1350 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1354 SetBackgroundColourIndex(p
,colInd
);
1356 // If this was on a visible grid, then draw it.
1357 DrawItemAndChildren(p
);
1360 // -----------------------------------------------------------------------
1362 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1364 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1366 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1369 // -----------------------------------------------------------------------
1371 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1373 unsigned char ind
= index
;
1375 p
->m_fgColIndex
= ind
;
1377 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1380 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1381 SetTextColourIndex( p
->Item(i
), index
, flags
);
1385 // -----------------------------------------------------------------------
1387 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1392 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1394 // As it is most likely that the previous colour is used, start comparison
1396 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1398 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1407 colInd
= m_arrFgCols
.size();
1408 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1409 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1415 // -----------------------------------------------------------------------
1417 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1420 wxPG_PROP_ARG_CALL_PROLOG()
1422 if ( p
->IsCategory() )
1424 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1425 cat
->SetTextColIndex(CacheColour(colour
));
1431 flags
|= wxPG_RECURSE
;
1432 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1434 DrawItemAndChildren(p
);
1437 // -----------------------------------------------------------------------
1439 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1441 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1443 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1446 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1448 wxPG_PROP_ARG_CALL_PROLOG()
1450 SetBackgroundColourIndex( p
, 0 );
1451 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1453 if ( p
->IsCategory() )
1455 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1456 cat
->SetTextColIndex(1);
1460 // -----------------------------------------------------------------------
1461 // wxPropertyGrid property adding and removal
1462 // -----------------------------------------------------------------------
1464 void wxPropertyGrid::PrepareAfterItemsAdded()
1466 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1468 m_pState
->m_itemsAdded
= 0;
1470 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1473 RecalculateVirtualSize();
1476 // -----------------------------------------------------------------------
1477 // wxPropertyGrid property value setting and getting
1478 // -----------------------------------------------------------------------
1480 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1482 m_pState
->DoSetPropertyValueUnspecified(p
);
1483 DrawItemAndChildren(p
);
1485 wxPGProperty
* parent
= p
->GetParent();
1486 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1489 parent
= parent
->GetParent();
1493 // -----------------------------------------------------------------------
1494 // wxPropertyGrid property operations
1495 // -----------------------------------------------------------------------
1497 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1499 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1503 bool changed
= false;
1505 // Is it inside collapsed section?
1506 if ( !p
->IsVisible() )
1509 wxPGProperty
* parent
= p
->GetParent();
1510 wxPGProperty
* grandparent
= parent
->GetParent();
1512 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1513 Expand( grandparent
);
1521 GetViewStart(&vx
,&vy
);
1522 vy
*=wxPG_PIXELS_PER_UNIT
;
1528 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1529 m_iFlags
|= wxPG_FL_SCROLLED
;
1532 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1534 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1535 m_iFlags
|= wxPG_FL_SCROLLED
;
1545 // -----------------------------------------------------------------------
1546 // wxPropertyGrid helper methods called by properties
1547 // -----------------------------------------------------------------------
1549 // Control font changer helper.
1550 void wxPropertyGrid::SetCurControlBoldFont()
1552 wxASSERT( m_wndEditor
);
1553 m_wndEditor
->SetFont( m_captionFont
);
1556 // -----------------------------------------------------------------------
1558 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1561 #if wxPG_SMALL_SCREEN
1562 // On small-screen devices, always show dialogs with default position and size.
1563 return wxDefaultPosition
;
1565 int splitterX
= GetSplitterPosition();
1569 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1571 ImprovedClientToScreen( &x
, &y
);
1573 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1574 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1581 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1591 new_y
= y
+ m_lineHeight
;
1593 return wxPoint(new_x
,new_y
);
1597 // -----------------------------------------------------------------------
1599 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1601 if ( src_str
.length() == 0 )
1607 bool prev_is_slash
= false;
1609 wxString::const_iterator i
= src_str
.begin();
1613 for ( ; i
!= src_str
.end(); i
++ )
1617 if ( a
!= wxS('\\') )
1619 if ( !prev_is_slash
)
1625 if ( a
== wxS('n') )
1628 dst_str
<< wxS('\n');
1630 dst_str
<< wxS('\n');
1633 else if ( a
== wxS('t') )
1634 dst_str
<< wxS('\t');
1638 prev_is_slash
= false;
1642 if ( prev_is_slash
)
1644 dst_str
<< wxS('\\');
1645 prev_is_slash
= false;
1649 prev_is_slash
= true;
1656 // -----------------------------------------------------------------------
1658 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1660 if ( src_str
.length() == 0 )
1666 wxString::const_iterator i
= src_str
.begin();
1667 wxUniChar prev_a
= wxS('\0');
1671 for ( ; i
!= src_str
.end(); i
++ )
1675 if ( a
>= wxS(' ') )
1677 // This surely is not something that requires an escape sequence.
1682 // This might need...
1683 if ( a
== wxS('\r') )
1685 // DOS style line end.
1686 // Already taken care below
1688 else if ( a
== wxS('\n') )
1689 // UNIX style line end.
1690 dst_str
<< wxS("\\n");
1691 else if ( a
== wxS('\t') )
1693 dst_str
<< wxS('\t');
1696 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1706 // -----------------------------------------------------------------------
1708 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1712 return (wxPGProperty
*) NULL
;
1715 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1718 // -----------------------------------------------------------------------
1719 // wxPropertyGrid graphics related methods
1720 // -----------------------------------------------------------------------
1722 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1726 // Update everything inside the box
1727 wxRect r
= GetUpdateRegion().GetBox();
1729 dc
.SetPen(m_colEmptySpace
);
1730 dc
.SetBrush(m_colEmptySpace
);
1731 dc
.DrawRectangle(r
);
1734 // -----------------------------------------------------------------------
1736 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1737 wxPGProperty
* property
) const
1739 // Prepare rectangle to be used
1741 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1742 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1744 #if (wxPG_USE_RENDERER_NATIVE)
1746 #elif wxPG_ICON_WIDTH
1747 // Drawing expand/collapse button manually
1748 dc
.SetPen(m_colPropFore
);
1749 if ( property
->IsCategory() )
1750 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1752 dc
.SetBrush(m_colPropBack
);
1754 dc
.DrawRectangle( r
);
1755 int _y
= r
.y
+(m_iconWidth
/2);
1756 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1761 if ( property
->IsExpanded() )
1763 // wxRenderer functions are non-mutating in nature, so it
1764 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1765 // Hopefully this does not cause problems.
1766 #if (wxPG_USE_RENDERER_NATIVE)
1767 wxRendererNative::Get().DrawTreeItemButton(
1773 #elif wxPG_ICON_WIDTH
1782 #if (wxPG_USE_RENDERER_NATIVE)
1783 wxRendererNative::Get().DrawTreeItemButton(
1789 #elif wxPG_ICON_WIDTH
1790 int _x
= r
.x
+(m_iconWidth
/2);
1791 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1797 #if (wxPG_USE_RENDERER_NATIVE)
1799 #elif wxPG_ICON_WIDTH
1802 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1806 // -----------------------------------------------------------------------
1809 // This is the one called by OnPaint event handler and others.
1810 // topy and bottomy are already unscrolled (ie. physical)
1812 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1814 unsigned int bottomy
,
1815 const wxRect
* clipRect
)
1817 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1819 m_pState
->EnsureVirtualHeight();
1821 wxRect tempClipRect
;
1824 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1825 clipRect
= &tempClipRect
;
1828 // items added check
1829 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1831 int paintFinishY
= 0;
1833 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1836 bool isBuffered
= false;
1838 #if wxPG_DOUBLE_BUFFER
1839 wxMemoryDC
* bufferDC
= NULL
;
1841 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1843 if ( !m_doubleBuffer
)
1845 paintFinishY
= clipRect
->y
;
1850 bufferDC
= new wxMemoryDC();
1852 // If nothing was changed, then just copy from double-buffer
1853 bufferDC
->SelectObject( *m_doubleBuffer
);
1863 dc
.SetClippingRegion( *clipRect
);
1864 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1867 #if wxPG_DOUBLE_BUFFER
1870 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1871 bufferDC
, 0, 0, wxCOPY
);
1872 dc
.DestroyClippingRegion(); // Is this really necessary?
1878 // Clear area beyond bottomY?
1879 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1881 dc
.SetPen(m_colEmptySpace
);
1882 dc
.SetBrush(m_colEmptySpace
);
1883 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1887 // -----------------------------------------------------------------------
1889 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1890 const wxPGProperty
* firstItem
,
1891 const wxPGProperty
* lastItem
,
1892 const wxRect
* clipRect
,
1893 bool isBuffered
) const
1895 // TODO: This should somehow be eliminated.
1896 wxRect tempClipRect
;
1899 wxASSERT(firstItem
);
1901 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1902 clipRect
= &tempClipRect
;
1906 firstItem
= DoGetItemAtY(clipRect
->y
);
1910 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1912 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1915 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1918 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1919 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1921 int lh
= m_lineHeight
;
1924 int lastItemBottomY
;
1926 firstItemTopY
= clipRect
->y
;
1927 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1929 // Align y coordinates to item boundaries
1930 firstItemTopY
-= firstItemTopY
% lh
;
1931 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1932 lastItemBottomY
-= 1;
1934 // Entire range outside scrolled, visible area?
1935 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1938 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1942 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1943 firstItem->GetLabel().c_str(),
1944 lastItem->GetLabel().c_str(),
1945 (int)(lastItemBottomY - firstItemTopY),
1947 (unsigned long)clipRect );
1952 long windowStyle
= m_windowStyle
;
1958 // With wxPG_DOUBLE_BUFFER, do double buffering
1959 // - buffer's y = 0, so align cliprect and coordinates to that
1961 #if wxPG_DOUBLE_BUFFER
1967 xRelMod
= clipRect
->x
;
1968 yRelMod
= clipRect
->y
;
1971 // clipRect conversion
1979 firstItemTopY
-= yRelMod
;
1980 lastItemBottomY
-= yRelMod
;
1983 wxUnusedVar(isBuffered
);
1986 int x
= m_marginWidth
- xRelMod
;
1988 const wxFont
& normalfont
= m_font
;
1990 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1992 bool isEnabled
= IsEnabled();
1995 // Prepare some pens and brushes that are often changed to.
1998 wxBrush
marginBrush(m_colMargin
);
1999 wxPen
marginPen(m_colMargin
);
2000 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2001 wxPen
linepen(m_colLine
,1,wxSOLID
);
2003 // pen that has same colour as text
2004 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2007 // Clear margin with background colour
2009 dc
.SetBrush( marginBrush
);
2010 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2012 dc
.SetPen( *wxTRANSPARENT_PEN
);
2013 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2016 const wxPGProperty
* selected
= m_selected
;
2017 const wxPropertyGridPageState
* state
= m_pState
;
2019 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2020 bool wasSelectedPainted
= false;
2023 // TODO: Only render columns that are within clipping region.
2025 dc
.SetFont(normalfont
);
2027 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2028 int endScanBottomY
= lastItemBottomY
+ lh
;
2029 int y
= firstItemTopY
;
2032 // Pregenerate list of visible properties.
2033 wxArrayPGProperty visPropArray
;
2034 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2036 for ( ; !it
.AtEnd(); it
.Next() )
2038 const wxPGProperty
* p
= *it
;
2040 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2042 visPropArray
.push_back((wxPGProperty
*)p
);
2044 if ( y
> endScanBottomY
)
2051 visPropArray
.push_back(NULL
);
2053 wxPGProperty
* nextP
= visPropArray
[0];
2055 int gridWidth
= state
->m_width
;
2058 for ( unsigned int arrInd
=1;
2059 nextP
&& y
<= lastItemBottomY
;
2062 wxPGProperty
* p
= nextP
;
2063 nextP
= visPropArray
[arrInd
];
2065 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2066 int textMarginHere
= x
;
2067 int renderFlags
= wxPGCellRenderer::Control
;
2069 int greyDepth
= m_marginWidth
;
2070 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2071 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2073 int greyDepthX
= greyDepth
- xRelMod
;
2075 // Use basic depth if in non-categoric mode and parent is base array.
2076 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2078 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2081 // Paint margin area
2082 dc
.SetBrush(marginBrush
);
2083 dc
.SetPen(marginPen
);
2084 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2086 dc
.SetPen( linepen
);
2091 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2097 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2099 sx
+= state
->m_colWidths
[si
];
2100 dc
.DrawLine( sx
, y
, sx
, y2
);
2103 // Horizontal Line, below
2104 // (not if both this and next is category caption)
2105 if ( p
->IsCategory() &&
2106 nextP
&& nextP
->IsCategory() )
2107 dc
.SetPen(m_colCapBack
);
2109 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2111 if ( p
== selected
)
2113 renderFlags
|= wxPGCellRenderer::Selected
;
2114 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2115 wasSelectedPainted
= true;
2123 if ( p
->IsCategory() )
2125 if ( p
->m_fgColIndex
== 0 )
2126 rowFgCol
= m_colCapFore
;
2128 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2129 rowBgBrush
= wxBrush(m_colCapBack
);
2131 else if ( p
!= selected
)
2133 // Disabled may get different colour.
2134 if ( !p
->IsEnabled() )
2135 rowFgCol
= m_colDisPropFore
;
2137 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2139 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2143 // Selected gets different colour.
2144 if ( reallyFocused
)
2146 rowFgCol
= m_colSelFore
;
2147 rowBgBrush
= wxBrush(m_colSelBack
);
2149 else if ( isEnabled
)
2151 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2152 rowBgBrush
= marginBrush
;
2156 rowFgCol
= m_colDisPropFore
;
2157 rowBgBrush
= wxBrush(m_colSelBack
);
2161 bool fontChanged
= false;
2163 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2168 if ( p
->IsCategory() )
2170 // Captions are all cells merged as one
2171 dc
.SetFont(m_captionFont
);
2173 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2175 dc
.SetBrush(rowBgBrush
);
2176 dc
.SetPen(rowBgBrush
.GetColour());
2177 dc
.SetTextForeground(rowFgCol
);
2179 dc
.DrawRectangle(cellRect
);
2182 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2183 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2186 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2187 DrawExpanderButton( dc
, butRect
, p
);
2191 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2193 dc
.SetFont(m_captionFont
);
2199 int nextCellWidth
= state
->m_colWidths
[0];
2200 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2201 int textXAdd
= textMarginHere
- greyDepthX
;
2203 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2205 cellRect
.width
= nextCellWidth
- 1;
2207 bool ctrlCell
= false;
2210 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2212 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2213 dc
.SetBrush(editorBgCol
);
2214 dc
.SetPen(editorBgCol
);
2215 dc
.SetTextForeground(m_colPropFore
);
2217 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2222 dc
.SetBrush(rowBgBrush
);
2223 dc
.SetPen(rowBgBrush
.GetColour());
2224 dc
.SetTextForeground(rowFgCol
);
2227 dc
.DrawRectangle(cellRect
);
2230 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2231 DrawExpanderButton( dc
, butRect
, p
);
2233 dc
.SetClippingRegion(cellRect
);
2235 cellRect
.x
+= textXAdd
;
2236 cellRect
.width
-= textXAdd
;
2241 wxPGCellRenderer
* renderer
;
2242 int cmnVal
= p
->GetCommonValue();
2243 if ( cmnVal
== -1 || ci
!= 1 )
2245 renderer
= p
->GetCellRenderer(ci
);
2246 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2250 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2251 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2255 cellX
+= state
->m_colWidths
[ci
];
2256 if ( ci
< (state
->m_colWidths
.size()-1) )
2257 nextCellWidth
= state
->m_colWidths
[ci
+1];
2259 dc
.DestroyClippingRegion(); // Is this really necessary?
2265 dc
.SetFont(normalfont
);
2270 // Refresh editor controls (seems not needed on msw)
2271 // NOTE: This code is mandatory for GTK!
2272 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2273 if ( wasSelectedPainted
)
2276 m_wndEditor
->Refresh();
2278 m_wndEditor2
->Refresh();
2285 // -----------------------------------------------------------------------
2287 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2291 if ( m_width
< 10 || m_height
< 10 ||
2292 !m_pState
->m_properties
->GetChildCount() ||
2293 p1
== (wxPGProperty
*) NULL
)
2294 return wxRect(0,0,0,0);
2299 // Return rect which encloses the given property range
2301 int visTop
= p1
->GetY();
2304 visBottom
= p2
->GetY() + m_lineHeight
;
2306 visBottom
= m_height
+ visTop
;
2308 // If seleced property is inside the range, we'll extend the range to include
2310 wxPGProperty
* selected
= m_selected
;
2313 int selectedY
= selected
->GetY();
2314 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2316 wxWindow
* editor
= GetEditorControl();
2319 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2320 if ( visBottom2
> visBottom
)
2321 visBottom
= visBottom2
;
2326 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2329 // -----------------------------------------------------------------------
2331 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2336 if ( m_pState
->m_itemsAdded
)
2337 PrepareAfterItemsAdded();
2339 wxRect r
= GetPropertyRect(p1
, p2
);
2342 m_canvas
->RefreshRect(r
);
2346 // -----------------------------------------------------------------------
2348 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2350 if ( p
== m_selected
)
2351 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2353 DrawItemAndChildren(p
);
2356 // -----------------------------------------------------------------------
2358 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2363 // Draw item, children, and parent too, if it is not category
2364 wxPGProperty
* parent
= p
->GetParent();
2367 !parent
->IsCategory() &&
2368 parent
->GetParent() )
2371 parent
= parent
->GetParent();
2374 DrawItemAndChildren(p
);
2377 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2379 wxCHECK_RET( p
, wxT("invalid property id") );
2381 // Do not draw if in non-visible page
2382 if ( p
->GetParentState() != m_pState
)
2385 // do not draw a single item if multiple pending
2386 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2389 wxWindow
* wndPrimary
= GetEditorControl();
2391 // Update child control.
2392 if ( m_selected
&& m_selected
->GetParent() == p
)
2393 m_selected
->UpdateControl(wndPrimary
);
2395 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2397 DrawItems(p
, lastDrawn
);
2400 // -----------------------------------------------------------------------
2402 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2403 const wxRect
*rect
)
2405 PrepareAfterItemsAdded();
2407 wxWindow::Refresh(false);
2409 // TODO: Coordinate translation
2410 m_canvas
->Refresh(false, rect
);
2412 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2413 // I think this really helps only GTK+1.2
2414 if ( m_wndEditor
) m_wndEditor
->Refresh();
2415 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2419 // -----------------------------------------------------------------------
2420 // wxPropertyGrid global operations
2421 // -----------------------------------------------------------------------
2423 void wxPropertyGrid::Clear()
2427 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2428 wxPG_CHECK_RET_DBG( selRes
,
2429 wxT("failed to deselect a property (editor probably had invalid value)") );
2432 m_pState
->DoClear();
2438 RecalculateVirtualSize();
2440 // Need to clear some area at the end
2442 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2445 // -----------------------------------------------------------------------
2447 bool wxPropertyGrid::EnableCategories( bool enable
)
2449 if ( !ClearSelection() )
2455 // Enable categories
2458 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2463 // Disable categories
2465 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2468 if ( !m_pState
->EnableCategories(enable
) )
2473 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2475 m_pState
->m_itemsAdded
= 1; // force
2476 PrepareAfterItemsAdded();
2480 m_pState
->m_itemsAdded
= 1;
2482 // No need for RecalculateVirtualSize() here - it is already called in
2483 // wxPropertyGridPageState method above.
2490 // -----------------------------------------------------------------------
2492 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2494 wxASSERT( pNewState
);
2495 wxASSERT( pNewState
->GetGrid() );
2497 if ( pNewState
== m_pState
)
2500 wxPGProperty
* oldSelection
= m_selected
;
2505 bool selRes
= ClearSelection();
2506 wxPG_CHECK_RET_DBG( selRes
,
2507 wxT("failed to deselect a property (editor probably had invalid value)") );
2510 m_pState
->m_selected
= oldSelection
;
2512 bool orig_mode
= m_pState
->IsInNonCatMode();
2513 bool new_state_mode
= pNewState
->IsInNonCatMode();
2515 m_pState
= pNewState
;
2518 int pgWidth
= GetClientSize().x
;
2519 if ( HasVirtualWidth() )
2521 int minWidth
= pgWidth
;
2522 if ( pNewState
->m_width
< minWidth
)
2524 pNewState
->m_width
= minWidth
;
2525 pNewState
->CheckColumnWidths();
2531 // Just in case, fully re-center splitter
2532 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2533 pNewState
->m_fSplitterX
= -1.0;
2535 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2538 m_propHover
= (wxPGProperty
*) NULL
;
2540 // If necessary, convert state to correct mode.
2541 if ( orig_mode
!= new_state_mode
)
2543 // This should refresh as well.
2544 EnableCategories( orig_mode
?false:true );
2546 else if ( !m_frozen
)
2548 // Refresh, if not frozen.
2549 if ( m_pState
->m_itemsAdded
)
2550 PrepareAfterItemsAdded();
2553 if ( m_pState
->m_selected
)
2554 DoSelectProperty( m_pState
->m_selected
);
2556 RecalculateVirtualSize(0);
2560 m_pState
->m_itemsAdded
= 1;
2563 // -----------------------------------------------------------------------
2565 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2567 wxPG_PROP_ARG_CALL_PROLOG()
2569 m_pState
->SortChildren( p
);
2572 // -----------------------------------------------------------------------
2574 void wxPropertyGrid::Sort()
2576 bool selRes
= ClearSelection(); // This must be before state clear
2577 wxPG_CHECK_RET_DBG( selRes
,
2578 wxT("failed to deselect a property (editor probably had invalid value)") );
2583 // -----------------------------------------------------------------------
2585 // Call to SetSplitterPosition will always disable splitter auto-centering
2586 // if parent window is shown.
2587 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2589 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2592 wxPropertyGridPageState
* state
= m_pState
;
2594 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2599 CorrectEditorWidgetSizeX();
2605 // -----------------------------------------------------------------------
2607 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2609 SetSplitterPosition( m_width
/2, true );
2610 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2611 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2614 // -----------------------------------------------------------------------
2615 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2616 // -----------------------------------------------------------------------
2618 // Returns nearest paint visible property (such that will be painted unless
2619 // window is scrolled or resized). If given property is paint visible, then
2620 // it itself will be returned
2621 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2623 int vx
,vy1
;// Top left corner of client
2624 GetViewStart(&vx
,&vy1
);
2625 vy1
*= wxPG_PIXELS_PER_UNIT
;
2627 int vy2
= vy1
+ m_height
;
2628 int propY
= p
->GetY2(m_lineHeight
);
2630 if ( (propY
+ m_lineHeight
) < vy1
)
2633 return DoGetItemAtY( vy1
);
2635 else if ( propY
> vy2
)
2638 return DoGetItemAtY( vy2
);
2641 // Itself paint visible
2646 // -----------------------------------------------------------------------
2648 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2652 m_pushButKeyCode
= keycode
;
2653 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2654 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2658 m_pushButKeyCode
= WXK_DOWN
;
2659 m_pushButKeyCodeNeedsCtrl
= 0;
2660 m_pushButKeyCodeNeedsAlt
= 1;
2664 // -----------------------------------------------------------------------
2665 // Methods related to change in value, value modification and sending events
2666 // -----------------------------------------------------------------------
2668 // commits any changes in editor of selected property
2669 // return true if validation did not fail
2670 // flags are same as with DoSelectProperty
2671 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2673 // Committing already?
2674 if ( m_inCommitChangesFromEditor
)
2677 // Don't do this if already processing editor event. It might
2678 // induce recursive dialogs and crap like that.
2679 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2681 if ( m_inDoPropertyChanged
)
2688 IsEditorsValueModified() &&
2689 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2692 m_inCommitChangesFromEditor
= 1;
2694 wxVariant
variant(m_selected
->GetValueRef());
2695 bool valueIsPending
= false;
2697 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2698 // due to another window getting focus
2699 wxWindow
* oldFocus
= m_curFocused
;
2701 bool validationFailure
= false;
2702 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2704 m_chgInfo_changedProperty
= NULL
;
2706 // If truly modified, schedule value as pending.
2707 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2709 if ( DoEditorValidate() &&
2710 PerformValidation(m_selected
, variant
) )
2712 valueIsPending
= true;
2716 validationFailure
= true;
2721 EditorsValueWasNotModified();
2726 m_inCommitChangesFromEditor
= 0;
2728 if ( validationFailure
&& !forceSuccess
)
2732 oldFocus
->SetFocus();
2733 m_curFocused
= oldFocus
;
2736 res
= OnValidationFailure(m_selected
, variant
);
2738 // Now prevent further validation failure messages
2741 EditorsValueWasNotModified();
2742 OnValidationFailureReset(m_selected
);
2745 else if ( valueIsPending
)
2747 DoPropertyChanged( m_selected
, flags
);
2748 EditorsValueWasNotModified();
2757 // -----------------------------------------------------------------------
2759 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2762 // Runs all validation functionality.
2763 // Returns true if value passes all tests.
2766 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2768 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2770 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2775 // Adapt list to child values, if necessary
2776 wxVariant listValue
= pendingValue
;
2777 wxVariant
* pPendingValue
= &pendingValue
;
2778 wxVariant
* pList
= NULL
;
2780 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2781 // string value, then we need treat as it was changed instead
2782 // (or, in addition, as is the case with composite string parent).
2783 // This includes creating list variant for child values.
2785 wxPGProperty
* pwc
= p
->GetParent();
2786 wxPGProperty
* changedProperty
= p
;
2787 wxPGProperty
* baseChangedProperty
= changedProperty
;
2788 wxVariant bcpPendingList
;
2790 listValue
= pendingValue
;
2791 listValue
.SetName(p
->GetBaseName());
2794 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2796 wxVariantList tempList
;
2797 wxVariant
lv(tempList
, pwc
->GetBaseName());
2798 lv
.Append(listValue
);
2800 pPendingValue
= &listValue
;
2802 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2804 baseChangedProperty
= pwc
;
2805 bcpPendingList
= lv
;
2808 changedProperty
= pwc
;
2809 pwc
= pwc
->GetParent();
2813 wxPGProperty
* evtChangingProperty
= changedProperty
;
2815 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2817 value
= *pPendingValue
;
2821 // Convert list to child values
2822 pList
= pPendingValue
;
2823 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2826 wxVariant evtChangingValue
= value
;
2828 // FIXME: After proper ValueToString()s added, remove
2829 // this. It is just a temporary fix, as evt_changing
2830 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2831 // (unless it is selected, and textctrl editor is open).
2832 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2834 evtChangingProperty
= baseChangedProperty
;
2835 if ( evtChangingProperty
!= p
)
2837 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2841 evtChangingValue
= pendingValue
;
2845 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2847 if ( changedProperty
== m_selected
)
2849 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2850 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2854 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2858 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2859 m_chgInfo_changedProperty
= changedProperty
;
2860 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2861 m_chgInfo_pendingValue
= value
;
2864 m_chgInfo_valueList
= *pList
;
2866 m_chgInfo_valueList
.MakeNull();
2868 // If changedProperty is not property which value was edited,
2869 // then call wxPGProperty::ValidateValue() for that as well.
2870 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2872 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2876 // SendEvent returns true if event was vetoed
2877 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2883 // -----------------------------------------------------------------------
2885 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2887 if ( !msg
.length() )
2891 if ( !wxPGGlobalVars
->m_offline
)
2893 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2896 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2899 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2902 pStatusBar
->SetStatusText(msg
);
2910 ::wxMessageBox(msg
, _T("Property Error"));
2913 // -----------------------------------------------------------------------
2915 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2917 int vfb
= m_validationInfo
.m_failureBehavior
;
2919 if ( vfb
& wxPG_VFB_BEEP
)
2922 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2923 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2925 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2926 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2928 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2930 wxColour vfbFg
= *wxWHITE
;
2931 wxColour vfbBg
= *wxRED
;
2932 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2933 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2935 DrawItemAndChildren(property
);
2937 if ( property
== m_selected
)
2939 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2941 wxWindow
* editor
= GetEditorControl();
2944 editor
->SetForegroundColour(vfbFg
);
2945 editor
->SetBackgroundColour(vfbBg
);
2951 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2953 wxString msg
= m_validationInfo
.m_failureMessage
;
2955 if ( !msg
.length() )
2956 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2958 DoShowPropertyError(property
, msg
);
2961 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2964 // -----------------------------------------------------------------------
2966 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2968 int vfb
= m_validationInfo
.m_failureBehavior
;
2970 if ( vfb
& wxPG_VFB_MARK_CELL
)
2972 property
->SetCell(0, NULL
);
2973 property
->SetCell(1, NULL
);
2975 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2977 if ( property
== m_selected
&& GetEditorControl() )
2979 // Calling this will recreate the control, thus resetting its colour
2980 RefreshProperty(property
);
2984 DrawItemAndChildren(property
);
2989 // -----------------------------------------------------------------------
2991 // flags are same as with DoSelectProperty
2992 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2994 if ( m_inDoPropertyChanged
)
2997 wxWindow
* editor
= GetEditorControl();
2999 m_pState
->m_anyModified
= 1;
3001 m_inDoPropertyChanged
= 1;
3003 // Maybe need to update control
3004 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3006 // These values were calculated in PerformValidation()
3007 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3008 wxVariant value
= m_chgInfo_pendingValue
;
3010 wxPGProperty
* topPaintedProperty
= changedProperty
;
3012 while ( !topPaintedProperty
->IsCategory() &&
3013 !topPaintedProperty
->IsRoot() )
3015 topPaintedProperty
= topPaintedProperty
->GetParent();
3018 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3020 // Set as Modified (not if dragging just began)
3021 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3023 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3024 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3027 SetCurControlBoldFont();
3033 // Propagate updates to parent(s)
3035 wxPGProperty
* prevPwc
= NULL
;
3037 while ( prevPwc
!= topPaintedProperty
)
3039 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3041 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3044 SetCurControlBoldFont();
3048 pwc
= pwc
->GetParent();
3051 // Draw the actual property
3052 DrawItemAndChildren( topPaintedProperty
);
3055 // If value was set by wxPGProperty::OnEvent, then update the editor
3057 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3060 p
->GetEditorClass()->UpdateControl(p
, editor
);
3064 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3065 if ( m_wndEditor
) m_wndEditor
->Refresh();
3066 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3071 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3073 // If top parent has composite string value, then send to child parents,
3074 // starting from baseChangedProperty.
3075 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3077 pwc
= m_chgInfo_baseChangedProperty
;
3079 while ( pwc
!= changedProperty
)
3081 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3082 pwc
= pwc
->GetParent();
3086 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3088 m_inDoPropertyChanged
= 0;
3093 // -----------------------------------------------------------------------
3095 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3097 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3099 m_chgInfo_changedProperty
= NULL
;
3101 if ( PerformValidation(p
, newValue
) )
3103 DoPropertyChanged(p
);
3108 OnValidationFailure(p
, newValue
);
3114 // -----------------------------------------------------------------------
3116 // Runs wxValidator for the selected property
3117 bool wxPropertyGrid::DoEditorValidate()
3122 // -----------------------------------------------------------------------
3124 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3126 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3127 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3129 wxWindow
* parent
= wnd
->GetParent();
3132 (parent
== m_canvas
||
3133 parent
->GetParent() == m_canvas
) )
3135 OnCustomEditorEvent((wxCommandEvent
&)event
);
3139 return wxPanel::ProcessEvent(event
);
3142 // -----------------------------------------------------------------------
3144 // NB: It may really not be wxCommandEvent - must check if necessary
3146 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3148 wxPGProperty
* selected
= m_selected
;
3151 // Somehow, event is handled after property has been deselected.
3152 // Possibly, but very rare.
3156 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3159 wxVariant
pendingValue(selected
->GetValueRef());
3160 wxWindow
* wnd
= GetEditorControl();
3162 bool wasUnspecified
= selected
->IsValueUnspecified();
3163 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3165 bool valueIsPending
= false;
3167 m_chgInfo_changedProperty
= NULL
;
3169 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3172 // Filter out excess wxTextCtrl modified events
3173 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3175 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3177 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3179 wxString newTcValue
= tc
->GetValue();
3180 if ( m_prevTcValue
== newTcValue
)
3183 m_prevTcValue
= newTcValue
;
3186 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3188 bool validationFailure
= false;
3189 bool buttonWasHandled
= false;
3192 // Try common button handling
3193 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3195 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3199 buttonWasHandled
= true;
3200 // Store as res2, as previously (and still currently alternatively)
3201 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3202 // in wxPGProperty::OnEvent().
3203 adapter
->ShowDialog( this, selected
);
3208 if ( !buttonWasHandled
)
3212 // First call editor class' event handler.
3213 const wxPGEditor
* editor
= selected
->GetEditorClass();
3215 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3217 // If changes, validate them
3218 if ( DoEditorValidate() )
3220 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3221 valueIsPending
= true;
3225 validationFailure
= true;
3230 // Then the property's custom handler (must be always called, unless
3231 // validation failed).
3232 if ( !validationFailure
)
3233 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3236 // SetValueInEvent(), as called in one of the functions referred above
3237 // overrides editor's value.
3238 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3240 valueIsPending
= true;
3241 pendingValue
= m_changeInEventValue
;
3242 selFlags
|= wxPG_SEL_DIALOGVAL
;
3245 if ( !validationFailure
&& valueIsPending
)
3246 if ( !PerformValidation(m_selected
, pendingValue
) )
3247 validationFailure
= true;
3249 if ( validationFailure
)
3251 OnValidationFailure(selected
, pendingValue
);
3253 else if ( valueIsPending
)
3255 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3257 DoPropertyChanged(selected
, selFlags
);
3258 EditorsValueWasNotModified();
3262 // No value after all
3264 // Let unhandled button click events go to the parent
3265 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3267 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3268 GetEventHandler()->AddPendingEvent(evt
);
3272 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3275 // -----------------------------------------------------------------------
3276 // wxPropertyGrid editor control helper methods
3277 // -----------------------------------------------------------------------
3279 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3281 int itemy
= p
->GetY2(m_lineHeight
);
3283 int cust_img_space
= 0;
3284 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3285 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3287 // TODO: If custom image detection changes from current, change this.
3288 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3290 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3291 int imwid
= p
->OnMeasureImage().x
;
3292 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3293 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3298 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3300 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3305 // -----------------------------------------------------------------------
3307 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3309 wxSize sz
= GetImageSize(p
, item
);
3310 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3311 wxPG_CUSTOM_IMAGE_SPACINGY
,
3316 // return size of custom paint image
3317 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3319 // If called with NULL property, then return default image
3320 // size for properties that use image.
3322 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3324 wxSize cis
= p
->OnMeasureImage(item
);
3326 int choiceCount
= p
->m_choices
.GetCount();
3327 int comVals
= p
->GetDisplayedCommonValueCount();
3328 if ( item
>= choiceCount
&& comVals
> 0 )
3330 unsigned int cvi
= item
-choiceCount
;
3331 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3333 else if ( item
>= 0 && choiceCount
== 0 )
3334 return wxSize(0, 0);
3339 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3344 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3351 // -----------------------------------------------------------------------
3353 // takes scrolling into account
3354 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3357 GetViewStart(&vx
,&vy
);
3358 vy
*=wxPG_PIXELS_PER_UNIT
;
3359 vx
*=wxPG_PIXELS_PER_UNIT
;
3362 ClientToScreen( px
, py
);
3365 // -----------------------------------------------------------------------
3367 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3370 GetViewStart(&pt2
.x
,&pt2
.y
);
3371 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3372 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3376 return m_pState
->HitTest(pt2
);
3379 // -----------------------------------------------------------------------
3381 // custom set cursor
3382 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3384 if ( type
== m_curcursor
&& !override
) return;
3386 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3388 if ( type
== wxCURSOR_SIZEWE
)
3389 cursor
= m_cursorSizeWE
;
3391 m_canvas
->SetCursor( *cursor
);
3396 // -----------------------------------------------------------------------
3397 // wxPropertyGrid property selection
3398 // -----------------------------------------------------------------------
3400 // Setups event handling for child control
3401 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
, int id
)
3403 if ( argWnd
== m_wndEditor
)
3405 this->Connect(id
, wxEVT_MOTION
,
3406 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3407 this->Connect(id
, wxEVT_LEFT_UP
,
3408 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3409 this->Connect(id
, wxEVT_LEFT_DOWN
,
3410 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3411 this->Connect(id
, wxEVT_RIGHT_UP
,
3412 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3413 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3414 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3415 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3416 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3420 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3421 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3424 this->Connect(id
, wxEVT_KEY_DOWN
,
3425 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3426 this->Connect(id
, wxEVT_KEY_UP
,
3427 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3428 this->Connect(id
, wxEVT_KILL_FOCUS
,
3429 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3432 void wxPropertyGrid::FreeEditors()
3434 // Do not free editors immediately if processing events
3435 if ( !m_windowsToDelete
)
3436 m_windowsToDelete
= new wxArrayPtrVoid
;
3440 m_windowsToDelete
->push_back(m_wndEditor2
);
3441 m_wndEditor2
->Hide();
3442 m_wndEditor2
= (wxWindow
*) NULL
;
3447 m_windowsToDelete
->push_back(m_wndEditor
);
3448 m_wndEditor
->Hide();
3449 m_wndEditor
= (wxWindow
*) NULL
;
3453 // Call with NULL to de-select property
3454 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3456 wxPanel
* canvas
= GetPanel();
3460 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3461 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3463 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3466 if ( m_inDoSelectProperty
)
3469 m_inDoSelectProperty
= 1;
3471 wxPGProperty
* prev
= m_selected
;
3474 // Delete windows pending for deletion
3475 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3479 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3480 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3482 m_windowsToDelete
->clear();
3487 m_inDoSelectProperty
= 0;
3492 // If we are frozen, then just set the values.
3495 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3496 m_editorFocused
= 0;
3499 m_pState
->m_selected
= p
;
3501 // If frozen, always free controls. But don't worry, as Thaw will
3502 // recall SelectProperty to recreate them.
3505 // Prevent any further selection measures in this call
3506 p
= (wxPGProperty
*) NULL
;
3511 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3513 // Only set focus if not deselecting
3516 if ( flags
& wxPG_SEL_FOCUS
)
3520 m_wndEditor
->SetFocus();
3521 m_editorFocused
= 1;
3530 m_inDoSelectProperty
= 0;
3535 // First, deactivate previous
3539 OnValidationFailureReset(m_selected
);
3541 // Must double-check if this is an selected in case of forceswitch
3544 if ( !CommitChangesFromEditor(flags
) )
3546 // Validation has failed, so we can't exit the previous editor
3547 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3548 // _("Invalid Value"),wxOK|wxICON_ERROR);
3549 m_inDoSelectProperty
= 0;
3557 m_selected
= (wxPGProperty
*) NULL
;
3558 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3560 // We need to always fully refresh the grid here
3563 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3564 EditorsValueWasNotModified();
3567 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3570 // Then, activate the one given.
3573 int propY
= p
->GetY2(m_lineHeight
);
3575 int splitterX
= GetSplitterPosition();
3576 m_editorFocused
= 0;
3578 m_pState
->m_selected
= p
;
3579 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3581 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3583 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3585 // Do we need OnMeasureCalls?
3586 wxSize imsz
= p
->OnMeasureImage();
3589 // Only create editor for non-disabled non-caption
3590 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3592 // do this for non-caption items
3596 // Do we need to paint the custom image, if any?
3597 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3598 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3599 !p
->GetEditorClass()->CanContainCustomImage()
3601 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3603 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3604 wxPoint goodPos
= grect
.GetPosition();
3605 #if wxPG_CREATE_CONTROLS_HIDDEN
3606 int coord_adjust
= m_height
- goodPos
.y
;
3607 goodPos
.y
+= coord_adjust
;
3610 const wxPGEditor
* editor
= p
->GetEditorClass();
3611 wxCHECK_MSG(editor
, false,
3612 wxT("NULL editor class not allowed"));
3614 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3616 wxPGWindowList wndList
= editor
->CreateControls(this,
3621 m_wndEditor
= wndList
.m_primary
;
3622 m_wndEditor2
= wndList
.m_secondary
;
3624 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3625 // value is drawn as normal, and m_wndEditor2 is assumed
3626 // to be a right-aligned button that triggers a separate editor
3631 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3632 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3634 // Set validator, if any
3635 #if wxUSE_VALIDATORS
3636 wxValidator
* validator
= p
->GetValidator();
3638 m_wndEditor
->SetValidator(*validator
);
3641 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3642 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3644 // If it has modified status, use bold font
3645 // (must be done before capturing m_ctrlXAdjust)
3646 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3647 SetCurControlBoldFont();
3650 // Fix TextCtrl indentation
3651 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3652 wxTextCtrl
* tc
= NULL
;
3653 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3654 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3656 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3658 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3661 // Store x relative to splitter (we'll need it).
3662 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3664 // Check if background clear is not necessary
3665 wxPoint pos
= m_wndEditor
->GetPosition();
3666 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3668 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3671 m_wndEditor
->SetSizeHints(3, 3);
3673 #if wxPG_CREATE_CONTROLS_HIDDEN
3674 m_wndEditor
->Show(false);
3675 m_wndEditor
->Freeze();
3677 goodPos
= m_wndEditor
->GetPosition();
3678 goodPos
.y
-= coord_adjust
;
3679 m_wndEditor
->Move( goodPos
);
3682 wxWindow
* primaryCtrl
= GetEditorControl();
3683 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3685 // Focus and select all (wxTextCtrl, wxComboBox etc)
3686 if ( flags
& wxPG_SEL_FOCUS
)
3688 primaryCtrl
->SetFocus();
3690 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3696 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3697 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3699 // Get proper id for wndSecondary
3700 m_wndSecId
= m_wndEditor2
->GetId();
3701 wxWindowList children
= m_wndEditor2
->GetChildren();
3702 wxWindowList::iterator node
= children
.begin();
3703 if ( node
!= children
.end() )
3704 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3706 m_wndEditor2
->SetSizeHints(3,3);
3708 #if wxPG_CREATE_CONTROLS_HIDDEN
3709 wxRect sec_rect
= m_wndEditor2
->GetRect();
3710 sec_rect
.y
-= coord_adjust
;
3712 // Fine tuning required to fix "oversized"
3713 // button disappearance bug.
3714 if ( sec_rect
.y
< 0 )
3716 sec_rect
.height
+= sec_rect
.y
;
3719 m_wndEditor2
->SetSize( sec_rect
);
3721 m_wndEditor2
->Show();
3723 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3725 // If no primary editor, focus to button to allow
3726 // it to interprete ENTER etc.
3727 // NOTE: Due to problems focusing away from it, this
3728 // has been disabled.
3730 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3731 m_wndEditor2->SetFocus();
3735 if ( flags
& wxPG_SEL_FOCUS
)
3736 m_editorFocused
= 1;
3741 // Make sure focus is in grid canvas (important for wxGTK, at least)
3745 EditorsValueWasNotModified();
3747 // If it's inside collapsed section, expand parent, scroll, etc.
3748 // Also, if it was partially visible, scroll it into view.
3749 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3754 #if wxPG_CREATE_CONTROLS_HIDDEN
3755 m_wndEditor
->Thaw();
3757 m_wndEditor
->Show(true);
3764 // Make sure focus is in grid canvas
3768 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3774 // Show help text in status bar.
3775 // (if found and grid not embedded in manager with help box and
3776 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3779 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3781 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3782 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3784 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3786 statusbar
= frame
->GetStatusBar();
3791 const wxString
* pHelpString
= (const wxString
*) NULL
;
3795 pHelpString
= &p
->GetHelpString();
3796 if ( pHelpString
->length() )
3798 // Set help box text.
3799 statusbar
->SetStatusText( *pHelpString
);
3800 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3804 if ( (!pHelpString
|| !pHelpString
->length()) &&
3805 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3807 // Clear help box - but only if it was written
3808 // by us at previous time.
3809 statusbar
->SetStatusText( m_emptyString
);
3810 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3816 m_inDoSelectProperty
= 0;
3818 // call wx event handler (here so that it also occurs on deselection)
3819 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3824 // -----------------------------------------------------------------------
3826 bool wxPropertyGrid::UnfocusEditor()
3828 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3831 if ( !CommitChangesFromEditor(0) )
3835 DrawItem(m_selected
);
3840 // -----------------------------------------------------------------------
3842 // This method is not inline because it called dozens of times
3843 // (i.e. two-arg function calls create smaller code size).
3844 bool wxPropertyGrid::DoClearSelection()
3846 return DoSelectProperty((wxPGProperty
*)NULL
);
3849 // -----------------------------------------------------------------------
3850 // wxPropertyGrid expand/collapse state
3851 // -----------------------------------------------------------------------
3853 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3855 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3857 // If active editor was inside collapsed section, then disable it
3858 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3860 if ( !ClearSelection() )
3864 // Store dont-center-splitter flag 'cause we need to temporarily set it
3865 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3866 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3868 bool res
= m_pState
->DoCollapse(pwc
);
3873 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3875 RecalculateVirtualSize();
3877 // Redraw etc. only if collapsed was visible.
3878 if (pwc
->IsVisible() &&
3880 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3882 // When item is collapsed so that scrollbar would move,
3883 // graphics mess is about (unless we redraw everything).
3888 // Clear dont-center-splitter flag if it wasn't set
3889 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3894 // -----------------------------------------------------------------------
3896 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3898 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3900 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3902 // Store dont-center-splitter flag 'cause we need to temporarily set it
3903 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3904 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3906 bool res
= m_pState
->DoExpand(pwc
);
3911 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3913 RecalculateVirtualSize();
3915 // Redraw etc. only if expanded was visible.
3916 if ( pwc
->IsVisible() && !m_frozen
&&
3917 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3921 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3924 DrawItems(pwc
, NULL
);
3929 // Clear dont-center-splitter flag if it wasn't set
3930 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3935 // -----------------------------------------------------------------------
3937 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3940 return m_pState
->DoHideProperty(p
, hide
, flags
);
3943 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3946 if ( !ClearSelection() )
3950 m_pState
->DoHideProperty(p
, hide
, flags
);
3952 RecalculateVirtualSize();
3959 // -----------------------------------------------------------------------
3960 // wxPropertyGrid size related methods
3961 // -----------------------------------------------------------------------
3963 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3965 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3969 // If virtual height was changed, then recalculate editor control position(s)
3970 if ( m_pState
->m_vhCalcPending
)
3971 CorrectEditorWidgetPosY();
3973 m_pState
->EnsureVirtualHeight();
3976 int by1
= m_pState
->GetVirtualHeight();
3977 int by2
= m_pState
->GetActualVirtualHeight();
3980 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3981 wxASSERT_MSG( false,
3987 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3989 int x
= m_pState
->m_width
;
3990 int y
= m_pState
->m_virtualHeight
;
3993 GetClientSize(&width
,&height
);
3995 // Now adjust virtual size.
3996 SetVirtualSize(x
, y
);
4002 // Adjust scrollbars
4003 if ( HasVirtualWidth() )
4005 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4006 xPos
= GetScrollPos( wxHORIZONTAL
);
4009 if ( forceXPos
!= -1 )
4012 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4015 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4016 int yPos
= GetScrollPos( wxVERTICAL
);
4018 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4019 xAmount
, yAmount
, xPos
, yPos
, true );
4021 // Must re-get size now
4022 GetClientSize(&width
,&height
);
4024 if ( !HasVirtualWidth() )
4026 m_pState
->SetVirtualWidth(width
);
4033 m_canvas
->SetSize( x
, y
);
4035 m_pState
->CheckColumnWidths();
4038 CorrectEditorWidgetSizeX();
4040 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4043 // -----------------------------------------------------------------------
4045 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4047 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4051 GetClientSize(&width
,&height
);
4056 #if wxPG_DOUBLE_BUFFER
4057 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4059 int dblh
= (m_lineHeight
*2);
4060 if ( !m_doubleBuffer
)
4062 // Create double buffer bitmap to draw on, if none
4063 int w
= (width
>250)?width
:250;
4064 int h
= height
+ dblh
;
4066 m_doubleBuffer
= new wxBitmap( w
, h
);
4070 int w
= m_doubleBuffer
->GetWidth();
4071 int h
= m_doubleBuffer
->GetHeight();
4073 // Double buffer must be large enough
4074 if ( w
< width
|| h
< (height
+dblh
) )
4076 if ( w
< width
) w
= width
;
4077 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4078 delete m_doubleBuffer
;
4079 m_doubleBuffer
= new wxBitmap( w
, h
);
4086 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4087 m_ncWidth
= event
.GetSize().x
;
4091 if ( m_pState
->m_itemsAdded
)
4092 PrepareAfterItemsAdded();
4094 // Without this, virtual size (atleast under wxGTK) will be skewed
4095 RecalculateVirtualSize();
4101 // -----------------------------------------------------------------------
4103 void wxPropertyGrid::SetVirtualWidth( int width
)
4107 // Disable virtual width
4108 width
= GetClientSize().x
;
4109 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4113 // Enable virtual width
4114 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4116 m_pState
->SetVirtualWidth( width
);
4119 void wxPropertyGrid::SetFocusOnCanvas()
4121 m_canvas
->SetFocusIgnoringChildren();
4122 m_editorFocused
= 0;
4125 // -----------------------------------------------------------------------
4126 // wxPropertyGrid mouse event handling
4127 // -----------------------------------------------------------------------
4129 // selFlags uses same values DoSelectProperty's flags
4130 // Returns true if event was vetoed.
4131 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4133 // Send property grid event of specific type and with specific property
4134 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4135 evt
.SetPropertyGrid(this);
4136 evt
.SetEventObject(m_eventObject
);
4140 evt
.SetCanVeto(true);
4141 evt
.SetupValidationInfo();
4142 m_validationInfo
.m_pValue
= pValue
;
4144 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4146 evtHandler
->ProcessEvent(evt
);
4148 return evt
.WasVetoed();
4151 // -----------------------------------------------------------------------
4153 // Return false if should be skipped
4154 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4158 // Need to set focus?
4159 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4164 wxPropertyGridPageState
* state
= m_pState
;
4166 int splitterHitOffset
;
4167 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4169 wxPGProperty
* p
= DoGetItemAtY(y
);
4173 int depth
= (int)p
->GetDepth() - 1;
4175 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4177 if ( x
>= marginEnds
)
4181 if ( p
->IsCategory() )
4183 // This is category.
4184 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4186 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4188 // Expand, collapse, activate etc. if click on text or left of splitter.
4191 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4196 if ( !DoSelectProperty( p
) )
4199 // On double-click, expand/collapse.
4200 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4202 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4203 else DoExpand( p
, true );
4207 else if ( splitterHit
== -1 )
4210 unsigned int selFlag
= 0;
4211 if ( columnHit
== 1 )
4213 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4214 selFlag
= wxPG_SEL_FOCUS
;
4216 if ( !DoSelectProperty( p
, selFlag
) )
4219 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4221 if ( p
->GetChildCount() && !p
->IsCategory() )
4222 // On double-click, expand/collapse.
4223 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4225 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4226 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4227 else DoExpand( p
, true );
4234 // click on splitter
4235 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4237 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4239 // Double-clicking the splitter causes auto-centering
4240 CenterSplitter( true );
4242 else if ( m_dragStatus
== 0 )
4245 // Begin draggin the splitter
4249 // Changes must be committed here or the
4250 // value won't be drawn correctly
4251 if ( !CommitChangesFromEditor() )
4254 m_wndEditor
->Show ( false );
4257 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4259 m_canvas
->CaptureMouse();
4260 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4264 m_draggedSplitter
= splitterHit
;
4265 m_dragOffset
= splitterHitOffset
;
4267 wxClientDC
dc(m_canvas
);
4269 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4270 // Fixes button disappearance bug
4272 m_wndEditor2
->Show ( false );
4275 m_startingSplitterX
= x
- splitterHitOffset
;
4283 if ( p
->GetChildCount() )
4285 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4287 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4289 int y2
= y
% m_lineHeight
;
4290 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4292 // On click on expander button, expand/collapse
4293 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4294 DoCollapse( p
, true );
4296 DoExpand( p
, true );
4305 // -----------------------------------------------------------------------
4307 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4308 wxMouseEvent
& WXUNUSED(event
) )
4312 // Select property here as well
4313 wxPGProperty
* p
= m_propHover
;
4314 if ( p
!= m_selected
)
4315 DoSelectProperty( p
);
4317 // Send right click event.
4318 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4325 // -----------------------------------------------------------------------
4327 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4328 wxMouseEvent
& WXUNUSED(event
) )
4332 // Select property here as well
4333 wxPGProperty
* p
= m_propHover
;
4335 if ( p
!= m_selected
)
4336 DoSelectProperty( p
);
4338 // Send double-click event.
4339 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4346 // -----------------------------------------------------------------------
4348 #if wxPG_SUPPORT_TOOLTIPS
4350 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4352 if ( tipString
.length() )
4354 m_canvas
->SetToolTip(tipString
);
4358 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4359 m_canvas
->SetToolTip( m_emptyString
);
4361 m_canvas
->SetToolTip( NULL
);
4366 #endif // #if wxPG_SUPPORT_TOOLTIPS
4368 // -----------------------------------------------------------------------
4370 // Return false if should be skipped
4371 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4373 // Safety check (needed because mouse capturing may
4374 // otherwise freeze the control)
4375 if ( m_dragStatus
> 0 && !event
.Dragging() )
4377 HandleMouseUp(x
,y
,event
);
4380 wxPropertyGridPageState
* state
= m_pState
;
4382 int splitterHitOffset
;
4383 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4384 int splitterX
= x
- splitterHitOffset
;
4386 if ( m_dragStatus
> 0 )
4388 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4389 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4392 int newSplitterX
= x
- m_dragOffset
;
4393 int splitterX
= x
- splitterHitOffset
;
4395 // Splitter redraw required?
4396 if ( newSplitterX
!= splitterX
)
4399 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4400 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4401 state
->m_fSplitterX
= (float) newSplitterX
;
4404 CorrectEditorWidgetSizeX();
4418 int ih
= m_lineHeight
;
4421 #if wxPG_SUPPORT_TOOLTIPS
4422 wxPGProperty
* prevHover
= m_propHover
;
4423 unsigned char prevSide
= m_mouseSide
;
4425 int curPropHoverY
= y
- (y
% ih
);
4427 // On which item it hovers
4428 if ( ( !m_propHover
)
4430 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4433 // Mouse moves on another property
4435 m_propHover
= DoGetItemAtY(y
);
4436 m_propHoverY
= curPropHoverY
;
4439 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4442 #if wxPG_SUPPORT_TOOLTIPS
4443 // Store which side we are on
4445 if ( columnHit
== 1 )
4447 else if ( columnHit
== 0 )
4451 // If tooltips are enabled, show label or value as a tip
4452 // in case it doesn't otherwise show in full length.
4454 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4456 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4458 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4460 if ( m_propHover
&& !m_propHover
->IsCategory() )
4463 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4465 // Show help string as a tooltip
4466 wxString tipString
= m_propHover
->GetHelpString();
4468 SetToolTip(tipString
);
4472 // Show cropped value string as a tooltip
4476 if ( m_mouseSide
== 1 )
4478 tipString
= m_propHover
->m_label
;
4479 space
= splitterX
-m_marginWidth
-3;
4481 else if ( m_mouseSide
== 2 )
4483 tipString
= m_propHover
->GetDisplayedString();
4485 space
= m_width
- splitterX
;
4486 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4487 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4493 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4496 SetToolTip( tipString
);
4503 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4504 m_canvas
->SetToolTip( m_emptyString
);
4506 m_canvas
->SetToolTip( NULL
);
4517 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4518 m_canvas
->SetToolTip( m_emptyString
);
4520 m_canvas
->SetToolTip( NULL
);
4528 if ( splitterHit
== -1 ||
4530 HasFlag(wxPG_STATIC_SPLITTER
) )
4532 // hovering on something else
4533 if ( m_curcursor
!= wxCURSOR_ARROW
)
4534 CustomSetCursor( wxCURSOR_ARROW
);
4538 // Do not allow splitter cursor on caption items.
4539 // (also not if we were dragging and its started
4540 // outside the splitter region)
4543 !m_propHover
->IsCategory() &&
4547 // hovering on splitter
4549 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4550 // reliably detected.
4551 //if ( m_curcursor != wxCURSOR_SIZEWE )
4552 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4558 // hovering on something else
4559 if ( m_curcursor
!= wxCURSOR_ARROW
)
4560 CustomSetCursor( wxCURSOR_ARROW
);
4567 // -----------------------------------------------------------------------
4569 // Also handles Leaving event
4570 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4571 wxMouseEvent
&WXUNUSED(event
) )
4573 wxPropertyGridPageState
* state
= m_pState
;
4577 int splitterHitOffset
;
4578 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4580 // No event type check - basicly calling this method should
4581 // just stop dragging.
4582 // Left up after dragged?
4583 if ( m_dragStatus
>= 1 )
4586 // End Splitter Dragging
4588 // DO NOT ENABLE FOLLOWING LINE!
4589 // (it is only here as a reminder to not to do it)
4592 // Disable splitter auto-centering
4593 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4595 // This is necessary to return cursor
4596 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4598 m_canvas
->ReleaseMouse();
4599 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4602 // Set back the default cursor, if necessary
4603 if ( splitterHit
== -1 ||
4606 CustomSetCursor( wxCURSOR_ARROW
);
4611 // Control background needs to be cleared
4612 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4613 DrawItem( m_selected
);
4617 m_wndEditor
->Show ( true );
4620 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4621 // Fixes button disappearance bug
4623 m_wndEditor2
->Show ( true );
4626 // This clears the focus.
4627 m_editorFocused
= 0;
4633 // -----------------------------------------------------------------------
4635 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4637 int splitterX
= GetSplitterPosition();
4640 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4644 wxWindow
* wnd
= m_wndEditor
;
4646 // Hide popup on clicks
4647 if ( event
.GetEventType() != wxEVT_MOTION
)
4648 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4650 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4656 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4658 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4659 ux
>= (r
.x
+r
.width
) ||
4661 event
.m_y
>= (r
.y
+r
.height
)
4671 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4676 // -----------------------------------------------------------------------
4678 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4681 if ( OnMouseCommon( event
, &x
, &y
) )
4683 HandleMouseClick(x
,y
,event
);
4688 // -----------------------------------------------------------------------
4690 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4693 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4694 HandleMouseRightClick(x
,y
,event
);
4698 // -----------------------------------------------------------------------
4700 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4702 // Always run standard mouse-down handler as well
4703 OnMouseClick(event
);
4706 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4707 HandleMouseDoubleClick(x
,y
,event
);
4711 // -----------------------------------------------------------------------
4713 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4716 if ( OnMouseCommon( event
, &x
, &y
) )
4718 HandleMouseMove(x
,y
,event
);
4723 // -----------------------------------------------------------------------
4725 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4727 // Called when mouse moves in the empty space below the properties.
4728 CustomSetCursor( wxCURSOR_ARROW
);
4731 // -----------------------------------------------------------------------
4733 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4736 if ( OnMouseCommon( event
, &x
, &y
) )
4738 HandleMouseUp(x
,y
,event
);
4743 // -----------------------------------------------------------------------
4745 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4747 // This may get called from child control as well, so event's
4748 // mouse position cannot be relied on.
4750 if ( event
.Entering() )
4752 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4754 // TODO: Fix this (detect parent and only do
4755 // cursor trick if it is a manager).
4756 wxASSERT( GetParent() );
4757 GetParent()->SetCursor(wxNullCursor
);
4759 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4762 GetParent()->SetCursor(wxNullCursor
);
4764 else if ( event
.Leaving() )
4766 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4767 m_canvas
->SetCursor( wxNullCursor
);
4769 // Get real cursor position
4770 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4772 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4775 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4777 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4781 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4789 // -----------------------------------------------------------------------
4791 // Common code used by various OnMouseXXXChild methods.
4792 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4794 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4795 wxASSERT( topCtrlWnd
);
4797 event
.GetPosition(&x
,&y
);
4799 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4801 int splitterX
= GetSplitterPosition();
4803 wxRect r
= topCtrlWnd
->GetRect();
4804 if ( !m_dragStatus
&&
4805 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4806 y
>= 0 && y
< r
.height \
4809 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4814 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4821 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4824 if ( OnMouseChildCommon(event
,&x
,&y
) )
4826 bool res
= HandleMouseClick(x
,y
,event
);
4827 if ( !res
) event
.Skip();
4831 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4834 wxASSERT( m_wndEditor
);
4835 // These coords may not be exact (about +-2),
4836 // but that should not matter (right click is about item, not position).
4837 wxPoint pt
= m_wndEditor
->GetPosition();
4838 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4839 wxASSERT( m_selected
);
4840 m_propHover
= m_selected
;
4841 bool res
= HandleMouseRightClick(x
,y
,event
);
4842 if ( !res
) event
.Skip();
4845 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4848 if ( OnMouseChildCommon(event
,&x
,&y
) )
4850 bool res
= HandleMouseMove(x
,y
,event
);
4851 if ( !res
) event
.Skip();
4855 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4858 if ( OnMouseChildCommon(event
,&x
,&y
) )
4860 bool res
= HandleMouseUp(x
,y
,event
);
4861 if ( !res
) event
.Skip();
4865 // -----------------------------------------------------------------------
4866 // wxPropertyGrid keyboard event handling
4867 // -----------------------------------------------------------------------
4869 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4871 wxNavigationKeyEvent evt
;
4872 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4873 (dir
?wxNavigationKeyEvent::IsForward
:
4874 wxNavigationKeyEvent::IsBackward
));
4875 evt
.SetEventObject(this);
4876 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4880 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4882 // Translates wxKeyEvent to wxPG_ACTION_XXX
4884 int keycode
= event
.GetKeyCode();
4885 int modifiers
= event
.GetModifiers();
4887 wxASSERT( !(modifiers
&~(0xFFFF)) );
4889 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4891 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4893 if ( it
== m_actionTriggers
.end() )
4898 int second
= (it
->second
>>16) & 0xFFFF;
4902 return (it
->second
& 0xFFFF);
4905 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4907 wxASSERT( !(modifiers
&~(0xFFFF)) );
4909 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4911 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4913 if ( it
!= m_actionTriggers
.end() )
4915 // This key combination is already used
4917 // Can add secondary?
4918 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4919 wxT("You can only add up to two separate actions per key combination.") );
4921 action
= it
->second
| (action
<<16);
4924 m_actionTriggers
[hashMapKey
] = action
;
4927 void wxPropertyGrid::ClearActionTriggers( int action
)
4929 wxPGHashMapI2I::iterator it
;
4931 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4933 if ( it
->second
== action
)
4935 m_actionTriggers
.erase(it
);
4940 static void CopyTextToClipboard( const wxString
& text
)
4942 if ( wxTheClipboard
->Open() )
4944 // This data objects are held by the clipboard,
4945 // so do not delete them in the app.
4946 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4947 wxTheClipboard
->Close();
4951 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4954 // Handles key event when editor control is not focused.
4957 wxASSERT( !m_frozen
);
4961 // Travelsal between items, collapsing/expanding, etc.
4962 int keycode
= event
.GetKeyCode();
4964 if ( keycode
== WXK_TAB
)
4966 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
4970 // Ignore Alt and Control when they are down alone
4971 if ( keycode
== WXK_ALT
||
4972 keycode
== WXK_CONTROL
)
4979 int action
= KeyEventToActions(event
, &secondAction
);
4985 if ( ButtonTriggerKeyTest(event
) )
4988 wxPGProperty
* p
= m_selected
;
4990 if ( action
== wxPG_ACTION_COPY
)
4992 CopyTextToClipboard(p
->GetDisplayedString());
4996 // Travel and expand/collapse
4999 if ( p
->GetChildCount() &&
5000 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5003 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5005 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5008 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5010 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5017 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5021 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5032 if ( selectDir
>= -1 )
5034 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5036 DoSelectProperty(p
);
5042 // If nothing was selected, select the first item now
5043 // (or navigate out of tab).
5044 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5046 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5047 if ( p
) DoSelectProperty(p
);
5052 // -----------------------------------------------------------------------
5054 // Potentially handles a keyboard event for editor controls.
5055 // Returns false if event should *not* be skipped (on true it can
5056 // be optionally skipped).
5057 // Basicly, false means that SelectProperty was called (or was about
5058 // to be called, if canDestroy was false).
5059 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5063 if ( !m_selected
|| !m_wndEditor
)
5068 int action
= KeyEventToAction(event
);
5071 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5074 // Esc cancels any changes
5075 if ( IsEditorsValueModified() )
5077 EditorsValueWasNotModified();
5079 // Update the control as well
5080 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5082 m_selected
->GetDisplayedString() );
5085 OnValidationFailureReset(m_selected
);
5091 else if ( action
== wxPG_ACTION_COPY
)
5093 // NB: There is some problem with getting native cut-copy-paste keys to go through
5094 // for embedded editor wxTextCtrl. This is why we emulate.
5096 wxTextCtrl
* tc
= GetEditorTextCtrl();
5099 wxString sel
= tc
->GetStringSelection();
5101 CopyTextToClipboard(sel
);
5105 CopyTextToClipboard(m_selected
->GetDisplayedString());
5108 else if ( action
== wxPG_ACTION_CUT
)
5110 wxTextCtrl
* tc
= GetEditorTextCtrl();
5114 tc
->GetSelection(&from
, &to
);
5117 CopyTextToClipboard(tc
->GetStringSelection());
5118 tc
->Remove(from
, to
);
5122 else if ( action
== wxPG_ACTION_PASTE
)
5124 wxTextCtrl
* tc
= GetEditorTextCtrl();
5127 if (wxTheClipboard
->Open())
5129 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5131 wxTextDataObject data
;
5132 wxTheClipboard
->GetData( data
);
5134 tc
->GetSelection(&from
, &to
);
5137 tc
->Remove(from
, to
);
5138 tc
->WriteText(data
.GetText());
5142 tc
->WriteText(data
.GetText());
5145 wxTheClipboard
->Close();
5153 // -----------------------------------------------------------------------
5155 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5159 // Events to editor controls should get relayed here.
5161 wxWindow
* focused
= wxWindow::FindFocus();
5163 wxWindow
* primaryCtrl
= GetEditorControl();
5166 (focused
==primaryCtrl
5167 || m_editorFocused
) )
5169 // Child key must be processed here, since it can
5170 // destroy the control which is referred by its own
5172 HandleChildKey( event
);
5175 HandleKeyEvent( event
);
5178 // -----------------------------------------------------------------------
5180 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5182 m_keyComboConsumed
= 0;
5187 // -----------------------------------------------------------------------
5189 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5191 // Ignore events that occur very close to focus set
5192 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5194 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5199 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5201 int dir
= event
.GetDirection()?1:-1;
5205 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5207 wxWindow
* focused
= wxWindow::FindFocus();
5209 wxWindow
* wndToCheck
= GetEditorControl();
5211 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5212 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5214 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5215 if ( comboTextCtrl
)
5216 wndToCheck
= comboTextCtrl
;
5220 // Because of problems navigating from wxButton, do not go to it.
5223 // No primary, use secondary
5224 wndToCheck = m_wndEditor2;
5226 // If it has editor button, focus to it after the primary editor.
5227 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5228 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5229 // have somewhat debugged in window.cpp itself).
5230 else if ( focused == wndToCheck &&
5232 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5234 wndToCheck = m_wndEditor2;
5235 wxLogDebug(wxT("Exp1"));
5239 if ( focused
!= wndToCheck
&&
5242 wndToCheck
->SetFocus();
5244 // Select all text in wxTextCtrl etc.
5245 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5246 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5248 m_editorFocused
= 1;
5255 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5259 // This allows preventing NavigateOut to occur
5260 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5269 // -----------------------------------------------------------------------
5271 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5273 int keycode
= event
.GetKeyCode();
5275 // Does the keycode trigger button?
5276 if ( keycode
== m_pushButKeyCode
&&
5278 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5279 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5281 m_keyComboConsumed
= 1;
5283 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5284 GetEventHandler()->AddPendingEvent(evt
);
5291 // -----------------------------------------------------------------------
5293 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5295 int keycode
= event
.GetKeyCode();
5297 // Ignore Alt and Control when they are down alone
5298 if ( keycode
== WXK_ALT
||
5299 keycode
== WXK_CONTROL
)
5305 if ( ButtonTriggerKeyTest(event
) )
5308 if ( HandleChildKey(event
) == true )
5311 GetEventHandler()->AddPendingEvent(event
);
5314 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5316 m_keyComboConsumed
= 0;
5318 GetEventHandler()->AddPendingEvent(event
);
5323 // -----------------------------------------------------------------------
5324 // wxPropertyGrid miscellaneous event handling
5325 // -----------------------------------------------------------------------
5327 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5330 // Check if the focus is in this control or one of its children
5331 wxWindow
* newFocused
= wxWindow::FindFocus();
5333 if ( newFocused
!= m_curFocused
)
5334 HandleFocusChange( newFocused
);
5337 // Called by focus event handlers. newFocused is the window that becomes focused.
5338 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5340 unsigned int oldFlags
= m_iFlags
;
5342 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5344 wxWindow
* parent
= newFocused
;
5346 // This must be one of nextFocus' parents.
5349 // Use m_eventObject, which is either wxPropertyGrid or
5350 // wxPropertyGridManager, as appropriate.
5351 if ( parent
== m_eventObject
)
5353 m_iFlags
|= wxPG_FL_FOCUSED
;
5356 parent
= parent
->GetParent();
5359 m_curFocused
= newFocused
;
5361 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5362 (oldFlags
& wxPG_FL_FOCUSED
) )
5364 // On each focus kill, mark the next nav key event
5365 // to be ignored (can't do on set focus since the
5366 // event would occur before it).
5367 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5369 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5371 // Need to store changed value
5372 CommitChangesFromEditor();
5378 // Preliminary code for tab-order respecting
5379 // tab-traversal (but should be moved to
5382 wxWindow* prevFocus = event.GetWindow();
5383 wxWindow* useThis = this;
5384 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5385 useThis = GetParent();
5388 prevFocus->GetParent() == useThis->GetParent() )
5390 wxList& children = useThis->GetParent()->GetChildren();
5392 wxNode* node = children.Find(prevFocus);
5394 if ( node->GetNext() &&
5395 useThis == node->GetNext()->GetData() )
5396 DoSelectProperty(GetFirst());
5397 else if ( node->GetPrevious () &&
5398 useThis == node->GetPrevious()->GetData() )
5399 DoSelectProperty(GetLastProperty());
5404 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5408 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5409 DrawItem( m_selected
);
5413 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5415 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5416 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5417 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5418 //else if ( event.GetWindow() )
5420 HandleFocusChange(event
.GetWindow());
5425 // -----------------------------------------------------------------------
5427 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5429 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5432 // event.Skip() being commented out is aworkaround for bug reported
5433 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5437 // -----------------------------------------------------------------------
5439 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5441 m_iFlags
|= wxPG_FL_SCROLLED
;
5446 // -----------------------------------------------------------------------
5448 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5450 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5452 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5456 // -----------------------------------------------------------------------
5457 // Property editor related functions
5458 // -----------------------------------------------------------------------
5460 // noDefCheck = true prevents infinite recursion.
5461 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5464 wxASSERT( editorClass
);
5466 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5467 RegisterDefaultEditors();
5469 wxString name
= editorClass
->GetName();
5471 // Existing editor under this name?
5472 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5474 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5475 (wxPGEditor
*) vt_it
->second
,
5476 "Editor with given name was already registered" );
5478 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5483 // Registers all default editor classes
5484 void wxPropertyGrid::RegisterDefaultEditors()
5486 wxPGRegisterDefaultEditorClass( TextCtrl
);
5487 wxPGRegisterDefaultEditorClass( Choice
);
5488 wxPGRegisterDefaultEditorClass( ComboBox
);
5489 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5490 #if wxPG_INCLUDE_CHECKBOX
5491 wxPGRegisterDefaultEditorClass( CheckBox
);
5493 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5495 // Register SpinCtrl etc. editors before use
5496 RegisterAdditionalEditors();
5499 // -----------------------------------------------------------------------
5500 // wxPGStringTokenizer
5501 // Needed to handle C-style string lists (e.g. "str1" "str2")
5502 // -----------------------------------------------------------------------
5504 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5505 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5509 wxPGStringTokenizer::~wxPGStringTokenizer()
5513 bool wxPGStringTokenizer::HasMoreTokens()
5515 const wxString
& str
= *m_str
;
5517 wxString::const_iterator i
= m_curPos
;
5519 wxUniChar delim
= m_delimeter
;
5521 wxUniChar prev_a
= wxT('\0');
5523 bool inToken
= false;
5525 while ( i
!= str
.end() )
5534 m_readyToken
.clear();
5539 if ( prev_a
!= wxT('\\') )
5543 if ( a
!= wxT('\\') )
5563 m_curPos
= str
.end();
5571 wxString
wxPGStringTokenizer::GetNextToken()
5573 return m_readyToken
;
5576 // -----------------------------------------------------------------------
5578 // -----------------------------------------------------------------------
5580 wxPGChoiceEntry::wxPGChoiceEntry()
5581 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5585 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5586 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5587 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5591 // -----------------------------------------------------------------------
5593 // -----------------------------------------------------------------------
5595 wxPGChoicesData::wxPGChoicesData()
5600 wxPGChoicesData::~wxPGChoicesData()
5605 void wxPGChoicesData::Clear()
5609 for ( i
=0; i
<m_items
.size(); i
++ )
5621 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5623 wxASSERT( m_items
.size() == 0 );
5627 for ( i
=0; i
<data
->GetCount(); i
++ )
5628 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5631 // -----------------------------------------------------------------------
5633 // -----------------------------------------------------------------------
5635 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5639 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5640 m_data
->Insert( -1, p
);
5644 // -----------------------------------------------------------------------
5646 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5650 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5651 p
->SetBitmap(bitmap
);
5652 m_data
->Insert( -1, p
);
5656 // -----------------------------------------------------------------------
5658 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5662 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5663 m_data
->Insert(index
, p
);
5667 // -----------------------------------------------------------------------
5669 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5673 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5674 m_data
->Insert( index
, p
);
5678 // -----------------------------------------------------------------------
5680 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5686 while ( index
< GetCount() )
5688 int cmpRes
= GetLabel(index
).Cmp(label
);
5694 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5695 m_data
->Insert( index
, p
);
5699 // -----------------------------------------------------------------------
5701 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5705 unsigned int itemcount
= 0;
5706 const wxChar
** p
= &labels
[0];
5707 while ( *p
) { p
++; itemcount
++; }
5710 for ( i
= 0; i
< itemcount
; i
++ )
5712 int value
= wxPG_INVALID_VALUE
;
5715 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5719 // -----------------------------------------------------------------------
5721 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5726 unsigned int itemcount
= arr
.size();
5728 for ( i
= 0; i
< itemcount
; i
++ )
5730 int value
= wxPG_INVALID_VALUE
;
5733 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5737 // -----------------------------------------------------------------------
5739 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5744 unsigned int itemcount
= arr
.size();
5746 for ( i
= 0; i
< itemcount
; i
++ )
5748 int value
= wxPG_INVALID_VALUE
;
5749 if ( &arrint
&& arrint
.size() )
5751 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5755 // -----------------------------------------------------------------------
5757 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5759 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5761 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5762 delete m_data
->Item(i
);
5763 m_data
->m_items
.RemoveAt(nIndex
, count
);
5766 // -----------------------------------------------------------------------
5768 int wxPGChoices::Index( const wxString
& str
) const
5773 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5775 if ( m_data
->Item(i
)->GetText() == str
)
5782 // -----------------------------------------------------------------------
5784 int wxPGChoices::Index( int val
) const
5789 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5791 if ( m_data
->Item(i
)->GetValue() == val
)
5798 // -----------------------------------------------------------------------
5800 wxArrayString
wxPGChoices::GetLabels() const
5805 if ( this && IsOk() )
5806 for ( i
=0; i
<GetCount(); i
++ )
5807 arr
.push_back(GetLabel(i
));
5812 // -----------------------------------------------------------------------
5814 bool wxPGChoices::HasValues() const
5819 // -----------------------------------------------------------------------
5821 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5828 for ( i
=0; i
< strings
.size(); i
++ )
5830 int index
= Index(strings
[i
]);
5832 arr
.Add(GetValue(index
));
5834 arr
.Add(wxPG_INVALID_VALUE
);
5841 // -----------------------------------------------------------------------
5843 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5844 wxArrayString
* unmatched
) const
5851 for ( i
=0; i
< strings
.size(); i
++ )
5853 const wxString
& str
= strings
[i
];
5854 int index
= Index(str
);
5857 else if ( unmatched
)
5858 unmatched
->Add(str
);
5865 // -----------------------------------------------------------------------
5867 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5871 if ( data
!= wxPGChoicesEmptyData
)
5878 // -----------------------------------------------------------------------
5880 void wxPGChoices::Init()
5882 m_data
= wxPGChoicesEmptyData
;
5885 // -----------------------------------------------------------------------
5887 void wxPGChoices::Free()
5889 if ( m_data
!= wxPGChoicesEmptyData
)
5892 m_data
= wxPGChoicesEmptyData
;
5896 // -----------------------------------------------------------------------
5897 // wxPropertyGridEvent
5898 // -----------------------------------------------------------------------
5900 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5903 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5904 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5905 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5906 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5907 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5908 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5909 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5910 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5911 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5914 // -----------------------------------------------------------------------
5916 void wxPropertyGridEvent::Init()
5918 m_validationInfo
= NULL
;
5920 m_wasVetoed
= false;
5923 // -----------------------------------------------------------------------
5925 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5926 : wxCommandEvent(commandType
,id
)
5932 // -----------------------------------------------------------------------
5934 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5935 : wxCommandEvent(event
)
5937 m_eventType
= event
.GetEventType();
5938 m_eventObject
= event
.m_eventObject
;
5940 m_property
= event
.m_property
;
5941 m_validationInfo
= event
.m_validationInfo
;
5942 m_canVeto
= event
.m_canVeto
;
5943 m_wasVetoed
= event
.m_wasVetoed
;
5946 // -----------------------------------------------------------------------
5948 wxPropertyGridEvent::~wxPropertyGridEvent()
5952 // -----------------------------------------------------------------------
5954 wxEvent
* wxPropertyGridEvent::Clone() const
5956 return new wxPropertyGridEvent( *this );
5959 // -----------------------------------------------------------------------
5960 // wxPropertyGridPopulator
5961 // -----------------------------------------------------------------------
5963 wxPropertyGridPopulator::wxPropertyGridPopulator()
5967 wxPGGlobalVars
->m_offline
++;
5970 // -----------------------------------------------------------------------
5972 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5975 m_propHierarchy
.clear();
5978 // -----------------------------------------------------------------------
5980 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5986 // -----------------------------------------------------------------------
5988 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5991 // Free unused sets of choices
5992 wxPGHashMapS2P::iterator it
;
5994 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5996 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6003 m_pg
->GetPanel()->Refresh();
6005 wxPGGlobalVars
->m_offline
--;
6008 // -----------------------------------------------------------------------
6010 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6011 const wxString
& propLabel
,
6012 const wxString
& propName
,
6013 const wxString
* propValue
,
6014 wxPGChoices
* pChoices
)
6016 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6017 wxPGProperty
* parent
= GetCurParent();
6019 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6021 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6025 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6027 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6031 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6033 property
->SetLabel(propLabel
);
6034 property
->DoSetName(propName
);
6036 if ( pChoices
&& pChoices
->IsOk() )
6037 property
->SetChoices(*pChoices
);
6039 m_state
->DoInsert(parent
, -1, property
);
6042 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6047 // -----------------------------------------------------------------------
6049 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6051 m_propHierarchy
.push_back(property
);
6052 DoScanForChildren();
6053 m_propHierarchy
.pop_back();
6056 // -----------------------------------------------------------------------
6058 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6059 const wxString
& idString
)
6061 wxPGChoices choices
;
6064 if ( choicesString
[0] == wxT('@') )
6066 wxString ids
= choicesString
.substr(1);
6067 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6068 if ( it
== m_dictIdChoices
.end() )
6069 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6071 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6076 if ( idString
.length() )
6078 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6079 if ( it
!= m_dictIdChoices
.end() )
6081 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6088 // Parse choices string
6089 wxString::const_iterator it
= choicesString
.begin();
6093 bool labelValid
= false;
6095 for ( ; it
!= choicesString
.end(); it
++ )
6101 if ( c
== wxT('"') )
6106 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6107 choices
.Add(label
, l
);
6110 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6115 else if ( c
== wxT('=') )
6122 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6129 if ( c
== wxT('"') )
6142 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6143 choices
.Add(label
, l
);
6146 if ( !choices
.IsOk() )
6148 choices
.EnsureData();
6152 if ( idString
.length() )
6153 m_dictIdChoices
[idString
] = choices
.GetData();
6160 // -----------------------------------------------------------------------
6162 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6164 if ( s
.Last() == wxT('%') )
6166 wxString s2
= s
.substr(0,s
.length()-1);
6168 if ( s2
.ToLong(&val
, 10) )
6170 *pval
= (val
*max
)/100;
6176 return s
.ToLong(pval
, 10);
6179 // -----------------------------------------------------------------------
6181 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6182 const wxString
& type
,
6183 const wxString
& value
)
6185 int l
= m_propHierarchy
.size();
6189 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6190 wxString valuel
= value
.Lower();
6193 if ( type
.length() == 0 )
6198 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6200 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6202 else if ( value
.ToLong(&v
, 0) )
6209 if ( type
== wxT("string") )
6213 else if ( type
== wxT("int") )
6216 value
.ToLong(&v
, 0);
6219 else if ( type
== wxT("bool") )
6221 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6228 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6233 p
->SetAttribute( name
, variant
);
6238 // -----------------------------------------------------------------------
6240 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6242 wxLogError(_("Error in resource: %s"),msg
.c_str());
6245 // -----------------------------------------------------------------------
6247 #endif // wxUSE_PROPGRID