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");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
237 // and tries to commit property value.
238 // -----------------------------------------------------------------------
240 class wxPGTLWHandler
: public wxEvtHandler
244 wxPGTLWHandler( wxPropertyGrid
* pg
)
252 void OnClose( wxCloseEvent
& event
)
254 // ClearSelection forces value validation/commit.
255 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
265 wxPropertyGrid
* m_pg
;
267 DECLARE_EVENT_TABLE()
270 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
271 EVT_CLOSE(wxPGTLWHandler::OnClose
)
274 // -----------------------------------------------------------------------
276 // -----------------------------------------------------------------------
279 // wxPGCanvas acts as a graphics sub-window of the
280 // wxScrolledWindow that wxPropertyGrid is.
282 class wxPGCanvas
: public wxPanel
285 wxPGCanvas() : wxPanel()
288 virtual ~wxPGCanvas() { }
291 void OnMouseMove( wxMouseEvent
&event
)
293 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
294 pg
->OnMouseMove( event
);
297 void OnMouseClick( wxMouseEvent
&event
)
299 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
300 pg
->OnMouseClick( event
);
303 void OnMouseUp( wxMouseEvent
&event
)
305 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
306 pg
->OnMouseUp( event
);
309 void OnMouseRightClick( wxMouseEvent
&event
)
311 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
312 pg
->OnMouseRightClick( event
);
315 void OnMouseDoubleClick( wxMouseEvent
&event
)
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 pg
->OnMouseDoubleClick( event
);
321 void OnKey( wxKeyEvent
& event
)
323 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
327 void OnPaint( wxPaintEvent
& event
);
329 // Always be focussable, even with child windows
330 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
331 { wxPanel::SetCanFocus(true); }
335 DECLARE_EVENT_TABLE()
336 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
340 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
342 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
343 EVT_MOTION(wxPGCanvas::OnMouseMove
)
344 EVT_PAINT(wxPGCanvas::OnPaint
)
345 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
346 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
347 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
348 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
349 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
353 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
355 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
356 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
360 // Don't paint after destruction has begun
361 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
364 // Update everything inside the box
365 wxRect r
= GetUpdateRegion().GetBox();
367 // FIXME: This is just a workaround for a bug that causes splitters not
368 // to paint when other windows are being dragged over the grid.
369 wxRect fullRect
= GetRect();
371 r
.width
= fullRect
.width
;
373 // Repaint this rectangle
374 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
376 // We assume that the size set when grid is shown
377 // is what is desired.
378 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
381 // -----------------------------------------------------------------------
383 // -----------------------------------------------------------------------
385 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
387 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
388 EVT_IDLE(wxPropertyGrid::OnIdle
)
389 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
390 EVT_PAINT(wxPropertyGrid::OnPaint
)
391 EVT_SIZE(wxPropertyGrid::OnResize
)
392 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
393 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
394 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
395 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
396 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
397 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
398 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
399 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
403 // -----------------------------------------------------------------------
405 wxPropertyGrid::wxPropertyGrid()
411 // -----------------------------------------------------------------------
413 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
418 const wxString
& name
)
422 Create(parent
,id
,pos
,size
,style
,name
);
425 // -----------------------------------------------------------------------
427 bool wxPropertyGrid::Create( wxWindow
*parent
,
432 const wxString
& name
)
435 if ( !(style
&wxBORDER_MASK
) )
436 style
|= wxSIMPLE_BORDER
;
440 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
441 style
&= ~(wxTAB_TRAVERSAL
);
442 style
|= wxWANTS_CHARS
;
444 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
451 // -----------------------------------------------------------------------
454 // Initialize values to defaults
456 void wxPropertyGrid::Init1()
458 // Register editor classes, if necessary.
459 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
460 wxPropertyGrid::RegisterDefaultEditors();
464 m_wndEditor
= m_wndEditor2
= NULL
;
468 m_eventObject
= this;
471 m_sortFunction
= NULL
;
472 m_inDoPropertyChanged
= 0;
473 m_inCommitChangesFromEditor
= 0;
474 m_inDoSelectProperty
= 0;
475 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
481 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
482 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
483 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
484 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
485 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
486 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
487 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
488 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
489 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
491 m_coloursCustomized
= 0;
496 #if wxPG_DOUBLE_BUFFER
497 m_doubleBuffer
= NULL
;
500 #ifndef wxPG_ICON_WIDTH
506 m_iconWidth
= wxPG_ICON_WIDTH
;
511 m_gutterWidth
= wxPG_GUTTER_MIN
;
512 m_subgroup_extramargin
= 10;
516 m_width
= m_height
= 0;
518 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
521 m_chgInfo_changedProperty
= NULL
;
524 // -----------------------------------------------------------------------
527 // Initialize after parent etc. set
529 void wxPropertyGrid::Init2()
531 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
534 // Smaller controls on Mac
535 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
538 // Now create state, if one didn't exist already
539 // (wxPropertyGridManager might have created it for us).
542 m_pState
= CreateState();
543 m_pState
->m_pPropGrid
= this;
544 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
547 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
548 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
550 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
552 m_pState
->InitNonCatMode();
554 m_pState
->m_properties
= m_pState
->m_abcArray
;
557 GetClientSize(&m_width
,&m_height
);
559 #ifndef wxPG_ICON_WIDTH
560 // create two bitmap nodes for drawing
561 m_expandbmp
= new wxBitmap(expand_xpm
);
562 m_collbmp
= new wxBitmap(collapse_xpm
);
564 // calculate average font height for bitmap centering
566 m_iconWidth
= m_expandbmp
->GetWidth();
567 m_iconHeight
= m_expandbmp
->GetHeight();
570 m_curcursor
= wxCURSOR_ARROW
;
571 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
573 // adjust bitmap icon y position so they are centered
574 m_vspacing
= wxPG_DEFAULT_VSPACING
;
576 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
578 // Allocate cell datas indirectly by calling setter
579 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
580 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
584 // This helps with flicker
585 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
588 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
589 m_tlp
= ::wxGetTopLevelParent(this);
590 m_tlwHandler
= handler
;
591 m_tlp
->PushEventHandler(handler
);
593 // set virtual size to this window size
594 wxSize wndsize
= GetSize();
595 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
597 m_timeCreated
= ::wxGetLocalTimeMillis();
599 m_canvas
= new wxPGCanvas();
600 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
601 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
602 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
604 m_iFlags
|= wxPG_FL_INITIALIZED
;
606 m_ncWidth
= wndsize
.GetWidth();
608 // Need to call OnResize handler or size given in constructor/Create
610 wxSizeEvent
sizeEvent(wndsize
,0);
614 // -----------------------------------------------------------------------
616 wxPropertyGrid::~wxPropertyGrid()
620 DoSelectProperty(NULL
);
622 // This should do prevent things from going too badly wrong
623 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
625 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
626 m_canvas
->ReleaseMouse();
628 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
629 m_tlp
->RemoveEventHandler(handler
);
633 if ( IsEditorsValueModified() )
634 ::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).)"),
635 wxS("wxPropertyGrid Debug Warning") );
638 #if wxPG_DOUBLE_BUFFER
639 if ( m_doubleBuffer
)
640 delete m_doubleBuffer
;
645 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
648 delete m_cursorSizeWE
;
650 #ifndef wxPG_ICON_WIDTH
655 // Delete common value records
656 for ( i
=0; i
<m_commonValues
.size(); i
++ )
658 delete GetCommonValue(i
);
662 // -----------------------------------------------------------------------
664 bool wxPropertyGrid::Destroy()
666 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
667 m_canvas
->ReleaseMouse();
669 return wxScrolledWindow::Destroy();
672 // -----------------------------------------------------------------------
674 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
676 return new wxPropertyGridPageState();
679 // -----------------------------------------------------------------------
680 // wxPropertyGrid overridden wxWindow methods
681 // -----------------------------------------------------------------------
683 void wxPropertyGrid::SetWindowStyleFlag( long style
)
685 long old_style
= m_windowStyle
;
687 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
689 wxASSERT( m_pState
);
691 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
694 EnableCategories( true );
696 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
698 // Disable categories
699 EnableCategories( false );
701 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
707 PrepareAfterItemsAdded();
709 m_pState
->m_itemsAdded
= 1;
711 #if wxPG_SUPPORT_TOOLTIPS
712 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
718 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
719 SetToolTip ( tooltip );
720 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
723 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
728 m_canvas
->SetToolTip( NULL
);
733 wxScrolledWindow::SetWindowStyleFlag ( style
);
735 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
737 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
739 CalculateFontAndBitmapStuff( m_vspacing
);
745 // -----------------------------------------------------------------------
747 void wxPropertyGrid::Freeze()
751 wxScrolledWindow::Freeze();
756 // -----------------------------------------------------------------------
758 void wxPropertyGrid::Thaw()
764 wxScrolledWindow::Thaw();
765 RecalculateVirtualSize();
766 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
770 // Force property re-selection
772 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
776 // -----------------------------------------------------------------------
778 void wxPropertyGrid::SetExtraStyle( long exStyle
)
780 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
782 #if defined(__WXMSW__)
785 // Don't use WS_EX_COMPOSITED just now.
788 if ( m_iFlags & wxPG_FL_IN_MANAGER )
789 hWnd = (HWND)GetParent()->GetHWND();
791 hWnd = (HWND)GetHWND();
793 ::SetWindowLong( hWnd, GWL_EXSTYLE,
794 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
797 //#elif defined(__WXGTK20__)
799 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
800 // truly was double-buffered.
801 if ( !this->IsDoubleBuffered() )
803 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
807 #if wxPG_DOUBLE_BUFFER
808 delete m_doubleBuffer
;
809 m_doubleBuffer
= NULL
;
814 wxScrolledWindow::SetExtraStyle( exStyle
);
816 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
817 m_pState
->InitNonCatMode();
819 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
820 m_windowStyle
|= wxPG_TOOLTIPS
;
823 wxPGGlobalVars
->m_extraStyle
= exStyle
;
826 // -----------------------------------------------------------------------
828 // returns the best acceptable minimal size
829 wxSize
wxPropertyGrid::DoGetBestSize() const
832 if ( m_lineHeight
> hei
)
834 wxSize sz
= wxSize( 60, hei
+40 );
840 // -----------------------------------------------------------------------
841 // wxPropertyGrid Font and Colour Methods
842 // -----------------------------------------------------------------------
844 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
848 m_captionFont
= wxScrolledWindow::GetFont();
850 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
851 m_subgroup_extramargin
= x
+ (x
/2);
854 #if wxPG_USE_RENDERER_NATIVE
855 m_iconWidth
= wxPG_ICON_WIDTH
;
856 #elif wxPG_ICON_WIDTH
858 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
859 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
860 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
864 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
865 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
866 m_gutterWidth
= wxPG_GUTTER_MIN
;
869 if ( vspacing
<= 1 ) vdiv
= 12;
870 else if ( vspacing
>= 3 ) vdiv
= 3;
872 m_spacingy
= m_fontHeight
/ vdiv
;
873 if ( m_spacingy
< wxPG_YSPACING_MIN
)
874 m_spacingy
= wxPG_YSPACING_MIN
;
877 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
878 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
880 m_captionFont
.SetWeight(wxBOLD
);
881 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
883 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
886 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
887 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
890 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
892 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
893 RecalculateVirtualSize();
895 InvalidateBestSize();
898 // -----------------------------------------------------------------------
900 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
906 // -----------------------------------------------------------------------
908 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
909 int ga
= 1000, int ba
= 1000,
910 bool forceDifferent
= false)
917 // Recursion guard (allow 2 max)
918 static int isinside
= 0;
920 wxCHECK_MSG( isinside
< 3,
922 wxT("wxPGAdjustColour should not be recursively called more than once") );
930 if ( r2
>255 ) r2
= 255;
931 else if ( r2
<0) r2
= 0;
933 if ( g2
>255 ) g2
= 255;
934 else if ( g2
<0) g2
= 0;
936 if ( b2
>255 ) b2
= 255;
937 else if ( b2
<0) b2
= 0;
939 // Make sure they are somewhat different
940 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
941 dst
= wxPGAdjustColour(src
,-(ra
*2));
943 dst
= wxColour(r2
,g2
,b2
);
945 // Recursion guard (allow 2 max)
952 static int wxPGGetColAvg( const wxColour
& col
)
954 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
958 void wxPropertyGrid::RegainColours()
960 if ( !(m_coloursCustomized
& 0x0002) )
962 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
964 // Make sure colour is dark enough
966 int colDec
= wxPGGetColAvg(col
) - 230;
968 int colDec
= wxPGGetColAvg(col
) - 200;
971 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
974 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
977 if ( !(m_coloursCustomized
& 0x0001) )
978 m_colMargin
= m_colCapBack
;
980 if ( !(m_coloursCustomized
& 0x0004) )
987 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
988 m_colCapFore
= capForeCol
;
989 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
992 if ( !(m_coloursCustomized
& 0x0008) )
994 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
995 m_colPropBack
= bgCol
;
996 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
999 if ( !(m_coloursCustomized
& 0x0010) )
1001 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1002 m_colPropFore
= fgCol
;
1003 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1006 if ( !(m_coloursCustomized
& 0x0020) )
1007 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1009 if ( !(m_coloursCustomized
& 0x0040) )
1010 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1012 if ( !(m_coloursCustomized
& 0x0080) )
1013 m_colLine
= m_colCapBack
;
1015 if ( !(m_coloursCustomized
& 0x0100) )
1016 m_colDisPropFore
= m_colCapFore
;
1018 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1021 // -----------------------------------------------------------------------
1023 void wxPropertyGrid::ResetColours()
1025 m_coloursCustomized
= 0;
1032 // -----------------------------------------------------------------------
1034 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1036 // Must disable active editor.
1037 ClearSelection(false);
1039 bool res
= wxScrolledWindow::SetFont( font
);
1042 CalculateFontAndBitmapStuff( m_vspacing
);
1049 // -----------------------------------------------------------------------
1051 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1054 m_coloursCustomized
|= 0x80;
1058 // -----------------------------------------------------------------------
1060 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1063 m_coloursCustomized
|= 0x01;
1067 // -----------------------------------------------------------------------
1069 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1071 m_colPropBack
= col
;
1072 m_coloursCustomized
|= 0x08;
1074 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1079 // -----------------------------------------------------------------------
1081 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1083 m_colPropFore
= col
;
1084 m_coloursCustomized
|= 0x10;
1086 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1091 // -----------------------------------------------------------------------
1093 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1095 m_colEmptySpace
= col
;
1100 // -----------------------------------------------------------------------
1102 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1104 m_colDisPropFore
= col
;
1105 m_coloursCustomized
|= 0x100;
1109 // -----------------------------------------------------------------------
1111 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1114 m_coloursCustomized
|= 0x20;
1118 // -----------------------------------------------------------------------
1120 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1123 m_coloursCustomized
|= 0x40;
1127 // -----------------------------------------------------------------------
1129 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1132 m_coloursCustomized
|= 0x02;
1134 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1139 // -----------------------------------------------------------------------
1141 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1144 m_coloursCustomized
|= 0x04;
1146 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1151 // -----------------------------------------------------------------------
1152 // wxPropertyGrid property adding and removal
1153 // -----------------------------------------------------------------------
1155 void wxPropertyGrid::PrepareAfterItemsAdded()
1157 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1159 m_pState
->m_itemsAdded
= 0;
1161 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1162 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1164 RecalculateVirtualSize();
1167 // -----------------------------------------------------------------------
1168 // wxPropertyGrid property operations
1169 // -----------------------------------------------------------------------
1171 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1173 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1177 bool changed
= false;
1179 // Is it inside collapsed section?
1180 if ( !p
->IsVisible() )
1183 wxPGProperty
* parent
= p
->GetParent();
1184 wxPGProperty
* grandparent
= parent
->GetParent();
1186 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1187 Expand( grandparent
);
1195 GetViewStart(&vx
,&vy
);
1196 vy
*=wxPG_PIXELS_PER_UNIT
;
1202 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1203 m_iFlags
|= wxPG_FL_SCROLLED
;
1206 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1208 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1209 m_iFlags
|= wxPG_FL_SCROLLED
;
1219 // -----------------------------------------------------------------------
1220 // wxPropertyGrid helper methods called by properties
1221 // -----------------------------------------------------------------------
1223 // Control font changer helper.
1224 void wxPropertyGrid::SetCurControlBoldFont()
1226 wxASSERT( m_wndEditor
);
1227 m_wndEditor
->SetFont( m_captionFont
);
1230 // -----------------------------------------------------------------------
1232 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1235 #if wxPG_SMALL_SCREEN
1236 // On small-screen devices, always show dialogs with default position and size.
1237 return wxDefaultPosition
;
1239 int splitterX
= GetSplitterPosition();
1243 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1245 ImprovedClientToScreen( &x
, &y
);
1247 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1248 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1255 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1265 new_y
= y
+ m_lineHeight
;
1267 return wxPoint(new_x
,new_y
);
1271 // -----------------------------------------------------------------------
1273 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1275 if ( src_str
.length() == 0 )
1281 bool prev_is_slash
= false;
1283 wxString::const_iterator i
= src_str
.begin();
1287 for ( ; i
!= src_str
.end(); ++i
)
1291 if ( a
!= wxS('\\') )
1293 if ( !prev_is_slash
)
1299 if ( a
== wxS('n') )
1302 dst_str
<< wxS('\n');
1304 dst_str
<< wxS('\n');
1307 else if ( a
== wxS('t') )
1308 dst_str
<< wxS('\t');
1312 prev_is_slash
= false;
1316 if ( prev_is_slash
)
1318 dst_str
<< wxS('\\');
1319 prev_is_slash
= false;
1323 prev_is_slash
= true;
1330 // -----------------------------------------------------------------------
1332 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1334 if ( src_str
.length() == 0 )
1340 wxString::const_iterator i
= src_str
.begin();
1341 wxUniChar prev_a
= wxS('\0');
1345 for ( ; i
!= src_str
.end(); ++i
)
1349 if ( a
>= wxS(' ') )
1351 // This surely is not something that requires an escape sequence.
1356 // This might need...
1357 if ( a
== wxS('\r') )
1359 // DOS style line end.
1360 // Already taken care below
1362 else if ( a
== wxS('\n') )
1363 // UNIX style line end.
1364 dst_str
<< wxS("\\n");
1365 else if ( a
== wxS('\t') )
1367 dst_str
<< wxS('\t');
1370 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1380 // -----------------------------------------------------------------------
1382 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1389 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1392 // -----------------------------------------------------------------------
1393 // wxPropertyGrid graphics related methods
1394 // -----------------------------------------------------------------------
1396 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1400 // Update everything inside the box
1401 wxRect r
= GetUpdateRegion().GetBox();
1403 dc
.SetPen(m_colEmptySpace
);
1404 dc
.SetBrush(m_colEmptySpace
);
1405 dc
.DrawRectangle(r
);
1408 // -----------------------------------------------------------------------
1410 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1411 wxPGProperty
* property
) const
1413 // Prepare rectangle to be used
1415 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1416 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1418 #if (wxPG_USE_RENDERER_NATIVE)
1420 #elif wxPG_ICON_WIDTH
1421 // Drawing expand/collapse button manually
1422 dc
.SetPen(m_colPropFore
);
1423 if ( property
->IsCategory() )
1424 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1426 dc
.SetBrush(m_colPropBack
);
1428 dc
.DrawRectangle( r
);
1429 int _y
= r
.y
+(m_iconWidth
/2);
1430 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1435 if ( property
->IsExpanded() )
1437 // wxRenderer functions are non-mutating in nature, so it
1438 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1439 // Hopefully this does not cause problems.
1440 #if (wxPG_USE_RENDERER_NATIVE)
1441 wxRendererNative::Get().DrawTreeItemButton(
1447 #elif wxPG_ICON_WIDTH
1456 #if (wxPG_USE_RENDERER_NATIVE)
1457 wxRendererNative::Get().DrawTreeItemButton(
1463 #elif wxPG_ICON_WIDTH
1464 int _x
= r
.x
+(m_iconWidth
/2);
1465 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1471 #if (wxPG_USE_RENDERER_NATIVE)
1473 #elif wxPG_ICON_WIDTH
1476 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1480 // -----------------------------------------------------------------------
1483 // This is the one called by OnPaint event handler and others.
1484 // topy and bottomy are already unscrolled (ie. physical)
1486 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1488 unsigned int bottomy
,
1489 const wxRect
* clipRect
)
1491 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1493 m_pState
->EnsureVirtualHeight();
1495 wxRect tempClipRect
;
1498 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1499 clipRect
= &tempClipRect
;
1502 // items added check
1503 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1505 int paintFinishY
= 0;
1507 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1510 bool isBuffered
= false;
1512 #if wxPG_DOUBLE_BUFFER
1513 wxMemoryDC
* bufferDC
= NULL
;
1515 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1517 if ( !m_doubleBuffer
)
1519 paintFinishY
= clipRect
->y
;
1524 bufferDC
= new wxMemoryDC();
1526 // If nothing was changed, then just copy from double-buffer
1527 bufferDC
->SelectObject( *m_doubleBuffer
);
1537 dc
.SetClippingRegion( *clipRect
);
1538 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1541 #if wxPG_DOUBLE_BUFFER
1544 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1545 bufferDC
, 0, 0, wxCOPY
);
1546 dc
.DestroyClippingRegion(); // Is this really necessary?
1552 // Clear area beyond bottomY?
1553 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1555 dc
.SetPen(m_colEmptySpace
);
1556 dc
.SetBrush(m_colEmptySpace
);
1557 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1561 // -----------------------------------------------------------------------
1563 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1564 const wxRect
* clipRect
,
1565 bool isBuffered
) const
1567 const wxPGProperty
* firstItem
;
1568 const wxPGProperty
* lastItem
;
1570 firstItem
= DoGetItemAtY(clipRect
->y
);
1571 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1574 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1576 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1579 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1580 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1582 int lh
= m_lineHeight
;
1585 int lastItemBottomY
;
1587 firstItemTopY
= clipRect
->y
;
1588 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1590 // Align y coordinates to item boundaries
1591 firstItemTopY
-= firstItemTopY
% lh
;
1592 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1593 lastItemBottomY
-= 1;
1595 // Entire range outside scrolled, visible area?
1596 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1599 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1603 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1604 firstItem->GetLabel().c_str(),
1605 lastItem->GetLabel().c_str(),
1606 (int)(lastItemBottomY - firstItemTopY),
1608 (unsigned long)clipRect );
1613 long windowStyle
= m_windowStyle
;
1619 // With wxPG_DOUBLE_BUFFER, do double buffering
1620 // - buffer's y = 0, so align cliprect and coordinates to that
1622 #if wxPG_DOUBLE_BUFFER
1628 xRelMod
= clipRect
->x
;
1629 yRelMod
= clipRect
->y
;
1632 // clipRect conversion
1637 firstItemTopY
-= yRelMod
;
1638 lastItemBottomY
-= yRelMod
;
1641 wxUnusedVar(isBuffered
);
1644 int x
= m_marginWidth
- xRelMod
;
1646 wxFont normalFont
= GetFont();
1648 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1650 bool isEnabled
= IsEnabled();
1653 // Prepare some pens and brushes that are often changed to.
1656 wxBrush
marginBrush(m_colMargin
);
1657 wxPen
marginPen(m_colMargin
);
1658 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1659 wxPen
linepen(m_colLine
,1,wxSOLID
);
1661 // pen that has same colour as text
1662 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1665 // Clear margin with background colour
1667 dc
.SetBrush( marginBrush
);
1668 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1670 dc
.SetPen( *wxTRANSPARENT_PEN
);
1671 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1674 const wxPGProperty
* selected
= m_selected
;
1675 const wxPropertyGridPageState
* state
= m_pState
;
1677 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1678 bool wasSelectedPainted
= false;
1681 // TODO: Only render columns that are within clipping region.
1683 dc
.SetFont(normalFont
);
1685 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1686 int endScanBottomY
= lastItemBottomY
+ lh
;
1687 int y
= firstItemTopY
;
1690 // Pregenerate list of visible properties.
1691 wxArrayPGProperty visPropArray
;
1692 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1694 for ( ; !it
.AtEnd(); it
.Next() )
1696 const wxPGProperty
* p
= *it
;
1698 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1700 visPropArray
.push_back((wxPGProperty
*)p
);
1702 if ( y
> endScanBottomY
)
1709 visPropArray
.push_back(NULL
);
1711 wxPGProperty
* nextP
= visPropArray
[0];
1713 int gridWidth
= state
->m_width
;
1716 for ( unsigned int arrInd
=1;
1717 nextP
&& y
<= lastItemBottomY
;
1720 wxPGProperty
* p
= nextP
;
1721 nextP
= visPropArray
[arrInd
];
1723 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1724 int textMarginHere
= x
;
1725 int renderFlags
= 0;
1727 int greyDepth
= m_marginWidth
;
1728 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1729 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1731 int greyDepthX
= greyDepth
- xRelMod
;
1733 // Use basic depth if in non-categoric mode and parent is base array.
1734 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1736 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1739 // Paint margin area
1740 dc
.SetBrush(marginBrush
);
1741 dc
.SetPen(marginPen
);
1742 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1744 dc
.SetPen( linepen
);
1749 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1755 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1757 sx
+= state
->m_colWidths
[si
];
1758 dc
.DrawLine( sx
, y
, sx
, y2
);
1761 // Horizontal Line, below
1762 // (not if both this and next is category caption)
1763 if ( p
->IsCategory() &&
1764 nextP
&& nextP
->IsCategory() )
1765 dc
.SetPen(m_colCapBack
);
1767 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1770 // Need to override row colours?
1774 if ( p
!= selected
)
1776 // Disabled may get different colour.
1777 if ( !p
->IsEnabled() )
1779 renderFlags
|= wxPGCellRenderer::Disabled
|
1780 wxPGCellRenderer::DontUseCellFgCol
;
1781 rowFgCol
= m_colDisPropFore
;
1786 renderFlags
|= wxPGCellRenderer::Selected
;
1788 if ( !p
->IsCategory() )
1790 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1791 wxPGCellRenderer::DontUseCellBgCol
;
1793 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1794 wasSelectedPainted
= true;
1797 // Selected gets different colour.
1798 if ( reallyFocused
)
1800 rowFgCol
= m_colSelFore
;
1801 rowBgCol
= m_colSelBack
;
1803 else if ( isEnabled
)
1805 rowFgCol
= m_colPropFore
;
1806 rowBgCol
= m_colMargin
;
1810 rowFgCol
= m_colDisPropFore
;
1811 rowBgCol
= m_colSelBack
;
1818 if ( rowBgCol
.IsOk() )
1819 rowBgBrush
= wxBrush(rowBgCol
);
1821 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1822 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1825 // Fill additional margin area with background colour of first cell
1826 if ( greyDepthX
< textMarginHere
)
1828 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1830 wxPGCell
& cell
= p
->GetCell(0);
1831 rowBgCol
= cell
.GetBgCol();
1832 rowBgBrush
= wxBrush(rowBgCol
);
1834 dc
.SetBrush(rowBgBrush
);
1835 dc
.SetPen(rowBgCol
);
1836 dc
.DrawRectangle(greyDepthX
+1, y
,
1837 textMarginHere
-greyDepthX
, lh
-1);
1840 bool fontChanged
= false;
1842 // Expander button rectangle
1843 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1848 if ( p
->IsCategory() )
1850 // Captions have their cell areas merged as one
1851 dc
.SetFont(m_captionFont
);
1853 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1855 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1857 dc
.SetBrush(rowBgBrush
);
1858 dc
.SetPen(rowBgCol
);
1861 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1863 dc
.SetTextForeground(rowFgCol
);
1866 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1867 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1870 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1871 DrawExpanderButton( dc
, butRect
, p
);
1875 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1877 dc
.SetFont(m_captionFont
);
1883 int nextCellWidth
= state
->m_colWidths
[0] -
1884 (greyDepthX
- m_marginWidth
);
1885 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1886 int textXAdd
= textMarginHere
- greyDepthX
;
1888 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1890 cellRect
.width
= nextCellWidth
- 1;
1892 bool ctrlCell
= false;
1893 int cellRenderFlags
= renderFlags
;
1896 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1897 DrawExpanderButton( dc
, butRect
, p
);
1900 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1902 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1903 dc
.SetBrush(editorBgCol
);
1904 dc
.SetPen(editorBgCol
);
1905 dc
.SetTextForeground(m_colPropFore
);
1906 dc
.DrawRectangle(cellRect
);
1908 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1913 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1915 dc
.SetBrush(rowBgBrush
);
1916 dc
.SetPen(rowBgCol
);
1919 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1921 dc
.SetTextForeground(rowFgCol
);
1925 dc
.SetClippingRegion(cellRect
);
1927 cellRect
.x
+= textXAdd
;
1928 cellRect
.width
-= textXAdd
;
1933 wxPGCellRenderer
* renderer
;
1934 int cmnVal
= p
->GetCommonValue();
1935 if ( cmnVal
== -1 || ci
!= 1 )
1937 renderer
= p
->GetCellRenderer(ci
);
1938 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1943 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1944 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1949 cellX
+= state
->m_colWidths
[ci
];
1950 if ( ci
< (state
->m_colWidths
.size()-1) )
1951 nextCellWidth
= state
->m_colWidths
[ci
+1];
1953 dc
.DestroyClippingRegion(); // Is this really necessary?
1959 dc
.SetFont(normalFont
);
1964 // Refresh editor controls (seems not needed on msw)
1965 // NOTE: This code is mandatory for GTK!
1966 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1967 if ( wasSelectedPainted
)
1970 m_wndEditor
->Refresh();
1972 m_wndEditor2
->Refresh();
1979 // -----------------------------------------------------------------------
1981 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1985 if ( m_width
< 10 || m_height
< 10 ||
1986 !m_pState
->m_properties
->GetChildCount() ||
1988 return wxRect(0,0,0,0);
1993 // Return rect which encloses the given property range
1995 int visTop
= p1
->GetY();
1998 visBottom
= p2
->GetY() + m_lineHeight
;
2000 visBottom
= m_height
+ visTop
;
2002 // If seleced property is inside the range, we'll extend the range to include
2004 wxPGProperty
* selected
= m_selected
;
2007 int selectedY
= selected
->GetY();
2008 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2010 wxWindow
* editor
= GetEditorControl();
2013 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2014 if ( visBottom2
> visBottom
)
2015 visBottom
= visBottom2
;
2020 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2023 // -----------------------------------------------------------------------
2025 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2030 if ( m_pState
->m_itemsAdded
)
2031 PrepareAfterItemsAdded();
2033 wxRect r
= GetPropertyRect(p1
, p2
);
2036 m_canvas
->RefreshRect(r
);
2040 // -----------------------------------------------------------------------
2042 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2044 if ( p
== m_selected
)
2045 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2047 DrawItemAndChildren(p
);
2050 // -----------------------------------------------------------------------
2052 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2057 // Draw item, children, and parent too, if it is not category
2058 wxPGProperty
* parent
= p
->GetParent();
2061 !parent
->IsCategory() &&
2062 parent
->GetParent() )
2065 parent
= parent
->GetParent();
2068 DrawItemAndChildren(p
);
2071 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2073 wxCHECK_RET( p
, wxT("invalid property id") );
2075 // Do not draw if in non-visible page
2076 if ( p
->GetParentState() != m_pState
)
2079 // do not draw a single item if multiple pending
2080 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2083 // Update child control.
2084 if ( m_selected
&& m_selected
->GetParent() == p
)
2087 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2089 DrawItems(p
, lastDrawn
);
2092 // -----------------------------------------------------------------------
2094 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2095 const wxRect
*rect
)
2097 PrepareAfterItemsAdded();
2099 wxWindow::Refresh(false);
2101 // TODO: Coordinate translation
2102 m_canvas
->Refresh(false, rect
);
2104 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2105 // I think this really helps only GTK+1.2
2106 if ( m_wndEditor
) m_wndEditor
->Refresh();
2107 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2111 // -----------------------------------------------------------------------
2112 // wxPropertyGrid global operations
2113 // -----------------------------------------------------------------------
2115 void wxPropertyGrid::Clear()
2117 m_pState
->DoClear();
2123 RecalculateVirtualSize();
2125 // Need to clear some area at the end
2127 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2130 // -----------------------------------------------------------------------
2132 bool wxPropertyGrid::EnableCategories( bool enable
)
2134 ClearSelection(false);
2139 // Enable categories
2142 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2147 // Disable categories
2149 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2152 if ( !m_pState
->EnableCategories(enable
) )
2157 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2159 m_pState
->m_itemsAdded
= 1; // force
2160 PrepareAfterItemsAdded();
2164 m_pState
->m_itemsAdded
= 1;
2166 // No need for RecalculateVirtualSize() here - it is already called in
2167 // wxPropertyGridPageState method above.
2174 // -----------------------------------------------------------------------
2176 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2178 wxASSERT( pNewState
);
2179 wxASSERT( pNewState
->GetGrid() );
2181 if ( pNewState
== m_pState
)
2184 wxPGProperty
* oldSelection
= m_selected
;
2186 ClearSelection(false);
2188 m_pState
->m_selected
= oldSelection
;
2190 bool orig_mode
= m_pState
->IsInNonCatMode();
2191 bool new_state_mode
= pNewState
->IsInNonCatMode();
2193 m_pState
= pNewState
;
2196 int pgWidth
= GetClientSize().x
;
2197 if ( HasVirtualWidth() )
2199 int minWidth
= pgWidth
;
2200 if ( pNewState
->m_width
< minWidth
)
2202 pNewState
->m_width
= minWidth
;
2203 pNewState
->CheckColumnWidths();
2209 // Just in case, fully re-center splitter
2210 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2211 pNewState
->m_fSplitterX
= -1.0;
2213 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2218 // If necessary, convert state to correct mode.
2219 if ( orig_mode
!= new_state_mode
)
2221 // This should refresh as well.
2222 EnableCategories( orig_mode
?false:true );
2224 else if ( !m_frozen
)
2226 // Refresh, if not frozen.
2227 m_pState
->PrepareAfterItemsAdded();
2230 if ( m_pState
->m_selected
)
2231 DoSelectProperty( m_pState
->m_selected
);
2233 RecalculateVirtualSize(0);
2237 m_pState
->m_itemsAdded
= 1;
2240 // -----------------------------------------------------------------------
2242 // Call to SetSplitterPosition will always disable splitter auto-centering
2243 // if parent window is shown.
2244 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2246 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2249 wxPropertyGridPageState
* state
= m_pState
;
2251 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2256 CorrectEditorWidgetSizeX();
2262 // -----------------------------------------------------------------------
2264 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2266 SetSplitterPosition( m_width
/2, true );
2267 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2268 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2271 // -----------------------------------------------------------------------
2272 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2273 // -----------------------------------------------------------------------
2275 // Returns nearest paint visible property (such that will be painted unless
2276 // window is scrolled or resized). If given property is paint visible, then
2277 // it itself will be returned
2278 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2280 int vx
,vy1
;// Top left corner of client
2281 GetViewStart(&vx
,&vy1
);
2282 vy1
*= wxPG_PIXELS_PER_UNIT
;
2284 int vy2
= vy1
+ m_height
;
2285 int propY
= p
->GetY2(m_lineHeight
);
2287 if ( (propY
+ m_lineHeight
) < vy1
)
2290 return DoGetItemAtY( vy1
);
2292 else if ( propY
> vy2
)
2295 return DoGetItemAtY( vy2
);
2298 // Itself paint visible
2303 // -----------------------------------------------------------------------
2304 // Methods related to change in value, value modification and sending events
2305 // -----------------------------------------------------------------------
2307 // commits any changes in editor of selected property
2308 // return true if validation did not fail
2309 // flags are same as with DoSelectProperty
2310 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2312 // Committing already?
2313 if ( m_inCommitChangesFromEditor
)
2316 // Don't do this if already processing editor event. It might
2317 // induce recursive dialogs and crap like that.
2318 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2320 if ( m_inDoPropertyChanged
)
2327 IsEditorsValueModified() &&
2328 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2331 m_inCommitChangesFromEditor
= 1;
2333 wxVariant
variant(m_selected
->GetValueRef());
2334 bool valueIsPending
= false;
2336 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2337 // due to another window getting focus
2338 wxWindow
* oldFocus
= m_curFocused
;
2340 bool validationFailure
= false;
2341 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2343 m_chgInfo_changedProperty
= NULL
;
2345 // If truly modified, schedule value as pending.
2346 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2348 if ( DoEditorValidate() &&
2349 PerformValidation(m_selected
, variant
) )
2351 valueIsPending
= true;
2355 validationFailure
= true;
2360 EditorsValueWasNotModified();
2365 m_inCommitChangesFromEditor
= 0;
2367 if ( validationFailure
&& !forceSuccess
)
2371 oldFocus
->SetFocus();
2372 m_curFocused
= oldFocus
;
2375 res
= OnValidationFailure(m_selected
, variant
);
2377 // Now prevent further validation failure messages
2380 EditorsValueWasNotModified();
2381 OnValidationFailureReset(m_selected
);
2384 else if ( valueIsPending
)
2386 DoPropertyChanged( m_selected
, flags
);
2387 EditorsValueWasNotModified();
2396 // -----------------------------------------------------------------------
2398 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2402 // Runs all validation functionality.
2403 // Returns true if value passes all tests.
2406 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2408 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2410 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2415 // Adapt list to child values, if necessary
2416 wxVariant listValue
= pendingValue
;
2417 wxVariant
* pPendingValue
= &pendingValue
;
2418 wxVariant
* pList
= NULL
;
2420 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2421 // string value, then we need treat as it was changed instead
2422 // (or, in addition, as is the case with composite string parent).
2423 // This includes creating list variant for child values.
2425 wxPGProperty
* pwc
= p
->GetParent();
2426 wxPGProperty
* changedProperty
= p
;
2427 wxPGProperty
* baseChangedProperty
= changedProperty
;
2428 wxVariant bcpPendingList
;
2430 listValue
= pendingValue
;
2431 listValue
.SetName(p
->GetBaseName());
2434 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2436 wxVariantList tempList
;
2437 wxVariant
lv(tempList
, pwc
->GetBaseName());
2438 lv
.Append(listValue
);
2440 pPendingValue
= &listValue
;
2442 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2444 baseChangedProperty
= pwc
;
2445 bcpPendingList
= lv
;
2448 changedProperty
= pwc
;
2449 pwc
= pwc
->GetParent();
2453 wxPGProperty
* evtChangingProperty
= changedProperty
;
2455 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2457 value
= *pPendingValue
;
2461 // Convert list to child values
2462 pList
= pPendingValue
;
2463 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2466 wxVariant evtChangingValue
= value
;
2468 if ( flags
& SendEvtChanging
)
2470 // FIXME: After proper ValueToString()s added, remove
2471 // this. It is just a temporary fix, as evt_changing
2472 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2473 // (unless it is selected, and textctrl editor is open).
2474 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2476 evtChangingProperty
= baseChangedProperty
;
2477 if ( evtChangingProperty
!= p
)
2479 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2483 evtChangingValue
= pendingValue
;
2487 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2489 if ( changedProperty
== m_selected
)
2491 wxWindow
* editor
= GetEditorControl();
2492 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2493 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2497 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2502 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2503 m_chgInfo_changedProperty
= changedProperty
;
2504 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2505 m_chgInfo_pendingValue
= value
;
2508 m_chgInfo_valueList
= *pList
;
2510 m_chgInfo_valueList
.MakeNull();
2512 // If changedProperty is not property which value was edited,
2513 // then call wxPGProperty::ValidateValue() for that as well.
2514 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2516 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2520 if ( flags
& SendEvtChanging
)
2522 // SendEvent returns true if event was vetoed
2523 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2527 if ( flags
& IsStandaloneValidation
)
2529 // If called in 'generic' context, we need to reset
2530 // m_chgInfo_changedProperty and write back translated value.
2531 m_chgInfo_changedProperty
= NULL
;
2532 pendingValue
= value
;
2538 // -----------------------------------------------------------------------
2540 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2542 if ( !msg
.length() )
2546 if ( !wxPGGlobalVars
->m_offline
)
2548 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2551 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2554 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2557 pStatusBar
->SetStatusText(msg
);
2565 ::wxMessageBox(msg
, _T("Property Error"));
2568 // -----------------------------------------------------------------------
2570 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2571 wxVariant
& invalidValue
)
2573 wxWindow
* editor
= GetEditorControl();
2575 // First call property's handler
2576 property
->OnValidationFailure(invalidValue
);
2578 bool res
= DoOnValidationFailure(property
, invalidValue
);
2581 // For non-wxTextCtrl editors, we do need to revert the value
2582 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2583 property
== m_selected
)
2585 property
->GetEditorClass()->UpdateControl(property
, editor
);
2588 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2593 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2595 int vfb
= m_validationInfo
.m_failureBehavior
;
2597 if ( vfb
& wxPG_VFB_BEEP
)
2600 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2601 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2603 unsigned int colCount
= m_pState
->GetColumnCount();
2605 // We need backup marked property's cells
2606 m_propCellsBackup
= property
->m_cells
;
2608 wxColour vfbFg
= *wxWHITE
;
2609 wxColour vfbBg
= *wxRED
;
2611 property
->EnsureCells(colCount
);
2613 for ( unsigned int i
=0; i
<colCount
; i
++ )
2615 wxPGCell
& cell
= property
->m_cells
[i
];
2616 cell
.SetFgCol(vfbFg
);
2617 cell
.SetBgCol(vfbBg
);
2620 DrawItemAndChildren(property
);
2622 if ( property
== m_selected
)
2624 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2626 wxWindow
* editor
= GetEditorControl();
2629 editor
->SetForegroundColour(vfbFg
);
2630 editor
->SetBackgroundColour(vfbBg
);
2635 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2637 wxString msg
= m_validationInfo
.m_failureMessage
;
2639 if ( !msg
.length() )
2640 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2642 DoShowPropertyError(property
, msg
);
2645 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2648 // -----------------------------------------------------------------------
2650 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2652 int vfb
= m_validationInfo
.m_failureBehavior
;
2654 if ( vfb
& wxPG_VFB_MARK_CELL
)
2657 property
->m_cells
= m_propCellsBackup
;
2659 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2661 if ( property
== m_selected
&& GetEditorControl() )
2663 // Calling this will recreate the control, thus resetting its colour
2664 RefreshProperty(property
);
2668 DrawItemAndChildren(property
);
2673 // -----------------------------------------------------------------------
2675 // flags are same as with DoSelectProperty
2676 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2678 if ( m_inDoPropertyChanged
)
2681 wxWindow
* editor
= GetEditorControl();
2683 m_pState
->m_anyModified
= 1;
2685 m_inDoPropertyChanged
= 1;
2687 // Maybe need to update control
2688 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2690 // These values were calculated in PerformValidation()
2691 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2692 wxVariant value
= m_chgInfo_pendingValue
;
2694 wxPGProperty
* topPaintedProperty
= changedProperty
;
2696 while ( !topPaintedProperty
->IsCategory() &&
2697 !topPaintedProperty
->IsRoot() )
2699 topPaintedProperty
= topPaintedProperty
->GetParent();
2702 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2704 // Set as Modified (not if dragging just began)
2705 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2707 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2708 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2711 SetCurControlBoldFont();
2717 // Propagate updates to parent(s)
2719 wxPGProperty
* prevPwc
= NULL
;
2721 while ( prevPwc
!= topPaintedProperty
)
2723 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2725 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2728 SetCurControlBoldFont();
2732 pwc
= pwc
->GetParent();
2735 // Draw the actual property
2736 DrawItemAndChildren( topPaintedProperty
);
2739 // If value was set by wxPGProperty::OnEvent, then update the editor
2741 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2747 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2748 if ( m_wndEditor
) m_wndEditor
->Refresh();
2749 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2754 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2756 // If top parent has composite string value, then send to child parents,
2757 // starting from baseChangedProperty.
2758 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2760 pwc
= m_chgInfo_baseChangedProperty
;
2762 while ( pwc
!= changedProperty
)
2764 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2765 pwc
= pwc
->GetParent();
2769 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2771 m_inDoPropertyChanged
= 0;
2776 // -----------------------------------------------------------------------
2778 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2780 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2782 m_chgInfo_changedProperty
= NULL
;
2784 if ( PerformValidation(p
, newValue
) )
2786 DoPropertyChanged(p
);
2791 OnValidationFailure(p
, newValue
);
2797 // -----------------------------------------------------------------------
2799 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2801 wxPGProperty
* prop
= GetSelectedProperty();
2804 return wxNullVariant
;
2806 wxTextCtrl
* tc
= GetEditorTextCtrl();
2807 wxVariant value
= prop
->GetValue();
2809 if ( !tc
|| !IsEditorsValueModified() )
2812 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2815 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2816 return prop
->GetValue();
2821 // -----------------------------------------------------------------------
2823 // Runs wxValidator for the selected property
2824 bool wxPropertyGrid::DoEditorValidate()
2829 // -----------------------------------------------------------------------
2831 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2833 wxPGProperty
* selected
= m_selected
;
2835 // Somehow, event is handled after property has been deselected.
2836 // Possibly, but very rare.
2840 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2843 wxVariant
pendingValue(selected
->GetValueRef());
2844 wxWindow
* wnd
= GetEditorControl();
2846 bool wasUnspecified
= selected
->IsValueUnspecified();
2847 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2849 bool valueIsPending
= false;
2851 m_chgInfo_changedProperty
= NULL
;
2853 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2856 // Filter out excess wxTextCtrl modified events
2857 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2859 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2861 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2863 wxString newTcValue
= tc
->GetValue();
2864 if ( m_prevTcValue
== newTcValue
)
2867 m_prevTcValue
= newTcValue
;
2870 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2872 bool validationFailure
= false;
2873 bool buttonWasHandled
= false;
2876 // Try common button handling
2877 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2879 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2883 buttonWasHandled
= true;
2884 // Store as res2, as previously (and still currently alternatively)
2885 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2886 // in wxPGProperty::OnEvent().
2887 adapter
->ShowDialog( this, selected
);
2892 if ( !buttonWasHandled
)
2896 // First call editor class' event handler.
2897 const wxPGEditor
* editor
= selected
->GetEditorClass();
2899 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2901 // If changes, validate them
2902 if ( DoEditorValidate() )
2904 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
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, wnd
, 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 cust_img_space
= 0;
2982 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2983 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2985 // TODO: If custom image detection changes from current, change this.
2986 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
2988 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2989 int imwid
= p
->OnMeasureImage().x
;
2990 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
2991 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
2996 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
2998 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3003 // -----------------------------------------------------------------------
3005 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3007 wxSize sz
= GetImageSize(p
, item
);
3008 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3009 wxPG_CUSTOM_IMAGE_SPACINGY
,
3014 // return size of custom paint image
3015 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3017 // If called with NULL property, then return default image
3018 // size for properties that use image.
3020 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3022 wxSize cis
= p
->OnMeasureImage(item
);
3024 int choiceCount
= p
->m_choices
.GetCount();
3025 int comVals
= p
->GetDisplayedCommonValueCount();
3026 if ( item
>= choiceCount
&& comVals
> 0 )
3028 unsigned int cvi
= item
-choiceCount
;
3029 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3031 else if ( item
>= 0 && choiceCount
== 0 )
3032 return wxSize(0, 0);
3037 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3042 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3049 // -----------------------------------------------------------------------
3051 // takes scrolling into account
3052 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3055 GetViewStart(&vx
,&vy
);
3056 vy
*=wxPG_PIXELS_PER_UNIT
;
3057 vx
*=wxPG_PIXELS_PER_UNIT
;
3060 ClientToScreen( px
, py
);
3063 // -----------------------------------------------------------------------
3065 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3068 GetViewStart(&pt2
.x
,&pt2
.y
);
3069 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3070 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3074 return m_pState
->HitTest(pt2
);
3077 // -----------------------------------------------------------------------
3079 // custom set cursor
3080 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3082 if ( type
== m_curcursor
&& !override
) return;
3084 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3086 if ( type
== wxCURSOR_SIZEWE
)
3087 cursor
= m_cursorSizeWE
;
3089 m_canvas
->SetCursor( *cursor
);
3094 // -----------------------------------------------------------------------
3095 // wxPropertyGrid property selection, editor creation
3096 // -----------------------------------------------------------------------
3099 // This class forwards events from property editor controls to wxPropertyGrid.
3100 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3103 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3104 : wxEvtHandler(), m_propGrid(propGrid
)
3108 virtual ~wxPropertyGridEditorEventForwarder()
3113 bool ProcessEvent( wxEvent
& event
)
3118 m_propGrid
->HandleCustomEditorEvent(event
);
3120 return wxEvtHandler::ProcessEvent(event
);
3123 wxPropertyGrid
* m_propGrid
;
3126 // Setups event handling for child control
3127 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3129 wxWindowID id
= argWnd
->GetId();
3131 if ( argWnd
== m_wndEditor
)
3133 argWnd
->Connect(id
, wxEVT_MOTION
,
3134 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3136 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3137 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3139 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3140 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3142 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3143 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3145 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3146 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3148 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3149 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3153 wxPropertyGridEditorEventForwarder
* forwarder
;
3154 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3155 argWnd
->PushEventHandler(forwarder
);
3157 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3158 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3162 void wxPropertyGrid::FreeEditors()
3165 // Return focus back to canvas from children (this is required at least for
3166 // GTK+, which, unlike Windows, clears focus when control is destroyed
3167 // instead of moving it to closest parent).
3168 wxWindow
* focus
= wxWindow::FindFocus();
3171 wxWindow
* parent
= focus
->GetParent();
3174 if ( parent
== m_canvas
)
3179 parent
= parent
->GetParent();
3183 // Do not free editors immediately if processing events
3186 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3187 m_wndEditor2
->Hide();
3188 wxPendingDelete
.Append( handler
);
3189 wxPendingDelete
.Append( m_wndEditor2
);
3190 m_wndEditor2
= NULL
;
3195 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3196 m_wndEditor
->Hide();
3197 wxPendingDelete
.Append( handler
);
3198 wxPendingDelete
.Append( m_wndEditor
);
3203 // Call with NULL to de-select property
3204 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3208 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3209 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3211 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3214 if ( m_inDoSelectProperty
)
3217 m_inDoSelectProperty
= 1;
3219 wxPGProperty
* prev
= m_selected
;
3223 m_inDoSelectProperty
= 0;
3229 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3231 wxPrintf( "None selected\n" );
3234 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3236 wxPrintf( "P = NULL\n" );
3239 // If we are frozen, then just set the values.
3242 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3243 m_editorFocused
= 0;
3246 m_pState
->m_selected
= p
;
3248 // If frozen, always free controls. But don't worry, as Thaw will
3249 // recall SelectProperty to recreate them.
3252 // Prevent any further selection measures in this call
3258 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3260 // Only set focus if not deselecting
3263 if ( flags
& wxPG_SEL_FOCUS
)
3267 m_wndEditor
->SetFocus();
3268 m_editorFocused
= 1;
3277 m_inDoSelectProperty
= 0;
3282 // First, deactivate previous
3286 OnValidationFailureReset(m_selected
);
3288 // Must double-check if this is an selected in case of forceswitch
3291 if ( !CommitChangesFromEditor(flags
) )
3293 // Validation has failed, so we can't exit the previous editor
3294 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3295 // _("Invalid Value"),wxOK|wxICON_ERROR);
3296 m_inDoSelectProperty
= 0;
3305 m_pState
->m_selected
= NULL
;
3307 // We need to always fully refresh the grid here
3310 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3311 EditorsValueWasNotModified();
3314 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3317 // Then, activate the one given.
3320 int propY
= p
->GetY2(m_lineHeight
);
3322 int splitterX
= GetSplitterPosition();
3323 m_editorFocused
= 0;
3325 m_pState
->m_selected
= p
;
3326 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3328 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3330 wxASSERT( m_wndEditor
== NULL
);
3333 // Only create editor for non-disabled non-caption
3334 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3336 // do this for non-caption items
3340 // Do we need to paint the custom image, if any?
3341 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3342 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3343 !p
->GetEditorClass()->CanContainCustomImage()
3345 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3347 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3348 wxPoint goodPos
= grect
.GetPosition();
3349 #if wxPG_CREATE_CONTROLS_HIDDEN
3350 int coord_adjust
= m_height
- goodPos
.y
;
3351 goodPos
.y
+= coord_adjust
;
3354 const wxPGEditor
* editor
= p
->GetEditorClass();
3355 wxCHECK_MSG(editor
, false,
3356 wxT("NULL editor class not allowed"));
3358 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3360 wxPGWindowList wndList
= editor
->CreateControls(this,
3365 m_wndEditor
= wndList
.m_primary
;
3366 m_wndEditor2
= wndList
.m_secondary
;
3367 wxWindow
* primaryCtrl
= GetEditorControl();
3370 // Essentially, primaryCtrl == m_wndEditor
3373 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3374 // value is drawn as normal, and m_wndEditor2 is assumed
3375 // to be a right-aligned button that triggers a separate editorCtrl
3380 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3381 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3383 // Set validator, if any
3384 #if wxUSE_VALIDATORS
3385 wxValidator
* validator
= p
->GetValidator();
3387 primaryCtrl
->SetValidator(*validator
);
3390 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3391 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3393 // If it has modified status, use bold font
3394 // (must be done before capturing m_ctrlXAdjust)
3395 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3396 SetCurControlBoldFont();
3399 // Fix TextCtrl indentation
3400 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3401 wxTextCtrl
* tc
= NULL
;
3402 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3403 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3405 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3407 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3410 // Store x relative to splitter (we'll need it).
3411 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3413 // Check if background clear is not necessary
3414 wxPoint pos
= m_wndEditor
->GetPosition();
3415 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3417 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3420 m_wndEditor
->SetSizeHints(3, 3);
3422 #if wxPG_CREATE_CONTROLS_HIDDEN
3423 m_wndEditor
->Show(false);
3424 m_wndEditor
->Freeze();
3426 goodPos
= m_wndEditor
->GetPosition();
3427 goodPos
.y
-= coord_adjust
;
3428 m_wndEditor
->Move( goodPos
);
3431 SetupChildEventHandling(primaryCtrl
);
3433 // Focus and select all (wxTextCtrl, wxComboBox etc)
3434 if ( flags
& wxPG_SEL_FOCUS
)
3436 primaryCtrl
->SetFocus();
3438 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3444 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3445 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3447 // Get proper id for wndSecondary
3448 m_wndSecId
= m_wndEditor2
->GetId();
3449 wxWindowList children
= m_wndEditor2
->GetChildren();
3450 wxWindowList::iterator node
= children
.begin();
3451 if ( node
!= children
.end() )
3452 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3454 m_wndEditor2
->SetSizeHints(3,3);
3456 #if wxPG_CREATE_CONTROLS_HIDDEN
3457 wxRect sec_rect
= m_wndEditor2
->GetRect();
3458 sec_rect
.y
-= coord_adjust
;
3460 // Fine tuning required to fix "oversized"
3461 // button disappearance bug.
3462 if ( sec_rect
.y
< 0 )
3464 sec_rect
.height
+= sec_rect
.y
;
3467 m_wndEditor2
->SetSize( sec_rect
);
3469 m_wndEditor2
->Show();
3471 SetupChildEventHandling(m_wndEditor2
);
3473 // If no primary editor, focus to button to allow
3474 // it to interprete ENTER etc.
3475 // NOTE: Due to problems focusing away from it, this
3476 // has been disabled.
3478 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3479 m_wndEditor2->SetFocus();
3483 if ( flags
& wxPG_SEL_FOCUS
)
3484 m_editorFocused
= 1;
3489 // Make sure focus is in grid canvas (important for wxGTK, at least)
3493 EditorsValueWasNotModified();
3495 // If it's inside collapsed section, expand parent, scroll, etc.
3496 // Also, if it was partially visible, scroll it into view.
3497 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3502 #if wxPG_CREATE_CONTROLS_HIDDEN
3503 m_wndEditor
->Thaw();
3505 m_wndEditor
->Show(true);
3512 // Make sure focus is in grid canvas
3516 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3522 // Show help text in status bar.
3523 // (if found and grid not embedded in manager with help box and
3524 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3527 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3529 wxStatusBar
* statusbar
= NULL
;
3530 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3532 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3534 statusbar
= frame
->GetStatusBar();
3539 const wxString
* pHelpString
= (const wxString
*) NULL
;
3543 pHelpString
= &p
->GetHelpString();
3544 if ( pHelpString
->length() )
3546 // Set help box text.
3547 statusbar
->SetStatusText( *pHelpString
);
3548 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3552 if ( (!pHelpString
|| !pHelpString
->length()) &&
3553 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3555 // Clear help box - but only if it was written
3556 // by us at previous time.
3557 statusbar
->SetStatusText( m_emptyString
);
3558 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3564 m_inDoSelectProperty
= 0;
3566 // call wx event handler (here so that it also occurs on deselection)
3567 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3572 // -----------------------------------------------------------------------
3574 bool wxPropertyGrid::UnfocusEditor()
3576 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3579 if ( !CommitChangesFromEditor(0) )
3583 DrawItem(m_selected
);
3588 // -----------------------------------------------------------------------
3590 void wxPropertyGrid::RefreshEditor()
3592 wxPGProperty
* p
= m_selected
;
3596 wxWindow
* wnd
= GetEditorControl();
3600 // Set editor font boldness - must do this before
3601 // calling UpdateControl().
3602 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3604 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3605 wnd
->SetFont(GetCaptionFont());
3607 wnd
->SetFont(GetFont());
3610 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3612 editorClass
->UpdateControl(p
, wnd
);
3614 if ( p
->IsValueUnspecified() )
3615 editorClass
->SetValueToUnspecified(p
, wnd
);
3618 // -----------------------------------------------------------------------
3620 // This method is not inline because it called dozens of times
3621 // (i.e. two-arg function calls create smaller code size).
3622 bool wxPropertyGrid::DoClearSelection()
3624 return DoSelectProperty(NULL
);
3627 // -----------------------------------------------------------------------
3628 // wxPropertyGrid expand/collapse state
3629 // -----------------------------------------------------------------------
3631 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3633 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3635 // If active editor was inside collapsed section, then disable it
3636 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3638 ClearSelection(false);
3641 // Store dont-center-splitter flag 'cause we need to temporarily set it
3642 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3643 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3645 bool res
= m_pState
->DoCollapse(pwc
);
3650 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3652 RecalculateVirtualSize();
3654 // Redraw etc. only if collapsed was visible.
3655 if (pwc
->IsVisible() &&
3657 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3659 // When item is collapsed so that scrollbar would move,
3660 // graphics mess is about (unless we redraw everything).
3665 // Clear dont-center-splitter flag if it wasn't set
3666 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3671 // -----------------------------------------------------------------------
3673 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3675 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3677 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3679 // Store dont-center-splitter flag 'cause we need to temporarily set it
3680 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3681 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3683 bool res
= m_pState
->DoExpand(pwc
);
3688 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3690 RecalculateVirtualSize();
3692 // Redraw etc. only if expanded was visible.
3693 if ( pwc
->IsVisible() && !m_frozen
&&
3694 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3698 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3701 DrawItems(pwc
, NULL
);
3706 // Clear dont-center-splitter flag if it wasn't set
3707 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3712 // -----------------------------------------------------------------------
3714 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3717 return m_pState
->DoHideProperty(p
, hide
, flags
);
3720 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3723 ClearSelection(false);
3726 m_pState
->DoHideProperty(p
, hide
, flags
);
3728 RecalculateVirtualSize();
3735 // -----------------------------------------------------------------------
3736 // wxPropertyGrid size related methods
3737 // -----------------------------------------------------------------------
3739 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3741 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3745 // If virtual height was changed, then recalculate editor control position(s)
3746 if ( m_pState
->m_vhCalcPending
)
3747 CorrectEditorWidgetPosY();
3749 m_pState
->EnsureVirtualHeight();
3752 int by1
= m_pState
->GetVirtualHeight();
3753 int by2
= m_pState
->GetActualVirtualHeight();
3756 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3757 wxFAIL_MSG(s
.c_str());
3762 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3764 int x
= m_pState
->m_width
;
3765 int y
= m_pState
->m_virtualHeight
;
3768 GetClientSize(&width
,&height
);
3770 // Now adjust virtual size.
3771 SetVirtualSize(x
, y
);
3777 // Adjust scrollbars
3778 if ( HasVirtualWidth() )
3780 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3781 xPos
= GetScrollPos( wxHORIZONTAL
);
3784 if ( forceXPos
!= -1 )
3787 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3790 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3791 int yPos
= GetScrollPos( wxVERTICAL
);
3793 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3794 xAmount
, yAmount
, xPos
, yPos
, true );
3796 // Must re-get size now
3797 GetClientSize(&width
,&height
);
3799 if ( !HasVirtualWidth() )
3801 m_pState
->SetVirtualWidth(width
);
3808 m_canvas
->SetSize( x
, y
);
3810 m_pState
->CheckColumnWidths();
3813 CorrectEditorWidgetSizeX();
3815 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3818 // -----------------------------------------------------------------------
3820 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3822 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3826 GetClientSize(&width
,&height
);
3831 #if wxPG_DOUBLE_BUFFER
3832 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3834 int dblh
= (m_lineHeight
*2);
3835 if ( !m_doubleBuffer
)
3837 // Create double buffer bitmap to draw on, if none
3838 int w
= (width
>250)?width
:250;
3839 int h
= height
+ dblh
;
3841 m_doubleBuffer
= new wxBitmap( w
, h
);
3845 int w
= m_doubleBuffer
->GetWidth();
3846 int h
= m_doubleBuffer
->GetHeight();
3848 // Double buffer must be large enough
3849 if ( w
< width
|| h
< (height
+dblh
) )
3851 if ( w
< width
) w
= width
;
3852 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3853 delete m_doubleBuffer
;
3854 m_doubleBuffer
= new wxBitmap( w
, h
);
3861 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3862 m_ncWidth
= event
.GetSize().x
;
3866 if ( m_pState
->m_itemsAdded
)
3867 PrepareAfterItemsAdded();
3869 // Without this, virtual size (atleast under wxGTK) will be skewed
3870 RecalculateVirtualSize();
3876 // -----------------------------------------------------------------------
3878 void wxPropertyGrid::SetVirtualWidth( int width
)
3882 // Disable virtual width
3883 width
= GetClientSize().x
;
3884 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3888 // Enable virtual width
3889 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3891 m_pState
->SetVirtualWidth( width
);
3894 void wxPropertyGrid::SetFocusOnCanvas()
3896 m_canvas
->SetFocusIgnoringChildren();
3897 m_editorFocused
= 0;
3900 // -----------------------------------------------------------------------
3901 // wxPropertyGrid mouse event handling
3902 // -----------------------------------------------------------------------
3904 // selFlags uses same values DoSelectProperty's flags
3905 // Returns true if event was vetoed.
3906 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3908 // Send property grid event of specific type and with specific property
3909 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3910 evt
.SetPropertyGrid(this);
3911 evt
.SetEventObject(m_eventObject
);
3915 evt
.SetCanVeto(true);
3916 evt
.SetupValidationInfo();
3917 m_validationInfo
.m_pValue
= pValue
;
3919 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3921 evtHandler
->ProcessEvent(evt
);
3923 return evt
.WasVetoed();
3926 // -----------------------------------------------------------------------
3928 // Return false if should be skipped
3929 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3933 // Need to set focus?
3934 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3939 wxPropertyGridPageState
* state
= m_pState
;
3941 int splitterHitOffset
;
3942 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3944 wxPGProperty
* p
= DoGetItemAtY(y
);
3948 int depth
= (int)p
->GetDepth() - 1;
3950 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3952 if ( x
>= marginEnds
)
3956 if ( p
->IsCategory() )
3958 // This is category.
3959 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3961 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3963 // Expand, collapse, activate etc. if click on text or left of splitter.
3966 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3971 if ( !DoSelectProperty( p
) )
3974 // On double-click, expand/collapse.
3975 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3977 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3978 else DoExpand( p
, true );
3982 else if ( splitterHit
== -1 )
3985 unsigned int selFlag
= 0;
3986 if ( columnHit
== 1 )
3988 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3989 selFlag
= wxPG_SEL_FOCUS
;
3991 if ( !DoSelectProperty( p
, selFlag
) )
3994 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3996 if ( p
->GetChildCount() && !p
->IsCategory() )
3997 // On double-click, expand/collapse.
3998 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4000 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4001 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4002 else DoExpand( p
, true );
4009 // click on splitter
4010 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4012 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4014 // Double-clicking the splitter causes auto-centering
4015 CenterSplitter( true );
4017 else if ( m_dragStatus
== 0 )
4020 // Begin draggin the splitter
4024 // Changes must be committed here or the
4025 // value won't be drawn correctly
4026 if ( !CommitChangesFromEditor() )
4029 m_wndEditor
->Show ( false );
4032 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4034 m_canvas
->CaptureMouse();
4035 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4039 m_draggedSplitter
= splitterHit
;
4040 m_dragOffset
= splitterHitOffset
;
4042 wxClientDC
dc(m_canvas
);
4044 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4045 // Fixes button disappearance bug
4047 m_wndEditor2
->Show ( false );
4050 m_startingSplitterX
= x
- splitterHitOffset
;
4058 if ( p
->GetChildCount() )
4060 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4062 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4064 int y2
= y
% m_lineHeight
;
4065 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4067 // On click on expander button, expand/collapse
4068 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4069 DoCollapse( p
, true );
4071 DoExpand( p
, true );
4080 // -----------------------------------------------------------------------
4082 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4083 wxMouseEvent
& WXUNUSED(event
) )
4087 // Select property here as well
4088 wxPGProperty
* p
= m_propHover
;
4089 if ( p
!= m_selected
)
4090 DoSelectProperty( p
);
4092 // Send right click event.
4093 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4100 // -----------------------------------------------------------------------
4102 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4103 wxMouseEvent
& WXUNUSED(event
) )
4107 // Select property here as well
4108 wxPGProperty
* p
= m_propHover
;
4110 if ( p
!= m_selected
)
4111 DoSelectProperty( p
);
4113 // Send double-click event.
4114 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4121 // -----------------------------------------------------------------------
4123 #if wxPG_SUPPORT_TOOLTIPS
4125 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4127 if ( tipString
.length() )
4129 m_canvas
->SetToolTip(tipString
);
4133 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4134 m_canvas
->SetToolTip( m_emptyString
);
4136 m_canvas
->SetToolTip( NULL
);
4141 #endif // #if wxPG_SUPPORT_TOOLTIPS
4143 // -----------------------------------------------------------------------
4145 // Return false if should be skipped
4146 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4148 // Safety check (needed because mouse capturing may
4149 // otherwise freeze the control)
4150 if ( m_dragStatus
> 0 && !event
.Dragging() )
4152 HandleMouseUp(x
,y
,event
);
4155 wxPropertyGridPageState
* state
= m_pState
;
4157 int splitterHitOffset
;
4158 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4159 int splitterX
= x
- splitterHitOffset
;
4161 if ( m_dragStatus
> 0 )
4163 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4164 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4167 int newSplitterX
= x
- m_dragOffset
;
4168 int splitterX
= x
- splitterHitOffset
;
4170 // Splitter redraw required?
4171 if ( newSplitterX
!= splitterX
)
4174 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4175 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4176 state
->m_fSplitterX
= (float) newSplitterX
;
4179 CorrectEditorWidgetSizeX();
4193 int ih
= m_lineHeight
;
4196 #if wxPG_SUPPORT_TOOLTIPS
4197 wxPGProperty
* prevHover
= m_propHover
;
4198 unsigned char prevSide
= m_mouseSide
;
4200 int curPropHoverY
= y
- (y
% ih
);
4202 // On which item it hovers
4205 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4208 // Mouse moves on another property
4210 m_propHover
= DoGetItemAtY(y
);
4211 m_propHoverY
= curPropHoverY
;
4214 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4217 #if wxPG_SUPPORT_TOOLTIPS
4218 // Store which side we are on
4220 if ( columnHit
== 1 )
4222 else if ( columnHit
== 0 )
4226 // If tooltips are enabled, show label or value as a tip
4227 // in case it doesn't otherwise show in full length.
4229 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4231 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4233 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4235 if ( m_propHover
&& !m_propHover
->IsCategory() )
4238 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4240 // Show help string as a tooltip
4241 wxString tipString
= m_propHover
->GetHelpString();
4243 SetToolTip(tipString
);
4247 // Show cropped value string as a tooltip
4251 if ( m_mouseSide
== 1 )
4253 tipString
= m_propHover
->m_label
;
4254 space
= splitterX
-m_marginWidth
-3;
4256 else if ( m_mouseSide
== 2 )
4258 tipString
= m_propHover
->GetDisplayedString();
4260 space
= m_width
- splitterX
;
4261 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4262 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4268 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4271 SetToolTip( tipString
);
4278 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4279 m_canvas
->SetToolTip( m_emptyString
);
4281 m_canvas
->SetToolTip( NULL
);
4292 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4293 m_canvas
->SetToolTip( m_emptyString
);
4295 m_canvas
->SetToolTip( NULL
);
4303 if ( splitterHit
== -1 ||
4305 HasFlag(wxPG_STATIC_SPLITTER
) )
4307 // hovering on something else
4308 if ( m_curcursor
!= wxCURSOR_ARROW
)
4309 CustomSetCursor( wxCURSOR_ARROW
);
4313 // Do not allow splitter cursor on caption items.
4314 // (also not if we were dragging and its started
4315 // outside the splitter region)
4317 if ( !m_propHover
->IsCategory() &&
4321 // hovering on splitter
4323 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4324 // reliably detected.
4325 //if ( m_curcursor != wxCURSOR_SIZEWE )
4326 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4332 // hovering on something else
4333 if ( m_curcursor
!= wxCURSOR_ARROW
)
4334 CustomSetCursor( wxCURSOR_ARROW
);
4341 // -----------------------------------------------------------------------
4343 // Also handles Leaving event
4344 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4345 wxMouseEvent
&WXUNUSED(event
) )
4347 wxPropertyGridPageState
* state
= m_pState
;
4351 int splitterHitOffset
;
4352 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4354 // No event type check - basicly calling this method should
4355 // just stop dragging.
4356 // Left up after dragged?
4357 if ( m_dragStatus
>= 1 )
4360 // End Splitter Dragging
4362 // DO NOT ENABLE FOLLOWING LINE!
4363 // (it is only here as a reminder to not to do it)
4366 // Disable splitter auto-centering
4367 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4369 // This is necessary to return cursor
4370 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4372 m_canvas
->ReleaseMouse();
4373 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4376 // Set back the default cursor, if necessary
4377 if ( splitterHit
== -1 ||
4380 CustomSetCursor( wxCURSOR_ARROW
);
4385 // Control background needs to be cleared
4386 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4387 DrawItem( m_selected
);
4391 m_wndEditor
->Show ( true );
4394 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4395 // Fixes button disappearance bug
4397 m_wndEditor2
->Show ( true );
4400 // This clears the focus.
4401 m_editorFocused
= 0;
4407 // -----------------------------------------------------------------------
4409 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4411 int splitterX
= GetSplitterPosition();
4414 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4418 wxWindow
* wnd
= GetEditorControl();
4420 // Hide popup on clicks
4421 if ( event
.GetEventType() != wxEVT_MOTION
)
4422 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4424 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4430 if ( wnd
== NULL
|| m_dragStatus
||
4432 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4433 ux
>= (r
.x
+r
.width
) ||
4435 event
.m_y
>= (r
.y
+r
.height
)
4445 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4450 // -----------------------------------------------------------------------
4452 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4455 if ( OnMouseCommon( event
, &x
, &y
) )
4457 HandleMouseClick(x
,y
,event
);
4462 // -----------------------------------------------------------------------
4464 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4467 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4468 HandleMouseRightClick(x
,y
,event
);
4472 // -----------------------------------------------------------------------
4474 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4476 // Always run standard mouse-down handler as well
4477 OnMouseClick(event
);
4480 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4481 HandleMouseDoubleClick(x
,y
,event
);
4485 // -----------------------------------------------------------------------
4487 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4490 if ( OnMouseCommon( event
, &x
, &y
) )
4492 HandleMouseMove(x
,y
,event
);
4497 // -----------------------------------------------------------------------
4499 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4501 // Called when mouse moves in the empty space below the properties.
4502 CustomSetCursor( wxCURSOR_ARROW
);
4505 // -----------------------------------------------------------------------
4507 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4510 if ( OnMouseCommon( event
, &x
, &y
) )
4512 HandleMouseUp(x
,y
,event
);
4517 // -----------------------------------------------------------------------
4519 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4521 // This may get called from child control as well, so event's
4522 // mouse position cannot be relied on.
4524 if ( event
.Entering() )
4526 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4528 // TODO: Fix this (detect parent and only do
4529 // cursor trick if it is a manager).
4530 wxASSERT( GetParent() );
4531 GetParent()->SetCursor(wxNullCursor
);
4533 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4536 GetParent()->SetCursor(wxNullCursor
);
4538 else if ( event
.Leaving() )
4540 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4541 m_canvas
->SetCursor( wxNullCursor
);
4543 // Get real cursor position
4544 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4546 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4549 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4551 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4555 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4563 // -----------------------------------------------------------------------
4565 // Common code used by various OnMouseXXXChild methods.
4566 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4568 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4569 wxASSERT( topCtrlWnd
);
4571 event
.GetPosition(&x
,&y
);
4573 int splitterX
= GetSplitterPosition();
4575 wxRect r
= topCtrlWnd
->GetRect();
4576 if ( !m_dragStatus
&&
4577 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4578 y
>= 0 && y
< r
.height \
4581 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4586 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4593 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4596 if ( OnMouseChildCommon(event
,&x
,&y
) )
4598 bool res
= HandleMouseClick(x
,y
,event
);
4599 if ( !res
) event
.Skip();
4603 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4606 wxASSERT( m_wndEditor
);
4607 // These coords may not be exact (about +-2),
4608 // but that should not matter (right click is about item, not position).
4609 wxPoint pt
= m_wndEditor
->GetPosition();
4610 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4611 wxASSERT( m_selected
);
4612 m_propHover
= m_selected
;
4613 bool res
= HandleMouseRightClick(x
,y
,event
);
4614 if ( !res
) event
.Skip();
4617 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4620 if ( OnMouseChildCommon(event
,&x
,&y
) )
4622 bool res
= HandleMouseMove(x
,y
,event
);
4623 if ( !res
) event
.Skip();
4627 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4630 if ( OnMouseChildCommon(event
,&x
,&y
) )
4632 bool res
= HandleMouseUp(x
,y
,event
);
4633 if ( !res
) event
.Skip();
4637 // -----------------------------------------------------------------------
4638 // wxPropertyGrid keyboard event handling
4639 // -----------------------------------------------------------------------
4641 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4643 // Translates wxKeyEvent to wxPG_ACTION_XXX
4645 int keycode
= event
.GetKeyCode();
4646 int modifiers
= event
.GetModifiers();
4648 wxASSERT( !(modifiers
&~(0xFFFF)) );
4650 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4652 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4654 if ( it
== m_actionTriggers
.end() )
4659 int second
= (it
->second
>>16) & 0xFFFF;
4663 return (it
->second
& 0xFFFF);
4666 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4668 wxASSERT( !(modifiers
&~(0xFFFF)) );
4670 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4672 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4674 if ( it
!= m_actionTriggers
.end() )
4676 // This key combination is already used
4678 // Can add secondary?
4679 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4680 wxT("You can only add up to two separate actions per key combination.") );
4682 action
= it
->second
| (action
<<16);
4685 m_actionTriggers
[hashMapKey
] = action
;
4688 void wxPropertyGrid::ClearActionTriggers( int action
)
4690 wxPGHashMapI2I::iterator it
;
4692 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4694 if ( it
->second
== action
)
4696 m_actionTriggers
.erase(it
);
4701 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4704 // Handles key event when editor control is not focused.
4707 wxCHECK2(!m_frozen
, return);
4709 // Travelsal between items, collapsing/expanding, etc.
4710 int keycode
= event
.GetKeyCode();
4711 bool editorFocused
= IsEditorFocused();
4713 if ( keycode
== WXK_TAB
)
4715 wxWindow
* mainControl
;
4717 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4718 mainControl
= GetParent();
4722 if ( !event
.ShiftDown() )
4724 if ( !editorFocused
&& m_wndEditor
)
4726 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4730 // Tab traversal workaround for platforms on which
4731 // wxWindow::Navigate() may navigate into first child
4732 // instead of next sibling. Does not work perfectly
4733 // in every scenario (for instance, when property grid
4734 // is either first or last control).
4735 #if defined(__WXGTK__)
4736 wxWindow
* sibling
= mainControl
->GetNextSibling();
4738 sibling
->SetFocusFromKbd();
4740 Navigate(wxNavigationKeyEvent::IsForward
);
4746 if ( editorFocused
)
4752 #if defined(__WXGTK__)
4753 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4755 sibling
->SetFocusFromKbd();
4757 Navigate(wxNavigationKeyEvent::IsBackward
);
4765 // Ignore Alt and Control when they are down alone
4766 if ( keycode
== WXK_ALT
||
4767 keycode
== WXK_CONTROL
)
4774 int action
= KeyEventToActions(event
, &secondAction
);
4776 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4779 // Esc cancels any changes
4780 if ( IsEditorsValueModified() )
4782 EditorsValueWasNotModified();
4784 // Update the control as well
4785 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4787 m_selected
->GetDisplayedString() );
4790 OnValidationFailureReset(m_selected
);
4796 // Except for TAB and ESC, handle child control events in child control
4799 // Only propagate event if it had modifiers
4800 if ( !event
.HasModifiers() )
4802 event
.StopPropagation();
4808 bool wasHandled
= false;
4813 if ( ButtonTriggerKeyTest(action
, event
) )
4816 wxPGProperty
* p
= m_selected
;
4818 // Travel and expand/collapse
4821 if ( p
->GetChildCount() &&
4822 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4825 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4827 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4830 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4832 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4839 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4843 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4849 if ( selectDir
>= -1 )
4851 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4853 DoSelectProperty(p
);
4859 // If nothing was selected, select the first item now
4860 // (or navigate out of tab).
4861 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4863 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4864 if ( p
) DoSelectProperty(p
);
4873 // -----------------------------------------------------------------------
4875 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4877 // If there was editor open and focused, then this event should not
4878 // really be processed here.
4879 if ( IsEditorFocused() )
4881 // However, if event had modifiers, it is probably still best
4883 if ( event
.HasModifiers() )
4886 event
.StopPropagation();
4890 HandleKeyEvent(event
, false);
4893 // -----------------------------------------------------------------------
4895 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4900 action
= KeyEventToActions(event
, &secondAction
);
4903 // Does the keycode trigger button?
4904 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4907 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4908 GetEventHandler()->AddPendingEvent(evt
);
4915 // -----------------------------------------------------------------------
4917 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4919 HandleKeyEvent(event
, true);
4922 // -----------------------------------------------------------------------
4923 // wxPropertyGrid miscellaneous event handling
4924 // -----------------------------------------------------------------------
4926 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4929 // Check if the focus is in this control or one of its children
4930 wxWindow
* newFocused
= wxWindow::FindFocus();
4932 if ( newFocused
!= m_curFocused
)
4933 HandleFocusChange( newFocused
);
4936 bool wxPropertyGrid::IsEditorFocused() const
4938 wxWindow
* focus
= wxWindow::FindFocus();
4940 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4941 focus
== GetEditorControl() )
4947 // Called by focus event handlers. newFocused is the window that becomes focused.
4948 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4950 unsigned int oldFlags
= m_iFlags
;
4952 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4954 wxWindow
* parent
= newFocused
;
4956 // This must be one of nextFocus' parents.
4959 // Use m_eventObject, which is either wxPropertyGrid or
4960 // wxPropertyGridManager, as appropriate.
4961 if ( parent
== m_eventObject
)
4963 m_iFlags
|= wxPG_FL_FOCUSED
;
4966 parent
= parent
->GetParent();
4969 m_curFocused
= newFocused
;
4971 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4972 (oldFlags
& wxPG_FL_FOCUSED
) )
4974 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4976 // Need to store changed value
4977 CommitChangesFromEditor();
4983 // Preliminary code for tab-order respecting
4984 // tab-traversal (but should be moved to
4987 wxWindow* prevFocus = event.GetWindow();
4988 wxWindow* useThis = this;
4989 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4990 useThis = GetParent();
4993 prevFocus->GetParent() == useThis->GetParent() )
4995 wxList& children = useThis->GetParent()->GetChildren();
4997 wxNode* node = children.Find(prevFocus);
4999 if ( node->GetNext() &&
5000 useThis == node->GetNext()->GetData() )
5001 DoSelectProperty(GetFirst());
5002 else if ( node->GetPrevious () &&
5003 useThis == node->GetPrevious()->GetData() )
5004 DoSelectProperty(GetLastProperty());
5011 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5012 DrawItem( m_selected
);
5016 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5018 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5019 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5020 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5021 //else if ( event.GetWindow() )
5023 HandleFocusChange(event
.GetWindow());
5028 // -----------------------------------------------------------------------
5030 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5032 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5035 // event.Skip() being commented out is aworkaround for bug reported
5036 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5040 // -----------------------------------------------------------------------
5042 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5044 m_iFlags
|= wxPG_FL_SCROLLED
;
5049 // -----------------------------------------------------------------------
5051 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5053 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5055 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5059 // -----------------------------------------------------------------------
5060 // Property editor related functions
5061 // -----------------------------------------------------------------------
5063 // noDefCheck = true prevents infinite recursion.
5064 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5067 wxASSERT( editorClass
);
5069 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5070 RegisterDefaultEditors();
5072 wxString name
= editorClass
->GetName();
5074 // Existing editor under this name?
5075 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5077 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5079 // If this name was already used, try class name.
5080 name
= editorClass
->GetClassInfo()->GetClassName();
5081 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5084 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5085 (wxPGEditor
*) vt_it
->second
,
5086 "Editor with given name was already registered" );
5088 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5093 // Use this in RegisterDefaultEditors.
5094 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5095 if ( wxPGEditor_##EDITOR == NULL ) \
5097 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5098 new wxPG##EDITOR##Editor, true ); \
5101 // Registers all default editor classes
5102 void wxPropertyGrid::RegisterDefaultEditors()
5104 wxPGRegisterDefaultEditorClass( TextCtrl
);
5105 wxPGRegisterDefaultEditorClass( Choice
);
5106 wxPGRegisterDefaultEditorClass( ComboBox
);
5107 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5108 #if wxPG_INCLUDE_CHECKBOX
5109 wxPGRegisterDefaultEditorClass( CheckBox
);
5111 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5113 // Register SpinCtrl etc. editors before use
5114 RegisterAdditionalEditors();
5117 // -----------------------------------------------------------------------
5118 // wxPGStringTokenizer
5119 // Needed to handle C-style string lists (e.g. "str1" "str2")
5120 // -----------------------------------------------------------------------
5122 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5123 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5127 wxPGStringTokenizer::~wxPGStringTokenizer()
5131 bool wxPGStringTokenizer::HasMoreTokens()
5133 const wxString
& str
= *m_str
;
5135 wxString::const_iterator i
= m_curPos
;
5137 wxUniChar delim
= m_delimeter
;
5139 wxUniChar prev_a
= wxT('\0');
5141 bool inToken
= false;
5143 while ( i
!= str
.end() )
5152 m_readyToken
.clear();
5157 if ( prev_a
!= wxT('\\') )
5161 if ( a
!= wxT('\\') )
5181 m_curPos
= str
.end();
5189 wxString
wxPGStringTokenizer::GetNextToken()
5191 return m_readyToken
;
5194 // -----------------------------------------------------------------------
5196 // -----------------------------------------------------------------------
5198 wxPGChoiceEntry::wxPGChoiceEntry()
5199 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5203 // -----------------------------------------------------------------------
5205 // -----------------------------------------------------------------------
5207 wxPGChoicesData::wxPGChoicesData()
5212 wxPGChoicesData::~wxPGChoicesData()
5217 void wxPGChoicesData::Clear()
5222 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5224 wxASSERT( m_items
.size() == 0 );
5226 m_items
= data
->m_items
;
5229 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5230 const wxPGChoiceEntry
& item
)
5232 wxVector
<wxPGChoiceEntry
>::iterator it
;
5236 index
= (int) m_items
.size();
5240 it
= m_items
.begin() + index
;
5243 m_items
.insert(it
, item
);
5245 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5247 // Need to fix value?
5248 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5249 ownEntry
.SetValue(index
);
5254 // -----------------------------------------------------------------------
5255 // wxPropertyGridEvent
5256 // -----------------------------------------------------------------------
5258 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5261 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5262 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5263 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5265 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5266 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5267 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5268 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5269 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5272 // -----------------------------------------------------------------------
5274 void wxPropertyGridEvent::Init()
5276 m_validationInfo
= NULL
;
5278 m_wasVetoed
= false;
5281 // -----------------------------------------------------------------------
5283 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5284 : wxCommandEvent(commandType
,id
)
5290 // -----------------------------------------------------------------------
5292 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5293 : wxCommandEvent(event
)
5295 m_eventType
= event
.GetEventType();
5296 m_eventObject
= event
.m_eventObject
;
5298 m_property
= event
.m_property
;
5299 m_validationInfo
= event
.m_validationInfo
;
5300 m_canVeto
= event
.m_canVeto
;
5301 m_wasVetoed
= event
.m_wasVetoed
;
5304 // -----------------------------------------------------------------------
5306 wxPropertyGridEvent::~wxPropertyGridEvent()
5310 // -----------------------------------------------------------------------
5312 wxEvent
* wxPropertyGridEvent::Clone() const
5314 return new wxPropertyGridEvent( *this );
5317 // -----------------------------------------------------------------------
5318 // wxPropertyGridPopulator
5319 // -----------------------------------------------------------------------
5321 wxPropertyGridPopulator::wxPropertyGridPopulator()
5325 wxPGGlobalVars
->m_offline
++;
5328 // -----------------------------------------------------------------------
5330 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5333 m_propHierarchy
.clear();
5336 // -----------------------------------------------------------------------
5338 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5344 // -----------------------------------------------------------------------
5346 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5349 // Free unused sets of choices
5350 wxPGHashMapS2P::iterator it
;
5352 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5354 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5361 m_pg
->GetPanel()->Refresh();
5363 wxPGGlobalVars
->m_offline
--;
5366 // -----------------------------------------------------------------------
5368 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5369 const wxString
& propLabel
,
5370 const wxString
& propName
,
5371 const wxString
* propValue
,
5372 wxPGChoices
* pChoices
)
5374 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5375 wxPGProperty
* parent
= GetCurParent();
5377 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5379 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5383 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5385 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5389 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5391 property
->SetLabel(propLabel
);
5392 property
->DoSetName(propName
);
5394 if ( pChoices
&& pChoices
->IsOk() )
5395 property
->SetChoices(*pChoices
);
5397 m_state
->DoInsert(parent
, -1, property
);
5400 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5401 wxPG_PROGRAMMATIC_VALUE
);
5406 // -----------------------------------------------------------------------
5408 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5410 m_propHierarchy
.push_back(property
);
5411 DoScanForChildren();
5412 m_propHierarchy
.pop_back();
5415 // -----------------------------------------------------------------------
5417 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5418 const wxString
& idString
)
5420 wxPGChoices choices
;
5423 if ( choicesString
[0] == wxT('@') )
5425 wxString ids
= choicesString
.substr(1);
5426 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5427 if ( it
== m_dictIdChoices
.end() )
5428 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5430 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5435 if ( idString
.length() )
5437 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5438 if ( it
!= m_dictIdChoices
.end() )
5440 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5447 // Parse choices string
5448 wxString::const_iterator it
= choicesString
.begin();
5452 bool labelValid
= false;
5454 for ( ; it
!= choicesString
.end(); ++it
)
5460 if ( c
== wxT('"') )
5465 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5466 choices
.Add(label
, l
);
5469 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5474 else if ( c
== wxT('=') )
5481 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5488 if ( c
== wxT('"') )
5501 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5502 choices
.Add(label
, l
);
5505 if ( !choices
.IsOk() )
5507 choices
.EnsureData();
5511 if ( idString
.length() )
5512 m_dictIdChoices
[idString
] = choices
.GetData();
5519 // -----------------------------------------------------------------------
5521 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5523 if ( s
.Last() == wxT('%') )
5525 wxString s2
= s
.substr(0,s
.length()-1);
5527 if ( s2
.ToLong(&val
, 10) )
5529 *pval
= (val
*max
)/100;
5535 return s
.ToLong(pval
, 10);
5538 // -----------------------------------------------------------------------
5540 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5541 const wxString
& type
,
5542 const wxString
& value
)
5544 int l
= m_propHierarchy
.size();
5548 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5549 wxString valuel
= value
.Lower();
5552 if ( type
.length() == 0 )
5557 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5559 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5561 else if ( value
.ToLong(&v
, 0) )
5568 if ( type
== wxT("string") )
5572 else if ( type
== wxT("int") )
5575 value
.ToLong(&v
, 0);
5578 else if ( type
== wxT("bool") )
5580 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5587 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5592 p
->SetAttribute( name
, variant
);
5597 // -----------------------------------------------------------------------
5599 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5601 wxLogError(_("Error in resource: %s"),msg
.c_str());
5604 // -----------------------------------------------------------------------
5606 #endif // wxUSE_PROPGRID