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 #if !defined(__WXMAC__)
1178 bool res
= wxScrolledWindow::SetFont( font
);
1181 CalculateFontAndBitmapStuff( m_vspacing
);
1184 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1192 // TODO: Remove after SetFont crash fixed.
1193 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1195 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."));
1201 // -----------------------------------------------------------------------
1203 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1206 m_coloursCustomized
|= 0x80;
1210 // -----------------------------------------------------------------------
1212 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1215 m_coloursCustomized
|= 0x01;
1219 // -----------------------------------------------------------------------
1221 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1223 m_colPropBack
= col
;
1224 m_coloursCustomized
|= 0x08;
1226 // Set the cached brush as well.
1227 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1232 // -----------------------------------------------------------------------
1234 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1236 m_colPropFore
= col
;
1237 m_coloursCustomized
|= 0x10;
1239 // Set the cached colour as well.
1240 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1245 // -----------------------------------------------------------------------
1247 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1249 m_colEmptySpace
= col
;
1254 // -----------------------------------------------------------------------
1256 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1258 m_colDisPropFore
= col
;
1259 m_coloursCustomized
|= 0x100;
1263 // -----------------------------------------------------------------------
1265 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1268 m_coloursCustomized
|= 0x20;
1272 // -----------------------------------------------------------------------
1274 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1277 m_coloursCustomized
|= 0x40;
1281 // -----------------------------------------------------------------------
1283 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1286 m_coloursCustomized
|= 0x02;
1290 // -----------------------------------------------------------------------
1292 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1295 m_coloursCustomized
|= 0x04;
1297 // Set the cached colour as well.
1298 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1303 // -----------------------------------------------------------------------
1305 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1307 unsigned char ind
= index
;
1309 p
->m_bgColIndex
= ind
;
1312 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1313 SetBackgroundColourIndex(p
->Item(i
),index
);
1316 // -----------------------------------------------------------------------
1318 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1320 wxPG_PROP_ARG_CALL_PROLOG()
1325 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1327 // As it is most likely that the previous colour is used, start comparison
1329 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1331 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1340 colInd
= m_arrBgBrushes
.size();
1341 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1342 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1346 SetBackgroundColourIndex(p
,colInd
);
1348 // If this was on a visible grid, then draw it.
1349 DrawItemAndChildren(p
);
1352 // -----------------------------------------------------------------------
1354 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1356 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1358 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1361 // -----------------------------------------------------------------------
1363 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1365 unsigned char ind
= index
;
1367 p
->m_fgColIndex
= ind
;
1369 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1372 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1373 SetTextColourIndex( p
->Item(i
), index
, flags
);
1377 // -----------------------------------------------------------------------
1379 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1384 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1386 // As it is most likely that the previous colour is used, start comparison
1388 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1390 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1399 colInd
= m_arrFgCols
.size();
1400 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1401 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1407 // -----------------------------------------------------------------------
1409 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1412 wxPG_PROP_ARG_CALL_PROLOG()
1414 if ( p
->IsCategory() )
1416 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1417 cat
->SetTextColIndex(CacheColour(colour
));
1423 flags
|= wxPG_RECURSE
;
1424 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1426 DrawItemAndChildren(p
);
1429 // -----------------------------------------------------------------------
1431 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1433 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1435 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1438 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1440 wxPG_PROP_ARG_CALL_PROLOG()
1442 SetBackgroundColourIndex( p
, 0 );
1443 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1445 if ( p
->IsCategory() )
1447 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1448 cat
->SetTextColIndex(1);
1452 // -----------------------------------------------------------------------
1453 // wxPropertyGrid property adding and removal
1454 // -----------------------------------------------------------------------
1456 void wxPropertyGrid::PrepareAfterItemsAdded()
1458 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1460 m_pState
->m_itemsAdded
= 0;
1462 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1465 RecalculateVirtualSize();
1468 // -----------------------------------------------------------------------
1469 // wxPropertyGrid property value setting and getting
1470 // -----------------------------------------------------------------------
1472 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1474 m_pState
->DoSetPropertyValueUnspecified(p
);
1475 DrawItemAndChildren(p
);
1477 wxPGProperty
* parent
= p
->GetParent();
1478 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1481 parent
= parent
->GetParent();
1485 // -----------------------------------------------------------------------
1486 // wxPropertyGrid property operations
1487 // -----------------------------------------------------------------------
1489 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1491 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1495 bool changed
= false;
1497 // Is it inside collapsed section?
1498 if ( !p
->IsVisible() )
1501 wxPGProperty
* parent
= p
->GetParent();
1502 wxPGProperty
* grandparent
= parent
->GetParent();
1504 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1505 Expand( grandparent
);
1513 GetViewStart(&vx
,&vy
);
1514 vy
*=wxPG_PIXELS_PER_UNIT
;
1520 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1521 m_iFlags
|= wxPG_FL_SCROLLED
;
1524 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1526 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1527 m_iFlags
|= wxPG_FL_SCROLLED
;
1537 // -----------------------------------------------------------------------
1538 // wxPropertyGrid helper methods called by properties
1539 // -----------------------------------------------------------------------
1541 // Control font changer helper.
1542 void wxPropertyGrid::SetCurControlBoldFont()
1544 wxASSERT( m_wndEditor
);
1545 m_wndEditor
->SetFont( m_captionFont
);
1548 // -----------------------------------------------------------------------
1550 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1553 #if wxPG_SMALL_SCREEN
1554 // On small-screen devices, always show dialogs with default position and size.
1555 return wxDefaultPosition
;
1557 int splitterX
= GetSplitterPosition();
1561 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1563 ImprovedClientToScreen( &x
, &y
);
1565 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1566 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1573 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1583 new_y
= y
+ m_lineHeight
;
1585 return wxPoint(new_x
,new_y
);
1589 // -----------------------------------------------------------------------
1591 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1593 if ( src_str
.length() == 0 )
1599 bool prev_is_slash
= false;
1601 wxString::const_iterator i
= src_str
.begin();
1605 for ( ; i
!= src_str
.end(); i
++ )
1609 if ( a
!= wxS('\\') )
1611 if ( !prev_is_slash
)
1617 if ( a
== wxS('n') )
1620 dst_str
<< wxS('\n');
1622 dst_str
<< wxS('\n');
1625 else if ( a
== wxS('t') )
1626 dst_str
<< wxS('\t');
1630 prev_is_slash
= false;
1634 if ( prev_is_slash
)
1636 dst_str
<< wxS('\\');
1637 prev_is_slash
= false;
1641 prev_is_slash
= true;
1648 // -----------------------------------------------------------------------
1650 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1652 if ( src_str
.length() == 0 )
1658 wxString::const_iterator i
= src_str
.begin();
1659 wxUniChar prev_a
= wxS('\0');
1663 for ( ; i
!= src_str
.end(); i
++ )
1667 if ( a
>= wxS(' ') )
1669 // This surely is not something that requires an escape sequence.
1674 // This might need...
1675 if ( a
== wxS('\r') )
1677 // DOS style line end.
1678 // Already taken care below
1680 else if ( a
== wxS('\n') )
1681 // UNIX style line end.
1682 dst_str
<< wxS("\\n");
1683 else if ( a
== wxS('\t') )
1685 dst_str
<< wxS('\t');
1688 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1698 // -----------------------------------------------------------------------
1700 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1704 return (wxPGProperty
*) NULL
;
1707 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1710 // -----------------------------------------------------------------------
1711 // wxPropertyGrid graphics related methods
1712 // -----------------------------------------------------------------------
1714 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1718 // Update everything inside the box
1719 wxRect r
= GetUpdateRegion().GetBox();
1721 dc
.SetPen(m_colEmptySpace
);
1722 dc
.SetBrush(m_colEmptySpace
);
1723 dc
.DrawRectangle(r
);
1726 // -----------------------------------------------------------------------
1728 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1729 wxPGProperty
* property
) const
1731 // Prepare rectangle to be used
1733 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1734 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1736 #if (wxPG_USE_RENDERER_NATIVE)
1738 #elif wxPG_ICON_WIDTH
1739 // Drawing expand/collapse button manually
1740 dc
.SetPen(m_colPropFore
);
1741 if ( property
->IsCategory() )
1742 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1744 dc
.SetBrush(m_colPropBack
);
1746 dc
.DrawRectangle( r
);
1747 int _y
= r
.y
+(m_iconWidth
/2);
1748 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1753 if ( property
->IsExpanded() )
1755 // wxRenderer functions are non-mutating in nature, so it
1756 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1757 // Hopefully this does not cause problems.
1758 #if (wxPG_USE_RENDERER_NATIVE)
1759 wxRendererNative::Get().DrawTreeItemButton(
1765 #elif wxPG_ICON_WIDTH
1774 #if (wxPG_USE_RENDERER_NATIVE)
1775 wxRendererNative::Get().DrawTreeItemButton(
1781 #elif wxPG_ICON_WIDTH
1782 int _x
= r
.x
+(m_iconWidth
/2);
1783 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1789 #if (wxPG_USE_RENDERER_NATIVE)
1791 #elif wxPG_ICON_WIDTH
1794 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1798 // -----------------------------------------------------------------------
1801 // This is the one called by OnPaint event handler and others.
1802 // topy and bottomy are already unscrolled (ie. physical)
1804 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1806 unsigned int bottomy
,
1807 const wxRect
* clipRect
)
1809 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1811 m_pState
->EnsureVirtualHeight();
1813 wxRect tempClipRect
;
1816 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1817 clipRect
= &tempClipRect
;
1820 // items added check
1821 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1823 int paintFinishY
= 0;
1825 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1828 bool isBuffered
= false;
1830 #if wxPG_DOUBLE_BUFFER
1831 wxMemoryDC
* bufferDC
= NULL
;
1833 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1835 if ( !m_doubleBuffer
)
1837 paintFinishY
= clipRect
->y
;
1842 bufferDC
= new wxMemoryDC();
1844 // If nothing was changed, then just copy from double-buffer
1845 bufferDC
->SelectObject( *m_doubleBuffer
);
1855 dc
.SetClippingRegion( *clipRect
);
1856 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1859 #if wxPG_DOUBLE_BUFFER
1862 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1863 bufferDC
, 0, 0, wxCOPY
);
1864 dc
.DestroyClippingRegion(); // Is this really necessary?
1870 // Clear area beyond bottomY?
1871 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1873 dc
.SetPen(m_colEmptySpace
);
1874 dc
.SetBrush(m_colEmptySpace
);
1875 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1879 // -----------------------------------------------------------------------
1881 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1882 const wxPGProperty
* firstItem
,
1883 const wxPGProperty
* lastItem
,
1884 const wxRect
* clipRect
,
1885 bool isBuffered
) const
1887 // TODO: This should somehow be eliminated.
1888 wxRect tempClipRect
;
1891 wxASSERT(firstItem
);
1893 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1894 clipRect
= &tempClipRect
;
1898 firstItem
= DoGetItemAtY(clipRect
->y
);
1902 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1904 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1907 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1910 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1911 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1913 int lh
= m_lineHeight
;
1916 int lastItemBottomY
;
1918 firstItemTopY
= clipRect
->y
;
1919 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1921 // Align y coordinates to item boundaries
1922 firstItemTopY
-= firstItemTopY
% lh
;
1923 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1924 lastItemBottomY
-= 1;
1926 // Entire range outside scrolled, visible area?
1927 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1930 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1934 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1935 firstItem->GetLabel().c_str(),
1936 lastItem->GetLabel().c_str(),
1937 (int)(lastItemBottomY - firstItemTopY),
1939 (unsigned long)clipRect );
1944 long windowStyle
= m_windowStyle
;
1950 // With wxPG_DOUBLE_BUFFER, do double buffering
1951 // - buffer's y = 0, so align cliprect and coordinates to that
1953 #if wxPG_DOUBLE_BUFFER
1959 xRelMod
= clipRect
->x
;
1960 yRelMod
= clipRect
->y
;
1963 // clipRect conversion
1971 firstItemTopY
-= yRelMod
;
1972 lastItemBottomY
-= yRelMod
;
1975 wxUnusedVar(isBuffered
);
1978 int x
= m_marginWidth
- xRelMod
;
1980 const wxFont
& normalfont
= m_font
;
1982 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1984 bool isEnabled
= IsEnabled();
1987 // Prepare some pens and brushes that are often changed to.
1990 wxBrush
marginBrush(m_colMargin
);
1991 wxPen
marginPen(m_colMargin
);
1992 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1993 wxPen
linepen(m_colLine
,1,wxSOLID
);
1995 // pen that has same colour as text
1996 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1999 // Clear margin with background colour
2001 dc
.SetBrush( marginBrush
);
2002 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2004 dc
.SetPen( *wxTRANSPARENT_PEN
);
2005 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2008 const wxPGProperty
* selected
= m_selected
;
2009 const wxPropertyGridPageState
* state
= m_pState
;
2011 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2012 bool wasSelectedPainted
= false;
2015 // TODO: Only render columns that are within clipping region.
2017 dc
.SetFont(normalfont
);
2019 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2020 int endScanBottomY
= lastItemBottomY
+ lh
;
2021 int y
= firstItemTopY
;
2024 // Pregenerate list of visible properties.
2025 wxArrayPGProperty visPropArray
;
2026 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2028 for ( ; !it
.AtEnd(); it
.Next() )
2030 const wxPGProperty
* p
= *it
;
2032 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2034 visPropArray
.push_back((wxPGProperty
*)p
);
2036 if ( y
> endScanBottomY
)
2043 visPropArray
.push_back(NULL
);
2045 wxPGProperty
* nextP
= visPropArray
[0];
2047 int gridWidth
= state
->m_width
;
2050 for ( unsigned int arrInd
=1;
2051 nextP
&& y
<= lastItemBottomY
;
2054 wxPGProperty
* p
= nextP
;
2055 nextP
= visPropArray
[arrInd
];
2057 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2058 int textMarginHere
= x
;
2059 int renderFlags
= wxPGCellRenderer::Control
;
2061 int greyDepth
= m_marginWidth
;
2062 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2063 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2065 int greyDepthX
= greyDepth
- xRelMod
;
2067 // Use basic depth if in non-categoric mode and parent is base array.
2068 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2070 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2073 // Paint margin area
2074 dc
.SetBrush(marginBrush
);
2075 dc
.SetPen(marginPen
);
2076 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2078 dc
.SetPen( linepen
);
2083 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2089 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2091 sx
+= state
->m_colWidths
[si
];
2092 dc
.DrawLine( sx
, y
, sx
, y2
);
2095 // Horizontal Line, below
2096 // (not if both this and next is category caption)
2097 if ( p
->IsCategory() &&
2098 nextP
&& nextP
->IsCategory() )
2099 dc
.SetPen(m_colCapBack
);
2101 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2103 if ( p
== selected
)
2105 renderFlags
|= wxPGCellRenderer::Selected
;
2106 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2107 wasSelectedPainted
= true;
2115 if ( p
->IsCategory() )
2117 if ( p
->m_fgColIndex
== 0 )
2118 rowFgCol
= m_colCapFore
;
2120 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2121 rowBgBrush
= wxBrush(m_colCapBack
);
2123 else if ( p
!= selected
)
2125 // Disabled may get different colour.
2126 if ( !p
->IsEnabled() )
2127 rowFgCol
= m_colDisPropFore
;
2129 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2131 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2135 // Selected gets different colour.
2136 if ( reallyFocused
)
2138 rowFgCol
= m_colSelFore
;
2139 rowBgBrush
= wxBrush(m_colSelBack
);
2141 else if ( isEnabled
)
2143 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2144 rowBgBrush
= marginBrush
;
2148 rowFgCol
= m_colDisPropFore
;
2149 rowBgBrush
= wxBrush(m_colSelBack
);
2153 bool fontChanged
= false;
2155 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2160 if ( p
->IsCategory() )
2162 // Captions are all cells merged as one
2163 dc
.SetFont(m_captionFont
);
2165 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2167 dc
.SetBrush(rowBgBrush
);
2168 dc
.SetPen(rowBgBrush
.GetColour());
2169 dc
.SetTextForeground(rowFgCol
);
2171 dc
.DrawRectangle(cellRect
);
2174 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2175 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2178 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2179 DrawExpanderButton( dc
, butRect
, p
);
2183 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2185 dc
.SetFont(m_captionFont
);
2191 int nextCellWidth
= state
->m_colWidths
[0];
2192 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2193 int textXAdd
= textMarginHere
- greyDepthX
;
2195 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2197 cellRect
.width
= nextCellWidth
- 1;
2199 bool ctrlCell
= false;
2202 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2204 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2205 dc
.SetBrush(editorBgCol
);
2206 dc
.SetPen(editorBgCol
);
2207 dc
.SetTextForeground(m_colPropFore
);
2209 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2214 dc
.SetBrush(rowBgBrush
);
2215 dc
.SetPen(rowBgBrush
.GetColour());
2216 dc
.SetTextForeground(rowFgCol
);
2219 dc
.DrawRectangle(cellRect
);
2222 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2223 DrawExpanderButton( dc
, butRect
, p
);
2225 dc
.SetClippingRegion(cellRect
);
2227 cellRect
.x
+= textXAdd
;
2228 cellRect
.width
-= textXAdd
;
2233 wxPGCellRenderer
* renderer
;
2234 int cmnVal
= p
->GetCommonValue();
2235 if ( cmnVal
== -1 || ci
!= 1 )
2237 renderer
= p
->GetCellRenderer(ci
);
2238 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2242 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2243 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2247 cellX
+= state
->m_colWidths
[ci
];
2248 if ( ci
< (state
->m_colWidths
.size()-1) )
2249 nextCellWidth
= state
->m_colWidths
[ci
+1];
2251 dc
.DestroyClippingRegion(); // Is this really necessary?
2257 dc
.SetFont(normalfont
);
2262 // Refresh editor controls (seems not needed on msw)
2263 // NOTE: This code is mandatory for GTK!
2264 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2265 if ( wasSelectedPainted
)
2268 m_wndEditor
->Refresh();
2270 m_wndEditor2
->Refresh();
2277 // -----------------------------------------------------------------------
2279 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2283 if ( m_width
< 10 || m_height
< 10 ||
2284 !m_pState
->m_properties
->GetChildCount() ||
2285 p1
== (wxPGProperty
*) NULL
)
2286 return wxRect(0,0,0,0);
2291 // Return rect which encloses the given property range
2293 int visTop
= p1
->GetY();
2296 visBottom
= p2
->GetY() + m_lineHeight
;
2298 visBottom
= m_height
+ visTop
;
2300 // If seleced property is inside the range, we'll extend the range to include
2302 wxPGProperty
* selected
= m_selected
;
2305 int selectedY
= selected
->GetY();
2306 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2308 wxWindow
* editor
= GetEditorControl();
2311 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2312 if ( visBottom2
> visBottom
)
2313 visBottom
= visBottom2
;
2318 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2321 // -----------------------------------------------------------------------
2323 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2328 if ( m_pState
->m_itemsAdded
)
2329 PrepareAfterItemsAdded();
2331 wxRect r
= GetPropertyRect(p1
, p2
);
2334 m_canvas
->RefreshRect(r
);
2338 // -----------------------------------------------------------------------
2340 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2342 if ( p
== m_selected
)
2343 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2345 DrawItemAndChildren(p
);
2348 // -----------------------------------------------------------------------
2350 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2355 // Draw item, children, and parent too, if it is not category
2356 wxPGProperty
* parent
= p
->GetParent();
2359 !parent
->IsCategory() &&
2360 parent
->GetParent() )
2363 parent
= parent
->GetParent();
2366 DrawItemAndChildren(p
);
2369 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2371 wxCHECK_RET( p
, wxT("invalid property id") );
2373 // Do not draw if in non-visible page
2374 if ( p
->GetParentState() != m_pState
)
2377 // do not draw a single item if multiple pending
2378 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2381 wxWindow
* wndPrimary
= GetEditorControl();
2383 // Update child control.
2384 if ( m_selected
&& m_selected
->GetParent() == p
)
2385 m_selected
->UpdateControl(wndPrimary
);
2387 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2389 DrawItems(p
, lastDrawn
);
2392 // -----------------------------------------------------------------------
2394 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2395 const wxRect
*rect
)
2397 PrepareAfterItemsAdded();
2399 wxWindow::Refresh(false);
2401 // TODO: Coordinate translation
2402 m_canvas
->Refresh(false, rect
);
2404 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2405 // I think this really helps only GTK+1.2
2406 if ( m_wndEditor
) m_wndEditor
->Refresh();
2407 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2411 // -----------------------------------------------------------------------
2412 // wxPropertyGrid global operations
2413 // -----------------------------------------------------------------------
2415 void wxPropertyGrid::Clear()
2419 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2420 wxPG_CHECK_RET_DBG( selRes
,
2421 wxT("failed to deselect a property (editor probably had invalid value)") );
2424 m_pState
->DoClear();
2430 RecalculateVirtualSize();
2432 // Need to clear some area at the end
2434 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2437 // -----------------------------------------------------------------------
2439 bool wxPropertyGrid::EnableCategories( bool enable
)
2441 if ( !ClearSelection() )
2447 // Enable categories
2450 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2455 // Disable categories
2457 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2460 if ( !m_pState
->EnableCategories(enable
) )
2465 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2467 m_pState
->m_itemsAdded
= 1; // force
2468 PrepareAfterItemsAdded();
2472 m_pState
->m_itemsAdded
= 1;
2474 // No need for RecalculateVirtualSize() here - it is already called in
2475 // wxPropertyGridPageState method above.
2482 // -----------------------------------------------------------------------
2484 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2486 wxASSERT( pNewState
);
2487 wxASSERT( pNewState
->GetGrid() );
2489 if ( pNewState
== m_pState
)
2492 wxPGProperty
* oldSelection
= m_selected
;
2497 bool selRes
= ClearSelection();
2498 wxPG_CHECK_RET_DBG( selRes
,
2499 wxT("failed to deselect a property (editor probably had invalid value)") );
2502 m_pState
->m_selected
= oldSelection
;
2504 bool orig_mode
= m_pState
->IsInNonCatMode();
2505 bool new_state_mode
= pNewState
->IsInNonCatMode();
2507 m_pState
= pNewState
;
2510 int pgWidth
= GetClientSize().x
;
2511 if ( HasVirtualWidth() )
2513 int minWidth
= pgWidth
;
2514 if ( pNewState
->m_width
< minWidth
)
2516 pNewState
->m_width
= minWidth
;
2517 pNewState
->CheckColumnWidths();
2523 // Just in case, fully re-center splitter
2524 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2525 pNewState
->m_fSplitterX
= -1.0;
2527 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2530 m_propHover
= (wxPGProperty
*) NULL
;
2532 // If necessary, convert state to correct mode.
2533 if ( orig_mode
!= new_state_mode
)
2535 // This should refresh as well.
2536 EnableCategories( orig_mode
?false:true );
2538 else if ( !m_frozen
)
2540 // Refresh, if not frozen.
2541 if ( m_pState
->m_itemsAdded
)
2542 PrepareAfterItemsAdded();
2545 if ( m_pState
->m_selected
)
2546 DoSelectProperty( m_pState
->m_selected
);
2548 RecalculateVirtualSize(0);
2552 m_pState
->m_itemsAdded
= 1;
2555 // -----------------------------------------------------------------------
2557 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2559 wxPG_PROP_ARG_CALL_PROLOG()
2561 m_pState
->SortChildren( p
);
2564 // -----------------------------------------------------------------------
2566 void wxPropertyGrid::Sort()
2568 bool selRes
= ClearSelection(); // This must be before state clear
2569 wxPG_CHECK_RET_DBG( selRes
,
2570 wxT("failed to deselect a property (editor probably had invalid value)") );
2575 // -----------------------------------------------------------------------
2577 // Call to SetSplitterPosition will always disable splitter auto-centering
2578 // if parent window is shown.
2579 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2581 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2584 wxPropertyGridPageState
* state
= m_pState
;
2586 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2591 CorrectEditorWidgetSizeX();
2597 // -----------------------------------------------------------------------
2599 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2601 SetSplitterPosition( m_width
/2, true );
2602 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2603 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2606 // -----------------------------------------------------------------------
2607 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2608 // -----------------------------------------------------------------------
2610 // Returns nearest paint visible property (such that will be painted unless
2611 // window is scrolled or resized). If given property is paint visible, then
2612 // it itself will be returned
2613 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2615 int vx
,vy1
;// Top left corner of client
2616 GetViewStart(&vx
,&vy1
);
2617 vy1
*= wxPG_PIXELS_PER_UNIT
;
2619 int vy2
= vy1
+ m_height
;
2620 int propY
= p
->GetY2(m_lineHeight
);
2622 if ( (propY
+ m_lineHeight
) < vy1
)
2625 return DoGetItemAtY( vy1
);
2627 else if ( propY
> vy2
)
2630 return DoGetItemAtY( vy2
);
2633 // Itself paint visible
2638 // -----------------------------------------------------------------------
2639 // Methods related to change in value, value modification and sending events
2640 // -----------------------------------------------------------------------
2642 // commits any changes in editor of selected property
2643 // return true if validation did not fail
2644 // flags are same as with DoSelectProperty
2645 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2647 // Committing already?
2648 if ( m_inCommitChangesFromEditor
)
2651 // Don't do this if already processing editor event. It might
2652 // induce recursive dialogs and crap like that.
2653 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2655 if ( m_inDoPropertyChanged
)
2662 IsEditorsValueModified() &&
2663 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2666 m_inCommitChangesFromEditor
= 1;
2668 wxVariant
variant(m_selected
->GetValueRef());
2669 bool valueIsPending
= false;
2671 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2672 // due to another window getting focus
2673 wxWindow
* oldFocus
= m_curFocused
;
2675 bool validationFailure
= false;
2676 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2678 m_chgInfo_changedProperty
= NULL
;
2680 // If truly modified, schedule value as pending.
2681 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2683 if ( DoEditorValidate() &&
2684 PerformValidation(m_selected
, variant
) )
2686 valueIsPending
= true;
2690 validationFailure
= true;
2695 EditorsValueWasNotModified();
2700 m_inCommitChangesFromEditor
= 0;
2702 if ( validationFailure
&& !forceSuccess
)
2706 oldFocus
->SetFocus();
2707 m_curFocused
= oldFocus
;
2710 res
= OnValidationFailure(m_selected
, variant
);
2712 // Now prevent further validation failure messages
2715 EditorsValueWasNotModified();
2716 OnValidationFailureReset(m_selected
);
2719 else if ( valueIsPending
)
2721 DoPropertyChanged( m_selected
, flags
);
2722 EditorsValueWasNotModified();
2731 // -----------------------------------------------------------------------
2733 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2736 // Runs all validation functionality.
2737 // Returns true if value passes all tests.
2740 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2742 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2744 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2749 // Adapt list to child values, if necessary
2750 wxVariant listValue
= pendingValue
;
2751 wxVariant
* pPendingValue
= &pendingValue
;
2752 wxVariant
* pList
= NULL
;
2754 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2755 // string value, then we need treat as it was changed instead
2756 // (or, in addition, as is the case with composite string parent).
2757 // This includes creating list variant for child values.
2759 wxPGProperty
* pwc
= p
->GetParent();
2760 wxPGProperty
* changedProperty
= p
;
2761 wxPGProperty
* baseChangedProperty
= changedProperty
;
2762 wxVariant bcpPendingList
;
2764 listValue
= pendingValue
;
2765 listValue
.SetName(p
->GetBaseName());
2768 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2770 wxVariantList tempList
;
2771 wxVariant
lv(tempList
, pwc
->GetBaseName());
2772 lv
.Append(listValue
);
2774 pPendingValue
= &listValue
;
2776 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2778 baseChangedProperty
= pwc
;
2779 bcpPendingList
= lv
;
2782 changedProperty
= pwc
;
2783 pwc
= pwc
->GetParent();
2787 wxPGProperty
* evtChangingProperty
= changedProperty
;
2789 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2791 value
= *pPendingValue
;
2795 // Convert list to child values
2796 pList
= pPendingValue
;
2797 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2800 wxVariant evtChangingValue
= value
;
2802 // FIXME: After proper ValueToString()s added, remove
2803 // this. It is just a temporary fix, as evt_changing
2804 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2805 // (unless it is selected, and textctrl editor is open).
2806 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2808 evtChangingProperty
= baseChangedProperty
;
2809 if ( evtChangingProperty
!= p
)
2811 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2815 evtChangingValue
= pendingValue
;
2819 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2821 if ( changedProperty
== m_selected
)
2823 wxWindow
* editor
= GetEditorControl();
2824 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2825 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2829 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2833 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2834 m_chgInfo_changedProperty
= changedProperty
;
2835 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2836 m_chgInfo_pendingValue
= value
;
2839 m_chgInfo_valueList
= *pList
;
2841 m_chgInfo_valueList
.MakeNull();
2843 // If changedProperty is not property which value was edited,
2844 // then call wxPGProperty::ValidateValue() for that as well.
2845 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2847 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2851 // SendEvent returns true if event was vetoed
2852 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2858 // -----------------------------------------------------------------------
2860 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2862 if ( !msg
.length() )
2866 if ( !wxPGGlobalVars
->m_offline
)
2868 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2871 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2874 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2877 pStatusBar
->SetStatusText(msg
);
2885 ::wxMessageBox(msg
, _T("Property Error"));
2888 // -----------------------------------------------------------------------
2890 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2892 int vfb
= m_validationInfo
.m_failureBehavior
;
2894 if ( vfb
& wxPG_VFB_BEEP
)
2897 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2898 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2900 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2901 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2903 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2905 wxColour vfbFg
= *wxWHITE
;
2906 wxColour vfbBg
= *wxRED
;
2907 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2908 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2910 DrawItemAndChildren(property
);
2912 if ( property
== m_selected
)
2914 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2916 wxWindow
* editor
= GetEditorControl();
2919 editor
->SetForegroundColour(vfbFg
);
2920 editor
->SetBackgroundColour(vfbBg
);
2926 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2928 wxString msg
= m_validationInfo
.m_failureMessage
;
2930 if ( !msg
.length() )
2931 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2933 DoShowPropertyError(property
, msg
);
2936 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2939 // -----------------------------------------------------------------------
2941 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2943 int vfb
= m_validationInfo
.m_failureBehavior
;
2945 if ( vfb
& wxPG_VFB_MARK_CELL
)
2947 property
->SetCell(0, NULL
);
2948 property
->SetCell(1, NULL
);
2950 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2952 if ( property
== m_selected
&& GetEditorControl() )
2954 // Calling this will recreate the control, thus resetting its colour
2955 RefreshProperty(property
);
2959 DrawItemAndChildren(property
);
2964 // -----------------------------------------------------------------------
2966 // flags are same as with DoSelectProperty
2967 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2969 if ( m_inDoPropertyChanged
)
2972 wxWindow
* editor
= GetEditorControl();
2974 m_pState
->m_anyModified
= 1;
2976 m_inDoPropertyChanged
= 1;
2978 // Maybe need to update control
2979 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2981 // These values were calculated in PerformValidation()
2982 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2983 wxVariant value
= m_chgInfo_pendingValue
;
2985 wxPGProperty
* topPaintedProperty
= changedProperty
;
2987 while ( !topPaintedProperty
->IsCategory() &&
2988 !topPaintedProperty
->IsRoot() )
2990 topPaintedProperty
= topPaintedProperty
->GetParent();
2993 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2995 // Set as Modified (not if dragging just began)
2996 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2998 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2999 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3002 SetCurControlBoldFont();
3008 // Propagate updates to parent(s)
3010 wxPGProperty
* prevPwc
= NULL
;
3012 while ( prevPwc
!= topPaintedProperty
)
3014 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3016 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3019 SetCurControlBoldFont();
3023 pwc
= pwc
->GetParent();
3026 // Draw the actual property
3027 DrawItemAndChildren( topPaintedProperty
);
3030 // If value was set by wxPGProperty::OnEvent, then update the editor
3032 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3035 p
->GetEditorClass()->UpdateControl(p
, editor
);
3039 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3040 if ( m_wndEditor
) m_wndEditor
->Refresh();
3041 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3046 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3048 // If top parent has composite string value, then send to child parents,
3049 // starting from baseChangedProperty.
3050 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3052 pwc
= m_chgInfo_baseChangedProperty
;
3054 while ( pwc
!= changedProperty
)
3056 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3057 pwc
= pwc
->GetParent();
3061 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3063 m_inDoPropertyChanged
= 0;
3068 // -----------------------------------------------------------------------
3070 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3072 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3074 m_chgInfo_changedProperty
= NULL
;
3076 if ( PerformValidation(p
, newValue
) )
3078 DoPropertyChanged(p
);
3083 OnValidationFailure(p
, newValue
);
3089 // -----------------------------------------------------------------------
3091 // Runs wxValidator for the selected property
3092 bool wxPropertyGrid::DoEditorValidate()
3097 // -----------------------------------------------------------------------
3099 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3101 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3102 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3104 wxWindow
* parent
= wnd
->GetParent();
3107 (parent
== m_canvas
||
3108 parent
->GetParent() == m_canvas
) )
3110 OnCustomEditorEvent((wxCommandEvent
&)event
);
3114 return wxPanel::ProcessEvent(event
);
3117 // -----------------------------------------------------------------------
3119 // NB: It may really not be wxCommandEvent - must check if necessary
3121 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3123 wxPGProperty
* selected
= m_selected
;
3125 // Somehow, event is handled after property has been deselected.
3126 // Possibly, but very rare.
3130 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3133 wxVariant
pendingValue(selected
->GetValueRef());
3134 wxWindow
* wnd
= GetEditorControl();
3136 bool wasUnspecified
= selected
->IsValueUnspecified();
3137 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3139 bool valueIsPending
= false;
3141 m_chgInfo_changedProperty
= NULL
;
3143 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3146 // Filter out excess wxTextCtrl modified events
3147 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3149 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3151 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3153 wxString newTcValue
= tc
->GetValue();
3154 if ( m_prevTcValue
== newTcValue
)
3157 m_prevTcValue
= newTcValue
;
3160 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3162 bool validationFailure
= false;
3163 bool buttonWasHandled
= false;
3166 // Try common button handling
3167 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3169 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3173 buttonWasHandled
= true;
3174 // Store as res2, as previously (and still currently alternatively)
3175 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3176 // in wxPGProperty::OnEvent().
3177 adapter
->ShowDialog( this, selected
);
3182 if ( !buttonWasHandled
)
3186 // First call editor class' event handler.
3187 const wxPGEditor
* editor
= selected
->GetEditorClass();
3189 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3191 // If changes, validate them
3192 if ( DoEditorValidate() )
3194 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3195 valueIsPending
= true;
3199 validationFailure
= true;
3204 // Then the property's custom handler (must be always called, unless
3205 // validation failed).
3206 if ( !validationFailure
)
3207 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3210 // SetValueInEvent(), as called in one of the functions referred above
3211 // overrides editor's value.
3212 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3214 valueIsPending
= true;
3215 pendingValue
= m_changeInEventValue
;
3216 selFlags
|= wxPG_SEL_DIALOGVAL
;
3219 if ( !validationFailure
&& valueIsPending
)
3220 if ( !PerformValidation(m_selected
, pendingValue
) )
3221 validationFailure
= true;
3223 if ( validationFailure
)
3225 OnValidationFailure(selected
, pendingValue
);
3227 else if ( valueIsPending
)
3229 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3231 DoPropertyChanged(selected
, selFlags
);
3232 EditorsValueWasNotModified();
3234 // Regardless of editor type, unfocus editor on
3235 // text-editing related enter press.
3236 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3243 // No value after all
3245 // Regardless of editor type, unfocus editor on
3246 // text-editing related enter press.
3247 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3252 // Let unhandled button click events go to the parent
3253 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3255 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3256 GetEventHandler()->AddPendingEvent(evt
);
3260 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3263 // -----------------------------------------------------------------------
3264 // wxPropertyGrid editor control helper methods
3265 // -----------------------------------------------------------------------
3267 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3269 int itemy
= p
->GetY2(m_lineHeight
);
3271 int cust_img_space
= 0;
3272 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3273 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3275 // TODO: If custom image detection changes from current, change this.
3276 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3278 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3279 int imwid
= p
->OnMeasureImage().x
;
3280 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3281 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3286 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3288 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3293 // -----------------------------------------------------------------------
3295 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3297 wxSize sz
= GetImageSize(p
, item
);
3298 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3299 wxPG_CUSTOM_IMAGE_SPACINGY
,
3304 // return size of custom paint image
3305 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3307 // If called with NULL property, then return default image
3308 // size for properties that use image.
3310 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3312 wxSize cis
= p
->OnMeasureImage(item
);
3314 int choiceCount
= p
->m_choices
.GetCount();
3315 int comVals
= p
->GetDisplayedCommonValueCount();
3316 if ( item
>= choiceCount
&& comVals
> 0 )
3318 unsigned int cvi
= item
-choiceCount
;
3319 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3321 else if ( item
>= 0 && choiceCount
== 0 )
3322 return wxSize(0, 0);
3327 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3332 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3339 // -----------------------------------------------------------------------
3341 // takes scrolling into account
3342 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3345 GetViewStart(&vx
,&vy
);
3346 vy
*=wxPG_PIXELS_PER_UNIT
;
3347 vx
*=wxPG_PIXELS_PER_UNIT
;
3350 ClientToScreen( px
, py
);
3353 // -----------------------------------------------------------------------
3355 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3358 GetViewStart(&pt2
.x
,&pt2
.y
);
3359 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3360 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3364 return m_pState
->HitTest(pt2
);
3367 // -----------------------------------------------------------------------
3369 // custom set cursor
3370 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3372 if ( type
== m_curcursor
&& !override
) return;
3374 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3376 if ( type
== wxCURSOR_SIZEWE
)
3377 cursor
= m_cursorSizeWE
;
3379 m_canvas
->SetCursor( *cursor
);
3384 // -----------------------------------------------------------------------
3385 // wxPropertyGrid property selection
3386 // -----------------------------------------------------------------------
3388 // Setups event handling for child control
3389 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3391 wxWindowID id
= argWnd
->GetId();
3393 if ( argWnd
== m_wndEditor
)
3395 argWnd
->Connect(id
, wxEVT_MOTION
,
3396 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3398 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3399 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3401 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3402 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3404 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3405 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3407 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3408 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3410 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3411 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3413 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3414 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3419 void wxPropertyGrid::FreeEditors()
3421 // Do not free editors immediately if processing events
3424 m_wndEditor2
->Hide();
3425 wxPendingDelete
.Append( m_wndEditor2
);
3426 m_wndEditor2
= (wxWindow
*) NULL
;
3431 m_wndEditor
->Hide();
3432 wxPendingDelete
.Append( m_wndEditor
);
3433 m_wndEditor
= (wxWindow
*) NULL
;
3437 // Call with NULL to de-select property
3438 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3440 wxPanel
* canvas
= GetPanel();
3444 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3445 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3447 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3450 if ( m_inDoSelectProperty
)
3453 m_inDoSelectProperty
= 1;
3455 wxPGProperty
* prev
= m_selected
;
3459 m_inDoSelectProperty
= 0;
3465 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3467 wxPrintf( "None selected\n" );
3470 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3472 wxPrintf( "P = NULL\n" );
3475 // If we are frozen, then just set the values.
3478 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3479 m_editorFocused
= 0;
3482 m_pState
->m_selected
= p
;
3484 // If frozen, always free controls. But don't worry, as Thaw will
3485 // recall SelectProperty to recreate them.
3488 // Prevent any further selection measures in this call
3489 p
= (wxPGProperty
*) NULL
;
3494 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3496 // Only set focus if not deselecting
3499 if ( flags
& wxPG_SEL_FOCUS
)
3503 m_wndEditor
->SetFocus();
3504 m_editorFocused
= 1;
3513 m_inDoSelectProperty
= 0;
3518 // First, deactivate previous
3522 OnValidationFailureReset(m_selected
);
3524 // Must double-check if this is an selected in case of forceswitch
3527 if ( !CommitChangesFromEditor(flags
) )
3529 // Validation has failed, so we can't exit the previous editor
3530 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3531 // _("Invalid Value"),wxOK|wxICON_ERROR);
3532 m_inDoSelectProperty
= 0;
3540 m_selected
= (wxPGProperty
*) NULL
;
3541 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3543 // We need to always fully refresh the grid here
3546 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3547 EditorsValueWasNotModified();
3550 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3553 // Then, activate the one given.
3556 int propY
= p
->GetY2(m_lineHeight
);
3558 int splitterX
= GetSplitterPosition();
3559 m_editorFocused
= 0;
3561 m_pState
->m_selected
= p
;
3562 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3564 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3566 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3568 // Do we need OnMeasureCalls?
3569 wxSize imsz
= p
->OnMeasureImage();
3572 // Only create editor for non-disabled non-caption
3573 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3575 // do this for non-caption items
3579 // Do we need to paint the custom image, if any?
3580 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3581 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3582 !p
->GetEditorClass()->CanContainCustomImage()
3584 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3586 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3587 wxPoint goodPos
= grect
.GetPosition();
3588 #if wxPG_CREATE_CONTROLS_HIDDEN
3589 int coord_adjust
= m_height
- goodPos
.y
;
3590 goodPos
.y
+= coord_adjust
;
3593 const wxPGEditor
* editor
= p
->GetEditorClass();
3594 wxCHECK_MSG(editor
, false,
3595 wxT("NULL editor class not allowed"));
3597 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3599 wxPGWindowList wndList
= editor
->CreateControls(this,
3604 m_wndEditor
= wndList
.m_primary
;
3605 m_wndEditor2
= wndList
.m_secondary
;
3606 wxWindow
* primaryCtrl
= GetEditorControl();
3609 // Essentially, primaryCtrl == m_wndEditor
3612 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3613 // value is drawn as normal, and m_wndEditor2 is assumed
3614 // to be a right-aligned button that triggers a separate editorCtrl
3619 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3620 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3622 // Set validator, if any
3623 #if wxUSE_VALIDATORS
3624 wxValidator
* validator
= p
->GetValidator();
3626 primaryCtrl
->SetValidator(*validator
);
3629 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3630 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3632 // If it has modified status, use bold font
3633 // (must be done before capturing m_ctrlXAdjust)
3634 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3635 SetCurControlBoldFont();
3638 // Fix TextCtrl indentation
3639 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3640 wxTextCtrl
* tc
= NULL
;
3641 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3642 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3644 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3646 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3649 // Store x relative to splitter (we'll need it).
3650 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3652 // Check if background clear is not necessary
3653 wxPoint pos
= m_wndEditor
->GetPosition();
3654 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3656 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3659 m_wndEditor
->SetSizeHints(3, 3);
3661 #if wxPG_CREATE_CONTROLS_HIDDEN
3662 m_wndEditor
->Show(false);
3663 m_wndEditor
->Freeze();
3665 goodPos
= m_wndEditor
->GetPosition();
3666 goodPos
.y
-= coord_adjust
;
3667 m_wndEditor
->Move( goodPos
);
3670 SetupChildEventHandling(primaryCtrl
);
3672 // Focus and select all (wxTextCtrl, wxComboBox etc)
3673 if ( flags
& wxPG_SEL_FOCUS
)
3675 primaryCtrl
->SetFocus();
3677 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3683 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3684 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3686 // Get proper id for wndSecondary
3687 m_wndSecId
= m_wndEditor2
->GetId();
3688 wxWindowList children
= m_wndEditor2
->GetChildren();
3689 wxWindowList::iterator node
= children
.begin();
3690 if ( node
!= children
.end() )
3691 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3693 m_wndEditor2
->SetSizeHints(3,3);
3695 #if wxPG_CREATE_CONTROLS_HIDDEN
3696 wxRect sec_rect
= m_wndEditor2
->GetRect();
3697 sec_rect
.y
-= coord_adjust
;
3699 // Fine tuning required to fix "oversized"
3700 // button disappearance bug.
3701 if ( sec_rect
.y
< 0 )
3703 sec_rect
.height
+= sec_rect
.y
;
3706 m_wndEditor2
->SetSize( sec_rect
);
3708 m_wndEditor2
->Show();
3710 SetupChildEventHandling(m_wndEditor2
);
3712 // If no primary editor, focus to button to allow
3713 // it to interprete ENTER etc.
3714 // NOTE: Due to problems focusing away from it, this
3715 // has been disabled.
3717 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3718 m_wndEditor2->SetFocus();
3722 if ( flags
& wxPG_SEL_FOCUS
)
3723 m_editorFocused
= 1;
3728 // Make sure focus is in grid canvas (important for wxGTK, at least)
3732 EditorsValueWasNotModified();
3734 // If it's inside collapsed section, expand parent, scroll, etc.
3735 // Also, if it was partially visible, scroll it into view.
3736 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3741 #if wxPG_CREATE_CONTROLS_HIDDEN
3742 m_wndEditor
->Thaw();
3744 m_wndEditor
->Show(true);
3751 // Make sure focus is in grid canvas
3755 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3761 // Show help text in status bar.
3762 // (if found and grid not embedded in manager with help box and
3763 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3766 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3768 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3769 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3771 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3773 statusbar
= frame
->GetStatusBar();
3778 const wxString
* pHelpString
= (const wxString
*) NULL
;
3782 pHelpString
= &p
->GetHelpString();
3783 if ( pHelpString
->length() )
3785 // Set help box text.
3786 statusbar
->SetStatusText( *pHelpString
);
3787 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3791 if ( (!pHelpString
|| !pHelpString
->length()) &&
3792 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3794 // Clear help box - but only if it was written
3795 // by us at previous time.
3796 statusbar
->SetStatusText( m_emptyString
);
3797 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3803 m_inDoSelectProperty
= 0;
3805 // call wx event handler (here so that it also occurs on deselection)
3806 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3811 // -----------------------------------------------------------------------
3813 bool wxPropertyGrid::UnfocusEditor()
3815 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3818 if ( !CommitChangesFromEditor(0) )
3822 DrawItem(m_selected
);
3827 // -----------------------------------------------------------------------
3829 // This method is not inline because it called dozens of times
3830 // (i.e. two-arg function calls create smaller code size).
3831 bool wxPropertyGrid::DoClearSelection()
3833 return DoSelectProperty((wxPGProperty
*)NULL
);
3836 // -----------------------------------------------------------------------
3837 // wxPropertyGrid expand/collapse state
3838 // -----------------------------------------------------------------------
3840 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3842 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3844 // If active editor was inside collapsed section, then disable it
3845 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3847 if ( !ClearSelection() )
3851 // Store dont-center-splitter flag 'cause we need to temporarily set it
3852 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3853 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3855 bool res
= m_pState
->DoCollapse(pwc
);
3860 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3862 RecalculateVirtualSize();
3864 // Redraw etc. only if collapsed was visible.
3865 if (pwc
->IsVisible() &&
3867 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3869 // When item is collapsed so that scrollbar would move,
3870 // graphics mess is about (unless we redraw everything).
3875 // Clear dont-center-splitter flag if it wasn't set
3876 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3881 // -----------------------------------------------------------------------
3883 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3885 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3887 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3889 // Store dont-center-splitter flag 'cause we need to temporarily set it
3890 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3891 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3893 bool res
= m_pState
->DoExpand(pwc
);
3898 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3900 RecalculateVirtualSize();
3902 // Redraw etc. only if expanded was visible.
3903 if ( pwc
->IsVisible() && !m_frozen
&&
3904 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3908 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3911 DrawItems(pwc
, NULL
);
3916 // Clear dont-center-splitter flag if it wasn't set
3917 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3922 // -----------------------------------------------------------------------
3924 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3927 return m_pState
->DoHideProperty(p
, hide
, flags
);
3930 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3933 if ( !ClearSelection() )
3937 m_pState
->DoHideProperty(p
, hide
, flags
);
3939 RecalculateVirtualSize();
3946 // -----------------------------------------------------------------------
3947 // wxPropertyGrid size related methods
3948 // -----------------------------------------------------------------------
3950 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3952 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3956 // If virtual height was changed, then recalculate editor control position(s)
3957 if ( m_pState
->m_vhCalcPending
)
3958 CorrectEditorWidgetPosY();
3960 m_pState
->EnsureVirtualHeight();
3963 int by1
= m_pState
->GetVirtualHeight();
3964 int by2
= m_pState
->GetActualVirtualHeight();
3967 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3968 wxASSERT_MSG( false,
3974 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3976 int x
= m_pState
->m_width
;
3977 int y
= m_pState
->m_virtualHeight
;
3980 GetClientSize(&width
,&height
);
3982 // Now adjust virtual size.
3983 SetVirtualSize(x
, y
);
3989 // Adjust scrollbars
3990 if ( HasVirtualWidth() )
3992 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3993 xPos
= GetScrollPos( wxHORIZONTAL
);
3996 if ( forceXPos
!= -1 )
3999 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4002 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4003 int yPos
= GetScrollPos( wxVERTICAL
);
4005 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4006 xAmount
, yAmount
, xPos
, yPos
, true );
4008 // Must re-get size now
4009 GetClientSize(&width
,&height
);
4011 if ( !HasVirtualWidth() )
4013 m_pState
->SetVirtualWidth(width
);
4020 m_canvas
->SetSize( x
, y
);
4022 m_pState
->CheckColumnWidths();
4025 CorrectEditorWidgetSizeX();
4027 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4030 // -----------------------------------------------------------------------
4032 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4034 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4038 GetClientSize(&width
,&height
);
4043 #if wxPG_DOUBLE_BUFFER
4044 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4046 int dblh
= (m_lineHeight
*2);
4047 if ( !m_doubleBuffer
)
4049 // Create double buffer bitmap to draw on, if none
4050 int w
= (width
>250)?width
:250;
4051 int h
= height
+ dblh
;
4053 m_doubleBuffer
= new wxBitmap( w
, h
);
4057 int w
= m_doubleBuffer
->GetWidth();
4058 int h
= m_doubleBuffer
->GetHeight();
4060 // Double buffer must be large enough
4061 if ( w
< width
|| h
< (height
+dblh
) )
4063 if ( w
< width
) w
= width
;
4064 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4065 delete m_doubleBuffer
;
4066 m_doubleBuffer
= new wxBitmap( w
, h
);
4073 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4074 m_ncWidth
= event
.GetSize().x
;
4078 if ( m_pState
->m_itemsAdded
)
4079 PrepareAfterItemsAdded();
4081 // Without this, virtual size (atleast under wxGTK) will be skewed
4082 RecalculateVirtualSize();
4088 // -----------------------------------------------------------------------
4090 void wxPropertyGrid::SetVirtualWidth( int width
)
4094 // Disable virtual width
4095 width
= GetClientSize().x
;
4096 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4100 // Enable virtual width
4101 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4103 m_pState
->SetVirtualWidth( width
);
4106 void wxPropertyGrid::SetFocusOnCanvas()
4108 m_canvas
->SetFocusIgnoringChildren();
4109 m_editorFocused
= 0;
4112 // -----------------------------------------------------------------------
4113 // wxPropertyGrid mouse event handling
4114 // -----------------------------------------------------------------------
4116 // selFlags uses same values DoSelectProperty's flags
4117 // Returns true if event was vetoed.
4118 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4120 // Send property grid event of specific type and with specific property
4121 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4122 evt
.SetPropertyGrid(this);
4123 evt
.SetEventObject(m_eventObject
);
4127 evt
.SetCanVeto(true);
4128 evt
.SetupValidationInfo();
4129 m_validationInfo
.m_pValue
= pValue
;
4131 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4133 evtHandler
->ProcessEvent(evt
);
4135 return evt
.WasVetoed();
4138 // -----------------------------------------------------------------------
4140 // Return false if should be skipped
4141 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4145 // Need to set focus?
4146 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4151 wxPropertyGridPageState
* state
= m_pState
;
4153 int splitterHitOffset
;
4154 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4156 wxPGProperty
* p
= DoGetItemAtY(y
);
4160 int depth
= (int)p
->GetDepth() - 1;
4162 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4164 if ( x
>= marginEnds
)
4168 if ( p
->IsCategory() )
4170 // This is category.
4171 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4173 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4175 // Expand, collapse, activate etc. if click on text or left of splitter.
4178 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4183 if ( !DoSelectProperty( p
) )
4186 // On double-click, expand/collapse.
4187 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4189 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4190 else DoExpand( p
, true );
4194 else if ( splitterHit
== -1 )
4197 unsigned int selFlag
= 0;
4198 if ( columnHit
== 1 )
4200 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4201 selFlag
= wxPG_SEL_FOCUS
;
4203 if ( !DoSelectProperty( p
, selFlag
) )
4206 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4208 if ( p
->GetChildCount() && !p
->IsCategory() )
4209 // On double-click, expand/collapse.
4210 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4212 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4213 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4214 else DoExpand( p
, true );
4221 // click on splitter
4222 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4224 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4226 // Double-clicking the splitter causes auto-centering
4227 CenterSplitter( true );
4229 else if ( m_dragStatus
== 0 )
4232 // Begin draggin the splitter
4236 // Changes must be committed here or the
4237 // value won't be drawn correctly
4238 if ( !CommitChangesFromEditor() )
4241 m_wndEditor
->Show ( false );
4244 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4246 m_canvas
->CaptureMouse();
4247 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4251 m_draggedSplitter
= splitterHit
;
4252 m_dragOffset
= splitterHitOffset
;
4254 wxClientDC
dc(m_canvas
);
4256 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4257 // Fixes button disappearance bug
4259 m_wndEditor2
->Show ( false );
4262 m_startingSplitterX
= x
- splitterHitOffset
;
4270 if ( p
->GetChildCount() )
4272 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4274 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4276 int y2
= y
% m_lineHeight
;
4277 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4279 // On click on expander button, expand/collapse
4280 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4281 DoCollapse( p
, true );
4283 DoExpand( p
, true );
4292 // -----------------------------------------------------------------------
4294 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4295 wxMouseEvent
& WXUNUSED(event
) )
4299 // Select property here as well
4300 wxPGProperty
* p
= m_propHover
;
4301 if ( p
!= m_selected
)
4302 DoSelectProperty( p
);
4304 // Send right click event.
4305 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4312 // -----------------------------------------------------------------------
4314 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4315 wxMouseEvent
& WXUNUSED(event
) )
4319 // Select property here as well
4320 wxPGProperty
* p
= m_propHover
;
4322 if ( p
!= m_selected
)
4323 DoSelectProperty( p
);
4325 // Send double-click event.
4326 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4333 // -----------------------------------------------------------------------
4335 #if wxPG_SUPPORT_TOOLTIPS
4337 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4339 if ( tipString
.length() )
4341 m_canvas
->SetToolTip(tipString
);
4345 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4346 m_canvas
->SetToolTip( m_emptyString
);
4348 m_canvas
->SetToolTip( NULL
);
4353 #endif // #if wxPG_SUPPORT_TOOLTIPS
4355 // -----------------------------------------------------------------------
4357 // Return false if should be skipped
4358 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4360 // Safety check (needed because mouse capturing may
4361 // otherwise freeze the control)
4362 if ( m_dragStatus
> 0 && !event
.Dragging() )
4364 HandleMouseUp(x
,y
,event
);
4367 wxPropertyGridPageState
* state
= m_pState
;
4369 int splitterHitOffset
;
4370 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4371 int splitterX
= x
- splitterHitOffset
;
4373 if ( m_dragStatus
> 0 )
4375 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4376 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4379 int newSplitterX
= x
- m_dragOffset
;
4380 int splitterX
= x
- splitterHitOffset
;
4382 // Splitter redraw required?
4383 if ( newSplitterX
!= splitterX
)
4386 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4387 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4388 state
->m_fSplitterX
= (float) newSplitterX
;
4391 CorrectEditorWidgetSizeX();
4405 int ih
= m_lineHeight
;
4408 #if wxPG_SUPPORT_TOOLTIPS
4409 wxPGProperty
* prevHover
= m_propHover
;
4410 unsigned char prevSide
= m_mouseSide
;
4412 int curPropHoverY
= y
- (y
% ih
);
4414 // On which item it hovers
4415 if ( ( !m_propHover
)
4417 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4420 // Mouse moves on another property
4422 m_propHover
= DoGetItemAtY(y
);
4423 m_propHoverY
= curPropHoverY
;
4426 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4429 #if wxPG_SUPPORT_TOOLTIPS
4430 // Store which side we are on
4432 if ( columnHit
== 1 )
4434 else if ( columnHit
== 0 )
4438 // If tooltips are enabled, show label or value as a tip
4439 // in case it doesn't otherwise show in full length.
4441 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4443 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4445 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4447 if ( m_propHover
&& !m_propHover
->IsCategory() )
4450 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4452 // Show help string as a tooltip
4453 wxString tipString
= m_propHover
->GetHelpString();
4455 SetToolTip(tipString
);
4459 // Show cropped value string as a tooltip
4463 if ( m_mouseSide
== 1 )
4465 tipString
= m_propHover
->m_label
;
4466 space
= splitterX
-m_marginWidth
-3;
4468 else if ( m_mouseSide
== 2 )
4470 tipString
= m_propHover
->GetDisplayedString();
4472 space
= m_width
- splitterX
;
4473 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4474 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4480 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4483 SetToolTip( tipString
);
4490 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4491 m_canvas
->SetToolTip( m_emptyString
);
4493 m_canvas
->SetToolTip( NULL
);
4504 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4505 m_canvas
->SetToolTip( m_emptyString
);
4507 m_canvas
->SetToolTip( NULL
);
4515 if ( splitterHit
== -1 ||
4517 HasFlag(wxPG_STATIC_SPLITTER
) )
4519 // hovering on something else
4520 if ( m_curcursor
!= wxCURSOR_ARROW
)
4521 CustomSetCursor( wxCURSOR_ARROW
);
4525 // Do not allow splitter cursor on caption items.
4526 // (also not if we were dragging and its started
4527 // outside the splitter region)
4530 !m_propHover
->IsCategory() &&
4534 // hovering on splitter
4536 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4537 // reliably detected.
4538 //if ( m_curcursor != wxCURSOR_SIZEWE )
4539 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4545 // hovering on something else
4546 if ( m_curcursor
!= wxCURSOR_ARROW
)
4547 CustomSetCursor( wxCURSOR_ARROW
);
4554 // -----------------------------------------------------------------------
4556 // Also handles Leaving event
4557 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4558 wxMouseEvent
&WXUNUSED(event
) )
4560 wxPropertyGridPageState
* state
= m_pState
;
4564 int splitterHitOffset
;
4565 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4567 // No event type check - basicly calling this method should
4568 // just stop dragging.
4569 // Left up after dragged?
4570 if ( m_dragStatus
>= 1 )
4573 // End Splitter Dragging
4575 // DO NOT ENABLE FOLLOWING LINE!
4576 // (it is only here as a reminder to not to do it)
4579 // Disable splitter auto-centering
4580 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4582 // This is necessary to return cursor
4583 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4585 m_canvas
->ReleaseMouse();
4586 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4589 // Set back the default cursor, if necessary
4590 if ( splitterHit
== -1 ||
4593 CustomSetCursor( wxCURSOR_ARROW
);
4598 // Control background needs to be cleared
4599 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4600 DrawItem( m_selected
);
4604 m_wndEditor
->Show ( true );
4607 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4608 // Fixes button disappearance bug
4610 m_wndEditor2
->Show ( true );
4613 // This clears the focus.
4614 m_editorFocused
= 0;
4620 // -----------------------------------------------------------------------
4622 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4624 int splitterX
= GetSplitterPosition();
4627 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4631 wxWindow
* wnd
= GetEditorControl();
4633 // Hide popup on clicks
4634 if ( event
.GetEventType() != wxEVT_MOTION
)
4635 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4637 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4643 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4645 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4646 ux
>= (r
.x
+r
.width
) ||
4648 event
.m_y
>= (r
.y
+r
.height
)
4658 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4663 // -----------------------------------------------------------------------
4665 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4668 if ( OnMouseCommon( event
, &x
, &y
) )
4670 HandleMouseClick(x
,y
,event
);
4675 // -----------------------------------------------------------------------
4677 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4680 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4681 HandleMouseRightClick(x
,y
,event
);
4685 // -----------------------------------------------------------------------
4687 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4689 // Always run standard mouse-down handler as well
4690 OnMouseClick(event
);
4693 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4694 HandleMouseDoubleClick(x
,y
,event
);
4698 // -----------------------------------------------------------------------
4700 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4703 if ( OnMouseCommon( event
, &x
, &y
) )
4705 HandleMouseMove(x
,y
,event
);
4710 // -----------------------------------------------------------------------
4712 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4714 // Called when mouse moves in the empty space below the properties.
4715 CustomSetCursor( wxCURSOR_ARROW
);
4718 // -----------------------------------------------------------------------
4720 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4723 if ( OnMouseCommon( event
, &x
, &y
) )
4725 HandleMouseUp(x
,y
,event
);
4730 // -----------------------------------------------------------------------
4732 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4734 // This may get called from child control as well, so event's
4735 // mouse position cannot be relied on.
4737 if ( event
.Entering() )
4739 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4741 // TODO: Fix this (detect parent and only do
4742 // cursor trick if it is a manager).
4743 wxASSERT( GetParent() );
4744 GetParent()->SetCursor(wxNullCursor
);
4746 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4749 GetParent()->SetCursor(wxNullCursor
);
4751 else if ( event
.Leaving() )
4753 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4754 m_canvas
->SetCursor( wxNullCursor
);
4756 // Get real cursor position
4757 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4759 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4762 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4764 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4768 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4776 // -----------------------------------------------------------------------
4778 // Common code used by various OnMouseXXXChild methods.
4779 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4781 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4782 wxASSERT( topCtrlWnd
);
4784 event
.GetPosition(&x
,&y
);
4786 int splitterX
= GetSplitterPosition();
4788 wxRect r
= topCtrlWnd
->GetRect();
4789 if ( !m_dragStatus
&&
4790 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4791 y
>= 0 && y
< r
.height \
4794 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4799 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4806 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4809 if ( OnMouseChildCommon(event
,&x
,&y
) )
4811 bool res
= HandleMouseClick(x
,y
,event
);
4812 if ( !res
) event
.Skip();
4816 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4819 wxASSERT( m_wndEditor
);
4820 // These coords may not be exact (about +-2),
4821 // but that should not matter (right click is about item, not position).
4822 wxPoint pt
= m_wndEditor
->GetPosition();
4823 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4824 wxASSERT( m_selected
);
4825 m_propHover
= m_selected
;
4826 bool res
= HandleMouseRightClick(x
,y
,event
);
4827 if ( !res
) event
.Skip();
4830 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4833 if ( OnMouseChildCommon(event
,&x
,&y
) )
4835 bool res
= HandleMouseMove(x
,y
,event
);
4836 if ( !res
) event
.Skip();
4840 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4843 if ( OnMouseChildCommon(event
,&x
,&y
) )
4845 bool res
= HandleMouseUp(x
,y
,event
);
4846 if ( !res
) event
.Skip();
4850 // -----------------------------------------------------------------------
4851 // wxPropertyGrid keyboard event handling
4852 // -----------------------------------------------------------------------
4854 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4856 // Translates wxKeyEvent to wxPG_ACTION_XXX
4858 int keycode
= event
.GetKeyCode();
4859 int modifiers
= event
.GetModifiers();
4861 wxASSERT( !(modifiers
&~(0xFFFF)) );
4863 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4865 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4867 if ( it
== m_actionTriggers
.end() )
4872 int second
= (it
->second
>>16) & 0xFFFF;
4876 return (it
->second
& 0xFFFF);
4879 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4881 wxASSERT( !(modifiers
&~(0xFFFF)) );
4883 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4885 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4887 if ( it
!= m_actionTriggers
.end() )
4889 // This key combination is already used
4891 // Can add secondary?
4892 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4893 wxT("You can only add up to two separate actions per key combination.") );
4895 action
= it
->second
| (action
<<16);
4898 m_actionTriggers
[hashMapKey
] = action
;
4901 void wxPropertyGrid::ClearActionTriggers( int action
)
4903 wxPGHashMapI2I::iterator it
;
4905 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4907 if ( it
->second
== action
)
4909 m_actionTriggers
.erase(it
);
4914 static void CopyTextToClipboard( const wxString
& text
)
4916 if ( wxTheClipboard
->Open() )
4918 // This data objects are held by the clipboard,
4919 // so do not delete them in the app.
4920 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4921 wxTheClipboard
->Close();
4925 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4928 // Handles key event when editor control is not focused.
4931 wxASSERT( !m_frozen
);
4935 // Travelsal between items, collapsing/expanding, etc.
4936 int keycode
= event
.GetKeyCode();
4938 if ( keycode
== WXK_TAB
)
4941 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4945 // Ignore Alt and Control when they are down alone
4946 if ( keycode
== WXK_ALT
||
4947 keycode
== WXK_CONTROL
)
4954 int action
= KeyEventToActions(event
, &secondAction
);
4960 if ( ButtonTriggerKeyTest(action
, event
) )
4963 wxPGProperty
* p
= m_selected
;
4965 if ( action
== wxPG_ACTION_COPY
)
4967 CopyTextToClipboard(p
->GetDisplayedString());
4971 // Travel and expand/collapse
4974 if ( p
->GetChildCount() &&
4975 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4978 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4980 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4983 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4985 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4992 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4996 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5007 if ( selectDir
>= -1 )
5009 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5011 DoSelectProperty(p
);
5017 // If nothing was selected, select the first item now
5018 // (or navigate out of tab).
5019 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5021 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5022 if ( p
) DoSelectProperty(p
);
5027 // -----------------------------------------------------------------------
5029 // Potentially handles a keyboard event for editor controls.
5030 // Returns false if event should *not* be skipped (on true it can
5031 // be optionally skipped).
5032 // Basicly, false means that SelectProperty was called (or was about
5033 // to be called, if canDestroy was false).
5034 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5038 if ( !m_selected
|| !m_wndEditor
)
5043 int action
= KeyEventToAction(event
);
5046 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5049 // Esc cancels any changes
5050 if ( IsEditorsValueModified() )
5052 EditorsValueWasNotModified();
5054 // Update the control as well
5055 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5057 m_selected
->GetDisplayedString() );
5060 OnValidationFailureReset(m_selected
);
5065 else if ( action
== wxPG_ACTION_COPY
)
5067 // NB: There is some problem with getting native cut-copy-paste keys to go through
5068 // for embedded editor wxTextCtrl. This is why we emulate.
5070 wxTextCtrl
* tc
= GetEditorTextCtrl();
5073 wxString sel
= tc
->GetStringSelection();
5075 CopyTextToClipboard(sel
);
5079 CopyTextToClipboard(m_selected
->GetDisplayedString());
5082 else if ( action
== wxPG_ACTION_CUT
)
5084 wxTextCtrl
* tc
= GetEditorTextCtrl();
5088 tc
->GetSelection(&from
, &to
);
5091 CopyTextToClipboard(tc
->GetStringSelection());
5092 tc
->Remove(from
, to
);
5096 else if ( action
== wxPG_ACTION_PASTE
)
5098 wxTextCtrl
* tc
= GetEditorTextCtrl();
5101 if (wxTheClipboard
->Open())
5103 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5105 wxTextDataObject data
;
5106 wxTheClipboard
->GetData( data
);
5108 tc
->GetSelection(&from
, &to
);
5111 tc
->Remove(from
, to
);
5112 tc
->WriteText(data
.GetText());
5116 tc
->WriteText(data
.GetText());
5119 wxTheClipboard
->Close();
5127 // -----------------------------------------------------------------------
5129 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5131 HandleKeyEvent( event
);
5134 // -----------------------------------------------------------------------
5136 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5141 // -----------------------------------------------------------------------
5143 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5148 action
= KeyEventToActions(event
, &secondAction
);
5151 // Does the keycode trigger button?
5152 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5155 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5156 GetEventHandler()->AddPendingEvent(evt
);
5163 // -----------------------------------------------------------------------
5165 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5167 int keycode
= event
.GetKeyCode();
5169 // Ignore Alt and Control when they are down alone
5170 if ( keycode
== WXK_ALT
||
5171 keycode
== WXK_CONTROL
)
5177 if ( ButtonTriggerKeyTest(-1, event
) )
5180 if ( HandleChildKey(event
) == true )
5183 GetEventHandler()->AddPendingEvent(event
);
5186 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5188 GetEventHandler()->AddPendingEvent(event
);
5193 // -----------------------------------------------------------------------
5194 // wxPropertyGrid miscellaneous event handling
5195 // -----------------------------------------------------------------------
5197 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5200 // Check if the focus is in this control or one of its children
5201 wxWindow
* newFocused
= wxWindow::FindFocus();
5203 if ( newFocused
!= m_curFocused
)
5204 HandleFocusChange( newFocused
);
5207 // Called by focus event handlers. newFocused is the window that becomes focused.
5208 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5210 unsigned int oldFlags
= m_iFlags
;
5212 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5214 wxWindow
* parent
= newFocused
;
5216 // This must be one of nextFocus' parents.
5219 // Use m_eventObject, which is either wxPropertyGrid or
5220 // wxPropertyGridManager, as appropriate.
5221 if ( parent
== m_eventObject
)
5223 m_iFlags
|= wxPG_FL_FOCUSED
;
5226 parent
= parent
->GetParent();
5229 m_curFocused
= newFocused
;
5231 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5232 (oldFlags
& wxPG_FL_FOCUSED
) )
5234 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5236 // Need to store changed value
5237 CommitChangesFromEditor();
5243 // Preliminary code for tab-order respecting
5244 // tab-traversal (but should be moved to
5247 wxWindow* prevFocus = event.GetWindow();
5248 wxWindow* useThis = this;
5249 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5250 useThis = GetParent();
5253 prevFocus->GetParent() == useThis->GetParent() )
5255 wxList& children = useThis->GetParent()->GetChildren();
5257 wxNode* node = children.Find(prevFocus);
5259 if ( node->GetNext() &&
5260 useThis == node->GetNext()->GetData() )
5261 DoSelectProperty(GetFirst());
5262 else if ( node->GetPrevious () &&
5263 useThis == node->GetPrevious()->GetData() )
5264 DoSelectProperty(GetLastProperty());
5271 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5272 DrawItem( m_selected
);
5276 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5278 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5279 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5280 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5281 //else if ( event.GetWindow() )
5283 HandleFocusChange(event
.GetWindow());
5288 // -----------------------------------------------------------------------
5290 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5292 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5295 // event.Skip() being commented out is aworkaround for bug reported
5296 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5300 // -----------------------------------------------------------------------
5302 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5304 m_iFlags
|= wxPG_FL_SCROLLED
;
5309 // -----------------------------------------------------------------------
5311 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5313 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5315 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5319 // -----------------------------------------------------------------------
5320 // Property editor related functions
5321 // -----------------------------------------------------------------------
5323 // noDefCheck = true prevents infinite recursion.
5324 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5327 wxASSERT( editorClass
);
5329 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5330 RegisterDefaultEditors();
5332 wxString name
= editorClass
->GetName();
5334 // Existing editor under this name?
5335 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5337 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5338 (wxPGEditor
*) vt_it
->second
,
5339 "Editor with given name was already registered" );
5341 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5346 // Registers all default editor classes
5347 void wxPropertyGrid::RegisterDefaultEditors()
5349 wxPGRegisterDefaultEditorClass( TextCtrl
);
5350 wxPGRegisterDefaultEditorClass( Choice
);
5351 wxPGRegisterDefaultEditorClass( ComboBox
);
5352 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5353 #if wxPG_INCLUDE_CHECKBOX
5354 wxPGRegisterDefaultEditorClass( CheckBox
);
5356 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5358 // Register SpinCtrl etc. editors before use
5359 RegisterAdditionalEditors();
5362 // -----------------------------------------------------------------------
5363 // wxPGStringTokenizer
5364 // Needed to handle C-style string lists (e.g. "str1" "str2")
5365 // -----------------------------------------------------------------------
5367 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5368 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5372 wxPGStringTokenizer::~wxPGStringTokenizer()
5376 bool wxPGStringTokenizer::HasMoreTokens()
5378 const wxString
& str
= *m_str
;
5380 wxString::const_iterator i
= m_curPos
;
5382 wxUniChar delim
= m_delimeter
;
5384 wxUniChar prev_a
= wxT('\0');
5386 bool inToken
= false;
5388 while ( i
!= str
.end() )
5397 m_readyToken
.clear();
5402 if ( prev_a
!= wxT('\\') )
5406 if ( a
!= wxT('\\') )
5426 m_curPos
= str
.end();
5434 wxString
wxPGStringTokenizer::GetNextToken()
5436 return m_readyToken
;
5439 // -----------------------------------------------------------------------
5441 // -----------------------------------------------------------------------
5443 wxPGChoiceEntry::wxPGChoiceEntry()
5444 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5448 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5449 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5450 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5454 // -----------------------------------------------------------------------
5456 // -----------------------------------------------------------------------
5458 wxPGChoicesData::wxPGChoicesData()
5463 wxPGChoicesData::~wxPGChoicesData()
5468 void wxPGChoicesData::Clear()
5472 for ( i
=0; i
<m_items
.size(); i
++ )
5480 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5482 wxASSERT( m_items
.size() == 0 );
5486 for ( i
=0; i
<data
->GetCount(); i
++ )
5487 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5490 // -----------------------------------------------------------------------
5492 // -----------------------------------------------------------------------
5494 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5498 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5499 m_data
->Insert( -1, p
);
5503 // -----------------------------------------------------------------------
5505 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5509 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5510 p
->SetBitmap(bitmap
);
5511 m_data
->Insert( -1, p
);
5515 // -----------------------------------------------------------------------
5517 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5521 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5522 m_data
->Insert(index
, p
);
5526 // -----------------------------------------------------------------------
5528 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5532 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5533 m_data
->Insert( index
, p
);
5537 // -----------------------------------------------------------------------
5539 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5545 while ( index
< GetCount() )
5547 int cmpRes
= GetLabel(index
).Cmp(label
);
5553 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5554 m_data
->Insert( index
, p
);
5558 // -----------------------------------------------------------------------
5560 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5564 unsigned int itemcount
= 0;
5565 const wxChar
** p
= &labels
[0];
5566 while ( *p
) { p
++; itemcount
++; }
5569 for ( i
= 0; i
< itemcount
; i
++ )
5571 int value
= wxPG_INVALID_VALUE
;
5574 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5578 // -----------------------------------------------------------------------
5580 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5585 unsigned int itemcount
= arr
.size();
5587 for ( i
= 0; i
< itemcount
; i
++ )
5589 int value
= wxPG_INVALID_VALUE
;
5592 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5596 // -----------------------------------------------------------------------
5598 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5603 unsigned int itemcount
= arr
.size();
5605 for ( i
= 0; i
< itemcount
; i
++ )
5607 int value
= wxPG_INVALID_VALUE
;
5608 if ( &arrint
&& arrint
.size() )
5610 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5614 // -----------------------------------------------------------------------
5616 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5618 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5620 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5621 delete m_data
->Item(i
);
5622 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5623 m_data
->m_items
.begin()+nIndex
+count
);
5626 // -----------------------------------------------------------------------
5628 int wxPGChoices::Index( const wxString
& str
) const
5633 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5635 if ( m_data
->Item(i
)->GetText() == str
)
5642 // -----------------------------------------------------------------------
5644 int wxPGChoices::Index( int val
) const
5649 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5651 if ( m_data
->Item(i
)->GetValue() == val
)
5658 // -----------------------------------------------------------------------
5660 wxArrayString
wxPGChoices::GetLabels() const
5665 if ( this && IsOk() )
5666 for ( i
=0; i
<GetCount(); i
++ )
5667 arr
.push_back(GetLabel(i
));
5672 // -----------------------------------------------------------------------
5674 bool wxPGChoices::HasValues() const
5679 // -----------------------------------------------------------------------
5681 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5688 for ( i
=0; i
< strings
.size(); i
++ )
5690 int index
= Index(strings
[i
]);
5692 arr
.Add(GetValue(index
));
5694 arr
.Add(wxPG_INVALID_VALUE
);
5701 // -----------------------------------------------------------------------
5703 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5704 wxArrayString
* unmatched
) const
5711 for ( i
=0; i
< strings
.size(); i
++ )
5713 const wxString
& str
= strings
[i
];
5714 int index
= Index(str
);
5717 else if ( unmatched
)
5718 unmatched
->Add(str
);
5725 // -----------------------------------------------------------------------
5727 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5731 if ( data
!= wxPGChoicesEmptyData
)
5738 // -----------------------------------------------------------------------
5740 void wxPGChoices::Init()
5742 m_data
= wxPGChoicesEmptyData
;
5745 // -----------------------------------------------------------------------
5747 void wxPGChoices::Free()
5749 if ( m_data
!= wxPGChoicesEmptyData
)
5752 m_data
= wxPGChoicesEmptyData
;
5756 // -----------------------------------------------------------------------
5757 // wxPropertyGridEvent
5758 // -----------------------------------------------------------------------
5760 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5763 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5764 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5765 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5766 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5767 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5768 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5769 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5770 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5771 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5774 // -----------------------------------------------------------------------
5776 void wxPropertyGridEvent::Init()
5778 m_validationInfo
= NULL
;
5780 m_wasVetoed
= false;
5783 // -----------------------------------------------------------------------
5785 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5786 : wxCommandEvent(commandType
,id
)
5792 // -----------------------------------------------------------------------
5794 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5795 : wxCommandEvent(event
)
5797 m_eventType
= event
.GetEventType();
5798 m_eventObject
= event
.m_eventObject
;
5800 m_property
= event
.m_property
;
5801 m_validationInfo
= event
.m_validationInfo
;
5802 m_canVeto
= event
.m_canVeto
;
5803 m_wasVetoed
= event
.m_wasVetoed
;
5806 // -----------------------------------------------------------------------
5808 wxPropertyGridEvent::~wxPropertyGridEvent()
5812 // -----------------------------------------------------------------------
5814 wxEvent
* wxPropertyGridEvent::Clone() const
5816 return new wxPropertyGridEvent( *this );
5819 // -----------------------------------------------------------------------
5820 // wxPropertyGridPopulator
5821 // -----------------------------------------------------------------------
5823 wxPropertyGridPopulator::wxPropertyGridPopulator()
5827 wxPGGlobalVars
->m_offline
++;
5830 // -----------------------------------------------------------------------
5832 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5835 m_propHierarchy
.clear();
5838 // -----------------------------------------------------------------------
5840 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5846 // -----------------------------------------------------------------------
5848 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5851 // Free unused sets of choices
5852 wxPGHashMapS2P::iterator it
;
5854 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5856 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5863 m_pg
->GetPanel()->Refresh();
5865 wxPGGlobalVars
->m_offline
--;
5868 // -----------------------------------------------------------------------
5870 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5871 const wxString
& propLabel
,
5872 const wxString
& propName
,
5873 const wxString
* propValue
,
5874 wxPGChoices
* pChoices
)
5876 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5877 wxPGProperty
* parent
= GetCurParent();
5879 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5881 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5885 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5887 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5891 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5893 property
->SetLabel(propLabel
);
5894 property
->DoSetName(propName
);
5896 if ( pChoices
&& pChoices
->IsOk() )
5897 property
->SetChoices(*pChoices
);
5899 m_state
->DoInsert(parent
, -1, property
);
5902 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
5907 // -----------------------------------------------------------------------
5909 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5911 m_propHierarchy
.push_back(property
);
5912 DoScanForChildren();
5913 m_propHierarchy
.pop_back();
5916 // -----------------------------------------------------------------------
5918 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5919 const wxString
& idString
)
5921 wxPGChoices choices
;
5924 if ( choicesString
[0] == wxT('@') )
5926 wxString ids
= choicesString
.substr(1);
5927 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5928 if ( it
== m_dictIdChoices
.end() )
5929 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5931 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5936 if ( idString
.length() )
5938 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5939 if ( it
!= m_dictIdChoices
.end() )
5941 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5948 // Parse choices string
5949 wxString::const_iterator it
= choicesString
.begin();
5953 bool labelValid
= false;
5955 for ( ; it
!= choicesString
.end(); it
++ )
5961 if ( c
== wxT('"') )
5966 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5967 choices
.Add(label
, l
);
5970 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5975 else if ( c
== wxT('=') )
5982 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5989 if ( c
== wxT('"') )
6002 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6003 choices
.Add(label
, l
);
6006 if ( !choices
.IsOk() )
6008 choices
.EnsureData();
6012 if ( idString
.length() )
6013 m_dictIdChoices
[idString
] = choices
.GetData();
6020 // -----------------------------------------------------------------------
6022 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6024 if ( s
.Last() == wxT('%') )
6026 wxString s2
= s
.substr(0,s
.length()-1);
6028 if ( s2
.ToLong(&val
, 10) )
6030 *pval
= (val
*max
)/100;
6036 return s
.ToLong(pval
, 10);
6039 // -----------------------------------------------------------------------
6041 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6042 const wxString
& type
,
6043 const wxString
& value
)
6045 int l
= m_propHierarchy
.size();
6049 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6050 wxString valuel
= value
.Lower();
6053 if ( type
.length() == 0 )
6058 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6060 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6062 else if ( value
.ToLong(&v
, 0) )
6069 if ( type
== wxT("string") )
6073 else if ( type
== wxT("int") )
6076 value
.ToLong(&v
, 0);
6079 else if ( type
== wxT("bool") )
6081 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6088 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6093 p
->SetAttribute( name
, variant
);
6098 // -----------------------------------------------------------------------
6100 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6102 wxLogError(_("Error in resource: %s"),msg
.c_str());
6105 // -----------------------------------------------------------------------
6107 #endif // wxUSE_PROPGRID