1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 //#define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 //#define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
200 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
204 delete m_defaultRenderer
;
206 // This will always have one ref
207 delete m_fontFamilyChoices
;
210 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
211 delete ((wxValidator
*)m_arrValidators
[i
]);
215 // Destroy value type class instances.
216 wxPGHashMapS2P::iterator vt_it
;
218 // Destroy editor class instances.
219 // iterate over all the elements in the class
220 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
222 delete ((wxPGEditor
*)vt_it
->second
);
225 delete wxPGProperty::sm_wxPG_LABEL
;
228 void wxPropertyGridInitGlobalsIfNeeded()
232 // -----------------------------------------------------------------------
234 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
235 // and tries to commit property value.
236 // -----------------------------------------------------------------------
238 class wxPGTLWHandler
: public wxEvtHandler
242 wxPGTLWHandler( wxPropertyGrid
* pg
)
250 void OnClose( wxCloseEvent
& event
)
252 // ClearSelection forces value validation/commit.
253 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
263 wxPropertyGrid
* m_pg
;
265 DECLARE_EVENT_TABLE()
268 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
269 EVT_CLOSE(wxPGTLWHandler::OnClose
)
272 // -----------------------------------------------------------------------
274 // -----------------------------------------------------------------------
277 // wxPGCanvas acts as a graphics sub-window of the
278 // wxScrolledWindow that wxPropertyGrid is.
280 class wxPGCanvas
: public wxPanel
283 wxPGCanvas() : wxPanel()
286 virtual ~wxPGCanvas() { }
289 void OnMouseMove( wxMouseEvent
&event
)
291 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
292 pg
->OnMouseMove( event
);
295 void OnMouseClick( wxMouseEvent
&event
)
297 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
298 pg
->OnMouseClick( event
);
301 void OnMouseUp( wxMouseEvent
&event
)
303 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
304 pg
->OnMouseUp( event
);
307 void OnMouseRightClick( wxMouseEvent
&event
)
309 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
310 pg
->OnMouseRightClick( event
);
313 void OnMouseDoubleClick( wxMouseEvent
&event
)
315 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
316 pg
->OnMouseDoubleClick( event
);
319 void OnKey( wxKeyEvent
& event
)
321 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
325 void OnPaint( wxPaintEvent
& event
);
327 // Always be focussable, even with child windows
328 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
329 { wxPanel::SetCanFocus(true); }
333 DECLARE_EVENT_TABLE()
334 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
338 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
340 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
341 EVT_MOTION(wxPGCanvas::OnMouseMove
)
342 EVT_PAINT(wxPGCanvas::OnPaint
)
343 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
344 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
345 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
346 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
347 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
351 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
353 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
354 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
358 // Don't paint after destruction has begun
359 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
362 // Update everything inside the box
363 wxRect r
= GetUpdateRegion().GetBox();
365 // FIXME: This is just a workaround for a bug that causes splitters not
366 // to paint when other windows are being dragged over the grid.
367 wxRect fullRect
= GetRect();
369 r
.width
= fullRect
.width
;
371 // Repaint this rectangle
372 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
374 // We assume that the size set when grid is shown
375 // is what is desired.
376 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
379 // -----------------------------------------------------------------------
381 // -----------------------------------------------------------------------
383 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
385 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
386 EVT_IDLE(wxPropertyGrid::OnIdle
)
387 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
388 EVT_PAINT(wxPropertyGrid::OnPaint
)
389 EVT_SIZE(wxPropertyGrid::OnResize
)
390 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
391 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
392 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
393 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
394 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
395 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
396 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
397 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
401 // -----------------------------------------------------------------------
403 wxPropertyGrid::wxPropertyGrid()
409 // -----------------------------------------------------------------------
411 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
416 const wxString
& name
)
420 Create(parent
,id
,pos
,size
,style
,name
);
423 // -----------------------------------------------------------------------
425 bool wxPropertyGrid::Create( wxWindow
*parent
,
430 const wxString
& name
)
433 if ( !(style
&wxBORDER_MASK
) )
434 style
|= wxSIMPLE_BORDER
;
438 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
439 style
&= ~(wxTAB_TRAVERSAL
);
440 style
|= wxWANTS_CHARS
;
442 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
449 // -----------------------------------------------------------------------
452 // Initialize values to defaults
454 void wxPropertyGrid::Init1()
456 // Register editor classes, if necessary.
457 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
458 wxPropertyGrid::RegisterDefaultEditors();
462 m_wndEditor
= m_wndEditor2
= NULL
;
466 m_eventObject
= this;
469 m_sortFunction
= NULL
;
470 m_inDoPropertyChanged
= 0;
471 m_inCommitChangesFromEditor
= 0;
472 m_inDoSelectProperty
= 0;
473 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
479 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
480 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
481 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
482 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
483 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
484 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
485 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
486 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
487 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
489 m_coloursCustomized
= 0;
494 #if wxPG_DOUBLE_BUFFER
495 m_doubleBuffer
= NULL
;
498 #ifndef wxPG_ICON_WIDTH
504 m_iconWidth
= wxPG_ICON_WIDTH
;
509 m_gutterWidth
= wxPG_GUTTER_MIN
;
510 m_subgroup_extramargin
= 10;
514 m_width
= m_height
= 0;
516 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
519 m_chgInfo_changedProperty
= NULL
;
522 // -----------------------------------------------------------------------
525 // Initialize after parent etc. set
527 void wxPropertyGrid::Init2()
529 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
532 // Smaller controls on Mac
533 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
536 // Now create state, if one didn't exist already
537 // (wxPropertyGridManager might have created it for us).
540 m_pState
= CreateState();
541 m_pState
->m_pPropGrid
= this;
542 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
545 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
546 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
548 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
550 m_pState
->InitNonCatMode();
552 m_pState
->m_properties
= m_pState
->m_abcArray
;
555 GetClientSize(&m_width
,&m_height
);
557 #ifndef wxPG_ICON_WIDTH
558 // create two bitmap nodes for drawing
559 m_expandbmp
= new wxBitmap(expand_xpm
);
560 m_collbmp
= new wxBitmap(collapse_xpm
);
562 // calculate average font height for bitmap centering
564 m_iconWidth
= m_expandbmp
->GetWidth();
565 m_iconHeight
= m_expandbmp
->GetHeight();
568 m_curcursor
= wxCURSOR_ARROW
;
569 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
571 // adjust bitmap icon y position so they are centered
572 m_vspacing
= wxPG_DEFAULT_VSPACING
;
574 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
576 // Allocate cell datas indirectly by calling setter
577 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
578 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
582 // This helps with flicker
583 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
586 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
587 m_tlp
= ::wxGetTopLevelParent(this);
588 m_tlwHandler
= handler
;
589 m_tlp
->PushEventHandler(handler
);
591 // set virtual size to this window size
592 wxSize wndsize
= GetSize();
593 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
595 m_timeCreated
= ::wxGetLocalTimeMillis();
597 m_canvas
= new wxPGCanvas();
598 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
599 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
600 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
602 m_iFlags
|= wxPG_FL_INITIALIZED
;
604 m_ncWidth
= wndsize
.GetWidth();
606 // Need to call OnResize handler or size given in constructor/Create
608 wxSizeEvent
sizeEvent(wndsize
,0);
612 // -----------------------------------------------------------------------
614 wxPropertyGrid::~wxPropertyGrid()
618 DoSelectProperty(NULL
);
620 // This should do prevent things from going too badly wrong
621 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
623 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
624 m_canvas
->ReleaseMouse();
626 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
627 m_tlp
->RemoveEventHandler(handler
);
630 wxASSERT_MSG( !IsEditorsValueModified(),
631 wxS("Most recent change in property editor was lost!!! ")
632 wxS("(if you don't want this to happen, close your frames ")
633 wxS("and dialogs using Close(false).)") );
635 #if wxPG_DOUBLE_BUFFER
636 if ( m_doubleBuffer
)
637 delete m_doubleBuffer
;
642 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
645 delete m_cursorSizeWE
;
647 #ifndef wxPG_ICON_WIDTH
652 // Delete common value records
653 for ( i
=0; i
<m_commonValues
.size(); i
++ )
655 delete GetCommonValue(i
);
659 // -----------------------------------------------------------------------
661 bool wxPropertyGrid::Destroy()
663 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
664 m_canvas
->ReleaseMouse();
666 return wxScrolledWindow::Destroy();
669 // -----------------------------------------------------------------------
671 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
673 return new wxPropertyGridPageState();
676 // -----------------------------------------------------------------------
677 // wxPropertyGrid overridden wxWindow methods
678 // -----------------------------------------------------------------------
680 void wxPropertyGrid::SetWindowStyleFlag( long style
)
682 long old_style
= m_windowStyle
;
684 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
686 wxASSERT( m_pState
);
688 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
691 EnableCategories( true );
693 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
695 // Disable categories
696 EnableCategories( false );
698 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
704 PrepareAfterItemsAdded();
706 m_pState
->m_itemsAdded
= 1;
708 #if wxPG_SUPPORT_TOOLTIPS
709 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
715 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
716 SetToolTip ( tooltip );
717 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
720 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
725 m_canvas
->SetToolTip( NULL
);
730 wxScrolledWindow::SetWindowStyleFlag ( style
);
732 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
734 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
736 CalculateFontAndBitmapStuff( m_vspacing
);
742 // -----------------------------------------------------------------------
744 void wxPropertyGrid::Freeze()
748 wxScrolledWindow::Freeze();
753 // -----------------------------------------------------------------------
755 void wxPropertyGrid::Thaw()
761 wxScrolledWindow::Thaw();
762 RecalculateVirtualSize();
763 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
767 // Force property re-selection
769 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
773 // -----------------------------------------------------------------------
775 void wxPropertyGrid::SetExtraStyle( long exStyle
)
777 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
779 #if defined(__WXMSW__)
782 // Don't use WS_EX_COMPOSITED just now.
785 if ( m_iFlags & wxPG_FL_IN_MANAGER )
786 hWnd = (HWND)GetParent()->GetHWND();
788 hWnd = (HWND)GetHWND();
790 ::SetWindowLong( hWnd, GWL_EXSTYLE,
791 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
794 //#elif defined(__WXGTK20__)
796 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
797 // truly was double-buffered.
798 if ( !this->IsDoubleBuffered() )
800 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
804 #if wxPG_DOUBLE_BUFFER
805 delete m_doubleBuffer
;
806 m_doubleBuffer
= NULL
;
811 wxScrolledWindow::SetExtraStyle( exStyle
);
813 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
814 m_pState
->InitNonCatMode();
816 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
817 m_windowStyle
|= wxPG_TOOLTIPS
;
820 wxPGGlobalVars
->m_extraStyle
= exStyle
;
823 // -----------------------------------------------------------------------
825 // returns the best acceptable minimal size
826 wxSize
wxPropertyGrid::DoGetBestSize() const
829 if ( m_lineHeight
> hei
)
831 wxSize sz
= wxSize( 60, hei
+40 );
837 // -----------------------------------------------------------------------
838 // wxPropertyGrid Font and Colour Methods
839 // -----------------------------------------------------------------------
841 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
845 m_captionFont
= wxScrolledWindow::GetFont();
847 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
848 m_subgroup_extramargin
= x
+ (x
/2);
851 #if wxPG_USE_RENDERER_NATIVE
852 m_iconWidth
= wxPG_ICON_WIDTH
;
853 #elif wxPG_ICON_WIDTH
855 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
856 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
857 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
861 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
862 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
863 m_gutterWidth
= wxPG_GUTTER_MIN
;
866 if ( vspacing
<= 1 ) vdiv
= 12;
867 else if ( vspacing
>= 3 ) vdiv
= 3;
869 m_spacingy
= m_fontHeight
/ vdiv
;
870 if ( m_spacingy
< wxPG_YSPACING_MIN
)
871 m_spacingy
= wxPG_YSPACING_MIN
;
874 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
875 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
877 m_captionFont
.SetWeight(wxBOLD
);
878 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
880 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
883 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
884 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
887 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
889 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
890 RecalculateVirtualSize();
892 InvalidateBestSize();
895 // -----------------------------------------------------------------------
897 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
903 // -----------------------------------------------------------------------
905 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
906 int ga
= 1000, int ba
= 1000,
907 bool forceDifferent
= false)
914 // Recursion guard (allow 2 max)
915 static int isinside
= 0;
917 wxCHECK_MSG( isinside
< 3,
919 wxT("wxPGAdjustColour should not be recursively called more than once") );
927 if ( r2
>255 ) r2
= 255;
928 else if ( r2
<0) r2
= 0;
930 if ( g2
>255 ) g2
= 255;
931 else if ( g2
<0) g2
= 0;
933 if ( b2
>255 ) b2
= 255;
934 else if ( b2
<0) b2
= 0;
936 // Make sure they are somewhat different
937 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
938 dst
= wxPGAdjustColour(src
,-(ra
*2));
940 dst
= wxColour(r2
,g2
,b2
);
942 // Recursion guard (allow 2 max)
949 static int wxPGGetColAvg( const wxColour
& col
)
951 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
955 void wxPropertyGrid::RegainColours()
957 if ( !(m_coloursCustomized
& 0x0002) )
959 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
961 // Make sure colour is dark enough
963 int colDec
= wxPGGetColAvg(col
) - 230;
965 int colDec
= wxPGGetColAvg(col
) - 200;
968 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
971 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
974 if ( !(m_coloursCustomized
& 0x0001) )
975 m_colMargin
= m_colCapBack
;
977 if ( !(m_coloursCustomized
& 0x0004) )
984 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
985 m_colCapFore
= capForeCol
;
986 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
989 if ( !(m_coloursCustomized
& 0x0008) )
991 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
992 m_colPropBack
= bgCol
;
993 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
996 if ( !(m_coloursCustomized
& 0x0010) )
998 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
999 m_colPropFore
= fgCol
;
1000 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1003 if ( !(m_coloursCustomized
& 0x0020) )
1004 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1006 if ( !(m_coloursCustomized
& 0x0040) )
1007 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1009 if ( !(m_coloursCustomized
& 0x0080) )
1010 m_colLine
= m_colCapBack
;
1012 if ( !(m_coloursCustomized
& 0x0100) )
1013 m_colDisPropFore
= m_colCapFore
;
1015 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1018 // -----------------------------------------------------------------------
1020 void wxPropertyGrid::ResetColours()
1022 m_coloursCustomized
= 0;
1029 // -----------------------------------------------------------------------
1031 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1033 // Must disable active editor.
1034 ClearSelection(false);
1036 bool res
= wxScrolledWindow::SetFont( font
);
1039 CalculateFontAndBitmapStuff( m_vspacing
);
1046 // -----------------------------------------------------------------------
1048 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1051 m_coloursCustomized
|= 0x80;
1055 // -----------------------------------------------------------------------
1057 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1060 m_coloursCustomized
|= 0x01;
1064 // -----------------------------------------------------------------------
1066 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1068 m_colPropBack
= col
;
1069 m_coloursCustomized
|= 0x08;
1071 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1076 // -----------------------------------------------------------------------
1078 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1080 m_colPropFore
= col
;
1081 m_coloursCustomized
|= 0x10;
1083 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1088 // -----------------------------------------------------------------------
1090 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1092 m_colEmptySpace
= col
;
1097 // -----------------------------------------------------------------------
1099 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1101 m_colDisPropFore
= col
;
1102 m_coloursCustomized
|= 0x100;
1106 // -----------------------------------------------------------------------
1108 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1111 m_coloursCustomized
|= 0x20;
1115 // -----------------------------------------------------------------------
1117 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1120 m_coloursCustomized
|= 0x40;
1124 // -----------------------------------------------------------------------
1126 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1129 m_coloursCustomized
|= 0x02;
1131 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1136 // -----------------------------------------------------------------------
1138 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1141 m_coloursCustomized
|= 0x04;
1143 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1148 // -----------------------------------------------------------------------
1149 // wxPropertyGrid property adding and removal
1150 // -----------------------------------------------------------------------
1152 void wxPropertyGrid::PrepareAfterItemsAdded()
1154 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1156 m_pState
->m_itemsAdded
= 0;
1158 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1159 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1161 RecalculateVirtualSize();
1164 // -----------------------------------------------------------------------
1165 // wxPropertyGrid property operations
1166 // -----------------------------------------------------------------------
1168 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1170 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1174 bool changed
= false;
1176 // Is it inside collapsed section?
1177 if ( !p
->IsVisible() )
1180 wxPGProperty
* parent
= p
->GetParent();
1181 wxPGProperty
* grandparent
= parent
->GetParent();
1183 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1184 Expand( grandparent
);
1192 GetViewStart(&vx
,&vy
);
1193 vy
*=wxPG_PIXELS_PER_UNIT
;
1199 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1200 m_iFlags
|= wxPG_FL_SCROLLED
;
1203 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1205 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1206 m_iFlags
|= wxPG_FL_SCROLLED
;
1216 // -----------------------------------------------------------------------
1217 // wxPropertyGrid helper methods called by properties
1218 // -----------------------------------------------------------------------
1220 // Control font changer helper.
1221 void wxPropertyGrid::SetCurControlBoldFont()
1223 wxASSERT( m_wndEditor
);
1224 m_wndEditor
->SetFont( m_captionFont
);
1227 // -----------------------------------------------------------------------
1229 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1232 #if wxPG_SMALL_SCREEN
1233 // On small-screen devices, always show dialogs with default position and size.
1234 return wxDefaultPosition
;
1236 int splitterX
= GetSplitterPosition();
1240 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1242 ImprovedClientToScreen( &x
, &y
);
1244 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1245 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1252 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1262 new_y
= y
+ m_lineHeight
;
1264 return wxPoint(new_x
,new_y
);
1268 // -----------------------------------------------------------------------
1270 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1272 if ( src_str
.length() == 0 )
1278 bool prev_is_slash
= false;
1280 wxString::const_iterator i
= src_str
.begin();
1284 for ( ; i
!= src_str
.end(); ++i
)
1288 if ( a
!= wxS('\\') )
1290 if ( !prev_is_slash
)
1296 if ( a
== wxS('n') )
1299 dst_str
<< wxS('\n');
1301 dst_str
<< wxS('\n');
1304 else if ( a
== wxS('t') )
1305 dst_str
<< wxS('\t');
1309 prev_is_slash
= false;
1313 if ( prev_is_slash
)
1315 dst_str
<< wxS('\\');
1316 prev_is_slash
= false;
1320 prev_is_slash
= true;
1327 // -----------------------------------------------------------------------
1329 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1331 if ( src_str
.length() == 0 )
1337 wxString::const_iterator i
= src_str
.begin();
1338 wxUniChar prev_a
= wxS('\0');
1342 for ( ; i
!= src_str
.end(); ++i
)
1346 if ( a
>= wxS(' ') )
1348 // This surely is not something that requires an escape sequence.
1353 // This might need...
1354 if ( a
== wxS('\r') )
1356 // DOS style line end.
1357 // Already taken care below
1359 else if ( a
== wxS('\n') )
1360 // UNIX style line end.
1361 dst_str
<< wxS("\\n");
1362 else if ( a
== wxS('\t') )
1364 dst_str
<< wxS('\t');
1367 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1377 // -----------------------------------------------------------------------
1379 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1386 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1389 // -----------------------------------------------------------------------
1390 // wxPropertyGrid graphics related methods
1391 // -----------------------------------------------------------------------
1393 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1397 // Update everything inside the box
1398 wxRect r
= GetUpdateRegion().GetBox();
1400 dc
.SetPen(m_colEmptySpace
);
1401 dc
.SetBrush(m_colEmptySpace
);
1402 dc
.DrawRectangle(r
);
1405 // -----------------------------------------------------------------------
1407 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1408 wxPGProperty
* property
) const
1410 // Prepare rectangle to be used
1412 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1413 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1415 #if (wxPG_USE_RENDERER_NATIVE)
1417 #elif wxPG_ICON_WIDTH
1418 // Drawing expand/collapse button manually
1419 dc
.SetPen(m_colPropFore
);
1420 if ( property
->IsCategory() )
1421 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1423 dc
.SetBrush(m_colPropBack
);
1425 dc
.DrawRectangle( r
);
1426 int _y
= r
.y
+(m_iconWidth
/2);
1427 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1432 if ( property
->IsExpanded() )
1434 // wxRenderer functions are non-mutating in nature, so it
1435 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1436 // Hopefully this does not cause problems.
1437 #if (wxPG_USE_RENDERER_NATIVE)
1438 wxRendererNative::Get().DrawTreeItemButton(
1444 #elif wxPG_ICON_WIDTH
1453 #if (wxPG_USE_RENDERER_NATIVE)
1454 wxRendererNative::Get().DrawTreeItemButton(
1460 #elif wxPG_ICON_WIDTH
1461 int _x
= r
.x
+(m_iconWidth
/2);
1462 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1468 #if (wxPG_USE_RENDERER_NATIVE)
1470 #elif wxPG_ICON_WIDTH
1473 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1477 // -----------------------------------------------------------------------
1480 // This is the one called by OnPaint event handler and others.
1481 // topy and bottomy are already unscrolled (ie. physical)
1483 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1485 unsigned int bottomy
,
1486 const wxRect
* clipRect
)
1488 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1490 m_pState
->EnsureVirtualHeight();
1492 wxRect tempClipRect
;
1495 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1496 clipRect
= &tempClipRect
;
1499 // items added check
1500 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1502 int paintFinishY
= 0;
1504 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1507 bool isBuffered
= false;
1509 #if wxPG_DOUBLE_BUFFER
1510 wxMemoryDC
* bufferDC
= NULL
;
1512 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1514 if ( !m_doubleBuffer
)
1516 paintFinishY
= clipRect
->y
;
1521 bufferDC
= new wxMemoryDC();
1523 // If nothing was changed, then just copy from double-buffer
1524 bufferDC
->SelectObject( *m_doubleBuffer
);
1534 dc
.SetClippingRegion( *clipRect
);
1535 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1538 #if wxPG_DOUBLE_BUFFER
1541 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1542 bufferDC
, 0, 0, wxCOPY
);
1543 dc
.DestroyClippingRegion(); // Is this really necessary?
1549 // Clear area beyond bottomY?
1550 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1552 dc
.SetPen(m_colEmptySpace
);
1553 dc
.SetBrush(m_colEmptySpace
);
1554 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1558 // -----------------------------------------------------------------------
1560 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1561 const wxRect
* clipRect
,
1562 bool isBuffered
) const
1564 const wxPGProperty
* firstItem
;
1565 const wxPGProperty
* lastItem
;
1567 firstItem
= DoGetItemAtY(clipRect
->y
);
1568 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1571 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1573 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1576 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1577 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1579 int lh
= m_lineHeight
;
1582 int lastItemBottomY
;
1584 firstItemTopY
= clipRect
->y
;
1585 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1587 // Align y coordinates to item boundaries
1588 firstItemTopY
-= firstItemTopY
% lh
;
1589 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1590 lastItemBottomY
-= 1;
1592 // Entire range outside scrolled, visible area?
1593 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1596 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1600 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1601 firstItem->GetLabel().c_str(),
1602 lastItem->GetLabel().c_str(),
1603 (int)(lastItemBottomY - firstItemTopY),
1605 (unsigned long)clipRect );
1610 long windowStyle
= m_windowStyle
;
1616 // With wxPG_DOUBLE_BUFFER, do double buffering
1617 // - buffer's y = 0, so align cliprect and coordinates to that
1619 #if wxPG_DOUBLE_BUFFER
1625 xRelMod
= clipRect
->x
;
1626 yRelMod
= clipRect
->y
;
1629 // clipRect conversion
1634 firstItemTopY
-= yRelMod
;
1635 lastItemBottomY
-= yRelMod
;
1638 wxUnusedVar(isBuffered
);
1641 int x
= m_marginWidth
- xRelMod
;
1643 wxFont normalFont
= GetFont();
1645 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1647 bool isEnabled
= IsEnabled();
1650 // Prepare some pens and brushes that are often changed to.
1653 wxBrush
marginBrush(m_colMargin
);
1654 wxPen
marginPen(m_colMargin
);
1655 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1656 wxPen
linepen(m_colLine
,1,wxSOLID
);
1658 // pen that has same colour as text
1659 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1662 // Clear margin with background colour
1664 dc
.SetBrush( marginBrush
);
1665 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1667 dc
.SetPen( *wxTRANSPARENT_PEN
);
1668 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1671 const wxPGProperty
* selected
= m_selected
;
1672 const wxPropertyGridPageState
* state
= m_pState
;
1674 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1675 bool wasSelectedPainted
= false;
1678 // TODO: Only render columns that are within clipping region.
1680 dc
.SetFont(normalFont
);
1682 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1683 int endScanBottomY
= lastItemBottomY
+ lh
;
1684 int y
= firstItemTopY
;
1687 // Pregenerate list of visible properties.
1688 wxArrayPGProperty visPropArray
;
1689 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1691 for ( ; !it
.AtEnd(); it
.Next() )
1693 const wxPGProperty
* p
= *it
;
1695 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1697 visPropArray
.push_back((wxPGProperty
*)p
);
1699 if ( y
> endScanBottomY
)
1706 visPropArray
.push_back(NULL
);
1708 wxPGProperty
* nextP
= visPropArray
[0];
1710 int gridWidth
= state
->m_width
;
1713 for ( unsigned int arrInd
=1;
1714 nextP
&& y
<= lastItemBottomY
;
1717 wxPGProperty
* p
= nextP
;
1718 nextP
= visPropArray
[arrInd
];
1720 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1721 int textMarginHere
= x
;
1722 int renderFlags
= 0;
1724 int greyDepth
= m_marginWidth
;
1725 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1726 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1728 int greyDepthX
= greyDepth
- xRelMod
;
1730 // Use basic depth if in non-categoric mode and parent is base array.
1731 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1733 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1736 // Paint margin area
1737 dc
.SetBrush(marginBrush
);
1738 dc
.SetPen(marginPen
);
1739 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1741 dc
.SetPen( linepen
);
1746 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1752 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1754 sx
+= state
->m_colWidths
[si
];
1755 dc
.DrawLine( sx
, y
, sx
, y2
);
1758 // Horizontal Line, below
1759 // (not if both this and next is category caption)
1760 if ( p
->IsCategory() &&
1761 nextP
&& nextP
->IsCategory() )
1762 dc
.SetPen(m_colCapBack
);
1764 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1767 // Need to override row colours?
1771 if ( p
!= selected
)
1773 // Disabled may get different colour.
1774 if ( !p
->IsEnabled() )
1776 renderFlags
|= wxPGCellRenderer::Disabled
|
1777 wxPGCellRenderer::DontUseCellFgCol
;
1778 rowFgCol
= m_colDisPropFore
;
1783 renderFlags
|= wxPGCellRenderer::Selected
;
1785 if ( !p
->IsCategory() )
1787 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1788 wxPGCellRenderer::DontUseCellBgCol
;
1790 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1791 wasSelectedPainted
= true;
1794 // Selected gets different colour.
1795 if ( reallyFocused
)
1797 rowFgCol
= m_colSelFore
;
1798 rowBgCol
= m_colSelBack
;
1800 else if ( isEnabled
)
1802 rowFgCol
= m_colPropFore
;
1803 rowBgCol
= m_colMargin
;
1807 rowFgCol
= m_colDisPropFore
;
1808 rowBgCol
= m_colSelBack
;
1815 if ( rowBgCol
.IsOk() )
1816 rowBgBrush
= wxBrush(rowBgCol
);
1818 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1819 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1822 // Fill additional margin area with background colour of first cell
1823 if ( greyDepthX
< textMarginHere
)
1825 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1827 wxPGCell
& cell
= p
->GetCell(0);
1828 rowBgCol
= cell
.GetBgCol();
1829 rowBgBrush
= wxBrush(rowBgCol
);
1831 dc
.SetBrush(rowBgBrush
);
1832 dc
.SetPen(rowBgCol
);
1833 dc
.DrawRectangle(greyDepthX
+1, y
,
1834 textMarginHere
-greyDepthX
, lh
-1);
1837 bool fontChanged
= false;
1839 // Expander button rectangle
1840 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1845 if ( p
->IsCategory() )
1847 // Captions have their cell areas merged as one
1848 dc
.SetFont(m_captionFont
);
1850 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1852 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1854 dc
.SetBrush(rowBgBrush
);
1855 dc
.SetPen(rowBgCol
);
1858 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1860 dc
.SetTextForeground(rowFgCol
);
1863 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1864 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1867 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1868 DrawExpanderButton( dc
, butRect
, p
);
1872 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1874 dc
.SetFont(m_captionFont
);
1880 int nextCellWidth
= state
->m_colWidths
[0] -
1881 (greyDepthX
- m_marginWidth
);
1882 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1883 int textXAdd
= textMarginHere
- greyDepthX
;
1885 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1887 cellRect
.width
= nextCellWidth
- 1;
1889 bool ctrlCell
= false;
1890 int cellRenderFlags
= renderFlags
;
1893 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1894 DrawExpanderButton( dc
, butRect
, p
);
1897 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1899 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1900 dc
.SetBrush(editorBgCol
);
1901 dc
.SetPen(editorBgCol
);
1902 dc
.SetTextForeground(m_colPropFore
);
1903 dc
.DrawRectangle(cellRect
);
1905 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1910 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1912 dc
.SetBrush(rowBgBrush
);
1913 dc
.SetPen(rowBgCol
);
1916 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1918 dc
.SetTextForeground(rowFgCol
);
1922 dc
.SetClippingRegion(cellRect
);
1924 cellRect
.x
+= textXAdd
;
1925 cellRect
.width
-= textXAdd
;
1930 wxPGCellRenderer
* renderer
;
1931 int cmnVal
= p
->GetCommonValue();
1932 if ( cmnVal
== -1 || ci
!= 1 )
1934 renderer
= p
->GetCellRenderer(ci
);
1935 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1940 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1941 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1946 cellX
+= state
->m_colWidths
[ci
];
1947 if ( ci
< (state
->m_colWidths
.size()-1) )
1948 nextCellWidth
= state
->m_colWidths
[ci
+1];
1950 dc
.DestroyClippingRegion(); // Is this really necessary?
1956 dc
.SetFont(normalFont
);
1961 // Refresh editor controls (seems not needed on msw)
1962 // NOTE: This code is mandatory for GTK!
1963 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1964 if ( wasSelectedPainted
)
1967 m_wndEditor
->Refresh();
1969 m_wndEditor2
->Refresh();
1976 // -----------------------------------------------------------------------
1978 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1982 if ( m_width
< 10 || m_height
< 10 ||
1983 !m_pState
->m_properties
->GetChildCount() ||
1985 return wxRect(0,0,0,0);
1990 // Return rect which encloses the given property range
1992 int visTop
= p1
->GetY();
1995 visBottom
= p2
->GetY() + m_lineHeight
;
1997 visBottom
= m_height
+ visTop
;
1999 // If seleced property is inside the range, we'll extend the range to include
2001 wxPGProperty
* selected
= m_selected
;
2004 int selectedY
= selected
->GetY();
2005 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2007 wxWindow
* editor
= GetEditorControl();
2010 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2011 if ( visBottom2
> visBottom
)
2012 visBottom
= visBottom2
;
2017 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2020 // -----------------------------------------------------------------------
2022 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2027 if ( m_pState
->m_itemsAdded
)
2028 PrepareAfterItemsAdded();
2030 wxRect r
= GetPropertyRect(p1
, p2
);
2033 m_canvas
->RefreshRect(r
);
2037 // -----------------------------------------------------------------------
2039 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2041 if ( p
== m_selected
)
2042 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2044 DrawItemAndChildren(p
);
2047 // -----------------------------------------------------------------------
2049 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2054 // Draw item, children, and parent too, if it is not category
2055 wxPGProperty
* parent
= p
->GetParent();
2058 !parent
->IsCategory() &&
2059 parent
->GetParent() )
2062 parent
= parent
->GetParent();
2065 DrawItemAndChildren(p
);
2068 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2070 wxCHECK_RET( p
, wxT("invalid property id") );
2072 // Do not draw if in non-visible page
2073 if ( p
->GetParentState() != m_pState
)
2076 // do not draw a single item if multiple pending
2077 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2080 // Update child control.
2081 if ( m_selected
&& m_selected
->GetParent() == p
)
2084 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2086 DrawItems(p
, lastDrawn
);
2089 // -----------------------------------------------------------------------
2091 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2092 const wxRect
*rect
)
2094 PrepareAfterItemsAdded();
2096 wxWindow::Refresh(false);
2098 // TODO: Coordinate translation
2099 m_canvas
->Refresh(false, rect
);
2101 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2102 // I think this really helps only GTK+1.2
2103 if ( m_wndEditor
) m_wndEditor
->Refresh();
2104 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2108 // -----------------------------------------------------------------------
2109 // wxPropertyGrid global operations
2110 // -----------------------------------------------------------------------
2112 void wxPropertyGrid::Clear()
2114 m_pState
->DoClear();
2120 RecalculateVirtualSize();
2122 // Need to clear some area at the end
2124 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2127 // -----------------------------------------------------------------------
2129 bool wxPropertyGrid::EnableCategories( bool enable
)
2131 ClearSelection(false);
2136 // Enable categories
2139 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2144 // Disable categories
2146 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2149 if ( !m_pState
->EnableCategories(enable
) )
2154 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2156 m_pState
->m_itemsAdded
= 1; // force
2157 PrepareAfterItemsAdded();
2161 m_pState
->m_itemsAdded
= 1;
2163 // No need for RecalculateVirtualSize() here - it is already called in
2164 // wxPropertyGridPageState method above.
2171 // -----------------------------------------------------------------------
2173 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2175 wxASSERT( pNewState
);
2176 wxASSERT( pNewState
->GetGrid() );
2178 if ( pNewState
== m_pState
)
2181 wxPGProperty
* oldSelection
= m_selected
;
2183 ClearSelection(false);
2185 m_pState
->m_selected
= oldSelection
;
2187 bool orig_mode
= m_pState
->IsInNonCatMode();
2188 bool new_state_mode
= pNewState
->IsInNonCatMode();
2190 m_pState
= pNewState
;
2193 int pgWidth
= GetClientSize().x
;
2194 if ( HasVirtualWidth() )
2196 int minWidth
= pgWidth
;
2197 if ( pNewState
->m_width
< minWidth
)
2199 pNewState
->m_width
= minWidth
;
2200 pNewState
->CheckColumnWidths();
2206 // Just in case, fully re-center splitter
2207 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2208 pNewState
->m_fSplitterX
= -1.0;
2210 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2215 // If necessary, convert state to correct mode.
2216 if ( orig_mode
!= new_state_mode
)
2218 // This should refresh as well.
2219 EnableCategories( orig_mode
?false:true );
2221 else if ( !m_frozen
)
2223 // Refresh, if not frozen.
2224 m_pState
->PrepareAfterItemsAdded();
2227 if ( m_pState
->m_selected
)
2228 DoSelectProperty( m_pState
->m_selected
);
2230 RecalculateVirtualSize(0);
2234 m_pState
->m_itemsAdded
= 1;
2237 // -----------------------------------------------------------------------
2239 // Call to SetSplitterPosition will always disable splitter auto-centering
2240 // if parent window is shown.
2241 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2243 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2246 wxPropertyGridPageState
* state
= m_pState
;
2248 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2253 CorrectEditorWidgetSizeX();
2259 // -----------------------------------------------------------------------
2261 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2263 SetSplitterPosition( m_width
/2, true );
2264 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2265 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2268 // -----------------------------------------------------------------------
2269 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2270 // -----------------------------------------------------------------------
2272 // Returns nearest paint visible property (such that will be painted unless
2273 // window is scrolled or resized). If given property is paint visible, then
2274 // it itself will be returned
2275 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2277 int vx
,vy1
;// Top left corner of client
2278 GetViewStart(&vx
,&vy1
);
2279 vy1
*= wxPG_PIXELS_PER_UNIT
;
2281 int vy2
= vy1
+ m_height
;
2282 int propY
= p
->GetY2(m_lineHeight
);
2284 if ( (propY
+ m_lineHeight
) < vy1
)
2287 return DoGetItemAtY( vy1
);
2289 else if ( propY
> vy2
)
2292 return DoGetItemAtY( vy2
);
2295 // Itself paint visible
2300 // -----------------------------------------------------------------------
2301 // Methods related to change in value, value modification and sending events
2302 // -----------------------------------------------------------------------
2304 // commits any changes in editor of selected property
2305 // return true if validation did not fail
2306 // flags are same as with DoSelectProperty
2307 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2309 // Committing already?
2310 if ( m_inCommitChangesFromEditor
)
2313 // Don't do this if already processing editor event. It might
2314 // induce recursive dialogs and crap like that.
2315 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2317 if ( m_inDoPropertyChanged
)
2324 IsEditorsValueModified() &&
2325 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2328 m_inCommitChangesFromEditor
= 1;
2330 wxVariant
variant(m_selected
->GetValueRef());
2331 bool valueIsPending
= false;
2333 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2334 // due to another window getting focus
2335 wxWindow
* oldFocus
= m_curFocused
;
2337 bool validationFailure
= false;
2338 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2340 m_chgInfo_changedProperty
= NULL
;
2342 // If truly modified, schedule value as pending.
2343 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2345 if ( DoEditorValidate() &&
2346 PerformValidation(m_selected
, variant
) )
2348 valueIsPending
= true;
2352 validationFailure
= true;
2357 EditorsValueWasNotModified();
2362 m_inCommitChangesFromEditor
= 0;
2364 if ( validationFailure
&& !forceSuccess
)
2368 oldFocus
->SetFocus();
2369 m_curFocused
= oldFocus
;
2372 res
= OnValidationFailure(m_selected
, variant
);
2374 // Now prevent further validation failure messages
2377 EditorsValueWasNotModified();
2378 OnValidationFailureReset(m_selected
);
2381 else if ( valueIsPending
)
2383 DoPropertyChanged( m_selected
, flags
);
2384 EditorsValueWasNotModified();
2393 // -----------------------------------------------------------------------
2395 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2399 // Runs all validation functionality.
2400 // Returns true if value passes all tests.
2403 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2405 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2407 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2412 // Adapt list to child values, if necessary
2413 wxVariant listValue
= pendingValue
;
2414 wxVariant
* pPendingValue
= &pendingValue
;
2415 wxVariant
* pList
= NULL
;
2417 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2418 // string value, then we need treat as it was changed instead
2419 // (or, in addition, as is the case with composite string parent).
2420 // This includes creating list variant for child values.
2422 wxPGProperty
* pwc
= p
->GetParent();
2423 wxPGProperty
* changedProperty
= p
;
2424 wxPGProperty
* baseChangedProperty
= changedProperty
;
2425 wxVariant bcpPendingList
;
2427 listValue
= pendingValue
;
2428 listValue
.SetName(p
->GetBaseName());
2431 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2433 wxVariantList tempList
;
2434 wxVariant
lv(tempList
, pwc
->GetBaseName());
2435 lv
.Append(listValue
);
2437 pPendingValue
= &listValue
;
2439 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2441 baseChangedProperty
= pwc
;
2442 bcpPendingList
= lv
;
2445 changedProperty
= pwc
;
2446 pwc
= pwc
->GetParent();
2450 wxPGProperty
* evtChangingProperty
= changedProperty
;
2452 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2454 value
= *pPendingValue
;
2458 // Convert list to child values
2459 pList
= pPendingValue
;
2460 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2463 wxVariant evtChangingValue
= value
;
2465 if ( flags
& SendEvtChanging
)
2467 // FIXME: After proper ValueToString()s added, remove
2468 // this. It is just a temporary fix, as evt_changing
2469 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2470 // (unless it is selected, and textctrl editor is open).
2471 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2473 evtChangingProperty
= baseChangedProperty
;
2474 if ( evtChangingProperty
!= p
)
2476 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2480 evtChangingValue
= pendingValue
;
2484 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2486 if ( changedProperty
== m_selected
)
2488 wxWindow
* editor
= GetEditorControl();
2489 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2490 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2494 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2499 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2500 m_chgInfo_changedProperty
= changedProperty
;
2501 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2502 m_chgInfo_pendingValue
= value
;
2505 m_chgInfo_valueList
= *pList
;
2507 m_chgInfo_valueList
.MakeNull();
2509 // If changedProperty is not property which value was edited,
2510 // then call wxPGProperty::ValidateValue() for that as well.
2511 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2513 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2517 if ( flags
& SendEvtChanging
)
2519 // SendEvent returns true if event was vetoed
2520 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2524 if ( flags
& IsStandaloneValidation
)
2526 // If called in 'generic' context, we need to reset
2527 // m_chgInfo_changedProperty and write back translated value.
2528 m_chgInfo_changedProperty
= NULL
;
2529 pendingValue
= value
;
2535 // -----------------------------------------------------------------------
2537 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2539 if ( !msg
.length() )
2543 if ( !wxPGGlobalVars
->m_offline
)
2545 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2548 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2551 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2554 pStatusBar
->SetStatusText(msg
);
2562 ::wxMessageBox(msg
, _T("Property Error"));
2565 // -----------------------------------------------------------------------
2567 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2568 wxVariant
& invalidValue
)
2570 wxWindow
* editor
= GetEditorControl();
2572 // First call property's handler
2573 property
->OnValidationFailure(invalidValue
);
2575 bool res
= DoOnValidationFailure(property
, invalidValue
);
2578 // For non-wxTextCtrl editors, we do need to revert the value
2579 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2580 property
== m_selected
)
2582 property
->GetEditorClass()->UpdateControl(property
, editor
);
2585 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2590 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2592 int vfb
= m_validationInfo
.m_failureBehavior
;
2594 if ( vfb
& wxPG_VFB_BEEP
)
2597 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2598 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2600 unsigned int colCount
= m_pState
->GetColumnCount();
2602 // We need backup marked property's cells
2603 m_propCellsBackup
= property
->m_cells
;
2605 wxColour vfbFg
= *wxWHITE
;
2606 wxColour vfbBg
= *wxRED
;
2608 property
->EnsureCells(colCount
);
2610 for ( unsigned int i
=0; i
<colCount
; i
++ )
2612 wxPGCell
& cell
= property
->m_cells
[i
];
2613 cell
.SetFgCol(vfbFg
);
2614 cell
.SetBgCol(vfbBg
);
2617 DrawItemAndChildren(property
);
2619 if ( property
== m_selected
)
2621 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2623 wxWindow
* editor
= GetEditorControl();
2626 editor
->SetForegroundColour(vfbFg
);
2627 editor
->SetBackgroundColour(vfbBg
);
2632 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2634 wxString msg
= m_validationInfo
.m_failureMessage
;
2636 if ( !msg
.length() )
2637 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2639 DoShowPropertyError(property
, msg
);
2642 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2645 // -----------------------------------------------------------------------
2647 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2649 int vfb
= m_validationInfo
.m_failureBehavior
;
2651 if ( vfb
& wxPG_VFB_MARK_CELL
)
2654 property
->m_cells
= m_propCellsBackup
;
2656 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2658 if ( property
== m_selected
&& GetEditorControl() )
2660 // Calling this will recreate the control, thus resetting its colour
2661 RefreshProperty(property
);
2665 DrawItemAndChildren(property
);
2670 // -----------------------------------------------------------------------
2672 // flags are same as with DoSelectProperty
2673 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2675 if ( m_inDoPropertyChanged
)
2678 wxWindow
* editor
= GetEditorControl();
2680 m_pState
->m_anyModified
= 1;
2682 m_inDoPropertyChanged
= 1;
2684 // Maybe need to update control
2685 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2687 // These values were calculated in PerformValidation()
2688 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2689 wxVariant value
= m_chgInfo_pendingValue
;
2691 wxPGProperty
* topPaintedProperty
= changedProperty
;
2693 while ( !topPaintedProperty
->IsCategory() &&
2694 !topPaintedProperty
->IsRoot() )
2696 topPaintedProperty
= topPaintedProperty
->GetParent();
2699 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2701 // Set as Modified (not if dragging just began)
2702 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2704 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2705 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2708 SetCurControlBoldFont();
2714 // Propagate updates to parent(s)
2716 wxPGProperty
* prevPwc
= NULL
;
2718 while ( prevPwc
!= topPaintedProperty
)
2720 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2722 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2725 SetCurControlBoldFont();
2729 pwc
= pwc
->GetParent();
2732 // Draw the actual property
2733 DrawItemAndChildren( topPaintedProperty
);
2736 // If value was set by wxPGProperty::OnEvent, then update the editor
2738 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2744 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2745 if ( m_wndEditor
) m_wndEditor
->Refresh();
2746 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2751 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2753 // If top parent has composite string value, then send to child parents,
2754 // starting from baseChangedProperty.
2755 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2757 pwc
= m_chgInfo_baseChangedProperty
;
2759 while ( pwc
!= changedProperty
)
2761 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2762 pwc
= pwc
->GetParent();
2766 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2768 m_inDoPropertyChanged
= 0;
2773 // -----------------------------------------------------------------------
2775 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2777 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2779 m_chgInfo_changedProperty
= NULL
;
2781 if ( PerformValidation(p
, newValue
) )
2783 DoPropertyChanged(p
);
2788 OnValidationFailure(p
, newValue
);
2794 // -----------------------------------------------------------------------
2796 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2798 wxPGProperty
* prop
= GetSelectedProperty();
2801 return wxNullVariant
;
2803 wxTextCtrl
* tc
= GetEditorTextCtrl();
2804 wxVariant value
= prop
->GetValue();
2806 if ( !tc
|| !IsEditorsValueModified() )
2809 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2812 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2813 return prop
->GetValue();
2818 // -----------------------------------------------------------------------
2820 // Runs wxValidator for the selected property
2821 bool wxPropertyGrid::DoEditorValidate()
2826 // -----------------------------------------------------------------------
2828 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2830 wxPGProperty
* selected
= m_selected
;
2832 // Somehow, event is handled after property has been deselected.
2833 // Possibly, but very rare.
2837 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2840 wxVariant
pendingValue(selected
->GetValueRef());
2841 wxWindow
* wnd
= GetEditorControl();
2842 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2844 bool wasUnspecified
= selected
->IsValueUnspecified();
2845 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2846 bool valueIsPending
= false;
2848 m_chgInfo_changedProperty
= NULL
;
2850 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2853 // Filter out excess wxTextCtrl modified events
2854 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2856 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2858 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2860 wxString newTcValue
= tc
->GetValue();
2861 if ( m_prevTcValue
== newTcValue
)
2864 m_prevTcValue
= newTcValue
;
2867 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2869 bool validationFailure
= false;
2870 bool buttonWasHandled
= false;
2873 // Try common button handling
2874 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2876 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2880 buttonWasHandled
= true;
2881 // Store as res2, as previously (and still currently alternatively)
2882 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2883 // in wxPGProperty::OnEvent().
2884 adapter
->ShowDialog( this, selected
);
2889 if ( !buttonWasHandled
)
2891 if ( wnd
|| m_wndEditor2
)
2893 // First call editor class' event handler.
2894 const wxPGEditor
* editor
= selected
->GetEditorClass();
2896 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2898 // If changes, validate them
2899 if ( DoEditorValidate() )
2901 if ( editor
->GetValueFromControl( pendingValue
,
2904 valueIsPending
= true;
2908 validationFailure
= true;
2913 // Then the property's custom handler (must be always called, unless
2914 // validation failed).
2915 if ( !validationFailure
)
2916 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2919 // SetValueInEvent(), as called in one of the functions referred above
2920 // overrides editor's value.
2921 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2923 valueIsPending
= true;
2924 pendingValue
= m_changeInEventValue
;
2925 selFlags
|= wxPG_SEL_DIALOGVAL
;
2928 if ( !validationFailure
&& valueIsPending
)
2929 if ( !PerformValidation(m_selected
, pendingValue
) )
2930 validationFailure
= true;
2932 if ( validationFailure
)
2934 OnValidationFailure(selected
, pendingValue
);
2936 else if ( valueIsPending
)
2938 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2940 DoPropertyChanged(selected
, selFlags
);
2941 EditorsValueWasNotModified();
2943 // Regardless of editor type, unfocus editor on
2944 // text-editing related enter press.
2945 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2952 // No value after all
2954 // Regardless of editor type, unfocus editor on
2955 // text-editing related enter press.
2956 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2961 // Let unhandled button click events go to the parent
2962 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2964 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2965 GetEventHandler()->AddPendingEvent(evt
);
2969 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2972 // -----------------------------------------------------------------------
2973 // wxPropertyGrid editor control helper methods
2974 // -----------------------------------------------------------------------
2976 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2978 int itemy
= p
->GetY2(m_lineHeight
);
2980 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2981 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2982 int imageOffset
= 0;
2984 // TODO: If custom image detection changes from current, change this.
2985 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
2987 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2988 int iw
= p
->OnMeasureImage().x
;
2990 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
2991 imageOffset
= p
->GetImageOffset(iw
);
2996 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
2998 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3003 // -----------------------------------------------------------------------
3005 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3007 wxSize sz
= GetImageSize(p
, item
);
3008 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3009 wxPG_CUSTOM_IMAGE_SPACINGY
,
3014 // return size of custom paint image
3015 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3017 // If called with NULL property, then return default image
3018 // size for properties that use image.
3020 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3022 wxSize cis
= p
->OnMeasureImage(item
);
3024 int choiceCount
= p
->m_choices
.GetCount();
3025 int comVals
= p
->GetDisplayedCommonValueCount();
3026 if ( item
>= choiceCount
&& comVals
> 0 )
3028 unsigned int cvi
= item
-choiceCount
;
3029 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3031 else if ( item
>= 0 && choiceCount
== 0 )
3032 return wxSize(0, 0);
3037 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3042 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3049 // -----------------------------------------------------------------------
3051 // takes scrolling into account
3052 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3055 GetViewStart(&vx
,&vy
);
3056 vy
*=wxPG_PIXELS_PER_UNIT
;
3057 vx
*=wxPG_PIXELS_PER_UNIT
;
3060 ClientToScreen( px
, py
);
3063 // -----------------------------------------------------------------------
3065 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3068 GetViewStart(&pt2
.x
,&pt2
.y
);
3069 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3070 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3074 return m_pState
->HitTest(pt2
);
3077 // -----------------------------------------------------------------------
3079 // custom set cursor
3080 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3082 if ( type
== m_curcursor
&& !override
) return;
3084 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3086 if ( type
== wxCURSOR_SIZEWE
)
3087 cursor
= m_cursorSizeWE
;
3089 m_canvas
->SetCursor( *cursor
);
3094 // -----------------------------------------------------------------------
3095 // wxPropertyGrid property selection, editor creation
3096 // -----------------------------------------------------------------------
3099 // This class forwards events from property editor controls to wxPropertyGrid.
3100 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3103 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3104 : wxEvtHandler(), m_propGrid(propGrid
)
3108 virtual ~wxPropertyGridEditorEventForwarder()
3113 bool ProcessEvent( wxEvent
& event
)
3118 m_propGrid
->HandleCustomEditorEvent(event
);
3120 return wxEvtHandler::ProcessEvent(event
);
3123 wxPropertyGrid
* m_propGrid
;
3126 // Setups event handling for child control
3127 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3129 wxWindowID id
= argWnd
->GetId();
3131 if ( argWnd
== m_wndEditor
)
3133 argWnd
->Connect(id
, wxEVT_MOTION
,
3134 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3136 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3137 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3139 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3140 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3142 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3143 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3145 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3146 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3148 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3149 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3153 wxPropertyGridEditorEventForwarder
* forwarder
;
3154 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3155 argWnd
->PushEventHandler(forwarder
);
3157 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3158 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3162 void wxPropertyGrid::FreeEditors()
3165 // Return focus back to canvas from children (this is required at least for
3166 // GTK+, which, unlike Windows, clears focus when control is destroyed
3167 // instead of moving it to closest parent).
3168 wxWindow
* focus
= wxWindow::FindFocus();
3171 wxWindow
* parent
= focus
->GetParent();
3174 if ( parent
== m_canvas
)
3179 parent
= parent
->GetParent();
3183 // Do not free editors immediately if processing events
3186 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3187 m_wndEditor2
->Hide();
3188 wxPendingDelete
.Append( handler
);
3189 wxPendingDelete
.Append( m_wndEditor2
);
3190 m_wndEditor2
= NULL
;
3195 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3196 m_wndEditor
->Hide();
3197 wxPendingDelete
.Append( handler
);
3198 wxPendingDelete
.Append( m_wndEditor
);
3203 // Call with NULL to de-select property
3204 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3208 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3209 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3211 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3214 if ( m_inDoSelectProperty
)
3217 m_inDoSelectProperty
= 1;
3219 wxPGProperty
* prev
= m_selected
;
3223 m_inDoSelectProperty
= 0;
3229 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3231 wxPrintf( "None selected\n" );
3234 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3236 wxPrintf( "P = NULL\n" );
3239 // If we are frozen, then just set the values.
3242 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3243 m_editorFocused
= 0;
3246 m_pState
->m_selected
= p
;
3248 // If frozen, always free controls. But don't worry, as Thaw will
3249 // recall SelectProperty to recreate them.
3252 // Prevent any further selection measures in this call
3258 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3260 // Only set focus if not deselecting
3263 if ( flags
& wxPG_SEL_FOCUS
)
3267 m_wndEditor
->SetFocus();
3268 m_editorFocused
= 1;
3277 m_inDoSelectProperty
= 0;
3282 // First, deactivate previous
3286 OnValidationFailureReset(m_selected
);
3288 // Must double-check if this is an selected in case of forceswitch
3291 if ( !CommitChangesFromEditor(flags
) )
3293 // Validation has failed, so we can't exit the previous editor
3294 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3295 // _("Invalid Value"),wxOK|wxICON_ERROR);
3296 m_inDoSelectProperty
= 0;
3305 m_pState
->m_selected
= NULL
;
3307 // We need to always fully refresh the grid here
3310 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3311 EditorsValueWasNotModified();
3314 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3317 // Then, activate the one given.
3320 int propY
= p
->GetY2(m_lineHeight
);
3322 int splitterX
= GetSplitterPosition();
3323 m_editorFocused
= 0;
3325 m_pState
->m_selected
= p
;
3326 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3328 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3330 wxASSERT( m_wndEditor
== NULL
);
3333 // Only create editor for non-disabled non-caption
3334 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3336 // do this for non-caption items
3340 // Do we need to paint the custom image, if any?
3341 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3342 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3343 !p
->GetEditorClass()->CanContainCustomImage()
3345 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3347 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3348 wxPoint goodPos
= grect
.GetPosition();
3349 #if wxPG_CREATE_CONTROLS_HIDDEN
3350 int coord_adjust
= m_height
- goodPos
.y
;
3351 goodPos
.y
+= coord_adjust
;
3354 const wxPGEditor
* editor
= p
->GetEditorClass();
3355 wxCHECK_MSG(editor
, false,
3356 wxT("NULL editor class not allowed"));
3358 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3360 wxPGWindowList wndList
= editor
->CreateControls(this,
3365 m_wndEditor
= wndList
.m_primary
;
3366 m_wndEditor2
= wndList
.m_secondary
;
3367 wxWindow
* primaryCtrl
= GetEditorControl();
3370 // Essentially, primaryCtrl == m_wndEditor
3373 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3374 // value is drawn as normal, and m_wndEditor2 is assumed
3375 // to be a right-aligned button that triggers a separate editorCtrl
3380 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3381 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3383 // Set validator, if any
3384 #if wxUSE_VALIDATORS
3385 wxValidator
* validator
= p
->GetValidator();
3387 primaryCtrl
->SetValidator(*validator
);
3390 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3391 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3393 // If it has modified status, use bold font
3394 // (must be done before capturing m_ctrlXAdjust)
3395 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3396 SetCurControlBoldFont();
3399 // Fix TextCtrl indentation
3400 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3401 wxTextCtrl
* tc
= NULL
;
3402 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3403 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3405 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3407 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3410 // Store x relative to splitter (we'll need it).
3411 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3413 // Check if background clear is not necessary
3414 wxPoint pos
= m_wndEditor
->GetPosition();
3415 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3417 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3420 m_wndEditor
->SetSizeHints(3, 3);
3422 #if wxPG_CREATE_CONTROLS_HIDDEN
3423 m_wndEditor
->Show(false);
3424 m_wndEditor
->Freeze();
3426 goodPos
= m_wndEditor
->GetPosition();
3427 goodPos
.y
-= coord_adjust
;
3428 m_wndEditor
->Move( goodPos
);
3431 SetupChildEventHandling(primaryCtrl
);
3433 // Focus and select all (wxTextCtrl, wxComboBox etc)
3434 if ( flags
& wxPG_SEL_FOCUS
)
3436 primaryCtrl
->SetFocus();
3438 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3444 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3445 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3447 // Get proper id for wndSecondary
3448 m_wndSecId
= m_wndEditor2
->GetId();
3449 wxWindowList children
= m_wndEditor2
->GetChildren();
3450 wxWindowList::iterator node
= children
.begin();
3451 if ( node
!= children
.end() )
3452 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3454 m_wndEditor2
->SetSizeHints(3,3);
3456 #if wxPG_CREATE_CONTROLS_HIDDEN
3457 wxRect sec_rect
= m_wndEditor2
->GetRect();
3458 sec_rect
.y
-= coord_adjust
;
3460 // Fine tuning required to fix "oversized"
3461 // button disappearance bug.
3462 if ( sec_rect
.y
< 0 )
3464 sec_rect
.height
+= sec_rect
.y
;
3467 m_wndEditor2
->SetSize( sec_rect
);
3469 m_wndEditor2
->Show();
3471 SetupChildEventHandling(m_wndEditor2
);
3473 // If no primary editor, focus to button to allow
3474 // it to interprete ENTER etc.
3475 // NOTE: Due to problems focusing away from it, this
3476 // has been disabled.
3478 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3479 m_wndEditor2->SetFocus();
3483 if ( flags
& wxPG_SEL_FOCUS
)
3484 m_editorFocused
= 1;
3489 // Make sure focus is in grid canvas (important for wxGTK, at least)
3493 EditorsValueWasNotModified();
3495 // If it's inside collapsed section, expand parent, scroll, etc.
3496 // Also, if it was partially visible, scroll it into view.
3497 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3502 #if wxPG_CREATE_CONTROLS_HIDDEN
3503 m_wndEditor
->Thaw();
3505 m_wndEditor
->Show(true);
3512 // Make sure focus is in grid canvas
3516 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3522 // Show help text in status bar.
3523 // (if found and grid not embedded in manager with help box and
3524 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3527 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3529 wxStatusBar
* statusbar
= NULL
;
3530 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3532 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3534 statusbar
= frame
->GetStatusBar();
3539 const wxString
* pHelpString
= (const wxString
*) NULL
;
3543 pHelpString
= &p
->GetHelpString();
3544 if ( pHelpString
->length() )
3546 // Set help box text.
3547 statusbar
->SetStatusText( *pHelpString
);
3548 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3552 if ( (!pHelpString
|| !pHelpString
->length()) &&
3553 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3555 // Clear help box - but only if it was written
3556 // by us at previous time.
3557 statusbar
->SetStatusText( m_emptyString
);
3558 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3564 m_inDoSelectProperty
= 0;
3566 // call wx event handler (here so that it also occurs on deselection)
3567 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3572 // -----------------------------------------------------------------------
3574 bool wxPropertyGrid::UnfocusEditor()
3576 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3579 if ( !CommitChangesFromEditor(0) )
3583 DrawItem(m_selected
);
3588 // -----------------------------------------------------------------------
3590 void wxPropertyGrid::RefreshEditor()
3592 wxPGProperty
* p
= m_selected
;
3596 wxWindow
* wnd
= GetEditorControl();
3600 // Set editor font boldness - must do this before
3601 // calling UpdateControl().
3602 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3604 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3605 wnd
->SetFont(GetCaptionFont());
3607 wnd
->SetFont(GetFont());
3610 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3612 editorClass
->UpdateControl(p
, wnd
);
3614 if ( p
->IsValueUnspecified() )
3615 editorClass
->SetValueToUnspecified(p
, wnd
);
3618 // -----------------------------------------------------------------------
3620 // This method is not inline because it called dozens of times
3621 // (i.e. two-arg function calls create smaller code size).
3622 bool wxPropertyGrid::DoClearSelection()
3624 return DoSelectProperty(NULL
);
3627 // -----------------------------------------------------------------------
3628 // wxPropertyGrid expand/collapse state
3629 // -----------------------------------------------------------------------
3631 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3633 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3635 // If active editor was inside collapsed section, then disable it
3636 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3638 ClearSelection(false);
3641 // Store dont-center-splitter flag 'cause we need to temporarily set it
3642 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3643 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3645 bool res
= m_pState
->DoCollapse(pwc
);
3650 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3652 RecalculateVirtualSize();
3654 // Redraw etc. only if collapsed was visible.
3655 if (pwc
->IsVisible() &&
3657 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3659 // When item is collapsed so that scrollbar would move,
3660 // graphics mess is about (unless we redraw everything).
3665 // Clear dont-center-splitter flag if it wasn't set
3666 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3671 // -----------------------------------------------------------------------
3673 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3675 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3677 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3679 // Store dont-center-splitter flag 'cause we need to temporarily set it
3680 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3681 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3683 bool res
= m_pState
->DoExpand(pwc
);
3688 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3690 RecalculateVirtualSize();
3692 // Redraw etc. only if expanded was visible.
3693 if ( pwc
->IsVisible() && !m_frozen
&&
3694 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3698 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3701 DrawItems(pwc
, NULL
);
3706 // Clear dont-center-splitter flag if it wasn't set
3707 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3712 // -----------------------------------------------------------------------
3714 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3717 return m_pState
->DoHideProperty(p
, hide
, flags
);
3720 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3723 ClearSelection(false);
3726 m_pState
->DoHideProperty(p
, hide
, flags
);
3728 RecalculateVirtualSize();
3735 // -----------------------------------------------------------------------
3736 // wxPropertyGrid size related methods
3737 // -----------------------------------------------------------------------
3739 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3741 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3745 // If virtual height was changed, then recalculate editor control position(s)
3746 if ( m_pState
->m_vhCalcPending
)
3747 CorrectEditorWidgetPosY();
3749 m_pState
->EnsureVirtualHeight();
3751 wxASSERT_LEVEL_2_MSG(
3752 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3753 "VirtualHeight and ActualVirtualHeight should match"
3756 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3758 int x
= m_pState
->m_width
;
3759 int y
= m_pState
->m_virtualHeight
;
3762 GetClientSize(&width
,&height
);
3764 // Now adjust virtual size.
3765 SetVirtualSize(x
, y
);
3771 // Adjust scrollbars
3772 if ( HasVirtualWidth() )
3774 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3775 xPos
= GetScrollPos( wxHORIZONTAL
);
3778 if ( forceXPos
!= -1 )
3781 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3784 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3785 int yPos
= GetScrollPos( wxVERTICAL
);
3787 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3788 xAmount
, yAmount
, xPos
, yPos
, true );
3790 // Must re-get size now
3791 GetClientSize(&width
,&height
);
3793 if ( !HasVirtualWidth() )
3795 m_pState
->SetVirtualWidth(width
);
3802 m_canvas
->SetSize( x
, y
);
3804 m_pState
->CheckColumnWidths();
3807 CorrectEditorWidgetSizeX();
3809 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3812 // -----------------------------------------------------------------------
3814 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3816 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3820 GetClientSize(&width
,&height
);
3825 #if wxPG_DOUBLE_BUFFER
3826 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3828 int dblh
= (m_lineHeight
*2);
3829 if ( !m_doubleBuffer
)
3831 // Create double buffer bitmap to draw on, if none
3832 int w
= (width
>250)?width
:250;
3833 int h
= height
+ dblh
;
3835 m_doubleBuffer
= new wxBitmap( w
, h
);
3839 int w
= m_doubleBuffer
->GetWidth();
3840 int h
= m_doubleBuffer
->GetHeight();
3842 // Double buffer must be large enough
3843 if ( w
< width
|| h
< (height
+dblh
) )
3845 if ( w
< width
) w
= width
;
3846 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3847 delete m_doubleBuffer
;
3848 m_doubleBuffer
= new wxBitmap( w
, h
);
3855 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3856 m_ncWidth
= event
.GetSize().x
;
3860 if ( m_pState
->m_itemsAdded
)
3861 PrepareAfterItemsAdded();
3863 // Without this, virtual size (atleast under wxGTK) will be skewed
3864 RecalculateVirtualSize();
3870 // -----------------------------------------------------------------------
3872 void wxPropertyGrid::SetVirtualWidth( int width
)
3876 // Disable virtual width
3877 width
= GetClientSize().x
;
3878 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3882 // Enable virtual width
3883 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3885 m_pState
->SetVirtualWidth( width
);
3888 void wxPropertyGrid::SetFocusOnCanvas()
3890 m_canvas
->SetFocusIgnoringChildren();
3891 m_editorFocused
= 0;
3894 // -----------------------------------------------------------------------
3895 // wxPropertyGrid mouse event handling
3896 // -----------------------------------------------------------------------
3898 // selFlags uses same values DoSelectProperty's flags
3899 // Returns true if event was vetoed.
3900 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3902 // Send property grid event of specific type and with specific property
3903 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3904 evt
.SetPropertyGrid(this);
3905 evt
.SetEventObject(m_eventObject
);
3909 evt
.SetCanVeto(true);
3910 evt
.SetupValidationInfo();
3911 m_validationInfo
.m_pValue
= pValue
;
3913 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3915 evtHandler
->ProcessEvent(evt
);
3917 return evt
.WasVetoed();
3920 // -----------------------------------------------------------------------
3922 // Return false if should be skipped
3923 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3927 // Need to set focus?
3928 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3933 wxPropertyGridPageState
* state
= m_pState
;
3935 int splitterHitOffset
;
3936 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3938 wxPGProperty
* p
= DoGetItemAtY(y
);
3942 int depth
= (int)p
->GetDepth() - 1;
3944 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3946 if ( x
>= marginEnds
)
3950 if ( p
->IsCategory() )
3952 // This is category.
3953 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3955 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3957 // Expand, collapse, activate etc. if click on text or left of splitter.
3960 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3965 if ( !DoSelectProperty( p
) )
3968 // On double-click, expand/collapse.
3969 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3971 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3972 else DoExpand( p
, true );
3976 else if ( splitterHit
== -1 )
3979 unsigned int selFlag
= 0;
3980 if ( columnHit
== 1 )
3982 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3983 selFlag
= wxPG_SEL_FOCUS
;
3985 if ( !DoSelectProperty( p
, selFlag
) )
3988 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3990 if ( p
->GetChildCount() && !p
->IsCategory() )
3991 // On double-click, expand/collapse.
3992 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3994 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3995 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3996 else DoExpand( p
, true );
4003 // click on splitter
4004 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4006 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4008 // Double-clicking the splitter causes auto-centering
4009 CenterSplitter( true );
4011 else if ( m_dragStatus
== 0 )
4014 // Begin draggin the splitter
4018 // Changes must be committed here or the
4019 // value won't be drawn correctly
4020 if ( !CommitChangesFromEditor() )
4023 m_wndEditor
->Show ( false );
4026 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4028 m_canvas
->CaptureMouse();
4029 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4033 m_draggedSplitter
= splitterHit
;
4034 m_dragOffset
= splitterHitOffset
;
4036 wxClientDC
dc(m_canvas
);
4038 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4039 // Fixes button disappearance bug
4041 m_wndEditor2
->Show ( false );
4044 m_startingSplitterX
= x
- splitterHitOffset
;
4052 if ( p
->GetChildCount() )
4054 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4056 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4058 int y2
= y
% m_lineHeight
;
4059 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4061 // On click on expander button, expand/collapse
4062 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4063 DoCollapse( p
, true );
4065 DoExpand( p
, true );
4074 // -----------------------------------------------------------------------
4076 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4077 wxMouseEvent
& WXUNUSED(event
) )
4081 // Select property here as well
4082 wxPGProperty
* p
= m_propHover
;
4083 if ( p
!= m_selected
)
4084 DoSelectProperty( p
);
4086 // Send right click event.
4087 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4094 // -----------------------------------------------------------------------
4096 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4097 wxMouseEvent
& WXUNUSED(event
) )
4101 // Select property here as well
4102 wxPGProperty
* p
= m_propHover
;
4104 if ( p
!= m_selected
)
4105 DoSelectProperty( p
);
4107 // Send double-click event.
4108 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4115 // -----------------------------------------------------------------------
4117 #if wxPG_SUPPORT_TOOLTIPS
4119 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4121 if ( tipString
.length() )
4123 m_canvas
->SetToolTip(tipString
);
4127 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4128 m_canvas
->SetToolTip( m_emptyString
);
4130 m_canvas
->SetToolTip( NULL
);
4135 #endif // #if wxPG_SUPPORT_TOOLTIPS
4137 // -----------------------------------------------------------------------
4139 // Return false if should be skipped
4140 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4142 // Safety check (needed because mouse capturing may
4143 // otherwise freeze the control)
4144 if ( m_dragStatus
> 0 && !event
.Dragging() )
4146 HandleMouseUp(x
,y
,event
);
4149 wxPropertyGridPageState
* state
= m_pState
;
4151 int splitterHitOffset
;
4152 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4153 int splitterX
= x
- splitterHitOffset
;
4155 if ( m_dragStatus
> 0 )
4157 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4158 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4161 int newSplitterX
= x
- m_dragOffset
;
4162 int splitterX
= x
- splitterHitOffset
;
4164 // Splitter redraw required?
4165 if ( newSplitterX
!= splitterX
)
4168 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4169 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4170 state
->m_fSplitterX
= (float) newSplitterX
;
4173 CorrectEditorWidgetSizeX();
4187 int ih
= m_lineHeight
;
4190 #if wxPG_SUPPORT_TOOLTIPS
4191 wxPGProperty
* prevHover
= m_propHover
;
4192 unsigned char prevSide
= m_mouseSide
;
4194 int curPropHoverY
= y
- (y
% ih
);
4196 // On which item it hovers
4199 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4202 // Mouse moves on another property
4204 m_propHover
= DoGetItemAtY(y
);
4205 m_propHoverY
= curPropHoverY
;
4208 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4211 #if wxPG_SUPPORT_TOOLTIPS
4212 // Store which side we are on
4214 if ( columnHit
== 1 )
4216 else if ( columnHit
== 0 )
4220 // If tooltips are enabled, show label or value as a tip
4221 // in case it doesn't otherwise show in full length.
4223 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4225 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4227 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4229 if ( m_propHover
&& !m_propHover
->IsCategory() )
4232 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4234 // Show help string as a tooltip
4235 wxString tipString
= m_propHover
->GetHelpString();
4237 SetToolTip(tipString
);
4241 // Show cropped value string as a tooltip
4245 if ( m_mouseSide
== 1 )
4247 tipString
= m_propHover
->m_label
;
4248 space
= splitterX
-m_marginWidth
-3;
4250 else if ( m_mouseSide
== 2 )
4252 tipString
= m_propHover
->GetDisplayedString();
4254 space
= m_width
- splitterX
;
4255 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4256 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4262 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4265 SetToolTip( tipString
);
4272 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4273 m_canvas
->SetToolTip( m_emptyString
);
4275 m_canvas
->SetToolTip( NULL
);
4286 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4287 m_canvas
->SetToolTip( m_emptyString
);
4289 m_canvas
->SetToolTip( NULL
);
4297 if ( splitterHit
== -1 ||
4299 HasFlag(wxPG_STATIC_SPLITTER
) )
4301 // hovering on something else
4302 if ( m_curcursor
!= wxCURSOR_ARROW
)
4303 CustomSetCursor( wxCURSOR_ARROW
);
4307 // Do not allow splitter cursor on caption items.
4308 // (also not if we were dragging and its started
4309 // outside the splitter region)
4311 if ( !m_propHover
->IsCategory() &&
4315 // hovering on splitter
4317 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4318 // reliably detected.
4319 //if ( m_curcursor != wxCURSOR_SIZEWE )
4320 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4326 // hovering on something else
4327 if ( m_curcursor
!= wxCURSOR_ARROW
)
4328 CustomSetCursor( wxCURSOR_ARROW
);
4335 // -----------------------------------------------------------------------
4337 // Also handles Leaving event
4338 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4339 wxMouseEvent
&WXUNUSED(event
) )
4341 wxPropertyGridPageState
* state
= m_pState
;
4345 int splitterHitOffset
;
4346 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4348 // No event type check - basicly calling this method should
4349 // just stop dragging.
4350 // Left up after dragged?
4351 if ( m_dragStatus
>= 1 )
4354 // End Splitter Dragging
4356 // DO NOT ENABLE FOLLOWING LINE!
4357 // (it is only here as a reminder to not to do it)
4360 // Disable splitter auto-centering
4361 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4363 // This is necessary to return cursor
4364 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4366 m_canvas
->ReleaseMouse();
4367 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4370 // Set back the default cursor, if necessary
4371 if ( splitterHit
== -1 ||
4374 CustomSetCursor( wxCURSOR_ARROW
);
4379 // Control background needs to be cleared
4380 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4381 DrawItem( m_selected
);
4385 m_wndEditor
->Show ( true );
4388 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4389 // Fixes button disappearance bug
4391 m_wndEditor2
->Show ( true );
4394 // This clears the focus.
4395 m_editorFocused
= 0;
4401 // -----------------------------------------------------------------------
4403 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4405 int splitterX
= GetSplitterPosition();
4408 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4412 wxWindow
* wnd
= GetEditorControl();
4414 // Hide popup on clicks
4415 if ( event
.GetEventType() != wxEVT_MOTION
)
4416 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4418 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4424 if ( wnd
== NULL
|| m_dragStatus
||
4426 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4427 ux
>= (r
.x
+r
.width
) ||
4429 event
.m_y
>= (r
.y
+r
.height
)
4439 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4444 // -----------------------------------------------------------------------
4446 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4449 if ( OnMouseCommon( event
, &x
, &y
) )
4451 HandleMouseClick(x
,y
,event
);
4456 // -----------------------------------------------------------------------
4458 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4461 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4462 HandleMouseRightClick(x
,y
,event
);
4466 // -----------------------------------------------------------------------
4468 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4470 // Always run standard mouse-down handler as well
4471 OnMouseClick(event
);
4474 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4475 HandleMouseDoubleClick(x
,y
,event
);
4479 // -----------------------------------------------------------------------
4481 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4484 if ( OnMouseCommon( event
, &x
, &y
) )
4486 HandleMouseMove(x
,y
,event
);
4491 // -----------------------------------------------------------------------
4493 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4495 // Called when mouse moves in the empty space below the properties.
4496 CustomSetCursor( wxCURSOR_ARROW
);
4499 // -----------------------------------------------------------------------
4501 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4504 if ( OnMouseCommon( event
, &x
, &y
) )
4506 HandleMouseUp(x
,y
,event
);
4511 // -----------------------------------------------------------------------
4513 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4515 // This may get called from child control as well, so event's
4516 // mouse position cannot be relied on.
4518 if ( event
.Entering() )
4520 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4522 // TODO: Fix this (detect parent and only do
4523 // cursor trick if it is a manager).
4524 wxASSERT( GetParent() );
4525 GetParent()->SetCursor(wxNullCursor
);
4527 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4530 GetParent()->SetCursor(wxNullCursor
);
4532 else if ( event
.Leaving() )
4534 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4535 m_canvas
->SetCursor( wxNullCursor
);
4537 // Get real cursor position
4538 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4540 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4543 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4545 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4549 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4557 // -----------------------------------------------------------------------
4559 // Common code used by various OnMouseXXXChild methods.
4560 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4562 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4563 wxASSERT( topCtrlWnd
);
4565 event
.GetPosition(&x
,&y
);
4567 int splitterX
= GetSplitterPosition();
4569 wxRect r
= topCtrlWnd
->GetRect();
4570 if ( !m_dragStatus
&&
4571 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4572 y
>= 0 && y
< r
.height \
4575 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4580 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4587 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4590 if ( OnMouseChildCommon(event
,&x
,&y
) )
4592 bool res
= HandleMouseClick(x
,y
,event
);
4593 if ( !res
) event
.Skip();
4597 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4600 wxASSERT( m_wndEditor
);
4601 // These coords may not be exact (about +-2),
4602 // but that should not matter (right click is about item, not position).
4603 wxPoint pt
= m_wndEditor
->GetPosition();
4604 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4605 wxASSERT( m_selected
);
4606 m_propHover
= m_selected
;
4607 bool res
= HandleMouseRightClick(x
,y
,event
);
4608 if ( !res
) event
.Skip();
4611 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4614 if ( OnMouseChildCommon(event
,&x
,&y
) )
4616 bool res
= HandleMouseMove(x
,y
,event
);
4617 if ( !res
) event
.Skip();
4621 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4624 if ( OnMouseChildCommon(event
,&x
,&y
) )
4626 bool res
= HandleMouseUp(x
,y
,event
);
4627 if ( !res
) event
.Skip();
4631 // -----------------------------------------------------------------------
4632 // wxPropertyGrid keyboard event handling
4633 // -----------------------------------------------------------------------
4635 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4637 // Translates wxKeyEvent to wxPG_ACTION_XXX
4639 int keycode
= event
.GetKeyCode();
4640 int modifiers
= event
.GetModifiers();
4642 wxASSERT( !(modifiers
&~(0xFFFF)) );
4644 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4646 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4648 if ( it
== m_actionTriggers
.end() )
4653 int second
= (it
->second
>>16) & 0xFFFF;
4657 return (it
->second
& 0xFFFF);
4660 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4662 wxASSERT( !(modifiers
&~(0xFFFF)) );
4664 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4666 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4668 if ( it
!= m_actionTriggers
.end() )
4670 // This key combination is already used
4672 // Can add secondary?
4673 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4674 wxT("You can only add up to two separate actions per key combination.") );
4676 action
= it
->second
| (action
<<16);
4679 m_actionTriggers
[hashMapKey
] = action
;
4682 void wxPropertyGrid::ClearActionTriggers( int action
)
4684 wxPGHashMapI2I::iterator it
;
4686 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4688 if ( it
->second
== action
)
4690 m_actionTriggers
.erase(it
);
4695 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4698 // Handles key event when editor control is not focused.
4701 wxCHECK2(!m_frozen
, return);
4703 // Travelsal between items, collapsing/expanding, etc.
4704 int keycode
= event
.GetKeyCode();
4705 bool editorFocused
= IsEditorFocused();
4707 if ( keycode
== WXK_TAB
)
4709 wxWindow
* mainControl
;
4711 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4712 mainControl
= GetParent();
4716 if ( !event
.ShiftDown() )
4718 if ( !editorFocused
&& m_wndEditor
)
4720 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4724 // Tab traversal workaround for platforms on which
4725 // wxWindow::Navigate() may navigate into first child
4726 // instead of next sibling. Does not work perfectly
4727 // in every scenario (for instance, when property grid
4728 // is either first or last control).
4729 #if defined(__WXGTK__)
4730 wxWindow
* sibling
= mainControl
->GetNextSibling();
4732 sibling
->SetFocusFromKbd();
4734 Navigate(wxNavigationKeyEvent::IsForward
);
4740 if ( editorFocused
)
4746 #if defined(__WXGTK__)
4747 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4749 sibling
->SetFocusFromKbd();
4751 Navigate(wxNavigationKeyEvent::IsBackward
);
4759 // Ignore Alt and Control when they are down alone
4760 if ( keycode
== WXK_ALT
||
4761 keycode
== WXK_CONTROL
)
4768 int action
= KeyEventToActions(event
, &secondAction
);
4770 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4773 // Esc cancels any changes
4774 if ( IsEditorsValueModified() )
4776 EditorsValueWasNotModified();
4778 // Update the control as well
4779 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4781 m_selected
->GetDisplayedString() );
4784 OnValidationFailureReset(m_selected
);
4790 // Except for TAB and ESC, handle child control events in child control
4793 // Only propagate event if it had modifiers
4794 if ( !event
.HasModifiers() )
4796 event
.StopPropagation();
4802 bool wasHandled
= false;
4807 if ( ButtonTriggerKeyTest(action
, event
) )
4810 wxPGProperty
* p
= m_selected
;
4812 // Travel and expand/collapse
4815 if ( p
->GetChildCount() )
4817 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4819 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4822 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4824 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4831 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4835 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4841 if ( selectDir
>= -1 )
4843 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4845 DoSelectProperty(p
);
4851 // If nothing was selected, select the first item now
4852 // (or navigate out of tab).
4853 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4855 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4856 if ( p
) DoSelectProperty(p
);
4865 // -----------------------------------------------------------------------
4867 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4869 // If there was editor open and focused, then this event should not
4870 // really be processed here.
4871 if ( IsEditorFocused() )
4873 // However, if event had modifiers, it is probably still best
4875 if ( event
.HasModifiers() )
4878 event
.StopPropagation();
4882 HandleKeyEvent(event
, false);
4885 // -----------------------------------------------------------------------
4887 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4892 action
= KeyEventToActions(event
, &secondAction
);
4895 // Does the keycode trigger button?
4896 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4899 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4900 GetEventHandler()->AddPendingEvent(evt
);
4907 // -----------------------------------------------------------------------
4909 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4911 HandleKeyEvent(event
, true);
4914 // -----------------------------------------------------------------------
4915 // wxPropertyGrid miscellaneous event handling
4916 // -----------------------------------------------------------------------
4918 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4921 // Check if the focus is in this control or one of its children
4922 wxWindow
* newFocused
= wxWindow::FindFocus();
4924 if ( newFocused
!= m_curFocused
)
4925 HandleFocusChange( newFocused
);
4928 bool wxPropertyGrid::IsEditorFocused() const
4930 wxWindow
* focus
= wxWindow::FindFocus();
4932 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4933 focus
== GetEditorControl() )
4939 // Called by focus event handlers. newFocused is the window that becomes focused.
4940 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4942 unsigned int oldFlags
= m_iFlags
;
4944 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4946 wxWindow
* parent
= newFocused
;
4948 // This must be one of nextFocus' parents.
4951 // Use m_eventObject, which is either wxPropertyGrid or
4952 // wxPropertyGridManager, as appropriate.
4953 if ( parent
== m_eventObject
)
4955 m_iFlags
|= wxPG_FL_FOCUSED
;
4958 parent
= parent
->GetParent();
4961 m_curFocused
= newFocused
;
4963 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4964 (oldFlags
& wxPG_FL_FOCUSED
) )
4966 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4968 // Need to store changed value
4969 CommitChangesFromEditor();
4975 // Preliminary code for tab-order respecting
4976 // tab-traversal (but should be moved to
4979 wxWindow* prevFocus = event.GetWindow();
4980 wxWindow* useThis = this;
4981 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4982 useThis = GetParent();
4985 prevFocus->GetParent() == useThis->GetParent() )
4987 wxList& children = useThis->GetParent()->GetChildren();
4989 wxNode* node = children.Find(prevFocus);
4991 if ( node->GetNext() &&
4992 useThis == node->GetNext()->GetData() )
4993 DoSelectProperty(GetFirst());
4994 else if ( node->GetPrevious () &&
4995 useThis == node->GetPrevious()->GetData() )
4996 DoSelectProperty(GetLastProperty());
5003 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5004 DrawItem( m_selected
);
5008 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5010 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5011 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5012 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5013 //else if ( event.GetWindow() )
5015 HandleFocusChange(event
.GetWindow());
5020 // -----------------------------------------------------------------------
5022 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5024 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5028 // -----------------------------------------------------------------------
5030 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5032 m_iFlags
|= wxPG_FL_SCROLLED
;
5037 // -----------------------------------------------------------------------
5039 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5041 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5043 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5047 // -----------------------------------------------------------------------
5048 // Property editor related functions
5049 // -----------------------------------------------------------------------
5051 // noDefCheck = true prevents infinite recursion.
5052 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5055 wxASSERT( editorClass
);
5057 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5058 RegisterDefaultEditors();
5060 wxString name
= editorClass
->GetName();
5062 // Existing editor under this name?
5063 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5065 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5067 // If this name was already used, try class name.
5068 name
= editorClass
->GetClassInfo()->GetClassName();
5069 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5072 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5073 (wxPGEditor
*) vt_it
->second
,
5074 "Editor with given name was already registered" );
5076 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5081 // Use this in RegisterDefaultEditors.
5082 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5083 if ( wxPGEditor_##EDITOR == NULL ) \
5085 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5086 new wxPG##EDITOR##Editor, true ); \
5089 // Registers all default editor classes
5090 void wxPropertyGrid::RegisterDefaultEditors()
5092 wxPGRegisterDefaultEditorClass( TextCtrl
);
5093 wxPGRegisterDefaultEditorClass( Choice
);
5094 wxPGRegisterDefaultEditorClass( ComboBox
);
5095 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5096 #if wxPG_INCLUDE_CHECKBOX
5097 wxPGRegisterDefaultEditorClass( CheckBox
);
5099 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5101 // Register SpinCtrl etc. editors before use
5102 RegisterAdditionalEditors();
5105 // -----------------------------------------------------------------------
5106 // wxPGStringTokenizer
5107 // Needed to handle C-style string lists (e.g. "str1" "str2")
5108 // -----------------------------------------------------------------------
5110 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5111 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5115 wxPGStringTokenizer::~wxPGStringTokenizer()
5119 bool wxPGStringTokenizer::HasMoreTokens()
5121 const wxString
& str
= *m_str
;
5123 wxString::const_iterator i
= m_curPos
;
5125 wxUniChar delim
= m_delimeter
;
5127 wxUniChar prev_a
= wxT('\0');
5129 bool inToken
= false;
5131 while ( i
!= str
.end() )
5140 m_readyToken
.clear();
5145 if ( prev_a
!= wxT('\\') )
5149 if ( a
!= wxT('\\') )
5169 m_curPos
= str
.end();
5177 wxString
wxPGStringTokenizer::GetNextToken()
5179 return m_readyToken
;
5182 // -----------------------------------------------------------------------
5184 // -----------------------------------------------------------------------
5186 wxPGChoiceEntry::wxPGChoiceEntry()
5187 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5191 // -----------------------------------------------------------------------
5193 // -----------------------------------------------------------------------
5195 wxPGChoicesData::wxPGChoicesData()
5200 wxPGChoicesData::~wxPGChoicesData()
5205 void wxPGChoicesData::Clear()
5210 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5212 wxASSERT( m_items
.size() == 0 );
5214 m_items
= data
->m_items
;
5217 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5218 const wxPGChoiceEntry
& item
)
5220 wxVector
<wxPGChoiceEntry
>::iterator it
;
5224 index
= (int) m_items
.size();
5228 it
= m_items
.begin() + index
;
5231 m_items
.insert(it
, item
);
5233 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5235 // Need to fix value?
5236 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5237 ownEntry
.SetValue(index
);
5242 // -----------------------------------------------------------------------
5243 // wxPropertyGridEvent
5244 // -----------------------------------------------------------------------
5246 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5249 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5250 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5251 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5252 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5253 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5254 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5255 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5256 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5257 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5260 // -----------------------------------------------------------------------
5262 void wxPropertyGridEvent::Init()
5264 m_validationInfo
= NULL
;
5266 m_wasVetoed
= false;
5269 // -----------------------------------------------------------------------
5271 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5272 : wxCommandEvent(commandType
,id
)
5278 // -----------------------------------------------------------------------
5280 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5281 : wxCommandEvent(event
)
5283 m_eventType
= event
.GetEventType();
5284 m_eventObject
= event
.m_eventObject
;
5286 m_property
= event
.m_property
;
5287 m_validationInfo
= event
.m_validationInfo
;
5288 m_canVeto
= event
.m_canVeto
;
5289 m_wasVetoed
= event
.m_wasVetoed
;
5292 // -----------------------------------------------------------------------
5294 wxPropertyGridEvent::~wxPropertyGridEvent()
5298 // -----------------------------------------------------------------------
5300 wxEvent
* wxPropertyGridEvent::Clone() const
5302 return new wxPropertyGridEvent( *this );
5305 // -----------------------------------------------------------------------
5306 // wxPropertyGridPopulator
5307 // -----------------------------------------------------------------------
5309 wxPropertyGridPopulator::wxPropertyGridPopulator()
5313 wxPGGlobalVars
->m_offline
++;
5316 // -----------------------------------------------------------------------
5318 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5321 m_propHierarchy
.clear();
5324 // -----------------------------------------------------------------------
5326 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5332 // -----------------------------------------------------------------------
5334 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5337 // Free unused sets of choices
5338 wxPGHashMapS2P::iterator it
;
5340 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5342 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5349 m_pg
->GetPanel()->Refresh();
5351 wxPGGlobalVars
->m_offline
--;
5354 // -----------------------------------------------------------------------
5356 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5357 const wxString
& propLabel
,
5358 const wxString
& propName
,
5359 const wxString
* propValue
,
5360 wxPGChoices
* pChoices
)
5362 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5363 wxPGProperty
* parent
= GetCurParent();
5365 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5367 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5371 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5373 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5377 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5379 property
->SetLabel(propLabel
);
5380 property
->DoSetName(propName
);
5382 if ( pChoices
&& pChoices
->IsOk() )
5383 property
->SetChoices(*pChoices
);
5385 m_state
->DoInsert(parent
, -1, property
);
5388 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5389 wxPG_PROGRAMMATIC_VALUE
);
5394 // -----------------------------------------------------------------------
5396 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5398 m_propHierarchy
.push_back(property
);
5399 DoScanForChildren();
5400 m_propHierarchy
.pop_back();
5403 // -----------------------------------------------------------------------
5405 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5406 const wxString
& idString
)
5408 wxPGChoices choices
;
5411 if ( choicesString
[0] == wxT('@') )
5413 wxString ids
= choicesString
.substr(1);
5414 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5415 if ( it
== m_dictIdChoices
.end() )
5416 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5418 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5423 if ( idString
.length() )
5425 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5426 if ( it
!= m_dictIdChoices
.end() )
5428 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5435 // Parse choices string
5436 wxString::const_iterator it
= choicesString
.begin();
5440 bool labelValid
= false;
5442 for ( ; it
!= choicesString
.end(); ++it
)
5448 if ( c
== wxT('"') )
5453 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5454 choices
.Add(label
, l
);
5457 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5462 else if ( c
== wxT('=') )
5469 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5476 if ( c
== wxT('"') )
5489 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5490 choices
.Add(label
, l
);
5493 if ( !choices
.IsOk() )
5495 choices
.EnsureData();
5499 if ( idString
.length() )
5500 m_dictIdChoices
[idString
] = choices
.GetData();
5507 // -----------------------------------------------------------------------
5509 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5511 if ( s
.Last() == wxT('%') )
5513 wxString s2
= s
.substr(0,s
.length()-1);
5515 if ( s2
.ToLong(&val
, 10) )
5517 *pval
= (val
*max
)/100;
5523 return s
.ToLong(pval
, 10);
5526 // -----------------------------------------------------------------------
5528 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5529 const wxString
& type
,
5530 const wxString
& value
)
5532 int l
= m_propHierarchy
.size();
5536 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5537 wxString valuel
= value
.Lower();
5540 if ( type
.length() == 0 )
5545 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5547 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5549 else if ( value
.ToLong(&v
, 0) )
5556 if ( type
== wxT("string") )
5560 else if ( type
== wxT("int") )
5563 value
.ToLong(&v
, 0);
5566 else if ( type
== wxT("bool") )
5568 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5575 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5580 p
->SetAttribute( name
, variant
);
5585 // -----------------------------------------------------------------------
5587 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5589 wxLogError(_("Error in resource: %s"),msg
.c_str());
5592 // -----------------------------------------------------------------------
5594 #endif // wxUSE_PROPGRID