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 OnPaint( wxPaintEvent
& event
);
413 // Always be focussable, even with child windows
414 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
415 { wxPanel::SetCanFocus(true); }
419 DECLARE_EVENT_TABLE()
420 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
424 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
426 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
427 EVT_MOTION(wxPGCanvas::OnMouseMove
)
428 EVT_PAINT(wxPGCanvas::OnPaint
)
429 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
430 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
431 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
432 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
433 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
437 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
439 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
440 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
444 // Don't paint after destruction has begun
445 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
448 // Update everything inside the box
449 wxRect r
= GetUpdateRegion().GetBox();
451 // Repaint this rectangle
452 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
454 // We assume that the size set when grid is shown
455 // is what is desired.
456 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
459 // -----------------------------------------------------------------------
461 // -----------------------------------------------------------------------
463 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
465 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
466 EVT_IDLE(wxPropertyGrid::OnIdle
)
467 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
468 EVT_PAINT(wxPropertyGrid::OnPaint
)
469 EVT_SIZE(wxPropertyGrid::OnResize
)
470 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
471 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
472 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
473 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
474 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
475 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
476 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
477 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
481 // -----------------------------------------------------------------------
483 wxPropertyGrid::wxPropertyGrid()
489 // -----------------------------------------------------------------------
491 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
500 Create(parent
,id
,pos
,size
,style
,name
);
503 // -----------------------------------------------------------------------
505 bool wxPropertyGrid::Create( wxWindow
*parent
,
513 if ( !(style
&wxBORDER_MASK
) )
514 style
|= wxSIMPLE_BORDER
;
518 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
519 style
&= ~(wxTAB_TRAVERSAL
);
520 style
|= wxWANTS_CHARS
;
522 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
529 // -----------------------------------------------------------------------
532 // Initialize values to defaults
534 void wxPropertyGrid::Init1()
536 // Register editor classes, if necessary.
537 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
538 wxPropertyGrid::RegisterDefaultEditors();
541 m_pState
= (wxPropertyGridPageState
*) NULL
;
542 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
543 m_selected
= (wxPGProperty
*) NULL
;
545 m_propHover
= (wxPGProperty
*) NULL
;
546 m_eventObject
= this;
547 m_curFocused
= (wxWindow
*) NULL
;
549 m_inDoPropertyChanged
= 0;
550 m_inCommitChangesFromEditor
= 0;
551 m_inDoSelectProperty
= 0;
552 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
558 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
559 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
560 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
561 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
562 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
563 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
564 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
565 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
566 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
568 m_coloursCustomized
= 0;
573 #if wxPG_DOUBLE_BUFFER
574 m_doubleBuffer
= (wxBitmap
*) NULL
;
577 #ifndef wxPG_ICON_WIDTH
583 m_iconWidth
= wxPG_ICON_WIDTH
;
588 m_gutterWidth
= wxPG_GUTTER_MIN
;
589 m_subgroup_extramargin
= 10;
593 m_width
= m_height
= 0;
595 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
598 m_chgInfo_changedProperty
= NULL
;
601 // -----------------------------------------------------------------------
604 // Initialize after parent etc. set
606 void wxPropertyGrid::Init2()
608 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
611 // Smaller controls on Mac
612 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
615 // Now create state, if one didn't exist already
616 // (wxPropertyGridManager might have created it for us).
619 m_pState
= CreateState();
620 m_pState
->m_pPropGrid
= this;
621 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
624 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
625 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
627 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
629 m_pState
->InitNonCatMode();
631 m_pState
->m_properties
= m_pState
->m_abcArray
;
634 GetClientSize(&m_width
,&m_height
);
636 #ifndef wxPG_ICON_WIDTH
637 // create two bitmap nodes for drawing
638 m_expandbmp
= new wxBitmap(expand_xpm
);
639 m_collbmp
= new wxBitmap(collapse_xpm
);
641 // calculate average font height for bitmap centering
643 m_iconWidth
= m_expandbmp
->GetWidth();
644 m_iconHeight
= m_expandbmp
->GetHeight();
647 m_curcursor
= wxCURSOR_ARROW
;
648 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
650 // adjust bitmap icon y position so they are centered
651 m_vspacing
= wxPG_DEFAULT_VSPACING
;
655 wxFont useFont
= wxScrolledWindow::GetFont();
656 wxScrolledWindow::SetOwnFont( useFont
);
659 // This should be otherwise called by SetOwnFont
660 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
662 // Add base brush item
663 m_arrBgBrushes
.Add((void*)new wxPGBrush());
665 // Add base colour items
666 m_arrFgCols
.Add((void*)new wxPGColour());
667 m_arrFgCols
.Add((void*)new wxPGColour());
671 // This helps with flicker
672 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
675 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
676 m_tlp
= ::wxGetTopLevelParent(this);
677 m_tlwHandler
= handler
;
678 m_tlp
->PushEventHandler(handler
);
680 // set virtual size to this window size
681 wxSize wndsize
= GetSize();
682 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
684 m_timeCreated
= ::wxGetLocalTimeMillis();
686 m_canvas
= new wxPGCanvas();
687 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
688 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
689 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
691 m_iFlags
|= wxPG_FL_INITIALIZED
;
693 m_ncWidth
= wndsize
.GetWidth();
695 // Need to call OnResize handler or size given in constructor/Create
697 wxSizeEvent
sizeEvent(wndsize
,0);
701 // -----------------------------------------------------------------------
703 wxPropertyGrid::~wxPropertyGrid()
707 DoSelectProperty(NULL
);
709 // This should do prevent things from going too badly wrong
710 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
712 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
713 m_canvas
->ReleaseMouse();
715 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
716 m_tlp
->RemoveEventHandler(handler
);
720 if ( IsEditorsValueModified() )
721 ::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).)"),
722 wxS("wxPropertyGrid Debug Warning") );
725 #if wxPG_DOUBLE_BUFFER
726 if ( m_doubleBuffer
)
727 delete m_doubleBuffer
;
730 //m_selected = (wxPGProperty*) NULL;
732 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
735 delete m_cursorSizeWE
;
737 #ifndef wxPG_ICON_WIDTH
742 // Delete cached text colours.
743 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
745 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
748 // Delete cached brushes.
749 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
751 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
754 // Delete common value records
755 for ( i
=0; i
<m_commonValues
.size(); i
++ )
757 delete GetCommonValue(i
);
761 // -----------------------------------------------------------------------
763 bool wxPropertyGrid::Destroy()
765 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
766 m_canvas
->ReleaseMouse();
768 return wxScrolledWindow::Destroy();
771 // -----------------------------------------------------------------------
773 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
775 return new wxPropertyGridPageState();
778 // -----------------------------------------------------------------------
779 // wxPropertyGrid overridden wxWindow methods
780 // -----------------------------------------------------------------------
782 void wxPropertyGrid::SetWindowStyleFlag( long style
)
784 long old_style
= m_windowStyle
;
786 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
788 wxASSERT( m_pState
);
790 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
793 EnableCategories( true );
795 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
797 // Disable categories
798 EnableCategories( false );
800 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
806 PrepareAfterItemsAdded();
808 m_pState
->m_itemsAdded
= 1;
810 #if wxPG_SUPPORT_TOOLTIPS
811 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
817 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
818 SetToolTip ( tooltip );
819 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
822 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
827 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
832 wxScrolledWindow::SetWindowStyleFlag ( style
);
834 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
836 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
838 CalculateFontAndBitmapStuff( m_vspacing
);
844 // -----------------------------------------------------------------------
846 void wxPropertyGrid::Freeze()
850 wxScrolledWindow::Freeze();
855 // -----------------------------------------------------------------------
857 void wxPropertyGrid::Thaw()
863 wxScrolledWindow::Thaw();
864 RecalculateVirtualSize();
865 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
869 // Force property re-selection
871 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
875 // -----------------------------------------------------------------------
877 void wxPropertyGrid::SetExtraStyle( long exStyle
)
879 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
881 #if defined(__WXMSW__)
884 // Don't use WS_EX_COMPOSITED just now.
887 if ( m_iFlags & wxPG_FL_IN_MANAGER )
888 hWnd = (HWND)GetParent()->GetHWND();
890 hWnd = (HWND)GetHWND();
892 ::SetWindowLong( hWnd, GWL_EXSTYLE,
893 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
896 //#elif defined(__WXGTK20__)
898 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
899 // truly was double-buffered.
900 if ( !this->IsDoubleBuffered() )
902 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
906 #if wxPG_DOUBLE_BUFFER
907 delete m_doubleBuffer
;
908 m_doubleBuffer
= NULL
;
913 wxScrolledWindow::SetExtraStyle( exStyle
);
915 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
916 m_pState
->InitNonCatMode();
918 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
919 m_windowStyle
|= wxPG_TOOLTIPS
;
922 wxPGGlobalVars
->m_extraStyle
= exStyle
;
925 // -----------------------------------------------------------------------
927 // returns the best acceptable minimal size
928 wxSize
wxPropertyGrid::DoGetBestSize() const
931 if ( m_lineHeight
> hei
)
933 wxSize sz
= wxSize( 60, hei
+40 );
939 // -----------------------------------------------------------------------
940 // wxPropertyGrid Font and Colour Methods
941 // -----------------------------------------------------------------------
943 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
947 m_captionFont
= wxScrolledWindow::GetFont();
949 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
950 m_subgroup_extramargin
= x
+ (x
/2);
953 #if wxPG_USE_RENDERER_NATIVE
954 m_iconWidth
= wxPG_ICON_WIDTH
;
955 #elif wxPG_ICON_WIDTH
957 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
958 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
959 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
963 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
964 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
965 m_gutterWidth
= wxPG_GUTTER_MIN
;
968 if ( vspacing
<= 1 ) vdiv
= 12;
969 else if ( vspacing
>= 3 ) vdiv
= 3;
971 m_spacingy
= m_fontHeight
/ vdiv
;
972 if ( m_spacingy
< wxPG_YSPACING_MIN
)
973 m_spacingy
= wxPG_YSPACING_MIN
;
976 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
977 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
979 m_captionFont
.SetWeight(wxBOLD
);
980 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
982 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
985 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
986 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
989 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
991 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
992 RecalculateVirtualSize();
994 InvalidateBestSize();
997 // -----------------------------------------------------------------------
999 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1005 // -----------------------------------------------------------------------
1007 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1008 int ga
= 1000, int ba
= 1000,
1009 bool forceDifferent
= false)
1016 // Recursion guard (allow 2 max)
1017 static int isinside
= 0;
1019 wxCHECK_MSG( isinside
< 3,
1021 wxT("wxPGAdjustColour should not be recursively called more than once") );
1026 int g
= src
.Green();
1029 if ( r2
>255 ) r2
= 255;
1030 else if ( r2
<0) r2
= 0;
1032 if ( g2
>255 ) g2
= 255;
1033 else if ( g2
<0) g2
= 0;
1035 if ( b2
>255 ) b2
= 255;
1036 else if ( b2
<0) b2
= 0;
1038 // Make sure they are somewhat different
1039 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1040 dst
= wxPGAdjustColour(src
,-(ra
*2));
1042 dst
= wxColour(r2
,g2
,b2
);
1044 // Recursion guard (allow 2 max)
1051 static int wxPGGetColAvg( const wxColour
& col
)
1053 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1057 void wxPropertyGrid::RegainColours()
1059 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1061 if ( !(m_coloursCustomized
& 0x0002) )
1063 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1065 // Make sure colour is dark enough
1067 int colDec
= wxPGGetColAvg(col
) - 230;
1069 int colDec
= wxPGGetColAvg(col
) - 200;
1072 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1077 if ( !(m_coloursCustomized
& 0x0001) )
1078 m_colMargin
= m_colCapBack
;
1080 if ( !(m_coloursCustomized
& 0x0004) )
1087 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1088 m_colCapFore
= capForeCol
;
1090 // Set the cached colour as well.
1091 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1094 if ( !(m_coloursCustomized
& 0x0008) )
1096 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1097 m_colPropBack
= bgCol
;
1099 // Set the cached brush as well.
1100 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1103 if ( !(m_coloursCustomized
& 0x0010) )
1105 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1106 m_colPropFore
= fgCol
;
1108 // Set the cached colour as well.
1109 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1112 if ( !(m_coloursCustomized
& 0x0020) )
1113 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1115 if ( !(m_coloursCustomized
& 0x0040) )
1116 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1118 if ( !(m_coloursCustomized
& 0x0080) )
1119 m_colLine
= m_colCapBack
;
1121 if ( !(m_coloursCustomized
& 0x0100) )
1122 m_colDisPropFore
= m_colCapFore
;
1124 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1127 // -----------------------------------------------------------------------
1129 void wxPropertyGrid::ResetColours()
1131 m_coloursCustomized
= 0;
1138 // -----------------------------------------------------------------------
1140 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1142 // Must disable active editor.
1145 bool selRes
= ClearSelection();
1146 wxPG_CHECK_MSG_DBG( selRes
,
1148 wxT("failed to deselect a property (editor probably had invalid value)") );
1151 // TODO: Following code is disabled with wxMac because
1152 // it is reported to fail. I (JMS) cannot debug it
1153 // personally right now.
1154 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1155 #if 1 // !defined(__WXMAC__)
1156 bool res
= wxScrolledWindow::SetFont( font
);
1159 CalculateFontAndBitmapStuff( m_vspacing
);
1162 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1170 // TODO: Remove after SetFont crash fixed.
1171 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1173 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."));
1179 // -----------------------------------------------------------------------
1181 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1184 m_coloursCustomized
|= 0x80;
1188 // -----------------------------------------------------------------------
1190 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1193 m_coloursCustomized
|= 0x01;
1197 // -----------------------------------------------------------------------
1199 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1201 m_colPropBack
= col
;
1202 m_coloursCustomized
|= 0x08;
1204 // Set the cached brush as well.
1205 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1210 // -----------------------------------------------------------------------
1212 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1214 m_colPropFore
= col
;
1215 m_coloursCustomized
|= 0x10;
1217 // Set the cached colour as well.
1218 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1223 // -----------------------------------------------------------------------
1225 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1227 m_colEmptySpace
= col
;
1232 // -----------------------------------------------------------------------
1234 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1236 m_colDisPropFore
= col
;
1237 m_coloursCustomized
|= 0x100;
1241 // -----------------------------------------------------------------------
1243 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1246 m_coloursCustomized
|= 0x20;
1250 // -----------------------------------------------------------------------
1252 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1255 m_coloursCustomized
|= 0x40;
1259 // -----------------------------------------------------------------------
1261 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1264 m_coloursCustomized
|= 0x02;
1268 // -----------------------------------------------------------------------
1270 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1273 m_coloursCustomized
|= 0x04;
1275 // Set the cached colour as well.
1276 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1281 // -----------------------------------------------------------------------
1283 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1285 unsigned char ind
= index
;
1287 p
->m_bgColIndex
= ind
;
1290 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1291 SetBackgroundColourIndex(p
->Item(i
),index
);
1294 // -----------------------------------------------------------------------
1296 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1298 wxPG_PROP_ARG_CALL_PROLOG()
1303 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1305 // As it is most likely that the previous colour is used, start comparison
1307 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1309 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1318 colInd
= m_arrBgBrushes
.size();
1319 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1320 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1324 SetBackgroundColourIndex(p
,colInd
);
1326 // If this was on a visible grid, then draw it.
1327 DrawItemAndChildren(p
);
1330 // -----------------------------------------------------------------------
1332 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1334 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1336 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1339 // -----------------------------------------------------------------------
1341 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1343 unsigned char ind
= index
;
1345 p
->m_fgColIndex
= ind
;
1347 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1350 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1351 SetTextColourIndex( p
->Item(i
), index
, flags
);
1355 // -----------------------------------------------------------------------
1357 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1362 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1364 // As it is most likely that the previous colour is used, start comparison
1366 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1368 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1377 colInd
= m_arrFgCols
.size();
1378 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1379 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1385 // -----------------------------------------------------------------------
1387 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1390 wxPG_PROP_ARG_CALL_PROLOG()
1392 if ( p
->IsCategory() )
1394 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1395 cat
->SetTextColIndex(CacheColour(colour
));
1401 flags
|= wxPG_RECURSE
;
1402 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1404 DrawItemAndChildren(p
);
1407 // -----------------------------------------------------------------------
1409 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1411 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1413 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1416 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1418 wxPG_PROP_ARG_CALL_PROLOG()
1420 SetBackgroundColourIndex( p
, 0 );
1421 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1423 if ( p
->IsCategory() )
1425 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1426 cat
->SetTextColIndex(1);
1430 // -----------------------------------------------------------------------
1431 // wxPropertyGrid property adding and removal
1432 // -----------------------------------------------------------------------
1434 void wxPropertyGrid::PrepareAfterItemsAdded()
1436 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1438 m_pState
->m_itemsAdded
= 0;
1440 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1443 RecalculateVirtualSize();
1446 // -----------------------------------------------------------------------
1447 // wxPropertyGrid property value setting and getting
1448 // -----------------------------------------------------------------------
1450 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1452 m_pState
->DoSetPropertyValueUnspecified(p
);
1453 DrawItemAndChildren(p
);
1455 wxPGProperty
* parent
= p
->GetParent();
1457 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1460 parent
= parent
->GetParent();
1464 // -----------------------------------------------------------------------
1465 // wxPropertyGrid property operations
1466 // -----------------------------------------------------------------------
1468 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1470 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1474 bool changed
= false;
1476 // Is it inside collapsed section?
1477 if ( !p
->IsVisible() )
1480 wxPGProperty
* parent
= p
->GetParent();
1481 wxPGProperty
* grandparent
= parent
->GetParent();
1483 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1484 Expand( grandparent
);
1492 GetViewStart(&vx
,&vy
);
1493 vy
*=wxPG_PIXELS_PER_UNIT
;
1499 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1500 m_iFlags
|= wxPG_FL_SCROLLED
;
1503 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1505 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1506 m_iFlags
|= wxPG_FL_SCROLLED
;
1516 // -----------------------------------------------------------------------
1517 // wxPropertyGrid helper methods called by properties
1518 // -----------------------------------------------------------------------
1520 // Control font changer helper.
1521 void wxPropertyGrid::SetCurControlBoldFont()
1523 wxASSERT( m_wndEditor
);
1524 m_wndEditor
->SetFont( m_captionFont
);
1527 // -----------------------------------------------------------------------
1529 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1532 #if wxPG_SMALL_SCREEN
1533 // On small-screen devices, always show dialogs with default position and size.
1534 return wxDefaultPosition
;
1536 int splitterX
= GetSplitterPosition();
1540 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1542 ImprovedClientToScreen( &x
, &y
);
1544 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1545 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1552 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1562 new_y
= y
+ m_lineHeight
;
1564 return wxPoint(new_x
,new_y
);
1568 // -----------------------------------------------------------------------
1570 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1572 if ( src_str
.length() == 0 )
1578 bool prev_is_slash
= false;
1580 wxString::const_iterator i
= src_str
.begin();
1584 for ( ; i
!= src_str
.end(); i
++ )
1588 if ( a
!= wxS('\\') )
1590 if ( !prev_is_slash
)
1596 if ( a
== wxS('n') )
1599 dst_str
<< wxS('\n');
1601 dst_str
<< wxS('\n');
1604 else if ( a
== wxS('t') )
1605 dst_str
<< wxS('\t');
1609 prev_is_slash
= false;
1613 if ( prev_is_slash
)
1615 dst_str
<< wxS('\\');
1616 prev_is_slash
= false;
1620 prev_is_slash
= true;
1627 // -----------------------------------------------------------------------
1629 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1631 if ( src_str
.length() == 0 )
1637 wxString::const_iterator i
= src_str
.begin();
1638 wxUniChar prev_a
= wxS('\0');
1642 for ( ; i
!= src_str
.end(); i
++ )
1646 if ( a
>= wxS(' ') )
1648 // This surely is not something that requires an escape sequence.
1653 // This might need...
1654 if ( a
== wxS('\r') )
1656 // DOS style line end.
1657 // Already taken care below
1659 else if ( a
== wxS('\n') )
1660 // UNIX style line end.
1661 dst_str
<< wxS("\\n");
1662 else if ( a
== wxS('\t') )
1664 dst_str
<< wxS('\t');
1667 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1677 // -----------------------------------------------------------------------
1679 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1683 return (wxPGProperty
*) NULL
;
1686 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1689 // -----------------------------------------------------------------------
1690 // wxPropertyGrid graphics related methods
1691 // -----------------------------------------------------------------------
1693 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1697 // Update everything inside the box
1698 wxRect r
= GetUpdateRegion().GetBox();
1700 dc
.SetPen(m_colEmptySpace
);
1701 dc
.SetBrush(m_colEmptySpace
);
1702 dc
.DrawRectangle(r
);
1705 // -----------------------------------------------------------------------
1707 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1708 wxPGProperty
* property
) const
1710 // Prepare rectangle to be used
1712 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1713 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1715 #if (wxPG_USE_RENDERER_NATIVE)
1717 #elif wxPG_ICON_WIDTH
1718 // Drawing expand/collapse button manually
1719 dc
.SetPen(m_colPropFore
);
1720 if ( property
->IsCategory() )
1721 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1723 dc
.SetBrush(m_colPropBack
);
1725 dc
.DrawRectangle( r
);
1726 int _y
= r
.y
+(m_iconWidth
/2);
1727 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1732 if ( property
->IsExpanded() )
1734 // wxRenderer functions are non-mutating in nature, so it
1735 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1736 // Hopefully this does not cause problems.
1737 #if (wxPG_USE_RENDERER_NATIVE)
1738 wxRendererNative::Get().DrawTreeItemButton(
1744 #elif wxPG_ICON_WIDTH
1753 #if (wxPG_USE_RENDERER_NATIVE)
1754 wxRendererNative::Get().DrawTreeItemButton(
1760 #elif wxPG_ICON_WIDTH
1761 int _x
= r
.x
+(m_iconWidth
/2);
1762 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1768 #if (wxPG_USE_RENDERER_NATIVE)
1770 #elif wxPG_ICON_WIDTH
1773 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1777 // -----------------------------------------------------------------------
1780 // This is the one called by OnPaint event handler and others.
1781 // topy and bottomy are already unscrolled (ie. physical)
1783 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1785 unsigned int bottomy
,
1786 const wxRect
* clipRect
)
1788 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1790 m_pState
->EnsureVirtualHeight();
1792 wxRect tempClipRect
;
1795 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1796 clipRect
= &tempClipRect
;
1799 // items added check
1800 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1802 int paintFinishY
= 0;
1804 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1807 bool isBuffered
= false;
1809 #if wxPG_DOUBLE_BUFFER
1810 wxMemoryDC
* bufferDC
= NULL
;
1812 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1814 if ( !m_doubleBuffer
)
1816 paintFinishY
= clipRect
->y
;
1821 bufferDC
= new wxMemoryDC();
1823 // If nothing was changed, then just copy from double-buffer
1824 bufferDC
->SelectObject( *m_doubleBuffer
);
1834 dc
.SetClippingRegion( *clipRect
);
1835 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1838 #if wxPG_DOUBLE_BUFFER
1841 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1842 bufferDC
, 0, 0, wxCOPY
);
1843 dc
.DestroyClippingRegion(); // Is this really necessary?
1849 // Clear area beyond bottomY?
1850 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1852 dc
.SetPen(m_colEmptySpace
);
1853 dc
.SetBrush(m_colEmptySpace
);
1854 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1858 // -----------------------------------------------------------------------
1860 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1861 const wxPGProperty
* firstItem
,
1862 const wxPGProperty
* lastItem
,
1863 const wxRect
* clipRect
,
1864 bool isBuffered
) const
1866 // TODO: This should somehow be eliminated.
1867 wxRect tempClipRect
;
1870 wxASSERT(firstItem
);
1872 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1873 clipRect
= &tempClipRect
;
1877 firstItem
= DoGetItemAtY(clipRect
->y
);
1881 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1883 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1886 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1889 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1890 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1892 int lh
= m_lineHeight
;
1895 int lastItemBottomY
;
1897 firstItemTopY
= clipRect
->y
;
1898 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1900 // Align y coordinates to item boundaries
1901 firstItemTopY
-= firstItemTopY
% lh
;
1902 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1903 lastItemBottomY
-= 1;
1905 // Entire range outside scrolled, visible area?
1906 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1909 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1913 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1914 firstItem->GetLabel().c_str(),
1915 lastItem->GetLabel().c_str(),
1916 (int)(lastItemBottomY - firstItemTopY),
1918 (unsigned long)clipRect );
1923 long windowStyle
= m_windowStyle
;
1929 // With wxPG_DOUBLE_BUFFER, do double buffering
1930 // - buffer's y = 0, so align cliprect and coordinates to that
1932 #if wxPG_DOUBLE_BUFFER
1938 xRelMod
= clipRect
->x
;
1939 yRelMod
= clipRect
->y
;
1942 // clipRect conversion
1950 firstItemTopY
-= yRelMod
;
1951 lastItemBottomY
-= yRelMod
;
1954 wxUnusedVar(isBuffered
);
1957 int x
= m_marginWidth
- xRelMod
;
1959 const wxFont
& normalfont
= m_font
;
1961 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1963 bool isEnabled
= IsEnabled();
1966 // Prepare some pens and brushes that are often changed to.
1969 wxBrush
marginBrush(m_colMargin
);
1970 wxPen
marginPen(m_colMargin
);
1971 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1972 wxPen
linepen(m_colLine
,1,wxSOLID
);
1974 // pen that has same colour as text
1975 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1978 // Clear margin with background colour
1980 dc
.SetBrush( marginBrush
);
1981 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1983 dc
.SetPen( *wxTRANSPARENT_PEN
);
1984 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1987 const wxPGProperty
* selected
= m_selected
;
1988 const wxPropertyGridPageState
* state
= m_pState
;
1990 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1991 bool wasSelectedPainted
= false;
1994 // TODO: Only render columns that are within clipping region.
1996 dc
.SetFont(normalfont
);
1998 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1999 int endScanBottomY
= lastItemBottomY
+ lh
;
2000 int y
= firstItemTopY
;
2003 // Pregenerate list of visible properties.
2004 wxArrayPGProperty visPropArray
;
2005 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2007 for ( ; !it
.AtEnd(); it
.Next() )
2009 const wxPGProperty
* p
= *it
;
2011 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2013 visPropArray
.push_back((wxPGProperty
*)p
);
2015 if ( y
> endScanBottomY
)
2022 visPropArray
.push_back(NULL
);
2024 wxPGProperty
* nextP
= visPropArray
[0];
2026 int gridWidth
= state
->m_width
;
2029 for ( unsigned int arrInd
=1;
2030 nextP
&& y
<= lastItemBottomY
;
2033 wxPGProperty
* p
= nextP
;
2034 nextP
= visPropArray
[arrInd
];
2036 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2037 int textMarginHere
= x
;
2038 int renderFlags
= wxPGCellRenderer::Control
;
2040 int greyDepth
= m_marginWidth
;
2041 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2042 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2044 int greyDepthX
= greyDepth
- xRelMod
;
2046 // Use basic depth if in non-categoric mode and parent is base array.
2047 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2049 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2052 // Paint margin area
2053 dc
.SetBrush(marginBrush
);
2054 dc
.SetPen(marginPen
);
2055 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2057 dc
.SetPen( linepen
);
2062 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2068 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2070 sx
+= state
->m_colWidths
[si
];
2071 dc
.DrawLine( sx
, y
, sx
, y2
);
2074 // Horizontal Line, below
2075 // (not if both this and next is category caption)
2076 if ( p
->IsCategory() &&
2077 nextP
&& nextP
->IsCategory() )
2078 dc
.SetPen(m_colCapBack
);
2080 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2082 if ( p
== selected
)
2084 renderFlags
|= wxPGCellRenderer::Selected
;
2085 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2086 wasSelectedPainted
= true;
2094 if ( p
->IsCategory() )
2096 if ( p
->m_fgColIndex
== 0 )
2097 rowFgCol
= m_colCapFore
;
2099 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2100 rowBgBrush
= wxBrush(m_colCapBack
);
2102 else if ( p
!= selected
)
2104 // Disabled may get different colour.
2105 if ( !p
->IsEnabled() )
2106 rowFgCol
= m_colDisPropFore
;
2108 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2110 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2114 // Selected gets different colour.
2115 if ( reallyFocused
)
2117 rowFgCol
= m_colSelFore
;
2118 rowBgBrush
= wxBrush(m_colSelBack
);
2120 else if ( isEnabled
)
2122 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2123 rowBgBrush
= marginBrush
;
2127 rowFgCol
= m_colDisPropFore
;
2128 rowBgBrush
= wxBrush(m_colSelBack
);
2132 bool fontChanged
= false;
2134 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2139 if ( p
->IsCategory() )
2141 // Captions are all cells merged as one
2142 dc
.SetFont(m_captionFont
);
2144 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2146 dc
.SetBrush(rowBgBrush
);
2147 dc
.SetPen(rowBgBrush
.GetColour());
2148 dc
.SetTextForeground(rowFgCol
);
2150 dc
.DrawRectangle(cellRect
);
2153 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2154 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2157 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2158 DrawExpanderButton( dc
, butRect
, p
);
2162 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2164 dc
.SetFont(m_captionFont
);
2170 int nextCellWidth
= state
->m_colWidths
[0];
2171 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2172 int textXAdd
= textMarginHere
- greyDepthX
;
2174 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2176 cellRect
.width
= nextCellWidth
- 1;
2178 bool ctrlCell
= false;
2181 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2183 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2184 dc
.SetBrush(editorBgCol
);
2185 dc
.SetPen(editorBgCol
);
2186 dc
.SetTextForeground(m_colPropFore
);
2188 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2193 dc
.SetBrush(rowBgBrush
);
2194 dc
.SetPen(rowBgBrush
.GetColour());
2195 dc
.SetTextForeground(rowFgCol
);
2198 dc
.DrawRectangle(cellRect
);
2201 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2202 DrawExpanderButton( dc
, butRect
, p
);
2204 dc
.SetClippingRegion(cellRect
);
2206 cellRect
.x
+= textXAdd
;
2207 cellRect
.width
-= textXAdd
;
2212 wxPGCellRenderer
* renderer
;
2213 int cmnVal
= p
->GetCommonValue();
2214 if ( cmnVal
== -1 || ci
!= 1 )
2216 renderer
= p
->GetCellRenderer(ci
);
2217 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2221 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2222 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2226 cellX
+= state
->m_colWidths
[ci
];
2227 if ( ci
< (state
->m_colWidths
.size()-1) )
2228 nextCellWidth
= state
->m_colWidths
[ci
+1];
2230 dc
.DestroyClippingRegion(); // Is this really necessary?
2236 dc
.SetFont(normalfont
);
2241 // Refresh editor controls (seems not needed on msw)
2242 // NOTE: This code is mandatory for GTK!
2243 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2244 if ( wasSelectedPainted
)
2247 m_wndEditor
->Refresh();
2249 m_wndEditor2
->Refresh();
2256 // -----------------------------------------------------------------------
2258 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2262 if ( m_width
< 10 || m_height
< 10 ||
2263 !m_pState
->m_properties
->GetChildCount() ||
2264 p1
== (wxPGProperty
*) NULL
)
2265 return wxRect(0,0,0,0);
2270 // Return rect which encloses the given property range
2272 int visTop
= p1
->GetY();
2275 visBottom
= p2
->GetY() + m_lineHeight
;
2277 visBottom
= m_height
+ visTop
;
2279 // If seleced property is inside the range, we'll extend the range to include
2281 wxPGProperty
* selected
= m_selected
;
2284 int selectedY
= selected
->GetY();
2285 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2287 wxWindow
* editor
= GetEditorControl();
2290 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2291 if ( visBottom2
> visBottom
)
2292 visBottom
= visBottom2
;
2297 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2300 // -----------------------------------------------------------------------
2302 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2307 if ( m_pState
->m_itemsAdded
)
2308 PrepareAfterItemsAdded();
2310 wxRect r
= GetPropertyRect(p1
, p2
);
2313 m_canvas
->RefreshRect(r
);
2317 // -----------------------------------------------------------------------
2319 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2321 if ( p
== m_selected
)
2322 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2324 DrawItemAndChildren(p
);
2327 // -----------------------------------------------------------------------
2329 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2334 // Draw item, children, and parent too, if it is not category
2335 wxPGProperty
* parent
= p
->GetParent();
2338 !parent
->IsCategory() &&
2339 parent
->GetParent() )
2342 parent
= parent
->GetParent();
2345 DrawItemAndChildren(p
);
2348 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2350 wxCHECK_RET( p
, wxT("invalid property id") );
2352 // Do not draw if in non-visible page
2353 if ( p
->GetParentState() != m_pState
)
2356 // do not draw a single item if multiple pending
2357 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2360 wxWindow
* wndPrimary
= GetEditorControl();
2362 // Update child control.
2363 if ( m_selected
&& m_selected
->GetParent() == p
)
2364 m_selected
->UpdateControl(wndPrimary
);
2366 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2368 DrawItems(p
, lastDrawn
);
2371 // -----------------------------------------------------------------------
2373 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2374 const wxRect
*rect
)
2376 PrepareAfterItemsAdded();
2378 wxWindow::Refresh(false);
2380 // TODO: Coordinate translation
2381 m_canvas
->Refresh(false, rect
);
2383 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2384 // I think this really helps only GTK+1.2
2385 if ( m_wndEditor
) m_wndEditor
->Refresh();
2386 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2390 // -----------------------------------------------------------------------
2391 // wxPropertyGrid global operations
2392 // -----------------------------------------------------------------------
2394 void wxPropertyGrid::Clear()
2398 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2399 wxPG_CHECK_RET_DBG( selRes
,
2400 wxT("failed to deselect a property (editor probably had invalid value)") );
2403 m_pState
->DoClear();
2409 RecalculateVirtualSize();
2411 // Need to clear some area at the end
2413 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2416 // -----------------------------------------------------------------------
2418 bool wxPropertyGrid::EnableCategories( bool enable
)
2420 if ( !ClearSelection() )
2426 // Enable categories
2429 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2434 // Disable categories
2436 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2439 if ( !m_pState
->EnableCategories(enable
) )
2444 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2446 m_pState
->m_itemsAdded
= 1; // force
2447 PrepareAfterItemsAdded();
2451 m_pState
->m_itemsAdded
= 1;
2453 // No need for RecalculateVirtualSize() here - it is already called in
2454 // wxPropertyGridPageState method above.
2461 // -----------------------------------------------------------------------
2463 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2465 wxASSERT( pNewState
);
2466 wxASSERT( pNewState
->GetGrid() );
2468 if ( pNewState
== m_pState
)
2471 wxPGProperty
* oldSelection
= m_selected
;
2476 bool selRes
= ClearSelection();
2477 wxPG_CHECK_RET_DBG( selRes
,
2478 wxT("failed to deselect a property (editor probably had invalid value)") );
2481 m_pState
->m_selected
= oldSelection
;
2483 bool orig_mode
= m_pState
->IsInNonCatMode();
2484 bool new_state_mode
= pNewState
->IsInNonCatMode();
2486 m_pState
= pNewState
;
2489 int pgWidth
= GetClientSize().x
;
2490 if ( HasVirtualWidth() )
2492 int minWidth
= pgWidth
;
2493 if ( pNewState
->m_width
< minWidth
)
2495 pNewState
->m_width
= minWidth
;
2496 pNewState
->CheckColumnWidths();
2502 // Just in case, fully re-center splitter
2503 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2504 pNewState
->m_fSplitterX
= -1.0;
2506 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2509 m_propHover
= (wxPGProperty
*) NULL
;
2511 // If necessary, convert state to correct mode.
2512 if ( orig_mode
!= new_state_mode
)
2514 // This should refresh as well.
2515 EnableCategories( orig_mode
?false:true );
2517 else if ( !m_frozen
)
2519 // Refresh, if not frozen.
2520 if ( m_pState
->m_itemsAdded
)
2521 PrepareAfterItemsAdded();
2524 if ( m_pState
->m_selected
)
2525 DoSelectProperty( m_pState
->m_selected
);
2527 RecalculateVirtualSize(0);
2531 m_pState
->m_itemsAdded
= 1;
2534 // -----------------------------------------------------------------------
2536 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2538 wxPG_PROP_ARG_CALL_PROLOG()
2540 m_pState
->SortChildren( p
);
2543 // -----------------------------------------------------------------------
2545 void wxPropertyGrid::Sort()
2547 bool selRes
= ClearSelection(); // This must be before state clear
2548 wxPG_CHECK_RET_DBG( selRes
,
2549 wxT("failed to deselect a property (editor probably had invalid value)") );
2554 // -----------------------------------------------------------------------
2556 // Call to SetSplitterPosition will always disable splitter auto-centering
2557 // if parent window is shown.
2558 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2560 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2563 wxPropertyGridPageState
* state
= m_pState
;
2565 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2570 CorrectEditorWidgetSizeX();
2576 // -----------------------------------------------------------------------
2578 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2580 SetSplitterPosition( m_width
/2, true );
2581 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2582 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2585 // -----------------------------------------------------------------------
2586 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2587 // -----------------------------------------------------------------------
2589 // Returns nearest paint visible property (such that will be painted unless
2590 // window is scrolled or resized). If given property is paint visible, then
2591 // it itself will be returned
2592 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2594 int vx
,vy1
;// Top left corner of client
2595 GetViewStart(&vx
,&vy1
);
2596 vy1
*= wxPG_PIXELS_PER_UNIT
;
2598 int vy2
= vy1
+ m_height
;
2599 int propY
= p
->GetY2(m_lineHeight
);
2601 if ( (propY
+ m_lineHeight
) < vy1
)
2604 return DoGetItemAtY( vy1
);
2606 else if ( propY
> vy2
)
2609 return DoGetItemAtY( vy2
);
2612 // Itself paint visible
2617 // -----------------------------------------------------------------------
2618 // Methods related to change in value, value modification and sending events
2619 // -----------------------------------------------------------------------
2621 // commits any changes in editor of selected property
2622 // return true if validation did not fail
2623 // flags are same as with DoSelectProperty
2624 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2626 // Committing already?
2627 if ( m_inCommitChangesFromEditor
)
2630 // Don't do this if already processing editor event. It might
2631 // induce recursive dialogs and crap like that.
2632 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2634 if ( m_inDoPropertyChanged
)
2641 IsEditorsValueModified() &&
2642 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2645 m_inCommitChangesFromEditor
= 1;
2647 wxVariant
variant(m_selected
->GetValueRef());
2648 bool valueIsPending
= false;
2650 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2651 // due to another window getting focus
2652 wxWindow
* oldFocus
= m_curFocused
;
2654 bool validationFailure
= false;
2655 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2657 m_chgInfo_changedProperty
= NULL
;
2659 // If truly modified, schedule value as pending.
2660 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2662 if ( DoEditorValidate() &&
2663 PerformValidation(m_selected
, variant
) )
2665 valueIsPending
= true;
2669 validationFailure
= true;
2674 EditorsValueWasNotModified();
2679 m_inCommitChangesFromEditor
= 0;
2681 if ( validationFailure
&& !forceSuccess
)
2685 oldFocus
->SetFocus();
2686 m_curFocused
= oldFocus
;
2689 res
= OnValidationFailure(m_selected
, variant
);
2691 // Now prevent further validation failure messages
2694 EditorsValueWasNotModified();
2695 OnValidationFailureReset(m_selected
);
2698 else if ( valueIsPending
)
2700 DoPropertyChanged( m_selected
, flags
);
2701 EditorsValueWasNotModified();
2710 // -----------------------------------------------------------------------
2712 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2716 // Runs all validation functionality.
2717 // Returns true if value passes all tests.
2720 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2722 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2724 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2729 // Adapt list to child values, if necessary
2730 wxVariant listValue
= pendingValue
;
2731 wxVariant
* pPendingValue
= &pendingValue
;
2732 wxVariant
* pList
= NULL
;
2734 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2735 // string value, then we need treat as it was changed instead
2736 // (or, in addition, as is the case with composite string parent).
2737 // This includes creating list variant for child values.
2739 wxPGProperty
* pwc
= p
->GetParent();
2740 wxPGProperty
* changedProperty
= p
;
2741 wxPGProperty
* baseChangedProperty
= changedProperty
;
2742 wxVariant bcpPendingList
;
2744 listValue
= pendingValue
;
2745 listValue
.SetName(p
->GetBaseName());
2748 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2750 wxVariantList tempList
;
2751 wxVariant
lv(tempList
, pwc
->GetBaseName());
2752 lv
.Append(listValue
);
2754 pPendingValue
= &listValue
;
2756 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2758 baseChangedProperty
= pwc
;
2759 bcpPendingList
= lv
;
2762 changedProperty
= pwc
;
2763 pwc
= pwc
->GetParent();
2767 wxPGProperty
* evtChangingProperty
= changedProperty
;
2769 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2771 value
= *pPendingValue
;
2775 // Convert list to child values
2776 pList
= pPendingValue
;
2777 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2780 wxVariant evtChangingValue
= value
;
2782 if ( flags
& SendEvtChanging
)
2784 // FIXME: After proper ValueToString()s added, remove
2785 // this. It is just a temporary fix, as evt_changing
2786 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2787 // (unless it is selected, and textctrl editor is open).
2788 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2790 evtChangingProperty
= baseChangedProperty
;
2791 if ( evtChangingProperty
!= p
)
2793 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2797 evtChangingValue
= pendingValue
;
2801 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2803 if ( changedProperty
== m_selected
)
2805 wxWindow
* editor
= GetEditorControl();
2806 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2807 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2811 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2816 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2817 m_chgInfo_changedProperty
= changedProperty
;
2818 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2819 m_chgInfo_pendingValue
= value
;
2822 m_chgInfo_valueList
= *pList
;
2824 m_chgInfo_valueList
.MakeNull();
2826 // If changedProperty is not property which value was edited,
2827 // then call wxPGProperty::ValidateValue() for that as well.
2828 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2830 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2834 if ( flags
& SendEvtChanging
)
2836 // SendEvent returns true if event was vetoed
2837 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2841 if ( flags
& IsStandaloneValidation
)
2843 // If called in 'generic' context, we need to reset
2844 // m_chgInfo_changedProperty and write back translated value.
2845 m_chgInfo_changedProperty
= NULL
;
2846 pendingValue
= value
;
2852 // -----------------------------------------------------------------------
2854 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2856 if ( !msg
.length() )
2860 if ( !wxPGGlobalVars
->m_offline
)
2862 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2865 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2868 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2871 pStatusBar
->SetStatusText(msg
);
2879 ::wxMessageBox(msg
, _T("Property Error"));
2882 // -----------------------------------------------------------------------
2884 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2886 int vfb
= m_validationInfo
.m_failureBehavior
;
2888 if ( vfb
& wxPG_VFB_BEEP
)
2891 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2892 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2894 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2895 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2897 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2899 wxColour vfbFg
= *wxWHITE
;
2900 wxColour vfbBg
= *wxRED
;
2901 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2902 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2904 DrawItemAndChildren(property
);
2906 if ( property
== m_selected
)
2908 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2910 wxWindow
* editor
= GetEditorControl();
2913 editor
->SetForegroundColour(vfbFg
);
2914 editor
->SetBackgroundColour(vfbBg
);
2920 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2922 wxString msg
= m_validationInfo
.m_failureMessage
;
2924 if ( !msg
.length() )
2925 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2927 DoShowPropertyError(property
, msg
);
2930 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2933 // -----------------------------------------------------------------------
2935 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2937 int vfb
= m_validationInfo
.m_failureBehavior
;
2939 if ( vfb
& wxPG_VFB_MARK_CELL
)
2941 property
->SetCell(0, NULL
);
2942 property
->SetCell(1, NULL
);
2944 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2946 if ( property
== m_selected
&& GetEditorControl() )
2948 // Calling this will recreate the control, thus resetting its colour
2949 RefreshProperty(property
);
2953 DrawItemAndChildren(property
);
2958 // -----------------------------------------------------------------------
2960 // flags are same as with DoSelectProperty
2961 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2963 if ( m_inDoPropertyChanged
)
2966 wxWindow
* editor
= GetEditorControl();
2968 m_pState
->m_anyModified
= 1;
2970 m_inDoPropertyChanged
= 1;
2972 // Maybe need to update control
2973 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2975 // These values were calculated in PerformValidation()
2976 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2977 wxVariant value
= m_chgInfo_pendingValue
;
2979 wxPGProperty
* topPaintedProperty
= changedProperty
;
2981 while ( !topPaintedProperty
->IsCategory() &&
2982 !topPaintedProperty
->IsRoot() )
2984 topPaintedProperty
= topPaintedProperty
->GetParent();
2987 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2989 // Set as Modified (not if dragging just began)
2990 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2992 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2993 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2996 SetCurControlBoldFont();
3002 // Propagate updates to parent(s)
3004 wxPGProperty
* prevPwc
= NULL
;
3006 while ( prevPwc
!= topPaintedProperty
)
3008 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3010 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3013 SetCurControlBoldFont();
3017 pwc
= pwc
->GetParent();
3020 // Draw the actual property
3021 DrawItemAndChildren( topPaintedProperty
);
3024 // If value was set by wxPGProperty::OnEvent, then update the editor
3026 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3029 p
->GetEditorClass()->UpdateControl(p
, editor
);
3033 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3034 if ( m_wndEditor
) m_wndEditor
->Refresh();
3035 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3040 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3042 // If top parent has composite string value, then send to child parents,
3043 // starting from baseChangedProperty.
3044 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3046 pwc
= m_chgInfo_baseChangedProperty
;
3048 while ( pwc
!= changedProperty
)
3050 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3051 pwc
= pwc
->GetParent();
3055 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3057 m_inDoPropertyChanged
= 0;
3062 // -----------------------------------------------------------------------
3064 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3066 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3068 m_chgInfo_changedProperty
= NULL
;
3070 if ( PerformValidation(p
, newValue
) )
3072 DoPropertyChanged(p
);
3077 OnValidationFailure(p
, newValue
);
3083 // -----------------------------------------------------------------------
3085 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3087 wxPGProperty
* prop
= GetSelectedProperty();
3090 return wxNullVariant
;
3092 wxTextCtrl
* tc
= GetEditorTextCtrl();
3093 wxVariant value
= prop
->GetValue();
3095 if ( !tc
|| !IsEditorsValueModified() )
3098 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3101 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3102 return prop
->GetValue();
3107 // -----------------------------------------------------------------------
3109 // Runs wxValidator for the selected property
3110 bool wxPropertyGrid::DoEditorValidate()
3115 // -----------------------------------------------------------------------
3117 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3119 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3120 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3122 wxWindow
* parent
= wnd
->GetParent();
3125 (parent
== m_canvas
||
3126 parent
->GetParent() == m_canvas
) )
3128 OnCustomEditorEvent(event
);
3132 return wxPanel::ProcessEvent(event
);
3135 // -----------------------------------------------------------------------
3137 void wxPropertyGrid::OnCustomEditorEvent( wxEvent
&event
)
3139 wxPGProperty
* selected
= m_selected
;
3141 // Somehow, event is handled after property has been deselected.
3142 // Possibly, but very rare.
3146 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3149 wxVariant
pendingValue(selected
->GetValueRef());
3150 wxWindow
* wnd
= GetEditorControl();
3152 bool wasUnspecified
= selected
->IsValueUnspecified();
3153 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3155 bool valueIsPending
= false;
3157 m_chgInfo_changedProperty
= NULL
;
3159 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3162 // Filter out excess wxTextCtrl modified events
3163 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3165 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3167 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3169 wxString newTcValue
= tc
->GetValue();
3170 if ( m_prevTcValue
== newTcValue
)
3173 m_prevTcValue
= newTcValue
;
3176 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3178 bool validationFailure
= false;
3179 bool buttonWasHandled
= false;
3182 // Try common button handling
3183 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3185 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3189 buttonWasHandled
= true;
3190 // Store as res2, as previously (and still currently alternatively)
3191 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3192 // in wxPGProperty::OnEvent().
3193 adapter
->ShowDialog( this, selected
);
3198 if ( !buttonWasHandled
)
3202 // First call editor class' event handler.
3203 const wxPGEditor
* editor
= selected
->GetEditorClass();
3205 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3207 // If changes, validate them
3208 if ( DoEditorValidate() )
3210 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3211 valueIsPending
= true;
3215 validationFailure
= true;
3220 // Then the property's custom handler (must be always called, unless
3221 // validation failed).
3222 if ( !validationFailure
)
3223 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3226 // SetValueInEvent(), as called in one of the functions referred above
3227 // overrides editor's value.
3228 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3230 valueIsPending
= true;
3231 pendingValue
= m_changeInEventValue
;
3232 selFlags
|= wxPG_SEL_DIALOGVAL
;
3235 if ( !validationFailure
&& valueIsPending
)
3236 if ( !PerformValidation(m_selected
, pendingValue
) )
3237 validationFailure
= true;
3239 if ( validationFailure
)
3241 OnValidationFailure(selected
, pendingValue
);
3243 else if ( valueIsPending
)
3245 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3247 DoPropertyChanged(selected
, selFlags
);
3248 EditorsValueWasNotModified();
3250 // Regardless of editor type, unfocus editor on
3251 // text-editing related enter press.
3252 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3259 // No value after all
3261 // Regardless of editor type, unfocus editor on
3262 // text-editing related enter press.
3263 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3268 // Let unhandled button click events go to the parent
3269 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3271 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3272 GetEventHandler()->AddPendingEvent(evt
);
3276 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3279 // -----------------------------------------------------------------------
3280 // wxPropertyGrid editor control helper methods
3281 // -----------------------------------------------------------------------
3283 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3285 int itemy
= p
->GetY2(m_lineHeight
);
3287 int cust_img_space
= 0;
3288 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3289 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3291 // TODO: If custom image detection changes from current, change this.
3292 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3294 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3295 int imwid
= p
->OnMeasureImage().x
;
3296 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3297 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3302 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3304 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3309 // -----------------------------------------------------------------------
3311 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3313 wxSize sz
= GetImageSize(p
, item
);
3314 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3315 wxPG_CUSTOM_IMAGE_SPACINGY
,
3320 // return size of custom paint image
3321 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3323 // If called with NULL property, then return default image
3324 // size for properties that use image.
3326 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3328 wxSize cis
= p
->OnMeasureImage(item
);
3330 int choiceCount
= p
->m_choices
.GetCount();
3331 int comVals
= p
->GetDisplayedCommonValueCount();
3332 if ( item
>= choiceCount
&& comVals
> 0 )
3334 unsigned int cvi
= item
-choiceCount
;
3335 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3337 else if ( item
>= 0 && choiceCount
== 0 )
3338 return wxSize(0, 0);
3343 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3348 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3355 // -----------------------------------------------------------------------
3357 // takes scrolling into account
3358 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3361 GetViewStart(&vx
,&vy
);
3362 vy
*=wxPG_PIXELS_PER_UNIT
;
3363 vx
*=wxPG_PIXELS_PER_UNIT
;
3366 ClientToScreen( px
, py
);
3369 // -----------------------------------------------------------------------
3371 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3374 GetViewStart(&pt2
.x
,&pt2
.y
);
3375 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3376 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3380 return m_pState
->HitTest(pt2
);
3383 // -----------------------------------------------------------------------
3385 // custom set cursor
3386 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3388 if ( type
== m_curcursor
&& !override
) return;
3390 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3392 if ( type
== wxCURSOR_SIZEWE
)
3393 cursor
= m_cursorSizeWE
;
3395 m_canvas
->SetCursor( *cursor
);
3400 // -----------------------------------------------------------------------
3401 // wxPropertyGrid property selection
3402 // -----------------------------------------------------------------------
3404 // Setups event handling for child control
3405 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3407 wxWindowID id
= argWnd
->GetId();
3409 if ( argWnd
== m_wndEditor
)
3411 argWnd
->Connect(id
, wxEVT_MOTION
,
3412 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3414 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3415 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3417 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3418 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3420 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3421 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3423 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3424 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3426 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3427 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3431 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3432 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3436 void wxPropertyGrid::FreeEditors()
3439 // Return focus back to canvas from children (this is required at least for
3440 // GTK+, which, unlike Windows, clears focus when control is destroyed
3441 // instead of moving it to closest parent).
3442 wxWindow
* focus
= wxWindow::FindFocus();
3445 wxWindow
* parent
= focus
->GetParent();
3448 if ( parent
== m_canvas
)
3453 parent
= parent
->GetParent();
3457 // Do not free editors immediately if processing events
3460 m_wndEditor2
->Hide();
3461 wxPendingDelete
.Append( m_wndEditor2
);
3462 m_wndEditor2
= (wxWindow
*) NULL
;
3467 m_wndEditor
->Hide();
3468 wxPendingDelete
.Append( m_wndEditor
);
3469 m_wndEditor
= (wxWindow
*) NULL
;
3473 // Call with NULL to de-select property
3474 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3476 wxPanel
* canvas
= GetPanel();
3480 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3481 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3483 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3486 if ( m_inDoSelectProperty
)
3489 m_inDoSelectProperty
= 1;
3491 wxPGProperty
* prev
= m_selected
;
3495 m_inDoSelectProperty
= 0;
3501 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3503 wxPrintf( "None selected\n" );
3506 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3508 wxPrintf( "P = NULL\n" );
3511 // If we are frozen, then just set the values.
3514 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3515 m_editorFocused
= 0;
3518 m_pState
->m_selected
= p
;
3520 // If frozen, always free controls. But don't worry, as Thaw will
3521 // recall SelectProperty to recreate them.
3524 // Prevent any further selection measures in this call
3525 p
= (wxPGProperty
*) NULL
;
3530 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3532 // Only set focus if not deselecting
3535 if ( flags
& wxPG_SEL_FOCUS
)
3539 m_wndEditor
->SetFocus();
3540 m_editorFocused
= 1;
3549 m_inDoSelectProperty
= 0;
3554 // First, deactivate previous
3558 OnValidationFailureReset(m_selected
);
3560 // Must double-check if this is an selected in case of forceswitch
3563 if ( !CommitChangesFromEditor(flags
) )
3565 // Validation has failed, so we can't exit the previous editor
3566 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3567 // _("Invalid Value"),wxOK|wxICON_ERROR);
3568 m_inDoSelectProperty
= 0;
3576 m_selected
= (wxPGProperty
*) NULL
;
3577 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3579 // We need to always fully refresh the grid here
3582 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3583 EditorsValueWasNotModified();
3586 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3589 // Then, activate the one given.
3592 int propY
= p
->GetY2(m_lineHeight
);
3594 int splitterX
= GetSplitterPosition();
3595 m_editorFocused
= 0;
3597 m_pState
->m_selected
= p
;
3598 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3600 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3602 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3604 // Do we need OnMeasureCalls?
3605 wxSize imsz
= p
->OnMeasureImage();
3608 // Only create editor for non-disabled non-caption
3609 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3611 // do this for non-caption items
3615 // Do we need to paint the custom image, if any?
3616 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3617 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3618 !p
->GetEditorClass()->CanContainCustomImage()
3620 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3622 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3623 wxPoint goodPos
= grect
.GetPosition();
3624 #if wxPG_CREATE_CONTROLS_HIDDEN
3625 int coord_adjust
= m_height
- goodPos
.y
;
3626 goodPos
.y
+= coord_adjust
;
3629 const wxPGEditor
* editor
= p
->GetEditorClass();
3630 wxCHECK_MSG(editor
, false,
3631 wxT("NULL editor class not allowed"));
3633 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3635 wxPGWindowList wndList
= editor
->CreateControls(this,
3640 m_wndEditor
= wndList
.m_primary
;
3641 m_wndEditor2
= wndList
.m_secondary
;
3642 wxWindow
* primaryCtrl
= GetEditorControl();
3645 // Essentially, primaryCtrl == m_wndEditor
3648 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3649 // value is drawn as normal, and m_wndEditor2 is assumed
3650 // to be a right-aligned button that triggers a separate editorCtrl
3655 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3656 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3658 // Set validator, if any
3659 #if wxUSE_VALIDATORS
3660 wxValidator
* validator
= p
->GetValidator();
3662 primaryCtrl
->SetValidator(*validator
);
3665 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3666 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3668 // If it has modified status, use bold font
3669 // (must be done before capturing m_ctrlXAdjust)
3670 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3671 SetCurControlBoldFont();
3674 // Fix TextCtrl indentation
3675 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3676 wxTextCtrl
* tc
= NULL
;
3677 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3678 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3680 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3682 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3685 // Store x relative to splitter (we'll need it).
3686 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3688 // Check if background clear is not necessary
3689 wxPoint pos
= m_wndEditor
->GetPosition();
3690 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3692 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3695 m_wndEditor
->SetSizeHints(3, 3);
3697 #if wxPG_CREATE_CONTROLS_HIDDEN
3698 m_wndEditor
->Show(false);
3699 m_wndEditor
->Freeze();
3701 goodPos
= m_wndEditor
->GetPosition();
3702 goodPos
.y
-= coord_adjust
;
3703 m_wndEditor
->Move( goodPos
);
3706 SetupChildEventHandling(primaryCtrl
);
3708 // Focus and select all (wxTextCtrl, wxComboBox etc)
3709 if ( flags
& wxPG_SEL_FOCUS
)
3711 primaryCtrl
->SetFocus();
3713 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3719 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3720 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3722 // Get proper id for wndSecondary
3723 m_wndSecId
= m_wndEditor2
->GetId();
3724 wxWindowList children
= m_wndEditor2
->GetChildren();
3725 wxWindowList::iterator node
= children
.begin();
3726 if ( node
!= children
.end() )
3727 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3729 m_wndEditor2
->SetSizeHints(3,3);
3731 #if wxPG_CREATE_CONTROLS_HIDDEN
3732 wxRect sec_rect
= m_wndEditor2
->GetRect();
3733 sec_rect
.y
-= coord_adjust
;
3735 // Fine tuning required to fix "oversized"
3736 // button disappearance bug.
3737 if ( sec_rect
.y
< 0 )
3739 sec_rect
.height
+= sec_rect
.y
;
3742 m_wndEditor2
->SetSize( sec_rect
);
3744 m_wndEditor2
->Show();
3746 SetupChildEventHandling(m_wndEditor2
);
3748 // If no primary editor, focus to button to allow
3749 // it to interprete ENTER etc.
3750 // NOTE: Due to problems focusing away from it, this
3751 // has been disabled.
3753 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3754 m_wndEditor2->SetFocus();
3758 if ( flags
& wxPG_SEL_FOCUS
)
3759 m_editorFocused
= 1;
3764 // Make sure focus is in grid canvas (important for wxGTK, at least)
3768 EditorsValueWasNotModified();
3770 // If it's inside collapsed section, expand parent, scroll, etc.
3771 // Also, if it was partially visible, scroll it into view.
3772 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3777 #if wxPG_CREATE_CONTROLS_HIDDEN
3778 m_wndEditor
->Thaw();
3780 m_wndEditor
->Show(true);
3787 // Make sure focus is in grid canvas
3791 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3797 // Show help text in status bar.
3798 // (if found and grid not embedded in manager with help box and
3799 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3802 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3804 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3805 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3807 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3809 statusbar
= frame
->GetStatusBar();
3814 const wxString
* pHelpString
= (const wxString
*) NULL
;
3818 pHelpString
= &p
->GetHelpString();
3819 if ( pHelpString
->length() )
3821 // Set help box text.
3822 statusbar
->SetStatusText( *pHelpString
);
3823 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3827 if ( (!pHelpString
|| !pHelpString
->length()) &&
3828 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3830 // Clear help box - but only if it was written
3831 // by us at previous time.
3832 statusbar
->SetStatusText( m_emptyString
);
3833 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3839 m_inDoSelectProperty
= 0;
3841 // call wx event handler (here so that it also occurs on deselection)
3842 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3847 // -----------------------------------------------------------------------
3849 bool wxPropertyGrid::UnfocusEditor()
3851 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3854 if ( !CommitChangesFromEditor(0) )
3858 DrawItem(m_selected
);
3863 // -----------------------------------------------------------------------
3865 // This method is not inline because it called dozens of times
3866 // (i.e. two-arg function calls create smaller code size).
3867 bool wxPropertyGrid::DoClearSelection()
3869 return DoSelectProperty((wxPGProperty
*)NULL
);
3872 // -----------------------------------------------------------------------
3873 // wxPropertyGrid expand/collapse state
3874 // -----------------------------------------------------------------------
3876 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3878 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3880 // If active editor was inside collapsed section, then disable it
3881 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3883 if ( !ClearSelection() )
3887 // Store dont-center-splitter flag 'cause we need to temporarily set it
3888 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3889 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3891 bool res
= m_pState
->DoCollapse(pwc
);
3896 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3898 RecalculateVirtualSize();
3900 // Redraw etc. only if collapsed was visible.
3901 if (pwc
->IsVisible() &&
3903 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3905 // When item is collapsed so that scrollbar would move,
3906 // graphics mess is about (unless we redraw everything).
3911 // Clear dont-center-splitter flag if it wasn't set
3912 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3917 // -----------------------------------------------------------------------
3919 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3921 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3923 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3925 // Store dont-center-splitter flag 'cause we need to temporarily set it
3926 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3927 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3929 bool res
= m_pState
->DoExpand(pwc
);
3934 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3936 RecalculateVirtualSize();
3938 // Redraw etc. only if expanded was visible.
3939 if ( pwc
->IsVisible() && !m_frozen
&&
3940 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3944 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3947 DrawItems(pwc
, NULL
);
3952 // Clear dont-center-splitter flag if it wasn't set
3953 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3958 // -----------------------------------------------------------------------
3960 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3963 return m_pState
->DoHideProperty(p
, hide
, flags
);
3966 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3969 if ( !ClearSelection() )
3973 m_pState
->DoHideProperty(p
, hide
, flags
);
3975 RecalculateVirtualSize();
3982 // -----------------------------------------------------------------------
3983 // wxPropertyGrid size related methods
3984 // -----------------------------------------------------------------------
3986 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3988 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3992 // If virtual height was changed, then recalculate editor control position(s)
3993 if ( m_pState
->m_vhCalcPending
)
3994 CorrectEditorWidgetPosY();
3996 m_pState
->EnsureVirtualHeight();
3999 int by1
= m_pState
->GetVirtualHeight();
4000 int by2
= m_pState
->GetActualVirtualHeight();
4003 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4004 wxASSERT_MSG( false,
4010 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4012 int x
= m_pState
->m_width
;
4013 int y
= m_pState
->m_virtualHeight
;
4016 GetClientSize(&width
,&height
);
4018 // Now adjust virtual size.
4019 SetVirtualSize(x
, y
);
4025 // Adjust scrollbars
4026 if ( HasVirtualWidth() )
4028 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4029 xPos
= GetScrollPos( wxHORIZONTAL
);
4032 if ( forceXPos
!= -1 )
4035 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4038 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4039 int yPos
= GetScrollPos( wxVERTICAL
);
4041 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4042 xAmount
, yAmount
, xPos
, yPos
, true );
4044 // Must re-get size now
4045 GetClientSize(&width
,&height
);
4047 if ( !HasVirtualWidth() )
4049 m_pState
->SetVirtualWidth(width
);
4056 m_canvas
->SetSize( x
, y
);
4058 m_pState
->CheckColumnWidths();
4061 CorrectEditorWidgetSizeX();
4063 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4066 // -----------------------------------------------------------------------
4068 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4070 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4074 GetClientSize(&width
,&height
);
4079 #if wxPG_DOUBLE_BUFFER
4080 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4082 int dblh
= (m_lineHeight
*2);
4083 if ( !m_doubleBuffer
)
4085 // Create double buffer bitmap to draw on, if none
4086 int w
= (width
>250)?width
:250;
4087 int h
= height
+ dblh
;
4089 m_doubleBuffer
= new wxBitmap( w
, h
);
4093 int w
= m_doubleBuffer
->GetWidth();
4094 int h
= m_doubleBuffer
->GetHeight();
4096 // Double buffer must be large enough
4097 if ( w
< width
|| h
< (height
+dblh
) )
4099 if ( w
< width
) w
= width
;
4100 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4101 delete m_doubleBuffer
;
4102 m_doubleBuffer
= new wxBitmap( w
, h
);
4109 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4110 m_ncWidth
= event
.GetSize().x
;
4114 if ( m_pState
->m_itemsAdded
)
4115 PrepareAfterItemsAdded();
4117 // Without this, virtual size (atleast under wxGTK) will be skewed
4118 RecalculateVirtualSize();
4124 // -----------------------------------------------------------------------
4126 void wxPropertyGrid::SetVirtualWidth( int width
)
4130 // Disable virtual width
4131 width
= GetClientSize().x
;
4132 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4136 // Enable virtual width
4137 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4139 m_pState
->SetVirtualWidth( width
);
4142 void wxPropertyGrid::SetFocusOnCanvas()
4144 m_canvas
->SetFocusIgnoringChildren();
4145 m_editorFocused
= 0;
4148 // -----------------------------------------------------------------------
4149 // wxPropertyGrid mouse event handling
4150 // -----------------------------------------------------------------------
4152 // selFlags uses same values DoSelectProperty's flags
4153 // Returns true if event was vetoed.
4154 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4156 // Send property grid event of specific type and with specific property
4157 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4158 evt
.SetPropertyGrid(this);
4159 evt
.SetEventObject(m_eventObject
);
4163 evt
.SetCanVeto(true);
4164 evt
.SetupValidationInfo();
4165 m_validationInfo
.m_pValue
= pValue
;
4167 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4169 evtHandler
->ProcessEvent(evt
);
4171 return evt
.WasVetoed();
4174 // -----------------------------------------------------------------------
4176 // Return false if should be skipped
4177 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4181 // Need to set focus?
4182 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4187 wxPropertyGridPageState
* state
= m_pState
;
4189 int splitterHitOffset
;
4190 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4192 wxPGProperty
* p
= DoGetItemAtY(y
);
4196 int depth
= (int)p
->GetDepth() - 1;
4198 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4200 if ( x
>= marginEnds
)
4204 if ( p
->IsCategory() )
4206 // This is category.
4207 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4209 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4211 // Expand, collapse, activate etc. if click on text or left of splitter.
4214 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4219 if ( !DoSelectProperty( p
) )
4222 // On double-click, expand/collapse.
4223 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4225 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4226 else DoExpand( p
, true );
4230 else if ( splitterHit
== -1 )
4233 unsigned int selFlag
= 0;
4234 if ( columnHit
== 1 )
4236 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4237 selFlag
= wxPG_SEL_FOCUS
;
4239 if ( !DoSelectProperty( p
, selFlag
) )
4242 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4244 if ( p
->GetChildCount() && !p
->IsCategory() )
4245 // On double-click, expand/collapse.
4246 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4248 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4249 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4250 else DoExpand( p
, true );
4257 // click on splitter
4258 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4260 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4262 // Double-clicking the splitter causes auto-centering
4263 CenterSplitter( true );
4265 else if ( m_dragStatus
== 0 )
4268 // Begin draggin the splitter
4272 // Changes must be committed here or the
4273 // value won't be drawn correctly
4274 if ( !CommitChangesFromEditor() )
4277 m_wndEditor
->Show ( false );
4280 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4282 m_canvas
->CaptureMouse();
4283 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4287 m_draggedSplitter
= splitterHit
;
4288 m_dragOffset
= splitterHitOffset
;
4290 wxClientDC
dc(m_canvas
);
4292 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4293 // Fixes button disappearance bug
4295 m_wndEditor2
->Show ( false );
4298 m_startingSplitterX
= x
- splitterHitOffset
;
4306 if ( p
->GetChildCount() )
4308 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4310 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4312 int y2
= y
% m_lineHeight
;
4313 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4315 // On click on expander button, expand/collapse
4316 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4317 DoCollapse( p
, true );
4319 DoExpand( p
, true );
4328 // -----------------------------------------------------------------------
4330 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4331 wxMouseEvent
& WXUNUSED(event
) )
4335 // Select property here as well
4336 wxPGProperty
* p
= m_propHover
;
4337 if ( p
!= m_selected
)
4338 DoSelectProperty( p
);
4340 // Send right click event.
4341 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4348 // -----------------------------------------------------------------------
4350 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4351 wxMouseEvent
& WXUNUSED(event
) )
4355 // Select property here as well
4356 wxPGProperty
* p
= m_propHover
;
4358 if ( p
!= m_selected
)
4359 DoSelectProperty( p
);
4361 // Send double-click event.
4362 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4369 // -----------------------------------------------------------------------
4371 #if wxPG_SUPPORT_TOOLTIPS
4373 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4375 if ( tipString
.length() )
4377 m_canvas
->SetToolTip(tipString
);
4381 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4382 m_canvas
->SetToolTip( m_emptyString
);
4384 m_canvas
->SetToolTip( NULL
);
4389 #endif // #if wxPG_SUPPORT_TOOLTIPS
4391 // -----------------------------------------------------------------------
4393 // Return false if should be skipped
4394 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4396 // Safety check (needed because mouse capturing may
4397 // otherwise freeze the control)
4398 if ( m_dragStatus
> 0 && !event
.Dragging() )
4400 HandleMouseUp(x
,y
,event
);
4403 wxPropertyGridPageState
* state
= m_pState
;
4405 int splitterHitOffset
;
4406 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4407 int splitterX
= x
- splitterHitOffset
;
4409 if ( m_dragStatus
> 0 )
4411 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4412 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4415 int newSplitterX
= x
- m_dragOffset
;
4416 int splitterX
= x
- splitterHitOffset
;
4418 // Splitter redraw required?
4419 if ( newSplitterX
!= splitterX
)
4422 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4423 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4424 state
->m_fSplitterX
= (float) newSplitterX
;
4427 CorrectEditorWidgetSizeX();
4441 int ih
= m_lineHeight
;
4444 #if wxPG_SUPPORT_TOOLTIPS
4445 wxPGProperty
* prevHover
= m_propHover
;
4446 unsigned char prevSide
= m_mouseSide
;
4448 int curPropHoverY
= y
- (y
% ih
);
4450 // On which item it hovers
4451 if ( ( !m_propHover
)
4453 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4456 // Mouse moves on another property
4458 m_propHover
= DoGetItemAtY(y
);
4459 m_propHoverY
= curPropHoverY
;
4462 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4465 #if wxPG_SUPPORT_TOOLTIPS
4466 // Store which side we are on
4468 if ( columnHit
== 1 )
4470 else if ( columnHit
== 0 )
4474 // If tooltips are enabled, show label or value as a tip
4475 // in case it doesn't otherwise show in full length.
4477 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4479 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4481 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4483 if ( m_propHover
&& !m_propHover
->IsCategory() )
4486 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4488 // Show help string as a tooltip
4489 wxString tipString
= m_propHover
->GetHelpString();
4491 SetToolTip(tipString
);
4495 // Show cropped value string as a tooltip
4499 if ( m_mouseSide
== 1 )
4501 tipString
= m_propHover
->m_label
;
4502 space
= splitterX
-m_marginWidth
-3;
4504 else if ( m_mouseSide
== 2 )
4506 tipString
= m_propHover
->GetDisplayedString();
4508 space
= m_width
- splitterX
;
4509 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4510 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4516 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4519 SetToolTip( tipString
);
4526 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4527 m_canvas
->SetToolTip( m_emptyString
);
4529 m_canvas
->SetToolTip( NULL
);
4540 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4541 m_canvas
->SetToolTip( m_emptyString
);
4543 m_canvas
->SetToolTip( NULL
);
4551 if ( splitterHit
== -1 ||
4553 HasFlag(wxPG_STATIC_SPLITTER
) )
4555 // hovering on something else
4556 if ( m_curcursor
!= wxCURSOR_ARROW
)
4557 CustomSetCursor( wxCURSOR_ARROW
);
4561 // Do not allow splitter cursor on caption items.
4562 // (also not if we were dragging and its started
4563 // outside the splitter region)
4566 !m_propHover
->IsCategory() &&
4570 // hovering on splitter
4572 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4573 // reliably detected.
4574 //if ( m_curcursor != wxCURSOR_SIZEWE )
4575 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4581 // hovering on something else
4582 if ( m_curcursor
!= wxCURSOR_ARROW
)
4583 CustomSetCursor( wxCURSOR_ARROW
);
4590 // -----------------------------------------------------------------------
4592 // Also handles Leaving event
4593 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4594 wxMouseEvent
&WXUNUSED(event
) )
4596 wxPropertyGridPageState
* state
= m_pState
;
4600 int splitterHitOffset
;
4601 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4603 // No event type check - basicly calling this method should
4604 // just stop dragging.
4605 // Left up after dragged?
4606 if ( m_dragStatus
>= 1 )
4609 // End Splitter Dragging
4611 // DO NOT ENABLE FOLLOWING LINE!
4612 // (it is only here as a reminder to not to do it)
4615 // Disable splitter auto-centering
4616 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4618 // This is necessary to return cursor
4619 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4621 m_canvas
->ReleaseMouse();
4622 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4625 // Set back the default cursor, if necessary
4626 if ( splitterHit
== -1 ||
4629 CustomSetCursor( wxCURSOR_ARROW
);
4634 // Control background needs to be cleared
4635 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4636 DrawItem( m_selected
);
4640 m_wndEditor
->Show ( true );
4643 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4644 // Fixes button disappearance bug
4646 m_wndEditor2
->Show ( true );
4649 // This clears the focus.
4650 m_editorFocused
= 0;
4656 // -----------------------------------------------------------------------
4658 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4660 int splitterX
= GetSplitterPosition();
4663 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4667 wxWindow
* wnd
= GetEditorControl();
4669 // Hide popup on clicks
4670 if ( event
.GetEventType() != wxEVT_MOTION
)
4671 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4673 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4679 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4681 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4682 ux
>= (r
.x
+r
.width
) ||
4684 event
.m_y
>= (r
.y
+r
.height
)
4694 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4699 // -----------------------------------------------------------------------
4701 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4704 if ( OnMouseCommon( event
, &x
, &y
) )
4706 HandleMouseClick(x
,y
,event
);
4711 // -----------------------------------------------------------------------
4713 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4716 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4717 HandleMouseRightClick(x
,y
,event
);
4721 // -----------------------------------------------------------------------
4723 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4725 // Always run standard mouse-down handler as well
4726 OnMouseClick(event
);
4729 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4730 HandleMouseDoubleClick(x
,y
,event
);
4734 // -----------------------------------------------------------------------
4736 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4739 if ( OnMouseCommon( event
, &x
, &y
) )
4741 HandleMouseMove(x
,y
,event
);
4746 // -----------------------------------------------------------------------
4748 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4750 // Called when mouse moves in the empty space below the properties.
4751 CustomSetCursor( wxCURSOR_ARROW
);
4754 // -----------------------------------------------------------------------
4756 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4759 if ( OnMouseCommon( event
, &x
, &y
) )
4761 HandleMouseUp(x
,y
,event
);
4766 // -----------------------------------------------------------------------
4768 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4770 // This may get called from child control as well, so event's
4771 // mouse position cannot be relied on.
4773 if ( event
.Entering() )
4775 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4777 // TODO: Fix this (detect parent and only do
4778 // cursor trick if it is a manager).
4779 wxASSERT( GetParent() );
4780 GetParent()->SetCursor(wxNullCursor
);
4782 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4785 GetParent()->SetCursor(wxNullCursor
);
4787 else if ( event
.Leaving() )
4789 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4790 m_canvas
->SetCursor( wxNullCursor
);
4792 // Get real cursor position
4793 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4795 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4798 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4800 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4804 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4812 // -----------------------------------------------------------------------
4814 // Common code used by various OnMouseXXXChild methods.
4815 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4817 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4818 wxASSERT( topCtrlWnd
);
4820 event
.GetPosition(&x
,&y
);
4822 int splitterX
= GetSplitterPosition();
4824 wxRect r
= topCtrlWnd
->GetRect();
4825 if ( !m_dragStatus
&&
4826 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4827 y
>= 0 && y
< r
.height \
4830 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4835 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4842 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4845 if ( OnMouseChildCommon(event
,&x
,&y
) )
4847 bool res
= HandleMouseClick(x
,y
,event
);
4848 if ( !res
) event
.Skip();
4852 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4855 wxASSERT( m_wndEditor
);
4856 // These coords may not be exact (about +-2),
4857 // but that should not matter (right click is about item, not position).
4858 wxPoint pt
= m_wndEditor
->GetPosition();
4859 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4860 wxASSERT( m_selected
);
4861 m_propHover
= m_selected
;
4862 bool res
= HandleMouseRightClick(x
,y
,event
);
4863 if ( !res
) event
.Skip();
4866 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4869 if ( OnMouseChildCommon(event
,&x
,&y
) )
4871 bool res
= HandleMouseMove(x
,y
,event
);
4872 if ( !res
) event
.Skip();
4876 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4879 if ( OnMouseChildCommon(event
,&x
,&y
) )
4881 bool res
= HandleMouseUp(x
,y
,event
);
4882 if ( !res
) event
.Skip();
4886 // -----------------------------------------------------------------------
4887 // wxPropertyGrid keyboard event handling
4888 // -----------------------------------------------------------------------
4890 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4892 // Translates wxKeyEvent to wxPG_ACTION_XXX
4894 int keycode
= event
.GetKeyCode();
4895 int modifiers
= event
.GetModifiers();
4897 wxASSERT( !(modifiers
&~(0xFFFF)) );
4899 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4901 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4903 if ( it
== m_actionTriggers
.end() )
4908 int second
= (it
->second
>>16) & 0xFFFF;
4912 return (it
->second
& 0xFFFF);
4915 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4917 wxASSERT( !(modifiers
&~(0xFFFF)) );
4919 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4921 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4923 if ( it
!= m_actionTriggers
.end() )
4925 // This key combination is already used
4927 // Can add secondary?
4928 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4929 wxT("You can only add up to two separate actions per key combination.") );
4931 action
= it
->second
| (action
<<16);
4934 m_actionTriggers
[hashMapKey
] = action
;
4937 void wxPropertyGrid::ClearActionTriggers( int action
)
4939 wxPGHashMapI2I::iterator it
;
4941 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4943 if ( it
->second
== action
)
4945 m_actionTriggers
.erase(it
);
4950 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4953 // Handles key event when editor control is not focused.
4956 wxASSERT( !m_frozen
);
4960 // Travelsal between items, collapsing/expanding, etc.
4961 int keycode
= event
.GetKeyCode();
4962 bool editorFocused
= IsEditorFocused();
4964 if ( keycode
== WXK_TAB
)
4966 if ( !event
.ShiftDown() )
4968 if ( !editorFocused
&& m_wndEditor
)
4969 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4971 Navigate(wxNavigationKeyEvent::IsForward
);
4975 if ( editorFocused
)
4978 Navigate(wxNavigationKeyEvent::IsBackward
);
4984 // Ignore Alt and Control when they are down alone
4985 if ( keycode
== WXK_ALT
||
4986 keycode
== WXK_CONTROL
)
4993 int action
= KeyEventToActions(event
, &secondAction
);
4995 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4998 // Esc cancels any changes
4999 if ( IsEditorsValueModified() )
5001 EditorsValueWasNotModified();
5003 // Update the control as well
5004 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5006 m_selected
->GetDisplayedString() );
5009 OnValidationFailureReset(m_selected
);
5015 // Except for TAB and ESC, handle child control events in child control
5022 bool wasHandled
= false;
5027 if ( ButtonTriggerKeyTest(action
, event
) )
5030 wxPGProperty
* p
= m_selected
;
5032 // Travel and expand/collapse
5035 if ( p
->GetChildCount() &&
5036 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5039 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5041 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5044 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5046 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5053 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5057 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5063 if ( selectDir
>= -1 )
5065 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5067 DoSelectProperty(p
);
5073 // If nothing was selected, select the first item now
5074 // (or navigate out of tab).
5075 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5077 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5078 if ( p
) DoSelectProperty(p
);
5087 // -----------------------------------------------------------------------
5089 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5091 HandleKeyEvent(event
, false);
5094 // -----------------------------------------------------------------------
5096 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5101 action
= KeyEventToActions(event
, &secondAction
);
5104 // Does the keycode trigger button?
5105 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5108 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5109 GetEventHandler()->AddPendingEvent(evt
);
5116 // -----------------------------------------------------------------------
5118 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5120 HandleKeyEvent(event
, true);
5123 // -----------------------------------------------------------------------
5124 // wxPropertyGrid miscellaneous event handling
5125 // -----------------------------------------------------------------------
5127 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5130 // Check if the focus is in this control or one of its children
5131 wxWindow
* newFocused
= wxWindow::FindFocus();
5133 if ( newFocused
!= m_curFocused
)
5134 HandleFocusChange( newFocused
);
5137 bool wxPropertyGrid::IsEditorFocused() const
5139 wxWindow
* focus
= wxWindow::FindFocus();
5141 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5142 focus
== GetEditorControl() )
5148 // Called by focus event handlers. newFocused is the window that becomes focused.
5149 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5151 unsigned int oldFlags
= m_iFlags
;
5153 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5155 wxWindow
* parent
= newFocused
;
5157 // This must be one of nextFocus' parents.
5160 // Use m_eventObject, which is either wxPropertyGrid or
5161 // wxPropertyGridManager, as appropriate.
5162 if ( parent
== m_eventObject
)
5164 m_iFlags
|= wxPG_FL_FOCUSED
;
5167 parent
= parent
->GetParent();
5170 m_curFocused
= newFocused
;
5172 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5173 (oldFlags
& wxPG_FL_FOCUSED
) )
5175 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5177 // Need to store changed value
5178 CommitChangesFromEditor();
5184 // Preliminary code for tab-order respecting
5185 // tab-traversal (but should be moved to
5188 wxWindow* prevFocus = event.GetWindow();
5189 wxWindow* useThis = this;
5190 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5191 useThis = GetParent();
5194 prevFocus->GetParent() == useThis->GetParent() )
5196 wxList& children = useThis->GetParent()->GetChildren();
5198 wxNode* node = children.Find(prevFocus);
5200 if ( node->GetNext() &&
5201 useThis == node->GetNext()->GetData() )
5202 DoSelectProperty(GetFirst());
5203 else if ( node->GetPrevious () &&
5204 useThis == node->GetPrevious()->GetData() )
5205 DoSelectProperty(GetLastProperty());
5212 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5213 DrawItem( m_selected
);
5217 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5219 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5220 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5221 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5222 //else if ( event.GetWindow() )
5224 HandleFocusChange(event
.GetWindow());
5229 // -----------------------------------------------------------------------
5231 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5233 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5236 // event.Skip() being commented out is aworkaround for bug reported
5237 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5241 // -----------------------------------------------------------------------
5243 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5245 m_iFlags
|= wxPG_FL_SCROLLED
;
5250 // -----------------------------------------------------------------------
5252 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5254 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5256 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5260 // -----------------------------------------------------------------------
5261 // Property editor related functions
5262 // -----------------------------------------------------------------------
5264 // noDefCheck = true prevents infinite recursion.
5265 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5268 wxASSERT( editorClass
);
5270 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5271 RegisterDefaultEditors();
5273 wxString name
= editorClass
->GetName();
5275 // Existing editor under this name?
5276 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5278 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5280 // If this name was already used, try class name.
5281 name
= editorClass
->GetClassInfo()->GetClassName();
5282 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5285 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5286 (wxPGEditor
*) vt_it
->second
,
5287 "Editor with given name was already registered" );
5289 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5294 // Use this in RegisterDefaultEditors.
5295 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5296 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5298 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5299 new wxPG##EDITOR##Editor, true ); \
5302 // Registers all default editor classes
5303 void wxPropertyGrid::RegisterDefaultEditors()
5305 wxPGRegisterDefaultEditorClass( TextCtrl
);
5306 wxPGRegisterDefaultEditorClass( Choice
);
5307 wxPGRegisterDefaultEditorClass( ComboBox
);
5308 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5309 #if wxPG_INCLUDE_CHECKBOX
5310 wxPGRegisterDefaultEditorClass( CheckBox
);
5312 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5314 // Register SpinCtrl etc. editors before use
5315 RegisterAdditionalEditors();
5318 // -----------------------------------------------------------------------
5319 // wxPGStringTokenizer
5320 // Needed to handle C-style string lists (e.g. "str1" "str2")
5321 // -----------------------------------------------------------------------
5323 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5324 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5328 wxPGStringTokenizer::~wxPGStringTokenizer()
5332 bool wxPGStringTokenizer::HasMoreTokens()
5334 const wxString
& str
= *m_str
;
5336 wxString::const_iterator i
= m_curPos
;
5338 wxUniChar delim
= m_delimeter
;
5340 wxUniChar prev_a
= wxT('\0');
5342 bool inToken
= false;
5344 while ( i
!= str
.end() )
5353 m_readyToken
.clear();
5358 if ( prev_a
!= wxT('\\') )
5362 if ( a
!= wxT('\\') )
5382 m_curPos
= str
.end();
5390 wxString
wxPGStringTokenizer::GetNextToken()
5392 return m_readyToken
;
5395 // -----------------------------------------------------------------------
5397 // -----------------------------------------------------------------------
5399 wxPGChoiceEntry::wxPGChoiceEntry()
5400 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5404 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5405 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5406 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5410 // -----------------------------------------------------------------------
5412 // -----------------------------------------------------------------------
5414 wxPGChoicesData::wxPGChoicesData()
5419 wxPGChoicesData::~wxPGChoicesData()
5424 void wxPGChoicesData::Clear()
5428 for ( i
=0; i
<m_items
.size(); i
++ )
5436 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5438 wxASSERT( m_items
.size() == 0 );
5442 for ( i
=0; i
<data
->GetCount(); i
++ )
5443 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5446 // -----------------------------------------------------------------------
5448 // -----------------------------------------------------------------------
5450 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5454 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5455 m_data
->Insert( -1, p
);
5459 // -----------------------------------------------------------------------
5461 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5465 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5466 p
->SetBitmap(bitmap
);
5467 m_data
->Insert( -1, p
);
5471 // -----------------------------------------------------------------------
5473 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5477 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5478 m_data
->Insert(index
, p
);
5482 // -----------------------------------------------------------------------
5484 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5488 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5489 m_data
->Insert( index
, p
);
5493 // -----------------------------------------------------------------------
5495 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5501 while ( index
< GetCount() )
5503 int cmpRes
= GetLabel(index
).Cmp(label
);
5509 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5510 m_data
->Insert( index
, p
);
5514 // -----------------------------------------------------------------------
5516 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5520 unsigned int itemcount
= 0;
5521 const wxChar
** p
= &labels
[0];
5522 while ( *p
) { p
++; itemcount
++; }
5525 for ( i
= 0; i
< itemcount
; i
++ )
5527 int value
= wxPG_INVALID_VALUE
;
5530 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5534 // -----------------------------------------------------------------------
5536 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5541 unsigned int itemcount
= arr
.size();
5543 for ( i
= 0; i
< itemcount
; i
++ )
5545 int value
= wxPG_INVALID_VALUE
;
5548 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5552 // -----------------------------------------------------------------------
5554 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5559 unsigned int itemcount
= arr
.size();
5561 for ( i
= 0; i
< itemcount
; i
++ )
5563 int value
= wxPG_INVALID_VALUE
;
5564 if ( &arrint
&& arrint
.size() )
5566 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5570 // -----------------------------------------------------------------------
5572 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5574 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5576 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5577 delete m_data
->Item(i
);
5578 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5579 m_data
->m_items
.begin()+nIndex
+count
);
5582 // -----------------------------------------------------------------------
5584 int wxPGChoices::Index( const wxString
& str
) const
5589 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5591 if ( m_data
->Item(i
)->GetText() == str
)
5598 // -----------------------------------------------------------------------
5600 int wxPGChoices::Index( int val
) const
5605 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5607 if ( m_data
->Item(i
)->GetValue() == val
)
5614 // -----------------------------------------------------------------------
5616 wxArrayString
wxPGChoices::GetLabels() const
5621 if ( this && IsOk() )
5622 for ( i
=0; i
<GetCount(); i
++ )
5623 arr
.push_back(GetLabel(i
));
5628 // -----------------------------------------------------------------------
5630 bool wxPGChoices::HasValues() const
5635 // -----------------------------------------------------------------------
5637 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5644 for ( i
=0; i
< strings
.size(); i
++ )
5646 int index
= Index(strings
[i
]);
5648 arr
.Add(GetValue(index
));
5650 arr
.Add(wxPG_INVALID_VALUE
);
5657 // -----------------------------------------------------------------------
5659 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5660 wxArrayString
* unmatched
) const
5667 for ( i
=0; i
< strings
.size(); i
++ )
5669 const wxString
& str
= strings
[i
];
5670 int index
= Index(str
);
5673 else if ( unmatched
)
5674 unmatched
->Add(str
);
5681 // -----------------------------------------------------------------------
5683 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5687 if ( data
!= wxPGChoicesEmptyData
)
5694 // -----------------------------------------------------------------------
5696 void wxPGChoices::Init()
5698 m_data
= wxPGChoicesEmptyData
;
5701 // -----------------------------------------------------------------------
5703 void wxPGChoices::Free()
5705 if ( m_data
!= wxPGChoicesEmptyData
)
5708 m_data
= wxPGChoicesEmptyData
;
5712 // -----------------------------------------------------------------------
5713 // wxPropertyGridEvent
5714 // -----------------------------------------------------------------------
5716 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5719 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5720 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5721 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5722 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5723 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5724 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5725 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5726 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5727 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5730 // -----------------------------------------------------------------------
5732 void wxPropertyGridEvent::Init()
5734 m_validationInfo
= NULL
;
5736 m_wasVetoed
= false;
5739 // -----------------------------------------------------------------------
5741 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5742 : wxCommandEvent(commandType
,id
)
5748 // -----------------------------------------------------------------------
5750 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5751 : wxCommandEvent(event
)
5753 m_eventType
= event
.GetEventType();
5754 m_eventObject
= event
.m_eventObject
;
5756 m_property
= event
.m_property
;
5757 m_validationInfo
= event
.m_validationInfo
;
5758 m_canVeto
= event
.m_canVeto
;
5759 m_wasVetoed
= event
.m_wasVetoed
;
5762 // -----------------------------------------------------------------------
5764 wxPropertyGridEvent::~wxPropertyGridEvent()
5768 // -----------------------------------------------------------------------
5770 wxEvent
* wxPropertyGridEvent::Clone() const
5772 return new wxPropertyGridEvent( *this );
5775 // -----------------------------------------------------------------------
5776 // wxPropertyGridPopulator
5777 // -----------------------------------------------------------------------
5779 wxPropertyGridPopulator::wxPropertyGridPopulator()
5783 wxPGGlobalVars
->m_offline
++;
5786 // -----------------------------------------------------------------------
5788 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5791 m_propHierarchy
.clear();
5794 // -----------------------------------------------------------------------
5796 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5802 // -----------------------------------------------------------------------
5804 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5807 // Free unused sets of choices
5808 wxPGHashMapS2P::iterator it
;
5810 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5812 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5819 m_pg
->GetPanel()->Refresh();
5821 wxPGGlobalVars
->m_offline
--;
5824 // -----------------------------------------------------------------------
5826 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5827 const wxString
& propLabel
,
5828 const wxString
& propName
,
5829 const wxString
* propValue
,
5830 wxPGChoices
* pChoices
)
5832 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5833 wxPGProperty
* parent
= GetCurParent();
5835 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5837 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5841 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5843 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5847 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5849 property
->SetLabel(propLabel
);
5850 property
->DoSetName(propName
);
5852 if ( pChoices
&& pChoices
->IsOk() )
5853 property
->SetChoices(*pChoices
);
5855 m_state
->DoInsert(parent
, -1, property
);
5858 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
5863 // -----------------------------------------------------------------------
5865 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5867 m_propHierarchy
.push_back(property
);
5868 DoScanForChildren();
5869 m_propHierarchy
.pop_back();
5872 // -----------------------------------------------------------------------
5874 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5875 const wxString
& idString
)
5877 wxPGChoices choices
;
5880 if ( choicesString
[0] == wxT('@') )
5882 wxString ids
= choicesString
.substr(1);
5883 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5884 if ( it
== m_dictIdChoices
.end() )
5885 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5887 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5892 if ( idString
.length() )
5894 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5895 if ( it
!= m_dictIdChoices
.end() )
5897 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5904 // Parse choices string
5905 wxString::const_iterator it
= choicesString
.begin();
5909 bool labelValid
= false;
5911 for ( ; it
!= choicesString
.end(); it
++ )
5917 if ( c
== wxT('"') )
5922 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5923 choices
.Add(label
, l
);
5926 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5931 else if ( c
== wxT('=') )
5938 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5945 if ( c
== wxT('"') )
5958 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5959 choices
.Add(label
, l
);
5962 if ( !choices
.IsOk() )
5964 choices
.EnsureData();
5968 if ( idString
.length() )
5969 m_dictIdChoices
[idString
] = choices
.GetData();
5976 // -----------------------------------------------------------------------
5978 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5980 if ( s
.Last() == wxT('%') )
5982 wxString s2
= s
.substr(0,s
.length()-1);
5984 if ( s2
.ToLong(&val
, 10) )
5986 *pval
= (val
*max
)/100;
5992 return s
.ToLong(pval
, 10);
5995 // -----------------------------------------------------------------------
5997 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5998 const wxString
& type
,
5999 const wxString
& value
)
6001 int l
= m_propHierarchy
.size();
6005 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6006 wxString valuel
= value
.Lower();
6009 if ( type
.length() == 0 )
6014 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6016 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6018 else if ( value
.ToLong(&v
, 0) )
6025 if ( type
== wxT("string") )
6029 else if ( type
== wxT("int") )
6032 value
.ToLong(&v
, 0);
6035 else if ( type
== wxT("bool") )
6037 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6044 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6049 p
->SetAttribute( name
, variant
);
6054 // -----------------------------------------------------------------------
6056 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6058 wxLogError(_("Error in resource: %s"),msg
.c_str());
6061 // -----------------------------------------------------------------------
6063 #endif // wxUSE_PROPGRID