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/settings.h"
35 #include "wx/textctrl.h"
37 #include "wx/statusbr.h"
41 // This define is necessary to prevent macro clearing
42 #define __wxPG_SOURCE_FILE__
44 #include "wx/propgrid/propgrid.h"
46 #include "wx/propgrid/manager.h"
49 #define wxPG_MAN_ALTERNATE_BASE_ID 11249 // Needed for wxID_ANY madnesss
52 // -----------------------------------------------------------------------
54 // For wxMSW cursor consistency, we must do mouse capturing even
55 // when using custom controls
57 #define BEGIN_MOUSE_CAPTURE \
58 if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) \
61 m_iFlags |= wxPG_FL_MOUSE_CAPTURED; \
64 #define END_MOUSE_CAPTURE \
65 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) \
68 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); \
71 // -----------------------------------------------------------------------
72 // wxPropertyGridManager
73 // -----------------------------------------------------------------------
75 const char wxPropertyGridManagerNameStr
[] = "wxPropertyGridManager";
78 // Categoric Mode Icon
79 static const char* gs_xpm_catmode
[] = {
104 // Alphabetic Mode Icon
105 static const char* gs_xpm_noncatmode
[] = {
130 // Default Page Icon.
131 static const char* gs_xpm_defpage
[] = {
156 // -----------------------------------------------------------------------
157 // wxPropertyGridPage
158 // -----------------------------------------------------------------------
161 IMPLEMENT_CLASS(wxPropertyGridPage
, wxEvtHandler
)
164 BEGIN_EVENT_TABLE(wxPropertyGridPage
, wxEvtHandler
)
168 wxPropertyGridPage::wxPropertyGridPage()
169 : wxEvtHandler(), wxPropertyGridInterface(), wxPropertyGridPageState()
171 m_pState
= this; // wxPropertyGridInterface to point to State
176 wxPropertyGridPage::~wxPropertyGridPage()
180 void wxPropertyGridPage::Clear()
182 GetStatePtr()->DoClear();
185 wxSize
wxPropertyGridPage::FitColumns()
187 wxSize sz
= DoFitColumns();
191 void wxPropertyGridPage::RefreshProperty( wxPGProperty
* p
)
194 m_manager
->RefreshProperty(p
);
197 void wxPropertyGridPage::OnShow()
201 void wxPropertyGridPage::SetSplitterPosition( int splitterPos
, int col
)
203 wxPropertyGrid
* pg
= GetGrid();
204 if ( pg
->GetState() == this )
205 pg
->SetSplitterPosition(splitterPos
);
207 DoSetSplitterPosition(splitterPos
, col
, false);
210 void wxPropertyGridPage::DoSetSplitterPosition( int pos
,
213 bool fromAutoCenter
)
215 if ( allPages
&& m_manager
->GetPageCount() )
216 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
218 wxPropertyGridPageState::DoSetSplitterPosition( pos
,
224 // -----------------------------------------------------------------------
225 // wxPropertyGridManager
226 // -----------------------------------------------------------------------
228 // Final default splitter y is client height minus this.
229 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
231 // -----------------------------------------------------------------------
233 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
235 #define ID_ADVTOOLBAR_OFFSET 1
236 #define ID_ADVHELPCAPTION_OFFSET 2
237 #define ID_ADVHELPCONTENT_OFFSET 3
238 //#define ID_ADVBUTTON_OFFSET 4
239 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
241 // -----------------------------------------------------------------------
243 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
244 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
245 EVT_SIZE(wxPropertyGridManager::OnResize
)
246 EVT_PAINT(wxPropertyGridManager::OnPaint
)
247 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
248 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
249 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
250 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
253 // -----------------------------------------------------------------------
255 wxPropertyGridManager::wxPropertyGridManager()
261 // -----------------------------------------------------------------------
263 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
268 const wxString
& name
)
272 Create(parent
,id
,pos
,size
,style
,name
);
275 // -----------------------------------------------------------------------
277 bool wxPropertyGridManager::Create( wxWindow
*parent
,
282 const wxString
& name
)
285 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
286 (style
&0xFFFF0000)|wxWANTS_CHARS
,
293 // -----------------------------------------------------------------------
296 // Initialize values to defaults
298 void wxPropertyGridManager::Init1()
301 //m_pPropGrid = (wxPropertyGrid*) NULL;
302 m_pPropGrid
= CreatePropertyGrid();
305 m_pToolbar
= (wxToolBar
*) NULL
;
307 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
308 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
310 m_emptyPage
= (wxPropertyGridPage
*) NULL
;
314 m_width
= m_height
= 0;
316 m_splitterHeight
= 5;
318 m_splitterY
= -1; // -1 causes default to be set.
320 m_nextDescBoxSize
= -1;
328 // -----------------------------------------------------------------------
330 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
332 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
333 wxNO_FULL_REPAINT_ON_RESIZE| \
336 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
337 wxNO_FULL_REPAINT_ON_RESIZE| \
341 // Which flags can be passed to underlying wxPropertyGrid.
342 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
345 // Initialize after parent etc. set
347 void wxPropertyGridManager::Init2( int style
)
350 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
353 m_windowStyle
|= (style
&0x0000FFFF);
355 wxSize csz
= GetClientSize();
357 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
359 // Prepare the first page
360 // NB: But just prepare - you still need to call Add/InsertPage
361 // to actually add properties on it.
362 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
363 pd
->m_isDefault
= true;
364 pd
->m_manager
= this;
365 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
366 state
->m_pPropGrid
= m_pPropGrid
;
367 m_arrPages
.push_back( pd
);
368 m_pPropGrid
->m_pState
= state
;
370 wxWindowID baseId
= GetId();
371 wxWindowID useId
= baseId
;
373 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
378 // Smaller controls on Mac
379 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
382 // Create propertygrid.
383 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
384 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
385 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
387 m_pPropGrid
->m_eventObject
= this;
389 m_pPropGrid
->SetId(useId
);
391 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
393 m_pState
= m_pPropGrid
->m_pState
;
395 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
397 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
400 // Connect to property grid onselect event.
401 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
402 // (see wxPropertyGridManager::ProcessEvent).
403 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
405 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
407 // Connect to toolbar button events.
408 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
409 wxEVT_COMMAND_TOOL_CLICKED
,
410 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
412 // Optional initial controls.
415 m_iFlags
|= wxPG_FL_INITIALIZED
;
419 // -----------------------------------------------------------------------
421 wxPropertyGridManager::~wxPropertyGridManager()
425 m_pPropGrid
->DoSelectProperty(NULL
);
426 m_pPropGrid
->m_pState
= NULL
;
429 for ( i
=0; i
<m_arrPages
.size(); i
++ )
431 delete m_arrPages
[i
];
437 // -----------------------------------------------------------------------
439 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
441 return new wxPropertyGrid();
444 // -----------------------------------------------------------------------
446 void wxPropertyGridManager::SetId( wxWindowID winid
)
448 wxWindow::SetId(winid
);
450 // TODO: Reconnect propgrid event handler(s).
452 m_pPropGrid
->SetId(winid
);
455 // -----------------------------------------------------------------------
457 wxSize
wxPropertyGridManager::DoGetBestSize() const
459 return wxSize(60,150);
462 // -----------------------------------------------------------------------
464 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
466 bool res
= wxWindow::SetFont(font
);
467 m_pPropGrid
->SetFont(font
);
469 // TODO: Need to do caption recacalculations for other pages as well.
471 for ( i
=0; i
<m_arrPages
.size(); i
++ )
473 wxPropertyGridPage
* page
= GetPage(i
);
475 if ( page
!= m_pPropGrid
->GetState() )
476 page
->CalculateFontAndBitmapStuff(-1);
482 // -----------------------------------------------------------------------
484 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
486 wxWindow::SetExtraStyle( exStyle
);
487 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
489 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
494 // -----------------------------------------------------------------------
496 void wxPropertyGridManager::Freeze()
498 m_pPropGrid
->Freeze();
502 // -----------------------------------------------------------------------
504 void wxPropertyGridManager::Thaw()
510 // -----------------------------------------------------------------------
512 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
514 int oldWindowStyle
= GetWindowStyleFlag();
516 wxWindow::SetWindowStyleFlag( style
);
517 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
518 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
520 // Need to re-position windows?
521 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
522 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
528 // -----------------------------------------------------------------------
530 // Actually shows given page.
531 bool wxPropertyGridManager::DoSelectPage( int index
)
533 // -1 means no page was selected
534 //wxASSERT( m_selPage >= 0 );
536 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
538 wxT("invalid page index") );
540 if ( m_selPage
== index
)
543 if ( m_pPropGrid
->m_selected
)
545 if ( !m_pPropGrid
->ClearSelection() )
549 wxPropertyGridPage
* prevPage
;
551 if ( m_selPage
>= 0 )
552 prevPage
= GetPage(m_selPage
);
554 prevPage
= m_emptyPage
;
556 wxPropertyGridPage
* nextPage
;
560 nextPage
= m_arrPages
[index
];
568 m_emptyPage
= new wxPropertyGridPage();
569 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
572 nextPage
= m_emptyPage
;
575 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
577 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
579 m_pState
= m_pPropGrid
->m_pState
;
587 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
589 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
596 // -----------------------------------------------------------------------
598 // Changes page *and* set the target page for insertion operations.
599 void wxPropertyGridManager::SelectPage( int index
)
604 // -----------------------------------------------------------------------
606 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
609 for ( i
=0; i
<GetPageCount(); i
++ )
611 if ( m_arrPages
[i
]->m_label
== name
)
617 // -----------------------------------------------------------------------
619 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
624 for ( i
=0; i
<GetPageCount(); i
++ )
626 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
633 // -----------------------------------------------------------------------
635 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
637 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
638 return m_arrPages
[index
]->m_label
;
641 // -----------------------------------------------------------------------
643 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
645 // Do not change this into wxCHECK because returning NULL is important
646 // for wxPropertyGridInterface page enumeration mechanics.
647 if ( page
>= (int)GetPageCount() )
652 return m_arrPages
[page
];
655 // -----------------------------------------------------------------------
657 void wxPropertyGridManager::Clear()
659 m_pPropGrid
->Freeze();
662 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
666 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
671 // -----------------------------------------------------------------------
673 void wxPropertyGridManager::ClearPage( int page
)
675 wxASSERT( page
>= 0 );
676 wxASSERT( page
< (int)GetPageCount() );
678 if ( page
>= 0 && page
< (int)GetPageCount() )
680 wxPropertyGridPageState
* state
= m_arrPages
[page
];
682 if ( state
== m_pPropGrid
->GetState() )
683 m_pPropGrid
->Clear();
689 // -----------------------------------------------------------------------
691 int wxPropertyGridManager::GetColumnCount( int page
) const
693 wxASSERT( page
>= -1 );
694 wxASSERT( page
< (int)GetPageCount() );
696 return GetPageState(page
)->GetColumnCount();
699 // -----------------------------------------------------------------------
701 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
703 wxASSERT( page
>= -1 );
704 wxASSERT( page
< (int)GetPageCount() );
706 GetPageState(page
)->SetColumnCount( colCount
);
707 GetGrid()->Refresh();
709 // -----------------------------------------------------------------------
711 size_t wxPropertyGridManager::GetPageCount() const
713 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
716 return m_arrPages
.size();
719 // -----------------------------------------------------------------------
721 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
722 const wxString
& label
,
724 wxPropertyGridPage
* pageObj
)
727 index
= GetPageCount();
729 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
730 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
732 bool needInit
= true;
733 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
735 wxASSERT( index
== 0 || isPageInserted
);
739 // No custom page object was given, so we will either re-use the default base
740 // page (if index==0), or create a new default page object.
741 if ( !isPageInserted
)
743 pageObj
= GetPage(0);
744 // Of course, if the base page was custom, we need to delete and
746 if ( !pageObj
->m_isDefault
)
749 pageObj
= new wxPropertyGridPage();
750 m_arrPages
[0] = pageObj
;
756 pageObj
= new wxPropertyGridPage();
758 pageObj
->m_isDefault
= true;
762 if ( !isPageInserted
)
764 // Initial page needs to be deleted and replaced
766 m_arrPages
[0] = pageObj
;
767 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
771 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
773 pageObj
->m_manager
= this;
777 state
->m_pPropGrid
= m_pPropGrid
;
778 state
->InitNonCatMode();
781 if ( label
.length() )
783 wxASSERT_MSG( !pageObj
->m_label
.length(),
784 wxT("If page label is given in constructor, empty label must be given in AddPage"));
785 pageObj
->m_label
= label
;
788 pageObj
->m_id
= m_nextTbInd
;
790 if ( isPageInserted
)
791 m_arrPages
.push_back( pageObj
);
794 if ( m_windowStyle
& wxPG_TOOLBAR
)
799 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
801 wxASSERT( m_pToolbar
);
803 // Add separator before first page.
804 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
805 m_pToolbar
->GetToolsCount() < 3 )
806 m_pToolbar
->AddSeparator();
808 if ( &bmp
!= &wxNullBitmap
)
809 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
810 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
812 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
817 m_pToolbar
->Realize();
824 // If selected page was above the point of insertion, fix the current page index
825 if ( isPageInserted
)
827 if ( m_selPage
>= index
)
834 // Set this value only when adding the first page
840 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
842 wxASSERT( pageObj
->GetGrid() );
847 // -----------------------------------------------------------------------
849 bool wxPropertyGridManager::IsAnyModified() const
852 for ( i
=0; i
<GetPageCount(); i
++ )
854 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
860 // -----------------------------------------------------------------------
862 bool wxPropertyGridManager::IsPageModified( size_t index
) const
864 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
869 // -----------------------------------------------------------------------
871 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
873 wxASSERT( index
>= 0 );
874 wxASSERT( index
< (int)m_arrPages
.size() );
876 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
879 // -----------------------------------------------------------------------
881 bool wxPropertyGridManager::RemovePage( int page
)
883 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
885 wxT("invalid page index") );
887 wxPropertyGridPage
* pd
= m_arrPages
[page
];
889 if ( m_arrPages
.size() == 1 )
891 // Last page: do not remove page entry
892 m_pPropGrid
->Clear();
894 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
898 // Change selection if current is page
899 else if ( page
== m_selPage
)
901 if ( !m_pPropGrid
->ClearSelection() )
904 // Substitute page to select
905 int substitute
= page
- 1;
906 if ( substitute
< 0 )
907 substitute
= page
+ 1;
909 SelectPage(substitute
);
912 // Remove toolbar icon
914 if ( HasFlag(wxPG_TOOLBAR
) )
916 wxASSERT( m_pToolbar
);
918 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
921 // Delete separator as well, for consistency
922 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
923 GetPageCount() == 1 )
924 m_pToolbar
->DeleteToolByPos(2);
926 m_pToolbar
->DeleteToolByPos(toolPos
);
930 if ( m_arrPages
.size() > 1 )
932 m_arrPages
.erase(m_arrPages
.begin() + page
);
936 // Adjust indexes that were above removed
937 if ( m_selPage
> page
)
943 // -----------------------------------------------------------------------
945 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
947 int evtType
= event
.GetEventType();
949 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
950 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
951 // don't really matter.
952 if ( evtType
== wxEVT_PG_SELECTED
)
953 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
955 // Property grid events get special attention
956 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
957 evtType
< (wxPG_MAX_EVT_TYPE
) &&
960 wxPropertyGridPage
* page
= GetPage(m_selPage
);
961 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
963 // Add property grid events to appropriate custom pages
964 // but stop propagating to parent if page says it is
965 // handling everything.
966 if ( pgEvent
&& !page
->m_isDefault
)
968 /*if ( pgEvent->IsPending() )
969 page->AddPendingEvent(event);
971 page
->ProcessEvent(event
);
973 if ( page
->IsHandlingAllEvents() )
974 event
.StopPropagation();
978 return wxPanel::ProcessEvent(event
);
981 // -----------------------------------------------------------------------
983 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
984 int new_height
, bool desc_too
)
986 int use_hei
= new_height
;
989 wxColour bgcol
= GetBackgroundColour();
990 dc
.SetBrush( bgcol
);
992 int rect_hei
= use_hei
-new_splittery
;
994 rect_hei
= m_splitterHeight
;
995 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
996 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
997 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
998 int box_height
= use_hei
-splitter_bottom
;
999 if ( box_height
> 1 )
1000 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
1002 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
1005 // -----------------------------------------------------------------------
1007 void wxPropertyGridManager::RefreshHelpBox( int new_splittery
, int new_width
, int new_height
)
1009 //if ( new_splittery == m_splitterY && new_width == m_width )
1012 int use_hei
= new_height
;
1015 //wxRendererNative::Get().DrawSplitterSash(this,dc,
1016 //wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
1018 //wxRendererNative::Get().DrawSplitterBorder(this,dc,
1019 // wxRect(0,new_splittery,new_width,m_splitterHeight));
1021 // Fix help control positions.
1022 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1023 int cap_y
= new_splittery
+m_splitterHeight
+5;
1024 int cnt_y
= cap_y
+cap_hei
+3;
1025 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1026 int cnt_hei
= use_hei
-cnt_y
;
1027 if ( sub_cap_hei
> 0 )
1029 cap_hei
-= sub_cap_hei
;
1034 m_pTxtHelpCaption
->Show( false );
1035 m_pTxtHelpContent
->Show( false );
1039 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1040 m_pTxtHelpCaption
->Wrap(-1);
1041 m_pTxtHelpCaption
->Show( true );
1044 m_pTxtHelpContent
->Show( false );
1048 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1049 m_pTxtHelpContent
->Show( true );
1053 wxClientDC
dc(this);
1054 RepaintSplitter( dc
, new_splittery
, new_width
, new_height
, true );
1056 m_splitterY
= new_splittery
;
1058 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1061 // -----------------------------------------------------------------------
1063 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1066 int propgridBottomY
= height
;
1068 // Toolbar at the top.
1074 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1077 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1078 #if defined(__WXMSW__)
1080 #elif defined(__WXGTK__)
1081 tbHeight
= -1; // 22;
1082 #elif defined(__WXMAC__)
1089 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1090 propgridY
+= m_pToolbar
->GetSize().y
;
1095 if ( m_pTxtHelpCaption
)
1097 int new_splittery
= m_splitterY
;
1100 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1102 if ( m_nextDescBoxSize
>= 0 )
1104 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1105 m_nextDescBoxSize
= -1;
1107 new_splittery
+= (height
-m_height
);
1111 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1112 if ( new_splittery
< 32 )
1116 // Check if beyond minimum.
1117 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1118 if ( new_splittery
< nspy_min
)
1119 new_splittery
= nspy_min
;
1121 propgridBottomY
= new_splittery
;
1123 RefreshHelpBox( new_splittery
, width
, height
);
1126 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1128 int pgh
= propgridBottomY
- propgridY
;
1129 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1131 m_extraHeight
= height
- pgh
;
1138 // -----------------------------------------------------------------------
1140 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1142 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1144 if ( ht
!= GetDescBoxHeight() )
1146 m_nextDescBoxSize
= ht
;
1148 RecalculatePositions(m_width
, m_height
);
1153 // -----------------------------------------------------------------------
1155 int wxPropertyGridManager::GetDescBoxHeight() const
1157 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1160 // -----------------------------------------------------------------------
1162 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1166 // Update everything inside the box
1167 wxRect r
= GetUpdateRegion().GetBox();
1169 // Repaint splitter?
1170 int r_bottom
= r
.y
+ r
.height
;
1171 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1172 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1173 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1176 // -----------------------------------------------------------------------
1178 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1180 m_pPropGrid
->Refresh(eraseBackground
);
1181 wxWindow::Refresh(eraseBackground
,rect
);
1184 // -----------------------------------------------------------------------
1186 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1188 wxPropertyGrid
* grid
= p
->GetGrid();
1190 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1191 grid
->RefreshProperty(p
);
1194 // -----------------------------------------------------------------------
1196 void wxPropertyGridManager::RecreateControls()
1199 bool was_shown
= IsShown();
1203 wxWindowID baseId
= m_pPropGrid
->GetId();
1205 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1208 if ( m_windowStyle
& wxPG_TOOLBAR
)
1213 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1214 wxDefaultPosition
,wxDefaultSize
,
1215 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1216 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1218 #if defined(__WXMSW__)
1219 // Eliminate toolbar flicker on XP
1220 // NOTE: Not enabled since it corrupts drawing somewhat.
1223 #ifndef WS_EX_COMPOSITED
1224 #define WS_EX_COMPOSITED 0x02000000L
1227 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1229 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1230 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1235 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1237 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1239 wxString
desc1(_("Categorized Mode"));
1240 wxString
desc2(_("Alphabetic Mode"));
1241 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1242 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1243 desc1
,wxITEM_RADIO
);
1244 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1245 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1246 desc2
,wxITEM_RADIO
);
1247 m_pToolbar
->Realize();
1252 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1254 // Toggle correct mode button.
1255 // TODO: This doesn't work in wxMSW (when changing,
1256 // both items will get toggled).
1257 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1258 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1259 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1261 toggle_but_on_ind
++;
1262 toggle_but_off_ind
--;
1265 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1266 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1274 m_pToolbar
->Destroy();
1275 m_pToolbar
= (wxToolBar
*) NULL
;
1279 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1282 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1284 if ( !m_pTxtHelpCaption
)
1286 m_pTxtHelpCaption
= new wxStaticText (this,baseId
+ID_ADVHELPCAPTION_OFFSET
,wxEmptyString
);
1287 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1288 m_pTxtHelpCaption
->SetCursor ( *wxSTANDARD_CURSOR
);
1290 if ( !m_pTxtHelpContent
)
1292 m_pTxtHelpContent
= new wxStaticText (this,baseId
+ID_ADVHELPCONTENT_OFFSET
,
1293 wxEmptyString
,wxDefaultPosition
,wxDefaultSize
,wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1294 m_pTxtHelpContent
->SetCursor ( *wxSTANDARD_CURSOR
);
1297 SetDescribedProperty(GetSelection());
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
= m_arrPages
[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 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1361 int id
= event
.GetId();
1364 int baseId
= m_pPropGrid
->GetId();
1366 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1368 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1370 // Categorized mode.
1371 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1373 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1374 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1375 m_pPropGrid
->EnableCategories( true );
1378 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1381 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1383 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1384 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1386 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1388 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1389 m_pPropGrid
->EnableCategories( false );
1398 wxPropertyGridPage
* pdc
;
1400 // Find page with given id.
1401 for ( i
=0; i
<GetPageCount(); i
++ )
1403 pdc
= m_arrPages
[i
];
1404 if ( pdc
->m_id
== id
)
1411 wxASSERT( index
>= 0 );
1413 if ( DoSelectPage( index
) )
1416 // Event dispatching must be last.
1417 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, (wxPGProperty
*) NULL
);
1422 // TODO: Depress the old button on toolbar.
1429 // -----------------------------------------------------------------------
1431 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1433 if ( name
== wxS("descboxheight") )
1435 SetDescBoxHeight(value
.GetLong(), true);
1441 // -----------------------------------------------------------------------
1443 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1445 if ( name
== wxS("descboxheight") )
1447 return (long) GetDescBoxHeight();
1449 return wxNullVariant
;
1452 // -----------------------------------------------------------------------
1454 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1456 if ( m_pTxtHelpCaption
)
1458 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1459 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1461 m_pTxtHelpCaption
->SetLabel(label
);
1462 m_pTxtHelpContent
->SetLabel(content
);
1464 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1465 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1467 if ( (m_iFlags
& wxPG_FL_DESC_REFRESH_REQUIRED
) || (osz2
.x
<(m_width
-10)) )
1468 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1472 // -----------------------------------------------------------------------
1474 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1476 if ( m_pTxtHelpCaption
)
1480 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1484 m_pTxtHelpCaption
->SetLabel(wxEmptyString
);
1485 m_pTxtHelpContent
->SetLabel(wxEmptyString
);
1490 // -----------------------------------------------------------------------
1492 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1496 m_pPropGrid
->SetSplitterLeft(subProps
);
1500 wxClientDC
dc(this);
1501 dc
.SetFont(m_pPropGrid
->m_font
);
1506 for ( i
=0; i
<GetPageCount(); i
++ )
1508 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1509 maxW
+= m_pPropGrid
->m_marginWidth
;
1510 if ( maxW
> highest
)
1515 m_pPropGrid
->SetSplitterPosition( highest
);
1517 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1521 // -----------------------------------------------------------------------
1523 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1526 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1527 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1529 SetDescribedProperty(event
.GetProperty());
1533 // -----------------------------------------------------------------------
1535 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1539 GetClientSize(&width
,&height
);
1541 if ( m_width
== -12345 )
1544 RecalculatePositions(width
,height
);
1547 // -----------------------------------------------------------------------
1549 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1551 // Correct cursor. This is required atleast for wxGTK, for which
1552 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1553 SetCursor( wxNullCursor
);
1557 // -----------------------------------------------------------------------
1559 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1561 if ( !m_pTxtHelpCaption
)
1566 if ( m_dragStatus
> 0 )
1568 int sy
= y
- m_dragOffset
;
1570 // Calculate drag limits
1571 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1572 int top_limit
= m_pPropGrid
->m_lineHeight
;
1574 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1577 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1580 int change
= sy
- m_splitterY
;
1585 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1586 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1588 m_extraHeight
-= change
;
1589 InvalidateBestSize();
1597 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1599 SetCursor ( m_cursorSizeNS
);
1606 SetCursor ( wxNullCursor
);
1613 // -----------------------------------------------------------------------
1615 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1619 // Click on splitter.
1620 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1622 if ( m_dragStatus
== 0 )
1625 // Begin draggin the splitter
1632 m_dragOffset
= y
- m_splitterY
;
1638 // -----------------------------------------------------------------------
1640 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1642 // No event type check - basicly calling this method should
1643 // just stop dragging.
1645 if ( m_dragStatus
>= 1 )
1648 // End Splitter Dragging
1653 // DO NOT ENABLE FOLLOWING LINE!
1654 // (it is only here as a reminder to not to do it)
1657 // This is necessary to return cursor
1660 // Set back the default cursor, if necessary
1661 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1663 SetCursor ( wxNullCursor
);
1670 // -----------------------------------------------------------------------
1672 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1674 wxASSERT_MSG( GetPageCount(),
1675 wxT("SetSplitterPosition() has no effect until pages have been added") );
1678 for ( i
=0; i
<GetPageCount(); i
++ )
1680 wxPropertyGridPage
* page
= GetPage(i
);
1681 page
->DoSetSplitterPosition( pos
, splitterColumn
, false );
1684 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1687 // -----------------------------------------------------------------------
1688 // wxPGVIterator_Manager
1689 // -----------------------------------------------------------------------
1691 // Default returned by wxPropertyGridInterface::CreateVIterator().
1692 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1695 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1696 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1698 m_it
.Init(manager
->GetPage(0), flags
);
1700 virtual ~wxPGVIteratorBase_Manager() { }
1709 if ( m_curPage
< m_manager
->GetPageCount() )
1710 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1714 wxPropertyGridManager
* m_manager
;
1716 unsigned int m_curPage
;
1719 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1721 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1724 #endif // wxUSE_PROPGRID