1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
68 #include "wx/msw/private.h"
71 // Two pics for the expand / collapse buttons.
72 // Files are not supplied with this project (since it is
73 // recommended to use either custom or native rendering).
74 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
75 // and copy xpm files from archive to wxPropertyGrid src directory
76 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
77 // and set wxPG_USE_RENDERER_NATIVE to 0).
78 #ifndef wxPG_ICON_WIDTH
79 #if defined(__WXMAC__)
80 #include "mac_collapse.xpm"
81 #include "mac_expand.xpm"
82 #elif defined(__WXGTK__)
83 #include "linux_collapse.xpm"
84 #include "linux_expand.xpm"
86 #include "default_collapse.xpm"
87 #include "default_expand.xpm"
92 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
93 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
94 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
95 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
96 #define wxPG_YSPACING_MIN 1
97 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
98 // but causes normal combobox to spill out under MSW
100 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
102 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
103 // Must be larger than largest control border
107 #define wxPG_DEFAULT_CURSOR wxNullCursor
110 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
112 //#define wxPG_HIDER_BUTTON_HEIGHT 25
114 #define wxPG_PIXELS_PER_UNIT m_lineHeight
116 #ifdef wxPG_ICON_WIDTH
117 #define m_iconHeight m_iconWidth
120 //#define wxPG_TOOLTIP_DELAY 1000
122 // -----------------------------------------------------------------------
125 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
127 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
130 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 // -----------------------------------------------------------------------
135 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
137 // -----------------------------------------------------------------------
138 // Statics in one class for easy destruction.
139 // -----------------------------------------------------------------------
141 #include "wx/module.h"
143 class wxPGGlobalVarsClassManager
: public wxModule
145 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
147 wxPGGlobalVarsClassManager() {}
148 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
149 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
152 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
155 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
158 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
160 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
162 m_boolChoices
.Add(_("False"));
163 m_boolChoices
.Add(_("True"));
165 m_fontFamilyChoices
= NULL
;
167 m_defaultRenderer
= new wxPGDefaultRenderer();
169 m_autoGetTranslation
= false;
177 // Prepare some shared variants
178 m_vEmptyString
= wxString();
180 m_vMinusOne
= (long) -1;
184 // Prepare cached string constants
185 m_strstring
= wxS("string");
186 m_strlong
= wxS("long");
187 m_strbool
= wxS("bool");
188 m_strlist
= wxS("list");
189 m_strMin
= wxS("Min");
190 m_strMax
= wxS("Max");
191 m_strUnits
= wxS("Units");
192 m_strInlineHelp
= wxS("InlineHelp");
198 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
202 delete m_defaultRenderer
;
204 // This will always have one ref
205 delete m_fontFamilyChoices
;
208 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
209 delete ((wxValidator
*)m_arrValidators
[i
]);
213 // Destroy value type class instances.
214 wxPGHashMapS2P::iterator vt_it
;
216 // Destroy editor class instances.
217 // iterate over all the elements in the class
218 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
220 delete ((wxPGEditor
*)vt_it
->second
);
223 delete wxPGProperty::sm_wxPG_LABEL
;
226 void wxPropertyGridInitGlobalsIfNeeded()
230 // -----------------------------------------------------------------------
232 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
233 // and tries to commit property value.
234 // -----------------------------------------------------------------------
236 class wxPGTLWHandler
: public wxEvtHandler
240 wxPGTLWHandler( wxPropertyGrid
* pg
)
248 void OnClose( wxCloseEvent
& event
)
250 // ClearSelection forces value validation/commit.
251 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
261 wxPropertyGrid
* m_pg
;
263 DECLARE_EVENT_TABLE()
266 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
267 EVT_CLOSE(wxPGTLWHandler::OnClose
)
270 // -----------------------------------------------------------------------
272 // -----------------------------------------------------------------------
275 // wxPGCanvas acts as a graphics sub-window of the
276 // wxScrolledWindow that wxPropertyGrid is.
278 class wxPGCanvas
: public wxPanel
281 wxPGCanvas() : wxPanel()
284 virtual ~wxPGCanvas() { }
287 void OnMouseMove( wxMouseEvent
&event
)
289 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
290 pg
->OnMouseMove( event
);
293 void OnMouseClick( wxMouseEvent
&event
)
295 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
296 pg
->OnMouseClick( event
);
299 void OnMouseUp( wxMouseEvent
&event
)
301 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
302 pg
->OnMouseUp( event
);
305 void OnMouseRightClick( wxMouseEvent
&event
)
307 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
308 pg
->OnMouseRightClick( event
);
311 void OnMouseDoubleClick( wxMouseEvent
&event
)
313 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
314 pg
->OnMouseDoubleClick( event
);
317 void OnKey( wxKeyEvent
& event
)
319 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
323 void OnPaint( wxPaintEvent
& event
);
325 // Always be focussable, even with child windows
326 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
327 { wxPanel::SetCanFocus(true); }
331 DECLARE_EVENT_TABLE()
332 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
336 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
338 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
339 EVT_MOTION(wxPGCanvas::OnMouseMove
)
340 EVT_PAINT(wxPGCanvas::OnPaint
)
341 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
342 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
343 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
344 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
345 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
349 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
351 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
352 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
356 // Don't paint after destruction has begun
357 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
360 // Update everything inside the box
361 wxRect r
= GetUpdateRegion().GetBox();
363 // FIXME: This is just a workaround for a bug that causes splitters not
364 // to paint when other windows are being dragged over the grid.
365 wxRect fullRect
= GetRect();
367 r
.width
= fullRect
.width
;
369 // Repaint this rectangle
370 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
372 // We assume that the size set when grid is shown
373 // is what is desired.
374 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
377 // -----------------------------------------------------------------------
379 // -----------------------------------------------------------------------
381 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
383 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
384 EVT_IDLE(wxPropertyGrid::OnIdle
)
385 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
386 EVT_PAINT(wxPropertyGrid::OnPaint
)
387 EVT_SIZE(wxPropertyGrid::OnResize
)
388 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
389 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
390 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
391 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
392 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
393 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
394 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
395 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
399 // -----------------------------------------------------------------------
401 wxPropertyGrid::wxPropertyGrid()
407 // -----------------------------------------------------------------------
409 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
414 const wxString
& name
)
418 Create(parent
,id
,pos
,size
,style
,name
);
421 // -----------------------------------------------------------------------
423 bool wxPropertyGrid::Create( wxWindow
*parent
,
428 const wxString
& name
)
431 if ( !(style
&wxBORDER_MASK
) )
432 style
|= wxSIMPLE_BORDER
;
436 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
437 style
&= ~(wxTAB_TRAVERSAL
);
438 style
|= wxWANTS_CHARS
;
440 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
447 // -----------------------------------------------------------------------
450 // Initialize values to defaults
452 void wxPropertyGrid::Init1()
454 // Register editor classes, if necessary.
455 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
456 wxPropertyGrid::RegisterDefaultEditors();
460 m_wndEditor
= m_wndEditor2
= NULL
;
464 m_eventObject
= this;
467 m_sortFunction
= NULL
;
468 m_inDoPropertyChanged
= 0;
469 m_inCommitChangesFromEditor
= 0;
470 m_inDoSelectProperty
= 0;
471 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
477 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
478 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
479 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
480 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
481 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
482 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
483 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
484 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
485 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
487 m_coloursCustomized
= 0;
492 #if wxPG_DOUBLE_BUFFER
493 m_doubleBuffer
= NULL
;
496 #ifndef wxPG_ICON_WIDTH
502 m_iconWidth
= wxPG_ICON_WIDTH
;
507 m_gutterWidth
= wxPG_GUTTER_MIN
;
508 m_subgroup_extramargin
= 10;
512 m_width
= m_height
= 0;
514 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
517 m_chgInfo_changedProperty
= NULL
;
520 // -----------------------------------------------------------------------
523 // Initialize after parent etc. set
525 void wxPropertyGrid::Init2()
527 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
530 // Smaller controls on Mac
531 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
534 // Now create state, if one didn't exist already
535 // (wxPropertyGridManager might have created it for us).
538 m_pState
= CreateState();
539 m_pState
->m_pPropGrid
= this;
540 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
543 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
544 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
546 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
548 m_pState
->InitNonCatMode();
550 m_pState
->m_properties
= m_pState
->m_abcArray
;
553 GetClientSize(&m_width
,&m_height
);
555 #ifndef wxPG_ICON_WIDTH
556 // create two bitmap nodes for drawing
557 m_expandbmp
= new wxBitmap(expand_xpm
);
558 m_collbmp
= new wxBitmap(collapse_xpm
);
560 // calculate average font height for bitmap centering
562 m_iconWidth
= m_expandbmp
->GetWidth();
563 m_iconHeight
= m_expandbmp
->GetHeight();
566 m_curcursor
= wxCURSOR_ARROW
;
567 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
569 // adjust bitmap icon y position so they are centered
570 m_vspacing
= wxPG_DEFAULT_VSPACING
;
572 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
574 // Allocate cell datas indirectly by calling setter
575 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
576 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
580 // This helps with flicker
581 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
584 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
585 m_tlp
= ::wxGetTopLevelParent(this);
586 m_tlwHandler
= handler
;
587 m_tlp
->PushEventHandler(handler
);
589 // set virtual size to this window size
590 wxSize wndsize
= GetSize();
591 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
593 m_timeCreated
= ::wxGetLocalTimeMillis();
595 m_canvas
= new wxPGCanvas();
596 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
597 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
598 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
600 m_iFlags
|= wxPG_FL_INITIALIZED
;
602 m_ncWidth
= wndsize
.GetWidth();
604 // Need to call OnResize handler or size given in constructor/Create
606 wxSizeEvent
sizeEvent(wndsize
,0);
610 // -----------------------------------------------------------------------
612 wxPropertyGrid::~wxPropertyGrid()
616 DoSelectProperty(NULL
);
618 // This should do prevent things from going too badly wrong
619 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
621 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
622 m_canvas
->ReleaseMouse();
624 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
625 m_tlp
->RemoveEventHandler(handler
);
628 wxASSERT_MSG( !IsEditorsValueModified(),
629 wxS("Most recent change in property editor was lost!!! ")
630 wxS("(if you don't want this to happen, close your frames ")
631 wxS("and dialogs using Close(false).)") );
633 #if wxPG_DOUBLE_BUFFER
634 if ( m_doubleBuffer
)
635 delete m_doubleBuffer
;
640 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
643 delete m_cursorSizeWE
;
645 #ifndef wxPG_ICON_WIDTH
650 // Delete common value records
651 for ( i
=0; i
<m_commonValues
.size(); i
++ )
653 delete GetCommonValue(i
);
657 // -----------------------------------------------------------------------
659 bool wxPropertyGrid::Destroy()
661 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
662 m_canvas
->ReleaseMouse();
664 return wxScrolledWindow::Destroy();
667 // -----------------------------------------------------------------------
669 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
671 return new wxPropertyGridPageState();
674 // -----------------------------------------------------------------------
675 // wxPropertyGrid overridden wxWindow methods
676 // -----------------------------------------------------------------------
678 void wxPropertyGrid::SetWindowStyleFlag( long style
)
680 long old_style
= m_windowStyle
;
682 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
684 wxASSERT( m_pState
);
686 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
689 EnableCategories( true );
691 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
693 // Disable categories
694 EnableCategories( false );
696 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
702 PrepareAfterItemsAdded();
704 m_pState
->m_itemsAdded
= 1;
706 #if wxPG_SUPPORT_TOOLTIPS
707 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
713 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
714 SetToolTip ( tooltip );
715 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
718 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
723 m_canvas
->SetToolTip( NULL
);
728 wxScrolledWindow::SetWindowStyleFlag ( style
);
730 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
732 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
734 CalculateFontAndBitmapStuff( m_vspacing
);
740 // -----------------------------------------------------------------------
742 void wxPropertyGrid::Freeze()
746 wxScrolledWindow::Freeze();
751 // -----------------------------------------------------------------------
753 void wxPropertyGrid::Thaw()
759 wxScrolledWindow::Thaw();
760 RecalculateVirtualSize();
761 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
765 // Force property re-selection
767 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
771 // -----------------------------------------------------------------------
773 void wxPropertyGrid::SetExtraStyle( long exStyle
)
775 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
777 #if defined(__WXMSW__)
780 // Don't use WS_EX_COMPOSITED just now.
783 if ( m_iFlags & wxPG_FL_IN_MANAGER )
784 hWnd = (HWND)GetParent()->GetHWND();
786 hWnd = (HWND)GetHWND();
788 ::SetWindowLong( hWnd, GWL_EXSTYLE,
789 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
792 //#elif defined(__WXGTK20__)
794 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
795 // truly was double-buffered.
796 if ( !this->IsDoubleBuffered() )
798 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
802 #if wxPG_DOUBLE_BUFFER
803 delete m_doubleBuffer
;
804 m_doubleBuffer
= NULL
;
809 wxScrolledWindow::SetExtraStyle( exStyle
);
811 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
812 m_pState
->InitNonCatMode();
814 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
815 m_windowStyle
|= wxPG_TOOLTIPS
;
818 wxPGGlobalVars
->m_extraStyle
= exStyle
;
821 // -----------------------------------------------------------------------
823 // returns the best acceptable minimal size
824 wxSize
wxPropertyGrid::DoGetBestSize() const
826 int lineHeight
= wxMax(15, m_lineHeight
);
828 // don't make the grid too tall (limit height to 10 items) but don't
829 // make it too small neither
832 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
836 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
841 // -----------------------------------------------------------------------
842 // wxPropertyGrid Font and Colour Methods
843 // -----------------------------------------------------------------------
845 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
849 m_captionFont
= wxScrolledWindow::GetFont();
851 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
852 m_subgroup_extramargin
= x
+ (x
/2);
855 #if wxPG_USE_RENDERER_NATIVE
856 m_iconWidth
= wxPG_ICON_WIDTH
;
857 #elif wxPG_ICON_WIDTH
859 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
860 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
861 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
865 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
866 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
867 m_gutterWidth
= wxPG_GUTTER_MIN
;
870 if ( vspacing
<= 1 ) vdiv
= 12;
871 else if ( vspacing
>= 3 ) vdiv
= 3;
873 m_spacingy
= m_fontHeight
/ vdiv
;
874 if ( m_spacingy
< wxPG_YSPACING_MIN
)
875 m_spacingy
= wxPG_YSPACING_MIN
;
878 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
879 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
881 m_captionFont
.SetWeight(wxBOLD
);
882 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
884 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
887 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
888 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
891 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
893 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
894 RecalculateVirtualSize();
896 InvalidateBestSize();
899 // -----------------------------------------------------------------------
901 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
907 // -----------------------------------------------------------------------
909 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
910 int ga
= 1000, int ba
= 1000,
911 bool forceDifferent
= false)
918 // Recursion guard (allow 2 max)
919 static int isinside
= 0;
921 wxCHECK_MSG( isinside
< 3,
923 wxT("wxPGAdjustColour should not be recursively called more than once") );
931 if ( r2
>255 ) r2
= 255;
932 else if ( r2
<0) r2
= 0;
934 if ( g2
>255 ) g2
= 255;
935 else if ( g2
<0) g2
= 0;
937 if ( b2
>255 ) b2
= 255;
938 else if ( b2
<0) b2
= 0;
940 // Make sure they are somewhat different
941 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
942 dst
= wxPGAdjustColour(src
,-(ra
*2));
944 dst
= wxColour(r2
,g2
,b2
);
946 // Recursion guard (allow 2 max)
953 static int wxPGGetColAvg( const wxColour
& col
)
955 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
959 void wxPropertyGrid::RegainColours()
961 if ( !(m_coloursCustomized
& 0x0002) )
963 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
965 // Make sure colour is dark enough
967 int colDec
= wxPGGetColAvg(col
) - 230;
969 int colDec
= wxPGGetColAvg(col
) - 200;
972 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
975 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
978 if ( !(m_coloursCustomized
& 0x0001) )
979 m_colMargin
= m_colCapBack
;
981 if ( !(m_coloursCustomized
& 0x0004) )
988 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
989 m_colCapFore
= capForeCol
;
990 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
993 if ( !(m_coloursCustomized
& 0x0008) )
995 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
996 m_colPropBack
= bgCol
;
997 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1000 if ( !(m_coloursCustomized
& 0x0010) )
1002 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1003 m_colPropFore
= fgCol
;
1004 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1007 if ( !(m_coloursCustomized
& 0x0020) )
1008 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1010 if ( !(m_coloursCustomized
& 0x0040) )
1011 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1013 if ( !(m_coloursCustomized
& 0x0080) )
1014 m_colLine
= m_colCapBack
;
1016 if ( !(m_coloursCustomized
& 0x0100) )
1017 m_colDisPropFore
= m_colCapFore
;
1019 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1022 // -----------------------------------------------------------------------
1024 void wxPropertyGrid::ResetColours()
1026 m_coloursCustomized
= 0;
1033 // -----------------------------------------------------------------------
1035 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1037 // Must disable active editor.
1038 ClearSelection(false);
1040 bool res
= wxScrolledWindow::SetFont( font
);
1041 if ( res
&& GetParent()) // may not have been Create()ed yet
1043 CalculateFontAndBitmapStuff( m_vspacing
);
1050 // -----------------------------------------------------------------------
1052 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1055 m_coloursCustomized
|= 0x80;
1059 // -----------------------------------------------------------------------
1061 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1064 m_coloursCustomized
|= 0x01;
1068 // -----------------------------------------------------------------------
1070 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1072 m_colPropBack
= col
;
1073 m_coloursCustomized
|= 0x08;
1075 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1080 // -----------------------------------------------------------------------
1082 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1084 m_colPropFore
= col
;
1085 m_coloursCustomized
|= 0x10;
1087 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1092 // -----------------------------------------------------------------------
1094 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1096 m_colEmptySpace
= col
;
1101 // -----------------------------------------------------------------------
1103 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1105 m_colDisPropFore
= col
;
1106 m_coloursCustomized
|= 0x100;
1110 // -----------------------------------------------------------------------
1112 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1115 m_coloursCustomized
|= 0x20;
1119 // -----------------------------------------------------------------------
1121 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1124 m_coloursCustomized
|= 0x40;
1128 // -----------------------------------------------------------------------
1130 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1133 m_coloursCustomized
|= 0x02;
1135 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1140 // -----------------------------------------------------------------------
1142 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1145 m_coloursCustomized
|= 0x04;
1147 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1152 // -----------------------------------------------------------------------
1153 // wxPropertyGrid property adding and removal
1154 // -----------------------------------------------------------------------
1156 void wxPropertyGrid::PrepareAfterItemsAdded()
1158 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1160 m_pState
->m_itemsAdded
= 0;
1162 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1163 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1165 RecalculateVirtualSize();
1168 // -----------------------------------------------------------------------
1169 // wxPropertyGrid property operations
1170 // -----------------------------------------------------------------------
1172 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1174 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1178 bool changed
= false;
1180 // Is it inside collapsed section?
1181 if ( !p
->IsVisible() )
1184 wxPGProperty
* parent
= p
->GetParent();
1185 wxPGProperty
* grandparent
= parent
->GetParent();
1187 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1188 Expand( grandparent
);
1196 GetViewStart(&vx
,&vy
);
1197 vy
*=wxPG_PIXELS_PER_UNIT
;
1203 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1204 m_iFlags
|= wxPG_FL_SCROLLED
;
1207 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1209 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1210 m_iFlags
|= wxPG_FL_SCROLLED
;
1220 // -----------------------------------------------------------------------
1221 // wxPropertyGrid helper methods called by properties
1222 // -----------------------------------------------------------------------
1224 // Control font changer helper.
1225 void wxPropertyGrid::SetCurControlBoldFont()
1227 wxASSERT( m_wndEditor
);
1228 m_wndEditor
->SetFont( m_captionFont
);
1231 // -----------------------------------------------------------------------
1233 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1236 #if wxPG_SMALL_SCREEN
1237 // On small-screen devices, always show dialogs with default position and size.
1238 return wxDefaultPosition
;
1240 int splitterX
= GetSplitterPosition();
1244 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1246 ImprovedClientToScreen( &x
, &y
);
1248 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1249 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1256 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1266 new_y
= y
+ m_lineHeight
;
1268 return wxPoint(new_x
,new_y
);
1272 // -----------------------------------------------------------------------
1274 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1276 if ( src_str
.length() == 0 )
1282 bool prev_is_slash
= false;
1284 wxString::const_iterator i
= src_str
.begin();
1288 for ( ; i
!= src_str
.end(); ++i
)
1292 if ( a
!= wxS('\\') )
1294 if ( !prev_is_slash
)
1300 if ( a
== wxS('n') )
1303 dst_str
<< wxS('\n');
1305 dst_str
<< wxS('\n');
1308 else if ( a
== wxS('t') )
1309 dst_str
<< wxS('\t');
1313 prev_is_slash
= false;
1317 if ( prev_is_slash
)
1319 dst_str
<< wxS('\\');
1320 prev_is_slash
= false;
1324 prev_is_slash
= true;
1331 // -----------------------------------------------------------------------
1333 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1335 if ( src_str
.length() == 0 )
1341 wxString::const_iterator i
= src_str
.begin();
1342 wxUniChar prev_a
= wxS('\0');
1346 for ( ; i
!= src_str
.end(); ++i
)
1350 if ( a
>= wxS(' ') )
1352 // This surely is not something that requires an escape sequence.
1357 // This might need...
1358 if ( a
== wxS('\r') )
1360 // DOS style line end.
1361 // Already taken care below
1363 else if ( a
== wxS('\n') )
1364 // UNIX style line end.
1365 dst_str
<< wxS("\\n");
1366 else if ( a
== wxS('\t') )
1368 dst_str
<< wxS('\t');
1371 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1381 // -----------------------------------------------------------------------
1383 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1390 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1393 // -----------------------------------------------------------------------
1394 // wxPropertyGrid graphics related methods
1395 // -----------------------------------------------------------------------
1397 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1401 // Update everything inside the box
1402 wxRect r
= GetUpdateRegion().GetBox();
1404 dc
.SetPen(m_colEmptySpace
);
1405 dc
.SetBrush(m_colEmptySpace
);
1406 dc
.DrawRectangle(r
);
1409 // -----------------------------------------------------------------------
1411 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1412 wxPGProperty
* property
) const
1414 // Prepare rectangle to be used
1416 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1417 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1419 #if (wxPG_USE_RENDERER_NATIVE)
1421 #elif wxPG_ICON_WIDTH
1422 // Drawing expand/collapse button manually
1423 dc
.SetPen(m_colPropFore
);
1424 if ( property
->IsCategory() )
1425 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1427 dc
.SetBrush(m_colPropBack
);
1429 dc
.DrawRectangle( r
);
1430 int _y
= r
.y
+(m_iconWidth
/2);
1431 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1436 if ( property
->IsExpanded() )
1438 // wxRenderer functions are non-mutating in nature, so it
1439 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1440 // Hopefully this does not cause problems.
1441 #if (wxPG_USE_RENDERER_NATIVE)
1442 wxRendererNative::Get().DrawTreeItemButton(
1448 #elif wxPG_ICON_WIDTH
1457 #if (wxPG_USE_RENDERER_NATIVE)
1458 wxRendererNative::Get().DrawTreeItemButton(
1464 #elif wxPG_ICON_WIDTH
1465 int _x
= r
.x
+(m_iconWidth
/2);
1466 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1472 #if (wxPG_USE_RENDERER_NATIVE)
1474 #elif wxPG_ICON_WIDTH
1477 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1481 // -----------------------------------------------------------------------
1484 // This is the one called by OnPaint event handler and others.
1485 // topy and bottomy are already unscrolled (ie. physical)
1487 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1489 unsigned int bottomy
,
1490 const wxRect
* clipRect
)
1492 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1494 m_pState
->EnsureVirtualHeight();
1496 wxRect tempClipRect
;
1499 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1500 clipRect
= &tempClipRect
;
1503 // items added check
1504 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1506 int paintFinishY
= 0;
1508 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1511 bool isBuffered
= false;
1513 #if wxPG_DOUBLE_BUFFER
1514 wxMemoryDC
* bufferDC
= NULL
;
1516 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1518 if ( !m_doubleBuffer
)
1520 paintFinishY
= clipRect
->y
;
1525 bufferDC
= new wxMemoryDC();
1527 // If nothing was changed, then just copy from double-buffer
1528 bufferDC
->SelectObject( *m_doubleBuffer
);
1538 dc
.SetClippingRegion( *clipRect
);
1539 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1542 #if wxPG_DOUBLE_BUFFER
1545 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1546 bufferDC
, 0, 0, wxCOPY
);
1547 dc
.DestroyClippingRegion(); // Is this really necessary?
1553 // Clear area beyond bottomY?
1554 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1556 dc
.SetPen(m_colEmptySpace
);
1557 dc
.SetBrush(m_colEmptySpace
);
1558 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1562 // -----------------------------------------------------------------------
1564 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1565 const wxRect
* clipRect
,
1566 bool isBuffered
) const
1568 const wxPGProperty
* firstItem
;
1569 const wxPGProperty
* lastItem
;
1571 firstItem
= DoGetItemAtY(clipRect
->y
);
1572 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1575 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1577 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1580 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1581 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1583 int lh
= m_lineHeight
;
1586 int lastItemBottomY
;
1588 firstItemTopY
= clipRect
->y
;
1589 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1591 // Align y coordinates to item boundaries
1592 firstItemTopY
-= firstItemTopY
% lh
;
1593 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1594 lastItemBottomY
-= 1;
1596 // Entire range outside scrolled, visible area?
1597 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1600 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1604 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1605 firstItem->GetLabel().c_str(),
1606 lastItem->GetLabel().c_str(),
1607 (int)(lastItemBottomY - firstItemTopY),
1609 (unsigned long)clipRect );
1614 long windowStyle
= m_windowStyle
;
1620 // With wxPG_DOUBLE_BUFFER, do double buffering
1621 // - buffer's y = 0, so align cliprect and coordinates to that
1623 #if wxPG_DOUBLE_BUFFER
1629 xRelMod
= clipRect
->x
;
1630 yRelMod
= clipRect
->y
;
1633 // clipRect conversion
1638 firstItemTopY
-= yRelMod
;
1639 lastItemBottomY
-= yRelMod
;
1642 wxUnusedVar(isBuffered
);
1645 int x
= m_marginWidth
- xRelMod
;
1647 wxFont normalFont
= GetFont();
1649 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1651 bool isEnabled
= IsEnabled();
1654 // Prepare some pens and brushes that are often changed to.
1657 wxBrush
marginBrush(m_colMargin
);
1658 wxPen
marginPen(m_colMargin
);
1659 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1660 wxPen
linepen(m_colLine
,1,wxSOLID
);
1662 // pen that has same colour as text
1663 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1666 // Clear margin with background colour
1668 dc
.SetBrush( marginBrush
);
1669 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1671 dc
.SetPen( *wxTRANSPARENT_PEN
);
1672 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1675 const wxPGProperty
* selected
= m_selected
;
1676 const wxPropertyGridPageState
* state
= m_pState
;
1678 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1679 bool wasSelectedPainted
= false;
1682 // TODO: Only render columns that are within clipping region.
1684 dc
.SetFont(normalFont
);
1686 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1687 int endScanBottomY
= lastItemBottomY
+ lh
;
1688 int y
= firstItemTopY
;
1691 // Pregenerate list of visible properties.
1692 wxArrayPGProperty visPropArray
;
1693 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1695 for ( ; !it
.AtEnd(); it
.Next() )
1697 const wxPGProperty
* p
= *it
;
1699 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1701 visPropArray
.push_back((wxPGProperty
*)p
);
1703 if ( y
> endScanBottomY
)
1710 visPropArray
.push_back(NULL
);
1712 wxPGProperty
* nextP
= visPropArray
[0];
1714 int gridWidth
= state
->m_width
;
1717 for ( unsigned int arrInd
=1;
1718 nextP
&& y
<= lastItemBottomY
;
1721 wxPGProperty
* p
= nextP
;
1722 nextP
= visPropArray
[arrInd
];
1724 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1725 int textMarginHere
= x
;
1726 int renderFlags
= 0;
1728 int greyDepth
= m_marginWidth
;
1729 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1730 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1732 int greyDepthX
= greyDepth
- xRelMod
;
1734 // Use basic depth if in non-categoric mode and parent is base array.
1735 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1737 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1740 // Paint margin area
1741 dc
.SetBrush(marginBrush
);
1742 dc
.SetPen(marginPen
);
1743 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1745 dc
.SetPen( linepen
);
1750 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1756 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1758 sx
+= state
->m_colWidths
[si
];
1759 dc
.DrawLine( sx
, y
, sx
, y2
);
1762 // Horizontal Line, below
1763 // (not if both this and next is category caption)
1764 if ( p
->IsCategory() &&
1765 nextP
&& nextP
->IsCategory() )
1766 dc
.SetPen(m_colCapBack
);
1768 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1771 // Need to override row colours?
1775 if ( p
!= selected
)
1777 // Disabled may get different colour.
1778 if ( !p
->IsEnabled() )
1780 renderFlags
|= wxPGCellRenderer::Disabled
|
1781 wxPGCellRenderer::DontUseCellFgCol
;
1782 rowFgCol
= m_colDisPropFore
;
1787 renderFlags
|= wxPGCellRenderer::Selected
;
1789 if ( !p
->IsCategory() )
1791 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1792 wxPGCellRenderer::DontUseCellBgCol
;
1794 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1795 wasSelectedPainted
= true;
1798 // Selected gets different colour.
1799 if ( reallyFocused
)
1801 rowFgCol
= m_colSelFore
;
1802 rowBgCol
= m_colSelBack
;
1804 else if ( isEnabled
)
1806 rowFgCol
= m_colPropFore
;
1807 rowBgCol
= m_colMargin
;
1811 rowFgCol
= m_colDisPropFore
;
1812 rowBgCol
= m_colSelBack
;
1819 if ( rowBgCol
.IsOk() )
1820 rowBgBrush
= wxBrush(rowBgCol
);
1822 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1823 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1826 // Fill additional margin area with background colour of first cell
1827 if ( greyDepthX
< textMarginHere
)
1829 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1831 wxPGCell
& cell
= p
->GetCell(0);
1832 rowBgCol
= cell
.GetBgCol();
1833 rowBgBrush
= wxBrush(rowBgCol
);
1835 dc
.SetBrush(rowBgBrush
);
1836 dc
.SetPen(rowBgCol
);
1837 dc
.DrawRectangle(greyDepthX
+1, y
,
1838 textMarginHere
-greyDepthX
, lh
-1);
1841 bool fontChanged
= false;
1843 // Expander button rectangle
1844 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1849 if ( p
->IsCategory() )
1851 // Captions have their cell areas merged as one
1852 dc
.SetFont(m_captionFont
);
1854 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1856 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1858 dc
.SetBrush(rowBgBrush
);
1859 dc
.SetPen(rowBgCol
);
1862 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1864 dc
.SetTextForeground(rowFgCol
);
1867 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1868 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1871 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1872 DrawExpanderButton( dc
, butRect
, p
);
1876 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1878 dc
.SetFont(m_captionFont
);
1884 int nextCellWidth
= state
->m_colWidths
[0] -
1885 (greyDepthX
- m_marginWidth
);
1886 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1887 int textXAdd
= textMarginHere
- greyDepthX
;
1889 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1891 cellRect
.width
= nextCellWidth
- 1;
1893 bool ctrlCell
= false;
1894 int cellRenderFlags
= renderFlags
;
1897 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1898 DrawExpanderButton( dc
, butRect
, p
);
1901 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1903 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1904 dc
.SetBrush(editorBgCol
);
1905 dc
.SetPen(editorBgCol
);
1906 dc
.SetTextForeground(m_colPropFore
);
1907 dc
.DrawRectangle(cellRect
);
1909 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1914 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1916 dc
.SetBrush(rowBgBrush
);
1917 dc
.SetPen(rowBgCol
);
1920 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1922 dc
.SetTextForeground(rowFgCol
);
1926 dc
.SetClippingRegion(cellRect
);
1928 cellRect
.x
+= textXAdd
;
1929 cellRect
.width
-= textXAdd
;
1934 wxPGCellRenderer
* renderer
;
1935 int cmnVal
= p
->GetCommonValue();
1936 if ( cmnVal
== -1 || ci
!= 1 )
1938 renderer
= p
->GetCellRenderer(ci
);
1939 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1944 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1945 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1950 cellX
+= state
->m_colWidths
[ci
];
1951 if ( ci
< (state
->m_colWidths
.size()-1) )
1952 nextCellWidth
= state
->m_colWidths
[ci
+1];
1954 dc
.DestroyClippingRegion(); // Is this really necessary?
1960 dc
.SetFont(normalFont
);
1965 // Refresh editor controls (seems not needed on msw)
1966 // NOTE: This code is mandatory for GTK!
1967 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1968 if ( wasSelectedPainted
)
1971 m_wndEditor
->Refresh();
1973 m_wndEditor2
->Refresh();
1980 // -----------------------------------------------------------------------
1982 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1986 if ( m_width
< 10 || m_height
< 10 ||
1987 !m_pState
->m_properties
->GetChildCount() ||
1989 return wxRect(0,0,0,0);
1994 // Return rect which encloses the given property range
1996 int visTop
= p1
->GetY();
1999 visBottom
= p2
->GetY() + m_lineHeight
;
2001 visBottom
= m_height
+ visTop
;
2003 // If seleced property is inside the range, we'll extend the range to include
2005 wxPGProperty
* selected
= m_selected
;
2008 int selectedY
= selected
->GetY();
2009 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2011 wxWindow
* editor
= GetEditorControl();
2014 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2015 if ( visBottom2
> visBottom
)
2016 visBottom
= visBottom2
;
2021 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2024 // -----------------------------------------------------------------------
2026 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2031 if ( m_pState
->m_itemsAdded
)
2032 PrepareAfterItemsAdded();
2034 wxRect r
= GetPropertyRect(p1
, p2
);
2037 m_canvas
->RefreshRect(r
);
2041 // -----------------------------------------------------------------------
2043 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2045 if ( p
== m_selected
)
2046 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2048 DrawItemAndChildren(p
);
2051 // -----------------------------------------------------------------------
2053 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2058 // Draw item, children, and parent too, if it is not category
2059 wxPGProperty
* parent
= p
->GetParent();
2062 !parent
->IsCategory() &&
2063 parent
->GetParent() )
2066 parent
= parent
->GetParent();
2069 DrawItemAndChildren(p
);
2072 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2074 wxCHECK_RET( p
, wxT("invalid property id") );
2076 // Do not draw if in non-visible page
2077 if ( p
->GetParentState() != m_pState
)
2080 // do not draw a single item if multiple pending
2081 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2084 // Update child control.
2085 if ( m_selected
&& m_selected
->GetParent() == p
)
2088 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2090 DrawItems(p
, lastDrawn
);
2093 // -----------------------------------------------------------------------
2095 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2096 const wxRect
*rect
)
2098 PrepareAfterItemsAdded();
2100 wxWindow::Refresh(false);
2102 // TODO: Coordinate translation
2103 m_canvas
->Refresh(false, rect
);
2105 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2106 // I think this really helps only GTK+1.2
2107 if ( m_wndEditor
) m_wndEditor
->Refresh();
2108 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2112 // -----------------------------------------------------------------------
2113 // wxPropertyGrid global operations
2114 // -----------------------------------------------------------------------
2116 void wxPropertyGrid::Clear()
2118 m_pState
->DoClear();
2124 RecalculateVirtualSize();
2126 // Need to clear some area at the end
2128 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2131 // -----------------------------------------------------------------------
2133 bool wxPropertyGrid::EnableCategories( bool enable
)
2135 ClearSelection(false);
2140 // Enable categories
2143 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2148 // Disable categories
2150 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2153 if ( !m_pState
->EnableCategories(enable
) )
2158 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2160 m_pState
->m_itemsAdded
= 1; // force
2161 PrepareAfterItemsAdded();
2165 m_pState
->m_itemsAdded
= 1;
2167 // No need for RecalculateVirtualSize() here - it is already called in
2168 // wxPropertyGridPageState method above.
2175 // -----------------------------------------------------------------------
2177 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2179 wxASSERT( pNewState
);
2180 wxASSERT( pNewState
->GetGrid() );
2182 if ( pNewState
== m_pState
)
2185 wxPGProperty
* oldSelection
= m_selected
;
2187 ClearSelection(false);
2189 m_pState
->m_selected
= oldSelection
;
2191 bool orig_mode
= m_pState
->IsInNonCatMode();
2192 bool new_state_mode
= pNewState
->IsInNonCatMode();
2194 m_pState
= pNewState
;
2197 int pgWidth
= GetClientSize().x
;
2198 if ( HasVirtualWidth() )
2200 int minWidth
= pgWidth
;
2201 if ( pNewState
->m_width
< minWidth
)
2203 pNewState
->m_width
= minWidth
;
2204 pNewState
->CheckColumnWidths();
2210 // Just in case, fully re-center splitter
2211 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2212 pNewState
->m_fSplitterX
= -1.0;
2214 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2219 // If necessary, convert state to correct mode.
2220 if ( orig_mode
!= new_state_mode
)
2222 // This should refresh as well.
2223 EnableCategories( orig_mode
?false:true );
2225 else if ( !m_frozen
)
2227 // Refresh, if not frozen.
2228 m_pState
->PrepareAfterItemsAdded();
2231 if ( m_pState
->m_selected
)
2232 DoSelectProperty( m_pState
->m_selected
);
2234 RecalculateVirtualSize(0);
2238 m_pState
->m_itemsAdded
= 1;
2241 // -----------------------------------------------------------------------
2243 // Call to SetSplitterPosition will always disable splitter auto-centering
2244 // if parent window is shown.
2245 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2247 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2250 wxPropertyGridPageState
* state
= m_pState
;
2252 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2257 CorrectEditorWidgetSizeX();
2263 // -----------------------------------------------------------------------
2265 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2267 SetSplitterPosition( m_width
/2, true );
2268 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2269 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2272 // -----------------------------------------------------------------------
2273 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2274 // -----------------------------------------------------------------------
2276 // Returns nearest paint visible property (such that will be painted unless
2277 // window is scrolled or resized). If given property is paint visible, then
2278 // it itself will be returned
2279 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2281 int vx
,vy1
;// Top left corner of client
2282 GetViewStart(&vx
,&vy1
);
2283 vy1
*= wxPG_PIXELS_PER_UNIT
;
2285 int vy2
= vy1
+ m_height
;
2286 int propY
= p
->GetY2(m_lineHeight
);
2288 if ( (propY
+ m_lineHeight
) < vy1
)
2291 return DoGetItemAtY( vy1
);
2293 else if ( propY
> vy2
)
2296 return DoGetItemAtY( vy2
);
2299 // Itself paint visible
2304 // -----------------------------------------------------------------------
2305 // Methods related to change in value, value modification and sending events
2306 // -----------------------------------------------------------------------
2308 // commits any changes in editor of selected property
2309 // return true if validation did not fail
2310 // flags are same as with DoSelectProperty
2311 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2313 // Committing already?
2314 if ( m_inCommitChangesFromEditor
)
2317 // Don't do this if already processing editor event. It might
2318 // induce recursive dialogs and crap like that.
2319 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2321 if ( m_inDoPropertyChanged
)
2328 IsEditorsValueModified() &&
2329 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2332 m_inCommitChangesFromEditor
= 1;
2334 wxVariant
variant(m_selected
->GetValueRef());
2335 bool valueIsPending
= false;
2337 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2338 // due to another window getting focus
2339 wxWindow
* oldFocus
= m_curFocused
;
2341 bool validationFailure
= false;
2342 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2344 m_chgInfo_changedProperty
= NULL
;
2346 // If truly modified, schedule value as pending.
2347 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2349 if ( DoEditorValidate() &&
2350 PerformValidation(m_selected
, variant
) )
2352 valueIsPending
= true;
2356 validationFailure
= true;
2361 EditorsValueWasNotModified();
2366 m_inCommitChangesFromEditor
= 0;
2368 if ( validationFailure
&& !forceSuccess
)
2372 oldFocus
->SetFocus();
2373 m_curFocused
= oldFocus
;
2376 res
= OnValidationFailure(m_selected
, variant
);
2378 // Now prevent further validation failure messages
2381 EditorsValueWasNotModified();
2382 OnValidationFailureReset(m_selected
);
2385 else if ( valueIsPending
)
2387 DoPropertyChanged( m_selected
, flags
);
2388 EditorsValueWasNotModified();
2397 // -----------------------------------------------------------------------
2399 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2403 // Runs all validation functionality.
2404 // Returns true if value passes all tests.
2407 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2409 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2411 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2416 // Adapt list to child values, if necessary
2417 wxVariant listValue
= pendingValue
;
2418 wxVariant
* pPendingValue
= &pendingValue
;
2419 wxVariant
* pList
= NULL
;
2421 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2422 // string value, then we need treat as it was changed instead
2423 // (or, in addition, as is the case with composite string parent).
2424 // This includes creating list variant for child values.
2426 wxPGProperty
* pwc
= p
->GetParent();
2427 wxPGProperty
* changedProperty
= p
;
2428 wxPGProperty
* baseChangedProperty
= changedProperty
;
2429 wxVariant bcpPendingList
;
2431 listValue
= pendingValue
;
2432 listValue
.SetName(p
->GetBaseName());
2435 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2437 wxVariantList tempList
;
2438 wxVariant
lv(tempList
, pwc
->GetBaseName());
2439 lv
.Append(listValue
);
2441 pPendingValue
= &listValue
;
2443 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2445 baseChangedProperty
= pwc
;
2446 bcpPendingList
= lv
;
2449 changedProperty
= pwc
;
2450 pwc
= pwc
->GetParent();
2454 wxPGProperty
* evtChangingProperty
= changedProperty
;
2456 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2458 value
= *pPendingValue
;
2462 // Convert list to child values
2463 pList
= pPendingValue
;
2464 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2467 wxVariant evtChangingValue
= value
;
2469 if ( flags
& SendEvtChanging
)
2471 // FIXME: After proper ValueToString()s added, remove
2472 // this. It is just a temporary fix, as evt_changing
2473 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2474 // (unless it is selected, and textctrl editor is open).
2475 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2477 evtChangingProperty
= baseChangedProperty
;
2478 if ( evtChangingProperty
!= p
)
2480 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2484 evtChangingValue
= pendingValue
;
2488 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2490 if ( changedProperty
== m_selected
)
2492 wxWindow
* editor
= GetEditorControl();
2493 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2494 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2498 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2503 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2504 m_chgInfo_changedProperty
= changedProperty
;
2505 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2506 m_chgInfo_pendingValue
= value
;
2509 m_chgInfo_valueList
= *pList
;
2511 m_chgInfo_valueList
.MakeNull();
2513 // If changedProperty is not property which value was edited,
2514 // then call wxPGProperty::ValidateValue() for that as well.
2515 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2517 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2521 if ( flags
& SendEvtChanging
)
2523 // SendEvent returns true if event was vetoed
2524 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2528 if ( flags
& IsStandaloneValidation
)
2530 // If called in 'generic' context, we need to reset
2531 // m_chgInfo_changedProperty and write back translated value.
2532 m_chgInfo_changedProperty
= NULL
;
2533 pendingValue
= value
;
2539 // -----------------------------------------------------------------------
2541 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2543 if ( !msg
.length() )
2547 if ( !wxPGGlobalVars
->m_offline
)
2549 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2552 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2555 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2558 pStatusBar
->SetStatusText(msg
);
2566 ::wxMessageBox(msg
, _T("Property Error"));
2569 // -----------------------------------------------------------------------
2571 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2572 wxVariant
& invalidValue
)
2574 wxWindow
* editor
= GetEditorControl();
2576 // First call property's handler
2577 property
->OnValidationFailure(invalidValue
);
2579 bool res
= DoOnValidationFailure(property
, invalidValue
);
2582 // For non-wxTextCtrl editors, we do need to revert the value
2583 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2584 property
== m_selected
)
2586 property
->GetEditorClass()->UpdateControl(property
, editor
);
2589 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2594 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2596 int vfb
= m_validationInfo
.m_failureBehavior
;
2598 if ( vfb
& wxPG_VFB_BEEP
)
2601 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2602 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2604 unsigned int colCount
= m_pState
->GetColumnCount();
2606 // We need backup marked property's cells
2607 m_propCellsBackup
= property
->m_cells
;
2609 wxColour vfbFg
= *wxWHITE
;
2610 wxColour vfbBg
= *wxRED
;
2612 property
->EnsureCells(colCount
);
2614 for ( unsigned int i
=0; i
<colCount
; i
++ )
2616 wxPGCell
& cell
= property
->m_cells
[i
];
2617 cell
.SetFgCol(vfbFg
);
2618 cell
.SetBgCol(vfbBg
);
2621 DrawItemAndChildren(property
);
2623 if ( property
== m_selected
)
2625 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2627 wxWindow
* editor
= GetEditorControl();
2630 editor
->SetForegroundColour(vfbFg
);
2631 editor
->SetBackgroundColour(vfbBg
);
2636 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2638 wxString msg
= m_validationInfo
.m_failureMessage
;
2640 if ( !msg
.length() )
2641 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2643 DoShowPropertyError(property
, msg
);
2646 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2649 // -----------------------------------------------------------------------
2651 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2653 int vfb
= m_validationInfo
.m_failureBehavior
;
2655 if ( vfb
& wxPG_VFB_MARK_CELL
)
2658 property
->m_cells
= m_propCellsBackup
;
2660 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2662 if ( property
== m_selected
&& GetEditorControl() )
2664 // Calling this will recreate the control, thus resetting its colour
2665 RefreshProperty(property
);
2669 DrawItemAndChildren(property
);
2674 // -----------------------------------------------------------------------
2676 // flags are same as with DoSelectProperty
2677 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2679 if ( m_inDoPropertyChanged
)
2682 wxWindow
* editor
= GetEditorControl();
2684 m_pState
->m_anyModified
= 1;
2686 m_inDoPropertyChanged
= 1;
2688 // Maybe need to update control
2689 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2691 // These values were calculated in PerformValidation()
2692 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2693 wxVariant value
= m_chgInfo_pendingValue
;
2695 wxPGProperty
* topPaintedProperty
= changedProperty
;
2697 while ( !topPaintedProperty
->IsCategory() &&
2698 !topPaintedProperty
->IsRoot() )
2700 topPaintedProperty
= topPaintedProperty
->GetParent();
2703 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2705 // Set as Modified (not if dragging just began)
2706 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2708 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2709 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2712 SetCurControlBoldFont();
2718 // Propagate updates to parent(s)
2720 wxPGProperty
* prevPwc
= NULL
;
2722 while ( prevPwc
!= topPaintedProperty
)
2724 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2726 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2729 SetCurControlBoldFont();
2733 pwc
= pwc
->GetParent();
2736 // Draw the actual property
2737 DrawItemAndChildren( topPaintedProperty
);
2740 // If value was set by wxPGProperty::OnEvent, then update the editor
2742 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2748 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2749 if ( m_wndEditor
) m_wndEditor
->Refresh();
2750 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2755 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2757 // If top parent has composite string value, then send to child parents,
2758 // starting from baseChangedProperty.
2759 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2761 pwc
= m_chgInfo_baseChangedProperty
;
2763 while ( pwc
!= changedProperty
)
2765 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2766 pwc
= pwc
->GetParent();
2770 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2772 m_inDoPropertyChanged
= 0;
2777 // -----------------------------------------------------------------------
2779 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2781 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2783 m_chgInfo_changedProperty
= NULL
;
2785 if ( PerformValidation(p
, newValue
) )
2787 DoPropertyChanged(p
);
2792 OnValidationFailure(p
, newValue
);
2798 // -----------------------------------------------------------------------
2800 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2802 wxPGProperty
* prop
= GetSelectedProperty();
2805 return wxNullVariant
;
2807 wxTextCtrl
* tc
= GetEditorTextCtrl();
2808 wxVariant value
= prop
->GetValue();
2810 if ( !tc
|| !IsEditorsValueModified() )
2813 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2816 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2817 return prop
->GetValue();
2822 // -----------------------------------------------------------------------
2824 // Runs wxValidator for the selected property
2825 bool wxPropertyGrid::DoEditorValidate()
2830 // -----------------------------------------------------------------------
2832 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2834 wxPGProperty
* selected
= m_selected
;
2836 // Somehow, event is handled after property has been deselected.
2837 // Possibly, but very rare.
2841 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2844 wxVariant
pendingValue(selected
->GetValueRef());
2845 wxWindow
* wnd
= GetEditorControl();
2846 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2848 bool wasUnspecified
= selected
->IsValueUnspecified();
2849 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2850 bool valueIsPending
= false;
2852 m_chgInfo_changedProperty
= NULL
;
2854 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2857 // Filter out excess wxTextCtrl modified events
2858 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2860 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2862 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2864 wxString newTcValue
= tc
->GetValue();
2865 if ( m_prevTcValue
== newTcValue
)
2868 m_prevTcValue
= newTcValue
;
2871 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2873 bool validationFailure
= false;
2874 bool buttonWasHandled
= false;
2877 // Try common button handling
2878 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2880 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2884 buttonWasHandled
= true;
2885 // Store as res2, as previously (and still currently alternatively)
2886 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2887 // in wxPGProperty::OnEvent().
2888 adapter
->ShowDialog( this, selected
);
2893 if ( !buttonWasHandled
)
2895 if ( wnd
|| m_wndEditor2
)
2897 // First call editor class' event handler.
2898 const wxPGEditor
* editor
= selected
->GetEditorClass();
2900 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2902 // If changes, validate them
2903 if ( DoEditorValidate() )
2905 if ( editor
->GetValueFromControl( pendingValue
,
2908 valueIsPending
= true;
2912 validationFailure
= true;
2917 // Then the property's custom handler (must be always called, unless
2918 // validation failed).
2919 if ( !validationFailure
)
2920 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2923 // SetValueInEvent(), as called in one of the functions referred above
2924 // overrides editor's value.
2925 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2927 valueIsPending
= true;
2928 pendingValue
= m_changeInEventValue
;
2929 selFlags
|= wxPG_SEL_DIALOGVAL
;
2932 if ( !validationFailure
&& valueIsPending
)
2933 if ( !PerformValidation(m_selected
, pendingValue
) )
2934 validationFailure
= true;
2936 if ( validationFailure
)
2938 OnValidationFailure(selected
, pendingValue
);
2940 else if ( valueIsPending
)
2942 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2944 DoPropertyChanged(selected
, selFlags
);
2945 EditorsValueWasNotModified();
2947 // Regardless of editor type, unfocus editor on
2948 // text-editing related enter press.
2949 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2956 // No value after all
2958 // Regardless of editor type, unfocus editor on
2959 // text-editing related enter press.
2960 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2965 // Let unhandled button click events go to the parent
2966 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2968 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2969 GetEventHandler()->AddPendingEvent(evt
);
2973 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2976 // -----------------------------------------------------------------------
2977 // wxPropertyGrid editor control helper methods
2978 // -----------------------------------------------------------------------
2980 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2982 int itemy
= p
->GetY2(m_lineHeight
);
2984 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2985 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2986 int imageOffset
= 0;
2988 // TODO: If custom image detection changes from current, change this.
2989 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
2991 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2992 int iw
= p
->OnMeasureImage().x
;
2994 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
2995 imageOffset
= p
->GetImageOffset(iw
);
3000 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3002 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3007 // -----------------------------------------------------------------------
3009 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3011 wxSize sz
= GetImageSize(p
, item
);
3012 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3013 wxPG_CUSTOM_IMAGE_SPACINGY
,
3018 // return size of custom paint image
3019 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3021 // If called with NULL property, then return default image
3022 // size for properties that use image.
3024 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3026 wxSize cis
= p
->OnMeasureImage(item
);
3028 int choiceCount
= p
->m_choices
.GetCount();
3029 int comVals
= p
->GetDisplayedCommonValueCount();
3030 if ( item
>= choiceCount
&& comVals
> 0 )
3032 unsigned int cvi
= item
-choiceCount
;
3033 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3035 else if ( item
>= 0 && choiceCount
== 0 )
3036 return wxSize(0, 0);
3041 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3046 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3053 // -----------------------------------------------------------------------
3055 // takes scrolling into account
3056 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3059 GetViewStart(&vx
,&vy
);
3060 vy
*=wxPG_PIXELS_PER_UNIT
;
3061 vx
*=wxPG_PIXELS_PER_UNIT
;
3064 ClientToScreen( px
, py
);
3067 // -----------------------------------------------------------------------
3069 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3072 GetViewStart(&pt2
.x
,&pt2
.y
);
3073 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3074 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3078 return m_pState
->HitTest(pt2
);
3081 // -----------------------------------------------------------------------
3083 // custom set cursor
3084 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3086 if ( type
== m_curcursor
&& !override
) return;
3088 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3090 if ( type
== wxCURSOR_SIZEWE
)
3091 cursor
= m_cursorSizeWE
;
3093 m_canvas
->SetCursor( *cursor
);
3098 // -----------------------------------------------------------------------
3099 // wxPropertyGrid property selection, editor creation
3100 // -----------------------------------------------------------------------
3103 // This class forwards events from property editor controls to wxPropertyGrid.
3104 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3107 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3108 : wxEvtHandler(), m_propGrid(propGrid
)
3112 virtual ~wxPropertyGridEditorEventForwarder()
3117 bool ProcessEvent( wxEvent
& event
)
3122 m_propGrid
->HandleCustomEditorEvent(event
);
3124 return wxEvtHandler::ProcessEvent(event
);
3127 wxPropertyGrid
* m_propGrid
;
3130 // Setups event handling for child control
3131 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3133 wxWindowID id
= argWnd
->GetId();
3135 if ( argWnd
== m_wndEditor
)
3137 argWnd
->Connect(id
, wxEVT_MOTION
,
3138 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3140 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3141 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3143 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3144 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3146 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3147 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3149 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3150 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3152 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3153 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3157 wxPropertyGridEditorEventForwarder
* forwarder
;
3158 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3159 argWnd
->PushEventHandler(forwarder
);
3161 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3162 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3166 void wxPropertyGrid::FreeEditors()
3169 // Return focus back to canvas from children (this is required at least for
3170 // GTK+, which, unlike Windows, clears focus when control is destroyed
3171 // instead of moving it to closest parent).
3172 wxWindow
* focus
= wxWindow::FindFocus();
3175 wxWindow
* parent
= focus
->GetParent();
3178 if ( parent
== m_canvas
)
3183 parent
= parent
->GetParent();
3187 // Do not free editors immediately if processing events
3190 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3191 m_wndEditor2
->Hide();
3192 wxPendingDelete
.Append( handler
);
3193 wxPendingDelete
.Append( m_wndEditor2
);
3194 m_wndEditor2
= NULL
;
3199 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3200 m_wndEditor
->Hide();
3201 wxPendingDelete
.Append( handler
);
3202 wxPendingDelete
.Append( m_wndEditor
);
3207 // Call with NULL to de-select property
3208 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3212 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3213 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3215 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3218 if ( m_inDoSelectProperty
)
3221 m_inDoSelectProperty
= 1;
3223 wxPGProperty
* prev
= m_selected
;
3227 m_inDoSelectProperty
= 0;
3233 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3235 wxPrintf( "None selected\n" );
3238 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3240 wxPrintf( "P = NULL\n" );
3243 // If we are frozen, then just set the values.
3246 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3247 m_editorFocused
= 0;
3250 m_pState
->m_selected
= p
;
3252 // If frozen, always free controls. But don't worry, as Thaw will
3253 // recall SelectProperty to recreate them.
3256 // Prevent any further selection measures in this call
3262 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3264 // Only set focus if not deselecting
3267 if ( flags
& wxPG_SEL_FOCUS
)
3271 m_wndEditor
->SetFocus();
3272 m_editorFocused
= 1;
3281 m_inDoSelectProperty
= 0;
3286 // First, deactivate previous
3290 OnValidationFailureReset(m_selected
);
3292 // Must double-check if this is an selected in case of forceswitch
3295 if ( !CommitChangesFromEditor(flags
) )
3297 // Validation has failed, so we can't exit the previous editor
3298 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3299 // _("Invalid Value"),wxOK|wxICON_ERROR);
3300 m_inDoSelectProperty
= 0;
3309 m_pState
->m_selected
= NULL
;
3311 // We need to always fully refresh the grid here
3314 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3315 EditorsValueWasNotModified();
3318 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3321 // Then, activate the one given.
3324 int propY
= p
->GetY2(m_lineHeight
);
3326 int splitterX
= GetSplitterPosition();
3327 m_editorFocused
= 0;
3329 m_pState
->m_selected
= p
;
3330 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3332 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3334 wxASSERT( m_wndEditor
== NULL
);
3337 // Only create editor for non-disabled non-caption
3338 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3340 // do this for non-caption items
3344 // Do we need to paint the custom image, if any?
3345 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3346 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3347 !p
->GetEditorClass()->CanContainCustomImage()
3349 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3351 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3352 wxPoint goodPos
= grect
.GetPosition();
3353 #if wxPG_CREATE_CONTROLS_HIDDEN
3354 int coord_adjust
= m_height
- goodPos
.y
;
3355 goodPos
.y
+= coord_adjust
;
3358 const wxPGEditor
* editor
= p
->GetEditorClass();
3359 wxCHECK_MSG(editor
, false,
3360 wxT("NULL editor class not allowed"));
3362 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3364 wxPGWindowList wndList
= editor
->CreateControls(this,
3369 m_wndEditor
= wndList
.m_primary
;
3370 m_wndEditor2
= wndList
.m_secondary
;
3371 wxWindow
* primaryCtrl
= GetEditorControl();
3374 // Essentially, primaryCtrl == m_wndEditor
3377 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3378 // value is drawn as normal, and m_wndEditor2 is assumed
3379 // to be a right-aligned button that triggers a separate editorCtrl
3384 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3385 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3387 // Set validator, if any
3388 #if wxUSE_VALIDATORS
3389 wxValidator
* validator
= p
->GetValidator();
3391 primaryCtrl
->SetValidator(*validator
);
3394 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3395 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3397 // If it has modified status, use bold font
3398 // (must be done before capturing m_ctrlXAdjust)
3399 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3400 SetCurControlBoldFont();
3403 // Fix TextCtrl indentation
3404 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3405 wxTextCtrl
* tc
= NULL
;
3406 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3407 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3409 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3411 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3414 // Store x relative to splitter (we'll need it).
3415 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3417 // Check if background clear is not necessary
3418 wxPoint pos
= m_wndEditor
->GetPosition();
3419 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3421 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3424 m_wndEditor
->SetSizeHints(3, 3);
3426 #if wxPG_CREATE_CONTROLS_HIDDEN
3427 m_wndEditor
->Show(false);
3428 m_wndEditor
->Freeze();
3430 goodPos
= m_wndEditor
->GetPosition();
3431 goodPos
.y
-= coord_adjust
;
3432 m_wndEditor
->Move( goodPos
);
3435 SetupChildEventHandling(primaryCtrl
);
3437 // Focus and select all (wxTextCtrl, wxComboBox etc)
3438 if ( flags
& wxPG_SEL_FOCUS
)
3440 primaryCtrl
->SetFocus();
3442 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3448 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3449 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3451 // Get proper id for wndSecondary
3452 m_wndSecId
= m_wndEditor2
->GetId();
3453 wxWindowList children
= m_wndEditor2
->GetChildren();
3454 wxWindowList::iterator node
= children
.begin();
3455 if ( node
!= children
.end() )
3456 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3458 m_wndEditor2
->SetSizeHints(3,3);
3460 #if wxPG_CREATE_CONTROLS_HIDDEN
3461 wxRect sec_rect
= m_wndEditor2
->GetRect();
3462 sec_rect
.y
-= coord_adjust
;
3464 // Fine tuning required to fix "oversized"
3465 // button disappearance bug.
3466 if ( sec_rect
.y
< 0 )
3468 sec_rect
.height
+= sec_rect
.y
;
3471 m_wndEditor2
->SetSize( sec_rect
);
3473 m_wndEditor2
->Show();
3475 SetupChildEventHandling(m_wndEditor2
);
3477 // If no primary editor, focus to button to allow
3478 // it to interprete ENTER etc.
3479 // NOTE: Due to problems focusing away from it, this
3480 // has been disabled.
3482 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3483 m_wndEditor2->SetFocus();
3487 if ( flags
& wxPG_SEL_FOCUS
)
3488 m_editorFocused
= 1;
3493 // Make sure focus is in grid canvas (important for wxGTK, at least)
3497 EditorsValueWasNotModified();
3499 // If it's inside collapsed section, expand parent, scroll, etc.
3500 // Also, if it was partially visible, scroll it into view.
3501 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3506 #if wxPG_CREATE_CONTROLS_HIDDEN
3507 m_wndEditor
->Thaw();
3509 m_wndEditor
->Show(true);
3516 // Make sure focus is in grid canvas
3520 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3526 // Show help text in status bar.
3527 // (if found and grid not embedded in manager with help box and
3528 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3531 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3533 wxStatusBar
* statusbar
= NULL
;
3534 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3536 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3538 statusbar
= frame
->GetStatusBar();
3543 const wxString
* pHelpString
= (const wxString
*) NULL
;
3547 pHelpString
= &p
->GetHelpString();
3548 if ( pHelpString
->length() )
3550 // Set help box text.
3551 statusbar
->SetStatusText( *pHelpString
);
3552 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3556 if ( (!pHelpString
|| !pHelpString
->length()) &&
3557 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3559 // Clear help box - but only if it was written
3560 // by us at previous time.
3561 statusbar
->SetStatusText( m_emptyString
);
3562 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3568 m_inDoSelectProperty
= 0;
3570 // call wx event handler (here so that it also occurs on deselection)
3571 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3576 // -----------------------------------------------------------------------
3578 bool wxPropertyGrid::UnfocusEditor()
3580 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3583 if ( !CommitChangesFromEditor(0) )
3587 DrawItem(m_selected
);
3592 // -----------------------------------------------------------------------
3594 void wxPropertyGrid::RefreshEditor()
3596 wxPGProperty
* p
= m_selected
;
3600 wxWindow
* wnd
= GetEditorControl();
3604 // Set editor font boldness - must do this before
3605 // calling UpdateControl().
3606 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3608 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3609 wnd
->SetFont(GetCaptionFont());
3611 wnd
->SetFont(GetFont());
3614 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3616 editorClass
->UpdateControl(p
, wnd
);
3618 if ( p
->IsValueUnspecified() )
3619 editorClass
->SetValueToUnspecified(p
, wnd
);
3622 // -----------------------------------------------------------------------
3624 // This method is not inline because it called dozens of times
3625 // (i.e. two-arg function calls create smaller code size).
3626 bool wxPropertyGrid::DoClearSelection()
3628 return DoSelectProperty(NULL
);
3631 // -----------------------------------------------------------------------
3632 // wxPropertyGrid expand/collapse state
3633 // -----------------------------------------------------------------------
3635 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3637 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3639 // If active editor was inside collapsed section, then disable it
3640 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3642 ClearSelection(false);
3645 // Store dont-center-splitter flag 'cause we need to temporarily set it
3646 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3647 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3649 bool res
= m_pState
->DoCollapse(pwc
);
3654 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3656 RecalculateVirtualSize();
3658 // Redraw etc. only if collapsed was visible.
3659 if (pwc
->IsVisible() &&
3661 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3663 // When item is collapsed so that scrollbar would move,
3664 // graphics mess is about (unless we redraw everything).
3669 // Clear dont-center-splitter flag if it wasn't set
3670 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3675 // -----------------------------------------------------------------------
3677 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3679 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3681 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3683 // Store dont-center-splitter flag 'cause we need to temporarily set it
3684 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3685 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3687 bool res
= m_pState
->DoExpand(pwc
);
3692 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3694 RecalculateVirtualSize();
3696 // Redraw etc. only if expanded was visible.
3697 if ( pwc
->IsVisible() && !m_frozen
&&
3698 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3702 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3705 DrawItems(pwc
, NULL
);
3710 // Clear dont-center-splitter flag if it wasn't set
3711 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3716 // -----------------------------------------------------------------------
3718 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3721 return m_pState
->DoHideProperty(p
, hide
, flags
);
3724 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3727 ClearSelection(false);
3730 m_pState
->DoHideProperty(p
, hide
, flags
);
3732 RecalculateVirtualSize();
3739 // -----------------------------------------------------------------------
3740 // wxPropertyGrid size related methods
3741 // -----------------------------------------------------------------------
3743 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3745 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3749 // If virtual height was changed, then recalculate editor control position(s)
3750 if ( m_pState
->m_vhCalcPending
)
3751 CorrectEditorWidgetPosY();
3753 m_pState
->EnsureVirtualHeight();
3755 wxASSERT_LEVEL_2_MSG(
3756 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3757 "VirtualHeight and ActualVirtualHeight should match"
3760 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3762 int x
= m_pState
->m_width
;
3763 int y
= m_pState
->m_virtualHeight
;
3766 GetClientSize(&width
,&height
);
3768 // Now adjust virtual size.
3769 SetVirtualSize(x
, y
);
3775 // Adjust scrollbars
3776 if ( HasVirtualWidth() )
3778 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3779 xPos
= GetScrollPos( wxHORIZONTAL
);
3782 if ( forceXPos
!= -1 )
3785 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3788 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3789 int yPos
= GetScrollPos( wxVERTICAL
);
3791 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3792 xAmount
, yAmount
, xPos
, yPos
, true );
3794 // Must re-get size now
3795 GetClientSize(&width
,&height
);
3797 if ( !HasVirtualWidth() )
3799 m_pState
->SetVirtualWidth(width
);
3806 m_canvas
->SetSize( x
, y
);
3808 m_pState
->CheckColumnWidths();
3811 CorrectEditorWidgetSizeX();
3813 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3816 // -----------------------------------------------------------------------
3818 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3820 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3824 GetClientSize(&width
,&height
);
3829 #if wxPG_DOUBLE_BUFFER
3830 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3832 int dblh
= (m_lineHeight
*2);
3833 if ( !m_doubleBuffer
)
3835 // Create double buffer bitmap to draw on, if none
3836 int w
= (width
>250)?width
:250;
3837 int h
= height
+ dblh
;
3839 m_doubleBuffer
= new wxBitmap( w
, h
);
3843 int w
= m_doubleBuffer
->GetWidth();
3844 int h
= m_doubleBuffer
->GetHeight();
3846 // Double buffer must be large enough
3847 if ( w
< width
|| h
< (height
+dblh
) )
3849 if ( w
< width
) w
= width
;
3850 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3851 delete m_doubleBuffer
;
3852 m_doubleBuffer
= new wxBitmap( w
, h
);
3859 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3860 m_ncWidth
= event
.GetSize().x
;
3864 if ( m_pState
->m_itemsAdded
)
3865 PrepareAfterItemsAdded();
3867 // Without this, virtual size (atleast under wxGTK) will be skewed
3868 RecalculateVirtualSize();
3874 // -----------------------------------------------------------------------
3876 void wxPropertyGrid::SetVirtualWidth( int width
)
3880 // Disable virtual width
3881 width
= GetClientSize().x
;
3882 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3886 // Enable virtual width
3887 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3889 m_pState
->SetVirtualWidth( width
);
3892 void wxPropertyGrid::SetFocusOnCanvas()
3894 m_canvas
->SetFocusIgnoringChildren();
3895 m_editorFocused
= 0;
3898 // -----------------------------------------------------------------------
3899 // wxPropertyGrid mouse event handling
3900 // -----------------------------------------------------------------------
3902 // selFlags uses same values DoSelectProperty's flags
3903 // Returns true if event was vetoed.
3904 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3906 // Send property grid event of specific type and with specific property
3907 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3908 evt
.SetPropertyGrid(this);
3909 evt
.SetEventObject(m_eventObject
);
3913 evt
.SetCanVeto(true);
3914 evt
.SetupValidationInfo();
3915 m_validationInfo
.m_pValue
= pValue
;
3917 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3919 evtHandler
->ProcessEvent(evt
);
3921 return evt
.WasVetoed();
3924 // -----------------------------------------------------------------------
3926 // Return false if should be skipped
3927 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3931 // Need to set focus?
3932 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3937 wxPropertyGridPageState
* state
= m_pState
;
3939 int splitterHitOffset
;
3940 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3942 wxPGProperty
* p
= DoGetItemAtY(y
);
3946 int depth
= (int)p
->GetDepth() - 1;
3948 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3950 if ( x
>= marginEnds
)
3954 if ( p
->IsCategory() )
3956 // This is category.
3957 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3959 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3961 // Expand, collapse, activate etc. if click on text or left of splitter.
3964 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3969 if ( !DoSelectProperty( p
) )
3972 // On double-click, expand/collapse.
3973 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3975 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3976 else DoExpand( p
, true );
3980 else if ( splitterHit
== -1 )
3983 unsigned int selFlag
= 0;
3984 if ( columnHit
== 1 )
3986 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3987 selFlag
= wxPG_SEL_FOCUS
;
3989 if ( !DoSelectProperty( p
, selFlag
) )
3992 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3994 if ( p
->GetChildCount() && !p
->IsCategory() )
3995 // On double-click, expand/collapse.
3996 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3998 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3999 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4000 else DoExpand( p
, true );
4007 // click on splitter
4008 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4010 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4012 // Double-clicking the splitter causes auto-centering
4013 CenterSplitter( true );
4015 else if ( m_dragStatus
== 0 )
4018 // Begin draggin the splitter
4022 // Changes must be committed here or the
4023 // value won't be drawn correctly
4024 if ( !CommitChangesFromEditor() )
4027 m_wndEditor
->Show ( false );
4030 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4032 m_canvas
->CaptureMouse();
4033 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4037 m_draggedSplitter
= splitterHit
;
4038 m_dragOffset
= splitterHitOffset
;
4040 wxClientDC
dc(m_canvas
);
4042 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4043 // Fixes button disappearance bug
4045 m_wndEditor2
->Show ( false );
4048 m_startingSplitterX
= x
- splitterHitOffset
;
4056 if ( p
->GetChildCount() )
4058 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4060 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4062 int y2
= y
% m_lineHeight
;
4063 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4065 // On click on expander button, expand/collapse
4066 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4067 DoCollapse( p
, true );
4069 DoExpand( p
, true );
4078 // -----------------------------------------------------------------------
4080 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4081 wxMouseEvent
& WXUNUSED(event
) )
4085 // Select property here as well
4086 wxPGProperty
* p
= m_propHover
;
4087 if ( p
!= m_selected
)
4088 DoSelectProperty( p
);
4090 // Send right click event.
4091 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4098 // -----------------------------------------------------------------------
4100 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4101 wxMouseEvent
& WXUNUSED(event
) )
4105 // Select property here as well
4106 wxPGProperty
* p
= m_propHover
;
4108 if ( p
!= m_selected
)
4109 DoSelectProperty( p
);
4111 // Send double-click event.
4112 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4119 // -----------------------------------------------------------------------
4121 #if wxPG_SUPPORT_TOOLTIPS
4123 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4125 if ( tipString
.length() )
4127 m_canvas
->SetToolTip(tipString
);
4131 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4132 m_canvas
->SetToolTip( m_emptyString
);
4134 m_canvas
->SetToolTip( NULL
);
4139 #endif // #if wxPG_SUPPORT_TOOLTIPS
4141 // -----------------------------------------------------------------------
4143 // Return false if should be skipped
4144 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4146 // Safety check (needed because mouse capturing may
4147 // otherwise freeze the control)
4148 if ( m_dragStatus
> 0 && !event
.Dragging() )
4150 HandleMouseUp(x
,y
,event
);
4153 wxPropertyGridPageState
* state
= m_pState
;
4155 int splitterHitOffset
;
4156 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4157 int splitterX
= x
- splitterHitOffset
;
4159 if ( m_dragStatus
> 0 )
4161 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4162 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4165 int newSplitterX
= x
- m_dragOffset
;
4166 int splitterX
= x
- splitterHitOffset
;
4168 // Splitter redraw required?
4169 if ( newSplitterX
!= splitterX
)
4172 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4173 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4174 state
->m_fSplitterX
= (float) newSplitterX
;
4177 CorrectEditorWidgetSizeX();
4191 int ih
= m_lineHeight
;
4194 #if wxPG_SUPPORT_TOOLTIPS
4195 wxPGProperty
* prevHover
= m_propHover
;
4196 unsigned char prevSide
= m_mouseSide
;
4198 int curPropHoverY
= y
- (y
% ih
);
4200 // On which item it hovers
4203 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4206 // Mouse moves on another property
4208 m_propHover
= DoGetItemAtY(y
);
4209 m_propHoverY
= curPropHoverY
;
4212 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4215 #if wxPG_SUPPORT_TOOLTIPS
4216 // Store which side we are on
4218 if ( columnHit
== 1 )
4220 else if ( columnHit
== 0 )
4224 // If tooltips are enabled, show label or value as a tip
4225 // in case it doesn't otherwise show in full length.
4227 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4229 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4231 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4233 if ( m_propHover
&& !m_propHover
->IsCategory() )
4236 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4238 // Show help string as a tooltip
4239 wxString tipString
= m_propHover
->GetHelpString();
4241 SetToolTip(tipString
);
4245 // Show cropped value string as a tooltip
4249 if ( m_mouseSide
== 1 )
4251 tipString
= m_propHover
->m_label
;
4252 space
= splitterX
-m_marginWidth
-3;
4254 else if ( m_mouseSide
== 2 )
4256 tipString
= m_propHover
->GetDisplayedString();
4258 space
= m_width
- splitterX
;
4259 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4260 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4266 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4269 SetToolTip( tipString
);
4276 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4277 m_canvas
->SetToolTip( m_emptyString
);
4279 m_canvas
->SetToolTip( NULL
);
4290 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4291 m_canvas
->SetToolTip( m_emptyString
);
4293 m_canvas
->SetToolTip( NULL
);
4301 if ( splitterHit
== -1 ||
4303 HasFlag(wxPG_STATIC_SPLITTER
) )
4305 // hovering on something else
4306 if ( m_curcursor
!= wxCURSOR_ARROW
)
4307 CustomSetCursor( wxCURSOR_ARROW
);
4311 // Do not allow splitter cursor on caption items.
4312 // (also not if we were dragging and its started
4313 // outside the splitter region)
4315 if ( !m_propHover
->IsCategory() &&
4319 // hovering on splitter
4321 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4322 // reliably detected.
4323 //if ( m_curcursor != wxCURSOR_SIZEWE )
4324 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4330 // hovering on something else
4331 if ( m_curcursor
!= wxCURSOR_ARROW
)
4332 CustomSetCursor( wxCURSOR_ARROW
);
4339 // -----------------------------------------------------------------------
4341 // Also handles Leaving event
4342 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4343 wxMouseEvent
&WXUNUSED(event
) )
4345 wxPropertyGridPageState
* state
= m_pState
;
4349 int splitterHitOffset
;
4350 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4352 // No event type check - basicly calling this method should
4353 // just stop dragging.
4354 // Left up after dragged?
4355 if ( m_dragStatus
>= 1 )
4358 // End Splitter Dragging
4360 // DO NOT ENABLE FOLLOWING LINE!
4361 // (it is only here as a reminder to not to do it)
4364 // Disable splitter auto-centering
4365 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4367 // This is necessary to return cursor
4368 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4370 m_canvas
->ReleaseMouse();
4371 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4374 // Set back the default cursor, if necessary
4375 if ( splitterHit
== -1 ||
4378 CustomSetCursor( wxCURSOR_ARROW
);
4383 // Control background needs to be cleared
4384 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4385 DrawItem( m_selected
);
4389 m_wndEditor
->Show ( true );
4392 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4393 // Fixes button disappearance bug
4395 m_wndEditor2
->Show ( true );
4398 // This clears the focus.
4399 m_editorFocused
= 0;
4405 // -----------------------------------------------------------------------
4407 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4409 int splitterX
= GetSplitterPosition();
4412 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4416 wxWindow
* wnd
= GetEditorControl();
4418 // Hide popup on clicks
4419 if ( event
.GetEventType() != wxEVT_MOTION
)
4420 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4422 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4428 if ( wnd
== NULL
|| m_dragStatus
||
4430 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4431 ux
>= (r
.x
+r
.width
) ||
4433 event
.m_y
>= (r
.y
+r
.height
)
4443 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4448 // -----------------------------------------------------------------------
4450 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4453 if ( OnMouseCommon( event
, &x
, &y
) )
4455 HandleMouseClick(x
,y
,event
);
4460 // -----------------------------------------------------------------------
4462 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4465 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4466 HandleMouseRightClick(x
,y
,event
);
4470 // -----------------------------------------------------------------------
4472 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4474 // Always run standard mouse-down handler as well
4475 OnMouseClick(event
);
4478 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4479 HandleMouseDoubleClick(x
,y
,event
);
4483 // -----------------------------------------------------------------------
4485 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4488 if ( OnMouseCommon( event
, &x
, &y
) )
4490 HandleMouseMove(x
,y
,event
);
4495 // -----------------------------------------------------------------------
4497 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4499 // Called when mouse moves in the empty space below the properties.
4500 CustomSetCursor( wxCURSOR_ARROW
);
4503 // -----------------------------------------------------------------------
4505 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4508 if ( OnMouseCommon( event
, &x
, &y
) )
4510 HandleMouseUp(x
,y
,event
);
4515 // -----------------------------------------------------------------------
4517 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4519 // This may get called from child control as well, so event's
4520 // mouse position cannot be relied on.
4522 if ( event
.Entering() )
4524 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4526 // TODO: Fix this (detect parent and only do
4527 // cursor trick if it is a manager).
4528 wxASSERT( GetParent() );
4529 GetParent()->SetCursor(wxNullCursor
);
4531 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4534 GetParent()->SetCursor(wxNullCursor
);
4536 else if ( event
.Leaving() )
4538 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4539 m_canvas
->SetCursor( wxNullCursor
);
4541 // Get real cursor position
4542 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4544 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4547 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4549 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4553 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4561 // -----------------------------------------------------------------------
4563 // Common code used by various OnMouseXXXChild methods.
4564 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4566 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4567 wxASSERT( topCtrlWnd
);
4569 event
.GetPosition(&x
,&y
);
4571 int splitterX
= GetSplitterPosition();
4573 wxRect r
= topCtrlWnd
->GetRect();
4574 if ( !m_dragStatus
&&
4575 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4576 y
>= 0 && y
< r
.height \
4579 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4584 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4591 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4594 if ( OnMouseChildCommon(event
,&x
,&y
) )
4596 bool res
= HandleMouseClick(x
,y
,event
);
4597 if ( !res
) event
.Skip();
4601 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4604 wxASSERT( m_wndEditor
);
4605 // These coords may not be exact (about +-2),
4606 // but that should not matter (right click is about item, not position).
4607 wxPoint pt
= m_wndEditor
->GetPosition();
4608 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4609 wxASSERT( m_selected
);
4610 m_propHover
= m_selected
;
4611 bool res
= HandleMouseRightClick(x
,y
,event
);
4612 if ( !res
) event
.Skip();
4615 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4618 if ( OnMouseChildCommon(event
,&x
,&y
) )
4620 bool res
= HandleMouseMove(x
,y
,event
);
4621 if ( !res
) event
.Skip();
4625 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4628 if ( OnMouseChildCommon(event
,&x
,&y
) )
4630 bool res
= HandleMouseUp(x
,y
,event
);
4631 if ( !res
) event
.Skip();
4635 // -----------------------------------------------------------------------
4636 // wxPropertyGrid keyboard event handling
4637 // -----------------------------------------------------------------------
4639 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4641 // Translates wxKeyEvent to wxPG_ACTION_XXX
4643 int keycode
= event
.GetKeyCode();
4644 int modifiers
= event
.GetModifiers();
4646 wxASSERT( !(modifiers
&~(0xFFFF)) );
4648 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4650 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4652 if ( it
== m_actionTriggers
.end() )
4657 int second
= (it
->second
>>16) & 0xFFFF;
4661 return (it
->second
& 0xFFFF);
4664 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4666 wxASSERT( !(modifiers
&~(0xFFFF)) );
4668 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4670 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4672 if ( it
!= m_actionTriggers
.end() )
4674 // This key combination is already used
4676 // Can add secondary?
4677 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4678 wxT("You can only add up to two separate actions per key combination.") );
4680 action
= it
->second
| (action
<<16);
4683 m_actionTriggers
[hashMapKey
] = action
;
4686 void wxPropertyGrid::ClearActionTriggers( int action
)
4688 wxPGHashMapI2I::iterator it
;
4690 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4692 if ( it
->second
== action
)
4694 m_actionTriggers
.erase(it
);
4699 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4702 // Handles key event when editor control is not focused.
4705 wxCHECK2(!m_frozen
, return);
4707 // Travelsal between items, collapsing/expanding, etc.
4708 int keycode
= event
.GetKeyCode();
4709 bool editorFocused
= IsEditorFocused();
4711 if ( keycode
== WXK_TAB
)
4713 wxWindow
* mainControl
;
4715 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4716 mainControl
= GetParent();
4720 if ( !event
.ShiftDown() )
4722 if ( !editorFocused
&& m_wndEditor
)
4724 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4728 // Tab traversal workaround for platforms on which
4729 // wxWindow::Navigate() may navigate into first child
4730 // instead of next sibling. Does not work perfectly
4731 // in every scenario (for instance, when property grid
4732 // is either first or last control).
4733 #if defined(__WXGTK__)
4734 wxWindow
* sibling
= mainControl
->GetNextSibling();
4736 sibling
->SetFocusFromKbd();
4738 Navigate(wxNavigationKeyEvent::IsForward
);
4744 if ( editorFocused
)
4750 #if defined(__WXGTK__)
4751 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4753 sibling
->SetFocusFromKbd();
4755 Navigate(wxNavigationKeyEvent::IsBackward
);
4763 // Ignore Alt and Control when they are down alone
4764 if ( keycode
== WXK_ALT
||
4765 keycode
== WXK_CONTROL
)
4772 int action
= KeyEventToActions(event
, &secondAction
);
4774 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4777 // Esc cancels any changes
4778 if ( IsEditorsValueModified() )
4780 EditorsValueWasNotModified();
4782 // Update the control as well
4783 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4785 m_selected
->GetDisplayedString() );
4788 OnValidationFailureReset(m_selected
);
4794 // Except for TAB and ESC, handle child control events in child control
4797 // Only propagate event if it had modifiers
4798 if ( !event
.HasModifiers() )
4800 event
.StopPropagation();
4806 bool wasHandled
= false;
4811 if ( ButtonTriggerKeyTest(action
, event
) )
4814 wxPGProperty
* p
= m_selected
;
4816 // Travel and expand/collapse
4819 if ( p
->GetChildCount() )
4821 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4823 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4826 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4828 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4835 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4839 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4845 if ( selectDir
>= -1 )
4847 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4849 DoSelectProperty(p
);
4855 // If nothing was selected, select the first item now
4856 // (or navigate out of tab).
4857 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4859 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4860 if ( p
) DoSelectProperty(p
);
4869 // -----------------------------------------------------------------------
4871 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4873 // If there was editor open and focused, then this event should not
4874 // really be processed here.
4875 if ( IsEditorFocused() )
4877 // However, if event had modifiers, it is probably still best
4879 if ( event
.HasModifiers() )
4882 event
.StopPropagation();
4886 HandleKeyEvent(event
, false);
4889 // -----------------------------------------------------------------------
4891 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4896 action
= KeyEventToActions(event
, &secondAction
);
4899 // Does the keycode trigger button?
4900 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4903 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4904 GetEventHandler()->AddPendingEvent(evt
);
4911 // -----------------------------------------------------------------------
4913 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4915 HandleKeyEvent(event
, true);
4918 // -----------------------------------------------------------------------
4919 // wxPropertyGrid miscellaneous event handling
4920 // -----------------------------------------------------------------------
4922 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4925 // Check if the focus is in this control or one of its children
4926 wxWindow
* newFocused
= wxWindow::FindFocus();
4928 if ( newFocused
!= m_curFocused
)
4929 HandleFocusChange( newFocused
);
4932 bool wxPropertyGrid::IsEditorFocused() const
4934 wxWindow
* focus
= wxWindow::FindFocus();
4936 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4937 focus
== GetEditorControl() )
4943 // Called by focus event handlers. newFocused is the window that becomes focused.
4944 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4946 unsigned int oldFlags
= m_iFlags
;
4948 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4950 wxWindow
* parent
= newFocused
;
4952 // This must be one of nextFocus' parents.
4955 // Use m_eventObject, which is either wxPropertyGrid or
4956 // wxPropertyGridManager, as appropriate.
4957 if ( parent
== m_eventObject
)
4959 m_iFlags
|= wxPG_FL_FOCUSED
;
4962 parent
= parent
->GetParent();
4965 m_curFocused
= newFocused
;
4967 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4968 (oldFlags
& wxPG_FL_FOCUSED
) )
4970 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4972 // Need to store changed value
4973 CommitChangesFromEditor();
4979 // Preliminary code for tab-order respecting
4980 // tab-traversal (but should be moved to
4983 wxWindow* prevFocus = event.GetWindow();
4984 wxWindow* useThis = this;
4985 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4986 useThis = GetParent();
4989 prevFocus->GetParent() == useThis->GetParent() )
4991 wxList& children = useThis->GetParent()->GetChildren();
4993 wxNode* node = children.Find(prevFocus);
4995 if ( node->GetNext() &&
4996 useThis == node->GetNext()->GetData() )
4997 DoSelectProperty(GetFirst());
4998 else if ( node->GetPrevious () &&
4999 useThis == node->GetPrevious()->GetData() )
5000 DoSelectProperty(GetLastProperty());
5007 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5008 DrawItem( m_selected
);
5012 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5014 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5015 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5016 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5017 //else if ( event.GetWindow() )
5019 HandleFocusChange(event
.GetWindow());
5024 // -----------------------------------------------------------------------
5026 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5028 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5032 // -----------------------------------------------------------------------
5034 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5036 m_iFlags
|= wxPG_FL_SCROLLED
;
5041 // -----------------------------------------------------------------------
5043 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5045 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5047 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5051 // -----------------------------------------------------------------------
5052 // Property editor related functions
5053 // -----------------------------------------------------------------------
5055 // noDefCheck = true prevents infinite recursion.
5056 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5059 wxASSERT( editorClass
);
5061 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5062 RegisterDefaultEditors();
5064 wxString name
= editorClass
->GetName();
5066 // Existing editor under this name?
5067 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5069 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5071 // If this name was already used, try class name.
5072 name
= editorClass
->GetClassInfo()->GetClassName();
5073 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5076 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5077 (wxPGEditor
*) vt_it
->second
,
5078 "Editor with given name was already registered" );
5080 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5085 // Use this in RegisterDefaultEditors.
5086 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5087 if ( wxPGEditor_##EDITOR == NULL ) \
5089 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5090 new wxPG##EDITOR##Editor, true ); \
5093 // Registers all default editor classes
5094 void wxPropertyGrid::RegisterDefaultEditors()
5096 wxPGRegisterDefaultEditorClass( TextCtrl
);
5097 wxPGRegisterDefaultEditorClass( Choice
);
5098 wxPGRegisterDefaultEditorClass( ComboBox
);
5099 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5100 #if wxPG_INCLUDE_CHECKBOX
5101 wxPGRegisterDefaultEditorClass( CheckBox
);
5103 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5105 // Register SpinCtrl etc. editors before use
5106 RegisterAdditionalEditors();
5109 // -----------------------------------------------------------------------
5110 // wxPGStringTokenizer
5111 // Needed to handle C-style string lists (e.g. "str1" "str2")
5112 // -----------------------------------------------------------------------
5114 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5115 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5119 wxPGStringTokenizer::~wxPGStringTokenizer()
5123 bool wxPGStringTokenizer::HasMoreTokens()
5125 const wxString
& str
= *m_str
;
5127 wxString::const_iterator i
= m_curPos
;
5129 wxUniChar delim
= m_delimeter
;
5131 wxUniChar prev_a
= wxT('\0');
5133 bool inToken
= false;
5135 while ( i
!= str
.end() )
5144 m_readyToken
.clear();
5149 if ( prev_a
!= wxT('\\') )
5153 if ( a
!= wxT('\\') )
5173 m_curPos
= str
.end();
5181 wxString
wxPGStringTokenizer::GetNextToken()
5183 return m_readyToken
;
5186 // -----------------------------------------------------------------------
5188 // -----------------------------------------------------------------------
5190 wxPGChoiceEntry::wxPGChoiceEntry()
5191 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5195 // -----------------------------------------------------------------------
5197 // -----------------------------------------------------------------------
5199 wxPGChoicesData::wxPGChoicesData()
5204 wxPGChoicesData::~wxPGChoicesData()
5209 void wxPGChoicesData::Clear()
5214 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5216 wxASSERT( m_items
.size() == 0 );
5218 m_items
= data
->m_items
;
5221 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5222 const wxPGChoiceEntry
& item
)
5224 wxVector
<wxPGChoiceEntry
>::iterator it
;
5228 index
= (int) m_items
.size();
5232 it
= m_items
.begin() + index
;
5235 m_items
.insert(it
, item
);
5237 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5239 // Need to fix value?
5240 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5241 ownEntry
.SetValue(index
);
5246 // -----------------------------------------------------------------------
5247 // wxPropertyGridEvent
5248 // -----------------------------------------------------------------------
5250 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5253 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5254 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5255 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5256 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5257 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5258 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5259 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5260 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5261 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5264 // -----------------------------------------------------------------------
5266 void wxPropertyGridEvent::Init()
5268 m_validationInfo
= NULL
;
5270 m_wasVetoed
= false;
5273 // -----------------------------------------------------------------------
5275 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5276 : wxCommandEvent(commandType
,id
)
5282 // -----------------------------------------------------------------------
5284 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5285 : wxCommandEvent(event
)
5287 m_eventType
= event
.GetEventType();
5288 m_eventObject
= event
.m_eventObject
;
5290 m_property
= event
.m_property
;
5291 m_validationInfo
= event
.m_validationInfo
;
5292 m_canVeto
= event
.m_canVeto
;
5293 m_wasVetoed
= event
.m_wasVetoed
;
5296 // -----------------------------------------------------------------------
5298 wxPropertyGridEvent::~wxPropertyGridEvent()
5302 // -----------------------------------------------------------------------
5304 wxEvent
* wxPropertyGridEvent::Clone() const
5306 return new wxPropertyGridEvent( *this );
5309 // -----------------------------------------------------------------------
5310 // wxPropertyGridPopulator
5311 // -----------------------------------------------------------------------
5313 wxPropertyGridPopulator::wxPropertyGridPopulator()
5317 wxPGGlobalVars
->m_offline
++;
5320 // -----------------------------------------------------------------------
5322 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5325 m_propHierarchy
.clear();
5328 // -----------------------------------------------------------------------
5330 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5336 // -----------------------------------------------------------------------
5338 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5341 // Free unused sets of choices
5342 wxPGHashMapS2P::iterator it
;
5344 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5346 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5353 m_pg
->GetPanel()->Refresh();
5355 wxPGGlobalVars
->m_offline
--;
5358 // -----------------------------------------------------------------------
5360 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5361 const wxString
& propLabel
,
5362 const wxString
& propName
,
5363 const wxString
* propValue
,
5364 wxPGChoices
* pChoices
)
5366 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5367 wxPGProperty
* parent
= GetCurParent();
5369 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5371 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5375 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5377 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5381 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5383 property
->SetLabel(propLabel
);
5384 property
->DoSetName(propName
);
5386 if ( pChoices
&& pChoices
->IsOk() )
5387 property
->SetChoices(*pChoices
);
5389 m_state
->DoInsert(parent
, -1, property
);
5392 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5393 wxPG_PROGRAMMATIC_VALUE
);
5398 // -----------------------------------------------------------------------
5400 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5402 m_propHierarchy
.push_back(property
);
5403 DoScanForChildren();
5404 m_propHierarchy
.pop_back();
5407 // -----------------------------------------------------------------------
5409 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5410 const wxString
& idString
)
5412 wxPGChoices choices
;
5415 if ( choicesString
[0] == wxT('@') )
5417 wxString ids
= choicesString
.substr(1);
5418 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5419 if ( it
== m_dictIdChoices
.end() )
5420 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5422 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5427 if ( idString
.length() )
5429 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5430 if ( it
!= m_dictIdChoices
.end() )
5432 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5439 // Parse choices string
5440 wxString::const_iterator it
= choicesString
.begin();
5444 bool labelValid
= false;
5446 for ( ; it
!= choicesString
.end(); ++it
)
5452 if ( c
== wxT('"') )
5457 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5458 choices
.Add(label
, l
);
5461 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5466 else if ( c
== wxT('=') )
5473 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5480 if ( c
== wxT('"') )
5493 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5494 choices
.Add(label
, l
);
5497 if ( !choices
.IsOk() )
5499 choices
.EnsureData();
5503 if ( idString
.length() )
5504 m_dictIdChoices
[idString
] = choices
.GetData();
5511 // -----------------------------------------------------------------------
5513 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5515 if ( s
.Last() == wxT('%') )
5517 wxString s2
= s
.substr(0,s
.length()-1);
5519 if ( s2
.ToLong(&val
, 10) )
5521 *pval
= (val
*max
)/100;
5527 return s
.ToLong(pval
, 10);
5530 // -----------------------------------------------------------------------
5532 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5533 const wxString
& type
,
5534 const wxString
& value
)
5536 int l
= m_propHierarchy
.size();
5540 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5541 wxString valuel
= value
.Lower();
5544 if ( type
.length() == 0 )
5549 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5551 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5553 else if ( value
.ToLong(&v
, 0) )
5560 if ( type
== wxT("string") )
5564 else if ( type
== wxT("int") )
5567 value
.ToLong(&v
, 0);
5570 else if ( type
== wxT("bool") )
5572 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5579 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5584 p
->SetAttribute( name
, variant
);
5589 // -----------------------------------------------------------------------
5591 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5593 wxLogError(_("Error in resource: %s"),msg
.c_str());
5596 // -----------------------------------------------------------------------
5598 #endif // wxUSE_PROPGRID