1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 //#define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 //#define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
237 // and tries to commit property value.
238 // -----------------------------------------------------------------------
240 class wxPGTLWHandler
: public wxEvtHandler
244 wxPGTLWHandler( wxPropertyGrid
* pg
)
252 void OnClose( wxCloseEvent
& event
)
254 // ClearSelection forces value validation/commit.
255 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
265 wxPropertyGrid
* m_pg
;
267 DECLARE_EVENT_TABLE()
270 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
271 EVT_CLOSE(wxPGTLWHandler::OnClose
)
274 // -----------------------------------------------------------------------
276 // -----------------------------------------------------------------------
279 // wxPGCanvas acts as a graphics sub-window of the
280 // wxScrolledWindow that wxPropertyGrid is.
282 class wxPGCanvas
: public wxPanel
285 wxPGCanvas() : wxPanel()
288 virtual ~wxPGCanvas() { }
291 void OnMouseMove( wxMouseEvent
&event
)
293 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
294 pg
->OnMouseMove( event
);
297 void OnMouseClick( wxMouseEvent
&event
)
299 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
300 pg
->OnMouseClick( event
);
303 void OnMouseUp( wxMouseEvent
&event
)
305 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
306 pg
->OnMouseUp( event
);
309 void OnMouseRightClick( wxMouseEvent
&event
)
311 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
312 pg
->OnMouseRightClick( event
);
315 void OnMouseDoubleClick( wxMouseEvent
&event
)
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 pg
->OnMouseDoubleClick( event
);
321 void OnKey( wxKeyEvent
& event
)
323 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
327 void OnPaint( wxPaintEvent
& event
);
329 // Always be focussable, even with child windows
330 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
331 { wxPanel::SetCanFocus(true); }
335 DECLARE_EVENT_TABLE()
336 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
340 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
342 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
343 EVT_MOTION(wxPGCanvas::OnMouseMove
)
344 EVT_PAINT(wxPGCanvas::OnPaint
)
345 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
346 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
347 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
348 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
349 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
353 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
355 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
356 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
360 // Don't paint after destruction has begun
361 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
364 // Update everything inside the box
365 wxRect r
= GetUpdateRegion().GetBox();
367 // Repaint this rectangle
368 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
370 // We assume that the size set when grid is shown
371 // is what is desired.
372 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
375 // -----------------------------------------------------------------------
377 // -----------------------------------------------------------------------
379 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
381 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
382 EVT_IDLE(wxPropertyGrid::OnIdle
)
383 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
384 EVT_PAINT(wxPropertyGrid::OnPaint
)
385 EVT_SIZE(wxPropertyGrid::OnResize
)
386 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
387 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
388 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
389 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
390 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
391 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
392 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
393 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
397 // -----------------------------------------------------------------------
399 wxPropertyGrid::wxPropertyGrid()
405 // -----------------------------------------------------------------------
407 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
412 const wxString
& name
)
416 Create(parent
,id
,pos
,size
,style
,name
);
419 // -----------------------------------------------------------------------
421 bool wxPropertyGrid::Create( wxWindow
*parent
,
426 const wxString
& name
)
429 if ( !(style
&wxBORDER_MASK
) )
430 style
|= wxSIMPLE_BORDER
;
434 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
435 style
&= ~(wxTAB_TRAVERSAL
);
436 style
|= wxWANTS_CHARS
;
438 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
445 // -----------------------------------------------------------------------
448 // Initialize values to defaults
450 void wxPropertyGrid::Init1()
452 // Register editor classes, if necessary.
453 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
454 wxPropertyGrid::RegisterDefaultEditors();
457 m_pState
= (wxPropertyGridPageState
*) NULL
;
458 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
459 m_selected
= (wxPGProperty
*) NULL
;
461 m_propHover
= (wxPGProperty
*) NULL
;
462 m_eventObject
= this;
463 m_curFocused
= (wxWindow
*) NULL
;
465 m_inDoPropertyChanged
= 0;
466 m_inCommitChangesFromEditor
= 0;
467 m_inDoSelectProperty
= 0;
468 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
474 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
475 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
476 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
477 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
478 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
479 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
480 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
481 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
482 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
484 m_coloursCustomized
= 0;
489 #if wxPG_DOUBLE_BUFFER
490 m_doubleBuffer
= (wxBitmap
*) NULL
;
493 #ifndef wxPG_ICON_WIDTH
499 m_iconWidth
= wxPG_ICON_WIDTH
;
504 m_gutterWidth
= wxPG_GUTTER_MIN
;
505 m_subgroup_extramargin
= 10;
509 m_width
= m_height
= 0;
511 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
514 m_chgInfo_changedProperty
= NULL
;
517 // -----------------------------------------------------------------------
520 // Initialize after parent etc. set
522 void wxPropertyGrid::Init2()
524 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
527 // Smaller controls on Mac
528 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
531 // Now create state, if one didn't exist already
532 // (wxPropertyGridManager might have created it for us).
535 m_pState
= CreateState();
536 m_pState
->m_pPropGrid
= this;
537 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
540 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
541 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
543 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
545 m_pState
->InitNonCatMode();
547 m_pState
->m_properties
= m_pState
->m_abcArray
;
550 GetClientSize(&m_width
,&m_height
);
552 #ifndef wxPG_ICON_WIDTH
553 // create two bitmap nodes for drawing
554 m_expandbmp
= new wxBitmap(expand_xpm
);
555 m_collbmp
= new wxBitmap(collapse_xpm
);
557 // calculate average font height for bitmap centering
559 m_iconWidth
= m_expandbmp
->GetWidth();
560 m_iconHeight
= m_expandbmp
->GetHeight();
563 m_curcursor
= wxCURSOR_ARROW
;
564 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
566 // adjust bitmap icon y position so they are centered
567 m_vspacing
= wxPG_DEFAULT_VSPACING
;
571 wxFont useFont
= wxScrolledWindow::GetFont();
572 wxScrolledWindow::SetOwnFont( useFont
);
576 // This should be otherwise called by SetOwnFont
577 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
580 // Allocate cell datas indirectly by calling setter
581 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
582 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
586 // This helps with flicker
587 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
590 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
591 m_tlp
= ::wxGetTopLevelParent(this);
592 m_tlwHandler
= handler
;
593 m_tlp
->PushEventHandler(handler
);
595 // set virtual size to this window size
596 wxSize wndsize
= GetSize();
597 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
599 m_timeCreated
= ::wxGetLocalTimeMillis();
601 m_canvas
= new wxPGCanvas();
602 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
603 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
604 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
606 m_iFlags
|= wxPG_FL_INITIALIZED
;
608 m_ncWidth
= wndsize
.GetWidth();
610 // Need to call OnResize handler or size given in constructor/Create
612 wxSizeEvent
sizeEvent(wndsize
,0);
616 // -----------------------------------------------------------------------
618 wxPropertyGrid::~wxPropertyGrid()
622 DoSelectProperty(NULL
);
624 // This should do prevent things from going too badly wrong
625 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
627 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
628 m_canvas
->ReleaseMouse();
630 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
631 m_tlp
->RemoveEventHandler(handler
);
635 if ( IsEditorsValueModified() )
636 ::wxMessageBox(wxS("Most recent change in property editor was lost!!!\n\n(if you don't want this to happen, close your frames and dialogs using Close(false).)"),
637 wxS("wxPropertyGrid Debug Warning") );
640 #if wxPG_DOUBLE_BUFFER
641 if ( m_doubleBuffer
)
642 delete m_doubleBuffer
;
645 //m_selected = (wxPGProperty*) NULL;
647 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
650 delete m_cursorSizeWE
;
652 #ifndef wxPG_ICON_WIDTH
657 // Delete common value records
658 for ( i
=0; i
<m_commonValues
.size(); i
++ )
660 delete GetCommonValue(i
);
664 // -----------------------------------------------------------------------
666 bool wxPropertyGrid::Destroy()
668 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
669 m_canvas
->ReleaseMouse();
671 return wxScrolledWindow::Destroy();
674 // -----------------------------------------------------------------------
676 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
678 return new wxPropertyGridPageState();
681 // -----------------------------------------------------------------------
682 // wxPropertyGrid overridden wxWindow methods
683 // -----------------------------------------------------------------------
685 void wxPropertyGrid::SetWindowStyleFlag( long style
)
687 long old_style
= m_windowStyle
;
689 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
691 wxASSERT( m_pState
);
693 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
696 EnableCategories( true );
698 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
700 // Disable categories
701 EnableCategories( false );
703 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
709 PrepareAfterItemsAdded();
711 m_pState
->m_itemsAdded
= 1;
713 #if wxPG_SUPPORT_TOOLTIPS
714 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
720 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
721 SetToolTip ( tooltip );
722 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
725 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
730 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
735 wxScrolledWindow::SetWindowStyleFlag ( style
);
737 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
739 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
741 CalculateFontAndBitmapStuff( m_vspacing
);
747 // -----------------------------------------------------------------------
749 void wxPropertyGrid::Freeze()
753 wxScrolledWindow::Freeze();
758 // -----------------------------------------------------------------------
760 void wxPropertyGrid::Thaw()
766 wxScrolledWindow::Thaw();
767 RecalculateVirtualSize();
768 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
772 // Force property re-selection
774 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
778 // -----------------------------------------------------------------------
780 void wxPropertyGrid::SetExtraStyle( long exStyle
)
782 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
784 #if defined(__WXMSW__)
787 // Don't use WS_EX_COMPOSITED just now.
790 if ( m_iFlags & wxPG_FL_IN_MANAGER )
791 hWnd = (HWND)GetParent()->GetHWND();
793 hWnd = (HWND)GetHWND();
795 ::SetWindowLong( hWnd, GWL_EXSTYLE,
796 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
799 //#elif defined(__WXGTK20__)
801 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
802 // truly was double-buffered.
803 if ( !this->IsDoubleBuffered() )
805 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
809 #if wxPG_DOUBLE_BUFFER
810 delete m_doubleBuffer
;
811 m_doubleBuffer
= NULL
;
816 wxScrolledWindow::SetExtraStyle( exStyle
);
818 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
819 m_pState
->InitNonCatMode();
821 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
822 m_windowStyle
|= wxPG_TOOLTIPS
;
825 wxPGGlobalVars
->m_extraStyle
= exStyle
;
828 // -----------------------------------------------------------------------
830 // returns the best acceptable minimal size
831 wxSize
wxPropertyGrid::DoGetBestSize() const
834 if ( m_lineHeight
> hei
)
836 wxSize sz
= wxSize( 60, hei
+40 );
842 // -----------------------------------------------------------------------
843 // wxPropertyGrid Font and Colour Methods
844 // -----------------------------------------------------------------------
846 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
850 m_captionFont
= wxScrolledWindow::GetFont();
852 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
853 m_subgroup_extramargin
= x
+ (x
/2);
856 #if wxPG_USE_RENDERER_NATIVE
857 m_iconWidth
= wxPG_ICON_WIDTH
;
858 #elif wxPG_ICON_WIDTH
860 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
861 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
862 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
866 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
867 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
868 m_gutterWidth
= wxPG_GUTTER_MIN
;
871 if ( vspacing
<= 1 ) vdiv
= 12;
872 else if ( vspacing
>= 3 ) vdiv
= 3;
874 m_spacingy
= m_fontHeight
/ vdiv
;
875 if ( m_spacingy
< wxPG_YSPACING_MIN
)
876 m_spacingy
= wxPG_YSPACING_MIN
;
879 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
880 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
882 m_captionFont
.SetWeight(wxBOLD
);
883 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
885 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
888 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
889 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
892 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
894 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
895 RecalculateVirtualSize();
897 InvalidateBestSize();
900 // -----------------------------------------------------------------------
902 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
908 // -----------------------------------------------------------------------
910 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
911 int ga
= 1000, int ba
= 1000,
912 bool forceDifferent
= false)
919 // Recursion guard (allow 2 max)
920 static int isinside
= 0;
922 wxCHECK_MSG( isinside
< 3,
924 wxT("wxPGAdjustColour should not be recursively called more than once") );
932 if ( r2
>255 ) r2
= 255;
933 else if ( r2
<0) r2
= 0;
935 if ( g2
>255 ) g2
= 255;
936 else if ( g2
<0) g2
= 0;
938 if ( b2
>255 ) b2
= 255;
939 else if ( b2
<0) b2
= 0;
941 // Make sure they are somewhat different
942 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
943 dst
= wxPGAdjustColour(src
,-(ra
*2));
945 dst
= wxColour(r2
,g2
,b2
);
947 // Recursion guard (allow 2 max)
954 static int wxPGGetColAvg( const wxColour
& col
)
956 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
960 void wxPropertyGrid::RegainColours()
962 if ( !(m_coloursCustomized
& 0x0002) )
964 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
966 // Make sure colour is dark enough
968 int colDec
= wxPGGetColAvg(col
) - 230;
970 int colDec
= wxPGGetColAvg(col
) - 200;
973 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
976 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
979 if ( !(m_coloursCustomized
& 0x0001) )
980 m_colMargin
= m_colCapBack
;
982 if ( !(m_coloursCustomized
& 0x0004) )
989 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
990 m_colCapFore
= capForeCol
;
991 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
994 if ( !(m_coloursCustomized
& 0x0008) )
996 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
997 m_colPropBack
= bgCol
;
998 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1001 if ( !(m_coloursCustomized
& 0x0010) )
1003 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1004 m_colPropFore
= fgCol
;
1005 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1008 if ( !(m_coloursCustomized
& 0x0020) )
1009 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1011 if ( !(m_coloursCustomized
& 0x0040) )
1012 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1014 if ( !(m_coloursCustomized
& 0x0080) )
1015 m_colLine
= m_colCapBack
;
1017 if ( !(m_coloursCustomized
& 0x0100) )
1018 m_colDisPropFore
= m_colCapFore
;
1020 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1023 // -----------------------------------------------------------------------
1025 void wxPropertyGrid::ResetColours()
1027 m_coloursCustomized
= 0;
1034 // -----------------------------------------------------------------------
1036 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1038 // Must disable active editor.
1039 ClearSelection(false);
1041 // TODO: Following code is disabled with wxMac because
1042 // it is reported to fail. I (JMS) cannot debug it
1043 // personally right now.
1044 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1045 #if 1 // !defined(__WXMAC__)
1046 bool res
= wxScrolledWindow::SetFont( font
);
1049 CalculateFontAndBitmapStuff( m_vspacing
);
1052 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1060 // TODO: Remove after SetFont crash fixed.
1061 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1063 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1069 // -----------------------------------------------------------------------
1071 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1074 m_coloursCustomized
|= 0x80;
1078 // -----------------------------------------------------------------------
1080 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1083 m_coloursCustomized
|= 0x01;
1087 // -----------------------------------------------------------------------
1089 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1091 m_colPropBack
= col
;
1092 m_coloursCustomized
|= 0x08;
1094 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1099 // -----------------------------------------------------------------------
1101 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1103 m_colPropFore
= col
;
1104 m_coloursCustomized
|= 0x10;
1106 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1111 // -----------------------------------------------------------------------
1113 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1115 m_colEmptySpace
= col
;
1120 // -----------------------------------------------------------------------
1122 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1124 m_colDisPropFore
= col
;
1125 m_coloursCustomized
|= 0x100;
1129 // -----------------------------------------------------------------------
1131 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1134 m_coloursCustomized
|= 0x20;
1138 // -----------------------------------------------------------------------
1140 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1143 m_coloursCustomized
|= 0x40;
1147 // -----------------------------------------------------------------------
1149 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1152 m_coloursCustomized
|= 0x02;
1154 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1159 // -----------------------------------------------------------------------
1161 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1164 m_coloursCustomized
|= 0x04;
1166 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1171 // -----------------------------------------------------------------------
1172 // wxPropertyGrid property adding and removal
1173 // -----------------------------------------------------------------------
1175 void wxPropertyGrid::PrepareAfterItemsAdded()
1177 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1179 m_pState
->m_itemsAdded
= 0;
1181 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1184 RecalculateVirtualSize();
1187 // -----------------------------------------------------------------------
1188 // wxPropertyGrid property value setting and getting
1189 // -----------------------------------------------------------------------
1191 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1193 m_pState
->DoSetPropertyValueUnspecified(p
);
1194 DrawItemAndChildren(p
);
1196 wxPGProperty
* parent
= p
->GetParent();
1198 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1201 parent
= parent
->GetParent();
1205 // -----------------------------------------------------------------------
1206 // wxPropertyGrid property operations
1207 // -----------------------------------------------------------------------
1209 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1211 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1215 bool changed
= false;
1217 // Is it inside collapsed section?
1218 if ( !p
->IsVisible() )
1221 wxPGProperty
* parent
= p
->GetParent();
1222 wxPGProperty
* grandparent
= parent
->GetParent();
1224 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1225 Expand( grandparent
);
1233 GetViewStart(&vx
,&vy
);
1234 vy
*=wxPG_PIXELS_PER_UNIT
;
1240 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1241 m_iFlags
|= wxPG_FL_SCROLLED
;
1244 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1246 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1247 m_iFlags
|= wxPG_FL_SCROLLED
;
1257 // -----------------------------------------------------------------------
1258 // wxPropertyGrid helper methods called by properties
1259 // -----------------------------------------------------------------------
1261 // Control font changer helper.
1262 void wxPropertyGrid::SetCurControlBoldFont()
1264 wxASSERT( m_wndEditor
);
1265 m_wndEditor
->SetFont( m_captionFont
);
1268 // -----------------------------------------------------------------------
1270 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1273 #if wxPG_SMALL_SCREEN
1274 // On small-screen devices, always show dialogs with default position and size.
1275 return wxDefaultPosition
;
1277 int splitterX
= GetSplitterPosition();
1281 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1283 ImprovedClientToScreen( &x
, &y
);
1285 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1286 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1293 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1303 new_y
= y
+ m_lineHeight
;
1305 return wxPoint(new_x
,new_y
);
1309 // -----------------------------------------------------------------------
1311 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1313 if ( src_str
.length() == 0 )
1319 bool prev_is_slash
= false;
1321 wxString::const_iterator i
= src_str
.begin();
1325 for ( ; i
!= src_str
.end(); ++i
)
1329 if ( a
!= wxS('\\') )
1331 if ( !prev_is_slash
)
1337 if ( a
== wxS('n') )
1340 dst_str
<< wxS('\n');
1342 dst_str
<< wxS('\n');
1345 else if ( a
== wxS('t') )
1346 dst_str
<< wxS('\t');
1350 prev_is_slash
= false;
1354 if ( prev_is_slash
)
1356 dst_str
<< wxS('\\');
1357 prev_is_slash
= false;
1361 prev_is_slash
= true;
1368 // -----------------------------------------------------------------------
1370 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1372 if ( src_str
.length() == 0 )
1378 wxString::const_iterator i
= src_str
.begin();
1379 wxUniChar prev_a
= wxS('\0');
1383 for ( ; i
!= src_str
.end(); ++i
)
1387 if ( a
>= wxS(' ') )
1389 // This surely is not something that requires an escape sequence.
1394 // This might need...
1395 if ( a
== wxS('\r') )
1397 // DOS style line end.
1398 // Already taken care below
1400 else if ( a
== wxS('\n') )
1401 // UNIX style line end.
1402 dst_str
<< wxS("\\n");
1403 else if ( a
== wxS('\t') )
1405 dst_str
<< wxS('\t');
1408 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1418 // -----------------------------------------------------------------------
1420 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1424 return (wxPGProperty
*) NULL
;
1427 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1430 // -----------------------------------------------------------------------
1431 // wxPropertyGrid graphics related methods
1432 // -----------------------------------------------------------------------
1434 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1438 // Update everything inside the box
1439 wxRect r
= GetUpdateRegion().GetBox();
1441 dc
.SetPen(m_colEmptySpace
);
1442 dc
.SetBrush(m_colEmptySpace
);
1443 dc
.DrawRectangle(r
);
1446 // -----------------------------------------------------------------------
1448 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1449 wxPGProperty
* property
) const
1451 // Prepare rectangle to be used
1453 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1454 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1456 #if (wxPG_USE_RENDERER_NATIVE)
1458 #elif wxPG_ICON_WIDTH
1459 // Drawing expand/collapse button manually
1460 dc
.SetPen(m_colPropFore
);
1461 if ( property
->IsCategory() )
1462 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1464 dc
.SetBrush(m_colPropBack
);
1466 dc
.DrawRectangle( r
);
1467 int _y
= r
.y
+(m_iconWidth
/2);
1468 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1473 if ( property
->IsExpanded() )
1475 // wxRenderer functions are non-mutating in nature, so it
1476 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1477 // Hopefully this does not cause problems.
1478 #if (wxPG_USE_RENDERER_NATIVE)
1479 wxRendererNative::Get().DrawTreeItemButton(
1485 #elif wxPG_ICON_WIDTH
1494 #if (wxPG_USE_RENDERER_NATIVE)
1495 wxRendererNative::Get().DrawTreeItemButton(
1501 #elif wxPG_ICON_WIDTH
1502 int _x
= r
.x
+(m_iconWidth
/2);
1503 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1509 #if (wxPG_USE_RENDERER_NATIVE)
1511 #elif wxPG_ICON_WIDTH
1514 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1518 // -----------------------------------------------------------------------
1521 // This is the one called by OnPaint event handler and others.
1522 // topy and bottomy are already unscrolled (ie. physical)
1524 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1526 unsigned int bottomy
,
1527 const wxRect
* clipRect
)
1529 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1531 m_pState
->EnsureVirtualHeight();
1533 wxRect tempClipRect
;
1536 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1537 clipRect
= &tempClipRect
;
1540 // items added check
1541 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1543 int paintFinishY
= 0;
1545 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1548 bool isBuffered
= false;
1550 #if wxPG_DOUBLE_BUFFER
1551 wxMemoryDC
* bufferDC
= NULL
;
1553 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1555 if ( !m_doubleBuffer
)
1557 paintFinishY
= clipRect
->y
;
1562 bufferDC
= new wxMemoryDC();
1564 // If nothing was changed, then just copy from double-buffer
1565 bufferDC
->SelectObject( *m_doubleBuffer
);
1575 dc
.SetClippingRegion( *clipRect
);
1576 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1579 #if wxPG_DOUBLE_BUFFER
1582 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1583 bufferDC
, 0, 0, wxCOPY
);
1584 dc
.DestroyClippingRegion(); // Is this really necessary?
1590 // Clear area beyond bottomY?
1591 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1593 dc
.SetPen(m_colEmptySpace
);
1594 dc
.SetBrush(m_colEmptySpace
);
1595 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1599 // -----------------------------------------------------------------------
1601 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1602 const wxPGProperty
* firstItem
,
1603 const wxPGProperty
* lastItem
,
1604 const wxRect
* clipRect
,
1605 bool isBuffered
) const
1607 // TODO: This should somehow be eliminated.
1608 wxRect tempClipRect
;
1611 wxASSERT(firstItem
);
1613 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1614 clipRect
= &tempClipRect
;
1618 firstItem
= DoGetItemAtY(clipRect
->y
);
1622 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1624 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1627 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1630 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1631 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1633 int lh
= m_lineHeight
;
1636 int lastItemBottomY
;
1638 firstItemTopY
= clipRect
->y
;
1639 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1641 // Align y coordinates to item boundaries
1642 firstItemTopY
-= firstItemTopY
% lh
;
1643 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1644 lastItemBottomY
-= 1;
1646 // Entire range outside scrolled, visible area?
1647 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1650 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1654 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1655 firstItem->GetLabel().c_str(),
1656 lastItem->GetLabel().c_str(),
1657 (int)(lastItemBottomY - firstItemTopY),
1659 (unsigned long)clipRect );
1664 long windowStyle
= m_windowStyle
;
1670 // With wxPG_DOUBLE_BUFFER, do double buffering
1671 // - buffer's y = 0, so align cliprect and coordinates to that
1673 #if wxPG_DOUBLE_BUFFER
1679 xRelMod
= clipRect
->x
;
1680 yRelMod
= clipRect
->y
;
1683 // clipRect conversion
1688 firstItemTopY
-= yRelMod
;
1689 lastItemBottomY
-= yRelMod
;
1692 wxUnusedVar(isBuffered
);
1695 int x
= m_marginWidth
- xRelMod
;
1697 const wxFont
& normalfont
= m_font
;
1699 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1701 bool isEnabled
= IsEnabled();
1704 // Prepare some pens and brushes that are often changed to.
1707 wxBrush
marginBrush(m_colMargin
);
1708 wxPen
marginPen(m_colMargin
);
1709 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1710 wxPen
linepen(m_colLine
,1,wxSOLID
);
1712 // pen that has same colour as text
1713 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1716 // Clear margin with background colour
1718 dc
.SetBrush( marginBrush
);
1719 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1721 dc
.SetPen( *wxTRANSPARENT_PEN
);
1722 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1725 const wxPGProperty
* selected
= m_selected
;
1726 const wxPropertyGridPageState
* state
= m_pState
;
1728 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1729 bool wasSelectedPainted
= false;
1732 // TODO: Only render columns that are within clipping region.
1734 dc
.SetFont(normalfont
);
1736 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1737 int endScanBottomY
= lastItemBottomY
+ lh
;
1738 int y
= firstItemTopY
;
1741 // Pregenerate list of visible properties.
1742 wxArrayPGProperty visPropArray
;
1743 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1745 for ( ; !it
.AtEnd(); it
.Next() )
1747 const wxPGProperty
* p
= *it
;
1749 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1751 visPropArray
.push_back((wxPGProperty
*)p
);
1753 if ( y
> endScanBottomY
)
1760 visPropArray
.push_back(NULL
);
1762 wxPGProperty
* nextP
= visPropArray
[0];
1764 int gridWidth
= state
->m_width
;
1767 for ( unsigned int arrInd
=1;
1768 nextP
&& y
<= lastItemBottomY
;
1771 wxPGProperty
* p
= nextP
;
1772 nextP
= visPropArray
[arrInd
];
1774 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1775 int textMarginHere
= x
;
1776 int renderFlags
= 0;
1778 int greyDepth
= m_marginWidth
;
1779 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1780 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1782 int greyDepthX
= greyDepth
- xRelMod
;
1784 // Use basic depth if in non-categoric mode and parent is base array.
1785 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1787 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1790 // Paint margin area
1791 dc
.SetBrush(marginBrush
);
1792 dc
.SetPen(marginPen
);
1793 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1795 dc
.SetPen( linepen
);
1800 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1806 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1808 sx
+= state
->m_colWidths
[si
];
1809 dc
.DrawLine( sx
, y
, sx
, y2
);
1812 // Horizontal Line, below
1813 // (not if both this and next is category caption)
1814 if ( p
->IsCategory() &&
1815 nextP
&& nextP
->IsCategory() )
1816 dc
.SetPen(m_colCapBack
);
1818 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1821 // Need to override row colours?
1825 if ( p
!= selected
)
1827 // Disabled may get different colour.
1828 if ( !p
->IsEnabled() )
1830 renderFlags
|= wxPGCellRenderer::Disabled
|
1831 wxPGCellRenderer::DontUseCellFgCol
;
1832 rowFgCol
= m_colDisPropFore
;
1837 renderFlags
|= wxPGCellRenderer::Selected
;
1839 if ( !p
->IsCategory() )
1841 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1842 wxPGCellRenderer::DontUseCellBgCol
;
1844 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1845 wasSelectedPainted
= true;
1848 // Selected gets different colour.
1849 if ( reallyFocused
)
1851 rowFgCol
= m_colSelFore
;
1852 rowBgCol
= m_colSelBack
;
1854 else if ( isEnabled
)
1856 rowFgCol
= m_colPropFore
;
1857 rowBgCol
= m_colMargin
;
1861 rowFgCol
= m_colDisPropFore
;
1862 rowBgCol
= m_colSelBack
;
1869 if ( rowBgCol
.IsOk() )
1870 rowBgBrush
= wxBrush(rowBgCol
);
1872 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1873 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1876 // Fill additional margin area with background colour of first cell
1877 if ( greyDepthX
< textMarginHere
)
1879 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1881 wxPGCell
& cell
= p
->GetCell(0);
1882 rowBgCol
= cell
.GetBgCol();
1883 rowBgBrush
= wxBrush(rowBgCol
);
1885 dc
.SetBrush(rowBgBrush
);
1886 dc
.SetPen(rowBgCol
);
1887 dc
.DrawRectangle(greyDepthX
+1, y
,
1888 textMarginHere
-greyDepthX
, lh
-1);
1891 bool fontChanged
= false;
1893 // Expander button rectangle
1894 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1899 if ( p
->IsCategory() )
1901 // Captions have their cell areas merged as one
1902 dc
.SetFont(m_captionFont
);
1904 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1906 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1908 dc
.SetBrush(rowBgBrush
);
1909 dc
.SetPen(rowBgCol
);
1912 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1914 dc
.SetTextForeground(rowFgCol
);
1917 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1918 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1921 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1922 DrawExpanderButton( dc
, butRect
, p
);
1926 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1928 dc
.SetFont(m_captionFont
);
1934 int nextCellWidth
= state
->m_colWidths
[0];
1935 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1936 int textXAdd
= textMarginHere
- greyDepthX
;
1938 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1940 cellRect
.width
= nextCellWidth
- 1;
1942 bool ctrlCell
= false;
1943 int cellRenderFlags
= renderFlags
;
1946 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1947 DrawExpanderButton( dc
, butRect
, p
);
1950 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1952 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1953 dc
.SetBrush(editorBgCol
);
1954 dc
.SetPen(editorBgCol
);
1955 dc
.SetTextForeground(m_colPropFore
);
1956 dc
.DrawRectangle(cellRect
);
1958 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1963 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1965 dc
.SetBrush(rowBgBrush
);
1966 dc
.SetPen(rowBgCol
);
1969 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1971 dc
.SetTextForeground(rowFgCol
);
1975 dc
.SetClippingRegion(cellRect
);
1977 cellRect
.x
+= textXAdd
;
1978 cellRect
.width
-= textXAdd
;
1983 wxPGCellRenderer
* renderer
;
1984 int cmnVal
= p
->GetCommonValue();
1985 if ( cmnVal
== -1 || ci
!= 1 )
1987 renderer
= p
->GetCellRenderer(ci
);
1988 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1993 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1994 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1999 cellX
+= state
->m_colWidths
[ci
];
2000 if ( ci
< (state
->m_colWidths
.size()-1) )
2001 nextCellWidth
= state
->m_colWidths
[ci
+1];
2003 dc
.DestroyClippingRegion(); // Is this really necessary?
2009 dc
.SetFont(normalfont
);
2014 // Refresh editor controls (seems not needed on msw)
2015 // NOTE: This code is mandatory for GTK!
2016 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2017 if ( wasSelectedPainted
)
2020 m_wndEditor
->Refresh();
2022 m_wndEditor2
->Refresh();
2029 // -----------------------------------------------------------------------
2031 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2035 if ( m_width
< 10 || m_height
< 10 ||
2036 !m_pState
->m_properties
->GetChildCount() ||
2037 p1
== (wxPGProperty
*) NULL
)
2038 return wxRect(0,0,0,0);
2043 // Return rect which encloses the given property range
2045 int visTop
= p1
->GetY();
2048 visBottom
= p2
->GetY() + m_lineHeight
;
2050 visBottom
= m_height
+ visTop
;
2052 // If seleced property is inside the range, we'll extend the range to include
2054 wxPGProperty
* selected
= m_selected
;
2057 int selectedY
= selected
->GetY();
2058 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2060 wxWindow
* editor
= GetEditorControl();
2063 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2064 if ( visBottom2
> visBottom
)
2065 visBottom
= visBottom2
;
2070 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2073 // -----------------------------------------------------------------------
2075 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2080 if ( m_pState
->m_itemsAdded
)
2081 PrepareAfterItemsAdded();
2083 wxRect r
= GetPropertyRect(p1
, p2
);
2086 m_canvas
->RefreshRect(r
);
2090 // -----------------------------------------------------------------------
2092 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2094 if ( p
== m_selected
)
2095 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2097 DrawItemAndChildren(p
);
2100 // -----------------------------------------------------------------------
2102 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2107 // Draw item, children, and parent too, if it is not category
2108 wxPGProperty
* parent
= p
->GetParent();
2111 !parent
->IsCategory() &&
2112 parent
->GetParent() )
2115 parent
= parent
->GetParent();
2118 DrawItemAndChildren(p
);
2121 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2123 wxCHECK_RET( p
, wxT("invalid property id") );
2125 // Do not draw if in non-visible page
2126 if ( p
->GetParentState() != m_pState
)
2129 // do not draw a single item if multiple pending
2130 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2133 wxWindow
* wndPrimary
= GetEditorControl();
2135 // Update child control.
2136 if ( m_selected
&& m_selected
->GetParent() == p
)
2137 m_selected
->UpdateControl(wndPrimary
);
2139 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2141 DrawItems(p
, lastDrawn
);
2144 // -----------------------------------------------------------------------
2146 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2147 const wxRect
*rect
)
2149 PrepareAfterItemsAdded();
2151 wxWindow::Refresh(false);
2153 // TODO: Coordinate translation
2154 m_canvas
->Refresh(false, rect
);
2156 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2157 // I think this really helps only GTK+1.2
2158 if ( m_wndEditor
) m_wndEditor
->Refresh();
2159 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2163 // -----------------------------------------------------------------------
2164 // wxPropertyGrid global operations
2165 // -----------------------------------------------------------------------
2167 void wxPropertyGrid::Clear()
2169 ClearSelection(false);
2171 m_pState
->DoClear();
2177 RecalculateVirtualSize();
2179 // Need to clear some area at the end
2181 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2184 // -----------------------------------------------------------------------
2186 bool wxPropertyGrid::EnableCategories( bool enable
)
2188 ClearSelection(false);
2193 // Enable categories
2196 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2201 // Disable categories
2203 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2206 if ( !m_pState
->EnableCategories(enable
) )
2211 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2213 m_pState
->m_itemsAdded
= 1; // force
2214 PrepareAfterItemsAdded();
2218 m_pState
->m_itemsAdded
= 1;
2220 // No need for RecalculateVirtualSize() here - it is already called in
2221 // wxPropertyGridPageState method above.
2228 // -----------------------------------------------------------------------
2230 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2232 wxASSERT( pNewState
);
2233 wxASSERT( pNewState
->GetGrid() );
2235 if ( pNewState
== m_pState
)
2238 wxPGProperty
* oldSelection
= m_selected
;
2240 ClearSelection(false);
2242 m_pState
->m_selected
= oldSelection
;
2244 bool orig_mode
= m_pState
->IsInNonCatMode();
2245 bool new_state_mode
= pNewState
->IsInNonCatMode();
2247 m_pState
= pNewState
;
2250 int pgWidth
= GetClientSize().x
;
2251 if ( HasVirtualWidth() )
2253 int minWidth
= pgWidth
;
2254 if ( pNewState
->m_width
< minWidth
)
2256 pNewState
->m_width
= minWidth
;
2257 pNewState
->CheckColumnWidths();
2263 // Just in case, fully re-center splitter
2264 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2265 pNewState
->m_fSplitterX
= -1.0;
2267 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2270 m_propHover
= (wxPGProperty
*) NULL
;
2272 // If necessary, convert state to correct mode.
2273 if ( orig_mode
!= new_state_mode
)
2275 // This should refresh as well.
2276 EnableCategories( orig_mode
?false:true );
2278 else if ( !m_frozen
)
2280 // Refresh, if not frozen.
2281 if ( m_pState
->m_itemsAdded
)
2282 PrepareAfterItemsAdded();
2285 if ( m_pState
->m_selected
)
2286 DoSelectProperty( m_pState
->m_selected
);
2288 RecalculateVirtualSize(0);
2292 m_pState
->m_itemsAdded
= 1;
2295 // -----------------------------------------------------------------------
2297 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2299 wxPG_PROP_ARG_CALL_PROLOG()
2301 m_pState
->SortChildren( p
);
2304 // -----------------------------------------------------------------------
2306 void wxPropertyGrid::Sort()
2308 ClearSelection(false); // This must be before state clear
2313 // -----------------------------------------------------------------------
2315 // Call to SetSplitterPosition will always disable splitter auto-centering
2316 // if parent window is shown.
2317 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2319 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2322 wxPropertyGridPageState
* state
= m_pState
;
2324 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2329 CorrectEditorWidgetSizeX();
2335 // -----------------------------------------------------------------------
2337 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2339 SetSplitterPosition( m_width
/2, true );
2340 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2341 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2344 // -----------------------------------------------------------------------
2345 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2346 // -----------------------------------------------------------------------
2348 // Returns nearest paint visible property (such that will be painted unless
2349 // window is scrolled or resized). If given property is paint visible, then
2350 // it itself will be returned
2351 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2353 int vx
,vy1
;// Top left corner of client
2354 GetViewStart(&vx
,&vy1
);
2355 vy1
*= wxPG_PIXELS_PER_UNIT
;
2357 int vy2
= vy1
+ m_height
;
2358 int propY
= p
->GetY2(m_lineHeight
);
2360 if ( (propY
+ m_lineHeight
) < vy1
)
2363 return DoGetItemAtY( vy1
);
2365 else if ( propY
> vy2
)
2368 return DoGetItemAtY( vy2
);
2371 // Itself paint visible
2376 // -----------------------------------------------------------------------
2377 // Methods related to change in value, value modification and sending events
2378 // -----------------------------------------------------------------------
2380 // commits any changes in editor of selected property
2381 // return true if validation did not fail
2382 // flags are same as with DoSelectProperty
2383 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2385 // Committing already?
2386 if ( m_inCommitChangesFromEditor
)
2389 // Don't do this if already processing editor event. It might
2390 // induce recursive dialogs and crap like that.
2391 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2393 if ( m_inDoPropertyChanged
)
2400 IsEditorsValueModified() &&
2401 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2404 m_inCommitChangesFromEditor
= 1;
2406 wxVariant
variant(m_selected
->GetValueRef());
2407 bool valueIsPending
= false;
2409 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2410 // due to another window getting focus
2411 wxWindow
* oldFocus
= m_curFocused
;
2413 bool validationFailure
= false;
2414 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2416 m_chgInfo_changedProperty
= NULL
;
2418 // If truly modified, schedule value as pending.
2419 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2421 if ( DoEditorValidate() &&
2422 PerformValidation(m_selected
, variant
) )
2424 valueIsPending
= true;
2428 validationFailure
= true;
2433 EditorsValueWasNotModified();
2438 m_inCommitChangesFromEditor
= 0;
2440 if ( validationFailure
&& !forceSuccess
)
2444 oldFocus
->SetFocus();
2445 m_curFocused
= oldFocus
;
2448 res
= OnValidationFailure(m_selected
, variant
);
2450 // Now prevent further validation failure messages
2453 EditorsValueWasNotModified();
2454 OnValidationFailureReset(m_selected
);
2457 else if ( valueIsPending
)
2459 DoPropertyChanged( m_selected
, flags
);
2460 EditorsValueWasNotModified();
2469 // -----------------------------------------------------------------------
2471 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2475 // Runs all validation functionality.
2476 // Returns true if value passes all tests.
2479 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2481 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2483 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2488 // Adapt list to child values, if necessary
2489 wxVariant listValue
= pendingValue
;
2490 wxVariant
* pPendingValue
= &pendingValue
;
2491 wxVariant
* pList
= NULL
;
2493 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2494 // string value, then we need treat as it was changed instead
2495 // (or, in addition, as is the case with composite string parent).
2496 // This includes creating list variant for child values.
2498 wxPGProperty
* pwc
= p
->GetParent();
2499 wxPGProperty
* changedProperty
= p
;
2500 wxPGProperty
* baseChangedProperty
= changedProperty
;
2501 wxVariant bcpPendingList
;
2503 listValue
= pendingValue
;
2504 listValue
.SetName(p
->GetBaseName());
2507 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2509 wxVariantList tempList
;
2510 wxVariant
lv(tempList
, pwc
->GetBaseName());
2511 lv
.Append(listValue
);
2513 pPendingValue
= &listValue
;
2515 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2517 baseChangedProperty
= pwc
;
2518 bcpPendingList
= lv
;
2521 changedProperty
= pwc
;
2522 pwc
= pwc
->GetParent();
2526 wxPGProperty
* evtChangingProperty
= changedProperty
;
2528 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2530 value
= *pPendingValue
;
2534 // Convert list to child values
2535 pList
= pPendingValue
;
2536 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2539 wxVariant evtChangingValue
= value
;
2541 if ( flags
& SendEvtChanging
)
2543 // FIXME: After proper ValueToString()s added, remove
2544 // this. It is just a temporary fix, as evt_changing
2545 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2546 // (unless it is selected, and textctrl editor is open).
2547 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2549 evtChangingProperty
= baseChangedProperty
;
2550 if ( evtChangingProperty
!= p
)
2552 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2556 evtChangingValue
= pendingValue
;
2560 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2562 if ( changedProperty
== m_selected
)
2564 wxWindow
* editor
= GetEditorControl();
2565 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2566 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2570 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2575 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2576 m_chgInfo_changedProperty
= changedProperty
;
2577 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2578 m_chgInfo_pendingValue
= value
;
2581 m_chgInfo_valueList
= *pList
;
2583 m_chgInfo_valueList
.MakeNull();
2585 // If changedProperty is not property which value was edited,
2586 // then call wxPGProperty::ValidateValue() for that as well.
2587 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2589 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2593 if ( flags
& SendEvtChanging
)
2595 // SendEvent returns true if event was vetoed
2596 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2600 if ( flags
& IsStandaloneValidation
)
2602 // If called in 'generic' context, we need to reset
2603 // m_chgInfo_changedProperty and write back translated value.
2604 m_chgInfo_changedProperty
= NULL
;
2605 pendingValue
= value
;
2611 // -----------------------------------------------------------------------
2613 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2615 if ( !msg
.length() )
2619 if ( !wxPGGlobalVars
->m_offline
)
2621 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2624 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2627 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2630 pStatusBar
->SetStatusText(msg
);
2638 ::wxMessageBox(msg
, _T("Property Error"));
2641 // -----------------------------------------------------------------------
2643 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2645 int vfb
= m_validationInfo
.m_failureBehavior
;
2647 if ( vfb
& wxPG_VFB_BEEP
)
2650 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2651 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2653 unsigned int colCount
= m_pState
->GetColumnCount();
2655 // We need backup marked property's cells
2656 m_propCellsBackup
= property
->m_cells
;
2658 wxColour vfbFg
= *wxWHITE
;
2659 wxColour vfbBg
= *wxRED
;
2661 property
->EnsureCells(colCount
);
2663 for ( unsigned int i
=0; i
<colCount
; i
++ )
2665 wxPGCell
& cell
= property
->m_cells
[i
];
2666 cell
.SetFgCol(vfbFg
);
2667 cell
.SetBgCol(vfbBg
);
2670 DrawItemAndChildren(property
);
2672 if ( property
== m_selected
)
2674 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2676 wxWindow
* editor
= GetEditorControl();
2679 editor
->SetForegroundColour(vfbFg
);
2680 editor
->SetBackgroundColour(vfbBg
);
2685 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2687 wxString msg
= m_validationInfo
.m_failureMessage
;
2689 if ( !msg
.length() )
2690 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2692 DoShowPropertyError(property
, msg
);
2695 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2698 // -----------------------------------------------------------------------
2700 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2702 int vfb
= m_validationInfo
.m_failureBehavior
;
2704 if ( vfb
& wxPG_VFB_MARK_CELL
)
2707 property
->m_cells
= m_propCellsBackup
;
2709 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2711 if ( property
== m_selected
&& GetEditorControl() )
2713 // Calling this will recreate the control, thus resetting its colour
2714 RefreshProperty(property
);
2718 DrawItemAndChildren(property
);
2723 // -----------------------------------------------------------------------
2725 // flags are same as with DoSelectProperty
2726 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2728 if ( m_inDoPropertyChanged
)
2731 wxWindow
* editor
= GetEditorControl();
2733 m_pState
->m_anyModified
= 1;
2735 m_inDoPropertyChanged
= 1;
2737 // Maybe need to update control
2738 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2740 // These values were calculated in PerformValidation()
2741 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2742 wxVariant value
= m_chgInfo_pendingValue
;
2744 wxPGProperty
* topPaintedProperty
= changedProperty
;
2746 while ( !topPaintedProperty
->IsCategory() &&
2747 !topPaintedProperty
->IsRoot() )
2749 topPaintedProperty
= topPaintedProperty
->GetParent();
2752 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2754 // Set as Modified (not if dragging just began)
2755 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2757 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2758 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2761 SetCurControlBoldFont();
2767 // Propagate updates to parent(s)
2769 wxPGProperty
* prevPwc
= NULL
;
2771 while ( prevPwc
!= topPaintedProperty
)
2773 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2775 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2778 SetCurControlBoldFont();
2782 pwc
= pwc
->GetParent();
2785 // Draw the actual property
2786 DrawItemAndChildren( topPaintedProperty
);
2789 // If value was set by wxPGProperty::OnEvent, then update the editor
2791 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2794 p
->GetEditorClass()->UpdateControl(p
, editor
);
2798 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2799 if ( m_wndEditor
) m_wndEditor
->Refresh();
2800 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2805 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2807 // If top parent has composite string value, then send to child parents,
2808 // starting from baseChangedProperty.
2809 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2811 pwc
= m_chgInfo_baseChangedProperty
;
2813 while ( pwc
!= changedProperty
)
2815 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2816 pwc
= pwc
->GetParent();
2820 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2822 m_inDoPropertyChanged
= 0;
2827 // -----------------------------------------------------------------------
2829 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2831 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2833 m_chgInfo_changedProperty
= NULL
;
2835 if ( PerformValidation(p
, newValue
) )
2837 DoPropertyChanged(p
);
2842 OnValidationFailure(p
, newValue
);
2848 // -----------------------------------------------------------------------
2850 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2852 wxPGProperty
* prop
= GetSelectedProperty();
2855 return wxNullVariant
;
2857 wxTextCtrl
* tc
= GetEditorTextCtrl();
2858 wxVariant value
= prop
->GetValue();
2860 if ( !tc
|| !IsEditorsValueModified() )
2863 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2866 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2867 return prop
->GetValue();
2872 // -----------------------------------------------------------------------
2874 // Runs wxValidator for the selected property
2875 bool wxPropertyGrid::DoEditorValidate()
2880 // -----------------------------------------------------------------------
2882 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2884 wxPGProperty
* selected
= m_selected
;
2886 // Somehow, event is handled after property has been deselected.
2887 // Possibly, but very rare.
2891 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2894 wxVariant
pendingValue(selected
->GetValueRef());
2895 wxWindow
* wnd
= GetEditorControl();
2897 bool wasUnspecified
= selected
->IsValueUnspecified();
2898 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2900 bool valueIsPending
= false;
2902 m_chgInfo_changedProperty
= NULL
;
2904 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2907 // Filter out excess wxTextCtrl modified events
2908 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2910 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2912 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2914 wxString newTcValue
= tc
->GetValue();
2915 if ( m_prevTcValue
== newTcValue
)
2918 m_prevTcValue
= newTcValue
;
2921 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2923 bool validationFailure
= false;
2924 bool buttonWasHandled
= false;
2927 // Try common button handling
2928 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2930 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2934 buttonWasHandled
= true;
2935 // Store as res2, as previously (and still currently alternatively)
2936 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2937 // in wxPGProperty::OnEvent().
2938 adapter
->ShowDialog( this, selected
);
2943 if ( !buttonWasHandled
)
2947 // First call editor class' event handler.
2948 const wxPGEditor
* editor
= selected
->GetEditorClass();
2950 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2952 // If changes, validate them
2953 if ( DoEditorValidate() )
2955 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2956 valueIsPending
= true;
2960 validationFailure
= true;
2965 // Then the property's custom handler (must be always called, unless
2966 // validation failed).
2967 if ( !validationFailure
)
2968 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2971 // SetValueInEvent(), as called in one of the functions referred above
2972 // overrides editor's value.
2973 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2975 valueIsPending
= true;
2976 pendingValue
= m_changeInEventValue
;
2977 selFlags
|= wxPG_SEL_DIALOGVAL
;
2980 if ( !validationFailure
&& valueIsPending
)
2981 if ( !PerformValidation(m_selected
, pendingValue
) )
2982 validationFailure
= true;
2984 if ( validationFailure
)
2986 OnValidationFailure(selected
, pendingValue
);
2988 else if ( valueIsPending
)
2990 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2992 DoPropertyChanged(selected
, selFlags
);
2993 EditorsValueWasNotModified();
2995 // Regardless of editor type, unfocus editor on
2996 // text-editing related enter press.
2997 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3004 // No value after all
3006 // Regardless of editor type, unfocus editor on
3007 // text-editing related enter press.
3008 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3013 // Let unhandled button click events go to the parent
3014 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3016 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3017 GetEventHandler()->AddPendingEvent(evt
);
3021 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3024 // -----------------------------------------------------------------------
3025 // wxPropertyGrid editor control helper methods
3026 // -----------------------------------------------------------------------
3028 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3030 int itemy
= p
->GetY2(m_lineHeight
);
3032 int cust_img_space
= 0;
3033 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3034 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3036 // TODO: If custom image detection changes from current, change this.
3037 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3039 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3040 int imwid
= p
->OnMeasureImage().x
;
3041 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3042 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3047 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3049 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3054 // -----------------------------------------------------------------------
3056 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3058 wxSize sz
= GetImageSize(p
, item
);
3059 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3060 wxPG_CUSTOM_IMAGE_SPACINGY
,
3065 // return size of custom paint image
3066 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3068 // If called with NULL property, then return default image
3069 // size for properties that use image.
3071 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3073 wxSize cis
= p
->OnMeasureImage(item
);
3075 int choiceCount
= p
->m_choices
.GetCount();
3076 int comVals
= p
->GetDisplayedCommonValueCount();
3077 if ( item
>= choiceCount
&& comVals
> 0 )
3079 unsigned int cvi
= item
-choiceCount
;
3080 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3082 else if ( item
>= 0 && choiceCount
== 0 )
3083 return wxSize(0, 0);
3088 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3093 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3100 // -----------------------------------------------------------------------
3102 // takes scrolling into account
3103 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3106 GetViewStart(&vx
,&vy
);
3107 vy
*=wxPG_PIXELS_PER_UNIT
;
3108 vx
*=wxPG_PIXELS_PER_UNIT
;
3111 ClientToScreen( px
, py
);
3114 // -----------------------------------------------------------------------
3116 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3119 GetViewStart(&pt2
.x
,&pt2
.y
);
3120 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3121 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3125 return m_pState
->HitTest(pt2
);
3128 // -----------------------------------------------------------------------
3130 // custom set cursor
3131 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3133 if ( type
== m_curcursor
&& !override
) return;
3135 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3137 if ( type
== wxCURSOR_SIZEWE
)
3138 cursor
= m_cursorSizeWE
;
3140 m_canvas
->SetCursor( *cursor
);
3145 // -----------------------------------------------------------------------
3146 // wxPropertyGrid property selection, editor creation
3147 // -----------------------------------------------------------------------
3150 // This class forwards events from property editor controls to wxPropertyGrid.
3151 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3154 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3155 : wxEvtHandler(), m_propGrid(propGrid
)
3159 virtual ~wxPropertyGridEditorEventForwarder()
3164 bool ProcessEvent( wxEvent
& event
)
3169 m_propGrid
->HandleCustomEditorEvent(event
);
3171 return wxEvtHandler::ProcessEvent(event
);
3174 wxPropertyGrid
* m_propGrid
;
3177 // Setups event handling for child control
3178 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3180 wxWindowID id
= argWnd
->GetId();
3182 if ( argWnd
== m_wndEditor
)
3184 argWnd
->Connect(id
, wxEVT_MOTION
,
3185 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3187 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3188 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3190 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3191 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3193 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3194 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3196 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3197 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3199 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3200 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3204 wxPropertyGridEditorEventForwarder
* forwarder
;
3205 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3206 argWnd
->PushEventHandler(forwarder
);
3208 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3209 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3213 void wxPropertyGrid::FreeEditors()
3216 // Return focus back to canvas from children (this is required at least for
3217 // GTK+, which, unlike Windows, clears focus when control is destroyed
3218 // instead of moving it to closest parent).
3219 wxWindow
* focus
= wxWindow::FindFocus();
3222 wxWindow
* parent
= focus
->GetParent();
3225 if ( parent
== m_canvas
)
3230 parent
= parent
->GetParent();
3234 // Do not free editors immediately if processing events
3237 m_wndEditor2
->PopEventHandler(true);
3238 m_wndEditor2
->Hide();
3239 wxPendingDelete
.Append( m_wndEditor2
);
3240 m_wndEditor2
= (wxWindow
*) NULL
;
3245 m_wndEditor
->PopEventHandler(true);
3246 m_wndEditor
->Hide();
3247 wxPendingDelete
.Append( m_wndEditor
);
3248 m_wndEditor
= (wxWindow
*) NULL
;
3252 // Call with NULL to de-select property
3253 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3257 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3258 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3260 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3263 if ( m_inDoSelectProperty
)
3266 m_inDoSelectProperty
= 1;
3268 wxPGProperty
* prev
= m_selected
;
3272 m_inDoSelectProperty
= 0;
3278 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3280 wxPrintf( "None selected\n" );
3283 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3285 wxPrintf( "P = NULL\n" );
3288 // If we are frozen, then just set the values.
3291 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3292 m_editorFocused
= 0;
3295 m_pState
->m_selected
= p
;
3297 // If frozen, always free controls. But don't worry, as Thaw will
3298 // recall SelectProperty to recreate them.
3301 // Prevent any further selection measures in this call
3302 p
= (wxPGProperty
*) NULL
;
3307 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3309 // Only set focus if not deselecting
3312 if ( flags
& wxPG_SEL_FOCUS
)
3316 m_wndEditor
->SetFocus();
3317 m_editorFocused
= 1;
3326 m_inDoSelectProperty
= 0;
3331 // First, deactivate previous
3335 OnValidationFailureReset(m_selected
);
3337 // Must double-check if this is an selected in case of forceswitch
3340 if ( !CommitChangesFromEditor(flags
) )
3342 // Validation has failed, so we can't exit the previous editor
3343 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3344 // _("Invalid Value"),wxOK|wxICON_ERROR);
3345 m_inDoSelectProperty
= 0;
3353 m_selected
= (wxPGProperty
*) NULL
;
3354 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3356 // We need to always fully refresh the grid here
3359 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3360 EditorsValueWasNotModified();
3363 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3366 // Then, activate the one given.
3369 int propY
= p
->GetY2(m_lineHeight
);
3371 int splitterX
= GetSplitterPosition();
3372 m_editorFocused
= 0;
3374 m_pState
->m_selected
= p
;
3375 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3377 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3379 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3382 // Only create editor for non-disabled non-caption
3383 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3385 // do this for non-caption items
3389 // Do we need to paint the custom image, if any?
3390 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3391 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3392 !p
->GetEditorClass()->CanContainCustomImage()
3394 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3396 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3397 wxPoint goodPos
= grect
.GetPosition();
3398 #if wxPG_CREATE_CONTROLS_HIDDEN
3399 int coord_adjust
= m_height
- goodPos
.y
;
3400 goodPos
.y
+= coord_adjust
;
3403 const wxPGEditor
* editor
= p
->GetEditorClass();
3404 wxCHECK_MSG(editor
, false,
3405 wxT("NULL editor class not allowed"));
3407 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3409 wxPGWindowList wndList
= editor
->CreateControls(this,
3414 m_wndEditor
= wndList
.m_primary
;
3415 m_wndEditor2
= wndList
.m_secondary
;
3416 wxWindow
* primaryCtrl
= GetEditorControl();
3419 // Essentially, primaryCtrl == m_wndEditor
3422 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3423 // value is drawn as normal, and m_wndEditor2 is assumed
3424 // to be a right-aligned button that triggers a separate editorCtrl
3429 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3430 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3432 // Set validator, if any
3433 #if wxUSE_VALIDATORS
3434 wxValidator
* validator
= p
->GetValidator();
3436 primaryCtrl
->SetValidator(*validator
);
3439 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3440 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3442 // If it has modified status, use bold font
3443 // (must be done before capturing m_ctrlXAdjust)
3444 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3445 SetCurControlBoldFont();
3448 // Fix TextCtrl indentation
3449 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3450 wxTextCtrl
* tc
= NULL
;
3451 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3452 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3454 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3456 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3459 // Store x relative to splitter (we'll need it).
3460 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3462 // Check if background clear is not necessary
3463 wxPoint pos
= m_wndEditor
->GetPosition();
3464 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3466 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3469 m_wndEditor
->SetSizeHints(3, 3);
3471 #if wxPG_CREATE_CONTROLS_HIDDEN
3472 m_wndEditor
->Show(false);
3473 m_wndEditor
->Freeze();
3475 goodPos
= m_wndEditor
->GetPosition();
3476 goodPos
.y
-= coord_adjust
;
3477 m_wndEditor
->Move( goodPos
);
3480 SetupChildEventHandling(primaryCtrl
);
3482 // Focus and select all (wxTextCtrl, wxComboBox etc)
3483 if ( flags
& wxPG_SEL_FOCUS
)
3485 primaryCtrl
->SetFocus();
3487 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3493 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3494 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3496 // Get proper id for wndSecondary
3497 m_wndSecId
= m_wndEditor2
->GetId();
3498 wxWindowList children
= m_wndEditor2
->GetChildren();
3499 wxWindowList::iterator node
= children
.begin();
3500 if ( node
!= children
.end() )
3501 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3503 m_wndEditor2
->SetSizeHints(3,3);
3505 #if wxPG_CREATE_CONTROLS_HIDDEN
3506 wxRect sec_rect
= m_wndEditor2
->GetRect();
3507 sec_rect
.y
-= coord_adjust
;
3509 // Fine tuning required to fix "oversized"
3510 // button disappearance bug.
3511 if ( sec_rect
.y
< 0 )
3513 sec_rect
.height
+= sec_rect
.y
;
3516 m_wndEditor2
->SetSize( sec_rect
);
3518 m_wndEditor2
->Show();
3520 SetupChildEventHandling(m_wndEditor2
);
3522 // If no primary editor, focus to button to allow
3523 // it to interprete ENTER etc.
3524 // NOTE: Due to problems focusing away from it, this
3525 // has been disabled.
3527 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3528 m_wndEditor2->SetFocus();
3532 if ( flags
& wxPG_SEL_FOCUS
)
3533 m_editorFocused
= 1;
3538 // Make sure focus is in grid canvas (important for wxGTK, at least)
3542 EditorsValueWasNotModified();
3544 // If it's inside collapsed section, expand parent, scroll, etc.
3545 // Also, if it was partially visible, scroll it into view.
3546 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3551 #if wxPG_CREATE_CONTROLS_HIDDEN
3552 m_wndEditor
->Thaw();
3554 m_wndEditor
->Show(true);
3561 // Make sure focus is in grid canvas
3565 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3571 // Show help text in status bar.
3572 // (if found and grid not embedded in manager with help box and
3573 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3576 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3578 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3579 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3581 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3583 statusbar
= frame
->GetStatusBar();
3588 const wxString
* pHelpString
= (const wxString
*) NULL
;
3592 pHelpString
= &p
->GetHelpString();
3593 if ( pHelpString
->length() )
3595 // Set help box text.
3596 statusbar
->SetStatusText( *pHelpString
);
3597 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3601 if ( (!pHelpString
|| !pHelpString
->length()) &&
3602 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3604 // Clear help box - but only if it was written
3605 // by us at previous time.
3606 statusbar
->SetStatusText( m_emptyString
);
3607 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3613 m_inDoSelectProperty
= 0;
3615 // call wx event handler (here so that it also occurs on deselection)
3616 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3621 // -----------------------------------------------------------------------
3623 bool wxPropertyGrid::UnfocusEditor()
3625 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3628 if ( !CommitChangesFromEditor(0) )
3632 DrawItem(m_selected
);
3637 // -----------------------------------------------------------------------
3639 void wxPropertyGrid::RefreshEditor()
3641 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3643 m_selected
->UpdateControl(m_wndEditor
);
3646 // -----------------------------------------------------------------------
3648 // This method is not inline because it called dozens of times
3649 // (i.e. two-arg function calls create smaller code size).
3650 bool wxPropertyGrid::DoClearSelection()
3652 return DoSelectProperty((wxPGProperty
*)NULL
);
3655 // -----------------------------------------------------------------------
3656 // wxPropertyGrid expand/collapse state
3657 // -----------------------------------------------------------------------
3659 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3661 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3663 // If active editor was inside collapsed section, then disable it
3664 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3666 ClearSelection(false);
3669 // Store dont-center-splitter flag 'cause we need to temporarily set it
3670 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3671 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3673 bool res
= m_pState
->DoCollapse(pwc
);
3678 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3680 RecalculateVirtualSize();
3682 // Redraw etc. only if collapsed was visible.
3683 if (pwc
->IsVisible() &&
3685 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3687 // When item is collapsed so that scrollbar would move,
3688 // graphics mess is about (unless we redraw everything).
3693 // Clear dont-center-splitter flag if it wasn't set
3694 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3699 // -----------------------------------------------------------------------
3701 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3703 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3705 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3707 // Store dont-center-splitter flag 'cause we need to temporarily set it
3708 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3709 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3711 bool res
= m_pState
->DoExpand(pwc
);
3716 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3718 RecalculateVirtualSize();
3720 // Redraw etc. only if expanded was visible.
3721 if ( pwc
->IsVisible() && !m_frozen
&&
3722 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3726 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3729 DrawItems(pwc
, NULL
);
3734 // Clear dont-center-splitter flag if it wasn't set
3735 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3740 // -----------------------------------------------------------------------
3742 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3745 return m_pState
->DoHideProperty(p
, hide
, flags
);
3748 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3751 ClearSelection(false);
3754 m_pState
->DoHideProperty(p
, hide
, flags
);
3756 RecalculateVirtualSize();
3763 // -----------------------------------------------------------------------
3764 // wxPropertyGrid size related methods
3765 // -----------------------------------------------------------------------
3767 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3769 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3773 // If virtual height was changed, then recalculate editor control position(s)
3774 if ( m_pState
->m_vhCalcPending
)
3775 CorrectEditorWidgetPosY();
3777 m_pState
->EnsureVirtualHeight();
3780 int by1
= m_pState
->GetVirtualHeight();
3781 int by2
= m_pState
->GetActualVirtualHeight();
3784 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3785 wxFAIL_MSG(s
.c_str());
3790 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3792 int x
= m_pState
->m_width
;
3793 int y
= m_pState
->m_virtualHeight
;
3796 GetClientSize(&width
,&height
);
3798 // Now adjust virtual size.
3799 SetVirtualSize(x
, y
);
3805 // Adjust scrollbars
3806 if ( HasVirtualWidth() )
3808 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3809 xPos
= GetScrollPos( wxHORIZONTAL
);
3812 if ( forceXPos
!= -1 )
3815 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3818 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3819 int yPos
= GetScrollPos( wxVERTICAL
);
3821 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3822 xAmount
, yAmount
, xPos
, yPos
, true );
3824 // Must re-get size now
3825 GetClientSize(&width
,&height
);
3827 if ( !HasVirtualWidth() )
3829 m_pState
->SetVirtualWidth(width
);
3836 m_canvas
->SetSize( x
, y
);
3838 m_pState
->CheckColumnWidths();
3841 CorrectEditorWidgetSizeX();
3843 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3846 // -----------------------------------------------------------------------
3848 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3850 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3854 GetClientSize(&width
,&height
);
3859 #if wxPG_DOUBLE_BUFFER
3860 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3862 int dblh
= (m_lineHeight
*2);
3863 if ( !m_doubleBuffer
)
3865 // Create double buffer bitmap to draw on, if none
3866 int w
= (width
>250)?width
:250;
3867 int h
= height
+ dblh
;
3869 m_doubleBuffer
= new wxBitmap( w
, h
);
3873 int w
= m_doubleBuffer
->GetWidth();
3874 int h
= m_doubleBuffer
->GetHeight();
3876 // Double buffer must be large enough
3877 if ( w
< width
|| h
< (height
+dblh
) )
3879 if ( w
< width
) w
= width
;
3880 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3881 delete m_doubleBuffer
;
3882 m_doubleBuffer
= new wxBitmap( w
, h
);
3889 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3890 m_ncWidth
= event
.GetSize().x
;
3894 if ( m_pState
->m_itemsAdded
)
3895 PrepareAfterItemsAdded();
3897 // Without this, virtual size (atleast under wxGTK) will be skewed
3898 RecalculateVirtualSize();
3904 // -----------------------------------------------------------------------
3906 void wxPropertyGrid::SetVirtualWidth( int width
)
3910 // Disable virtual width
3911 width
= GetClientSize().x
;
3912 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3916 // Enable virtual width
3917 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3919 m_pState
->SetVirtualWidth( width
);
3922 void wxPropertyGrid::SetFocusOnCanvas()
3924 m_canvas
->SetFocusIgnoringChildren();
3925 m_editorFocused
= 0;
3928 // -----------------------------------------------------------------------
3929 // wxPropertyGrid mouse event handling
3930 // -----------------------------------------------------------------------
3932 // selFlags uses same values DoSelectProperty's flags
3933 // Returns true if event was vetoed.
3934 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3936 // Send property grid event of specific type and with specific property
3937 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3938 evt
.SetPropertyGrid(this);
3939 evt
.SetEventObject(m_eventObject
);
3943 evt
.SetCanVeto(true);
3944 evt
.SetupValidationInfo();
3945 m_validationInfo
.m_pValue
= pValue
;
3947 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3949 evtHandler
->ProcessEvent(evt
);
3951 return evt
.WasVetoed();
3954 // -----------------------------------------------------------------------
3956 // Return false if should be skipped
3957 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3961 // Need to set focus?
3962 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3967 wxPropertyGridPageState
* state
= m_pState
;
3969 int splitterHitOffset
;
3970 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3972 wxPGProperty
* p
= DoGetItemAtY(y
);
3976 int depth
= (int)p
->GetDepth() - 1;
3978 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3980 if ( x
>= marginEnds
)
3984 if ( p
->IsCategory() )
3986 // This is category.
3987 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3989 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3991 // Expand, collapse, activate etc. if click on text or left of splitter.
3994 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3999 if ( !DoSelectProperty( p
) )
4002 // On double-click, expand/collapse.
4003 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4005 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4006 else DoExpand( p
, true );
4010 else if ( splitterHit
== -1 )
4013 unsigned int selFlag
= 0;
4014 if ( columnHit
== 1 )
4016 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4017 selFlag
= wxPG_SEL_FOCUS
;
4019 if ( !DoSelectProperty( p
, selFlag
) )
4022 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4024 if ( p
->GetChildCount() && !p
->IsCategory() )
4025 // On double-click, expand/collapse.
4026 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4028 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4029 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4030 else DoExpand( p
, true );
4037 // click on splitter
4038 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4040 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4042 // Double-clicking the splitter causes auto-centering
4043 CenterSplitter( true );
4045 else if ( m_dragStatus
== 0 )
4048 // Begin draggin the splitter
4052 // Changes must be committed here or the
4053 // value won't be drawn correctly
4054 if ( !CommitChangesFromEditor() )
4057 m_wndEditor
->Show ( false );
4060 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4062 m_canvas
->CaptureMouse();
4063 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4067 m_draggedSplitter
= splitterHit
;
4068 m_dragOffset
= splitterHitOffset
;
4070 wxClientDC
dc(m_canvas
);
4072 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4073 // Fixes button disappearance bug
4075 m_wndEditor2
->Show ( false );
4078 m_startingSplitterX
= x
- splitterHitOffset
;
4086 if ( p
->GetChildCount() )
4088 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4090 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4092 int y2
= y
% m_lineHeight
;
4093 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4095 // On click on expander button, expand/collapse
4096 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4097 DoCollapse( p
, true );
4099 DoExpand( p
, true );
4108 // -----------------------------------------------------------------------
4110 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4111 wxMouseEvent
& WXUNUSED(event
) )
4115 // Select property here as well
4116 wxPGProperty
* p
= m_propHover
;
4117 if ( p
!= m_selected
)
4118 DoSelectProperty( p
);
4120 // Send right click event.
4121 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4128 // -----------------------------------------------------------------------
4130 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4131 wxMouseEvent
& WXUNUSED(event
) )
4135 // Select property here as well
4136 wxPGProperty
* p
= m_propHover
;
4138 if ( p
!= m_selected
)
4139 DoSelectProperty( p
);
4141 // Send double-click event.
4142 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4149 // -----------------------------------------------------------------------
4151 #if wxPG_SUPPORT_TOOLTIPS
4153 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4155 if ( tipString
.length() )
4157 m_canvas
->SetToolTip(tipString
);
4161 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4162 m_canvas
->SetToolTip( m_emptyString
);
4164 m_canvas
->SetToolTip( NULL
);
4169 #endif // #if wxPG_SUPPORT_TOOLTIPS
4171 // -----------------------------------------------------------------------
4173 // Return false if should be skipped
4174 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4176 // Safety check (needed because mouse capturing may
4177 // otherwise freeze the control)
4178 if ( m_dragStatus
> 0 && !event
.Dragging() )
4180 HandleMouseUp(x
,y
,event
);
4183 wxPropertyGridPageState
* state
= m_pState
;
4185 int splitterHitOffset
;
4186 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4187 int splitterX
= x
- splitterHitOffset
;
4189 if ( m_dragStatus
> 0 )
4191 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4192 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4195 int newSplitterX
= x
- m_dragOffset
;
4196 int splitterX
= x
- splitterHitOffset
;
4198 // Splitter redraw required?
4199 if ( newSplitterX
!= splitterX
)
4202 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4203 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4204 state
->m_fSplitterX
= (float) newSplitterX
;
4207 CorrectEditorWidgetSizeX();
4221 int ih
= m_lineHeight
;
4224 #if wxPG_SUPPORT_TOOLTIPS
4225 wxPGProperty
* prevHover
= m_propHover
;
4226 unsigned char prevSide
= m_mouseSide
;
4228 int curPropHoverY
= y
- (y
% ih
);
4230 // On which item it hovers
4233 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4236 // Mouse moves on another property
4238 m_propHover
= DoGetItemAtY(y
);
4239 m_propHoverY
= curPropHoverY
;
4242 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4245 #if wxPG_SUPPORT_TOOLTIPS
4246 // Store which side we are on
4248 if ( columnHit
== 1 )
4250 else if ( columnHit
== 0 )
4254 // If tooltips are enabled, show label or value as a tip
4255 // in case it doesn't otherwise show in full length.
4257 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4259 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4261 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4263 if ( m_propHover
&& !m_propHover
->IsCategory() )
4266 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4268 // Show help string as a tooltip
4269 wxString tipString
= m_propHover
->GetHelpString();
4271 SetToolTip(tipString
);
4275 // Show cropped value string as a tooltip
4279 if ( m_mouseSide
== 1 )
4281 tipString
= m_propHover
->m_label
;
4282 space
= splitterX
-m_marginWidth
-3;
4284 else if ( m_mouseSide
== 2 )
4286 tipString
= m_propHover
->GetDisplayedString();
4288 space
= m_width
- splitterX
;
4289 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4290 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4296 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4299 SetToolTip( tipString
);
4306 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4307 m_canvas
->SetToolTip( m_emptyString
);
4309 m_canvas
->SetToolTip( NULL
);
4320 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4321 m_canvas
->SetToolTip( m_emptyString
);
4323 m_canvas
->SetToolTip( NULL
);
4331 if ( splitterHit
== -1 ||
4333 HasFlag(wxPG_STATIC_SPLITTER
) )
4335 // hovering on something else
4336 if ( m_curcursor
!= wxCURSOR_ARROW
)
4337 CustomSetCursor( wxCURSOR_ARROW
);
4341 // Do not allow splitter cursor on caption items.
4342 // (also not if we were dragging and its started
4343 // outside the splitter region)
4345 if ( !m_propHover
->IsCategory() &&
4349 // hovering on splitter
4351 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4352 // reliably detected.
4353 //if ( m_curcursor != wxCURSOR_SIZEWE )
4354 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4360 // hovering on something else
4361 if ( m_curcursor
!= wxCURSOR_ARROW
)
4362 CustomSetCursor( wxCURSOR_ARROW
);
4369 // -----------------------------------------------------------------------
4371 // Also handles Leaving event
4372 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4373 wxMouseEvent
&WXUNUSED(event
) )
4375 wxPropertyGridPageState
* state
= m_pState
;
4379 int splitterHitOffset
;
4380 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4382 // No event type check - basicly calling this method should
4383 // just stop dragging.
4384 // Left up after dragged?
4385 if ( m_dragStatus
>= 1 )
4388 // End Splitter Dragging
4390 // DO NOT ENABLE FOLLOWING LINE!
4391 // (it is only here as a reminder to not to do it)
4394 // Disable splitter auto-centering
4395 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4397 // This is necessary to return cursor
4398 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4400 m_canvas
->ReleaseMouse();
4401 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4404 // Set back the default cursor, if necessary
4405 if ( splitterHit
== -1 ||
4408 CustomSetCursor( wxCURSOR_ARROW
);
4413 // Control background needs to be cleared
4414 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4415 DrawItem( m_selected
);
4419 m_wndEditor
->Show ( true );
4422 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4423 // Fixes button disappearance bug
4425 m_wndEditor2
->Show ( true );
4428 // This clears the focus.
4429 m_editorFocused
= 0;
4435 // -----------------------------------------------------------------------
4437 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4439 int splitterX
= GetSplitterPosition();
4442 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4446 wxWindow
* wnd
= GetEditorControl();
4448 // Hide popup on clicks
4449 if ( event
.GetEventType() != wxEVT_MOTION
)
4450 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4452 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4458 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4460 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4461 ux
>= (r
.x
+r
.width
) ||
4463 event
.m_y
>= (r
.y
+r
.height
)
4473 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4478 // -----------------------------------------------------------------------
4480 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4483 if ( OnMouseCommon( event
, &x
, &y
) )
4485 HandleMouseClick(x
,y
,event
);
4490 // -----------------------------------------------------------------------
4492 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4495 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4496 HandleMouseRightClick(x
,y
,event
);
4500 // -----------------------------------------------------------------------
4502 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4504 // Always run standard mouse-down handler as well
4505 OnMouseClick(event
);
4508 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4509 HandleMouseDoubleClick(x
,y
,event
);
4513 // -----------------------------------------------------------------------
4515 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4518 if ( OnMouseCommon( event
, &x
, &y
) )
4520 HandleMouseMove(x
,y
,event
);
4525 // -----------------------------------------------------------------------
4527 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4529 // Called when mouse moves in the empty space below the properties.
4530 CustomSetCursor( wxCURSOR_ARROW
);
4533 // -----------------------------------------------------------------------
4535 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4538 if ( OnMouseCommon( event
, &x
, &y
) )
4540 HandleMouseUp(x
,y
,event
);
4545 // -----------------------------------------------------------------------
4547 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4549 // This may get called from child control as well, so event's
4550 // mouse position cannot be relied on.
4552 if ( event
.Entering() )
4554 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4556 // TODO: Fix this (detect parent and only do
4557 // cursor trick if it is a manager).
4558 wxASSERT( GetParent() );
4559 GetParent()->SetCursor(wxNullCursor
);
4561 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4564 GetParent()->SetCursor(wxNullCursor
);
4566 else if ( event
.Leaving() )
4568 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4569 m_canvas
->SetCursor( wxNullCursor
);
4571 // Get real cursor position
4572 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4574 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4577 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4579 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4583 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4591 // -----------------------------------------------------------------------
4593 // Common code used by various OnMouseXXXChild methods.
4594 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4596 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4597 wxASSERT( topCtrlWnd
);
4599 event
.GetPosition(&x
,&y
);
4601 int splitterX
= GetSplitterPosition();
4603 wxRect r
= topCtrlWnd
->GetRect();
4604 if ( !m_dragStatus
&&
4605 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4606 y
>= 0 && y
< r
.height \
4609 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4614 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4621 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4624 if ( OnMouseChildCommon(event
,&x
,&y
) )
4626 bool res
= HandleMouseClick(x
,y
,event
);
4627 if ( !res
) event
.Skip();
4631 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4634 wxASSERT( m_wndEditor
);
4635 // These coords may not be exact (about +-2),
4636 // but that should not matter (right click is about item, not position).
4637 wxPoint pt
= m_wndEditor
->GetPosition();
4638 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4639 wxASSERT( m_selected
);
4640 m_propHover
= m_selected
;
4641 bool res
= HandleMouseRightClick(x
,y
,event
);
4642 if ( !res
) event
.Skip();
4645 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4648 if ( OnMouseChildCommon(event
,&x
,&y
) )
4650 bool res
= HandleMouseMove(x
,y
,event
);
4651 if ( !res
) event
.Skip();
4655 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4658 if ( OnMouseChildCommon(event
,&x
,&y
) )
4660 bool res
= HandleMouseUp(x
,y
,event
);
4661 if ( !res
) event
.Skip();
4665 // -----------------------------------------------------------------------
4666 // wxPropertyGrid keyboard event handling
4667 // -----------------------------------------------------------------------
4669 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4671 // Translates wxKeyEvent to wxPG_ACTION_XXX
4673 int keycode
= event
.GetKeyCode();
4674 int modifiers
= event
.GetModifiers();
4676 wxASSERT( !(modifiers
&~(0xFFFF)) );
4678 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4680 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4682 if ( it
== m_actionTriggers
.end() )
4687 int second
= (it
->second
>>16) & 0xFFFF;
4691 return (it
->second
& 0xFFFF);
4694 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4696 wxASSERT( !(modifiers
&~(0xFFFF)) );
4698 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4700 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4702 if ( it
!= m_actionTriggers
.end() )
4704 // This key combination is already used
4706 // Can add secondary?
4707 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4708 wxT("You can only add up to two separate actions per key combination.") );
4710 action
= it
->second
| (action
<<16);
4713 m_actionTriggers
[hashMapKey
] = action
;
4716 void wxPropertyGrid::ClearActionTriggers( int action
)
4718 wxPGHashMapI2I::iterator it
;
4720 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4722 if ( it
->second
== action
)
4724 m_actionTriggers
.erase(it
);
4729 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4732 // Handles key event when editor control is not focused.
4735 wxCHECK2(!m_frozen
, return);
4737 // Travelsal between items, collapsing/expanding, etc.
4738 int keycode
= event
.GetKeyCode();
4739 bool editorFocused
= IsEditorFocused();
4741 if ( keycode
== WXK_TAB
)
4743 wxWindow
* mainControl
;
4745 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4746 mainControl
= GetParent();
4750 if ( !event
.ShiftDown() )
4752 if ( !editorFocused
&& m_wndEditor
)
4754 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4758 // Tab traversal workaround for platforms on which
4759 // wxWindow::Navigate() may navigate into first child
4760 // instead of next sibling. Does not work perfectly
4761 // in every scenario (for instance, when property grid
4762 // is either first or last control).
4763 #if defined(__WXGTK__)
4764 wxWindow
* sibling
= mainControl
->GetNextSibling();
4766 sibling
->SetFocusFromKbd();
4768 Navigate(wxNavigationKeyEvent::IsForward
);
4774 if ( editorFocused
)
4780 #if defined(__WXGTK__)
4781 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4783 sibling
->SetFocusFromKbd();
4785 Navigate(wxNavigationKeyEvent::IsBackward
);
4793 // Ignore Alt and Control when they are down alone
4794 if ( keycode
== WXK_ALT
||
4795 keycode
== WXK_CONTROL
)
4802 int action
= KeyEventToActions(event
, &secondAction
);
4804 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4807 // Esc cancels any changes
4808 if ( IsEditorsValueModified() )
4810 EditorsValueWasNotModified();
4812 // Update the control as well
4813 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4815 m_selected
->GetDisplayedString() );
4818 OnValidationFailureReset(m_selected
);
4824 // Except for TAB and ESC, handle child control events in child control
4831 bool wasHandled
= false;
4836 if ( ButtonTriggerKeyTest(action
, event
) )
4839 wxPGProperty
* p
= m_selected
;
4841 // Travel and expand/collapse
4844 if ( p
->GetChildCount() &&
4845 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4848 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4850 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4853 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4855 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4862 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4866 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4872 if ( selectDir
>= -1 )
4874 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4876 DoSelectProperty(p
);
4882 // If nothing was selected, select the first item now
4883 // (or navigate out of tab).
4884 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4886 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4887 if ( p
) DoSelectProperty(p
);
4896 // -----------------------------------------------------------------------
4898 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4900 HandleKeyEvent(event
, false);
4903 // -----------------------------------------------------------------------
4905 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4910 action
= KeyEventToActions(event
, &secondAction
);
4913 // Does the keycode trigger button?
4914 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4917 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4918 GetEventHandler()->AddPendingEvent(evt
);
4925 // -----------------------------------------------------------------------
4927 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4929 HandleKeyEvent(event
, true);
4932 // -----------------------------------------------------------------------
4933 // wxPropertyGrid miscellaneous event handling
4934 // -----------------------------------------------------------------------
4936 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4939 // Check if the focus is in this control or one of its children
4940 wxWindow
* newFocused
= wxWindow::FindFocus();
4942 if ( newFocused
!= m_curFocused
)
4943 HandleFocusChange( newFocused
);
4946 bool wxPropertyGrid::IsEditorFocused() const
4948 wxWindow
* focus
= wxWindow::FindFocus();
4950 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4951 focus
== GetEditorControl() )
4957 // Called by focus event handlers. newFocused is the window that becomes focused.
4958 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4960 unsigned int oldFlags
= m_iFlags
;
4962 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4964 wxWindow
* parent
= newFocused
;
4966 // This must be one of nextFocus' parents.
4969 // Use m_eventObject, which is either wxPropertyGrid or
4970 // wxPropertyGridManager, as appropriate.
4971 if ( parent
== m_eventObject
)
4973 m_iFlags
|= wxPG_FL_FOCUSED
;
4976 parent
= parent
->GetParent();
4979 m_curFocused
= newFocused
;
4981 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4982 (oldFlags
& wxPG_FL_FOCUSED
) )
4984 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4986 // Need to store changed value
4987 CommitChangesFromEditor();
4993 // Preliminary code for tab-order respecting
4994 // tab-traversal (but should be moved to
4997 wxWindow* prevFocus = event.GetWindow();
4998 wxWindow* useThis = this;
4999 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5000 useThis = GetParent();
5003 prevFocus->GetParent() == useThis->GetParent() )
5005 wxList& children = useThis->GetParent()->GetChildren();
5007 wxNode* node = children.Find(prevFocus);
5009 if ( node->GetNext() &&
5010 useThis == node->GetNext()->GetData() )
5011 DoSelectProperty(GetFirst());
5012 else if ( node->GetPrevious () &&
5013 useThis == node->GetPrevious()->GetData() )
5014 DoSelectProperty(GetLastProperty());
5021 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5022 DrawItem( m_selected
);
5026 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5028 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5029 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5030 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5031 //else if ( event.GetWindow() )
5033 HandleFocusChange(event
.GetWindow());
5038 // -----------------------------------------------------------------------
5040 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5042 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5045 // event.Skip() being commented out is aworkaround for bug reported
5046 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5050 // -----------------------------------------------------------------------
5052 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5054 m_iFlags
|= wxPG_FL_SCROLLED
;
5059 // -----------------------------------------------------------------------
5061 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5063 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5065 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5069 // -----------------------------------------------------------------------
5070 // Property editor related functions
5071 // -----------------------------------------------------------------------
5073 // noDefCheck = true prevents infinite recursion.
5074 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5077 wxASSERT( editorClass
);
5079 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5080 RegisterDefaultEditors();
5082 wxString name
= editorClass
->GetName();
5084 // Existing editor under this name?
5085 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5087 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5089 // If this name was already used, try class name.
5090 name
= editorClass
->GetClassInfo()->GetClassName();
5091 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5094 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5095 (wxPGEditor
*) vt_it
->second
,
5096 "Editor with given name was already registered" );
5098 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5103 // Use this in RegisterDefaultEditors.
5104 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5105 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5107 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5108 new wxPG##EDITOR##Editor, true ); \
5111 // Registers all default editor classes
5112 void wxPropertyGrid::RegisterDefaultEditors()
5114 wxPGRegisterDefaultEditorClass( TextCtrl
);
5115 wxPGRegisterDefaultEditorClass( Choice
);
5116 wxPGRegisterDefaultEditorClass( ComboBox
);
5117 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5118 #if wxPG_INCLUDE_CHECKBOX
5119 wxPGRegisterDefaultEditorClass( CheckBox
);
5121 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5123 // Register SpinCtrl etc. editors before use
5124 RegisterAdditionalEditors();
5127 // -----------------------------------------------------------------------
5128 // wxPGStringTokenizer
5129 // Needed to handle C-style string lists (e.g. "str1" "str2")
5130 // -----------------------------------------------------------------------
5132 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5133 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5137 wxPGStringTokenizer::~wxPGStringTokenizer()
5141 bool wxPGStringTokenizer::HasMoreTokens()
5143 const wxString
& str
= *m_str
;
5145 wxString::const_iterator i
= m_curPos
;
5147 wxUniChar delim
= m_delimeter
;
5149 wxUniChar prev_a
= wxT('\0');
5151 bool inToken
= false;
5153 while ( i
!= str
.end() )
5162 m_readyToken
.clear();
5167 if ( prev_a
!= wxT('\\') )
5171 if ( a
!= wxT('\\') )
5191 m_curPos
= str
.end();
5199 wxString
wxPGStringTokenizer::GetNextToken()
5201 return m_readyToken
;
5204 // -----------------------------------------------------------------------
5206 // -----------------------------------------------------------------------
5208 wxPGChoiceEntry::wxPGChoiceEntry()
5209 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5213 // -----------------------------------------------------------------------
5215 // -----------------------------------------------------------------------
5217 wxPGChoicesData::wxPGChoicesData()
5222 wxPGChoicesData::~wxPGChoicesData()
5227 void wxPGChoicesData::Clear()
5232 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5234 wxASSERT( m_items
.size() == 0 );
5236 m_items
= data
->m_items
;
5239 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5240 const wxPGChoiceEntry
& item
)
5242 wxVector
<wxPGChoiceEntry
>::iterator it
;
5246 index
= (int) m_items
.size();
5250 it
= m_items
.begin() + index
;
5253 m_items
.insert(it
, item
);
5255 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5257 // Need to fix value?
5258 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5259 ownEntry
.SetValue(index
);
5264 // -----------------------------------------------------------------------
5266 // -----------------------------------------------------------------------
5268 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5272 wxPGChoiceEntry
entry(label
, value
);
5273 return m_data
->Insert( -1, entry
);
5276 // -----------------------------------------------------------------------
5278 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5282 wxPGChoiceEntry
entry(label
, value
);
5283 entry
.SetBitmap(bitmap
);
5284 return m_data
->Insert( -1, entry
);
5287 // -----------------------------------------------------------------------
5289 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5292 return m_data
->Insert( index
, entry
);
5295 // -----------------------------------------------------------------------
5297 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5301 wxPGChoiceEntry
entry(label
, value
);
5302 return m_data
->Insert( index
, entry
);
5305 // -----------------------------------------------------------------------
5307 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5313 while ( index
< GetCount() )
5315 int cmpRes
= GetLabel(index
).Cmp(label
);
5321 wxPGChoiceEntry
entry(label
, value
);
5322 return m_data
->Insert( index
, entry
);
5325 // -----------------------------------------------------------------------
5327 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5331 unsigned int itemcount
= 0;
5332 const wxChar
** p
= &labels
[0];
5333 while ( *p
) { p
++; itemcount
++; }
5336 for ( i
= 0; i
< itemcount
; i
++ )
5341 wxPGChoiceEntry
entry(labels
[i
], value
);
5342 m_data
->Insert( i
, entry
);
5346 // -----------------------------------------------------------------------
5348 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5353 unsigned int itemcount
= arr
.size();
5355 for ( i
= 0; i
< itemcount
; i
++ )
5358 if ( &arrint
&& arrint
.size() )
5360 wxPGChoiceEntry
entry(arr
[i
], value
);
5361 m_data
->Insert( i
, entry
);
5365 // -----------------------------------------------------------------------
5367 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5369 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5370 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5371 m_data
->m_items
.begin()+nIndex
+count
);
5374 // -----------------------------------------------------------------------
5376 int wxPGChoices::Index( const wxString
& str
) const
5381 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5383 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5384 if ( entry
.HasText() && entry
.GetText() == str
)
5391 // -----------------------------------------------------------------------
5393 int wxPGChoices::Index( int val
) const
5398 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5400 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5401 if ( entry
.GetValue() == val
)
5408 // -----------------------------------------------------------------------
5410 wxArrayString
wxPGChoices::GetLabels() const
5415 if ( this && IsOk() )
5416 for ( i
=0; i
<GetCount(); i
++ )
5417 arr
.push_back(GetLabel(i
));
5422 // -----------------------------------------------------------------------
5424 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5431 for ( i
=0; i
< strings
.size(); i
++ )
5433 int index
= Index(strings
[i
]);
5435 arr
.Add(GetValue(index
));
5437 arr
.Add(wxPG_INVALID_VALUE
);
5444 // -----------------------------------------------------------------------
5446 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5447 wxArrayString
* unmatched
) const
5454 for ( i
=0; i
< strings
.size(); i
++ )
5456 const wxString
& str
= strings
[i
];
5457 int index
= Index(str
);
5460 else if ( unmatched
)
5461 unmatched
->Add(str
);
5468 // -----------------------------------------------------------------------
5470 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5474 if ( data
!= wxPGChoicesEmptyData
)
5481 // -----------------------------------------------------------------------
5483 void wxPGChoices::Init()
5485 m_data
= wxPGChoicesEmptyData
;
5488 // -----------------------------------------------------------------------
5490 void wxPGChoices::Free()
5492 if ( m_data
!= wxPGChoicesEmptyData
)
5495 m_data
= wxPGChoicesEmptyData
;
5499 // -----------------------------------------------------------------------
5500 // wxPropertyGridEvent
5501 // -----------------------------------------------------------------------
5503 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5506 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5507 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5508 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5509 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5510 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5511 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5512 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5513 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5514 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5517 // -----------------------------------------------------------------------
5519 void wxPropertyGridEvent::Init()
5521 m_validationInfo
= NULL
;
5523 m_wasVetoed
= false;
5526 // -----------------------------------------------------------------------
5528 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5529 : wxCommandEvent(commandType
,id
)
5535 // -----------------------------------------------------------------------
5537 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5538 : wxCommandEvent(event
)
5540 m_eventType
= event
.GetEventType();
5541 m_eventObject
= event
.m_eventObject
;
5543 m_property
= event
.m_property
;
5544 m_validationInfo
= event
.m_validationInfo
;
5545 m_canVeto
= event
.m_canVeto
;
5546 m_wasVetoed
= event
.m_wasVetoed
;
5549 // -----------------------------------------------------------------------
5551 wxPropertyGridEvent::~wxPropertyGridEvent()
5555 // -----------------------------------------------------------------------
5557 wxEvent
* wxPropertyGridEvent::Clone() const
5559 return new wxPropertyGridEvent( *this );
5562 // -----------------------------------------------------------------------
5563 // wxPropertyGridPopulator
5564 // -----------------------------------------------------------------------
5566 wxPropertyGridPopulator::wxPropertyGridPopulator()
5570 wxPGGlobalVars
->m_offline
++;
5573 // -----------------------------------------------------------------------
5575 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5578 m_propHierarchy
.clear();
5581 // -----------------------------------------------------------------------
5583 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5589 // -----------------------------------------------------------------------
5591 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5594 // Free unused sets of choices
5595 wxPGHashMapS2P::iterator it
;
5597 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5599 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5606 m_pg
->GetPanel()->Refresh();
5608 wxPGGlobalVars
->m_offline
--;
5611 // -----------------------------------------------------------------------
5613 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5614 const wxString
& propLabel
,
5615 const wxString
& propName
,
5616 const wxString
* propValue
,
5617 wxPGChoices
* pChoices
)
5619 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5620 wxPGProperty
* parent
= GetCurParent();
5622 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5624 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5628 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5630 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5634 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5636 property
->SetLabel(propLabel
);
5637 property
->DoSetName(propName
);
5639 if ( pChoices
&& pChoices
->IsOk() )
5640 property
->SetChoices(*pChoices
);
5642 m_state
->DoInsert(parent
, -1, property
);
5645 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5646 wxPG_PROGRAMMATIC_VALUE
);
5651 // -----------------------------------------------------------------------
5653 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5655 m_propHierarchy
.push_back(property
);
5656 DoScanForChildren();
5657 m_propHierarchy
.pop_back();
5660 // -----------------------------------------------------------------------
5662 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5663 const wxString
& idString
)
5665 wxPGChoices choices
;
5668 if ( choicesString
[0] == wxT('@') )
5670 wxString ids
= choicesString
.substr(1);
5671 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5672 if ( it
== m_dictIdChoices
.end() )
5673 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5675 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5680 if ( idString
.length() )
5682 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5683 if ( it
!= m_dictIdChoices
.end() )
5685 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5692 // Parse choices string
5693 wxString::const_iterator it
= choicesString
.begin();
5697 bool labelValid
= false;
5699 for ( ; it
!= choicesString
.end(); ++it
)
5705 if ( c
== wxT('"') )
5710 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5711 choices
.Add(label
, l
);
5714 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5719 else if ( c
== wxT('=') )
5726 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5733 if ( c
== wxT('"') )
5746 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5747 choices
.Add(label
, l
);
5750 if ( !choices
.IsOk() )
5752 choices
.EnsureData();
5756 if ( idString
.length() )
5757 m_dictIdChoices
[idString
] = choices
.GetData();
5764 // -----------------------------------------------------------------------
5766 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5768 if ( s
.Last() == wxT('%') )
5770 wxString s2
= s
.substr(0,s
.length()-1);
5772 if ( s2
.ToLong(&val
, 10) )
5774 *pval
= (val
*max
)/100;
5780 return s
.ToLong(pval
, 10);
5783 // -----------------------------------------------------------------------
5785 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5786 const wxString
& type
,
5787 const wxString
& value
)
5789 int l
= m_propHierarchy
.size();
5793 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5794 wxString valuel
= value
.Lower();
5797 if ( type
.length() == 0 )
5802 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5804 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5806 else if ( value
.ToLong(&v
, 0) )
5813 if ( type
== wxT("string") )
5817 else if ( type
== wxT("int") )
5820 value
.ToLong(&v
, 0);
5823 else if ( type
== wxT("bool") )
5825 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5832 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5837 p
->SetAttribute( name
, variant
);
5842 // -----------------------------------------------------------------------
5844 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5846 wxLogError(_("Error in resource: %s"),msg
.c_str());
5849 // -----------------------------------------------------------------------
5851 #endif // wxUSE_PROPGRID