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 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
964 if ( !(m_coloursCustomized
& 0x0002) )
966 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
968 // Make sure colour is dark enough
970 int colDec
= wxPGGetColAvg(col
) - 230;
972 int colDec
= wxPGGetColAvg(col
) - 200;
975 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
978 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
981 if ( !(m_coloursCustomized
& 0x0001) )
982 m_colMargin
= m_colCapBack
;
984 if ( !(m_coloursCustomized
& 0x0004) )
991 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
992 m_colCapFore
= capForeCol
;
993 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
996 if ( !(m_coloursCustomized
& 0x0008) )
998 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
999 m_colPropBack
= bgCol
;
1000 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1003 if ( !(m_coloursCustomized
& 0x0010) )
1005 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1006 m_colPropFore
= fgCol
;
1007 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1010 if ( !(m_coloursCustomized
& 0x0020) )
1011 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1013 if ( !(m_coloursCustomized
& 0x0040) )
1014 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1016 if ( !(m_coloursCustomized
& 0x0080) )
1017 m_colLine
= m_colCapBack
;
1019 if ( !(m_coloursCustomized
& 0x0100) )
1020 m_colDisPropFore
= m_colCapFore
;
1022 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1025 // -----------------------------------------------------------------------
1027 void wxPropertyGrid::ResetColours()
1029 m_coloursCustomized
= 0;
1036 // -----------------------------------------------------------------------
1038 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1040 // Must disable active editor.
1041 ClearSelection(false);
1043 // TODO: Following code is disabled with wxMac because
1044 // it is reported to fail. I (JMS) cannot debug it
1045 // personally right now.
1046 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1047 #if 1 // !defined(__WXMAC__)
1048 bool res
= wxScrolledWindow::SetFont( font
);
1051 CalculateFontAndBitmapStuff( m_vspacing
);
1054 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1062 // TODO: Remove after SetFont crash fixed.
1063 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1065 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."));
1071 // -----------------------------------------------------------------------
1073 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1076 m_coloursCustomized
|= 0x80;
1080 // -----------------------------------------------------------------------
1082 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1085 m_coloursCustomized
|= 0x01;
1089 // -----------------------------------------------------------------------
1091 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1093 m_colPropBack
= col
;
1094 m_coloursCustomized
|= 0x08;
1096 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1101 // -----------------------------------------------------------------------
1103 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1105 m_colPropFore
= col
;
1106 m_coloursCustomized
|= 0x10;
1108 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1113 // -----------------------------------------------------------------------
1115 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1117 m_colEmptySpace
= col
;
1122 // -----------------------------------------------------------------------
1124 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1126 m_colDisPropFore
= col
;
1127 m_coloursCustomized
|= 0x100;
1131 // -----------------------------------------------------------------------
1133 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1136 m_coloursCustomized
|= 0x20;
1140 // -----------------------------------------------------------------------
1142 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1145 m_coloursCustomized
|= 0x40;
1149 // -----------------------------------------------------------------------
1151 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1154 m_coloursCustomized
|= 0x02;
1156 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1161 // -----------------------------------------------------------------------
1163 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1166 m_coloursCustomized
|= 0x04;
1168 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1173 // -----------------------------------------------------------------------
1174 // wxPropertyGrid property adding and removal
1175 // -----------------------------------------------------------------------
1177 void wxPropertyGrid::PrepareAfterItemsAdded()
1179 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1181 m_pState
->m_itemsAdded
= 0;
1183 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1186 RecalculateVirtualSize();
1189 // -----------------------------------------------------------------------
1190 // wxPropertyGrid property value setting and getting
1191 // -----------------------------------------------------------------------
1193 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1195 m_pState
->DoSetPropertyValueUnspecified(p
);
1196 DrawItemAndChildren(p
);
1198 wxPGProperty
* parent
= p
->GetParent();
1200 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1203 parent
= parent
->GetParent();
1207 // -----------------------------------------------------------------------
1208 // wxPropertyGrid property operations
1209 // -----------------------------------------------------------------------
1211 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1213 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1217 bool changed
= false;
1219 // Is it inside collapsed section?
1220 if ( !p
->IsVisible() )
1223 wxPGProperty
* parent
= p
->GetParent();
1224 wxPGProperty
* grandparent
= parent
->GetParent();
1226 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1227 Expand( grandparent
);
1235 GetViewStart(&vx
,&vy
);
1236 vy
*=wxPG_PIXELS_PER_UNIT
;
1242 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1243 m_iFlags
|= wxPG_FL_SCROLLED
;
1246 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1248 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1249 m_iFlags
|= wxPG_FL_SCROLLED
;
1259 // -----------------------------------------------------------------------
1260 // wxPropertyGrid helper methods called by properties
1261 // -----------------------------------------------------------------------
1263 // Control font changer helper.
1264 void wxPropertyGrid::SetCurControlBoldFont()
1266 wxASSERT( m_wndEditor
);
1267 m_wndEditor
->SetFont( m_captionFont
);
1270 // -----------------------------------------------------------------------
1272 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1275 #if wxPG_SMALL_SCREEN
1276 // On small-screen devices, always show dialogs with default position and size.
1277 return wxDefaultPosition
;
1279 int splitterX
= GetSplitterPosition();
1283 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1285 ImprovedClientToScreen( &x
, &y
);
1287 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1288 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1295 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1305 new_y
= y
+ m_lineHeight
;
1307 return wxPoint(new_x
,new_y
);
1311 // -----------------------------------------------------------------------
1313 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1315 if ( src_str
.length() == 0 )
1321 bool prev_is_slash
= false;
1323 wxString::const_iterator i
= src_str
.begin();
1327 for ( ; i
!= src_str
.end(); i
++ )
1331 if ( a
!= wxS('\\') )
1333 if ( !prev_is_slash
)
1339 if ( a
== wxS('n') )
1342 dst_str
<< wxS('\n');
1344 dst_str
<< wxS('\n');
1347 else if ( a
== wxS('t') )
1348 dst_str
<< wxS('\t');
1352 prev_is_slash
= false;
1356 if ( prev_is_slash
)
1358 dst_str
<< wxS('\\');
1359 prev_is_slash
= false;
1363 prev_is_slash
= true;
1370 // -----------------------------------------------------------------------
1372 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1374 if ( src_str
.length() == 0 )
1380 wxString::const_iterator i
= src_str
.begin();
1381 wxUniChar prev_a
= wxS('\0');
1385 for ( ; i
!= src_str
.end(); i
++ )
1389 if ( a
>= wxS(' ') )
1391 // This surely is not something that requires an escape sequence.
1396 // This might need...
1397 if ( a
== wxS('\r') )
1399 // DOS style line end.
1400 // Already taken care below
1402 else if ( a
== wxS('\n') )
1403 // UNIX style line end.
1404 dst_str
<< wxS("\\n");
1405 else if ( a
== wxS('\t') )
1407 dst_str
<< wxS('\t');
1410 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1420 // -----------------------------------------------------------------------
1422 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1426 return (wxPGProperty
*) NULL
;
1429 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1432 // -----------------------------------------------------------------------
1433 // wxPropertyGrid graphics related methods
1434 // -----------------------------------------------------------------------
1436 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1440 // Update everything inside the box
1441 wxRect r
= GetUpdateRegion().GetBox();
1443 dc
.SetPen(m_colEmptySpace
);
1444 dc
.SetBrush(m_colEmptySpace
);
1445 dc
.DrawRectangle(r
);
1448 // -----------------------------------------------------------------------
1450 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1451 wxPGProperty
* property
) const
1453 // Prepare rectangle to be used
1455 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1456 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1458 #if (wxPG_USE_RENDERER_NATIVE)
1460 #elif wxPG_ICON_WIDTH
1461 // Drawing expand/collapse button manually
1462 dc
.SetPen(m_colPropFore
);
1463 if ( property
->IsCategory() )
1464 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1466 dc
.SetBrush(m_colPropBack
);
1468 dc
.DrawRectangle( r
);
1469 int _y
= r
.y
+(m_iconWidth
/2);
1470 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1475 if ( property
->IsExpanded() )
1477 // wxRenderer functions are non-mutating in nature, so it
1478 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1479 // Hopefully this does not cause problems.
1480 #if (wxPG_USE_RENDERER_NATIVE)
1481 wxRendererNative::Get().DrawTreeItemButton(
1487 #elif wxPG_ICON_WIDTH
1496 #if (wxPG_USE_RENDERER_NATIVE)
1497 wxRendererNative::Get().DrawTreeItemButton(
1503 #elif wxPG_ICON_WIDTH
1504 int _x
= r
.x
+(m_iconWidth
/2);
1505 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1511 #if (wxPG_USE_RENDERER_NATIVE)
1513 #elif wxPG_ICON_WIDTH
1516 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1520 // -----------------------------------------------------------------------
1523 // This is the one called by OnPaint event handler and others.
1524 // topy and bottomy are already unscrolled (ie. physical)
1526 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1528 unsigned int bottomy
,
1529 const wxRect
* clipRect
)
1531 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1533 m_pState
->EnsureVirtualHeight();
1535 wxRect tempClipRect
;
1538 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1539 clipRect
= &tempClipRect
;
1542 // items added check
1543 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1545 int paintFinishY
= 0;
1547 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1550 bool isBuffered
= false;
1552 #if wxPG_DOUBLE_BUFFER
1553 wxMemoryDC
* bufferDC
= NULL
;
1555 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1557 if ( !m_doubleBuffer
)
1559 paintFinishY
= clipRect
->y
;
1564 bufferDC
= new wxMemoryDC();
1566 // If nothing was changed, then just copy from double-buffer
1567 bufferDC
->SelectObject( *m_doubleBuffer
);
1577 dc
.SetClippingRegion( *clipRect
);
1578 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1581 #if wxPG_DOUBLE_BUFFER
1584 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1585 bufferDC
, 0, 0, wxCOPY
);
1586 dc
.DestroyClippingRegion(); // Is this really necessary?
1592 // Clear area beyond bottomY?
1593 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1595 dc
.SetPen(m_colEmptySpace
);
1596 dc
.SetBrush(m_colEmptySpace
);
1597 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1601 // -----------------------------------------------------------------------
1603 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1604 const wxPGProperty
* firstItem
,
1605 const wxPGProperty
* lastItem
,
1606 const wxRect
* clipRect
,
1607 bool isBuffered
) const
1609 // TODO: This should somehow be eliminated.
1610 wxRect tempClipRect
;
1613 wxASSERT(firstItem
);
1615 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1616 clipRect
= &tempClipRect
;
1620 firstItem
= DoGetItemAtY(clipRect
->y
);
1624 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1626 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1629 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1632 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1633 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1635 int lh
= m_lineHeight
;
1638 int lastItemBottomY
;
1640 firstItemTopY
= clipRect
->y
;
1641 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1643 // Align y coordinates to item boundaries
1644 firstItemTopY
-= firstItemTopY
% lh
;
1645 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1646 lastItemBottomY
-= 1;
1648 // Entire range outside scrolled, visible area?
1649 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1652 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1656 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1657 firstItem->GetLabel().c_str(),
1658 lastItem->GetLabel().c_str(),
1659 (int)(lastItemBottomY - firstItemTopY),
1661 (unsigned long)clipRect );
1666 long windowStyle
= m_windowStyle
;
1672 // With wxPG_DOUBLE_BUFFER, do double buffering
1673 // - buffer's y = 0, so align cliprect and coordinates to that
1675 #if wxPG_DOUBLE_BUFFER
1681 xRelMod
= clipRect
->x
;
1682 yRelMod
= clipRect
->y
;
1685 // clipRect conversion
1693 firstItemTopY
-= yRelMod
;
1694 lastItemBottomY
-= yRelMod
;
1697 wxUnusedVar(isBuffered
);
1700 int x
= m_marginWidth
- xRelMod
;
1702 const wxFont
& normalfont
= m_font
;
1704 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1706 bool isEnabled
= IsEnabled();
1709 // Prepare some pens and brushes that are often changed to.
1712 wxBrush
marginBrush(m_colMargin
);
1713 wxPen
marginPen(m_colMargin
);
1714 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1715 wxPen
linepen(m_colLine
,1,wxSOLID
);
1717 // pen that has same colour as text
1718 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1721 // Clear margin with background colour
1723 dc
.SetBrush( marginBrush
);
1724 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1726 dc
.SetPen( *wxTRANSPARENT_PEN
);
1727 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1730 const wxPGProperty
* selected
= m_selected
;
1731 const wxPropertyGridPageState
* state
= m_pState
;
1733 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1734 bool wasSelectedPainted
= false;
1737 // TODO: Only render columns that are within clipping region.
1739 dc
.SetFont(normalfont
);
1741 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1742 int endScanBottomY
= lastItemBottomY
+ lh
;
1743 int y
= firstItemTopY
;
1746 // Pregenerate list of visible properties.
1747 wxArrayPGProperty visPropArray
;
1748 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1750 for ( ; !it
.AtEnd(); it
.Next() )
1752 const wxPGProperty
* p
= *it
;
1754 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1756 visPropArray
.push_back((wxPGProperty
*)p
);
1758 if ( y
> endScanBottomY
)
1765 visPropArray
.push_back(NULL
);
1767 wxPGProperty
* nextP
= visPropArray
[0];
1769 int gridWidth
= state
->m_width
;
1772 for ( unsigned int arrInd
=1;
1773 nextP
&& y
<= lastItemBottomY
;
1776 wxPGProperty
* p
= nextP
;
1777 nextP
= visPropArray
[arrInd
];
1779 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1780 int textMarginHere
= x
;
1781 int renderFlags
= 0;
1783 int greyDepth
= m_marginWidth
;
1784 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1785 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1787 int greyDepthX
= greyDepth
- xRelMod
;
1789 // Use basic depth if in non-categoric mode and parent is base array.
1790 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1792 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1795 // Paint margin area
1796 dc
.SetBrush(marginBrush
);
1797 dc
.SetPen(marginPen
);
1798 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1800 dc
.SetPen( linepen
);
1805 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1811 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1813 sx
+= state
->m_colWidths
[si
];
1814 dc
.DrawLine( sx
, y
, sx
, y2
);
1817 // Horizontal Line, below
1818 // (not if both this and next is category caption)
1819 if ( p
->IsCategory() &&
1820 nextP
&& nextP
->IsCategory() )
1821 dc
.SetPen(m_colCapBack
);
1823 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1826 // Need to override row colours?
1830 if ( p
!= selected
)
1832 // Disabled may get different colour.
1833 if ( !p
->IsEnabled() )
1835 renderFlags
|= wxPGCellRenderer::Disabled
|
1836 wxPGCellRenderer::DontUseCellFgCol
;
1837 rowFgCol
= m_colDisPropFore
;
1842 renderFlags
|= wxPGCellRenderer::Selected
;
1844 if ( !p
->IsCategory() )
1846 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1847 wxPGCellRenderer::DontUseCellBgCol
;
1849 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1850 wasSelectedPainted
= true;
1853 // Selected gets different colour.
1854 if ( reallyFocused
)
1856 rowFgCol
= m_colSelFore
;
1857 rowBgCol
= m_colSelBack
;
1859 else if ( isEnabled
)
1861 rowFgCol
= m_colPropFore
;
1862 rowBgCol
= m_colMargin
;
1866 rowFgCol
= m_colDisPropFore
;
1867 rowBgCol
= m_colSelBack
;
1874 if ( rowBgCol
.IsOk() )
1875 rowBgBrush
= wxBrush(rowBgCol
);
1877 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1878 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1881 // Fill additional margin area with background colour of first cell
1882 if ( greyDepthX
< textMarginHere
)
1884 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1886 wxPGCell
& cell
= p
->GetCell(0);
1887 rowBgCol
= cell
.GetBgCol();
1888 rowBgBrush
= wxBrush(rowBgCol
);
1890 dc
.SetBrush(rowBgBrush
);
1891 dc
.SetPen(rowBgCol
);
1892 dc
.DrawRectangle(greyDepthX
+1, y
,
1893 textMarginHere
-greyDepthX
, lh
-1);
1896 bool fontChanged
= false;
1898 // Expander button rectangle
1899 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1904 if ( p
->IsCategory() )
1906 // Captions have their cell areas merged as one
1907 dc
.SetFont(m_captionFont
);
1909 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1911 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1913 dc
.SetBrush(rowBgBrush
);
1914 dc
.SetPen(rowBgCol
);
1917 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1919 dc
.SetTextForeground(rowFgCol
);
1922 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1923 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1926 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1927 DrawExpanderButton( dc
, butRect
, p
);
1931 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1933 dc
.SetFont(m_captionFont
);
1939 int nextCellWidth
= state
->m_colWidths
[0];
1940 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1941 int textXAdd
= textMarginHere
- greyDepthX
;
1943 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1945 cellRect
.width
= nextCellWidth
- 1;
1947 bool ctrlCell
= false;
1948 int cellRenderFlags
= renderFlags
;
1951 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1952 DrawExpanderButton( dc
, butRect
, p
);
1955 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1957 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1958 dc
.SetBrush(editorBgCol
);
1959 dc
.SetPen(editorBgCol
);
1960 dc
.SetTextForeground(m_colPropFore
);
1961 dc
.DrawRectangle(cellRect
);
1963 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1968 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1970 dc
.SetBrush(rowBgBrush
);
1971 dc
.SetPen(rowBgCol
);
1974 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1976 dc
.SetTextForeground(rowFgCol
);
1980 dc
.SetClippingRegion(cellRect
);
1982 cellRect
.x
+= textXAdd
;
1983 cellRect
.width
-= textXAdd
;
1988 wxPGCellRenderer
* renderer
;
1989 int cmnVal
= p
->GetCommonValue();
1990 if ( cmnVal
== -1 || ci
!= 1 )
1992 renderer
= p
->GetCellRenderer(ci
);
1993 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1998 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1999 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2004 cellX
+= state
->m_colWidths
[ci
];
2005 if ( ci
< (state
->m_colWidths
.size()-1) )
2006 nextCellWidth
= state
->m_colWidths
[ci
+1];
2008 dc
.DestroyClippingRegion(); // Is this really necessary?
2014 dc
.SetFont(normalfont
);
2019 // Refresh editor controls (seems not needed on msw)
2020 // NOTE: This code is mandatory for GTK!
2021 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2022 if ( wasSelectedPainted
)
2025 m_wndEditor
->Refresh();
2027 m_wndEditor2
->Refresh();
2034 // -----------------------------------------------------------------------
2036 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2040 if ( m_width
< 10 || m_height
< 10 ||
2041 !m_pState
->m_properties
->GetChildCount() ||
2042 p1
== (wxPGProperty
*) NULL
)
2043 return wxRect(0,0,0,0);
2048 // Return rect which encloses the given property range
2050 int visTop
= p1
->GetY();
2053 visBottom
= p2
->GetY() + m_lineHeight
;
2055 visBottom
= m_height
+ visTop
;
2057 // If seleced property is inside the range, we'll extend the range to include
2059 wxPGProperty
* selected
= m_selected
;
2062 int selectedY
= selected
->GetY();
2063 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2065 wxWindow
* editor
= GetEditorControl();
2068 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2069 if ( visBottom2
> visBottom
)
2070 visBottom
= visBottom2
;
2075 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2078 // -----------------------------------------------------------------------
2080 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2085 if ( m_pState
->m_itemsAdded
)
2086 PrepareAfterItemsAdded();
2088 wxRect r
= GetPropertyRect(p1
, p2
);
2091 m_canvas
->RefreshRect(r
);
2095 // -----------------------------------------------------------------------
2097 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2099 if ( p
== m_selected
)
2100 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2102 DrawItemAndChildren(p
);
2105 // -----------------------------------------------------------------------
2107 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2112 // Draw item, children, and parent too, if it is not category
2113 wxPGProperty
* parent
= p
->GetParent();
2116 !parent
->IsCategory() &&
2117 parent
->GetParent() )
2120 parent
= parent
->GetParent();
2123 DrawItemAndChildren(p
);
2126 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2128 wxCHECK_RET( p
, wxT("invalid property id") );
2130 // Do not draw if in non-visible page
2131 if ( p
->GetParentState() != m_pState
)
2134 // do not draw a single item if multiple pending
2135 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2138 wxWindow
* wndPrimary
= GetEditorControl();
2140 // Update child control.
2141 if ( m_selected
&& m_selected
->GetParent() == p
)
2142 m_selected
->UpdateControl(wndPrimary
);
2144 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2146 DrawItems(p
, lastDrawn
);
2149 // -----------------------------------------------------------------------
2151 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2152 const wxRect
*rect
)
2154 PrepareAfterItemsAdded();
2156 wxWindow::Refresh(false);
2158 // TODO: Coordinate translation
2159 m_canvas
->Refresh(false, rect
);
2161 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2162 // I think this really helps only GTK+1.2
2163 if ( m_wndEditor
) m_wndEditor
->Refresh();
2164 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2168 // -----------------------------------------------------------------------
2169 // wxPropertyGrid global operations
2170 // -----------------------------------------------------------------------
2172 void wxPropertyGrid::Clear()
2174 ClearSelection(false);
2176 m_pState
->DoClear();
2182 RecalculateVirtualSize();
2184 // Need to clear some area at the end
2186 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2189 // -----------------------------------------------------------------------
2191 bool wxPropertyGrid::EnableCategories( bool enable
)
2193 ClearSelection(false);
2198 // Enable categories
2201 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2206 // Disable categories
2208 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2211 if ( !m_pState
->EnableCategories(enable
) )
2216 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2218 m_pState
->m_itemsAdded
= 1; // force
2219 PrepareAfterItemsAdded();
2223 m_pState
->m_itemsAdded
= 1;
2225 // No need for RecalculateVirtualSize() here - it is already called in
2226 // wxPropertyGridPageState method above.
2233 // -----------------------------------------------------------------------
2235 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2237 wxASSERT( pNewState
);
2238 wxASSERT( pNewState
->GetGrid() );
2240 if ( pNewState
== m_pState
)
2243 wxPGProperty
* oldSelection
= m_selected
;
2245 ClearSelection(false);
2247 m_pState
->m_selected
= oldSelection
;
2249 bool orig_mode
= m_pState
->IsInNonCatMode();
2250 bool new_state_mode
= pNewState
->IsInNonCatMode();
2252 m_pState
= pNewState
;
2255 int pgWidth
= GetClientSize().x
;
2256 if ( HasVirtualWidth() )
2258 int minWidth
= pgWidth
;
2259 if ( pNewState
->m_width
< minWidth
)
2261 pNewState
->m_width
= minWidth
;
2262 pNewState
->CheckColumnWidths();
2268 // Just in case, fully re-center splitter
2269 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2270 pNewState
->m_fSplitterX
= -1.0;
2272 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2275 m_propHover
= (wxPGProperty
*) NULL
;
2277 // If necessary, convert state to correct mode.
2278 if ( orig_mode
!= new_state_mode
)
2280 // This should refresh as well.
2281 EnableCategories( orig_mode
?false:true );
2283 else if ( !m_frozen
)
2285 // Refresh, if not frozen.
2286 if ( m_pState
->m_itemsAdded
)
2287 PrepareAfterItemsAdded();
2290 if ( m_pState
->m_selected
)
2291 DoSelectProperty( m_pState
->m_selected
);
2293 RecalculateVirtualSize(0);
2297 m_pState
->m_itemsAdded
= 1;
2300 // -----------------------------------------------------------------------
2302 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2304 wxPG_PROP_ARG_CALL_PROLOG()
2306 m_pState
->SortChildren( p
);
2309 // -----------------------------------------------------------------------
2311 void wxPropertyGrid::Sort()
2313 ClearSelection(false); // This must be before state clear
2318 // -----------------------------------------------------------------------
2320 // Call to SetSplitterPosition will always disable splitter auto-centering
2321 // if parent window is shown.
2322 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2324 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2327 wxPropertyGridPageState
* state
= m_pState
;
2329 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2334 CorrectEditorWidgetSizeX();
2340 // -----------------------------------------------------------------------
2342 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2344 SetSplitterPosition( m_width
/2, true );
2345 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2346 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2349 // -----------------------------------------------------------------------
2350 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2351 // -----------------------------------------------------------------------
2353 // Returns nearest paint visible property (such that will be painted unless
2354 // window is scrolled or resized). If given property is paint visible, then
2355 // it itself will be returned
2356 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2358 int vx
,vy1
;// Top left corner of client
2359 GetViewStart(&vx
,&vy1
);
2360 vy1
*= wxPG_PIXELS_PER_UNIT
;
2362 int vy2
= vy1
+ m_height
;
2363 int propY
= p
->GetY2(m_lineHeight
);
2365 if ( (propY
+ m_lineHeight
) < vy1
)
2368 return DoGetItemAtY( vy1
);
2370 else if ( propY
> vy2
)
2373 return DoGetItemAtY( vy2
);
2376 // Itself paint visible
2381 // -----------------------------------------------------------------------
2382 // Methods related to change in value, value modification and sending events
2383 // -----------------------------------------------------------------------
2385 // commits any changes in editor of selected property
2386 // return true if validation did not fail
2387 // flags are same as with DoSelectProperty
2388 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2390 // Committing already?
2391 if ( m_inCommitChangesFromEditor
)
2394 // Don't do this if already processing editor event. It might
2395 // induce recursive dialogs and crap like that.
2396 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2398 if ( m_inDoPropertyChanged
)
2405 IsEditorsValueModified() &&
2406 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2409 m_inCommitChangesFromEditor
= 1;
2411 wxVariant
variant(m_selected
->GetValueRef());
2412 bool valueIsPending
= false;
2414 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2415 // due to another window getting focus
2416 wxWindow
* oldFocus
= m_curFocused
;
2418 bool validationFailure
= false;
2419 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2421 m_chgInfo_changedProperty
= NULL
;
2423 // If truly modified, schedule value as pending.
2424 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2426 if ( DoEditorValidate() &&
2427 PerformValidation(m_selected
, variant
) )
2429 valueIsPending
= true;
2433 validationFailure
= true;
2438 EditorsValueWasNotModified();
2443 m_inCommitChangesFromEditor
= 0;
2445 if ( validationFailure
&& !forceSuccess
)
2449 oldFocus
->SetFocus();
2450 m_curFocused
= oldFocus
;
2453 res
= OnValidationFailure(m_selected
, variant
);
2455 // Now prevent further validation failure messages
2458 EditorsValueWasNotModified();
2459 OnValidationFailureReset(m_selected
);
2462 else if ( valueIsPending
)
2464 DoPropertyChanged( m_selected
, flags
);
2465 EditorsValueWasNotModified();
2474 // -----------------------------------------------------------------------
2476 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2480 // Runs all validation functionality.
2481 // Returns true if value passes all tests.
2484 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2486 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2488 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2493 // Adapt list to child values, if necessary
2494 wxVariant listValue
= pendingValue
;
2495 wxVariant
* pPendingValue
= &pendingValue
;
2496 wxVariant
* pList
= NULL
;
2498 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2499 // string value, then we need treat as it was changed instead
2500 // (or, in addition, as is the case with composite string parent).
2501 // This includes creating list variant for child values.
2503 wxPGProperty
* pwc
= p
->GetParent();
2504 wxPGProperty
* changedProperty
= p
;
2505 wxPGProperty
* baseChangedProperty
= changedProperty
;
2506 wxVariant bcpPendingList
;
2508 listValue
= pendingValue
;
2509 listValue
.SetName(p
->GetBaseName());
2512 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2514 wxVariantList tempList
;
2515 wxVariant
lv(tempList
, pwc
->GetBaseName());
2516 lv
.Append(listValue
);
2518 pPendingValue
= &listValue
;
2520 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2522 baseChangedProperty
= pwc
;
2523 bcpPendingList
= lv
;
2526 changedProperty
= pwc
;
2527 pwc
= pwc
->GetParent();
2531 wxPGProperty
* evtChangingProperty
= changedProperty
;
2533 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2535 value
= *pPendingValue
;
2539 // Convert list to child values
2540 pList
= pPendingValue
;
2541 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2544 wxVariant evtChangingValue
= value
;
2546 if ( flags
& SendEvtChanging
)
2548 // FIXME: After proper ValueToString()s added, remove
2549 // this. It is just a temporary fix, as evt_changing
2550 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2551 // (unless it is selected, and textctrl editor is open).
2552 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2554 evtChangingProperty
= baseChangedProperty
;
2555 if ( evtChangingProperty
!= p
)
2557 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2561 evtChangingValue
= pendingValue
;
2565 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2567 if ( changedProperty
== m_selected
)
2569 wxWindow
* editor
= GetEditorControl();
2570 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2571 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2575 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2580 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2581 m_chgInfo_changedProperty
= changedProperty
;
2582 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2583 m_chgInfo_pendingValue
= value
;
2586 m_chgInfo_valueList
= *pList
;
2588 m_chgInfo_valueList
.MakeNull();
2590 // If changedProperty is not property which value was edited,
2591 // then call wxPGProperty::ValidateValue() for that as well.
2592 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2594 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2598 if ( flags
& SendEvtChanging
)
2600 // SendEvent returns true if event was vetoed
2601 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2605 if ( flags
& IsStandaloneValidation
)
2607 // If called in 'generic' context, we need to reset
2608 // m_chgInfo_changedProperty and write back translated value.
2609 m_chgInfo_changedProperty
= NULL
;
2610 pendingValue
= value
;
2616 // -----------------------------------------------------------------------
2618 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2620 if ( !msg
.length() )
2624 if ( !wxPGGlobalVars
->m_offline
)
2626 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2629 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2632 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2635 pStatusBar
->SetStatusText(msg
);
2643 ::wxMessageBox(msg
, _T("Property Error"));
2646 // -----------------------------------------------------------------------
2648 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2650 int vfb
= m_validationInfo
.m_failureBehavior
;
2652 if ( vfb
& wxPG_VFB_BEEP
)
2655 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2656 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2658 unsigned int colCount
= m_pState
->GetColumnCount();
2660 // We need backup marked property's cells
2661 m_propCellsBackup
= property
->m_cells
;
2663 wxColour vfbFg
= *wxWHITE
;
2664 wxColour vfbBg
= *wxRED
;
2666 property
->EnsureCells(colCount
);
2668 for ( unsigned int i
=0; i
<colCount
; i
++ )
2670 wxPGCell
& cell
= property
->m_cells
[i
];
2671 cell
.SetFgCol(vfbFg
);
2672 cell
.SetBgCol(vfbBg
);
2675 DrawItemAndChildren(property
);
2677 if ( property
== m_selected
)
2679 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2681 wxWindow
* editor
= GetEditorControl();
2684 editor
->SetForegroundColour(vfbFg
);
2685 editor
->SetBackgroundColour(vfbBg
);
2690 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2692 wxString msg
= m_validationInfo
.m_failureMessage
;
2694 if ( !msg
.length() )
2695 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2697 DoShowPropertyError(property
, msg
);
2700 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2703 // -----------------------------------------------------------------------
2705 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2707 int vfb
= m_validationInfo
.m_failureBehavior
;
2709 if ( vfb
& wxPG_VFB_MARK_CELL
)
2712 property
->m_cells
= m_propCellsBackup
;
2714 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2716 if ( property
== m_selected
&& GetEditorControl() )
2718 // Calling this will recreate the control, thus resetting its colour
2719 RefreshProperty(property
);
2723 DrawItemAndChildren(property
);
2728 // -----------------------------------------------------------------------
2730 // flags are same as with DoSelectProperty
2731 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2733 if ( m_inDoPropertyChanged
)
2736 wxWindow
* editor
= GetEditorControl();
2738 m_pState
->m_anyModified
= 1;
2740 m_inDoPropertyChanged
= 1;
2742 // Maybe need to update control
2743 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2745 // These values were calculated in PerformValidation()
2746 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2747 wxVariant value
= m_chgInfo_pendingValue
;
2749 wxPGProperty
* topPaintedProperty
= changedProperty
;
2751 while ( !topPaintedProperty
->IsCategory() &&
2752 !topPaintedProperty
->IsRoot() )
2754 topPaintedProperty
= topPaintedProperty
->GetParent();
2757 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2759 // Set as Modified (not if dragging just began)
2760 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2762 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2763 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2766 SetCurControlBoldFont();
2772 // Propagate updates to parent(s)
2774 wxPGProperty
* prevPwc
= NULL
;
2776 while ( prevPwc
!= topPaintedProperty
)
2778 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2780 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2783 SetCurControlBoldFont();
2787 pwc
= pwc
->GetParent();
2790 // Draw the actual property
2791 DrawItemAndChildren( topPaintedProperty
);
2794 // If value was set by wxPGProperty::OnEvent, then update the editor
2796 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2799 p
->GetEditorClass()->UpdateControl(p
, editor
);
2803 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2804 if ( m_wndEditor
) m_wndEditor
->Refresh();
2805 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2810 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2812 // If top parent has composite string value, then send to child parents,
2813 // starting from baseChangedProperty.
2814 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2816 pwc
= m_chgInfo_baseChangedProperty
;
2818 while ( pwc
!= changedProperty
)
2820 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2821 pwc
= pwc
->GetParent();
2825 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2827 m_inDoPropertyChanged
= 0;
2832 // -----------------------------------------------------------------------
2834 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2836 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2838 m_chgInfo_changedProperty
= NULL
;
2840 if ( PerformValidation(p
, newValue
) )
2842 DoPropertyChanged(p
);
2847 OnValidationFailure(p
, newValue
);
2853 // -----------------------------------------------------------------------
2855 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2857 wxPGProperty
* prop
= GetSelectedProperty();
2860 return wxNullVariant
;
2862 wxTextCtrl
* tc
= GetEditorTextCtrl();
2863 wxVariant value
= prop
->GetValue();
2865 if ( !tc
|| !IsEditorsValueModified() )
2868 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2871 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2872 return prop
->GetValue();
2877 // -----------------------------------------------------------------------
2879 // Runs wxValidator for the selected property
2880 bool wxPropertyGrid::DoEditorValidate()
2885 // -----------------------------------------------------------------------
2887 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
2889 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
2890 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
2892 wxWindow
* parent
= wnd
->GetParent();
2895 (parent
== m_canvas
||
2896 parent
->GetParent() == m_canvas
) )
2898 OnCustomEditorEvent(event
);
2902 return wxPanel::ProcessEvent(event
);
2905 // -----------------------------------------------------------------------
2907 void wxPropertyGrid::OnCustomEditorEvent( wxEvent
&event
)
2909 wxPGProperty
* selected
= m_selected
;
2911 // Somehow, event is handled after property has been deselected.
2912 // Possibly, but very rare.
2916 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2919 wxVariant
pendingValue(selected
->GetValueRef());
2920 wxWindow
* wnd
= GetEditorControl();
2922 bool wasUnspecified
= selected
->IsValueUnspecified();
2923 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2925 bool valueIsPending
= false;
2927 m_chgInfo_changedProperty
= NULL
;
2929 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2932 // Filter out excess wxTextCtrl modified events
2933 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2935 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2937 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2939 wxString newTcValue
= tc
->GetValue();
2940 if ( m_prevTcValue
== newTcValue
)
2943 m_prevTcValue
= newTcValue
;
2946 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
2948 bool validationFailure
= false;
2949 bool buttonWasHandled
= false;
2952 // Try common button handling
2953 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2955 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2959 buttonWasHandled
= true;
2960 // Store as res2, as previously (and still currently alternatively)
2961 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2962 // in wxPGProperty::OnEvent().
2963 adapter
->ShowDialog( this, selected
);
2968 if ( !buttonWasHandled
)
2972 // First call editor class' event handler.
2973 const wxPGEditor
* editor
= selected
->GetEditorClass();
2975 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2977 // If changes, validate them
2978 if ( DoEditorValidate() )
2980 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2981 valueIsPending
= true;
2985 validationFailure
= true;
2990 // Then the property's custom handler (must be always called, unless
2991 // validation failed).
2992 if ( !validationFailure
)
2993 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2996 // SetValueInEvent(), as called in one of the functions referred above
2997 // overrides editor's value.
2998 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3000 valueIsPending
= true;
3001 pendingValue
= m_changeInEventValue
;
3002 selFlags
|= wxPG_SEL_DIALOGVAL
;
3005 if ( !validationFailure
&& valueIsPending
)
3006 if ( !PerformValidation(m_selected
, pendingValue
) )
3007 validationFailure
= true;
3009 if ( validationFailure
)
3011 OnValidationFailure(selected
, pendingValue
);
3013 else if ( valueIsPending
)
3015 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3017 DoPropertyChanged(selected
, selFlags
);
3018 EditorsValueWasNotModified();
3020 // Regardless of editor type, unfocus editor on
3021 // text-editing related enter press.
3022 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3029 // No value after all
3031 // Regardless of editor type, unfocus editor on
3032 // text-editing related enter press.
3033 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3038 // Let unhandled button click events go to the parent
3039 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3041 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3042 GetEventHandler()->AddPendingEvent(evt
);
3046 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3049 // -----------------------------------------------------------------------
3050 // wxPropertyGrid editor control helper methods
3051 // -----------------------------------------------------------------------
3053 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3055 int itemy
= p
->GetY2(m_lineHeight
);
3057 int cust_img_space
= 0;
3058 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3059 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3061 // TODO: If custom image detection changes from current, change this.
3062 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3064 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3065 int imwid
= p
->OnMeasureImage().x
;
3066 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3067 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3072 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3074 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3079 // -----------------------------------------------------------------------
3081 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3083 wxSize sz
= GetImageSize(p
, item
);
3084 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3085 wxPG_CUSTOM_IMAGE_SPACINGY
,
3090 // return size of custom paint image
3091 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3093 // If called with NULL property, then return default image
3094 // size for properties that use image.
3096 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3098 wxSize cis
= p
->OnMeasureImage(item
);
3100 int choiceCount
= p
->m_choices
.GetCount();
3101 int comVals
= p
->GetDisplayedCommonValueCount();
3102 if ( item
>= choiceCount
&& comVals
> 0 )
3104 unsigned int cvi
= item
-choiceCount
;
3105 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3107 else if ( item
>= 0 && choiceCount
== 0 )
3108 return wxSize(0, 0);
3113 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3118 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3125 // -----------------------------------------------------------------------
3127 // takes scrolling into account
3128 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3131 GetViewStart(&vx
,&vy
);
3132 vy
*=wxPG_PIXELS_PER_UNIT
;
3133 vx
*=wxPG_PIXELS_PER_UNIT
;
3136 ClientToScreen( px
, py
);
3139 // -----------------------------------------------------------------------
3141 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3144 GetViewStart(&pt2
.x
,&pt2
.y
);
3145 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3146 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3150 return m_pState
->HitTest(pt2
);
3153 // -----------------------------------------------------------------------
3155 // custom set cursor
3156 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3158 if ( type
== m_curcursor
&& !override
) return;
3160 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3162 if ( type
== wxCURSOR_SIZEWE
)
3163 cursor
= m_cursorSizeWE
;
3165 m_canvas
->SetCursor( *cursor
);
3170 // -----------------------------------------------------------------------
3171 // wxPropertyGrid property selection
3172 // -----------------------------------------------------------------------
3174 // Setups event handling for child control
3175 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3177 wxWindowID id
= argWnd
->GetId();
3179 if ( argWnd
== m_wndEditor
)
3181 argWnd
->Connect(id
, wxEVT_MOTION
,
3182 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3184 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3185 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3187 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3188 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3190 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3191 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3193 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3194 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3196 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3197 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3201 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3202 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3206 void wxPropertyGrid::FreeEditors()
3209 // Return focus back to canvas from children (this is required at least for
3210 // GTK+, which, unlike Windows, clears focus when control is destroyed
3211 // instead of moving it to closest parent).
3212 wxWindow
* focus
= wxWindow::FindFocus();
3215 wxWindow
* parent
= focus
->GetParent();
3218 if ( parent
== m_canvas
)
3223 parent
= parent
->GetParent();
3227 // Do not free editors immediately if processing events
3230 m_wndEditor2
->Hide();
3231 wxPendingDelete
.Append( m_wndEditor2
);
3232 m_wndEditor2
= (wxWindow
*) NULL
;
3237 m_wndEditor
->Hide();
3238 wxPendingDelete
.Append( m_wndEditor
);
3239 m_wndEditor
= (wxWindow
*) NULL
;
3243 // Call with NULL to de-select property
3244 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3248 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3249 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3251 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3254 if ( m_inDoSelectProperty
)
3257 m_inDoSelectProperty
= 1;
3259 wxPGProperty
* prev
= m_selected
;
3263 m_inDoSelectProperty
= 0;
3269 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3271 wxPrintf( "None selected\n" );
3274 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3276 wxPrintf( "P = NULL\n" );
3279 // If we are frozen, then just set the values.
3282 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3283 m_editorFocused
= 0;
3286 m_pState
->m_selected
= p
;
3288 // If frozen, always free controls. But don't worry, as Thaw will
3289 // recall SelectProperty to recreate them.
3292 // Prevent any further selection measures in this call
3293 p
= (wxPGProperty
*) NULL
;
3298 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3300 // Only set focus if not deselecting
3303 if ( flags
& wxPG_SEL_FOCUS
)
3307 m_wndEditor
->SetFocus();
3308 m_editorFocused
= 1;
3317 m_inDoSelectProperty
= 0;
3322 // First, deactivate previous
3326 OnValidationFailureReset(m_selected
);
3328 // Must double-check if this is an selected in case of forceswitch
3331 if ( !CommitChangesFromEditor(flags
) )
3333 // Validation has failed, so we can't exit the previous editor
3334 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3335 // _("Invalid Value"),wxOK|wxICON_ERROR);
3336 m_inDoSelectProperty
= 0;
3344 m_selected
= (wxPGProperty
*) NULL
;
3345 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3347 // We need to always fully refresh the grid here
3350 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3351 EditorsValueWasNotModified();
3354 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3357 // Then, activate the one given.
3360 int propY
= p
->GetY2(m_lineHeight
);
3362 int splitterX
= GetSplitterPosition();
3363 m_editorFocused
= 0;
3365 m_pState
->m_selected
= p
;
3366 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3368 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3370 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3372 // Do we need OnMeasureCalls?
3373 wxSize imsz
= p
->OnMeasureImage();
3376 // Only create editor for non-disabled non-caption
3377 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3379 // do this for non-caption items
3383 // Do we need to paint the custom image, if any?
3384 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3385 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3386 !p
->GetEditorClass()->CanContainCustomImage()
3388 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3390 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3391 wxPoint goodPos
= grect
.GetPosition();
3392 #if wxPG_CREATE_CONTROLS_HIDDEN
3393 int coord_adjust
= m_height
- goodPos
.y
;
3394 goodPos
.y
+= coord_adjust
;
3397 const wxPGEditor
* editor
= p
->GetEditorClass();
3398 wxCHECK_MSG(editor
, false,
3399 wxT("NULL editor class not allowed"));
3401 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3403 wxPGWindowList wndList
= editor
->CreateControls(this,
3408 m_wndEditor
= wndList
.m_primary
;
3409 m_wndEditor2
= wndList
.m_secondary
;
3410 wxWindow
* primaryCtrl
= GetEditorControl();
3413 // Essentially, primaryCtrl == m_wndEditor
3416 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3417 // value is drawn as normal, and m_wndEditor2 is assumed
3418 // to be a right-aligned button that triggers a separate editorCtrl
3423 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3424 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3426 // Set validator, if any
3427 #if wxUSE_VALIDATORS
3428 wxValidator
* validator
= p
->GetValidator();
3430 primaryCtrl
->SetValidator(*validator
);
3433 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3434 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3436 // If it has modified status, use bold font
3437 // (must be done before capturing m_ctrlXAdjust)
3438 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3439 SetCurControlBoldFont();
3442 // Fix TextCtrl indentation
3443 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3444 wxTextCtrl
* tc
= NULL
;
3445 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3446 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3448 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3450 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3453 // Store x relative to splitter (we'll need it).
3454 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3456 // Check if background clear is not necessary
3457 wxPoint pos
= m_wndEditor
->GetPosition();
3458 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3460 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3463 m_wndEditor
->SetSizeHints(3, 3);
3465 #if wxPG_CREATE_CONTROLS_HIDDEN
3466 m_wndEditor
->Show(false);
3467 m_wndEditor
->Freeze();
3469 goodPos
= m_wndEditor
->GetPosition();
3470 goodPos
.y
-= coord_adjust
;
3471 m_wndEditor
->Move( goodPos
);
3474 SetupChildEventHandling(primaryCtrl
);
3476 // Focus and select all (wxTextCtrl, wxComboBox etc)
3477 if ( flags
& wxPG_SEL_FOCUS
)
3479 primaryCtrl
->SetFocus();
3481 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3487 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3488 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3490 // Get proper id for wndSecondary
3491 m_wndSecId
= m_wndEditor2
->GetId();
3492 wxWindowList children
= m_wndEditor2
->GetChildren();
3493 wxWindowList::iterator node
= children
.begin();
3494 if ( node
!= children
.end() )
3495 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3497 m_wndEditor2
->SetSizeHints(3,3);
3499 #if wxPG_CREATE_CONTROLS_HIDDEN
3500 wxRect sec_rect
= m_wndEditor2
->GetRect();
3501 sec_rect
.y
-= coord_adjust
;
3503 // Fine tuning required to fix "oversized"
3504 // button disappearance bug.
3505 if ( sec_rect
.y
< 0 )
3507 sec_rect
.height
+= sec_rect
.y
;
3510 m_wndEditor2
->SetSize( sec_rect
);
3512 m_wndEditor2
->Show();
3514 SetupChildEventHandling(m_wndEditor2
);
3516 // If no primary editor, focus to button to allow
3517 // it to interprete ENTER etc.
3518 // NOTE: Due to problems focusing away from it, this
3519 // has been disabled.
3521 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3522 m_wndEditor2->SetFocus();
3526 if ( flags
& wxPG_SEL_FOCUS
)
3527 m_editorFocused
= 1;
3532 // Make sure focus is in grid canvas (important for wxGTK, at least)
3536 EditorsValueWasNotModified();
3538 // If it's inside collapsed section, expand parent, scroll, etc.
3539 // Also, if it was partially visible, scroll it into view.
3540 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3545 #if wxPG_CREATE_CONTROLS_HIDDEN
3546 m_wndEditor
->Thaw();
3548 m_wndEditor
->Show(true);
3555 // Make sure focus is in grid canvas
3559 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3565 // Show help text in status bar.
3566 // (if found and grid not embedded in manager with help box and
3567 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3570 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3572 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3573 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3575 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3577 statusbar
= frame
->GetStatusBar();
3582 const wxString
* pHelpString
= (const wxString
*) NULL
;
3586 pHelpString
= &p
->GetHelpString();
3587 if ( pHelpString
->length() )
3589 // Set help box text.
3590 statusbar
->SetStatusText( *pHelpString
);
3591 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3595 if ( (!pHelpString
|| !pHelpString
->length()) &&
3596 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3598 // Clear help box - but only if it was written
3599 // by us at previous time.
3600 statusbar
->SetStatusText( m_emptyString
);
3601 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3607 m_inDoSelectProperty
= 0;
3609 // call wx event handler (here so that it also occurs on deselection)
3610 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3615 // -----------------------------------------------------------------------
3617 bool wxPropertyGrid::UnfocusEditor()
3619 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3622 if ( !CommitChangesFromEditor(0) )
3626 DrawItem(m_selected
);
3631 // -----------------------------------------------------------------------
3633 // This method is not inline because it called dozens of times
3634 // (i.e. two-arg function calls create smaller code size).
3635 bool wxPropertyGrid::DoClearSelection()
3637 return DoSelectProperty((wxPGProperty
*)NULL
);
3640 // -----------------------------------------------------------------------
3641 // wxPropertyGrid expand/collapse state
3642 // -----------------------------------------------------------------------
3644 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3646 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3648 // If active editor was inside collapsed section, then disable it
3649 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3651 ClearSelection(false);
3654 // Store dont-center-splitter flag 'cause we need to temporarily set it
3655 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3656 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3658 bool res
= m_pState
->DoCollapse(pwc
);
3663 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3665 RecalculateVirtualSize();
3667 // Redraw etc. only if collapsed was visible.
3668 if (pwc
->IsVisible() &&
3670 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3672 // When item is collapsed so that scrollbar would move,
3673 // graphics mess is about (unless we redraw everything).
3678 // Clear dont-center-splitter flag if it wasn't set
3679 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3684 // -----------------------------------------------------------------------
3686 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3688 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3690 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3692 // Store dont-center-splitter flag 'cause we need to temporarily set it
3693 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3694 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3696 bool res
= m_pState
->DoExpand(pwc
);
3701 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3703 RecalculateVirtualSize();
3705 // Redraw etc. only if expanded was visible.
3706 if ( pwc
->IsVisible() && !m_frozen
&&
3707 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3711 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3714 DrawItems(pwc
, NULL
);
3719 // Clear dont-center-splitter flag if it wasn't set
3720 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3725 // -----------------------------------------------------------------------
3727 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3730 return m_pState
->DoHideProperty(p
, hide
, flags
);
3733 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3736 ClearSelection(false);
3739 m_pState
->DoHideProperty(p
, hide
, flags
);
3741 RecalculateVirtualSize();
3748 // -----------------------------------------------------------------------
3749 // wxPropertyGrid size related methods
3750 // -----------------------------------------------------------------------
3752 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3754 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3758 // If virtual height was changed, then recalculate editor control position(s)
3759 if ( m_pState
->m_vhCalcPending
)
3760 CorrectEditorWidgetPosY();
3762 m_pState
->EnsureVirtualHeight();
3765 int by1
= m_pState
->GetVirtualHeight();
3766 int by2
= m_pState
->GetActualVirtualHeight();
3769 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3770 wxASSERT_MSG( false,
3776 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3778 int x
= m_pState
->m_width
;
3779 int y
= m_pState
->m_virtualHeight
;
3782 GetClientSize(&width
,&height
);
3784 // Now adjust virtual size.
3785 SetVirtualSize(x
, y
);
3791 // Adjust scrollbars
3792 if ( HasVirtualWidth() )
3794 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3795 xPos
= GetScrollPos( wxHORIZONTAL
);
3798 if ( forceXPos
!= -1 )
3801 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3804 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3805 int yPos
= GetScrollPos( wxVERTICAL
);
3807 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3808 xAmount
, yAmount
, xPos
, yPos
, true );
3810 // Must re-get size now
3811 GetClientSize(&width
,&height
);
3813 if ( !HasVirtualWidth() )
3815 m_pState
->SetVirtualWidth(width
);
3822 m_canvas
->SetSize( x
, y
);
3824 m_pState
->CheckColumnWidths();
3827 CorrectEditorWidgetSizeX();
3829 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3832 // -----------------------------------------------------------------------
3834 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3836 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3840 GetClientSize(&width
,&height
);
3845 #if wxPG_DOUBLE_BUFFER
3846 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3848 int dblh
= (m_lineHeight
*2);
3849 if ( !m_doubleBuffer
)
3851 // Create double buffer bitmap to draw on, if none
3852 int w
= (width
>250)?width
:250;
3853 int h
= height
+ dblh
;
3855 m_doubleBuffer
= new wxBitmap( w
, h
);
3859 int w
= m_doubleBuffer
->GetWidth();
3860 int h
= m_doubleBuffer
->GetHeight();
3862 // Double buffer must be large enough
3863 if ( w
< width
|| h
< (height
+dblh
) )
3865 if ( w
< width
) w
= width
;
3866 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3867 delete m_doubleBuffer
;
3868 m_doubleBuffer
= new wxBitmap( w
, h
);
3875 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3876 m_ncWidth
= event
.GetSize().x
;
3880 if ( m_pState
->m_itemsAdded
)
3881 PrepareAfterItemsAdded();
3883 // Without this, virtual size (atleast under wxGTK) will be skewed
3884 RecalculateVirtualSize();
3890 // -----------------------------------------------------------------------
3892 void wxPropertyGrid::SetVirtualWidth( int width
)
3896 // Disable virtual width
3897 width
= GetClientSize().x
;
3898 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3902 // Enable virtual width
3903 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3905 m_pState
->SetVirtualWidth( width
);
3908 void wxPropertyGrid::SetFocusOnCanvas()
3910 m_canvas
->SetFocusIgnoringChildren();
3911 m_editorFocused
= 0;
3914 // -----------------------------------------------------------------------
3915 // wxPropertyGrid mouse event handling
3916 // -----------------------------------------------------------------------
3918 // selFlags uses same values DoSelectProperty's flags
3919 // Returns true if event was vetoed.
3920 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3922 // Send property grid event of specific type and with specific property
3923 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3924 evt
.SetPropertyGrid(this);
3925 evt
.SetEventObject(m_eventObject
);
3929 evt
.SetCanVeto(true);
3930 evt
.SetupValidationInfo();
3931 m_validationInfo
.m_pValue
= pValue
;
3933 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3935 evtHandler
->ProcessEvent(evt
);
3937 return evt
.WasVetoed();
3940 // -----------------------------------------------------------------------
3942 // Return false if should be skipped
3943 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3947 // Need to set focus?
3948 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3953 wxPropertyGridPageState
* state
= m_pState
;
3955 int splitterHitOffset
;
3956 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3958 wxPGProperty
* p
= DoGetItemAtY(y
);
3962 int depth
= (int)p
->GetDepth() - 1;
3964 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3966 if ( x
>= marginEnds
)
3970 if ( p
->IsCategory() )
3972 // This is category.
3973 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3975 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3977 // Expand, collapse, activate etc. if click on text or left of splitter.
3980 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3985 if ( !DoSelectProperty( p
) )
3988 // On double-click, expand/collapse.
3989 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3991 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3992 else DoExpand( p
, true );
3996 else if ( splitterHit
== -1 )
3999 unsigned int selFlag
= 0;
4000 if ( columnHit
== 1 )
4002 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4003 selFlag
= wxPG_SEL_FOCUS
;
4005 if ( !DoSelectProperty( p
, selFlag
) )
4008 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4010 if ( p
->GetChildCount() && !p
->IsCategory() )
4011 // On double-click, expand/collapse.
4012 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4014 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4015 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4016 else DoExpand( p
, true );
4023 // click on splitter
4024 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4026 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4028 // Double-clicking the splitter causes auto-centering
4029 CenterSplitter( true );
4031 else if ( m_dragStatus
== 0 )
4034 // Begin draggin the splitter
4038 // Changes must be committed here or the
4039 // value won't be drawn correctly
4040 if ( !CommitChangesFromEditor() )
4043 m_wndEditor
->Show ( false );
4046 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4048 m_canvas
->CaptureMouse();
4049 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4053 m_draggedSplitter
= splitterHit
;
4054 m_dragOffset
= splitterHitOffset
;
4056 wxClientDC
dc(m_canvas
);
4058 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4059 // Fixes button disappearance bug
4061 m_wndEditor2
->Show ( false );
4064 m_startingSplitterX
= x
- splitterHitOffset
;
4072 if ( p
->GetChildCount() )
4074 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4076 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4078 int y2
= y
% m_lineHeight
;
4079 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4081 // On click on expander button, expand/collapse
4082 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4083 DoCollapse( p
, true );
4085 DoExpand( p
, true );
4094 // -----------------------------------------------------------------------
4096 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4097 wxMouseEvent
& WXUNUSED(event
) )
4101 // Select property here as well
4102 wxPGProperty
* p
= m_propHover
;
4103 if ( p
!= m_selected
)
4104 DoSelectProperty( p
);
4106 // Send right click event.
4107 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4114 // -----------------------------------------------------------------------
4116 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4117 wxMouseEvent
& WXUNUSED(event
) )
4121 // Select property here as well
4122 wxPGProperty
* p
= m_propHover
;
4124 if ( p
!= m_selected
)
4125 DoSelectProperty( p
);
4127 // Send double-click event.
4128 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4135 // -----------------------------------------------------------------------
4137 #if wxPG_SUPPORT_TOOLTIPS
4139 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4141 if ( tipString
.length() )
4143 m_canvas
->SetToolTip(tipString
);
4147 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4148 m_canvas
->SetToolTip( m_emptyString
);
4150 m_canvas
->SetToolTip( NULL
);
4155 #endif // #if wxPG_SUPPORT_TOOLTIPS
4157 // -----------------------------------------------------------------------
4159 // Return false if should be skipped
4160 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4162 // Safety check (needed because mouse capturing may
4163 // otherwise freeze the control)
4164 if ( m_dragStatus
> 0 && !event
.Dragging() )
4166 HandleMouseUp(x
,y
,event
);
4169 wxPropertyGridPageState
* state
= m_pState
;
4171 int splitterHitOffset
;
4172 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4173 int splitterX
= x
- splitterHitOffset
;
4175 if ( m_dragStatus
> 0 )
4177 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4178 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4181 int newSplitterX
= x
- m_dragOffset
;
4182 int splitterX
= x
- splitterHitOffset
;
4184 // Splitter redraw required?
4185 if ( newSplitterX
!= splitterX
)
4188 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4189 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4190 state
->m_fSplitterX
= (float) newSplitterX
;
4193 CorrectEditorWidgetSizeX();
4207 int ih
= m_lineHeight
;
4210 #if wxPG_SUPPORT_TOOLTIPS
4211 wxPGProperty
* prevHover
= m_propHover
;
4212 unsigned char prevSide
= m_mouseSide
;
4214 int curPropHoverY
= y
- (y
% ih
);
4216 // On which item it hovers
4217 if ( ( !m_propHover
)
4219 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4222 // Mouse moves on another property
4224 m_propHover
= DoGetItemAtY(y
);
4225 m_propHoverY
= curPropHoverY
;
4228 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4231 #if wxPG_SUPPORT_TOOLTIPS
4232 // Store which side we are on
4234 if ( columnHit
== 1 )
4236 else if ( columnHit
== 0 )
4240 // If tooltips are enabled, show label or value as a tip
4241 // in case it doesn't otherwise show in full length.
4243 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4245 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4247 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4249 if ( m_propHover
&& !m_propHover
->IsCategory() )
4252 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4254 // Show help string as a tooltip
4255 wxString tipString
= m_propHover
->GetHelpString();
4257 SetToolTip(tipString
);
4261 // Show cropped value string as a tooltip
4265 if ( m_mouseSide
== 1 )
4267 tipString
= m_propHover
->m_label
;
4268 space
= splitterX
-m_marginWidth
-3;
4270 else if ( m_mouseSide
== 2 )
4272 tipString
= m_propHover
->GetDisplayedString();
4274 space
= m_width
- splitterX
;
4275 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4276 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4282 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4285 SetToolTip( tipString
);
4292 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4293 m_canvas
->SetToolTip( m_emptyString
);
4295 m_canvas
->SetToolTip( NULL
);
4306 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4307 m_canvas
->SetToolTip( m_emptyString
);
4309 m_canvas
->SetToolTip( NULL
);
4317 if ( splitterHit
== -1 ||
4319 HasFlag(wxPG_STATIC_SPLITTER
) )
4321 // hovering on something else
4322 if ( m_curcursor
!= wxCURSOR_ARROW
)
4323 CustomSetCursor( wxCURSOR_ARROW
);
4327 // Do not allow splitter cursor on caption items.
4328 // (also not if we were dragging and its started
4329 // outside the splitter region)
4332 !m_propHover
->IsCategory() &&
4336 // hovering on splitter
4338 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4339 // reliably detected.
4340 //if ( m_curcursor != wxCURSOR_SIZEWE )
4341 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4347 // hovering on something else
4348 if ( m_curcursor
!= wxCURSOR_ARROW
)
4349 CustomSetCursor( wxCURSOR_ARROW
);
4356 // -----------------------------------------------------------------------
4358 // Also handles Leaving event
4359 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4360 wxMouseEvent
&WXUNUSED(event
) )
4362 wxPropertyGridPageState
* state
= m_pState
;
4366 int splitterHitOffset
;
4367 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4369 // No event type check - basicly calling this method should
4370 // just stop dragging.
4371 // Left up after dragged?
4372 if ( m_dragStatus
>= 1 )
4375 // End Splitter Dragging
4377 // DO NOT ENABLE FOLLOWING LINE!
4378 // (it is only here as a reminder to not to do it)
4381 // Disable splitter auto-centering
4382 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4384 // This is necessary to return cursor
4385 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4387 m_canvas
->ReleaseMouse();
4388 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4391 // Set back the default cursor, if necessary
4392 if ( splitterHit
== -1 ||
4395 CustomSetCursor( wxCURSOR_ARROW
);
4400 // Control background needs to be cleared
4401 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4402 DrawItem( m_selected
);
4406 m_wndEditor
->Show ( true );
4409 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4410 // Fixes button disappearance bug
4412 m_wndEditor2
->Show ( true );
4415 // This clears the focus.
4416 m_editorFocused
= 0;
4422 // -----------------------------------------------------------------------
4424 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4426 int splitterX
= GetSplitterPosition();
4429 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4433 wxWindow
* wnd
= GetEditorControl();
4435 // Hide popup on clicks
4436 if ( event
.GetEventType() != wxEVT_MOTION
)
4437 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4439 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4445 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4447 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4448 ux
>= (r
.x
+r
.width
) ||
4450 event
.m_y
>= (r
.y
+r
.height
)
4460 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4465 // -----------------------------------------------------------------------
4467 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4470 if ( OnMouseCommon( event
, &x
, &y
) )
4472 HandleMouseClick(x
,y
,event
);
4477 // -----------------------------------------------------------------------
4479 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4482 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4483 HandleMouseRightClick(x
,y
,event
);
4487 // -----------------------------------------------------------------------
4489 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4491 // Always run standard mouse-down handler as well
4492 OnMouseClick(event
);
4495 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4496 HandleMouseDoubleClick(x
,y
,event
);
4500 // -----------------------------------------------------------------------
4502 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4505 if ( OnMouseCommon( event
, &x
, &y
) )
4507 HandleMouseMove(x
,y
,event
);
4512 // -----------------------------------------------------------------------
4514 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4516 // Called when mouse moves in the empty space below the properties.
4517 CustomSetCursor( wxCURSOR_ARROW
);
4520 // -----------------------------------------------------------------------
4522 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4525 if ( OnMouseCommon( event
, &x
, &y
) )
4527 HandleMouseUp(x
,y
,event
);
4532 // -----------------------------------------------------------------------
4534 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4536 // This may get called from child control as well, so event's
4537 // mouse position cannot be relied on.
4539 if ( event
.Entering() )
4541 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4543 // TODO: Fix this (detect parent and only do
4544 // cursor trick if it is a manager).
4545 wxASSERT( GetParent() );
4546 GetParent()->SetCursor(wxNullCursor
);
4548 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4551 GetParent()->SetCursor(wxNullCursor
);
4553 else if ( event
.Leaving() )
4555 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4556 m_canvas
->SetCursor( wxNullCursor
);
4558 // Get real cursor position
4559 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4561 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4564 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4566 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4570 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4578 // -----------------------------------------------------------------------
4580 // Common code used by various OnMouseXXXChild methods.
4581 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4583 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4584 wxASSERT( topCtrlWnd
);
4586 event
.GetPosition(&x
,&y
);
4588 int splitterX
= GetSplitterPosition();
4590 wxRect r
= topCtrlWnd
->GetRect();
4591 if ( !m_dragStatus
&&
4592 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4593 y
>= 0 && y
< r
.height \
4596 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4601 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4608 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4611 if ( OnMouseChildCommon(event
,&x
,&y
) )
4613 bool res
= HandleMouseClick(x
,y
,event
);
4614 if ( !res
) event
.Skip();
4618 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4621 wxASSERT( m_wndEditor
);
4622 // These coords may not be exact (about +-2),
4623 // but that should not matter (right click is about item, not position).
4624 wxPoint pt
= m_wndEditor
->GetPosition();
4625 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4626 wxASSERT( m_selected
);
4627 m_propHover
= m_selected
;
4628 bool res
= HandleMouseRightClick(x
,y
,event
);
4629 if ( !res
) event
.Skip();
4632 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4635 if ( OnMouseChildCommon(event
,&x
,&y
) )
4637 bool res
= HandleMouseMove(x
,y
,event
);
4638 if ( !res
) event
.Skip();
4642 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4645 if ( OnMouseChildCommon(event
,&x
,&y
) )
4647 bool res
= HandleMouseUp(x
,y
,event
);
4648 if ( !res
) event
.Skip();
4652 // -----------------------------------------------------------------------
4653 // wxPropertyGrid keyboard event handling
4654 // -----------------------------------------------------------------------
4656 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4658 // Translates wxKeyEvent to wxPG_ACTION_XXX
4660 int keycode
= event
.GetKeyCode();
4661 int modifiers
= event
.GetModifiers();
4663 wxASSERT( !(modifiers
&~(0xFFFF)) );
4665 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4667 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4669 if ( it
== m_actionTriggers
.end() )
4674 int second
= (it
->second
>>16) & 0xFFFF;
4678 return (it
->second
& 0xFFFF);
4681 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4683 wxASSERT( !(modifiers
&~(0xFFFF)) );
4685 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4687 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4689 if ( it
!= m_actionTriggers
.end() )
4691 // This key combination is already used
4693 // Can add secondary?
4694 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4695 wxT("You can only add up to two separate actions per key combination.") );
4697 action
= it
->second
| (action
<<16);
4700 m_actionTriggers
[hashMapKey
] = action
;
4703 void wxPropertyGrid::ClearActionTriggers( int action
)
4705 wxPGHashMapI2I::iterator it
;
4707 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4709 if ( it
->second
== action
)
4711 m_actionTriggers
.erase(it
);
4716 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4719 // Handles key event when editor control is not focused.
4722 wxASSERT( !m_frozen
);
4726 // Travelsal between items, collapsing/expanding, etc.
4727 int keycode
= event
.GetKeyCode();
4728 bool editorFocused
= IsEditorFocused();
4730 if ( keycode
== WXK_TAB
)
4732 wxWindow
* mainControl
;
4734 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4735 mainControl
= GetParent();
4739 if ( !event
.ShiftDown() )
4741 if ( !editorFocused
&& m_wndEditor
)
4743 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4747 // Tab traversal workaround for platforms on which
4748 // wxWindow::Navigate() may navigate into first child
4749 // instead of next sibling. Does not work perfectly
4750 // in every scenario (for instance, when property grid
4751 // is either first or last control).
4752 #if defined(__WXGTK__)
4753 wxWindow
* sibling
= mainControl
->GetNextSibling();
4755 sibling
->SetFocusFromKbd();
4757 Navigate(wxNavigationKeyEvent::IsForward
);
4763 if ( editorFocused
)
4769 #if defined(__WXGTK__)
4770 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4772 sibling
->SetFocusFromKbd();
4774 Navigate(wxNavigationKeyEvent::IsBackward
);
4782 // Ignore Alt and Control when they are down alone
4783 if ( keycode
== WXK_ALT
||
4784 keycode
== WXK_CONTROL
)
4791 int action
= KeyEventToActions(event
, &secondAction
);
4793 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4796 // Esc cancels any changes
4797 if ( IsEditorsValueModified() )
4799 EditorsValueWasNotModified();
4801 // Update the control as well
4802 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4804 m_selected
->GetDisplayedString() );
4807 OnValidationFailureReset(m_selected
);
4813 // Except for TAB and ESC, handle child control events in child control
4820 bool wasHandled
= false;
4825 if ( ButtonTriggerKeyTest(action
, event
) )
4828 wxPGProperty
* p
= m_selected
;
4830 // Travel and expand/collapse
4833 if ( p
->GetChildCount() &&
4834 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4837 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4839 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4842 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4844 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4851 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4855 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4861 if ( selectDir
>= -1 )
4863 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4865 DoSelectProperty(p
);
4871 // If nothing was selected, select the first item now
4872 // (or navigate out of tab).
4873 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4875 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4876 if ( p
) DoSelectProperty(p
);
4885 // -----------------------------------------------------------------------
4887 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4889 HandleKeyEvent(event
, false);
4892 // -----------------------------------------------------------------------
4894 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4899 action
= KeyEventToActions(event
, &secondAction
);
4902 // Does the keycode trigger button?
4903 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4906 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4907 GetEventHandler()->AddPendingEvent(evt
);
4914 // -----------------------------------------------------------------------
4916 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4918 HandleKeyEvent(event
, true);
4921 // -----------------------------------------------------------------------
4922 // wxPropertyGrid miscellaneous event handling
4923 // -----------------------------------------------------------------------
4925 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4928 // Check if the focus is in this control or one of its children
4929 wxWindow
* newFocused
= wxWindow::FindFocus();
4931 if ( newFocused
!= m_curFocused
)
4932 HandleFocusChange( newFocused
);
4935 bool wxPropertyGrid::IsEditorFocused() const
4937 wxWindow
* focus
= wxWindow::FindFocus();
4939 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4940 focus
== GetEditorControl() )
4946 // Called by focus event handlers. newFocused is the window that becomes focused.
4947 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4949 unsigned int oldFlags
= m_iFlags
;
4951 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4953 wxWindow
* parent
= newFocused
;
4955 // This must be one of nextFocus' parents.
4958 // Use m_eventObject, which is either wxPropertyGrid or
4959 // wxPropertyGridManager, as appropriate.
4960 if ( parent
== m_eventObject
)
4962 m_iFlags
|= wxPG_FL_FOCUSED
;
4965 parent
= parent
->GetParent();
4968 m_curFocused
= newFocused
;
4970 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4971 (oldFlags
& wxPG_FL_FOCUSED
) )
4973 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4975 // Need to store changed value
4976 CommitChangesFromEditor();
4982 // Preliminary code for tab-order respecting
4983 // tab-traversal (but should be moved to
4986 wxWindow* prevFocus = event.GetWindow();
4987 wxWindow* useThis = this;
4988 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4989 useThis = GetParent();
4992 prevFocus->GetParent() == useThis->GetParent() )
4994 wxList& children = useThis->GetParent()->GetChildren();
4996 wxNode* node = children.Find(prevFocus);
4998 if ( node->GetNext() &&
4999 useThis == node->GetNext()->GetData() )
5000 DoSelectProperty(GetFirst());
5001 else if ( node->GetPrevious () &&
5002 useThis == node->GetPrevious()->GetData() )
5003 DoSelectProperty(GetLastProperty());
5010 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5011 DrawItem( m_selected
);
5015 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5017 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5018 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5019 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5020 //else if ( event.GetWindow() )
5022 HandleFocusChange(event
.GetWindow());
5027 // -----------------------------------------------------------------------
5029 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5031 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5034 // event.Skip() being commented out is aworkaround for bug reported
5035 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5039 // -----------------------------------------------------------------------
5041 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5043 m_iFlags
|= wxPG_FL_SCROLLED
;
5048 // -----------------------------------------------------------------------
5050 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5052 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5054 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5058 // -----------------------------------------------------------------------
5059 // Property editor related functions
5060 // -----------------------------------------------------------------------
5062 // noDefCheck = true prevents infinite recursion.
5063 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5066 wxASSERT( editorClass
);
5068 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5069 RegisterDefaultEditors();
5071 wxString name
= editorClass
->GetName();
5073 // Existing editor under this name?
5074 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5076 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5078 // If this name was already used, try class name.
5079 name
= editorClass
->GetClassInfo()->GetClassName();
5080 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5083 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5084 (wxPGEditor
*) vt_it
->second
,
5085 "Editor with given name was already registered" );
5087 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5092 // Use this in RegisterDefaultEditors.
5093 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5094 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5096 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5097 new wxPG##EDITOR##Editor, true ); \
5100 // Registers all default editor classes
5101 void wxPropertyGrid::RegisterDefaultEditors()
5103 wxPGRegisterDefaultEditorClass( TextCtrl
);
5104 wxPGRegisterDefaultEditorClass( Choice
);
5105 wxPGRegisterDefaultEditorClass( ComboBox
);
5106 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5107 #if wxPG_INCLUDE_CHECKBOX
5108 wxPGRegisterDefaultEditorClass( CheckBox
);
5110 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5112 // Register SpinCtrl etc. editors before use
5113 RegisterAdditionalEditors();
5116 // -----------------------------------------------------------------------
5117 // wxPGStringTokenizer
5118 // Needed to handle C-style string lists (e.g. "str1" "str2")
5119 // -----------------------------------------------------------------------
5121 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5122 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5126 wxPGStringTokenizer::~wxPGStringTokenizer()
5130 bool wxPGStringTokenizer::HasMoreTokens()
5132 const wxString
& str
= *m_str
;
5134 wxString::const_iterator i
= m_curPos
;
5136 wxUniChar delim
= m_delimeter
;
5138 wxUniChar prev_a
= wxT('\0');
5140 bool inToken
= false;
5142 while ( i
!= str
.end() )
5151 m_readyToken
.clear();
5156 if ( prev_a
!= wxT('\\') )
5160 if ( a
!= wxT('\\') )
5180 m_curPos
= str
.end();
5188 wxString
wxPGStringTokenizer::GetNextToken()
5190 return m_readyToken
;
5193 // -----------------------------------------------------------------------
5195 // -----------------------------------------------------------------------
5197 wxPGChoiceEntry::wxPGChoiceEntry()
5198 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5202 // -----------------------------------------------------------------------
5204 // -----------------------------------------------------------------------
5206 wxPGChoicesData::wxPGChoicesData()
5211 wxPGChoicesData::~wxPGChoicesData()
5216 void wxPGChoicesData::Clear()
5221 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5223 wxASSERT( m_items
.size() == 0 );
5225 m_items
= data
->m_items
;
5228 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5229 const wxPGChoiceEntry
& item
)
5231 wxVector
<wxPGChoiceEntry
>::iterator it
;
5235 index
= (int) m_items
.size();
5239 it
= m_items
.begin() + index
;
5242 m_items
.insert(it
, item
);
5244 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5246 // Need to fix value?
5247 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5248 ownEntry
.SetValue(index
);
5253 // -----------------------------------------------------------------------
5255 // -----------------------------------------------------------------------
5257 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5261 wxPGChoiceEntry
entry(label
, value
);
5262 return m_data
->Insert( -1, entry
);
5265 // -----------------------------------------------------------------------
5267 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5271 wxPGChoiceEntry
entry(label
, value
);
5272 entry
.SetBitmap(bitmap
);
5273 return m_data
->Insert( -1, entry
);
5276 // -----------------------------------------------------------------------
5278 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5281 return m_data
->Insert( index
, entry
);
5284 // -----------------------------------------------------------------------
5286 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5290 wxPGChoiceEntry
entry(label
, value
);
5291 return m_data
->Insert( index
, entry
);
5294 // -----------------------------------------------------------------------
5296 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5302 while ( index
< GetCount() )
5304 int cmpRes
= GetLabel(index
).Cmp(label
);
5310 wxPGChoiceEntry
entry(label
, value
);
5311 return m_data
->Insert( index
, entry
);
5314 // -----------------------------------------------------------------------
5316 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5320 unsigned int itemcount
= 0;
5321 const wxChar
** p
= &labels
[0];
5322 while ( *p
) { p
++; itemcount
++; }
5325 for ( i
= 0; i
< itemcount
; i
++ )
5330 wxPGChoiceEntry
entry(labels
[i
], value
);
5331 m_data
->Insert( i
, entry
);
5335 // -----------------------------------------------------------------------
5337 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5342 unsigned int itemcount
= arr
.size();
5344 for ( i
= 0; i
< itemcount
; i
++ )
5347 if ( &arrint
&& arrint
.size() )
5349 wxPGChoiceEntry
entry(arr
[i
], value
);
5350 m_data
->Insert( i
, entry
);
5354 // -----------------------------------------------------------------------
5356 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5358 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5359 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5360 m_data
->m_items
.begin()+nIndex
+count
);
5363 // -----------------------------------------------------------------------
5365 int wxPGChoices::Index( const wxString
& str
) const
5370 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5372 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5373 if ( entry
.HasText() && entry
.GetText() == str
)
5380 // -----------------------------------------------------------------------
5382 int wxPGChoices::Index( int val
) const
5387 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5389 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5390 if ( entry
.GetValue() == val
)
5397 // -----------------------------------------------------------------------
5399 wxArrayString
wxPGChoices::GetLabels() const
5404 if ( this && IsOk() )
5405 for ( i
=0; i
<GetCount(); i
++ )
5406 arr
.push_back(GetLabel(i
));
5411 // -----------------------------------------------------------------------
5413 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5420 for ( i
=0; i
< strings
.size(); i
++ )
5422 int index
= Index(strings
[i
]);
5424 arr
.Add(GetValue(index
));
5426 arr
.Add(wxPG_INVALID_VALUE
);
5433 // -----------------------------------------------------------------------
5435 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5436 wxArrayString
* unmatched
) const
5443 for ( i
=0; i
< strings
.size(); i
++ )
5445 const wxString
& str
= strings
[i
];
5446 int index
= Index(str
);
5449 else if ( unmatched
)
5450 unmatched
->Add(str
);
5457 // -----------------------------------------------------------------------
5459 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5463 if ( data
!= wxPGChoicesEmptyData
)
5470 // -----------------------------------------------------------------------
5472 void wxPGChoices::Init()
5474 m_data
= wxPGChoicesEmptyData
;
5477 // -----------------------------------------------------------------------
5479 void wxPGChoices::Free()
5481 if ( m_data
!= wxPGChoicesEmptyData
)
5484 m_data
= wxPGChoicesEmptyData
;
5488 // -----------------------------------------------------------------------
5489 // wxPropertyGridEvent
5490 // -----------------------------------------------------------------------
5492 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5495 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5496 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5497 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5498 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5499 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5500 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5501 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5502 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5503 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5506 // -----------------------------------------------------------------------
5508 void wxPropertyGridEvent::Init()
5510 m_validationInfo
= NULL
;
5512 m_wasVetoed
= false;
5515 // -----------------------------------------------------------------------
5517 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5518 : wxCommandEvent(commandType
,id
)
5524 // -----------------------------------------------------------------------
5526 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5527 : wxCommandEvent(event
)
5529 m_eventType
= event
.GetEventType();
5530 m_eventObject
= event
.m_eventObject
;
5532 m_property
= event
.m_property
;
5533 m_validationInfo
= event
.m_validationInfo
;
5534 m_canVeto
= event
.m_canVeto
;
5535 m_wasVetoed
= event
.m_wasVetoed
;
5538 // -----------------------------------------------------------------------
5540 wxPropertyGridEvent::~wxPropertyGridEvent()
5544 // -----------------------------------------------------------------------
5546 wxEvent
* wxPropertyGridEvent::Clone() const
5548 return new wxPropertyGridEvent( *this );
5551 // -----------------------------------------------------------------------
5552 // wxPropertyGridPopulator
5553 // -----------------------------------------------------------------------
5555 wxPropertyGridPopulator::wxPropertyGridPopulator()
5559 wxPGGlobalVars
->m_offline
++;
5562 // -----------------------------------------------------------------------
5564 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5567 m_propHierarchy
.clear();
5570 // -----------------------------------------------------------------------
5572 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5578 // -----------------------------------------------------------------------
5580 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5583 // Free unused sets of choices
5584 wxPGHashMapS2P::iterator it
;
5586 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5588 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5595 m_pg
->GetPanel()->Refresh();
5597 wxPGGlobalVars
->m_offline
--;
5600 // -----------------------------------------------------------------------
5602 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5603 const wxString
& propLabel
,
5604 const wxString
& propName
,
5605 const wxString
* propValue
,
5606 wxPGChoices
* pChoices
)
5608 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5609 wxPGProperty
* parent
= GetCurParent();
5611 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5613 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5617 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5619 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5623 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5625 property
->SetLabel(propLabel
);
5626 property
->DoSetName(propName
);
5628 if ( pChoices
&& pChoices
->IsOk() )
5629 property
->SetChoices(*pChoices
);
5631 m_state
->DoInsert(parent
, -1, property
);
5634 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5635 wxPG_PROGRAMMATIC_VALUE
);
5640 // -----------------------------------------------------------------------
5642 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5644 m_propHierarchy
.push_back(property
);
5645 DoScanForChildren();
5646 m_propHierarchy
.pop_back();
5649 // -----------------------------------------------------------------------
5651 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5652 const wxString
& idString
)
5654 wxPGChoices choices
;
5657 if ( choicesString
[0] == wxT('@') )
5659 wxString ids
= choicesString
.substr(1);
5660 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5661 if ( it
== m_dictIdChoices
.end() )
5662 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5664 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5669 if ( idString
.length() )
5671 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5672 if ( it
!= m_dictIdChoices
.end() )
5674 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5681 // Parse choices string
5682 wxString::const_iterator it
= choicesString
.begin();
5686 bool labelValid
= false;
5688 for ( ; it
!= choicesString
.end(); it
++ )
5694 if ( c
== wxT('"') )
5699 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5700 choices
.Add(label
, l
);
5703 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5708 else if ( c
== wxT('=') )
5715 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5722 if ( c
== wxT('"') )
5735 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5736 choices
.Add(label
, l
);
5739 if ( !choices
.IsOk() )
5741 choices
.EnsureData();
5745 if ( idString
.length() )
5746 m_dictIdChoices
[idString
] = choices
.GetData();
5753 // -----------------------------------------------------------------------
5755 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5757 if ( s
.Last() == wxT('%') )
5759 wxString s2
= s
.substr(0,s
.length()-1);
5761 if ( s2
.ToLong(&val
, 10) )
5763 *pval
= (val
*max
)/100;
5769 return s
.ToLong(pval
, 10);
5772 // -----------------------------------------------------------------------
5774 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5775 const wxString
& type
,
5776 const wxString
& value
)
5778 int l
= m_propHierarchy
.size();
5782 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5783 wxString valuel
= value
.Lower();
5786 if ( type
.length() == 0 )
5791 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5793 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5795 else if ( value
.ToLong(&v
, 0) )
5802 if ( type
== wxT("string") )
5806 else if ( type
== wxT("int") )
5809 value
.ToLong(&v
, 0);
5812 else if ( type
== wxT("bool") )
5814 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5821 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5826 p
->SetAttribute( name
, variant
);
5831 // -----------------------------------------------------------------------
5833 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5835 wxLogError(_("Error in resource: %s"),msg
.c_str());
5838 // -----------------------------------------------------------------------
5840 #endif // wxUSE_PROPGRID