1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/manager.cpp
3 // Purpose: wxPropertyGridManager
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"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/textctrl.h"
39 #include "wx/dirdlg.h"
40 #include "wx/combobox.h"
41 #include "wx/layout.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
49 // This define is necessary to prevent macro clearing
50 #define __wxPG_SOURCE_FILE__
52 #include <wx/propgrid/propgrid.h>
54 #include <wx/propgrid/manager.h>
57 #define wxPG_MAN_ALTERNATE_BASE_ID 11249 // Needed for wxID_ANY madnesss
60 // -----------------------------------------------------------------------
62 // For wxMSW cursor consistency, we must do mouse capturing even
63 // when using custom controls
65 #define BEGIN_MOUSE_CAPTURE \
66 if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) \
69 m_iFlags |= wxPG_FL_MOUSE_CAPTURED; \
72 #define END_MOUSE_CAPTURE \
73 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) \
76 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); \
79 // -----------------------------------------------------------------------
80 // wxPropertyGridManager
81 // -----------------------------------------------------------------------
83 const wxChar
*wxPropertyGridManagerNameStr
= wxT("wxPropertyGridManager");
86 // Categoric Mode Icon
87 static const char* gs_xpm_catmode
[] = {
112 // Alphabetic Mode Icon
113 static const char* gs_xpm_noncatmode
[] = {
138 // Default Page Icon.
139 static const char* gs_xpm_defpage
[] = {
164 #define GETPAGESTATE(page) ((wxPropertyGridPage*)m_arrPages.Item(page))->GetStatePtr()
166 // -----------------------------------------------------------------------
167 // wxPropertyGridPage
168 // -----------------------------------------------------------------------
171 IMPLEMENT_CLASS(wxPropertyGridPage
, wxEvtHandler
)
174 BEGIN_EVENT_TABLE(wxPropertyGridPage
, wxEvtHandler
)
178 wxPropertyGridPage::wxPropertyGridPage()
179 : wxEvtHandler(), wxPropertyGridInterface(), wxPropertyGridPageState()
181 m_pState
= this; // wxPropertyGridInterface to point to State
186 wxPropertyGridPage::~wxPropertyGridPage()
190 void wxPropertyGridPage::Clear()
192 GetStatePtr()->DoClear();
195 wxSize
wxPropertyGridPage::FitColumns()
197 wxSize sz
= DoFitColumns();
201 void wxPropertyGridPage::RefreshProperty( wxPGProperty
* p
)
204 m_manager
->RefreshProperty(p
);
207 void wxPropertyGridPage::OnShow()
211 void wxPropertyGridPage::SetSplitterPosition( int splitterPos
, int col
)
213 wxPropertyGrid
* pg
= GetGrid();
214 if ( pg
->GetState() == this )
215 pg
->SetSplitterPosition(splitterPos
);
217 DoSetSplitterPosition(splitterPos
, col
, false);
220 void wxPropertyGridPage::DoSetSplitterPosition( int pos
, int splitterColumn
, bool allPages
)
222 if ( allPages
&& m_manager
->GetPageCount() )
223 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
225 DoSetSplitterPositionThisPage( pos
, splitterColumn
);
228 // -----------------------------------------------------------------------
229 // wxPropertyGridManager
230 // -----------------------------------------------------------------------
232 // Final default splitter y is client height minus this.
233 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
235 // -----------------------------------------------------------------------
237 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
239 #define ID_ADVTOOLBAR_OFFSET 1
240 #define ID_ADVHELPCAPTION_OFFSET 2
241 #define ID_ADVHELPCONTENT_OFFSET 3
242 #define ID_ADVBUTTON_OFFSET 4
243 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
245 // -----------------------------------------------------------------------
247 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
248 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
249 EVT_SIZE(wxPropertyGridManager::OnResize
)
250 EVT_PAINT(wxPropertyGridManager::OnPaint
)
251 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
252 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
253 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
254 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
257 // -----------------------------------------------------------------------
259 wxPropertyGridManager::wxPropertyGridManager()
265 // -----------------------------------------------------------------------
267 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
276 Create(parent
,id
,pos
,size
,style
,name
);
279 // -----------------------------------------------------------------------
281 bool wxPropertyGridManager::Create( wxWindow
*parent
,
289 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
290 (style
&0xFFFF0000)|wxWANTS_CHARS
,
297 // -----------------------------------------------------------------------
300 // Initialize values to defaults
302 void wxPropertyGridManager::Init1()
305 //m_pPropGrid = (wxPropertyGrid*) NULL;
306 m_pPropGrid
= CreatePropertyGrid();
309 m_pToolbar
= (wxToolBar
*) NULL
;
311 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
312 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
314 m_emptyPage
= (wxPropertyGridPage
*) NULL
;
318 m_width
= m_height
= 0;
320 m_splitterHeight
= 5;
322 m_splitterY
= -1; // -1 causes default to be set.
324 m_nextDescBoxSize
= -1;
332 // -----------------------------------------------------------------------
334 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
336 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
337 wxNO_FULL_REPAINT_ON_RESIZE| \
340 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
341 wxNO_FULL_REPAINT_ON_RESIZE| \
345 // Which flags can be passed to underlying wxPropertyGrid.
346 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
349 // Initialize after parent etc. set
351 void wxPropertyGridManager::Init2( int style
)
354 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
357 m_windowStyle
|= (style
&0x0000FFFF);
359 wxSize csz
= GetClientSize();
361 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
363 // Prepare the first page
364 // NB: But just prepare - you still need to call Add/InsertPage
365 // to actually add properties on it.
366 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
367 pd
->m_isDefault
= true;
368 pd
->m_manager
= this;
369 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
370 state
->m_pPropGrid
= m_pPropGrid
;
371 m_arrPages
.Add( (void*)pd
);
372 m_pPropGrid
->m_pState
= state
;
374 wxWindowID baseId
= GetId();
375 wxWindowID useId
= baseId
;
377 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
382 // Smaller controls on Mac
383 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
386 // Create propertygrid.
387 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
388 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
389 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
391 m_pPropGrid
->m_eventObject
= this;
393 m_pPropGrid
->SetId(useId
);
395 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
397 m_pState
= m_pPropGrid
->m_pState
;
399 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
401 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
404 // Connect to property grid onselect event.
405 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
406 // (see wxPropertyGridManager::ProcessEvent).
407 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
409 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
411 // Connect to toolbar button events.
412 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
413 wxEVT_COMMAND_TOOL_CLICKED
,
414 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
416 // Optional initial controls.
419 m_iFlags
|= wxPG_FL_INITIALIZED
;
423 // -----------------------------------------------------------------------
425 wxPropertyGridManager::~wxPropertyGridManager()
429 m_pPropGrid
->DoSelectProperty(NULL
);
430 m_pPropGrid
->m_pState
= NULL
;
433 for ( i
=0; i
<m_arrPages
.GetCount(); i
++ )
435 delete (wxPropertyGridPage
*)m_arrPages
.Item(i
);
441 // -----------------------------------------------------------------------
443 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
445 return new wxPropertyGrid();
448 // -----------------------------------------------------------------------
450 void wxPropertyGridManager::SetId( wxWindowID winid
)
452 wxWindow::SetId(winid
);
454 // TODO: Reconnect propgrid event handler(s).
456 m_pPropGrid
->SetId(winid
);
459 // -----------------------------------------------------------------------
461 wxSize
wxPropertyGridManager::DoGetBestSize() const
463 return wxSize(60,150);
466 // -----------------------------------------------------------------------
468 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
470 bool res
= wxWindow::SetFont(font
);
471 m_pPropGrid
->SetFont(font
);
473 // TODO: Need to do caption recacalculations for other pages as well.
475 for ( i
=0; i
<m_arrPages
.GetCount(); i
++ )
477 wxPropertyGridPage
* page
= GetPage(i
);
479 if ( page
!= m_pPropGrid
->GetState() )
480 page
->CalculateFontAndBitmapStuff(-1);
486 // -----------------------------------------------------------------------
488 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
490 wxWindow::SetExtraStyle( exStyle
);
491 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
493 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
498 // -----------------------------------------------------------------------
500 void wxPropertyGridManager::Freeze()
502 m_pPropGrid
->Freeze();
506 // -----------------------------------------------------------------------
508 void wxPropertyGridManager::Thaw()
514 // -----------------------------------------------------------------------
516 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
518 wxWindow::SetWindowStyleFlag( style
);
519 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
520 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
523 // -----------------------------------------------------------------------
525 // Actually shows given page.
526 bool wxPropertyGridManager::DoSelectPage( int index
)
528 // -1 means no page was selected
529 //wxASSERT( m_selPage >= 0 );
531 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
533 wxT("invalid page index") );
535 if ( m_selPage
== index
)
538 if ( m_pPropGrid
->m_selected
)
540 if ( !m_pPropGrid
->ClearSelection() )
544 wxPropertyGridPage
* prevPage
;
546 if ( m_selPage
>= 0 )
547 prevPage
= GetPage(m_selPage
);
549 prevPage
= m_emptyPage
;
551 wxPropertyGridPage
* nextPage
;
555 nextPage
= (wxPropertyGridPage
*)m_arrPages
.Item(index
);
563 m_emptyPage
= new wxPropertyGridPage();
564 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
567 nextPage
= m_emptyPage
;
570 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
572 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
574 m_pState
= m_pPropGrid
->m_pState
;
582 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
584 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
591 // -----------------------------------------------------------------------
593 // Changes page *and* set the target page for insertion operations.
594 void wxPropertyGridManager::SelectPage( int index
)
599 // -----------------------------------------------------------------------
601 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
604 for ( i
=0; i
<GetPageCount(); i
++ )
606 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->m_label
== name
)
612 // -----------------------------------------------------------------------
614 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
619 for ( i
=0; i
<GetPageCount(); i
++ )
621 if ( pState
== ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr() )
628 // -----------------------------------------------------------------------
630 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
632 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
633 return ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->m_label
;
636 // -----------------------------------------------------------------------
638 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
640 // Do not change this into wxCHECK because returning NULL is important
641 // for wxPropertyGridInterface page enumeration mechanics.
642 if ( page
>= (int)GetPageCount() )
647 return GETPAGESTATE(page
);
650 // -----------------------------------------------------------------------
652 void wxPropertyGridManager::Clear()
654 m_pPropGrid
->Freeze();
657 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
661 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
666 // -----------------------------------------------------------------------
668 void wxPropertyGridManager::ClearPage( int page
)
670 wxASSERT( page
>= 0 );
671 wxASSERT( page
< (int)GetPageCount() );
673 if ( page
>= 0 && page
< (int)GetPageCount() )
675 wxPropertyGridPageState
* state
= GETPAGESTATE(page
);
677 if ( state
== m_pPropGrid
->GetState() )
678 m_pPropGrid
->Clear();
684 // -----------------------------------------------------------------------
686 int wxPropertyGridManager::GetColumnCount( int page
) const
688 wxASSERT( page
>= -1 );
689 wxASSERT( page
< (int)GetPageCount() );
691 return GetPageState(page
)->GetColumnCount();
694 // -----------------------------------------------------------------------
696 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
698 wxASSERT( page
>= -1 );
699 wxASSERT( page
< (int)GetPageCount() );
701 GetPageState(page
)->SetColumnCount( colCount
);
702 GetGrid()->Refresh();
704 // -----------------------------------------------------------------------
706 void wxPropertyGridManager::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
709 for ( i
=0; i
<GetPageCount(); i
++ )
711 wxPropertyGridPage
* page
= (wxPropertyGridPage
*)m_arrPages
.Item(i
);
713 DoSetPropertyAttribute(page
->GetStatePtr()->m_properties
, attrName
, value
, wxPG_RECURSE
);
717 // -----------------------------------------------------------------------
719 size_t wxPropertyGridManager::GetPageCount() const
721 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
724 return m_arrPages
.GetCount();
727 // -----------------------------------------------------------------------
729 int wxPropertyGridManager::InsertPage( int index
, const wxString
& label
,
730 const wxBitmap
& bmp
, wxPropertyGridPage
* pageObj
)
733 index
= GetPageCount();
735 wxCHECK_MSG( (size_t)index
== GetPageCount(), -1,
736 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
738 bool needInit
= true;
739 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
741 wxASSERT( index
== 0 || isPageInserted
);
745 // No custom page object was given, so we will either re-use the default base
746 // page (if index==0), or create a new default page object.
747 if ( !isPageInserted
)
749 pageObj
= GetPage(0);
750 // Of course, if the base page was custom, we need to delete and
752 if ( !pageObj
->m_isDefault
)
755 pageObj
= new wxPropertyGridPage();
756 m_arrPages
[0] = pageObj
;
762 pageObj
= new wxPropertyGridPage();
764 pageObj
->m_isDefault
= true;
768 if ( !isPageInserted
)
770 // Initial page needs to be deleted and replaced
772 m_arrPages
[0] = pageObj
;
773 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
777 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
779 pageObj
->m_manager
= this;
783 state
->m_pPropGrid
= m_pPropGrid
;
784 state
->InitNonCatMode();
787 if ( label
.length() )
789 wxASSERT_MSG( !pageObj
->m_label
.length(),
790 wxT("If page label is given in constructor, empty label must be given in AddPage"));
791 pageObj
->m_label
= label
;
794 pageObj
->m_id
= m_nextTbInd
;
796 if ( isPageInserted
)
797 m_arrPages
.Add( (void*)pageObj
);
800 if ( m_windowStyle
& wxPG_TOOLBAR
)
805 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
807 wxASSERT( m_pToolbar
);
809 // Add separator before first page.
810 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
811 m_pToolbar
->GetToolsCount() < 3 )
812 m_pToolbar
->AddSeparator();
814 if ( &bmp
!= &wxNullBitmap
)
815 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
816 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
818 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
823 m_pToolbar
->Realize();
830 // If selected page was above the point of insertion, fix the current page index
831 if ( isPageInserted
)
833 if ( m_selPage
>= index
)
840 // Set this value only when adding the first page
846 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
848 wxASSERT( pageObj
->GetGrid() );
853 // -----------------------------------------------------------------------
855 bool wxPropertyGridManager::IsAnyModified() const
858 for ( i
=0; i
<GetPageCount(); i
++ )
860 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr()->m_anyModified
)
866 // -----------------------------------------------------------------------
868 bool wxPropertyGridManager::IsPageModified( size_t index
) const
870 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->GetStatePtr()->m_anyModified
)
875 // -----------------------------------------------------------------------
877 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
879 wxASSERT( index
>= 0 );
880 wxASSERT( index
< (int)m_arrPages
.GetCount() );
882 return ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->GetStatePtr()->m_properties
;
885 // -----------------------------------------------------------------------
887 bool wxPropertyGridManager::RemovePage( int page
)
889 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
891 wxT("invalid page index") );
893 wxPropertyGridPage
* pd
= (wxPropertyGridPage
*)m_arrPages
.Item(page
);
895 if ( m_arrPages
.GetCount() == 1 )
897 // Last page: do not remove page entry
898 m_pPropGrid
->Clear();
900 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
903 // Change selection if current is page
904 else if ( page
== m_selPage
)
906 if ( !m_pPropGrid
->ClearSelection() )
909 // Substitute page to select
910 int substitute
= page
- 1;
911 if ( substitute
< 0 )
912 substitute
= page
+ 1;
914 SelectPage(substitute
);
917 // Remove toolbar icon
919 if ( HasFlag(wxPG_TOOLBAR
) )
921 wxASSERT( m_pToolbar
);
923 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
926 // Delete separator as well, for consistency
927 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
928 GetPageCount() == 1 )
929 m_pToolbar
->DeleteToolByPos(2);
931 m_pToolbar
->DeleteToolByPos(toolPos
);
935 if ( m_arrPages
.GetCount() > 1 )
937 m_arrPages
.RemoveAt(page
);
941 // Adjust indexes that were above removed
942 if ( m_selPage
> page
)
948 // -----------------------------------------------------------------------
950 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
952 int evtType
= event
.GetEventType();
954 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
955 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
956 // don't really matter.
957 if ( evtType
== wxEVT_PG_SELECTED
)
958 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
960 // Property grid events get special attention
961 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
962 evtType
< (wxPG_MAX_EVT_TYPE
) &&
965 wxPropertyGridPage
* page
= GetPage(m_selPage
);
966 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
968 // Add property grid events to appropriate custom pages
969 // but stop propagating to parent if page says it is
970 // handling everything.
971 if ( pgEvent
&& !page
->m_isDefault
)
973 /*if ( pgEvent->IsPending() )
974 page->AddPendingEvent(event);
976 page
->ProcessEvent(event
);
978 if ( page
->IsHandlingAllEvents() )
979 event
.StopPropagation();
983 return wxPanel::ProcessEvent(event
);
986 // -----------------------------------------------------------------------
988 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
989 int new_height
, bool desc_too
)
991 int use_hei
= new_height
;
994 wxColour bgcol
= GetBackgroundColour();
995 dc
.SetBrush( bgcol
);
997 int rect_hei
= use_hei
-new_splittery
;
999 rect_hei
= m_splitterHeight
;
1000 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
1001 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
1002 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
1003 int box_height
= use_hei
-splitter_bottom
;
1004 if ( box_height
> 1 )
1005 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
1007 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
1010 // -----------------------------------------------------------------------
1012 void wxPropertyGridManager::RefreshHelpBox( int new_splittery
, int new_width
, int new_height
)
1014 //if ( new_splittery == m_splitterY && new_width == m_width )
1017 int use_hei
= new_height
;
1020 //wxRendererNative::Get().DrawSplitterSash(this,dc,
1021 //wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
1023 //wxRendererNative::Get().DrawSplitterBorder(this,dc,
1024 // wxRect(0,new_splittery,new_width,m_splitterHeight));
1026 // Fix help control positions.
1027 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1028 int cap_y
= new_splittery
+m_splitterHeight
+5;
1029 int cnt_y
= cap_y
+cap_hei
+3;
1030 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1031 int cnt_hei
= use_hei
-cnt_y
;
1032 if ( sub_cap_hei
> 0 )
1034 cap_hei
-= sub_cap_hei
;
1039 m_pTxtHelpCaption
->Show( false );
1040 m_pTxtHelpContent
->Show( false );
1044 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1045 m_pTxtHelpCaption
->Wrap(-1);
1046 m_pTxtHelpCaption
->Show( true );
1049 m_pTxtHelpContent
->Show( false );
1053 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1054 m_pTxtHelpContent
->Show( true );
1058 wxClientDC
dc(this);
1059 RepaintSplitter( dc
, new_splittery
, new_width
, new_height
, true );
1061 m_splitterY
= new_splittery
;
1063 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1066 // -----------------------------------------------------------------------
1068 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1071 int propgridBottomY
= height
;
1073 // Toolbar at the top.
1079 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1082 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1083 #if defined(__WXMSW__)
1085 #elif defined(__WXGTK__)
1086 tbHeight
= -1; // 22;
1087 #elif defined(__WXMAC__)
1094 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1095 propgridY
+= m_pToolbar
->GetSize().y
;
1100 if ( m_pTxtHelpCaption
)
1102 int new_splittery
= m_splitterY
;
1105 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1107 if ( m_nextDescBoxSize
>= 0 )
1109 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1110 m_nextDescBoxSize
= -1;
1112 new_splittery
+= (height
-m_height
);
1116 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1117 if ( new_splittery
< 32 )
1121 // Check if beyond minimum.
1122 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1123 if ( new_splittery
< nspy_min
)
1124 new_splittery
= nspy_min
;
1126 propgridBottomY
= new_splittery
;
1128 RefreshHelpBox( new_splittery
, width
, height
);
1131 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1133 int pgh
= propgridBottomY
- propgridY
;
1134 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1136 m_extraHeight
= height
- pgh
;
1143 // -----------------------------------------------------------------------
1145 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1147 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1149 m_nextDescBoxSize
= ht
;
1151 RecalculatePositions(m_width
, m_height
);
1155 // -----------------------------------------------------------------------
1157 int wxPropertyGridManager::GetDescBoxHeight() const
1159 return GetClientSize().y
- m_splitterY
;
1162 // -----------------------------------------------------------------------
1164 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1168 // Update everything inside the box
1169 wxRect r
= GetUpdateRegion().GetBox();
1171 // Repaint splitter?
1172 int r_bottom
= r
.y
+ r
.height
;
1173 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1174 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1175 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1178 // -----------------------------------------------------------------------
1180 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1182 m_pPropGrid
->Refresh(eraseBackground
);
1183 wxWindow::Refresh(eraseBackground
,rect
);
1186 // -----------------------------------------------------------------------
1188 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1190 wxPropertyGrid
* grid
= p
->GetGrid();
1192 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1193 grid
->RefreshProperty(p
);
1196 // -----------------------------------------------------------------------
1198 void wxPropertyGridManager::RecreateControls()
1201 bool was_shown
= IsShown();
1205 wxWindowID baseId
= m_pPropGrid
->GetId();
1207 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1210 if ( m_windowStyle
& wxPG_TOOLBAR
)
1215 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1216 wxDefaultPosition
,wxDefaultSize
,
1217 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1218 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1220 #if defined(__WXMSW__)
1221 // Eliminate toolbar flicker on XP
1222 // NOTE: Not enabled since it corrupts drawing somewhat.
1225 #ifndef WS_EX_COMPOSITED
1226 #define WS_EX_COMPOSITED 0x02000000L
1229 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1231 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1232 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1237 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1239 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1241 wxString
desc1(_("Categorized Mode"));
1242 wxString
desc2(_("Alphabetic Mode"));
1243 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1244 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1245 desc1
,wxITEM_RADIO
);
1246 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1247 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1248 desc2
,wxITEM_RADIO
);
1249 m_pToolbar
->Realize();
1254 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1256 // Toggle correct mode button.
1257 // TODO: This doesn't work in wxMSW (when changing,
1258 // both items will get toggled).
1259 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1260 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1261 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1263 toggle_but_on_ind
++;
1264 toggle_but_off_ind
--;
1267 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1268 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1276 m_pToolbar
->Destroy();
1277 m_pToolbar
= (wxToolBar
*) NULL
;
1281 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1284 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1286 if ( !m_pTxtHelpCaption
)
1288 m_pTxtHelpCaption
= new wxStaticText (this,baseId
+ID_ADVHELPCAPTION_OFFSET
,wxEmptyString
);
1289 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1290 m_pTxtHelpCaption
->SetCursor ( *wxSTANDARD_CURSOR
);
1292 if ( !m_pTxtHelpContent
)
1294 m_pTxtHelpContent
= new wxStaticText (this,baseId
+ID_ADVHELPCONTENT_OFFSET
,
1295 wxEmptyString
,wxDefaultPosition
,wxDefaultSize
,wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1296 m_pTxtHelpContent
->SetCursor ( *wxSTANDARD_CURSOR
);
1302 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1304 if ( m_pTxtHelpCaption
)
1305 m_pTxtHelpCaption
->Destroy();
1307 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
1309 if ( m_pTxtHelpContent
)
1310 m_pTxtHelpContent
->Destroy();
1312 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
1317 GetClientSize(&width
,&height
);
1319 RecalculatePositions(width
,height
);
1325 // -----------------------------------------------------------------------
1327 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1330 for ( i
=0; i
<GetPageCount(); i
++ )
1332 wxPropertyGridPageState
* pState
= ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr();
1333 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1342 // -----------------------------------------------------------------------
1344 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1346 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1348 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1350 // Select correct page.
1351 if ( m_pPropGrid
->m_pState
!= parentState
)
1352 DoSelectPage( GetPageByState(parentState
) );
1354 return m_pPropGrid
->EnsureVisible(id
);
1357 // -----------------------------------------------------------------------
1359 size_t wxPropertyGridManager::GetChildrenCount( int page_index
)
1361 return GetChildrenCount( GetPage(page_index
)->GetStatePtr()->m_properties
);
1364 // -----------------------------------------------------------------------
1366 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1368 int id
= event
.GetId();
1371 int baseId
= m_pPropGrid
->GetId();
1373 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1375 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1377 // Categorized mode.
1378 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1379 m_pPropGrid
->EnableCategories( true );
1381 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1384 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1385 m_pPropGrid
->EnableCategories( false );
1393 wxPropertyGridPage
* pdc
;
1395 // Find page with given id.
1396 for ( i
=0; i
<GetPageCount(); i
++ )
1398 pdc
= (wxPropertyGridPage
*)m_arrPages
.Item(i
);
1399 if ( pdc
->m_id
== id
)
1406 wxASSERT( index
>= 0 );
1408 if ( DoSelectPage( index
) )
1411 // Event dispatching must be last.
1412 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, (wxPGProperty
*) NULL
);
1417 // TODO: Depress the old button on toolbar.
1424 // -----------------------------------------------------------------------
1426 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1428 if ( m_pTxtHelpCaption
)
1430 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1431 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1433 m_pTxtHelpCaption
->SetLabel(label
);
1434 m_pTxtHelpContent
->SetLabel(content
);
1436 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1437 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1439 if ( (m_iFlags
& wxPG_FL_DESC_REFRESH_REQUIRED
) || (osz2
.x
<(m_width
-10)) )
1440 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1444 // -----------------------------------------------------------------------
1446 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1448 if ( m_pTxtHelpCaption
)
1452 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1456 m_pTxtHelpCaption
->SetLabel(wxEmptyString
);
1457 m_pTxtHelpContent
->SetLabel(wxEmptyString
);
1462 // -----------------------------------------------------------------------
1464 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1468 m_pPropGrid
->SetSplitterLeft(subProps
);
1472 wxClientDC
dc(this);
1473 dc
.SetFont(m_pPropGrid
->m_font
);
1478 for ( i
=0; i
<GetPageCount(); i
++ )
1480 int maxW
= m_pState
->GetColumnFitWidth(dc
, GETPAGESTATE(i
)->m_properties
, 0, subProps
);
1481 maxW
+= m_pPropGrid
->m_marginWidth
;
1482 if ( maxW
> highest
)
1487 m_pPropGrid
->SetSplitterPosition( highest
);
1489 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1493 // -----------------------------------------------------------------------
1495 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1498 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1499 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1501 SetDescribedProperty(event
.GetProperty());
1505 // -----------------------------------------------------------------------
1507 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1511 GetClientSize(&width
,&height
);
1513 if ( m_width
== -12345 )
1516 RecalculatePositions(width
,height
);
1519 // -----------------------------------------------------------------------
1521 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1523 // Correct cursor. This is required atleast for wxGTK, for which
1524 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1525 SetCursor( wxNullCursor
);
1529 // -----------------------------------------------------------------------
1531 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1533 if ( !m_pTxtHelpCaption
)
1538 if ( m_dragStatus
> 0 )
1540 int sy
= y
- m_dragOffset
;
1542 // Calculate drag limits
1543 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1544 int top_limit
= m_pPropGrid
->m_lineHeight
;
1546 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1549 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1552 int change
= sy
- m_splitterY
;
1557 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1558 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1560 m_extraHeight
-= change
;
1561 InvalidateBestSize();
1569 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1571 SetCursor ( m_cursorSizeNS
);
1578 SetCursor ( wxNullCursor
);
1585 // -----------------------------------------------------------------------
1587 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1591 // Click on splitter.
1592 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1594 if ( m_dragStatus
== 0 )
1597 // Begin draggin the splitter
1604 m_dragOffset
= y
- m_splitterY
;
1610 // -----------------------------------------------------------------------
1612 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1614 // No event type check - basicly calling this method should
1615 // just stop dragging.
1617 if ( m_dragStatus
>= 1 )
1620 // End Splitter Dragging
1625 // DO NOT ENABLE FOLLOWING LINE!
1626 // (it is only here as a reminder to not to do it)
1629 // This is necessary to return cursor
1632 // Set back the default cursor, if necessary
1633 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1635 SetCursor ( wxNullCursor
);
1642 // -----------------------------------------------------------------------
1644 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1646 wxASSERT_MSG( GetPageCount(),
1647 wxT("SetSplitterPosition() has no effect until pages have been added") );
1650 for ( i
=0; i
<GetPageCount(); i
++ )
1652 wxPropertyGridPage
* page
= GetPage(i
);
1653 page
->DoSetSplitterPositionThisPage( pos
, splitterColumn
);
1656 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1659 // -----------------------------------------------------------------------
1660 // wxPGVIterator_Manager
1661 // -----------------------------------------------------------------------
1663 // Default returned by wxPropertyGridInterface::CreateVIterator().
1664 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1667 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1668 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1670 m_it
.Init(manager
->GetPage(0), flags
);
1672 virtual ~wxPGVIteratorBase_Manager() { }
1681 if ( m_curPage
< m_manager
->GetPageCount() )
1682 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1686 wxPropertyGridManager
* m_manager
;
1688 unsigned int m_curPage
;
1691 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1693 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1696 #endif // wxUSE_PROPGRID