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()
430 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
431 EVT_MOTION(wxPGCanvas::OnMouseMove
)
432 EVT_PAINT(wxPGCanvas::OnPaint
)
433 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
434 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
435 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
436 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
437 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
438 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
439 EVT_CHAR(wxPGCanvas::OnKey
)
440 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
444 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
446 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
447 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
451 // Don't paint after destruction has begun
452 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
455 // Update everything inside the box
456 wxRect r
= GetUpdateRegion().GetBox();
458 // Repaint this rectangle
459 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
461 // We assume that the size set when grid is shown
462 // is what is desired.
463 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
466 // -----------------------------------------------------------------------
468 // -----------------------------------------------------------------------
470 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
472 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
473 EVT_IDLE(wxPropertyGrid::OnIdle
)
474 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
475 EVT_PAINT(wxPropertyGrid::OnPaint
)
476 EVT_SIZE(wxPropertyGrid::OnResize
)
477 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
478 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
479 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
480 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
481 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
482 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
483 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
484 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
488 // -----------------------------------------------------------------------
490 wxPropertyGrid::wxPropertyGrid()
496 // -----------------------------------------------------------------------
498 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
507 Create(parent
,id
,pos
,size
,style
,name
);
510 // -----------------------------------------------------------------------
512 bool wxPropertyGrid::Create( wxWindow
*parent
,
520 if ( !(style
&wxBORDER_MASK
) )
521 style
|= wxSIMPLE_BORDER
;
526 // This prevents crash under Win2K, but still
527 // enables keyboard navigation
528 if ( style
& wxTAB_TRAVERSAL
)
530 style
&= ~(wxTAB_TRAVERSAL
);
531 style
|= wxWANTS_CHARS
;
534 if ( style
& wxTAB_TRAVERSAL
)
535 style
|= wxWANTS_CHARS
;
538 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
545 // -----------------------------------------------------------------------
548 // Initialize values to defaults
550 void wxPropertyGrid::Init1()
552 // Register editor classes, if necessary.
553 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
554 wxPropertyGrid::RegisterDefaultEditors();
557 m_pState
= (wxPropertyGridPageState
*) NULL
;
558 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
559 m_selected
= (wxPGProperty
*) NULL
;
561 m_propHover
= (wxPGProperty
*) NULL
;
562 m_eventObject
= this;
563 m_curFocused
= (wxWindow
*) NULL
;
565 m_inDoPropertyChanged
= 0;
566 m_inCommitChangesFromEditor
= 0;
567 m_inDoSelectProperty
= 0;
568 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
574 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
575 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
576 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
577 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
578 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
579 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
580 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
581 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
582 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
583 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
584 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
585 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
586 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
588 m_coloursCustomized
= 0;
593 #if wxPG_DOUBLE_BUFFER
594 m_doubleBuffer
= (wxBitmap
*) NULL
;
597 m_windowsToDelete
= NULL
;
599 #ifndef wxPG_ICON_WIDTH
605 m_iconWidth
= wxPG_ICON_WIDTH
;
610 m_gutterWidth
= wxPG_GUTTER_MIN
;
611 m_subgroup_extramargin
= 10;
615 m_width
= m_height
= 0;
617 SetButtonShortcut(0);
619 m_keyComboConsumed
= 0;
621 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
624 m_chgInfo_changedProperty
= NULL
;
627 // -----------------------------------------------------------------------
630 // Initialize after parent etc. set
632 void wxPropertyGrid::Init2()
634 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
637 // Smaller controls on Mac
638 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
641 // Now create state, if one didn't exist already
642 // (wxPropertyGridManager might have created it for us).
645 m_pState
= CreateState();
646 m_pState
->m_pPropGrid
= this;
647 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
650 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
651 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
653 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
655 m_pState
->InitNonCatMode();
657 m_pState
->m_properties
= m_pState
->m_abcArray
;
660 GetClientSize(&m_width
,&m_height
);
662 #ifndef wxPG_ICON_WIDTH
663 // create two bitmap nodes for drawing
664 m_expandbmp
= new wxBitmap(expand_xpm
);
665 m_collbmp
= new wxBitmap(collapse_xpm
);
667 // calculate average font height for bitmap centering
669 m_iconWidth
= m_expandbmp
->GetWidth();
670 m_iconHeight
= m_expandbmp
->GetHeight();
673 m_curcursor
= wxCURSOR_ARROW
;
674 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
676 // adjust bitmap icon y position so they are centered
677 m_vspacing
= wxPG_DEFAULT_VSPACING
;
681 wxFont useFont
= wxScrolledWindow::GetFont();
682 wxScrolledWindow::SetOwnFont( useFont
);
685 // This should be otherwise called by SetOwnFont
686 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
688 // Add base brush item
689 m_arrBgBrushes
.Add((void*)new wxPGBrush());
691 // Add base colour items
692 m_arrFgCols
.Add((void*)new wxPGColour());
693 m_arrFgCols
.Add((void*)new wxPGColour());
697 // This helps with flicker
698 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
701 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
702 m_tlp
= ::wxGetTopLevelParent(this);
703 m_tlwHandler
= handler
;
704 m_tlp
->PushEventHandler(handler
);
706 // set virtual size to this window size
707 wxSize wndsize
= GetSize();
708 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
710 m_timeCreated
= ::wxGetLocalTimeMillis();
712 m_canvas
= new wxPGCanvas();
713 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
714 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
715 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
717 m_iFlags
|= wxPG_FL_INITIALIZED
;
719 m_ncWidth
= wndsize
.GetWidth();
721 // Need to call OnResize handler or size given in constructor/Create
723 wxSizeEvent
sizeEvent(wndsize
,0);
727 // -----------------------------------------------------------------------
729 wxPropertyGrid::~wxPropertyGrid()
733 DoSelectProperty(NULL
);
735 // This should do prevent things from going too badly wrong
736 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
738 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
739 m_canvas
->ReleaseMouse();
741 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
742 m_tlp
->RemoveEventHandler(handler
);
746 if ( IsEditorsValueModified() )
747 ::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).)"),
748 wxS("wxPropertyGrid Debug Warning") );
751 #if wxPG_DOUBLE_BUFFER
752 if ( m_doubleBuffer
)
753 delete m_doubleBuffer
;
756 delete m_windowsToDelete
;
758 //m_selected = (wxPGProperty*) NULL;
760 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
763 delete m_cursorSizeWE
;
765 #ifndef wxPG_ICON_WIDTH
770 // Delete cached text colours.
771 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
773 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
776 // Delete cached brushes.
777 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
779 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
782 // Delete common value records
783 for ( i
=0; i
<m_commonValues
.size(); i
++ )
785 delete GetCommonValue(i
);
789 // -----------------------------------------------------------------------
791 bool wxPropertyGrid::Destroy()
793 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
794 m_canvas
->ReleaseMouse();
796 return wxScrolledWindow::Destroy();
799 // -----------------------------------------------------------------------
801 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
803 return new wxPropertyGridPageState();
806 // -----------------------------------------------------------------------
807 // wxPropertyGrid overridden wxWindow methods
808 // -----------------------------------------------------------------------
810 void wxPropertyGrid::SetWindowStyleFlag( long style
)
812 long old_style
= m_windowStyle
;
814 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
816 wxASSERT( m_pState
);
818 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
821 EnableCategories( true );
823 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
825 // Disable categories
826 EnableCategories( false );
828 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
834 PrepareAfterItemsAdded();
836 m_pState
->m_itemsAdded
= 1;
838 #if wxPG_SUPPORT_TOOLTIPS
839 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
845 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
846 SetToolTip ( tooltip );
847 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
850 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
855 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
860 wxScrolledWindow::SetWindowStyleFlag ( style
);
862 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
864 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
866 CalculateFontAndBitmapStuff( m_vspacing
);
872 // -----------------------------------------------------------------------
874 void wxPropertyGrid::Freeze()
878 wxScrolledWindow::Freeze();
883 // -----------------------------------------------------------------------
885 void wxPropertyGrid::Thaw()
891 wxScrolledWindow::Thaw();
892 RecalculateVirtualSize();
893 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
897 // Force property re-selection
899 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
903 // -----------------------------------------------------------------------
905 void wxPropertyGrid::SetExtraStyle( long exStyle
)
907 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
909 #if defined(__WXMSW__)
912 // Don't use WS_EX_COMPOSITED just now.
915 if ( m_iFlags & wxPG_FL_IN_MANAGER )
916 hWnd = (HWND)GetParent()->GetHWND();
918 hWnd = (HWND)GetHWND();
920 ::SetWindowLong( hWnd, GWL_EXSTYLE,
921 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
924 //#elif defined(__WXGTK20__)
926 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
927 // truly was double-buffered.
928 if ( !this->IsDoubleBuffered() )
930 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
934 #if wxPG_DOUBLE_BUFFER
935 delete m_doubleBuffer
;
936 m_doubleBuffer
= NULL
;
941 wxScrolledWindow::SetExtraStyle( exStyle
);
943 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
944 m_pState
->InitNonCatMode();
946 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
947 m_windowStyle
|= wxPG_TOOLTIPS
;
950 wxPGGlobalVars
->m_extraStyle
= exStyle
;
953 // -----------------------------------------------------------------------
955 // returns the best acceptable minimal size
956 wxSize
wxPropertyGrid::DoGetBestSize() const
959 if ( m_lineHeight
> hei
)
961 wxSize sz
= wxSize( 60, hei
+40 );
967 // -----------------------------------------------------------------------
968 // wxPropertyGrid Font and Colour Methods
969 // -----------------------------------------------------------------------
971 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
975 m_captionFont
= wxScrolledWindow::GetFont();
977 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
978 m_subgroup_extramargin
= x
+ (x
/2);
981 #if wxPG_USE_RENDERER_NATIVE
982 m_iconWidth
= wxPG_ICON_WIDTH
;
983 #elif wxPG_ICON_WIDTH
985 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
986 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
987 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
991 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
992 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
993 m_gutterWidth
= wxPG_GUTTER_MIN
;
996 if ( vspacing
<= 1 ) vdiv
= 12;
997 else if ( vspacing
>= 3 ) vdiv
= 3;
999 m_spacingy
= m_fontHeight
/ vdiv
;
1000 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1001 m_spacingy
= wxPG_YSPACING_MIN
;
1004 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1005 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1007 m_captionFont
.SetWeight(wxBOLD
);
1008 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1010 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1013 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1014 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1017 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1019 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1020 RecalculateVirtualSize();
1022 InvalidateBestSize();
1025 // -----------------------------------------------------------------------
1027 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1033 // -----------------------------------------------------------------------
1035 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1036 int ga
= 1000, int ba
= 1000,
1037 bool forceDifferent
= false)
1044 // Recursion guard (allow 2 max)
1045 static int isinside
= 0;
1047 wxCHECK_MSG( isinside
< 3,
1049 wxT("wxPGAdjustColour should not be recursively called more than once") );
1054 int g
= src
.Green();
1057 if ( r2
>255 ) r2
= 255;
1058 else if ( r2
<0) r2
= 0;
1060 if ( g2
>255 ) g2
= 255;
1061 else if ( g2
<0) g2
= 0;
1063 if ( b2
>255 ) b2
= 255;
1064 else if ( b2
<0) b2
= 0;
1066 // Make sure they are somewhat different
1067 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1068 dst
= wxPGAdjustColour(src
,-(ra
*2));
1070 dst
= wxColour(r2
,g2
,b2
);
1072 // Recursion guard (allow 2 max)
1079 static int wxPGGetColAvg( const wxColour
& col
)
1081 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1085 void wxPropertyGrid::RegainColours()
1087 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1089 if ( !(m_coloursCustomized
& 0x0002) )
1091 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1093 // Make sure colour is dark enough
1095 int colDec
= wxPGGetColAvg(col
) - 230;
1097 int colDec
= wxPGGetColAvg(col
) - 200;
1100 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1105 if ( !(m_coloursCustomized
& 0x0001) )
1106 m_colMargin
= m_colCapBack
;
1108 if ( !(m_coloursCustomized
& 0x0004) )
1115 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1116 m_colCapFore
= capForeCol
;
1118 // Set the cached colour as well.
1119 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1122 if ( !(m_coloursCustomized
& 0x0008) )
1124 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1125 m_colPropBack
= bgCol
;
1127 // Set the cached brush as well.
1128 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1131 if ( !(m_coloursCustomized
& 0x0010) )
1133 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1134 m_colPropFore
= fgCol
;
1136 // Set the cached colour as well.
1137 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1140 if ( !(m_coloursCustomized
& 0x0020) )
1141 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1143 if ( !(m_coloursCustomized
& 0x0040) )
1144 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1146 if ( !(m_coloursCustomized
& 0x0080) )
1147 m_colLine
= m_colCapBack
;
1149 if ( !(m_coloursCustomized
& 0x0100) )
1150 m_colDisPropFore
= m_colCapFore
;
1152 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1155 // -----------------------------------------------------------------------
1157 void wxPropertyGrid::ResetColours()
1159 m_coloursCustomized
= 0;
1166 // -----------------------------------------------------------------------
1168 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1170 // Must disable active editor.
1173 bool selRes
= ClearSelection();
1174 wxPG_CHECK_MSG_DBG( selRes
,
1176 wxT("failed to deselect a property (editor probably had invalid value)") );
1179 // TODO: Following code is disabled with wxMac because
1180 // it is reported to fail. I (JMS) cannot debug it
1181 // personally right now.
1182 #if !defined(__WXMAC__)
1183 bool res
= wxScrolledWindow::SetFont( font
);
1186 CalculateFontAndBitmapStuff( m_vspacing
);
1189 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1197 // TODO: Remove after SetFont crash fixed.
1198 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1200 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."));
1206 // -----------------------------------------------------------------------
1208 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1211 m_coloursCustomized
|= 0x80;
1215 // -----------------------------------------------------------------------
1217 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1220 m_coloursCustomized
|= 0x01;
1224 // -----------------------------------------------------------------------
1226 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1228 m_colPropBack
= col
;
1229 m_coloursCustomized
|= 0x08;
1231 // Set the cached brush as well.
1232 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1237 // -----------------------------------------------------------------------
1239 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1241 m_colPropFore
= col
;
1242 m_coloursCustomized
|= 0x10;
1244 // Set the cached colour as well.
1245 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1250 // -----------------------------------------------------------------------
1252 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1254 m_colEmptySpace
= col
;
1259 // -----------------------------------------------------------------------
1261 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1263 m_colDisPropFore
= col
;
1264 m_coloursCustomized
|= 0x100;
1268 // -----------------------------------------------------------------------
1270 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1273 m_coloursCustomized
|= 0x20;
1277 // -----------------------------------------------------------------------
1279 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1282 m_coloursCustomized
|= 0x40;
1286 // -----------------------------------------------------------------------
1288 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1291 m_coloursCustomized
|= 0x02;
1295 // -----------------------------------------------------------------------
1297 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1300 m_coloursCustomized
|= 0x04;
1302 // Set the cached colour as well.
1303 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1308 // -----------------------------------------------------------------------
1310 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1312 unsigned char ind
= index
;
1314 p
->m_bgColIndex
= ind
;
1317 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1318 SetBackgroundColourIndex(p
->Item(i
),index
);
1321 // -----------------------------------------------------------------------
1323 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1325 wxPG_PROP_ARG_CALL_PROLOG()
1330 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1332 // As it is most likely that the previous colour is used, start comparison
1334 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1336 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1345 colInd
= m_arrBgBrushes
.size();
1346 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1347 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1351 SetBackgroundColourIndex(p
,colInd
);
1353 // If this was on a visible grid, then draw it.
1354 DrawItemAndChildren(p
);
1357 // -----------------------------------------------------------------------
1359 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1361 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1363 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1366 // -----------------------------------------------------------------------
1368 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1370 unsigned char ind
= index
;
1372 p
->m_fgColIndex
= ind
;
1374 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1377 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1378 SetTextColourIndex( p
->Item(i
), index
, flags
);
1382 // -----------------------------------------------------------------------
1384 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1389 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1391 // As it is most likely that the previous colour is used, start comparison
1393 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1395 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1404 colInd
= m_arrFgCols
.size();
1405 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1406 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1412 // -----------------------------------------------------------------------
1414 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1417 wxPG_PROP_ARG_CALL_PROLOG()
1419 if ( p
->IsCategory() )
1421 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1422 cat
->SetTextColIndex(CacheColour(colour
));
1428 flags
|= wxPG_RECURSE
;
1429 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1431 DrawItemAndChildren(p
);
1434 // -----------------------------------------------------------------------
1436 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1438 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1440 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1443 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1445 wxPG_PROP_ARG_CALL_PROLOG()
1447 SetBackgroundColourIndex( p
, 0 );
1448 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1450 if ( p
->IsCategory() )
1452 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1453 cat
->SetTextColIndex(1);
1457 // -----------------------------------------------------------------------
1458 // wxPropertyGrid property adding and removal
1459 // -----------------------------------------------------------------------
1461 void wxPropertyGrid::PrepareAfterItemsAdded()
1463 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1465 m_pState
->m_itemsAdded
= 0;
1467 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1470 RecalculateVirtualSize();
1473 // -----------------------------------------------------------------------
1474 // wxPropertyGrid property value setting and getting
1475 // -----------------------------------------------------------------------
1477 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1479 m_pState
->DoSetPropertyValueUnspecified(p
);
1480 DrawItemAndChildren(p
);
1482 wxPGProperty
* parent
= p
->GetParent();
1483 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1486 parent
= parent
->GetParent();
1490 // -----------------------------------------------------------------------
1491 // wxPropertyGrid property operations
1492 // -----------------------------------------------------------------------
1494 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1496 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1500 bool changed
= false;
1502 // Is it inside collapsed section?
1503 if ( !p
->IsVisible() )
1506 wxPGProperty
* parent
= p
->GetParent();
1507 wxPGProperty
* grandparent
= parent
->GetParent();
1509 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1510 Expand( grandparent
);
1518 GetViewStart(&vx
,&vy
);
1519 vy
*=wxPG_PIXELS_PER_UNIT
;
1525 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1526 m_iFlags
|= wxPG_FL_SCROLLED
;
1529 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1531 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1532 m_iFlags
|= wxPG_FL_SCROLLED
;
1542 // -----------------------------------------------------------------------
1543 // wxPropertyGrid helper methods called by properties
1544 // -----------------------------------------------------------------------
1546 // Control font changer helper.
1547 void wxPropertyGrid::SetCurControlBoldFont()
1549 wxASSERT( m_wndEditor
);
1550 m_wndEditor
->SetFont( m_captionFont
);
1553 // -----------------------------------------------------------------------
1555 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1558 #if wxPG_SMALL_SCREEN
1559 // On small-screen devices, always show dialogs with default position and size.
1560 return wxDefaultPosition
;
1562 int splitterX
= GetSplitterPosition();
1566 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1568 ImprovedClientToScreen( &x
, &y
);
1570 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1571 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1578 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1588 new_y
= y
+ m_lineHeight
;
1590 return wxPoint(new_x
,new_y
);
1594 // -----------------------------------------------------------------------
1596 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1598 if ( src_str
.length() == 0 )
1604 bool prev_is_slash
= false;
1606 wxString::const_iterator i
= src_str
.begin();
1610 for ( ; i
!= src_str
.end(); i
++ )
1614 if ( a
!= wxS('\\') )
1616 if ( !prev_is_slash
)
1622 if ( a
== wxS('n') )
1625 dst_str
<< wxS('\n');
1627 dst_str
<< wxS('\n');
1630 else if ( a
== wxS('t') )
1631 dst_str
<< wxS('\t');
1635 prev_is_slash
= false;
1639 if ( prev_is_slash
)
1641 dst_str
<< wxS('\\');
1642 prev_is_slash
= false;
1646 prev_is_slash
= true;
1653 // -----------------------------------------------------------------------
1655 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1657 if ( src_str
.length() == 0 )
1663 wxString::const_iterator i
= src_str
.begin();
1664 wxUniChar prev_a
= wxS('\0');
1668 for ( ; i
!= src_str
.end(); i
++ )
1672 if ( a
>= wxS(' ') )
1674 // This surely is not something that requires an escape sequence.
1679 // This might need...
1680 if ( a
== wxS('\r') )
1682 // DOS style line end.
1683 // Already taken care below
1685 else if ( a
== wxS('\n') )
1686 // UNIX style line end.
1687 dst_str
<< wxS("\\n");
1688 else if ( a
== wxS('\t') )
1690 dst_str
<< wxS('\t');
1693 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1703 // -----------------------------------------------------------------------
1705 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1709 return (wxPGProperty
*) NULL
;
1712 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1715 // -----------------------------------------------------------------------
1716 // wxPropertyGrid graphics related methods
1717 // -----------------------------------------------------------------------
1719 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1723 // Update everything inside the box
1724 wxRect r
= GetUpdateRegion().GetBox();
1726 dc
.SetPen(m_colEmptySpace
);
1727 dc
.SetBrush(m_colEmptySpace
);
1728 dc
.DrawRectangle(r
);
1731 // -----------------------------------------------------------------------
1733 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1734 wxPGProperty
* property
) const
1736 // Prepare rectangle to be used
1738 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1739 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1741 #if (wxPG_USE_RENDERER_NATIVE)
1743 #elif wxPG_ICON_WIDTH
1744 // Drawing expand/collapse button manually
1745 dc
.SetPen(m_colPropFore
);
1746 if ( property
->IsCategory() )
1747 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1749 dc
.SetBrush(m_colPropBack
);
1751 dc
.DrawRectangle( r
);
1752 int _y
= r
.y
+(m_iconWidth
/2);
1753 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1758 if ( property
->IsExpanded() )
1760 // wxRenderer functions are non-mutating in nature, so it
1761 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1762 // Hopefully this does not cause problems.
1763 #if (wxPG_USE_RENDERER_NATIVE)
1764 wxRendererNative::Get().DrawTreeItemButton(
1770 #elif wxPG_ICON_WIDTH
1779 #if (wxPG_USE_RENDERER_NATIVE)
1780 wxRendererNative::Get().DrawTreeItemButton(
1786 #elif wxPG_ICON_WIDTH
1787 int _x
= r
.x
+(m_iconWidth
/2);
1788 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1794 #if (wxPG_USE_RENDERER_NATIVE)
1796 #elif wxPG_ICON_WIDTH
1799 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1803 // -----------------------------------------------------------------------
1806 // This is the one called by OnPaint event handler and others.
1807 // topy and bottomy are already unscrolled (ie. physical)
1809 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1811 unsigned int bottomy
,
1812 const wxRect
* clipRect
)
1814 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1816 m_pState
->EnsureVirtualHeight();
1818 wxRect tempClipRect
;
1821 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1822 clipRect
= &tempClipRect
;
1825 // items added check
1826 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1828 int paintFinishY
= 0;
1830 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1833 bool isBuffered
= false;
1835 #if wxPG_DOUBLE_BUFFER
1836 wxMemoryDC
* bufferDC
= NULL
;
1838 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1840 if ( !m_doubleBuffer
)
1842 paintFinishY
= clipRect
->y
;
1847 bufferDC
= new wxMemoryDC();
1849 // If nothing was changed, then just copy from double-buffer
1850 bufferDC
->SelectObject( *m_doubleBuffer
);
1860 dc
.SetClippingRegion( *clipRect
);
1861 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1864 #if wxPG_DOUBLE_BUFFER
1867 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1868 bufferDC
, 0, 0, wxCOPY
);
1869 dc
.DestroyClippingRegion(); // Is this really necessary?
1875 // Clear area beyond bottomY?
1876 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1878 dc
.SetPen(m_colEmptySpace
);
1879 dc
.SetBrush(m_colEmptySpace
);
1880 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1884 // -----------------------------------------------------------------------
1886 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1887 const wxPGProperty
* firstItem
,
1888 const wxPGProperty
* lastItem
,
1889 const wxRect
* clipRect
,
1890 bool isBuffered
) const
1892 // TODO: This should somehow be eliminated.
1893 wxRect tempClipRect
;
1896 wxASSERT(firstItem
);
1898 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1899 clipRect
= &tempClipRect
;
1903 firstItem
= DoGetItemAtY(clipRect
->y
);
1907 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1909 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1912 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1915 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1916 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1918 int lh
= m_lineHeight
;
1921 int lastItemBottomY
;
1923 firstItemTopY
= clipRect
->y
;
1924 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1926 // Align y coordinates to item boundaries
1927 firstItemTopY
-= firstItemTopY
% lh
;
1928 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1929 lastItemBottomY
-= 1;
1931 // Entire range outside scrolled, visible area?
1932 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1935 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1939 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1940 firstItem->GetLabel().c_str(),
1941 lastItem->GetLabel().c_str(),
1942 (int)(lastItemBottomY - firstItemTopY),
1944 (unsigned long)clipRect );
1949 long windowStyle
= m_windowStyle
;
1955 // With wxPG_DOUBLE_BUFFER, do double buffering
1956 // - buffer's y = 0, so align cliprect and coordinates to that
1958 #if wxPG_DOUBLE_BUFFER
1964 xRelMod
= clipRect
->x
;
1965 yRelMod
= clipRect
->y
;
1968 // clipRect conversion
1976 firstItemTopY
-= yRelMod
;
1977 lastItemBottomY
-= yRelMod
;
1980 wxUnusedVar(isBuffered
);
1983 int x
= m_marginWidth
- xRelMod
;
1985 const wxFont
& normalfont
= m_font
;
1987 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1989 bool isEnabled
= IsEnabled();
1992 // Prepare some pens and brushes that are often changed to.
1995 wxBrush
marginBrush(m_colMargin
);
1996 wxPen
marginPen(m_colMargin
);
1997 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1998 wxPen
linepen(m_colLine
,1,wxSOLID
);
2000 // pen that has same colour as text
2001 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2004 // Clear margin with background colour
2006 dc
.SetBrush( marginBrush
);
2007 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2009 dc
.SetPen( *wxTRANSPARENT_PEN
);
2010 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2013 const wxPGProperty
* selected
= m_selected
;
2014 const wxPropertyGridPageState
* state
= m_pState
;
2016 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2017 bool wasSelectedPainted
= false;
2020 // TODO: Only render columns that are within clipping region.
2022 dc
.SetFont(normalfont
);
2024 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2025 int endScanBottomY
= lastItemBottomY
+ lh
;
2026 int y
= firstItemTopY
;
2029 // Pregenerate list of visible properties.
2030 wxArrayPGProperty visPropArray
;
2031 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2033 for ( ; !it
.AtEnd(); it
.Next() )
2035 const wxPGProperty
* p
= *it
;
2037 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2039 visPropArray
.push_back((wxPGProperty
*)p
);
2041 if ( y
> endScanBottomY
)
2048 visPropArray
.push_back(NULL
);
2050 wxPGProperty
* nextP
= visPropArray
[0];
2052 int gridWidth
= state
->m_width
;
2055 for ( unsigned int arrInd
=1;
2056 nextP
&& y
<= lastItemBottomY
;
2059 wxPGProperty
* p
= nextP
;
2060 nextP
= visPropArray
[arrInd
];
2062 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2063 int textMarginHere
= x
;
2064 int renderFlags
= wxPGCellRenderer::Control
;
2066 int greyDepth
= m_marginWidth
;
2067 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2068 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2070 int greyDepthX
= greyDepth
- xRelMod
;
2072 // Use basic depth if in non-categoric mode and parent is base array.
2073 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2075 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2078 // Paint margin area
2079 dc
.SetBrush(marginBrush
);
2080 dc
.SetPen(marginPen
);
2081 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2083 dc
.SetPen( linepen
);
2088 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2094 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2096 sx
+= state
->m_colWidths
[si
];
2097 dc
.DrawLine( sx
, y
, sx
, y2
);
2100 // Horizontal Line, below
2101 // (not if both this and next is category caption)
2102 if ( p
->IsCategory() &&
2103 nextP
&& nextP
->IsCategory() )
2104 dc
.SetPen(m_colCapBack
);
2106 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2108 if ( p
== selected
)
2110 renderFlags
|= wxPGCellRenderer::Selected
;
2111 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2112 wasSelectedPainted
= true;
2120 if ( p
->IsCategory() )
2122 if ( p
->m_fgColIndex
== 0 )
2123 rowFgCol
= m_colCapFore
;
2125 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2126 rowBgBrush
= wxBrush(m_colCapBack
);
2128 else if ( p
!= selected
)
2130 // Disabled may get different colour.
2131 if ( !p
->IsEnabled() )
2132 rowFgCol
= m_colDisPropFore
;
2134 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2136 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2140 // Selected gets different colour.
2141 if ( reallyFocused
)
2143 rowFgCol
= m_colSelFore
;
2144 rowBgBrush
= wxBrush(m_colSelBack
);
2146 else if ( isEnabled
)
2148 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2149 rowBgBrush
= marginBrush
;
2153 rowFgCol
= m_colDisPropFore
;
2154 rowBgBrush
= wxBrush(m_colSelBack
);
2158 bool fontChanged
= false;
2160 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2165 if ( p
->IsCategory() )
2167 // Captions are all cells merged as one
2168 dc
.SetFont(m_captionFont
);
2170 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2172 dc
.SetBrush(rowBgBrush
);
2173 dc
.SetPen(rowBgBrush
.GetColour());
2174 dc
.SetTextForeground(rowFgCol
);
2176 dc
.DrawRectangle(cellRect
);
2179 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2180 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2183 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2184 DrawExpanderButton( dc
, butRect
, p
);
2188 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2190 dc
.SetFont(m_captionFont
);
2196 int nextCellWidth
= state
->m_colWidths
[0];
2197 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2198 int textXAdd
= textMarginHere
- greyDepthX
;
2200 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2202 cellRect
.width
= nextCellWidth
- 1;
2204 bool ctrlCell
= false;
2207 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2209 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2210 dc
.SetBrush(editorBgCol
);
2211 dc
.SetPen(editorBgCol
);
2212 dc
.SetTextForeground(m_colPropFore
);
2214 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2219 dc
.SetBrush(rowBgBrush
);
2220 dc
.SetPen(rowBgBrush
.GetColour());
2221 dc
.SetTextForeground(rowFgCol
);
2224 dc
.DrawRectangle(cellRect
);
2227 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2228 DrawExpanderButton( dc
, butRect
, p
);
2230 dc
.SetClippingRegion(cellRect
);
2232 cellRect
.x
+= textXAdd
;
2233 cellRect
.width
-= textXAdd
;
2238 wxPGCellRenderer
* renderer
;
2239 int cmnVal
= p
->GetCommonValue();
2240 if ( cmnVal
== -1 || ci
!= 1 )
2242 renderer
= p
->GetCellRenderer(ci
);
2243 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2247 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2248 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2252 cellX
+= state
->m_colWidths
[ci
];
2253 if ( ci
< (state
->m_colWidths
.size()-1) )
2254 nextCellWidth
= state
->m_colWidths
[ci
+1];
2256 dc
.DestroyClippingRegion(); // Is this really necessary?
2262 dc
.SetFont(normalfont
);
2267 // Refresh editor controls (seems not needed on msw)
2268 // NOTE: This code is mandatory for GTK!
2269 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2270 if ( wasSelectedPainted
)
2273 m_wndEditor
->Refresh();
2275 m_wndEditor2
->Refresh();
2282 // -----------------------------------------------------------------------
2284 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2288 if ( m_width
< 10 || m_height
< 10 ||
2289 !m_pState
->m_properties
->GetChildCount() ||
2290 p1
== (wxPGProperty
*) NULL
)
2291 return wxRect(0,0,0,0);
2296 // Return rect which encloses the given property range
2298 int visTop
= p1
->GetY();
2301 visBottom
= p2
->GetY() + m_lineHeight
;
2303 visBottom
= m_height
+ visTop
;
2305 // If seleced property is inside the range, we'll extend the range to include
2307 wxPGProperty
* selected
= m_selected
;
2310 int selectedY
= selected
->GetY();
2311 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2313 wxWindow
* editor
= GetEditorControl();
2316 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2317 if ( visBottom2
> visBottom
)
2318 visBottom
= visBottom2
;
2323 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2326 // -----------------------------------------------------------------------
2328 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2333 if ( m_pState
->m_itemsAdded
)
2334 PrepareAfterItemsAdded();
2336 wxRect r
= GetPropertyRect(p1
, p2
);
2339 m_canvas
->RefreshRect(r
);
2343 // -----------------------------------------------------------------------
2345 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2347 if ( p
== m_selected
)
2348 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2350 DrawItemAndChildren(p
);
2353 // -----------------------------------------------------------------------
2355 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2360 // Draw item, children, and parent too, if it is not category
2361 wxPGProperty
* parent
= p
->GetParent();
2364 !parent
->IsCategory() &&
2365 parent
->GetParent() )
2368 parent
= parent
->GetParent();
2371 DrawItemAndChildren(p
);
2374 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2376 wxCHECK_RET( p
, wxT("invalid property id") );
2378 // Do not draw if in non-visible page
2379 if ( p
->GetParentState() != m_pState
)
2382 // do not draw a single item if multiple pending
2383 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2386 wxWindow
* wndPrimary
= GetEditorControl();
2388 // Update child control.
2389 if ( m_selected
&& m_selected
->GetParent() == p
)
2390 m_selected
->UpdateControl(wndPrimary
);
2392 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2394 DrawItems(p
, lastDrawn
);
2397 // -----------------------------------------------------------------------
2399 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2400 const wxRect
*rect
)
2402 PrepareAfterItemsAdded();
2404 wxWindow::Refresh(false);
2406 // TODO: Coordinate translation
2407 m_canvas
->Refresh(false, rect
);
2409 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2410 // I think this really helps only GTK+1.2
2411 if ( m_wndEditor
) m_wndEditor
->Refresh();
2412 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2416 // -----------------------------------------------------------------------
2417 // wxPropertyGrid global operations
2418 // -----------------------------------------------------------------------
2420 void wxPropertyGrid::Clear()
2424 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2425 wxPG_CHECK_RET_DBG( selRes
,
2426 wxT("failed to deselect a property (editor probably had invalid value)") );
2429 m_pState
->DoClear();
2435 RecalculateVirtualSize();
2437 // Need to clear some area at the end
2439 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2442 // -----------------------------------------------------------------------
2444 bool wxPropertyGrid::EnableCategories( bool enable
)
2446 if ( !ClearSelection() )
2452 // Enable categories
2455 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2460 // Disable categories
2462 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2465 if ( !m_pState
->EnableCategories(enable
) )
2470 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2472 m_pState
->m_itemsAdded
= 1; // force
2473 PrepareAfterItemsAdded();
2477 m_pState
->m_itemsAdded
= 1;
2479 // No need for RecalculateVirtualSize() here - it is already called in
2480 // wxPropertyGridPageState method above.
2487 // -----------------------------------------------------------------------
2489 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2491 wxASSERT( pNewState
);
2492 wxASSERT( pNewState
->GetGrid() );
2494 if ( pNewState
== m_pState
)
2497 wxPGProperty
* oldSelection
= m_selected
;
2502 bool selRes
= ClearSelection();
2503 wxPG_CHECK_RET_DBG( selRes
,
2504 wxT("failed to deselect a property (editor probably had invalid value)") );
2507 m_pState
->m_selected
= oldSelection
;
2509 bool orig_mode
= m_pState
->IsInNonCatMode();
2510 bool new_state_mode
= pNewState
->IsInNonCatMode();
2512 m_pState
= pNewState
;
2515 int pgWidth
= GetClientSize().x
;
2516 if ( HasVirtualWidth() )
2518 int minWidth
= pgWidth
;
2519 if ( pNewState
->m_width
< minWidth
)
2521 pNewState
->m_width
= minWidth
;
2522 pNewState
->CheckColumnWidths();
2528 // Just in case, fully re-center splitter
2529 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2530 pNewState
->m_fSplitterX
= -1.0;
2532 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2535 m_propHover
= (wxPGProperty
*) NULL
;
2537 // If necessary, convert state to correct mode.
2538 if ( orig_mode
!= new_state_mode
)
2540 // This should refresh as well.
2541 EnableCategories( orig_mode
?false:true );
2543 else if ( !m_frozen
)
2545 // Refresh, if not frozen.
2546 if ( m_pState
->m_itemsAdded
)
2547 PrepareAfterItemsAdded();
2550 if ( m_pState
->m_selected
)
2551 DoSelectProperty( m_pState
->m_selected
);
2553 RecalculateVirtualSize(0);
2557 m_pState
->m_itemsAdded
= 1;
2560 // -----------------------------------------------------------------------
2562 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2564 wxPG_PROP_ARG_CALL_PROLOG()
2566 m_pState
->SortChildren( p
);
2569 // -----------------------------------------------------------------------
2571 void wxPropertyGrid::Sort()
2573 bool selRes
= ClearSelection(); // This must be before state clear
2574 wxPG_CHECK_RET_DBG( selRes
,
2575 wxT("failed to deselect a property (editor probably had invalid value)") );
2580 // -----------------------------------------------------------------------
2582 // Call to SetSplitterPosition will always disable splitter auto-centering
2583 // if parent window is shown.
2584 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2586 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2589 wxPropertyGridPageState
* state
= m_pState
;
2591 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2596 CorrectEditorWidgetSizeX();
2602 // -----------------------------------------------------------------------
2604 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2606 SetSplitterPosition( m_width
/2, true );
2607 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2608 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2611 // -----------------------------------------------------------------------
2612 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2613 // -----------------------------------------------------------------------
2615 // Returns nearest paint visible property (such that will be painted unless
2616 // window is scrolled or resized). If given property is paint visible, then
2617 // it itself will be returned
2618 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2620 int vx
,vy1
;// Top left corner of client
2621 GetViewStart(&vx
,&vy1
);
2622 vy1
*= wxPG_PIXELS_PER_UNIT
;
2624 int vy2
= vy1
+ m_height
;
2625 int propY
= p
->GetY2(m_lineHeight
);
2627 if ( (propY
+ m_lineHeight
) < vy1
)
2630 return DoGetItemAtY( vy1
);
2632 else if ( propY
> vy2
)
2635 return DoGetItemAtY( vy2
);
2638 // Itself paint visible
2643 // -----------------------------------------------------------------------
2645 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2649 m_pushButKeyCode
= keycode
;
2650 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2651 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2655 m_pushButKeyCode
= WXK_DOWN
;
2656 m_pushButKeyCodeNeedsCtrl
= 0;
2657 m_pushButKeyCodeNeedsAlt
= 1;
2661 // -----------------------------------------------------------------------
2662 // Methods related to change in value, value modification and sending events
2663 // -----------------------------------------------------------------------
2665 // commits any changes in editor of selected property
2666 // return true if validation did not fail
2667 // flags are same as with DoSelectProperty
2668 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2670 // Committing already?
2671 if ( m_inCommitChangesFromEditor
)
2674 // Don't do this if already processing editor event. It might
2675 // induce recursive dialogs and crap like that.
2676 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2678 if ( m_inDoPropertyChanged
)
2685 IsEditorsValueModified() &&
2686 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2689 m_inCommitChangesFromEditor
= 1;
2691 wxVariant
variant(m_selected
->GetValueRef());
2692 bool valueIsPending
= false;
2694 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2695 // due to another window getting focus
2696 wxWindow
* oldFocus
= m_curFocused
;
2698 bool validationFailure
= false;
2699 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2701 m_chgInfo_changedProperty
= NULL
;
2703 // If truly modified, schedule value as pending.
2704 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2706 if ( DoEditorValidate() &&
2707 PerformValidation(m_selected
, variant
) )
2709 valueIsPending
= true;
2713 validationFailure
= true;
2718 EditorsValueWasNotModified();
2723 m_inCommitChangesFromEditor
= 0;
2725 if ( validationFailure
&& !forceSuccess
)
2729 oldFocus
->SetFocus();
2730 m_curFocused
= oldFocus
;
2733 res
= OnValidationFailure(m_selected
, variant
);
2735 // Now prevent further validation failure messages
2738 EditorsValueWasNotModified();
2739 OnValidationFailureReset(m_selected
);
2742 else if ( valueIsPending
)
2744 DoPropertyChanged( m_selected
, flags
);
2745 EditorsValueWasNotModified();
2754 // -----------------------------------------------------------------------
2756 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2759 // Runs all validation functionality.
2760 // Returns true if value passes all tests.
2763 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2765 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2767 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2772 // Adapt list to child values, if necessary
2773 wxVariant listValue
= pendingValue
;
2774 wxVariant
* pPendingValue
= &pendingValue
;
2775 wxVariant
* pList
= NULL
;
2777 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2778 // string value, then we need treat as it was changed instead
2779 // (or, in addition, as is the case with composite string parent).
2780 // This includes creating list variant for child values.
2782 wxPGProperty
* pwc
= p
->GetParent();
2783 wxPGProperty
* changedProperty
= p
;
2784 wxPGProperty
* baseChangedProperty
= changedProperty
;
2785 wxVariant bcpPendingList
;
2787 listValue
= pendingValue
;
2788 listValue
.SetName(p
->GetBaseName());
2791 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2793 wxVariantList tempList
;
2794 wxVariant
lv(tempList
, pwc
->GetBaseName());
2795 lv
.Append(listValue
);
2797 pPendingValue
= &listValue
;
2799 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2801 baseChangedProperty
= pwc
;
2802 bcpPendingList
= lv
;
2805 changedProperty
= pwc
;
2806 pwc
= pwc
->GetParent();
2810 wxPGProperty
* evtChangingProperty
= changedProperty
;
2812 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2814 value
= *pPendingValue
;
2818 // Convert list to child values
2819 pList
= pPendingValue
;
2820 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2823 wxVariant evtChangingValue
= value
;
2825 // FIXME: After proper ValueToString()s added, remove
2826 // this. It is just a temporary fix, as evt_changing
2827 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2828 // (unless it is selected, and textctrl editor is open).
2829 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2831 evtChangingProperty
= baseChangedProperty
;
2832 if ( evtChangingProperty
!= p
)
2834 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2838 evtChangingValue
= pendingValue
;
2842 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2844 if ( changedProperty
== m_selected
)
2846 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2847 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2851 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2855 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2856 m_chgInfo_changedProperty
= changedProperty
;
2857 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2858 m_chgInfo_pendingValue
= value
;
2861 m_chgInfo_valueList
= *pList
;
2863 m_chgInfo_valueList
.MakeNull();
2865 // If changedProperty is not property which value was edited,
2866 // then call wxPGProperty::ValidateValue() for that as well.
2867 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2869 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2873 // SendEvent returns true if event was vetoed
2874 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2880 // -----------------------------------------------------------------------
2882 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2884 if ( !msg
.length() )
2888 if ( !wxPGGlobalVars
->m_offline
)
2890 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2893 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2896 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2899 pStatusBar
->SetStatusText(msg
);
2907 ::wxMessageBox(msg
, _T("Property Error"));
2910 // -----------------------------------------------------------------------
2912 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2914 int vfb
= m_validationInfo
.m_failureBehavior
;
2916 if ( vfb
& wxPG_VFB_BEEP
)
2919 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2920 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2922 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2923 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2925 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2927 wxColour vfbFg
= *wxWHITE
;
2928 wxColour vfbBg
= *wxRED
;
2929 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2930 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2932 DrawItemAndChildren(property
);
2934 if ( property
== m_selected
)
2936 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2938 wxWindow
* editor
= GetEditorControl();
2941 editor
->SetForegroundColour(vfbFg
);
2942 editor
->SetBackgroundColour(vfbBg
);
2948 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2950 wxString msg
= m_validationInfo
.m_failureMessage
;
2952 if ( !msg
.length() )
2953 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2955 DoShowPropertyError(property
, msg
);
2958 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2961 // -----------------------------------------------------------------------
2963 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2965 int vfb
= m_validationInfo
.m_failureBehavior
;
2967 if ( vfb
& wxPG_VFB_MARK_CELL
)
2969 property
->SetCell(0, NULL
);
2970 property
->SetCell(1, NULL
);
2972 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2974 if ( property
== m_selected
&& GetEditorControl() )
2976 // Calling this will recreate the control, thus resetting its colour
2977 RefreshProperty(property
);
2981 DrawItemAndChildren(property
);
2986 // -----------------------------------------------------------------------
2988 // flags are same as with DoSelectProperty
2989 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2991 if ( m_inDoPropertyChanged
)
2994 wxWindow
* editor
= GetEditorControl();
2996 m_pState
->m_anyModified
= 1;
2998 m_inDoPropertyChanged
= 1;
3000 // Maybe need to update control
3001 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3003 // These values were calculated in PerformValidation()
3004 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3005 wxVariant value
= m_chgInfo_pendingValue
;
3007 wxPGProperty
* topPaintedProperty
= changedProperty
;
3009 while ( !topPaintedProperty
->IsCategory() &&
3010 !topPaintedProperty
->IsRoot() )
3012 topPaintedProperty
= topPaintedProperty
->GetParent();
3015 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3017 // Set as Modified (not if dragging just began)
3018 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3020 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3021 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3024 SetCurControlBoldFont();
3030 // Propagate updates to parent(s)
3032 wxPGProperty
* prevPwc
= NULL
;
3034 while ( prevPwc
!= topPaintedProperty
)
3036 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3038 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3041 SetCurControlBoldFont();
3045 pwc
= pwc
->GetParent();
3048 // Draw the actual property
3049 DrawItemAndChildren( topPaintedProperty
);
3052 // If value was set by wxPGProperty::OnEvent, then update the editor
3054 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3057 p
->GetEditorClass()->UpdateControl(p
, editor
);
3061 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3062 if ( m_wndEditor
) m_wndEditor
->Refresh();
3063 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3068 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3070 // If top parent has composite string value, then send to child parents,
3071 // starting from baseChangedProperty.
3072 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3074 pwc
= m_chgInfo_baseChangedProperty
;
3076 while ( pwc
!= changedProperty
)
3078 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3079 pwc
= pwc
->GetParent();
3083 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3085 m_inDoPropertyChanged
= 0;
3090 // -----------------------------------------------------------------------
3092 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3094 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3096 m_chgInfo_changedProperty
= NULL
;
3098 if ( PerformValidation(p
, newValue
) )
3100 DoPropertyChanged(p
);
3105 OnValidationFailure(p
, newValue
);
3111 // -----------------------------------------------------------------------
3113 // Runs wxValidator for the selected property
3114 bool wxPropertyGrid::DoEditorValidate()
3119 // -----------------------------------------------------------------------
3121 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3123 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3124 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3126 wxWindow
* parent
= wnd
->GetParent();
3129 (parent
== m_canvas
||
3130 parent
->GetParent() == m_canvas
) )
3132 OnCustomEditorEvent((wxCommandEvent
&)event
);
3136 return wxPanel::ProcessEvent(event
);
3139 // -----------------------------------------------------------------------
3141 // NB: It may really not be wxCommandEvent - must check if necessary
3143 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3145 wxPGProperty
* selected
= m_selected
;
3148 // Somehow, event is handled after property has been deselected.
3149 // Possibly, but very rare.
3153 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3156 wxVariant
pendingValue(selected
->GetValueRef());
3157 wxWindow
* wnd
= GetEditorControl();
3159 bool wasUnspecified
= selected
->IsValueUnspecified();
3160 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3162 bool valueIsPending
= false;
3164 m_chgInfo_changedProperty
= NULL
;
3166 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3169 // Filter out excess wxTextCtrl modified events
3170 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3172 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3174 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3176 wxString newTcValue
= tc
->GetValue();
3177 if ( m_prevTcValue
== newTcValue
)
3180 m_prevTcValue
= newTcValue
;
3183 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3185 bool validationFailure
= false;
3186 bool buttonWasHandled
= false;
3189 // Try common button handling
3190 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3192 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3196 buttonWasHandled
= true;
3197 // Store as res2, as previously (and still currently alternatively)
3198 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3199 // in wxPGProperty::OnEvent().
3200 adapter
->ShowDialog( this, selected
);
3205 if ( !buttonWasHandled
)
3209 // First call editor class' event handler.
3210 const wxPGEditor
* editor
= selected
->GetEditorClass();
3212 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3214 // If changes, validate them
3215 if ( DoEditorValidate() )
3217 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3218 valueIsPending
= true;
3222 validationFailure
= true;
3227 // Then the property's custom handler (must be always called, unless
3228 // validation failed).
3229 if ( !validationFailure
)
3230 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3233 // SetValueInEvent(), as called in one of the functions referred above
3234 // overrides editor's value.
3235 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3237 valueIsPending
= true;
3238 pendingValue
= m_changeInEventValue
;
3239 selFlags
|= wxPG_SEL_DIALOGVAL
;
3242 if ( !validationFailure
&& valueIsPending
)
3243 if ( !PerformValidation(m_selected
, pendingValue
) )
3244 validationFailure
= true;
3246 if ( validationFailure
)
3248 OnValidationFailure(selected
, pendingValue
);
3250 else if ( valueIsPending
)
3252 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3254 DoPropertyChanged(selected
, selFlags
);
3255 EditorsValueWasNotModified();
3259 // No value after all
3261 // Let unhandled button click events go to the parent
3262 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3264 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3265 GetEventHandler()->AddPendingEvent(evt
);
3269 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3272 // -----------------------------------------------------------------------
3273 // wxPropertyGrid editor control helper methods
3274 // -----------------------------------------------------------------------
3276 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3278 int itemy
= p
->GetY2(m_lineHeight
);
3280 int cust_img_space
= 0;
3281 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3282 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3284 // TODO: If custom image detection changes from current, change this.
3285 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3287 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3288 int imwid
= p
->OnMeasureImage().x
;
3289 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3290 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3295 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3297 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3302 // -----------------------------------------------------------------------
3304 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3306 wxSize sz
= GetImageSize(p
, item
);
3307 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3308 wxPG_CUSTOM_IMAGE_SPACINGY
,
3313 // return size of custom paint image
3314 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3316 // If called with NULL property, then return default image
3317 // size for properties that use image.
3319 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3321 wxSize cis
= p
->OnMeasureImage(item
);
3323 int choiceCount
= p
->m_choices
.GetCount();
3324 int comVals
= p
->GetDisplayedCommonValueCount();
3325 if ( item
>= choiceCount
&& comVals
> 0 )
3327 unsigned int cvi
= item
-choiceCount
;
3328 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3330 else if ( item
>= 0 && choiceCount
== 0 )
3331 return wxSize(0, 0);
3336 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3341 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3348 // -----------------------------------------------------------------------
3350 // takes scrolling into account
3351 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3354 GetViewStart(&vx
,&vy
);
3355 vy
*=wxPG_PIXELS_PER_UNIT
;
3356 vx
*=wxPG_PIXELS_PER_UNIT
;
3359 ClientToScreen( px
, py
);
3362 // -----------------------------------------------------------------------
3364 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3367 GetViewStart(&pt2
.x
,&pt2
.y
);
3368 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3369 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3373 return m_pState
->HitTest(pt2
);
3376 // -----------------------------------------------------------------------
3378 // custom set cursor
3379 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3381 if ( type
== m_curcursor
&& !override
) return;
3383 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3385 if ( type
== wxCURSOR_SIZEWE
)
3386 cursor
= m_cursorSizeWE
;
3388 m_canvas
->SetCursor( *cursor
);
3393 // -----------------------------------------------------------------------
3394 // wxPropertyGrid property selection
3395 // -----------------------------------------------------------------------
3397 // Setups event handling for child control
3398 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
, int id
)
3400 if ( argWnd
== m_wndEditor
)
3402 this->Connect(id
, wxEVT_MOTION
,
3403 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3404 this->Connect(id
, wxEVT_LEFT_UP
,
3405 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3406 this->Connect(id
, wxEVT_LEFT_DOWN
,
3407 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3408 this->Connect(id
, wxEVT_RIGHT_UP
,
3409 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3410 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3411 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3412 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3413 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3417 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3418 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3421 this->Connect(id
, wxEVT_KEY_DOWN
,
3422 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3423 this->Connect(id
, wxEVT_KEY_UP
,
3424 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3425 this->Connect(id
, wxEVT_KILL_FOCUS
,
3426 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3429 void wxPropertyGrid::FreeEditors()
3431 // Do not free editors immediately if processing events
3432 if ( !m_windowsToDelete
)
3433 m_windowsToDelete
= new wxArrayPtrVoid
;
3437 m_windowsToDelete
->push_back(m_wndEditor2
);
3438 m_wndEditor2
->Hide();
3439 m_wndEditor2
= (wxWindow
*) NULL
;
3444 m_windowsToDelete
->push_back(m_wndEditor
);
3445 m_wndEditor
->Hide();
3446 m_wndEditor
= (wxWindow
*) NULL
;
3450 // Call with NULL to de-select property
3451 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3453 wxPanel
* canvas
= GetPanel();
3457 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3458 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3460 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3463 if ( m_inDoSelectProperty
)
3466 m_inDoSelectProperty
= 1;
3468 wxPGProperty
* prev
= m_selected
;
3471 // Delete windows pending for deletion
3472 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3476 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3477 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3479 m_windowsToDelete
->clear();
3484 m_inDoSelectProperty
= 0;
3489 // If we are frozen, then just set the values.
3492 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3493 m_editorFocused
= 0;
3496 m_pState
->m_selected
= p
;
3498 // If frozen, always free controls. But don't worry, as Thaw will
3499 // recall SelectProperty to recreate them.
3502 // Prevent any further selection measures in this call
3503 p
= (wxPGProperty
*) NULL
;
3508 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3510 // Only set focus if not deselecting
3513 if ( flags
& wxPG_SEL_FOCUS
)
3517 m_wndEditor
->SetFocus();
3518 m_editorFocused
= 1;
3527 m_inDoSelectProperty
= 0;
3532 // First, deactivate previous
3536 OnValidationFailureReset(m_selected
);
3538 // Must double-check if this is an selected in case of forceswitch
3541 if ( !CommitChangesFromEditor(flags
) )
3543 // Validation has failed, so we can't exit the previous editor
3544 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3545 // _("Invalid Value"),wxOK|wxICON_ERROR);
3546 m_inDoSelectProperty
= 0;
3554 m_selected
= (wxPGProperty
*) NULL
;
3555 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3557 // We need to always fully refresh the grid here
3560 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3561 EditorsValueWasNotModified();
3564 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3567 // Then, activate the one given.
3570 int propY
= p
->GetY2(m_lineHeight
);
3572 int splitterX
= GetSplitterPosition();
3573 m_editorFocused
= 0;
3575 m_pState
->m_selected
= p
;
3576 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3578 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3580 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3582 // Do we need OnMeasureCalls?
3583 wxSize imsz
= p
->OnMeasureImage();
3586 // Only create editor for non-disabled non-caption
3587 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3589 // do this for non-caption items
3593 // Do we need to paint the custom image, if any?
3594 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3595 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3596 !p
->GetEditorClass()->CanContainCustomImage()
3598 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3600 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3601 wxPoint goodPos
= grect
.GetPosition();
3602 #if wxPG_CREATE_CONTROLS_HIDDEN
3603 int coord_adjust
= m_height
- goodPos
.y
;
3604 goodPos
.y
+= coord_adjust
;
3607 const wxPGEditor
* editor
= p
->GetEditorClass();
3608 wxCHECK_MSG(editor
, false,
3609 wxT("NULL editor class not allowed"));
3611 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3613 wxPGWindowList wndList
= editor
->CreateControls(this,
3618 m_wndEditor
= wndList
.m_primary
;
3619 m_wndEditor2
= wndList
.m_secondary
;
3621 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3622 // value is drawn as normal, and m_wndEditor2 is assumed
3623 // to be a right-aligned button that triggers a separate editor
3628 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3629 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3631 // Set validator, if any
3632 #if wxUSE_VALIDATORS
3633 wxValidator
* validator
= p
->GetValidator();
3635 m_wndEditor
->SetValidator(*validator
);
3638 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3639 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3641 // If it has modified status, use bold font
3642 // (must be done before capturing m_ctrlXAdjust)
3643 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3644 SetCurControlBoldFont();
3647 // Fix TextCtrl indentation
3648 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3649 wxTextCtrl
* tc
= NULL
;
3650 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3651 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3653 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3655 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3658 // Store x relative to splitter (we'll need it).
3659 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3661 // Check if background clear is not necessary
3662 wxPoint pos
= m_wndEditor
->GetPosition();
3663 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3665 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3668 m_wndEditor
->SetSizeHints(3, 3);
3670 #if wxPG_CREATE_CONTROLS_HIDDEN
3671 m_wndEditor
->Show(false);
3672 m_wndEditor
->Freeze();
3674 goodPos
= m_wndEditor
->GetPosition();
3675 goodPos
.y
-= coord_adjust
;
3676 m_wndEditor
->Move( goodPos
);
3679 wxWindow
* primaryCtrl
= GetEditorControl();
3680 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3682 // Focus and select all (wxTextCtrl, wxComboBox etc)
3683 if ( flags
& wxPG_SEL_FOCUS
)
3685 primaryCtrl
->SetFocus();
3687 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3693 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3694 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3696 // Get proper id for wndSecondary
3697 m_wndSecId
= m_wndEditor2
->GetId();
3698 wxWindowList children
= m_wndEditor2
->GetChildren();
3699 wxWindowList::iterator node
= children
.begin();
3700 if ( node
!= children
.end() )
3701 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3703 m_wndEditor2
->SetSizeHints(3,3);
3705 #if wxPG_CREATE_CONTROLS_HIDDEN
3706 wxRect sec_rect
= m_wndEditor2
->GetRect();
3707 sec_rect
.y
-= coord_adjust
;
3709 // Fine tuning required to fix "oversized"
3710 // button disappearance bug.
3711 if ( sec_rect
.y
< 0 )
3713 sec_rect
.height
+= sec_rect
.y
;
3716 m_wndEditor2
->SetSize( sec_rect
);
3718 m_wndEditor2
->Show();
3720 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3722 // If no primary editor, focus to button to allow
3723 // it to interprete ENTER etc.
3724 // NOTE: Due to problems focusing away from it, this
3725 // has been disabled.
3727 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3728 m_wndEditor2->SetFocus();
3732 if ( flags
& wxPG_SEL_FOCUS
)
3733 m_editorFocused
= 1;
3738 // Make sure focus is in grid canvas (important for wxGTK, at least)
3742 EditorsValueWasNotModified();
3744 // If it's inside collapsed section, expand parent, scroll, etc.
3745 // Also, if it was partially visible, scroll it into view.
3746 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3751 #if wxPG_CREATE_CONTROLS_HIDDEN
3752 m_wndEditor
->Thaw();
3754 m_wndEditor
->Show(true);
3761 // Make sure focus is in grid canvas
3765 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3771 // Show help text in status bar.
3772 // (if found and grid not embedded in manager with help box and
3773 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3776 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3778 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3779 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3781 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3783 statusbar
= frame
->GetStatusBar();
3788 const wxString
* pHelpString
= (const wxString
*) NULL
;
3792 pHelpString
= &p
->GetHelpString();
3793 if ( pHelpString
->length() )
3795 // Set help box text.
3796 statusbar
->SetStatusText( *pHelpString
);
3797 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3801 if ( (!pHelpString
|| !pHelpString
->length()) &&
3802 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3804 // Clear help box - but only if it was written
3805 // by us at previous time.
3806 statusbar
->SetStatusText( m_emptyString
);
3807 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3813 m_inDoSelectProperty
= 0;
3815 // call wx event handler (here so that it also occurs on deselection)
3816 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3821 // -----------------------------------------------------------------------
3823 bool wxPropertyGrid::UnfocusEditor()
3825 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3828 if ( !CommitChangesFromEditor(0) )
3832 DrawItem(m_selected
);
3837 // -----------------------------------------------------------------------
3839 // This method is not inline because it called dozens of times
3840 // (i.e. two-arg function calls create smaller code size).
3841 bool wxPropertyGrid::DoClearSelection()
3843 return DoSelectProperty((wxPGProperty
*)NULL
);
3846 // -----------------------------------------------------------------------
3847 // wxPropertyGrid expand/collapse state
3848 // -----------------------------------------------------------------------
3850 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3852 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3854 // If active editor was inside collapsed section, then disable it
3855 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3857 if ( !ClearSelection() )
3861 // Store dont-center-splitter flag 'cause we need to temporarily set it
3862 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3863 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3865 bool res
= m_pState
->DoCollapse(pwc
);
3870 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3872 RecalculateVirtualSize();
3874 // Redraw etc. only if collapsed was visible.
3875 if (pwc
->IsVisible() &&
3877 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3879 // When item is collapsed so that scrollbar would move,
3880 // graphics mess is about (unless we redraw everything).
3885 // Clear dont-center-splitter flag if it wasn't set
3886 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3891 // -----------------------------------------------------------------------
3893 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3895 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3897 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3899 // Store dont-center-splitter flag 'cause we need to temporarily set it
3900 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3901 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3903 bool res
= m_pState
->DoExpand(pwc
);
3908 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3910 RecalculateVirtualSize();
3912 // Redraw etc. only if expanded was visible.
3913 if ( pwc
->IsVisible() && !m_frozen
&&
3914 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3918 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3921 DrawItems(pwc
, NULL
);
3926 // Clear dont-center-splitter flag if it wasn't set
3927 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3932 // -----------------------------------------------------------------------
3934 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3937 return m_pState
->DoHideProperty(p
, hide
, flags
);
3940 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3943 if ( !ClearSelection() )
3947 m_pState
->DoHideProperty(p
, hide
, flags
);
3949 RecalculateVirtualSize();
3956 // -----------------------------------------------------------------------
3957 // wxPropertyGrid size related methods
3958 // -----------------------------------------------------------------------
3960 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3962 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3966 // If virtual height was changed, then recalculate editor control position(s)
3967 if ( m_pState
->m_vhCalcPending
)
3968 CorrectEditorWidgetPosY();
3970 m_pState
->EnsureVirtualHeight();
3973 int by1
= m_pState
->GetVirtualHeight();
3974 int by2
= m_pState
->GetActualVirtualHeight();
3977 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3978 wxASSERT_MSG( false,
3984 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3986 int x
= m_pState
->m_width
;
3987 int y
= m_pState
->m_virtualHeight
;
3990 GetClientSize(&width
,&height
);
3992 // Now adjust virtual size.
3993 SetVirtualSize(x
, y
);
3999 // Adjust scrollbars
4000 if ( HasVirtualWidth() )
4002 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4003 xPos
= GetScrollPos( wxHORIZONTAL
);
4006 if ( forceXPos
!= -1 )
4009 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4012 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4013 int yPos
= GetScrollPos( wxVERTICAL
);
4015 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4016 xAmount
, yAmount
, xPos
, yPos
, true );
4018 // Must re-get size now
4019 GetClientSize(&width
,&height
);
4021 if ( !HasVirtualWidth() )
4023 m_pState
->SetVirtualWidth(width
);
4030 m_canvas
->SetSize( x
, y
);
4032 m_pState
->CheckColumnWidths();
4035 CorrectEditorWidgetSizeX();
4037 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4040 // -----------------------------------------------------------------------
4042 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4044 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4048 GetClientSize(&width
,&height
);
4053 #if wxPG_DOUBLE_BUFFER
4054 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4056 int dblh
= (m_lineHeight
*2);
4057 if ( !m_doubleBuffer
)
4059 // Create double buffer bitmap to draw on, if none
4060 int w
= (width
>250)?width
:250;
4061 int h
= height
+ dblh
;
4063 m_doubleBuffer
= new wxBitmap( w
, h
);
4067 int w
= m_doubleBuffer
->GetWidth();
4068 int h
= m_doubleBuffer
->GetHeight();
4070 // Double buffer must be large enough
4071 if ( w
< width
|| h
< (height
+dblh
) )
4073 if ( w
< width
) w
= width
;
4074 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4075 delete m_doubleBuffer
;
4076 m_doubleBuffer
= new wxBitmap( w
, h
);
4083 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4084 m_ncWidth
= event
.GetSize().x
;
4088 if ( m_pState
->m_itemsAdded
)
4089 PrepareAfterItemsAdded();
4091 // Without this, virtual size (atleast under wxGTK) will be skewed
4092 RecalculateVirtualSize();
4098 // -----------------------------------------------------------------------
4100 void wxPropertyGrid::SetVirtualWidth( int width
)
4104 // Disable virtual width
4105 width
= GetClientSize().x
;
4106 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4110 // Enable virtual width
4111 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4113 m_pState
->SetVirtualWidth( width
);
4116 // -----------------------------------------------------------------------
4117 // wxPropertyGrid mouse event handling
4118 // -----------------------------------------------------------------------
4120 // selFlags uses same values DoSelectProperty's flags
4121 // Returns true if event was vetoed.
4122 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4124 // Send property grid event of specific type and with specific property
4125 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4126 evt
.SetPropertyGrid(this);
4127 evt
.SetEventObject(m_eventObject
);
4131 evt
.SetCanVeto(true);
4132 evt
.SetupValidationInfo();
4133 m_validationInfo
.m_pValue
= pValue
;
4135 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4137 evtHandler
->ProcessEvent(evt
);
4139 return evt
.WasVetoed();
4142 // -----------------------------------------------------------------------
4144 // Return false if should be skipped
4145 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4149 // Need to set focus?
4150 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4155 wxPropertyGridPageState
* state
= m_pState
;
4157 int splitterHitOffset
;
4158 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4160 wxPGProperty
* p
= DoGetItemAtY(y
);
4164 int depth
= (int)p
->GetDepth() - 1;
4166 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4168 if ( x
>= marginEnds
)
4172 if ( p
->IsCategory() )
4174 // This is category.
4175 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4177 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4179 // Expand, collapse, activate etc. if click on text or left of splitter.
4182 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4187 if ( !DoSelectProperty( p
) )
4190 // On double-click, expand/collapse.
4191 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4193 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4194 else DoExpand( p
, true );
4198 else if ( splitterHit
== -1 )
4201 unsigned int selFlag
= 0;
4202 if ( columnHit
== 1 )
4204 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4205 selFlag
= wxPG_SEL_FOCUS
;
4207 if ( !DoSelectProperty( p
, selFlag
) )
4210 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4212 if ( p
->GetChildCount() && !p
->IsCategory() )
4213 // On double-click, expand/collapse.
4214 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4216 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4217 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4218 else DoExpand( p
, true );
4225 // click on splitter
4226 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4228 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4230 // Double-clicking the splitter causes auto-centering
4231 CenterSplitter( true );
4233 else if ( m_dragStatus
== 0 )
4236 // Begin draggin the splitter
4240 // Changes must be committed here or the
4241 // value won't be drawn correctly
4242 if ( !CommitChangesFromEditor() )
4245 m_wndEditor
->Show ( false );
4248 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4250 m_canvas
->CaptureMouse();
4251 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4255 m_draggedSplitter
= splitterHit
;
4256 m_dragOffset
= splitterHitOffset
;
4258 wxClientDC
dc(m_canvas
);
4260 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4261 // Fixes button disappearance bug
4263 m_wndEditor2
->Show ( false );
4266 m_startingSplitterX
= x
- splitterHitOffset
;
4274 if ( p
->GetChildCount() )
4276 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4278 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4280 int y2
= y
% m_lineHeight
;
4281 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4283 // On click on expander button, expand/collapse
4284 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4285 DoCollapse( p
, true );
4287 DoExpand( p
, true );
4296 // -----------------------------------------------------------------------
4298 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4299 wxMouseEvent
& WXUNUSED(event
) )
4303 // Select property here as well
4304 wxPGProperty
* p
= m_propHover
;
4305 if ( p
!= m_selected
)
4306 DoSelectProperty( p
);
4308 // Send right click event.
4309 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4316 // -----------------------------------------------------------------------
4318 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4319 wxMouseEvent
& WXUNUSED(event
) )
4323 // Select property here as well
4324 wxPGProperty
* p
= m_propHover
;
4326 if ( p
!= m_selected
)
4327 DoSelectProperty( p
);
4329 // Send double-click event.
4330 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4337 // -----------------------------------------------------------------------
4339 #if wxPG_SUPPORT_TOOLTIPS
4341 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4343 if ( tipString
.length() )
4345 m_canvas
->SetToolTip(tipString
);
4349 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4350 m_canvas
->SetToolTip( m_emptyString
);
4352 m_canvas
->SetToolTip( NULL
);
4357 #endif // #if wxPG_SUPPORT_TOOLTIPS
4359 // -----------------------------------------------------------------------
4361 // Return false if should be skipped
4362 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4364 // Safety check (needed because mouse capturing may
4365 // otherwise freeze the control)
4366 if ( m_dragStatus
> 0 && !event
.Dragging() )
4368 HandleMouseUp(x
,y
,event
);
4371 wxPropertyGridPageState
* state
= m_pState
;
4373 int splitterHitOffset
;
4374 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4375 int splitterX
= x
- splitterHitOffset
;
4377 if ( m_dragStatus
> 0 )
4379 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4380 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4383 int newSplitterX
= x
- m_dragOffset
;
4384 int splitterX
= x
- splitterHitOffset
;
4386 // Splitter redraw required?
4387 if ( newSplitterX
!= splitterX
)
4390 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4391 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4392 state
->m_fSplitterX
= (float) newSplitterX
;
4395 CorrectEditorWidgetSizeX();
4409 int ih
= m_lineHeight
;
4412 #if wxPG_SUPPORT_TOOLTIPS
4413 wxPGProperty
* prevHover
= m_propHover
;
4414 unsigned char prevSide
= m_mouseSide
;
4416 int curPropHoverY
= y
- (y
% ih
);
4418 // On which item it hovers
4419 if ( ( !m_propHover
)
4421 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4424 // Mouse moves on another property
4426 m_propHover
= DoGetItemAtY(y
);
4427 m_propHoverY
= curPropHoverY
;
4430 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4433 #if wxPG_SUPPORT_TOOLTIPS
4434 // Store which side we are on
4436 if ( columnHit
== 1 )
4438 else if ( columnHit
== 0 )
4442 // If tooltips are enabled, show label or value as a tip
4443 // in case it doesn't otherwise show in full length.
4445 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4447 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4449 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4451 if ( m_propHover
&& !m_propHover
->IsCategory() )
4454 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4456 // Show help string as a tooltip
4457 wxString tipString
= m_propHover
->GetHelpString();
4459 SetToolTip(tipString
);
4463 // Show cropped value string as a tooltip
4467 if ( m_mouseSide
== 1 )
4469 tipString
= m_propHover
->m_label
;
4470 space
= splitterX
-m_marginWidth
-3;
4472 else if ( m_mouseSide
== 2 )
4474 tipString
= m_propHover
->GetDisplayedString();
4476 space
= m_width
- splitterX
;
4477 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4478 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4484 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4487 SetToolTip( tipString
);
4494 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4495 m_canvas
->SetToolTip( m_emptyString
);
4497 m_canvas
->SetToolTip( NULL
);
4508 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4509 m_canvas
->SetToolTip( m_emptyString
);
4511 m_canvas
->SetToolTip( NULL
);
4519 if ( splitterHit
== -1 ||
4521 HasFlag(wxPG_STATIC_SPLITTER
) )
4523 // hovering on something else
4524 if ( m_curcursor
!= wxCURSOR_ARROW
)
4525 CustomSetCursor( wxCURSOR_ARROW
);
4529 // Do not allow splitter cursor on caption items.
4530 // (also not if we were dragging and its started
4531 // outside the splitter region)
4534 !m_propHover
->IsCategory() &&
4538 // hovering on splitter
4540 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4541 // reliably detected.
4542 //if ( m_curcursor != wxCURSOR_SIZEWE )
4543 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4549 // hovering on something else
4550 if ( m_curcursor
!= wxCURSOR_ARROW
)
4551 CustomSetCursor( wxCURSOR_ARROW
);
4558 // -----------------------------------------------------------------------
4560 // Also handles Leaving event
4561 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4562 wxMouseEvent
&WXUNUSED(event
) )
4564 wxPropertyGridPageState
* state
= m_pState
;
4568 int splitterHitOffset
;
4569 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4571 // No event type check - basicly calling this method should
4572 // just stop dragging.
4573 // Left up after dragged?
4574 if ( m_dragStatus
>= 1 )
4577 // End Splitter Dragging
4579 // DO NOT ENABLE FOLLOWING LINE!
4580 // (it is only here as a reminder to not to do it)
4583 // Disable splitter auto-centering
4584 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4586 // This is necessary to return cursor
4587 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4589 m_canvas
->ReleaseMouse();
4590 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4593 // Set back the default cursor, if necessary
4594 if ( splitterHit
== -1 ||
4597 CustomSetCursor( wxCURSOR_ARROW
);
4602 // Control background needs to be cleared
4603 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4604 DrawItem( m_selected
);
4608 m_wndEditor
->Show ( true );
4611 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4612 // Fixes button disappearance bug
4614 m_wndEditor2
->Show ( true );
4617 // This clears the focus.
4618 m_editorFocused
= 0;
4624 // -----------------------------------------------------------------------
4626 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4628 int splitterX
= GetSplitterPosition();
4631 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4635 wxWindow
* wnd
= m_wndEditor
;
4637 // Hide popup on clicks
4638 if ( event
.GetEventType() != wxEVT_MOTION
)
4639 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4641 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4647 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4649 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4650 ux
>= (r
.x
+r
.width
) ||
4652 event
.m_y
>= (r
.y
+r
.height
)
4662 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4667 // -----------------------------------------------------------------------
4669 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4672 if ( OnMouseCommon( event
, &x
, &y
) )
4674 HandleMouseClick(x
,y
,event
);
4679 // -----------------------------------------------------------------------
4681 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4684 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4685 HandleMouseRightClick(x
,y
,event
);
4689 // -----------------------------------------------------------------------
4691 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4693 // Always run standard mouse-down handler as well
4694 OnMouseClick(event
);
4697 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4698 HandleMouseDoubleClick(x
,y
,event
);
4702 // -----------------------------------------------------------------------
4704 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4707 if ( OnMouseCommon( event
, &x
, &y
) )
4709 HandleMouseMove(x
,y
,event
);
4714 // -----------------------------------------------------------------------
4716 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4718 // Called when mouse moves in the empty space below the properties.
4719 CustomSetCursor( wxCURSOR_ARROW
);
4722 // -----------------------------------------------------------------------
4724 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4727 if ( OnMouseCommon( event
, &x
, &y
) )
4729 HandleMouseUp(x
,y
,event
);
4734 // -----------------------------------------------------------------------
4736 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4738 // This may get called from child control as well, so event's
4739 // mouse position cannot be relied on.
4741 if ( event
.Entering() )
4743 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4745 // TODO: Fix this (detect parent and only do
4746 // cursor trick if it is a manager).
4747 wxASSERT( GetParent() );
4748 GetParent()->SetCursor(wxNullCursor
);
4750 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4753 GetParent()->SetCursor(wxNullCursor
);
4755 else if ( event
.Leaving() )
4757 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4758 m_canvas
->SetCursor( wxNullCursor
);
4760 // Get real cursor position
4761 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4763 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4766 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4768 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4772 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4780 // -----------------------------------------------------------------------
4782 // Common code used by various OnMouseXXXChild methods.
4783 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4785 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4786 wxASSERT( topCtrlWnd
);
4788 event
.GetPosition(&x
,&y
);
4790 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4792 int splitterX
= GetSplitterPosition();
4794 wxRect r
= topCtrlWnd
->GetRect();
4795 if ( !m_dragStatus
&&
4796 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4797 y
>= 0 && y
< r
.height \
4800 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4805 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4812 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4815 if ( OnMouseChildCommon(event
,&x
,&y
) )
4817 bool res
= HandleMouseClick(x
,y
,event
);
4818 if ( !res
) event
.Skip();
4822 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4825 wxASSERT( m_wndEditor
);
4826 // These coords may not be exact (about +-2),
4827 // but that should not matter (right click is about item, not position).
4828 wxPoint pt
= m_wndEditor
->GetPosition();
4829 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4830 wxASSERT( m_selected
);
4831 m_propHover
= m_selected
;
4832 bool res
= HandleMouseRightClick(x
,y
,event
);
4833 if ( !res
) event
.Skip();
4836 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4839 if ( OnMouseChildCommon(event
,&x
,&y
) )
4841 bool res
= HandleMouseMove(x
,y
,event
);
4842 if ( !res
) event
.Skip();
4846 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4849 if ( OnMouseChildCommon(event
,&x
,&y
) )
4851 bool res
= HandleMouseUp(x
,y
,event
);
4852 if ( !res
) event
.Skip();
4856 // -----------------------------------------------------------------------
4857 // wxPropertyGrid keyboard event handling
4858 // -----------------------------------------------------------------------
4860 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4862 wxNavigationKeyEvent evt
;
4863 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4864 (dir
?wxNavigationKeyEvent::IsForward
:
4865 wxNavigationKeyEvent::IsBackward
));
4866 evt
.SetEventObject(this);
4867 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4871 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4873 // Translates wxKeyEvent to wxPG_ACTION_XXX
4875 int keycode
= event
.GetKeyCode();
4876 int modifiers
= event
.GetModifiers();
4878 wxASSERT( !(modifiers
&~(0xFFFF)) );
4880 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4882 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4884 if ( it
== m_actionTriggers
.end() )
4889 int second
= (it
->second
>>16) & 0xFFFF;
4893 return (it
->second
& 0xFFFF);
4896 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4898 wxASSERT( !(modifiers
&~(0xFFFF)) );
4900 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4902 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4904 if ( it
!= m_actionTriggers
.end() )
4906 // This key combination is already used
4908 // Can add secondary?
4909 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4910 wxT("You can only add up to two separate actions per key combination.") );
4912 action
= it
->second
| (action
<<16);
4915 m_actionTriggers
[hashMapKey
] = action
;
4918 void wxPropertyGrid::ClearActionTriggers( int action
)
4920 wxPGHashMapI2I::iterator it
;
4922 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4924 if ( it
->second
== action
)
4926 m_actionTriggers
.erase(it
);
4931 static void CopyTextToClipboard( const wxString
& text
)
4933 if ( wxTheClipboard
->Open() )
4935 // This data objects are held by the clipboard,
4936 // so do not delete them in the app.
4937 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4938 wxTheClipboard
->Close();
4942 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4945 // Handles key event when editor control is not focused.
4948 wxASSERT( !m_frozen
);
4952 // Travelsal between items, collapsing/expanding, etc.
4953 int keycode
= event
.GetKeyCode();
4955 if ( keycode
== WXK_TAB
)
4957 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
4961 // Ignore Alt and Control when they are down alone
4962 if ( keycode
== WXK_ALT
||
4963 keycode
== WXK_CONTROL
)
4970 int action
= KeyEventToActions(event
, &secondAction
);
4976 if ( ButtonTriggerKeyTest(event
) )
4979 wxPGProperty
* p
= m_selected
;
4981 if ( action
== wxPG_ACTION_COPY
)
4983 CopyTextToClipboard(p
->GetDisplayedString());
4987 // Travel and expand/collapse
4990 if ( p
->GetChildCount() &&
4991 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4994 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4996 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4999 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5001 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5008 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5012 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5023 if ( selectDir
>= -1 )
5025 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5027 DoSelectProperty(p
);
5033 // If nothing was selected, select the first item now
5034 // (or navigate out of tab).
5035 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5037 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5038 if ( p
) DoSelectProperty(p
);
5043 // -----------------------------------------------------------------------
5045 // Potentially handles a keyboard event for editor controls.
5046 // Returns false if event should *not* be skipped (on true it can
5047 // be optionally skipped).
5048 // Basicly, false means that SelectProperty was called (or was about
5049 // to be called, if canDestroy was false).
5050 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5054 if ( !m_selected
|| !m_wndEditor
)
5059 int action
= KeyEventToAction(event
);
5062 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5065 // Esc cancels any changes
5066 if ( IsEditorsValueModified() )
5068 EditorsValueWasNotModified();
5070 // Update the control as well
5071 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5073 m_selected
->GetDisplayedString() );
5076 OnValidationFailureReset(m_selected
);
5082 else if ( action
== wxPG_ACTION_COPY
)
5084 // NB: There is some problem with getting native cut-copy-paste keys to go through
5085 // for embedded editor wxTextCtrl. This is why we emulate.
5087 wxTextCtrl
* tc
= GetEditorTextCtrl();
5090 wxString sel
= tc
->GetStringSelection();
5092 CopyTextToClipboard(sel
);
5096 CopyTextToClipboard(m_selected
->GetDisplayedString());
5099 else if ( action
== wxPG_ACTION_CUT
)
5101 wxTextCtrl
* tc
= GetEditorTextCtrl();
5105 tc
->GetSelection(&from
, &to
);
5108 CopyTextToClipboard(tc
->GetStringSelection());
5109 tc
->Remove(from
, to
);
5113 else if ( action
== wxPG_ACTION_PASTE
)
5115 wxTextCtrl
* tc
= GetEditorTextCtrl();
5118 if (wxTheClipboard
->Open())
5120 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5122 wxTextDataObject data
;
5123 wxTheClipboard
->GetData( data
);
5125 tc
->GetSelection(&from
, &to
);
5128 tc
->Remove(from
, to
);
5129 tc
->WriteText(data
.GetText());
5133 tc
->WriteText(data
.GetText());
5136 wxTheClipboard
->Close();
5144 // -----------------------------------------------------------------------
5146 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5150 // Events to editor controls should get relayed here.
5152 wxWindow
* focused
= wxWindow::FindFocus();
5154 wxWindow
* primaryCtrl
= GetEditorControl();
5157 (focused
==primaryCtrl
5158 || m_editorFocused
) )
5160 // Child key must be processed here, since it can
5161 // destroy the control which is referred by its own
5163 HandleChildKey( event
);
5166 HandleKeyEvent( event
);
5169 // -----------------------------------------------------------------------
5171 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5173 m_keyComboConsumed
= 0;
5178 // -----------------------------------------------------------------------
5180 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5182 // Ignore events that occur very close to focus set
5183 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5185 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5190 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5192 int dir
= event
.GetDirection()?1:-1;
5196 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5198 wxWindow
* focused
= wxWindow::FindFocus();
5200 wxWindow
* wndToCheck
= GetEditorControl();
5202 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5203 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5205 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5206 if ( comboTextCtrl
)
5207 wndToCheck
= comboTextCtrl
;
5211 // Because of problems navigating from wxButton, do not go to it.
5214 // No primary, use secondary
5215 wndToCheck = m_wndEditor2;
5217 // If it has editor button, focus to it after the primary editor.
5218 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5219 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5220 // have somewhat debugged in window.cpp itself).
5221 else if ( focused == wndToCheck &&
5223 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5225 wndToCheck = m_wndEditor2;
5226 wxLogDebug(wxT("Exp1"));
5230 if ( focused
!= wndToCheck
&&
5233 wndToCheck
->SetFocus();
5235 // Select all text in wxTextCtrl etc.
5236 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5237 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5239 m_editorFocused
= 1;
5246 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5250 // This allows preventing NavigateOut to occur
5251 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5260 // -----------------------------------------------------------------------
5262 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5264 int keycode
= event
.GetKeyCode();
5266 // Does the keycode trigger button?
5267 if ( keycode
== m_pushButKeyCode
&&
5269 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5270 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5272 m_keyComboConsumed
= 1;
5274 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5275 GetEventHandler()->AddPendingEvent(evt
);
5282 // -----------------------------------------------------------------------
5284 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5286 int keycode
= event
.GetKeyCode();
5288 // Ignore Alt and Control when they are down alone
5289 if ( keycode
== WXK_ALT
||
5290 keycode
== WXK_CONTROL
)
5296 if ( ButtonTriggerKeyTest(event
) )
5299 if ( HandleChildKey(event
) == true )
5302 GetEventHandler()->AddPendingEvent(event
);
5305 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5307 m_keyComboConsumed
= 0;
5309 GetEventHandler()->AddPendingEvent(event
);
5314 // -----------------------------------------------------------------------
5315 // wxPropertyGrid miscellaneous event handling
5316 // -----------------------------------------------------------------------
5318 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5321 // Check if the focus is in this control or one of its children
5322 wxWindow
* newFocused
= wxWindow::FindFocus();
5324 if ( newFocused
!= m_curFocused
)
5325 HandleFocusChange( newFocused
);
5328 // Called by focus event handlers. newFocused is the window that becomes focused.
5329 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5331 unsigned int oldFlags
= m_iFlags
;
5333 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5335 wxWindow
* parent
= newFocused
;
5337 // This must be one of nextFocus' parents.
5340 // Use m_eventObject, which is either wxPropertyGrid or
5341 // wxPropertyGridManager, as appropriate.
5342 if ( parent
== m_eventObject
)
5344 m_iFlags
|= wxPG_FL_FOCUSED
;
5347 parent
= parent
->GetParent();
5350 m_curFocused
= newFocused
;
5352 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5353 (oldFlags
& wxPG_FL_FOCUSED
) )
5355 // On each focus kill, mark the next nav key event
5356 // to be ignored (can't do on set focus since the
5357 // event would occur before it).
5358 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5360 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5362 // Need to store changed value
5363 CommitChangesFromEditor();
5369 // Preliminary code for tab-order respecting
5370 // tab-traversal (but should be moved to
5373 wxWindow* prevFocus = event.GetWindow();
5374 wxWindow* useThis = this;
5375 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5376 useThis = GetParent();
5379 prevFocus->GetParent() == useThis->GetParent() )
5381 wxList& children = useThis->GetParent()->GetChildren();
5383 wxNode* node = children.Find(prevFocus);
5385 if ( node->GetNext() &&
5386 useThis == node->GetNext()->GetData() )
5387 DoSelectProperty(GetFirst());
5388 else if ( node->GetPrevious () &&
5389 useThis == node->GetPrevious()->GetData() )
5390 DoSelectProperty(GetLastProperty());
5395 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5399 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5400 DrawItem( m_selected
);
5404 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5406 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5407 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5408 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5409 //else if ( event.GetWindow() )
5411 HandleFocusChange(event
.GetWindow());
5416 // -----------------------------------------------------------------------
5418 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5420 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5423 // event.Skip() being commented out is aworkaround for bug reported
5424 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5428 // -----------------------------------------------------------------------
5430 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5432 m_iFlags
|= wxPG_FL_SCROLLED
;
5437 // -----------------------------------------------------------------------
5439 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5441 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5443 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5447 // -----------------------------------------------------------------------
5448 // Property editor related functions
5449 // -----------------------------------------------------------------------
5451 // noDefCheck = true prevents infinite recursion.
5452 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5455 wxASSERT( editorClass
);
5457 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5458 RegisterDefaultEditors();
5460 wxString name
= editorClass
->GetName();
5462 // Existing editor under this name?
5463 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5465 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5466 (wxPGEditor
*) vt_it
->second
,
5467 "Editor with given name was already registered" );
5469 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5474 // Registers all default editor classes
5475 void wxPropertyGrid::RegisterDefaultEditors()
5477 wxPGRegisterDefaultEditorClass( TextCtrl
);
5478 wxPGRegisterDefaultEditorClass( Choice
);
5479 wxPGRegisterDefaultEditorClass( ComboBox
);
5480 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5481 #if wxPG_INCLUDE_CHECKBOX
5482 wxPGRegisterDefaultEditorClass( CheckBox
);
5484 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5486 // Register SpinCtrl etc. editors before use
5487 RegisterAdditionalEditors();
5490 // -----------------------------------------------------------------------
5491 // wxPGStringTokenizer
5492 // Needed to handle C-style string lists (e.g. "str1" "str2")
5493 // -----------------------------------------------------------------------
5495 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5496 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5500 wxPGStringTokenizer::~wxPGStringTokenizer()
5504 bool wxPGStringTokenizer::HasMoreTokens()
5506 const wxString
& str
= *m_str
;
5508 wxString::const_iterator i
= m_curPos
;
5510 wxUniChar delim
= m_delimeter
;
5512 wxUniChar prev_a
= wxT('\0');
5514 bool inToken
= false;
5516 while ( i
!= str
.end() )
5525 m_readyToken
.clear();
5530 if ( prev_a
!= wxT('\\') )
5534 if ( a
!= wxT('\\') )
5554 m_curPos
= str
.end();
5562 wxString
wxPGStringTokenizer::GetNextToken()
5564 return m_readyToken
;
5567 // -----------------------------------------------------------------------
5569 // -----------------------------------------------------------------------
5571 wxPGChoiceEntry::wxPGChoiceEntry()
5572 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5576 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5577 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5578 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5582 // -----------------------------------------------------------------------
5584 // -----------------------------------------------------------------------
5586 wxPGChoicesData::wxPGChoicesData()
5591 wxPGChoicesData::~wxPGChoicesData()
5596 void wxPGChoicesData::Clear()
5600 for ( i
=0; i
<m_items
.size(); i
++ )
5612 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5614 wxASSERT( m_items
.size() == 0 );
5618 for ( i
=0; i
<data
->GetCount(); i
++ )
5619 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5622 // -----------------------------------------------------------------------
5624 // -----------------------------------------------------------------------
5626 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5630 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5631 m_data
->Insert( -1, p
);
5635 // -----------------------------------------------------------------------
5637 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5641 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5642 p
->SetBitmap(bitmap
);
5643 m_data
->Insert( -1, p
);
5647 // -----------------------------------------------------------------------
5649 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5653 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5654 m_data
->Insert(index
, p
);
5658 // -----------------------------------------------------------------------
5660 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5664 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5665 m_data
->Insert( index
, p
);
5669 // -----------------------------------------------------------------------
5671 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5677 while ( index
< GetCount() )
5679 int cmpRes
= GetLabel(index
).Cmp(label
);
5685 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5686 m_data
->Insert( index
, p
);
5690 // -----------------------------------------------------------------------
5692 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5696 unsigned int itemcount
= 0;
5697 const wxChar
** p
= &labels
[0];
5698 while ( *p
) { p
++; itemcount
++; }
5701 for ( i
= 0; i
< itemcount
; i
++ )
5703 int value
= wxPG_INVALID_VALUE
;
5706 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5710 // -----------------------------------------------------------------------
5712 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5717 unsigned int itemcount
= arr
.size();
5719 for ( i
= 0; i
< itemcount
; i
++ )
5721 int value
= wxPG_INVALID_VALUE
;
5724 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5728 // -----------------------------------------------------------------------
5730 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5735 unsigned int itemcount
= arr
.size();
5737 for ( i
= 0; i
< itemcount
; i
++ )
5739 int value
= wxPG_INVALID_VALUE
;
5740 if ( &arrint
&& arrint
.size() )
5742 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5746 // -----------------------------------------------------------------------
5748 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5750 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5752 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5753 delete m_data
->Item(i
);
5754 m_data
->m_items
.RemoveAt(nIndex
, count
);
5757 // -----------------------------------------------------------------------
5759 int wxPGChoices::Index( const wxString
& str
) const
5764 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5766 if ( m_data
->Item(i
)->GetText() == str
)
5773 // -----------------------------------------------------------------------
5775 int wxPGChoices::Index( int val
) const
5780 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5782 if ( m_data
->Item(i
)->GetValue() == val
)
5789 // -----------------------------------------------------------------------
5791 wxArrayString
wxPGChoices::GetLabels() const
5796 if ( this && IsOk() )
5797 for ( i
=0; i
<GetCount(); i
++ )
5798 arr
.push_back(GetLabel(i
));
5803 // -----------------------------------------------------------------------
5805 bool wxPGChoices::HasValues() const
5810 // -----------------------------------------------------------------------
5812 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5819 for ( i
=0; i
< strings
.size(); i
++ )
5821 int index
= Index(strings
[i
]);
5823 arr
.Add(GetValue(index
));
5825 arr
.Add(wxPG_INVALID_VALUE
);
5832 // -----------------------------------------------------------------------
5834 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5835 wxArrayString
* unmatched
) const
5842 for ( i
=0; i
< strings
.size(); i
++ )
5844 const wxString
& str
= strings
[i
];
5845 int index
= Index(str
);
5848 else if ( unmatched
)
5849 unmatched
->Add(str
);
5856 // -----------------------------------------------------------------------
5858 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5862 if ( data
!= wxPGChoicesEmptyData
)
5869 // -----------------------------------------------------------------------
5871 void wxPGChoices::Init()
5873 m_data
= wxPGChoicesEmptyData
;
5876 // -----------------------------------------------------------------------
5878 void wxPGChoices::Free()
5880 if ( m_data
!= wxPGChoicesEmptyData
)
5883 m_data
= wxPGChoicesEmptyData
;
5887 // -----------------------------------------------------------------------
5888 // wxPropertyGridEvent
5889 // -----------------------------------------------------------------------
5891 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5894 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5895 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5896 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5897 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5898 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5899 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5900 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5901 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5902 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5905 // -----------------------------------------------------------------------
5907 void wxPropertyGridEvent::Init()
5909 m_validationInfo
= NULL
;
5911 m_wasVetoed
= false;
5914 // -----------------------------------------------------------------------
5916 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5917 : wxCommandEvent(commandType
,id
)
5923 // -----------------------------------------------------------------------
5925 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5926 : wxCommandEvent(event
)
5928 m_eventType
= event
.GetEventType();
5929 m_eventObject
= event
.m_eventObject
;
5931 m_property
= event
.m_property
;
5932 m_validationInfo
= event
.m_validationInfo
;
5933 m_canVeto
= event
.m_canVeto
;
5934 m_wasVetoed
= event
.m_wasVetoed
;
5937 // -----------------------------------------------------------------------
5939 wxPropertyGridEvent::~wxPropertyGridEvent()
5943 // -----------------------------------------------------------------------
5945 wxEvent
* wxPropertyGridEvent::Clone() const
5947 return new wxPropertyGridEvent( *this );
5950 // -----------------------------------------------------------------------
5951 // wxPropertyGridPopulator
5952 // -----------------------------------------------------------------------
5954 wxPropertyGridPopulator::wxPropertyGridPopulator()
5958 wxPGGlobalVars
->m_offline
++;
5961 // -----------------------------------------------------------------------
5963 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5966 m_propHierarchy
.clear();
5969 // -----------------------------------------------------------------------
5971 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5977 // -----------------------------------------------------------------------
5979 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5982 // Free unused sets of choices
5983 wxPGHashMapS2P::iterator it
;
5985 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5987 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5994 m_pg
->GetPanel()->Refresh();
5996 wxPGGlobalVars
->m_offline
--;
5999 // -----------------------------------------------------------------------
6001 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6002 const wxString
& propLabel
,
6003 const wxString
& propName
,
6004 const wxString
* propValue
,
6005 wxPGChoices
* pChoices
)
6007 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6008 wxPGProperty
* parent
= GetCurParent();
6010 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6012 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6016 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6018 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6022 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6024 property
->SetLabel(propLabel
);
6025 property
->DoSetName(propName
);
6027 if ( pChoices
&& pChoices
->IsOk() )
6028 property
->SetChoices(*pChoices
);
6030 m_state
->DoInsert(parent
, -1, property
);
6033 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6038 // -----------------------------------------------------------------------
6040 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6042 m_propHierarchy
.push_back(property
);
6043 DoScanForChildren();
6044 m_propHierarchy
.pop_back();
6047 // -----------------------------------------------------------------------
6049 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6050 const wxString
& idString
)
6052 wxPGChoices choices
;
6055 if ( choicesString
[0] == wxT('@') )
6057 wxString ids
= choicesString
.substr(1);
6058 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6059 if ( it
== m_dictIdChoices
.end() )
6060 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6062 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6067 if ( idString
.length() )
6069 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6070 if ( it
!= m_dictIdChoices
.end() )
6072 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6079 // Parse choices string
6080 wxString::const_iterator it
= choicesString
.begin();
6084 bool labelValid
= false;
6086 for ( ; it
!= choicesString
.end(); it
++ )
6092 if ( c
== wxT('"') )
6097 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6098 choices
.Add(label
, l
);
6101 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6106 else if ( c
== wxT('=') )
6113 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6120 if ( c
== wxT('"') )
6133 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6134 choices
.Add(label
, l
);
6137 if ( !choices
.IsOk() )
6139 choices
.EnsureData();
6143 if ( idString
.length() )
6144 m_dictIdChoices
[idString
] = choices
.GetData();
6151 // -----------------------------------------------------------------------
6153 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6155 if ( s
.Last() == wxT('%') )
6157 wxString s2
= s
.substr(0,s
.length()-1);
6159 if ( s2
.ToLong(&val
, 10) )
6161 *pval
= (val
*max
)/100;
6167 return s
.ToLong(pval
, 10);
6170 // -----------------------------------------------------------------------
6172 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6173 const wxString
& type
,
6174 const wxString
& value
)
6176 int l
= m_propHierarchy
.size();
6180 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6181 wxString valuel
= value
.Lower();
6184 if ( type
.length() == 0 )
6189 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6191 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6193 else if ( value
.ToLong(&v
, 0) )
6200 if ( type
== wxT("string") )
6204 else if ( type
== wxT("int") )
6207 value
.ToLong(&v
, 0);
6210 else if ( type
== wxT("bool") )
6212 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6219 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6224 p
->SetAttribute( name
, variant
);
6229 // -----------------------------------------------------------------------
6231 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6233 wxLogError(_("Error in resource: %s"),msg
.c_str());
6236 // -----------------------------------------------------------------------
6238 #endif // wxUSE_PROPGRID