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"
68 #include "wx/msw/private.h"
71 // Two pics for the expand / collapse buttons.
72 // Files are not supplied with this project (since it is
73 // recommended to use either custom or native rendering).
74 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
75 // and copy xpm files from archive to wxPropertyGrid src directory
76 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
77 // and set wxPG_USE_RENDERER_NATIVE to 0).
78 #ifndef wxPG_ICON_WIDTH
79 #if defined(__WXMAC__)
80 #include "mac_collapse.xpm"
81 #include "mac_expand.xpm"
82 #elif defined(__WXGTK__)
83 #include "linux_collapse.xpm"
84 #include "linux_expand.xpm"
86 #include "default_collapse.xpm"
87 #include "default_expand.xpm"
92 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
93 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
94 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
95 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
96 #define wxPG_YSPACING_MIN 1
97 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
98 // but causes normal combobox to spill out under MSW
100 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
102 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
103 // Must be larger than largest control border
107 #define wxPG_DEFAULT_CURSOR wxNullCursor
110 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
112 //#define wxPG_HIDER_BUTTON_HEIGHT 25
114 #define wxPG_PIXELS_PER_UNIT m_lineHeight
116 #ifdef wxPG_ICON_WIDTH
117 #define m_iconHeight m_iconWidth
120 //#define wxPG_TOOLTIP_DELAY 1000
122 // -----------------------------------------------------------------------
125 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
127 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
130 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 // -----------------------------------------------------------------------
135 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
137 // -----------------------------------------------------------------------
138 // Statics in one class for easy destruction.
139 // -----------------------------------------------------------------------
141 #include "wx/module.h"
143 class wxPGGlobalVarsClassManager
: public wxModule
145 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
147 wxPGGlobalVarsClassManager() {}
148 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
149 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
152 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
155 // When wxPG is loaded dynamically after the application is already running
156 // then the built-in module system won't pick this one up. Add it manually.
157 void wxPGInitResourceModule()
159 wxModule
* module = new wxPGGlobalVarsClassManager
;
161 wxModule::RegisterModule(module);
164 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
167 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
169 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
171 m_boolChoices
.Add(_("False"));
172 m_boolChoices
.Add(_("True"));
174 m_fontFamilyChoices
= NULL
;
176 m_defaultRenderer
= new wxPGDefaultRenderer();
178 m_autoGetTranslation
= false;
186 // Prepare some shared variants
187 m_vEmptyString
= wxString();
189 m_vMinusOne
= (long) -1;
193 // Prepare cached string constants
194 m_strstring
= wxS("string");
195 m_strlong
= wxS("long");
196 m_strbool
= wxS("bool");
197 m_strlist
= wxS("list");
198 m_strDefaultValue
= wxS("DefaultValue");
199 m_strMin
= wxS("Min");
200 m_strMax
= wxS("Max");
201 m_strUnits
= wxS("Units");
202 m_strInlineHelp
= wxS("InlineHelp");
208 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
212 delete m_defaultRenderer
;
214 // This will always have one ref
215 delete m_fontFamilyChoices
;
218 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
219 delete ((wxValidator
*)m_arrValidators
[i
]);
223 // Destroy value type class instances.
224 wxPGHashMapS2P::iterator vt_it
;
226 // Destroy editor class instances.
227 // iterate over all the elements in the class
228 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
230 delete ((wxPGEditor
*)vt_it
->second
);
233 delete wxPGProperty::sm_wxPG_LABEL
;
236 void wxPropertyGridInitGlobalsIfNeeded()
240 // -----------------------------------------------------------------------
242 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
243 // and tries to commit property value.
244 // -----------------------------------------------------------------------
246 class wxPGTLWHandler
: public wxEvtHandler
250 wxPGTLWHandler( wxPropertyGrid
* pg
)
258 void OnClose( wxCloseEvent
& event
)
260 // ClearSelection forces value validation/commit.
261 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
271 wxPropertyGrid
* m_pg
;
273 DECLARE_EVENT_TABLE()
276 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
277 EVT_CLOSE(wxPGTLWHandler::OnClose
)
280 // -----------------------------------------------------------------------
282 // -----------------------------------------------------------------------
285 // wxPGCanvas acts as a graphics sub-window of the
286 // wxScrolledWindow that wxPropertyGrid is.
288 class wxPGCanvas
: public wxPanel
291 wxPGCanvas() : wxPanel()
294 virtual ~wxPGCanvas() { }
297 void OnMouseMove( wxMouseEvent
&event
)
299 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
300 pg
->OnMouseMove( event
);
303 void OnMouseClick( wxMouseEvent
&event
)
305 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
306 pg
->OnMouseClick( event
);
309 void OnMouseUp( wxMouseEvent
&event
)
311 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
312 pg
->OnMouseUp( event
);
315 void OnMouseRightClick( wxMouseEvent
&event
)
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 pg
->OnMouseRightClick( event
);
321 void OnMouseDoubleClick( wxMouseEvent
&event
)
323 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
324 pg
->OnMouseDoubleClick( event
);
327 void OnKey( wxKeyEvent
& event
)
329 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
333 void OnPaint( wxPaintEvent
& event
);
335 // Always be focussable, even with child windows
336 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
337 { wxPanel::SetCanFocus(true); }
341 DECLARE_EVENT_TABLE()
342 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
346 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
348 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
349 EVT_MOTION(wxPGCanvas::OnMouseMove
)
350 EVT_PAINT(wxPGCanvas::OnPaint
)
351 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
352 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
353 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
354 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
355 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
359 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
361 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
362 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
366 // Don't paint after destruction has begun
367 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
370 // Update everything inside the box
371 wxRect r
= GetUpdateRegion().GetBox();
373 // FIXME: This is just a workaround for a bug that causes splitters not
374 // to paint when other windows are being dragged over the grid.
375 wxRect fullRect
= GetRect();
377 r
.width
= fullRect
.width
;
379 // Repaint this rectangle
380 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
382 // We assume that the size set when grid is shown
383 // is what is desired.
384 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
387 // -----------------------------------------------------------------------
389 // -----------------------------------------------------------------------
391 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
393 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
394 EVT_IDLE(wxPropertyGrid::OnIdle
)
395 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
396 EVT_PAINT(wxPropertyGrid::OnPaint
)
397 EVT_SIZE(wxPropertyGrid::OnResize
)
398 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
399 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
400 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
401 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
402 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
403 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
404 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
405 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
409 // -----------------------------------------------------------------------
411 wxPropertyGrid::wxPropertyGrid()
417 // -----------------------------------------------------------------------
419 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
424 const wxString
& name
)
428 Create(parent
,id
,pos
,size
,style
,name
);
431 // -----------------------------------------------------------------------
433 bool wxPropertyGrid::Create( wxWindow
*parent
,
438 const wxString
& name
)
441 if ( !(style
&wxBORDER_MASK
) )
442 style
|= wxSIMPLE_BORDER
;
446 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
447 style
&= ~(wxTAB_TRAVERSAL
);
448 style
|= wxWANTS_CHARS
;
450 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
457 // -----------------------------------------------------------------------
460 // Initialize values to defaults
462 void wxPropertyGrid::Init1()
464 // Register editor classes, if necessary.
465 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
466 wxPropertyGrid::RegisterDefaultEditors();
470 m_wndEditor
= m_wndEditor2
= NULL
;
474 m_eventObject
= this;
477 m_sortFunction
= NULL
;
478 m_inDoPropertyChanged
= 0;
479 m_inCommitChangesFromEditor
= 0;
480 m_inDoSelectProperty
= 0;
481 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
487 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
488 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
489 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
490 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
491 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
492 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
493 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
494 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
495 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
497 m_coloursCustomized
= 0;
502 #if wxPG_DOUBLE_BUFFER
503 m_doubleBuffer
= NULL
;
506 #ifndef wxPG_ICON_WIDTH
512 m_iconWidth
= wxPG_ICON_WIDTH
;
517 m_gutterWidth
= wxPG_GUTTER_MIN
;
518 m_subgroup_extramargin
= 10;
522 m_width
= m_height
= 0;
524 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
527 m_chgInfo_changedProperty
= NULL
;
530 // -----------------------------------------------------------------------
533 // Initialize after parent etc. set
535 void wxPropertyGrid::Init2()
537 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
540 // Smaller controls on Mac
541 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
544 // Now create state, if one didn't exist already
545 // (wxPropertyGridManager might have created it for us).
548 m_pState
= CreateState();
549 m_pState
->m_pPropGrid
= this;
550 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
553 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
554 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
556 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
558 m_pState
->InitNonCatMode();
560 m_pState
->m_properties
= m_pState
->m_abcArray
;
563 GetClientSize(&m_width
,&m_height
);
565 #ifndef wxPG_ICON_WIDTH
566 // create two bitmap nodes for drawing
567 m_expandbmp
= new wxBitmap(expand_xpm
);
568 m_collbmp
= new wxBitmap(collapse_xpm
);
570 // calculate average font height for bitmap centering
572 m_iconWidth
= m_expandbmp
->GetWidth();
573 m_iconHeight
= m_expandbmp
->GetHeight();
576 m_curcursor
= wxCURSOR_ARROW
;
577 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
579 // adjust bitmap icon y position so they are centered
580 m_vspacing
= wxPG_DEFAULT_VSPACING
;
582 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
584 // Allocate cell datas indirectly by calling setter
585 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
586 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
590 // This helps with flicker
591 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
594 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
595 m_tlp
= ::wxGetTopLevelParent(this);
596 m_tlwHandler
= handler
;
597 m_tlp
->PushEventHandler(handler
);
599 // set virtual size to this window size
600 wxSize wndsize
= GetSize();
601 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
603 m_timeCreated
= ::wxGetLocalTimeMillis();
605 m_canvas
= new wxPGCanvas();
606 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
607 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
608 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
610 m_iFlags
|= wxPG_FL_INITIALIZED
;
612 m_ncWidth
= wndsize
.GetWidth();
614 // Need to call OnResize handler or size given in constructor/Create
616 wxSizeEvent
sizeEvent(wndsize
,0);
620 // -----------------------------------------------------------------------
622 wxPropertyGrid::~wxPropertyGrid()
626 DoSelectProperty(NULL
);
628 // This should do prevent things from going too badly wrong
629 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
631 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
632 m_canvas
->ReleaseMouse();
634 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
635 m_tlp
->RemoveEventHandler(handler
);
638 wxASSERT_MSG( !IsEditorsValueModified(),
639 wxS("Most recent change in property editor was lost!!! ")
640 wxS("(if you don't want this to happen, close your frames ")
641 wxS("and dialogs using Close(false).)") );
643 #if wxPG_DOUBLE_BUFFER
644 if ( m_doubleBuffer
)
645 delete m_doubleBuffer
;
650 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
653 delete m_cursorSizeWE
;
655 #ifndef wxPG_ICON_WIDTH
660 // Delete common value records
661 for ( i
=0; i
<m_commonValues
.size(); i
++ )
663 delete GetCommonValue(i
);
667 // -----------------------------------------------------------------------
669 bool wxPropertyGrid::Destroy()
671 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
672 m_canvas
->ReleaseMouse();
674 return wxScrolledWindow::Destroy();
677 // -----------------------------------------------------------------------
679 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
681 return new wxPropertyGridPageState();
684 // -----------------------------------------------------------------------
685 // wxPropertyGrid overridden wxWindow methods
686 // -----------------------------------------------------------------------
688 void wxPropertyGrid::SetWindowStyleFlag( long style
)
690 long old_style
= m_windowStyle
;
692 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
694 wxASSERT( m_pState
);
696 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
699 EnableCategories( true );
701 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
703 // Disable categories
704 EnableCategories( false );
706 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
712 PrepareAfterItemsAdded();
714 m_pState
->m_itemsAdded
= 1;
716 #if wxPG_SUPPORT_TOOLTIPS
717 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
723 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
724 SetToolTip ( tooltip );
725 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
728 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
733 m_canvas
->SetToolTip( NULL
);
738 wxScrolledWindow::SetWindowStyleFlag ( style
);
740 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
742 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
744 CalculateFontAndBitmapStuff( m_vspacing
);
750 // -----------------------------------------------------------------------
752 void wxPropertyGrid::Freeze()
756 wxScrolledWindow::Freeze();
761 // -----------------------------------------------------------------------
763 void wxPropertyGrid::Thaw()
769 wxScrolledWindow::Thaw();
770 RecalculateVirtualSize();
771 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
775 // Force property re-selection
777 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
781 // -----------------------------------------------------------------------
783 void wxPropertyGrid::SetExtraStyle( long exStyle
)
785 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
787 #if defined(__WXMSW__)
790 // Don't use WS_EX_COMPOSITED just now.
793 if ( m_iFlags & wxPG_FL_IN_MANAGER )
794 hWnd = (HWND)GetParent()->GetHWND();
796 hWnd = (HWND)GetHWND();
798 ::SetWindowLong( hWnd, GWL_EXSTYLE,
799 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
802 //#elif defined(__WXGTK20__)
804 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
805 // truly was double-buffered.
806 if ( !this->IsDoubleBuffered() )
808 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
812 #if wxPG_DOUBLE_BUFFER
813 delete m_doubleBuffer
;
814 m_doubleBuffer
= NULL
;
819 wxScrolledWindow::SetExtraStyle( exStyle
);
821 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
822 m_pState
->InitNonCatMode();
824 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
825 m_windowStyle
|= wxPG_TOOLTIPS
;
828 wxPGGlobalVars
->m_extraStyle
= exStyle
;
831 // -----------------------------------------------------------------------
833 // returns the best acceptable minimal size
834 wxSize
wxPropertyGrid::DoGetBestSize() const
836 int lineHeight
= wxMax(15, m_lineHeight
);
838 // don't make the grid too tall (limit height to 10 items) but don't
839 // make it too small neither
842 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
846 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
851 // -----------------------------------------------------------------------
852 // wxPropertyGrid Font and Colour Methods
853 // -----------------------------------------------------------------------
855 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
859 m_captionFont
= wxScrolledWindow::GetFont();
861 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
862 m_subgroup_extramargin
= x
+ (x
/2);
865 #if wxPG_USE_RENDERER_NATIVE
866 m_iconWidth
= wxPG_ICON_WIDTH
;
867 #elif wxPG_ICON_WIDTH
869 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
870 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
871 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
875 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
876 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
877 m_gutterWidth
= wxPG_GUTTER_MIN
;
880 if ( vspacing
<= 1 ) vdiv
= 12;
881 else if ( vspacing
>= 3 ) vdiv
= 3;
883 m_spacingy
= m_fontHeight
/ vdiv
;
884 if ( m_spacingy
< wxPG_YSPACING_MIN
)
885 m_spacingy
= wxPG_YSPACING_MIN
;
888 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
889 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
891 m_captionFont
.SetWeight(wxBOLD
);
892 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
894 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
897 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
898 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
901 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
903 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
904 RecalculateVirtualSize();
906 InvalidateBestSize();
909 // -----------------------------------------------------------------------
911 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
917 // -----------------------------------------------------------------------
919 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
920 int ga
= 1000, int ba
= 1000,
921 bool forceDifferent
= false)
928 // Recursion guard (allow 2 max)
929 static int isinside
= 0;
931 wxCHECK_MSG( isinside
< 3,
933 wxT("wxPGAdjustColour should not be recursively called more than once") );
941 if ( r2
>255 ) r2
= 255;
942 else if ( r2
<0) r2
= 0;
944 if ( g2
>255 ) g2
= 255;
945 else if ( g2
<0) g2
= 0;
947 if ( b2
>255 ) b2
= 255;
948 else if ( b2
<0) b2
= 0;
950 // Make sure they are somewhat different
951 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
952 dst
= wxPGAdjustColour(src
,-(ra
*2));
954 dst
= wxColour(r2
,g2
,b2
);
956 // Recursion guard (allow 2 max)
963 static int wxPGGetColAvg( const wxColour
& col
)
965 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
969 void wxPropertyGrid::RegainColours()
971 if ( !(m_coloursCustomized
& 0x0002) )
973 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
975 // Make sure colour is dark enough
977 int colDec
= wxPGGetColAvg(col
) - 230;
979 int colDec
= wxPGGetColAvg(col
) - 200;
982 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
985 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
988 if ( !(m_coloursCustomized
& 0x0001) )
989 m_colMargin
= m_colCapBack
;
991 if ( !(m_coloursCustomized
& 0x0004) )
998 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
999 m_colCapFore
= capForeCol
;
1000 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1003 if ( !(m_coloursCustomized
& 0x0008) )
1005 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1006 m_colPropBack
= bgCol
;
1007 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1010 if ( !(m_coloursCustomized
& 0x0010) )
1012 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1013 m_colPropFore
= fgCol
;
1014 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1017 if ( !(m_coloursCustomized
& 0x0020) )
1018 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1020 if ( !(m_coloursCustomized
& 0x0040) )
1021 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1023 if ( !(m_coloursCustomized
& 0x0080) )
1024 m_colLine
= m_colCapBack
;
1026 if ( !(m_coloursCustomized
& 0x0100) )
1027 m_colDisPropFore
= m_colCapFore
;
1029 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1032 // -----------------------------------------------------------------------
1034 void wxPropertyGrid::ResetColours()
1036 m_coloursCustomized
= 0;
1043 // -----------------------------------------------------------------------
1045 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1047 // Must disable active editor.
1048 ClearSelection(false);
1050 bool res
= wxScrolledWindow::SetFont( font
);
1051 if ( res
&& GetParent()) // may not have been Create()ed yet
1053 CalculateFontAndBitmapStuff( m_vspacing
);
1060 // -----------------------------------------------------------------------
1062 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1065 m_coloursCustomized
|= 0x80;
1069 // -----------------------------------------------------------------------
1071 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1074 m_coloursCustomized
|= 0x01;
1078 // -----------------------------------------------------------------------
1080 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1082 m_colPropBack
= col
;
1083 m_coloursCustomized
|= 0x08;
1085 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1090 // -----------------------------------------------------------------------
1092 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1094 m_colPropFore
= col
;
1095 m_coloursCustomized
|= 0x10;
1097 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1102 // -----------------------------------------------------------------------
1104 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1106 m_colEmptySpace
= col
;
1111 // -----------------------------------------------------------------------
1113 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1115 m_colDisPropFore
= col
;
1116 m_coloursCustomized
|= 0x100;
1120 // -----------------------------------------------------------------------
1122 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1125 m_coloursCustomized
|= 0x20;
1129 // -----------------------------------------------------------------------
1131 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1134 m_coloursCustomized
|= 0x40;
1138 // -----------------------------------------------------------------------
1140 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1143 m_coloursCustomized
|= 0x02;
1145 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1150 // -----------------------------------------------------------------------
1152 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1155 m_coloursCustomized
|= 0x04;
1157 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1162 // -----------------------------------------------------------------------
1163 // wxPropertyGrid property adding and removal
1164 // -----------------------------------------------------------------------
1166 void wxPropertyGrid::PrepareAfterItemsAdded()
1168 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1170 m_pState
->m_itemsAdded
= 0;
1172 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1173 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1175 RecalculateVirtualSize();
1178 // -----------------------------------------------------------------------
1179 // wxPropertyGrid property operations
1180 // -----------------------------------------------------------------------
1182 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1184 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1188 bool changed
= false;
1190 // Is it inside collapsed section?
1191 if ( !p
->IsVisible() )
1194 wxPGProperty
* parent
= p
->GetParent();
1195 wxPGProperty
* grandparent
= parent
->GetParent();
1197 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1198 Expand( grandparent
);
1206 GetViewStart(&vx
,&vy
);
1207 vy
*=wxPG_PIXELS_PER_UNIT
;
1213 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1214 m_iFlags
|= wxPG_FL_SCROLLED
;
1217 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1219 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1220 m_iFlags
|= wxPG_FL_SCROLLED
;
1230 // -----------------------------------------------------------------------
1231 // wxPropertyGrid helper methods called by properties
1232 // -----------------------------------------------------------------------
1234 // Control font changer helper.
1235 void wxPropertyGrid::SetCurControlBoldFont()
1237 wxASSERT( m_wndEditor
);
1238 m_wndEditor
->SetFont( m_captionFont
);
1241 // -----------------------------------------------------------------------
1243 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1246 #if wxPG_SMALL_SCREEN
1247 // On small-screen devices, always show dialogs with default position and size.
1248 return wxDefaultPosition
;
1250 int splitterX
= GetSplitterPosition();
1254 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1256 ImprovedClientToScreen( &x
, &y
);
1258 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1259 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1266 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1276 new_y
= y
+ m_lineHeight
;
1278 return wxPoint(new_x
,new_y
);
1282 // -----------------------------------------------------------------------
1284 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1286 if ( src_str
.length() == 0 )
1292 bool prev_is_slash
= false;
1294 wxString::const_iterator i
= src_str
.begin();
1298 for ( ; i
!= src_str
.end(); ++i
)
1302 if ( a
!= wxS('\\') )
1304 if ( !prev_is_slash
)
1310 if ( a
== wxS('n') )
1313 dst_str
<< wxS('\n');
1315 dst_str
<< wxS('\n');
1318 else if ( a
== wxS('t') )
1319 dst_str
<< wxS('\t');
1323 prev_is_slash
= false;
1327 if ( prev_is_slash
)
1329 dst_str
<< wxS('\\');
1330 prev_is_slash
= false;
1334 prev_is_slash
= true;
1341 // -----------------------------------------------------------------------
1343 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1345 if ( src_str
.length() == 0 )
1351 wxString::const_iterator i
= src_str
.begin();
1352 wxUniChar prev_a
= wxS('\0');
1356 for ( ; i
!= src_str
.end(); ++i
)
1360 if ( a
>= wxS(' ') )
1362 // This surely is not something that requires an escape sequence.
1367 // This might need...
1368 if ( a
== wxS('\r') )
1370 // DOS style line end.
1371 // Already taken care below
1373 else if ( a
== wxS('\n') )
1374 // UNIX style line end.
1375 dst_str
<< wxS("\\n");
1376 else if ( a
== wxS('\t') )
1378 dst_str
<< wxS('\t');
1381 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1391 // -----------------------------------------------------------------------
1393 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1400 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1403 // -----------------------------------------------------------------------
1404 // wxPropertyGrid graphics related methods
1405 // -----------------------------------------------------------------------
1407 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1411 // Update everything inside the box
1412 wxRect r
= GetUpdateRegion().GetBox();
1414 dc
.SetPen(m_colEmptySpace
);
1415 dc
.SetBrush(m_colEmptySpace
);
1416 dc
.DrawRectangle(r
);
1419 // -----------------------------------------------------------------------
1421 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1422 wxPGProperty
* property
) const
1424 // Prepare rectangle to be used
1426 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1427 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1429 #if (wxPG_USE_RENDERER_NATIVE)
1431 #elif wxPG_ICON_WIDTH
1432 // Drawing expand/collapse button manually
1433 dc
.SetPen(m_colPropFore
);
1434 if ( property
->IsCategory() )
1435 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1437 dc
.SetBrush(m_colPropBack
);
1439 dc
.DrawRectangle( r
);
1440 int _y
= r
.y
+(m_iconWidth
/2);
1441 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1446 if ( property
->IsExpanded() )
1448 // wxRenderer functions are non-mutating in nature, so it
1449 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1450 // Hopefully this does not cause problems.
1451 #if (wxPG_USE_RENDERER_NATIVE)
1452 wxRendererNative::Get().DrawTreeItemButton(
1458 #elif wxPG_ICON_WIDTH
1467 #if (wxPG_USE_RENDERER_NATIVE)
1468 wxRendererNative::Get().DrawTreeItemButton(
1474 #elif wxPG_ICON_WIDTH
1475 int _x
= r
.x
+(m_iconWidth
/2);
1476 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1482 #if (wxPG_USE_RENDERER_NATIVE)
1484 #elif wxPG_ICON_WIDTH
1487 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1491 // -----------------------------------------------------------------------
1494 // This is the one called by OnPaint event handler and others.
1495 // topy and bottomy are already unscrolled (ie. physical)
1497 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1499 unsigned int bottomy
,
1500 const wxRect
* clipRect
)
1502 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1504 m_pState
->EnsureVirtualHeight();
1506 wxRect tempClipRect
;
1509 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1510 clipRect
= &tempClipRect
;
1513 // items added check
1514 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1516 int paintFinishY
= 0;
1518 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1521 bool isBuffered
= false;
1523 #if wxPG_DOUBLE_BUFFER
1524 wxMemoryDC
* bufferDC
= NULL
;
1526 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1528 if ( !m_doubleBuffer
)
1530 paintFinishY
= clipRect
->y
;
1535 bufferDC
= new wxMemoryDC();
1537 // If nothing was changed, then just copy from double-buffer
1538 bufferDC
->SelectObject( *m_doubleBuffer
);
1548 dc
.SetClippingRegion( *clipRect
);
1549 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1552 #if wxPG_DOUBLE_BUFFER
1555 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1556 bufferDC
, 0, 0, wxCOPY
);
1557 dc
.DestroyClippingRegion(); // Is this really necessary?
1563 // Clear area beyond bottomY?
1564 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1566 dc
.SetPen(m_colEmptySpace
);
1567 dc
.SetBrush(m_colEmptySpace
);
1568 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1572 // -----------------------------------------------------------------------
1574 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1575 const wxRect
* clipRect
,
1576 bool isBuffered
) const
1578 const wxPGProperty
* firstItem
;
1579 const wxPGProperty
* lastItem
;
1581 firstItem
= DoGetItemAtY(clipRect
->y
);
1582 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1585 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1587 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1590 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1591 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1593 int lh
= m_lineHeight
;
1596 int lastItemBottomY
;
1598 firstItemTopY
= clipRect
->y
;
1599 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1601 // Align y coordinates to item boundaries
1602 firstItemTopY
-= firstItemTopY
% lh
;
1603 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1604 lastItemBottomY
-= 1;
1606 // Entire range outside scrolled, visible area?
1607 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1610 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1614 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1615 firstItem->GetLabel().c_str(),
1616 lastItem->GetLabel().c_str(),
1617 (int)(lastItemBottomY - firstItemTopY),
1619 (unsigned long)clipRect );
1624 long windowStyle
= m_windowStyle
;
1630 // With wxPG_DOUBLE_BUFFER, do double buffering
1631 // - buffer's y = 0, so align cliprect and coordinates to that
1633 #if wxPG_DOUBLE_BUFFER
1639 xRelMod
= clipRect
->x
;
1640 yRelMod
= clipRect
->y
;
1643 // clipRect conversion
1648 firstItemTopY
-= yRelMod
;
1649 lastItemBottomY
-= yRelMod
;
1652 wxUnusedVar(isBuffered
);
1655 int x
= m_marginWidth
- xRelMod
;
1657 wxFont normalFont
= GetFont();
1659 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1661 bool isEnabled
= IsEnabled();
1664 // Prepare some pens and brushes that are often changed to.
1667 wxBrush
marginBrush(m_colMargin
);
1668 wxPen
marginPen(m_colMargin
);
1669 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1670 wxPen
linepen(m_colLine
,1,wxSOLID
);
1672 // pen that has same colour as text
1673 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1676 // Clear margin with background colour
1678 dc
.SetBrush( marginBrush
);
1679 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1681 dc
.SetPen( *wxTRANSPARENT_PEN
);
1682 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1685 const wxPGProperty
* selected
= m_selected
;
1686 const wxPropertyGridPageState
* state
= m_pState
;
1688 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1689 bool wasSelectedPainted
= false;
1692 // TODO: Only render columns that are within clipping region.
1694 dc
.SetFont(normalFont
);
1696 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1697 int endScanBottomY
= lastItemBottomY
+ lh
;
1698 int y
= firstItemTopY
;
1701 // Pregenerate list of visible properties.
1702 wxArrayPGProperty visPropArray
;
1703 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1705 for ( ; !it
.AtEnd(); it
.Next() )
1707 const wxPGProperty
* p
= *it
;
1709 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1711 visPropArray
.push_back((wxPGProperty
*)p
);
1713 if ( y
> endScanBottomY
)
1720 visPropArray
.push_back(NULL
);
1722 wxPGProperty
* nextP
= visPropArray
[0];
1724 int gridWidth
= state
->m_width
;
1727 for ( unsigned int arrInd
=1;
1728 nextP
&& y
<= lastItemBottomY
;
1731 wxPGProperty
* p
= nextP
;
1732 nextP
= visPropArray
[arrInd
];
1734 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1735 int textMarginHere
= x
;
1736 int renderFlags
= 0;
1738 int greyDepth
= m_marginWidth
;
1739 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1740 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1742 int greyDepthX
= greyDepth
- xRelMod
;
1744 // Use basic depth if in non-categoric mode and parent is base array.
1745 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1747 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1750 // Paint margin area
1751 dc
.SetBrush(marginBrush
);
1752 dc
.SetPen(marginPen
);
1753 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1755 dc
.SetPen( linepen
);
1760 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1766 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1768 sx
+= state
->m_colWidths
[si
];
1769 dc
.DrawLine( sx
, y
, sx
, y2
);
1772 // Horizontal Line, below
1773 // (not if both this and next is category caption)
1774 if ( p
->IsCategory() &&
1775 nextP
&& nextP
->IsCategory() )
1776 dc
.SetPen(m_colCapBack
);
1778 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1781 // Need to override row colours?
1785 if ( p
!= selected
)
1787 // Disabled may get different colour.
1788 if ( !p
->IsEnabled() )
1790 renderFlags
|= wxPGCellRenderer::Disabled
|
1791 wxPGCellRenderer::DontUseCellFgCol
;
1792 rowFgCol
= m_colDisPropFore
;
1797 renderFlags
|= wxPGCellRenderer::Selected
;
1799 if ( !p
->IsCategory() )
1801 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1802 wxPGCellRenderer::DontUseCellBgCol
;
1804 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1805 wasSelectedPainted
= true;
1808 // Selected gets different colour.
1809 if ( reallyFocused
)
1811 rowFgCol
= m_colSelFore
;
1812 rowBgCol
= m_colSelBack
;
1814 else if ( isEnabled
)
1816 rowFgCol
= m_colPropFore
;
1817 rowBgCol
= m_colMargin
;
1821 rowFgCol
= m_colDisPropFore
;
1822 rowBgCol
= m_colSelBack
;
1829 if ( rowBgCol
.IsOk() )
1830 rowBgBrush
= wxBrush(rowBgCol
);
1832 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1833 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1836 // Fill additional margin area with background colour of first cell
1837 if ( greyDepthX
< textMarginHere
)
1839 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1841 wxPGCell
& cell
= p
->GetCell(0);
1842 rowBgCol
= cell
.GetBgCol();
1843 rowBgBrush
= wxBrush(rowBgCol
);
1845 dc
.SetBrush(rowBgBrush
);
1846 dc
.SetPen(rowBgCol
);
1847 dc
.DrawRectangle(greyDepthX
+1, y
,
1848 textMarginHere
-greyDepthX
, lh
-1);
1851 bool fontChanged
= false;
1853 // Expander button rectangle
1854 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1859 if ( p
->IsCategory() )
1861 // Captions have their cell areas merged as one
1862 dc
.SetFont(m_captionFont
);
1864 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1866 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1868 dc
.SetBrush(rowBgBrush
);
1869 dc
.SetPen(rowBgCol
);
1872 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1874 dc
.SetTextForeground(rowFgCol
);
1877 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1878 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1881 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1882 DrawExpanderButton( dc
, butRect
, p
);
1886 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1888 dc
.SetFont(m_captionFont
);
1894 int nextCellWidth
= state
->m_colWidths
[0] -
1895 (greyDepthX
- m_marginWidth
);
1896 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1897 int textXAdd
= textMarginHere
- greyDepthX
;
1899 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1901 cellRect
.width
= nextCellWidth
- 1;
1903 bool ctrlCell
= false;
1904 int cellRenderFlags
= renderFlags
;
1907 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1908 DrawExpanderButton( dc
, butRect
, p
);
1911 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1913 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1914 dc
.SetBrush(editorBgCol
);
1915 dc
.SetPen(editorBgCol
);
1916 dc
.SetTextForeground(m_colPropFore
);
1917 dc
.DrawRectangle(cellRect
);
1919 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1924 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1926 dc
.SetBrush(rowBgBrush
);
1927 dc
.SetPen(rowBgCol
);
1930 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1932 dc
.SetTextForeground(rowFgCol
);
1936 dc
.SetClippingRegion(cellRect
);
1938 cellRect
.x
+= textXAdd
;
1939 cellRect
.width
-= textXAdd
;
1944 wxPGCellRenderer
* renderer
;
1945 int cmnVal
= p
->GetCommonValue();
1946 if ( cmnVal
== -1 || ci
!= 1 )
1948 renderer
= p
->GetCellRenderer(ci
);
1949 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1954 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1955 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1960 cellX
+= state
->m_colWidths
[ci
];
1961 if ( ci
< (state
->m_colWidths
.size()-1) )
1962 nextCellWidth
= state
->m_colWidths
[ci
+1];
1964 dc
.DestroyClippingRegion(); // Is this really necessary?
1970 dc
.SetFont(normalFont
);
1975 // Refresh editor controls (seems not needed on msw)
1976 // NOTE: This code is mandatory for GTK!
1977 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1978 if ( wasSelectedPainted
)
1981 m_wndEditor
->Refresh();
1983 m_wndEditor2
->Refresh();
1990 // -----------------------------------------------------------------------
1992 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1996 if ( m_width
< 10 || m_height
< 10 ||
1997 !m_pState
->m_properties
->GetChildCount() ||
1999 return wxRect(0,0,0,0);
2004 // Return rect which encloses the given property range
2006 int visTop
= p1
->GetY();
2009 visBottom
= p2
->GetY() + m_lineHeight
;
2011 visBottom
= m_height
+ visTop
;
2013 // If seleced property is inside the range, we'll extend the range to include
2015 wxPGProperty
* selected
= m_selected
;
2018 int selectedY
= selected
->GetY();
2019 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2021 wxWindow
* editor
= GetEditorControl();
2024 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2025 if ( visBottom2
> visBottom
)
2026 visBottom
= visBottom2
;
2031 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2034 // -----------------------------------------------------------------------
2036 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2041 if ( m_pState
->m_itemsAdded
)
2042 PrepareAfterItemsAdded();
2044 wxRect r
= GetPropertyRect(p1
, p2
);
2047 m_canvas
->RefreshRect(r
);
2051 // -----------------------------------------------------------------------
2053 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2055 if ( p
== m_selected
)
2056 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2058 DrawItemAndChildren(p
);
2061 // -----------------------------------------------------------------------
2063 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2068 // Draw item, children, and parent too, if it is not category
2069 wxPGProperty
* parent
= p
->GetParent();
2072 !parent
->IsCategory() &&
2073 parent
->GetParent() )
2076 parent
= parent
->GetParent();
2079 DrawItemAndChildren(p
);
2082 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2084 wxCHECK_RET( p
, wxT("invalid property id") );
2086 // Do not draw if in non-visible page
2087 if ( p
->GetParentState() != m_pState
)
2090 // do not draw a single item if multiple pending
2091 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2094 // Update child control.
2095 if ( m_selected
&& m_selected
->GetParent() == p
)
2098 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2100 DrawItems(p
, lastDrawn
);
2103 // -----------------------------------------------------------------------
2105 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2106 const wxRect
*rect
)
2108 PrepareAfterItemsAdded();
2110 wxWindow::Refresh(false);
2112 // TODO: Coordinate translation
2113 m_canvas
->Refresh(false, rect
);
2115 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2116 // I think this really helps only GTK+1.2
2117 if ( m_wndEditor
) m_wndEditor
->Refresh();
2118 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2122 // -----------------------------------------------------------------------
2123 // wxPropertyGrid global operations
2124 // -----------------------------------------------------------------------
2126 void wxPropertyGrid::Clear()
2128 m_pState
->DoClear();
2134 RecalculateVirtualSize();
2136 // Need to clear some area at the end
2138 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2141 // -----------------------------------------------------------------------
2143 bool wxPropertyGrid::EnableCategories( bool enable
)
2145 ClearSelection(false);
2150 // Enable categories
2153 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2158 // Disable categories
2160 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2163 if ( !m_pState
->EnableCategories(enable
) )
2168 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2170 m_pState
->m_itemsAdded
= 1; // force
2171 PrepareAfterItemsAdded();
2175 m_pState
->m_itemsAdded
= 1;
2177 // No need for RecalculateVirtualSize() here - it is already called in
2178 // wxPropertyGridPageState method above.
2185 // -----------------------------------------------------------------------
2187 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2189 wxASSERT( pNewState
);
2190 wxASSERT( pNewState
->GetGrid() );
2192 if ( pNewState
== m_pState
)
2195 wxPGProperty
* oldSelection
= m_selected
;
2197 ClearSelection(false);
2199 m_pState
->m_selected
= oldSelection
;
2201 bool orig_mode
= m_pState
->IsInNonCatMode();
2202 bool new_state_mode
= pNewState
->IsInNonCatMode();
2204 m_pState
= pNewState
;
2207 int pgWidth
= GetClientSize().x
;
2208 if ( HasVirtualWidth() )
2210 int minWidth
= pgWidth
;
2211 if ( pNewState
->m_width
< minWidth
)
2213 pNewState
->m_width
= minWidth
;
2214 pNewState
->CheckColumnWidths();
2220 // Just in case, fully re-center splitter
2221 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2222 pNewState
->m_fSplitterX
= -1.0;
2224 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2229 // If necessary, convert state to correct mode.
2230 if ( orig_mode
!= new_state_mode
)
2232 // This should refresh as well.
2233 EnableCategories( orig_mode
?false:true );
2235 else if ( !m_frozen
)
2237 // Refresh, if not frozen.
2238 m_pState
->PrepareAfterItemsAdded();
2241 if ( m_pState
->m_selected
)
2242 DoSelectProperty( m_pState
->m_selected
);
2244 RecalculateVirtualSize(0);
2248 m_pState
->m_itemsAdded
= 1;
2251 // -----------------------------------------------------------------------
2253 // Call to SetSplitterPosition will always disable splitter auto-centering
2254 // if parent window is shown.
2255 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2257 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2260 wxPropertyGridPageState
* state
= m_pState
;
2262 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2267 CorrectEditorWidgetSizeX();
2273 // -----------------------------------------------------------------------
2275 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2277 SetSplitterPosition( m_width
/2, true );
2278 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2279 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2282 // -----------------------------------------------------------------------
2283 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2284 // -----------------------------------------------------------------------
2286 // Returns nearest paint visible property (such that will be painted unless
2287 // window is scrolled or resized). If given property is paint visible, then
2288 // it itself will be returned
2289 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2291 int vx
,vy1
;// Top left corner of client
2292 GetViewStart(&vx
,&vy1
);
2293 vy1
*= wxPG_PIXELS_PER_UNIT
;
2295 int vy2
= vy1
+ m_height
;
2296 int propY
= p
->GetY2(m_lineHeight
);
2298 if ( (propY
+ m_lineHeight
) < vy1
)
2301 return DoGetItemAtY( vy1
);
2303 else if ( propY
> vy2
)
2306 return DoGetItemAtY( vy2
);
2309 // Itself paint visible
2314 // -----------------------------------------------------------------------
2315 // Methods related to change in value, value modification and sending events
2316 // -----------------------------------------------------------------------
2318 // commits any changes in editor of selected property
2319 // return true if validation did not fail
2320 // flags are same as with DoSelectProperty
2321 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2323 // Committing already?
2324 if ( m_inCommitChangesFromEditor
)
2327 // Don't do this if already processing editor event. It might
2328 // induce recursive dialogs and crap like that.
2329 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2331 if ( m_inDoPropertyChanged
)
2338 IsEditorsValueModified() &&
2339 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2342 m_inCommitChangesFromEditor
= 1;
2344 wxVariant
variant(m_selected
->GetValueRef());
2345 bool valueIsPending
= false;
2347 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2348 // due to another window getting focus
2349 wxWindow
* oldFocus
= m_curFocused
;
2351 bool validationFailure
= false;
2352 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2354 m_chgInfo_changedProperty
= NULL
;
2356 // If truly modified, schedule value as pending.
2357 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2359 if ( DoEditorValidate() &&
2360 PerformValidation(m_selected
, variant
) )
2362 valueIsPending
= true;
2366 validationFailure
= true;
2371 EditorsValueWasNotModified();
2376 m_inCommitChangesFromEditor
= 0;
2378 if ( validationFailure
&& !forceSuccess
)
2382 oldFocus
->SetFocus();
2383 m_curFocused
= oldFocus
;
2386 res
= OnValidationFailure(m_selected
, variant
);
2388 // Now prevent further validation failure messages
2391 EditorsValueWasNotModified();
2392 OnValidationFailureReset(m_selected
);
2395 else if ( valueIsPending
)
2397 DoPropertyChanged( m_selected
, flags
);
2398 EditorsValueWasNotModified();
2407 // -----------------------------------------------------------------------
2409 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2413 // Runs all validation functionality.
2414 // Returns true if value passes all tests.
2417 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2419 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2421 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2426 // Adapt list to child values, if necessary
2427 wxVariant listValue
= pendingValue
;
2428 wxVariant
* pPendingValue
= &pendingValue
;
2429 wxVariant
* pList
= NULL
;
2431 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2432 // string value, then we need treat as it was changed instead
2433 // (or, in addition, as is the case with composite string parent).
2434 // This includes creating list variant for child values.
2436 wxPGProperty
* pwc
= p
->GetParent();
2437 wxPGProperty
* changedProperty
= p
;
2438 wxPGProperty
* baseChangedProperty
= changedProperty
;
2439 wxVariant bcpPendingList
;
2441 listValue
= pendingValue
;
2442 listValue
.SetName(p
->GetBaseName());
2445 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2447 wxVariantList tempList
;
2448 wxVariant
lv(tempList
, pwc
->GetBaseName());
2449 lv
.Append(listValue
);
2451 pPendingValue
= &listValue
;
2453 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2455 baseChangedProperty
= pwc
;
2456 bcpPendingList
= lv
;
2459 changedProperty
= pwc
;
2460 pwc
= pwc
->GetParent();
2464 wxPGProperty
* evtChangingProperty
= changedProperty
;
2466 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2468 value
= *pPendingValue
;
2472 // Convert list to child values
2473 pList
= pPendingValue
;
2474 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2477 wxVariant evtChangingValue
= value
;
2479 if ( flags
& SendEvtChanging
)
2481 // FIXME: After proper ValueToString()s added, remove
2482 // this. It is just a temporary fix, as evt_changing
2483 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2484 // (unless it is selected, and textctrl editor is open).
2485 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2487 evtChangingProperty
= baseChangedProperty
;
2488 if ( evtChangingProperty
!= p
)
2490 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2494 evtChangingValue
= pendingValue
;
2498 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2500 if ( changedProperty
== m_selected
)
2502 wxWindow
* editor
= GetEditorControl();
2503 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2504 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2508 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2513 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2514 m_chgInfo_changedProperty
= changedProperty
;
2515 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2516 m_chgInfo_pendingValue
= value
;
2519 m_chgInfo_valueList
= *pList
;
2521 m_chgInfo_valueList
.MakeNull();
2523 // If changedProperty is not property which value was edited,
2524 // then call wxPGProperty::ValidateValue() for that as well.
2525 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2527 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2531 if ( flags
& SendEvtChanging
)
2533 // SendEvent returns true if event was vetoed
2534 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2538 if ( flags
& IsStandaloneValidation
)
2540 // If called in 'generic' context, we need to reset
2541 // m_chgInfo_changedProperty and write back translated value.
2542 m_chgInfo_changedProperty
= NULL
;
2543 pendingValue
= value
;
2549 // -----------------------------------------------------------------------
2551 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2553 if ( !msg
.length() )
2557 if ( !wxPGGlobalVars
->m_offline
)
2559 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2562 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2565 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2568 pStatusBar
->SetStatusText(msg
);
2576 ::wxMessageBox(msg
, _T("Property Error"));
2579 // -----------------------------------------------------------------------
2581 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2582 wxVariant
& invalidValue
)
2584 wxWindow
* editor
= GetEditorControl();
2586 // First call property's handler
2587 property
->OnValidationFailure(invalidValue
);
2589 bool res
= DoOnValidationFailure(property
, invalidValue
);
2592 // For non-wxTextCtrl editors, we do need to revert the value
2593 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2594 property
== m_selected
)
2596 property
->GetEditorClass()->UpdateControl(property
, editor
);
2599 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2604 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2606 int vfb
= m_validationInfo
.m_failureBehavior
;
2608 if ( vfb
& wxPG_VFB_BEEP
)
2611 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2612 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2614 unsigned int colCount
= m_pState
->GetColumnCount();
2616 // We need backup marked property's cells
2617 m_propCellsBackup
= property
->m_cells
;
2619 wxColour vfbFg
= *wxWHITE
;
2620 wxColour vfbBg
= *wxRED
;
2622 property
->EnsureCells(colCount
);
2624 for ( unsigned int i
=0; i
<colCount
; i
++ )
2626 wxPGCell
& cell
= property
->m_cells
[i
];
2627 cell
.SetFgCol(vfbFg
);
2628 cell
.SetBgCol(vfbBg
);
2631 DrawItemAndChildren(property
);
2633 if ( property
== m_selected
)
2635 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2637 wxWindow
* editor
= GetEditorControl();
2640 editor
->SetForegroundColour(vfbFg
);
2641 editor
->SetBackgroundColour(vfbBg
);
2646 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2648 wxString msg
= m_validationInfo
.m_failureMessage
;
2650 if ( !msg
.length() )
2651 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2653 DoShowPropertyError(property
, msg
);
2656 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2659 // -----------------------------------------------------------------------
2661 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2663 int vfb
= m_validationInfo
.m_failureBehavior
;
2665 if ( vfb
& wxPG_VFB_MARK_CELL
)
2668 property
->m_cells
= m_propCellsBackup
;
2670 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2672 if ( property
== m_selected
&& GetEditorControl() )
2674 // Calling this will recreate the control, thus resetting its colour
2675 RefreshProperty(property
);
2679 DrawItemAndChildren(property
);
2684 // -----------------------------------------------------------------------
2686 // flags are same as with DoSelectProperty
2687 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2689 if ( m_inDoPropertyChanged
)
2692 wxWindow
* editor
= GetEditorControl();
2694 m_pState
->m_anyModified
= 1;
2696 m_inDoPropertyChanged
= 1;
2698 // Maybe need to update control
2699 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2701 // These values were calculated in PerformValidation()
2702 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2703 wxVariant value
= m_chgInfo_pendingValue
;
2705 wxPGProperty
* topPaintedProperty
= changedProperty
;
2707 while ( !topPaintedProperty
->IsCategory() &&
2708 !topPaintedProperty
->IsRoot() )
2710 topPaintedProperty
= topPaintedProperty
->GetParent();
2713 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2715 // Set as Modified (not if dragging just began)
2716 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2718 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2719 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2722 SetCurControlBoldFont();
2728 // Propagate updates to parent(s)
2730 wxPGProperty
* prevPwc
= NULL
;
2732 while ( prevPwc
!= topPaintedProperty
)
2734 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2736 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2739 SetCurControlBoldFont();
2743 pwc
= pwc
->GetParent();
2746 // Draw the actual property
2747 DrawItemAndChildren( topPaintedProperty
);
2750 // If value was set by wxPGProperty::OnEvent, then update the editor
2752 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2758 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2759 if ( m_wndEditor
) m_wndEditor
->Refresh();
2760 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2765 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2767 // If top parent has composite string value, then send to child parents,
2768 // starting from baseChangedProperty.
2769 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2771 pwc
= m_chgInfo_baseChangedProperty
;
2773 while ( pwc
!= changedProperty
)
2775 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2776 pwc
= pwc
->GetParent();
2780 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2782 m_inDoPropertyChanged
= 0;
2787 // -----------------------------------------------------------------------
2789 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2791 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2793 m_chgInfo_changedProperty
= NULL
;
2795 if ( PerformValidation(p
, newValue
) )
2797 DoPropertyChanged(p
);
2802 OnValidationFailure(p
, newValue
);
2808 // -----------------------------------------------------------------------
2810 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2812 wxPGProperty
* prop
= GetSelectedProperty();
2815 return wxNullVariant
;
2817 wxTextCtrl
* tc
= GetEditorTextCtrl();
2818 wxVariant value
= prop
->GetValue();
2820 if ( !tc
|| !IsEditorsValueModified() )
2823 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2826 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2827 return prop
->GetValue();
2832 // -----------------------------------------------------------------------
2834 // Runs wxValidator for the selected property
2835 bool wxPropertyGrid::DoEditorValidate()
2840 // -----------------------------------------------------------------------
2842 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2844 wxPGProperty
* selected
= m_selected
;
2846 // Somehow, event is handled after property has been deselected.
2847 // Possibly, but very rare.
2851 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2854 wxVariant
pendingValue(selected
->GetValueRef());
2855 wxWindow
* wnd
= GetEditorControl();
2856 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2858 bool wasUnspecified
= selected
->IsValueUnspecified();
2859 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2860 bool valueIsPending
= false;
2862 m_chgInfo_changedProperty
= NULL
;
2864 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2867 // Filter out excess wxTextCtrl modified events
2868 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2870 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2872 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2874 wxString newTcValue
= tc
->GetValue();
2875 if ( m_prevTcValue
== newTcValue
)
2878 m_prevTcValue
= newTcValue
;
2881 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2883 bool validationFailure
= false;
2884 bool buttonWasHandled
= false;
2887 // Try common button handling
2888 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2890 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2894 buttonWasHandled
= true;
2895 // Store as res2, as previously (and still currently alternatively)
2896 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2897 // in wxPGProperty::OnEvent().
2898 adapter
->ShowDialog( this, selected
);
2903 if ( !buttonWasHandled
)
2905 if ( wnd
|| m_wndEditor2
)
2907 // First call editor class' event handler.
2908 const wxPGEditor
* editor
= selected
->GetEditorClass();
2910 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2912 // If changes, validate them
2913 if ( DoEditorValidate() )
2915 if ( editor
->GetValueFromControl( pendingValue
,
2918 valueIsPending
= true;
2922 validationFailure
= true;
2927 // Then the property's custom handler (must be always called, unless
2928 // validation failed).
2929 if ( !validationFailure
)
2930 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2933 // SetValueInEvent(), as called in one of the functions referred above
2934 // overrides editor's value.
2935 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2937 valueIsPending
= true;
2938 pendingValue
= m_changeInEventValue
;
2939 selFlags
|= wxPG_SEL_DIALOGVAL
;
2942 if ( !validationFailure
&& valueIsPending
)
2943 if ( !PerformValidation(m_selected
, pendingValue
) )
2944 validationFailure
= true;
2946 if ( validationFailure
)
2948 OnValidationFailure(selected
, pendingValue
);
2950 else if ( valueIsPending
)
2952 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2954 DoPropertyChanged(selected
, selFlags
);
2955 EditorsValueWasNotModified();
2957 // Regardless of editor type, unfocus editor on
2958 // text-editing related enter press.
2959 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2966 // No value after all
2968 // Regardless of editor type, unfocus editor on
2969 // text-editing related enter press.
2970 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2975 // Let unhandled button click events go to the parent
2976 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2978 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2979 GetEventHandler()->AddPendingEvent(evt
);
2983 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2986 // -----------------------------------------------------------------------
2987 // wxPropertyGrid editor control helper methods
2988 // -----------------------------------------------------------------------
2990 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2992 int itemy
= p
->GetY2(m_lineHeight
);
2994 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2995 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2996 int imageOffset
= 0;
2998 // TODO: If custom image detection changes from current, change this.
2999 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3001 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3002 int iw
= p
->OnMeasureImage().x
;
3004 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3005 imageOffset
= p
->GetImageOffset(iw
);
3010 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3012 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3017 // -----------------------------------------------------------------------
3019 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3021 wxSize sz
= GetImageSize(p
, item
);
3022 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3023 wxPG_CUSTOM_IMAGE_SPACINGY
,
3028 // return size of custom paint image
3029 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3031 // If called with NULL property, then return default image
3032 // size for properties that use image.
3034 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3036 wxSize cis
= p
->OnMeasureImage(item
);
3038 int choiceCount
= p
->m_choices
.GetCount();
3039 int comVals
= p
->GetDisplayedCommonValueCount();
3040 if ( item
>= choiceCount
&& comVals
> 0 )
3042 unsigned int cvi
= item
-choiceCount
;
3043 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3045 else if ( item
>= 0 && choiceCount
== 0 )
3046 return wxSize(0, 0);
3051 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3056 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3063 // -----------------------------------------------------------------------
3065 // takes scrolling into account
3066 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3069 GetViewStart(&vx
,&vy
);
3070 vy
*=wxPG_PIXELS_PER_UNIT
;
3071 vx
*=wxPG_PIXELS_PER_UNIT
;
3074 ClientToScreen( px
, py
);
3077 // -----------------------------------------------------------------------
3079 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3082 GetViewStart(&pt2
.x
,&pt2
.y
);
3083 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3084 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3088 return m_pState
->HitTest(pt2
);
3091 // -----------------------------------------------------------------------
3093 // custom set cursor
3094 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3096 if ( type
== m_curcursor
&& !override
) return;
3098 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3100 if ( type
== wxCURSOR_SIZEWE
)
3101 cursor
= m_cursorSizeWE
;
3103 m_canvas
->SetCursor( *cursor
);
3108 // -----------------------------------------------------------------------
3109 // wxPropertyGrid property selection, editor creation
3110 // -----------------------------------------------------------------------
3113 // This class forwards events from property editor controls to wxPropertyGrid.
3114 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3117 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3118 : wxEvtHandler(), m_propGrid(propGrid
)
3122 virtual ~wxPropertyGridEditorEventForwarder()
3127 bool ProcessEvent( wxEvent
& event
)
3132 m_propGrid
->HandleCustomEditorEvent(event
);
3134 return wxEvtHandler::ProcessEvent(event
);
3137 wxPropertyGrid
* m_propGrid
;
3140 // Setups event handling for child control
3141 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3143 wxWindowID id
= argWnd
->GetId();
3145 if ( argWnd
== m_wndEditor
)
3147 argWnd
->Connect(id
, wxEVT_MOTION
,
3148 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3150 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3151 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3153 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3154 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3156 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3157 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3159 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3160 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3162 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3163 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3167 wxPropertyGridEditorEventForwarder
* forwarder
;
3168 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3169 argWnd
->PushEventHandler(forwarder
);
3171 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3172 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3176 void wxPropertyGrid::FreeEditors()
3179 // Return focus back to canvas from children (this is required at least for
3180 // GTK+, which, unlike Windows, clears focus when control is destroyed
3181 // instead of moving it to closest parent).
3182 wxWindow
* focus
= wxWindow::FindFocus();
3185 wxWindow
* parent
= focus
->GetParent();
3188 if ( parent
== m_canvas
)
3193 parent
= parent
->GetParent();
3197 // Do not free editors immediately if processing events
3200 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3201 m_wndEditor2
->Hide();
3202 wxPendingDelete
.Append( handler
);
3203 wxPendingDelete
.Append( m_wndEditor2
);
3204 m_wndEditor2
= NULL
;
3209 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3210 m_wndEditor
->Hide();
3211 wxPendingDelete
.Append( handler
);
3212 wxPendingDelete
.Append( m_wndEditor
);
3217 // Call with NULL to de-select property
3218 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3222 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3223 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3225 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3228 if ( m_inDoSelectProperty
)
3231 m_inDoSelectProperty
= 1;
3233 wxPGProperty
* prev
= m_selected
;
3237 m_inDoSelectProperty
= 0;
3243 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3245 wxPrintf( "None selected\n" );
3248 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3250 wxPrintf( "P = NULL\n" );
3253 // If we are frozen, then just set the values.
3256 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3257 m_editorFocused
= 0;
3260 m_pState
->m_selected
= p
;
3262 // If frozen, always free controls. But don't worry, as Thaw will
3263 // recall SelectProperty to recreate them.
3266 // Prevent any further selection measures in this call
3272 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3274 // Only set focus if not deselecting
3277 if ( flags
& wxPG_SEL_FOCUS
)
3281 m_wndEditor
->SetFocus();
3282 m_editorFocused
= 1;
3291 m_inDoSelectProperty
= 0;
3296 // First, deactivate previous
3300 OnValidationFailureReset(m_selected
);
3302 // Must double-check if this is an selected in case of forceswitch
3305 if ( !CommitChangesFromEditor(flags
) )
3307 // Validation has failed, so we can't exit the previous editor
3308 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3309 // _("Invalid Value"),wxOK|wxICON_ERROR);
3310 m_inDoSelectProperty
= 0;
3319 m_pState
->m_selected
= NULL
;
3321 // We need to always fully refresh the grid here
3324 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3325 EditorsValueWasNotModified();
3328 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3331 // Then, activate the one given.
3334 int propY
= p
->GetY2(m_lineHeight
);
3336 int splitterX
= GetSplitterPosition();
3337 m_editorFocused
= 0;
3339 m_pState
->m_selected
= p
;
3340 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3342 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3344 wxASSERT( m_wndEditor
== NULL
);
3347 // Only create editor for non-disabled non-caption
3348 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3350 // do this for non-caption items
3354 // Do we need to paint the custom image, if any?
3355 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3356 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3357 !p
->GetEditorClass()->CanContainCustomImage()
3359 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3361 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3362 wxPoint goodPos
= grect
.GetPosition();
3363 #if wxPG_CREATE_CONTROLS_HIDDEN
3364 int coord_adjust
= m_height
- goodPos
.y
;
3365 goodPos
.y
+= coord_adjust
;
3368 const wxPGEditor
* editor
= p
->GetEditorClass();
3369 wxCHECK_MSG(editor
, false,
3370 wxT("NULL editor class not allowed"));
3372 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3374 wxPGWindowList wndList
= editor
->CreateControls(this,
3379 m_wndEditor
= wndList
.m_primary
;
3380 m_wndEditor2
= wndList
.m_secondary
;
3381 wxWindow
* primaryCtrl
= GetEditorControl();
3384 // Essentially, primaryCtrl == m_wndEditor
3387 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3388 // value is drawn as normal, and m_wndEditor2 is assumed
3389 // to be a right-aligned button that triggers a separate editorCtrl
3394 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3395 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3397 // Set validator, if any
3398 #if wxUSE_VALIDATORS
3399 wxValidator
* validator
= p
->GetValidator();
3401 primaryCtrl
->SetValidator(*validator
);
3404 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3405 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3407 // If it has modified status, use bold font
3408 // (must be done before capturing m_ctrlXAdjust)
3409 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3410 SetCurControlBoldFont();
3413 // Fix TextCtrl indentation
3414 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3415 wxTextCtrl
* tc
= NULL
;
3416 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3417 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3419 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3421 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3424 // Store x relative to splitter (we'll need it).
3425 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3427 // Check if background clear is not necessary
3428 wxPoint pos
= m_wndEditor
->GetPosition();
3429 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3431 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3434 m_wndEditor
->SetSizeHints(3, 3);
3436 #if wxPG_CREATE_CONTROLS_HIDDEN
3437 m_wndEditor
->Show(false);
3438 m_wndEditor
->Freeze();
3440 goodPos
= m_wndEditor
->GetPosition();
3441 goodPos
.y
-= coord_adjust
;
3442 m_wndEditor
->Move( goodPos
);
3445 SetupChildEventHandling(primaryCtrl
);
3447 // Focus and select all (wxTextCtrl, wxComboBox etc)
3448 if ( flags
& wxPG_SEL_FOCUS
)
3450 primaryCtrl
->SetFocus();
3452 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3458 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3459 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3461 // Get proper id for wndSecondary
3462 m_wndSecId
= m_wndEditor2
->GetId();
3463 wxWindowList children
= m_wndEditor2
->GetChildren();
3464 wxWindowList::iterator node
= children
.begin();
3465 if ( node
!= children
.end() )
3466 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3468 m_wndEditor2
->SetSizeHints(3,3);
3470 #if wxPG_CREATE_CONTROLS_HIDDEN
3471 wxRect sec_rect
= m_wndEditor2
->GetRect();
3472 sec_rect
.y
-= coord_adjust
;
3474 // Fine tuning required to fix "oversized"
3475 // button disappearance bug.
3476 if ( sec_rect
.y
< 0 )
3478 sec_rect
.height
+= sec_rect
.y
;
3481 m_wndEditor2
->SetSize( sec_rect
);
3483 m_wndEditor2
->Show();
3485 SetupChildEventHandling(m_wndEditor2
);
3487 // If no primary editor, focus to button to allow
3488 // it to interprete ENTER etc.
3489 // NOTE: Due to problems focusing away from it, this
3490 // has been disabled.
3492 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3493 m_wndEditor2->SetFocus();
3497 if ( flags
& wxPG_SEL_FOCUS
)
3498 m_editorFocused
= 1;
3503 // Make sure focus is in grid canvas (important for wxGTK, at least)
3507 EditorsValueWasNotModified();
3509 // If it's inside collapsed section, expand parent, scroll, etc.
3510 // Also, if it was partially visible, scroll it into view.
3511 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3516 #if wxPG_CREATE_CONTROLS_HIDDEN
3517 m_wndEditor
->Thaw();
3519 m_wndEditor
->Show(true);
3526 // Make sure focus is in grid canvas
3530 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3536 // Show help text in status bar.
3537 // (if found and grid not embedded in manager with help box and
3538 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3541 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3543 wxStatusBar
* statusbar
= NULL
;
3544 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3546 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3548 statusbar
= frame
->GetStatusBar();
3553 const wxString
* pHelpString
= (const wxString
*) NULL
;
3557 pHelpString
= &p
->GetHelpString();
3558 if ( pHelpString
->length() )
3560 // Set help box text.
3561 statusbar
->SetStatusText( *pHelpString
);
3562 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3566 if ( (!pHelpString
|| !pHelpString
->length()) &&
3567 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3569 // Clear help box - but only if it was written
3570 // by us at previous time.
3571 statusbar
->SetStatusText( m_emptyString
);
3572 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3578 m_inDoSelectProperty
= 0;
3580 // call wx event handler (here so that it also occurs on deselection)
3581 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3586 // -----------------------------------------------------------------------
3588 bool wxPropertyGrid::UnfocusEditor()
3590 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3593 if ( !CommitChangesFromEditor(0) )
3597 DrawItem(m_selected
);
3602 // -----------------------------------------------------------------------
3604 void wxPropertyGrid::RefreshEditor()
3606 wxPGProperty
* p
= m_selected
;
3610 wxWindow
* wnd
= GetEditorControl();
3614 // Set editor font boldness - must do this before
3615 // calling UpdateControl().
3616 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3618 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3619 wnd
->SetFont(GetCaptionFont());
3621 wnd
->SetFont(GetFont());
3624 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3626 editorClass
->UpdateControl(p
, wnd
);
3628 if ( p
->IsValueUnspecified() )
3629 editorClass
->SetValueToUnspecified(p
, wnd
);
3632 // -----------------------------------------------------------------------
3634 // This method is not inline because it called dozens of times
3635 // (i.e. two-arg function calls create smaller code size).
3636 bool wxPropertyGrid::DoClearSelection()
3638 return DoSelectProperty(NULL
);
3641 // -----------------------------------------------------------------------
3642 // wxPropertyGrid expand/collapse state
3643 // -----------------------------------------------------------------------
3645 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3647 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3649 // If active editor was inside collapsed section, then disable it
3650 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3652 ClearSelection(false);
3655 // Store dont-center-splitter flag 'cause we need to temporarily set it
3656 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3657 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3659 bool res
= m_pState
->DoCollapse(pwc
);
3664 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3666 RecalculateVirtualSize();
3668 // Redraw etc. only if collapsed was visible.
3669 if (pwc
->IsVisible() &&
3671 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3673 // When item is collapsed so that scrollbar would move,
3674 // graphics mess is about (unless we redraw everything).
3679 // Clear dont-center-splitter flag if it wasn't set
3680 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3685 // -----------------------------------------------------------------------
3687 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3689 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3691 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3693 // Store dont-center-splitter flag 'cause we need to temporarily set it
3694 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3695 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3697 bool res
= m_pState
->DoExpand(pwc
);
3702 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3704 RecalculateVirtualSize();
3706 // Redraw etc. only if expanded was visible.
3707 if ( pwc
->IsVisible() && !m_frozen
&&
3708 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3712 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3715 DrawItems(pwc
, NULL
);
3720 // Clear dont-center-splitter flag if it wasn't set
3721 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3726 // -----------------------------------------------------------------------
3728 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3731 return m_pState
->DoHideProperty(p
, hide
, flags
);
3734 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3737 ClearSelection(false);
3740 m_pState
->DoHideProperty(p
, hide
, flags
);
3742 RecalculateVirtualSize();
3749 // -----------------------------------------------------------------------
3750 // wxPropertyGrid size related methods
3751 // -----------------------------------------------------------------------
3753 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3755 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3759 // If virtual height was changed, then recalculate editor control position(s)
3760 if ( m_pState
->m_vhCalcPending
)
3761 CorrectEditorWidgetPosY();
3763 m_pState
->EnsureVirtualHeight();
3765 wxASSERT_LEVEL_2_MSG(
3766 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3767 "VirtualHeight and ActualVirtualHeight should match"
3770 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3772 int x
= m_pState
->m_width
;
3773 int y
= m_pState
->m_virtualHeight
;
3776 GetClientSize(&width
,&height
);
3778 // Now adjust virtual size.
3779 SetVirtualSize(x
, y
);
3785 // Adjust scrollbars
3786 if ( HasVirtualWidth() )
3788 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3789 xPos
= GetScrollPos( wxHORIZONTAL
);
3792 if ( forceXPos
!= -1 )
3795 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3798 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3799 int yPos
= GetScrollPos( wxVERTICAL
);
3801 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3802 xAmount
, yAmount
, xPos
, yPos
, true );
3804 // Must re-get size now
3805 GetClientSize(&width
,&height
);
3807 if ( !HasVirtualWidth() )
3809 m_pState
->SetVirtualWidth(width
);
3816 m_canvas
->SetSize( x
, y
);
3818 m_pState
->CheckColumnWidths();
3821 CorrectEditorWidgetSizeX();
3823 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3826 // -----------------------------------------------------------------------
3828 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3830 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3834 GetClientSize(&width
,&height
);
3839 #if wxPG_DOUBLE_BUFFER
3840 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3842 int dblh
= (m_lineHeight
*2);
3843 if ( !m_doubleBuffer
)
3845 // Create double buffer bitmap to draw on, if none
3846 int w
= (width
>250)?width
:250;
3847 int h
= height
+ dblh
;
3849 m_doubleBuffer
= new wxBitmap( w
, h
);
3853 int w
= m_doubleBuffer
->GetWidth();
3854 int h
= m_doubleBuffer
->GetHeight();
3856 // Double buffer must be large enough
3857 if ( w
< width
|| h
< (height
+dblh
) )
3859 if ( w
< width
) w
= width
;
3860 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3861 delete m_doubleBuffer
;
3862 m_doubleBuffer
= new wxBitmap( w
, h
);
3869 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3870 m_ncWidth
= event
.GetSize().x
;
3874 if ( m_pState
->m_itemsAdded
)
3875 PrepareAfterItemsAdded();
3877 // Without this, virtual size (atleast under wxGTK) will be skewed
3878 RecalculateVirtualSize();
3884 // -----------------------------------------------------------------------
3886 void wxPropertyGrid::SetVirtualWidth( int width
)
3890 // Disable virtual width
3891 width
= GetClientSize().x
;
3892 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3896 // Enable virtual width
3897 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3899 m_pState
->SetVirtualWidth( width
);
3902 void wxPropertyGrid::SetFocusOnCanvas()
3904 m_canvas
->SetFocusIgnoringChildren();
3905 m_editorFocused
= 0;
3908 // -----------------------------------------------------------------------
3909 // wxPropertyGrid mouse event handling
3910 // -----------------------------------------------------------------------
3912 // selFlags uses same values DoSelectProperty's flags
3913 // Returns true if event was vetoed.
3914 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3916 // Send property grid event of specific type and with specific property
3917 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3918 evt
.SetPropertyGrid(this);
3919 evt
.SetEventObject(m_eventObject
);
3923 evt
.SetCanVeto(true);
3924 evt
.SetupValidationInfo();
3925 m_validationInfo
.m_pValue
= pValue
;
3927 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3929 evtHandler
->ProcessEvent(evt
);
3931 return evt
.WasVetoed();
3934 // -----------------------------------------------------------------------
3936 // Return false if should be skipped
3937 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3941 // Need to set focus?
3942 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3947 wxPropertyGridPageState
* state
= m_pState
;
3949 int splitterHitOffset
;
3950 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3952 wxPGProperty
* p
= DoGetItemAtY(y
);
3956 int depth
= (int)p
->GetDepth() - 1;
3958 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3960 if ( x
>= marginEnds
)
3964 if ( p
->IsCategory() )
3966 // This is category.
3967 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3969 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3971 // Expand, collapse, activate etc. if click on text or left of splitter.
3974 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3979 if ( !DoSelectProperty( p
) )
3982 // On double-click, expand/collapse.
3983 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3985 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3986 else DoExpand( p
, true );
3990 else if ( splitterHit
== -1 )
3993 unsigned int selFlag
= 0;
3994 if ( columnHit
== 1 )
3996 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3997 selFlag
= wxPG_SEL_FOCUS
;
3999 if ( !DoSelectProperty( p
, selFlag
) )
4002 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4004 if ( p
->GetChildCount() && !p
->IsCategory() )
4005 // On double-click, expand/collapse.
4006 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4008 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4009 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4010 else DoExpand( p
, true );
4017 // click on splitter
4018 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4020 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4022 // Double-clicking the splitter causes auto-centering
4023 CenterSplitter( true );
4025 else if ( m_dragStatus
== 0 )
4028 // Begin draggin the splitter
4032 // Changes must be committed here or the
4033 // value won't be drawn correctly
4034 if ( !CommitChangesFromEditor() )
4037 m_wndEditor
->Show ( false );
4040 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4042 m_canvas
->CaptureMouse();
4043 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4047 m_draggedSplitter
= splitterHit
;
4048 m_dragOffset
= splitterHitOffset
;
4050 wxClientDC
dc(m_canvas
);
4052 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4053 // Fixes button disappearance bug
4055 m_wndEditor2
->Show ( false );
4058 m_startingSplitterX
= x
- splitterHitOffset
;
4066 if ( p
->GetChildCount() )
4068 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4070 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4072 int y2
= y
% m_lineHeight
;
4073 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4075 // On click on expander button, expand/collapse
4076 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4077 DoCollapse( p
, true );
4079 DoExpand( p
, true );
4088 // -----------------------------------------------------------------------
4090 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4091 wxMouseEvent
& WXUNUSED(event
) )
4095 // Select property here as well
4096 wxPGProperty
* p
= m_propHover
;
4097 if ( p
!= m_selected
)
4098 DoSelectProperty( p
);
4100 // Send right click event.
4101 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4108 // -----------------------------------------------------------------------
4110 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4111 wxMouseEvent
& WXUNUSED(event
) )
4115 // Select property here as well
4116 wxPGProperty
* p
= m_propHover
;
4118 if ( p
!= m_selected
)
4119 DoSelectProperty( p
);
4121 // Send double-click event.
4122 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4129 // -----------------------------------------------------------------------
4131 #if wxPG_SUPPORT_TOOLTIPS
4133 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4135 if ( tipString
.length() )
4137 m_canvas
->SetToolTip(tipString
);
4141 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4142 m_canvas
->SetToolTip( m_emptyString
);
4144 m_canvas
->SetToolTip( NULL
);
4149 #endif // #if wxPG_SUPPORT_TOOLTIPS
4151 // -----------------------------------------------------------------------
4153 // Return false if should be skipped
4154 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4156 // Safety check (needed because mouse capturing may
4157 // otherwise freeze the control)
4158 if ( m_dragStatus
> 0 && !event
.Dragging() )
4160 HandleMouseUp(x
,y
,event
);
4163 wxPropertyGridPageState
* state
= m_pState
;
4165 int splitterHitOffset
;
4166 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4167 int splitterX
= x
- splitterHitOffset
;
4169 if ( m_dragStatus
> 0 )
4171 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4172 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4175 int newSplitterX
= x
- m_dragOffset
;
4176 int splitterX
= x
- splitterHitOffset
;
4178 // Splitter redraw required?
4179 if ( newSplitterX
!= splitterX
)
4182 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4183 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4184 state
->m_fSplitterX
= (float) newSplitterX
;
4187 CorrectEditorWidgetSizeX();
4201 int ih
= m_lineHeight
;
4204 #if wxPG_SUPPORT_TOOLTIPS
4205 wxPGProperty
* prevHover
= m_propHover
;
4206 unsigned char prevSide
= m_mouseSide
;
4208 int curPropHoverY
= y
- (y
% ih
);
4210 // On which item it hovers
4213 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4216 // Mouse moves on another property
4218 m_propHover
= DoGetItemAtY(y
);
4219 m_propHoverY
= curPropHoverY
;
4222 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4225 #if wxPG_SUPPORT_TOOLTIPS
4226 // Store which side we are on
4228 if ( columnHit
== 1 )
4230 else if ( columnHit
== 0 )
4234 // If tooltips are enabled, show label or value as a tip
4235 // in case it doesn't otherwise show in full length.
4237 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4239 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4241 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4243 if ( m_propHover
&& !m_propHover
->IsCategory() )
4246 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4248 // Show help string as a tooltip
4249 wxString tipString
= m_propHover
->GetHelpString();
4251 SetToolTip(tipString
);
4255 // Show cropped value string as a tooltip
4259 if ( m_mouseSide
== 1 )
4261 tipString
= m_propHover
->m_label
;
4262 space
= splitterX
-m_marginWidth
-3;
4264 else if ( m_mouseSide
== 2 )
4266 tipString
= m_propHover
->GetDisplayedString();
4268 space
= m_width
- splitterX
;
4269 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4270 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4276 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4279 SetToolTip( tipString
);
4286 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4287 m_canvas
->SetToolTip( m_emptyString
);
4289 m_canvas
->SetToolTip( NULL
);
4300 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4301 m_canvas
->SetToolTip( m_emptyString
);
4303 m_canvas
->SetToolTip( NULL
);
4311 if ( splitterHit
== -1 ||
4313 HasFlag(wxPG_STATIC_SPLITTER
) )
4315 // hovering on something else
4316 if ( m_curcursor
!= wxCURSOR_ARROW
)
4317 CustomSetCursor( wxCURSOR_ARROW
);
4321 // Do not allow splitter cursor on caption items.
4322 // (also not if we were dragging and its started
4323 // outside the splitter region)
4325 if ( !m_propHover
->IsCategory() &&
4329 // hovering on splitter
4331 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4332 // reliably detected.
4333 //if ( m_curcursor != wxCURSOR_SIZEWE )
4334 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4340 // hovering on something else
4341 if ( m_curcursor
!= wxCURSOR_ARROW
)
4342 CustomSetCursor( wxCURSOR_ARROW
);
4349 // -----------------------------------------------------------------------
4351 // Also handles Leaving event
4352 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4353 wxMouseEvent
&WXUNUSED(event
) )
4355 wxPropertyGridPageState
* state
= m_pState
;
4359 int splitterHitOffset
;
4360 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4362 // No event type check - basicly calling this method should
4363 // just stop dragging.
4364 // Left up after dragged?
4365 if ( m_dragStatus
>= 1 )
4368 // End Splitter Dragging
4370 // DO NOT ENABLE FOLLOWING LINE!
4371 // (it is only here as a reminder to not to do it)
4374 // Disable splitter auto-centering
4375 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4377 // This is necessary to return cursor
4378 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4380 m_canvas
->ReleaseMouse();
4381 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4384 // Set back the default cursor, if necessary
4385 if ( splitterHit
== -1 ||
4388 CustomSetCursor( wxCURSOR_ARROW
);
4393 // Control background needs to be cleared
4394 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4395 DrawItem( m_selected
);
4399 m_wndEditor
->Show ( true );
4402 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4403 // Fixes button disappearance bug
4405 m_wndEditor2
->Show ( true );
4408 // This clears the focus.
4409 m_editorFocused
= 0;
4415 // -----------------------------------------------------------------------
4417 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4419 int splitterX
= GetSplitterPosition();
4422 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4426 wxWindow
* wnd
= GetEditorControl();
4428 // Hide popup on clicks
4429 if ( event
.GetEventType() != wxEVT_MOTION
)
4430 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4432 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4438 if ( wnd
== NULL
|| m_dragStatus
||
4440 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4441 ux
>= (r
.x
+r
.width
) ||
4443 event
.m_y
>= (r
.y
+r
.height
)
4453 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4458 // -----------------------------------------------------------------------
4460 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4463 if ( OnMouseCommon( event
, &x
, &y
) )
4465 HandleMouseClick(x
,y
,event
);
4470 // -----------------------------------------------------------------------
4472 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4475 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4476 HandleMouseRightClick(x
,y
,event
);
4480 // -----------------------------------------------------------------------
4482 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4484 // Always run standard mouse-down handler as well
4485 OnMouseClick(event
);
4488 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4489 HandleMouseDoubleClick(x
,y
,event
);
4493 // -----------------------------------------------------------------------
4495 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4498 if ( OnMouseCommon( event
, &x
, &y
) )
4500 HandleMouseMove(x
,y
,event
);
4505 // -----------------------------------------------------------------------
4507 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4509 // Called when mouse moves in the empty space below the properties.
4510 CustomSetCursor( wxCURSOR_ARROW
);
4513 // -----------------------------------------------------------------------
4515 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4518 if ( OnMouseCommon( event
, &x
, &y
) )
4520 HandleMouseUp(x
,y
,event
);
4525 // -----------------------------------------------------------------------
4527 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4529 // This may get called from child control as well, so event's
4530 // mouse position cannot be relied on.
4532 if ( event
.Entering() )
4534 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4536 // TODO: Fix this (detect parent and only do
4537 // cursor trick if it is a manager).
4538 wxASSERT( GetParent() );
4539 GetParent()->SetCursor(wxNullCursor
);
4541 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4544 GetParent()->SetCursor(wxNullCursor
);
4546 else if ( event
.Leaving() )
4548 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4549 m_canvas
->SetCursor( wxNullCursor
);
4551 // Get real cursor position
4552 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4554 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4557 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4559 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4563 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4571 // -----------------------------------------------------------------------
4573 // Common code used by various OnMouseXXXChild methods.
4574 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4576 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4577 wxASSERT( topCtrlWnd
);
4579 event
.GetPosition(&x
,&y
);
4581 int splitterX
= GetSplitterPosition();
4583 wxRect r
= topCtrlWnd
->GetRect();
4584 if ( !m_dragStatus
&&
4585 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4586 y
>= 0 && y
< r
.height \
4589 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4594 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4601 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4604 if ( OnMouseChildCommon(event
,&x
,&y
) )
4606 bool res
= HandleMouseClick(x
,y
,event
);
4607 if ( !res
) event
.Skip();
4611 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4614 wxASSERT( m_wndEditor
);
4615 // These coords may not be exact (about +-2),
4616 // but that should not matter (right click is about item, not position).
4617 wxPoint pt
= m_wndEditor
->GetPosition();
4618 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4619 wxASSERT( m_selected
);
4620 m_propHover
= m_selected
;
4621 bool res
= HandleMouseRightClick(x
,y
,event
);
4622 if ( !res
) event
.Skip();
4625 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4628 if ( OnMouseChildCommon(event
,&x
,&y
) )
4630 bool res
= HandleMouseMove(x
,y
,event
);
4631 if ( !res
) event
.Skip();
4635 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4638 if ( OnMouseChildCommon(event
,&x
,&y
) )
4640 bool res
= HandleMouseUp(x
,y
,event
);
4641 if ( !res
) event
.Skip();
4645 // -----------------------------------------------------------------------
4646 // wxPropertyGrid keyboard event handling
4647 // -----------------------------------------------------------------------
4649 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4651 // Translates wxKeyEvent to wxPG_ACTION_XXX
4653 int keycode
= event
.GetKeyCode();
4654 int modifiers
= event
.GetModifiers();
4656 wxASSERT( !(modifiers
&~(0xFFFF)) );
4658 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4660 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4662 if ( it
== m_actionTriggers
.end() )
4667 int second
= (it
->second
>>16) & 0xFFFF;
4671 return (it
->second
& 0xFFFF);
4674 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4676 wxASSERT( !(modifiers
&~(0xFFFF)) );
4678 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4680 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4682 if ( it
!= m_actionTriggers
.end() )
4684 // This key combination is already used
4686 // Can add secondary?
4687 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4688 wxT("You can only add up to two separate actions per key combination.") );
4690 action
= it
->second
| (action
<<16);
4693 m_actionTriggers
[hashMapKey
] = action
;
4696 void wxPropertyGrid::ClearActionTriggers( int action
)
4698 wxPGHashMapI2I::iterator it
;
4700 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4702 if ( it
->second
== action
)
4704 m_actionTriggers
.erase(it
);
4709 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4712 // Handles key event when editor control is not focused.
4715 wxCHECK2(!m_frozen
, return);
4717 // Travelsal between items, collapsing/expanding, etc.
4718 int keycode
= event
.GetKeyCode();
4719 bool editorFocused
= IsEditorFocused();
4721 if ( keycode
== WXK_TAB
)
4723 wxWindow
* mainControl
;
4725 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4726 mainControl
= GetParent();
4730 if ( !event
.ShiftDown() )
4732 if ( !editorFocused
&& m_wndEditor
)
4734 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4738 // Tab traversal workaround for platforms on which
4739 // wxWindow::Navigate() may navigate into first child
4740 // instead of next sibling. Does not work perfectly
4741 // in every scenario (for instance, when property grid
4742 // is either first or last control).
4743 #if defined(__WXGTK__)
4744 wxWindow
* sibling
= mainControl
->GetNextSibling();
4746 sibling
->SetFocusFromKbd();
4748 Navigate(wxNavigationKeyEvent::IsForward
);
4754 if ( editorFocused
)
4760 #if defined(__WXGTK__)
4761 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4763 sibling
->SetFocusFromKbd();
4765 Navigate(wxNavigationKeyEvent::IsBackward
);
4773 // Ignore Alt and Control when they are down alone
4774 if ( keycode
== WXK_ALT
||
4775 keycode
== WXK_CONTROL
)
4782 int action
= KeyEventToActions(event
, &secondAction
);
4784 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4787 // Esc cancels any changes
4788 if ( IsEditorsValueModified() )
4790 EditorsValueWasNotModified();
4792 // Update the control as well
4793 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4795 m_selected
->GetDisplayedString() );
4798 OnValidationFailureReset(m_selected
);
4804 // Except for TAB and ESC, handle child control events in child control
4807 // Only propagate event if it had modifiers
4808 if ( !event
.HasModifiers() )
4810 event
.StopPropagation();
4816 bool wasHandled
= false;
4821 if ( ButtonTriggerKeyTest(action
, event
) )
4824 wxPGProperty
* p
= m_selected
;
4826 // Travel and expand/collapse
4829 if ( p
->GetChildCount() )
4831 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4833 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4836 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4838 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4845 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4849 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4855 if ( selectDir
>= -1 )
4857 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4859 DoSelectProperty(p
);
4865 // If nothing was selected, select the first item now
4866 // (or navigate out of tab).
4867 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4869 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4870 if ( p
) DoSelectProperty(p
);
4879 // -----------------------------------------------------------------------
4881 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4883 // If there was editor open and focused, then this event should not
4884 // really be processed here.
4885 if ( IsEditorFocused() )
4887 // However, if event had modifiers, it is probably still best
4889 if ( event
.HasModifiers() )
4892 event
.StopPropagation();
4896 HandleKeyEvent(event
, false);
4899 // -----------------------------------------------------------------------
4901 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4906 action
= KeyEventToActions(event
, &secondAction
);
4909 // Does the keycode trigger button?
4910 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4913 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4914 GetEventHandler()->AddPendingEvent(evt
);
4921 // -----------------------------------------------------------------------
4923 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4925 HandleKeyEvent(event
, true);
4928 // -----------------------------------------------------------------------
4929 // wxPropertyGrid miscellaneous event handling
4930 // -----------------------------------------------------------------------
4932 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4935 // Check if the focus is in this control or one of its children
4936 wxWindow
* newFocused
= wxWindow::FindFocus();
4938 if ( newFocused
!= m_curFocused
)
4939 HandleFocusChange( newFocused
);
4942 bool wxPropertyGrid::IsEditorFocused() const
4944 wxWindow
* focus
= wxWindow::FindFocus();
4946 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4947 focus
== GetEditorControl() )
4953 // Called by focus event handlers. newFocused is the window that becomes focused.
4954 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4956 unsigned int oldFlags
= m_iFlags
;
4958 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4960 wxWindow
* parent
= newFocused
;
4962 // This must be one of nextFocus' parents.
4965 // Use m_eventObject, which is either wxPropertyGrid or
4966 // wxPropertyGridManager, as appropriate.
4967 if ( parent
== m_eventObject
)
4969 m_iFlags
|= wxPG_FL_FOCUSED
;
4972 parent
= parent
->GetParent();
4975 m_curFocused
= newFocused
;
4977 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4978 (oldFlags
& wxPG_FL_FOCUSED
) )
4980 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4982 // Need to store changed value
4983 CommitChangesFromEditor();
4989 // Preliminary code for tab-order respecting
4990 // tab-traversal (but should be moved to
4993 wxWindow* prevFocus = event.GetWindow();
4994 wxWindow* useThis = this;
4995 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4996 useThis = GetParent();
4999 prevFocus->GetParent() == useThis->GetParent() )
5001 wxList& children = useThis->GetParent()->GetChildren();
5003 wxNode* node = children.Find(prevFocus);
5005 if ( node->GetNext() &&
5006 useThis == node->GetNext()->GetData() )
5007 DoSelectProperty(GetFirst());
5008 else if ( node->GetPrevious () &&
5009 useThis == node->GetPrevious()->GetData() )
5010 DoSelectProperty(GetLastProperty());
5017 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5018 DrawItem( m_selected
);
5022 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5024 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5025 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5026 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5027 //else if ( event.GetWindow() )
5029 HandleFocusChange(event
.GetWindow());
5034 // -----------------------------------------------------------------------
5036 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5038 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5042 // -----------------------------------------------------------------------
5044 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5046 m_iFlags
|= wxPG_FL_SCROLLED
;
5051 // -----------------------------------------------------------------------
5053 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5055 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5057 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5061 // -----------------------------------------------------------------------
5062 // Property editor related functions
5063 // -----------------------------------------------------------------------
5065 // noDefCheck = true prevents infinite recursion.
5066 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5069 wxASSERT( editorClass
);
5071 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5072 RegisterDefaultEditors();
5074 wxString name
= editorClass
->GetName();
5076 // Existing editor under this name?
5077 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5079 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5081 // If this name was already used, try class name.
5082 name
= editorClass
->GetClassInfo()->GetClassName();
5083 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5086 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5087 (wxPGEditor
*) vt_it
->second
,
5088 "Editor with given name was already registered" );
5090 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5095 // Use this in RegisterDefaultEditors.
5096 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5097 if ( wxPGEditor_##EDITOR == NULL ) \
5099 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5100 new wxPG##EDITOR##Editor, true ); \
5103 // Registers all default editor classes
5104 void wxPropertyGrid::RegisterDefaultEditors()
5106 wxPGRegisterDefaultEditorClass( TextCtrl
);
5107 wxPGRegisterDefaultEditorClass( Choice
);
5108 wxPGRegisterDefaultEditorClass( ComboBox
);
5109 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5110 #if wxPG_INCLUDE_CHECKBOX
5111 wxPGRegisterDefaultEditorClass( CheckBox
);
5113 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5115 // Register SpinCtrl etc. editors before use
5116 RegisterAdditionalEditors();
5119 // -----------------------------------------------------------------------
5120 // wxPGStringTokenizer
5121 // Needed to handle C-style string lists (e.g. "str1" "str2")
5122 // -----------------------------------------------------------------------
5124 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5125 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5129 wxPGStringTokenizer::~wxPGStringTokenizer()
5133 bool wxPGStringTokenizer::HasMoreTokens()
5135 const wxString
& str
= *m_str
;
5137 wxString::const_iterator i
= m_curPos
;
5139 wxUniChar delim
= m_delimeter
;
5141 wxUniChar prev_a
= wxT('\0');
5143 bool inToken
= false;
5145 while ( i
!= str
.end() )
5154 m_readyToken
.clear();
5159 if ( prev_a
!= wxT('\\') )
5163 if ( a
!= wxT('\\') )
5183 m_curPos
= str
.end();
5191 wxString
wxPGStringTokenizer::GetNextToken()
5193 return m_readyToken
;
5196 // -----------------------------------------------------------------------
5198 // -----------------------------------------------------------------------
5200 wxPGChoiceEntry::wxPGChoiceEntry()
5201 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5205 // -----------------------------------------------------------------------
5207 // -----------------------------------------------------------------------
5209 wxPGChoicesData::wxPGChoicesData()
5214 wxPGChoicesData::~wxPGChoicesData()
5219 void wxPGChoicesData::Clear()
5224 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5226 wxASSERT( m_items
.size() == 0 );
5228 m_items
= data
->m_items
;
5231 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5232 const wxPGChoiceEntry
& item
)
5234 wxVector
<wxPGChoiceEntry
>::iterator it
;
5238 index
= (int) m_items
.size();
5242 it
= m_items
.begin() + index
;
5245 m_items
.insert(it
, item
);
5247 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5249 // Need to fix value?
5250 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5251 ownEntry
.SetValue(index
);
5256 // -----------------------------------------------------------------------
5257 // wxPropertyGridEvent
5258 // -----------------------------------------------------------------------
5260 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5263 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5265 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5266 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5267 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5268 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5269 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5270 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5271 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5274 // -----------------------------------------------------------------------
5276 void wxPropertyGridEvent::Init()
5278 m_validationInfo
= NULL
;
5280 m_wasVetoed
= false;
5283 // -----------------------------------------------------------------------
5285 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5286 : wxCommandEvent(commandType
,id
)
5292 // -----------------------------------------------------------------------
5294 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5295 : wxCommandEvent(event
)
5297 m_eventType
= event
.GetEventType();
5298 m_eventObject
= event
.m_eventObject
;
5300 m_property
= event
.m_property
;
5301 m_validationInfo
= event
.m_validationInfo
;
5302 m_canVeto
= event
.m_canVeto
;
5303 m_wasVetoed
= event
.m_wasVetoed
;
5306 // -----------------------------------------------------------------------
5308 wxPropertyGridEvent::~wxPropertyGridEvent()
5312 // -----------------------------------------------------------------------
5314 wxEvent
* wxPropertyGridEvent::Clone() const
5316 return new wxPropertyGridEvent( *this );
5319 // -----------------------------------------------------------------------
5320 // wxPropertyGridPopulator
5321 // -----------------------------------------------------------------------
5323 wxPropertyGridPopulator::wxPropertyGridPopulator()
5327 wxPGGlobalVars
->m_offline
++;
5330 // -----------------------------------------------------------------------
5332 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5335 m_propHierarchy
.clear();
5338 // -----------------------------------------------------------------------
5340 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5346 // -----------------------------------------------------------------------
5348 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5351 // Free unused sets of choices
5352 wxPGHashMapS2P::iterator it
;
5354 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5356 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5363 m_pg
->GetPanel()->Refresh();
5365 wxPGGlobalVars
->m_offline
--;
5368 // -----------------------------------------------------------------------
5370 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5371 const wxString
& propLabel
,
5372 const wxString
& propName
,
5373 const wxString
* propValue
,
5374 wxPGChoices
* pChoices
)
5376 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5377 wxPGProperty
* parent
= GetCurParent();
5379 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5381 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5385 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5387 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5391 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5393 property
->SetLabel(propLabel
);
5394 property
->DoSetName(propName
);
5396 if ( pChoices
&& pChoices
->IsOk() )
5397 property
->SetChoices(*pChoices
);
5399 m_state
->DoInsert(parent
, -1, property
);
5402 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5403 wxPG_PROGRAMMATIC_VALUE
);
5408 // -----------------------------------------------------------------------
5410 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5412 m_propHierarchy
.push_back(property
);
5413 DoScanForChildren();
5414 m_propHierarchy
.pop_back();
5417 // -----------------------------------------------------------------------
5419 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5420 const wxString
& idString
)
5422 wxPGChoices choices
;
5425 if ( choicesString
[0] == wxT('@') )
5427 wxString ids
= choicesString
.substr(1);
5428 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5429 if ( it
== m_dictIdChoices
.end() )
5430 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5432 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5437 if ( idString
.length() )
5439 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5440 if ( it
!= m_dictIdChoices
.end() )
5442 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5449 // Parse choices string
5450 wxString::const_iterator it
= choicesString
.begin();
5454 bool labelValid
= false;
5456 for ( ; it
!= choicesString
.end(); ++it
)
5462 if ( c
== wxT('"') )
5467 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5468 choices
.Add(label
, l
);
5471 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5476 else if ( c
== wxT('=') )
5483 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5490 if ( c
== wxT('"') )
5503 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5504 choices
.Add(label
, l
);
5507 if ( !choices
.IsOk() )
5509 choices
.EnsureData();
5513 if ( idString
.length() )
5514 m_dictIdChoices
[idString
] = choices
.GetData();
5521 // -----------------------------------------------------------------------
5523 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5525 if ( s
.Last() == wxT('%') )
5527 wxString s2
= s
.substr(0,s
.length()-1);
5529 if ( s2
.ToLong(&val
, 10) )
5531 *pval
= (val
*max
)/100;
5537 return s
.ToLong(pval
, 10);
5540 // -----------------------------------------------------------------------
5542 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5543 const wxString
& type
,
5544 const wxString
& value
)
5546 int l
= m_propHierarchy
.size();
5550 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5551 wxString valuel
= value
.Lower();
5554 if ( type
.length() == 0 )
5559 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5561 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5563 else if ( value
.ToLong(&v
, 0) )
5570 if ( type
== wxT("string") )
5574 else if ( type
== wxT("int") )
5577 value
.ToLong(&v
, 0);
5580 else if ( type
== wxT("bool") )
5582 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5589 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5594 p
->SetAttribute( name
, variant
);
5599 // -----------------------------------------------------------------------
5601 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5603 wxLogError(_("Error in resource: %s"),msg
.c_str());
5606 // -----------------------------------------------------------------------
5608 #endif // wxUSE_PROPGRID