1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 //#define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 //#define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
200 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
204 delete m_defaultRenderer
;
206 // This will always have one ref
207 delete m_fontFamilyChoices
;
210 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
211 delete ((wxValidator
*)m_arrValidators
[i
]);
215 // Destroy value type class instances.
216 wxPGHashMapS2P::iterator vt_it
;
218 // Destroy editor class instances.
219 // iterate over all the elements in the class
220 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
222 delete ((wxPGEditor
*)vt_it
->second
);
225 delete wxPGProperty::sm_wxPG_LABEL
;
228 void wxPropertyGridInitGlobalsIfNeeded()
232 // -----------------------------------------------------------------------
234 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
235 // and tries to commit property value.
236 // -----------------------------------------------------------------------
238 class wxPGTLWHandler
: public wxEvtHandler
242 wxPGTLWHandler( wxPropertyGrid
* pg
)
250 void OnClose( wxCloseEvent
& event
)
252 // ClearSelection forces value validation/commit.
253 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
263 wxPropertyGrid
* m_pg
;
265 DECLARE_EVENT_TABLE()
268 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
269 EVT_CLOSE(wxPGTLWHandler::OnClose
)
272 // -----------------------------------------------------------------------
274 // -----------------------------------------------------------------------
277 // wxPGCanvas acts as a graphics sub-window of the
278 // wxScrolledWindow that wxPropertyGrid is.
280 class wxPGCanvas
: public wxPanel
283 wxPGCanvas() : wxPanel()
286 virtual ~wxPGCanvas() { }
289 void OnMouseMove( wxMouseEvent
&event
)
291 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
292 pg
->OnMouseMove( event
);
295 void OnMouseClick( wxMouseEvent
&event
)
297 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
298 pg
->OnMouseClick( event
);
301 void OnMouseUp( wxMouseEvent
&event
)
303 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
304 pg
->OnMouseUp( event
);
307 void OnMouseRightClick( wxMouseEvent
&event
)
309 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
310 pg
->OnMouseRightClick( event
);
313 void OnMouseDoubleClick( wxMouseEvent
&event
)
315 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
316 pg
->OnMouseDoubleClick( event
);
319 void OnKey( wxKeyEvent
& event
)
321 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
325 void OnPaint( wxPaintEvent
& event
);
327 // Always be focussable, even with child windows
328 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
329 { wxPanel::SetCanFocus(true); }
333 DECLARE_EVENT_TABLE()
334 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
338 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
340 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
341 EVT_MOTION(wxPGCanvas::OnMouseMove
)
342 EVT_PAINT(wxPGCanvas::OnPaint
)
343 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
344 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
345 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
346 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
347 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
351 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
353 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
354 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
358 // Don't paint after destruction has begun
359 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
362 // Update everything inside the box
363 wxRect r
= GetUpdateRegion().GetBox();
365 // FIXME: This is just a workaround for a bug that causes splitters not
366 // to paint when other windows are being dragged over the grid.
367 wxRect fullRect
= GetRect();
369 r
.width
= fullRect
.width
;
371 // Repaint this rectangle
372 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
374 // We assume that the size set when grid is shown
375 // is what is desired.
376 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
379 // -----------------------------------------------------------------------
381 // -----------------------------------------------------------------------
383 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
385 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
386 EVT_IDLE(wxPropertyGrid::OnIdle
)
387 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
388 EVT_PAINT(wxPropertyGrid::OnPaint
)
389 EVT_SIZE(wxPropertyGrid::OnResize
)
390 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
391 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
392 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
393 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
394 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
395 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
396 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
397 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
401 // -----------------------------------------------------------------------
403 wxPropertyGrid::wxPropertyGrid()
409 // -----------------------------------------------------------------------
411 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
416 const wxString
& name
)
420 Create(parent
,id
,pos
,size
,style
,name
);
423 // -----------------------------------------------------------------------
425 bool wxPropertyGrid::Create( wxWindow
*parent
,
430 const wxString
& name
)
433 if ( !(style
&wxBORDER_MASK
) )
434 style
|= wxSIMPLE_BORDER
;
438 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
439 style
&= ~(wxTAB_TRAVERSAL
);
440 style
|= wxWANTS_CHARS
;
442 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
449 // -----------------------------------------------------------------------
452 // Initialize values to defaults
454 void wxPropertyGrid::Init1()
456 // Register editor classes, if necessary.
457 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
458 wxPropertyGrid::RegisterDefaultEditors();
462 m_wndEditor
= m_wndEditor2
= NULL
;
466 m_eventObject
= this;
469 m_sortFunction
= NULL
;
470 m_inDoPropertyChanged
= 0;
471 m_inCommitChangesFromEditor
= 0;
472 m_inDoSelectProperty
= 0;
473 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
479 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
480 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
481 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
482 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
483 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
484 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
485 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
486 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
487 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
489 m_coloursCustomized
= 0;
494 #if wxPG_DOUBLE_BUFFER
495 m_doubleBuffer
= NULL
;
498 #ifndef wxPG_ICON_WIDTH
504 m_iconWidth
= wxPG_ICON_WIDTH
;
509 m_gutterWidth
= wxPG_GUTTER_MIN
;
510 m_subgroup_extramargin
= 10;
514 m_width
= m_height
= 0;
516 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
519 m_chgInfo_changedProperty
= NULL
;
522 // -----------------------------------------------------------------------
525 // Initialize after parent etc. set
527 void wxPropertyGrid::Init2()
529 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
532 // Smaller controls on Mac
533 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
536 // Now create state, if one didn't exist already
537 // (wxPropertyGridManager might have created it for us).
540 m_pState
= CreateState();
541 m_pState
->m_pPropGrid
= this;
542 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
545 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
546 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
548 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
550 m_pState
->InitNonCatMode();
552 m_pState
->m_properties
= m_pState
->m_abcArray
;
555 GetClientSize(&m_width
,&m_height
);
557 #ifndef wxPG_ICON_WIDTH
558 // create two bitmap nodes for drawing
559 m_expandbmp
= new wxBitmap(expand_xpm
);
560 m_collbmp
= new wxBitmap(collapse_xpm
);
562 // calculate average font height for bitmap centering
564 m_iconWidth
= m_expandbmp
->GetWidth();
565 m_iconHeight
= m_expandbmp
->GetHeight();
568 m_curcursor
= wxCURSOR_ARROW
;
569 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
571 // adjust bitmap icon y position so they are centered
572 m_vspacing
= wxPG_DEFAULT_VSPACING
;
574 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
576 // Allocate cell datas indirectly by calling setter
577 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
578 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
582 // This helps with flicker
583 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
586 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
587 m_tlp
= ::wxGetTopLevelParent(this);
588 m_tlwHandler
= handler
;
589 m_tlp
->PushEventHandler(handler
);
591 // set virtual size to this window size
592 wxSize wndsize
= GetSize();
593 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
595 m_timeCreated
= ::wxGetLocalTimeMillis();
597 m_canvas
= new wxPGCanvas();
598 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
599 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
600 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
602 m_iFlags
|= wxPG_FL_INITIALIZED
;
604 m_ncWidth
= wndsize
.GetWidth();
606 // Need to call OnResize handler or size given in constructor/Create
608 wxSizeEvent
sizeEvent(wndsize
,0);
612 // -----------------------------------------------------------------------
614 wxPropertyGrid::~wxPropertyGrid()
618 DoSelectProperty(NULL
);
620 // This should do prevent things from going too badly wrong
621 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
623 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
624 m_canvas
->ReleaseMouse();
626 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
627 m_tlp
->RemoveEventHandler(handler
);
630 wxASSERT_MSG( !IsEditorsValueModified(),
631 wxS("Most recent change in property editor was lost!!! ")
632 wxS("(if you don't want this to happen, close your frames ")
633 wxS("and dialogs using Close(false).)") );
635 #if wxPG_DOUBLE_BUFFER
636 if ( m_doubleBuffer
)
637 delete m_doubleBuffer
;
642 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
645 delete m_cursorSizeWE
;
647 #ifndef wxPG_ICON_WIDTH
652 // Delete common value records
653 for ( i
=0; i
<m_commonValues
.size(); i
++ )
655 delete GetCommonValue(i
);
659 // -----------------------------------------------------------------------
661 bool wxPropertyGrid::Destroy()
663 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
664 m_canvas
->ReleaseMouse();
666 return wxScrolledWindow::Destroy();
669 // -----------------------------------------------------------------------
671 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
673 return new wxPropertyGridPageState();
676 // -----------------------------------------------------------------------
677 // wxPropertyGrid overridden wxWindow methods
678 // -----------------------------------------------------------------------
680 void wxPropertyGrid::SetWindowStyleFlag( long style
)
682 long old_style
= m_windowStyle
;
684 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
686 wxASSERT( m_pState
);
688 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
691 EnableCategories( true );
693 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
695 // Disable categories
696 EnableCategories( false );
698 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
704 PrepareAfterItemsAdded();
706 m_pState
->m_itemsAdded
= 1;
708 #if wxPG_SUPPORT_TOOLTIPS
709 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
715 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
716 SetToolTip ( tooltip );
717 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
720 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
725 m_canvas
->SetToolTip( NULL
);
730 wxScrolledWindow::SetWindowStyleFlag ( style
);
732 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
734 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
736 CalculateFontAndBitmapStuff( m_vspacing
);
742 // -----------------------------------------------------------------------
744 void wxPropertyGrid::Freeze()
748 wxScrolledWindow::Freeze();
753 // -----------------------------------------------------------------------
755 void wxPropertyGrid::Thaw()
761 wxScrolledWindow::Thaw();
762 RecalculateVirtualSize();
763 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
767 // Force property re-selection
769 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
773 // -----------------------------------------------------------------------
775 void wxPropertyGrid::SetExtraStyle( long exStyle
)
777 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
779 #if defined(__WXMSW__)
782 // Don't use WS_EX_COMPOSITED just now.
785 if ( m_iFlags & wxPG_FL_IN_MANAGER )
786 hWnd = (HWND)GetParent()->GetHWND();
788 hWnd = (HWND)GetHWND();
790 ::SetWindowLong( hWnd, GWL_EXSTYLE,
791 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
794 //#elif defined(__WXGTK20__)
796 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
797 // truly was double-buffered.
798 if ( !this->IsDoubleBuffered() )
800 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
804 #if wxPG_DOUBLE_BUFFER
805 delete m_doubleBuffer
;
806 m_doubleBuffer
= NULL
;
811 wxScrolledWindow::SetExtraStyle( exStyle
);
813 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
814 m_pState
->InitNonCatMode();
816 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
817 m_windowStyle
|= wxPG_TOOLTIPS
;
820 wxPGGlobalVars
->m_extraStyle
= exStyle
;
823 // -----------------------------------------------------------------------
825 // returns the best acceptable minimal size
826 wxSize
wxPropertyGrid::DoGetBestSize() const
828 int lineHeight
= wxMax(15, m_lineHeight
);
830 // don't make the grid too tall (limit height to 10 items) but don't
831 // make it too small neither
834 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
838 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
843 // -----------------------------------------------------------------------
844 // wxPropertyGrid Font and Colour Methods
845 // -----------------------------------------------------------------------
847 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
851 m_captionFont
= wxScrolledWindow::GetFont();
853 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
854 m_subgroup_extramargin
= x
+ (x
/2);
857 #if wxPG_USE_RENDERER_NATIVE
858 m_iconWidth
= wxPG_ICON_WIDTH
;
859 #elif wxPG_ICON_WIDTH
861 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
862 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
863 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
867 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
868 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
869 m_gutterWidth
= wxPG_GUTTER_MIN
;
872 if ( vspacing
<= 1 ) vdiv
= 12;
873 else if ( vspacing
>= 3 ) vdiv
= 3;
875 m_spacingy
= m_fontHeight
/ vdiv
;
876 if ( m_spacingy
< wxPG_YSPACING_MIN
)
877 m_spacingy
= wxPG_YSPACING_MIN
;
880 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
881 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
883 m_captionFont
.SetWeight(wxBOLD
);
884 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
886 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
889 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
890 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
893 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
895 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
896 RecalculateVirtualSize();
898 InvalidateBestSize();
901 // -----------------------------------------------------------------------
903 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
909 // -----------------------------------------------------------------------
911 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
912 int ga
= 1000, int ba
= 1000,
913 bool forceDifferent
= false)
920 // Recursion guard (allow 2 max)
921 static int isinside
= 0;
923 wxCHECK_MSG( isinside
< 3,
925 wxT("wxPGAdjustColour should not be recursively called more than once") );
933 if ( r2
>255 ) r2
= 255;
934 else if ( r2
<0) r2
= 0;
936 if ( g2
>255 ) g2
= 255;
937 else if ( g2
<0) g2
= 0;
939 if ( b2
>255 ) b2
= 255;
940 else if ( b2
<0) b2
= 0;
942 // Make sure they are somewhat different
943 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
944 dst
= wxPGAdjustColour(src
,-(ra
*2));
946 dst
= wxColour(r2
,g2
,b2
);
948 // Recursion guard (allow 2 max)
955 static int wxPGGetColAvg( const wxColour
& col
)
957 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
961 void wxPropertyGrid::RegainColours()
963 if ( !(m_coloursCustomized
& 0x0002) )
965 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
967 // Make sure colour is dark enough
969 int colDec
= wxPGGetColAvg(col
) - 230;
971 int colDec
= wxPGGetColAvg(col
) - 200;
974 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
977 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
980 if ( !(m_coloursCustomized
& 0x0001) )
981 m_colMargin
= m_colCapBack
;
983 if ( !(m_coloursCustomized
& 0x0004) )
990 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
991 m_colCapFore
= capForeCol
;
992 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
995 if ( !(m_coloursCustomized
& 0x0008) )
997 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
998 m_colPropBack
= bgCol
;
999 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1002 if ( !(m_coloursCustomized
& 0x0010) )
1004 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1005 m_colPropFore
= fgCol
;
1006 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1009 if ( !(m_coloursCustomized
& 0x0020) )
1010 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1012 if ( !(m_coloursCustomized
& 0x0040) )
1013 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1015 if ( !(m_coloursCustomized
& 0x0080) )
1016 m_colLine
= m_colCapBack
;
1018 if ( !(m_coloursCustomized
& 0x0100) )
1019 m_colDisPropFore
= m_colCapFore
;
1021 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1024 // -----------------------------------------------------------------------
1026 void wxPropertyGrid::ResetColours()
1028 m_coloursCustomized
= 0;
1035 // -----------------------------------------------------------------------
1037 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1039 // Must disable active editor.
1040 ClearSelection(false);
1042 bool res
= wxScrolledWindow::SetFont( font
);
1045 CalculateFontAndBitmapStuff( m_vspacing
);
1052 // -----------------------------------------------------------------------
1054 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1057 m_coloursCustomized
|= 0x80;
1061 // -----------------------------------------------------------------------
1063 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1066 m_coloursCustomized
|= 0x01;
1070 // -----------------------------------------------------------------------
1072 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1074 m_colPropBack
= col
;
1075 m_coloursCustomized
|= 0x08;
1077 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1082 // -----------------------------------------------------------------------
1084 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1086 m_colPropFore
= col
;
1087 m_coloursCustomized
|= 0x10;
1089 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1094 // -----------------------------------------------------------------------
1096 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1098 m_colEmptySpace
= col
;
1103 // -----------------------------------------------------------------------
1105 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1107 m_colDisPropFore
= col
;
1108 m_coloursCustomized
|= 0x100;
1112 // -----------------------------------------------------------------------
1114 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1117 m_coloursCustomized
|= 0x20;
1121 // -----------------------------------------------------------------------
1123 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1126 m_coloursCustomized
|= 0x40;
1130 // -----------------------------------------------------------------------
1132 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1135 m_coloursCustomized
|= 0x02;
1137 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1142 // -----------------------------------------------------------------------
1144 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1147 m_coloursCustomized
|= 0x04;
1149 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1154 // -----------------------------------------------------------------------
1155 // wxPropertyGrid property adding and removal
1156 // -----------------------------------------------------------------------
1158 void wxPropertyGrid::PrepareAfterItemsAdded()
1160 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1162 m_pState
->m_itemsAdded
= 0;
1164 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1165 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1167 RecalculateVirtualSize();
1170 // -----------------------------------------------------------------------
1171 // wxPropertyGrid property operations
1172 // -----------------------------------------------------------------------
1174 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1176 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1180 bool changed
= false;
1182 // Is it inside collapsed section?
1183 if ( !p
->IsVisible() )
1186 wxPGProperty
* parent
= p
->GetParent();
1187 wxPGProperty
* grandparent
= parent
->GetParent();
1189 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1190 Expand( grandparent
);
1198 GetViewStart(&vx
,&vy
);
1199 vy
*=wxPG_PIXELS_PER_UNIT
;
1205 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1206 m_iFlags
|= wxPG_FL_SCROLLED
;
1209 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1211 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1212 m_iFlags
|= wxPG_FL_SCROLLED
;
1222 // -----------------------------------------------------------------------
1223 // wxPropertyGrid helper methods called by properties
1224 // -----------------------------------------------------------------------
1226 // Control font changer helper.
1227 void wxPropertyGrid::SetCurControlBoldFont()
1229 wxASSERT( m_wndEditor
);
1230 m_wndEditor
->SetFont( m_captionFont
);
1233 // -----------------------------------------------------------------------
1235 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1238 #if wxPG_SMALL_SCREEN
1239 // On small-screen devices, always show dialogs with default position and size.
1240 return wxDefaultPosition
;
1242 int splitterX
= GetSplitterPosition();
1246 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1248 ImprovedClientToScreen( &x
, &y
);
1250 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1251 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1258 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1268 new_y
= y
+ m_lineHeight
;
1270 return wxPoint(new_x
,new_y
);
1274 // -----------------------------------------------------------------------
1276 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1278 if ( src_str
.length() == 0 )
1284 bool prev_is_slash
= false;
1286 wxString::const_iterator i
= src_str
.begin();
1290 for ( ; i
!= src_str
.end(); ++i
)
1294 if ( a
!= wxS('\\') )
1296 if ( !prev_is_slash
)
1302 if ( a
== wxS('n') )
1305 dst_str
<< wxS('\n');
1307 dst_str
<< wxS('\n');
1310 else if ( a
== wxS('t') )
1311 dst_str
<< wxS('\t');
1315 prev_is_slash
= false;
1319 if ( prev_is_slash
)
1321 dst_str
<< wxS('\\');
1322 prev_is_slash
= false;
1326 prev_is_slash
= true;
1333 // -----------------------------------------------------------------------
1335 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1337 if ( src_str
.length() == 0 )
1343 wxString::const_iterator i
= src_str
.begin();
1344 wxUniChar prev_a
= wxS('\0');
1348 for ( ; i
!= src_str
.end(); ++i
)
1352 if ( a
>= wxS(' ') )
1354 // This surely is not something that requires an escape sequence.
1359 // This might need...
1360 if ( a
== wxS('\r') )
1362 // DOS style line end.
1363 // Already taken care below
1365 else if ( a
== wxS('\n') )
1366 // UNIX style line end.
1367 dst_str
<< wxS("\\n");
1368 else if ( a
== wxS('\t') )
1370 dst_str
<< wxS('\t');
1373 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1383 // -----------------------------------------------------------------------
1385 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1392 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1395 // -----------------------------------------------------------------------
1396 // wxPropertyGrid graphics related methods
1397 // -----------------------------------------------------------------------
1399 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1403 // Update everything inside the box
1404 wxRect r
= GetUpdateRegion().GetBox();
1406 dc
.SetPen(m_colEmptySpace
);
1407 dc
.SetBrush(m_colEmptySpace
);
1408 dc
.DrawRectangle(r
);
1411 // -----------------------------------------------------------------------
1413 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1414 wxPGProperty
* property
) const
1416 // Prepare rectangle to be used
1418 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1419 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1421 #if (wxPG_USE_RENDERER_NATIVE)
1423 #elif wxPG_ICON_WIDTH
1424 // Drawing expand/collapse button manually
1425 dc
.SetPen(m_colPropFore
);
1426 if ( property
->IsCategory() )
1427 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1429 dc
.SetBrush(m_colPropBack
);
1431 dc
.DrawRectangle( r
);
1432 int _y
= r
.y
+(m_iconWidth
/2);
1433 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1438 if ( property
->IsExpanded() )
1440 // wxRenderer functions are non-mutating in nature, so it
1441 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1442 // Hopefully this does not cause problems.
1443 #if (wxPG_USE_RENDERER_NATIVE)
1444 wxRendererNative::Get().DrawTreeItemButton(
1450 #elif wxPG_ICON_WIDTH
1459 #if (wxPG_USE_RENDERER_NATIVE)
1460 wxRendererNative::Get().DrawTreeItemButton(
1466 #elif wxPG_ICON_WIDTH
1467 int _x
= r
.x
+(m_iconWidth
/2);
1468 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1474 #if (wxPG_USE_RENDERER_NATIVE)
1476 #elif wxPG_ICON_WIDTH
1479 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1483 // -----------------------------------------------------------------------
1486 // This is the one called by OnPaint event handler and others.
1487 // topy and bottomy are already unscrolled (ie. physical)
1489 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1491 unsigned int bottomy
,
1492 const wxRect
* clipRect
)
1494 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1496 m_pState
->EnsureVirtualHeight();
1498 wxRect tempClipRect
;
1501 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1502 clipRect
= &tempClipRect
;
1505 // items added check
1506 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1508 int paintFinishY
= 0;
1510 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1513 bool isBuffered
= false;
1515 #if wxPG_DOUBLE_BUFFER
1516 wxMemoryDC
* bufferDC
= NULL
;
1518 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1520 if ( !m_doubleBuffer
)
1522 paintFinishY
= clipRect
->y
;
1527 bufferDC
= new wxMemoryDC();
1529 // If nothing was changed, then just copy from double-buffer
1530 bufferDC
->SelectObject( *m_doubleBuffer
);
1540 dc
.SetClippingRegion( *clipRect
);
1541 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1544 #if wxPG_DOUBLE_BUFFER
1547 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1548 bufferDC
, 0, 0, wxCOPY
);
1549 dc
.DestroyClippingRegion(); // Is this really necessary?
1555 // Clear area beyond bottomY?
1556 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1558 dc
.SetPen(m_colEmptySpace
);
1559 dc
.SetBrush(m_colEmptySpace
);
1560 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1564 // -----------------------------------------------------------------------
1566 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1567 const wxRect
* clipRect
,
1568 bool isBuffered
) const
1570 const wxPGProperty
* firstItem
;
1571 const wxPGProperty
* lastItem
;
1573 firstItem
= DoGetItemAtY(clipRect
->y
);
1574 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1577 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1579 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1582 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1583 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1585 int lh
= m_lineHeight
;
1588 int lastItemBottomY
;
1590 firstItemTopY
= clipRect
->y
;
1591 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1593 // Align y coordinates to item boundaries
1594 firstItemTopY
-= firstItemTopY
% lh
;
1595 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1596 lastItemBottomY
-= 1;
1598 // Entire range outside scrolled, visible area?
1599 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1602 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1606 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1607 firstItem->GetLabel().c_str(),
1608 lastItem->GetLabel().c_str(),
1609 (int)(lastItemBottomY - firstItemTopY),
1611 (unsigned long)clipRect );
1616 long windowStyle
= m_windowStyle
;
1622 // With wxPG_DOUBLE_BUFFER, do double buffering
1623 // - buffer's y = 0, so align cliprect and coordinates to that
1625 #if wxPG_DOUBLE_BUFFER
1631 xRelMod
= clipRect
->x
;
1632 yRelMod
= clipRect
->y
;
1635 // clipRect conversion
1640 firstItemTopY
-= yRelMod
;
1641 lastItemBottomY
-= yRelMod
;
1644 wxUnusedVar(isBuffered
);
1647 int x
= m_marginWidth
- xRelMod
;
1649 wxFont normalFont
= GetFont();
1651 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1653 bool isEnabled
= IsEnabled();
1656 // Prepare some pens and brushes that are often changed to.
1659 wxBrush
marginBrush(m_colMargin
);
1660 wxPen
marginPen(m_colMargin
);
1661 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1662 wxPen
linepen(m_colLine
,1,wxSOLID
);
1664 // pen that has same colour as text
1665 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1668 // Clear margin with background colour
1670 dc
.SetBrush( marginBrush
);
1671 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1673 dc
.SetPen( *wxTRANSPARENT_PEN
);
1674 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1677 const wxPGProperty
* selected
= m_selected
;
1678 const wxPropertyGridPageState
* state
= m_pState
;
1680 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1681 bool wasSelectedPainted
= false;
1684 // TODO: Only render columns that are within clipping region.
1686 dc
.SetFont(normalFont
);
1688 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1689 int endScanBottomY
= lastItemBottomY
+ lh
;
1690 int y
= firstItemTopY
;
1693 // Pregenerate list of visible properties.
1694 wxArrayPGProperty visPropArray
;
1695 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1697 for ( ; !it
.AtEnd(); it
.Next() )
1699 const wxPGProperty
* p
= *it
;
1701 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1703 visPropArray
.push_back((wxPGProperty
*)p
);
1705 if ( y
> endScanBottomY
)
1712 visPropArray
.push_back(NULL
);
1714 wxPGProperty
* nextP
= visPropArray
[0];
1716 int gridWidth
= state
->m_width
;
1719 for ( unsigned int arrInd
=1;
1720 nextP
&& y
<= lastItemBottomY
;
1723 wxPGProperty
* p
= nextP
;
1724 nextP
= visPropArray
[arrInd
];
1726 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1727 int textMarginHere
= x
;
1728 int renderFlags
= 0;
1730 int greyDepth
= m_marginWidth
;
1731 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1732 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1734 int greyDepthX
= greyDepth
- xRelMod
;
1736 // Use basic depth if in non-categoric mode and parent is base array.
1737 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1739 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1742 // Paint margin area
1743 dc
.SetBrush(marginBrush
);
1744 dc
.SetPen(marginPen
);
1745 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1747 dc
.SetPen( linepen
);
1752 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1758 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1760 sx
+= state
->m_colWidths
[si
];
1761 dc
.DrawLine( sx
, y
, sx
, y2
);
1764 // Horizontal Line, below
1765 // (not if both this and next is category caption)
1766 if ( p
->IsCategory() &&
1767 nextP
&& nextP
->IsCategory() )
1768 dc
.SetPen(m_colCapBack
);
1770 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1773 // Need to override row colours?
1777 if ( p
!= selected
)
1779 // Disabled may get different colour.
1780 if ( !p
->IsEnabled() )
1782 renderFlags
|= wxPGCellRenderer::Disabled
|
1783 wxPGCellRenderer::DontUseCellFgCol
;
1784 rowFgCol
= m_colDisPropFore
;
1789 renderFlags
|= wxPGCellRenderer::Selected
;
1791 if ( !p
->IsCategory() )
1793 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1794 wxPGCellRenderer::DontUseCellBgCol
;
1796 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1797 wasSelectedPainted
= true;
1800 // Selected gets different colour.
1801 if ( reallyFocused
)
1803 rowFgCol
= m_colSelFore
;
1804 rowBgCol
= m_colSelBack
;
1806 else if ( isEnabled
)
1808 rowFgCol
= m_colPropFore
;
1809 rowBgCol
= m_colMargin
;
1813 rowFgCol
= m_colDisPropFore
;
1814 rowBgCol
= m_colSelBack
;
1821 if ( rowBgCol
.IsOk() )
1822 rowBgBrush
= wxBrush(rowBgCol
);
1824 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1825 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1828 // Fill additional margin area with background colour of first cell
1829 if ( greyDepthX
< textMarginHere
)
1831 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1833 wxPGCell
& cell
= p
->GetCell(0);
1834 rowBgCol
= cell
.GetBgCol();
1835 rowBgBrush
= wxBrush(rowBgCol
);
1837 dc
.SetBrush(rowBgBrush
);
1838 dc
.SetPen(rowBgCol
);
1839 dc
.DrawRectangle(greyDepthX
+1, y
,
1840 textMarginHere
-greyDepthX
, lh
-1);
1843 bool fontChanged
= false;
1845 // Expander button rectangle
1846 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1851 if ( p
->IsCategory() )
1853 // Captions have their cell areas merged as one
1854 dc
.SetFont(m_captionFont
);
1856 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1858 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1860 dc
.SetBrush(rowBgBrush
);
1861 dc
.SetPen(rowBgCol
);
1864 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1866 dc
.SetTextForeground(rowFgCol
);
1869 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1870 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1873 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1874 DrawExpanderButton( dc
, butRect
, p
);
1878 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1880 dc
.SetFont(m_captionFont
);
1886 int nextCellWidth
= state
->m_colWidths
[0] -
1887 (greyDepthX
- m_marginWidth
);
1888 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1889 int textXAdd
= textMarginHere
- greyDepthX
;
1891 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1893 cellRect
.width
= nextCellWidth
- 1;
1895 bool ctrlCell
= false;
1896 int cellRenderFlags
= renderFlags
;
1899 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1900 DrawExpanderButton( dc
, butRect
, p
);
1903 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1905 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1906 dc
.SetBrush(editorBgCol
);
1907 dc
.SetPen(editorBgCol
);
1908 dc
.SetTextForeground(m_colPropFore
);
1909 dc
.DrawRectangle(cellRect
);
1911 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1916 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1918 dc
.SetBrush(rowBgBrush
);
1919 dc
.SetPen(rowBgCol
);
1922 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1924 dc
.SetTextForeground(rowFgCol
);
1928 dc
.SetClippingRegion(cellRect
);
1930 cellRect
.x
+= textXAdd
;
1931 cellRect
.width
-= textXAdd
;
1936 wxPGCellRenderer
* renderer
;
1937 int cmnVal
= p
->GetCommonValue();
1938 if ( cmnVal
== -1 || ci
!= 1 )
1940 renderer
= p
->GetCellRenderer(ci
);
1941 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1946 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1947 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1952 cellX
+= state
->m_colWidths
[ci
];
1953 if ( ci
< (state
->m_colWidths
.size()-1) )
1954 nextCellWidth
= state
->m_colWidths
[ci
+1];
1956 dc
.DestroyClippingRegion(); // Is this really necessary?
1962 dc
.SetFont(normalFont
);
1967 // Refresh editor controls (seems not needed on msw)
1968 // NOTE: This code is mandatory for GTK!
1969 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1970 if ( wasSelectedPainted
)
1973 m_wndEditor
->Refresh();
1975 m_wndEditor2
->Refresh();
1982 // -----------------------------------------------------------------------
1984 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1988 if ( m_width
< 10 || m_height
< 10 ||
1989 !m_pState
->m_properties
->GetChildCount() ||
1991 return wxRect(0,0,0,0);
1996 // Return rect which encloses the given property range
1998 int visTop
= p1
->GetY();
2001 visBottom
= p2
->GetY() + m_lineHeight
;
2003 visBottom
= m_height
+ visTop
;
2005 // If seleced property is inside the range, we'll extend the range to include
2007 wxPGProperty
* selected
= m_selected
;
2010 int selectedY
= selected
->GetY();
2011 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2013 wxWindow
* editor
= GetEditorControl();
2016 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2017 if ( visBottom2
> visBottom
)
2018 visBottom
= visBottom2
;
2023 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2026 // -----------------------------------------------------------------------
2028 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2033 if ( m_pState
->m_itemsAdded
)
2034 PrepareAfterItemsAdded();
2036 wxRect r
= GetPropertyRect(p1
, p2
);
2039 m_canvas
->RefreshRect(r
);
2043 // -----------------------------------------------------------------------
2045 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2047 if ( p
== m_selected
)
2048 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2050 DrawItemAndChildren(p
);
2053 // -----------------------------------------------------------------------
2055 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2060 // Draw item, children, and parent too, if it is not category
2061 wxPGProperty
* parent
= p
->GetParent();
2064 !parent
->IsCategory() &&
2065 parent
->GetParent() )
2068 parent
= parent
->GetParent();
2071 DrawItemAndChildren(p
);
2074 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2076 wxCHECK_RET( p
, wxT("invalid property id") );
2078 // Do not draw if in non-visible page
2079 if ( p
->GetParentState() != m_pState
)
2082 // do not draw a single item if multiple pending
2083 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2086 // Update child control.
2087 if ( m_selected
&& m_selected
->GetParent() == p
)
2090 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2092 DrawItems(p
, lastDrawn
);
2095 // -----------------------------------------------------------------------
2097 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2098 const wxRect
*rect
)
2100 PrepareAfterItemsAdded();
2102 wxWindow::Refresh(false);
2104 // TODO: Coordinate translation
2105 m_canvas
->Refresh(false, rect
);
2107 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2108 // I think this really helps only GTK+1.2
2109 if ( m_wndEditor
) m_wndEditor
->Refresh();
2110 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2114 // -----------------------------------------------------------------------
2115 // wxPropertyGrid global operations
2116 // -----------------------------------------------------------------------
2118 void wxPropertyGrid::Clear()
2120 m_pState
->DoClear();
2126 RecalculateVirtualSize();
2128 // Need to clear some area at the end
2130 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2133 // -----------------------------------------------------------------------
2135 bool wxPropertyGrid::EnableCategories( bool enable
)
2137 ClearSelection(false);
2142 // Enable categories
2145 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2150 // Disable categories
2152 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2155 if ( !m_pState
->EnableCategories(enable
) )
2160 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2162 m_pState
->m_itemsAdded
= 1; // force
2163 PrepareAfterItemsAdded();
2167 m_pState
->m_itemsAdded
= 1;
2169 // No need for RecalculateVirtualSize() here - it is already called in
2170 // wxPropertyGridPageState method above.
2177 // -----------------------------------------------------------------------
2179 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2181 wxASSERT( pNewState
);
2182 wxASSERT( pNewState
->GetGrid() );
2184 if ( pNewState
== m_pState
)
2187 wxPGProperty
* oldSelection
= m_selected
;
2189 ClearSelection(false);
2191 m_pState
->m_selected
= oldSelection
;
2193 bool orig_mode
= m_pState
->IsInNonCatMode();
2194 bool new_state_mode
= pNewState
->IsInNonCatMode();
2196 m_pState
= pNewState
;
2199 int pgWidth
= GetClientSize().x
;
2200 if ( HasVirtualWidth() )
2202 int minWidth
= pgWidth
;
2203 if ( pNewState
->m_width
< minWidth
)
2205 pNewState
->m_width
= minWidth
;
2206 pNewState
->CheckColumnWidths();
2212 // Just in case, fully re-center splitter
2213 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2214 pNewState
->m_fSplitterX
= -1.0;
2216 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2221 // If necessary, convert state to correct mode.
2222 if ( orig_mode
!= new_state_mode
)
2224 // This should refresh as well.
2225 EnableCategories( orig_mode
?false:true );
2227 else if ( !m_frozen
)
2229 // Refresh, if not frozen.
2230 m_pState
->PrepareAfterItemsAdded();
2233 if ( m_pState
->m_selected
)
2234 DoSelectProperty( m_pState
->m_selected
);
2236 RecalculateVirtualSize(0);
2240 m_pState
->m_itemsAdded
= 1;
2243 // -----------------------------------------------------------------------
2245 // Call to SetSplitterPosition will always disable splitter auto-centering
2246 // if parent window is shown.
2247 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2249 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2252 wxPropertyGridPageState
* state
= m_pState
;
2254 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2259 CorrectEditorWidgetSizeX();
2265 // -----------------------------------------------------------------------
2267 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2269 SetSplitterPosition( m_width
/2, true );
2270 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2271 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2274 // -----------------------------------------------------------------------
2275 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2276 // -----------------------------------------------------------------------
2278 // Returns nearest paint visible property (such that will be painted unless
2279 // window is scrolled or resized). If given property is paint visible, then
2280 // it itself will be returned
2281 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2283 int vx
,vy1
;// Top left corner of client
2284 GetViewStart(&vx
,&vy1
);
2285 vy1
*= wxPG_PIXELS_PER_UNIT
;
2287 int vy2
= vy1
+ m_height
;
2288 int propY
= p
->GetY2(m_lineHeight
);
2290 if ( (propY
+ m_lineHeight
) < vy1
)
2293 return DoGetItemAtY( vy1
);
2295 else if ( propY
> vy2
)
2298 return DoGetItemAtY( vy2
);
2301 // Itself paint visible
2306 // -----------------------------------------------------------------------
2307 // Methods related to change in value, value modification and sending events
2308 // -----------------------------------------------------------------------
2310 // commits any changes in editor of selected property
2311 // return true if validation did not fail
2312 // flags are same as with DoSelectProperty
2313 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2315 // Committing already?
2316 if ( m_inCommitChangesFromEditor
)
2319 // Don't do this if already processing editor event. It might
2320 // induce recursive dialogs and crap like that.
2321 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2323 if ( m_inDoPropertyChanged
)
2330 IsEditorsValueModified() &&
2331 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2334 m_inCommitChangesFromEditor
= 1;
2336 wxVariant
variant(m_selected
->GetValueRef());
2337 bool valueIsPending
= false;
2339 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2340 // due to another window getting focus
2341 wxWindow
* oldFocus
= m_curFocused
;
2343 bool validationFailure
= false;
2344 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2346 m_chgInfo_changedProperty
= NULL
;
2348 // If truly modified, schedule value as pending.
2349 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2351 if ( DoEditorValidate() &&
2352 PerformValidation(m_selected
, variant
) )
2354 valueIsPending
= true;
2358 validationFailure
= true;
2363 EditorsValueWasNotModified();
2368 m_inCommitChangesFromEditor
= 0;
2370 if ( validationFailure
&& !forceSuccess
)
2374 oldFocus
->SetFocus();
2375 m_curFocused
= oldFocus
;
2378 res
= OnValidationFailure(m_selected
, variant
);
2380 // Now prevent further validation failure messages
2383 EditorsValueWasNotModified();
2384 OnValidationFailureReset(m_selected
);
2387 else if ( valueIsPending
)
2389 DoPropertyChanged( m_selected
, flags
);
2390 EditorsValueWasNotModified();
2399 // -----------------------------------------------------------------------
2401 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2405 // Runs all validation functionality.
2406 // Returns true if value passes all tests.
2409 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2411 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2413 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2418 // Adapt list to child values, if necessary
2419 wxVariant listValue
= pendingValue
;
2420 wxVariant
* pPendingValue
= &pendingValue
;
2421 wxVariant
* pList
= NULL
;
2423 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2424 // string value, then we need treat as it was changed instead
2425 // (or, in addition, as is the case with composite string parent).
2426 // This includes creating list variant for child values.
2428 wxPGProperty
* pwc
= p
->GetParent();
2429 wxPGProperty
* changedProperty
= p
;
2430 wxPGProperty
* baseChangedProperty
= changedProperty
;
2431 wxVariant bcpPendingList
;
2433 listValue
= pendingValue
;
2434 listValue
.SetName(p
->GetBaseName());
2437 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2439 wxVariantList tempList
;
2440 wxVariant
lv(tempList
, pwc
->GetBaseName());
2441 lv
.Append(listValue
);
2443 pPendingValue
= &listValue
;
2445 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2447 baseChangedProperty
= pwc
;
2448 bcpPendingList
= lv
;
2451 changedProperty
= pwc
;
2452 pwc
= pwc
->GetParent();
2456 wxPGProperty
* evtChangingProperty
= changedProperty
;
2458 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2460 value
= *pPendingValue
;
2464 // Convert list to child values
2465 pList
= pPendingValue
;
2466 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2469 wxVariant evtChangingValue
= value
;
2471 if ( flags
& SendEvtChanging
)
2473 // FIXME: After proper ValueToString()s added, remove
2474 // this. It is just a temporary fix, as evt_changing
2475 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2476 // (unless it is selected, and textctrl editor is open).
2477 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2479 evtChangingProperty
= baseChangedProperty
;
2480 if ( evtChangingProperty
!= p
)
2482 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2486 evtChangingValue
= pendingValue
;
2490 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2492 if ( changedProperty
== m_selected
)
2494 wxWindow
* editor
= GetEditorControl();
2495 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2496 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2500 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2505 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2506 m_chgInfo_changedProperty
= changedProperty
;
2507 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2508 m_chgInfo_pendingValue
= value
;
2511 m_chgInfo_valueList
= *pList
;
2513 m_chgInfo_valueList
.MakeNull();
2515 // If changedProperty is not property which value was edited,
2516 // then call wxPGProperty::ValidateValue() for that as well.
2517 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2519 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2523 if ( flags
& SendEvtChanging
)
2525 // SendEvent returns true if event was vetoed
2526 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2530 if ( flags
& IsStandaloneValidation
)
2532 // If called in 'generic' context, we need to reset
2533 // m_chgInfo_changedProperty and write back translated value.
2534 m_chgInfo_changedProperty
= NULL
;
2535 pendingValue
= value
;
2541 // -----------------------------------------------------------------------
2543 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2545 if ( !msg
.length() )
2549 if ( !wxPGGlobalVars
->m_offline
)
2551 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2554 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2557 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2560 pStatusBar
->SetStatusText(msg
);
2568 ::wxMessageBox(msg
, _T("Property Error"));
2571 // -----------------------------------------------------------------------
2573 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2574 wxVariant
& invalidValue
)
2576 wxWindow
* editor
= GetEditorControl();
2578 // First call property's handler
2579 property
->OnValidationFailure(invalidValue
);
2581 bool res
= DoOnValidationFailure(property
, invalidValue
);
2584 // For non-wxTextCtrl editors, we do need to revert the value
2585 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2586 property
== m_selected
)
2588 property
->GetEditorClass()->UpdateControl(property
, editor
);
2591 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2596 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2598 int vfb
= m_validationInfo
.m_failureBehavior
;
2600 if ( vfb
& wxPG_VFB_BEEP
)
2603 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2604 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2606 unsigned int colCount
= m_pState
->GetColumnCount();
2608 // We need backup marked property's cells
2609 m_propCellsBackup
= property
->m_cells
;
2611 wxColour vfbFg
= *wxWHITE
;
2612 wxColour vfbBg
= *wxRED
;
2614 property
->EnsureCells(colCount
);
2616 for ( unsigned int i
=0; i
<colCount
; i
++ )
2618 wxPGCell
& cell
= property
->m_cells
[i
];
2619 cell
.SetFgCol(vfbFg
);
2620 cell
.SetBgCol(vfbBg
);
2623 DrawItemAndChildren(property
);
2625 if ( property
== m_selected
)
2627 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2629 wxWindow
* editor
= GetEditorControl();
2632 editor
->SetForegroundColour(vfbFg
);
2633 editor
->SetBackgroundColour(vfbBg
);
2638 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2640 wxString msg
= m_validationInfo
.m_failureMessage
;
2642 if ( !msg
.length() )
2643 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2645 DoShowPropertyError(property
, msg
);
2648 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2651 // -----------------------------------------------------------------------
2653 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2655 int vfb
= m_validationInfo
.m_failureBehavior
;
2657 if ( vfb
& wxPG_VFB_MARK_CELL
)
2660 property
->m_cells
= m_propCellsBackup
;
2662 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2664 if ( property
== m_selected
&& GetEditorControl() )
2666 // Calling this will recreate the control, thus resetting its colour
2667 RefreshProperty(property
);
2671 DrawItemAndChildren(property
);
2676 // -----------------------------------------------------------------------
2678 // flags are same as with DoSelectProperty
2679 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2681 if ( m_inDoPropertyChanged
)
2684 wxWindow
* editor
= GetEditorControl();
2686 m_pState
->m_anyModified
= 1;
2688 m_inDoPropertyChanged
= 1;
2690 // Maybe need to update control
2691 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2693 // These values were calculated in PerformValidation()
2694 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2695 wxVariant value
= m_chgInfo_pendingValue
;
2697 wxPGProperty
* topPaintedProperty
= changedProperty
;
2699 while ( !topPaintedProperty
->IsCategory() &&
2700 !topPaintedProperty
->IsRoot() )
2702 topPaintedProperty
= topPaintedProperty
->GetParent();
2705 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2707 // Set as Modified (not if dragging just began)
2708 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2710 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2711 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2714 SetCurControlBoldFont();
2720 // Propagate updates to parent(s)
2722 wxPGProperty
* prevPwc
= NULL
;
2724 while ( prevPwc
!= topPaintedProperty
)
2726 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2728 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2731 SetCurControlBoldFont();
2735 pwc
= pwc
->GetParent();
2738 // Draw the actual property
2739 DrawItemAndChildren( topPaintedProperty
);
2742 // If value was set by wxPGProperty::OnEvent, then update the editor
2744 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2750 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2751 if ( m_wndEditor
) m_wndEditor
->Refresh();
2752 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2757 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2759 // If top parent has composite string value, then send to child parents,
2760 // starting from baseChangedProperty.
2761 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2763 pwc
= m_chgInfo_baseChangedProperty
;
2765 while ( pwc
!= changedProperty
)
2767 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2768 pwc
= pwc
->GetParent();
2772 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2774 m_inDoPropertyChanged
= 0;
2779 // -----------------------------------------------------------------------
2781 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2783 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2785 m_chgInfo_changedProperty
= NULL
;
2787 if ( PerformValidation(p
, newValue
) )
2789 DoPropertyChanged(p
);
2794 OnValidationFailure(p
, newValue
);
2800 // -----------------------------------------------------------------------
2802 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2804 wxPGProperty
* prop
= GetSelectedProperty();
2807 return wxNullVariant
;
2809 wxTextCtrl
* tc
= GetEditorTextCtrl();
2810 wxVariant value
= prop
->GetValue();
2812 if ( !tc
|| !IsEditorsValueModified() )
2815 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2818 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2819 return prop
->GetValue();
2824 // -----------------------------------------------------------------------
2826 // Runs wxValidator for the selected property
2827 bool wxPropertyGrid::DoEditorValidate()
2832 // -----------------------------------------------------------------------
2834 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2836 wxPGProperty
* selected
= m_selected
;
2838 // Somehow, event is handled after property has been deselected.
2839 // Possibly, but very rare.
2843 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2846 wxVariant
pendingValue(selected
->GetValueRef());
2847 wxWindow
* wnd
= GetEditorControl();
2848 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2850 bool wasUnspecified
= selected
->IsValueUnspecified();
2851 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2852 bool valueIsPending
= false;
2854 m_chgInfo_changedProperty
= NULL
;
2856 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2859 // Filter out excess wxTextCtrl modified events
2860 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2862 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2864 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2866 wxString newTcValue
= tc
->GetValue();
2867 if ( m_prevTcValue
== newTcValue
)
2870 m_prevTcValue
= newTcValue
;
2873 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2875 bool validationFailure
= false;
2876 bool buttonWasHandled
= false;
2879 // Try common button handling
2880 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2882 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2886 buttonWasHandled
= true;
2887 // Store as res2, as previously (and still currently alternatively)
2888 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2889 // in wxPGProperty::OnEvent().
2890 adapter
->ShowDialog( this, selected
);
2895 if ( !buttonWasHandled
)
2897 if ( wnd
|| m_wndEditor2
)
2899 // First call editor class' event handler.
2900 const wxPGEditor
* editor
= selected
->GetEditorClass();
2902 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2904 // If changes, validate them
2905 if ( DoEditorValidate() )
2907 if ( editor
->GetValueFromControl( pendingValue
,
2910 valueIsPending
= true;
2914 validationFailure
= true;
2919 // Then the property's custom handler (must be always called, unless
2920 // validation failed).
2921 if ( !validationFailure
)
2922 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2925 // SetValueInEvent(), as called in one of the functions referred above
2926 // overrides editor's value.
2927 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2929 valueIsPending
= true;
2930 pendingValue
= m_changeInEventValue
;
2931 selFlags
|= wxPG_SEL_DIALOGVAL
;
2934 if ( !validationFailure
&& valueIsPending
)
2935 if ( !PerformValidation(m_selected
, pendingValue
) )
2936 validationFailure
= true;
2938 if ( validationFailure
)
2940 OnValidationFailure(selected
, pendingValue
);
2942 else if ( valueIsPending
)
2944 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2946 DoPropertyChanged(selected
, selFlags
);
2947 EditorsValueWasNotModified();
2949 // Regardless of editor type, unfocus editor on
2950 // text-editing related enter press.
2951 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2958 // No value after all
2960 // Regardless of editor type, unfocus editor on
2961 // text-editing related enter press.
2962 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2967 // Let unhandled button click events go to the parent
2968 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2970 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2971 GetEventHandler()->AddPendingEvent(evt
);
2975 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2978 // -----------------------------------------------------------------------
2979 // wxPropertyGrid editor control helper methods
2980 // -----------------------------------------------------------------------
2982 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2984 int itemy
= p
->GetY2(m_lineHeight
);
2986 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2987 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2988 int imageOffset
= 0;
2990 // TODO: If custom image detection changes from current, change this.
2991 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
2993 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2994 int iw
= p
->OnMeasureImage().x
;
2996 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
2997 imageOffset
= p
->GetImageOffset(iw
);
3002 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3004 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3009 // -----------------------------------------------------------------------
3011 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3013 wxSize sz
= GetImageSize(p
, item
);
3014 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3015 wxPG_CUSTOM_IMAGE_SPACINGY
,
3020 // return size of custom paint image
3021 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3023 // If called with NULL property, then return default image
3024 // size for properties that use image.
3026 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3028 wxSize cis
= p
->OnMeasureImage(item
);
3030 int choiceCount
= p
->m_choices
.GetCount();
3031 int comVals
= p
->GetDisplayedCommonValueCount();
3032 if ( item
>= choiceCount
&& comVals
> 0 )
3034 unsigned int cvi
= item
-choiceCount
;
3035 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3037 else if ( item
>= 0 && choiceCount
== 0 )
3038 return wxSize(0, 0);
3043 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3048 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3055 // -----------------------------------------------------------------------
3057 // takes scrolling into account
3058 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3061 GetViewStart(&vx
,&vy
);
3062 vy
*=wxPG_PIXELS_PER_UNIT
;
3063 vx
*=wxPG_PIXELS_PER_UNIT
;
3066 ClientToScreen( px
, py
);
3069 // -----------------------------------------------------------------------
3071 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3074 GetViewStart(&pt2
.x
,&pt2
.y
);
3075 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3076 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3080 return m_pState
->HitTest(pt2
);
3083 // -----------------------------------------------------------------------
3085 // custom set cursor
3086 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3088 if ( type
== m_curcursor
&& !override
) return;
3090 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3092 if ( type
== wxCURSOR_SIZEWE
)
3093 cursor
= m_cursorSizeWE
;
3095 m_canvas
->SetCursor( *cursor
);
3100 // -----------------------------------------------------------------------
3101 // wxPropertyGrid property selection, editor creation
3102 // -----------------------------------------------------------------------
3105 // This class forwards events from property editor controls to wxPropertyGrid.
3106 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3109 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3110 : wxEvtHandler(), m_propGrid(propGrid
)
3114 virtual ~wxPropertyGridEditorEventForwarder()
3119 bool ProcessEvent( wxEvent
& event
)
3124 m_propGrid
->HandleCustomEditorEvent(event
);
3126 return wxEvtHandler::ProcessEvent(event
);
3129 wxPropertyGrid
* m_propGrid
;
3132 // Setups event handling for child control
3133 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3135 wxWindowID id
= argWnd
->GetId();
3137 if ( argWnd
== m_wndEditor
)
3139 argWnd
->Connect(id
, wxEVT_MOTION
,
3140 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3142 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3143 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3145 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3146 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3148 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3149 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3151 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3152 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3154 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3155 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3159 wxPropertyGridEditorEventForwarder
* forwarder
;
3160 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3161 argWnd
->PushEventHandler(forwarder
);
3163 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3164 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3168 void wxPropertyGrid::FreeEditors()
3171 // Return focus back to canvas from children (this is required at least for
3172 // GTK+, which, unlike Windows, clears focus when control is destroyed
3173 // instead of moving it to closest parent).
3174 wxWindow
* focus
= wxWindow::FindFocus();
3177 wxWindow
* parent
= focus
->GetParent();
3180 if ( parent
== m_canvas
)
3185 parent
= parent
->GetParent();
3189 // Do not free editors immediately if processing events
3192 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3193 m_wndEditor2
->Hide();
3194 wxPendingDelete
.Append( handler
);
3195 wxPendingDelete
.Append( m_wndEditor2
);
3196 m_wndEditor2
= NULL
;
3201 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3202 m_wndEditor
->Hide();
3203 wxPendingDelete
.Append( handler
);
3204 wxPendingDelete
.Append( m_wndEditor
);
3209 // Call with NULL to de-select property
3210 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3214 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3215 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3217 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3220 if ( m_inDoSelectProperty
)
3223 m_inDoSelectProperty
= 1;
3225 wxPGProperty
* prev
= m_selected
;
3229 m_inDoSelectProperty
= 0;
3235 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3237 wxPrintf( "None selected\n" );
3240 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3242 wxPrintf( "P = NULL\n" );
3245 // If we are frozen, then just set the values.
3248 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3249 m_editorFocused
= 0;
3252 m_pState
->m_selected
= p
;
3254 // If frozen, always free controls. But don't worry, as Thaw will
3255 // recall SelectProperty to recreate them.
3258 // Prevent any further selection measures in this call
3264 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3266 // Only set focus if not deselecting
3269 if ( flags
& wxPG_SEL_FOCUS
)
3273 m_wndEditor
->SetFocus();
3274 m_editorFocused
= 1;
3283 m_inDoSelectProperty
= 0;
3288 // First, deactivate previous
3292 OnValidationFailureReset(m_selected
);
3294 // Must double-check if this is an selected in case of forceswitch
3297 if ( !CommitChangesFromEditor(flags
) )
3299 // Validation has failed, so we can't exit the previous editor
3300 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3301 // _("Invalid Value"),wxOK|wxICON_ERROR);
3302 m_inDoSelectProperty
= 0;
3311 m_pState
->m_selected
= NULL
;
3313 // We need to always fully refresh the grid here
3316 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3317 EditorsValueWasNotModified();
3320 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3323 // Then, activate the one given.
3326 int propY
= p
->GetY2(m_lineHeight
);
3328 int splitterX
= GetSplitterPosition();
3329 m_editorFocused
= 0;
3331 m_pState
->m_selected
= p
;
3332 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3334 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3336 wxASSERT( m_wndEditor
== NULL
);
3339 // Only create editor for non-disabled non-caption
3340 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3342 // do this for non-caption items
3346 // Do we need to paint the custom image, if any?
3347 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3348 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3349 !p
->GetEditorClass()->CanContainCustomImage()
3351 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3353 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3354 wxPoint goodPos
= grect
.GetPosition();
3355 #if wxPG_CREATE_CONTROLS_HIDDEN
3356 int coord_adjust
= m_height
- goodPos
.y
;
3357 goodPos
.y
+= coord_adjust
;
3360 const wxPGEditor
* editor
= p
->GetEditorClass();
3361 wxCHECK_MSG(editor
, false,
3362 wxT("NULL editor class not allowed"));
3364 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3366 wxPGWindowList wndList
= editor
->CreateControls(this,
3371 m_wndEditor
= wndList
.m_primary
;
3372 m_wndEditor2
= wndList
.m_secondary
;
3373 wxWindow
* primaryCtrl
= GetEditorControl();
3376 // Essentially, primaryCtrl == m_wndEditor
3379 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3380 // value is drawn as normal, and m_wndEditor2 is assumed
3381 // to be a right-aligned button that triggers a separate editorCtrl
3386 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3387 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3389 // Set validator, if any
3390 #if wxUSE_VALIDATORS
3391 wxValidator
* validator
= p
->GetValidator();
3393 primaryCtrl
->SetValidator(*validator
);
3396 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3397 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3399 // If it has modified status, use bold font
3400 // (must be done before capturing m_ctrlXAdjust)
3401 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3402 SetCurControlBoldFont();
3405 // Fix TextCtrl indentation
3406 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3407 wxTextCtrl
* tc
= NULL
;
3408 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3409 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3411 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3413 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3416 // Store x relative to splitter (we'll need it).
3417 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3419 // Check if background clear is not necessary
3420 wxPoint pos
= m_wndEditor
->GetPosition();
3421 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3423 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3426 m_wndEditor
->SetSizeHints(3, 3);
3428 #if wxPG_CREATE_CONTROLS_HIDDEN
3429 m_wndEditor
->Show(false);
3430 m_wndEditor
->Freeze();
3432 goodPos
= m_wndEditor
->GetPosition();
3433 goodPos
.y
-= coord_adjust
;
3434 m_wndEditor
->Move( goodPos
);
3437 SetupChildEventHandling(primaryCtrl
);
3439 // Focus and select all (wxTextCtrl, wxComboBox etc)
3440 if ( flags
& wxPG_SEL_FOCUS
)
3442 primaryCtrl
->SetFocus();
3444 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3450 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3451 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3453 // Get proper id for wndSecondary
3454 m_wndSecId
= m_wndEditor2
->GetId();
3455 wxWindowList children
= m_wndEditor2
->GetChildren();
3456 wxWindowList::iterator node
= children
.begin();
3457 if ( node
!= children
.end() )
3458 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3460 m_wndEditor2
->SetSizeHints(3,3);
3462 #if wxPG_CREATE_CONTROLS_HIDDEN
3463 wxRect sec_rect
= m_wndEditor2
->GetRect();
3464 sec_rect
.y
-= coord_adjust
;
3466 // Fine tuning required to fix "oversized"
3467 // button disappearance bug.
3468 if ( sec_rect
.y
< 0 )
3470 sec_rect
.height
+= sec_rect
.y
;
3473 m_wndEditor2
->SetSize( sec_rect
);
3475 m_wndEditor2
->Show();
3477 SetupChildEventHandling(m_wndEditor2
);
3479 // If no primary editor, focus to button to allow
3480 // it to interprete ENTER etc.
3481 // NOTE: Due to problems focusing away from it, this
3482 // has been disabled.
3484 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3485 m_wndEditor2->SetFocus();
3489 if ( flags
& wxPG_SEL_FOCUS
)
3490 m_editorFocused
= 1;
3495 // Make sure focus is in grid canvas (important for wxGTK, at least)
3499 EditorsValueWasNotModified();
3501 // If it's inside collapsed section, expand parent, scroll, etc.
3502 // Also, if it was partially visible, scroll it into view.
3503 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3508 #if wxPG_CREATE_CONTROLS_HIDDEN
3509 m_wndEditor
->Thaw();
3511 m_wndEditor
->Show(true);
3518 // Make sure focus is in grid canvas
3522 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3528 // Show help text in status bar.
3529 // (if found and grid not embedded in manager with help box and
3530 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3533 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3535 wxStatusBar
* statusbar
= NULL
;
3536 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3538 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3540 statusbar
= frame
->GetStatusBar();
3545 const wxString
* pHelpString
= (const wxString
*) NULL
;
3549 pHelpString
= &p
->GetHelpString();
3550 if ( pHelpString
->length() )
3552 // Set help box text.
3553 statusbar
->SetStatusText( *pHelpString
);
3554 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3558 if ( (!pHelpString
|| !pHelpString
->length()) &&
3559 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3561 // Clear help box - but only if it was written
3562 // by us at previous time.
3563 statusbar
->SetStatusText( m_emptyString
);
3564 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3570 m_inDoSelectProperty
= 0;
3572 // call wx event handler (here so that it also occurs on deselection)
3573 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3578 // -----------------------------------------------------------------------
3580 bool wxPropertyGrid::UnfocusEditor()
3582 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3585 if ( !CommitChangesFromEditor(0) )
3589 DrawItem(m_selected
);
3594 // -----------------------------------------------------------------------
3596 void wxPropertyGrid::RefreshEditor()
3598 wxPGProperty
* p
= m_selected
;
3602 wxWindow
* wnd
= GetEditorControl();
3606 // Set editor font boldness - must do this before
3607 // calling UpdateControl().
3608 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3610 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3611 wnd
->SetFont(GetCaptionFont());
3613 wnd
->SetFont(GetFont());
3616 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3618 editorClass
->UpdateControl(p
, wnd
);
3620 if ( p
->IsValueUnspecified() )
3621 editorClass
->SetValueToUnspecified(p
, wnd
);
3624 // -----------------------------------------------------------------------
3626 // This method is not inline because it called dozens of times
3627 // (i.e. two-arg function calls create smaller code size).
3628 bool wxPropertyGrid::DoClearSelection()
3630 return DoSelectProperty(NULL
);
3633 // -----------------------------------------------------------------------
3634 // wxPropertyGrid expand/collapse state
3635 // -----------------------------------------------------------------------
3637 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3639 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3641 // If active editor was inside collapsed section, then disable it
3642 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3644 ClearSelection(false);
3647 // Store dont-center-splitter flag 'cause we need to temporarily set it
3648 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3649 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3651 bool res
= m_pState
->DoCollapse(pwc
);
3656 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3658 RecalculateVirtualSize();
3660 // Redraw etc. only if collapsed was visible.
3661 if (pwc
->IsVisible() &&
3663 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3665 // When item is collapsed so that scrollbar would move,
3666 // graphics mess is about (unless we redraw everything).
3671 // Clear dont-center-splitter flag if it wasn't set
3672 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3677 // -----------------------------------------------------------------------
3679 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3681 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3683 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3685 // Store dont-center-splitter flag 'cause we need to temporarily set it
3686 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3687 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3689 bool res
= m_pState
->DoExpand(pwc
);
3694 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3696 RecalculateVirtualSize();
3698 // Redraw etc. only if expanded was visible.
3699 if ( pwc
->IsVisible() && !m_frozen
&&
3700 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3704 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3707 DrawItems(pwc
, NULL
);
3712 // Clear dont-center-splitter flag if it wasn't set
3713 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3718 // -----------------------------------------------------------------------
3720 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3723 return m_pState
->DoHideProperty(p
, hide
, flags
);
3726 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3729 ClearSelection(false);
3732 m_pState
->DoHideProperty(p
, hide
, flags
);
3734 RecalculateVirtualSize();
3741 // -----------------------------------------------------------------------
3742 // wxPropertyGrid size related methods
3743 // -----------------------------------------------------------------------
3745 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3747 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3751 // If virtual height was changed, then recalculate editor control position(s)
3752 if ( m_pState
->m_vhCalcPending
)
3753 CorrectEditorWidgetPosY();
3755 m_pState
->EnsureVirtualHeight();
3757 wxASSERT_LEVEL_2_MSG(
3758 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3759 "VirtualHeight and ActualVirtualHeight should match"
3762 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3764 int x
= m_pState
->m_width
;
3765 int y
= m_pState
->m_virtualHeight
;
3768 GetClientSize(&width
,&height
);
3770 // Now adjust virtual size.
3771 SetVirtualSize(x
, y
);
3777 // Adjust scrollbars
3778 if ( HasVirtualWidth() )
3780 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3781 xPos
= GetScrollPos( wxHORIZONTAL
);
3784 if ( forceXPos
!= -1 )
3787 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3790 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3791 int yPos
= GetScrollPos( wxVERTICAL
);
3793 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3794 xAmount
, yAmount
, xPos
, yPos
, true );
3796 // Must re-get size now
3797 GetClientSize(&width
,&height
);
3799 if ( !HasVirtualWidth() )
3801 m_pState
->SetVirtualWidth(width
);
3808 m_canvas
->SetSize( x
, y
);
3810 m_pState
->CheckColumnWidths();
3813 CorrectEditorWidgetSizeX();
3815 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3818 // -----------------------------------------------------------------------
3820 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3822 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3826 GetClientSize(&width
,&height
);
3831 #if wxPG_DOUBLE_BUFFER
3832 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3834 int dblh
= (m_lineHeight
*2);
3835 if ( !m_doubleBuffer
)
3837 // Create double buffer bitmap to draw on, if none
3838 int w
= (width
>250)?width
:250;
3839 int h
= height
+ dblh
;
3841 m_doubleBuffer
= new wxBitmap( w
, h
);
3845 int w
= m_doubleBuffer
->GetWidth();
3846 int h
= m_doubleBuffer
->GetHeight();
3848 // Double buffer must be large enough
3849 if ( w
< width
|| h
< (height
+dblh
) )
3851 if ( w
< width
) w
= width
;
3852 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3853 delete m_doubleBuffer
;
3854 m_doubleBuffer
= new wxBitmap( w
, h
);
3861 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3862 m_ncWidth
= event
.GetSize().x
;
3866 if ( m_pState
->m_itemsAdded
)
3867 PrepareAfterItemsAdded();
3869 // Without this, virtual size (atleast under wxGTK) will be skewed
3870 RecalculateVirtualSize();
3876 // -----------------------------------------------------------------------
3878 void wxPropertyGrid::SetVirtualWidth( int width
)
3882 // Disable virtual width
3883 width
= GetClientSize().x
;
3884 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3888 // Enable virtual width
3889 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3891 m_pState
->SetVirtualWidth( width
);
3894 void wxPropertyGrid::SetFocusOnCanvas()
3896 m_canvas
->SetFocusIgnoringChildren();
3897 m_editorFocused
= 0;
3900 // -----------------------------------------------------------------------
3901 // wxPropertyGrid mouse event handling
3902 // -----------------------------------------------------------------------
3904 // selFlags uses same values DoSelectProperty's flags
3905 // Returns true if event was vetoed.
3906 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3908 // Send property grid event of specific type and with specific property
3909 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3910 evt
.SetPropertyGrid(this);
3911 evt
.SetEventObject(m_eventObject
);
3915 evt
.SetCanVeto(true);
3916 evt
.SetupValidationInfo();
3917 m_validationInfo
.m_pValue
= pValue
;
3919 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3921 evtHandler
->ProcessEvent(evt
);
3923 return evt
.WasVetoed();
3926 // -----------------------------------------------------------------------
3928 // Return false if should be skipped
3929 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3933 // Need to set focus?
3934 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3939 wxPropertyGridPageState
* state
= m_pState
;
3941 int splitterHitOffset
;
3942 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3944 wxPGProperty
* p
= DoGetItemAtY(y
);
3948 int depth
= (int)p
->GetDepth() - 1;
3950 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3952 if ( x
>= marginEnds
)
3956 if ( p
->IsCategory() )
3958 // This is category.
3959 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3961 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3963 // Expand, collapse, activate etc. if click on text or left of splitter.
3966 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3971 if ( !DoSelectProperty( p
) )
3974 // On double-click, expand/collapse.
3975 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3977 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3978 else DoExpand( p
, true );
3982 else if ( splitterHit
== -1 )
3985 unsigned int selFlag
= 0;
3986 if ( columnHit
== 1 )
3988 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3989 selFlag
= wxPG_SEL_FOCUS
;
3991 if ( !DoSelectProperty( p
, selFlag
) )
3994 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3996 if ( p
->GetChildCount() && !p
->IsCategory() )
3997 // On double-click, expand/collapse.
3998 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4000 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4001 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4002 else DoExpand( p
, true );
4009 // click on splitter
4010 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4012 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4014 // Double-clicking the splitter causes auto-centering
4015 CenterSplitter( true );
4017 else if ( m_dragStatus
== 0 )
4020 // Begin draggin the splitter
4024 // Changes must be committed here or the
4025 // value won't be drawn correctly
4026 if ( !CommitChangesFromEditor() )
4029 m_wndEditor
->Show ( false );
4032 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4034 m_canvas
->CaptureMouse();
4035 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4039 m_draggedSplitter
= splitterHit
;
4040 m_dragOffset
= splitterHitOffset
;
4042 wxClientDC
dc(m_canvas
);
4044 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4045 // Fixes button disappearance bug
4047 m_wndEditor2
->Show ( false );
4050 m_startingSplitterX
= x
- splitterHitOffset
;
4058 if ( p
->GetChildCount() )
4060 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4062 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4064 int y2
= y
% m_lineHeight
;
4065 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4067 // On click on expander button, expand/collapse
4068 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4069 DoCollapse( p
, true );
4071 DoExpand( p
, true );
4080 // -----------------------------------------------------------------------
4082 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4083 wxMouseEvent
& WXUNUSED(event
) )
4087 // Select property here as well
4088 wxPGProperty
* p
= m_propHover
;
4089 if ( p
!= m_selected
)
4090 DoSelectProperty( p
);
4092 // Send right click event.
4093 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4100 // -----------------------------------------------------------------------
4102 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4103 wxMouseEvent
& WXUNUSED(event
) )
4107 // Select property here as well
4108 wxPGProperty
* p
= m_propHover
;
4110 if ( p
!= m_selected
)
4111 DoSelectProperty( p
);
4113 // Send double-click event.
4114 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4121 // -----------------------------------------------------------------------
4123 #if wxPG_SUPPORT_TOOLTIPS
4125 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4127 if ( tipString
.length() )
4129 m_canvas
->SetToolTip(tipString
);
4133 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4134 m_canvas
->SetToolTip( m_emptyString
);
4136 m_canvas
->SetToolTip( NULL
);
4141 #endif // #if wxPG_SUPPORT_TOOLTIPS
4143 // -----------------------------------------------------------------------
4145 // Return false if should be skipped
4146 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4148 // Safety check (needed because mouse capturing may
4149 // otherwise freeze the control)
4150 if ( m_dragStatus
> 0 && !event
.Dragging() )
4152 HandleMouseUp(x
,y
,event
);
4155 wxPropertyGridPageState
* state
= m_pState
;
4157 int splitterHitOffset
;
4158 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4159 int splitterX
= x
- splitterHitOffset
;
4161 if ( m_dragStatus
> 0 )
4163 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4164 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4167 int newSplitterX
= x
- m_dragOffset
;
4168 int splitterX
= x
- splitterHitOffset
;
4170 // Splitter redraw required?
4171 if ( newSplitterX
!= splitterX
)
4174 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4175 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4176 state
->m_fSplitterX
= (float) newSplitterX
;
4179 CorrectEditorWidgetSizeX();
4193 int ih
= m_lineHeight
;
4196 #if wxPG_SUPPORT_TOOLTIPS
4197 wxPGProperty
* prevHover
= m_propHover
;
4198 unsigned char prevSide
= m_mouseSide
;
4200 int curPropHoverY
= y
- (y
% ih
);
4202 // On which item it hovers
4205 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4208 // Mouse moves on another property
4210 m_propHover
= DoGetItemAtY(y
);
4211 m_propHoverY
= curPropHoverY
;
4214 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4217 #if wxPG_SUPPORT_TOOLTIPS
4218 // Store which side we are on
4220 if ( columnHit
== 1 )
4222 else if ( columnHit
== 0 )
4226 // If tooltips are enabled, show label or value as a tip
4227 // in case it doesn't otherwise show in full length.
4229 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4231 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4233 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4235 if ( m_propHover
&& !m_propHover
->IsCategory() )
4238 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4240 // Show help string as a tooltip
4241 wxString tipString
= m_propHover
->GetHelpString();
4243 SetToolTip(tipString
);
4247 // Show cropped value string as a tooltip
4251 if ( m_mouseSide
== 1 )
4253 tipString
= m_propHover
->m_label
;
4254 space
= splitterX
-m_marginWidth
-3;
4256 else if ( m_mouseSide
== 2 )
4258 tipString
= m_propHover
->GetDisplayedString();
4260 space
= m_width
- splitterX
;
4261 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4262 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4268 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4271 SetToolTip( tipString
);
4278 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4279 m_canvas
->SetToolTip( m_emptyString
);
4281 m_canvas
->SetToolTip( NULL
);
4292 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4293 m_canvas
->SetToolTip( m_emptyString
);
4295 m_canvas
->SetToolTip( NULL
);
4303 if ( splitterHit
== -1 ||
4305 HasFlag(wxPG_STATIC_SPLITTER
) )
4307 // hovering on something else
4308 if ( m_curcursor
!= wxCURSOR_ARROW
)
4309 CustomSetCursor( wxCURSOR_ARROW
);
4313 // Do not allow splitter cursor on caption items.
4314 // (also not if we were dragging and its started
4315 // outside the splitter region)
4317 if ( !m_propHover
->IsCategory() &&
4321 // hovering on splitter
4323 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4324 // reliably detected.
4325 //if ( m_curcursor != wxCURSOR_SIZEWE )
4326 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4332 // hovering on something else
4333 if ( m_curcursor
!= wxCURSOR_ARROW
)
4334 CustomSetCursor( wxCURSOR_ARROW
);
4341 // -----------------------------------------------------------------------
4343 // Also handles Leaving event
4344 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4345 wxMouseEvent
&WXUNUSED(event
) )
4347 wxPropertyGridPageState
* state
= m_pState
;
4351 int splitterHitOffset
;
4352 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4354 // No event type check - basicly calling this method should
4355 // just stop dragging.
4356 // Left up after dragged?
4357 if ( m_dragStatus
>= 1 )
4360 // End Splitter Dragging
4362 // DO NOT ENABLE FOLLOWING LINE!
4363 // (it is only here as a reminder to not to do it)
4366 // Disable splitter auto-centering
4367 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4369 // This is necessary to return cursor
4370 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4372 m_canvas
->ReleaseMouse();
4373 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4376 // Set back the default cursor, if necessary
4377 if ( splitterHit
== -1 ||
4380 CustomSetCursor( wxCURSOR_ARROW
);
4385 // Control background needs to be cleared
4386 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4387 DrawItem( m_selected
);
4391 m_wndEditor
->Show ( true );
4394 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4395 // Fixes button disappearance bug
4397 m_wndEditor2
->Show ( true );
4400 // This clears the focus.
4401 m_editorFocused
= 0;
4407 // -----------------------------------------------------------------------
4409 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4411 int splitterX
= GetSplitterPosition();
4414 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4418 wxWindow
* wnd
= GetEditorControl();
4420 // Hide popup on clicks
4421 if ( event
.GetEventType() != wxEVT_MOTION
)
4422 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4424 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4430 if ( wnd
== NULL
|| m_dragStatus
||
4432 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4433 ux
>= (r
.x
+r
.width
) ||
4435 event
.m_y
>= (r
.y
+r
.height
)
4445 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4450 // -----------------------------------------------------------------------
4452 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4455 if ( OnMouseCommon( event
, &x
, &y
) )
4457 HandleMouseClick(x
,y
,event
);
4462 // -----------------------------------------------------------------------
4464 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4467 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4468 HandleMouseRightClick(x
,y
,event
);
4472 // -----------------------------------------------------------------------
4474 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4476 // Always run standard mouse-down handler as well
4477 OnMouseClick(event
);
4480 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4481 HandleMouseDoubleClick(x
,y
,event
);
4485 // -----------------------------------------------------------------------
4487 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4490 if ( OnMouseCommon( event
, &x
, &y
) )
4492 HandleMouseMove(x
,y
,event
);
4497 // -----------------------------------------------------------------------
4499 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4501 // Called when mouse moves in the empty space below the properties.
4502 CustomSetCursor( wxCURSOR_ARROW
);
4505 // -----------------------------------------------------------------------
4507 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4510 if ( OnMouseCommon( event
, &x
, &y
) )
4512 HandleMouseUp(x
,y
,event
);
4517 // -----------------------------------------------------------------------
4519 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4521 // This may get called from child control as well, so event's
4522 // mouse position cannot be relied on.
4524 if ( event
.Entering() )
4526 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4528 // TODO: Fix this (detect parent and only do
4529 // cursor trick if it is a manager).
4530 wxASSERT( GetParent() );
4531 GetParent()->SetCursor(wxNullCursor
);
4533 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4536 GetParent()->SetCursor(wxNullCursor
);
4538 else if ( event
.Leaving() )
4540 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4541 m_canvas
->SetCursor( wxNullCursor
);
4543 // Get real cursor position
4544 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4546 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4549 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4551 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4555 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4563 // -----------------------------------------------------------------------
4565 // Common code used by various OnMouseXXXChild methods.
4566 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4568 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4569 wxASSERT( topCtrlWnd
);
4571 event
.GetPosition(&x
,&y
);
4573 int splitterX
= GetSplitterPosition();
4575 wxRect r
= topCtrlWnd
->GetRect();
4576 if ( !m_dragStatus
&&
4577 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4578 y
>= 0 && y
< r
.height \
4581 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4586 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4593 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4596 if ( OnMouseChildCommon(event
,&x
,&y
) )
4598 bool res
= HandleMouseClick(x
,y
,event
);
4599 if ( !res
) event
.Skip();
4603 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4606 wxASSERT( m_wndEditor
);
4607 // These coords may not be exact (about +-2),
4608 // but that should not matter (right click is about item, not position).
4609 wxPoint pt
= m_wndEditor
->GetPosition();
4610 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4611 wxASSERT( m_selected
);
4612 m_propHover
= m_selected
;
4613 bool res
= HandleMouseRightClick(x
,y
,event
);
4614 if ( !res
) event
.Skip();
4617 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4620 if ( OnMouseChildCommon(event
,&x
,&y
) )
4622 bool res
= HandleMouseMove(x
,y
,event
);
4623 if ( !res
) event
.Skip();
4627 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4630 if ( OnMouseChildCommon(event
,&x
,&y
) )
4632 bool res
= HandleMouseUp(x
,y
,event
);
4633 if ( !res
) event
.Skip();
4637 // -----------------------------------------------------------------------
4638 // wxPropertyGrid keyboard event handling
4639 // -----------------------------------------------------------------------
4641 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4643 // Translates wxKeyEvent to wxPG_ACTION_XXX
4645 int keycode
= event
.GetKeyCode();
4646 int modifiers
= event
.GetModifiers();
4648 wxASSERT( !(modifiers
&~(0xFFFF)) );
4650 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4652 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4654 if ( it
== m_actionTriggers
.end() )
4659 int second
= (it
->second
>>16) & 0xFFFF;
4663 return (it
->second
& 0xFFFF);
4666 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4668 wxASSERT( !(modifiers
&~(0xFFFF)) );
4670 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4672 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4674 if ( it
!= m_actionTriggers
.end() )
4676 // This key combination is already used
4678 // Can add secondary?
4679 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4680 wxT("You can only add up to two separate actions per key combination.") );
4682 action
= it
->second
| (action
<<16);
4685 m_actionTriggers
[hashMapKey
] = action
;
4688 void wxPropertyGrid::ClearActionTriggers( int action
)
4690 wxPGHashMapI2I::iterator it
;
4692 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4694 if ( it
->second
== action
)
4696 m_actionTriggers
.erase(it
);
4701 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4704 // Handles key event when editor control is not focused.
4707 wxCHECK2(!m_frozen
, return);
4709 // Travelsal between items, collapsing/expanding, etc.
4710 int keycode
= event
.GetKeyCode();
4711 bool editorFocused
= IsEditorFocused();
4713 if ( keycode
== WXK_TAB
)
4715 wxWindow
* mainControl
;
4717 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4718 mainControl
= GetParent();
4722 if ( !event
.ShiftDown() )
4724 if ( !editorFocused
&& m_wndEditor
)
4726 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4730 // Tab traversal workaround for platforms on which
4731 // wxWindow::Navigate() may navigate into first child
4732 // instead of next sibling. Does not work perfectly
4733 // in every scenario (for instance, when property grid
4734 // is either first or last control).
4735 #if defined(__WXGTK__)
4736 wxWindow
* sibling
= mainControl
->GetNextSibling();
4738 sibling
->SetFocusFromKbd();
4740 Navigate(wxNavigationKeyEvent::IsForward
);
4746 if ( editorFocused
)
4752 #if defined(__WXGTK__)
4753 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4755 sibling
->SetFocusFromKbd();
4757 Navigate(wxNavigationKeyEvent::IsBackward
);
4765 // Ignore Alt and Control when they are down alone
4766 if ( keycode
== WXK_ALT
||
4767 keycode
== WXK_CONTROL
)
4774 int action
= KeyEventToActions(event
, &secondAction
);
4776 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4779 // Esc cancels any changes
4780 if ( IsEditorsValueModified() )
4782 EditorsValueWasNotModified();
4784 // Update the control as well
4785 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4787 m_selected
->GetDisplayedString() );
4790 OnValidationFailureReset(m_selected
);
4796 // Except for TAB and ESC, handle child control events in child control
4799 // Only propagate event if it had modifiers
4800 if ( !event
.HasModifiers() )
4802 event
.StopPropagation();
4808 bool wasHandled
= false;
4813 if ( ButtonTriggerKeyTest(action
, event
) )
4816 wxPGProperty
* p
= m_selected
;
4818 // Travel and expand/collapse
4821 if ( p
->GetChildCount() )
4823 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4825 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4828 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4830 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4837 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4841 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4847 if ( selectDir
>= -1 )
4849 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4851 DoSelectProperty(p
);
4857 // If nothing was selected, select the first item now
4858 // (or navigate out of tab).
4859 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4861 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4862 if ( p
) DoSelectProperty(p
);
4871 // -----------------------------------------------------------------------
4873 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4875 // If there was editor open and focused, then this event should not
4876 // really be processed here.
4877 if ( IsEditorFocused() )
4879 // However, if event had modifiers, it is probably still best
4881 if ( event
.HasModifiers() )
4884 event
.StopPropagation();
4888 HandleKeyEvent(event
, false);
4891 // -----------------------------------------------------------------------
4893 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4898 action
= KeyEventToActions(event
, &secondAction
);
4901 // Does the keycode trigger button?
4902 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4905 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4906 GetEventHandler()->AddPendingEvent(evt
);
4913 // -----------------------------------------------------------------------
4915 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4917 HandleKeyEvent(event
, true);
4920 // -----------------------------------------------------------------------
4921 // wxPropertyGrid miscellaneous event handling
4922 // -----------------------------------------------------------------------
4924 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4927 // Check if the focus is in this control or one of its children
4928 wxWindow
* newFocused
= wxWindow::FindFocus();
4930 if ( newFocused
!= m_curFocused
)
4931 HandleFocusChange( newFocused
);
4934 bool wxPropertyGrid::IsEditorFocused() const
4936 wxWindow
* focus
= wxWindow::FindFocus();
4938 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4939 focus
== GetEditorControl() )
4945 // Called by focus event handlers. newFocused is the window that becomes focused.
4946 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4948 unsigned int oldFlags
= m_iFlags
;
4950 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4952 wxWindow
* parent
= newFocused
;
4954 // This must be one of nextFocus' parents.
4957 // Use m_eventObject, which is either wxPropertyGrid or
4958 // wxPropertyGridManager, as appropriate.
4959 if ( parent
== m_eventObject
)
4961 m_iFlags
|= wxPG_FL_FOCUSED
;
4964 parent
= parent
->GetParent();
4967 m_curFocused
= newFocused
;
4969 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4970 (oldFlags
& wxPG_FL_FOCUSED
) )
4972 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4974 // Need to store changed value
4975 CommitChangesFromEditor();
4981 // Preliminary code for tab-order respecting
4982 // tab-traversal (but should be moved to
4985 wxWindow* prevFocus = event.GetWindow();
4986 wxWindow* useThis = this;
4987 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4988 useThis = GetParent();
4991 prevFocus->GetParent() == useThis->GetParent() )
4993 wxList& children = useThis->GetParent()->GetChildren();
4995 wxNode* node = children.Find(prevFocus);
4997 if ( node->GetNext() &&
4998 useThis == node->GetNext()->GetData() )
4999 DoSelectProperty(GetFirst());
5000 else if ( node->GetPrevious () &&
5001 useThis == node->GetPrevious()->GetData() )
5002 DoSelectProperty(GetLastProperty());
5009 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5010 DrawItem( m_selected
);
5014 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5016 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5017 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5018 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5019 //else if ( event.GetWindow() )
5021 HandleFocusChange(event
.GetWindow());
5026 // -----------------------------------------------------------------------
5028 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5030 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5034 // -----------------------------------------------------------------------
5036 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5038 m_iFlags
|= wxPG_FL_SCROLLED
;
5043 // -----------------------------------------------------------------------
5045 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5047 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5049 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5053 // -----------------------------------------------------------------------
5054 // Property editor related functions
5055 // -----------------------------------------------------------------------
5057 // noDefCheck = true prevents infinite recursion.
5058 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5061 wxASSERT( editorClass
);
5063 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5064 RegisterDefaultEditors();
5066 wxString name
= editorClass
->GetName();
5068 // Existing editor under this name?
5069 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5071 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5073 // If this name was already used, try class name.
5074 name
= editorClass
->GetClassInfo()->GetClassName();
5075 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5078 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5079 (wxPGEditor
*) vt_it
->second
,
5080 "Editor with given name was already registered" );
5082 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5087 // Use this in RegisterDefaultEditors.
5088 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5089 if ( wxPGEditor_##EDITOR == NULL ) \
5091 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5092 new wxPG##EDITOR##Editor, true ); \
5095 // Registers all default editor classes
5096 void wxPropertyGrid::RegisterDefaultEditors()
5098 wxPGRegisterDefaultEditorClass( TextCtrl
);
5099 wxPGRegisterDefaultEditorClass( Choice
);
5100 wxPGRegisterDefaultEditorClass( ComboBox
);
5101 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5102 #if wxPG_INCLUDE_CHECKBOX
5103 wxPGRegisterDefaultEditorClass( CheckBox
);
5105 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5107 // Register SpinCtrl etc. editors before use
5108 RegisterAdditionalEditors();
5111 // -----------------------------------------------------------------------
5112 // wxPGStringTokenizer
5113 // Needed to handle C-style string lists (e.g. "str1" "str2")
5114 // -----------------------------------------------------------------------
5116 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5117 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5121 wxPGStringTokenizer::~wxPGStringTokenizer()
5125 bool wxPGStringTokenizer::HasMoreTokens()
5127 const wxString
& str
= *m_str
;
5129 wxString::const_iterator i
= m_curPos
;
5131 wxUniChar delim
= m_delimeter
;
5133 wxUniChar prev_a
= wxT('\0');
5135 bool inToken
= false;
5137 while ( i
!= str
.end() )
5146 m_readyToken
.clear();
5151 if ( prev_a
!= wxT('\\') )
5155 if ( a
!= wxT('\\') )
5175 m_curPos
= str
.end();
5183 wxString
wxPGStringTokenizer::GetNextToken()
5185 return m_readyToken
;
5188 // -----------------------------------------------------------------------
5190 // -----------------------------------------------------------------------
5192 wxPGChoiceEntry::wxPGChoiceEntry()
5193 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5197 // -----------------------------------------------------------------------
5199 // -----------------------------------------------------------------------
5201 wxPGChoicesData::wxPGChoicesData()
5206 wxPGChoicesData::~wxPGChoicesData()
5211 void wxPGChoicesData::Clear()
5216 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5218 wxASSERT( m_items
.size() == 0 );
5220 m_items
= data
->m_items
;
5223 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5224 const wxPGChoiceEntry
& item
)
5226 wxVector
<wxPGChoiceEntry
>::iterator it
;
5230 index
= (int) m_items
.size();
5234 it
= m_items
.begin() + index
;
5237 m_items
.insert(it
, item
);
5239 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5241 // Need to fix value?
5242 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5243 ownEntry
.SetValue(index
);
5248 // -----------------------------------------------------------------------
5249 // wxPropertyGridEvent
5250 // -----------------------------------------------------------------------
5252 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5255 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5256 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5257 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5258 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5259 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5260 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5261 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5262 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5263 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5266 // -----------------------------------------------------------------------
5268 void wxPropertyGridEvent::Init()
5270 m_validationInfo
= NULL
;
5272 m_wasVetoed
= false;
5275 // -----------------------------------------------------------------------
5277 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5278 : wxCommandEvent(commandType
,id
)
5284 // -----------------------------------------------------------------------
5286 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5287 : wxCommandEvent(event
)
5289 m_eventType
= event
.GetEventType();
5290 m_eventObject
= event
.m_eventObject
;
5292 m_property
= event
.m_property
;
5293 m_validationInfo
= event
.m_validationInfo
;
5294 m_canVeto
= event
.m_canVeto
;
5295 m_wasVetoed
= event
.m_wasVetoed
;
5298 // -----------------------------------------------------------------------
5300 wxPropertyGridEvent::~wxPropertyGridEvent()
5304 // -----------------------------------------------------------------------
5306 wxEvent
* wxPropertyGridEvent::Clone() const
5308 return new wxPropertyGridEvent( *this );
5311 // -----------------------------------------------------------------------
5312 // wxPropertyGridPopulator
5313 // -----------------------------------------------------------------------
5315 wxPropertyGridPopulator::wxPropertyGridPopulator()
5319 wxPGGlobalVars
->m_offline
++;
5322 // -----------------------------------------------------------------------
5324 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5327 m_propHierarchy
.clear();
5330 // -----------------------------------------------------------------------
5332 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5338 // -----------------------------------------------------------------------
5340 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5343 // Free unused sets of choices
5344 wxPGHashMapS2P::iterator it
;
5346 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5348 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5355 m_pg
->GetPanel()->Refresh();
5357 wxPGGlobalVars
->m_offline
--;
5360 // -----------------------------------------------------------------------
5362 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5363 const wxString
& propLabel
,
5364 const wxString
& propName
,
5365 const wxString
* propValue
,
5366 wxPGChoices
* pChoices
)
5368 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5369 wxPGProperty
* parent
= GetCurParent();
5371 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5373 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5377 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5379 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5383 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5385 property
->SetLabel(propLabel
);
5386 property
->DoSetName(propName
);
5388 if ( pChoices
&& pChoices
->IsOk() )
5389 property
->SetChoices(*pChoices
);
5391 m_state
->DoInsert(parent
, -1, property
);
5394 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5395 wxPG_PROGRAMMATIC_VALUE
);
5400 // -----------------------------------------------------------------------
5402 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5404 m_propHierarchy
.push_back(property
);
5405 DoScanForChildren();
5406 m_propHierarchy
.pop_back();
5409 // -----------------------------------------------------------------------
5411 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5412 const wxString
& idString
)
5414 wxPGChoices choices
;
5417 if ( choicesString
[0] == wxT('@') )
5419 wxString ids
= choicesString
.substr(1);
5420 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5421 if ( it
== m_dictIdChoices
.end() )
5422 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5424 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5429 if ( idString
.length() )
5431 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5432 if ( it
!= m_dictIdChoices
.end() )
5434 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5441 // Parse choices string
5442 wxString::const_iterator it
= choicesString
.begin();
5446 bool labelValid
= false;
5448 for ( ; it
!= choicesString
.end(); ++it
)
5454 if ( c
== wxT('"') )
5459 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5460 choices
.Add(label
, l
);
5463 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5468 else if ( c
== wxT('=') )
5475 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5482 if ( c
== wxT('"') )
5495 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5496 choices
.Add(label
, l
);
5499 if ( !choices
.IsOk() )
5501 choices
.EnsureData();
5505 if ( idString
.length() )
5506 m_dictIdChoices
[idString
] = choices
.GetData();
5513 // -----------------------------------------------------------------------
5515 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5517 if ( s
.Last() == wxT('%') )
5519 wxString s2
= s
.substr(0,s
.length()-1);
5521 if ( s2
.ToLong(&val
, 10) )
5523 *pval
= (val
*max
)/100;
5529 return s
.ToLong(pval
, 10);
5532 // -----------------------------------------------------------------------
5534 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5535 const wxString
& type
,
5536 const wxString
& value
)
5538 int l
= m_propHierarchy
.size();
5542 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5543 wxString valuel
= value
.Lower();
5546 if ( type
.length() == 0 )
5551 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5553 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5555 else if ( value
.ToLong(&v
, 0) )
5562 if ( type
== wxT("string") )
5566 else if ( type
== wxT("int") )
5569 value
.ToLong(&v
, 0);
5572 else if ( type
== wxT("bool") )
5574 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5581 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5586 p
->SetAttribute( name
, variant
);
5591 // -----------------------------------------------------------------------
5593 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5595 wxLogError(_("Error in resource: %s"),msg
.c_str());
5598 // -----------------------------------------------------------------------
5600 #endif // wxUSE_PROPGRID