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 char wxPropertyGridNameStr
[] = "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
= 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
= 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");
200 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
204 delete m_defaultRenderer
;
206 // This will always have one ref
207 delete m_fontFamilyChoices
;
210 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
211 delete ((wxValidator
*)m_arrValidators
[i
]);
215 // Destroy value type class instances.
216 wxPGHashMapS2P::iterator vt_it
;
218 // Destroy editor class instances.
219 // iterate over all the elements in the class
220 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
222 delete ((wxPGEditor
*)vt_it
->second
);
225 delete wxPGProperty::sm_wxPG_LABEL
;
228 void wxPropertyGridInitGlobalsIfNeeded()
232 // -----------------------------------------------------------------------
234 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
235 // and tries to commit property value.
236 // -----------------------------------------------------------------------
238 class wxPGTLWHandler
: public wxEvtHandler
242 wxPGTLWHandler( wxPropertyGrid
* pg
)
250 void OnClose( wxCloseEvent
& event
)
252 // ClearSelection forces value validation/commit.
253 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
263 wxPropertyGrid
* m_pg
;
265 DECLARE_EVENT_TABLE()
268 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
269 EVT_CLOSE(wxPGTLWHandler::OnClose
)
272 // -----------------------------------------------------------------------
274 // -----------------------------------------------------------------------
277 // wxPGCanvas acts as a graphics sub-window of the
278 // wxScrolledWindow that wxPropertyGrid is.
280 class wxPGCanvas
: public wxPanel
283 wxPGCanvas() : wxPanel()
286 virtual ~wxPGCanvas() { }
289 void OnMouseMove( wxMouseEvent
&event
)
291 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
292 pg
->OnMouseMove( event
);
295 void OnMouseClick( wxMouseEvent
&event
)
297 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
298 pg
->OnMouseClick( event
);
301 void OnMouseUp( wxMouseEvent
&event
)
303 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
304 pg
->OnMouseUp( event
);
307 void OnMouseRightClick( wxMouseEvent
&event
)
309 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
310 pg
->OnMouseRightClick( event
);
313 void OnMouseDoubleClick( wxMouseEvent
&event
)
315 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
316 pg
->OnMouseDoubleClick( event
);
319 void OnKey( wxKeyEvent
& event
)
321 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
325 void OnPaint( wxPaintEvent
& event
);
327 // Always be focussable, even with child windows
328 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
329 { wxPanel::SetCanFocus(true); }
333 DECLARE_EVENT_TABLE()
334 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
338 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
340 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
341 EVT_MOTION(wxPGCanvas::OnMouseMove
)
342 EVT_PAINT(wxPGCanvas::OnPaint
)
343 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
344 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
345 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
346 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
347 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
351 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
353 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
354 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
358 // Don't paint after destruction has begun
359 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
362 // Update everything inside the box
363 wxRect r
= GetUpdateRegion().GetBox();
365 // FIXME: This is just a workaround for a bug that causes splitters not
366 // to paint when other windows are being dragged over the grid.
367 wxRect fullRect
= GetRect();
369 r
.width
= fullRect
.width
;
371 // Repaint this rectangle
372 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
374 // We assume that the size set when grid is shown
375 // is what is desired.
376 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
379 // -----------------------------------------------------------------------
381 // -----------------------------------------------------------------------
383 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
385 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
386 EVT_IDLE(wxPropertyGrid::OnIdle
)
387 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
388 EVT_PAINT(wxPropertyGrid::OnPaint
)
389 EVT_SIZE(wxPropertyGrid::OnResize
)
390 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
391 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
392 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
393 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
394 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
395 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
396 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
397 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
401 // -----------------------------------------------------------------------
403 wxPropertyGrid::wxPropertyGrid()
409 // -----------------------------------------------------------------------
411 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
416 const wxString
& name
)
420 Create(parent
,id
,pos
,size
,style
,name
);
423 // -----------------------------------------------------------------------
425 bool wxPropertyGrid::Create( wxWindow
*parent
,
430 const wxString
& name
)
433 if ( !(style
&wxBORDER_MASK
) )
434 style
|= wxSIMPLE_BORDER
;
438 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
439 style
&= ~(wxTAB_TRAVERSAL
);
440 style
|= wxWANTS_CHARS
;
442 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
449 // -----------------------------------------------------------------------
452 // Initialize values to defaults
454 void wxPropertyGrid::Init1()
456 // Register editor classes, if necessary.
457 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
458 wxPropertyGrid::RegisterDefaultEditors();
462 m_wndEditor
= m_wndEditor2
= NULL
;
466 m_eventObject
= this;
469 m_sortFunction
= NULL
;
470 m_inDoPropertyChanged
= 0;
471 m_inCommitChangesFromEditor
= 0;
472 m_inDoSelectProperty
= 0;
473 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
479 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
480 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
481 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
482 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
483 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
484 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
485 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
486 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
487 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
489 m_coloursCustomized
= 0;
494 #if wxPG_DOUBLE_BUFFER
495 m_doubleBuffer
= NULL
;
498 #ifndef wxPG_ICON_WIDTH
504 m_iconWidth
= wxPG_ICON_WIDTH
;
509 m_gutterWidth
= wxPG_GUTTER_MIN
;
510 m_subgroup_extramargin
= 10;
514 m_width
= m_height
= 0;
516 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
519 m_chgInfo_changedProperty
= NULL
;
522 // -----------------------------------------------------------------------
525 // Initialize after parent etc. set
527 void wxPropertyGrid::Init2()
529 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
532 // Smaller controls on Mac
533 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
536 // Now create state, if one didn't exist already
537 // (wxPropertyGridManager might have created it for us).
540 m_pState
= CreateState();
541 m_pState
->m_pPropGrid
= this;
542 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
545 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
546 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
548 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
550 m_pState
->InitNonCatMode();
552 m_pState
->m_properties
= m_pState
->m_abcArray
;
555 GetClientSize(&m_width
,&m_height
);
557 #ifndef wxPG_ICON_WIDTH
558 // create two bitmap nodes for drawing
559 m_expandbmp
= new wxBitmap(expand_xpm
);
560 m_collbmp
= new wxBitmap(collapse_xpm
);
562 // calculate average font height for bitmap centering
564 m_iconWidth
= m_expandbmp
->GetWidth();
565 m_iconHeight
= m_expandbmp
->GetHeight();
568 m_curcursor
= wxCURSOR_ARROW
;
569 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
571 // adjust bitmap icon y position so they are centered
572 m_vspacing
= wxPG_DEFAULT_VSPACING
;
574 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
576 // Allocate cell datas indirectly by calling setter
577 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
578 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
582 // This helps with flicker
583 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
586 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
587 m_tlp
= ::wxGetTopLevelParent(this);
588 m_tlwHandler
= handler
;
589 m_tlp
->PushEventHandler(handler
);
591 // set virtual size to this window size
592 wxSize wndsize
= GetSize();
593 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
595 m_timeCreated
= ::wxGetLocalTimeMillis();
597 m_canvas
= new wxPGCanvas();
598 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
599 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
600 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
602 m_iFlags
|= wxPG_FL_INITIALIZED
;
604 m_ncWidth
= wndsize
.GetWidth();
606 // Need to call OnResize handler or size given in constructor/Create
608 wxSizeEvent
sizeEvent(wndsize
,0);
612 // -----------------------------------------------------------------------
614 wxPropertyGrid::~wxPropertyGrid()
618 DoSelectProperty(NULL
);
620 // This should do prevent things from going too badly wrong
621 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
623 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
624 m_canvas
->ReleaseMouse();
626 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
627 m_tlp
->RemoveEventHandler(handler
);
631 if ( IsEditorsValueModified() )
632 ::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).)"),
633 wxS("wxPropertyGrid Debug Warning") );
636 #if wxPG_DOUBLE_BUFFER
637 if ( m_doubleBuffer
)
638 delete m_doubleBuffer
;
643 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
646 delete m_cursorSizeWE
;
648 #ifndef wxPG_ICON_WIDTH
653 // Delete common value records
654 for ( i
=0; i
<m_commonValues
.size(); i
++ )
656 delete GetCommonValue(i
);
660 // -----------------------------------------------------------------------
662 bool wxPropertyGrid::Destroy()
664 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
665 m_canvas
->ReleaseMouse();
667 return wxScrolledWindow::Destroy();
670 // -----------------------------------------------------------------------
672 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
674 return new wxPropertyGridPageState();
677 // -----------------------------------------------------------------------
678 // wxPropertyGrid overridden wxWindow methods
679 // -----------------------------------------------------------------------
681 void wxPropertyGrid::SetWindowStyleFlag( long style
)
683 long old_style
= m_windowStyle
;
685 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
687 wxASSERT( m_pState
);
689 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
692 EnableCategories( true );
694 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
696 // Disable categories
697 EnableCategories( false );
699 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
705 PrepareAfterItemsAdded();
707 m_pState
->m_itemsAdded
= 1;
709 #if wxPG_SUPPORT_TOOLTIPS
710 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
716 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
717 SetToolTip ( tooltip );
718 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
721 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
726 m_canvas
->SetToolTip( NULL
);
731 wxScrolledWindow::SetWindowStyleFlag ( style
);
733 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
735 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
737 CalculateFontAndBitmapStuff( m_vspacing
);
743 // -----------------------------------------------------------------------
745 void wxPropertyGrid::Freeze()
749 wxScrolledWindow::Freeze();
754 // -----------------------------------------------------------------------
756 void wxPropertyGrid::Thaw()
762 wxScrolledWindow::Thaw();
763 RecalculateVirtualSize();
764 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
768 // Force property re-selection
770 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
774 // -----------------------------------------------------------------------
776 void wxPropertyGrid::SetExtraStyle( long exStyle
)
778 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
780 #if defined(__WXMSW__)
783 // Don't use WS_EX_COMPOSITED just now.
786 if ( m_iFlags & wxPG_FL_IN_MANAGER )
787 hWnd = (HWND)GetParent()->GetHWND();
789 hWnd = (HWND)GetHWND();
791 ::SetWindowLong( hWnd, GWL_EXSTYLE,
792 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
795 //#elif defined(__WXGTK20__)
797 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
798 // truly was double-buffered.
799 if ( !this->IsDoubleBuffered() )
801 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
805 #if wxPG_DOUBLE_BUFFER
806 delete m_doubleBuffer
;
807 m_doubleBuffer
= NULL
;
812 wxScrolledWindow::SetExtraStyle( exStyle
);
814 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
815 m_pState
->InitNonCatMode();
817 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
818 m_windowStyle
|= wxPG_TOOLTIPS
;
821 wxPGGlobalVars
->m_extraStyle
= exStyle
;
824 // -----------------------------------------------------------------------
826 // returns the best acceptable minimal size
827 wxSize
wxPropertyGrid::DoGetBestSize() const
830 if ( m_lineHeight
> hei
)
832 wxSize sz
= wxSize( 60, hei
+40 );
838 // -----------------------------------------------------------------------
839 // wxPropertyGrid Font and Colour Methods
840 // -----------------------------------------------------------------------
842 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
846 m_captionFont
= wxScrolledWindow::GetFont();
848 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
849 m_subgroup_extramargin
= x
+ (x
/2);
852 #if wxPG_USE_RENDERER_NATIVE
853 m_iconWidth
= wxPG_ICON_WIDTH
;
854 #elif wxPG_ICON_WIDTH
856 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
857 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
858 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
862 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
863 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
864 m_gutterWidth
= wxPG_GUTTER_MIN
;
867 if ( vspacing
<= 1 ) vdiv
= 12;
868 else if ( vspacing
>= 3 ) vdiv
= 3;
870 m_spacingy
= m_fontHeight
/ vdiv
;
871 if ( m_spacingy
< wxPG_YSPACING_MIN
)
872 m_spacingy
= wxPG_YSPACING_MIN
;
875 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
876 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
878 m_captionFont
.SetWeight(wxBOLD
);
879 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
881 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
884 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
885 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
888 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
890 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
891 RecalculateVirtualSize();
893 InvalidateBestSize();
896 // -----------------------------------------------------------------------
898 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
904 // -----------------------------------------------------------------------
906 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
907 int ga
= 1000, int ba
= 1000,
908 bool forceDifferent
= false)
915 // Recursion guard (allow 2 max)
916 static int isinside
= 0;
918 wxCHECK_MSG( isinside
< 3,
920 wxT("wxPGAdjustColour should not be recursively called more than once") );
928 if ( r2
>255 ) r2
= 255;
929 else if ( r2
<0) r2
= 0;
931 if ( g2
>255 ) g2
= 255;
932 else if ( g2
<0) g2
= 0;
934 if ( b2
>255 ) b2
= 255;
935 else if ( b2
<0) b2
= 0;
937 // Make sure they are somewhat different
938 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
939 dst
= wxPGAdjustColour(src
,-(ra
*2));
941 dst
= wxColour(r2
,g2
,b2
);
943 // Recursion guard (allow 2 max)
950 static int wxPGGetColAvg( const wxColour
& col
)
952 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
956 void wxPropertyGrid::RegainColours()
958 if ( !(m_coloursCustomized
& 0x0002) )
960 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
962 // Make sure colour is dark enough
964 int colDec
= wxPGGetColAvg(col
) - 230;
966 int colDec
= wxPGGetColAvg(col
) - 200;
969 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
972 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
975 if ( !(m_coloursCustomized
& 0x0001) )
976 m_colMargin
= m_colCapBack
;
978 if ( !(m_coloursCustomized
& 0x0004) )
985 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
986 m_colCapFore
= capForeCol
;
987 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
990 if ( !(m_coloursCustomized
& 0x0008) )
992 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
993 m_colPropBack
= bgCol
;
994 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
997 if ( !(m_coloursCustomized
& 0x0010) )
999 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1000 m_colPropFore
= fgCol
;
1001 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1004 if ( !(m_coloursCustomized
& 0x0020) )
1005 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1007 if ( !(m_coloursCustomized
& 0x0040) )
1008 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1010 if ( !(m_coloursCustomized
& 0x0080) )
1011 m_colLine
= m_colCapBack
;
1013 if ( !(m_coloursCustomized
& 0x0100) )
1014 m_colDisPropFore
= m_colCapFore
;
1016 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1019 // -----------------------------------------------------------------------
1021 void wxPropertyGrid::ResetColours()
1023 m_coloursCustomized
= 0;
1030 // -----------------------------------------------------------------------
1032 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1034 // Must disable active editor.
1035 ClearSelection(false);
1037 bool res
= wxScrolledWindow::SetFont( font
);
1040 CalculateFontAndBitmapStuff( m_vspacing
);
1047 // -----------------------------------------------------------------------
1049 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1052 m_coloursCustomized
|= 0x80;
1056 // -----------------------------------------------------------------------
1058 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1061 m_coloursCustomized
|= 0x01;
1065 // -----------------------------------------------------------------------
1067 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1069 m_colPropBack
= col
;
1070 m_coloursCustomized
|= 0x08;
1072 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1077 // -----------------------------------------------------------------------
1079 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1081 m_colPropFore
= col
;
1082 m_coloursCustomized
|= 0x10;
1084 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1089 // -----------------------------------------------------------------------
1091 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1093 m_colEmptySpace
= col
;
1098 // -----------------------------------------------------------------------
1100 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1102 m_colDisPropFore
= col
;
1103 m_coloursCustomized
|= 0x100;
1107 // -----------------------------------------------------------------------
1109 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1112 m_coloursCustomized
|= 0x20;
1116 // -----------------------------------------------------------------------
1118 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1121 m_coloursCustomized
|= 0x40;
1125 // -----------------------------------------------------------------------
1127 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1130 m_coloursCustomized
|= 0x02;
1132 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1137 // -----------------------------------------------------------------------
1139 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1142 m_coloursCustomized
|= 0x04;
1144 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1149 // -----------------------------------------------------------------------
1150 // wxPropertyGrid property adding and removal
1151 // -----------------------------------------------------------------------
1153 void wxPropertyGrid::PrepareAfterItemsAdded()
1155 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1157 m_pState
->m_itemsAdded
= 0;
1159 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1160 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1162 RecalculateVirtualSize();
1165 // -----------------------------------------------------------------------
1166 // wxPropertyGrid property operations
1167 // -----------------------------------------------------------------------
1169 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1171 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1175 bool changed
= false;
1177 // Is it inside collapsed section?
1178 if ( !p
->IsVisible() )
1181 wxPGProperty
* parent
= p
->GetParent();
1182 wxPGProperty
* grandparent
= parent
->GetParent();
1184 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1185 Expand( grandparent
);
1193 GetViewStart(&vx
,&vy
);
1194 vy
*=wxPG_PIXELS_PER_UNIT
;
1200 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1201 m_iFlags
|= wxPG_FL_SCROLLED
;
1204 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1206 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1207 m_iFlags
|= wxPG_FL_SCROLLED
;
1217 // -----------------------------------------------------------------------
1218 // wxPropertyGrid helper methods called by properties
1219 // -----------------------------------------------------------------------
1221 // Control font changer helper.
1222 void wxPropertyGrid::SetCurControlBoldFont()
1224 wxASSERT( m_wndEditor
);
1225 m_wndEditor
->SetFont( m_captionFont
);
1228 // -----------------------------------------------------------------------
1230 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1233 #if wxPG_SMALL_SCREEN
1234 // On small-screen devices, always show dialogs with default position and size.
1235 return wxDefaultPosition
;
1237 int splitterX
= GetSplitterPosition();
1241 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1243 ImprovedClientToScreen( &x
, &y
);
1245 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1246 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1253 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1263 new_y
= y
+ m_lineHeight
;
1265 return wxPoint(new_x
,new_y
);
1269 // -----------------------------------------------------------------------
1271 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1273 if ( src_str
.length() == 0 )
1279 bool prev_is_slash
= false;
1281 wxString::const_iterator i
= src_str
.begin();
1285 for ( ; i
!= src_str
.end(); ++i
)
1289 if ( a
!= wxS('\\') )
1291 if ( !prev_is_slash
)
1297 if ( a
== wxS('n') )
1300 dst_str
<< wxS('\n');
1302 dst_str
<< wxS('\n');
1305 else if ( a
== wxS('t') )
1306 dst_str
<< wxS('\t');
1310 prev_is_slash
= false;
1314 if ( prev_is_slash
)
1316 dst_str
<< wxS('\\');
1317 prev_is_slash
= false;
1321 prev_is_slash
= true;
1328 // -----------------------------------------------------------------------
1330 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1332 if ( src_str
.length() == 0 )
1338 wxString::const_iterator i
= src_str
.begin();
1339 wxUniChar prev_a
= wxS('\0');
1343 for ( ; i
!= src_str
.end(); ++i
)
1347 if ( a
>= wxS(' ') )
1349 // This surely is not something that requires an escape sequence.
1354 // This might need...
1355 if ( a
== wxS('\r') )
1357 // DOS style line end.
1358 // Already taken care below
1360 else if ( a
== wxS('\n') )
1361 // UNIX style line end.
1362 dst_str
<< wxS("\\n");
1363 else if ( a
== wxS('\t') )
1365 dst_str
<< wxS('\t');
1368 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1378 // -----------------------------------------------------------------------
1380 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1387 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1390 // -----------------------------------------------------------------------
1391 // wxPropertyGrid graphics related methods
1392 // -----------------------------------------------------------------------
1394 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1398 // Update everything inside the box
1399 wxRect r
= GetUpdateRegion().GetBox();
1401 dc
.SetPen(m_colEmptySpace
);
1402 dc
.SetBrush(m_colEmptySpace
);
1403 dc
.DrawRectangle(r
);
1406 // -----------------------------------------------------------------------
1408 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1409 wxPGProperty
* property
) const
1411 // Prepare rectangle to be used
1413 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1414 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1416 #if (wxPG_USE_RENDERER_NATIVE)
1418 #elif wxPG_ICON_WIDTH
1419 // Drawing expand/collapse button manually
1420 dc
.SetPen(m_colPropFore
);
1421 if ( property
->IsCategory() )
1422 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1424 dc
.SetBrush(m_colPropBack
);
1426 dc
.DrawRectangle( r
);
1427 int _y
= r
.y
+(m_iconWidth
/2);
1428 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1433 if ( property
->IsExpanded() )
1435 // wxRenderer functions are non-mutating in nature, so it
1436 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1437 // Hopefully this does not cause problems.
1438 #if (wxPG_USE_RENDERER_NATIVE)
1439 wxRendererNative::Get().DrawTreeItemButton(
1445 #elif wxPG_ICON_WIDTH
1454 #if (wxPG_USE_RENDERER_NATIVE)
1455 wxRendererNative::Get().DrawTreeItemButton(
1461 #elif wxPG_ICON_WIDTH
1462 int _x
= r
.x
+(m_iconWidth
/2);
1463 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1469 #if (wxPG_USE_RENDERER_NATIVE)
1471 #elif wxPG_ICON_WIDTH
1474 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1478 // -----------------------------------------------------------------------
1481 // This is the one called by OnPaint event handler and others.
1482 // topy and bottomy are already unscrolled (ie. physical)
1484 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1486 unsigned int bottomy
,
1487 const wxRect
* clipRect
)
1489 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1491 m_pState
->EnsureVirtualHeight();
1493 wxRect tempClipRect
;
1496 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1497 clipRect
= &tempClipRect
;
1500 // items added check
1501 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1503 int paintFinishY
= 0;
1505 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1508 bool isBuffered
= false;
1510 #if wxPG_DOUBLE_BUFFER
1511 wxMemoryDC
* bufferDC
= NULL
;
1513 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1515 if ( !m_doubleBuffer
)
1517 paintFinishY
= clipRect
->y
;
1522 bufferDC
= new wxMemoryDC();
1524 // If nothing was changed, then just copy from double-buffer
1525 bufferDC
->SelectObject( *m_doubleBuffer
);
1535 dc
.SetClippingRegion( *clipRect
);
1536 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1539 #if wxPG_DOUBLE_BUFFER
1542 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1543 bufferDC
, 0, 0, wxCOPY
);
1544 dc
.DestroyClippingRegion(); // Is this really necessary?
1550 // Clear area beyond bottomY?
1551 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1553 dc
.SetPen(m_colEmptySpace
);
1554 dc
.SetBrush(m_colEmptySpace
);
1555 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1559 // -----------------------------------------------------------------------
1561 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1562 const wxRect
* clipRect
,
1563 bool isBuffered
) const
1565 const wxPGProperty
* firstItem
;
1566 const wxPGProperty
* lastItem
;
1568 firstItem
= DoGetItemAtY(clipRect
->y
);
1569 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1572 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1574 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1577 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1578 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1580 int lh
= m_lineHeight
;
1583 int lastItemBottomY
;
1585 firstItemTopY
= clipRect
->y
;
1586 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1588 // Align y coordinates to item boundaries
1589 firstItemTopY
-= firstItemTopY
% lh
;
1590 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1591 lastItemBottomY
-= 1;
1593 // Entire range outside scrolled, visible area?
1594 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1597 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1601 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1602 firstItem->GetLabel().c_str(),
1603 lastItem->GetLabel().c_str(),
1604 (int)(lastItemBottomY - firstItemTopY),
1606 (unsigned long)clipRect );
1611 long windowStyle
= m_windowStyle
;
1617 // With wxPG_DOUBLE_BUFFER, do double buffering
1618 // - buffer's y = 0, so align cliprect and coordinates to that
1620 #if wxPG_DOUBLE_BUFFER
1626 xRelMod
= clipRect
->x
;
1627 yRelMod
= clipRect
->y
;
1630 // clipRect conversion
1635 firstItemTopY
-= yRelMod
;
1636 lastItemBottomY
-= yRelMod
;
1639 wxUnusedVar(isBuffered
);
1642 int x
= m_marginWidth
- xRelMod
;
1644 wxFont normalFont
= GetFont();
1646 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1648 bool isEnabled
= IsEnabled();
1651 // Prepare some pens and brushes that are often changed to.
1654 wxBrush
marginBrush(m_colMargin
);
1655 wxPen
marginPen(m_colMargin
);
1656 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1657 wxPen
linepen(m_colLine
,1,wxSOLID
);
1659 // pen that has same colour as text
1660 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1663 // Clear margin with background colour
1665 dc
.SetBrush( marginBrush
);
1666 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1668 dc
.SetPen( *wxTRANSPARENT_PEN
);
1669 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1672 const wxPGProperty
* selected
= m_selected
;
1673 const wxPropertyGridPageState
* state
= m_pState
;
1675 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1676 bool wasSelectedPainted
= false;
1679 // TODO: Only render columns that are within clipping region.
1681 dc
.SetFont(normalFont
);
1683 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1684 int endScanBottomY
= lastItemBottomY
+ lh
;
1685 int y
= firstItemTopY
;
1688 // Pregenerate list of visible properties.
1689 wxArrayPGProperty visPropArray
;
1690 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1692 for ( ; !it
.AtEnd(); it
.Next() )
1694 const wxPGProperty
* p
= *it
;
1696 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1698 visPropArray
.push_back((wxPGProperty
*)p
);
1700 if ( y
> endScanBottomY
)
1707 visPropArray
.push_back(NULL
);
1709 wxPGProperty
* nextP
= visPropArray
[0];
1711 int gridWidth
= state
->m_width
;
1714 for ( unsigned int arrInd
=1;
1715 nextP
&& y
<= lastItemBottomY
;
1718 wxPGProperty
* p
= nextP
;
1719 nextP
= visPropArray
[arrInd
];
1721 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1722 int textMarginHere
= x
;
1723 int renderFlags
= 0;
1725 int greyDepth
= m_marginWidth
;
1726 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1727 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1729 int greyDepthX
= greyDepth
- xRelMod
;
1731 // Use basic depth if in non-categoric mode and parent is base array.
1732 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1734 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1737 // Paint margin area
1738 dc
.SetBrush(marginBrush
);
1739 dc
.SetPen(marginPen
);
1740 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1742 dc
.SetPen( linepen
);
1747 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1753 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1755 sx
+= state
->m_colWidths
[si
];
1756 dc
.DrawLine( sx
, y
, sx
, y2
);
1759 // Horizontal Line, below
1760 // (not if both this and next is category caption)
1761 if ( p
->IsCategory() &&
1762 nextP
&& nextP
->IsCategory() )
1763 dc
.SetPen(m_colCapBack
);
1765 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1768 // Need to override row colours?
1772 if ( p
!= selected
)
1774 // Disabled may get different colour.
1775 if ( !p
->IsEnabled() )
1777 renderFlags
|= wxPGCellRenderer::Disabled
|
1778 wxPGCellRenderer::DontUseCellFgCol
;
1779 rowFgCol
= m_colDisPropFore
;
1784 renderFlags
|= wxPGCellRenderer::Selected
;
1786 if ( !p
->IsCategory() )
1788 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1789 wxPGCellRenderer::DontUseCellBgCol
;
1791 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1792 wasSelectedPainted
= true;
1795 // Selected gets different colour.
1796 if ( reallyFocused
)
1798 rowFgCol
= m_colSelFore
;
1799 rowBgCol
= m_colSelBack
;
1801 else if ( isEnabled
)
1803 rowFgCol
= m_colPropFore
;
1804 rowBgCol
= m_colMargin
;
1808 rowFgCol
= m_colDisPropFore
;
1809 rowBgCol
= m_colSelBack
;
1816 if ( rowBgCol
.IsOk() )
1817 rowBgBrush
= wxBrush(rowBgCol
);
1819 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1820 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1823 // Fill additional margin area with background colour of first cell
1824 if ( greyDepthX
< textMarginHere
)
1826 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1828 wxPGCell
& cell
= p
->GetCell(0);
1829 rowBgCol
= cell
.GetBgCol();
1830 rowBgBrush
= wxBrush(rowBgCol
);
1832 dc
.SetBrush(rowBgBrush
);
1833 dc
.SetPen(rowBgCol
);
1834 dc
.DrawRectangle(greyDepthX
+1, y
,
1835 textMarginHere
-greyDepthX
, lh
-1);
1838 bool fontChanged
= false;
1840 // Expander button rectangle
1841 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1846 if ( p
->IsCategory() )
1848 // Captions have their cell areas merged as one
1849 dc
.SetFont(m_captionFont
);
1851 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1853 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1855 dc
.SetBrush(rowBgBrush
);
1856 dc
.SetPen(rowBgCol
);
1859 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1861 dc
.SetTextForeground(rowFgCol
);
1864 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1865 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1868 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1869 DrawExpanderButton( dc
, butRect
, p
);
1873 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1875 dc
.SetFont(m_captionFont
);
1881 int nextCellWidth
= state
->m_colWidths
[0] -
1882 (greyDepthX
- m_marginWidth
);
1883 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1884 int textXAdd
= textMarginHere
- greyDepthX
;
1886 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1888 cellRect
.width
= nextCellWidth
- 1;
1890 bool ctrlCell
= false;
1891 int cellRenderFlags
= renderFlags
;
1894 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1895 DrawExpanderButton( dc
, butRect
, p
);
1898 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1900 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1901 dc
.SetBrush(editorBgCol
);
1902 dc
.SetPen(editorBgCol
);
1903 dc
.SetTextForeground(m_colPropFore
);
1904 dc
.DrawRectangle(cellRect
);
1906 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1911 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1913 dc
.SetBrush(rowBgBrush
);
1914 dc
.SetPen(rowBgCol
);
1917 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1919 dc
.SetTextForeground(rowFgCol
);
1923 dc
.SetClippingRegion(cellRect
);
1925 cellRect
.x
+= textXAdd
;
1926 cellRect
.width
-= textXAdd
;
1931 wxPGCellRenderer
* renderer
;
1932 int cmnVal
= p
->GetCommonValue();
1933 if ( cmnVal
== -1 || ci
!= 1 )
1935 renderer
= p
->GetCellRenderer(ci
);
1936 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1941 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1942 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1947 cellX
+= state
->m_colWidths
[ci
];
1948 if ( ci
< (state
->m_colWidths
.size()-1) )
1949 nextCellWidth
= state
->m_colWidths
[ci
+1];
1951 dc
.DestroyClippingRegion(); // Is this really necessary?
1957 dc
.SetFont(normalFont
);
1962 // Refresh editor controls (seems not needed on msw)
1963 // NOTE: This code is mandatory for GTK!
1964 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1965 if ( wasSelectedPainted
)
1968 m_wndEditor
->Refresh();
1970 m_wndEditor2
->Refresh();
1977 // -----------------------------------------------------------------------
1979 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1983 if ( m_width
< 10 || m_height
< 10 ||
1984 !m_pState
->m_properties
->GetChildCount() ||
1986 return wxRect(0,0,0,0);
1991 // Return rect which encloses the given property range
1993 int visTop
= p1
->GetY();
1996 visBottom
= p2
->GetY() + m_lineHeight
;
1998 visBottom
= m_height
+ visTop
;
2000 // If seleced property is inside the range, we'll extend the range to include
2002 wxPGProperty
* selected
= m_selected
;
2005 int selectedY
= selected
->GetY();
2006 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2008 wxWindow
* editor
= GetEditorControl();
2011 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2012 if ( visBottom2
> visBottom
)
2013 visBottom
= visBottom2
;
2018 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2021 // -----------------------------------------------------------------------
2023 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2028 if ( m_pState
->m_itemsAdded
)
2029 PrepareAfterItemsAdded();
2031 wxRect r
= GetPropertyRect(p1
, p2
);
2034 m_canvas
->RefreshRect(r
);
2038 // -----------------------------------------------------------------------
2040 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2042 if ( p
== m_selected
)
2043 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2045 DrawItemAndChildren(p
);
2048 // -----------------------------------------------------------------------
2050 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2055 // Draw item, children, and parent too, if it is not category
2056 wxPGProperty
* parent
= p
->GetParent();
2059 !parent
->IsCategory() &&
2060 parent
->GetParent() )
2063 parent
= parent
->GetParent();
2066 DrawItemAndChildren(p
);
2069 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2071 wxCHECK_RET( p
, wxT("invalid property id") );
2073 // Do not draw if in non-visible page
2074 if ( p
->GetParentState() != m_pState
)
2077 // do not draw a single item if multiple pending
2078 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2081 // Update child control.
2082 if ( m_selected
&& m_selected
->GetParent() == p
)
2085 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2087 DrawItems(p
, lastDrawn
);
2090 // -----------------------------------------------------------------------
2092 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2093 const wxRect
*rect
)
2095 PrepareAfterItemsAdded();
2097 wxWindow::Refresh(false);
2099 // TODO: Coordinate translation
2100 m_canvas
->Refresh(false, rect
);
2102 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2103 // I think this really helps only GTK+1.2
2104 if ( m_wndEditor
) m_wndEditor
->Refresh();
2105 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2109 // -----------------------------------------------------------------------
2110 // wxPropertyGrid global operations
2111 // -----------------------------------------------------------------------
2113 void wxPropertyGrid::Clear()
2115 m_pState
->DoClear();
2121 RecalculateVirtualSize();
2123 // Need to clear some area at the end
2125 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2128 // -----------------------------------------------------------------------
2130 bool wxPropertyGrid::EnableCategories( bool enable
)
2132 ClearSelection(false);
2137 // Enable categories
2140 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2145 // Disable categories
2147 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2150 if ( !m_pState
->EnableCategories(enable
) )
2155 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2157 m_pState
->m_itemsAdded
= 1; // force
2158 PrepareAfterItemsAdded();
2162 m_pState
->m_itemsAdded
= 1;
2164 // No need for RecalculateVirtualSize() here - it is already called in
2165 // wxPropertyGridPageState method above.
2172 // -----------------------------------------------------------------------
2174 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2176 wxASSERT( pNewState
);
2177 wxASSERT( pNewState
->GetGrid() );
2179 if ( pNewState
== m_pState
)
2182 wxPGProperty
* oldSelection
= m_selected
;
2184 ClearSelection(false);
2186 m_pState
->m_selected
= oldSelection
;
2188 bool orig_mode
= m_pState
->IsInNonCatMode();
2189 bool new_state_mode
= pNewState
->IsInNonCatMode();
2191 m_pState
= pNewState
;
2194 int pgWidth
= GetClientSize().x
;
2195 if ( HasVirtualWidth() )
2197 int minWidth
= pgWidth
;
2198 if ( pNewState
->m_width
< minWidth
)
2200 pNewState
->m_width
= minWidth
;
2201 pNewState
->CheckColumnWidths();
2207 // Just in case, fully re-center splitter
2208 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2209 pNewState
->m_fSplitterX
= -1.0;
2211 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2216 // If necessary, convert state to correct mode.
2217 if ( orig_mode
!= new_state_mode
)
2219 // This should refresh as well.
2220 EnableCategories( orig_mode
?false:true );
2222 else if ( !m_frozen
)
2224 // Refresh, if not frozen.
2225 m_pState
->PrepareAfterItemsAdded();
2228 if ( m_pState
->m_selected
)
2229 DoSelectProperty( m_pState
->m_selected
);
2231 RecalculateVirtualSize(0);
2235 m_pState
->m_itemsAdded
= 1;
2238 // -----------------------------------------------------------------------
2240 // Call to SetSplitterPosition will always disable splitter auto-centering
2241 // if parent window is shown.
2242 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2244 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2247 wxPropertyGridPageState
* state
= m_pState
;
2249 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2254 CorrectEditorWidgetSizeX();
2260 // -----------------------------------------------------------------------
2262 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2264 SetSplitterPosition( m_width
/2, true );
2265 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2266 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2269 // -----------------------------------------------------------------------
2270 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2271 // -----------------------------------------------------------------------
2273 // Returns nearest paint visible property (such that will be painted unless
2274 // window is scrolled or resized). If given property is paint visible, then
2275 // it itself will be returned
2276 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2278 int vx
,vy1
;// Top left corner of client
2279 GetViewStart(&vx
,&vy1
);
2280 vy1
*= wxPG_PIXELS_PER_UNIT
;
2282 int vy2
= vy1
+ m_height
;
2283 int propY
= p
->GetY2(m_lineHeight
);
2285 if ( (propY
+ m_lineHeight
) < vy1
)
2288 return DoGetItemAtY( vy1
);
2290 else if ( propY
> vy2
)
2293 return DoGetItemAtY( vy2
);
2296 // Itself paint visible
2301 // -----------------------------------------------------------------------
2302 // Methods related to change in value, value modification and sending events
2303 // -----------------------------------------------------------------------
2305 // commits any changes in editor of selected property
2306 // return true if validation did not fail
2307 // flags are same as with DoSelectProperty
2308 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2310 // Committing already?
2311 if ( m_inCommitChangesFromEditor
)
2314 // Don't do this if already processing editor event. It might
2315 // induce recursive dialogs and crap like that.
2316 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2318 if ( m_inDoPropertyChanged
)
2325 IsEditorsValueModified() &&
2326 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2329 m_inCommitChangesFromEditor
= 1;
2331 wxVariant
variant(m_selected
->GetValueRef());
2332 bool valueIsPending
= false;
2334 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2335 // due to another window getting focus
2336 wxWindow
* oldFocus
= m_curFocused
;
2338 bool validationFailure
= false;
2339 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2341 m_chgInfo_changedProperty
= NULL
;
2343 // If truly modified, schedule value as pending.
2344 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2346 if ( DoEditorValidate() &&
2347 PerformValidation(m_selected
, variant
) )
2349 valueIsPending
= true;
2353 validationFailure
= true;
2358 EditorsValueWasNotModified();
2363 m_inCommitChangesFromEditor
= 0;
2365 if ( validationFailure
&& !forceSuccess
)
2369 oldFocus
->SetFocus();
2370 m_curFocused
= oldFocus
;
2373 res
= OnValidationFailure(m_selected
, variant
);
2375 // Now prevent further validation failure messages
2378 EditorsValueWasNotModified();
2379 OnValidationFailureReset(m_selected
);
2382 else if ( valueIsPending
)
2384 DoPropertyChanged( m_selected
, flags
);
2385 EditorsValueWasNotModified();
2394 // -----------------------------------------------------------------------
2396 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2400 // Runs all validation functionality.
2401 // Returns true if value passes all tests.
2404 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2406 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2408 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2413 // Adapt list to child values, if necessary
2414 wxVariant listValue
= pendingValue
;
2415 wxVariant
* pPendingValue
= &pendingValue
;
2416 wxVariant
* pList
= NULL
;
2418 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2419 // string value, then we need treat as it was changed instead
2420 // (or, in addition, as is the case with composite string parent).
2421 // This includes creating list variant for child values.
2423 wxPGProperty
* pwc
= p
->GetParent();
2424 wxPGProperty
* changedProperty
= p
;
2425 wxPGProperty
* baseChangedProperty
= changedProperty
;
2426 wxVariant bcpPendingList
;
2428 listValue
= pendingValue
;
2429 listValue
.SetName(p
->GetBaseName());
2432 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2434 wxVariantList tempList
;
2435 wxVariant
lv(tempList
, pwc
->GetBaseName());
2436 lv
.Append(listValue
);
2438 pPendingValue
= &listValue
;
2440 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2442 baseChangedProperty
= pwc
;
2443 bcpPendingList
= lv
;
2446 changedProperty
= pwc
;
2447 pwc
= pwc
->GetParent();
2451 wxPGProperty
* evtChangingProperty
= changedProperty
;
2453 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2455 value
= *pPendingValue
;
2459 // Convert list to child values
2460 pList
= pPendingValue
;
2461 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2464 wxVariant evtChangingValue
= value
;
2466 if ( flags
& SendEvtChanging
)
2468 // FIXME: After proper ValueToString()s added, remove
2469 // this. It is just a temporary fix, as evt_changing
2470 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2471 // (unless it is selected, and textctrl editor is open).
2472 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2474 evtChangingProperty
= baseChangedProperty
;
2475 if ( evtChangingProperty
!= p
)
2477 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2481 evtChangingValue
= pendingValue
;
2485 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2487 if ( changedProperty
== m_selected
)
2489 wxWindow
* editor
= GetEditorControl();
2490 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2491 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2495 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2500 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2501 m_chgInfo_changedProperty
= changedProperty
;
2502 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2503 m_chgInfo_pendingValue
= value
;
2506 m_chgInfo_valueList
= *pList
;
2508 m_chgInfo_valueList
.MakeNull();
2510 // If changedProperty is not property which value was edited,
2511 // then call wxPGProperty::ValidateValue() for that as well.
2512 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2514 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2518 if ( flags
& SendEvtChanging
)
2520 // SendEvent returns true if event was vetoed
2521 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2525 if ( flags
& IsStandaloneValidation
)
2527 // If called in 'generic' context, we need to reset
2528 // m_chgInfo_changedProperty and write back translated value.
2529 m_chgInfo_changedProperty
= NULL
;
2530 pendingValue
= value
;
2536 // -----------------------------------------------------------------------
2538 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2540 if ( !msg
.length() )
2544 if ( !wxPGGlobalVars
->m_offline
)
2546 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2549 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2552 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2555 pStatusBar
->SetStatusText(msg
);
2563 ::wxMessageBox(msg
, _T("Property Error"));
2566 // -----------------------------------------------------------------------
2568 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2569 wxVariant
& invalidValue
)
2571 wxWindow
* editor
= GetEditorControl();
2573 // First call property's handler
2574 property
->OnValidationFailure(invalidValue
);
2576 bool res
= DoOnValidationFailure(property
, invalidValue
);
2579 // For non-wxTextCtrl editors, we do need to revert the value
2580 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2581 property
== m_selected
)
2583 property
->GetEditorClass()->UpdateControl(property
, editor
);
2586 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2591 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2593 int vfb
= m_validationInfo
.m_failureBehavior
;
2595 if ( vfb
& wxPG_VFB_BEEP
)
2598 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2599 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2601 unsigned int colCount
= m_pState
->GetColumnCount();
2603 // We need backup marked property's cells
2604 m_propCellsBackup
= property
->m_cells
;
2606 wxColour vfbFg
= *wxWHITE
;
2607 wxColour vfbBg
= *wxRED
;
2609 property
->EnsureCells(colCount
);
2611 for ( unsigned int i
=0; i
<colCount
; i
++ )
2613 wxPGCell
& cell
= property
->m_cells
[i
];
2614 cell
.SetFgCol(vfbFg
);
2615 cell
.SetBgCol(vfbBg
);
2618 DrawItemAndChildren(property
);
2620 if ( property
== m_selected
)
2622 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2624 wxWindow
* editor
= GetEditorControl();
2627 editor
->SetForegroundColour(vfbFg
);
2628 editor
->SetBackgroundColour(vfbBg
);
2633 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2635 wxString msg
= m_validationInfo
.m_failureMessage
;
2637 if ( !msg
.length() )
2638 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2640 DoShowPropertyError(property
, msg
);
2643 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2646 // -----------------------------------------------------------------------
2648 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2650 int vfb
= m_validationInfo
.m_failureBehavior
;
2652 if ( vfb
& wxPG_VFB_MARK_CELL
)
2655 property
->m_cells
= m_propCellsBackup
;
2657 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2659 if ( property
== m_selected
&& GetEditorControl() )
2661 // Calling this will recreate the control, thus resetting its colour
2662 RefreshProperty(property
);
2666 DrawItemAndChildren(property
);
2671 // -----------------------------------------------------------------------
2673 // flags are same as with DoSelectProperty
2674 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2676 if ( m_inDoPropertyChanged
)
2679 wxWindow
* editor
= GetEditorControl();
2681 m_pState
->m_anyModified
= 1;
2683 m_inDoPropertyChanged
= 1;
2685 // Maybe need to update control
2686 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2688 // These values were calculated in PerformValidation()
2689 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2690 wxVariant value
= m_chgInfo_pendingValue
;
2692 wxPGProperty
* topPaintedProperty
= changedProperty
;
2694 while ( !topPaintedProperty
->IsCategory() &&
2695 !topPaintedProperty
->IsRoot() )
2697 topPaintedProperty
= topPaintedProperty
->GetParent();
2700 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2702 // Set as Modified (not if dragging just began)
2703 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2705 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2706 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2709 SetCurControlBoldFont();
2715 // Propagate updates to parent(s)
2717 wxPGProperty
* prevPwc
= NULL
;
2719 while ( prevPwc
!= topPaintedProperty
)
2721 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2723 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2726 SetCurControlBoldFont();
2730 pwc
= pwc
->GetParent();
2733 // Draw the actual property
2734 DrawItemAndChildren( topPaintedProperty
);
2737 // If value was set by wxPGProperty::OnEvent, then update the editor
2739 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2745 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2746 if ( m_wndEditor
) m_wndEditor
->Refresh();
2747 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2752 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2754 // If top parent has composite string value, then send to child parents,
2755 // starting from baseChangedProperty.
2756 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2758 pwc
= m_chgInfo_baseChangedProperty
;
2760 while ( pwc
!= changedProperty
)
2762 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2763 pwc
= pwc
->GetParent();
2767 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2769 m_inDoPropertyChanged
= 0;
2774 // -----------------------------------------------------------------------
2776 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2778 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2780 m_chgInfo_changedProperty
= NULL
;
2782 if ( PerformValidation(p
, newValue
) )
2784 DoPropertyChanged(p
);
2789 OnValidationFailure(p
, newValue
);
2795 // -----------------------------------------------------------------------
2797 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2799 wxPGProperty
* prop
= GetSelectedProperty();
2802 return wxNullVariant
;
2804 wxTextCtrl
* tc
= GetEditorTextCtrl();
2805 wxVariant value
= prop
->GetValue();
2807 if ( !tc
|| !IsEditorsValueModified() )
2810 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2813 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2814 return prop
->GetValue();
2819 // -----------------------------------------------------------------------
2821 // Runs wxValidator for the selected property
2822 bool wxPropertyGrid::DoEditorValidate()
2827 // -----------------------------------------------------------------------
2829 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2831 wxPGProperty
* selected
= m_selected
;
2833 // Somehow, event is handled after property has been deselected.
2834 // Possibly, but very rare.
2838 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2841 wxVariant
pendingValue(selected
->GetValueRef());
2842 wxWindow
* wnd
= GetEditorControl();
2843 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2845 bool wasUnspecified
= selected
->IsValueUnspecified();
2846 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2847 bool valueIsPending
= false;
2849 m_chgInfo_changedProperty
= NULL
;
2851 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2854 // Filter out excess wxTextCtrl modified events
2855 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2857 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2859 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2861 wxString newTcValue
= tc
->GetValue();
2862 if ( m_prevTcValue
== newTcValue
)
2865 m_prevTcValue
= newTcValue
;
2868 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2870 bool validationFailure
= false;
2871 bool buttonWasHandled
= false;
2874 // Try common button handling
2875 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2877 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2881 buttonWasHandled
= true;
2882 // Store as res2, as previously (and still currently alternatively)
2883 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2884 // in wxPGProperty::OnEvent().
2885 adapter
->ShowDialog( this, selected
);
2890 if ( !buttonWasHandled
)
2892 if ( wnd
|| m_wndEditor2
)
2894 // First call editor class' event handler.
2895 const wxPGEditor
* editor
= selected
->GetEditorClass();
2897 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2899 // If changes, validate them
2900 if ( DoEditorValidate() )
2902 if ( editor
->GetValueFromControl( pendingValue
,
2905 valueIsPending
= true;
2909 validationFailure
= true;
2914 // Then the property's custom handler (must be always called, unless
2915 // validation failed).
2916 if ( !validationFailure
)
2917 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2920 // SetValueInEvent(), as called in one of the functions referred above
2921 // overrides editor's value.
2922 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2924 valueIsPending
= true;
2925 pendingValue
= m_changeInEventValue
;
2926 selFlags
|= wxPG_SEL_DIALOGVAL
;
2929 if ( !validationFailure
&& valueIsPending
)
2930 if ( !PerformValidation(m_selected
, pendingValue
) )
2931 validationFailure
= true;
2933 if ( validationFailure
)
2935 OnValidationFailure(selected
, pendingValue
);
2937 else if ( valueIsPending
)
2939 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2941 DoPropertyChanged(selected
, selFlags
);
2942 EditorsValueWasNotModified();
2944 // Regardless of editor type, unfocus editor on
2945 // text-editing related enter press.
2946 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2953 // No value after all
2955 // Regardless of editor type, unfocus editor on
2956 // text-editing related enter press.
2957 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2962 // Let unhandled button click events go to the parent
2963 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2965 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2966 GetEventHandler()->AddPendingEvent(evt
);
2970 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2973 // -----------------------------------------------------------------------
2974 // wxPropertyGrid editor control helper methods
2975 // -----------------------------------------------------------------------
2977 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2979 int itemy
= p
->GetY2(m_lineHeight
);
2981 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2982 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2983 int imageOffset
= 0;
2985 // TODO: If custom image detection changes from current, change this.
2986 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
2988 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2989 int iw
= p
->OnMeasureImage().x
;
2991 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
2992 imageOffset
= p
->GetImageOffset(iw
);
2997 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
2999 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3004 // -----------------------------------------------------------------------
3006 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3008 wxSize sz
= GetImageSize(p
, item
);
3009 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3010 wxPG_CUSTOM_IMAGE_SPACINGY
,
3015 // return size of custom paint image
3016 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3018 // If called with NULL property, then return default image
3019 // size for properties that use image.
3021 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3023 wxSize cis
= p
->OnMeasureImage(item
);
3025 int choiceCount
= p
->m_choices
.GetCount();
3026 int comVals
= p
->GetDisplayedCommonValueCount();
3027 if ( item
>= choiceCount
&& comVals
> 0 )
3029 unsigned int cvi
= item
-choiceCount
;
3030 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3032 else if ( item
>= 0 && choiceCount
== 0 )
3033 return wxSize(0, 0);
3038 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3043 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3050 // -----------------------------------------------------------------------
3052 // takes scrolling into account
3053 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3056 GetViewStart(&vx
,&vy
);
3057 vy
*=wxPG_PIXELS_PER_UNIT
;
3058 vx
*=wxPG_PIXELS_PER_UNIT
;
3061 ClientToScreen( px
, py
);
3064 // -----------------------------------------------------------------------
3066 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3069 GetViewStart(&pt2
.x
,&pt2
.y
);
3070 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3071 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3075 return m_pState
->HitTest(pt2
);
3078 // -----------------------------------------------------------------------
3080 // custom set cursor
3081 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3083 if ( type
== m_curcursor
&& !override
) return;
3085 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3087 if ( type
== wxCURSOR_SIZEWE
)
3088 cursor
= m_cursorSizeWE
;
3090 m_canvas
->SetCursor( *cursor
);
3095 // -----------------------------------------------------------------------
3096 // wxPropertyGrid property selection, editor creation
3097 // -----------------------------------------------------------------------
3100 // This class forwards events from property editor controls to wxPropertyGrid.
3101 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3104 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3105 : wxEvtHandler(), m_propGrid(propGrid
)
3109 virtual ~wxPropertyGridEditorEventForwarder()
3114 bool ProcessEvent( wxEvent
& event
)
3119 m_propGrid
->HandleCustomEditorEvent(event
);
3121 return wxEvtHandler::ProcessEvent(event
);
3124 wxPropertyGrid
* m_propGrid
;
3127 // Setups event handling for child control
3128 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3130 wxWindowID id
= argWnd
->GetId();
3132 if ( argWnd
== m_wndEditor
)
3134 argWnd
->Connect(id
, wxEVT_MOTION
,
3135 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3137 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3138 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3140 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3141 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3143 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3144 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3146 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3147 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3149 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3150 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3154 wxPropertyGridEditorEventForwarder
* forwarder
;
3155 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3156 argWnd
->PushEventHandler(forwarder
);
3158 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3159 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3163 void wxPropertyGrid::FreeEditors()
3166 // Return focus back to canvas from children (this is required at least for
3167 // GTK+, which, unlike Windows, clears focus when control is destroyed
3168 // instead of moving it to closest parent).
3169 wxWindow
* focus
= wxWindow::FindFocus();
3172 wxWindow
* parent
= focus
->GetParent();
3175 if ( parent
== m_canvas
)
3180 parent
= parent
->GetParent();
3184 // Do not free editors immediately if processing events
3187 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3188 m_wndEditor2
->Hide();
3189 wxPendingDelete
.Append( handler
);
3190 wxPendingDelete
.Append( m_wndEditor2
);
3191 m_wndEditor2
= NULL
;
3196 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3197 m_wndEditor
->Hide();
3198 wxPendingDelete
.Append( handler
);
3199 wxPendingDelete
.Append( m_wndEditor
);
3204 // Call with NULL to de-select property
3205 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3209 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3210 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3212 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3215 if ( m_inDoSelectProperty
)
3218 m_inDoSelectProperty
= 1;
3220 wxPGProperty
* prev
= m_selected
;
3224 m_inDoSelectProperty
= 0;
3230 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3232 wxPrintf( "None selected\n" );
3235 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3237 wxPrintf( "P = NULL\n" );
3240 // If we are frozen, then just set the values.
3243 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3244 m_editorFocused
= 0;
3247 m_pState
->m_selected
= p
;
3249 // If frozen, always free controls. But don't worry, as Thaw will
3250 // recall SelectProperty to recreate them.
3253 // Prevent any further selection measures in this call
3259 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3261 // Only set focus if not deselecting
3264 if ( flags
& wxPG_SEL_FOCUS
)
3268 m_wndEditor
->SetFocus();
3269 m_editorFocused
= 1;
3278 m_inDoSelectProperty
= 0;
3283 // First, deactivate previous
3287 OnValidationFailureReset(m_selected
);
3289 // Must double-check if this is an selected in case of forceswitch
3292 if ( !CommitChangesFromEditor(flags
) )
3294 // Validation has failed, so we can't exit the previous editor
3295 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3296 // _("Invalid Value"),wxOK|wxICON_ERROR);
3297 m_inDoSelectProperty
= 0;
3306 m_pState
->m_selected
= NULL
;
3308 // We need to always fully refresh the grid here
3311 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3312 EditorsValueWasNotModified();
3315 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3318 // Then, activate the one given.
3321 int propY
= p
->GetY2(m_lineHeight
);
3323 int splitterX
= GetSplitterPosition();
3324 m_editorFocused
= 0;
3326 m_pState
->m_selected
= p
;
3327 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3329 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3331 wxASSERT( m_wndEditor
== NULL
);
3334 // Only create editor for non-disabled non-caption
3335 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3337 // do this for non-caption items
3341 // Do we need to paint the custom image, if any?
3342 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3343 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3344 !p
->GetEditorClass()->CanContainCustomImage()
3346 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3348 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3349 wxPoint goodPos
= grect
.GetPosition();
3350 #if wxPG_CREATE_CONTROLS_HIDDEN
3351 int coord_adjust
= m_height
- goodPos
.y
;
3352 goodPos
.y
+= coord_adjust
;
3355 const wxPGEditor
* editor
= p
->GetEditorClass();
3356 wxCHECK_MSG(editor
, false,
3357 wxT("NULL editor class not allowed"));
3359 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3361 wxPGWindowList wndList
= editor
->CreateControls(this,
3366 m_wndEditor
= wndList
.m_primary
;
3367 m_wndEditor2
= wndList
.m_secondary
;
3368 wxWindow
* primaryCtrl
= GetEditorControl();
3371 // Essentially, primaryCtrl == m_wndEditor
3374 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3375 // value is drawn as normal, and m_wndEditor2 is assumed
3376 // to be a right-aligned button that triggers a separate editorCtrl
3381 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3382 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3384 // Set validator, if any
3385 #if wxUSE_VALIDATORS
3386 wxValidator
* validator
= p
->GetValidator();
3388 primaryCtrl
->SetValidator(*validator
);
3391 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3392 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3394 // If it has modified status, use bold font
3395 // (must be done before capturing m_ctrlXAdjust)
3396 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3397 SetCurControlBoldFont();
3400 // Fix TextCtrl indentation
3401 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3402 wxTextCtrl
* tc
= NULL
;
3403 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3404 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3406 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3408 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3411 // Store x relative to splitter (we'll need it).
3412 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3414 // Check if background clear is not necessary
3415 wxPoint pos
= m_wndEditor
->GetPosition();
3416 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3418 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3421 m_wndEditor
->SetSizeHints(3, 3);
3423 #if wxPG_CREATE_CONTROLS_HIDDEN
3424 m_wndEditor
->Show(false);
3425 m_wndEditor
->Freeze();
3427 goodPos
= m_wndEditor
->GetPosition();
3428 goodPos
.y
-= coord_adjust
;
3429 m_wndEditor
->Move( goodPos
);
3432 SetupChildEventHandling(primaryCtrl
);
3434 // Focus and select all (wxTextCtrl, wxComboBox etc)
3435 if ( flags
& wxPG_SEL_FOCUS
)
3437 primaryCtrl
->SetFocus();
3439 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3445 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3446 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3448 // Get proper id for wndSecondary
3449 m_wndSecId
= m_wndEditor2
->GetId();
3450 wxWindowList children
= m_wndEditor2
->GetChildren();
3451 wxWindowList::iterator node
= children
.begin();
3452 if ( node
!= children
.end() )
3453 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3455 m_wndEditor2
->SetSizeHints(3,3);
3457 #if wxPG_CREATE_CONTROLS_HIDDEN
3458 wxRect sec_rect
= m_wndEditor2
->GetRect();
3459 sec_rect
.y
-= coord_adjust
;
3461 // Fine tuning required to fix "oversized"
3462 // button disappearance bug.
3463 if ( sec_rect
.y
< 0 )
3465 sec_rect
.height
+= sec_rect
.y
;
3468 m_wndEditor2
->SetSize( sec_rect
);
3470 m_wndEditor2
->Show();
3472 SetupChildEventHandling(m_wndEditor2
);
3474 // If no primary editor, focus to button to allow
3475 // it to interprete ENTER etc.
3476 // NOTE: Due to problems focusing away from it, this
3477 // has been disabled.
3479 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3480 m_wndEditor2->SetFocus();
3484 if ( flags
& wxPG_SEL_FOCUS
)
3485 m_editorFocused
= 1;
3490 // Make sure focus is in grid canvas (important for wxGTK, at least)
3494 EditorsValueWasNotModified();
3496 // If it's inside collapsed section, expand parent, scroll, etc.
3497 // Also, if it was partially visible, scroll it into view.
3498 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3503 #if wxPG_CREATE_CONTROLS_HIDDEN
3504 m_wndEditor
->Thaw();
3506 m_wndEditor
->Show(true);
3513 // Make sure focus is in grid canvas
3517 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3523 // Show help text in status bar.
3524 // (if found and grid not embedded in manager with help box and
3525 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3528 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3530 wxStatusBar
* statusbar
= NULL
;
3531 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3533 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3535 statusbar
= frame
->GetStatusBar();
3540 const wxString
* pHelpString
= (const wxString
*) NULL
;
3544 pHelpString
= &p
->GetHelpString();
3545 if ( pHelpString
->length() )
3547 // Set help box text.
3548 statusbar
->SetStatusText( *pHelpString
);
3549 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3553 if ( (!pHelpString
|| !pHelpString
->length()) &&
3554 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3556 // Clear help box - but only if it was written
3557 // by us at previous time.
3558 statusbar
->SetStatusText( m_emptyString
);
3559 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3565 m_inDoSelectProperty
= 0;
3567 // call wx event handler (here so that it also occurs on deselection)
3568 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3573 // -----------------------------------------------------------------------
3575 bool wxPropertyGrid::UnfocusEditor()
3577 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3580 if ( !CommitChangesFromEditor(0) )
3584 DrawItem(m_selected
);
3589 // -----------------------------------------------------------------------
3591 void wxPropertyGrid::RefreshEditor()
3593 wxPGProperty
* p
= m_selected
;
3597 wxWindow
* wnd
= GetEditorControl();
3601 // Set editor font boldness - must do this before
3602 // calling UpdateControl().
3603 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3605 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3606 wnd
->SetFont(GetCaptionFont());
3608 wnd
->SetFont(GetFont());
3611 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3613 editorClass
->UpdateControl(p
, wnd
);
3615 if ( p
->IsValueUnspecified() )
3616 editorClass
->SetValueToUnspecified(p
, wnd
);
3619 // -----------------------------------------------------------------------
3621 // This method is not inline because it called dozens of times
3622 // (i.e. two-arg function calls create smaller code size).
3623 bool wxPropertyGrid::DoClearSelection()
3625 return DoSelectProperty(NULL
);
3628 // -----------------------------------------------------------------------
3629 // wxPropertyGrid expand/collapse state
3630 // -----------------------------------------------------------------------
3632 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3634 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3636 // If active editor was inside collapsed section, then disable it
3637 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3639 ClearSelection(false);
3642 // Store dont-center-splitter flag 'cause we need to temporarily set it
3643 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3644 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3646 bool res
= m_pState
->DoCollapse(pwc
);
3651 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3653 RecalculateVirtualSize();
3655 // Redraw etc. only if collapsed was visible.
3656 if (pwc
->IsVisible() &&
3658 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3660 // When item is collapsed so that scrollbar would move,
3661 // graphics mess is about (unless we redraw everything).
3666 // Clear dont-center-splitter flag if it wasn't set
3667 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3672 // -----------------------------------------------------------------------
3674 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3676 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3678 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3680 // Store dont-center-splitter flag 'cause we need to temporarily set it
3681 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3682 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3684 bool res
= m_pState
->DoExpand(pwc
);
3689 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3691 RecalculateVirtualSize();
3693 // Redraw etc. only if expanded was visible.
3694 if ( pwc
->IsVisible() && !m_frozen
&&
3695 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3699 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3702 DrawItems(pwc
, NULL
);
3707 // Clear dont-center-splitter flag if it wasn't set
3708 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3713 // -----------------------------------------------------------------------
3715 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3718 return m_pState
->DoHideProperty(p
, hide
, flags
);
3721 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3724 ClearSelection(false);
3727 m_pState
->DoHideProperty(p
, hide
, flags
);
3729 RecalculateVirtualSize();
3736 // -----------------------------------------------------------------------
3737 // wxPropertyGrid size related methods
3738 // -----------------------------------------------------------------------
3740 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3742 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3746 // If virtual height was changed, then recalculate editor control position(s)
3747 if ( m_pState
->m_vhCalcPending
)
3748 CorrectEditorWidgetPosY();
3750 m_pState
->EnsureVirtualHeight();
3753 int by1
= m_pState
->GetVirtualHeight();
3754 int by2
= m_pState
->GetActualVirtualHeight();
3757 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3758 wxFAIL_MSG(s
.c_str());
3763 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3765 int x
= m_pState
->m_width
;
3766 int y
= m_pState
->m_virtualHeight
;
3769 GetClientSize(&width
,&height
);
3771 // Now adjust virtual size.
3772 SetVirtualSize(x
, y
);
3778 // Adjust scrollbars
3779 if ( HasVirtualWidth() )
3781 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3782 xPos
= GetScrollPos( wxHORIZONTAL
);
3785 if ( forceXPos
!= -1 )
3788 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3791 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3792 int yPos
= GetScrollPos( wxVERTICAL
);
3794 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3795 xAmount
, yAmount
, xPos
, yPos
, true );
3797 // Must re-get size now
3798 GetClientSize(&width
,&height
);
3800 if ( !HasVirtualWidth() )
3802 m_pState
->SetVirtualWidth(width
);
3809 m_canvas
->SetSize( x
, y
);
3811 m_pState
->CheckColumnWidths();
3814 CorrectEditorWidgetSizeX();
3816 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3819 // -----------------------------------------------------------------------
3821 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3823 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3827 GetClientSize(&width
,&height
);
3832 #if wxPG_DOUBLE_BUFFER
3833 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3835 int dblh
= (m_lineHeight
*2);
3836 if ( !m_doubleBuffer
)
3838 // Create double buffer bitmap to draw on, if none
3839 int w
= (width
>250)?width
:250;
3840 int h
= height
+ dblh
;
3842 m_doubleBuffer
= new wxBitmap( w
, h
);
3846 int w
= m_doubleBuffer
->GetWidth();
3847 int h
= m_doubleBuffer
->GetHeight();
3849 // Double buffer must be large enough
3850 if ( w
< width
|| h
< (height
+dblh
) )
3852 if ( w
< width
) w
= width
;
3853 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3854 delete m_doubleBuffer
;
3855 m_doubleBuffer
= new wxBitmap( w
, h
);
3862 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3863 m_ncWidth
= event
.GetSize().x
;
3867 if ( m_pState
->m_itemsAdded
)
3868 PrepareAfterItemsAdded();
3870 // Without this, virtual size (atleast under wxGTK) will be skewed
3871 RecalculateVirtualSize();
3877 // -----------------------------------------------------------------------
3879 void wxPropertyGrid::SetVirtualWidth( int width
)
3883 // Disable virtual width
3884 width
= GetClientSize().x
;
3885 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3889 // Enable virtual width
3890 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3892 m_pState
->SetVirtualWidth( width
);
3895 void wxPropertyGrid::SetFocusOnCanvas()
3897 m_canvas
->SetFocusIgnoringChildren();
3898 m_editorFocused
= 0;
3901 // -----------------------------------------------------------------------
3902 // wxPropertyGrid mouse event handling
3903 // -----------------------------------------------------------------------
3905 // selFlags uses same values DoSelectProperty's flags
3906 // Returns true if event was vetoed.
3907 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3909 // Send property grid event of specific type and with specific property
3910 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3911 evt
.SetPropertyGrid(this);
3912 evt
.SetEventObject(m_eventObject
);
3916 evt
.SetCanVeto(true);
3917 evt
.SetupValidationInfo();
3918 m_validationInfo
.m_pValue
= pValue
;
3920 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3922 evtHandler
->ProcessEvent(evt
);
3924 return evt
.WasVetoed();
3927 // -----------------------------------------------------------------------
3929 // Return false if should be skipped
3930 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3934 // Need to set focus?
3935 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3940 wxPropertyGridPageState
* state
= m_pState
;
3942 int splitterHitOffset
;
3943 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3945 wxPGProperty
* p
= DoGetItemAtY(y
);
3949 int depth
= (int)p
->GetDepth() - 1;
3951 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3953 if ( x
>= marginEnds
)
3957 if ( p
->IsCategory() )
3959 // This is category.
3960 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3962 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3964 // Expand, collapse, activate etc. if click on text or left of splitter.
3967 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3972 if ( !DoSelectProperty( p
) )
3975 // On double-click, expand/collapse.
3976 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3978 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3979 else DoExpand( p
, true );
3983 else if ( splitterHit
== -1 )
3986 unsigned int selFlag
= 0;
3987 if ( columnHit
== 1 )
3989 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3990 selFlag
= wxPG_SEL_FOCUS
;
3992 if ( !DoSelectProperty( p
, selFlag
) )
3995 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3997 if ( p
->GetChildCount() && !p
->IsCategory() )
3998 // On double-click, expand/collapse.
3999 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4001 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4002 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4003 else DoExpand( p
, true );
4010 // click on splitter
4011 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4013 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4015 // Double-clicking the splitter causes auto-centering
4016 CenterSplitter( true );
4018 else if ( m_dragStatus
== 0 )
4021 // Begin draggin the splitter
4025 // Changes must be committed here or the
4026 // value won't be drawn correctly
4027 if ( !CommitChangesFromEditor() )
4030 m_wndEditor
->Show ( false );
4033 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4035 m_canvas
->CaptureMouse();
4036 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4040 m_draggedSplitter
= splitterHit
;
4041 m_dragOffset
= splitterHitOffset
;
4043 wxClientDC
dc(m_canvas
);
4045 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4046 // Fixes button disappearance bug
4048 m_wndEditor2
->Show ( false );
4051 m_startingSplitterX
= x
- splitterHitOffset
;
4059 if ( p
->GetChildCount() )
4061 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4063 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4065 int y2
= y
% m_lineHeight
;
4066 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4068 // On click on expander button, expand/collapse
4069 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4070 DoCollapse( p
, true );
4072 DoExpand( p
, true );
4081 // -----------------------------------------------------------------------
4083 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4084 wxMouseEvent
& WXUNUSED(event
) )
4088 // Select property here as well
4089 wxPGProperty
* p
= m_propHover
;
4090 if ( p
!= m_selected
)
4091 DoSelectProperty( p
);
4093 // Send right click event.
4094 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4101 // -----------------------------------------------------------------------
4103 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4104 wxMouseEvent
& WXUNUSED(event
) )
4108 // Select property here as well
4109 wxPGProperty
* p
= m_propHover
;
4111 if ( p
!= m_selected
)
4112 DoSelectProperty( p
);
4114 // Send double-click event.
4115 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4122 // -----------------------------------------------------------------------
4124 #if wxPG_SUPPORT_TOOLTIPS
4126 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4128 if ( tipString
.length() )
4130 m_canvas
->SetToolTip(tipString
);
4134 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4135 m_canvas
->SetToolTip( m_emptyString
);
4137 m_canvas
->SetToolTip( NULL
);
4142 #endif // #if wxPG_SUPPORT_TOOLTIPS
4144 // -----------------------------------------------------------------------
4146 // Return false if should be skipped
4147 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4149 // Safety check (needed because mouse capturing may
4150 // otherwise freeze the control)
4151 if ( m_dragStatus
> 0 && !event
.Dragging() )
4153 HandleMouseUp(x
,y
,event
);
4156 wxPropertyGridPageState
* state
= m_pState
;
4158 int splitterHitOffset
;
4159 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4160 int splitterX
= x
- splitterHitOffset
;
4162 if ( m_dragStatus
> 0 )
4164 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4165 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4168 int newSplitterX
= x
- m_dragOffset
;
4169 int splitterX
= x
- splitterHitOffset
;
4171 // Splitter redraw required?
4172 if ( newSplitterX
!= splitterX
)
4175 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4176 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4177 state
->m_fSplitterX
= (float) newSplitterX
;
4180 CorrectEditorWidgetSizeX();
4194 int ih
= m_lineHeight
;
4197 #if wxPG_SUPPORT_TOOLTIPS
4198 wxPGProperty
* prevHover
= m_propHover
;
4199 unsigned char prevSide
= m_mouseSide
;
4201 int curPropHoverY
= y
- (y
% ih
);
4203 // On which item it hovers
4206 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4209 // Mouse moves on another property
4211 m_propHover
= DoGetItemAtY(y
);
4212 m_propHoverY
= curPropHoverY
;
4215 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4218 #if wxPG_SUPPORT_TOOLTIPS
4219 // Store which side we are on
4221 if ( columnHit
== 1 )
4223 else if ( columnHit
== 0 )
4227 // If tooltips are enabled, show label or value as a tip
4228 // in case it doesn't otherwise show in full length.
4230 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4232 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4234 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4236 if ( m_propHover
&& !m_propHover
->IsCategory() )
4239 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4241 // Show help string as a tooltip
4242 wxString tipString
= m_propHover
->GetHelpString();
4244 SetToolTip(tipString
);
4248 // Show cropped value string as a tooltip
4252 if ( m_mouseSide
== 1 )
4254 tipString
= m_propHover
->m_label
;
4255 space
= splitterX
-m_marginWidth
-3;
4257 else if ( m_mouseSide
== 2 )
4259 tipString
= m_propHover
->GetDisplayedString();
4261 space
= m_width
- splitterX
;
4262 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4263 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4269 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4272 SetToolTip( tipString
);
4279 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4280 m_canvas
->SetToolTip( m_emptyString
);
4282 m_canvas
->SetToolTip( NULL
);
4293 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4294 m_canvas
->SetToolTip( m_emptyString
);
4296 m_canvas
->SetToolTip( NULL
);
4304 if ( splitterHit
== -1 ||
4306 HasFlag(wxPG_STATIC_SPLITTER
) )
4308 // hovering on something else
4309 if ( m_curcursor
!= wxCURSOR_ARROW
)
4310 CustomSetCursor( wxCURSOR_ARROW
);
4314 // Do not allow splitter cursor on caption items.
4315 // (also not if we were dragging and its started
4316 // outside the splitter region)
4318 if ( !m_propHover
->IsCategory() &&
4322 // hovering on splitter
4324 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4325 // reliably detected.
4326 //if ( m_curcursor != wxCURSOR_SIZEWE )
4327 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4333 // hovering on something else
4334 if ( m_curcursor
!= wxCURSOR_ARROW
)
4335 CustomSetCursor( wxCURSOR_ARROW
);
4342 // -----------------------------------------------------------------------
4344 // Also handles Leaving event
4345 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4346 wxMouseEvent
&WXUNUSED(event
) )
4348 wxPropertyGridPageState
* state
= m_pState
;
4352 int splitterHitOffset
;
4353 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4355 // No event type check - basicly calling this method should
4356 // just stop dragging.
4357 // Left up after dragged?
4358 if ( m_dragStatus
>= 1 )
4361 // End Splitter Dragging
4363 // DO NOT ENABLE FOLLOWING LINE!
4364 // (it is only here as a reminder to not to do it)
4367 // Disable splitter auto-centering
4368 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4370 // This is necessary to return cursor
4371 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4373 m_canvas
->ReleaseMouse();
4374 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4377 // Set back the default cursor, if necessary
4378 if ( splitterHit
== -1 ||
4381 CustomSetCursor( wxCURSOR_ARROW
);
4386 // Control background needs to be cleared
4387 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4388 DrawItem( m_selected
);
4392 m_wndEditor
->Show ( true );
4395 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4396 // Fixes button disappearance bug
4398 m_wndEditor2
->Show ( true );
4401 // This clears the focus.
4402 m_editorFocused
= 0;
4408 // -----------------------------------------------------------------------
4410 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4412 int splitterX
= GetSplitterPosition();
4415 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4419 wxWindow
* wnd
= GetEditorControl();
4421 // Hide popup on clicks
4422 if ( event
.GetEventType() != wxEVT_MOTION
)
4423 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4425 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4431 if ( wnd
== NULL
|| m_dragStatus
||
4433 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4434 ux
>= (r
.x
+r
.width
) ||
4436 event
.m_y
>= (r
.y
+r
.height
)
4446 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4451 // -----------------------------------------------------------------------
4453 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4456 if ( OnMouseCommon( event
, &x
, &y
) )
4458 HandleMouseClick(x
,y
,event
);
4463 // -----------------------------------------------------------------------
4465 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4468 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4469 HandleMouseRightClick(x
,y
,event
);
4473 // -----------------------------------------------------------------------
4475 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4477 // Always run standard mouse-down handler as well
4478 OnMouseClick(event
);
4481 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4482 HandleMouseDoubleClick(x
,y
,event
);
4486 // -----------------------------------------------------------------------
4488 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4491 if ( OnMouseCommon( event
, &x
, &y
) )
4493 HandleMouseMove(x
,y
,event
);
4498 // -----------------------------------------------------------------------
4500 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4502 // Called when mouse moves in the empty space below the properties.
4503 CustomSetCursor( wxCURSOR_ARROW
);
4506 // -----------------------------------------------------------------------
4508 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4511 if ( OnMouseCommon( event
, &x
, &y
) )
4513 HandleMouseUp(x
,y
,event
);
4518 // -----------------------------------------------------------------------
4520 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4522 // This may get called from child control as well, so event's
4523 // mouse position cannot be relied on.
4525 if ( event
.Entering() )
4527 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4529 // TODO: Fix this (detect parent and only do
4530 // cursor trick if it is a manager).
4531 wxASSERT( GetParent() );
4532 GetParent()->SetCursor(wxNullCursor
);
4534 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4537 GetParent()->SetCursor(wxNullCursor
);
4539 else if ( event
.Leaving() )
4541 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4542 m_canvas
->SetCursor( wxNullCursor
);
4544 // Get real cursor position
4545 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4547 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4550 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4552 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4556 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4564 // -----------------------------------------------------------------------
4566 // Common code used by various OnMouseXXXChild methods.
4567 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4569 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4570 wxASSERT( topCtrlWnd
);
4572 event
.GetPosition(&x
,&y
);
4574 int splitterX
= GetSplitterPosition();
4576 wxRect r
= topCtrlWnd
->GetRect();
4577 if ( !m_dragStatus
&&
4578 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4579 y
>= 0 && y
< r
.height \
4582 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4587 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4594 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4597 if ( OnMouseChildCommon(event
,&x
,&y
) )
4599 bool res
= HandleMouseClick(x
,y
,event
);
4600 if ( !res
) event
.Skip();
4604 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4607 wxASSERT( m_wndEditor
);
4608 // These coords may not be exact (about +-2),
4609 // but that should not matter (right click is about item, not position).
4610 wxPoint pt
= m_wndEditor
->GetPosition();
4611 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4612 wxASSERT( m_selected
);
4613 m_propHover
= m_selected
;
4614 bool res
= HandleMouseRightClick(x
,y
,event
);
4615 if ( !res
) event
.Skip();
4618 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4621 if ( OnMouseChildCommon(event
,&x
,&y
) )
4623 bool res
= HandleMouseMove(x
,y
,event
);
4624 if ( !res
) event
.Skip();
4628 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4631 if ( OnMouseChildCommon(event
,&x
,&y
) )
4633 bool res
= HandleMouseUp(x
,y
,event
);
4634 if ( !res
) event
.Skip();
4638 // -----------------------------------------------------------------------
4639 // wxPropertyGrid keyboard event handling
4640 // -----------------------------------------------------------------------
4642 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4644 // Translates wxKeyEvent to wxPG_ACTION_XXX
4646 int keycode
= event
.GetKeyCode();
4647 int modifiers
= event
.GetModifiers();
4649 wxASSERT( !(modifiers
&~(0xFFFF)) );
4651 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4653 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4655 if ( it
== m_actionTriggers
.end() )
4660 int second
= (it
->second
>>16) & 0xFFFF;
4664 return (it
->second
& 0xFFFF);
4667 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4669 wxASSERT( !(modifiers
&~(0xFFFF)) );
4671 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4673 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4675 if ( it
!= m_actionTriggers
.end() )
4677 // This key combination is already used
4679 // Can add secondary?
4680 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4681 wxT("You can only add up to two separate actions per key combination.") );
4683 action
= it
->second
| (action
<<16);
4686 m_actionTriggers
[hashMapKey
] = action
;
4689 void wxPropertyGrid::ClearActionTriggers( int action
)
4691 wxPGHashMapI2I::iterator it
;
4693 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4695 if ( it
->second
== action
)
4697 m_actionTriggers
.erase(it
);
4702 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4705 // Handles key event when editor control is not focused.
4708 wxCHECK2(!m_frozen
, return);
4710 // Travelsal between items, collapsing/expanding, etc.
4711 int keycode
= event
.GetKeyCode();
4712 bool editorFocused
= IsEditorFocused();
4714 if ( keycode
== WXK_TAB
)
4716 wxWindow
* mainControl
;
4718 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4719 mainControl
= GetParent();
4723 if ( !event
.ShiftDown() )
4725 if ( !editorFocused
&& m_wndEditor
)
4727 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4731 // Tab traversal workaround for platforms on which
4732 // wxWindow::Navigate() may navigate into first child
4733 // instead of next sibling. Does not work perfectly
4734 // in every scenario (for instance, when property grid
4735 // is either first or last control).
4736 #if defined(__WXGTK__)
4737 wxWindow
* sibling
= mainControl
->GetNextSibling();
4739 sibling
->SetFocusFromKbd();
4741 Navigate(wxNavigationKeyEvent::IsForward
);
4747 if ( editorFocused
)
4753 #if defined(__WXGTK__)
4754 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4756 sibling
->SetFocusFromKbd();
4758 Navigate(wxNavigationKeyEvent::IsBackward
);
4766 // Ignore Alt and Control when they are down alone
4767 if ( keycode
== WXK_ALT
||
4768 keycode
== WXK_CONTROL
)
4775 int action
= KeyEventToActions(event
, &secondAction
);
4777 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4780 // Esc cancels any changes
4781 if ( IsEditorsValueModified() )
4783 EditorsValueWasNotModified();
4785 // Update the control as well
4786 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4788 m_selected
->GetDisplayedString() );
4791 OnValidationFailureReset(m_selected
);
4797 // Except for TAB and ESC, handle child control events in child control
4800 // Only propagate event if it had modifiers
4801 if ( !event
.HasModifiers() )
4803 event
.StopPropagation();
4809 bool wasHandled
= false;
4814 if ( ButtonTriggerKeyTest(action
, event
) )
4817 wxPGProperty
* p
= m_selected
;
4819 // Travel and expand/collapse
4822 if ( p
->GetChildCount() )
4824 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4826 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4829 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4831 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4838 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4842 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4848 if ( selectDir
>= -1 )
4850 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4852 DoSelectProperty(p
);
4858 // If nothing was selected, select the first item now
4859 // (or navigate out of tab).
4860 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4862 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4863 if ( p
) DoSelectProperty(p
);
4872 // -----------------------------------------------------------------------
4874 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4876 // If there was editor open and focused, then this event should not
4877 // really be processed here.
4878 if ( IsEditorFocused() )
4880 // However, if event had modifiers, it is probably still best
4882 if ( event
.HasModifiers() )
4885 event
.StopPropagation();
4889 HandleKeyEvent(event
, false);
4892 // -----------------------------------------------------------------------
4894 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4899 action
= KeyEventToActions(event
, &secondAction
);
4902 // Does the keycode trigger button?
4903 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4906 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4907 GetEventHandler()->AddPendingEvent(evt
);
4914 // -----------------------------------------------------------------------
4916 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4918 HandleKeyEvent(event
, true);
4921 // -----------------------------------------------------------------------
4922 // wxPropertyGrid miscellaneous event handling
4923 // -----------------------------------------------------------------------
4925 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4928 // Check if the focus is in this control or one of its children
4929 wxWindow
* newFocused
= wxWindow::FindFocus();
4931 if ( newFocused
!= m_curFocused
)
4932 HandleFocusChange( newFocused
);
4935 bool wxPropertyGrid::IsEditorFocused() const
4937 wxWindow
* focus
= wxWindow::FindFocus();
4939 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4940 focus
== GetEditorControl() )
4946 // Called by focus event handlers. newFocused is the window that becomes focused.
4947 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4949 unsigned int oldFlags
= m_iFlags
;
4951 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4953 wxWindow
* parent
= newFocused
;
4955 // This must be one of nextFocus' parents.
4958 // Use m_eventObject, which is either wxPropertyGrid or
4959 // wxPropertyGridManager, as appropriate.
4960 if ( parent
== m_eventObject
)
4962 m_iFlags
|= wxPG_FL_FOCUSED
;
4965 parent
= parent
->GetParent();
4968 m_curFocused
= newFocused
;
4970 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4971 (oldFlags
& wxPG_FL_FOCUSED
) )
4973 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4975 // Need to store changed value
4976 CommitChangesFromEditor();
4982 // Preliminary code for tab-order respecting
4983 // tab-traversal (but should be moved to
4986 wxWindow* prevFocus = event.GetWindow();
4987 wxWindow* useThis = this;
4988 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4989 useThis = GetParent();
4992 prevFocus->GetParent() == useThis->GetParent() )
4994 wxList& children = useThis->GetParent()->GetChildren();
4996 wxNode* node = children.Find(prevFocus);
4998 if ( node->GetNext() &&
4999 useThis == node->GetNext()->GetData() )
5000 DoSelectProperty(GetFirst());
5001 else if ( node->GetPrevious () &&
5002 useThis == node->GetPrevious()->GetData() )
5003 DoSelectProperty(GetLastProperty());
5010 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5011 DrawItem( m_selected
);
5015 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5017 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5018 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5019 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5020 //else if ( event.GetWindow() )
5022 HandleFocusChange(event
.GetWindow());
5027 // -----------------------------------------------------------------------
5029 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5031 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5035 // -----------------------------------------------------------------------
5037 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5039 m_iFlags
|= wxPG_FL_SCROLLED
;
5044 // -----------------------------------------------------------------------
5046 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5048 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5050 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5054 // -----------------------------------------------------------------------
5055 // Property editor related functions
5056 // -----------------------------------------------------------------------
5058 // noDefCheck = true prevents infinite recursion.
5059 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5062 wxASSERT( editorClass
);
5064 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5065 RegisterDefaultEditors();
5067 wxString name
= editorClass
->GetName();
5069 // Existing editor under this name?
5070 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5072 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5074 // If this name was already used, try class name.
5075 name
= editorClass
->GetClassInfo()->GetClassName();
5076 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5079 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5080 (wxPGEditor
*) vt_it
->second
,
5081 "Editor with given name was already registered" );
5083 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5088 // Use this in RegisterDefaultEditors.
5089 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5090 if ( wxPGEditor_##EDITOR == NULL ) \
5092 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5093 new wxPG##EDITOR##Editor, true ); \
5096 // Registers all default editor classes
5097 void wxPropertyGrid::RegisterDefaultEditors()
5099 wxPGRegisterDefaultEditorClass( TextCtrl
);
5100 wxPGRegisterDefaultEditorClass( Choice
);
5101 wxPGRegisterDefaultEditorClass( ComboBox
);
5102 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5103 #if wxPG_INCLUDE_CHECKBOX
5104 wxPGRegisterDefaultEditorClass( CheckBox
);
5106 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5108 // Register SpinCtrl etc. editors before use
5109 RegisterAdditionalEditors();
5112 // -----------------------------------------------------------------------
5113 // wxPGStringTokenizer
5114 // Needed to handle C-style string lists (e.g. "str1" "str2")
5115 // -----------------------------------------------------------------------
5117 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5118 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5122 wxPGStringTokenizer::~wxPGStringTokenizer()
5126 bool wxPGStringTokenizer::HasMoreTokens()
5128 const wxString
& str
= *m_str
;
5130 wxString::const_iterator i
= m_curPos
;
5132 wxUniChar delim
= m_delimeter
;
5134 wxUniChar prev_a
= wxT('\0');
5136 bool inToken
= false;
5138 while ( i
!= str
.end() )
5147 m_readyToken
.clear();
5152 if ( prev_a
!= wxT('\\') )
5156 if ( a
!= wxT('\\') )
5176 m_curPos
= str
.end();
5184 wxString
wxPGStringTokenizer::GetNextToken()
5186 return m_readyToken
;
5189 // -----------------------------------------------------------------------
5191 // -----------------------------------------------------------------------
5193 wxPGChoiceEntry::wxPGChoiceEntry()
5194 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5198 // -----------------------------------------------------------------------
5200 // -----------------------------------------------------------------------
5202 wxPGChoicesData::wxPGChoicesData()
5207 wxPGChoicesData::~wxPGChoicesData()
5212 void wxPGChoicesData::Clear()
5217 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5219 wxASSERT( m_items
.size() == 0 );
5221 m_items
= data
->m_items
;
5224 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5225 const wxPGChoiceEntry
& item
)
5227 wxVector
<wxPGChoiceEntry
>::iterator it
;
5231 index
= (int) m_items
.size();
5235 it
= m_items
.begin() + index
;
5238 m_items
.insert(it
, item
);
5240 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5242 // Need to fix value?
5243 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5244 ownEntry
.SetValue(index
);
5249 // -----------------------------------------------------------------------
5250 // wxPropertyGridEvent
5251 // -----------------------------------------------------------------------
5253 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5256 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5257 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5258 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5259 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5260 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5261 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5262 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5263 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5267 // -----------------------------------------------------------------------
5269 void wxPropertyGridEvent::Init()
5271 m_validationInfo
= NULL
;
5273 m_wasVetoed
= false;
5276 // -----------------------------------------------------------------------
5278 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5279 : wxCommandEvent(commandType
,id
)
5285 // -----------------------------------------------------------------------
5287 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5288 : wxCommandEvent(event
)
5290 m_eventType
= event
.GetEventType();
5291 m_eventObject
= event
.m_eventObject
;
5293 m_property
= event
.m_property
;
5294 m_validationInfo
= event
.m_validationInfo
;
5295 m_canVeto
= event
.m_canVeto
;
5296 m_wasVetoed
= event
.m_wasVetoed
;
5299 // -----------------------------------------------------------------------
5301 wxPropertyGridEvent::~wxPropertyGridEvent()
5305 // -----------------------------------------------------------------------
5307 wxEvent
* wxPropertyGridEvent::Clone() const
5309 return new wxPropertyGridEvent( *this );
5312 // -----------------------------------------------------------------------
5313 // wxPropertyGridPopulator
5314 // -----------------------------------------------------------------------
5316 wxPropertyGridPopulator::wxPropertyGridPopulator()
5320 wxPGGlobalVars
->m_offline
++;
5323 // -----------------------------------------------------------------------
5325 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5328 m_propHierarchy
.clear();
5331 // -----------------------------------------------------------------------
5333 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5339 // -----------------------------------------------------------------------
5341 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5344 // Free unused sets of choices
5345 wxPGHashMapS2P::iterator it
;
5347 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5349 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5356 m_pg
->GetPanel()->Refresh();
5358 wxPGGlobalVars
->m_offline
--;
5361 // -----------------------------------------------------------------------
5363 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5364 const wxString
& propLabel
,
5365 const wxString
& propName
,
5366 const wxString
* propValue
,
5367 wxPGChoices
* pChoices
)
5369 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5370 wxPGProperty
* parent
= GetCurParent();
5372 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5374 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5378 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5380 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5384 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5386 property
->SetLabel(propLabel
);
5387 property
->DoSetName(propName
);
5389 if ( pChoices
&& pChoices
->IsOk() )
5390 property
->SetChoices(*pChoices
);
5392 m_state
->DoInsert(parent
, -1, property
);
5395 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5396 wxPG_PROGRAMMATIC_VALUE
);
5401 // -----------------------------------------------------------------------
5403 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5405 m_propHierarchy
.push_back(property
);
5406 DoScanForChildren();
5407 m_propHierarchy
.pop_back();
5410 // -----------------------------------------------------------------------
5412 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5413 const wxString
& idString
)
5415 wxPGChoices choices
;
5418 if ( choicesString
[0] == wxT('@') )
5420 wxString ids
= choicesString
.substr(1);
5421 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5422 if ( it
== m_dictIdChoices
.end() )
5423 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5425 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5430 if ( idString
.length() )
5432 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5433 if ( it
!= m_dictIdChoices
.end() )
5435 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5442 // Parse choices string
5443 wxString::const_iterator it
= choicesString
.begin();
5447 bool labelValid
= false;
5449 for ( ; it
!= choicesString
.end(); ++it
)
5455 if ( c
== wxT('"') )
5460 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5461 choices
.Add(label
, l
);
5464 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5469 else if ( c
== wxT('=') )
5476 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5483 if ( c
== wxT('"') )
5496 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5497 choices
.Add(label
, l
);
5500 if ( !choices
.IsOk() )
5502 choices
.EnsureData();
5506 if ( idString
.length() )
5507 m_dictIdChoices
[idString
] = choices
.GetData();
5514 // -----------------------------------------------------------------------
5516 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5518 if ( s
.Last() == wxT('%') )
5520 wxString s2
= s
.substr(0,s
.length()-1);
5522 if ( s2
.ToLong(&val
, 10) )
5524 *pval
= (val
*max
)/100;
5530 return s
.ToLong(pval
, 10);
5533 // -----------------------------------------------------------------------
5535 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5536 const wxString
& type
,
5537 const wxString
& value
)
5539 int l
= m_propHierarchy
.size();
5543 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5544 wxString valuel
= value
.Lower();
5547 if ( type
.length() == 0 )
5552 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5554 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5556 else if ( value
.ToLong(&v
, 0) )
5563 if ( type
== wxT("string") )
5567 else if ( type
== wxT("int") )
5570 value
.ToLong(&v
, 0);
5573 else if ( type
== wxT("bool") )
5575 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5582 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5587 p
->SetAttribute( name
, variant
);
5592 // -----------------------------------------------------------------------
5594 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5596 wxLogError(_("Error in resource: %s"),msg
.c_str());
5599 // -----------------------------------------------------------------------
5601 #endif // wxUSE_PROPGRID