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 // This method is not inline because it called dozens of times
3640 // (i.e. two-arg function calls create smaller code size).
3641 bool wxPropertyGrid::DoClearSelection()
3643 return DoSelectProperty((wxPGProperty
*)NULL
);
3646 // -----------------------------------------------------------------------
3647 // wxPropertyGrid expand/collapse state
3648 // -----------------------------------------------------------------------
3650 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3652 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3654 // If active editor was inside collapsed section, then disable it
3655 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3657 ClearSelection(false);
3660 // Store dont-center-splitter flag 'cause we need to temporarily set it
3661 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3662 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3664 bool res
= m_pState
->DoCollapse(pwc
);
3669 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3671 RecalculateVirtualSize();
3673 // Redraw etc. only if collapsed was visible.
3674 if (pwc
->IsVisible() &&
3676 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3678 // When item is collapsed so that scrollbar would move,
3679 // graphics mess is about (unless we redraw everything).
3684 // Clear dont-center-splitter flag if it wasn't set
3685 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3690 // -----------------------------------------------------------------------
3692 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3694 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3696 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3698 // Store dont-center-splitter flag 'cause we need to temporarily set it
3699 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3700 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3702 bool res
= m_pState
->DoExpand(pwc
);
3707 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3709 RecalculateVirtualSize();
3711 // Redraw etc. only if expanded was visible.
3712 if ( pwc
->IsVisible() && !m_frozen
&&
3713 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3717 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3720 DrawItems(pwc
, NULL
);
3725 // Clear dont-center-splitter flag if it wasn't set
3726 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3731 // -----------------------------------------------------------------------
3733 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3736 return m_pState
->DoHideProperty(p
, hide
, flags
);
3739 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3742 ClearSelection(false);
3745 m_pState
->DoHideProperty(p
, hide
, flags
);
3747 RecalculateVirtualSize();
3754 // -----------------------------------------------------------------------
3755 // wxPropertyGrid size related methods
3756 // -----------------------------------------------------------------------
3758 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3760 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3764 // If virtual height was changed, then recalculate editor control position(s)
3765 if ( m_pState
->m_vhCalcPending
)
3766 CorrectEditorWidgetPosY();
3768 m_pState
->EnsureVirtualHeight();
3771 int by1
= m_pState
->GetVirtualHeight();
3772 int by2
= m_pState
->GetActualVirtualHeight();
3775 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3776 wxFAIL_MSG(s
.c_str());
3781 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3783 int x
= m_pState
->m_width
;
3784 int y
= m_pState
->m_virtualHeight
;
3787 GetClientSize(&width
,&height
);
3789 // Now adjust virtual size.
3790 SetVirtualSize(x
, y
);
3796 // Adjust scrollbars
3797 if ( HasVirtualWidth() )
3799 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3800 xPos
= GetScrollPos( wxHORIZONTAL
);
3803 if ( forceXPos
!= -1 )
3806 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3809 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3810 int yPos
= GetScrollPos( wxVERTICAL
);
3812 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3813 xAmount
, yAmount
, xPos
, yPos
, true );
3815 // Must re-get size now
3816 GetClientSize(&width
,&height
);
3818 if ( !HasVirtualWidth() )
3820 m_pState
->SetVirtualWidth(width
);
3827 m_canvas
->SetSize( x
, y
);
3829 m_pState
->CheckColumnWidths();
3832 CorrectEditorWidgetSizeX();
3834 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3837 // -----------------------------------------------------------------------
3839 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3841 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3845 GetClientSize(&width
,&height
);
3850 #if wxPG_DOUBLE_BUFFER
3851 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3853 int dblh
= (m_lineHeight
*2);
3854 if ( !m_doubleBuffer
)
3856 // Create double buffer bitmap to draw on, if none
3857 int w
= (width
>250)?width
:250;
3858 int h
= height
+ dblh
;
3860 m_doubleBuffer
= new wxBitmap( w
, h
);
3864 int w
= m_doubleBuffer
->GetWidth();
3865 int h
= m_doubleBuffer
->GetHeight();
3867 // Double buffer must be large enough
3868 if ( w
< width
|| h
< (height
+dblh
) )
3870 if ( w
< width
) w
= width
;
3871 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3872 delete m_doubleBuffer
;
3873 m_doubleBuffer
= new wxBitmap( w
, h
);
3880 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3881 m_ncWidth
= event
.GetSize().x
;
3885 if ( m_pState
->m_itemsAdded
)
3886 PrepareAfterItemsAdded();
3888 // Without this, virtual size (atleast under wxGTK) will be skewed
3889 RecalculateVirtualSize();
3895 // -----------------------------------------------------------------------
3897 void wxPropertyGrid::SetVirtualWidth( int width
)
3901 // Disable virtual width
3902 width
= GetClientSize().x
;
3903 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3907 // Enable virtual width
3908 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3910 m_pState
->SetVirtualWidth( width
);
3913 void wxPropertyGrid::SetFocusOnCanvas()
3915 m_canvas
->SetFocusIgnoringChildren();
3916 m_editorFocused
= 0;
3919 // -----------------------------------------------------------------------
3920 // wxPropertyGrid mouse event handling
3921 // -----------------------------------------------------------------------
3923 // selFlags uses same values DoSelectProperty's flags
3924 // Returns true if event was vetoed.
3925 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3927 // Send property grid event of specific type and with specific property
3928 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3929 evt
.SetPropertyGrid(this);
3930 evt
.SetEventObject(m_eventObject
);
3934 evt
.SetCanVeto(true);
3935 evt
.SetupValidationInfo();
3936 m_validationInfo
.m_pValue
= pValue
;
3938 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3940 evtHandler
->ProcessEvent(evt
);
3942 return evt
.WasVetoed();
3945 // -----------------------------------------------------------------------
3947 // Return false if should be skipped
3948 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3952 // Need to set focus?
3953 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3958 wxPropertyGridPageState
* state
= m_pState
;
3960 int splitterHitOffset
;
3961 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3963 wxPGProperty
* p
= DoGetItemAtY(y
);
3967 int depth
= (int)p
->GetDepth() - 1;
3969 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3971 if ( x
>= marginEnds
)
3975 if ( p
->IsCategory() )
3977 // This is category.
3978 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3980 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3982 // Expand, collapse, activate etc. if click on text or left of splitter.
3985 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3990 if ( !DoSelectProperty( p
) )
3993 // On double-click, expand/collapse.
3994 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3996 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3997 else DoExpand( p
, true );
4001 else if ( splitterHit
== -1 )
4004 unsigned int selFlag
= 0;
4005 if ( columnHit
== 1 )
4007 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4008 selFlag
= wxPG_SEL_FOCUS
;
4010 if ( !DoSelectProperty( p
, selFlag
) )
4013 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4015 if ( p
->GetChildCount() && !p
->IsCategory() )
4016 // On double-click, expand/collapse.
4017 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4019 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4020 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4021 else DoExpand( p
, true );
4028 // click on splitter
4029 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4031 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4033 // Double-clicking the splitter causes auto-centering
4034 CenterSplitter( true );
4036 else if ( m_dragStatus
== 0 )
4039 // Begin draggin the splitter
4043 // Changes must be committed here or the
4044 // value won't be drawn correctly
4045 if ( !CommitChangesFromEditor() )
4048 m_wndEditor
->Show ( false );
4051 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4053 m_canvas
->CaptureMouse();
4054 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4058 m_draggedSplitter
= splitterHit
;
4059 m_dragOffset
= splitterHitOffset
;
4061 wxClientDC
dc(m_canvas
);
4063 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4064 // Fixes button disappearance bug
4066 m_wndEditor2
->Show ( false );
4069 m_startingSplitterX
= x
- splitterHitOffset
;
4077 if ( p
->GetChildCount() )
4079 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4081 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4083 int y2
= y
% m_lineHeight
;
4084 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4086 // On click on expander button, expand/collapse
4087 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4088 DoCollapse( p
, true );
4090 DoExpand( p
, true );
4099 // -----------------------------------------------------------------------
4101 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4102 wxMouseEvent
& WXUNUSED(event
) )
4106 // Select property here as well
4107 wxPGProperty
* p
= m_propHover
;
4108 if ( p
!= m_selected
)
4109 DoSelectProperty( p
);
4111 // Send right click event.
4112 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4119 // -----------------------------------------------------------------------
4121 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4122 wxMouseEvent
& WXUNUSED(event
) )
4126 // Select property here as well
4127 wxPGProperty
* p
= m_propHover
;
4129 if ( p
!= m_selected
)
4130 DoSelectProperty( p
);
4132 // Send double-click event.
4133 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4140 // -----------------------------------------------------------------------
4142 #if wxPG_SUPPORT_TOOLTIPS
4144 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4146 if ( tipString
.length() )
4148 m_canvas
->SetToolTip(tipString
);
4152 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4153 m_canvas
->SetToolTip( m_emptyString
);
4155 m_canvas
->SetToolTip( NULL
);
4160 #endif // #if wxPG_SUPPORT_TOOLTIPS
4162 // -----------------------------------------------------------------------
4164 // Return false if should be skipped
4165 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4167 // Safety check (needed because mouse capturing may
4168 // otherwise freeze the control)
4169 if ( m_dragStatus
> 0 && !event
.Dragging() )
4171 HandleMouseUp(x
,y
,event
);
4174 wxPropertyGridPageState
* state
= m_pState
;
4176 int splitterHitOffset
;
4177 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4178 int splitterX
= x
- splitterHitOffset
;
4180 if ( m_dragStatus
> 0 )
4182 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4183 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4186 int newSplitterX
= x
- m_dragOffset
;
4187 int splitterX
= x
- splitterHitOffset
;
4189 // Splitter redraw required?
4190 if ( newSplitterX
!= splitterX
)
4193 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4194 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4195 state
->m_fSplitterX
= (float) newSplitterX
;
4198 CorrectEditorWidgetSizeX();
4212 int ih
= m_lineHeight
;
4215 #if wxPG_SUPPORT_TOOLTIPS
4216 wxPGProperty
* prevHover
= m_propHover
;
4217 unsigned char prevSide
= m_mouseSide
;
4219 int curPropHoverY
= y
- (y
% ih
);
4221 // On which item it hovers
4224 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4227 // Mouse moves on another property
4229 m_propHover
= DoGetItemAtY(y
);
4230 m_propHoverY
= curPropHoverY
;
4233 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4236 #if wxPG_SUPPORT_TOOLTIPS
4237 // Store which side we are on
4239 if ( columnHit
== 1 )
4241 else if ( columnHit
== 0 )
4245 // If tooltips are enabled, show label or value as a tip
4246 // in case it doesn't otherwise show in full length.
4248 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4250 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4252 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4254 if ( m_propHover
&& !m_propHover
->IsCategory() )
4257 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4259 // Show help string as a tooltip
4260 wxString tipString
= m_propHover
->GetHelpString();
4262 SetToolTip(tipString
);
4266 // Show cropped value string as a tooltip
4270 if ( m_mouseSide
== 1 )
4272 tipString
= m_propHover
->m_label
;
4273 space
= splitterX
-m_marginWidth
-3;
4275 else if ( m_mouseSide
== 2 )
4277 tipString
= m_propHover
->GetDisplayedString();
4279 space
= m_width
- splitterX
;
4280 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4281 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4287 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4290 SetToolTip( tipString
);
4297 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4298 m_canvas
->SetToolTip( m_emptyString
);
4300 m_canvas
->SetToolTip( NULL
);
4311 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4312 m_canvas
->SetToolTip( m_emptyString
);
4314 m_canvas
->SetToolTip( NULL
);
4322 if ( splitterHit
== -1 ||
4324 HasFlag(wxPG_STATIC_SPLITTER
) )
4326 // hovering on something else
4327 if ( m_curcursor
!= wxCURSOR_ARROW
)
4328 CustomSetCursor( wxCURSOR_ARROW
);
4332 // Do not allow splitter cursor on caption items.
4333 // (also not if we were dragging and its started
4334 // outside the splitter region)
4336 if ( !m_propHover
->IsCategory() &&
4340 // hovering on splitter
4342 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4343 // reliably detected.
4344 //if ( m_curcursor != wxCURSOR_SIZEWE )
4345 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4351 // hovering on something else
4352 if ( m_curcursor
!= wxCURSOR_ARROW
)
4353 CustomSetCursor( wxCURSOR_ARROW
);
4360 // -----------------------------------------------------------------------
4362 // Also handles Leaving event
4363 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4364 wxMouseEvent
&WXUNUSED(event
) )
4366 wxPropertyGridPageState
* state
= m_pState
;
4370 int splitterHitOffset
;
4371 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4373 // No event type check - basicly calling this method should
4374 // just stop dragging.
4375 // Left up after dragged?
4376 if ( m_dragStatus
>= 1 )
4379 // End Splitter Dragging
4381 // DO NOT ENABLE FOLLOWING LINE!
4382 // (it is only here as a reminder to not to do it)
4385 // Disable splitter auto-centering
4386 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4388 // This is necessary to return cursor
4389 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4391 m_canvas
->ReleaseMouse();
4392 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4395 // Set back the default cursor, if necessary
4396 if ( splitterHit
== -1 ||
4399 CustomSetCursor( wxCURSOR_ARROW
);
4404 // Control background needs to be cleared
4405 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4406 DrawItem( m_selected
);
4410 m_wndEditor
->Show ( true );
4413 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4414 // Fixes button disappearance bug
4416 m_wndEditor2
->Show ( true );
4419 // This clears the focus.
4420 m_editorFocused
= 0;
4426 // -----------------------------------------------------------------------
4428 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4430 int splitterX
= GetSplitterPosition();
4433 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4437 wxWindow
* wnd
= GetEditorControl();
4439 // Hide popup on clicks
4440 if ( event
.GetEventType() != wxEVT_MOTION
)
4441 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4443 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4449 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4451 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4452 ux
>= (r
.x
+r
.width
) ||
4454 event
.m_y
>= (r
.y
+r
.height
)
4464 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4469 // -----------------------------------------------------------------------
4471 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4474 if ( OnMouseCommon( event
, &x
, &y
) )
4476 HandleMouseClick(x
,y
,event
);
4481 // -----------------------------------------------------------------------
4483 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4486 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4487 HandleMouseRightClick(x
,y
,event
);
4491 // -----------------------------------------------------------------------
4493 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4495 // Always run standard mouse-down handler as well
4496 OnMouseClick(event
);
4499 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4500 HandleMouseDoubleClick(x
,y
,event
);
4504 // -----------------------------------------------------------------------
4506 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4509 if ( OnMouseCommon( event
, &x
, &y
) )
4511 HandleMouseMove(x
,y
,event
);
4516 // -----------------------------------------------------------------------
4518 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4520 // Called when mouse moves in the empty space below the properties.
4521 CustomSetCursor( wxCURSOR_ARROW
);
4524 // -----------------------------------------------------------------------
4526 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4529 if ( OnMouseCommon( event
, &x
, &y
) )
4531 HandleMouseUp(x
,y
,event
);
4536 // -----------------------------------------------------------------------
4538 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4540 // This may get called from child control as well, so event's
4541 // mouse position cannot be relied on.
4543 if ( event
.Entering() )
4545 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4547 // TODO: Fix this (detect parent and only do
4548 // cursor trick if it is a manager).
4549 wxASSERT( GetParent() );
4550 GetParent()->SetCursor(wxNullCursor
);
4552 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4555 GetParent()->SetCursor(wxNullCursor
);
4557 else if ( event
.Leaving() )
4559 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4560 m_canvas
->SetCursor( wxNullCursor
);
4562 // Get real cursor position
4563 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4565 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4568 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4570 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4574 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4582 // -----------------------------------------------------------------------
4584 // Common code used by various OnMouseXXXChild methods.
4585 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4587 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4588 wxASSERT( topCtrlWnd
);
4590 event
.GetPosition(&x
,&y
);
4592 int splitterX
= GetSplitterPosition();
4594 wxRect r
= topCtrlWnd
->GetRect();
4595 if ( !m_dragStatus
&&
4596 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4597 y
>= 0 && y
< r
.height \
4600 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4605 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4612 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4615 if ( OnMouseChildCommon(event
,&x
,&y
) )
4617 bool res
= HandleMouseClick(x
,y
,event
);
4618 if ( !res
) event
.Skip();
4622 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4625 wxASSERT( m_wndEditor
);
4626 // These coords may not be exact (about +-2),
4627 // but that should not matter (right click is about item, not position).
4628 wxPoint pt
= m_wndEditor
->GetPosition();
4629 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4630 wxASSERT( m_selected
);
4631 m_propHover
= m_selected
;
4632 bool res
= HandleMouseRightClick(x
,y
,event
);
4633 if ( !res
) event
.Skip();
4636 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4639 if ( OnMouseChildCommon(event
,&x
,&y
) )
4641 bool res
= HandleMouseMove(x
,y
,event
);
4642 if ( !res
) event
.Skip();
4646 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4649 if ( OnMouseChildCommon(event
,&x
,&y
) )
4651 bool res
= HandleMouseUp(x
,y
,event
);
4652 if ( !res
) event
.Skip();
4656 // -----------------------------------------------------------------------
4657 // wxPropertyGrid keyboard event handling
4658 // -----------------------------------------------------------------------
4660 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4662 // Translates wxKeyEvent to wxPG_ACTION_XXX
4664 int keycode
= event
.GetKeyCode();
4665 int modifiers
= event
.GetModifiers();
4667 wxASSERT( !(modifiers
&~(0xFFFF)) );
4669 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4671 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4673 if ( it
== m_actionTriggers
.end() )
4678 int second
= (it
->second
>>16) & 0xFFFF;
4682 return (it
->second
& 0xFFFF);
4685 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4687 wxASSERT( !(modifiers
&~(0xFFFF)) );
4689 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4691 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4693 if ( it
!= m_actionTriggers
.end() )
4695 // This key combination is already used
4697 // Can add secondary?
4698 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4699 wxT("You can only add up to two separate actions per key combination.") );
4701 action
= it
->second
| (action
<<16);
4704 m_actionTriggers
[hashMapKey
] = action
;
4707 void wxPropertyGrid::ClearActionTriggers( int action
)
4709 wxPGHashMapI2I::iterator it
;
4711 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4713 if ( it
->second
== action
)
4715 m_actionTriggers
.erase(it
);
4720 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4723 // Handles key event when editor control is not focused.
4726 wxCHECK2(!m_frozen
, return);
4728 // Travelsal between items, collapsing/expanding, etc.
4729 int keycode
= event
.GetKeyCode();
4730 bool editorFocused
= IsEditorFocused();
4732 if ( keycode
== WXK_TAB
)
4734 wxWindow
* mainControl
;
4736 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4737 mainControl
= GetParent();
4741 if ( !event
.ShiftDown() )
4743 if ( !editorFocused
&& m_wndEditor
)
4745 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4749 // Tab traversal workaround for platforms on which
4750 // wxWindow::Navigate() may navigate into first child
4751 // instead of next sibling. Does not work perfectly
4752 // in every scenario (for instance, when property grid
4753 // is either first or last control).
4754 #if defined(__WXGTK__)
4755 wxWindow
* sibling
= mainControl
->GetNextSibling();
4757 sibling
->SetFocusFromKbd();
4759 Navigate(wxNavigationKeyEvent::IsForward
);
4765 if ( editorFocused
)
4771 #if defined(__WXGTK__)
4772 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4774 sibling
->SetFocusFromKbd();
4776 Navigate(wxNavigationKeyEvent::IsBackward
);
4784 // Ignore Alt and Control when they are down alone
4785 if ( keycode
== WXK_ALT
||
4786 keycode
== WXK_CONTROL
)
4793 int action
= KeyEventToActions(event
, &secondAction
);
4795 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4798 // Esc cancels any changes
4799 if ( IsEditorsValueModified() )
4801 EditorsValueWasNotModified();
4803 // Update the control as well
4804 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4806 m_selected
->GetDisplayedString() );
4809 OnValidationFailureReset(m_selected
);
4815 // Except for TAB and ESC, handle child control events in child control
4822 bool wasHandled
= false;
4827 if ( ButtonTriggerKeyTest(action
, event
) )
4830 wxPGProperty
* p
= m_selected
;
4832 // Travel and expand/collapse
4835 if ( p
->GetChildCount() &&
4836 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4839 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4841 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4844 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4846 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4853 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4857 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4863 if ( selectDir
>= -1 )
4865 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4867 DoSelectProperty(p
);
4873 // If nothing was selected, select the first item now
4874 // (or navigate out of tab).
4875 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4877 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4878 if ( p
) DoSelectProperty(p
);
4887 // -----------------------------------------------------------------------
4889 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4891 HandleKeyEvent(event
, false);
4894 // -----------------------------------------------------------------------
4896 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4901 action
= KeyEventToActions(event
, &secondAction
);
4904 // Does the keycode trigger button?
4905 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4908 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4909 GetEventHandler()->AddPendingEvent(evt
);
4916 // -----------------------------------------------------------------------
4918 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4920 HandleKeyEvent(event
, true);
4923 // -----------------------------------------------------------------------
4924 // wxPropertyGrid miscellaneous event handling
4925 // -----------------------------------------------------------------------
4927 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4930 // Check if the focus is in this control or one of its children
4931 wxWindow
* newFocused
= wxWindow::FindFocus();
4933 if ( newFocused
!= m_curFocused
)
4934 HandleFocusChange( newFocused
);
4937 bool wxPropertyGrid::IsEditorFocused() const
4939 wxWindow
* focus
= wxWindow::FindFocus();
4941 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4942 focus
== GetEditorControl() )
4948 // Called by focus event handlers. newFocused is the window that becomes focused.
4949 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4951 unsigned int oldFlags
= m_iFlags
;
4953 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4955 wxWindow
* parent
= newFocused
;
4957 // This must be one of nextFocus' parents.
4960 // Use m_eventObject, which is either wxPropertyGrid or
4961 // wxPropertyGridManager, as appropriate.
4962 if ( parent
== m_eventObject
)
4964 m_iFlags
|= wxPG_FL_FOCUSED
;
4967 parent
= parent
->GetParent();
4970 m_curFocused
= newFocused
;
4972 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4973 (oldFlags
& wxPG_FL_FOCUSED
) )
4975 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4977 // Need to store changed value
4978 CommitChangesFromEditor();
4984 // Preliminary code for tab-order respecting
4985 // tab-traversal (but should be moved to
4988 wxWindow* prevFocus = event.GetWindow();
4989 wxWindow* useThis = this;
4990 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4991 useThis = GetParent();
4994 prevFocus->GetParent() == useThis->GetParent() )
4996 wxList& children = useThis->GetParent()->GetChildren();
4998 wxNode* node = children.Find(prevFocus);
5000 if ( node->GetNext() &&
5001 useThis == node->GetNext()->GetData() )
5002 DoSelectProperty(GetFirst());
5003 else if ( node->GetPrevious () &&
5004 useThis == node->GetPrevious()->GetData() )
5005 DoSelectProperty(GetLastProperty());
5012 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5013 DrawItem( m_selected
);
5017 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5019 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5020 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5021 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5022 //else if ( event.GetWindow() )
5024 HandleFocusChange(event
.GetWindow());
5029 // -----------------------------------------------------------------------
5031 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5033 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5036 // event.Skip() being commented out is aworkaround for bug reported
5037 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5041 // -----------------------------------------------------------------------
5043 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5045 m_iFlags
|= wxPG_FL_SCROLLED
;
5050 // -----------------------------------------------------------------------
5052 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5054 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5056 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5060 // -----------------------------------------------------------------------
5061 // Property editor related functions
5062 // -----------------------------------------------------------------------
5064 // noDefCheck = true prevents infinite recursion.
5065 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5068 wxASSERT( editorClass
);
5070 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5071 RegisterDefaultEditors();
5073 wxString name
= editorClass
->GetName();
5075 // Existing editor under this name?
5076 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5078 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5080 // If this name was already used, try class name.
5081 name
= editorClass
->GetClassInfo()->GetClassName();
5082 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5085 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5086 (wxPGEditor
*) vt_it
->second
,
5087 "Editor with given name was already registered" );
5089 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5094 // Use this in RegisterDefaultEditors.
5095 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5096 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5098 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5099 new wxPG##EDITOR##Editor, true ); \
5102 // Registers all default editor classes
5103 void wxPropertyGrid::RegisterDefaultEditors()
5105 wxPGRegisterDefaultEditorClass( TextCtrl
);
5106 wxPGRegisterDefaultEditorClass( Choice
);
5107 wxPGRegisterDefaultEditorClass( ComboBox
);
5108 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5109 #if wxPG_INCLUDE_CHECKBOX
5110 wxPGRegisterDefaultEditorClass( CheckBox
);
5112 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5114 // Register SpinCtrl etc. editors before use
5115 RegisterAdditionalEditors();
5118 // -----------------------------------------------------------------------
5119 // wxPGStringTokenizer
5120 // Needed to handle C-style string lists (e.g. "str1" "str2")
5121 // -----------------------------------------------------------------------
5123 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5124 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5128 wxPGStringTokenizer::~wxPGStringTokenizer()
5132 bool wxPGStringTokenizer::HasMoreTokens()
5134 const wxString
& str
= *m_str
;
5136 wxString::const_iterator i
= m_curPos
;
5138 wxUniChar delim
= m_delimeter
;
5140 wxUniChar prev_a
= wxT('\0');
5142 bool inToken
= false;
5144 while ( i
!= str
.end() )
5153 m_readyToken
.clear();
5158 if ( prev_a
!= wxT('\\') )
5162 if ( a
!= wxT('\\') )
5182 m_curPos
= str
.end();
5190 wxString
wxPGStringTokenizer::GetNextToken()
5192 return m_readyToken
;
5195 // -----------------------------------------------------------------------
5197 // -----------------------------------------------------------------------
5199 wxPGChoiceEntry::wxPGChoiceEntry()
5200 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5204 // -----------------------------------------------------------------------
5206 // -----------------------------------------------------------------------
5208 wxPGChoicesData::wxPGChoicesData()
5213 wxPGChoicesData::~wxPGChoicesData()
5218 void wxPGChoicesData::Clear()
5223 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5225 wxASSERT( m_items
.size() == 0 );
5227 m_items
= data
->m_items
;
5230 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5231 const wxPGChoiceEntry
& item
)
5233 wxVector
<wxPGChoiceEntry
>::iterator it
;
5237 index
= (int) m_items
.size();
5241 it
= m_items
.begin() + index
;
5244 m_items
.insert(it
, item
);
5246 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5248 // Need to fix value?
5249 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5250 ownEntry
.SetValue(index
);
5255 // -----------------------------------------------------------------------
5257 // -----------------------------------------------------------------------
5259 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5263 wxPGChoiceEntry
entry(label
, value
);
5264 return m_data
->Insert( -1, entry
);
5267 // -----------------------------------------------------------------------
5269 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5273 wxPGChoiceEntry
entry(label
, value
);
5274 entry
.SetBitmap(bitmap
);
5275 return m_data
->Insert( -1, entry
);
5278 // -----------------------------------------------------------------------
5280 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5283 return m_data
->Insert( index
, entry
);
5286 // -----------------------------------------------------------------------
5288 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5292 wxPGChoiceEntry
entry(label
, value
);
5293 return m_data
->Insert( index
, entry
);
5296 // -----------------------------------------------------------------------
5298 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5304 while ( index
< GetCount() )
5306 int cmpRes
= GetLabel(index
).Cmp(label
);
5312 wxPGChoiceEntry
entry(label
, value
);
5313 return m_data
->Insert( index
, entry
);
5316 // -----------------------------------------------------------------------
5318 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5322 unsigned int itemcount
= 0;
5323 const wxChar
** p
= &labels
[0];
5324 while ( *p
) { p
++; itemcount
++; }
5327 for ( i
= 0; i
< itemcount
; i
++ )
5332 wxPGChoiceEntry
entry(labels
[i
], value
);
5333 m_data
->Insert( i
, entry
);
5337 // -----------------------------------------------------------------------
5339 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5344 unsigned int itemcount
= arr
.size();
5346 for ( i
= 0; i
< itemcount
; i
++ )
5349 if ( &arrint
&& arrint
.size() )
5351 wxPGChoiceEntry
entry(arr
[i
], value
);
5352 m_data
->Insert( i
, entry
);
5356 // -----------------------------------------------------------------------
5358 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5360 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5361 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5362 m_data
->m_items
.begin()+nIndex
+count
);
5365 // -----------------------------------------------------------------------
5367 int wxPGChoices::Index( const wxString
& str
) const
5372 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5374 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5375 if ( entry
.HasText() && entry
.GetText() == str
)
5382 // -----------------------------------------------------------------------
5384 int wxPGChoices::Index( int val
) const
5389 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5391 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5392 if ( entry
.GetValue() == val
)
5399 // -----------------------------------------------------------------------
5401 wxArrayString
wxPGChoices::GetLabels() const
5406 if ( this && IsOk() )
5407 for ( i
=0; i
<GetCount(); i
++ )
5408 arr
.push_back(GetLabel(i
));
5413 // -----------------------------------------------------------------------
5415 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5422 for ( i
=0; i
< strings
.size(); i
++ )
5424 int index
= Index(strings
[i
]);
5426 arr
.Add(GetValue(index
));
5428 arr
.Add(wxPG_INVALID_VALUE
);
5435 // -----------------------------------------------------------------------
5437 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5438 wxArrayString
* unmatched
) const
5445 for ( i
=0; i
< strings
.size(); i
++ )
5447 const wxString
& str
= strings
[i
];
5448 int index
= Index(str
);
5451 else if ( unmatched
)
5452 unmatched
->Add(str
);
5459 // -----------------------------------------------------------------------
5461 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5465 if ( data
!= wxPGChoicesEmptyData
)
5472 // -----------------------------------------------------------------------
5474 void wxPGChoices::Init()
5476 m_data
= wxPGChoicesEmptyData
;
5479 // -----------------------------------------------------------------------
5481 void wxPGChoices::Free()
5483 if ( m_data
!= wxPGChoicesEmptyData
)
5486 m_data
= wxPGChoicesEmptyData
;
5490 // -----------------------------------------------------------------------
5491 // wxPropertyGridEvent
5492 // -----------------------------------------------------------------------
5494 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5497 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5498 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5499 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5500 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5501 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5502 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5503 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5504 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5505 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5508 // -----------------------------------------------------------------------
5510 void wxPropertyGridEvent::Init()
5512 m_validationInfo
= NULL
;
5514 m_wasVetoed
= false;
5517 // -----------------------------------------------------------------------
5519 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5520 : wxCommandEvent(commandType
,id
)
5526 // -----------------------------------------------------------------------
5528 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5529 : wxCommandEvent(event
)
5531 m_eventType
= event
.GetEventType();
5532 m_eventObject
= event
.m_eventObject
;
5534 m_property
= event
.m_property
;
5535 m_validationInfo
= event
.m_validationInfo
;
5536 m_canVeto
= event
.m_canVeto
;
5537 m_wasVetoed
= event
.m_wasVetoed
;
5540 // -----------------------------------------------------------------------
5542 wxPropertyGridEvent::~wxPropertyGridEvent()
5546 // -----------------------------------------------------------------------
5548 wxEvent
* wxPropertyGridEvent::Clone() const
5550 return new wxPropertyGridEvent( *this );
5553 // -----------------------------------------------------------------------
5554 // wxPropertyGridPopulator
5555 // -----------------------------------------------------------------------
5557 wxPropertyGridPopulator::wxPropertyGridPopulator()
5561 wxPGGlobalVars
->m_offline
++;
5564 // -----------------------------------------------------------------------
5566 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5569 m_propHierarchy
.clear();
5572 // -----------------------------------------------------------------------
5574 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5580 // -----------------------------------------------------------------------
5582 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5585 // Free unused sets of choices
5586 wxPGHashMapS2P::iterator it
;
5588 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5590 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5597 m_pg
->GetPanel()->Refresh();
5599 wxPGGlobalVars
->m_offline
--;
5602 // -----------------------------------------------------------------------
5604 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5605 const wxString
& propLabel
,
5606 const wxString
& propName
,
5607 const wxString
* propValue
,
5608 wxPGChoices
* pChoices
)
5610 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5611 wxPGProperty
* parent
= GetCurParent();
5613 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5615 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5619 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5621 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5625 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5627 property
->SetLabel(propLabel
);
5628 property
->DoSetName(propName
);
5630 if ( pChoices
&& pChoices
->IsOk() )
5631 property
->SetChoices(*pChoices
);
5633 m_state
->DoInsert(parent
, -1, property
);
5636 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5637 wxPG_PROGRAMMATIC_VALUE
);
5642 // -----------------------------------------------------------------------
5644 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5646 m_propHierarchy
.push_back(property
);
5647 DoScanForChildren();
5648 m_propHierarchy
.pop_back();
5651 // -----------------------------------------------------------------------
5653 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5654 const wxString
& idString
)
5656 wxPGChoices choices
;
5659 if ( choicesString
[0] == wxT('@') )
5661 wxString ids
= choicesString
.substr(1);
5662 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5663 if ( it
== m_dictIdChoices
.end() )
5664 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5666 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5671 if ( idString
.length() )
5673 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5674 if ( it
!= m_dictIdChoices
.end() )
5676 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5683 // Parse choices string
5684 wxString::const_iterator it
= choicesString
.begin();
5688 bool labelValid
= false;
5690 for ( ; it
!= choicesString
.end(); ++it
)
5696 if ( c
== wxT('"') )
5701 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5702 choices
.Add(label
, l
);
5705 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5710 else if ( c
== wxT('=') )
5717 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5724 if ( c
== wxT('"') )
5737 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5738 choices
.Add(label
, l
);
5741 if ( !choices
.IsOk() )
5743 choices
.EnsureData();
5747 if ( idString
.length() )
5748 m_dictIdChoices
[idString
] = choices
.GetData();
5755 // -----------------------------------------------------------------------
5757 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5759 if ( s
.Last() == wxT('%') )
5761 wxString s2
= s
.substr(0,s
.length()-1);
5763 if ( s2
.ToLong(&val
, 10) )
5765 *pval
= (val
*max
)/100;
5771 return s
.ToLong(pval
, 10);
5774 // -----------------------------------------------------------------------
5776 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5777 const wxString
& type
,
5778 const wxString
& value
)
5780 int l
= m_propHierarchy
.size();
5784 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5785 wxString valuel
= value
.Lower();
5788 if ( type
.length() == 0 )
5793 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5795 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5797 else if ( value
.ToLong(&v
, 0) )
5804 if ( type
== wxT("string") )
5808 else if ( type
== wxT("int") )
5811 value
.ToLong(&v
, 0);
5814 else if ( type
== wxT("bool") )
5816 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5823 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5828 p
->SetAttribute( name
, variant
);
5833 // -----------------------------------------------------------------------
5835 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5837 wxLogError(_("Error in resource: %s"),msg
.c_str());
5840 // -----------------------------------------------------------------------
5842 #endif // wxUSE_PROPGRID