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 splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2982 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2983 int imageOffset
= 0;
2985 // TODO: If custom image detection changes from current, change this.
2986 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
2988 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2989 int iw
= p
->OnMeasureImage().x
;
2991 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
2992 imageOffset
= p
->GetImageOffset(iw
);
2997 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
2999 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3004 // -----------------------------------------------------------------------
3006 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3008 wxSize sz
= GetImageSize(p
, item
);
3009 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3010 wxPG_CUSTOM_IMAGE_SPACINGY
,
3015 // return size of custom paint image
3016 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3018 // If called with NULL property, then return default image
3019 // size for properties that use image.
3021 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3023 wxSize cis
= p
->OnMeasureImage(item
);
3025 int choiceCount
= p
->m_choices
.GetCount();
3026 int comVals
= p
->GetDisplayedCommonValueCount();
3027 if ( item
>= choiceCount
&& comVals
> 0 )
3029 unsigned int cvi
= item
-choiceCount
;
3030 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3032 else if ( item
>= 0 && choiceCount
== 0 )
3033 return wxSize(0, 0);
3038 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3043 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3050 // -----------------------------------------------------------------------
3052 // takes scrolling into account
3053 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3056 GetViewStart(&vx
,&vy
);
3057 vy
*=wxPG_PIXELS_PER_UNIT
;
3058 vx
*=wxPG_PIXELS_PER_UNIT
;
3061 ClientToScreen( px
, py
);
3064 // -----------------------------------------------------------------------
3066 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3069 GetViewStart(&pt2
.x
,&pt2
.y
);
3070 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3071 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3075 return m_pState
->HitTest(pt2
);
3078 // -----------------------------------------------------------------------
3080 // custom set cursor
3081 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3083 if ( type
== m_curcursor
&& !override
) return;
3085 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3087 if ( type
== wxCURSOR_SIZEWE
)
3088 cursor
= m_cursorSizeWE
;
3090 m_canvas
->SetCursor( *cursor
);
3095 // -----------------------------------------------------------------------
3096 // wxPropertyGrid property selection, editor creation
3097 // -----------------------------------------------------------------------
3100 // This class forwards events from property editor controls to wxPropertyGrid.
3101 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3104 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3105 : wxEvtHandler(), m_propGrid(propGrid
)
3109 virtual ~wxPropertyGridEditorEventForwarder()
3114 bool ProcessEvent( wxEvent
& event
)
3119 m_propGrid
->HandleCustomEditorEvent(event
);
3121 return wxEvtHandler::ProcessEvent(event
);
3124 wxPropertyGrid
* m_propGrid
;
3127 // Setups event handling for child control
3128 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3130 wxWindowID id
= argWnd
->GetId();
3132 if ( argWnd
== m_wndEditor
)
3134 argWnd
->Connect(id
, wxEVT_MOTION
,
3135 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3137 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3138 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3140 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3141 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3143 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3144 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3146 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3147 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3149 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3150 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3154 wxPropertyGridEditorEventForwarder
* forwarder
;
3155 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3156 argWnd
->PushEventHandler(forwarder
);
3158 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3159 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3163 void wxPropertyGrid::FreeEditors()
3166 // Return focus back to canvas from children (this is required at least for
3167 // GTK+, which, unlike Windows, clears focus when control is destroyed
3168 // instead of moving it to closest parent).
3169 wxWindow
* focus
= wxWindow::FindFocus();
3172 wxWindow
* parent
= focus
->GetParent();
3175 if ( parent
== m_canvas
)
3180 parent
= parent
->GetParent();
3184 // Do not free editors immediately if processing events
3187 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3188 m_wndEditor2
->Hide();
3189 wxPendingDelete
.Append( handler
);
3190 wxPendingDelete
.Append( m_wndEditor2
);
3191 m_wndEditor2
= NULL
;
3196 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3197 m_wndEditor
->Hide();
3198 wxPendingDelete
.Append( handler
);
3199 wxPendingDelete
.Append( m_wndEditor
);
3204 // Call with NULL to de-select property
3205 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3209 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3210 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3212 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3215 if ( m_inDoSelectProperty
)
3218 m_inDoSelectProperty
= 1;
3220 wxPGProperty
* prev
= m_selected
;
3224 m_inDoSelectProperty
= 0;
3230 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3232 wxPrintf( "None selected\n" );
3235 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3237 wxPrintf( "P = NULL\n" );
3240 // If we are frozen, then just set the values.
3243 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3244 m_editorFocused
= 0;
3247 m_pState
->m_selected
= p
;
3249 // If frozen, always free controls. But don't worry, as Thaw will
3250 // recall SelectProperty to recreate them.
3253 // Prevent any further selection measures in this call
3259 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3261 // Only set focus if not deselecting
3264 if ( flags
& wxPG_SEL_FOCUS
)
3268 m_wndEditor
->SetFocus();
3269 m_editorFocused
= 1;
3278 m_inDoSelectProperty
= 0;
3283 // First, deactivate previous
3287 OnValidationFailureReset(m_selected
);
3289 // Must double-check if this is an selected in case of forceswitch
3292 if ( !CommitChangesFromEditor(flags
) )
3294 // Validation has failed, so we can't exit the previous editor
3295 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3296 // _("Invalid Value"),wxOK|wxICON_ERROR);
3297 m_inDoSelectProperty
= 0;
3306 m_pState
->m_selected
= NULL
;
3308 // We need to always fully refresh the grid here
3311 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3312 EditorsValueWasNotModified();
3315 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3318 // Then, activate the one given.
3321 int propY
= p
->GetY2(m_lineHeight
);
3323 int splitterX
= GetSplitterPosition();
3324 m_editorFocused
= 0;
3326 m_pState
->m_selected
= p
;
3327 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3329 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3331 wxASSERT( m_wndEditor
== NULL
);
3334 // Only create editor for non-disabled non-caption
3335 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3337 // do this for non-caption items
3341 // Do we need to paint the custom image, if any?
3342 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3343 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3344 !p
->GetEditorClass()->CanContainCustomImage()
3346 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3348 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3349 wxPoint goodPos
= grect
.GetPosition();
3350 #if wxPG_CREATE_CONTROLS_HIDDEN
3351 int coord_adjust
= m_height
- goodPos
.y
;
3352 goodPos
.y
+= coord_adjust
;
3355 const wxPGEditor
* editor
= p
->GetEditorClass();
3356 wxCHECK_MSG(editor
, false,
3357 wxT("NULL editor class not allowed"));
3359 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3361 wxPGWindowList wndList
= editor
->CreateControls(this,
3366 m_wndEditor
= wndList
.m_primary
;
3367 m_wndEditor2
= wndList
.m_secondary
;
3368 wxWindow
* primaryCtrl
= GetEditorControl();
3371 // Essentially, primaryCtrl == m_wndEditor
3374 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3375 // value is drawn as normal, and m_wndEditor2 is assumed
3376 // to be a right-aligned button that triggers a separate editorCtrl
3381 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3382 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3384 // Set validator, if any
3385 #if wxUSE_VALIDATORS
3386 wxValidator
* validator
= p
->GetValidator();
3388 primaryCtrl
->SetValidator(*validator
);
3391 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3392 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3394 // If it has modified status, use bold font
3395 // (must be done before capturing m_ctrlXAdjust)
3396 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3397 SetCurControlBoldFont();
3400 // Fix TextCtrl indentation
3401 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3402 wxTextCtrl
* tc
= NULL
;
3403 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3404 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3406 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3408 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3411 // Store x relative to splitter (we'll need it).
3412 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3414 // Check if background clear is not necessary
3415 wxPoint pos
= m_wndEditor
->GetPosition();
3416 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3418 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3421 m_wndEditor
->SetSizeHints(3, 3);
3423 #if wxPG_CREATE_CONTROLS_HIDDEN
3424 m_wndEditor
->Show(false);
3425 m_wndEditor
->Freeze();
3427 goodPos
= m_wndEditor
->GetPosition();
3428 goodPos
.y
-= coord_adjust
;
3429 m_wndEditor
->Move( goodPos
);
3432 SetupChildEventHandling(primaryCtrl
);
3434 // Focus and select all (wxTextCtrl, wxComboBox etc)
3435 if ( flags
& wxPG_SEL_FOCUS
)
3437 primaryCtrl
->SetFocus();
3439 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3445 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3446 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3448 // Get proper id for wndSecondary
3449 m_wndSecId
= m_wndEditor2
->GetId();
3450 wxWindowList children
= m_wndEditor2
->GetChildren();
3451 wxWindowList::iterator node
= children
.begin();
3452 if ( node
!= children
.end() )
3453 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3455 m_wndEditor2
->SetSizeHints(3,3);
3457 #if wxPG_CREATE_CONTROLS_HIDDEN
3458 wxRect sec_rect
= m_wndEditor2
->GetRect();
3459 sec_rect
.y
-= coord_adjust
;
3461 // Fine tuning required to fix "oversized"
3462 // button disappearance bug.
3463 if ( sec_rect
.y
< 0 )
3465 sec_rect
.height
+= sec_rect
.y
;
3468 m_wndEditor2
->SetSize( sec_rect
);
3470 m_wndEditor2
->Show();
3472 SetupChildEventHandling(m_wndEditor2
);
3474 // If no primary editor, focus to button to allow
3475 // it to interprete ENTER etc.
3476 // NOTE: Due to problems focusing away from it, this
3477 // has been disabled.
3479 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3480 m_wndEditor2->SetFocus();
3484 if ( flags
& wxPG_SEL_FOCUS
)
3485 m_editorFocused
= 1;
3490 // Make sure focus is in grid canvas (important for wxGTK, at least)
3494 EditorsValueWasNotModified();
3496 // If it's inside collapsed section, expand parent, scroll, etc.
3497 // Also, if it was partially visible, scroll it into view.
3498 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3503 #if wxPG_CREATE_CONTROLS_HIDDEN
3504 m_wndEditor
->Thaw();
3506 m_wndEditor
->Show(true);
3513 // Make sure focus is in grid canvas
3517 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3523 // Show help text in status bar.
3524 // (if found and grid not embedded in manager with help box and
3525 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3528 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3530 wxStatusBar
* statusbar
= NULL
;
3531 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3533 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3535 statusbar
= frame
->GetStatusBar();
3540 const wxString
* pHelpString
= (const wxString
*) NULL
;
3544 pHelpString
= &p
->GetHelpString();
3545 if ( pHelpString
->length() )
3547 // Set help box text.
3548 statusbar
->SetStatusText( *pHelpString
);
3549 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3553 if ( (!pHelpString
|| !pHelpString
->length()) &&
3554 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3556 // Clear help box - but only if it was written
3557 // by us at previous time.
3558 statusbar
->SetStatusText( m_emptyString
);
3559 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3565 m_inDoSelectProperty
= 0;
3567 // call wx event handler (here so that it also occurs on deselection)
3568 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3573 // -----------------------------------------------------------------------
3575 bool wxPropertyGrid::UnfocusEditor()
3577 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3580 if ( !CommitChangesFromEditor(0) )
3584 DrawItem(m_selected
);
3589 // -----------------------------------------------------------------------
3591 void wxPropertyGrid::RefreshEditor()
3593 wxPGProperty
* p
= m_selected
;
3597 wxWindow
* wnd
= GetEditorControl();
3601 // Set editor font boldness - must do this before
3602 // calling UpdateControl().
3603 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3605 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3606 wnd
->SetFont(GetCaptionFont());
3608 wnd
->SetFont(GetFont());
3611 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3613 editorClass
->UpdateControl(p
, wnd
);
3615 if ( p
->IsValueUnspecified() )
3616 editorClass
->SetValueToUnspecified(p
, wnd
);
3619 // -----------------------------------------------------------------------
3621 // This method is not inline because it called dozens of times
3622 // (i.e. two-arg function calls create smaller code size).
3623 bool wxPropertyGrid::DoClearSelection()
3625 return DoSelectProperty(NULL
);
3628 // -----------------------------------------------------------------------
3629 // wxPropertyGrid expand/collapse state
3630 // -----------------------------------------------------------------------
3632 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3634 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3636 // If active editor was inside collapsed section, then disable it
3637 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3639 ClearSelection(false);
3642 // Store dont-center-splitter flag 'cause we need to temporarily set it
3643 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3644 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3646 bool res
= m_pState
->DoCollapse(pwc
);
3651 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3653 RecalculateVirtualSize();
3655 // Redraw etc. only if collapsed was visible.
3656 if (pwc
->IsVisible() &&
3658 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3660 // When item is collapsed so that scrollbar would move,
3661 // graphics mess is about (unless we redraw everything).
3666 // Clear dont-center-splitter flag if it wasn't set
3667 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3672 // -----------------------------------------------------------------------
3674 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3676 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3678 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3680 // Store dont-center-splitter flag 'cause we need to temporarily set it
3681 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3682 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3684 bool res
= m_pState
->DoExpand(pwc
);
3689 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3691 RecalculateVirtualSize();
3693 // Redraw etc. only if expanded was visible.
3694 if ( pwc
->IsVisible() && !m_frozen
&&
3695 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3699 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3702 DrawItems(pwc
, NULL
);
3707 // Clear dont-center-splitter flag if it wasn't set
3708 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3713 // -----------------------------------------------------------------------
3715 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3718 return m_pState
->DoHideProperty(p
, hide
, flags
);
3721 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3724 ClearSelection(false);
3727 m_pState
->DoHideProperty(p
, hide
, flags
);
3729 RecalculateVirtualSize();
3736 // -----------------------------------------------------------------------
3737 // wxPropertyGrid size related methods
3738 // -----------------------------------------------------------------------
3740 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3742 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3746 // If virtual height was changed, then recalculate editor control position(s)
3747 if ( m_pState
->m_vhCalcPending
)
3748 CorrectEditorWidgetPosY();
3750 m_pState
->EnsureVirtualHeight();
3753 int by1
= m_pState
->GetVirtualHeight();
3754 int by2
= m_pState
->GetActualVirtualHeight();
3757 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3758 wxFAIL_MSG(s
.c_str());
3763 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3765 int x
= m_pState
->m_width
;
3766 int y
= m_pState
->m_virtualHeight
;
3769 GetClientSize(&width
,&height
);
3771 // Now adjust virtual size.
3772 SetVirtualSize(x
, y
);
3778 // Adjust scrollbars
3779 if ( HasVirtualWidth() )
3781 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3782 xPos
= GetScrollPos( wxHORIZONTAL
);
3785 if ( forceXPos
!= -1 )
3788 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3791 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3792 int yPos
= GetScrollPos( wxVERTICAL
);
3794 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3795 xAmount
, yAmount
, xPos
, yPos
, true );
3797 // Must re-get size now
3798 GetClientSize(&width
,&height
);
3800 if ( !HasVirtualWidth() )
3802 m_pState
->SetVirtualWidth(width
);
3809 m_canvas
->SetSize( x
, y
);
3811 m_pState
->CheckColumnWidths();
3814 CorrectEditorWidgetSizeX();
3816 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3819 // -----------------------------------------------------------------------
3821 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3823 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3827 GetClientSize(&width
,&height
);
3832 #if wxPG_DOUBLE_BUFFER
3833 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3835 int dblh
= (m_lineHeight
*2);
3836 if ( !m_doubleBuffer
)
3838 // Create double buffer bitmap to draw on, if none
3839 int w
= (width
>250)?width
:250;
3840 int h
= height
+ dblh
;
3842 m_doubleBuffer
= new wxBitmap( w
, h
);
3846 int w
= m_doubleBuffer
->GetWidth();
3847 int h
= m_doubleBuffer
->GetHeight();
3849 // Double buffer must be large enough
3850 if ( w
< width
|| h
< (height
+dblh
) )
3852 if ( w
< width
) w
= width
;
3853 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3854 delete m_doubleBuffer
;
3855 m_doubleBuffer
= new wxBitmap( w
, h
);
3862 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3863 m_ncWidth
= event
.GetSize().x
;
3867 if ( m_pState
->m_itemsAdded
)
3868 PrepareAfterItemsAdded();
3870 // Without this, virtual size (atleast under wxGTK) will be skewed
3871 RecalculateVirtualSize();
3877 // -----------------------------------------------------------------------
3879 void wxPropertyGrid::SetVirtualWidth( int width
)
3883 // Disable virtual width
3884 width
= GetClientSize().x
;
3885 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3889 // Enable virtual width
3890 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3892 m_pState
->SetVirtualWidth( width
);
3895 void wxPropertyGrid::SetFocusOnCanvas()
3897 m_canvas
->SetFocusIgnoringChildren();
3898 m_editorFocused
= 0;
3901 // -----------------------------------------------------------------------
3902 // wxPropertyGrid mouse event handling
3903 // -----------------------------------------------------------------------
3905 // selFlags uses same values DoSelectProperty's flags
3906 // Returns true if event was vetoed.
3907 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3909 // Send property grid event of specific type and with specific property
3910 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3911 evt
.SetPropertyGrid(this);
3912 evt
.SetEventObject(m_eventObject
);
3916 evt
.SetCanVeto(true);
3917 evt
.SetupValidationInfo();
3918 m_validationInfo
.m_pValue
= pValue
;
3920 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3922 evtHandler
->ProcessEvent(evt
);
3924 return evt
.WasVetoed();
3927 // -----------------------------------------------------------------------
3929 // Return false if should be skipped
3930 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3934 // Need to set focus?
3935 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3940 wxPropertyGridPageState
* state
= m_pState
;
3942 int splitterHitOffset
;
3943 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3945 wxPGProperty
* p
= DoGetItemAtY(y
);
3949 int depth
= (int)p
->GetDepth() - 1;
3951 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3953 if ( x
>= marginEnds
)
3957 if ( p
->IsCategory() )
3959 // This is category.
3960 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3962 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3964 // Expand, collapse, activate etc. if click on text or left of splitter.
3967 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3972 if ( !DoSelectProperty( p
) )
3975 // On double-click, expand/collapse.
3976 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3978 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3979 else DoExpand( p
, true );
3983 else if ( splitterHit
== -1 )
3986 unsigned int selFlag
= 0;
3987 if ( columnHit
== 1 )
3989 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3990 selFlag
= wxPG_SEL_FOCUS
;
3992 if ( !DoSelectProperty( p
, selFlag
) )
3995 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3997 if ( p
->GetChildCount() && !p
->IsCategory() )
3998 // On double-click, expand/collapse.
3999 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4001 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4002 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4003 else DoExpand( p
, true );
4010 // click on splitter
4011 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4013 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4015 // Double-clicking the splitter causes auto-centering
4016 CenterSplitter( true );
4018 else if ( m_dragStatus
== 0 )
4021 // Begin draggin the splitter
4025 // Changes must be committed here or the
4026 // value won't be drawn correctly
4027 if ( !CommitChangesFromEditor() )
4030 m_wndEditor
->Show ( false );
4033 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4035 m_canvas
->CaptureMouse();
4036 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4040 m_draggedSplitter
= splitterHit
;
4041 m_dragOffset
= splitterHitOffset
;
4043 wxClientDC
dc(m_canvas
);
4045 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4046 // Fixes button disappearance bug
4048 m_wndEditor2
->Show ( false );
4051 m_startingSplitterX
= x
- splitterHitOffset
;
4059 if ( p
->GetChildCount() )
4061 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4063 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4065 int y2
= y
% m_lineHeight
;
4066 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4068 // On click on expander button, expand/collapse
4069 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4070 DoCollapse( p
, true );
4072 DoExpand( p
, true );
4081 // -----------------------------------------------------------------------
4083 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4084 wxMouseEvent
& WXUNUSED(event
) )
4088 // Select property here as well
4089 wxPGProperty
* p
= m_propHover
;
4090 if ( p
!= m_selected
)
4091 DoSelectProperty( p
);
4093 // Send right click event.
4094 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4101 // -----------------------------------------------------------------------
4103 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4104 wxMouseEvent
& WXUNUSED(event
) )
4108 // Select property here as well
4109 wxPGProperty
* p
= m_propHover
;
4111 if ( p
!= m_selected
)
4112 DoSelectProperty( p
);
4114 // Send double-click event.
4115 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4122 // -----------------------------------------------------------------------
4124 #if wxPG_SUPPORT_TOOLTIPS
4126 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4128 if ( tipString
.length() )
4130 m_canvas
->SetToolTip(tipString
);
4134 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4135 m_canvas
->SetToolTip( m_emptyString
);
4137 m_canvas
->SetToolTip( NULL
);
4142 #endif // #if wxPG_SUPPORT_TOOLTIPS
4144 // -----------------------------------------------------------------------
4146 // Return false if should be skipped
4147 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4149 // Safety check (needed because mouse capturing may
4150 // otherwise freeze the control)
4151 if ( m_dragStatus
> 0 && !event
.Dragging() )
4153 HandleMouseUp(x
,y
,event
);
4156 wxPropertyGridPageState
* state
= m_pState
;
4158 int splitterHitOffset
;
4159 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4160 int splitterX
= x
- splitterHitOffset
;
4162 if ( m_dragStatus
> 0 )
4164 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4165 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4168 int newSplitterX
= x
- m_dragOffset
;
4169 int splitterX
= x
- splitterHitOffset
;
4171 // Splitter redraw required?
4172 if ( newSplitterX
!= splitterX
)
4175 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4176 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4177 state
->m_fSplitterX
= (float) newSplitterX
;
4180 CorrectEditorWidgetSizeX();
4194 int ih
= m_lineHeight
;
4197 #if wxPG_SUPPORT_TOOLTIPS
4198 wxPGProperty
* prevHover
= m_propHover
;
4199 unsigned char prevSide
= m_mouseSide
;
4201 int curPropHoverY
= y
- (y
% ih
);
4203 // On which item it hovers
4206 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4209 // Mouse moves on another property
4211 m_propHover
= DoGetItemAtY(y
);
4212 m_propHoverY
= curPropHoverY
;
4215 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4218 #if wxPG_SUPPORT_TOOLTIPS
4219 // Store which side we are on
4221 if ( columnHit
== 1 )
4223 else if ( columnHit
== 0 )
4227 // If tooltips are enabled, show label or value as a tip
4228 // in case it doesn't otherwise show in full length.
4230 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4232 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4234 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4236 if ( m_propHover
&& !m_propHover
->IsCategory() )
4239 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4241 // Show help string as a tooltip
4242 wxString tipString
= m_propHover
->GetHelpString();
4244 SetToolTip(tipString
);
4248 // Show cropped value string as a tooltip
4252 if ( m_mouseSide
== 1 )
4254 tipString
= m_propHover
->m_label
;
4255 space
= splitterX
-m_marginWidth
-3;
4257 else if ( m_mouseSide
== 2 )
4259 tipString
= m_propHover
->GetDisplayedString();
4261 space
= m_width
- splitterX
;
4262 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4263 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4269 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4272 SetToolTip( tipString
);
4279 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4280 m_canvas
->SetToolTip( m_emptyString
);
4282 m_canvas
->SetToolTip( NULL
);
4293 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4294 m_canvas
->SetToolTip( m_emptyString
);
4296 m_canvas
->SetToolTip( NULL
);
4304 if ( splitterHit
== -1 ||
4306 HasFlag(wxPG_STATIC_SPLITTER
) )
4308 // hovering on something else
4309 if ( m_curcursor
!= wxCURSOR_ARROW
)
4310 CustomSetCursor( wxCURSOR_ARROW
);
4314 // Do not allow splitter cursor on caption items.
4315 // (also not if we were dragging and its started
4316 // outside the splitter region)
4318 if ( !m_propHover
->IsCategory() &&
4322 // hovering on splitter
4324 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4325 // reliably detected.
4326 //if ( m_curcursor != wxCURSOR_SIZEWE )
4327 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4333 // hovering on something else
4334 if ( m_curcursor
!= wxCURSOR_ARROW
)
4335 CustomSetCursor( wxCURSOR_ARROW
);
4342 // -----------------------------------------------------------------------
4344 // Also handles Leaving event
4345 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4346 wxMouseEvent
&WXUNUSED(event
) )
4348 wxPropertyGridPageState
* state
= m_pState
;
4352 int splitterHitOffset
;
4353 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4355 // No event type check - basicly calling this method should
4356 // just stop dragging.
4357 // Left up after dragged?
4358 if ( m_dragStatus
>= 1 )
4361 // End Splitter Dragging
4363 // DO NOT ENABLE FOLLOWING LINE!
4364 // (it is only here as a reminder to not to do it)
4367 // Disable splitter auto-centering
4368 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4370 // This is necessary to return cursor
4371 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4373 m_canvas
->ReleaseMouse();
4374 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4377 // Set back the default cursor, if necessary
4378 if ( splitterHit
== -1 ||
4381 CustomSetCursor( wxCURSOR_ARROW
);
4386 // Control background needs to be cleared
4387 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4388 DrawItem( m_selected
);
4392 m_wndEditor
->Show ( true );
4395 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4396 // Fixes button disappearance bug
4398 m_wndEditor2
->Show ( true );
4401 // This clears the focus.
4402 m_editorFocused
= 0;
4408 // -----------------------------------------------------------------------
4410 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4412 int splitterX
= GetSplitterPosition();
4415 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4419 wxWindow
* wnd
= GetEditorControl();
4421 // Hide popup on clicks
4422 if ( event
.GetEventType() != wxEVT_MOTION
)
4423 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4425 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4431 if ( wnd
== NULL
|| m_dragStatus
||
4433 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4434 ux
>= (r
.x
+r
.width
) ||
4436 event
.m_y
>= (r
.y
+r
.height
)
4446 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4451 // -----------------------------------------------------------------------
4453 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4456 if ( OnMouseCommon( event
, &x
, &y
) )
4458 HandleMouseClick(x
,y
,event
);
4463 // -----------------------------------------------------------------------
4465 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4468 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4469 HandleMouseRightClick(x
,y
,event
);
4473 // -----------------------------------------------------------------------
4475 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4477 // Always run standard mouse-down handler as well
4478 OnMouseClick(event
);
4481 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4482 HandleMouseDoubleClick(x
,y
,event
);
4486 // -----------------------------------------------------------------------
4488 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4491 if ( OnMouseCommon( event
, &x
, &y
) )
4493 HandleMouseMove(x
,y
,event
);
4498 // -----------------------------------------------------------------------
4500 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4502 // Called when mouse moves in the empty space below the properties.
4503 CustomSetCursor( wxCURSOR_ARROW
);
4506 // -----------------------------------------------------------------------
4508 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4511 if ( OnMouseCommon( event
, &x
, &y
) )
4513 HandleMouseUp(x
,y
,event
);
4518 // -----------------------------------------------------------------------
4520 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4522 // This may get called from child control as well, so event's
4523 // mouse position cannot be relied on.
4525 if ( event
.Entering() )
4527 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4529 // TODO: Fix this (detect parent and only do
4530 // cursor trick if it is a manager).
4531 wxASSERT( GetParent() );
4532 GetParent()->SetCursor(wxNullCursor
);
4534 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4537 GetParent()->SetCursor(wxNullCursor
);
4539 else if ( event
.Leaving() )
4541 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4542 m_canvas
->SetCursor( wxNullCursor
);
4544 // Get real cursor position
4545 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4547 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4550 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4552 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4556 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4564 // -----------------------------------------------------------------------
4566 // Common code used by various OnMouseXXXChild methods.
4567 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4569 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4570 wxASSERT( topCtrlWnd
);
4572 event
.GetPosition(&x
,&y
);
4574 int splitterX
= GetSplitterPosition();
4576 wxRect r
= topCtrlWnd
->GetRect();
4577 if ( !m_dragStatus
&&
4578 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4579 y
>= 0 && y
< r
.height \
4582 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4587 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4594 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4597 if ( OnMouseChildCommon(event
,&x
,&y
) )
4599 bool res
= HandleMouseClick(x
,y
,event
);
4600 if ( !res
) event
.Skip();
4604 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4607 wxASSERT( m_wndEditor
);
4608 // These coords may not be exact (about +-2),
4609 // but that should not matter (right click is about item, not position).
4610 wxPoint pt
= m_wndEditor
->GetPosition();
4611 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4612 wxASSERT( m_selected
);
4613 m_propHover
= m_selected
;
4614 bool res
= HandleMouseRightClick(x
,y
,event
);
4615 if ( !res
) event
.Skip();
4618 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4621 if ( OnMouseChildCommon(event
,&x
,&y
) )
4623 bool res
= HandleMouseMove(x
,y
,event
);
4624 if ( !res
) event
.Skip();
4628 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4631 if ( OnMouseChildCommon(event
,&x
,&y
) )
4633 bool res
= HandleMouseUp(x
,y
,event
);
4634 if ( !res
) event
.Skip();
4638 // -----------------------------------------------------------------------
4639 // wxPropertyGrid keyboard event handling
4640 // -----------------------------------------------------------------------
4642 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4644 // Translates wxKeyEvent to wxPG_ACTION_XXX
4646 int keycode
= event
.GetKeyCode();
4647 int modifiers
= event
.GetModifiers();
4649 wxASSERT( !(modifiers
&~(0xFFFF)) );
4651 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4653 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4655 if ( it
== m_actionTriggers
.end() )
4660 int second
= (it
->second
>>16) & 0xFFFF;
4664 return (it
->second
& 0xFFFF);
4667 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4669 wxASSERT( !(modifiers
&~(0xFFFF)) );
4671 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4673 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4675 if ( it
!= m_actionTriggers
.end() )
4677 // This key combination is already used
4679 // Can add secondary?
4680 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4681 wxT("You can only add up to two separate actions per key combination.") );
4683 action
= it
->second
| (action
<<16);
4686 m_actionTriggers
[hashMapKey
] = action
;
4689 void wxPropertyGrid::ClearActionTriggers( int action
)
4691 wxPGHashMapI2I::iterator it
;
4693 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4695 if ( it
->second
== action
)
4697 m_actionTriggers
.erase(it
);
4702 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4705 // Handles key event when editor control is not focused.
4708 wxCHECK2(!m_frozen
, return);
4710 // Travelsal between items, collapsing/expanding, etc.
4711 int keycode
= event
.GetKeyCode();
4712 bool editorFocused
= IsEditorFocused();
4714 if ( keycode
== WXK_TAB
)
4716 wxWindow
* mainControl
;
4718 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4719 mainControl
= GetParent();
4723 if ( !event
.ShiftDown() )
4725 if ( !editorFocused
&& m_wndEditor
)
4727 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4731 // Tab traversal workaround for platforms on which
4732 // wxWindow::Navigate() may navigate into first child
4733 // instead of next sibling. Does not work perfectly
4734 // in every scenario (for instance, when property grid
4735 // is either first or last control).
4736 #if defined(__WXGTK__)
4737 wxWindow
* sibling
= mainControl
->GetNextSibling();
4739 sibling
->SetFocusFromKbd();
4741 Navigate(wxNavigationKeyEvent::IsForward
);
4747 if ( editorFocused
)
4753 #if defined(__WXGTK__)
4754 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4756 sibling
->SetFocusFromKbd();
4758 Navigate(wxNavigationKeyEvent::IsBackward
);
4766 // Ignore Alt and Control when they are down alone
4767 if ( keycode
== WXK_ALT
||
4768 keycode
== WXK_CONTROL
)
4775 int action
= KeyEventToActions(event
, &secondAction
);
4777 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4780 // Esc cancels any changes
4781 if ( IsEditorsValueModified() )
4783 EditorsValueWasNotModified();
4785 // Update the control as well
4786 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4788 m_selected
->GetDisplayedString() );
4791 OnValidationFailureReset(m_selected
);
4797 // Except for TAB and ESC, handle child control events in child control
4800 // Only propagate event if it had modifiers
4801 if ( !event
.HasModifiers() )
4803 event
.StopPropagation();
4809 bool wasHandled
= false;
4814 if ( ButtonTriggerKeyTest(action
, event
) )
4817 wxPGProperty
* p
= m_selected
;
4819 // Travel and expand/collapse
4822 if ( p
->GetChildCount() &&
4823 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4826 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4828 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4831 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4833 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4840 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4844 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4850 if ( selectDir
>= -1 )
4852 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4854 DoSelectProperty(p
);
4860 // If nothing was selected, select the first item now
4861 // (or navigate out of tab).
4862 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4864 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4865 if ( p
) DoSelectProperty(p
);
4874 // -----------------------------------------------------------------------
4876 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4878 // If there was editor open and focused, then this event should not
4879 // really be processed here.
4880 if ( IsEditorFocused() )
4882 // However, if event had modifiers, it is probably still best
4884 if ( event
.HasModifiers() )
4887 event
.StopPropagation();
4891 HandleKeyEvent(event
, false);
4894 // -----------------------------------------------------------------------
4896 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4901 action
= KeyEventToActions(event
, &secondAction
);
4904 // Does the keycode trigger button?
4905 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4908 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4909 GetEventHandler()->AddPendingEvent(evt
);
4916 // -----------------------------------------------------------------------
4918 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4920 HandleKeyEvent(event
, true);
4923 // -----------------------------------------------------------------------
4924 // wxPropertyGrid miscellaneous event handling
4925 // -----------------------------------------------------------------------
4927 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4930 // Check if the focus is in this control or one of its children
4931 wxWindow
* newFocused
= wxWindow::FindFocus();
4933 if ( newFocused
!= m_curFocused
)
4934 HandleFocusChange( newFocused
);
4937 bool wxPropertyGrid::IsEditorFocused() const
4939 wxWindow
* focus
= wxWindow::FindFocus();
4941 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4942 focus
== GetEditorControl() )
4948 // Called by focus event handlers. newFocused is the window that becomes focused.
4949 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4951 unsigned int oldFlags
= m_iFlags
;
4953 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4955 wxWindow
* parent
= newFocused
;
4957 // This must be one of nextFocus' parents.
4960 // Use m_eventObject, which is either wxPropertyGrid or
4961 // wxPropertyGridManager, as appropriate.
4962 if ( parent
== m_eventObject
)
4964 m_iFlags
|= wxPG_FL_FOCUSED
;
4967 parent
= parent
->GetParent();
4970 m_curFocused
= newFocused
;
4972 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4973 (oldFlags
& wxPG_FL_FOCUSED
) )
4975 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4977 // Need to store changed value
4978 CommitChangesFromEditor();
4984 // Preliminary code for tab-order respecting
4985 // tab-traversal (but should be moved to
4988 wxWindow* prevFocus = event.GetWindow();
4989 wxWindow* useThis = this;
4990 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4991 useThis = GetParent();
4994 prevFocus->GetParent() == useThis->GetParent() )
4996 wxList& children = useThis->GetParent()->GetChildren();
4998 wxNode* node = children.Find(prevFocus);
5000 if ( node->GetNext() &&
5001 useThis == node->GetNext()->GetData() )
5002 DoSelectProperty(GetFirst());
5003 else if ( node->GetPrevious () &&
5004 useThis == node->GetPrevious()->GetData() )
5005 DoSelectProperty(GetLastProperty());
5012 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5013 DrawItem( m_selected
);
5017 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5019 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5020 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5021 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5022 //else if ( event.GetWindow() )
5024 HandleFocusChange(event
.GetWindow());
5029 // -----------------------------------------------------------------------
5031 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5033 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5037 // -----------------------------------------------------------------------
5039 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5041 m_iFlags
|= wxPG_FL_SCROLLED
;
5046 // -----------------------------------------------------------------------
5048 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5050 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5052 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5056 // -----------------------------------------------------------------------
5057 // Property editor related functions
5058 // -----------------------------------------------------------------------
5060 // noDefCheck = true prevents infinite recursion.
5061 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5064 wxASSERT( editorClass
);
5066 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5067 RegisterDefaultEditors();
5069 wxString name
= editorClass
->GetName();
5071 // Existing editor under this name?
5072 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5074 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5076 // If this name was already used, try class name.
5077 name
= editorClass
->GetClassInfo()->GetClassName();
5078 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5081 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5082 (wxPGEditor
*) vt_it
->second
,
5083 "Editor with given name was already registered" );
5085 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5090 // Use this in RegisterDefaultEditors.
5091 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5092 if ( wxPGEditor_##EDITOR == NULL ) \
5094 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5095 new wxPG##EDITOR##Editor, true ); \
5098 // Registers all default editor classes
5099 void wxPropertyGrid::RegisterDefaultEditors()
5101 wxPGRegisterDefaultEditorClass( TextCtrl
);
5102 wxPGRegisterDefaultEditorClass( Choice
);
5103 wxPGRegisterDefaultEditorClass( ComboBox
);
5104 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5105 #if wxPG_INCLUDE_CHECKBOX
5106 wxPGRegisterDefaultEditorClass( CheckBox
);
5108 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5110 // Register SpinCtrl etc. editors before use
5111 RegisterAdditionalEditors();
5114 // -----------------------------------------------------------------------
5115 // wxPGStringTokenizer
5116 // Needed to handle C-style string lists (e.g. "str1" "str2")
5117 // -----------------------------------------------------------------------
5119 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5120 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5124 wxPGStringTokenizer::~wxPGStringTokenizer()
5128 bool wxPGStringTokenizer::HasMoreTokens()
5130 const wxString
& str
= *m_str
;
5132 wxString::const_iterator i
= m_curPos
;
5134 wxUniChar delim
= m_delimeter
;
5136 wxUniChar prev_a
= wxT('\0');
5138 bool inToken
= false;
5140 while ( i
!= str
.end() )
5149 m_readyToken
.clear();
5154 if ( prev_a
!= wxT('\\') )
5158 if ( a
!= wxT('\\') )
5178 m_curPos
= str
.end();
5186 wxString
wxPGStringTokenizer::GetNextToken()
5188 return m_readyToken
;
5191 // -----------------------------------------------------------------------
5193 // -----------------------------------------------------------------------
5195 wxPGChoiceEntry::wxPGChoiceEntry()
5196 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5200 // -----------------------------------------------------------------------
5202 // -----------------------------------------------------------------------
5204 wxPGChoicesData::wxPGChoicesData()
5209 wxPGChoicesData::~wxPGChoicesData()
5214 void wxPGChoicesData::Clear()
5219 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5221 wxASSERT( m_items
.size() == 0 );
5223 m_items
= data
->m_items
;
5226 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5227 const wxPGChoiceEntry
& item
)
5229 wxVector
<wxPGChoiceEntry
>::iterator it
;
5233 index
= (int) m_items
.size();
5237 it
= m_items
.begin() + index
;
5240 m_items
.insert(it
, item
);
5242 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5244 // Need to fix value?
5245 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5246 ownEntry
.SetValue(index
);
5251 // -----------------------------------------------------------------------
5252 // wxPropertyGridEvent
5253 // -----------------------------------------------------------------------
5255 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5258 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5259 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5260 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5261 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5262 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5263 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5265 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5266 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5269 // -----------------------------------------------------------------------
5271 void wxPropertyGridEvent::Init()
5273 m_validationInfo
= NULL
;
5275 m_wasVetoed
= false;
5278 // -----------------------------------------------------------------------
5280 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5281 : wxCommandEvent(commandType
,id
)
5287 // -----------------------------------------------------------------------
5289 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5290 : wxCommandEvent(event
)
5292 m_eventType
= event
.GetEventType();
5293 m_eventObject
= event
.m_eventObject
;
5295 m_property
= event
.m_property
;
5296 m_validationInfo
= event
.m_validationInfo
;
5297 m_canVeto
= event
.m_canVeto
;
5298 m_wasVetoed
= event
.m_wasVetoed
;
5301 // -----------------------------------------------------------------------
5303 wxPropertyGridEvent::~wxPropertyGridEvent()
5307 // -----------------------------------------------------------------------
5309 wxEvent
* wxPropertyGridEvent::Clone() const
5311 return new wxPropertyGridEvent( *this );
5314 // -----------------------------------------------------------------------
5315 // wxPropertyGridPopulator
5316 // -----------------------------------------------------------------------
5318 wxPropertyGridPopulator::wxPropertyGridPopulator()
5322 wxPGGlobalVars
->m_offline
++;
5325 // -----------------------------------------------------------------------
5327 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5330 m_propHierarchy
.clear();
5333 // -----------------------------------------------------------------------
5335 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5341 // -----------------------------------------------------------------------
5343 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5346 // Free unused sets of choices
5347 wxPGHashMapS2P::iterator it
;
5349 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5351 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5358 m_pg
->GetPanel()->Refresh();
5360 wxPGGlobalVars
->m_offline
--;
5363 // -----------------------------------------------------------------------
5365 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5366 const wxString
& propLabel
,
5367 const wxString
& propName
,
5368 const wxString
* propValue
,
5369 wxPGChoices
* pChoices
)
5371 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5372 wxPGProperty
* parent
= GetCurParent();
5374 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5376 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5380 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5382 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5386 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5388 property
->SetLabel(propLabel
);
5389 property
->DoSetName(propName
);
5391 if ( pChoices
&& pChoices
->IsOk() )
5392 property
->SetChoices(*pChoices
);
5394 m_state
->DoInsert(parent
, -1, property
);
5397 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5398 wxPG_PROGRAMMATIC_VALUE
);
5403 // -----------------------------------------------------------------------
5405 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5407 m_propHierarchy
.push_back(property
);
5408 DoScanForChildren();
5409 m_propHierarchy
.pop_back();
5412 // -----------------------------------------------------------------------
5414 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5415 const wxString
& idString
)
5417 wxPGChoices choices
;
5420 if ( choicesString
[0] == wxT('@') )
5422 wxString ids
= choicesString
.substr(1);
5423 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5424 if ( it
== m_dictIdChoices
.end() )
5425 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5427 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5432 if ( idString
.length() )
5434 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5435 if ( it
!= m_dictIdChoices
.end() )
5437 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5444 // Parse choices string
5445 wxString::const_iterator it
= choicesString
.begin();
5449 bool labelValid
= false;
5451 for ( ; it
!= choicesString
.end(); ++it
)
5457 if ( c
== wxT('"') )
5462 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5463 choices
.Add(label
, l
);
5466 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5471 else if ( c
== wxT('=') )
5478 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5485 if ( c
== wxT('"') )
5498 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5499 choices
.Add(label
, l
);
5502 if ( !choices
.IsOk() )
5504 choices
.EnsureData();
5508 if ( idString
.length() )
5509 m_dictIdChoices
[idString
] = choices
.GetData();
5516 // -----------------------------------------------------------------------
5518 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5520 if ( s
.Last() == wxT('%') )
5522 wxString s2
= s
.substr(0,s
.length()-1);
5524 if ( s2
.ToLong(&val
, 10) )
5526 *pval
= (val
*max
)/100;
5532 return s
.ToLong(pval
, 10);
5535 // -----------------------------------------------------------------------
5537 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5538 const wxString
& type
,
5539 const wxString
& value
)
5541 int l
= m_propHierarchy
.size();
5545 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5546 wxString valuel
= value
.Lower();
5549 if ( type
.length() == 0 )
5554 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5556 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5558 else if ( value
.ToLong(&v
, 0) )
5565 if ( type
== wxT("string") )
5569 else if ( type
== wxT("int") )
5572 value
.ToLong(&v
, 0);
5575 else if ( type
== wxT("bool") )
5577 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5584 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5589 p
->SetAttribute( name
, variant
);
5594 // -----------------------------------------------------------------------
5596 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5598 wxLogError(_("Error in resource: %s"),msg
.c_str());
5601 // -----------------------------------------------------------------------
5603 #endif // wxUSE_PROPGRID