1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
68 #include "wx/msw/private.h"
71 // Two pics for the expand / collapse buttons.
72 // Files are not supplied with this project (since it is
73 // recommended to use either custom or native rendering).
74 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
75 // and copy xpm files from archive to wxPropertyGrid src directory
76 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
77 // and set wxPG_USE_RENDERER_NATIVE to 0).
78 #ifndef wxPG_ICON_WIDTH
79 #if defined(__WXMAC__)
80 #include "mac_collapse.xpm"
81 #include "mac_expand.xpm"
82 #elif defined(__WXGTK__)
83 #include "linux_collapse.xpm"
84 #include "linux_expand.xpm"
86 #include "default_collapse.xpm"
87 #include "default_expand.xpm"
92 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
93 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
94 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
95 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
96 #define wxPG_YSPACING_MIN 1
97 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
98 // but causes normal combobox to spill out under MSW
100 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
102 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
103 // Must be larger than largest control border
107 #define wxPG_DEFAULT_CURSOR wxNullCursor
110 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
112 //#define wxPG_HIDER_BUTTON_HEIGHT 25
114 #define wxPG_PIXELS_PER_UNIT m_lineHeight
116 #ifdef wxPG_ICON_WIDTH
117 #define m_iconHeight m_iconWidth
120 //#define wxPG_TOOLTIP_DELAY 1000
122 // -----------------------------------------------------------------------
125 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
127 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
130 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 // -----------------------------------------------------------------------
135 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
137 // -----------------------------------------------------------------------
138 // Statics in one class for easy destruction.
139 // -----------------------------------------------------------------------
141 #include "wx/module.h"
143 class wxPGGlobalVarsClassManager
: public wxModule
145 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
147 wxPGGlobalVarsClassManager() {}
148 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
149 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
152 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
155 // When wxPG is loaded dynamically after the application is already running
156 // then the built-in module system won't pick this one up. Add it manually.
157 void wxPGInitResourceModule()
159 wxModule
* module = new wxPGGlobalVarsClassManager
;
161 wxModule::RegisterModule(module);
164 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
167 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
169 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
171 m_boolChoices
.Add(_("False"));
172 m_boolChoices
.Add(_("True"));
174 m_fontFamilyChoices
= NULL
;
176 m_defaultRenderer
= new wxPGDefaultRenderer();
178 m_autoGetTranslation
= false;
186 // Prepare some shared variants
187 m_vEmptyString
= wxString();
189 m_vMinusOne
= (long) -1;
193 // Prepare cached string constants
194 m_strstring
= wxS("string");
195 m_strlong
= wxS("long");
196 m_strbool
= wxS("bool");
197 m_strlist
= wxS("list");
198 m_strMin
= wxS("Min");
199 m_strMax
= wxS("Max");
200 m_strUnits
= wxS("Units");
201 m_strInlineHelp
= wxS("InlineHelp");
207 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
211 delete m_defaultRenderer
;
213 // This will always have one ref
214 delete m_fontFamilyChoices
;
217 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
218 delete ((wxValidator
*)m_arrValidators
[i
]);
222 // Destroy value type class instances.
223 wxPGHashMapS2P::iterator vt_it
;
225 // Destroy editor class instances.
226 // iterate over all the elements in the class
227 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
229 delete ((wxPGEditor
*)vt_it
->second
);
232 delete wxPGProperty::sm_wxPG_LABEL
;
235 void wxPropertyGridInitGlobalsIfNeeded()
239 // -----------------------------------------------------------------------
241 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
242 // and tries to commit property value.
243 // -----------------------------------------------------------------------
245 class wxPGTLWHandler
: public wxEvtHandler
249 wxPGTLWHandler( wxPropertyGrid
* pg
)
257 void OnClose( wxCloseEvent
& event
)
259 // ClearSelection forces value validation/commit.
260 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
270 wxPropertyGrid
* m_pg
;
272 DECLARE_EVENT_TABLE()
275 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
276 EVT_CLOSE(wxPGTLWHandler::OnClose
)
279 // -----------------------------------------------------------------------
281 // -----------------------------------------------------------------------
284 // wxPGCanvas acts as a graphics sub-window of the
285 // wxScrolledWindow that wxPropertyGrid is.
287 class wxPGCanvas
: public wxPanel
290 wxPGCanvas() : wxPanel()
293 virtual ~wxPGCanvas() { }
296 void OnMouseMove( wxMouseEvent
&event
)
298 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
299 pg
->OnMouseMove( event
);
302 void OnMouseClick( wxMouseEvent
&event
)
304 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
305 pg
->OnMouseClick( event
);
308 void OnMouseUp( wxMouseEvent
&event
)
310 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
311 pg
->OnMouseUp( event
);
314 void OnMouseRightClick( wxMouseEvent
&event
)
316 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
317 pg
->OnMouseRightClick( event
);
320 void OnMouseDoubleClick( wxMouseEvent
&event
)
322 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
323 pg
->OnMouseDoubleClick( event
);
326 void OnKey( wxKeyEvent
& event
)
328 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
332 void OnPaint( wxPaintEvent
& event
);
334 // Always be focussable, even with child windows
335 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
336 { wxPanel::SetCanFocus(true); }
340 DECLARE_EVENT_TABLE()
341 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
345 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
347 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
348 EVT_MOTION(wxPGCanvas::OnMouseMove
)
349 EVT_PAINT(wxPGCanvas::OnPaint
)
350 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
351 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
352 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
353 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
354 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
358 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
360 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
361 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
365 // Don't paint after destruction has begun
366 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
369 // Update everything inside the box
370 wxRect r
= GetUpdateRegion().GetBox();
372 // FIXME: This is just a workaround for a bug that causes splitters not
373 // to paint when other windows are being dragged over the grid.
374 wxRect fullRect
= GetRect();
376 r
.width
= fullRect
.width
;
378 // Repaint this rectangle
379 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
381 // We assume that the size set when grid is shown
382 // is what is desired.
383 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
386 // -----------------------------------------------------------------------
388 // -----------------------------------------------------------------------
390 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
392 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
393 EVT_IDLE(wxPropertyGrid::OnIdle
)
394 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
395 EVT_PAINT(wxPropertyGrid::OnPaint
)
396 EVT_SIZE(wxPropertyGrid::OnResize
)
397 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
398 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
399 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
400 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
401 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
402 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
403 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
404 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
408 // -----------------------------------------------------------------------
410 wxPropertyGrid::wxPropertyGrid()
416 // -----------------------------------------------------------------------
418 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
423 const wxString
& name
)
427 Create(parent
,id
,pos
,size
,style
,name
);
430 // -----------------------------------------------------------------------
432 bool wxPropertyGrid::Create( wxWindow
*parent
,
437 const wxString
& name
)
440 if ( !(style
&wxBORDER_MASK
) )
441 style
|= wxSIMPLE_BORDER
;
445 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
446 style
&= ~(wxTAB_TRAVERSAL
);
447 style
|= wxWANTS_CHARS
;
449 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
456 // -----------------------------------------------------------------------
459 // Initialize values to defaults
461 void wxPropertyGrid::Init1()
463 // Register editor classes, if necessary.
464 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
465 wxPropertyGrid::RegisterDefaultEditors();
469 m_wndEditor
= m_wndEditor2
= NULL
;
473 m_eventObject
= this;
476 m_sortFunction
= NULL
;
477 m_inDoPropertyChanged
= 0;
478 m_inCommitChangesFromEditor
= 0;
479 m_inDoSelectProperty
= 0;
480 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
486 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
487 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
488 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
489 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
490 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
491 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
492 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
493 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
494 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
496 m_coloursCustomized
= 0;
501 #if wxPG_DOUBLE_BUFFER
502 m_doubleBuffer
= NULL
;
505 #ifndef wxPG_ICON_WIDTH
511 m_iconWidth
= wxPG_ICON_WIDTH
;
516 m_gutterWidth
= wxPG_GUTTER_MIN
;
517 m_subgroup_extramargin
= 10;
521 m_width
= m_height
= 0;
523 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
526 m_chgInfo_changedProperty
= NULL
;
529 // -----------------------------------------------------------------------
532 // Initialize after parent etc. set
534 void wxPropertyGrid::Init2()
536 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
539 // Smaller controls on Mac
540 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
543 // Now create state, if one didn't exist already
544 // (wxPropertyGridManager might have created it for us).
547 m_pState
= CreateState();
548 m_pState
->m_pPropGrid
= this;
549 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
552 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
553 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
555 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
557 m_pState
->InitNonCatMode();
559 m_pState
->m_properties
= m_pState
->m_abcArray
;
562 GetClientSize(&m_width
,&m_height
);
564 #ifndef wxPG_ICON_WIDTH
565 // create two bitmap nodes for drawing
566 m_expandbmp
= new wxBitmap(expand_xpm
);
567 m_collbmp
= new wxBitmap(collapse_xpm
);
569 // calculate average font height for bitmap centering
571 m_iconWidth
= m_expandbmp
->GetWidth();
572 m_iconHeight
= m_expandbmp
->GetHeight();
575 m_curcursor
= wxCURSOR_ARROW
;
576 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
578 // adjust bitmap icon y position so they are centered
579 m_vspacing
= wxPG_DEFAULT_VSPACING
;
581 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
583 // Allocate cell datas indirectly by calling setter
584 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
585 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
589 // This helps with flicker
590 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
593 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
594 m_tlp
= ::wxGetTopLevelParent(this);
595 m_tlwHandler
= handler
;
596 m_tlp
->PushEventHandler(handler
);
598 // set virtual size to this window size
599 wxSize wndsize
= GetSize();
600 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
602 m_timeCreated
= ::wxGetLocalTimeMillis();
604 m_canvas
= new wxPGCanvas();
605 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
606 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
607 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
609 m_iFlags
|= wxPG_FL_INITIALIZED
;
611 m_ncWidth
= wndsize
.GetWidth();
613 // Need to call OnResize handler or size given in constructor/Create
615 wxSizeEvent
sizeEvent(wndsize
,0);
619 // -----------------------------------------------------------------------
621 wxPropertyGrid::~wxPropertyGrid()
625 DoSelectProperty(NULL
);
627 // This should do prevent things from going too badly wrong
628 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
630 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
631 m_canvas
->ReleaseMouse();
633 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
634 m_tlp
->RemoveEventHandler(handler
);
637 wxASSERT_MSG( !IsEditorsValueModified(),
638 wxS("Most recent change in property editor was lost!!! ")
639 wxS("(if you don't want this to happen, close your frames ")
640 wxS("and dialogs using Close(false).)") );
642 #if wxPG_DOUBLE_BUFFER
643 if ( m_doubleBuffer
)
644 delete m_doubleBuffer
;
649 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
652 delete m_cursorSizeWE
;
654 #ifndef wxPG_ICON_WIDTH
659 // Delete common value records
660 for ( i
=0; i
<m_commonValues
.size(); i
++ )
662 delete GetCommonValue(i
);
666 // -----------------------------------------------------------------------
668 bool wxPropertyGrid::Destroy()
670 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
671 m_canvas
->ReleaseMouse();
673 return wxScrolledWindow::Destroy();
676 // -----------------------------------------------------------------------
678 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
680 return new wxPropertyGridPageState();
683 // -----------------------------------------------------------------------
684 // wxPropertyGrid overridden wxWindow methods
685 // -----------------------------------------------------------------------
687 void wxPropertyGrid::SetWindowStyleFlag( long style
)
689 long old_style
= m_windowStyle
;
691 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
693 wxASSERT( m_pState
);
695 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
698 EnableCategories( true );
700 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
702 // Disable categories
703 EnableCategories( false );
705 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
711 PrepareAfterItemsAdded();
713 m_pState
->m_itemsAdded
= 1;
715 #if wxPG_SUPPORT_TOOLTIPS
716 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
722 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
723 SetToolTip ( tooltip );
724 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
727 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
732 m_canvas
->SetToolTip( NULL
);
737 wxScrolledWindow::SetWindowStyleFlag ( style
);
739 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
741 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
743 CalculateFontAndBitmapStuff( m_vspacing
);
749 // -----------------------------------------------------------------------
751 void wxPropertyGrid::Freeze()
755 wxScrolledWindow::Freeze();
760 // -----------------------------------------------------------------------
762 void wxPropertyGrid::Thaw()
768 wxScrolledWindow::Thaw();
769 RecalculateVirtualSize();
770 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
774 // Force property re-selection
776 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
780 // -----------------------------------------------------------------------
782 void wxPropertyGrid::SetExtraStyle( long exStyle
)
784 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
786 #if defined(__WXMSW__)
789 // Don't use WS_EX_COMPOSITED just now.
792 if ( m_iFlags & wxPG_FL_IN_MANAGER )
793 hWnd = (HWND)GetParent()->GetHWND();
795 hWnd = (HWND)GetHWND();
797 ::SetWindowLong( hWnd, GWL_EXSTYLE,
798 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
801 //#elif defined(__WXGTK20__)
803 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
804 // truly was double-buffered.
805 if ( !this->IsDoubleBuffered() )
807 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
811 #if wxPG_DOUBLE_BUFFER
812 delete m_doubleBuffer
;
813 m_doubleBuffer
= NULL
;
818 wxScrolledWindow::SetExtraStyle( exStyle
);
820 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
821 m_pState
->InitNonCatMode();
823 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
824 m_windowStyle
|= wxPG_TOOLTIPS
;
827 wxPGGlobalVars
->m_extraStyle
= exStyle
;
830 // -----------------------------------------------------------------------
832 // returns the best acceptable minimal size
833 wxSize
wxPropertyGrid::DoGetBestSize() const
835 int lineHeight
= wxMax(15, m_lineHeight
);
837 // don't make the grid too tall (limit height to 10 items) but don't
838 // make it too small neither
841 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
845 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
850 // -----------------------------------------------------------------------
851 // wxPropertyGrid Font and Colour Methods
852 // -----------------------------------------------------------------------
854 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
858 m_captionFont
= wxScrolledWindow::GetFont();
860 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
861 m_subgroup_extramargin
= x
+ (x
/2);
864 #if wxPG_USE_RENDERER_NATIVE
865 m_iconWidth
= wxPG_ICON_WIDTH
;
866 #elif wxPG_ICON_WIDTH
868 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
869 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
870 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
874 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
875 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
876 m_gutterWidth
= wxPG_GUTTER_MIN
;
879 if ( vspacing
<= 1 ) vdiv
= 12;
880 else if ( vspacing
>= 3 ) vdiv
= 3;
882 m_spacingy
= m_fontHeight
/ vdiv
;
883 if ( m_spacingy
< wxPG_YSPACING_MIN
)
884 m_spacingy
= wxPG_YSPACING_MIN
;
887 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
888 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
890 m_captionFont
.SetWeight(wxBOLD
);
891 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
893 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
896 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
897 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
900 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
902 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
903 RecalculateVirtualSize();
905 InvalidateBestSize();
908 // -----------------------------------------------------------------------
910 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
916 // -----------------------------------------------------------------------
918 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
919 int ga
= 1000, int ba
= 1000,
920 bool forceDifferent
= false)
927 // Recursion guard (allow 2 max)
928 static int isinside
= 0;
930 wxCHECK_MSG( isinside
< 3,
932 wxT("wxPGAdjustColour should not be recursively called more than once") );
940 if ( r2
>255 ) r2
= 255;
941 else if ( r2
<0) r2
= 0;
943 if ( g2
>255 ) g2
= 255;
944 else if ( g2
<0) g2
= 0;
946 if ( b2
>255 ) b2
= 255;
947 else if ( b2
<0) b2
= 0;
949 // Make sure they are somewhat different
950 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
951 dst
= wxPGAdjustColour(src
,-(ra
*2));
953 dst
= wxColour(r2
,g2
,b2
);
955 // Recursion guard (allow 2 max)
962 static int wxPGGetColAvg( const wxColour
& col
)
964 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
968 void wxPropertyGrid::RegainColours()
970 if ( !(m_coloursCustomized
& 0x0002) )
972 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
974 // Make sure colour is dark enough
976 int colDec
= wxPGGetColAvg(col
) - 230;
978 int colDec
= wxPGGetColAvg(col
) - 200;
981 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
984 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
987 if ( !(m_coloursCustomized
& 0x0001) )
988 m_colMargin
= m_colCapBack
;
990 if ( !(m_coloursCustomized
& 0x0004) )
997 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
998 m_colCapFore
= capForeCol
;
999 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1002 if ( !(m_coloursCustomized
& 0x0008) )
1004 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1005 m_colPropBack
= bgCol
;
1006 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1009 if ( !(m_coloursCustomized
& 0x0010) )
1011 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1012 m_colPropFore
= fgCol
;
1013 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1016 if ( !(m_coloursCustomized
& 0x0020) )
1017 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1019 if ( !(m_coloursCustomized
& 0x0040) )
1020 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1022 if ( !(m_coloursCustomized
& 0x0080) )
1023 m_colLine
= m_colCapBack
;
1025 if ( !(m_coloursCustomized
& 0x0100) )
1026 m_colDisPropFore
= m_colCapFore
;
1028 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1031 // -----------------------------------------------------------------------
1033 void wxPropertyGrid::ResetColours()
1035 m_coloursCustomized
= 0;
1042 // -----------------------------------------------------------------------
1044 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1046 // Must disable active editor.
1047 ClearSelection(false);
1049 bool res
= wxScrolledWindow::SetFont( font
);
1050 if ( res
&& GetParent()) // may not have been Create()ed yet
1052 CalculateFontAndBitmapStuff( m_vspacing
);
1059 // -----------------------------------------------------------------------
1061 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1064 m_coloursCustomized
|= 0x80;
1068 // -----------------------------------------------------------------------
1070 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1073 m_coloursCustomized
|= 0x01;
1077 // -----------------------------------------------------------------------
1079 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1081 m_colPropBack
= col
;
1082 m_coloursCustomized
|= 0x08;
1084 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1089 // -----------------------------------------------------------------------
1091 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1093 m_colPropFore
= col
;
1094 m_coloursCustomized
|= 0x10;
1096 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1101 // -----------------------------------------------------------------------
1103 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1105 m_colEmptySpace
= col
;
1110 // -----------------------------------------------------------------------
1112 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1114 m_colDisPropFore
= col
;
1115 m_coloursCustomized
|= 0x100;
1119 // -----------------------------------------------------------------------
1121 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1124 m_coloursCustomized
|= 0x20;
1128 // -----------------------------------------------------------------------
1130 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1133 m_coloursCustomized
|= 0x40;
1137 // -----------------------------------------------------------------------
1139 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1142 m_coloursCustomized
|= 0x02;
1144 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1149 // -----------------------------------------------------------------------
1151 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1154 m_coloursCustomized
|= 0x04;
1156 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1161 // -----------------------------------------------------------------------
1162 // wxPropertyGrid property adding and removal
1163 // -----------------------------------------------------------------------
1165 void wxPropertyGrid::PrepareAfterItemsAdded()
1167 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1169 m_pState
->m_itemsAdded
= 0;
1171 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1172 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1174 RecalculateVirtualSize();
1177 // -----------------------------------------------------------------------
1178 // wxPropertyGrid property operations
1179 // -----------------------------------------------------------------------
1181 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1183 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1187 bool changed
= false;
1189 // Is it inside collapsed section?
1190 if ( !p
->IsVisible() )
1193 wxPGProperty
* parent
= p
->GetParent();
1194 wxPGProperty
* grandparent
= parent
->GetParent();
1196 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1197 Expand( grandparent
);
1205 GetViewStart(&vx
,&vy
);
1206 vy
*=wxPG_PIXELS_PER_UNIT
;
1212 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1213 m_iFlags
|= wxPG_FL_SCROLLED
;
1216 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1218 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1219 m_iFlags
|= wxPG_FL_SCROLLED
;
1229 // -----------------------------------------------------------------------
1230 // wxPropertyGrid helper methods called by properties
1231 // -----------------------------------------------------------------------
1233 // Control font changer helper.
1234 void wxPropertyGrid::SetCurControlBoldFont()
1236 wxASSERT( m_wndEditor
);
1237 m_wndEditor
->SetFont( m_captionFont
);
1240 // -----------------------------------------------------------------------
1242 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1245 #if wxPG_SMALL_SCREEN
1246 // On small-screen devices, always show dialogs with default position and size.
1247 return wxDefaultPosition
;
1249 int splitterX
= GetSplitterPosition();
1253 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1255 ImprovedClientToScreen( &x
, &y
);
1257 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1258 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1265 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1275 new_y
= y
+ m_lineHeight
;
1277 return wxPoint(new_x
,new_y
);
1281 // -----------------------------------------------------------------------
1283 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1285 if ( src_str
.length() == 0 )
1291 bool prev_is_slash
= false;
1293 wxString::const_iterator i
= src_str
.begin();
1297 for ( ; i
!= src_str
.end(); ++i
)
1301 if ( a
!= wxS('\\') )
1303 if ( !prev_is_slash
)
1309 if ( a
== wxS('n') )
1312 dst_str
<< wxS('\n');
1314 dst_str
<< wxS('\n');
1317 else if ( a
== wxS('t') )
1318 dst_str
<< wxS('\t');
1322 prev_is_slash
= false;
1326 if ( prev_is_slash
)
1328 dst_str
<< wxS('\\');
1329 prev_is_slash
= false;
1333 prev_is_slash
= true;
1340 // -----------------------------------------------------------------------
1342 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1344 if ( src_str
.length() == 0 )
1350 wxString::const_iterator i
= src_str
.begin();
1351 wxUniChar prev_a
= wxS('\0');
1355 for ( ; i
!= src_str
.end(); ++i
)
1359 if ( a
>= wxS(' ') )
1361 // This surely is not something that requires an escape sequence.
1366 // This might need...
1367 if ( a
== wxS('\r') )
1369 // DOS style line end.
1370 // Already taken care below
1372 else if ( a
== wxS('\n') )
1373 // UNIX style line end.
1374 dst_str
<< wxS("\\n");
1375 else if ( a
== wxS('\t') )
1377 dst_str
<< wxS('\t');
1380 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1390 // -----------------------------------------------------------------------
1392 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1399 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1402 // -----------------------------------------------------------------------
1403 // wxPropertyGrid graphics related methods
1404 // -----------------------------------------------------------------------
1406 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1410 // Update everything inside the box
1411 wxRect r
= GetUpdateRegion().GetBox();
1413 dc
.SetPen(m_colEmptySpace
);
1414 dc
.SetBrush(m_colEmptySpace
);
1415 dc
.DrawRectangle(r
);
1418 // -----------------------------------------------------------------------
1420 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1421 wxPGProperty
* property
) const
1423 // Prepare rectangle to be used
1425 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1426 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1428 #if (wxPG_USE_RENDERER_NATIVE)
1430 #elif wxPG_ICON_WIDTH
1431 // Drawing expand/collapse button manually
1432 dc
.SetPen(m_colPropFore
);
1433 if ( property
->IsCategory() )
1434 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1436 dc
.SetBrush(m_colPropBack
);
1438 dc
.DrawRectangle( r
);
1439 int _y
= r
.y
+(m_iconWidth
/2);
1440 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1445 if ( property
->IsExpanded() )
1447 // wxRenderer functions are non-mutating in nature, so it
1448 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1449 // Hopefully this does not cause problems.
1450 #if (wxPG_USE_RENDERER_NATIVE)
1451 wxRendererNative::Get().DrawTreeItemButton(
1457 #elif wxPG_ICON_WIDTH
1466 #if (wxPG_USE_RENDERER_NATIVE)
1467 wxRendererNative::Get().DrawTreeItemButton(
1473 #elif wxPG_ICON_WIDTH
1474 int _x
= r
.x
+(m_iconWidth
/2);
1475 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1481 #if (wxPG_USE_RENDERER_NATIVE)
1483 #elif wxPG_ICON_WIDTH
1486 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1490 // -----------------------------------------------------------------------
1493 // This is the one called by OnPaint event handler and others.
1494 // topy and bottomy are already unscrolled (ie. physical)
1496 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1498 unsigned int bottomy
,
1499 const wxRect
* clipRect
)
1501 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1503 m_pState
->EnsureVirtualHeight();
1505 wxRect tempClipRect
;
1508 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1509 clipRect
= &tempClipRect
;
1512 // items added check
1513 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1515 int paintFinishY
= 0;
1517 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1520 bool isBuffered
= false;
1522 #if wxPG_DOUBLE_BUFFER
1523 wxMemoryDC
* bufferDC
= NULL
;
1525 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1527 if ( !m_doubleBuffer
)
1529 paintFinishY
= clipRect
->y
;
1534 bufferDC
= new wxMemoryDC();
1536 // If nothing was changed, then just copy from double-buffer
1537 bufferDC
->SelectObject( *m_doubleBuffer
);
1547 dc
.SetClippingRegion( *clipRect
);
1548 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1551 #if wxPG_DOUBLE_BUFFER
1554 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1555 bufferDC
, 0, 0, wxCOPY
);
1556 dc
.DestroyClippingRegion(); // Is this really necessary?
1562 // Clear area beyond bottomY?
1563 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1565 dc
.SetPen(m_colEmptySpace
);
1566 dc
.SetBrush(m_colEmptySpace
);
1567 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1571 // -----------------------------------------------------------------------
1573 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1574 const wxRect
* clipRect
,
1575 bool isBuffered
) const
1577 const wxPGProperty
* firstItem
;
1578 const wxPGProperty
* lastItem
;
1580 firstItem
= DoGetItemAtY(clipRect
->y
);
1581 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1584 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1586 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1589 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1590 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1592 int lh
= m_lineHeight
;
1595 int lastItemBottomY
;
1597 firstItemTopY
= clipRect
->y
;
1598 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1600 // Align y coordinates to item boundaries
1601 firstItemTopY
-= firstItemTopY
% lh
;
1602 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1603 lastItemBottomY
-= 1;
1605 // Entire range outside scrolled, visible area?
1606 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1609 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1613 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1614 firstItem->GetLabel().c_str(),
1615 lastItem->GetLabel().c_str(),
1616 (int)(lastItemBottomY - firstItemTopY),
1618 (unsigned long)clipRect );
1623 long windowStyle
= m_windowStyle
;
1629 // With wxPG_DOUBLE_BUFFER, do double buffering
1630 // - buffer's y = 0, so align cliprect and coordinates to that
1632 #if wxPG_DOUBLE_BUFFER
1638 xRelMod
= clipRect
->x
;
1639 yRelMod
= clipRect
->y
;
1642 // clipRect conversion
1647 firstItemTopY
-= yRelMod
;
1648 lastItemBottomY
-= yRelMod
;
1651 wxUnusedVar(isBuffered
);
1654 int x
= m_marginWidth
- xRelMod
;
1656 wxFont normalFont
= GetFont();
1658 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1660 bool isEnabled
= IsEnabled();
1663 // Prepare some pens and brushes that are often changed to.
1666 wxBrush
marginBrush(m_colMargin
);
1667 wxPen
marginPen(m_colMargin
);
1668 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1669 wxPen
linepen(m_colLine
,1,wxSOLID
);
1671 // pen that has same colour as text
1672 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1675 // Clear margin with background colour
1677 dc
.SetBrush( marginBrush
);
1678 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1680 dc
.SetPen( *wxTRANSPARENT_PEN
);
1681 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1684 const wxPGProperty
* selected
= m_selected
;
1685 const wxPropertyGridPageState
* state
= m_pState
;
1687 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1688 bool wasSelectedPainted
= false;
1691 // TODO: Only render columns that are within clipping region.
1693 dc
.SetFont(normalFont
);
1695 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1696 int endScanBottomY
= lastItemBottomY
+ lh
;
1697 int y
= firstItemTopY
;
1700 // Pregenerate list of visible properties.
1701 wxArrayPGProperty visPropArray
;
1702 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1704 for ( ; !it
.AtEnd(); it
.Next() )
1706 const wxPGProperty
* p
= *it
;
1708 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1710 visPropArray
.push_back((wxPGProperty
*)p
);
1712 if ( y
> endScanBottomY
)
1719 visPropArray
.push_back(NULL
);
1721 wxPGProperty
* nextP
= visPropArray
[0];
1723 int gridWidth
= state
->m_width
;
1726 for ( unsigned int arrInd
=1;
1727 nextP
&& y
<= lastItemBottomY
;
1730 wxPGProperty
* p
= nextP
;
1731 nextP
= visPropArray
[arrInd
];
1733 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1734 int textMarginHere
= x
;
1735 int renderFlags
= 0;
1737 int greyDepth
= m_marginWidth
;
1738 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1739 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1741 int greyDepthX
= greyDepth
- xRelMod
;
1743 // Use basic depth if in non-categoric mode and parent is base array.
1744 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1746 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1749 // Paint margin area
1750 dc
.SetBrush(marginBrush
);
1751 dc
.SetPen(marginPen
);
1752 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1754 dc
.SetPen( linepen
);
1759 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1765 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1767 sx
+= state
->m_colWidths
[si
];
1768 dc
.DrawLine( sx
, y
, sx
, y2
);
1771 // Horizontal Line, below
1772 // (not if both this and next is category caption)
1773 if ( p
->IsCategory() &&
1774 nextP
&& nextP
->IsCategory() )
1775 dc
.SetPen(m_colCapBack
);
1777 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1780 // Need to override row colours?
1784 if ( p
!= selected
)
1786 // Disabled may get different colour.
1787 if ( !p
->IsEnabled() )
1789 renderFlags
|= wxPGCellRenderer::Disabled
|
1790 wxPGCellRenderer::DontUseCellFgCol
;
1791 rowFgCol
= m_colDisPropFore
;
1796 renderFlags
|= wxPGCellRenderer::Selected
;
1798 if ( !p
->IsCategory() )
1800 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1801 wxPGCellRenderer::DontUseCellBgCol
;
1803 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1804 wasSelectedPainted
= true;
1807 // Selected gets different colour.
1808 if ( reallyFocused
)
1810 rowFgCol
= m_colSelFore
;
1811 rowBgCol
= m_colSelBack
;
1813 else if ( isEnabled
)
1815 rowFgCol
= m_colPropFore
;
1816 rowBgCol
= m_colMargin
;
1820 rowFgCol
= m_colDisPropFore
;
1821 rowBgCol
= m_colSelBack
;
1828 if ( rowBgCol
.IsOk() )
1829 rowBgBrush
= wxBrush(rowBgCol
);
1831 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1832 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1835 // Fill additional margin area with background colour of first cell
1836 if ( greyDepthX
< textMarginHere
)
1838 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1840 wxPGCell
& cell
= p
->GetCell(0);
1841 rowBgCol
= cell
.GetBgCol();
1842 rowBgBrush
= wxBrush(rowBgCol
);
1844 dc
.SetBrush(rowBgBrush
);
1845 dc
.SetPen(rowBgCol
);
1846 dc
.DrawRectangle(greyDepthX
+1, y
,
1847 textMarginHere
-greyDepthX
, lh
-1);
1850 bool fontChanged
= false;
1852 // Expander button rectangle
1853 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1858 if ( p
->IsCategory() )
1860 // Captions have their cell areas merged as one
1861 dc
.SetFont(m_captionFont
);
1863 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1865 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1867 dc
.SetBrush(rowBgBrush
);
1868 dc
.SetPen(rowBgCol
);
1871 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1873 dc
.SetTextForeground(rowFgCol
);
1876 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1877 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1880 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1881 DrawExpanderButton( dc
, butRect
, p
);
1885 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1887 dc
.SetFont(m_captionFont
);
1893 int nextCellWidth
= state
->m_colWidths
[0] -
1894 (greyDepthX
- m_marginWidth
);
1895 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1896 int textXAdd
= textMarginHere
- greyDepthX
;
1898 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1900 cellRect
.width
= nextCellWidth
- 1;
1902 bool ctrlCell
= false;
1903 int cellRenderFlags
= renderFlags
;
1906 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1907 DrawExpanderButton( dc
, butRect
, p
);
1910 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1912 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1913 dc
.SetBrush(editorBgCol
);
1914 dc
.SetPen(editorBgCol
);
1915 dc
.SetTextForeground(m_colPropFore
);
1916 dc
.DrawRectangle(cellRect
);
1918 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1923 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1925 dc
.SetBrush(rowBgBrush
);
1926 dc
.SetPen(rowBgCol
);
1929 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1931 dc
.SetTextForeground(rowFgCol
);
1935 dc
.SetClippingRegion(cellRect
);
1937 cellRect
.x
+= textXAdd
;
1938 cellRect
.width
-= textXAdd
;
1943 wxPGCellRenderer
* renderer
;
1944 int cmnVal
= p
->GetCommonValue();
1945 if ( cmnVal
== -1 || ci
!= 1 )
1947 renderer
= p
->GetCellRenderer(ci
);
1948 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1953 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1954 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1959 cellX
+= state
->m_colWidths
[ci
];
1960 if ( ci
< (state
->m_colWidths
.size()-1) )
1961 nextCellWidth
= state
->m_colWidths
[ci
+1];
1963 dc
.DestroyClippingRegion(); // Is this really necessary?
1969 dc
.SetFont(normalFont
);
1974 // Refresh editor controls (seems not needed on msw)
1975 // NOTE: This code is mandatory for GTK!
1976 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1977 if ( wasSelectedPainted
)
1980 m_wndEditor
->Refresh();
1982 m_wndEditor2
->Refresh();
1989 // -----------------------------------------------------------------------
1991 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1995 if ( m_width
< 10 || m_height
< 10 ||
1996 !m_pState
->m_properties
->GetChildCount() ||
1998 return wxRect(0,0,0,0);
2003 // Return rect which encloses the given property range
2005 int visTop
= p1
->GetY();
2008 visBottom
= p2
->GetY() + m_lineHeight
;
2010 visBottom
= m_height
+ visTop
;
2012 // If seleced property is inside the range, we'll extend the range to include
2014 wxPGProperty
* selected
= m_selected
;
2017 int selectedY
= selected
->GetY();
2018 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2020 wxWindow
* editor
= GetEditorControl();
2023 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2024 if ( visBottom2
> visBottom
)
2025 visBottom
= visBottom2
;
2030 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2033 // -----------------------------------------------------------------------
2035 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2040 if ( m_pState
->m_itemsAdded
)
2041 PrepareAfterItemsAdded();
2043 wxRect r
= GetPropertyRect(p1
, p2
);
2046 m_canvas
->RefreshRect(r
);
2050 // -----------------------------------------------------------------------
2052 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2054 if ( p
== m_selected
)
2055 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2057 DrawItemAndChildren(p
);
2060 // -----------------------------------------------------------------------
2062 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2067 // Draw item, children, and parent too, if it is not category
2068 wxPGProperty
* parent
= p
->GetParent();
2071 !parent
->IsCategory() &&
2072 parent
->GetParent() )
2075 parent
= parent
->GetParent();
2078 DrawItemAndChildren(p
);
2081 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2083 wxCHECK_RET( p
, wxT("invalid property id") );
2085 // Do not draw if in non-visible page
2086 if ( p
->GetParentState() != m_pState
)
2089 // do not draw a single item if multiple pending
2090 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2093 // Update child control.
2094 if ( m_selected
&& m_selected
->GetParent() == p
)
2097 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2099 DrawItems(p
, lastDrawn
);
2102 // -----------------------------------------------------------------------
2104 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2105 const wxRect
*rect
)
2107 PrepareAfterItemsAdded();
2109 wxWindow::Refresh(false);
2111 // TODO: Coordinate translation
2112 m_canvas
->Refresh(false, rect
);
2114 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2115 // I think this really helps only GTK+1.2
2116 if ( m_wndEditor
) m_wndEditor
->Refresh();
2117 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2121 // -----------------------------------------------------------------------
2122 // wxPropertyGrid global operations
2123 // -----------------------------------------------------------------------
2125 void wxPropertyGrid::Clear()
2127 m_pState
->DoClear();
2133 RecalculateVirtualSize();
2135 // Need to clear some area at the end
2137 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2140 // -----------------------------------------------------------------------
2142 bool wxPropertyGrid::EnableCategories( bool enable
)
2144 ClearSelection(false);
2149 // Enable categories
2152 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2157 // Disable categories
2159 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2162 if ( !m_pState
->EnableCategories(enable
) )
2167 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2169 m_pState
->m_itemsAdded
= 1; // force
2170 PrepareAfterItemsAdded();
2174 m_pState
->m_itemsAdded
= 1;
2176 // No need for RecalculateVirtualSize() here - it is already called in
2177 // wxPropertyGridPageState method above.
2184 // -----------------------------------------------------------------------
2186 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2188 wxASSERT( pNewState
);
2189 wxASSERT( pNewState
->GetGrid() );
2191 if ( pNewState
== m_pState
)
2194 wxPGProperty
* oldSelection
= m_selected
;
2196 ClearSelection(false);
2198 m_pState
->m_selected
= oldSelection
;
2200 bool orig_mode
= m_pState
->IsInNonCatMode();
2201 bool new_state_mode
= pNewState
->IsInNonCatMode();
2203 m_pState
= pNewState
;
2206 int pgWidth
= GetClientSize().x
;
2207 if ( HasVirtualWidth() )
2209 int minWidth
= pgWidth
;
2210 if ( pNewState
->m_width
< minWidth
)
2212 pNewState
->m_width
= minWidth
;
2213 pNewState
->CheckColumnWidths();
2219 // Just in case, fully re-center splitter
2220 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2221 pNewState
->m_fSplitterX
= -1.0;
2223 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2228 // If necessary, convert state to correct mode.
2229 if ( orig_mode
!= new_state_mode
)
2231 // This should refresh as well.
2232 EnableCategories( orig_mode
?false:true );
2234 else if ( !m_frozen
)
2236 // Refresh, if not frozen.
2237 m_pState
->PrepareAfterItemsAdded();
2240 if ( m_pState
->m_selected
)
2241 DoSelectProperty( m_pState
->m_selected
);
2243 RecalculateVirtualSize(0);
2247 m_pState
->m_itemsAdded
= 1;
2250 // -----------------------------------------------------------------------
2252 // Call to SetSplitterPosition will always disable splitter auto-centering
2253 // if parent window is shown.
2254 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2256 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2259 wxPropertyGridPageState
* state
= m_pState
;
2261 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2266 CorrectEditorWidgetSizeX();
2272 // -----------------------------------------------------------------------
2274 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2276 SetSplitterPosition( m_width
/2, true );
2277 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2278 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2281 // -----------------------------------------------------------------------
2282 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2283 // -----------------------------------------------------------------------
2285 // Returns nearest paint visible property (such that will be painted unless
2286 // window is scrolled or resized). If given property is paint visible, then
2287 // it itself will be returned
2288 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2290 int vx
,vy1
;// Top left corner of client
2291 GetViewStart(&vx
,&vy1
);
2292 vy1
*= wxPG_PIXELS_PER_UNIT
;
2294 int vy2
= vy1
+ m_height
;
2295 int propY
= p
->GetY2(m_lineHeight
);
2297 if ( (propY
+ m_lineHeight
) < vy1
)
2300 return DoGetItemAtY( vy1
);
2302 else if ( propY
> vy2
)
2305 return DoGetItemAtY( vy2
);
2308 // Itself paint visible
2313 // -----------------------------------------------------------------------
2314 // Methods related to change in value, value modification and sending events
2315 // -----------------------------------------------------------------------
2317 // commits any changes in editor of selected property
2318 // return true if validation did not fail
2319 // flags are same as with DoSelectProperty
2320 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2322 // Committing already?
2323 if ( m_inCommitChangesFromEditor
)
2326 // Don't do this if already processing editor event. It might
2327 // induce recursive dialogs and crap like that.
2328 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2330 if ( m_inDoPropertyChanged
)
2337 IsEditorsValueModified() &&
2338 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2341 m_inCommitChangesFromEditor
= 1;
2343 wxVariant
variant(m_selected
->GetValueRef());
2344 bool valueIsPending
= false;
2346 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2347 // due to another window getting focus
2348 wxWindow
* oldFocus
= m_curFocused
;
2350 bool validationFailure
= false;
2351 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2353 m_chgInfo_changedProperty
= NULL
;
2355 // If truly modified, schedule value as pending.
2356 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2358 if ( DoEditorValidate() &&
2359 PerformValidation(m_selected
, variant
) )
2361 valueIsPending
= true;
2365 validationFailure
= true;
2370 EditorsValueWasNotModified();
2375 m_inCommitChangesFromEditor
= 0;
2377 if ( validationFailure
&& !forceSuccess
)
2381 oldFocus
->SetFocus();
2382 m_curFocused
= oldFocus
;
2385 res
= OnValidationFailure(m_selected
, variant
);
2387 // Now prevent further validation failure messages
2390 EditorsValueWasNotModified();
2391 OnValidationFailureReset(m_selected
);
2394 else if ( valueIsPending
)
2396 DoPropertyChanged( m_selected
, flags
);
2397 EditorsValueWasNotModified();
2406 // -----------------------------------------------------------------------
2408 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2412 // Runs all validation functionality.
2413 // Returns true if value passes all tests.
2416 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2418 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2420 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2425 // Adapt list to child values, if necessary
2426 wxVariant listValue
= pendingValue
;
2427 wxVariant
* pPendingValue
= &pendingValue
;
2428 wxVariant
* pList
= NULL
;
2430 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2431 // string value, then we need treat as it was changed instead
2432 // (or, in addition, as is the case with composite string parent).
2433 // This includes creating list variant for child values.
2435 wxPGProperty
* pwc
= p
->GetParent();
2436 wxPGProperty
* changedProperty
= p
;
2437 wxPGProperty
* baseChangedProperty
= changedProperty
;
2438 wxVariant bcpPendingList
;
2440 listValue
= pendingValue
;
2441 listValue
.SetName(p
->GetBaseName());
2444 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2446 wxVariantList tempList
;
2447 wxVariant
lv(tempList
, pwc
->GetBaseName());
2448 lv
.Append(listValue
);
2450 pPendingValue
= &listValue
;
2452 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2454 baseChangedProperty
= pwc
;
2455 bcpPendingList
= lv
;
2458 changedProperty
= pwc
;
2459 pwc
= pwc
->GetParent();
2463 wxPGProperty
* evtChangingProperty
= changedProperty
;
2465 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2467 value
= *pPendingValue
;
2471 // Convert list to child values
2472 pList
= pPendingValue
;
2473 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2476 wxVariant evtChangingValue
= value
;
2478 if ( flags
& SendEvtChanging
)
2480 // FIXME: After proper ValueToString()s added, remove
2481 // this. It is just a temporary fix, as evt_changing
2482 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2483 // (unless it is selected, and textctrl editor is open).
2484 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2486 evtChangingProperty
= baseChangedProperty
;
2487 if ( evtChangingProperty
!= p
)
2489 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2493 evtChangingValue
= pendingValue
;
2497 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2499 if ( changedProperty
== m_selected
)
2501 wxWindow
* editor
= GetEditorControl();
2502 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2503 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2507 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2512 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2513 m_chgInfo_changedProperty
= changedProperty
;
2514 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2515 m_chgInfo_pendingValue
= value
;
2518 m_chgInfo_valueList
= *pList
;
2520 m_chgInfo_valueList
.MakeNull();
2522 // If changedProperty is not property which value was edited,
2523 // then call wxPGProperty::ValidateValue() for that as well.
2524 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2526 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2530 if ( flags
& SendEvtChanging
)
2532 // SendEvent returns true if event was vetoed
2533 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2537 if ( flags
& IsStandaloneValidation
)
2539 // If called in 'generic' context, we need to reset
2540 // m_chgInfo_changedProperty and write back translated value.
2541 m_chgInfo_changedProperty
= NULL
;
2542 pendingValue
= value
;
2548 // -----------------------------------------------------------------------
2550 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2552 if ( !msg
.length() )
2556 if ( !wxPGGlobalVars
->m_offline
)
2558 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2561 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2564 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2567 pStatusBar
->SetStatusText(msg
);
2575 ::wxMessageBox(msg
, _T("Property Error"));
2578 // -----------------------------------------------------------------------
2580 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2581 wxVariant
& invalidValue
)
2583 wxWindow
* editor
= GetEditorControl();
2585 // First call property's handler
2586 property
->OnValidationFailure(invalidValue
);
2588 bool res
= DoOnValidationFailure(property
, invalidValue
);
2591 // For non-wxTextCtrl editors, we do need to revert the value
2592 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2593 property
== m_selected
)
2595 property
->GetEditorClass()->UpdateControl(property
, editor
);
2598 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2603 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2605 int vfb
= m_validationInfo
.m_failureBehavior
;
2607 if ( vfb
& wxPG_VFB_BEEP
)
2610 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2611 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2613 unsigned int colCount
= m_pState
->GetColumnCount();
2615 // We need backup marked property's cells
2616 m_propCellsBackup
= property
->m_cells
;
2618 wxColour vfbFg
= *wxWHITE
;
2619 wxColour vfbBg
= *wxRED
;
2621 property
->EnsureCells(colCount
);
2623 for ( unsigned int i
=0; i
<colCount
; i
++ )
2625 wxPGCell
& cell
= property
->m_cells
[i
];
2626 cell
.SetFgCol(vfbFg
);
2627 cell
.SetBgCol(vfbBg
);
2630 DrawItemAndChildren(property
);
2632 if ( property
== m_selected
)
2634 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2636 wxWindow
* editor
= GetEditorControl();
2639 editor
->SetForegroundColour(vfbFg
);
2640 editor
->SetBackgroundColour(vfbBg
);
2645 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2647 wxString msg
= m_validationInfo
.m_failureMessage
;
2649 if ( !msg
.length() )
2650 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2652 DoShowPropertyError(property
, msg
);
2655 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2658 // -----------------------------------------------------------------------
2660 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2662 int vfb
= m_validationInfo
.m_failureBehavior
;
2664 if ( vfb
& wxPG_VFB_MARK_CELL
)
2667 property
->m_cells
= m_propCellsBackup
;
2669 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2671 if ( property
== m_selected
&& GetEditorControl() )
2673 // Calling this will recreate the control, thus resetting its colour
2674 RefreshProperty(property
);
2678 DrawItemAndChildren(property
);
2683 // -----------------------------------------------------------------------
2685 // flags are same as with DoSelectProperty
2686 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2688 if ( m_inDoPropertyChanged
)
2691 wxWindow
* editor
= GetEditorControl();
2693 m_pState
->m_anyModified
= 1;
2695 m_inDoPropertyChanged
= 1;
2697 // Maybe need to update control
2698 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2700 // These values were calculated in PerformValidation()
2701 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2702 wxVariant value
= m_chgInfo_pendingValue
;
2704 wxPGProperty
* topPaintedProperty
= changedProperty
;
2706 while ( !topPaintedProperty
->IsCategory() &&
2707 !topPaintedProperty
->IsRoot() )
2709 topPaintedProperty
= topPaintedProperty
->GetParent();
2712 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2714 // Set as Modified (not if dragging just began)
2715 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2717 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2718 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2721 SetCurControlBoldFont();
2727 // Propagate updates to parent(s)
2729 wxPGProperty
* prevPwc
= NULL
;
2731 while ( prevPwc
!= topPaintedProperty
)
2733 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2735 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2738 SetCurControlBoldFont();
2742 pwc
= pwc
->GetParent();
2745 // Draw the actual property
2746 DrawItemAndChildren( topPaintedProperty
);
2749 // If value was set by wxPGProperty::OnEvent, then update the editor
2751 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2757 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2758 if ( m_wndEditor
) m_wndEditor
->Refresh();
2759 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2764 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2766 // If top parent has composite string value, then send to child parents,
2767 // starting from baseChangedProperty.
2768 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2770 pwc
= m_chgInfo_baseChangedProperty
;
2772 while ( pwc
!= changedProperty
)
2774 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2775 pwc
= pwc
->GetParent();
2779 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2781 m_inDoPropertyChanged
= 0;
2786 // -----------------------------------------------------------------------
2788 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2790 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2792 m_chgInfo_changedProperty
= NULL
;
2794 if ( PerformValidation(p
, newValue
) )
2796 DoPropertyChanged(p
);
2801 OnValidationFailure(p
, newValue
);
2807 // -----------------------------------------------------------------------
2809 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2811 wxPGProperty
* prop
= GetSelectedProperty();
2814 return wxNullVariant
;
2816 wxTextCtrl
* tc
= GetEditorTextCtrl();
2817 wxVariant value
= prop
->GetValue();
2819 if ( !tc
|| !IsEditorsValueModified() )
2822 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2825 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2826 return prop
->GetValue();
2831 // -----------------------------------------------------------------------
2833 // Runs wxValidator for the selected property
2834 bool wxPropertyGrid::DoEditorValidate()
2839 // -----------------------------------------------------------------------
2841 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2843 wxPGProperty
* selected
= m_selected
;
2845 // Somehow, event is handled after property has been deselected.
2846 // Possibly, but very rare.
2850 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2853 wxVariant
pendingValue(selected
->GetValueRef());
2854 wxWindow
* wnd
= GetEditorControl();
2855 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2857 bool wasUnspecified
= selected
->IsValueUnspecified();
2858 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2859 bool valueIsPending
= false;
2861 m_chgInfo_changedProperty
= NULL
;
2863 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2866 // Filter out excess wxTextCtrl modified events
2867 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2869 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2871 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2873 wxString newTcValue
= tc
->GetValue();
2874 if ( m_prevTcValue
== newTcValue
)
2877 m_prevTcValue
= newTcValue
;
2880 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2882 bool validationFailure
= false;
2883 bool buttonWasHandled
= false;
2886 // Try common button handling
2887 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2889 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2893 buttonWasHandled
= true;
2894 // Store as res2, as previously (and still currently alternatively)
2895 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2896 // in wxPGProperty::OnEvent().
2897 adapter
->ShowDialog( this, selected
);
2902 if ( !buttonWasHandled
)
2904 if ( wnd
|| m_wndEditor2
)
2906 // First call editor class' event handler.
2907 const wxPGEditor
* editor
= selected
->GetEditorClass();
2909 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2911 // If changes, validate them
2912 if ( DoEditorValidate() )
2914 if ( editor
->GetValueFromControl( pendingValue
,
2917 valueIsPending
= true;
2921 validationFailure
= true;
2926 // Then the property's custom handler (must be always called, unless
2927 // validation failed).
2928 if ( !validationFailure
)
2929 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2932 // SetValueInEvent(), as called in one of the functions referred above
2933 // overrides editor's value.
2934 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2936 valueIsPending
= true;
2937 pendingValue
= m_changeInEventValue
;
2938 selFlags
|= wxPG_SEL_DIALOGVAL
;
2941 if ( !validationFailure
&& valueIsPending
)
2942 if ( !PerformValidation(m_selected
, pendingValue
) )
2943 validationFailure
= true;
2945 if ( validationFailure
)
2947 OnValidationFailure(selected
, pendingValue
);
2949 else if ( valueIsPending
)
2951 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2953 DoPropertyChanged(selected
, selFlags
);
2954 EditorsValueWasNotModified();
2956 // Regardless of editor type, unfocus editor on
2957 // text-editing related enter press.
2958 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2965 // No value after all
2967 // Regardless of editor type, unfocus editor on
2968 // text-editing related enter press.
2969 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2974 // Let unhandled button click events go to the parent
2975 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2977 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2978 GetEventHandler()->AddPendingEvent(evt
);
2982 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2985 // -----------------------------------------------------------------------
2986 // wxPropertyGrid editor control helper methods
2987 // -----------------------------------------------------------------------
2989 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2991 int itemy
= p
->GetY2(m_lineHeight
);
2993 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2994 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2995 int imageOffset
= 0;
2997 // TODO: If custom image detection changes from current, change this.
2998 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3000 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3001 int iw
= p
->OnMeasureImage().x
;
3003 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3004 imageOffset
= p
->GetImageOffset(iw
);
3009 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3011 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3016 // -----------------------------------------------------------------------
3018 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3020 wxSize sz
= GetImageSize(p
, item
);
3021 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3022 wxPG_CUSTOM_IMAGE_SPACINGY
,
3027 // return size of custom paint image
3028 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3030 // If called with NULL property, then return default image
3031 // size for properties that use image.
3033 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3035 wxSize cis
= p
->OnMeasureImage(item
);
3037 int choiceCount
= p
->m_choices
.GetCount();
3038 int comVals
= p
->GetDisplayedCommonValueCount();
3039 if ( item
>= choiceCount
&& comVals
> 0 )
3041 unsigned int cvi
= item
-choiceCount
;
3042 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3044 else if ( item
>= 0 && choiceCount
== 0 )
3045 return wxSize(0, 0);
3050 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3055 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3062 // -----------------------------------------------------------------------
3064 // takes scrolling into account
3065 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3068 GetViewStart(&vx
,&vy
);
3069 vy
*=wxPG_PIXELS_PER_UNIT
;
3070 vx
*=wxPG_PIXELS_PER_UNIT
;
3073 ClientToScreen( px
, py
);
3076 // -----------------------------------------------------------------------
3078 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3081 GetViewStart(&pt2
.x
,&pt2
.y
);
3082 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3083 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3087 return m_pState
->HitTest(pt2
);
3090 // -----------------------------------------------------------------------
3092 // custom set cursor
3093 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3095 if ( type
== m_curcursor
&& !override
) return;
3097 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3099 if ( type
== wxCURSOR_SIZEWE
)
3100 cursor
= m_cursorSizeWE
;
3102 m_canvas
->SetCursor( *cursor
);
3107 // -----------------------------------------------------------------------
3108 // wxPropertyGrid property selection, editor creation
3109 // -----------------------------------------------------------------------
3112 // This class forwards events from property editor controls to wxPropertyGrid.
3113 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3116 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3117 : wxEvtHandler(), m_propGrid(propGrid
)
3121 virtual ~wxPropertyGridEditorEventForwarder()
3126 bool ProcessEvent( wxEvent
& event
)
3131 m_propGrid
->HandleCustomEditorEvent(event
);
3133 return wxEvtHandler::ProcessEvent(event
);
3136 wxPropertyGrid
* m_propGrid
;
3139 // Setups event handling for child control
3140 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3142 wxWindowID id
= argWnd
->GetId();
3144 if ( argWnd
== m_wndEditor
)
3146 argWnd
->Connect(id
, wxEVT_MOTION
,
3147 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3149 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3150 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3152 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3153 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3155 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3156 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3158 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3159 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3161 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3162 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3166 wxPropertyGridEditorEventForwarder
* forwarder
;
3167 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3168 argWnd
->PushEventHandler(forwarder
);
3170 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3171 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3175 void wxPropertyGrid::FreeEditors()
3178 // Return focus back to canvas from children (this is required at least for
3179 // GTK+, which, unlike Windows, clears focus when control is destroyed
3180 // instead of moving it to closest parent).
3181 wxWindow
* focus
= wxWindow::FindFocus();
3184 wxWindow
* parent
= focus
->GetParent();
3187 if ( parent
== m_canvas
)
3192 parent
= parent
->GetParent();
3196 // Do not free editors immediately if processing events
3199 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3200 m_wndEditor2
->Hide();
3201 wxPendingDelete
.Append( handler
);
3202 wxPendingDelete
.Append( m_wndEditor2
);
3203 m_wndEditor2
= NULL
;
3208 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3209 m_wndEditor
->Hide();
3210 wxPendingDelete
.Append( handler
);
3211 wxPendingDelete
.Append( m_wndEditor
);
3216 // Call with NULL to de-select property
3217 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3221 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3222 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3224 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3227 if ( m_inDoSelectProperty
)
3230 m_inDoSelectProperty
= 1;
3232 wxPGProperty
* prev
= m_selected
;
3236 m_inDoSelectProperty
= 0;
3242 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3244 wxPrintf( "None selected\n" );
3247 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3249 wxPrintf( "P = NULL\n" );
3252 // If we are frozen, then just set the values.
3255 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3256 m_editorFocused
= 0;
3259 m_pState
->m_selected
= p
;
3261 // If frozen, always free controls. But don't worry, as Thaw will
3262 // recall SelectProperty to recreate them.
3265 // Prevent any further selection measures in this call
3271 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3273 // Only set focus if not deselecting
3276 if ( flags
& wxPG_SEL_FOCUS
)
3280 m_wndEditor
->SetFocus();
3281 m_editorFocused
= 1;
3290 m_inDoSelectProperty
= 0;
3295 // First, deactivate previous
3299 OnValidationFailureReset(m_selected
);
3301 // Must double-check if this is an selected in case of forceswitch
3304 if ( !CommitChangesFromEditor(flags
) )
3306 // Validation has failed, so we can't exit the previous editor
3307 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3308 // _("Invalid Value"),wxOK|wxICON_ERROR);
3309 m_inDoSelectProperty
= 0;
3318 m_pState
->m_selected
= NULL
;
3320 // We need to always fully refresh the grid here
3323 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3324 EditorsValueWasNotModified();
3327 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3330 // Then, activate the one given.
3333 int propY
= p
->GetY2(m_lineHeight
);
3335 int splitterX
= GetSplitterPosition();
3336 m_editorFocused
= 0;
3338 m_pState
->m_selected
= p
;
3339 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3341 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3343 wxASSERT( m_wndEditor
== NULL
);
3346 // Only create editor for non-disabled non-caption
3347 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3349 // do this for non-caption items
3353 // Do we need to paint the custom image, if any?
3354 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3355 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3356 !p
->GetEditorClass()->CanContainCustomImage()
3358 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3360 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3361 wxPoint goodPos
= grect
.GetPosition();
3362 #if wxPG_CREATE_CONTROLS_HIDDEN
3363 int coord_adjust
= m_height
- goodPos
.y
;
3364 goodPos
.y
+= coord_adjust
;
3367 const wxPGEditor
* editor
= p
->GetEditorClass();
3368 wxCHECK_MSG(editor
, false,
3369 wxT("NULL editor class not allowed"));
3371 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3373 wxPGWindowList wndList
= editor
->CreateControls(this,
3378 m_wndEditor
= wndList
.m_primary
;
3379 m_wndEditor2
= wndList
.m_secondary
;
3380 wxWindow
* primaryCtrl
= GetEditorControl();
3383 // Essentially, primaryCtrl == m_wndEditor
3386 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3387 // value is drawn as normal, and m_wndEditor2 is assumed
3388 // to be a right-aligned button that triggers a separate editorCtrl
3393 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3394 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3396 // Set validator, if any
3397 #if wxUSE_VALIDATORS
3398 wxValidator
* validator
= p
->GetValidator();
3400 primaryCtrl
->SetValidator(*validator
);
3403 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3404 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3406 // If it has modified status, use bold font
3407 // (must be done before capturing m_ctrlXAdjust)
3408 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3409 SetCurControlBoldFont();
3412 // Fix TextCtrl indentation
3413 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3414 wxTextCtrl
* tc
= NULL
;
3415 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3416 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3418 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3420 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3423 // Store x relative to splitter (we'll need it).
3424 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3426 // Check if background clear is not necessary
3427 wxPoint pos
= m_wndEditor
->GetPosition();
3428 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3430 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3433 m_wndEditor
->SetSizeHints(3, 3);
3435 #if wxPG_CREATE_CONTROLS_HIDDEN
3436 m_wndEditor
->Show(false);
3437 m_wndEditor
->Freeze();
3439 goodPos
= m_wndEditor
->GetPosition();
3440 goodPos
.y
-= coord_adjust
;
3441 m_wndEditor
->Move( goodPos
);
3444 SetupChildEventHandling(primaryCtrl
);
3446 // Focus and select all (wxTextCtrl, wxComboBox etc)
3447 if ( flags
& wxPG_SEL_FOCUS
)
3449 primaryCtrl
->SetFocus();
3451 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3457 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3458 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3460 // Get proper id for wndSecondary
3461 m_wndSecId
= m_wndEditor2
->GetId();
3462 wxWindowList children
= m_wndEditor2
->GetChildren();
3463 wxWindowList::iterator node
= children
.begin();
3464 if ( node
!= children
.end() )
3465 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3467 m_wndEditor2
->SetSizeHints(3,3);
3469 #if wxPG_CREATE_CONTROLS_HIDDEN
3470 wxRect sec_rect
= m_wndEditor2
->GetRect();
3471 sec_rect
.y
-= coord_adjust
;
3473 // Fine tuning required to fix "oversized"
3474 // button disappearance bug.
3475 if ( sec_rect
.y
< 0 )
3477 sec_rect
.height
+= sec_rect
.y
;
3480 m_wndEditor2
->SetSize( sec_rect
);
3482 m_wndEditor2
->Show();
3484 SetupChildEventHandling(m_wndEditor2
);
3486 // If no primary editor, focus to button to allow
3487 // it to interprete ENTER etc.
3488 // NOTE: Due to problems focusing away from it, this
3489 // has been disabled.
3491 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3492 m_wndEditor2->SetFocus();
3496 if ( flags
& wxPG_SEL_FOCUS
)
3497 m_editorFocused
= 1;
3502 // Make sure focus is in grid canvas (important for wxGTK, at least)
3506 EditorsValueWasNotModified();
3508 // If it's inside collapsed section, expand parent, scroll, etc.
3509 // Also, if it was partially visible, scroll it into view.
3510 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3515 #if wxPG_CREATE_CONTROLS_HIDDEN
3516 m_wndEditor
->Thaw();
3518 m_wndEditor
->Show(true);
3525 // Make sure focus is in grid canvas
3529 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3535 // Show help text in status bar.
3536 // (if found and grid not embedded in manager with help box and
3537 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3540 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3542 wxStatusBar
* statusbar
= NULL
;
3543 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3545 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3547 statusbar
= frame
->GetStatusBar();
3552 const wxString
* pHelpString
= (const wxString
*) NULL
;
3556 pHelpString
= &p
->GetHelpString();
3557 if ( pHelpString
->length() )
3559 // Set help box text.
3560 statusbar
->SetStatusText( *pHelpString
);
3561 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3565 if ( (!pHelpString
|| !pHelpString
->length()) &&
3566 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3568 // Clear help box - but only if it was written
3569 // by us at previous time.
3570 statusbar
->SetStatusText( m_emptyString
);
3571 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3577 m_inDoSelectProperty
= 0;
3579 // call wx event handler (here so that it also occurs on deselection)
3580 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3585 // -----------------------------------------------------------------------
3587 bool wxPropertyGrid::UnfocusEditor()
3589 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3592 if ( !CommitChangesFromEditor(0) )
3596 DrawItem(m_selected
);
3601 // -----------------------------------------------------------------------
3603 void wxPropertyGrid::RefreshEditor()
3605 wxPGProperty
* p
= m_selected
;
3609 wxWindow
* wnd
= GetEditorControl();
3613 // Set editor font boldness - must do this before
3614 // calling UpdateControl().
3615 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3617 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3618 wnd
->SetFont(GetCaptionFont());
3620 wnd
->SetFont(GetFont());
3623 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3625 editorClass
->UpdateControl(p
, wnd
);
3627 if ( p
->IsValueUnspecified() )
3628 editorClass
->SetValueToUnspecified(p
, wnd
);
3631 // -----------------------------------------------------------------------
3633 // This method is not inline because it called dozens of times
3634 // (i.e. two-arg function calls create smaller code size).
3635 bool wxPropertyGrid::DoClearSelection()
3637 return DoSelectProperty(NULL
);
3640 // -----------------------------------------------------------------------
3641 // wxPropertyGrid expand/collapse state
3642 // -----------------------------------------------------------------------
3644 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3646 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3648 // If active editor was inside collapsed section, then disable it
3649 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3651 ClearSelection(false);
3654 // Store dont-center-splitter flag 'cause we need to temporarily set it
3655 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3656 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3658 bool res
= m_pState
->DoCollapse(pwc
);
3663 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3665 RecalculateVirtualSize();
3667 // Redraw etc. only if collapsed was visible.
3668 if (pwc
->IsVisible() &&
3670 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3672 // When item is collapsed so that scrollbar would move,
3673 // graphics mess is about (unless we redraw everything).
3678 // Clear dont-center-splitter flag if it wasn't set
3679 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3684 // -----------------------------------------------------------------------
3686 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3688 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3690 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3692 // Store dont-center-splitter flag 'cause we need to temporarily set it
3693 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3694 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3696 bool res
= m_pState
->DoExpand(pwc
);
3701 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3703 RecalculateVirtualSize();
3705 // Redraw etc. only if expanded was visible.
3706 if ( pwc
->IsVisible() && !m_frozen
&&
3707 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3711 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3714 DrawItems(pwc
, NULL
);
3719 // Clear dont-center-splitter flag if it wasn't set
3720 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3725 // -----------------------------------------------------------------------
3727 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3730 return m_pState
->DoHideProperty(p
, hide
, flags
);
3733 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3736 ClearSelection(false);
3739 m_pState
->DoHideProperty(p
, hide
, flags
);
3741 RecalculateVirtualSize();
3748 // -----------------------------------------------------------------------
3749 // wxPropertyGrid size related methods
3750 // -----------------------------------------------------------------------
3752 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3754 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3758 // If virtual height was changed, then recalculate editor control position(s)
3759 if ( m_pState
->m_vhCalcPending
)
3760 CorrectEditorWidgetPosY();
3762 m_pState
->EnsureVirtualHeight();
3764 wxASSERT_LEVEL_2_MSG(
3765 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3766 "VirtualHeight and ActualVirtualHeight should match"
3769 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3771 int x
= m_pState
->m_width
;
3772 int y
= m_pState
->m_virtualHeight
;
3775 GetClientSize(&width
,&height
);
3777 // Now adjust virtual size.
3778 SetVirtualSize(x
, y
);
3784 // Adjust scrollbars
3785 if ( HasVirtualWidth() )
3787 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3788 xPos
= GetScrollPos( wxHORIZONTAL
);
3791 if ( forceXPos
!= -1 )
3794 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3797 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3798 int yPos
= GetScrollPos( wxVERTICAL
);
3800 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3801 xAmount
, yAmount
, xPos
, yPos
, true );
3803 // Must re-get size now
3804 GetClientSize(&width
,&height
);
3806 if ( !HasVirtualWidth() )
3808 m_pState
->SetVirtualWidth(width
);
3815 m_canvas
->SetSize( x
, y
);
3817 m_pState
->CheckColumnWidths();
3820 CorrectEditorWidgetSizeX();
3822 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3825 // -----------------------------------------------------------------------
3827 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3829 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3833 GetClientSize(&width
,&height
);
3838 #if wxPG_DOUBLE_BUFFER
3839 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3841 int dblh
= (m_lineHeight
*2);
3842 if ( !m_doubleBuffer
)
3844 // Create double buffer bitmap to draw on, if none
3845 int w
= (width
>250)?width
:250;
3846 int h
= height
+ dblh
;
3848 m_doubleBuffer
= new wxBitmap( w
, h
);
3852 int w
= m_doubleBuffer
->GetWidth();
3853 int h
= m_doubleBuffer
->GetHeight();
3855 // Double buffer must be large enough
3856 if ( w
< width
|| h
< (height
+dblh
) )
3858 if ( w
< width
) w
= width
;
3859 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3860 delete m_doubleBuffer
;
3861 m_doubleBuffer
= new wxBitmap( w
, h
);
3868 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3869 m_ncWidth
= event
.GetSize().x
;
3873 if ( m_pState
->m_itemsAdded
)
3874 PrepareAfterItemsAdded();
3876 // Without this, virtual size (atleast under wxGTK) will be skewed
3877 RecalculateVirtualSize();
3883 // -----------------------------------------------------------------------
3885 void wxPropertyGrid::SetVirtualWidth( int width
)
3889 // Disable virtual width
3890 width
= GetClientSize().x
;
3891 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3895 // Enable virtual width
3896 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3898 m_pState
->SetVirtualWidth( width
);
3901 void wxPropertyGrid::SetFocusOnCanvas()
3903 m_canvas
->SetFocusIgnoringChildren();
3904 m_editorFocused
= 0;
3907 // -----------------------------------------------------------------------
3908 // wxPropertyGrid mouse event handling
3909 // -----------------------------------------------------------------------
3911 // selFlags uses same values DoSelectProperty's flags
3912 // Returns true if event was vetoed.
3913 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3915 // Send property grid event of specific type and with specific property
3916 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3917 evt
.SetPropertyGrid(this);
3918 evt
.SetEventObject(m_eventObject
);
3922 evt
.SetCanVeto(true);
3923 evt
.SetupValidationInfo();
3924 m_validationInfo
.m_pValue
= pValue
;
3926 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3928 evtHandler
->ProcessEvent(evt
);
3930 return evt
.WasVetoed();
3933 // -----------------------------------------------------------------------
3935 // Return false if should be skipped
3936 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3940 // Need to set focus?
3941 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3946 wxPropertyGridPageState
* state
= m_pState
;
3948 int splitterHitOffset
;
3949 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3951 wxPGProperty
* p
= DoGetItemAtY(y
);
3955 int depth
= (int)p
->GetDepth() - 1;
3957 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3959 if ( x
>= marginEnds
)
3963 if ( p
->IsCategory() )
3965 // This is category.
3966 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3968 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3970 // Expand, collapse, activate etc. if click on text or left of splitter.
3973 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3978 if ( !DoSelectProperty( p
) )
3981 // On double-click, expand/collapse.
3982 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3984 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3985 else DoExpand( p
, true );
3989 else if ( splitterHit
== -1 )
3992 unsigned int selFlag
= 0;
3993 if ( columnHit
== 1 )
3995 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3996 selFlag
= wxPG_SEL_FOCUS
;
3998 if ( !DoSelectProperty( p
, selFlag
) )
4001 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4003 if ( p
->GetChildCount() && !p
->IsCategory() )
4004 // On double-click, expand/collapse.
4005 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4007 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4008 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4009 else DoExpand( p
, true );
4016 // click on splitter
4017 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4019 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4021 // Double-clicking the splitter causes auto-centering
4022 CenterSplitter( true );
4024 else if ( m_dragStatus
== 0 )
4027 // Begin draggin the splitter
4031 // Changes must be committed here or the
4032 // value won't be drawn correctly
4033 if ( !CommitChangesFromEditor() )
4036 m_wndEditor
->Show ( false );
4039 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4041 m_canvas
->CaptureMouse();
4042 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4046 m_draggedSplitter
= splitterHit
;
4047 m_dragOffset
= splitterHitOffset
;
4049 wxClientDC
dc(m_canvas
);
4051 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4052 // Fixes button disappearance bug
4054 m_wndEditor2
->Show ( false );
4057 m_startingSplitterX
= x
- splitterHitOffset
;
4065 if ( p
->GetChildCount() )
4067 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4069 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4071 int y2
= y
% m_lineHeight
;
4072 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4074 // On click on expander button, expand/collapse
4075 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4076 DoCollapse( p
, true );
4078 DoExpand( p
, true );
4087 // -----------------------------------------------------------------------
4089 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4090 wxMouseEvent
& WXUNUSED(event
) )
4094 // Select property here as well
4095 wxPGProperty
* p
= m_propHover
;
4096 if ( p
!= m_selected
)
4097 DoSelectProperty( p
);
4099 // Send right click event.
4100 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4107 // -----------------------------------------------------------------------
4109 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4110 wxMouseEvent
& WXUNUSED(event
) )
4114 // Select property here as well
4115 wxPGProperty
* p
= m_propHover
;
4117 if ( p
!= m_selected
)
4118 DoSelectProperty( p
);
4120 // Send double-click event.
4121 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4128 // -----------------------------------------------------------------------
4130 #if wxPG_SUPPORT_TOOLTIPS
4132 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4134 if ( tipString
.length() )
4136 m_canvas
->SetToolTip(tipString
);
4140 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4141 m_canvas
->SetToolTip( m_emptyString
);
4143 m_canvas
->SetToolTip( NULL
);
4148 #endif // #if wxPG_SUPPORT_TOOLTIPS
4150 // -----------------------------------------------------------------------
4152 // Return false if should be skipped
4153 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4155 // Safety check (needed because mouse capturing may
4156 // otherwise freeze the control)
4157 if ( m_dragStatus
> 0 && !event
.Dragging() )
4159 HandleMouseUp(x
,y
,event
);
4162 wxPropertyGridPageState
* state
= m_pState
;
4164 int splitterHitOffset
;
4165 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4166 int splitterX
= x
- splitterHitOffset
;
4168 if ( m_dragStatus
> 0 )
4170 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4171 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4174 int newSplitterX
= x
- m_dragOffset
;
4175 int splitterX
= x
- splitterHitOffset
;
4177 // Splitter redraw required?
4178 if ( newSplitterX
!= splitterX
)
4181 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4182 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4183 state
->m_fSplitterX
= (float) newSplitterX
;
4186 CorrectEditorWidgetSizeX();
4200 int ih
= m_lineHeight
;
4203 #if wxPG_SUPPORT_TOOLTIPS
4204 wxPGProperty
* prevHover
= m_propHover
;
4205 unsigned char prevSide
= m_mouseSide
;
4207 int curPropHoverY
= y
- (y
% ih
);
4209 // On which item it hovers
4212 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4215 // Mouse moves on another property
4217 m_propHover
= DoGetItemAtY(y
);
4218 m_propHoverY
= curPropHoverY
;
4221 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4224 #if wxPG_SUPPORT_TOOLTIPS
4225 // Store which side we are on
4227 if ( columnHit
== 1 )
4229 else if ( columnHit
== 0 )
4233 // If tooltips are enabled, show label or value as a tip
4234 // in case it doesn't otherwise show in full length.
4236 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4238 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4240 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4242 if ( m_propHover
&& !m_propHover
->IsCategory() )
4245 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4247 // Show help string as a tooltip
4248 wxString tipString
= m_propHover
->GetHelpString();
4250 SetToolTip(tipString
);
4254 // Show cropped value string as a tooltip
4258 if ( m_mouseSide
== 1 )
4260 tipString
= m_propHover
->m_label
;
4261 space
= splitterX
-m_marginWidth
-3;
4263 else if ( m_mouseSide
== 2 )
4265 tipString
= m_propHover
->GetDisplayedString();
4267 space
= m_width
- splitterX
;
4268 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4269 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4275 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4278 SetToolTip( tipString
);
4285 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4286 m_canvas
->SetToolTip( m_emptyString
);
4288 m_canvas
->SetToolTip( NULL
);
4299 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4300 m_canvas
->SetToolTip( m_emptyString
);
4302 m_canvas
->SetToolTip( NULL
);
4310 if ( splitterHit
== -1 ||
4312 HasFlag(wxPG_STATIC_SPLITTER
) )
4314 // hovering on something else
4315 if ( m_curcursor
!= wxCURSOR_ARROW
)
4316 CustomSetCursor( wxCURSOR_ARROW
);
4320 // Do not allow splitter cursor on caption items.
4321 // (also not if we were dragging and its started
4322 // outside the splitter region)
4324 if ( !m_propHover
->IsCategory() &&
4328 // hovering on splitter
4330 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4331 // reliably detected.
4332 //if ( m_curcursor != wxCURSOR_SIZEWE )
4333 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4339 // hovering on something else
4340 if ( m_curcursor
!= wxCURSOR_ARROW
)
4341 CustomSetCursor( wxCURSOR_ARROW
);
4348 // -----------------------------------------------------------------------
4350 // Also handles Leaving event
4351 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4352 wxMouseEvent
&WXUNUSED(event
) )
4354 wxPropertyGridPageState
* state
= m_pState
;
4358 int splitterHitOffset
;
4359 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4361 // No event type check - basicly calling this method should
4362 // just stop dragging.
4363 // Left up after dragged?
4364 if ( m_dragStatus
>= 1 )
4367 // End Splitter Dragging
4369 // DO NOT ENABLE FOLLOWING LINE!
4370 // (it is only here as a reminder to not to do it)
4373 // Disable splitter auto-centering
4374 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4376 // This is necessary to return cursor
4377 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4379 m_canvas
->ReleaseMouse();
4380 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4383 // Set back the default cursor, if necessary
4384 if ( splitterHit
== -1 ||
4387 CustomSetCursor( wxCURSOR_ARROW
);
4392 // Control background needs to be cleared
4393 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4394 DrawItem( m_selected
);
4398 m_wndEditor
->Show ( true );
4401 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4402 // Fixes button disappearance bug
4404 m_wndEditor2
->Show ( true );
4407 // This clears the focus.
4408 m_editorFocused
= 0;
4414 // -----------------------------------------------------------------------
4416 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4418 int splitterX
= GetSplitterPosition();
4421 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4425 wxWindow
* wnd
= GetEditorControl();
4427 // Hide popup on clicks
4428 if ( event
.GetEventType() != wxEVT_MOTION
)
4429 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4431 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4437 if ( wnd
== NULL
|| m_dragStatus
||
4439 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4440 ux
>= (r
.x
+r
.width
) ||
4442 event
.m_y
>= (r
.y
+r
.height
)
4452 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4457 // -----------------------------------------------------------------------
4459 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4462 if ( OnMouseCommon( event
, &x
, &y
) )
4464 HandleMouseClick(x
,y
,event
);
4469 // -----------------------------------------------------------------------
4471 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4474 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4475 HandleMouseRightClick(x
,y
,event
);
4479 // -----------------------------------------------------------------------
4481 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4483 // Always run standard mouse-down handler as well
4484 OnMouseClick(event
);
4487 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4488 HandleMouseDoubleClick(x
,y
,event
);
4492 // -----------------------------------------------------------------------
4494 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4497 if ( OnMouseCommon( event
, &x
, &y
) )
4499 HandleMouseMove(x
,y
,event
);
4504 // -----------------------------------------------------------------------
4506 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4508 // Called when mouse moves in the empty space below the properties.
4509 CustomSetCursor( wxCURSOR_ARROW
);
4512 // -----------------------------------------------------------------------
4514 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4517 if ( OnMouseCommon( event
, &x
, &y
) )
4519 HandleMouseUp(x
,y
,event
);
4524 // -----------------------------------------------------------------------
4526 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4528 // This may get called from child control as well, so event's
4529 // mouse position cannot be relied on.
4531 if ( event
.Entering() )
4533 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4535 // TODO: Fix this (detect parent and only do
4536 // cursor trick if it is a manager).
4537 wxASSERT( GetParent() );
4538 GetParent()->SetCursor(wxNullCursor
);
4540 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4543 GetParent()->SetCursor(wxNullCursor
);
4545 else if ( event
.Leaving() )
4547 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4548 m_canvas
->SetCursor( wxNullCursor
);
4550 // Get real cursor position
4551 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4553 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4556 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4558 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4562 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4570 // -----------------------------------------------------------------------
4572 // Common code used by various OnMouseXXXChild methods.
4573 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4575 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4576 wxASSERT( topCtrlWnd
);
4578 event
.GetPosition(&x
,&y
);
4580 int splitterX
= GetSplitterPosition();
4582 wxRect r
= topCtrlWnd
->GetRect();
4583 if ( !m_dragStatus
&&
4584 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4585 y
>= 0 && y
< r
.height \
4588 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4593 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4600 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4603 if ( OnMouseChildCommon(event
,&x
,&y
) )
4605 bool res
= HandleMouseClick(x
,y
,event
);
4606 if ( !res
) event
.Skip();
4610 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4613 wxASSERT( m_wndEditor
);
4614 // These coords may not be exact (about +-2),
4615 // but that should not matter (right click is about item, not position).
4616 wxPoint pt
= m_wndEditor
->GetPosition();
4617 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4618 wxASSERT( m_selected
);
4619 m_propHover
= m_selected
;
4620 bool res
= HandleMouseRightClick(x
,y
,event
);
4621 if ( !res
) event
.Skip();
4624 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4627 if ( OnMouseChildCommon(event
,&x
,&y
) )
4629 bool res
= HandleMouseMove(x
,y
,event
);
4630 if ( !res
) event
.Skip();
4634 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4637 if ( OnMouseChildCommon(event
,&x
,&y
) )
4639 bool res
= HandleMouseUp(x
,y
,event
);
4640 if ( !res
) event
.Skip();
4644 // -----------------------------------------------------------------------
4645 // wxPropertyGrid keyboard event handling
4646 // -----------------------------------------------------------------------
4648 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4650 // Translates wxKeyEvent to wxPG_ACTION_XXX
4652 int keycode
= event
.GetKeyCode();
4653 int modifiers
= event
.GetModifiers();
4655 wxASSERT( !(modifiers
&~(0xFFFF)) );
4657 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4659 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4661 if ( it
== m_actionTriggers
.end() )
4666 int second
= (it
->second
>>16) & 0xFFFF;
4670 return (it
->second
& 0xFFFF);
4673 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4675 wxASSERT( !(modifiers
&~(0xFFFF)) );
4677 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4679 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4681 if ( it
!= m_actionTriggers
.end() )
4683 // This key combination is already used
4685 // Can add secondary?
4686 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4687 wxT("You can only add up to two separate actions per key combination.") );
4689 action
= it
->second
| (action
<<16);
4692 m_actionTriggers
[hashMapKey
] = action
;
4695 void wxPropertyGrid::ClearActionTriggers( int action
)
4697 wxPGHashMapI2I::iterator it
;
4699 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4701 if ( it
->second
== action
)
4703 m_actionTriggers
.erase(it
);
4708 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4711 // Handles key event when editor control is not focused.
4714 wxCHECK2(!m_frozen
, return);
4716 // Travelsal between items, collapsing/expanding, etc.
4717 int keycode
= event
.GetKeyCode();
4718 bool editorFocused
= IsEditorFocused();
4720 if ( keycode
== WXK_TAB
)
4722 wxWindow
* mainControl
;
4724 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4725 mainControl
= GetParent();
4729 if ( !event
.ShiftDown() )
4731 if ( !editorFocused
&& m_wndEditor
)
4733 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4737 // Tab traversal workaround for platforms on which
4738 // wxWindow::Navigate() may navigate into first child
4739 // instead of next sibling. Does not work perfectly
4740 // in every scenario (for instance, when property grid
4741 // is either first or last control).
4742 #if defined(__WXGTK__)
4743 wxWindow
* sibling
= mainControl
->GetNextSibling();
4745 sibling
->SetFocusFromKbd();
4747 Navigate(wxNavigationKeyEvent::IsForward
);
4753 if ( editorFocused
)
4759 #if defined(__WXGTK__)
4760 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4762 sibling
->SetFocusFromKbd();
4764 Navigate(wxNavigationKeyEvent::IsBackward
);
4772 // Ignore Alt and Control when they are down alone
4773 if ( keycode
== WXK_ALT
||
4774 keycode
== WXK_CONTROL
)
4781 int action
= KeyEventToActions(event
, &secondAction
);
4783 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4786 // Esc cancels any changes
4787 if ( IsEditorsValueModified() )
4789 EditorsValueWasNotModified();
4791 // Update the control as well
4792 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4794 m_selected
->GetDisplayedString() );
4797 OnValidationFailureReset(m_selected
);
4803 // Except for TAB and ESC, handle child control events in child control
4806 // Only propagate event if it had modifiers
4807 if ( !event
.HasModifiers() )
4809 event
.StopPropagation();
4815 bool wasHandled
= false;
4820 if ( ButtonTriggerKeyTest(action
, event
) )
4823 wxPGProperty
* p
= m_selected
;
4825 // Travel and expand/collapse
4828 if ( p
->GetChildCount() )
4830 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4832 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4835 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4837 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4844 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4848 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4854 if ( selectDir
>= -1 )
4856 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4858 DoSelectProperty(p
);
4864 // If nothing was selected, select the first item now
4865 // (or navigate out of tab).
4866 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4868 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4869 if ( p
) DoSelectProperty(p
);
4878 // -----------------------------------------------------------------------
4880 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4882 // If there was editor open and focused, then this event should not
4883 // really be processed here.
4884 if ( IsEditorFocused() )
4886 // However, if event had modifiers, it is probably still best
4888 if ( event
.HasModifiers() )
4891 event
.StopPropagation();
4895 HandleKeyEvent(event
, false);
4898 // -----------------------------------------------------------------------
4900 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4905 action
= KeyEventToActions(event
, &secondAction
);
4908 // Does the keycode trigger button?
4909 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4912 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4913 GetEventHandler()->AddPendingEvent(evt
);
4920 // -----------------------------------------------------------------------
4922 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4924 HandleKeyEvent(event
, true);
4927 // -----------------------------------------------------------------------
4928 // wxPropertyGrid miscellaneous event handling
4929 // -----------------------------------------------------------------------
4931 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4934 // Check if the focus is in this control or one of its children
4935 wxWindow
* newFocused
= wxWindow::FindFocus();
4937 if ( newFocused
!= m_curFocused
)
4938 HandleFocusChange( newFocused
);
4941 bool wxPropertyGrid::IsEditorFocused() const
4943 wxWindow
* focus
= wxWindow::FindFocus();
4945 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4946 focus
== GetEditorControl() )
4952 // Called by focus event handlers. newFocused is the window that becomes focused.
4953 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4955 unsigned int oldFlags
= m_iFlags
;
4957 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4959 wxWindow
* parent
= newFocused
;
4961 // This must be one of nextFocus' parents.
4964 // Use m_eventObject, which is either wxPropertyGrid or
4965 // wxPropertyGridManager, as appropriate.
4966 if ( parent
== m_eventObject
)
4968 m_iFlags
|= wxPG_FL_FOCUSED
;
4971 parent
= parent
->GetParent();
4974 m_curFocused
= newFocused
;
4976 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4977 (oldFlags
& wxPG_FL_FOCUSED
) )
4979 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4981 // Need to store changed value
4982 CommitChangesFromEditor();
4988 // Preliminary code for tab-order respecting
4989 // tab-traversal (but should be moved to
4992 wxWindow* prevFocus = event.GetWindow();
4993 wxWindow* useThis = this;
4994 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4995 useThis = GetParent();
4998 prevFocus->GetParent() == useThis->GetParent() )
5000 wxList& children = useThis->GetParent()->GetChildren();
5002 wxNode* node = children.Find(prevFocus);
5004 if ( node->GetNext() &&
5005 useThis == node->GetNext()->GetData() )
5006 DoSelectProperty(GetFirst());
5007 else if ( node->GetPrevious () &&
5008 useThis == node->GetPrevious()->GetData() )
5009 DoSelectProperty(GetLastProperty());
5016 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5017 DrawItem( m_selected
);
5021 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5023 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5024 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5025 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5026 //else if ( event.GetWindow() )
5028 HandleFocusChange(event
.GetWindow());
5033 // -----------------------------------------------------------------------
5035 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5037 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5041 // -----------------------------------------------------------------------
5043 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5045 m_iFlags
|= wxPG_FL_SCROLLED
;
5050 // -----------------------------------------------------------------------
5052 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5054 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5056 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5060 // -----------------------------------------------------------------------
5061 // Property editor related functions
5062 // -----------------------------------------------------------------------
5064 // noDefCheck = true prevents infinite recursion.
5065 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5068 wxASSERT( editorClass
);
5070 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5071 RegisterDefaultEditors();
5073 wxString name
= editorClass
->GetName();
5075 // Existing editor under this name?
5076 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5078 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5080 // If this name was already used, try class name.
5081 name
= editorClass
->GetClassInfo()->GetClassName();
5082 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5085 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5086 (wxPGEditor
*) vt_it
->second
,
5087 "Editor with given name was already registered" );
5089 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5094 // Use this in RegisterDefaultEditors.
5095 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5096 if ( wxPGEditor_##EDITOR == NULL ) \
5098 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5099 new wxPG##EDITOR##Editor, true ); \
5102 // Registers all default editor classes
5103 void wxPropertyGrid::RegisterDefaultEditors()
5105 wxPGRegisterDefaultEditorClass( TextCtrl
);
5106 wxPGRegisterDefaultEditorClass( Choice
);
5107 wxPGRegisterDefaultEditorClass( ComboBox
);
5108 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5109 #if wxPG_INCLUDE_CHECKBOX
5110 wxPGRegisterDefaultEditorClass( CheckBox
);
5112 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5114 // Register SpinCtrl etc. editors before use
5115 RegisterAdditionalEditors();
5118 // -----------------------------------------------------------------------
5119 // wxPGStringTokenizer
5120 // Needed to handle C-style string lists (e.g. "str1" "str2")
5121 // -----------------------------------------------------------------------
5123 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5124 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5128 wxPGStringTokenizer::~wxPGStringTokenizer()
5132 bool wxPGStringTokenizer::HasMoreTokens()
5134 const wxString
& str
= *m_str
;
5136 wxString::const_iterator i
= m_curPos
;
5138 wxUniChar delim
= m_delimeter
;
5140 wxUniChar prev_a
= wxT('\0');
5142 bool inToken
= false;
5144 while ( i
!= str
.end() )
5153 m_readyToken
.clear();
5158 if ( prev_a
!= wxT('\\') )
5162 if ( a
!= wxT('\\') )
5182 m_curPos
= str
.end();
5190 wxString
wxPGStringTokenizer::GetNextToken()
5192 return m_readyToken
;
5195 // -----------------------------------------------------------------------
5197 // -----------------------------------------------------------------------
5199 wxPGChoiceEntry::wxPGChoiceEntry()
5200 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5204 // -----------------------------------------------------------------------
5206 // -----------------------------------------------------------------------
5208 wxPGChoicesData::wxPGChoicesData()
5213 wxPGChoicesData::~wxPGChoicesData()
5218 void wxPGChoicesData::Clear()
5223 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5225 wxASSERT( m_items
.size() == 0 );
5227 m_items
= data
->m_items
;
5230 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5231 const wxPGChoiceEntry
& item
)
5233 wxVector
<wxPGChoiceEntry
>::iterator it
;
5237 index
= (int) m_items
.size();
5241 it
= m_items
.begin() + index
;
5244 m_items
.insert(it
, item
);
5246 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5248 // Need to fix value?
5249 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5250 ownEntry
.SetValue(index
);
5255 // -----------------------------------------------------------------------
5256 // wxPropertyGridEvent
5257 // -----------------------------------------------------------------------
5259 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5262 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5263 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5265 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5266 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5267 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5268 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5269 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5270 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5273 // -----------------------------------------------------------------------
5275 void wxPropertyGridEvent::Init()
5277 m_validationInfo
= NULL
;
5279 m_wasVetoed
= false;
5282 // -----------------------------------------------------------------------
5284 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5285 : wxCommandEvent(commandType
,id
)
5291 // -----------------------------------------------------------------------
5293 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5294 : wxCommandEvent(event
)
5296 m_eventType
= event
.GetEventType();
5297 m_eventObject
= event
.m_eventObject
;
5299 m_property
= event
.m_property
;
5300 m_validationInfo
= event
.m_validationInfo
;
5301 m_canVeto
= event
.m_canVeto
;
5302 m_wasVetoed
= event
.m_wasVetoed
;
5305 // -----------------------------------------------------------------------
5307 wxPropertyGridEvent::~wxPropertyGridEvent()
5311 // -----------------------------------------------------------------------
5313 wxEvent
* wxPropertyGridEvent::Clone() const
5315 return new wxPropertyGridEvent( *this );
5318 // -----------------------------------------------------------------------
5319 // wxPropertyGridPopulator
5320 // -----------------------------------------------------------------------
5322 wxPropertyGridPopulator::wxPropertyGridPopulator()
5326 wxPGGlobalVars
->m_offline
++;
5329 // -----------------------------------------------------------------------
5331 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5334 m_propHierarchy
.clear();
5337 // -----------------------------------------------------------------------
5339 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5345 // -----------------------------------------------------------------------
5347 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5350 // Free unused sets of choices
5351 wxPGHashMapS2P::iterator it
;
5353 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5355 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5362 m_pg
->GetPanel()->Refresh();
5364 wxPGGlobalVars
->m_offline
--;
5367 // -----------------------------------------------------------------------
5369 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5370 const wxString
& propLabel
,
5371 const wxString
& propName
,
5372 const wxString
* propValue
,
5373 wxPGChoices
* pChoices
)
5375 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5376 wxPGProperty
* parent
= GetCurParent();
5378 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5380 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5384 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5386 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5390 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5392 property
->SetLabel(propLabel
);
5393 property
->DoSetName(propName
);
5395 if ( pChoices
&& pChoices
->IsOk() )
5396 property
->SetChoices(*pChoices
);
5398 m_state
->DoInsert(parent
, -1, property
);
5401 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5402 wxPG_PROGRAMMATIC_VALUE
);
5407 // -----------------------------------------------------------------------
5409 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5411 m_propHierarchy
.push_back(property
);
5412 DoScanForChildren();
5413 m_propHierarchy
.pop_back();
5416 // -----------------------------------------------------------------------
5418 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5419 const wxString
& idString
)
5421 wxPGChoices choices
;
5424 if ( choicesString
[0] == wxT('@') )
5426 wxString ids
= choicesString
.substr(1);
5427 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5428 if ( it
== m_dictIdChoices
.end() )
5429 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5431 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5436 if ( idString
.length() )
5438 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5439 if ( it
!= m_dictIdChoices
.end() )
5441 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5448 // Parse choices string
5449 wxString::const_iterator it
= choicesString
.begin();
5453 bool labelValid
= false;
5455 for ( ; it
!= choicesString
.end(); ++it
)
5461 if ( c
== wxT('"') )
5466 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5467 choices
.Add(label
, l
);
5470 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5475 else if ( c
== wxT('=') )
5482 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5489 if ( c
== wxT('"') )
5502 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5503 choices
.Add(label
, l
);
5506 if ( !choices
.IsOk() )
5508 choices
.EnsureData();
5512 if ( idString
.length() )
5513 m_dictIdChoices
[idString
] = choices
.GetData();
5520 // -----------------------------------------------------------------------
5522 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5524 if ( s
.Last() == wxT('%') )
5526 wxString s2
= s
.substr(0,s
.length()-1);
5528 if ( s2
.ToLong(&val
, 10) )
5530 *pval
= (val
*max
)/100;
5536 return s
.ToLong(pval
, 10);
5539 // -----------------------------------------------------------------------
5541 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5542 const wxString
& type
,
5543 const wxString
& value
)
5545 int l
= m_propHierarchy
.size();
5549 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5550 wxString valuel
= value
.Lower();
5553 if ( type
.length() == 0 )
5558 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5560 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5562 else if ( value
.ToLong(&v
, 0) )
5569 if ( type
== wxT("string") )
5573 else if ( type
== wxT("int") )
5576 value
.ToLong(&v
, 0);
5579 else if ( type
== wxT("bool") )
5581 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5588 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5593 p
->SetAttribute( name
, variant
);
5598 // -----------------------------------------------------------------------
5600 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5602 wxLogError(_("Error in resource: %s"),msg
.c_str());
5605 // -----------------------------------------------------------------------
5607 #endif // wxUSE_PROPGRID