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((wxCommandEvent
&)event
);
3132 return wxPanel::ProcessEvent(event
);
3135 // -----------------------------------------------------------------------
3137 // NB: It may really not be wxCommandEvent - must check if necessary
3139 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3141 wxPGProperty
* selected
= m_selected
;
3143 // Somehow, event is handled after property has been deselected.
3144 // Possibly, but very rare.
3148 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3151 wxVariant
pendingValue(selected
->GetValueRef());
3152 wxWindow
* wnd
= GetEditorControl();
3154 bool wasUnspecified
= selected
->IsValueUnspecified();
3155 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3157 bool valueIsPending
= false;
3159 m_chgInfo_changedProperty
= NULL
;
3161 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3164 // Filter out excess wxTextCtrl modified events
3165 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3167 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3169 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3171 wxString newTcValue
= tc
->GetValue();
3172 if ( m_prevTcValue
== newTcValue
)
3175 m_prevTcValue
= newTcValue
;
3178 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3180 bool validationFailure
= false;
3181 bool buttonWasHandled
= false;
3184 // Try common button handling
3185 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3187 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3191 buttonWasHandled
= true;
3192 // Store as res2, as previously (and still currently alternatively)
3193 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3194 // in wxPGProperty::OnEvent().
3195 adapter
->ShowDialog( this, selected
);
3200 if ( !buttonWasHandled
)
3204 // First call editor class' event handler.
3205 const wxPGEditor
* editor
= selected
->GetEditorClass();
3207 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3209 // If changes, validate them
3210 if ( DoEditorValidate() )
3212 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3213 valueIsPending
= true;
3217 validationFailure
= true;
3222 // Then the property's custom handler (must be always called, unless
3223 // validation failed).
3224 if ( !validationFailure
)
3225 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3228 // SetValueInEvent(), as called in one of the functions referred above
3229 // overrides editor's value.
3230 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3232 valueIsPending
= true;
3233 pendingValue
= m_changeInEventValue
;
3234 selFlags
|= wxPG_SEL_DIALOGVAL
;
3237 if ( !validationFailure
&& valueIsPending
)
3238 if ( !PerformValidation(m_selected
, pendingValue
) )
3239 validationFailure
= true;
3241 if ( validationFailure
)
3243 OnValidationFailure(selected
, pendingValue
);
3245 else if ( valueIsPending
)
3247 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3249 DoPropertyChanged(selected
, selFlags
);
3250 EditorsValueWasNotModified();
3252 // Regardless of editor type, unfocus editor on
3253 // text-editing related enter press.
3254 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3261 // No value after all
3263 // Regardless of editor type, unfocus editor on
3264 // text-editing related enter press.
3265 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3270 // Let unhandled button click events go to the parent
3271 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3273 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3274 GetEventHandler()->AddPendingEvent(evt
);
3278 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3281 // -----------------------------------------------------------------------
3282 // wxPropertyGrid editor control helper methods
3283 // -----------------------------------------------------------------------
3285 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3287 int itemy
= p
->GetY2(m_lineHeight
);
3289 int cust_img_space
= 0;
3290 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3291 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3293 // TODO: If custom image detection changes from current, change this.
3294 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3296 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3297 int imwid
= p
->OnMeasureImage().x
;
3298 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3299 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3304 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3306 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3311 // -----------------------------------------------------------------------
3313 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3315 wxSize sz
= GetImageSize(p
, item
);
3316 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3317 wxPG_CUSTOM_IMAGE_SPACINGY
,
3322 // return size of custom paint image
3323 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3325 // If called with NULL property, then return default image
3326 // size for properties that use image.
3328 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3330 wxSize cis
= p
->OnMeasureImage(item
);
3332 int choiceCount
= p
->m_choices
.GetCount();
3333 int comVals
= p
->GetDisplayedCommonValueCount();
3334 if ( item
>= choiceCount
&& comVals
> 0 )
3336 unsigned int cvi
= item
-choiceCount
;
3337 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3339 else if ( item
>= 0 && choiceCount
== 0 )
3340 return wxSize(0, 0);
3345 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3350 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3357 // -----------------------------------------------------------------------
3359 // takes scrolling into account
3360 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3363 GetViewStart(&vx
,&vy
);
3364 vy
*=wxPG_PIXELS_PER_UNIT
;
3365 vx
*=wxPG_PIXELS_PER_UNIT
;
3368 ClientToScreen( px
, py
);
3371 // -----------------------------------------------------------------------
3373 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3376 GetViewStart(&pt2
.x
,&pt2
.y
);
3377 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3378 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3382 return m_pState
->HitTest(pt2
);
3385 // -----------------------------------------------------------------------
3387 // custom set cursor
3388 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3390 if ( type
== m_curcursor
&& !override
) return;
3392 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3394 if ( type
== wxCURSOR_SIZEWE
)
3395 cursor
= m_cursorSizeWE
;
3397 m_canvas
->SetCursor( *cursor
);
3402 // -----------------------------------------------------------------------
3403 // wxPropertyGrid property selection
3404 // -----------------------------------------------------------------------
3406 // Setups event handling for child control
3407 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3409 wxWindowID id
= argWnd
->GetId();
3411 if ( argWnd
== m_wndEditor
)
3413 argWnd
->Connect(id
, wxEVT_MOTION
,
3414 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3416 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3417 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3419 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3420 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3422 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3423 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3425 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3426 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3428 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3429 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3431 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3432 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3437 void wxPropertyGrid::FreeEditors()
3440 // Return focus back to canvas from children (this is required at least for
3441 // GTK+, which, unlike Windows, clears focus when control is destroyed
3442 // instead of moving it to closest parent).
3443 wxWindow
* focus
= wxWindow::FindFocus();
3446 wxWindow
* parent
= focus
->GetParent();
3449 if ( parent
== m_canvas
)
3454 parent
= parent
->GetParent();
3458 // Do not free editors immediately if processing events
3461 m_wndEditor2
->Hide();
3462 wxPendingDelete
.Append( m_wndEditor2
);
3463 m_wndEditor2
= (wxWindow
*) NULL
;
3468 m_wndEditor
->Hide();
3469 wxPendingDelete
.Append( m_wndEditor
);
3470 m_wndEditor
= (wxWindow
*) NULL
;
3474 // Call with NULL to de-select property
3475 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3477 wxPanel
* canvas
= GetPanel();
3481 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3482 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3484 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3487 if ( m_inDoSelectProperty
)
3490 m_inDoSelectProperty
= 1;
3492 wxPGProperty
* prev
= m_selected
;
3496 m_inDoSelectProperty
= 0;
3502 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3504 wxPrintf( "None selected\n" );
3507 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3509 wxPrintf( "P = NULL\n" );
3512 // If we are frozen, then just set the values.
3515 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3516 m_editorFocused
= 0;
3519 m_pState
->m_selected
= p
;
3521 // If frozen, always free controls. But don't worry, as Thaw will
3522 // recall SelectProperty to recreate them.
3525 // Prevent any further selection measures in this call
3526 p
= (wxPGProperty
*) NULL
;
3531 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3533 // Only set focus if not deselecting
3536 if ( flags
& wxPG_SEL_FOCUS
)
3540 m_wndEditor
->SetFocus();
3541 m_editorFocused
= 1;
3550 m_inDoSelectProperty
= 0;
3555 // First, deactivate previous
3559 OnValidationFailureReset(m_selected
);
3561 // Must double-check if this is an selected in case of forceswitch
3564 if ( !CommitChangesFromEditor(flags
) )
3566 // Validation has failed, so we can't exit the previous editor
3567 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3568 // _("Invalid Value"),wxOK|wxICON_ERROR);
3569 m_inDoSelectProperty
= 0;
3577 m_selected
= (wxPGProperty
*) NULL
;
3578 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3580 // We need to always fully refresh the grid here
3583 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3584 EditorsValueWasNotModified();
3587 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3590 // Then, activate the one given.
3593 int propY
= p
->GetY2(m_lineHeight
);
3595 int splitterX
= GetSplitterPosition();
3596 m_editorFocused
= 0;
3598 m_pState
->m_selected
= p
;
3599 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3601 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3603 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3605 // Do we need OnMeasureCalls?
3606 wxSize imsz
= p
->OnMeasureImage();
3609 // Only create editor for non-disabled non-caption
3610 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3612 // do this for non-caption items
3616 // Do we need to paint the custom image, if any?
3617 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3618 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3619 !p
->GetEditorClass()->CanContainCustomImage()
3621 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3623 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3624 wxPoint goodPos
= grect
.GetPosition();
3625 #if wxPG_CREATE_CONTROLS_HIDDEN
3626 int coord_adjust
= m_height
- goodPos
.y
;
3627 goodPos
.y
+= coord_adjust
;
3630 const wxPGEditor
* editor
= p
->GetEditorClass();
3631 wxCHECK_MSG(editor
, false,
3632 wxT("NULL editor class not allowed"));
3634 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3636 wxPGWindowList wndList
= editor
->CreateControls(this,
3641 m_wndEditor
= wndList
.m_primary
;
3642 m_wndEditor2
= wndList
.m_secondary
;
3643 wxWindow
* primaryCtrl
= GetEditorControl();
3646 // Essentially, primaryCtrl == m_wndEditor
3649 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3650 // value is drawn as normal, and m_wndEditor2 is assumed
3651 // to be a right-aligned button that triggers a separate editorCtrl
3656 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3657 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3659 // Set validator, if any
3660 #if wxUSE_VALIDATORS
3661 wxValidator
* validator
= p
->GetValidator();
3663 primaryCtrl
->SetValidator(*validator
);
3666 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3667 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3669 // If it has modified status, use bold font
3670 // (must be done before capturing m_ctrlXAdjust)
3671 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3672 SetCurControlBoldFont();
3675 // Fix TextCtrl indentation
3676 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3677 wxTextCtrl
* tc
= NULL
;
3678 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3679 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3681 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3683 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3686 // Store x relative to splitter (we'll need it).
3687 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3689 // Check if background clear is not necessary
3690 wxPoint pos
= m_wndEditor
->GetPosition();
3691 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3693 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3696 m_wndEditor
->SetSizeHints(3, 3);
3698 #if wxPG_CREATE_CONTROLS_HIDDEN
3699 m_wndEditor
->Show(false);
3700 m_wndEditor
->Freeze();
3702 goodPos
= m_wndEditor
->GetPosition();
3703 goodPos
.y
-= coord_adjust
;
3704 m_wndEditor
->Move( goodPos
);
3707 SetupChildEventHandling(primaryCtrl
);
3709 // Focus and select all (wxTextCtrl, wxComboBox etc)
3710 if ( flags
& wxPG_SEL_FOCUS
)
3712 primaryCtrl
->SetFocus();
3714 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3720 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3721 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3723 // Get proper id for wndSecondary
3724 m_wndSecId
= m_wndEditor2
->GetId();
3725 wxWindowList children
= m_wndEditor2
->GetChildren();
3726 wxWindowList::iterator node
= children
.begin();
3727 if ( node
!= children
.end() )
3728 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3730 m_wndEditor2
->SetSizeHints(3,3);
3732 #if wxPG_CREATE_CONTROLS_HIDDEN
3733 wxRect sec_rect
= m_wndEditor2
->GetRect();
3734 sec_rect
.y
-= coord_adjust
;
3736 // Fine tuning required to fix "oversized"
3737 // button disappearance bug.
3738 if ( sec_rect
.y
< 0 )
3740 sec_rect
.height
+= sec_rect
.y
;
3743 m_wndEditor2
->SetSize( sec_rect
);
3745 m_wndEditor2
->Show();
3747 SetupChildEventHandling(m_wndEditor2
);
3749 // If no primary editor, focus to button to allow
3750 // it to interprete ENTER etc.
3751 // NOTE: Due to problems focusing away from it, this
3752 // has been disabled.
3754 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3755 m_wndEditor2->SetFocus();
3759 if ( flags
& wxPG_SEL_FOCUS
)
3760 m_editorFocused
= 1;
3765 // Make sure focus is in grid canvas (important for wxGTK, at least)
3769 EditorsValueWasNotModified();
3771 // If it's inside collapsed section, expand parent, scroll, etc.
3772 // Also, if it was partially visible, scroll it into view.
3773 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3778 #if wxPG_CREATE_CONTROLS_HIDDEN
3779 m_wndEditor
->Thaw();
3781 m_wndEditor
->Show(true);
3788 // Make sure focus is in grid canvas
3792 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3798 // Show help text in status bar.
3799 // (if found and grid not embedded in manager with help box and
3800 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3803 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3805 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3806 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3808 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3810 statusbar
= frame
->GetStatusBar();
3815 const wxString
* pHelpString
= (const wxString
*) NULL
;
3819 pHelpString
= &p
->GetHelpString();
3820 if ( pHelpString
->length() )
3822 // Set help box text.
3823 statusbar
->SetStatusText( *pHelpString
);
3824 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3828 if ( (!pHelpString
|| !pHelpString
->length()) &&
3829 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3831 // Clear help box - but only if it was written
3832 // by us at previous time.
3833 statusbar
->SetStatusText( m_emptyString
);
3834 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3840 m_inDoSelectProperty
= 0;
3842 // call wx event handler (here so that it also occurs on deselection)
3843 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3848 // -----------------------------------------------------------------------
3850 bool wxPropertyGrid::UnfocusEditor()
3852 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3855 if ( !CommitChangesFromEditor(0) )
3859 DrawItem(m_selected
);
3864 // -----------------------------------------------------------------------
3866 // This method is not inline because it called dozens of times
3867 // (i.e. two-arg function calls create smaller code size).
3868 bool wxPropertyGrid::DoClearSelection()
3870 return DoSelectProperty((wxPGProperty
*)NULL
);
3873 // -----------------------------------------------------------------------
3874 // wxPropertyGrid expand/collapse state
3875 // -----------------------------------------------------------------------
3877 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3879 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3881 // If active editor was inside collapsed section, then disable it
3882 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3884 if ( !ClearSelection() )
3888 // Store dont-center-splitter flag 'cause we need to temporarily set it
3889 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3890 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3892 bool res
= m_pState
->DoCollapse(pwc
);
3897 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3899 RecalculateVirtualSize();
3901 // Redraw etc. only if collapsed was visible.
3902 if (pwc
->IsVisible() &&
3904 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3906 // When item is collapsed so that scrollbar would move,
3907 // graphics mess is about (unless we redraw everything).
3912 // Clear dont-center-splitter flag if it wasn't set
3913 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3918 // -----------------------------------------------------------------------
3920 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3922 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3924 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3926 // Store dont-center-splitter flag 'cause we need to temporarily set it
3927 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3928 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3930 bool res
= m_pState
->DoExpand(pwc
);
3935 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3937 RecalculateVirtualSize();
3939 // Redraw etc. only if expanded was visible.
3940 if ( pwc
->IsVisible() && !m_frozen
&&
3941 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3945 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3948 DrawItems(pwc
, NULL
);
3953 // Clear dont-center-splitter flag if it wasn't set
3954 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3959 // -----------------------------------------------------------------------
3961 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3964 return m_pState
->DoHideProperty(p
, hide
, flags
);
3967 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3970 if ( !ClearSelection() )
3974 m_pState
->DoHideProperty(p
, hide
, flags
);
3976 RecalculateVirtualSize();
3983 // -----------------------------------------------------------------------
3984 // wxPropertyGrid size related methods
3985 // -----------------------------------------------------------------------
3987 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3989 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3993 // If virtual height was changed, then recalculate editor control position(s)
3994 if ( m_pState
->m_vhCalcPending
)
3995 CorrectEditorWidgetPosY();
3997 m_pState
->EnsureVirtualHeight();
4000 int by1
= m_pState
->GetVirtualHeight();
4001 int by2
= m_pState
->GetActualVirtualHeight();
4004 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4005 wxASSERT_MSG( false,
4011 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4013 int x
= m_pState
->m_width
;
4014 int y
= m_pState
->m_virtualHeight
;
4017 GetClientSize(&width
,&height
);
4019 // Now adjust virtual size.
4020 SetVirtualSize(x
, y
);
4026 // Adjust scrollbars
4027 if ( HasVirtualWidth() )
4029 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4030 xPos
= GetScrollPos( wxHORIZONTAL
);
4033 if ( forceXPos
!= -1 )
4036 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4039 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4040 int yPos
= GetScrollPos( wxVERTICAL
);
4042 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4043 xAmount
, yAmount
, xPos
, yPos
, true );
4045 // Must re-get size now
4046 GetClientSize(&width
,&height
);
4048 if ( !HasVirtualWidth() )
4050 m_pState
->SetVirtualWidth(width
);
4057 m_canvas
->SetSize( x
, y
);
4059 m_pState
->CheckColumnWidths();
4062 CorrectEditorWidgetSizeX();
4064 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4067 // -----------------------------------------------------------------------
4069 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4071 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4075 GetClientSize(&width
,&height
);
4080 #if wxPG_DOUBLE_BUFFER
4081 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4083 int dblh
= (m_lineHeight
*2);
4084 if ( !m_doubleBuffer
)
4086 // Create double buffer bitmap to draw on, if none
4087 int w
= (width
>250)?width
:250;
4088 int h
= height
+ dblh
;
4090 m_doubleBuffer
= new wxBitmap( w
, h
);
4094 int w
= m_doubleBuffer
->GetWidth();
4095 int h
= m_doubleBuffer
->GetHeight();
4097 // Double buffer must be large enough
4098 if ( w
< width
|| h
< (height
+dblh
) )
4100 if ( w
< width
) w
= width
;
4101 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4102 delete m_doubleBuffer
;
4103 m_doubleBuffer
= new wxBitmap( w
, h
);
4110 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4111 m_ncWidth
= event
.GetSize().x
;
4115 if ( m_pState
->m_itemsAdded
)
4116 PrepareAfterItemsAdded();
4118 // Without this, virtual size (atleast under wxGTK) will be skewed
4119 RecalculateVirtualSize();
4125 // -----------------------------------------------------------------------
4127 void wxPropertyGrid::SetVirtualWidth( int width
)
4131 // Disable virtual width
4132 width
= GetClientSize().x
;
4133 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4137 // Enable virtual width
4138 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4140 m_pState
->SetVirtualWidth( width
);
4143 void wxPropertyGrid::SetFocusOnCanvas()
4145 m_canvas
->SetFocusIgnoringChildren();
4146 m_editorFocused
= 0;
4149 // -----------------------------------------------------------------------
4150 // wxPropertyGrid mouse event handling
4151 // -----------------------------------------------------------------------
4153 // selFlags uses same values DoSelectProperty's flags
4154 // Returns true if event was vetoed.
4155 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4157 // Send property grid event of specific type and with specific property
4158 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4159 evt
.SetPropertyGrid(this);
4160 evt
.SetEventObject(m_eventObject
);
4164 evt
.SetCanVeto(true);
4165 evt
.SetupValidationInfo();
4166 m_validationInfo
.m_pValue
= pValue
;
4168 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4170 evtHandler
->ProcessEvent(evt
);
4172 return evt
.WasVetoed();
4175 // -----------------------------------------------------------------------
4177 // Return false if should be skipped
4178 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4182 // Need to set focus?
4183 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4188 wxPropertyGridPageState
* state
= m_pState
;
4190 int splitterHitOffset
;
4191 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4193 wxPGProperty
* p
= DoGetItemAtY(y
);
4197 int depth
= (int)p
->GetDepth() - 1;
4199 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4201 if ( x
>= marginEnds
)
4205 if ( p
->IsCategory() )
4207 // This is category.
4208 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4210 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4212 // Expand, collapse, activate etc. if click on text or left of splitter.
4215 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4220 if ( !DoSelectProperty( p
) )
4223 // On double-click, expand/collapse.
4224 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4226 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4227 else DoExpand( p
, true );
4231 else if ( splitterHit
== -1 )
4234 unsigned int selFlag
= 0;
4235 if ( columnHit
== 1 )
4237 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4238 selFlag
= wxPG_SEL_FOCUS
;
4240 if ( !DoSelectProperty( p
, selFlag
) )
4243 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4245 if ( p
->GetChildCount() && !p
->IsCategory() )
4246 // On double-click, expand/collapse.
4247 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4249 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4250 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4251 else DoExpand( p
, true );
4258 // click on splitter
4259 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4261 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4263 // Double-clicking the splitter causes auto-centering
4264 CenterSplitter( true );
4266 else if ( m_dragStatus
== 0 )
4269 // Begin draggin the splitter
4273 // Changes must be committed here or the
4274 // value won't be drawn correctly
4275 if ( !CommitChangesFromEditor() )
4278 m_wndEditor
->Show ( false );
4281 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4283 m_canvas
->CaptureMouse();
4284 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4288 m_draggedSplitter
= splitterHit
;
4289 m_dragOffset
= splitterHitOffset
;
4291 wxClientDC
dc(m_canvas
);
4293 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4294 // Fixes button disappearance bug
4296 m_wndEditor2
->Show ( false );
4299 m_startingSplitterX
= x
- splitterHitOffset
;
4307 if ( p
->GetChildCount() )
4309 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4311 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4313 int y2
= y
% m_lineHeight
;
4314 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4316 // On click on expander button, expand/collapse
4317 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4318 DoCollapse( p
, true );
4320 DoExpand( p
, true );
4329 // -----------------------------------------------------------------------
4331 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4332 wxMouseEvent
& WXUNUSED(event
) )
4336 // Select property here as well
4337 wxPGProperty
* p
= m_propHover
;
4338 if ( p
!= m_selected
)
4339 DoSelectProperty( p
);
4341 // Send right click event.
4342 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4349 // -----------------------------------------------------------------------
4351 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4352 wxMouseEvent
& WXUNUSED(event
) )
4356 // Select property here as well
4357 wxPGProperty
* p
= m_propHover
;
4359 if ( p
!= m_selected
)
4360 DoSelectProperty( p
);
4362 // Send double-click event.
4363 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4370 // -----------------------------------------------------------------------
4372 #if wxPG_SUPPORT_TOOLTIPS
4374 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4376 if ( tipString
.length() )
4378 m_canvas
->SetToolTip(tipString
);
4382 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4383 m_canvas
->SetToolTip( m_emptyString
);
4385 m_canvas
->SetToolTip( NULL
);
4390 #endif // #if wxPG_SUPPORT_TOOLTIPS
4392 // -----------------------------------------------------------------------
4394 // Return false if should be skipped
4395 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4397 // Safety check (needed because mouse capturing may
4398 // otherwise freeze the control)
4399 if ( m_dragStatus
> 0 && !event
.Dragging() )
4401 HandleMouseUp(x
,y
,event
);
4404 wxPropertyGridPageState
* state
= m_pState
;
4406 int splitterHitOffset
;
4407 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4408 int splitterX
= x
- splitterHitOffset
;
4410 if ( m_dragStatus
> 0 )
4412 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4413 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4416 int newSplitterX
= x
- m_dragOffset
;
4417 int splitterX
= x
- splitterHitOffset
;
4419 // Splitter redraw required?
4420 if ( newSplitterX
!= splitterX
)
4423 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4424 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4425 state
->m_fSplitterX
= (float) newSplitterX
;
4428 CorrectEditorWidgetSizeX();
4442 int ih
= m_lineHeight
;
4445 #if wxPG_SUPPORT_TOOLTIPS
4446 wxPGProperty
* prevHover
= m_propHover
;
4447 unsigned char prevSide
= m_mouseSide
;
4449 int curPropHoverY
= y
- (y
% ih
);
4451 // On which item it hovers
4452 if ( ( !m_propHover
)
4454 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4457 // Mouse moves on another property
4459 m_propHover
= DoGetItemAtY(y
);
4460 m_propHoverY
= curPropHoverY
;
4463 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4466 #if wxPG_SUPPORT_TOOLTIPS
4467 // Store which side we are on
4469 if ( columnHit
== 1 )
4471 else if ( columnHit
== 0 )
4475 // If tooltips are enabled, show label or value as a tip
4476 // in case it doesn't otherwise show in full length.
4478 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4480 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4482 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4484 if ( m_propHover
&& !m_propHover
->IsCategory() )
4487 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4489 // Show help string as a tooltip
4490 wxString tipString
= m_propHover
->GetHelpString();
4492 SetToolTip(tipString
);
4496 // Show cropped value string as a tooltip
4500 if ( m_mouseSide
== 1 )
4502 tipString
= m_propHover
->m_label
;
4503 space
= splitterX
-m_marginWidth
-3;
4505 else if ( m_mouseSide
== 2 )
4507 tipString
= m_propHover
->GetDisplayedString();
4509 space
= m_width
- splitterX
;
4510 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4511 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4517 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4520 SetToolTip( tipString
);
4527 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4528 m_canvas
->SetToolTip( m_emptyString
);
4530 m_canvas
->SetToolTip( NULL
);
4541 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4542 m_canvas
->SetToolTip( m_emptyString
);
4544 m_canvas
->SetToolTip( NULL
);
4552 if ( splitterHit
== -1 ||
4554 HasFlag(wxPG_STATIC_SPLITTER
) )
4556 // hovering on something else
4557 if ( m_curcursor
!= wxCURSOR_ARROW
)
4558 CustomSetCursor( wxCURSOR_ARROW
);
4562 // Do not allow splitter cursor on caption items.
4563 // (also not if we were dragging and its started
4564 // outside the splitter region)
4567 !m_propHover
->IsCategory() &&
4571 // hovering on splitter
4573 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4574 // reliably detected.
4575 //if ( m_curcursor != wxCURSOR_SIZEWE )
4576 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4582 // hovering on something else
4583 if ( m_curcursor
!= wxCURSOR_ARROW
)
4584 CustomSetCursor( wxCURSOR_ARROW
);
4591 // -----------------------------------------------------------------------
4593 // Also handles Leaving event
4594 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4595 wxMouseEvent
&WXUNUSED(event
) )
4597 wxPropertyGridPageState
* state
= m_pState
;
4601 int splitterHitOffset
;
4602 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4604 // No event type check - basicly calling this method should
4605 // just stop dragging.
4606 // Left up after dragged?
4607 if ( m_dragStatus
>= 1 )
4610 // End Splitter Dragging
4612 // DO NOT ENABLE FOLLOWING LINE!
4613 // (it is only here as a reminder to not to do it)
4616 // Disable splitter auto-centering
4617 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4619 // This is necessary to return cursor
4620 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4622 m_canvas
->ReleaseMouse();
4623 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4626 // Set back the default cursor, if necessary
4627 if ( splitterHit
== -1 ||
4630 CustomSetCursor( wxCURSOR_ARROW
);
4635 // Control background needs to be cleared
4636 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4637 DrawItem( m_selected
);
4641 m_wndEditor
->Show ( true );
4644 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4645 // Fixes button disappearance bug
4647 m_wndEditor2
->Show ( true );
4650 // This clears the focus.
4651 m_editorFocused
= 0;
4657 // -----------------------------------------------------------------------
4659 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4661 int splitterX
= GetSplitterPosition();
4664 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4668 wxWindow
* wnd
= GetEditorControl();
4670 // Hide popup on clicks
4671 if ( event
.GetEventType() != wxEVT_MOTION
)
4672 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4674 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4680 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4682 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4683 ux
>= (r
.x
+r
.width
) ||
4685 event
.m_y
>= (r
.y
+r
.height
)
4695 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4700 // -----------------------------------------------------------------------
4702 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4705 if ( OnMouseCommon( event
, &x
, &y
) )
4707 HandleMouseClick(x
,y
,event
);
4712 // -----------------------------------------------------------------------
4714 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4717 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4718 HandleMouseRightClick(x
,y
,event
);
4722 // -----------------------------------------------------------------------
4724 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4726 // Always run standard mouse-down handler as well
4727 OnMouseClick(event
);
4730 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4731 HandleMouseDoubleClick(x
,y
,event
);
4735 // -----------------------------------------------------------------------
4737 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4740 if ( OnMouseCommon( event
, &x
, &y
) )
4742 HandleMouseMove(x
,y
,event
);
4747 // -----------------------------------------------------------------------
4749 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4751 // Called when mouse moves in the empty space below the properties.
4752 CustomSetCursor( wxCURSOR_ARROW
);
4755 // -----------------------------------------------------------------------
4757 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4760 if ( OnMouseCommon( event
, &x
, &y
) )
4762 HandleMouseUp(x
,y
,event
);
4767 // -----------------------------------------------------------------------
4769 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4771 // This may get called from child control as well, so event's
4772 // mouse position cannot be relied on.
4774 if ( event
.Entering() )
4776 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4778 // TODO: Fix this (detect parent and only do
4779 // cursor trick if it is a manager).
4780 wxASSERT( GetParent() );
4781 GetParent()->SetCursor(wxNullCursor
);
4783 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4786 GetParent()->SetCursor(wxNullCursor
);
4788 else if ( event
.Leaving() )
4790 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4791 m_canvas
->SetCursor( wxNullCursor
);
4793 // Get real cursor position
4794 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4796 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4799 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4801 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4805 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4813 // -----------------------------------------------------------------------
4815 // Common code used by various OnMouseXXXChild methods.
4816 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4818 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4819 wxASSERT( topCtrlWnd
);
4821 event
.GetPosition(&x
,&y
);
4823 int splitterX
= GetSplitterPosition();
4825 wxRect r
= topCtrlWnd
->GetRect();
4826 if ( !m_dragStatus
&&
4827 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4828 y
>= 0 && y
< r
.height \
4831 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4836 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4843 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4846 if ( OnMouseChildCommon(event
,&x
,&y
) )
4848 bool res
= HandleMouseClick(x
,y
,event
);
4849 if ( !res
) event
.Skip();
4853 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4856 wxASSERT( m_wndEditor
);
4857 // These coords may not be exact (about +-2),
4858 // but that should not matter (right click is about item, not position).
4859 wxPoint pt
= m_wndEditor
->GetPosition();
4860 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4861 wxASSERT( m_selected
);
4862 m_propHover
= m_selected
;
4863 bool res
= HandleMouseRightClick(x
,y
,event
);
4864 if ( !res
) event
.Skip();
4867 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4870 if ( OnMouseChildCommon(event
,&x
,&y
) )
4872 bool res
= HandleMouseMove(x
,y
,event
);
4873 if ( !res
) event
.Skip();
4877 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4880 if ( OnMouseChildCommon(event
,&x
,&y
) )
4882 bool res
= HandleMouseUp(x
,y
,event
);
4883 if ( !res
) event
.Skip();
4887 // -----------------------------------------------------------------------
4888 // wxPropertyGrid keyboard event handling
4889 // -----------------------------------------------------------------------
4891 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4893 // Translates wxKeyEvent to wxPG_ACTION_XXX
4895 int keycode
= event
.GetKeyCode();
4896 int modifiers
= event
.GetModifiers();
4898 wxASSERT( !(modifiers
&~(0xFFFF)) );
4900 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4902 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4904 if ( it
== m_actionTriggers
.end() )
4909 int second
= (it
->second
>>16) & 0xFFFF;
4913 return (it
->second
& 0xFFFF);
4916 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4918 wxASSERT( !(modifiers
&~(0xFFFF)) );
4920 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4922 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4924 if ( it
!= m_actionTriggers
.end() )
4926 // This key combination is already used
4928 // Can add secondary?
4929 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4930 wxT("You can only add up to two separate actions per key combination.") );
4932 action
= it
->second
| (action
<<16);
4935 m_actionTriggers
[hashMapKey
] = action
;
4938 void wxPropertyGrid::ClearActionTriggers( int action
)
4940 wxPGHashMapI2I::iterator it
;
4942 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4944 if ( it
->second
== action
)
4946 m_actionTriggers
.erase(it
);
4951 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4954 // Handles key event when editor control is not focused.
4957 wxASSERT( !m_frozen
);
4961 // Travelsal between items, collapsing/expanding, etc.
4962 int keycode
= event
.GetKeyCode();
4963 bool editorFocused
= IsEditorFocused();
4965 if ( keycode
== WXK_TAB
)
4967 if ( !event
.ShiftDown() )
4969 if ( !editorFocused
&& m_wndEditor
)
4970 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4972 Navigate(wxNavigationKeyEvent::IsForward
);
4976 if ( editorFocused
)
4979 Navigate(wxNavigationKeyEvent::IsBackward
);
4985 // Ignore Alt and Control when they are down alone
4986 if ( keycode
== WXK_ALT
||
4987 keycode
== WXK_CONTROL
)
4994 int action
= KeyEventToActions(event
, &secondAction
);
4996 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4999 // Esc cancels any changes
5000 if ( IsEditorsValueModified() )
5002 EditorsValueWasNotModified();
5004 // Update the control as well
5005 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5007 m_selected
->GetDisplayedString() );
5010 OnValidationFailureReset(m_selected
);
5016 // Except for TAB and ESC, handle child control events in child control
5023 if ( ButtonTriggerKeyTest(action
, event
) )
5026 wxPGProperty
* p
= m_selected
;
5028 // Travel and expand/collapse
5031 if ( p
->GetChildCount() &&
5032 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5035 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5037 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5040 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5042 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5049 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5053 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5059 if ( selectDir
>= -1 )
5061 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5063 DoSelectProperty(p
);
5068 // If nothing was selected, select the first item now
5069 // (or navigate out of tab).
5070 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5072 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5073 if ( p
) DoSelectProperty(p
);
5078 // -----------------------------------------------------------------------
5080 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5082 HandleKeyEvent(event
, false);
5085 // -----------------------------------------------------------------------
5087 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5092 action
= KeyEventToActions(event
, &secondAction
);
5095 // Does the keycode trigger button?
5096 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5099 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5100 GetEventHandler()->AddPendingEvent(evt
);
5107 // -----------------------------------------------------------------------
5109 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5111 HandleKeyEvent(event
, true);
5114 // -----------------------------------------------------------------------
5115 // wxPropertyGrid miscellaneous event handling
5116 // -----------------------------------------------------------------------
5118 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5121 // Check if the focus is in this control or one of its children
5122 wxWindow
* newFocused
= wxWindow::FindFocus();
5124 if ( newFocused
!= m_curFocused
)
5125 HandleFocusChange( newFocused
);
5128 bool wxPropertyGrid::IsEditorFocused() const
5130 wxWindow
* focus
= wxWindow::FindFocus();
5132 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5133 focus
== GetEditorControl() )
5139 // Called by focus event handlers. newFocused is the window that becomes focused.
5140 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5142 unsigned int oldFlags
= m_iFlags
;
5144 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5146 wxWindow
* parent
= newFocused
;
5148 // This must be one of nextFocus' parents.
5151 // Use m_eventObject, which is either wxPropertyGrid or
5152 // wxPropertyGridManager, as appropriate.
5153 if ( parent
== m_eventObject
)
5155 m_iFlags
|= wxPG_FL_FOCUSED
;
5158 parent
= parent
->GetParent();
5161 m_curFocused
= newFocused
;
5163 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5164 (oldFlags
& wxPG_FL_FOCUSED
) )
5166 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5168 // Need to store changed value
5169 CommitChangesFromEditor();
5175 // Preliminary code for tab-order respecting
5176 // tab-traversal (but should be moved to
5179 wxWindow* prevFocus = event.GetWindow();
5180 wxWindow* useThis = this;
5181 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5182 useThis = GetParent();
5185 prevFocus->GetParent() == useThis->GetParent() )
5187 wxList& children = useThis->GetParent()->GetChildren();
5189 wxNode* node = children.Find(prevFocus);
5191 if ( node->GetNext() &&
5192 useThis == node->GetNext()->GetData() )
5193 DoSelectProperty(GetFirst());
5194 else if ( node->GetPrevious () &&
5195 useThis == node->GetPrevious()->GetData() )
5196 DoSelectProperty(GetLastProperty());
5203 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5204 DrawItem( m_selected
);
5208 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5210 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5211 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5212 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5213 //else if ( event.GetWindow() )
5215 HandleFocusChange(event
.GetWindow());
5220 // -----------------------------------------------------------------------
5222 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5224 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5227 // event.Skip() being commented out is aworkaround for bug reported
5228 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5232 // -----------------------------------------------------------------------
5234 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5236 m_iFlags
|= wxPG_FL_SCROLLED
;
5241 // -----------------------------------------------------------------------
5243 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5245 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5247 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5251 // -----------------------------------------------------------------------
5252 // Property editor related functions
5253 // -----------------------------------------------------------------------
5255 // noDefCheck = true prevents infinite recursion.
5256 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5259 wxASSERT( editorClass
);
5261 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5262 RegisterDefaultEditors();
5264 wxString name
= editorClass
->GetName();
5266 // Existing editor under this name?
5267 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5269 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5271 // If this name was already used, try class name.
5272 name
= editorClass
->GetClassInfo()->GetClassName();
5273 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5276 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5277 (wxPGEditor
*) vt_it
->second
,
5278 "Editor with given name was already registered" );
5280 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5285 // Use this in RegisterDefaultEditors.
5286 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5287 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5289 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5290 new wxPG##EDITOR##Editor, true ); \
5293 // Registers all default editor classes
5294 void wxPropertyGrid::RegisterDefaultEditors()
5296 wxPGRegisterDefaultEditorClass( TextCtrl
);
5297 wxPGRegisterDefaultEditorClass( Choice
);
5298 wxPGRegisterDefaultEditorClass( ComboBox
);
5299 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5300 #if wxPG_INCLUDE_CHECKBOX
5301 wxPGRegisterDefaultEditorClass( CheckBox
);
5303 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5305 // Register SpinCtrl etc. editors before use
5306 RegisterAdditionalEditors();
5309 // -----------------------------------------------------------------------
5310 // wxPGStringTokenizer
5311 // Needed to handle C-style string lists (e.g. "str1" "str2")
5312 // -----------------------------------------------------------------------
5314 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5315 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5319 wxPGStringTokenizer::~wxPGStringTokenizer()
5323 bool wxPGStringTokenizer::HasMoreTokens()
5325 const wxString
& str
= *m_str
;
5327 wxString::const_iterator i
= m_curPos
;
5329 wxUniChar delim
= m_delimeter
;
5331 wxUniChar prev_a
= wxT('\0');
5333 bool inToken
= false;
5335 while ( i
!= str
.end() )
5344 m_readyToken
.clear();
5349 if ( prev_a
!= wxT('\\') )
5353 if ( a
!= wxT('\\') )
5373 m_curPos
= str
.end();
5381 wxString
wxPGStringTokenizer::GetNextToken()
5383 return m_readyToken
;
5386 // -----------------------------------------------------------------------
5388 // -----------------------------------------------------------------------
5390 wxPGChoiceEntry::wxPGChoiceEntry()
5391 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5395 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5396 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5397 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5401 // -----------------------------------------------------------------------
5403 // -----------------------------------------------------------------------
5405 wxPGChoicesData::wxPGChoicesData()
5410 wxPGChoicesData::~wxPGChoicesData()
5415 void wxPGChoicesData::Clear()
5419 for ( i
=0; i
<m_items
.size(); i
++ )
5427 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5429 wxASSERT( m_items
.size() == 0 );
5433 for ( i
=0; i
<data
->GetCount(); i
++ )
5434 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5437 // -----------------------------------------------------------------------
5439 // -----------------------------------------------------------------------
5441 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5445 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5446 m_data
->Insert( -1, p
);
5450 // -----------------------------------------------------------------------
5452 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5456 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5457 p
->SetBitmap(bitmap
);
5458 m_data
->Insert( -1, p
);
5462 // -----------------------------------------------------------------------
5464 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5468 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5469 m_data
->Insert(index
, p
);
5473 // -----------------------------------------------------------------------
5475 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5479 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5480 m_data
->Insert( index
, p
);
5484 // -----------------------------------------------------------------------
5486 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5492 while ( index
< GetCount() )
5494 int cmpRes
= GetLabel(index
).Cmp(label
);
5500 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5501 m_data
->Insert( index
, p
);
5505 // -----------------------------------------------------------------------
5507 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5511 unsigned int itemcount
= 0;
5512 const wxChar
** p
= &labels
[0];
5513 while ( *p
) { p
++; itemcount
++; }
5516 for ( i
= 0; i
< itemcount
; i
++ )
5518 int value
= wxPG_INVALID_VALUE
;
5521 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5525 // -----------------------------------------------------------------------
5527 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5532 unsigned int itemcount
= arr
.size();
5534 for ( i
= 0; i
< itemcount
; i
++ )
5536 int value
= wxPG_INVALID_VALUE
;
5539 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5543 // -----------------------------------------------------------------------
5545 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5550 unsigned int itemcount
= arr
.size();
5552 for ( i
= 0; i
< itemcount
; i
++ )
5554 int value
= wxPG_INVALID_VALUE
;
5555 if ( &arrint
&& arrint
.size() )
5557 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5561 // -----------------------------------------------------------------------
5563 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5565 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5567 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5568 delete m_data
->Item(i
);
5569 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5570 m_data
->m_items
.begin()+nIndex
+count
);
5573 // -----------------------------------------------------------------------
5575 int wxPGChoices::Index( const wxString
& str
) const
5580 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5582 if ( m_data
->Item(i
)->GetText() == str
)
5589 // -----------------------------------------------------------------------
5591 int wxPGChoices::Index( int val
) const
5596 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5598 if ( m_data
->Item(i
)->GetValue() == val
)
5605 // -----------------------------------------------------------------------
5607 wxArrayString
wxPGChoices::GetLabels() const
5612 if ( this && IsOk() )
5613 for ( i
=0; i
<GetCount(); i
++ )
5614 arr
.push_back(GetLabel(i
));
5619 // -----------------------------------------------------------------------
5621 bool wxPGChoices::HasValues() const
5626 // -----------------------------------------------------------------------
5628 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5635 for ( i
=0; i
< strings
.size(); i
++ )
5637 int index
= Index(strings
[i
]);
5639 arr
.Add(GetValue(index
));
5641 arr
.Add(wxPG_INVALID_VALUE
);
5648 // -----------------------------------------------------------------------
5650 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5651 wxArrayString
* unmatched
) const
5658 for ( i
=0; i
< strings
.size(); i
++ )
5660 const wxString
& str
= strings
[i
];
5661 int index
= Index(str
);
5664 else if ( unmatched
)
5665 unmatched
->Add(str
);
5672 // -----------------------------------------------------------------------
5674 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5678 if ( data
!= wxPGChoicesEmptyData
)
5685 // -----------------------------------------------------------------------
5687 void wxPGChoices::Init()
5689 m_data
= wxPGChoicesEmptyData
;
5692 // -----------------------------------------------------------------------
5694 void wxPGChoices::Free()
5696 if ( m_data
!= wxPGChoicesEmptyData
)
5699 m_data
= wxPGChoicesEmptyData
;
5703 // -----------------------------------------------------------------------
5704 // wxPropertyGridEvent
5705 // -----------------------------------------------------------------------
5707 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5710 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5711 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5712 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5713 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5714 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5715 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5716 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5717 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5718 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5721 // -----------------------------------------------------------------------
5723 void wxPropertyGridEvent::Init()
5725 m_validationInfo
= NULL
;
5727 m_wasVetoed
= false;
5730 // -----------------------------------------------------------------------
5732 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5733 : wxCommandEvent(commandType
,id
)
5739 // -----------------------------------------------------------------------
5741 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5742 : wxCommandEvent(event
)
5744 m_eventType
= event
.GetEventType();
5745 m_eventObject
= event
.m_eventObject
;
5747 m_property
= event
.m_property
;
5748 m_validationInfo
= event
.m_validationInfo
;
5749 m_canVeto
= event
.m_canVeto
;
5750 m_wasVetoed
= event
.m_wasVetoed
;
5753 // -----------------------------------------------------------------------
5755 wxPropertyGridEvent::~wxPropertyGridEvent()
5759 // -----------------------------------------------------------------------
5761 wxEvent
* wxPropertyGridEvent::Clone() const
5763 return new wxPropertyGridEvent( *this );
5766 // -----------------------------------------------------------------------
5767 // wxPropertyGridPopulator
5768 // -----------------------------------------------------------------------
5770 wxPropertyGridPopulator::wxPropertyGridPopulator()
5774 wxPGGlobalVars
->m_offline
++;
5777 // -----------------------------------------------------------------------
5779 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5782 m_propHierarchy
.clear();
5785 // -----------------------------------------------------------------------
5787 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5793 // -----------------------------------------------------------------------
5795 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5798 // Free unused sets of choices
5799 wxPGHashMapS2P::iterator it
;
5801 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5803 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5810 m_pg
->GetPanel()->Refresh();
5812 wxPGGlobalVars
->m_offline
--;
5815 // -----------------------------------------------------------------------
5817 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5818 const wxString
& propLabel
,
5819 const wxString
& propName
,
5820 const wxString
* propValue
,
5821 wxPGChoices
* pChoices
)
5823 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5824 wxPGProperty
* parent
= GetCurParent();
5826 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5828 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5832 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5834 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5838 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5840 property
->SetLabel(propLabel
);
5841 property
->DoSetName(propName
);
5843 if ( pChoices
&& pChoices
->IsOk() )
5844 property
->SetChoices(*pChoices
);
5846 m_state
->DoInsert(parent
, -1, property
);
5849 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
5854 // -----------------------------------------------------------------------
5856 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5858 m_propHierarchy
.push_back(property
);
5859 DoScanForChildren();
5860 m_propHierarchy
.pop_back();
5863 // -----------------------------------------------------------------------
5865 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5866 const wxString
& idString
)
5868 wxPGChoices choices
;
5871 if ( choicesString
[0] == wxT('@') )
5873 wxString ids
= choicesString
.substr(1);
5874 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5875 if ( it
== m_dictIdChoices
.end() )
5876 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5878 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5883 if ( idString
.length() )
5885 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5886 if ( it
!= m_dictIdChoices
.end() )
5888 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5895 // Parse choices string
5896 wxString::const_iterator it
= choicesString
.begin();
5900 bool labelValid
= false;
5902 for ( ; it
!= choicesString
.end(); it
++ )
5908 if ( c
== wxT('"') )
5913 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5914 choices
.Add(label
, l
);
5917 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5922 else if ( c
== wxT('=') )
5929 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5936 if ( c
== wxT('"') )
5949 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5950 choices
.Add(label
, l
);
5953 if ( !choices
.IsOk() )
5955 choices
.EnsureData();
5959 if ( idString
.length() )
5960 m_dictIdChoices
[idString
] = choices
.GetData();
5967 // -----------------------------------------------------------------------
5969 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5971 if ( s
.Last() == wxT('%') )
5973 wxString s2
= s
.substr(0,s
.length()-1);
5975 if ( s2
.ToLong(&val
, 10) )
5977 *pval
= (val
*max
)/100;
5983 return s
.ToLong(pval
, 10);
5986 // -----------------------------------------------------------------------
5988 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5989 const wxString
& type
,
5990 const wxString
& value
)
5992 int l
= m_propHierarchy
.size();
5996 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5997 wxString valuel
= value
.Lower();
6000 if ( type
.length() == 0 )
6005 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6007 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6009 else if ( value
.ToLong(&v
, 0) )
6016 if ( type
== wxT("string") )
6020 else if ( type
== wxT("int") )
6023 value
.ToLong(&v
, 0);
6026 else if ( type
== wxT("bool") )
6028 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6035 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6040 p
->SetAttribute( name
, variant
);
6045 // -----------------------------------------------------------------------
6047 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6049 wxLogError(_("Error in resource: %s"),msg
.c_str());
6052 // -----------------------------------------------------------------------
6054 #endif // wxUSE_PROPGRID