1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 #define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 #define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // -----------------------------------------------------------------------
239 // This class is a wxBrush derivative used in the background colour
240 // brush cache. It adds wxPG-type colour-in-long to the class.
241 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
242 // object does), but this is simpler implementation and equally
246 class wxPGBrush
: public wxBrush
249 wxPGBrush( const wxColour
& colour
);
251 virtual ~wxPGBrush() { }
252 void SetColour2( const wxColour
& colour
);
253 inline long GetColourAsLong() const { return m_colAsLong
; }
259 void wxPGBrush::SetColour2( const wxColour
& colour
)
261 wxBrush::SetColour(colour
);
262 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
266 wxPGBrush::wxPGBrush() : wxBrush()
272 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
274 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
278 // -----------------------------------------------------------------------
280 // -----------------------------------------------------------------------
283 // Same as wxPGBrush, but for wxColour instead.
286 class wxPGColour
: public wxColour
289 wxPGColour( const wxColour
& colour
);
291 virtual ~wxPGColour() { }
292 void SetColour2( const wxColour
& colour
);
293 inline long GetColourAsLong() const { return m_colAsLong
; }
299 void wxPGColour::SetColour2( const wxColour
& colour
)
302 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
306 wxPGColour::wxPGColour() : wxColour()
312 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
314 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
318 // -----------------------------------------------------------------------
320 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
321 // and tries to commit property value.
322 // -----------------------------------------------------------------------
324 class wxPGTLWHandler
: public wxEvtHandler
328 wxPGTLWHandler( wxPropertyGrid
* pg
)
336 void OnClose( wxCloseEvent
& event
)
338 // ClearSelection forces value validation/commit.
339 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
349 wxPropertyGrid
* m_pg
;
351 DECLARE_EVENT_TABLE()
354 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
355 EVT_CLOSE(wxPGTLWHandler::OnClose
)
358 // -----------------------------------------------------------------------
360 // -----------------------------------------------------------------------
363 // wxPGCanvas acts as a graphics sub-window of the
364 // wxScrolledWindow that wxPropertyGrid is.
366 class wxPGCanvas
: public wxPanel
369 wxPGCanvas() : wxPanel()
372 virtual ~wxPGCanvas() { }
375 void OnMouseMove( wxMouseEvent
&event
)
377 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
378 pg
->OnMouseMove( event
);
381 void OnMouseClick( wxMouseEvent
&event
)
383 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
384 pg
->OnMouseClick( event
);
387 void OnMouseUp( wxMouseEvent
&event
)
389 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
390 pg
->OnMouseUp( event
);
393 void OnMouseRightClick( wxMouseEvent
&event
)
395 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
396 pg
->OnMouseRightClick( event
);
399 void OnMouseDoubleClick( wxMouseEvent
&event
)
401 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
402 pg
->OnMouseDoubleClick( event
);
405 void OnKey( wxKeyEvent
& event
)
407 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
411 void OnKeyUp( wxKeyEvent
& event
)
413 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
414 pg
->OnKeyUp( event
);
417 void OnPaint( wxPaintEvent
& event
);
419 // Always be focussable, even with child windows
420 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
421 { wxPanel::SetCanFocus(true); }
425 DECLARE_EVENT_TABLE()
426 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
430 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
432 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
433 EVT_MOTION(wxPGCanvas::OnMouseMove
)
434 EVT_PAINT(wxPGCanvas::OnPaint
)
435 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
436 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
437 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
438 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
439 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
440 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
441 EVT_CHAR(wxPGCanvas::OnKey
)
445 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
447 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
448 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
452 // Don't paint after destruction has begun
453 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
456 // Update everything inside the box
457 wxRect r
= GetUpdateRegion().GetBox();
459 // Repaint this rectangle
460 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
462 // We assume that the size set when grid is shown
463 // is what is desired.
464 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
467 // -----------------------------------------------------------------------
469 // -----------------------------------------------------------------------
471 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
473 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
474 EVT_IDLE(wxPropertyGrid::OnIdle
)
475 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
476 EVT_PAINT(wxPropertyGrid::OnPaint
)
477 EVT_SIZE(wxPropertyGrid::OnResize
)
478 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
479 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
480 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
481 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
482 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
483 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
484 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
485 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
489 // -----------------------------------------------------------------------
491 wxPropertyGrid::wxPropertyGrid()
497 // -----------------------------------------------------------------------
499 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
508 Create(parent
,id
,pos
,size
,style
,name
);
511 // -----------------------------------------------------------------------
513 bool wxPropertyGrid::Create( wxWindow
*parent
,
521 if ( !(style
&wxBORDER_MASK
) )
522 style
|= wxSIMPLE_BORDER
;
527 // This prevents crash under Win2K, but still
528 // enables keyboard navigation
529 if ( style
& wxTAB_TRAVERSAL
)
531 style
&= ~(wxTAB_TRAVERSAL
);
532 style
|= wxWANTS_CHARS
;
535 if ( style
& wxTAB_TRAVERSAL
)
536 style
|= wxWANTS_CHARS
;
539 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
546 // -----------------------------------------------------------------------
549 // Initialize values to defaults
551 void wxPropertyGrid::Init1()
553 // Register editor classes, if necessary.
554 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
555 wxPropertyGrid::RegisterDefaultEditors();
558 m_pState
= (wxPropertyGridPageState
*) NULL
;
559 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
560 m_selected
= (wxPGProperty
*) NULL
;
562 m_propHover
= (wxPGProperty
*) NULL
;
563 m_eventObject
= this;
564 m_curFocused
= (wxWindow
*) NULL
;
566 m_inDoPropertyChanged
= 0;
567 m_inCommitChangesFromEditor
= 0;
568 m_inDoSelectProperty
= 0;
569 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
575 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
576 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
577 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
578 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
579 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
580 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
581 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
582 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
583 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
584 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
585 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
586 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
587 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
588 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
589 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
591 m_coloursCustomized
= 0;
596 #if wxPG_DOUBLE_BUFFER
597 m_doubleBuffer
= (wxBitmap
*) NULL
;
600 #ifndef wxPG_ICON_WIDTH
606 m_iconWidth
= wxPG_ICON_WIDTH
;
611 m_gutterWidth
= wxPG_GUTTER_MIN
;
612 m_subgroup_extramargin
= 10;
616 m_width
= m_height
= 0;
618 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
621 m_chgInfo_changedProperty
= NULL
;
624 // -----------------------------------------------------------------------
627 // Initialize after parent etc. set
629 void wxPropertyGrid::Init2()
631 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
634 // Smaller controls on Mac
635 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
638 // Now create state, if one didn't exist already
639 // (wxPropertyGridManager might have created it for us).
642 m_pState
= CreateState();
643 m_pState
->m_pPropGrid
= this;
644 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
647 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
648 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
650 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
652 m_pState
->InitNonCatMode();
654 m_pState
->m_properties
= m_pState
->m_abcArray
;
657 GetClientSize(&m_width
,&m_height
);
659 #ifndef wxPG_ICON_WIDTH
660 // create two bitmap nodes for drawing
661 m_expandbmp
= new wxBitmap(expand_xpm
);
662 m_collbmp
= new wxBitmap(collapse_xpm
);
664 // calculate average font height for bitmap centering
666 m_iconWidth
= m_expandbmp
->GetWidth();
667 m_iconHeight
= m_expandbmp
->GetHeight();
670 m_curcursor
= wxCURSOR_ARROW
;
671 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
673 // adjust bitmap icon y position so they are centered
674 m_vspacing
= wxPG_DEFAULT_VSPACING
;
678 wxFont useFont
= wxScrolledWindow::GetFont();
679 wxScrolledWindow::SetOwnFont( useFont
);
682 // This should be otherwise called by SetOwnFont
683 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
685 // Add base brush item
686 m_arrBgBrushes
.Add((void*)new wxPGBrush());
688 // Add base colour items
689 m_arrFgCols
.Add((void*)new wxPGColour());
690 m_arrFgCols
.Add((void*)new wxPGColour());
694 // This helps with flicker
695 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
698 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
699 m_tlp
= ::wxGetTopLevelParent(this);
700 m_tlwHandler
= handler
;
701 m_tlp
->PushEventHandler(handler
);
703 // set virtual size to this window size
704 wxSize wndsize
= GetSize();
705 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
707 m_timeCreated
= ::wxGetLocalTimeMillis();
709 m_canvas
= new wxPGCanvas();
710 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
711 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
712 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
714 m_iFlags
|= wxPG_FL_INITIALIZED
;
716 m_ncWidth
= wndsize
.GetWidth();
718 // Need to call OnResize handler or size given in constructor/Create
720 wxSizeEvent
sizeEvent(wndsize
,0);
724 // -----------------------------------------------------------------------
726 wxPropertyGrid::~wxPropertyGrid()
730 DoSelectProperty(NULL
);
732 // This should do prevent things from going too badly wrong
733 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
735 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
736 m_canvas
->ReleaseMouse();
738 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
739 m_tlp
->RemoveEventHandler(handler
);
743 if ( IsEditorsValueModified() )
744 ::wxMessageBox(wxS("Most recent change in property editor was lost!!!\n\n(if you don't want this to happen, close your frames and dialogs using Close(false).)"),
745 wxS("wxPropertyGrid Debug Warning") );
748 #if wxPG_DOUBLE_BUFFER
749 if ( m_doubleBuffer
)
750 delete m_doubleBuffer
;
753 //m_selected = (wxPGProperty*) NULL;
755 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
758 delete m_cursorSizeWE
;
760 #ifndef wxPG_ICON_WIDTH
765 // Delete cached text colours.
766 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
768 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
771 // Delete cached brushes.
772 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
774 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
777 // Delete common value records
778 for ( i
=0; i
<m_commonValues
.size(); i
++ )
780 delete GetCommonValue(i
);
784 // -----------------------------------------------------------------------
786 bool wxPropertyGrid::Destroy()
788 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
789 m_canvas
->ReleaseMouse();
791 return wxScrolledWindow::Destroy();
794 // -----------------------------------------------------------------------
796 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
798 return new wxPropertyGridPageState();
801 // -----------------------------------------------------------------------
802 // wxPropertyGrid overridden wxWindow methods
803 // -----------------------------------------------------------------------
805 void wxPropertyGrid::SetWindowStyleFlag( long style
)
807 long old_style
= m_windowStyle
;
809 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
811 wxASSERT( m_pState
);
813 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
816 EnableCategories( true );
818 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
820 // Disable categories
821 EnableCategories( false );
823 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
829 PrepareAfterItemsAdded();
831 m_pState
->m_itemsAdded
= 1;
833 #if wxPG_SUPPORT_TOOLTIPS
834 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
840 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
841 SetToolTip ( tooltip );
842 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
845 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
850 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
855 wxScrolledWindow::SetWindowStyleFlag ( style
);
857 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
859 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
861 CalculateFontAndBitmapStuff( m_vspacing
);
867 // -----------------------------------------------------------------------
869 void wxPropertyGrid::Freeze()
873 wxScrolledWindow::Freeze();
878 // -----------------------------------------------------------------------
880 void wxPropertyGrid::Thaw()
886 wxScrolledWindow::Thaw();
887 RecalculateVirtualSize();
888 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
892 // Force property re-selection
894 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
898 // -----------------------------------------------------------------------
900 void wxPropertyGrid::SetExtraStyle( long exStyle
)
902 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
904 #if defined(__WXMSW__)
907 // Don't use WS_EX_COMPOSITED just now.
910 if ( m_iFlags & wxPG_FL_IN_MANAGER )
911 hWnd = (HWND)GetParent()->GetHWND();
913 hWnd = (HWND)GetHWND();
915 ::SetWindowLong( hWnd, GWL_EXSTYLE,
916 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
919 //#elif defined(__WXGTK20__)
921 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
922 // truly was double-buffered.
923 if ( !this->IsDoubleBuffered() )
925 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
929 #if wxPG_DOUBLE_BUFFER
930 delete m_doubleBuffer
;
931 m_doubleBuffer
= NULL
;
936 wxScrolledWindow::SetExtraStyle( exStyle
);
938 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
939 m_pState
->InitNonCatMode();
941 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
942 m_windowStyle
|= wxPG_TOOLTIPS
;
945 wxPGGlobalVars
->m_extraStyle
= exStyle
;
948 // -----------------------------------------------------------------------
950 // returns the best acceptable minimal size
951 wxSize
wxPropertyGrid::DoGetBestSize() const
954 if ( m_lineHeight
> hei
)
956 wxSize sz
= wxSize( 60, hei
+40 );
962 // -----------------------------------------------------------------------
963 // wxPropertyGrid Font and Colour Methods
964 // -----------------------------------------------------------------------
966 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
970 m_captionFont
= wxScrolledWindow::GetFont();
972 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
973 m_subgroup_extramargin
= x
+ (x
/2);
976 #if wxPG_USE_RENDERER_NATIVE
977 m_iconWidth
= wxPG_ICON_WIDTH
;
978 #elif wxPG_ICON_WIDTH
980 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
981 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
982 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
986 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
987 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
988 m_gutterWidth
= wxPG_GUTTER_MIN
;
991 if ( vspacing
<= 1 ) vdiv
= 12;
992 else if ( vspacing
>= 3 ) vdiv
= 3;
994 m_spacingy
= m_fontHeight
/ vdiv
;
995 if ( m_spacingy
< wxPG_YSPACING_MIN
)
996 m_spacingy
= wxPG_YSPACING_MIN
;
999 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1000 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1002 m_captionFont
.SetWeight(wxBOLD
);
1003 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1005 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1008 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1009 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1012 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1014 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1015 RecalculateVirtualSize();
1017 InvalidateBestSize();
1020 // -----------------------------------------------------------------------
1022 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1028 // -----------------------------------------------------------------------
1030 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1031 int ga
= 1000, int ba
= 1000,
1032 bool forceDifferent
= false)
1039 // Recursion guard (allow 2 max)
1040 static int isinside
= 0;
1042 wxCHECK_MSG( isinside
< 3,
1044 wxT("wxPGAdjustColour should not be recursively called more than once") );
1049 int g
= src
.Green();
1052 if ( r2
>255 ) r2
= 255;
1053 else if ( r2
<0) r2
= 0;
1055 if ( g2
>255 ) g2
= 255;
1056 else if ( g2
<0) g2
= 0;
1058 if ( b2
>255 ) b2
= 255;
1059 else if ( b2
<0) b2
= 0;
1061 // Make sure they are somewhat different
1062 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1063 dst
= wxPGAdjustColour(src
,-(ra
*2));
1065 dst
= wxColour(r2
,g2
,b2
);
1067 // Recursion guard (allow 2 max)
1074 static int wxPGGetColAvg( const wxColour
& col
)
1076 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1080 void wxPropertyGrid::RegainColours()
1082 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1084 if ( !(m_coloursCustomized
& 0x0002) )
1086 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1088 // Make sure colour is dark enough
1090 int colDec
= wxPGGetColAvg(col
) - 230;
1092 int colDec
= wxPGGetColAvg(col
) - 200;
1095 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1100 if ( !(m_coloursCustomized
& 0x0001) )
1101 m_colMargin
= m_colCapBack
;
1103 if ( !(m_coloursCustomized
& 0x0004) )
1110 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1111 m_colCapFore
= capForeCol
;
1113 // Set the cached colour as well.
1114 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1117 if ( !(m_coloursCustomized
& 0x0008) )
1119 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1120 m_colPropBack
= bgCol
;
1122 // Set the cached brush as well.
1123 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1126 if ( !(m_coloursCustomized
& 0x0010) )
1128 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1129 m_colPropFore
= fgCol
;
1131 // Set the cached colour as well.
1132 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1135 if ( !(m_coloursCustomized
& 0x0020) )
1136 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1138 if ( !(m_coloursCustomized
& 0x0040) )
1139 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1141 if ( !(m_coloursCustomized
& 0x0080) )
1142 m_colLine
= m_colCapBack
;
1144 if ( !(m_coloursCustomized
& 0x0100) )
1145 m_colDisPropFore
= m_colCapFore
;
1147 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1150 // -----------------------------------------------------------------------
1152 void wxPropertyGrid::ResetColours()
1154 m_coloursCustomized
= 0;
1161 // -----------------------------------------------------------------------
1163 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1165 // Must disable active editor.
1168 bool selRes
= ClearSelection();
1169 wxPG_CHECK_MSG_DBG( selRes
,
1171 wxT("failed to deselect a property (editor probably had invalid value)") );
1174 // TODO: Following code is disabled with wxMac because
1175 // it is reported to fail. I (JMS) cannot debug it
1176 // personally right now.
1177 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1178 #if 1 // !defined(__WXMAC__)
1179 bool res
= wxScrolledWindow::SetFont( font
);
1182 CalculateFontAndBitmapStuff( m_vspacing
);
1185 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1193 // TODO: Remove after SetFont crash fixed.
1194 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1196 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1202 // -----------------------------------------------------------------------
1204 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1207 m_coloursCustomized
|= 0x80;
1211 // -----------------------------------------------------------------------
1213 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1216 m_coloursCustomized
|= 0x01;
1220 // -----------------------------------------------------------------------
1222 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1224 m_colPropBack
= col
;
1225 m_coloursCustomized
|= 0x08;
1227 // Set the cached brush as well.
1228 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1233 // -----------------------------------------------------------------------
1235 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1237 m_colPropFore
= col
;
1238 m_coloursCustomized
|= 0x10;
1240 // Set the cached colour as well.
1241 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1246 // -----------------------------------------------------------------------
1248 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1250 m_colEmptySpace
= col
;
1255 // -----------------------------------------------------------------------
1257 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1259 m_colDisPropFore
= col
;
1260 m_coloursCustomized
|= 0x100;
1264 // -----------------------------------------------------------------------
1266 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1269 m_coloursCustomized
|= 0x20;
1273 // -----------------------------------------------------------------------
1275 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1278 m_coloursCustomized
|= 0x40;
1282 // -----------------------------------------------------------------------
1284 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1287 m_coloursCustomized
|= 0x02;
1291 // -----------------------------------------------------------------------
1293 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1296 m_coloursCustomized
|= 0x04;
1298 // Set the cached colour as well.
1299 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1304 // -----------------------------------------------------------------------
1306 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1308 unsigned char ind
= index
;
1310 p
->m_bgColIndex
= ind
;
1313 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1314 SetBackgroundColourIndex(p
->Item(i
),index
);
1317 // -----------------------------------------------------------------------
1319 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1321 wxPG_PROP_ARG_CALL_PROLOG()
1326 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1328 // As it is most likely that the previous colour is used, start comparison
1330 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1332 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1341 colInd
= m_arrBgBrushes
.size();
1342 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1343 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1347 SetBackgroundColourIndex(p
,colInd
);
1349 // If this was on a visible grid, then draw it.
1350 DrawItemAndChildren(p
);
1353 // -----------------------------------------------------------------------
1355 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1357 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1359 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1362 // -----------------------------------------------------------------------
1364 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1366 unsigned char ind
= index
;
1368 p
->m_fgColIndex
= ind
;
1370 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1373 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1374 SetTextColourIndex( p
->Item(i
), index
, flags
);
1378 // -----------------------------------------------------------------------
1380 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1385 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1387 // As it is most likely that the previous colour is used, start comparison
1389 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1391 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1400 colInd
= m_arrFgCols
.size();
1401 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1402 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1408 // -----------------------------------------------------------------------
1410 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1413 wxPG_PROP_ARG_CALL_PROLOG()
1415 if ( p
->IsCategory() )
1417 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1418 cat
->SetTextColIndex(CacheColour(colour
));
1424 flags
|= wxPG_RECURSE
;
1425 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1427 DrawItemAndChildren(p
);
1430 // -----------------------------------------------------------------------
1432 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1434 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1436 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1439 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1441 wxPG_PROP_ARG_CALL_PROLOG()
1443 SetBackgroundColourIndex( p
, 0 );
1444 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1446 if ( p
->IsCategory() )
1448 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1449 cat
->SetTextColIndex(1);
1453 // -----------------------------------------------------------------------
1454 // wxPropertyGrid property adding and removal
1455 // -----------------------------------------------------------------------
1457 void wxPropertyGrid::PrepareAfterItemsAdded()
1459 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1461 m_pState
->m_itemsAdded
= 0;
1463 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1466 RecalculateVirtualSize();
1469 // -----------------------------------------------------------------------
1470 // wxPropertyGrid property value setting and getting
1471 // -----------------------------------------------------------------------
1473 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1475 m_pState
->DoSetPropertyValueUnspecified(p
);
1476 DrawItemAndChildren(p
);
1478 wxPGProperty
* parent
= p
->GetParent();
1480 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1483 parent
= parent
->GetParent();
1487 // -----------------------------------------------------------------------
1488 // wxPropertyGrid property operations
1489 // -----------------------------------------------------------------------
1491 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1493 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1497 bool changed
= false;
1499 // Is it inside collapsed section?
1500 if ( !p
->IsVisible() )
1503 wxPGProperty
* parent
= p
->GetParent();
1504 wxPGProperty
* grandparent
= parent
->GetParent();
1506 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1507 Expand( grandparent
);
1515 GetViewStart(&vx
,&vy
);
1516 vy
*=wxPG_PIXELS_PER_UNIT
;
1522 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1523 m_iFlags
|= wxPG_FL_SCROLLED
;
1526 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1528 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1529 m_iFlags
|= wxPG_FL_SCROLLED
;
1539 // -----------------------------------------------------------------------
1540 // wxPropertyGrid helper methods called by properties
1541 // -----------------------------------------------------------------------
1543 // Control font changer helper.
1544 void wxPropertyGrid::SetCurControlBoldFont()
1546 wxASSERT( m_wndEditor
);
1547 m_wndEditor
->SetFont( m_captionFont
);
1550 // -----------------------------------------------------------------------
1552 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1555 #if wxPG_SMALL_SCREEN
1556 // On small-screen devices, always show dialogs with default position and size.
1557 return wxDefaultPosition
;
1559 int splitterX
= GetSplitterPosition();
1563 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1565 ImprovedClientToScreen( &x
, &y
);
1567 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1568 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1575 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1585 new_y
= y
+ m_lineHeight
;
1587 return wxPoint(new_x
,new_y
);
1591 // -----------------------------------------------------------------------
1593 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1595 if ( src_str
.length() == 0 )
1601 bool prev_is_slash
= false;
1603 wxString::const_iterator i
= src_str
.begin();
1607 for ( ; i
!= src_str
.end(); i
++ )
1611 if ( a
!= wxS('\\') )
1613 if ( !prev_is_slash
)
1619 if ( a
== wxS('n') )
1622 dst_str
<< wxS('\n');
1624 dst_str
<< wxS('\n');
1627 else if ( a
== wxS('t') )
1628 dst_str
<< wxS('\t');
1632 prev_is_slash
= false;
1636 if ( prev_is_slash
)
1638 dst_str
<< wxS('\\');
1639 prev_is_slash
= false;
1643 prev_is_slash
= true;
1650 // -----------------------------------------------------------------------
1652 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1654 if ( src_str
.length() == 0 )
1660 wxString::const_iterator i
= src_str
.begin();
1661 wxUniChar prev_a
= wxS('\0');
1665 for ( ; i
!= src_str
.end(); i
++ )
1669 if ( a
>= wxS(' ') )
1671 // This surely is not something that requires an escape sequence.
1676 // This might need...
1677 if ( a
== wxS('\r') )
1679 // DOS style line end.
1680 // Already taken care below
1682 else if ( a
== wxS('\n') )
1683 // UNIX style line end.
1684 dst_str
<< wxS("\\n");
1685 else if ( a
== wxS('\t') )
1687 dst_str
<< wxS('\t');
1690 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1700 // -----------------------------------------------------------------------
1702 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1706 return (wxPGProperty
*) NULL
;
1709 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1712 // -----------------------------------------------------------------------
1713 // wxPropertyGrid graphics related methods
1714 // -----------------------------------------------------------------------
1716 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1720 // Update everything inside the box
1721 wxRect r
= GetUpdateRegion().GetBox();
1723 dc
.SetPen(m_colEmptySpace
);
1724 dc
.SetBrush(m_colEmptySpace
);
1725 dc
.DrawRectangle(r
);
1728 // -----------------------------------------------------------------------
1730 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1731 wxPGProperty
* property
) const
1733 // Prepare rectangle to be used
1735 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1736 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1738 #if (wxPG_USE_RENDERER_NATIVE)
1740 #elif wxPG_ICON_WIDTH
1741 // Drawing expand/collapse button manually
1742 dc
.SetPen(m_colPropFore
);
1743 if ( property
->IsCategory() )
1744 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1746 dc
.SetBrush(m_colPropBack
);
1748 dc
.DrawRectangle( r
);
1749 int _y
= r
.y
+(m_iconWidth
/2);
1750 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1755 if ( property
->IsExpanded() )
1757 // wxRenderer functions are non-mutating in nature, so it
1758 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1759 // Hopefully this does not cause problems.
1760 #if (wxPG_USE_RENDERER_NATIVE)
1761 wxRendererNative::Get().DrawTreeItemButton(
1767 #elif wxPG_ICON_WIDTH
1776 #if (wxPG_USE_RENDERER_NATIVE)
1777 wxRendererNative::Get().DrawTreeItemButton(
1783 #elif wxPG_ICON_WIDTH
1784 int _x
= r
.x
+(m_iconWidth
/2);
1785 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1791 #if (wxPG_USE_RENDERER_NATIVE)
1793 #elif wxPG_ICON_WIDTH
1796 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1800 // -----------------------------------------------------------------------
1803 // This is the one called by OnPaint event handler and others.
1804 // topy and bottomy are already unscrolled (ie. physical)
1806 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1808 unsigned int bottomy
,
1809 const wxRect
* clipRect
)
1811 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1813 m_pState
->EnsureVirtualHeight();
1815 wxRect tempClipRect
;
1818 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1819 clipRect
= &tempClipRect
;
1822 // items added check
1823 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1825 int paintFinishY
= 0;
1827 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1830 bool isBuffered
= false;
1832 #if wxPG_DOUBLE_BUFFER
1833 wxMemoryDC
* bufferDC
= NULL
;
1835 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1837 if ( !m_doubleBuffer
)
1839 paintFinishY
= clipRect
->y
;
1844 bufferDC
= new wxMemoryDC();
1846 // If nothing was changed, then just copy from double-buffer
1847 bufferDC
->SelectObject( *m_doubleBuffer
);
1857 dc
.SetClippingRegion( *clipRect
);
1858 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1861 #if wxPG_DOUBLE_BUFFER
1864 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1865 bufferDC
, 0, 0, wxCOPY
);
1866 dc
.DestroyClippingRegion(); // Is this really necessary?
1872 // Clear area beyond bottomY?
1873 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1875 dc
.SetPen(m_colEmptySpace
);
1876 dc
.SetBrush(m_colEmptySpace
);
1877 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1881 // -----------------------------------------------------------------------
1883 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1884 const wxPGProperty
* firstItem
,
1885 const wxPGProperty
* lastItem
,
1886 const wxRect
* clipRect
,
1887 bool isBuffered
) const
1889 // TODO: This should somehow be eliminated.
1890 wxRect tempClipRect
;
1893 wxASSERT(firstItem
);
1895 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1896 clipRect
= &tempClipRect
;
1900 firstItem
= DoGetItemAtY(clipRect
->y
);
1904 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1906 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1909 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1912 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1913 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1915 int lh
= m_lineHeight
;
1918 int lastItemBottomY
;
1920 firstItemTopY
= clipRect
->y
;
1921 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1923 // Align y coordinates to item boundaries
1924 firstItemTopY
-= firstItemTopY
% lh
;
1925 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1926 lastItemBottomY
-= 1;
1928 // Entire range outside scrolled, visible area?
1929 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1932 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1936 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1937 firstItem->GetLabel().c_str(),
1938 lastItem->GetLabel().c_str(),
1939 (int)(lastItemBottomY - firstItemTopY),
1941 (unsigned long)clipRect );
1946 long windowStyle
= m_windowStyle
;
1952 // With wxPG_DOUBLE_BUFFER, do double buffering
1953 // - buffer's y = 0, so align cliprect and coordinates to that
1955 #if wxPG_DOUBLE_BUFFER
1961 xRelMod
= clipRect
->x
;
1962 yRelMod
= clipRect
->y
;
1965 // clipRect conversion
1973 firstItemTopY
-= yRelMod
;
1974 lastItemBottomY
-= yRelMod
;
1977 wxUnusedVar(isBuffered
);
1980 int x
= m_marginWidth
- xRelMod
;
1982 const wxFont
& normalfont
= m_font
;
1984 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1986 bool isEnabled
= IsEnabled();
1989 // Prepare some pens and brushes that are often changed to.
1992 wxBrush
marginBrush(m_colMargin
);
1993 wxPen
marginPen(m_colMargin
);
1994 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1995 wxPen
linepen(m_colLine
,1,wxSOLID
);
1997 // pen that has same colour as text
1998 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2001 // Clear margin with background colour
2003 dc
.SetBrush( marginBrush
);
2004 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2006 dc
.SetPen( *wxTRANSPARENT_PEN
);
2007 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2010 const wxPGProperty
* selected
= m_selected
;
2011 const wxPropertyGridPageState
* state
= m_pState
;
2013 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2014 bool wasSelectedPainted
= false;
2017 // TODO: Only render columns that are within clipping region.
2019 dc
.SetFont(normalfont
);
2021 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2022 int endScanBottomY
= lastItemBottomY
+ lh
;
2023 int y
= firstItemTopY
;
2026 // Pregenerate list of visible properties.
2027 wxArrayPGProperty visPropArray
;
2028 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2030 for ( ; !it
.AtEnd(); it
.Next() )
2032 const wxPGProperty
* p
= *it
;
2034 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2036 visPropArray
.push_back((wxPGProperty
*)p
);
2038 if ( y
> endScanBottomY
)
2045 visPropArray
.push_back(NULL
);
2047 wxPGProperty
* nextP
= visPropArray
[0];
2049 int gridWidth
= state
->m_width
;
2052 for ( unsigned int arrInd
=1;
2053 nextP
&& y
<= lastItemBottomY
;
2056 wxPGProperty
* p
= nextP
;
2057 nextP
= visPropArray
[arrInd
];
2059 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2060 int textMarginHere
= x
;
2061 int renderFlags
= wxPGCellRenderer::Control
;
2063 int greyDepth
= m_marginWidth
;
2064 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2065 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2067 int greyDepthX
= greyDepth
- xRelMod
;
2069 // Use basic depth if in non-categoric mode and parent is base array.
2070 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2072 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2075 // Paint margin area
2076 dc
.SetBrush(marginBrush
);
2077 dc
.SetPen(marginPen
);
2078 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2080 dc
.SetPen( linepen
);
2085 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2091 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2093 sx
+= state
->m_colWidths
[si
];
2094 dc
.DrawLine( sx
, y
, sx
, y2
);
2097 // Horizontal Line, below
2098 // (not if both this and next is category caption)
2099 if ( p
->IsCategory() &&
2100 nextP
&& nextP
->IsCategory() )
2101 dc
.SetPen(m_colCapBack
);
2103 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2105 if ( p
== selected
)
2107 renderFlags
|= wxPGCellRenderer::Selected
;
2108 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2109 wasSelectedPainted
= true;
2117 if ( p
->IsCategory() )
2119 if ( p
->m_fgColIndex
== 0 )
2120 rowFgCol
= m_colCapFore
;
2122 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2123 rowBgBrush
= wxBrush(m_colCapBack
);
2125 else if ( p
!= selected
)
2127 // Disabled may get different colour.
2128 if ( !p
->IsEnabled() )
2129 rowFgCol
= m_colDisPropFore
;
2131 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2133 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2137 // Selected gets different colour.
2138 if ( reallyFocused
)
2140 rowFgCol
= m_colSelFore
;
2141 rowBgBrush
= wxBrush(m_colSelBack
);
2143 else if ( isEnabled
)
2145 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2146 rowBgBrush
= marginBrush
;
2150 rowFgCol
= m_colDisPropFore
;
2151 rowBgBrush
= wxBrush(m_colSelBack
);
2155 bool fontChanged
= false;
2157 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2162 if ( p
->IsCategory() )
2164 // Captions are all cells merged as one
2165 dc
.SetFont(m_captionFont
);
2167 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2169 dc
.SetBrush(rowBgBrush
);
2170 dc
.SetPen(rowBgBrush
.GetColour());
2171 dc
.SetTextForeground(rowFgCol
);
2173 dc
.DrawRectangle(cellRect
);
2176 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2177 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2180 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2181 DrawExpanderButton( dc
, butRect
, p
);
2185 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2187 dc
.SetFont(m_captionFont
);
2193 int nextCellWidth
= state
->m_colWidths
[0];
2194 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2195 int textXAdd
= textMarginHere
- greyDepthX
;
2197 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2199 cellRect
.width
= nextCellWidth
- 1;
2201 bool ctrlCell
= false;
2204 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2206 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2207 dc
.SetBrush(editorBgCol
);
2208 dc
.SetPen(editorBgCol
);
2209 dc
.SetTextForeground(m_colPropFore
);
2211 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2216 dc
.SetBrush(rowBgBrush
);
2217 dc
.SetPen(rowBgBrush
.GetColour());
2218 dc
.SetTextForeground(rowFgCol
);
2221 dc
.DrawRectangle(cellRect
);
2224 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2225 DrawExpanderButton( dc
, butRect
, p
);
2227 dc
.SetClippingRegion(cellRect
);
2229 cellRect
.x
+= textXAdd
;
2230 cellRect
.width
-= textXAdd
;
2235 wxPGCellRenderer
* renderer
;
2236 int cmnVal
= p
->GetCommonValue();
2237 if ( cmnVal
== -1 || ci
!= 1 )
2239 renderer
= p
->GetCellRenderer(ci
);
2240 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2244 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2245 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2249 cellX
+= state
->m_colWidths
[ci
];
2250 if ( ci
< (state
->m_colWidths
.size()-1) )
2251 nextCellWidth
= state
->m_colWidths
[ci
+1];
2253 dc
.DestroyClippingRegion(); // Is this really necessary?
2259 dc
.SetFont(normalfont
);
2264 // Refresh editor controls (seems not needed on msw)
2265 // NOTE: This code is mandatory for GTK!
2266 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2267 if ( wasSelectedPainted
)
2270 m_wndEditor
->Refresh();
2272 m_wndEditor2
->Refresh();
2279 // -----------------------------------------------------------------------
2281 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2285 if ( m_width
< 10 || m_height
< 10 ||
2286 !m_pState
->m_properties
->GetChildCount() ||
2287 p1
== (wxPGProperty
*) NULL
)
2288 return wxRect(0,0,0,0);
2293 // Return rect which encloses the given property range
2295 int visTop
= p1
->GetY();
2298 visBottom
= p2
->GetY() + m_lineHeight
;
2300 visBottom
= m_height
+ visTop
;
2302 // If seleced property is inside the range, we'll extend the range to include
2304 wxPGProperty
* selected
= m_selected
;
2307 int selectedY
= selected
->GetY();
2308 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2310 wxWindow
* editor
= GetEditorControl();
2313 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2314 if ( visBottom2
> visBottom
)
2315 visBottom
= visBottom2
;
2320 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2323 // -----------------------------------------------------------------------
2325 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2330 if ( m_pState
->m_itemsAdded
)
2331 PrepareAfterItemsAdded();
2333 wxRect r
= GetPropertyRect(p1
, p2
);
2336 m_canvas
->RefreshRect(r
);
2340 // -----------------------------------------------------------------------
2342 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2344 if ( p
== m_selected
)
2345 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2347 DrawItemAndChildren(p
);
2350 // -----------------------------------------------------------------------
2352 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2357 // Draw item, children, and parent too, if it is not category
2358 wxPGProperty
* parent
= p
->GetParent();
2361 !parent
->IsCategory() &&
2362 parent
->GetParent() )
2365 parent
= parent
->GetParent();
2368 DrawItemAndChildren(p
);
2371 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2373 wxCHECK_RET( p
, wxT("invalid property id") );
2375 // Do not draw if in non-visible page
2376 if ( p
->GetParentState() != m_pState
)
2379 // do not draw a single item if multiple pending
2380 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2383 wxWindow
* wndPrimary
= GetEditorControl();
2385 // Update child control.
2386 if ( m_selected
&& m_selected
->GetParent() == p
)
2387 m_selected
->UpdateControl(wndPrimary
);
2389 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2391 DrawItems(p
, lastDrawn
);
2394 // -----------------------------------------------------------------------
2396 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2397 const wxRect
*rect
)
2399 PrepareAfterItemsAdded();
2401 wxWindow::Refresh(false);
2403 // TODO: Coordinate translation
2404 m_canvas
->Refresh(false, rect
);
2406 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2407 // I think this really helps only GTK+1.2
2408 if ( m_wndEditor
) m_wndEditor
->Refresh();
2409 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2413 // -----------------------------------------------------------------------
2414 // wxPropertyGrid global operations
2415 // -----------------------------------------------------------------------
2417 void wxPropertyGrid::Clear()
2421 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2422 wxPG_CHECK_RET_DBG( selRes
,
2423 wxT("failed to deselect a property (editor probably had invalid value)") );
2426 m_pState
->DoClear();
2432 RecalculateVirtualSize();
2434 // Need to clear some area at the end
2436 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2439 // -----------------------------------------------------------------------
2441 bool wxPropertyGrid::EnableCategories( bool enable
)
2443 if ( !ClearSelection() )
2449 // Enable categories
2452 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2457 // Disable categories
2459 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2462 if ( !m_pState
->EnableCategories(enable
) )
2467 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2469 m_pState
->m_itemsAdded
= 1; // force
2470 PrepareAfterItemsAdded();
2474 m_pState
->m_itemsAdded
= 1;
2476 // No need for RecalculateVirtualSize() here - it is already called in
2477 // wxPropertyGridPageState method above.
2484 // -----------------------------------------------------------------------
2486 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2488 wxASSERT( pNewState
);
2489 wxASSERT( pNewState
->GetGrid() );
2491 if ( pNewState
== m_pState
)
2494 wxPGProperty
* oldSelection
= m_selected
;
2499 bool selRes
= ClearSelection();
2500 wxPG_CHECK_RET_DBG( selRes
,
2501 wxT("failed to deselect a property (editor probably had invalid value)") );
2504 m_pState
->m_selected
= oldSelection
;
2506 bool orig_mode
= m_pState
->IsInNonCatMode();
2507 bool new_state_mode
= pNewState
->IsInNonCatMode();
2509 m_pState
= pNewState
;
2512 int pgWidth
= GetClientSize().x
;
2513 if ( HasVirtualWidth() )
2515 int minWidth
= pgWidth
;
2516 if ( pNewState
->m_width
< minWidth
)
2518 pNewState
->m_width
= minWidth
;
2519 pNewState
->CheckColumnWidths();
2525 // Just in case, fully re-center splitter
2526 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2527 pNewState
->m_fSplitterX
= -1.0;
2529 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2532 m_propHover
= (wxPGProperty
*) NULL
;
2534 // If necessary, convert state to correct mode.
2535 if ( orig_mode
!= new_state_mode
)
2537 // This should refresh as well.
2538 EnableCategories( orig_mode
?false:true );
2540 else if ( !m_frozen
)
2542 // Refresh, if not frozen.
2543 if ( m_pState
->m_itemsAdded
)
2544 PrepareAfterItemsAdded();
2547 if ( m_pState
->m_selected
)
2548 DoSelectProperty( m_pState
->m_selected
);
2550 RecalculateVirtualSize(0);
2554 m_pState
->m_itemsAdded
= 1;
2557 // -----------------------------------------------------------------------
2559 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2561 wxPG_PROP_ARG_CALL_PROLOG()
2563 m_pState
->SortChildren( p
);
2566 // -----------------------------------------------------------------------
2568 void wxPropertyGrid::Sort()
2570 bool selRes
= ClearSelection(); // This must be before state clear
2571 wxPG_CHECK_RET_DBG( selRes
,
2572 wxT("failed to deselect a property (editor probably had invalid value)") );
2577 // -----------------------------------------------------------------------
2579 // Call to SetSplitterPosition will always disable splitter auto-centering
2580 // if parent window is shown.
2581 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2583 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2586 wxPropertyGridPageState
* state
= m_pState
;
2588 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2593 CorrectEditorWidgetSizeX();
2599 // -----------------------------------------------------------------------
2601 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2603 SetSplitterPosition( m_width
/2, true );
2604 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2605 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2608 // -----------------------------------------------------------------------
2609 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2610 // -----------------------------------------------------------------------
2612 // Returns nearest paint visible property (such that will be painted unless
2613 // window is scrolled or resized). If given property is paint visible, then
2614 // it itself will be returned
2615 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2617 int vx
,vy1
;// Top left corner of client
2618 GetViewStart(&vx
,&vy1
);
2619 vy1
*= wxPG_PIXELS_PER_UNIT
;
2621 int vy2
= vy1
+ m_height
;
2622 int propY
= p
->GetY2(m_lineHeight
);
2624 if ( (propY
+ m_lineHeight
) < vy1
)
2627 return DoGetItemAtY( vy1
);
2629 else if ( propY
> vy2
)
2632 return DoGetItemAtY( vy2
);
2635 // Itself paint visible
2640 // -----------------------------------------------------------------------
2641 // Methods related to change in value, value modification and sending events
2642 // -----------------------------------------------------------------------
2644 // commits any changes in editor of selected property
2645 // return true if validation did not fail
2646 // flags are same as with DoSelectProperty
2647 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2649 // Committing already?
2650 if ( m_inCommitChangesFromEditor
)
2653 // Don't do this if already processing editor event. It might
2654 // induce recursive dialogs and crap like that.
2655 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2657 if ( m_inDoPropertyChanged
)
2664 IsEditorsValueModified() &&
2665 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2668 m_inCommitChangesFromEditor
= 1;
2670 wxVariant
variant(m_selected
->GetValueRef());
2671 bool valueIsPending
= false;
2673 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2674 // due to another window getting focus
2675 wxWindow
* oldFocus
= m_curFocused
;
2677 bool validationFailure
= false;
2678 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2680 m_chgInfo_changedProperty
= NULL
;
2682 // If truly modified, schedule value as pending.
2683 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2685 if ( DoEditorValidate() &&
2686 PerformValidation(m_selected
, variant
) )
2688 valueIsPending
= true;
2692 validationFailure
= true;
2697 EditorsValueWasNotModified();
2702 m_inCommitChangesFromEditor
= 0;
2704 if ( validationFailure
&& !forceSuccess
)
2708 oldFocus
->SetFocus();
2709 m_curFocused
= oldFocus
;
2712 res
= OnValidationFailure(m_selected
, variant
);
2714 // Now prevent further validation failure messages
2717 EditorsValueWasNotModified();
2718 OnValidationFailureReset(m_selected
);
2721 else if ( valueIsPending
)
2723 DoPropertyChanged( m_selected
, flags
);
2724 EditorsValueWasNotModified();
2733 // -----------------------------------------------------------------------
2735 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2739 // Runs all validation functionality.
2740 // Returns true if value passes all tests.
2743 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2745 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2747 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2752 // Adapt list to child values, if necessary
2753 wxVariant listValue
= pendingValue
;
2754 wxVariant
* pPendingValue
= &pendingValue
;
2755 wxVariant
* pList
= NULL
;
2757 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2758 // string value, then we need treat as it was changed instead
2759 // (or, in addition, as is the case with composite string parent).
2760 // This includes creating list variant for child values.
2762 wxPGProperty
* pwc
= p
->GetParent();
2763 wxPGProperty
* changedProperty
= p
;
2764 wxPGProperty
* baseChangedProperty
= changedProperty
;
2765 wxVariant bcpPendingList
;
2767 listValue
= pendingValue
;
2768 listValue
.SetName(p
->GetBaseName());
2771 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2773 wxVariantList tempList
;
2774 wxVariant
lv(tempList
, pwc
->GetBaseName());
2775 lv
.Append(listValue
);
2777 pPendingValue
= &listValue
;
2779 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2781 baseChangedProperty
= pwc
;
2782 bcpPendingList
= lv
;
2785 changedProperty
= pwc
;
2786 pwc
= pwc
->GetParent();
2790 wxPGProperty
* evtChangingProperty
= changedProperty
;
2792 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2794 value
= *pPendingValue
;
2798 // Convert list to child values
2799 pList
= pPendingValue
;
2800 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2803 wxVariant evtChangingValue
= value
;
2805 if ( flags
& SendEvtChanging
)
2807 // FIXME: After proper ValueToString()s added, remove
2808 // this. It is just a temporary fix, as evt_changing
2809 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2810 // (unless it is selected, and textctrl editor is open).
2811 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2813 evtChangingProperty
= baseChangedProperty
;
2814 if ( evtChangingProperty
!= p
)
2816 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2820 evtChangingValue
= pendingValue
;
2824 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2826 if ( changedProperty
== m_selected
)
2828 wxWindow
* editor
= GetEditorControl();
2829 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2830 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2834 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2839 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2840 m_chgInfo_changedProperty
= changedProperty
;
2841 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2842 m_chgInfo_pendingValue
= value
;
2845 m_chgInfo_valueList
= *pList
;
2847 m_chgInfo_valueList
.MakeNull();
2849 // If changedProperty is not property which value was edited,
2850 // then call wxPGProperty::ValidateValue() for that as well.
2851 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2853 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2857 if ( flags
& SendEvtChanging
)
2859 // SendEvent returns true if event was vetoed
2860 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2864 if ( flags
& IsStandaloneValidation
)
2866 // If called in 'generic' context, we need to reset
2867 // m_chgInfo_changedProperty and write back translated value.
2868 m_chgInfo_changedProperty
= NULL
;
2869 pendingValue
= value
;
2875 // -----------------------------------------------------------------------
2877 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2879 if ( !msg
.length() )
2883 if ( !wxPGGlobalVars
->m_offline
)
2885 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2888 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2891 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2894 pStatusBar
->SetStatusText(msg
);
2902 ::wxMessageBox(msg
, _T("Property Error"));
2905 // -----------------------------------------------------------------------
2907 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2909 int vfb
= m_validationInfo
.m_failureBehavior
;
2911 if ( vfb
& wxPG_VFB_BEEP
)
2914 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2915 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2917 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2918 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2920 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2922 wxColour vfbFg
= *wxWHITE
;
2923 wxColour vfbBg
= *wxRED
;
2924 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2925 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2927 DrawItemAndChildren(property
);
2929 if ( property
== m_selected
)
2931 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2933 wxWindow
* editor
= GetEditorControl();
2936 editor
->SetForegroundColour(vfbFg
);
2937 editor
->SetBackgroundColour(vfbBg
);
2943 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2945 wxString msg
= m_validationInfo
.m_failureMessage
;
2947 if ( !msg
.length() )
2948 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2950 DoShowPropertyError(property
, msg
);
2953 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2956 // -----------------------------------------------------------------------
2958 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2960 int vfb
= m_validationInfo
.m_failureBehavior
;
2962 if ( vfb
& wxPG_VFB_MARK_CELL
)
2964 property
->SetCell(0, NULL
);
2965 property
->SetCell(1, NULL
);
2967 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2969 if ( property
== m_selected
&& GetEditorControl() )
2971 // Calling this will recreate the control, thus resetting its colour
2972 RefreshProperty(property
);
2976 DrawItemAndChildren(property
);
2981 // -----------------------------------------------------------------------
2983 // flags are same as with DoSelectProperty
2984 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2986 if ( m_inDoPropertyChanged
)
2989 wxWindow
* editor
= GetEditorControl();
2991 m_pState
->m_anyModified
= 1;
2993 m_inDoPropertyChanged
= 1;
2995 // Maybe need to update control
2996 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2998 // These values were calculated in PerformValidation()
2999 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3000 wxVariant value
= m_chgInfo_pendingValue
;
3002 wxPGProperty
* topPaintedProperty
= changedProperty
;
3004 while ( !topPaintedProperty
->IsCategory() &&
3005 !topPaintedProperty
->IsRoot() )
3007 topPaintedProperty
= topPaintedProperty
->GetParent();
3010 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3012 // Set as Modified (not if dragging just began)
3013 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3015 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3016 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3019 SetCurControlBoldFont();
3025 // Propagate updates to parent(s)
3027 wxPGProperty
* prevPwc
= NULL
;
3029 while ( prevPwc
!= topPaintedProperty
)
3031 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3033 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3036 SetCurControlBoldFont();
3040 pwc
= pwc
->GetParent();
3043 // Draw the actual property
3044 DrawItemAndChildren( topPaintedProperty
);
3047 // If value was set by wxPGProperty::OnEvent, then update the editor
3049 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3052 p
->GetEditorClass()->UpdateControl(p
, editor
);
3056 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3057 if ( m_wndEditor
) m_wndEditor
->Refresh();
3058 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3063 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3065 // If top parent has composite string value, then send to child parents,
3066 // starting from baseChangedProperty.
3067 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3069 pwc
= m_chgInfo_baseChangedProperty
;
3071 while ( pwc
!= changedProperty
)
3073 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3074 pwc
= pwc
->GetParent();
3078 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3080 m_inDoPropertyChanged
= 0;
3085 // -----------------------------------------------------------------------
3087 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3089 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3091 m_chgInfo_changedProperty
= NULL
;
3093 if ( PerformValidation(p
, newValue
) )
3095 DoPropertyChanged(p
);
3100 OnValidationFailure(p
, newValue
);
3106 // -----------------------------------------------------------------------
3108 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3110 wxPGProperty
* prop
= GetSelectedProperty();
3113 return wxNullVariant
;
3115 wxTextCtrl
* tc
= GetEditorTextCtrl();
3116 wxVariant value
= prop
->GetValue();
3118 if ( !tc
|| !IsEditorsValueModified() )
3121 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3124 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3125 return prop
->GetValue();
3130 // -----------------------------------------------------------------------
3132 // Runs wxValidator for the selected property
3133 bool wxPropertyGrid::DoEditorValidate()
3138 // -----------------------------------------------------------------------
3140 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3142 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3143 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3145 wxWindow
* parent
= wnd
->GetParent();
3148 (parent
== m_canvas
||
3149 parent
->GetParent() == m_canvas
) )
3151 OnCustomEditorEvent((wxCommandEvent
&)event
);
3155 return wxPanel::ProcessEvent(event
);
3158 // -----------------------------------------------------------------------
3160 // NB: It may really not be wxCommandEvent - must check if necessary
3162 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3164 wxPGProperty
* selected
= m_selected
;
3166 // Somehow, event is handled after property has been deselected.
3167 // Possibly, but very rare.
3171 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3174 wxVariant
pendingValue(selected
->GetValueRef());
3175 wxWindow
* wnd
= GetEditorControl();
3177 bool wasUnspecified
= selected
->IsValueUnspecified();
3178 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3180 bool valueIsPending
= false;
3182 m_chgInfo_changedProperty
= NULL
;
3184 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3187 // Filter out excess wxTextCtrl modified events
3188 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3190 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3192 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3194 wxString newTcValue
= tc
->GetValue();
3195 if ( m_prevTcValue
== newTcValue
)
3198 m_prevTcValue
= newTcValue
;
3201 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3203 bool validationFailure
= false;
3204 bool buttonWasHandled
= false;
3207 // Try common button handling
3208 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3210 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3214 buttonWasHandled
= true;
3215 // Store as res2, as previously (and still currently alternatively)
3216 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3217 // in wxPGProperty::OnEvent().
3218 adapter
->ShowDialog( this, selected
);
3223 if ( !buttonWasHandled
)
3227 // First call editor class' event handler.
3228 const wxPGEditor
* editor
= selected
->GetEditorClass();
3230 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3232 // If changes, validate them
3233 if ( DoEditorValidate() )
3235 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3236 valueIsPending
= true;
3240 validationFailure
= true;
3245 // Then the property's custom handler (must be always called, unless
3246 // validation failed).
3247 if ( !validationFailure
)
3248 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3251 // SetValueInEvent(), as called in one of the functions referred above
3252 // overrides editor's value.
3253 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3255 valueIsPending
= true;
3256 pendingValue
= m_changeInEventValue
;
3257 selFlags
|= wxPG_SEL_DIALOGVAL
;
3260 if ( !validationFailure
&& valueIsPending
)
3261 if ( !PerformValidation(m_selected
, pendingValue
) )
3262 validationFailure
= true;
3264 if ( validationFailure
)
3266 OnValidationFailure(selected
, pendingValue
);
3268 else if ( valueIsPending
)
3270 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3272 DoPropertyChanged(selected
, selFlags
);
3273 EditorsValueWasNotModified();
3275 // Regardless of editor type, unfocus editor on
3276 // text-editing related enter press.
3277 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3284 // No value after all
3286 // Regardless of editor type, unfocus editor on
3287 // text-editing related enter press.
3288 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3293 // Let unhandled button click events go to the parent
3294 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3296 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3297 GetEventHandler()->AddPendingEvent(evt
);
3301 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3304 // -----------------------------------------------------------------------
3305 // wxPropertyGrid editor control helper methods
3306 // -----------------------------------------------------------------------
3308 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3310 int itemy
= p
->GetY2(m_lineHeight
);
3312 int cust_img_space
= 0;
3313 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3314 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3316 // TODO: If custom image detection changes from current, change this.
3317 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3319 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3320 int imwid
= p
->OnMeasureImage().x
;
3321 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3322 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3327 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3329 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3334 // -----------------------------------------------------------------------
3336 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3338 wxSize sz
= GetImageSize(p
, item
);
3339 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3340 wxPG_CUSTOM_IMAGE_SPACINGY
,
3345 // return size of custom paint image
3346 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3348 // If called with NULL property, then return default image
3349 // size for properties that use image.
3351 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3353 wxSize cis
= p
->OnMeasureImage(item
);
3355 int choiceCount
= p
->m_choices
.GetCount();
3356 int comVals
= p
->GetDisplayedCommonValueCount();
3357 if ( item
>= choiceCount
&& comVals
> 0 )
3359 unsigned int cvi
= item
-choiceCount
;
3360 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3362 else if ( item
>= 0 && choiceCount
== 0 )
3363 return wxSize(0, 0);
3368 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3373 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3380 // -----------------------------------------------------------------------
3382 // takes scrolling into account
3383 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3386 GetViewStart(&vx
,&vy
);
3387 vy
*=wxPG_PIXELS_PER_UNIT
;
3388 vx
*=wxPG_PIXELS_PER_UNIT
;
3391 ClientToScreen( px
, py
);
3394 // -----------------------------------------------------------------------
3396 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3399 GetViewStart(&pt2
.x
,&pt2
.y
);
3400 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3401 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3405 return m_pState
->HitTest(pt2
);
3408 // -----------------------------------------------------------------------
3410 // custom set cursor
3411 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3413 if ( type
== m_curcursor
&& !override
) return;
3415 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3417 if ( type
== wxCURSOR_SIZEWE
)
3418 cursor
= m_cursorSizeWE
;
3420 m_canvas
->SetCursor( *cursor
);
3425 // -----------------------------------------------------------------------
3426 // wxPropertyGrid property selection
3427 // -----------------------------------------------------------------------
3429 // Setups event handling for child control
3430 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3432 wxWindowID id
= argWnd
->GetId();
3434 if ( argWnd
== m_wndEditor
)
3436 argWnd
->Connect(id
, wxEVT_MOTION
,
3437 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3439 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3440 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3442 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3443 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3445 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3446 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3448 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3449 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3451 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3452 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3454 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3455 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3460 void wxPropertyGrid::FreeEditors()
3463 // Return focus back to canvas from children (this is required at least for
3464 // GTK+, which, unlike Windows, clears focus when control is destroyed
3465 // instead of moving it to closest parent).
3466 wxWindow
* focus
= wxWindow::FindFocus();
3469 wxWindow
* parent
= focus
->GetParent();
3472 if ( parent
== m_canvas
)
3477 parent
= parent
->GetParent();
3481 // Do not free editors immediately if processing events
3484 m_wndEditor2
->Hide();
3485 wxPendingDelete
.Append( m_wndEditor2
);
3486 m_wndEditor2
= (wxWindow
*) NULL
;
3491 m_wndEditor
->Hide();
3492 wxPendingDelete
.Append( m_wndEditor
);
3493 m_wndEditor
= (wxWindow
*) NULL
;
3497 // Call with NULL to de-select property
3498 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3500 wxPanel
* canvas
= GetPanel();
3504 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3505 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3507 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3510 if ( m_inDoSelectProperty
)
3513 m_inDoSelectProperty
= 1;
3515 wxPGProperty
* prev
= m_selected
;
3519 m_inDoSelectProperty
= 0;
3525 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3527 wxPrintf( "None selected\n" );
3530 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3532 wxPrintf( "P = NULL\n" );
3535 // If we are frozen, then just set the values.
3538 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3539 m_editorFocused
= 0;
3542 m_pState
->m_selected
= p
;
3544 // If frozen, always free controls. But don't worry, as Thaw will
3545 // recall SelectProperty to recreate them.
3548 // Prevent any further selection measures in this call
3549 p
= (wxPGProperty
*) NULL
;
3554 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3556 // Only set focus if not deselecting
3559 if ( flags
& wxPG_SEL_FOCUS
)
3563 m_wndEditor
->SetFocus();
3564 m_editorFocused
= 1;
3573 m_inDoSelectProperty
= 0;
3578 // First, deactivate previous
3582 OnValidationFailureReset(m_selected
);
3584 // Must double-check if this is an selected in case of forceswitch
3587 if ( !CommitChangesFromEditor(flags
) )
3589 // Validation has failed, so we can't exit the previous editor
3590 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3591 // _("Invalid Value"),wxOK|wxICON_ERROR);
3592 m_inDoSelectProperty
= 0;
3600 m_selected
= (wxPGProperty
*) NULL
;
3601 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3603 // We need to always fully refresh the grid here
3606 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3607 EditorsValueWasNotModified();
3610 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3613 // Then, activate the one given.
3616 int propY
= p
->GetY2(m_lineHeight
);
3618 int splitterX
= GetSplitterPosition();
3619 m_editorFocused
= 0;
3621 m_pState
->m_selected
= p
;
3622 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3624 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3626 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3628 // Do we need OnMeasureCalls?
3629 wxSize imsz
= p
->OnMeasureImage();
3632 // Only create editor for non-disabled non-caption
3633 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3635 // do this for non-caption items
3639 // Do we need to paint the custom image, if any?
3640 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3641 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3642 !p
->GetEditorClass()->CanContainCustomImage()
3644 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3646 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3647 wxPoint goodPos
= grect
.GetPosition();
3648 #if wxPG_CREATE_CONTROLS_HIDDEN
3649 int coord_adjust
= m_height
- goodPos
.y
;
3650 goodPos
.y
+= coord_adjust
;
3653 const wxPGEditor
* editor
= p
->GetEditorClass();
3654 wxCHECK_MSG(editor
, false,
3655 wxT("NULL editor class not allowed"));
3657 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3659 wxPGWindowList wndList
= editor
->CreateControls(this,
3664 m_wndEditor
= wndList
.m_primary
;
3665 m_wndEditor2
= wndList
.m_secondary
;
3666 wxWindow
* primaryCtrl
= GetEditorControl();
3669 // Essentially, primaryCtrl == m_wndEditor
3672 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3673 // value is drawn as normal, and m_wndEditor2 is assumed
3674 // to be a right-aligned button that triggers a separate editorCtrl
3679 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3680 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3682 // Set validator, if any
3683 #if wxUSE_VALIDATORS
3684 wxValidator
* validator
= p
->GetValidator();
3686 primaryCtrl
->SetValidator(*validator
);
3689 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3690 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3692 // If it has modified status, use bold font
3693 // (must be done before capturing m_ctrlXAdjust)
3694 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3695 SetCurControlBoldFont();
3698 // Fix TextCtrl indentation
3699 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3700 wxTextCtrl
* tc
= NULL
;
3701 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3702 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3704 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3706 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3709 // Store x relative to splitter (we'll need it).
3710 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3712 // Check if background clear is not necessary
3713 wxPoint pos
= m_wndEditor
->GetPosition();
3714 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3716 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3719 m_wndEditor
->SetSizeHints(3, 3);
3721 #if wxPG_CREATE_CONTROLS_HIDDEN
3722 m_wndEditor
->Show(false);
3723 m_wndEditor
->Freeze();
3725 goodPos
= m_wndEditor
->GetPosition();
3726 goodPos
.y
-= coord_adjust
;
3727 m_wndEditor
->Move( goodPos
);
3730 SetupChildEventHandling(primaryCtrl
);
3732 // Focus and select all (wxTextCtrl, wxComboBox etc)
3733 if ( flags
& wxPG_SEL_FOCUS
)
3735 primaryCtrl
->SetFocus();
3737 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3743 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3744 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3746 // Get proper id for wndSecondary
3747 m_wndSecId
= m_wndEditor2
->GetId();
3748 wxWindowList children
= m_wndEditor2
->GetChildren();
3749 wxWindowList::iterator node
= children
.begin();
3750 if ( node
!= children
.end() )
3751 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3753 m_wndEditor2
->SetSizeHints(3,3);
3755 #if wxPG_CREATE_CONTROLS_HIDDEN
3756 wxRect sec_rect
= m_wndEditor2
->GetRect();
3757 sec_rect
.y
-= coord_adjust
;
3759 // Fine tuning required to fix "oversized"
3760 // button disappearance bug.
3761 if ( sec_rect
.y
< 0 )
3763 sec_rect
.height
+= sec_rect
.y
;
3766 m_wndEditor2
->SetSize( sec_rect
);
3768 m_wndEditor2
->Show();
3770 SetupChildEventHandling(m_wndEditor2
);
3772 // If no primary editor, focus to button to allow
3773 // it to interprete ENTER etc.
3774 // NOTE: Due to problems focusing away from it, this
3775 // has been disabled.
3777 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3778 m_wndEditor2->SetFocus();
3782 if ( flags
& wxPG_SEL_FOCUS
)
3783 m_editorFocused
= 1;
3788 // Make sure focus is in grid canvas (important for wxGTK, at least)
3792 EditorsValueWasNotModified();
3794 // If it's inside collapsed section, expand parent, scroll, etc.
3795 // Also, if it was partially visible, scroll it into view.
3796 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3801 #if wxPG_CREATE_CONTROLS_HIDDEN
3802 m_wndEditor
->Thaw();
3804 m_wndEditor
->Show(true);
3811 // Make sure focus is in grid canvas
3815 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3821 // Show help text in status bar.
3822 // (if found and grid not embedded in manager with help box and
3823 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3826 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3828 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3829 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3831 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3833 statusbar
= frame
->GetStatusBar();
3838 const wxString
* pHelpString
= (const wxString
*) NULL
;
3842 pHelpString
= &p
->GetHelpString();
3843 if ( pHelpString
->length() )
3845 // Set help box text.
3846 statusbar
->SetStatusText( *pHelpString
);
3847 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3851 if ( (!pHelpString
|| !pHelpString
->length()) &&
3852 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3854 // Clear help box - but only if it was written
3855 // by us at previous time.
3856 statusbar
->SetStatusText( m_emptyString
);
3857 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3863 m_inDoSelectProperty
= 0;
3865 // call wx event handler (here so that it also occurs on deselection)
3866 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3871 // -----------------------------------------------------------------------
3873 bool wxPropertyGrid::UnfocusEditor()
3875 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3878 if ( !CommitChangesFromEditor(0) )
3882 DrawItem(m_selected
);
3887 // -----------------------------------------------------------------------
3889 // This method is not inline because it called dozens of times
3890 // (i.e. two-arg function calls create smaller code size).
3891 bool wxPropertyGrid::DoClearSelection()
3893 return DoSelectProperty((wxPGProperty
*)NULL
);
3896 // -----------------------------------------------------------------------
3897 // wxPropertyGrid expand/collapse state
3898 // -----------------------------------------------------------------------
3900 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3902 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3904 // If active editor was inside collapsed section, then disable it
3905 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3907 if ( !ClearSelection() )
3911 // Store dont-center-splitter flag 'cause we need to temporarily set it
3912 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3913 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3915 bool res
= m_pState
->DoCollapse(pwc
);
3920 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3922 RecalculateVirtualSize();
3924 // Redraw etc. only if collapsed was visible.
3925 if (pwc
->IsVisible() &&
3927 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3929 // When item is collapsed so that scrollbar would move,
3930 // graphics mess is about (unless we redraw everything).
3935 // Clear dont-center-splitter flag if it wasn't set
3936 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3941 // -----------------------------------------------------------------------
3943 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3945 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3947 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3949 // Store dont-center-splitter flag 'cause we need to temporarily set it
3950 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3951 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3953 bool res
= m_pState
->DoExpand(pwc
);
3958 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3960 RecalculateVirtualSize();
3962 // Redraw etc. only if expanded was visible.
3963 if ( pwc
->IsVisible() && !m_frozen
&&
3964 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3968 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3971 DrawItems(pwc
, NULL
);
3976 // Clear dont-center-splitter flag if it wasn't set
3977 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3982 // -----------------------------------------------------------------------
3984 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3987 return m_pState
->DoHideProperty(p
, hide
, flags
);
3990 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3993 if ( !ClearSelection() )
3997 m_pState
->DoHideProperty(p
, hide
, flags
);
3999 RecalculateVirtualSize();
4006 // -----------------------------------------------------------------------
4007 // wxPropertyGrid size related methods
4008 // -----------------------------------------------------------------------
4010 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4012 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4016 // If virtual height was changed, then recalculate editor control position(s)
4017 if ( m_pState
->m_vhCalcPending
)
4018 CorrectEditorWidgetPosY();
4020 m_pState
->EnsureVirtualHeight();
4023 int by1
= m_pState
->GetVirtualHeight();
4024 int by2
= m_pState
->GetActualVirtualHeight();
4027 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4028 wxASSERT_MSG( false,
4034 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4036 int x
= m_pState
->m_width
;
4037 int y
= m_pState
->m_virtualHeight
;
4040 GetClientSize(&width
,&height
);
4042 // Now adjust virtual size.
4043 SetVirtualSize(x
, y
);
4049 // Adjust scrollbars
4050 if ( HasVirtualWidth() )
4052 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4053 xPos
= GetScrollPos( wxHORIZONTAL
);
4056 if ( forceXPos
!= -1 )
4059 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4062 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4063 int yPos
= GetScrollPos( wxVERTICAL
);
4065 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4066 xAmount
, yAmount
, xPos
, yPos
, true );
4068 // Must re-get size now
4069 GetClientSize(&width
,&height
);
4071 if ( !HasVirtualWidth() )
4073 m_pState
->SetVirtualWidth(width
);
4080 m_canvas
->SetSize( x
, y
);
4082 m_pState
->CheckColumnWidths();
4085 CorrectEditorWidgetSizeX();
4087 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4090 // -----------------------------------------------------------------------
4092 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4094 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4098 GetClientSize(&width
,&height
);
4103 #if wxPG_DOUBLE_BUFFER
4104 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4106 int dblh
= (m_lineHeight
*2);
4107 if ( !m_doubleBuffer
)
4109 // Create double buffer bitmap to draw on, if none
4110 int w
= (width
>250)?width
:250;
4111 int h
= height
+ dblh
;
4113 m_doubleBuffer
= new wxBitmap( w
, h
);
4117 int w
= m_doubleBuffer
->GetWidth();
4118 int h
= m_doubleBuffer
->GetHeight();
4120 // Double buffer must be large enough
4121 if ( w
< width
|| h
< (height
+dblh
) )
4123 if ( w
< width
) w
= width
;
4124 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4125 delete m_doubleBuffer
;
4126 m_doubleBuffer
= new wxBitmap( w
, h
);
4133 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4134 m_ncWidth
= event
.GetSize().x
;
4138 if ( m_pState
->m_itemsAdded
)
4139 PrepareAfterItemsAdded();
4141 // Without this, virtual size (atleast under wxGTK) will be skewed
4142 RecalculateVirtualSize();
4148 // -----------------------------------------------------------------------
4150 void wxPropertyGrid::SetVirtualWidth( int width
)
4154 // Disable virtual width
4155 width
= GetClientSize().x
;
4156 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4160 // Enable virtual width
4161 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4163 m_pState
->SetVirtualWidth( width
);
4166 void wxPropertyGrid::SetFocusOnCanvas()
4168 m_canvas
->SetFocusIgnoringChildren();
4169 m_editorFocused
= 0;
4172 // -----------------------------------------------------------------------
4173 // wxPropertyGrid mouse event handling
4174 // -----------------------------------------------------------------------
4176 // selFlags uses same values DoSelectProperty's flags
4177 // Returns true if event was vetoed.
4178 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4180 // Send property grid event of specific type and with specific property
4181 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4182 evt
.SetPropertyGrid(this);
4183 evt
.SetEventObject(m_eventObject
);
4187 evt
.SetCanVeto(true);
4188 evt
.SetupValidationInfo();
4189 m_validationInfo
.m_pValue
= pValue
;
4191 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4193 evtHandler
->ProcessEvent(evt
);
4195 return evt
.WasVetoed();
4198 // -----------------------------------------------------------------------
4200 // Return false if should be skipped
4201 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4205 // Need to set focus?
4206 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4211 wxPropertyGridPageState
* state
= m_pState
;
4213 int splitterHitOffset
;
4214 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4216 wxPGProperty
* p
= DoGetItemAtY(y
);
4220 int depth
= (int)p
->GetDepth() - 1;
4222 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4224 if ( x
>= marginEnds
)
4228 if ( p
->IsCategory() )
4230 // This is category.
4231 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4233 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4235 // Expand, collapse, activate etc. if click on text or left of splitter.
4238 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4243 if ( !DoSelectProperty( p
) )
4246 // On double-click, expand/collapse.
4247 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4249 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4250 else DoExpand( p
, true );
4254 else if ( splitterHit
== -1 )
4257 unsigned int selFlag
= 0;
4258 if ( columnHit
== 1 )
4260 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4261 selFlag
= wxPG_SEL_FOCUS
;
4263 if ( !DoSelectProperty( p
, selFlag
) )
4266 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4268 if ( p
->GetChildCount() && !p
->IsCategory() )
4269 // On double-click, expand/collapse.
4270 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4272 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4273 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4274 else DoExpand( p
, true );
4281 // click on splitter
4282 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4284 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4286 // Double-clicking the splitter causes auto-centering
4287 CenterSplitter( true );
4289 else if ( m_dragStatus
== 0 )
4292 // Begin draggin the splitter
4296 // Changes must be committed here or the
4297 // value won't be drawn correctly
4298 if ( !CommitChangesFromEditor() )
4301 m_wndEditor
->Show ( false );
4304 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4306 m_canvas
->CaptureMouse();
4307 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4311 m_draggedSplitter
= splitterHit
;
4312 m_dragOffset
= splitterHitOffset
;
4314 wxClientDC
dc(m_canvas
);
4316 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4317 // Fixes button disappearance bug
4319 m_wndEditor2
->Show ( false );
4322 m_startingSplitterX
= x
- splitterHitOffset
;
4330 if ( p
->GetChildCount() )
4332 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4334 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4336 int y2
= y
% m_lineHeight
;
4337 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4339 // On click on expander button, expand/collapse
4340 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4341 DoCollapse( p
, true );
4343 DoExpand( p
, true );
4352 // -----------------------------------------------------------------------
4354 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4355 wxMouseEvent
& WXUNUSED(event
) )
4359 // Select property here as well
4360 wxPGProperty
* p
= m_propHover
;
4361 if ( p
!= m_selected
)
4362 DoSelectProperty( p
);
4364 // Send right click event.
4365 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4372 // -----------------------------------------------------------------------
4374 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4375 wxMouseEvent
& WXUNUSED(event
) )
4379 // Select property here as well
4380 wxPGProperty
* p
= m_propHover
;
4382 if ( p
!= m_selected
)
4383 DoSelectProperty( p
);
4385 // Send double-click event.
4386 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4393 // -----------------------------------------------------------------------
4395 #if wxPG_SUPPORT_TOOLTIPS
4397 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4399 if ( tipString
.length() )
4401 m_canvas
->SetToolTip(tipString
);
4405 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4406 m_canvas
->SetToolTip( m_emptyString
);
4408 m_canvas
->SetToolTip( NULL
);
4413 #endif // #if wxPG_SUPPORT_TOOLTIPS
4415 // -----------------------------------------------------------------------
4417 // Return false if should be skipped
4418 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4420 // Safety check (needed because mouse capturing may
4421 // otherwise freeze the control)
4422 if ( m_dragStatus
> 0 && !event
.Dragging() )
4424 HandleMouseUp(x
,y
,event
);
4427 wxPropertyGridPageState
* state
= m_pState
;
4429 int splitterHitOffset
;
4430 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4431 int splitterX
= x
- splitterHitOffset
;
4433 if ( m_dragStatus
> 0 )
4435 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4436 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4439 int newSplitterX
= x
- m_dragOffset
;
4440 int splitterX
= x
- splitterHitOffset
;
4442 // Splitter redraw required?
4443 if ( newSplitterX
!= splitterX
)
4446 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4447 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4448 state
->m_fSplitterX
= (float) newSplitterX
;
4451 CorrectEditorWidgetSizeX();
4465 int ih
= m_lineHeight
;
4468 #if wxPG_SUPPORT_TOOLTIPS
4469 wxPGProperty
* prevHover
= m_propHover
;
4470 unsigned char prevSide
= m_mouseSide
;
4472 int curPropHoverY
= y
- (y
% ih
);
4474 // On which item it hovers
4475 if ( ( !m_propHover
)
4477 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4480 // Mouse moves on another property
4482 m_propHover
= DoGetItemAtY(y
);
4483 m_propHoverY
= curPropHoverY
;
4486 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4489 #if wxPG_SUPPORT_TOOLTIPS
4490 // Store which side we are on
4492 if ( columnHit
== 1 )
4494 else if ( columnHit
== 0 )
4498 // If tooltips are enabled, show label or value as a tip
4499 // in case it doesn't otherwise show in full length.
4501 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4503 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4505 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4507 if ( m_propHover
&& !m_propHover
->IsCategory() )
4510 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4512 // Show help string as a tooltip
4513 wxString tipString
= m_propHover
->GetHelpString();
4515 SetToolTip(tipString
);
4519 // Show cropped value string as a tooltip
4523 if ( m_mouseSide
== 1 )
4525 tipString
= m_propHover
->m_label
;
4526 space
= splitterX
-m_marginWidth
-3;
4528 else if ( m_mouseSide
== 2 )
4530 tipString
= m_propHover
->GetDisplayedString();
4532 space
= m_width
- splitterX
;
4533 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4534 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4540 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4543 SetToolTip( tipString
);
4550 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4551 m_canvas
->SetToolTip( m_emptyString
);
4553 m_canvas
->SetToolTip( NULL
);
4564 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4565 m_canvas
->SetToolTip( m_emptyString
);
4567 m_canvas
->SetToolTip( NULL
);
4575 if ( splitterHit
== -1 ||
4577 HasFlag(wxPG_STATIC_SPLITTER
) )
4579 // hovering on something else
4580 if ( m_curcursor
!= wxCURSOR_ARROW
)
4581 CustomSetCursor( wxCURSOR_ARROW
);
4585 // Do not allow splitter cursor on caption items.
4586 // (also not if we were dragging and its started
4587 // outside the splitter region)
4590 !m_propHover
->IsCategory() &&
4594 // hovering on splitter
4596 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4597 // reliably detected.
4598 //if ( m_curcursor != wxCURSOR_SIZEWE )
4599 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4605 // hovering on something else
4606 if ( m_curcursor
!= wxCURSOR_ARROW
)
4607 CustomSetCursor( wxCURSOR_ARROW
);
4614 // -----------------------------------------------------------------------
4616 // Also handles Leaving event
4617 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4618 wxMouseEvent
&WXUNUSED(event
) )
4620 wxPropertyGridPageState
* state
= m_pState
;
4624 int splitterHitOffset
;
4625 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4627 // No event type check - basicly calling this method should
4628 // just stop dragging.
4629 // Left up after dragged?
4630 if ( m_dragStatus
>= 1 )
4633 // End Splitter Dragging
4635 // DO NOT ENABLE FOLLOWING LINE!
4636 // (it is only here as a reminder to not to do it)
4639 // Disable splitter auto-centering
4640 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4642 // This is necessary to return cursor
4643 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4645 m_canvas
->ReleaseMouse();
4646 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4649 // Set back the default cursor, if necessary
4650 if ( splitterHit
== -1 ||
4653 CustomSetCursor( wxCURSOR_ARROW
);
4658 // Control background needs to be cleared
4659 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4660 DrawItem( m_selected
);
4664 m_wndEditor
->Show ( true );
4667 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4668 // Fixes button disappearance bug
4670 m_wndEditor2
->Show ( true );
4673 // This clears the focus.
4674 m_editorFocused
= 0;
4680 // -----------------------------------------------------------------------
4682 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4684 int splitterX
= GetSplitterPosition();
4687 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4691 wxWindow
* wnd
= GetEditorControl();
4693 // Hide popup on clicks
4694 if ( event
.GetEventType() != wxEVT_MOTION
)
4695 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4697 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4703 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4705 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4706 ux
>= (r
.x
+r
.width
) ||
4708 event
.m_y
>= (r
.y
+r
.height
)
4718 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4723 // -----------------------------------------------------------------------
4725 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4728 if ( OnMouseCommon( event
, &x
, &y
) )
4730 HandleMouseClick(x
,y
,event
);
4735 // -----------------------------------------------------------------------
4737 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4740 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4741 HandleMouseRightClick(x
,y
,event
);
4745 // -----------------------------------------------------------------------
4747 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4749 // Always run standard mouse-down handler as well
4750 OnMouseClick(event
);
4753 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4754 HandleMouseDoubleClick(x
,y
,event
);
4758 // -----------------------------------------------------------------------
4760 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4763 if ( OnMouseCommon( event
, &x
, &y
) )
4765 HandleMouseMove(x
,y
,event
);
4770 // -----------------------------------------------------------------------
4772 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4774 // Called when mouse moves in the empty space below the properties.
4775 CustomSetCursor( wxCURSOR_ARROW
);
4778 // -----------------------------------------------------------------------
4780 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4783 if ( OnMouseCommon( event
, &x
, &y
) )
4785 HandleMouseUp(x
,y
,event
);
4790 // -----------------------------------------------------------------------
4792 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4794 // This may get called from child control as well, so event's
4795 // mouse position cannot be relied on.
4797 if ( event
.Entering() )
4799 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4801 // TODO: Fix this (detect parent and only do
4802 // cursor trick if it is a manager).
4803 wxASSERT( GetParent() );
4804 GetParent()->SetCursor(wxNullCursor
);
4806 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4809 GetParent()->SetCursor(wxNullCursor
);
4811 else if ( event
.Leaving() )
4813 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4814 m_canvas
->SetCursor( wxNullCursor
);
4816 // Get real cursor position
4817 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4819 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4822 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4824 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4828 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4836 // -----------------------------------------------------------------------
4838 // Common code used by various OnMouseXXXChild methods.
4839 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4841 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4842 wxASSERT( topCtrlWnd
);
4844 event
.GetPosition(&x
,&y
);
4846 int splitterX
= GetSplitterPosition();
4848 wxRect r
= topCtrlWnd
->GetRect();
4849 if ( !m_dragStatus
&&
4850 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4851 y
>= 0 && y
< r
.height \
4854 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4859 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4866 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4869 if ( OnMouseChildCommon(event
,&x
,&y
) )
4871 bool res
= HandleMouseClick(x
,y
,event
);
4872 if ( !res
) event
.Skip();
4876 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4879 wxASSERT( m_wndEditor
);
4880 // These coords may not be exact (about +-2),
4881 // but that should not matter (right click is about item, not position).
4882 wxPoint pt
= m_wndEditor
->GetPosition();
4883 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4884 wxASSERT( m_selected
);
4885 m_propHover
= m_selected
;
4886 bool res
= HandleMouseRightClick(x
,y
,event
);
4887 if ( !res
) event
.Skip();
4890 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4893 if ( OnMouseChildCommon(event
,&x
,&y
) )
4895 bool res
= HandleMouseMove(x
,y
,event
);
4896 if ( !res
) event
.Skip();
4900 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4903 if ( OnMouseChildCommon(event
,&x
,&y
) )
4905 bool res
= HandleMouseUp(x
,y
,event
);
4906 if ( !res
) event
.Skip();
4910 // -----------------------------------------------------------------------
4911 // wxPropertyGrid keyboard event handling
4912 // -----------------------------------------------------------------------
4914 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4916 // Translates wxKeyEvent to wxPG_ACTION_XXX
4918 int keycode
= event
.GetKeyCode();
4919 int modifiers
= event
.GetModifiers();
4921 wxASSERT( !(modifiers
&~(0xFFFF)) );
4923 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4925 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4927 if ( it
== m_actionTriggers
.end() )
4932 int second
= (it
->second
>>16) & 0xFFFF;
4936 return (it
->second
& 0xFFFF);
4939 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4941 wxASSERT( !(modifiers
&~(0xFFFF)) );
4943 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4945 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4947 if ( it
!= m_actionTriggers
.end() )
4949 // This key combination is already used
4951 // Can add secondary?
4952 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4953 wxT("You can only add up to two separate actions per key combination.") );
4955 action
= it
->second
| (action
<<16);
4958 m_actionTriggers
[hashMapKey
] = action
;
4961 void wxPropertyGrid::ClearActionTriggers( int action
)
4963 wxPGHashMapI2I::iterator it
;
4965 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4967 if ( it
->second
== action
)
4969 m_actionTriggers
.erase(it
);
4974 static void CopyTextToClipboard( const wxString
& text
)
4976 if ( wxTheClipboard
->Open() )
4978 // This data objects are held by the clipboard,
4979 // so do not delete them in the app.
4980 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4981 wxTheClipboard
->Close();
4985 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4988 // Handles key event when editor control is not focused.
4991 wxASSERT( !m_frozen
);
4995 // Travelsal between items, collapsing/expanding, etc.
4996 int keycode
= event
.GetKeyCode();
4998 if ( keycode
== WXK_TAB
)
5001 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
5005 // Ignore Alt and Control when they are down alone
5006 if ( keycode
== WXK_ALT
||
5007 keycode
== WXK_CONTROL
)
5014 int action
= KeyEventToActions(event
, &secondAction
);
5020 if ( ButtonTriggerKeyTest(action
, event
) )
5023 wxPGProperty
* p
= m_selected
;
5025 if ( action
== wxPG_ACTION_COPY
)
5027 CopyTextToClipboard(p
->GetDisplayedString());
5031 // Travel and expand/collapse
5034 if ( p
->GetChildCount() &&
5035 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5038 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5040 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5043 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5045 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5052 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5056 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5067 if ( selectDir
>= -1 )
5069 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5071 DoSelectProperty(p
);
5077 // If nothing was selected, select the first item now
5078 // (or navigate out of tab).
5079 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5081 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5082 if ( p
) DoSelectProperty(p
);
5087 // -----------------------------------------------------------------------
5089 // Potentially handles a keyboard event for editor controls.
5090 // Returns false if event should *not* be skipped (on true it can
5091 // be optionally skipped).
5092 // Basicly, false means that SelectProperty was called (or was about
5093 // to be called, if canDestroy was false).
5094 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5098 if ( !m_selected
|| !m_wndEditor
)
5103 int action
= KeyEventToAction(event
);
5106 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5109 // Esc cancels any changes
5110 if ( IsEditorsValueModified() )
5112 EditorsValueWasNotModified();
5114 // Update the control as well
5115 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5117 m_selected
->GetDisplayedString() );
5120 OnValidationFailureReset(m_selected
);
5125 else if ( action
== wxPG_ACTION_COPY
)
5127 // NB: There is some problem with getting native cut-copy-paste keys to go through
5128 // for embedded editor wxTextCtrl. This is why we emulate.
5130 wxTextCtrl
* tc
= GetEditorTextCtrl();
5133 wxString sel
= tc
->GetStringSelection();
5135 CopyTextToClipboard(sel
);
5139 CopyTextToClipboard(m_selected
->GetDisplayedString());
5142 else if ( action
== wxPG_ACTION_CUT
)
5144 wxTextCtrl
* tc
= GetEditorTextCtrl();
5148 tc
->GetSelection(&from
, &to
);
5151 CopyTextToClipboard(tc
->GetStringSelection());
5152 tc
->Remove(from
, to
);
5156 else if ( action
== wxPG_ACTION_PASTE
)
5158 wxTextCtrl
* tc
= GetEditorTextCtrl();
5161 if (wxTheClipboard
->Open())
5163 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5165 wxTextDataObject data
;
5166 wxTheClipboard
->GetData( data
);
5168 tc
->GetSelection(&from
, &to
);
5171 tc
->Remove(from
, to
);
5172 tc
->WriteText(data
.GetText());
5176 tc
->WriteText(data
.GetText());
5179 wxTheClipboard
->Close();
5187 // -----------------------------------------------------------------------
5189 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5191 HandleKeyEvent( event
);
5194 // -----------------------------------------------------------------------
5196 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5201 // -----------------------------------------------------------------------
5203 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5208 action
= KeyEventToActions(event
, &secondAction
);
5211 // Does the keycode trigger button?
5212 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5215 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5216 GetEventHandler()->AddPendingEvent(evt
);
5223 // -----------------------------------------------------------------------
5225 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5227 int keycode
= event
.GetKeyCode();
5229 // Ignore Alt and Control when they are down alone
5230 if ( keycode
== WXK_ALT
||
5231 keycode
== WXK_CONTROL
)
5237 if ( ButtonTriggerKeyTest(-1, event
) )
5240 if ( HandleChildKey(event
) == true )
5243 GetEventHandler()->AddPendingEvent(event
);
5246 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5248 GetEventHandler()->AddPendingEvent(event
);
5253 // -----------------------------------------------------------------------
5254 // wxPropertyGrid miscellaneous event handling
5255 // -----------------------------------------------------------------------
5257 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5260 // Check if the focus is in this control or one of its children
5261 wxWindow
* newFocused
= wxWindow::FindFocus();
5263 if ( newFocused
!= m_curFocused
)
5264 HandleFocusChange( newFocused
);
5267 // Called by focus event handlers. newFocused is the window that becomes focused.
5268 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5270 unsigned int oldFlags
= m_iFlags
;
5272 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5274 wxWindow
* parent
= newFocused
;
5276 // This must be one of nextFocus' parents.
5279 // Use m_eventObject, which is either wxPropertyGrid or
5280 // wxPropertyGridManager, as appropriate.
5281 if ( parent
== m_eventObject
)
5283 m_iFlags
|= wxPG_FL_FOCUSED
;
5286 parent
= parent
->GetParent();
5289 m_curFocused
= newFocused
;
5291 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5292 (oldFlags
& wxPG_FL_FOCUSED
) )
5294 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5296 // Need to store changed value
5297 CommitChangesFromEditor();
5303 // Preliminary code for tab-order respecting
5304 // tab-traversal (but should be moved to
5307 wxWindow* prevFocus = event.GetWindow();
5308 wxWindow* useThis = this;
5309 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5310 useThis = GetParent();
5313 prevFocus->GetParent() == useThis->GetParent() )
5315 wxList& children = useThis->GetParent()->GetChildren();
5317 wxNode* node = children.Find(prevFocus);
5319 if ( node->GetNext() &&
5320 useThis == node->GetNext()->GetData() )
5321 DoSelectProperty(GetFirst());
5322 else if ( node->GetPrevious () &&
5323 useThis == node->GetPrevious()->GetData() )
5324 DoSelectProperty(GetLastProperty());
5331 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5332 DrawItem( m_selected
);
5336 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5338 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5339 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5340 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5341 //else if ( event.GetWindow() )
5343 HandleFocusChange(event
.GetWindow());
5348 // -----------------------------------------------------------------------
5350 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5352 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5355 // event.Skip() being commented out is aworkaround for bug reported
5356 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5360 // -----------------------------------------------------------------------
5362 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5364 m_iFlags
|= wxPG_FL_SCROLLED
;
5369 // -----------------------------------------------------------------------
5371 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5373 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5375 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5379 // -----------------------------------------------------------------------
5380 // Property editor related functions
5381 // -----------------------------------------------------------------------
5383 // noDefCheck = true prevents infinite recursion.
5384 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5387 wxASSERT( editorClass
);
5389 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5390 RegisterDefaultEditors();
5392 wxString name
= editorClass
->GetName();
5394 // Existing editor under this name?
5395 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5397 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5399 // If this name was already used, try class name.
5400 name
= editorClass
->GetClassInfo()->GetClassName();
5401 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5404 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5405 (wxPGEditor
*) vt_it
->second
,
5406 "Editor with given name was already registered" );
5408 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5413 // Use this in RegisterDefaultEditors.
5414 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5415 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5417 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5418 new wxPG##EDITOR##Editor, true ); \
5421 // Registers all default editor classes
5422 void wxPropertyGrid::RegisterDefaultEditors()
5424 wxPGRegisterDefaultEditorClass( TextCtrl
);
5425 wxPGRegisterDefaultEditorClass( Choice
);
5426 wxPGRegisterDefaultEditorClass( ComboBox
);
5427 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5428 #if wxPG_INCLUDE_CHECKBOX
5429 wxPGRegisterDefaultEditorClass( CheckBox
);
5431 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5433 // Register SpinCtrl etc. editors before use
5434 RegisterAdditionalEditors();
5437 // -----------------------------------------------------------------------
5438 // wxPGStringTokenizer
5439 // Needed to handle C-style string lists (e.g. "str1" "str2")
5440 // -----------------------------------------------------------------------
5442 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5443 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5447 wxPGStringTokenizer::~wxPGStringTokenizer()
5451 bool wxPGStringTokenizer::HasMoreTokens()
5453 const wxString
& str
= *m_str
;
5455 wxString::const_iterator i
= m_curPos
;
5457 wxUniChar delim
= m_delimeter
;
5459 wxUniChar prev_a
= wxT('\0');
5461 bool inToken
= false;
5463 while ( i
!= str
.end() )
5472 m_readyToken
.clear();
5477 if ( prev_a
!= wxT('\\') )
5481 if ( a
!= wxT('\\') )
5501 m_curPos
= str
.end();
5509 wxString
wxPGStringTokenizer::GetNextToken()
5511 return m_readyToken
;
5514 // -----------------------------------------------------------------------
5516 // -----------------------------------------------------------------------
5518 wxPGChoiceEntry::wxPGChoiceEntry()
5519 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5523 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5524 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5525 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5529 // -----------------------------------------------------------------------
5531 // -----------------------------------------------------------------------
5533 wxPGChoicesData::wxPGChoicesData()
5538 wxPGChoicesData::~wxPGChoicesData()
5543 void wxPGChoicesData::Clear()
5547 for ( i
=0; i
<m_items
.size(); i
++ )
5555 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5557 wxASSERT( m_items
.size() == 0 );
5561 for ( i
=0; i
<data
->GetCount(); i
++ )
5562 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5565 // -----------------------------------------------------------------------
5567 // -----------------------------------------------------------------------
5569 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5573 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5574 m_data
->Insert( -1, p
);
5578 // -----------------------------------------------------------------------
5580 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5584 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5585 p
->SetBitmap(bitmap
);
5586 m_data
->Insert( -1, p
);
5590 // -----------------------------------------------------------------------
5592 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5596 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5597 m_data
->Insert(index
, p
);
5601 // -----------------------------------------------------------------------
5603 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5607 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5608 m_data
->Insert( index
, p
);
5612 // -----------------------------------------------------------------------
5614 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5620 while ( index
< GetCount() )
5622 int cmpRes
= GetLabel(index
).Cmp(label
);
5628 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5629 m_data
->Insert( index
, p
);
5633 // -----------------------------------------------------------------------
5635 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5639 unsigned int itemcount
= 0;
5640 const wxChar
** p
= &labels
[0];
5641 while ( *p
) { p
++; itemcount
++; }
5644 for ( i
= 0; i
< itemcount
; i
++ )
5646 int value
= wxPG_INVALID_VALUE
;
5649 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5653 // -----------------------------------------------------------------------
5655 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5660 unsigned int itemcount
= arr
.size();
5662 for ( i
= 0; i
< itemcount
; i
++ )
5664 int value
= wxPG_INVALID_VALUE
;
5667 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5671 // -----------------------------------------------------------------------
5673 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5678 unsigned int itemcount
= arr
.size();
5680 for ( i
= 0; i
< itemcount
; i
++ )
5682 int value
= wxPG_INVALID_VALUE
;
5683 if ( &arrint
&& arrint
.size() )
5685 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5689 // -----------------------------------------------------------------------
5691 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5693 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5695 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5696 delete m_data
->Item(i
);
5697 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5698 m_data
->m_items
.begin()+nIndex
+count
);
5701 // -----------------------------------------------------------------------
5703 int wxPGChoices::Index( const wxString
& str
) const
5708 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5710 if ( m_data
->Item(i
)->GetText() == str
)
5717 // -----------------------------------------------------------------------
5719 int wxPGChoices::Index( int val
) const
5724 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5726 if ( m_data
->Item(i
)->GetValue() == val
)
5733 // -----------------------------------------------------------------------
5735 wxArrayString
wxPGChoices::GetLabels() const
5740 if ( this && IsOk() )
5741 for ( i
=0; i
<GetCount(); i
++ )
5742 arr
.push_back(GetLabel(i
));
5747 // -----------------------------------------------------------------------
5749 bool wxPGChoices::HasValues() const
5754 // -----------------------------------------------------------------------
5756 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5763 for ( i
=0; i
< strings
.size(); i
++ )
5765 int index
= Index(strings
[i
]);
5767 arr
.Add(GetValue(index
));
5769 arr
.Add(wxPG_INVALID_VALUE
);
5776 // -----------------------------------------------------------------------
5778 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5779 wxArrayString
* unmatched
) const
5786 for ( i
=0; i
< strings
.size(); i
++ )
5788 const wxString
& str
= strings
[i
];
5789 int index
= Index(str
);
5792 else if ( unmatched
)
5793 unmatched
->Add(str
);
5800 // -----------------------------------------------------------------------
5802 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5806 if ( data
!= wxPGChoicesEmptyData
)
5813 // -----------------------------------------------------------------------
5815 void wxPGChoices::Init()
5817 m_data
= wxPGChoicesEmptyData
;
5820 // -----------------------------------------------------------------------
5822 void wxPGChoices::Free()
5824 if ( m_data
!= wxPGChoicesEmptyData
)
5827 m_data
= wxPGChoicesEmptyData
;
5831 // -----------------------------------------------------------------------
5832 // wxPropertyGridEvent
5833 // -----------------------------------------------------------------------
5835 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5838 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5839 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5840 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5841 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5842 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5843 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5844 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5845 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5846 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5849 // -----------------------------------------------------------------------
5851 void wxPropertyGridEvent::Init()
5853 m_validationInfo
= NULL
;
5855 m_wasVetoed
= false;
5858 // -----------------------------------------------------------------------
5860 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5861 : wxCommandEvent(commandType
,id
)
5867 // -----------------------------------------------------------------------
5869 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5870 : wxCommandEvent(event
)
5872 m_eventType
= event
.GetEventType();
5873 m_eventObject
= event
.m_eventObject
;
5875 m_property
= event
.m_property
;
5876 m_validationInfo
= event
.m_validationInfo
;
5877 m_canVeto
= event
.m_canVeto
;
5878 m_wasVetoed
= event
.m_wasVetoed
;
5881 // -----------------------------------------------------------------------
5883 wxPropertyGridEvent::~wxPropertyGridEvent()
5887 // -----------------------------------------------------------------------
5889 wxEvent
* wxPropertyGridEvent::Clone() const
5891 return new wxPropertyGridEvent( *this );
5894 // -----------------------------------------------------------------------
5895 // wxPropertyGridPopulator
5896 // -----------------------------------------------------------------------
5898 wxPropertyGridPopulator::wxPropertyGridPopulator()
5902 wxPGGlobalVars
->m_offline
++;
5905 // -----------------------------------------------------------------------
5907 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5910 m_propHierarchy
.clear();
5913 // -----------------------------------------------------------------------
5915 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5921 // -----------------------------------------------------------------------
5923 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5926 // Free unused sets of choices
5927 wxPGHashMapS2P::iterator it
;
5929 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5931 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5938 m_pg
->GetPanel()->Refresh();
5940 wxPGGlobalVars
->m_offline
--;
5943 // -----------------------------------------------------------------------
5945 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5946 const wxString
& propLabel
,
5947 const wxString
& propName
,
5948 const wxString
* propValue
,
5949 wxPGChoices
* pChoices
)
5951 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5952 wxPGProperty
* parent
= GetCurParent();
5954 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5956 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5960 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5962 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5966 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5968 property
->SetLabel(propLabel
);
5969 property
->DoSetName(propName
);
5971 if ( pChoices
&& pChoices
->IsOk() )
5972 property
->SetChoices(*pChoices
);
5974 m_state
->DoInsert(parent
, -1, property
);
5977 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
5982 // -----------------------------------------------------------------------
5984 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5986 m_propHierarchy
.push_back(property
);
5987 DoScanForChildren();
5988 m_propHierarchy
.pop_back();
5991 // -----------------------------------------------------------------------
5993 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5994 const wxString
& idString
)
5996 wxPGChoices choices
;
5999 if ( choicesString
[0] == wxT('@') )
6001 wxString ids
= choicesString
.substr(1);
6002 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6003 if ( it
== m_dictIdChoices
.end() )
6004 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6006 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6011 if ( idString
.length() )
6013 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6014 if ( it
!= m_dictIdChoices
.end() )
6016 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6023 // Parse choices string
6024 wxString::const_iterator it
= choicesString
.begin();
6028 bool labelValid
= false;
6030 for ( ; it
!= choicesString
.end(); it
++ )
6036 if ( c
== wxT('"') )
6041 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6042 choices
.Add(label
, l
);
6045 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6050 else if ( c
== wxT('=') )
6057 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6064 if ( c
== wxT('"') )
6077 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6078 choices
.Add(label
, l
);
6081 if ( !choices
.IsOk() )
6083 choices
.EnsureData();
6087 if ( idString
.length() )
6088 m_dictIdChoices
[idString
] = choices
.GetData();
6095 // -----------------------------------------------------------------------
6097 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6099 if ( s
.Last() == wxT('%') )
6101 wxString s2
= s
.substr(0,s
.length()-1);
6103 if ( s2
.ToLong(&val
, 10) )
6105 *pval
= (val
*max
)/100;
6111 return s
.ToLong(pval
, 10);
6114 // -----------------------------------------------------------------------
6116 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6117 const wxString
& type
,
6118 const wxString
& value
)
6120 int l
= m_propHierarchy
.size();
6124 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6125 wxString valuel
= value
.Lower();
6128 if ( type
.length() == 0 )
6133 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6135 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6137 else if ( value
.ToLong(&v
, 0) )
6144 if ( type
== wxT("string") )
6148 else if ( type
== wxT("int") )
6151 value
.ToLong(&v
, 0);
6154 else if ( type
== wxT("bool") )
6156 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6163 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6168 p
->SetAttribute( name
, variant
);
6173 // -----------------------------------------------------------------------
6175 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6177 wxLogError(_("Error in resource: %s"),msg
.c_str());
6180 // -----------------------------------------------------------------------
6182 #endif // wxUSE_PROPGRID