1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 #define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 #define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // -----------------------------------------------------------------------
239 // This class is a wxBrush derivative used in the background colour
240 // brush cache. It adds wxPG-type colour-in-long to the class.
241 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
242 // object does), but this is simpler implementation and equally
246 class wxPGBrush
: public wxBrush
249 wxPGBrush( const wxColour
& colour
);
251 virtual ~wxPGBrush() { }
252 void SetColour2( const wxColour
& colour
);
253 inline long GetColourAsLong() const { return m_colAsLong
; }
259 void wxPGBrush::SetColour2( const wxColour
& colour
)
261 wxBrush::SetColour(colour
);
262 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
266 wxPGBrush::wxPGBrush() : wxBrush()
272 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
274 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
278 // -----------------------------------------------------------------------
280 // -----------------------------------------------------------------------
283 // Same as wxPGBrush, but for wxColour instead.
286 class wxPGColour
: public wxColour
289 wxPGColour( const wxColour
& colour
);
291 virtual ~wxPGColour() { }
292 void SetColour2( const wxColour
& colour
);
293 inline long GetColourAsLong() const { return m_colAsLong
; }
299 void wxPGColour::SetColour2( const wxColour
& colour
)
302 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
306 wxPGColour::wxPGColour() : wxColour()
312 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
314 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
318 // -----------------------------------------------------------------------
320 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
321 // and tries to commit property value.
322 // -----------------------------------------------------------------------
324 class wxPGTLWHandler
: public wxEvtHandler
328 wxPGTLWHandler( wxPropertyGrid
* pg
)
336 void OnClose( wxCloseEvent
& event
)
338 // ClearSelection forces value validation/commit.
339 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
349 wxPropertyGrid
* m_pg
;
351 DECLARE_EVENT_TABLE()
354 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
355 EVT_CLOSE(wxPGTLWHandler::OnClose
)
358 // -----------------------------------------------------------------------
360 // -----------------------------------------------------------------------
363 // wxPGCanvas acts as a graphics sub-window of the
364 // wxScrolledWindow that wxPropertyGrid is.
366 class wxPGCanvas
: public wxPanel
369 wxPGCanvas() : wxPanel()
372 virtual ~wxPGCanvas() { }
375 void OnMouseMove( wxMouseEvent
&event
)
377 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
378 pg
->OnMouseMove( event
);
381 void OnMouseClick( wxMouseEvent
&event
)
383 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
384 pg
->OnMouseClick( event
);
387 void OnMouseUp( wxMouseEvent
&event
)
389 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
390 pg
->OnMouseUp( event
);
393 void OnMouseRightClick( wxMouseEvent
&event
)
395 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
396 pg
->OnMouseRightClick( event
);
399 void OnMouseDoubleClick( wxMouseEvent
&event
)
401 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
402 pg
->OnMouseDoubleClick( event
);
405 void OnKey( wxKeyEvent
& event
)
407 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
411 void OnKeyUp( wxKeyEvent
& event
)
413 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
414 pg
->OnKeyUp( event
);
417 void OnPaint( wxPaintEvent
& event
);
419 // Always be focussable, even with child windows
420 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
421 { wxPanel::SetCanFocus(true); }
425 DECLARE_EVENT_TABLE()
426 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
430 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
432 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
433 EVT_MOTION(wxPGCanvas::OnMouseMove
)
434 EVT_PAINT(wxPGCanvas::OnPaint
)
435 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
436 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
437 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
438 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
439 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
440 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
441 EVT_CHAR(wxPGCanvas::OnKey
)
445 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
447 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
448 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
452 // Don't paint after destruction has begun
453 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
456 // Update everything inside the box
457 wxRect r
= GetUpdateRegion().GetBox();
459 // Repaint this rectangle
460 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
462 // We assume that the size set when grid is shown
463 // is what is desired.
464 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
467 // -----------------------------------------------------------------------
469 // -----------------------------------------------------------------------
471 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
473 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
474 EVT_IDLE(wxPropertyGrid::OnIdle
)
475 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
476 EVT_PAINT(wxPropertyGrid::OnPaint
)
477 EVT_SIZE(wxPropertyGrid::OnResize
)
478 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
479 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
480 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
481 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
482 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
483 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
484 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
485 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
489 // -----------------------------------------------------------------------
491 wxPropertyGrid::wxPropertyGrid()
497 // -----------------------------------------------------------------------
499 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
508 Create(parent
,id
,pos
,size
,style
,name
);
511 // -----------------------------------------------------------------------
513 bool wxPropertyGrid::Create( wxWindow
*parent
,
521 if ( !(style
&wxBORDER_MASK
) )
522 style
|= wxSIMPLE_BORDER
;
527 // This prevents crash under Win2K, but still
528 // enables keyboard navigation
529 if ( style
& wxTAB_TRAVERSAL
)
531 style
&= ~(wxTAB_TRAVERSAL
);
532 style
|= wxWANTS_CHARS
;
535 if ( style
& wxTAB_TRAVERSAL
)
536 style
|= wxWANTS_CHARS
;
539 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
546 // -----------------------------------------------------------------------
549 // Initialize values to defaults
551 void wxPropertyGrid::Init1()
553 // Register editor classes, if necessary.
554 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
555 wxPropertyGrid::RegisterDefaultEditors();
558 m_pState
= (wxPropertyGridPageState
*) NULL
;
559 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
560 m_selected
= (wxPGProperty
*) NULL
;
562 m_propHover
= (wxPGProperty
*) NULL
;
563 m_eventObject
= this;
564 m_curFocused
= (wxWindow
*) NULL
;
566 m_inDoPropertyChanged
= 0;
567 m_inCommitChangesFromEditor
= 0;
568 m_inDoSelectProperty
= 0;
569 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
575 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
576 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
577 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
578 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
579 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
580 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
581 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
582 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
583 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
584 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
585 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
586 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
587 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
588 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
589 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
591 m_coloursCustomized
= 0;
596 #if wxPG_DOUBLE_BUFFER
597 m_doubleBuffer
= (wxBitmap
*) NULL
;
600 #ifndef wxPG_ICON_WIDTH
606 m_iconWidth
= wxPG_ICON_WIDTH
;
611 m_gutterWidth
= wxPG_GUTTER_MIN
;
612 m_subgroup_extramargin
= 10;
616 m_width
= m_height
= 0;
618 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
621 m_chgInfo_changedProperty
= NULL
;
624 // -----------------------------------------------------------------------
627 // Initialize after parent etc. set
629 void wxPropertyGrid::Init2()
631 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
634 // Smaller controls on Mac
635 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
638 // Now create state, if one didn't exist already
639 // (wxPropertyGridManager might have created it for us).
642 m_pState
= CreateState();
643 m_pState
->m_pPropGrid
= this;
644 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
647 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
648 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
650 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
652 m_pState
->InitNonCatMode();
654 m_pState
->m_properties
= m_pState
->m_abcArray
;
657 GetClientSize(&m_width
,&m_height
);
659 #ifndef wxPG_ICON_WIDTH
660 // create two bitmap nodes for drawing
661 m_expandbmp
= new wxBitmap(expand_xpm
);
662 m_collbmp
= new wxBitmap(collapse_xpm
);
664 // calculate average font height for bitmap centering
666 m_iconWidth
= m_expandbmp
->GetWidth();
667 m_iconHeight
= m_expandbmp
->GetHeight();
670 m_curcursor
= wxCURSOR_ARROW
;
671 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
673 // adjust bitmap icon y position so they are centered
674 m_vspacing
= wxPG_DEFAULT_VSPACING
;
678 wxFont useFont
= wxScrolledWindow::GetFont();
679 wxScrolledWindow::SetOwnFont( useFont
);
682 // This should be otherwise called by SetOwnFont
683 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
685 // Add base brush item
686 m_arrBgBrushes
.Add((void*)new wxPGBrush());
688 // Add base colour items
689 m_arrFgCols
.Add((void*)new wxPGColour());
690 m_arrFgCols
.Add((void*)new wxPGColour());
694 // This helps with flicker
695 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
698 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
699 m_tlp
= ::wxGetTopLevelParent(this);
700 m_tlwHandler
= handler
;
701 m_tlp
->PushEventHandler(handler
);
703 // set virtual size to this window size
704 wxSize wndsize
= GetSize();
705 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
707 m_timeCreated
= ::wxGetLocalTimeMillis();
709 m_canvas
= new wxPGCanvas();
710 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
711 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
712 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
714 m_iFlags
|= wxPG_FL_INITIALIZED
;
716 m_ncWidth
= wndsize
.GetWidth();
718 // Need to call OnResize handler or size given in constructor/Create
720 wxSizeEvent
sizeEvent(wndsize
,0);
724 // -----------------------------------------------------------------------
726 wxPropertyGrid::~wxPropertyGrid()
730 DoSelectProperty(NULL
);
732 // This should do prevent things from going too badly wrong
733 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
735 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
736 m_canvas
->ReleaseMouse();
738 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
739 m_tlp
->RemoveEventHandler(handler
);
743 if ( IsEditorsValueModified() )
744 ::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).)"),
745 wxS("wxPropertyGrid Debug Warning") );
748 #if wxPG_DOUBLE_BUFFER
749 if ( m_doubleBuffer
)
750 delete m_doubleBuffer
;
753 //m_selected = (wxPGProperty*) NULL;
755 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
758 delete m_cursorSizeWE
;
760 #ifndef wxPG_ICON_WIDTH
765 // Delete cached text colours.
766 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
768 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
771 // Delete cached brushes.
772 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
774 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
777 // Delete common value records
778 for ( i
=0; i
<m_commonValues
.size(); i
++ )
780 delete GetCommonValue(i
);
784 // -----------------------------------------------------------------------
786 bool wxPropertyGrid::Destroy()
788 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
789 m_canvas
->ReleaseMouse();
791 return wxScrolledWindow::Destroy();
794 // -----------------------------------------------------------------------
796 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
798 return new wxPropertyGridPageState();
801 // -----------------------------------------------------------------------
802 // wxPropertyGrid overridden wxWindow methods
803 // -----------------------------------------------------------------------
805 void wxPropertyGrid::SetWindowStyleFlag( long style
)
807 long old_style
= m_windowStyle
;
809 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
811 wxASSERT( m_pState
);
813 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
816 EnableCategories( true );
818 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
820 // Disable categories
821 EnableCategories( false );
823 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
829 PrepareAfterItemsAdded();
831 m_pState
->m_itemsAdded
= 1;
833 #if wxPG_SUPPORT_TOOLTIPS
834 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
840 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
841 SetToolTip ( tooltip );
842 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
845 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
850 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
855 wxScrolledWindow::SetWindowStyleFlag ( style
);
857 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
859 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
861 CalculateFontAndBitmapStuff( m_vspacing
);
867 // -----------------------------------------------------------------------
869 void wxPropertyGrid::Freeze()
873 wxScrolledWindow::Freeze();
878 // -----------------------------------------------------------------------
880 void wxPropertyGrid::Thaw()
886 wxScrolledWindow::Thaw();
887 RecalculateVirtualSize();
888 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
892 // Force property re-selection
894 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
898 // -----------------------------------------------------------------------
900 void wxPropertyGrid::SetExtraStyle( long exStyle
)
902 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
904 #if defined(__WXMSW__)
907 // Don't use WS_EX_COMPOSITED just now.
910 if ( m_iFlags & wxPG_FL_IN_MANAGER )
911 hWnd = (HWND)GetParent()->GetHWND();
913 hWnd = (HWND)GetHWND();
915 ::SetWindowLong( hWnd, GWL_EXSTYLE,
916 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
919 //#elif defined(__WXGTK20__)
921 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
922 // truly was double-buffered.
923 if ( !this->IsDoubleBuffered() )
925 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
929 #if wxPG_DOUBLE_BUFFER
930 delete m_doubleBuffer
;
931 m_doubleBuffer
= NULL
;
936 wxScrolledWindow::SetExtraStyle( exStyle
);
938 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
939 m_pState
->InitNonCatMode();
941 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
942 m_windowStyle
|= wxPG_TOOLTIPS
;
945 wxPGGlobalVars
->m_extraStyle
= exStyle
;
948 // -----------------------------------------------------------------------
950 // returns the best acceptable minimal size
951 wxSize
wxPropertyGrid::DoGetBestSize() const
954 if ( m_lineHeight
> hei
)
956 wxSize sz
= wxSize( 60, hei
+40 );
962 // -----------------------------------------------------------------------
963 // wxPropertyGrid Font and Colour Methods
964 // -----------------------------------------------------------------------
966 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
970 m_captionFont
= wxScrolledWindow::GetFont();
972 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
973 m_subgroup_extramargin
= x
+ (x
/2);
976 #if wxPG_USE_RENDERER_NATIVE
977 m_iconWidth
= wxPG_ICON_WIDTH
;
978 #elif wxPG_ICON_WIDTH
980 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
981 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
982 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
986 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
987 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
988 m_gutterWidth
= wxPG_GUTTER_MIN
;
991 if ( vspacing
<= 1 ) vdiv
= 12;
992 else if ( vspacing
>= 3 ) vdiv
= 3;
994 m_spacingy
= m_fontHeight
/ vdiv
;
995 if ( m_spacingy
< wxPG_YSPACING_MIN
)
996 m_spacingy
= wxPG_YSPACING_MIN
;
999 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1000 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1002 m_captionFont
.SetWeight(wxBOLD
);
1003 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1005 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1008 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1009 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1012 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1014 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1015 RecalculateVirtualSize();
1017 InvalidateBestSize();
1020 // -----------------------------------------------------------------------
1022 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1028 // -----------------------------------------------------------------------
1030 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1031 int ga
= 1000, int ba
= 1000,
1032 bool forceDifferent
= false)
1039 // Recursion guard (allow 2 max)
1040 static int isinside
= 0;
1042 wxCHECK_MSG( isinside
< 3,
1044 wxT("wxPGAdjustColour should not be recursively called more than once") );
1049 int g
= src
.Green();
1052 if ( r2
>255 ) r2
= 255;
1053 else if ( r2
<0) r2
= 0;
1055 if ( g2
>255 ) g2
= 255;
1056 else if ( g2
<0) g2
= 0;
1058 if ( b2
>255 ) b2
= 255;
1059 else if ( b2
<0) b2
= 0;
1061 // Make sure they are somewhat different
1062 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1063 dst
= wxPGAdjustColour(src
,-(ra
*2));
1065 dst
= wxColour(r2
,g2
,b2
);
1067 // Recursion guard (allow 2 max)
1074 static int wxPGGetColAvg( const wxColour
& col
)
1076 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1080 void wxPropertyGrid::RegainColours()
1082 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1084 if ( !(m_coloursCustomized
& 0x0002) )
1086 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1088 // Make sure colour is dark enough
1090 int colDec
= wxPGGetColAvg(col
) - 230;
1092 int colDec
= wxPGGetColAvg(col
) - 200;
1095 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1100 if ( !(m_coloursCustomized
& 0x0001) )
1101 m_colMargin
= m_colCapBack
;
1103 if ( !(m_coloursCustomized
& 0x0004) )
1110 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1111 m_colCapFore
= capForeCol
;
1113 // Set the cached colour as well.
1114 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1117 if ( !(m_coloursCustomized
& 0x0008) )
1119 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1120 m_colPropBack
= bgCol
;
1122 // Set the cached brush as well.
1123 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1126 if ( !(m_coloursCustomized
& 0x0010) )
1128 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1129 m_colPropFore
= fgCol
;
1131 // Set the cached colour as well.
1132 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1135 if ( !(m_coloursCustomized
& 0x0020) )
1136 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1138 if ( !(m_coloursCustomized
& 0x0040) )
1139 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1141 if ( !(m_coloursCustomized
& 0x0080) )
1142 m_colLine
= m_colCapBack
;
1144 if ( !(m_coloursCustomized
& 0x0100) )
1145 m_colDisPropFore
= m_colCapFore
;
1147 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1150 // -----------------------------------------------------------------------
1152 void wxPropertyGrid::ResetColours()
1154 m_coloursCustomized
= 0;
1161 // -----------------------------------------------------------------------
1163 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1165 // Must disable active editor.
1168 bool selRes
= ClearSelection();
1169 wxPG_CHECK_MSG_DBG( selRes
,
1171 wxT("failed to deselect a property (editor probably had invalid value)") );
1174 // TODO: Following code is disabled with wxMac because
1175 // it is reported to fail. I (JMS) cannot debug it
1176 // personally right now.
1177 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1178 #if 1 // !defined(__WXMAC__)
1179 bool res
= wxScrolledWindow::SetFont( font
);
1182 CalculateFontAndBitmapStuff( m_vspacing
);
1185 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1193 // TODO: Remove after SetFont crash fixed.
1194 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1196 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."));
1202 // -----------------------------------------------------------------------
1204 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1207 m_coloursCustomized
|= 0x80;
1211 // -----------------------------------------------------------------------
1213 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1216 m_coloursCustomized
|= 0x01;
1220 // -----------------------------------------------------------------------
1222 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1224 m_colPropBack
= col
;
1225 m_coloursCustomized
|= 0x08;
1227 // Set the cached brush as well.
1228 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1233 // -----------------------------------------------------------------------
1235 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1237 m_colPropFore
= col
;
1238 m_coloursCustomized
|= 0x10;
1240 // Set the cached colour as well.
1241 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1246 // -----------------------------------------------------------------------
1248 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1250 m_colEmptySpace
= col
;
1255 // -----------------------------------------------------------------------
1257 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1259 m_colDisPropFore
= col
;
1260 m_coloursCustomized
|= 0x100;
1264 // -----------------------------------------------------------------------
1266 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1269 m_coloursCustomized
|= 0x20;
1273 // -----------------------------------------------------------------------
1275 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1278 m_coloursCustomized
|= 0x40;
1282 // -----------------------------------------------------------------------
1284 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1287 m_coloursCustomized
|= 0x02;
1291 // -----------------------------------------------------------------------
1293 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1296 m_coloursCustomized
|= 0x04;
1298 // Set the cached colour as well.
1299 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1304 // -----------------------------------------------------------------------
1306 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1308 unsigned char ind
= index
;
1310 p
->m_bgColIndex
= ind
;
1313 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1314 SetBackgroundColourIndex(p
->Item(i
),index
);
1317 // -----------------------------------------------------------------------
1319 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1321 wxPG_PROP_ARG_CALL_PROLOG()
1326 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1328 // As it is most likely that the previous colour is used, start comparison
1330 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1332 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1341 colInd
= m_arrBgBrushes
.size();
1342 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1343 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1347 SetBackgroundColourIndex(p
,colInd
);
1349 // If this was on a visible grid, then draw it.
1350 DrawItemAndChildren(p
);
1353 // -----------------------------------------------------------------------
1355 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1357 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1359 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1362 // -----------------------------------------------------------------------
1364 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1366 unsigned char ind
= index
;
1368 p
->m_fgColIndex
= ind
;
1370 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1373 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1374 SetTextColourIndex( p
->Item(i
), index
, flags
);
1378 // -----------------------------------------------------------------------
1380 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1385 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1387 // As it is most likely that the previous colour is used, start comparison
1389 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1391 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1400 colInd
= m_arrFgCols
.size();
1401 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1402 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1408 // -----------------------------------------------------------------------
1410 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1413 wxPG_PROP_ARG_CALL_PROLOG()
1415 if ( p
->IsCategory() )
1417 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1418 cat
->SetTextColIndex(CacheColour(colour
));
1424 flags
|= wxPG_RECURSE
;
1425 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1427 DrawItemAndChildren(p
);
1430 // -----------------------------------------------------------------------
1432 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1434 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1436 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1439 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1441 wxPG_PROP_ARG_CALL_PROLOG()
1443 SetBackgroundColourIndex( p
, 0 );
1444 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1446 if ( p
->IsCategory() )
1448 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1449 cat
->SetTextColIndex(1);
1453 // -----------------------------------------------------------------------
1454 // wxPropertyGrid property adding and removal
1455 // -----------------------------------------------------------------------
1457 void wxPropertyGrid::PrepareAfterItemsAdded()
1459 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1461 m_pState
->m_itemsAdded
= 0;
1463 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1466 RecalculateVirtualSize();
1469 // -----------------------------------------------------------------------
1470 // wxPropertyGrid property value setting and getting
1471 // -----------------------------------------------------------------------
1473 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1475 m_pState
->DoSetPropertyValueUnspecified(p
);
1476 DrawItemAndChildren(p
);
1478 wxPGProperty
* parent
= p
->GetParent();
1479 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1482 parent
= parent
->GetParent();
1486 // -----------------------------------------------------------------------
1487 // wxPropertyGrid property operations
1488 // -----------------------------------------------------------------------
1490 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1492 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1496 bool changed
= false;
1498 // Is it inside collapsed section?
1499 if ( !p
->IsVisible() )
1502 wxPGProperty
* parent
= p
->GetParent();
1503 wxPGProperty
* grandparent
= parent
->GetParent();
1505 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1506 Expand( grandparent
);
1514 GetViewStart(&vx
,&vy
);
1515 vy
*=wxPG_PIXELS_PER_UNIT
;
1521 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1522 m_iFlags
|= wxPG_FL_SCROLLED
;
1525 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1527 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1528 m_iFlags
|= wxPG_FL_SCROLLED
;
1538 // -----------------------------------------------------------------------
1539 // wxPropertyGrid helper methods called by properties
1540 // -----------------------------------------------------------------------
1542 // Control font changer helper.
1543 void wxPropertyGrid::SetCurControlBoldFont()
1545 wxASSERT( m_wndEditor
);
1546 m_wndEditor
->SetFont( m_captionFont
);
1549 // -----------------------------------------------------------------------
1551 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1554 #if wxPG_SMALL_SCREEN
1555 // On small-screen devices, always show dialogs with default position and size.
1556 return wxDefaultPosition
;
1558 int splitterX
= GetSplitterPosition();
1562 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1564 ImprovedClientToScreen( &x
, &y
);
1566 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1567 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1574 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1584 new_y
= y
+ m_lineHeight
;
1586 return wxPoint(new_x
,new_y
);
1590 // -----------------------------------------------------------------------
1592 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1594 if ( src_str
.length() == 0 )
1600 bool prev_is_slash
= false;
1602 wxString::const_iterator i
= src_str
.begin();
1606 for ( ; i
!= src_str
.end(); i
++ )
1610 if ( a
!= wxS('\\') )
1612 if ( !prev_is_slash
)
1618 if ( a
== wxS('n') )
1621 dst_str
<< wxS('\n');
1623 dst_str
<< wxS('\n');
1626 else if ( a
== wxS('t') )
1627 dst_str
<< wxS('\t');
1631 prev_is_slash
= false;
1635 if ( prev_is_slash
)
1637 dst_str
<< wxS('\\');
1638 prev_is_slash
= false;
1642 prev_is_slash
= true;
1649 // -----------------------------------------------------------------------
1651 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1653 if ( src_str
.length() == 0 )
1659 wxString::const_iterator i
= src_str
.begin();
1660 wxUniChar prev_a
= wxS('\0');
1664 for ( ; i
!= src_str
.end(); i
++ )
1668 if ( a
>= wxS(' ') )
1670 // This surely is not something that requires an escape sequence.
1675 // This might need...
1676 if ( a
== wxS('\r') )
1678 // DOS style line end.
1679 // Already taken care below
1681 else if ( a
== wxS('\n') )
1682 // UNIX style line end.
1683 dst_str
<< wxS("\\n");
1684 else if ( a
== wxS('\t') )
1686 dst_str
<< wxS('\t');
1689 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1699 // -----------------------------------------------------------------------
1701 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1705 return (wxPGProperty
*) NULL
;
1708 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1711 // -----------------------------------------------------------------------
1712 // wxPropertyGrid graphics related methods
1713 // -----------------------------------------------------------------------
1715 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1719 // Update everything inside the box
1720 wxRect r
= GetUpdateRegion().GetBox();
1722 dc
.SetPen(m_colEmptySpace
);
1723 dc
.SetBrush(m_colEmptySpace
);
1724 dc
.DrawRectangle(r
);
1727 // -----------------------------------------------------------------------
1729 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1730 wxPGProperty
* property
) const
1732 // Prepare rectangle to be used
1734 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1735 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1737 #if (wxPG_USE_RENDERER_NATIVE)
1739 #elif wxPG_ICON_WIDTH
1740 // Drawing expand/collapse button manually
1741 dc
.SetPen(m_colPropFore
);
1742 if ( property
->IsCategory() )
1743 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1745 dc
.SetBrush(m_colPropBack
);
1747 dc
.DrawRectangle( r
);
1748 int _y
= r
.y
+(m_iconWidth
/2);
1749 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1754 if ( property
->IsExpanded() )
1756 // wxRenderer functions are non-mutating in nature, so it
1757 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1758 // Hopefully this does not cause problems.
1759 #if (wxPG_USE_RENDERER_NATIVE)
1760 wxRendererNative::Get().DrawTreeItemButton(
1766 #elif wxPG_ICON_WIDTH
1775 #if (wxPG_USE_RENDERER_NATIVE)
1776 wxRendererNative::Get().DrawTreeItemButton(
1782 #elif wxPG_ICON_WIDTH
1783 int _x
= r
.x
+(m_iconWidth
/2);
1784 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1790 #if (wxPG_USE_RENDERER_NATIVE)
1792 #elif wxPG_ICON_WIDTH
1795 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1799 // -----------------------------------------------------------------------
1802 // This is the one called by OnPaint event handler and others.
1803 // topy and bottomy are already unscrolled (ie. physical)
1805 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1807 unsigned int bottomy
,
1808 const wxRect
* clipRect
)
1810 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1812 m_pState
->EnsureVirtualHeight();
1814 wxRect tempClipRect
;
1817 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1818 clipRect
= &tempClipRect
;
1821 // items added check
1822 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1824 int paintFinishY
= 0;
1826 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1829 bool isBuffered
= false;
1831 #if wxPG_DOUBLE_BUFFER
1832 wxMemoryDC
* bufferDC
= NULL
;
1834 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1836 if ( !m_doubleBuffer
)
1838 paintFinishY
= clipRect
->y
;
1843 bufferDC
= new wxMemoryDC();
1845 // If nothing was changed, then just copy from double-buffer
1846 bufferDC
->SelectObject( *m_doubleBuffer
);
1856 dc
.SetClippingRegion( *clipRect
);
1857 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1860 #if wxPG_DOUBLE_BUFFER
1863 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1864 bufferDC
, 0, 0, wxCOPY
);
1865 dc
.DestroyClippingRegion(); // Is this really necessary?
1871 // Clear area beyond bottomY?
1872 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1874 dc
.SetPen(m_colEmptySpace
);
1875 dc
.SetBrush(m_colEmptySpace
);
1876 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1880 // -----------------------------------------------------------------------
1882 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1883 const wxPGProperty
* firstItem
,
1884 const wxPGProperty
* lastItem
,
1885 const wxRect
* clipRect
,
1886 bool isBuffered
) const
1888 // TODO: This should somehow be eliminated.
1889 wxRect tempClipRect
;
1892 wxASSERT(firstItem
);
1894 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1895 clipRect
= &tempClipRect
;
1899 firstItem
= DoGetItemAtY(clipRect
->y
);
1903 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1905 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1908 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1911 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1912 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1914 int lh
= m_lineHeight
;
1917 int lastItemBottomY
;
1919 firstItemTopY
= clipRect
->y
;
1920 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1922 // Align y coordinates to item boundaries
1923 firstItemTopY
-= firstItemTopY
% lh
;
1924 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1925 lastItemBottomY
-= 1;
1927 // Entire range outside scrolled, visible area?
1928 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1931 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1935 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1936 firstItem->GetLabel().c_str(),
1937 lastItem->GetLabel().c_str(),
1938 (int)(lastItemBottomY - firstItemTopY),
1940 (unsigned long)clipRect );
1945 long windowStyle
= m_windowStyle
;
1951 // With wxPG_DOUBLE_BUFFER, do double buffering
1952 // - buffer's y = 0, so align cliprect and coordinates to that
1954 #if wxPG_DOUBLE_BUFFER
1960 xRelMod
= clipRect
->x
;
1961 yRelMod
= clipRect
->y
;
1964 // clipRect conversion
1972 firstItemTopY
-= yRelMod
;
1973 lastItemBottomY
-= yRelMod
;
1976 wxUnusedVar(isBuffered
);
1979 int x
= m_marginWidth
- xRelMod
;
1981 const wxFont
& normalfont
= m_font
;
1983 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1985 bool isEnabled
= IsEnabled();
1988 // Prepare some pens and brushes that are often changed to.
1991 wxBrush
marginBrush(m_colMargin
);
1992 wxPen
marginPen(m_colMargin
);
1993 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1994 wxPen
linepen(m_colLine
,1,wxSOLID
);
1996 // pen that has same colour as text
1997 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2000 // Clear margin with background colour
2002 dc
.SetBrush( marginBrush
);
2003 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2005 dc
.SetPen( *wxTRANSPARENT_PEN
);
2006 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2009 const wxPGProperty
* selected
= m_selected
;
2010 const wxPropertyGridPageState
* state
= m_pState
;
2012 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2013 bool wasSelectedPainted
= false;
2016 // TODO: Only render columns that are within clipping region.
2018 dc
.SetFont(normalfont
);
2020 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2021 int endScanBottomY
= lastItemBottomY
+ lh
;
2022 int y
= firstItemTopY
;
2025 // Pregenerate list of visible properties.
2026 wxArrayPGProperty visPropArray
;
2027 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2029 for ( ; !it
.AtEnd(); it
.Next() )
2031 const wxPGProperty
* p
= *it
;
2033 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2035 visPropArray
.push_back((wxPGProperty
*)p
);
2037 if ( y
> endScanBottomY
)
2044 visPropArray
.push_back(NULL
);
2046 wxPGProperty
* nextP
= visPropArray
[0];
2048 int gridWidth
= state
->m_width
;
2051 for ( unsigned int arrInd
=1;
2052 nextP
&& y
<= lastItemBottomY
;
2055 wxPGProperty
* p
= nextP
;
2056 nextP
= visPropArray
[arrInd
];
2058 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2059 int textMarginHere
= x
;
2060 int renderFlags
= wxPGCellRenderer::Control
;
2062 int greyDepth
= m_marginWidth
;
2063 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2064 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2066 int greyDepthX
= greyDepth
- xRelMod
;
2068 // Use basic depth if in non-categoric mode and parent is base array.
2069 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2071 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2074 // Paint margin area
2075 dc
.SetBrush(marginBrush
);
2076 dc
.SetPen(marginPen
);
2077 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2079 dc
.SetPen( linepen
);
2084 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2090 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2092 sx
+= state
->m_colWidths
[si
];
2093 dc
.DrawLine( sx
, y
, sx
, y2
);
2096 // Horizontal Line, below
2097 // (not if both this and next is category caption)
2098 if ( p
->IsCategory() &&
2099 nextP
&& nextP
->IsCategory() )
2100 dc
.SetPen(m_colCapBack
);
2102 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2104 if ( p
== selected
)
2106 renderFlags
|= wxPGCellRenderer::Selected
;
2107 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2108 wasSelectedPainted
= true;
2116 if ( p
->IsCategory() )
2118 if ( p
->m_fgColIndex
== 0 )
2119 rowFgCol
= m_colCapFore
;
2121 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2122 rowBgBrush
= wxBrush(m_colCapBack
);
2124 else if ( p
!= selected
)
2126 // Disabled may get different colour.
2127 if ( !p
->IsEnabled() )
2128 rowFgCol
= m_colDisPropFore
;
2130 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2132 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2136 // Selected gets different colour.
2137 if ( reallyFocused
)
2139 rowFgCol
= m_colSelFore
;
2140 rowBgBrush
= wxBrush(m_colSelBack
);
2142 else if ( isEnabled
)
2144 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2145 rowBgBrush
= marginBrush
;
2149 rowFgCol
= m_colDisPropFore
;
2150 rowBgBrush
= wxBrush(m_colSelBack
);
2154 bool fontChanged
= false;
2156 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2161 if ( p
->IsCategory() )
2163 // Captions are all cells merged as one
2164 dc
.SetFont(m_captionFont
);
2166 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2168 dc
.SetBrush(rowBgBrush
);
2169 dc
.SetPen(rowBgBrush
.GetColour());
2170 dc
.SetTextForeground(rowFgCol
);
2172 dc
.DrawRectangle(cellRect
);
2175 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2176 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2179 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2180 DrawExpanderButton( dc
, butRect
, p
);
2184 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2186 dc
.SetFont(m_captionFont
);
2192 int nextCellWidth
= state
->m_colWidths
[0];
2193 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2194 int textXAdd
= textMarginHere
- greyDepthX
;
2196 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2198 cellRect
.width
= nextCellWidth
- 1;
2200 bool ctrlCell
= false;
2203 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2205 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2206 dc
.SetBrush(editorBgCol
);
2207 dc
.SetPen(editorBgCol
);
2208 dc
.SetTextForeground(m_colPropFore
);
2210 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2215 dc
.SetBrush(rowBgBrush
);
2216 dc
.SetPen(rowBgBrush
.GetColour());
2217 dc
.SetTextForeground(rowFgCol
);
2220 dc
.DrawRectangle(cellRect
);
2223 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2224 DrawExpanderButton( dc
, butRect
, p
);
2226 dc
.SetClippingRegion(cellRect
);
2228 cellRect
.x
+= textXAdd
;
2229 cellRect
.width
-= textXAdd
;
2234 wxPGCellRenderer
* renderer
;
2235 int cmnVal
= p
->GetCommonValue();
2236 if ( cmnVal
== -1 || ci
!= 1 )
2238 renderer
= p
->GetCellRenderer(ci
);
2239 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2243 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2244 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2248 cellX
+= state
->m_colWidths
[ci
];
2249 if ( ci
< (state
->m_colWidths
.size()-1) )
2250 nextCellWidth
= state
->m_colWidths
[ci
+1];
2252 dc
.DestroyClippingRegion(); // Is this really necessary?
2258 dc
.SetFont(normalfont
);
2263 // Refresh editor controls (seems not needed on msw)
2264 // NOTE: This code is mandatory for GTK!
2265 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2266 if ( wasSelectedPainted
)
2269 m_wndEditor
->Refresh();
2271 m_wndEditor2
->Refresh();
2278 // -----------------------------------------------------------------------
2280 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2284 if ( m_width
< 10 || m_height
< 10 ||
2285 !m_pState
->m_properties
->GetChildCount() ||
2286 p1
== (wxPGProperty
*) NULL
)
2287 return wxRect(0,0,0,0);
2292 // Return rect which encloses the given property range
2294 int visTop
= p1
->GetY();
2297 visBottom
= p2
->GetY() + m_lineHeight
;
2299 visBottom
= m_height
+ visTop
;
2301 // If seleced property is inside the range, we'll extend the range to include
2303 wxPGProperty
* selected
= m_selected
;
2306 int selectedY
= selected
->GetY();
2307 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2309 wxWindow
* editor
= GetEditorControl();
2312 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2313 if ( visBottom2
> visBottom
)
2314 visBottom
= visBottom2
;
2319 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2322 // -----------------------------------------------------------------------
2324 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2329 if ( m_pState
->m_itemsAdded
)
2330 PrepareAfterItemsAdded();
2332 wxRect r
= GetPropertyRect(p1
, p2
);
2335 m_canvas
->RefreshRect(r
);
2339 // -----------------------------------------------------------------------
2341 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2343 if ( p
== m_selected
)
2344 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2346 DrawItemAndChildren(p
);
2349 // -----------------------------------------------------------------------
2351 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2356 // Draw item, children, and parent too, if it is not category
2357 wxPGProperty
* parent
= p
->GetParent();
2360 !parent
->IsCategory() &&
2361 parent
->GetParent() )
2364 parent
= parent
->GetParent();
2367 DrawItemAndChildren(p
);
2370 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2372 wxCHECK_RET( p
, wxT("invalid property id") );
2374 // Do not draw if in non-visible page
2375 if ( p
->GetParentState() != m_pState
)
2378 // do not draw a single item if multiple pending
2379 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2382 wxWindow
* wndPrimary
= GetEditorControl();
2384 // Update child control.
2385 if ( m_selected
&& m_selected
->GetParent() == p
)
2386 m_selected
->UpdateControl(wndPrimary
);
2388 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2390 DrawItems(p
, lastDrawn
);
2393 // -----------------------------------------------------------------------
2395 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2396 const wxRect
*rect
)
2398 PrepareAfterItemsAdded();
2400 wxWindow::Refresh(false);
2402 // TODO: Coordinate translation
2403 m_canvas
->Refresh(false, rect
);
2405 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2406 // I think this really helps only GTK+1.2
2407 if ( m_wndEditor
) m_wndEditor
->Refresh();
2408 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2412 // -----------------------------------------------------------------------
2413 // wxPropertyGrid global operations
2414 // -----------------------------------------------------------------------
2416 void wxPropertyGrid::Clear()
2420 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2421 wxPG_CHECK_RET_DBG( selRes
,
2422 wxT("failed to deselect a property (editor probably had invalid value)") );
2425 m_pState
->DoClear();
2431 RecalculateVirtualSize();
2433 // Need to clear some area at the end
2435 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2438 // -----------------------------------------------------------------------
2440 bool wxPropertyGrid::EnableCategories( bool enable
)
2442 if ( !ClearSelection() )
2448 // Enable categories
2451 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2456 // Disable categories
2458 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2461 if ( !m_pState
->EnableCategories(enable
) )
2466 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2468 m_pState
->m_itemsAdded
= 1; // force
2469 PrepareAfterItemsAdded();
2473 m_pState
->m_itemsAdded
= 1;
2475 // No need for RecalculateVirtualSize() here - it is already called in
2476 // wxPropertyGridPageState method above.
2483 // -----------------------------------------------------------------------
2485 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2487 wxASSERT( pNewState
);
2488 wxASSERT( pNewState
->GetGrid() );
2490 if ( pNewState
== m_pState
)
2493 wxPGProperty
* oldSelection
= m_selected
;
2498 bool selRes
= ClearSelection();
2499 wxPG_CHECK_RET_DBG( selRes
,
2500 wxT("failed to deselect a property (editor probably had invalid value)") );
2503 m_pState
->m_selected
= oldSelection
;
2505 bool orig_mode
= m_pState
->IsInNonCatMode();
2506 bool new_state_mode
= pNewState
->IsInNonCatMode();
2508 m_pState
= pNewState
;
2511 int pgWidth
= GetClientSize().x
;
2512 if ( HasVirtualWidth() )
2514 int minWidth
= pgWidth
;
2515 if ( pNewState
->m_width
< minWidth
)
2517 pNewState
->m_width
= minWidth
;
2518 pNewState
->CheckColumnWidths();
2524 // Just in case, fully re-center splitter
2525 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2526 pNewState
->m_fSplitterX
= -1.0;
2528 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2531 m_propHover
= (wxPGProperty
*) NULL
;
2533 // If necessary, convert state to correct mode.
2534 if ( orig_mode
!= new_state_mode
)
2536 // This should refresh as well.
2537 EnableCategories( orig_mode
?false:true );
2539 else if ( !m_frozen
)
2541 // Refresh, if not frozen.
2542 if ( m_pState
->m_itemsAdded
)
2543 PrepareAfterItemsAdded();
2546 if ( m_pState
->m_selected
)
2547 DoSelectProperty( m_pState
->m_selected
);
2549 RecalculateVirtualSize(0);
2553 m_pState
->m_itemsAdded
= 1;
2556 // -----------------------------------------------------------------------
2558 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2560 wxPG_PROP_ARG_CALL_PROLOG()
2562 m_pState
->SortChildren( p
);
2565 // -----------------------------------------------------------------------
2567 void wxPropertyGrid::Sort()
2569 bool selRes
= ClearSelection(); // This must be before state clear
2570 wxPG_CHECK_RET_DBG( selRes
,
2571 wxT("failed to deselect a property (editor probably had invalid value)") );
2576 // -----------------------------------------------------------------------
2578 // Call to SetSplitterPosition will always disable splitter auto-centering
2579 // if parent window is shown.
2580 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2582 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2585 wxPropertyGridPageState
* state
= m_pState
;
2587 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2592 CorrectEditorWidgetSizeX();
2598 // -----------------------------------------------------------------------
2600 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2602 SetSplitterPosition( m_width
/2, true );
2603 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2604 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2607 // -----------------------------------------------------------------------
2608 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2609 // -----------------------------------------------------------------------
2611 // Returns nearest paint visible property (such that will be painted unless
2612 // window is scrolled or resized). If given property is paint visible, then
2613 // it itself will be returned
2614 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2616 int vx
,vy1
;// Top left corner of client
2617 GetViewStart(&vx
,&vy1
);
2618 vy1
*= wxPG_PIXELS_PER_UNIT
;
2620 int vy2
= vy1
+ m_height
;
2621 int propY
= p
->GetY2(m_lineHeight
);
2623 if ( (propY
+ m_lineHeight
) < vy1
)
2626 return DoGetItemAtY( vy1
);
2628 else if ( propY
> vy2
)
2631 return DoGetItemAtY( vy2
);
2634 // Itself paint visible
2639 // -----------------------------------------------------------------------
2640 // Methods related to change in value, value modification and sending events
2641 // -----------------------------------------------------------------------
2643 // commits any changes in editor of selected property
2644 // return true if validation did not fail
2645 // flags are same as with DoSelectProperty
2646 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2648 // Committing already?
2649 if ( m_inCommitChangesFromEditor
)
2652 // Don't do this if already processing editor event. It might
2653 // induce recursive dialogs and crap like that.
2654 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2656 if ( m_inDoPropertyChanged
)
2663 IsEditorsValueModified() &&
2664 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2667 m_inCommitChangesFromEditor
= 1;
2669 wxVariant
variant(m_selected
->GetValueRef());
2670 bool valueIsPending
= false;
2672 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2673 // due to another window getting focus
2674 wxWindow
* oldFocus
= m_curFocused
;
2676 bool validationFailure
= false;
2677 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2679 m_chgInfo_changedProperty
= NULL
;
2681 // If truly modified, schedule value as pending.
2682 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2684 if ( DoEditorValidate() &&
2685 PerformValidation(m_selected
, variant
) )
2687 valueIsPending
= true;
2691 validationFailure
= true;
2696 EditorsValueWasNotModified();
2701 m_inCommitChangesFromEditor
= 0;
2703 if ( validationFailure
&& !forceSuccess
)
2707 oldFocus
->SetFocus();
2708 m_curFocused
= oldFocus
;
2711 res
= OnValidationFailure(m_selected
, variant
);
2713 // Now prevent further validation failure messages
2716 EditorsValueWasNotModified();
2717 OnValidationFailureReset(m_selected
);
2720 else if ( valueIsPending
)
2722 DoPropertyChanged( m_selected
, flags
);
2723 EditorsValueWasNotModified();
2732 // -----------------------------------------------------------------------
2734 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2737 // Runs all validation functionality.
2738 // Returns true if value passes all tests.
2741 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2743 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2745 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2750 // Adapt list to child values, if necessary
2751 wxVariant listValue
= pendingValue
;
2752 wxVariant
* pPendingValue
= &pendingValue
;
2753 wxVariant
* pList
= NULL
;
2755 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2756 // string value, then we need treat as it was changed instead
2757 // (or, in addition, as is the case with composite string parent).
2758 // This includes creating list variant for child values.
2760 wxPGProperty
* pwc
= p
->GetParent();
2761 wxPGProperty
* changedProperty
= p
;
2762 wxPGProperty
* baseChangedProperty
= changedProperty
;
2763 wxVariant bcpPendingList
;
2765 listValue
= pendingValue
;
2766 listValue
.SetName(p
->GetBaseName());
2769 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2771 wxVariantList tempList
;
2772 wxVariant
lv(tempList
, pwc
->GetBaseName());
2773 lv
.Append(listValue
);
2775 pPendingValue
= &listValue
;
2777 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2779 baseChangedProperty
= pwc
;
2780 bcpPendingList
= lv
;
2783 changedProperty
= pwc
;
2784 pwc
= pwc
->GetParent();
2788 wxPGProperty
* evtChangingProperty
= changedProperty
;
2790 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2792 value
= *pPendingValue
;
2796 // Convert list to child values
2797 pList
= pPendingValue
;
2798 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2801 wxVariant evtChangingValue
= value
;
2803 // FIXME: After proper ValueToString()s added, remove
2804 // this. It is just a temporary fix, as evt_changing
2805 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2806 // (unless it is selected, and textctrl editor is open).
2807 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2809 evtChangingProperty
= baseChangedProperty
;
2810 if ( evtChangingProperty
!= p
)
2812 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2816 evtChangingValue
= pendingValue
;
2820 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2822 if ( changedProperty
== m_selected
)
2824 wxWindow
* editor
= GetEditorControl();
2825 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2826 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2830 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2834 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2835 m_chgInfo_changedProperty
= changedProperty
;
2836 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2837 m_chgInfo_pendingValue
= value
;
2840 m_chgInfo_valueList
= *pList
;
2842 m_chgInfo_valueList
.MakeNull();
2844 // If changedProperty is not property which value was edited,
2845 // then call wxPGProperty::ValidateValue() for that as well.
2846 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2848 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2852 // SendEvent returns true if event was vetoed
2853 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2859 // -----------------------------------------------------------------------
2861 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2863 if ( !msg
.length() )
2867 if ( !wxPGGlobalVars
->m_offline
)
2869 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2872 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2875 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2878 pStatusBar
->SetStatusText(msg
);
2886 ::wxMessageBox(msg
, _T("Property Error"));
2889 // -----------------------------------------------------------------------
2891 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2893 int vfb
= m_validationInfo
.m_failureBehavior
;
2895 if ( vfb
& wxPG_VFB_BEEP
)
2898 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2899 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2901 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2902 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2904 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2906 wxColour vfbFg
= *wxWHITE
;
2907 wxColour vfbBg
= *wxRED
;
2908 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2909 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2911 DrawItemAndChildren(property
);
2913 if ( property
== m_selected
)
2915 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2917 wxWindow
* editor
= GetEditorControl();
2920 editor
->SetForegroundColour(vfbFg
);
2921 editor
->SetBackgroundColour(vfbBg
);
2927 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2929 wxString msg
= m_validationInfo
.m_failureMessage
;
2931 if ( !msg
.length() )
2932 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2934 DoShowPropertyError(property
, msg
);
2937 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2940 // -----------------------------------------------------------------------
2942 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2944 int vfb
= m_validationInfo
.m_failureBehavior
;
2946 if ( vfb
& wxPG_VFB_MARK_CELL
)
2948 property
->SetCell(0, NULL
);
2949 property
->SetCell(1, NULL
);
2951 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2953 if ( property
== m_selected
&& GetEditorControl() )
2955 // Calling this will recreate the control, thus resetting its colour
2956 RefreshProperty(property
);
2960 DrawItemAndChildren(property
);
2965 // -----------------------------------------------------------------------
2967 // flags are same as with DoSelectProperty
2968 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2970 if ( m_inDoPropertyChanged
)
2973 wxWindow
* editor
= GetEditorControl();
2975 m_pState
->m_anyModified
= 1;
2977 m_inDoPropertyChanged
= 1;
2979 // Maybe need to update control
2980 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2982 // These values were calculated in PerformValidation()
2983 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2984 wxVariant value
= m_chgInfo_pendingValue
;
2986 wxPGProperty
* topPaintedProperty
= changedProperty
;
2988 while ( !topPaintedProperty
->IsCategory() &&
2989 !topPaintedProperty
->IsRoot() )
2991 topPaintedProperty
= topPaintedProperty
->GetParent();
2994 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2996 // Set as Modified (not if dragging just began)
2997 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2999 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3000 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3003 SetCurControlBoldFont();
3009 // Propagate updates to parent(s)
3011 wxPGProperty
* prevPwc
= NULL
;
3013 while ( prevPwc
!= topPaintedProperty
)
3015 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3017 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3020 SetCurControlBoldFont();
3024 pwc
= pwc
->GetParent();
3027 // Draw the actual property
3028 DrawItemAndChildren( topPaintedProperty
);
3031 // If value was set by wxPGProperty::OnEvent, then update the editor
3033 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3036 p
->GetEditorClass()->UpdateControl(p
, editor
);
3040 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3041 if ( m_wndEditor
) m_wndEditor
->Refresh();
3042 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3047 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3049 // If top parent has composite string value, then send to child parents,
3050 // starting from baseChangedProperty.
3051 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3053 pwc
= m_chgInfo_baseChangedProperty
;
3055 while ( pwc
!= changedProperty
)
3057 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3058 pwc
= pwc
->GetParent();
3062 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3064 m_inDoPropertyChanged
= 0;
3069 // -----------------------------------------------------------------------
3071 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3073 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3075 m_chgInfo_changedProperty
= NULL
;
3077 if ( PerformValidation(p
, newValue
) )
3079 DoPropertyChanged(p
);
3084 OnValidationFailure(p
, newValue
);
3090 // -----------------------------------------------------------------------
3092 // Runs wxValidator for the selected property
3093 bool wxPropertyGrid::DoEditorValidate()
3098 // -----------------------------------------------------------------------
3100 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3102 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3103 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3105 wxWindow
* parent
= wnd
->GetParent();
3108 (parent
== m_canvas
||
3109 parent
->GetParent() == m_canvas
) )
3111 OnCustomEditorEvent((wxCommandEvent
&)event
);
3115 return wxPanel::ProcessEvent(event
);
3118 // -----------------------------------------------------------------------
3120 // NB: It may really not be wxCommandEvent - must check if necessary
3122 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3124 wxPGProperty
* selected
= m_selected
;
3126 // Somehow, event is handled after property has been deselected.
3127 // Possibly, but very rare.
3131 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3134 wxVariant
pendingValue(selected
->GetValueRef());
3135 wxWindow
* wnd
= GetEditorControl();
3137 bool wasUnspecified
= selected
->IsValueUnspecified();
3138 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3140 bool valueIsPending
= false;
3142 m_chgInfo_changedProperty
= NULL
;
3144 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3147 // Filter out excess wxTextCtrl modified events
3148 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3150 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3152 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3154 wxString newTcValue
= tc
->GetValue();
3155 if ( m_prevTcValue
== newTcValue
)
3158 m_prevTcValue
= newTcValue
;
3161 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3163 bool validationFailure
= false;
3164 bool buttonWasHandled
= false;
3167 // Try common button handling
3168 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3170 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3174 buttonWasHandled
= true;
3175 // Store as res2, as previously (and still currently alternatively)
3176 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3177 // in wxPGProperty::OnEvent().
3178 adapter
->ShowDialog( this, selected
);
3183 if ( !buttonWasHandled
)
3187 // First call editor class' event handler.
3188 const wxPGEditor
* editor
= selected
->GetEditorClass();
3190 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3192 // If changes, validate them
3193 if ( DoEditorValidate() )
3195 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3196 valueIsPending
= true;
3200 validationFailure
= true;
3205 // Then the property's custom handler (must be always called, unless
3206 // validation failed).
3207 if ( !validationFailure
)
3208 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3211 // SetValueInEvent(), as called in one of the functions referred above
3212 // overrides editor's value.
3213 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3215 valueIsPending
= true;
3216 pendingValue
= m_changeInEventValue
;
3217 selFlags
|= wxPG_SEL_DIALOGVAL
;
3220 if ( !validationFailure
&& valueIsPending
)
3221 if ( !PerformValidation(m_selected
, pendingValue
) )
3222 validationFailure
= true;
3224 if ( validationFailure
)
3226 OnValidationFailure(selected
, pendingValue
);
3228 else if ( valueIsPending
)
3230 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3232 DoPropertyChanged(selected
, selFlags
);
3233 EditorsValueWasNotModified();
3235 // Regardless of editor type, unfocus editor on
3236 // text-editing related enter press.
3237 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3244 // No value after all
3246 // Regardless of editor type, unfocus editor on
3247 // text-editing related enter press.
3248 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3253 // Let unhandled button click events go to the parent
3254 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3256 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3257 GetEventHandler()->AddPendingEvent(evt
);
3261 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3264 // -----------------------------------------------------------------------
3265 // wxPropertyGrid editor control helper methods
3266 // -----------------------------------------------------------------------
3268 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3270 int itemy
= p
->GetY2(m_lineHeight
);
3272 int cust_img_space
= 0;
3273 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3274 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3276 // TODO: If custom image detection changes from current, change this.
3277 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3279 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3280 int imwid
= p
->OnMeasureImage().x
;
3281 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3282 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3287 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3289 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3294 // -----------------------------------------------------------------------
3296 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3298 wxSize sz
= GetImageSize(p
, item
);
3299 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3300 wxPG_CUSTOM_IMAGE_SPACINGY
,
3305 // return size of custom paint image
3306 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3308 // If called with NULL property, then return default image
3309 // size for properties that use image.
3311 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3313 wxSize cis
= p
->OnMeasureImage(item
);
3315 int choiceCount
= p
->m_choices
.GetCount();
3316 int comVals
= p
->GetDisplayedCommonValueCount();
3317 if ( item
>= choiceCount
&& comVals
> 0 )
3319 unsigned int cvi
= item
-choiceCount
;
3320 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3322 else if ( item
>= 0 && choiceCount
== 0 )
3323 return wxSize(0, 0);
3328 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3333 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3340 // -----------------------------------------------------------------------
3342 // takes scrolling into account
3343 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3346 GetViewStart(&vx
,&vy
);
3347 vy
*=wxPG_PIXELS_PER_UNIT
;
3348 vx
*=wxPG_PIXELS_PER_UNIT
;
3351 ClientToScreen( px
, py
);
3354 // -----------------------------------------------------------------------
3356 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3359 GetViewStart(&pt2
.x
,&pt2
.y
);
3360 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3361 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3365 return m_pState
->HitTest(pt2
);
3368 // -----------------------------------------------------------------------
3370 // custom set cursor
3371 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3373 if ( type
== m_curcursor
&& !override
) return;
3375 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3377 if ( type
== wxCURSOR_SIZEWE
)
3378 cursor
= m_cursorSizeWE
;
3380 m_canvas
->SetCursor( *cursor
);
3385 // -----------------------------------------------------------------------
3386 // wxPropertyGrid property selection
3387 // -----------------------------------------------------------------------
3389 // Setups event handling for child control
3390 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3392 wxWindowID id
= argWnd
->GetId();
3394 if ( argWnd
== m_wndEditor
)
3396 argWnd
->Connect(id
, wxEVT_MOTION
,
3397 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3399 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3400 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3402 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3403 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3405 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3406 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3408 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3409 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3411 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3412 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3414 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3415 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3420 void wxPropertyGrid::FreeEditors()
3422 // Do not free editors immediately if processing events
3425 m_wndEditor2
->Hide();
3426 wxPendingDelete
.Append( m_wndEditor2
);
3427 m_wndEditor2
= (wxWindow
*) NULL
;
3432 m_wndEditor
->Hide();
3433 wxPendingDelete
.Append( m_wndEditor
);
3434 m_wndEditor
= (wxWindow
*) NULL
;
3438 // Call with NULL to de-select property
3439 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3441 wxPanel
* canvas
= GetPanel();
3445 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3446 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3448 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3451 if ( m_inDoSelectProperty
)
3454 m_inDoSelectProperty
= 1;
3456 wxPGProperty
* prev
= m_selected
;
3460 m_inDoSelectProperty
= 0;
3466 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3468 wxPrintf( "None selected\n" );
3471 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3473 wxPrintf( "P = NULL\n" );
3476 // If we are frozen, then just set the values.
3479 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3480 m_editorFocused
= 0;
3483 m_pState
->m_selected
= p
;
3485 // If frozen, always free controls. But don't worry, as Thaw will
3486 // recall SelectProperty to recreate them.
3489 // Prevent any further selection measures in this call
3490 p
= (wxPGProperty
*) NULL
;
3495 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3497 // Only set focus if not deselecting
3500 if ( flags
& wxPG_SEL_FOCUS
)
3504 m_wndEditor
->SetFocus();
3505 m_editorFocused
= 1;
3514 m_inDoSelectProperty
= 0;
3519 // First, deactivate previous
3523 OnValidationFailureReset(m_selected
);
3525 // Must double-check if this is an selected in case of forceswitch
3528 if ( !CommitChangesFromEditor(flags
) )
3530 // Validation has failed, so we can't exit the previous editor
3531 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3532 // _("Invalid Value"),wxOK|wxICON_ERROR);
3533 m_inDoSelectProperty
= 0;
3541 m_selected
= (wxPGProperty
*) NULL
;
3542 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3544 // We need to always fully refresh the grid here
3547 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3548 EditorsValueWasNotModified();
3551 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3554 // Then, activate the one given.
3557 int propY
= p
->GetY2(m_lineHeight
);
3559 int splitterX
= GetSplitterPosition();
3560 m_editorFocused
= 0;
3562 m_pState
->m_selected
= p
;
3563 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3565 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3567 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3569 // Do we need OnMeasureCalls?
3570 wxSize imsz
= p
->OnMeasureImage();
3573 // Only create editor for non-disabled non-caption
3574 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3576 // do this for non-caption items
3580 // Do we need to paint the custom image, if any?
3581 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3582 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3583 !p
->GetEditorClass()->CanContainCustomImage()
3585 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3587 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3588 wxPoint goodPos
= grect
.GetPosition();
3589 #if wxPG_CREATE_CONTROLS_HIDDEN
3590 int coord_adjust
= m_height
- goodPos
.y
;
3591 goodPos
.y
+= coord_adjust
;
3594 const wxPGEditor
* editor
= p
->GetEditorClass();
3595 wxCHECK_MSG(editor
, false,
3596 wxT("NULL editor class not allowed"));
3598 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3600 wxPGWindowList wndList
= editor
->CreateControls(this,
3605 m_wndEditor
= wndList
.m_primary
;
3606 m_wndEditor2
= wndList
.m_secondary
;
3607 wxWindow
* primaryCtrl
= GetEditorControl();
3610 // Essentially, primaryCtrl == m_wndEditor
3613 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3614 // value is drawn as normal, and m_wndEditor2 is assumed
3615 // to be a right-aligned button that triggers a separate editorCtrl
3620 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3621 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3623 // Set validator, if any
3624 #if wxUSE_VALIDATORS
3625 wxValidator
* validator
= p
->GetValidator();
3627 primaryCtrl
->SetValidator(*validator
);
3630 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3631 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3633 // If it has modified status, use bold font
3634 // (must be done before capturing m_ctrlXAdjust)
3635 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3636 SetCurControlBoldFont();
3639 // Fix TextCtrl indentation
3640 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3641 wxTextCtrl
* tc
= NULL
;
3642 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3643 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3645 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3647 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3650 // Store x relative to splitter (we'll need it).
3651 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3653 // Check if background clear is not necessary
3654 wxPoint pos
= m_wndEditor
->GetPosition();
3655 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3657 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3660 m_wndEditor
->SetSizeHints(3, 3);
3662 #if wxPG_CREATE_CONTROLS_HIDDEN
3663 m_wndEditor
->Show(false);
3664 m_wndEditor
->Freeze();
3666 goodPos
= m_wndEditor
->GetPosition();
3667 goodPos
.y
-= coord_adjust
;
3668 m_wndEditor
->Move( goodPos
);
3671 SetupChildEventHandling(primaryCtrl
);
3673 // Focus and select all (wxTextCtrl, wxComboBox etc)
3674 if ( flags
& wxPG_SEL_FOCUS
)
3676 primaryCtrl
->SetFocus();
3678 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3684 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3685 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3687 // Get proper id for wndSecondary
3688 m_wndSecId
= m_wndEditor2
->GetId();
3689 wxWindowList children
= m_wndEditor2
->GetChildren();
3690 wxWindowList::iterator node
= children
.begin();
3691 if ( node
!= children
.end() )
3692 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3694 m_wndEditor2
->SetSizeHints(3,3);
3696 #if wxPG_CREATE_CONTROLS_HIDDEN
3697 wxRect sec_rect
= m_wndEditor2
->GetRect();
3698 sec_rect
.y
-= coord_adjust
;
3700 // Fine tuning required to fix "oversized"
3701 // button disappearance bug.
3702 if ( sec_rect
.y
< 0 )
3704 sec_rect
.height
+= sec_rect
.y
;
3707 m_wndEditor2
->SetSize( sec_rect
);
3709 m_wndEditor2
->Show();
3711 SetupChildEventHandling(m_wndEditor2
);
3713 // If no primary editor, focus to button to allow
3714 // it to interprete ENTER etc.
3715 // NOTE: Due to problems focusing away from it, this
3716 // has been disabled.
3718 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3719 m_wndEditor2->SetFocus();
3723 if ( flags
& wxPG_SEL_FOCUS
)
3724 m_editorFocused
= 1;
3729 // Make sure focus is in grid canvas (important for wxGTK, at least)
3733 EditorsValueWasNotModified();
3735 // If it's inside collapsed section, expand parent, scroll, etc.
3736 // Also, if it was partially visible, scroll it into view.
3737 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3742 #if wxPG_CREATE_CONTROLS_HIDDEN
3743 m_wndEditor
->Thaw();
3745 m_wndEditor
->Show(true);
3752 // Make sure focus is in grid canvas
3756 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3762 // Show help text in status bar.
3763 // (if found and grid not embedded in manager with help box and
3764 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3767 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3769 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3770 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3772 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3774 statusbar
= frame
->GetStatusBar();
3779 const wxString
* pHelpString
= (const wxString
*) NULL
;
3783 pHelpString
= &p
->GetHelpString();
3784 if ( pHelpString
->length() )
3786 // Set help box text.
3787 statusbar
->SetStatusText( *pHelpString
);
3788 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3792 if ( (!pHelpString
|| !pHelpString
->length()) &&
3793 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3795 // Clear help box - but only if it was written
3796 // by us at previous time.
3797 statusbar
->SetStatusText( m_emptyString
);
3798 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3804 m_inDoSelectProperty
= 0;
3806 // call wx event handler (here so that it also occurs on deselection)
3807 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3812 // -----------------------------------------------------------------------
3814 bool wxPropertyGrid::UnfocusEditor()
3816 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3819 if ( !CommitChangesFromEditor(0) )
3823 DrawItem(m_selected
);
3828 // -----------------------------------------------------------------------
3830 // This method is not inline because it called dozens of times
3831 // (i.e. two-arg function calls create smaller code size).
3832 bool wxPropertyGrid::DoClearSelection()
3834 return DoSelectProperty((wxPGProperty
*)NULL
);
3837 // -----------------------------------------------------------------------
3838 // wxPropertyGrid expand/collapse state
3839 // -----------------------------------------------------------------------
3841 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3843 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3845 // If active editor was inside collapsed section, then disable it
3846 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3848 if ( !ClearSelection() )
3852 // Store dont-center-splitter flag 'cause we need to temporarily set it
3853 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3854 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3856 bool res
= m_pState
->DoCollapse(pwc
);
3861 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3863 RecalculateVirtualSize();
3865 // Redraw etc. only if collapsed was visible.
3866 if (pwc
->IsVisible() &&
3868 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3870 // When item is collapsed so that scrollbar would move,
3871 // graphics mess is about (unless we redraw everything).
3876 // Clear dont-center-splitter flag if it wasn't set
3877 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3882 // -----------------------------------------------------------------------
3884 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3886 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3888 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3890 // Store dont-center-splitter flag 'cause we need to temporarily set it
3891 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3892 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3894 bool res
= m_pState
->DoExpand(pwc
);
3899 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3901 RecalculateVirtualSize();
3903 // Redraw etc. only if expanded was visible.
3904 if ( pwc
->IsVisible() && !m_frozen
&&
3905 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3909 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3912 DrawItems(pwc
, NULL
);
3917 // Clear dont-center-splitter flag if it wasn't set
3918 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3923 // -----------------------------------------------------------------------
3925 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3928 return m_pState
->DoHideProperty(p
, hide
, flags
);
3931 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3934 if ( !ClearSelection() )
3938 m_pState
->DoHideProperty(p
, hide
, flags
);
3940 RecalculateVirtualSize();
3947 // -----------------------------------------------------------------------
3948 // wxPropertyGrid size related methods
3949 // -----------------------------------------------------------------------
3951 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3953 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3957 // If virtual height was changed, then recalculate editor control position(s)
3958 if ( m_pState
->m_vhCalcPending
)
3959 CorrectEditorWidgetPosY();
3961 m_pState
->EnsureVirtualHeight();
3964 int by1
= m_pState
->GetVirtualHeight();
3965 int by2
= m_pState
->GetActualVirtualHeight();
3968 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3969 wxASSERT_MSG( false,
3975 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3977 int x
= m_pState
->m_width
;
3978 int y
= m_pState
->m_virtualHeight
;
3981 GetClientSize(&width
,&height
);
3983 // Now adjust virtual size.
3984 SetVirtualSize(x
, y
);
3990 // Adjust scrollbars
3991 if ( HasVirtualWidth() )
3993 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3994 xPos
= GetScrollPos( wxHORIZONTAL
);
3997 if ( forceXPos
!= -1 )
4000 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4003 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4004 int yPos
= GetScrollPos( wxVERTICAL
);
4006 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4007 xAmount
, yAmount
, xPos
, yPos
, true );
4009 // Must re-get size now
4010 GetClientSize(&width
,&height
);
4012 if ( !HasVirtualWidth() )
4014 m_pState
->SetVirtualWidth(width
);
4021 m_canvas
->SetSize( x
, y
);
4023 m_pState
->CheckColumnWidths();
4026 CorrectEditorWidgetSizeX();
4028 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4031 // -----------------------------------------------------------------------
4033 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4035 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4039 GetClientSize(&width
,&height
);
4044 #if wxPG_DOUBLE_BUFFER
4045 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4047 int dblh
= (m_lineHeight
*2);
4048 if ( !m_doubleBuffer
)
4050 // Create double buffer bitmap to draw on, if none
4051 int w
= (width
>250)?width
:250;
4052 int h
= height
+ dblh
;
4054 m_doubleBuffer
= new wxBitmap( w
, h
);
4058 int w
= m_doubleBuffer
->GetWidth();
4059 int h
= m_doubleBuffer
->GetHeight();
4061 // Double buffer must be large enough
4062 if ( w
< width
|| h
< (height
+dblh
) )
4064 if ( w
< width
) w
= width
;
4065 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4066 delete m_doubleBuffer
;
4067 m_doubleBuffer
= new wxBitmap( w
, h
);
4074 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4075 m_ncWidth
= event
.GetSize().x
;
4079 if ( m_pState
->m_itemsAdded
)
4080 PrepareAfterItemsAdded();
4082 // Without this, virtual size (atleast under wxGTK) will be skewed
4083 RecalculateVirtualSize();
4089 // -----------------------------------------------------------------------
4091 void wxPropertyGrid::SetVirtualWidth( int width
)
4095 // Disable virtual width
4096 width
= GetClientSize().x
;
4097 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4101 // Enable virtual width
4102 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4104 m_pState
->SetVirtualWidth( width
);
4107 void wxPropertyGrid::SetFocusOnCanvas()
4109 m_canvas
->SetFocusIgnoringChildren();
4110 m_editorFocused
= 0;
4113 // -----------------------------------------------------------------------
4114 // wxPropertyGrid mouse event handling
4115 // -----------------------------------------------------------------------
4117 // selFlags uses same values DoSelectProperty's flags
4118 // Returns true if event was vetoed.
4119 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4121 // Send property grid event of specific type and with specific property
4122 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4123 evt
.SetPropertyGrid(this);
4124 evt
.SetEventObject(m_eventObject
);
4128 evt
.SetCanVeto(true);
4129 evt
.SetupValidationInfo();
4130 m_validationInfo
.m_pValue
= pValue
;
4132 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4134 evtHandler
->ProcessEvent(evt
);
4136 return evt
.WasVetoed();
4139 // -----------------------------------------------------------------------
4141 // Return false if should be skipped
4142 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4146 // Need to set focus?
4147 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4152 wxPropertyGridPageState
* state
= m_pState
;
4154 int splitterHitOffset
;
4155 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4157 wxPGProperty
* p
= DoGetItemAtY(y
);
4161 int depth
= (int)p
->GetDepth() - 1;
4163 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4165 if ( x
>= marginEnds
)
4169 if ( p
->IsCategory() )
4171 // This is category.
4172 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4174 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4176 // Expand, collapse, activate etc. if click on text or left of splitter.
4179 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4184 if ( !DoSelectProperty( p
) )
4187 // On double-click, expand/collapse.
4188 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4190 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4191 else DoExpand( p
, true );
4195 else if ( splitterHit
== -1 )
4198 unsigned int selFlag
= 0;
4199 if ( columnHit
== 1 )
4201 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4202 selFlag
= wxPG_SEL_FOCUS
;
4204 if ( !DoSelectProperty( p
, selFlag
) )
4207 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4209 if ( p
->GetChildCount() && !p
->IsCategory() )
4210 // On double-click, expand/collapse.
4211 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4213 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4214 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4215 else DoExpand( p
, true );
4222 // click on splitter
4223 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4225 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4227 // Double-clicking the splitter causes auto-centering
4228 CenterSplitter( true );
4230 else if ( m_dragStatus
== 0 )
4233 // Begin draggin the splitter
4237 // Changes must be committed here or the
4238 // value won't be drawn correctly
4239 if ( !CommitChangesFromEditor() )
4242 m_wndEditor
->Show ( false );
4245 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4247 m_canvas
->CaptureMouse();
4248 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4252 m_draggedSplitter
= splitterHit
;
4253 m_dragOffset
= splitterHitOffset
;
4255 wxClientDC
dc(m_canvas
);
4257 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4258 // Fixes button disappearance bug
4260 m_wndEditor2
->Show ( false );
4263 m_startingSplitterX
= x
- splitterHitOffset
;
4271 if ( p
->GetChildCount() )
4273 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4275 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4277 int y2
= y
% m_lineHeight
;
4278 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4280 // On click on expander button, expand/collapse
4281 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4282 DoCollapse( p
, true );
4284 DoExpand( p
, true );
4293 // -----------------------------------------------------------------------
4295 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4296 wxMouseEvent
& WXUNUSED(event
) )
4300 // Select property here as well
4301 wxPGProperty
* p
= m_propHover
;
4302 if ( p
!= m_selected
)
4303 DoSelectProperty( p
);
4305 // Send right click event.
4306 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4313 // -----------------------------------------------------------------------
4315 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4316 wxMouseEvent
& WXUNUSED(event
) )
4320 // Select property here as well
4321 wxPGProperty
* p
= m_propHover
;
4323 if ( p
!= m_selected
)
4324 DoSelectProperty( p
);
4326 // Send double-click event.
4327 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4334 // -----------------------------------------------------------------------
4336 #if wxPG_SUPPORT_TOOLTIPS
4338 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4340 if ( tipString
.length() )
4342 m_canvas
->SetToolTip(tipString
);
4346 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4347 m_canvas
->SetToolTip( m_emptyString
);
4349 m_canvas
->SetToolTip( NULL
);
4354 #endif // #if wxPG_SUPPORT_TOOLTIPS
4356 // -----------------------------------------------------------------------
4358 // Return false if should be skipped
4359 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4361 // Safety check (needed because mouse capturing may
4362 // otherwise freeze the control)
4363 if ( m_dragStatus
> 0 && !event
.Dragging() )
4365 HandleMouseUp(x
,y
,event
);
4368 wxPropertyGridPageState
* state
= m_pState
;
4370 int splitterHitOffset
;
4371 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4372 int splitterX
= x
- splitterHitOffset
;
4374 if ( m_dragStatus
> 0 )
4376 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4377 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4380 int newSplitterX
= x
- m_dragOffset
;
4381 int splitterX
= x
- splitterHitOffset
;
4383 // Splitter redraw required?
4384 if ( newSplitterX
!= splitterX
)
4387 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4388 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4389 state
->m_fSplitterX
= (float) newSplitterX
;
4392 CorrectEditorWidgetSizeX();
4406 int ih
= m_lineHeight
;
4409 #if wxPG_SUPPORT_TOOLTIPS
4410 wxPGProperty
* prevHover
= m_propHover
;
4411 unsigned char prevSide
= m_mouseSide
;
4413 int curPropHoverY
= y
- (y
% ih
);
4415 // On which item it hovers
4416 if ( ( !m_propHover
)
4418 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4421 // Mouse moves on another property
4423 m_propHover
= DoGetItemAtY(y
);
4424 m_propHoverY
= curPropHoverY
;
4427 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4430 #if wxPG_SUPPORT_TOOLTIPS
4431 // Store which side we are on
4433 if ( columnHit
== 1 )
4435 else if ( columnHit
== 0 )
4439 // If tooltips are enabled, show label or value as a tip
4440 // in case it doesn't otherwise show in full length.
4442 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4444 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4446 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4448 if ( m_propHover
&& !m_propHover
->IsCategory() )
4451 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4453 // Show help string as a tooltip
4454 wxString tipString
= m_propHover
->GetHelpString();
4456 SetToolTip(tipString
);
4460 // Show cropped value string as a tooltip
4464 if ( m_mouseSide
== 1 )
4466 tipString
= m_propHover
->m_label
;
4467 space
= splitterX
-m_marginWidth
-3;
4469 else if ( m_mouseSide
== 2 )
4471 tipString
= m_propHover
->GetDisplayedString();
4473 space
= m_width
- splitterX
;
4474 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4475 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4481 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4484 SetToolTip( tipString
);
4491 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4492 m_canvas
->SetToolTip( m_emptyString
);
4494 m_canvas
->SetToolTip( NULL
);
4505 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4506 m_canvas
->SetToolTip( m_emptyString
);
4508 m_canvas
->SetToolTip( NULL
);
4516 if ( splitterHit
== -1 ||
4518 HasFlag(wxPG_STATIC_SPLITTER
) )
4520 // hovering on something else
4521 if ( m_curcursor
!= wxCURSOR_ARROW
)
4522 CustomSetCursor( wxCURSOR_ARROW
);
4526 // Do not allow splitter cursor on caption items.
4527 // (also not if we were dragging and its started
4528 // outside the splitter region)
4531 !m_propHover
->IsCategory() &&
4535 // hovering on splitter
4537 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4538 // reliably detected.
4539 //if ( m_curcursor != wxCURSOR_SIZEWE )
4540 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4546 // hovering on something else
4547 if ( m_curcursor
!= wxCURSOR_ARROW
)
4548 CustomSetCursor( wxCURSOR_ARROW
);
4555 // -----------------------------------------------------------------------
4557 // Also handles Leaving event
4558 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4559 wxMouseEvent
&WXUNUSED(event
) )
4561 wxPropertyGridPageState
* state
= m_pState
;
4565 int splitterHitOffset
;
4566 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4568 // No event type check - basicly calling this method should
4569 // just stop dragging.
4570 // Left up after dragged?
4571 if ( m_dragStatus
>= 1 )
4574 // End Splitter Dragging
4576 // DO NOT ENABLE FOLLOWING LINE!
4577 // (it is only here as a reminder to not to do it)
4580 // Disable splitter auto-centering
4581 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4583 // This is necessary to return cursor
4584 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4586 m_canvas
->ReleaseMouse();
4587 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4590 // Set back the default cursor, if necessary
4591 if ( splitterHit
== -1 ||
4594 CustomSetCursor( wxCURSOR_ARROW
);
4599 // Control background needs to be cleared
4600 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4601 DrawItem( m_selected
);
4605 m_wndEditor
->Show ( true );
4608 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4609 // Fixes button disappearance bug
4611 m_wndEditor2
->Show ( true );
4614 // This clears the focus.
4615 m_editorFocused
= 0;
4621 // -----------------------------------------------------------------------
4623 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4625 int splitterX
= GetSplitterPosition();
4628 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4632 wxWindow
* wnd
= GetEditorControl();
4634 // Hide popup on clicks
4635 if ( event
.GetEventType() != wxEVT_MOTION
)
4636 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4638 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4644 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4646 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4647 ux
>= (r
.x
+r
.width
) ||
4649 event
.m_y
>= (r
.y
+r
.height
)
4659 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4664 // -----------------------------------------------------------------------
4666 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4669 if ( OnMouseCommon( event
, &x
, &y
) )
4671 HandleMouseClick(x
,y
,event
);
4676 // -----------------------------------------------------------------------
4678 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4681 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4682 HandleMouseRightClick(x
,y
,event
);
4686 // -----------------------------------------------------------------------
4688 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4690 // Always run standard mouse-down handler as well
4691 OnMouseClick(event
);
4694 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4695 HandleMouseDoubleClick(x
,y
,event
);
4699 // -----------------------------------------------------------------------
4701 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4704 if ( OnMouseCommon( event
, &x
, &y
) )
4706 HandleMouseMove(x
,y
,event
);
4711 // -----------------------------------------------------------------------
4713 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4715 // Called when mouse moves in the empty space below the properties.
4716 CustomSetCursor( wxCURSOR_ARROW
);
4719 // -----------------------------------------------------------------------
4721 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4724 if ( OnMouseCommon( event
, &x
, &y
) )
4726 HandleMouseUp(x
,y
,event
);
4731 // -----------------------------------------------------------------------
4733 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4735 // This may get called from child control as well, so event's
4736 // mouse position cannot be relied on.
4738 if ( event
.Entering() )
4740 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4742 // TODO: Fix this (detect parent and only do
4743 // cursor trick if it is a manager).
4744 wxASSERT( GetParent() );
4745 GetParent()->SetCursor(wxNullCursor
);
4747 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4750 GetParent()->SetCursor(wxNullCursor
);
4752 else if ( event
.Leaving() )
4754 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4755 m_canvas
->SetCursor( wxNullCursor
);
4757 // Get real cursor position
4758 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4760 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4763 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4765 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4769 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4777 // -----------------------------------------------------------------------
4779 // Common code used by various OnMouseXXXChild methods.
4780 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4782 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4783 wxASSERT( topCtrlWnd
);
4785 event
.GetPosition(&x
,&y
);
4787 int splitterX
= GetSplitterPosition();
4789 wxRect r
= topCtrlWnd
->GetRect();
4790 if ( !m_dragStatus
&&
4791 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4792 y
>= 0 && y
< r
.height \
4795 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4800 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4807 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4810 if ( OnMouseChildCommon(event
,&x
,&y
) )
4812 bool res
= HandleMouseClick(x
,y
,event
);
4813 if ( !res
) event
.Skip();
4817 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4820 wxASSERT( m_wndEditor
);
4821 // These coords may not be exact (about +-2),
4822 // but that should not matter (right click is about item, not position).
4823 wxPoint pt
= m_wndEditor
->GetPosition();
4824 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4825 wxASSERT( m_selected
);
4826 m_propHover
= m_selected
;
4827 bool res
= HandleMouseRightClick(x
,y
,event
);
4828 if ( !res
) event
.Skip();
4831 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4834 if ( OnMouseChildCommon(event
,&x
,&y
) )
4836 bool res
= HandleMouseMove(x
,y
,event
);
4837 if ( !res
) event
.Skip();
4841 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4844 if ( OnMouseChildCommon(event
,&x
,&y
) )
4846 bool res
= HandleMouseUp(x
,y
,event
);
4847 if ( !res
) event
.Skip();
4851 // -----------------------------------------------------------------------
4852 // wxPropertyGrid keyboard event handling
4853 // -----------------------------------------------------------------------
4855 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4857 // Translates wxKeyEvent to wxPG_ACTION_XXX
4859 int keycode
= event
.GetKeyCode();
4860 int modifiers
= event
.GetModifiers();
4862 wxASSERT( !(modifiers
&~(0xFFFF)) );
4864 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4866 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4868 if ( it
== m_actionTriggers
.end() )
4873 int second
= (it
->second
>>16) & 0xFFFF;
4877 return (it
->second
& 0xFFFF);
4880 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4882 wxASSERT( !(modifiers
&~(0xFFFF)) );
4884 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4886 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4888 if ( it
!= m_actionTriggers
.end() )
4890 // This key combination is already used
4892 // Can add secondary?
4893 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4894 wxT("You can only add up to two separate actions per key combination.") );
4896 action
= it
->second
| (action
<<16);
4899 m_actionTriggers
[hashMapKey
] = action
;
4902 void wxPropertyGrid::ClearActionTriggers( int action
)
4904 wxPGHashMapI2I::iterator it
;
4906 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4908 if ( it
->second
== action
)
4910 m_actionTriggers
.erase(it
);
4915 static void CopyTextToClipboard( const wxString
& text
)
4917 if ( wxTheClipboard
->Open() )
4919 // This data objects are held by the clipboard,
4920 // so do not delete them in the app.
4921 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4922 wxTheClipboard
->Close();
4926 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4929 // Handles key event when editor control is not focused.
4932 wxASSERT( !m_frozen
);
4936 // Travelsal between items, collapsing/expanding, etc.
4937 int keycode
= event
.GetKeyCode();
4939 if ( keycode
== WXK_TAB
)
4942 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4946 // Ignore Alt and Control when they are down alone
4947 if ( keycode
== WXK_ALT
||
4948 keycode
== WXK_CONTROL
)
4955 int action
= KeyEventToActions(event
, &secondAction
);
4961 if ( ButtonTriggerKeyTest(action
, event
) )
4964 wxPGProperty
* p
= m_selected
;
4966 if ( action
== wxPG_ACTION_COPY
)
4968 CopyTextToClipboard(p
->GetDisplayedString());
4972 // Travel and expand/collapse
4975 if ( p
->GetChildCount() &&
4976 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4979 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4981 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4984 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4986 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4993 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4997 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5008 if ( selectDir
>= -1 )
5010 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5012 DoSelectProperty(p
);
5018 // If nothing was selected, select the first item now
5019 // (or navigate out of tab).
5020 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5022 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5023 if ( p
) DoSelectProperty(p
);
5028 // -----------------------------------------------------------------------
5030 // Potentially handles a keyboard event for editor controls.
5031 // Returns false if event should *not* be skipped (on true it can
5032 // be optionally skipped).
5033 // Basicly, false means that SelectProperty was called (or was about
5034 // to be called, if canDestroy was false).
5035 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5039 if ( !m_selected
|| !m_wndEditor
)
5044 int action
= KeyEventToAction(event
);
5047 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5050 // Esc cancels any changes
5051 if ( IsEditorsValueModified() )
5053 EditorsValueWasNotModified();
5055 // Update the control as well
5056 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5058 m_selected
->GetDisplayedString() );
5061 OnValidationFailureReset(m_selected
);
5066 else if ( action
== wxPG_ACTION_COPY
)
5068 // NB: There is some problem with getting native cut-copy-paste keys to go through
5069 // for embedded editor wxTextCtrl. This is why we emulate.
5071 wxTextCtrl
* tc
= GetEditorTextCtrl();
5074 wxString sel
= tc
->GetStringSelection();
5076 CopyTextToClipboard(sel
);
5080 CopyTextToClipboard(m_selected
->GetDisplayedString());
5083 else if ( action
== wxPG_ACTION_CUT
)
5085 wxTextCtrl
* tc
= GetEditorTextCtrl();
5089 tc
->GetSelection(&from
, &to
);
5092 CopyTextToClipboard(tc
->GetStringSelection());
5093 tc
->Remove(from
, to
);
5097 else if ( action
== wxPG_ACTION_PASTE
)
5099 wxTextCtrl
* tc
= GetEditorTextCtrl();
5102 if (wxTheClipboard
->Open())
5104 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5106 wxTextDataObject data
;
5107 wxTheClipboard
->GetData( data
);
5109 tc
->GetSelection(&from
, &to
);
5112 tc
->Remove(from
, to
);
5113 tc
->WriteText(data
.GetText());
5117 tc
->WriteText(data
.GetText());
5120 wxTheClipboard
->Close();
5128 // -----------------------------------------------------------------------
5130 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5132 HandleKeyEvent( event
);
5135 // -----------------------------------------------------------------------
5137 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5142 // -----------------------------------------------------------------------
5144 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5149 action
= KeyEventToActions(event
, &secondAction
);
5152 // Does the keycode trigger button?
5153 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5156 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5157 GetEventHandler()->AddPendingEvent(evt
);
5164 // -----------------------------------------------------------------------
5166 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5168 int keycode
= event
.GetKeyCode();
5170 // Ignore Alt and Control when they are down alone
5171 if ( keycode
== WXK_ALT
||
5172 keycode
== WXK_CONTROL
)
5178 if ( ButtonTriggerKeyTest(-1, event
) )
5181 if ( HandleChildKey(event
) == true )
5184 GetEventHandler()->AddPendingEvent(event
);
5187 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5189 GetEventHandler()->AddPendingEvent(event
);
5194 // -----------------------------------------------------------------------
5195 // wxPropertyGrid miscellaneous event handling
5196 // -----------------------------------------------------------------------
5198 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5201 // Check if the focus is in this control or one of its children
5202 wxWindow
* newFocused
= wxWindow::FindFocus();
5204 if ( newFocused
!= m_curFocused
)
5205 HandleFocusChange( newFocused
);
5208 // Called by focus event handlers. newFocused is the window that becomes focused.
5209 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5211 unsigned int oldFlags
= m_iFlags
;
5213 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5215 wxWindow
* parent
= newFocused
;
5217 // This must be one of nextFocus' parents.
5220 // Use m_eventObject, which is either wxPropertyGrid or
5221 // wxPropertyGridManager, as appropriate.
5222 if ( parent
== m_eventObject
)
5224 m_iFlags
|= wxPG_FL_FOCUSED
;
5227 parent
= parent
->GetParent();
5230 m_curFocused
= newFocused
;
5232 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5233 (oldFlags
& wxPG_FL_FOCUSED
) )
5235 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5237 // Need to store changed value
5238 CommitChangesFromEditor();
5244 // Preliminary code for tab-order respecting
5245 // tab-traversal (but should be moved to
5248 wxWindow* prevFocus = event.GetWindow();
5249 wxWindow* useThis = this;
5250 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5251 useThis = GetParent();
5254 prevFocus->GetParent() == useThis->GetParent() )
5256 wxList& children = useThis->GetParent()->GetChildren();
5258 wxNode* node = children.Find(prevFocus);
5260 if ( node->GetNext() &&
5261 useThis == node->GetNext()->GetData() )
5262 DoSelectProperty(GetFirst());
5263 else if ( node->GetPrevious () &&
5264 useThis == node->GetPrevious()->GetData() )
5265 DoSelectProperty(GetLastProperty());
5272 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5273 DrawItem( m_selected
);
5277 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5279 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5280 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5281 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5282 //else if ( event.GetWindow() )
5284 HandleFocusChange(event
.GetWindow());
5289 // -----------------------------------------------------------------------
5291 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5293 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5296 // event.Skip() being commented out is aworkaround for bug reported
5297 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5301 // -----------------------------------------------------------------------
5303 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5305 m_iFlags
|= wxPG_FL_SCROLLED
;
5310 // -----------------------------------------------------------------------
5312 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5314 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5316 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5320 // -----------------------------------------------------------------------
5321 // Property editor related functions
5322 // -----------------------------------------------------------------------
5324 // noDefCheck = true prevents infinite recursion.
5325 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5328 wxASSERT( editorClass
);
5330 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5331 RegisterDefaultEditors();
5333 wxString name
= editorClass
->GetName();
5335 // Existing editor under this name?
5336 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5338 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5339 (wxPGEditor
*) vt_it
->second
,
5340 "Editor with given name was already registered" );
5342 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5347 // Registers all default editor classes
5348 void wxPropertyGrid::RegisterDefaultEditors()
5350 wxPGRegisterDefaultEditorClass( TextCtrl
);
5351 wxPGRegisterDefaultEditorClass( Choice
);
5352 wxPGRegisterDefaultEditorClass( ComboBox
);
5353 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5354 #if wxPG_INCLUDE_CHECKBOX
5355 wxPGRegisterDefaultEditorClass( CheckBox
);
5357 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5359 // Register SpinCtrl etc. editors before use
5360 RegisterAdditionalEditors();
5363 // -----------------------------------------------------------------------
5364 // wxPGStringTokenizer
5365 // Needed to handle C-style string lists (e.g. "str1" "str2")
5366 // -----------------------------------------------------------------------
5368 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5369 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5373 wxPGStringTokenizer::~wxPGStringTokenizer()
5377 bool wxPGStringTokenizer::HasMoreTokens()
5379 const wxString
& str
= *m_str
;
5381 wxString::const_iterator i
= m_curPos
;
5383 wxUniChar delim
= m_delimeter
;
5385 wxUniChar prev_a
= wxT('\0');
5387 bool inToken
= false;
5389 while ( i
!= str
.end() )
5398 m_readyToken
.clear();
5403 if ( prev_a
!= wxT('\\') )
5407 if ( a
!= wxT('\\') )
5427 m_curPos
= str
.end();
5435 wxString
wxPGStringTokenizer::GetNextToken()
5437 return m_readyToken
;
5440 // -----------------------------------------------------------------------
5442 // -----------------------------------------------------------------------
5444 wxPGChoiceEntry::wxPGChoiceEntry()
5445 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5449 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5450 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5451 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5455 // -----------------------------------------------------------------------
5457 // -----------------------------------------------------------------------
5459 wxPGChoicesData::wxPGChoicesData()
5464 wxPGChoicesData::~wxPGChoicesData()
5469 void wxPGChoicesData::Clear()
5473 for ( i
=0; i
<m_items
.size(); i
++ )
5481 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5483 wxASSERT( m_items
.size() == 0 );
5487 for ( i
=0; i
<data
->GetCount(); i
++ )
5488 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5491 // -----------------------------------------------------------------------
5493 // -----------------------------------------------------------------------
5495 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5499 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5500 m_data
->Insert( -1, p
);
5504 // -----------------------------------------------------------------------
5506 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5510 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5511 p
->SetBitmap(bitmap
);
5512 m_data
->Insert( -1, p
);
5516 // -----------------------------------------------------------------------
5518 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5522 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5523 m_data
->Insert(index
, p
);
5527 // -----------------------------------------------------------------------
5529 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5533 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5534 m_data
->Insert( index
, p
);
5538 // -----------------------------------------------------------------------
5540 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5546 while ( index
< GetCount() )
5548 int cmpRes
= GetLabel(index
).Cmp(label
);
5554 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5555 m_data
->Insert( index
, p
);
5559 // -----------------------------------------------------------------------
5561 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5565 unsigned int itemcount
= 0;
5566 const wxChar
** p
= &labels
[0];
5567 while ( *p
) { p
++; itemcount
++; }
5570 for ( i
= 0; i
< itemcount
; i
++ )
5572 int value
= wxPG_INVALID_VALUE
;
5575 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5579 // -----------------------------------------------------------------------
5581 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5586 unsigned int itemcount
= arr
.size();
5588 for ( i
= 0; i
< itemcount
; i
++ )
5590 int value
= wxPG_INVALID_VALUE
;
5593 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5597 // -----------------------------------------------------------------------
5599 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5604 unsigned int itemcount
= arr
.size();
5606 for ( i
= 0; i
< itemcount
; i
++ )
5608 int value
= wxPG_INVALID_VALUE
;
5609 if ( &arrint
&& arrint
.size() )
5611 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5615 // -----------------------------------------------------------------------
5617 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5619 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5621 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5622 delete m_data
->Item(i
);
5623 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5624 m_data
->m_items
.begin()+nIndex
+count
);
5627 // -----------------------------------------------------------------------
5629 int wxPGChoices::Index( const wxString
& str
) const
5634 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5636 if ( m_data
->Item(i
)->GetText() == str
)
5643 // -----------------------------------------------------------------------
5645 int wxPGChoices::Index( int val
) const
5650 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5652 if ( m_data
->Item(i
)->GetValue() == val
)
5659 // -----------------------------------------------------------------------
5661 wxArrayString
wxPGChoices::GetLabels() const
5666 if ( this && IsOk() )
5667 for ( i
=0; i
<GetCount(); i
++ )
5668 arr
.push_back(GetLabel(i
));
5673 // -----------------------------------------------------------------------
5675 bool wxPGChoices::HasValues() const
5680 // -----------------------------------------------------------------------
5682 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5689 for ( i
=0; i
< strings
.size(); i
++ )
5691 int index
= Index(strings
[i
]);
5693 arr
.Add(GetValue(index
));
5695 arr
.Add(wxPG_INVALID_VALUE
);
5702 // -----------------------------------------------------------------------
5704 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5705 wxArrayString
* unmatched
) const
5712 for ( i
=0; i
< strings
.size(); i
++ )
5714 const wxString
& str
= strings
[i
];
5715 int index
= Index(str
);
5718 else if ( unmatched
)
5719 unmatched
->Add(str
);
5726 // -----------------------------------------------------------------------
5728 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5732 if ( data
!= wxPGChoicesEmptyData
)
5739 // -----------------------------------------------------------------------
5741 void wxPGChoices::Init()
5743 m_data
= wxPGChoicesEmptyData
;
5746 // -----------------------------------------------------------------------
5748 void wxPGChoices::Free()
5750 if ( m_data
!= wxPGChoicesEmptyData
)
5753 m_data
= wxPGChoicesEmptyData
;
5757 // -----------------------------------------------------------------------
5758 // wxPropertyGridEvent
5759 // -----------------------------------------------------------------------
5761 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5764 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5765 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5766 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5767 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5768 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5769 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5770 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5771 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5772 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5775 // -----------------------------------------------------------------------
5777 void wxPropertyGridEvent::Init()
5779 m_validationInfo
= NULL
;
5781 m_wasVetoed
= false;
5784 // -----------------------------------------------------------------------
5786 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5787 : wxCommandEvent(commandType
,id
)
5793 // -----------------------------------------------------------------------
5795 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5796 : wxCommandEvent(event
)
5798 m_eventType
= event
.GetEventType();
5799 m_eventObject
= event
.m_eventObject
;
5801 m_property
= event
.m_property
;
5802 m_validationInfo
= event
.m_validationInfo
;
5803 m_canVeto
= event
.m_canVeto
;
5804 m_wasVetoed
= event
.m_wasVetoed
;
5807 // -----------------------------------------------------------------------
5809 wxPropertyGridEvent::~wxPropertyGridEvent()
5813 // -----------------------------------------------------------------------
5815 wxEvent
* wxPropertyGridEvent::Clone() const
5817 return new wxPropertyGridEvent( *this );
5820 // -----------------------------------------------------------------------
5821 // wxPropertyGridPopulator
5822 // -----------------------------------------------------------------------
5824 wxPropertyGridPopulator::wxPropertyGridPopulator()
5828 wxPGGlobalVars
->m_offline
++;
5831 // -----------------------------------------------------------------------
5833 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5836 m_propHierarchy
.clear();
5839 // -----------------------------------------------------------------------
5841 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5847 // -----------------------------------------------------------------------
5849 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5852 // Free unused sets of choices
5853 wxPGHashMapS2P::iterator it
;
5855 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5857 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5864 m_pg
->GetPanel()->Refresh();
5866 wxPGGlobalVars
->m_offline
--;
5869 // -----------------------------------------------------------------------
5871 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5872 const wxString
& propLabel
,
5873 const wxString
& propName
,
5874 const wxString
* propValue
,
5875 wxPGChoices
* pChoices
)
5877 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5878 wxPGProperty
* parent
= GetCurParent();
5880 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5882 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5886 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5888 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5892 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5894 property
->SetLabel(propLabel
);
5895 property
->DoSetName(propName
);
5897 if ( pChoices
&& pChoices
->IsOk() )
5898 property
->SetChoices(*pChoices
);
5900 m_state
->DoInsert(parent
, -1, property
);
5903 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
5908 // -----------------------------------------------------------------------
5910 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5912 m_propHierarchy
.push_back(property
);
5913 DoScanForChildren();
5914 m_propHierarchy
.pop_back();
5917 // -----------------------------------------------------------------------
5919 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5920 const wxString
& idString
)
5922 wxPGChoices choices
;
5925 if ( choicesString
[0] == wxT('@') )
5927 wxString ids
= choicesString
.substr(1);
5928 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5929 if ( it
== m_dictIdChoices
.end() )
5930 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5932 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5937 if ( idString
.length() )
5939 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5940 if ( it
!= m_dictIdChoices
.end() )
5942 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5949 // Parse choices string
5950 wxString::const_iterator it
= choicesString
.begin();
5954 bool labelValid
= false;
5956 for ( ; it
!= choicesString
.end(); it
++ )
5962 if ( c
== wxT('"') )
5967 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5968 choices
.Add(label
, l
);
5971 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5976 else if ( c
== wxT('=') )
5983 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5990 if ( c
== wxT('"') )
6003 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6004 choices
.Add(label
, l
);
6007 if ( !choices
.IsOk() )
6009 choices
.EnsureData();
6013 if ( idString
.length() )
6014 m_dictIdChoices
[idString
] = choices
.GetData();
6021 // -----------------------------------------------------------------------
6023 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6025 if ( s
.Last() == wxT('%') )
6027 wxString s2
= s
.substr(0,s
.length()-1);
6029 if ( s2
.ToLong(&val
, 10) )
6031 *pval
= (val
*max
)/100;
6037 return s
.ToLong(pval
, 10);
6040 // -----------------------------------------------------------------------
6042 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6043 const wxString
& type
,
6044 const wxString
& value
)
6046 int l
= m_propHierarchy
.size();
6050 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6051 wxString valuel
= value
.Lower();
6054 if ( type
.length() == 0 )
6059 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6061 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6063 else if ( value
.ToLong(&v
, 0) )
6070 if ( type
== wxT("string") )
6074 else if ( type
== wxT("int") )
6077 value
.ToLong(&v
, 0);
6080 else if ( type
== wxT("bool") )
6082 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6089 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6094 p
->SetAttribute( name
, variant
);
6099 // -----------------------------------------------------------------------
6101 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6103 wxLogError(_("Error in resource: %s"),msg
.c_str());
6106 // -----------------------------------------------------------------------
6108 #endif // wxUSE_PROPGRID