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 wxChar
*wxPropertyGridManagerNameStr
= wxT("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 #define GETPAGESTATE(page) ((wxPropertyGridPage*)m_arrPages.Item(page))->GetStatePtr()
158 // -----------------------------------------------------------------------
159 // wxPropertyGridPage
160 // -----------------------------------------------------------------------
163 IMPLEMENT_CLASS(wxPropertyGridPage
, wxEvtHandler
)
166 BEGIN_EVENT_TABLE(wxPropertyGridPage
, wxEvtHandler
)
170 wxPropertyGridPage::wxPropertyGridPage()
171 : wxEvtHandler(), wxPropertyGridInterface(), wxPropertyGridPageState()
173 m_pState
= this; // wxPropertyGridInterface to point to State
178 wxPropertyGridPage::~wxPropertyGridPage()
182 void wxPropertyGridPage::Clear()
184 GetStatePtr()->DoClear();
187 wxSize
wxPropertyGridPage::FitColumns()
189 wxSize sz
= DoFitColumns();
193 void wxPropertyGridPage::RefreshProperty( wxPGProperty
* p
)
196 m_manager
->RefreshProperty(p
);
199 void wxPropertyGridPage::OnShow()
203 void wxPropertyGridPage::SetSplitterPosition( int splitterPos
, int col
)
205 wxPropertyGrid
* pg
= GetGrid();
206 if ( pg
->GetState() == this )
207 pg
->SetSplitterPosition(splitterPos
);
209 DoSetSplitterPosition(splitterPos
, col
, false);
212 void wxPropertyGridPage::DoSetSplitterPosition( int pos
, int splitterColumn
, bool allPages
)
214 if ( allPages
&& m_manager
->GetPageCount() )
215 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
217 DoSetSplitterPositionThisPage( pos
, splitterColumn
);
220 // -----------------------------------------------------------------------
221 // wxPropertyGridManager
222 // -----------------------------------------------------------------------
224 // Final default splitter y is client height minus this.
225 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
227 // -----------------------------------------------------------------------
229 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
231 #define ID_ADVTOOLBAR_OFFSET 1
232 #define ID_ADVHELPCAPTION_OFFSET 2
233 #define ID_ADVHELPCONTENT_OFFSET 3
234 #define ID_ADVBUTTON_OFFSET 4
235 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
237 // -----------------------------------------------------------------------
239 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
240 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
241 EVT_SIZE(wxPropertyGridManager::OnResize
)
242 EVT_PAINT(wxPropertyGridManager::OnPaint
)
243 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
244 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
245 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
246 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
249 // -----------------------------------------------------------------------
251 wxPropertyGridManager::wxPropertyGridManager()
257 // -----------------------------------------------------------------------
259 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
268 Create(parent
,id
,pos
,size
,style
,name
);
271 // -----------------------------------------------------------------------
273 bool wxPropertyGridManager::Create( wxWindow
*parent
,
281 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
282 (style
&0xFFFF0000)|wxWANTS_CHARS
,
289 // -----------------------------------------------------------------------
292 // Initialize values to defaults
294 void wxPropertyGridManager::Init1()
297 //m_pPropGrid = (wxPropertyGrid*) NULL;
298 m_pPropGrid
= CreatePropertyGrid();
301 m_pToolbar
= (wxToolBar
*) NULL
;
303 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
304 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
306 m_emptyPage
= (wxPropertyGridPage
*) NULL
;
310 m_width
= m_height
= 0;
312 m_splitterHeight
= 5;
314 m_splitterY
= -1; // -1 causes default to be set.
316 m_nextDescBoxSize
= -1;
324 // -----------------------------------------------------------------------
326 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
328 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
329 wxNO_FULL_REPAINT_ON_RESIZE| \
332 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
333 wxNO_FULL_REPAINT_ON_RESIZE| \
337 // Which flags can be passed to underlying wxPropertyGrid.
338 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
341 // Initialize after parent etc. set
343 void wxPropertyGridManager::Init2( int style
)
346 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
349 m_windowStyle
|= (style
&0x0000FFFF);
351 wxSize csz
= GetClientSize();
353 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
355 // Prepare the first page
356 // NB: But just prepare - you still need to call Add/InsertPage
357 // to actually add properties on it.
358 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
359 pd
->m_isDefault
= true;
360 pd
->m_manager
= this;
361 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
362 state
->m_pPropGrid
= m_pPropGrid
;
363 m_arrPages
.Add( (void*)pd
);
364 m_pPropGrid
->m_pState
= state
;
366 wxWindowID baseId
= GetId();
367 wxWindowID useId
= baseId
;
369 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
374 // Smaller controls on Mac
375 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
378 // Create propertygrid.
379 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
380 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
381 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
383 m_pPropGrid
->m_eventObject
= this;
385 m_pPropGrid
->SetId(useId
);
387 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
389 m_pState
= m_pPropGrid
->m_pState
;
391 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
393 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
396 // Connect to property grid onselect event.
397 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
398 // (see wxPropertyGridManager::ProcessEvent).
399 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
401 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
403 // Connect to toolbar button events.
404 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
405 wxEVT_COMMAND_TOOL_CLICKED
,
406 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
408 // Optional initial controls.
411 m_iFlags
|= wxPG_FL_INITIALIZED
;
415 // -----------------------------------------------------------------------
417 wxPropertyGridManager::~wxPropertyGridManager()
421 m_pPropGrid
->DoSelectProperty(NULL
);
422 m_pPropGrid
->m_pState
= NULL
;
425 for ( i
=0; i
<m_arrPages
.GetCount(); i
++ )
427 delete (wxPropertyGridPage
*)m_arrPages
.Item(i
);
433 // -----------------------------------------------------------------------
435 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
437 return new wxPropertyGrid();
440 // -----------------------------------------------------------------------
442 void wxPropertyGridManager::SetId( wxWindowID winid
)
444 wxWindow::SetId(winid
);
446 // TODO: Reconnect propgrid event handler(s).
448 m_pPropGrid
->SetId(winid
);
451 // -----------------------------------------------------------------------
453 wxSize
wxPropertyGridManager::DoGetBestSize() const
455 return wxSize(60,150);
458 // -----------------------------------------------------------------------
460 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
462 bool res
= wxWindow::SetFont(font
);
463 m_pPropGrid
->SetFont(font
);
465 // TODO: Need to do caption recacalculations for other pages as well.
467 for ( i
=0; i
<m_arrPages
.GetCount(); i
++ )
469 wxPropertyGridPage
* page
= GetPage(i
);
471 if ( page
!= m_pPropGrid
->GetState() )
472 page
->CalculateFontAndBitmapStuff(-1);
478 // -----------------------------------------------------------------------
480 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
482 wxWindow::SetExtraStyle( exStyle
);
483 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
485 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
490 // -----------------------------------------------------------------------
492 void wxPropertyGridManager::Freeze()
494 m_pPropGrid
->Freeze();
498 // -----------------------------------------------------------------------
500 void wxPropertyGridManager::Thaw()
506 // -----------------------------------------------------------------------
508 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
510 wxWindow::SetWindowStyleFlag( style
);
511 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
512 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
515 // -----------------------------------------------------------------------
517 // Actually shows given page.
518 bool wxPropertyGridManager::DoSelectPage( int index
)
520 // -1 means no page was selected
521 //wxASSERT( m_selPage >= 0 );
523 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
525 wxT("invalid page index") );
527 if ( m_selPage
== index
)
530 if ( m_pPropGrid
->m_selected
)
532 if ( !m_pPropGrid
->ClearSelection() )
536 wxPropertyGridPage
* prevPage
;
538 if ( m_selPage
>= 0 )
539 prevPage
= GetPage(m_selPage
);
541 prevPage
= m_emptyPage
;
543 wxPropertyGridPage
* nextPage
;
547 nextPage
= (wxPropertyGridPage
*)m_arrPages
.Item(index
);
555 m_emptyPage
= new wxPropertyGridPage();
556 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
559 nextPage
= m_emptyPage
;
562 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
564 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
566 m_pState
= m_pPropGrid
->m_pState
;
574 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
576 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
583 // -----------------------------------------------------------------------
585 // Changes page *and* set the target page for insertion operations.
586 void wxPropertyGridManager::SelectPage( int index
)
591 // -----------------------------------------------------------------------
593 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
596 for ( i
=0; i
<GetPageCount(); i
++ )
598 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->m_label
== name
)
604 // -----------------------------------------------------------------------
606 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
611 for ( i
=0; i
<GetPageCount(); i
++ )
613 if ( pState
== ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr() )
620 // -----------------------------------------------------------------------
622 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
624 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
625 return ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->m_label
;
628 // -----------------------------------------------------------------------
630 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
632 // Do not change this into wxCHECK because returning NULL is important
633 // for wxPropertyGridInterface page enumeration mechanics.
634 if ( page
>= (int)GetPageCount() )
639 return GETPAGESTATE(page
);
642 // -----------------------------------------------------------------------
644 void wxPropertyGridManager::Clear()
646 m_pPropGrid
->Freeze();
649 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
653 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
658 // -----------------------------------------------------------------------
660 void wxPropertyGridManager::ClearPage( int page
)
662 wxASSERT( page
>= 0 );
663 wxASSERT( page
< (int)GetPageCount() );
665 if ( page
>= 0 && page
< (int)GetPageCount() )
667 wxPropertyGridPageState
* state
= GETPAGESTATE(page
);
669 if ( state
== m_pPropGrid
->GetState() )
670 m_pPropGrid
->Clear();
676 // -----------------------------------------------------------------------
678 int wxPropertyGridManager::GetColumnCount( int page
) const
680 wxASSERT( page
>= -1 );
681 wxASSERT( page
< (int)GetPageCount() );
683 return GetPageState(page
)->GetColumnCount();
686 // -----------------------------------------------------------------------
688 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
690 wxASSERT( page
>= -1 );
691 wxASSERT( page
< (int)GetPageCount() );
693 GetPageState(page
)->SetColumnCount( colCount
);
694 GetGrid()->Refresh();
696 // -----------------------------------------------------------------------
698 size_t wxPropertyGridManager::GetPageCount() const
700 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
703 return m_arrPages
.GetCount();
706 // -----------------------------------------------------------------------
708 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
709 const wxString
& label
,
711 wxPropertyGridPage
* pageObj
)
714 index
= GetPageCount();
716 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
717 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
719 bool needInit
= true;
720 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
722 wxASSERT( index
== 0 || isPageInserted
);
726 // No custom page object was given, so we will either re-use the default base
727 // page (if index==0), or create a new default page object.
728 if ( !isPageInserted
)
730 pageObj
= GetPage(0);
731 // Of course, if the base page was custom, we need to delete and
733 if ( !pageObj
->m_isDefault
)
736 pageObj
= new wxPropertyGridPage();
737 m_arrPages
[0] = pageObj
;
743 pageObj
= new wxPropertyGridPage();
745 pageObj
->m_isDefault
= true;
749 if ( !isPageInserted
)
751 // Initial page needs to be deleted and replaced
753 m_arrPages
[0] = pageObj
;
754 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
758 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
760 pageObj
->m_manager
= this;
764 state
->m_pPropGrid
= m_pPropGrid
;
765 state
->InitNonCatMode();
768 if ( label
.length() )
770 wxASSERT_MSG( !pageObj
->m_label
.length(),
771 wxT("If page label is given in constructor, empty label must be given in AddPage"));
772 pageObj
->m_label
= label
;
775 pageObj
->m_id
= m_nextTbInd
;
777 if ( isPageInserted
)
778 m_arrPages
.Add( (void*)pageObj
);
781 if ( m_windowStyle
& wxPG_TOOLBAR
)
786 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
788 wxASSERT( m_pToolbar
);
790 // Add separator before first page.
791 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
792 m_pToolbar
->GetToolsCount() < 3 )
793 m_pToolbar
->AddSeparator();
795 if ( &bmp
!= &wxNullBitmap
)
796 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
797 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
799 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
804 m_pToolbar
->Realize();
811 // If selected page was above the point of insertion, fix the current page index
812 if ( isPageInserted
)
814 if ( m_selPage
>= index
)
821 // Set this value only when adding the first page
827 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
829 wxASSERT( pageObj
->GetGrid() );
834 // -----------------------------------------------------------------------
836 bool wxPropertyGridManager::IsAnyModified() const
839 for ( i
=0; i
<GetPageCount(); i
++ )
841 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr()->m_anyModified
)
847 // -----------------------------------------------------------------------
849 bool wxPropertyGridManager::IsPageModified( size_t index
) const
851 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->GetStatePtr()->m_anyModified
)
856 // -----------------------------------------------------------------------
858 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
860 wxASSERT( index
>= 0 );
861 wxASSERT( index
< (int)m_arrPages
.GetCount() );
863 return ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->GetStatePtr()->m_properties
;
866 // -----------------------------------------------------------------------
868 bool wxPropertyGridManager::RemovePage( int page
)
870 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
872 wxT("invalid page index") );
874 wxPropertyGridPage
* pd
= (wxPropertyGridPage
*)m_arrPages
.Item(page
);
876 if ( m_arrPages
.GetCount() == 1 )
878 // Last page: do not remove page entry
879 m_pPropGrid
->Clear();
881 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
884 // Change selection if current is page
885 else if ( page
== m_selPage
)
887 if ( !m_pPropGrid
->ClearSelection() )
890 // Substitute page to select
891 int substitute
= page
- 1;
892 if ( substitute
< 0 )
893 substitute
= page
+ 1;
895 SelectPage(substitute
);
898 // Remove toolbar icon
900 if ( HasFlag(wxPG_TOOLBAR
) )
902 wxASSERT( m_pToolbar
);
904 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
907 // Delete separator as well, for consistency
908 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
909 GetPageCount() == 1 )
910 m_pToolbar
->DeleteToolByPos(2);
912 m_pToolbar
->DeleteToolByPos(toolPos
);
916 if ( m_arrPages
.GetCount() > 1 )
918 m_arrPages
.RemoveAt(page
);
922 // Adjust indexes that were above removed
923 if ( m_selPage
> page
)
929 // -----------------------------------------------------------------------
931 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
933 int evtType
= event
.GetEventType();
935 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
936 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
937 // don't really matter.
938 if ( evtType
== wxEVT_PG_SELECTED
)
939 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
941 // Property grid events get special attention
942 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
943 evtType
< (wxPG_MAX_EVT_TYPE
) &&
946 wxPropertyGridPage
* page
= GetPage(m_selPage
);
947 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
949 // Add property grid events to appropriate custom pages
950 // but stop propagating to parent if page says it is
951 // handling everything.
952 if ( pgEvent
&& !page
->m_isDefault
)
954 /*if ( pgEvent->IsPending() )
955 page->AddPendingEvent(event);
957 page
->ProcessEvent(event
);
959 if ( page
->IsHandlingAllEvents() )
960 event
.StopPropagation();
964 return wxPanel::ProcessEvent(event
);
967 // -----------------------------------------------------------------------
969 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
970 int new_height
, bool desc_too
)
972 int use_hei
= new_height
;
975 wxColour bgcol
= GetBackgroundColour();
976 dc
.SetBrush( bgcol
);
978 int rect_hei
= use_hei
-new_splittery
;
980 rect_hei
= m_splitterHeight
;
981 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
982 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
983 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
984 int box_height
= use_hei
-splitter_bottom
;
985 if ( box_height
> 1 )
986 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
988 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
991 // -----------------------------------------------------------------------
993 void wxPropertyGridManager::RefreshHelpBox( int new_splittery
, int new_width
, int new_height
)
995 //if ( new_splittery == m_splitterY && new_width == m_width )
998 int use_hei
= new_height
;
1001 //wxRendererNative::Get().DrawSplitterSash(this,dc,
1002 //wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
1004 //wxRendererNative::Get().DrawSplitterBorder(this,dc,
1005 // wxRect(0,new_splittery,new_width,m_splitterHeight));
1007 // Fix help control positions.
1008 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1009 int cap_y
= new_splittery
+m_splitterHeight
+5;
1010 int cnt_y
= cap_y
+cap_hei
+3;
1011 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1012 int cnt_hei
= use_hei
-cnt_y
;
1013 if ( sub_cap_hei
> 0 )
1015 cap_hei
-= sub_cap_hei
;
1020 m_pTxtHelpCaption
->Show( false );
1021 m_pTxtHelpContent
->Show( false );
1025 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1026 m_pTxtHelpCaption
->Wrap(-1);
1027 m_pTxtHelpCaption
->Show( true );
1030 m_pTxtHelpContent
->Show( false );
1034 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1035 m_pTxtHelpContent
->Show( true );
1039 wxClientDC
dc(this);
1040 RepaintSplitter( dc
, new_splittery
, new_width
, new_height
, true );
1042 m_splitterY
= new_splittery
;
1044 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1047 // -----------------------------------------------------------------------
1049 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1052 int propgridBottomY
= height
;
1054 // Toolbar at the top.
1060 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1063 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1064 #if defined(__WXMSW__)
1066 #elif defined(__WXGTK__)
1067 tbHeight
= -1; // 22;
1068 #elif defined(__WXMAC__)
1075 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1076 propgridY
+= m_pToolbar
->GetSize().y
;
1081 if ( m_pTxtHelpCaption
)
1083 int new_splittery
= m_splitterY
;
1086 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1088 if ( m_nextDescBoxSize
>= 0 )
1090 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1091 m_nextDescBoxSize
= -1;
1093 new_splittery
+= (height
-m_height
);
1097 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1098 if ( new_splittery
< 32 )
1102 // Check if beyond minimum.
1103 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1104 if ( new_splittery
< nspy_min
)
1105 new_splittery
= nspy_min
;
1107 propgridBottomY
= new_splittery
;
1109 RefreshHelpBox( new_splittery
, width
, height
);
1112 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1114 int pgh
= propgridBottomY
- propgridY
;
1115 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1117 m_extraHeight
= height
- pgh
;
1124 // -----------------------------------------------------------------------
1126 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1128 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1130 m_nextDescBoxSize
= ht
;
1132 RecalculatePositions(m_width
, m_height
);
1136 // -----------------------------------------------------------------------
1138 int wxPropertyGridManager::GetDescBoxHeight() const
1140 return GetClientSize().y
- m_splitterY
;
1143 // -----------------------------------------------------------------------
1145 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1149 // Update everything inside the box
1150 wxRect r
= GetUpdateRegion().GetBox();
1152 // Repaint splitter?
1153 int r_bottom
= r
.y
+ r
.height
;
1154 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1155 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1156 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1159 // -----------------------------------------------------------------------
1161 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1163 m_pPropGrid
->Refresh(eraseBackground
);
1164 wxWindow::Refresh(eraseBackground
,rect
);
1167 // -----------------------------------------------------------------------
1169 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1171 wxPropertyGrid
* grid
= p
->GetGrid();
1173 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1174 grid
->RefreshProperty(p
);
1177 // -----------------------------------------------------------------------
1179 void wxPropertyGridManager::RecreateControls()
1182 bool was_shown
= IsShown();
1186 wxWindowID baseId
= m_pPropGrid
->GetId();
1188 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1191 if ( m_windowStyle
& wxPG_TOOLBAR
)
1196 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1197 wxDefaultPosition
,wxDefaultSize
,
1198 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1199 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1201 #if defined(__WXMSW__)
1202 // Eliminate toolbar flicker on XP
1203 // NOTE: Not enabled since it corrupts drawing somewhat.
1206 #ifndef WS_EX_COMPOSITED
1207 #define WS_EX_COMPOSITED 0x02000000L
1210 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1212 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1213 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1218 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1220 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1222 wxString
desc1(_("Categorized Mode"));
1223 wxString
desc2(_("Alphabetic Mode"));
1224 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1225 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1226 desc1
,wxITEM_RADIO
);
1227 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1228 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1229 desc2
,wxITEM_RADIO
);
1230 m_pToolbar
->Realize();
1235 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1237 // Toggle correct mode button.
1238 // TODO: This doesn't work in wxMSW (when changing,
1239 // both items will get toggled).
1240 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1241 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1242 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1244 toggle_but_on_ind
++;
1245 toggle_but_off_ind
--;
1248 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1249 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1257 m_pToolbar
->Destroy();
1258 m_pToolbar
= (wxToolBar
*) NULL
;
1262 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1265 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1267 if ( !m_pTxtHelpCaption
)
1269 m_pTxtHelpCaption
= new wxStaticText (this,baseId
+ID_ADVHELPCAPTION_OFFSET
,wxEmptyString
);
1270 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1271 m_pTxtHelpCaption
->SetCursor ( *wxSTANDARD_CURSOR
);
1273 if ( !m_pTxtHelpContent
)
1275 m_pTxtHelpContent
= new wxStaticText (this,baseId
+ID_ADVHELPCONTENT_OFFSET
,
1276 wxEmptyString
,wxDefaultPosition
,wxDefaultSize
,wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1277 m_pTxtHelpContent
->SetCursor ( *wxSTANDARD_CURSOR
);
1283 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1285 if ( m_pTxtHelpCaption
)
1286 m_pTxtHelpCaption
->Destroy();
1288 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
1290 if ( m_pTxtHelpContent
)
1291 m_pTxtHelpContent
->Destroy();
1293 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
1298 GetClientSize(&width
,&height
);
1300 RecalculatePositions(width
,height
);
1306 // -----------------------------------------------------------------------
1308 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1311 for ( i
=0; i
<GetPageCount(); i
++ )
1313 wxPropertyGridPageState
* pState
= ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr();
1314 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1323 // -----------------------------------------------------------------------
1325 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1327 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1329 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1331 // Select correct page.
1332 if ( m_pPropGrid
->m_pState
!= parentState
)
1333 DoSelectPage( GetPageByState(parentState
) );
1335 return m_pPropGrid
->EnsureVisible(id
);
1338 // -----------------------------------------------------------------------
1340 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1342 int id
= event
.GetId();
1345 int baseId
= m_pPropGrid
->GetId();
1347 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1349 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1351 // Categorized mode.
1352 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1353 m_pPropGrid
->EnableCategories( true );
1355 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1358 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1359 m_pPropGrid
->EnableCategories( false );
1367 wxPropertyGridPage
* pdc
;
1369 // Find page with given id.
1370 for ( i
=0; i
<GetPageCount(); i
++ )
1372 pdc
= (wxPropertyGridPage
*)m_arrPages
.Item(i
);
1373 if ( pdc
->m_id
== id
)
1380 wxASSERT( index
>= 0 );
1382 if ( DoSelectPage( index
) )
1385 // Event dispatching must be last.
1386 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, (wxPGProperty
*) NULL
);
1391 // TODO: Depress the old button on toolbar.
1398 // -----------------------------------------------------------------------
1400 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1402 if ( m_pTxtHelpCaption
)
1404 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1405 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1407 m_pTxtHelpCaption
->SetLabel(label
);
1408 m_pTxtHelpContent
->SetLabel(content
);
1410 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1411 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1413 if ( (m_iFlags
& wxPG_FL_DESC_REFRESH_REQUIRED
) || (osz2
.x
<(m_width
-10)) )
1414 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1418 // -----------------------------------------------------------------------
1420 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1422 if ( m_pTxtHelpCaption
)
1426 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1430 m_pTxtHelpCaption
->SetLabel(wxEmptyString
);
1431 m_pTxtHelpContent
->SetLabel(wxEmptyString
);
1436 // -----------------------------------------------------------------------
1438 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1442 m_pPropGrid
->SetSplitterLeft(subProps
);
1446 wxClientDC
dc(this);
1447 dc
.SetFont(m_pPropGrid
->m_font
);
1452 for ( i
=0; i
<GetPageCount(); i
++ )
1454 int maxW
= m_pState
->GetColumnFitWidth(dc
, GETPAGESTATE(i
)->m_properties
, 0, subProps
);
1455 maxW
+= m_pPropGrid
->m_marginWidth
;
1456 if ( maxW
> highest
)
1461 m_pPropGrid
->SetSplitterPosition( highest
);
1463 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1467 // -----------------------------------------------------------------------
1469 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1472 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1473 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1475 SetDescribedProperty(event
.GetProperty());
1479 // -----------------------------------------------------------------------
1481 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1485 GetClientSize(&width
,&height
);
1487 if ( m_width
== -12345 )
1490 RecalculatePositions(width
,height
);
1493 // -----------------------------------------------------------------------
1495 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1497 // Correct cursor. This is required atleast for wxGTK, for which
1498 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1499 SetCursor( wxNullCursor
);
1503 // -----------------------------------------------------------------------
1505 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1507 if ( !m_pTxtHelpCaption
)
1512 if ( m_dragStatus
> 0 )
1514 int sy
= y
- m_dragOffset
;
1516 // Calculate drag limits
1517 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1518 int top_limit
= m_pPropGrid
->m_lineHeight
;
1520 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1523 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1526 int change
= sy
- m_splitterY
;
1531 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1532 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1534 m_extraHeight
-= change
;
1535 InvalidateBestSize();
1543 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1545 SetCursor ( m_cursorSizeNS
);
1552 SetCursor ( wxNullCursor
);
1559 // -----------------------------------------------------------------------
1561 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1565 // Click on splitter.
1566 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1568 if ( m_dragStatus
== 0 )
1571 // Begin draggin the splitter
1578 m_dragOffset
= y
- m_splitterY
;
1584 // -----------------------------------------------------------------------
1586 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1588 // No event type check - basicly calling this method should
1589 // just stop dragging.
1591 if ( m_dragStatus
>= 1 )
1594 // End Splitter Dragging
1599 // DO NOT ENABLE FOLLOWING LINE!
1600 // (it is only here as a reminder to not to do it)
1603 // This is necessary to return cursor
1606 // Set back the default cursor, if necessary
1607 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1609 SetCursor ( wxNullCursor
);
1616 // -----------------------------------------------------------------------
1618 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1620 wxASSERT_MSG( GetPageCount(),
1621 wxT("SetSplitterPosition() has no effect until pages have been added") );
1624 for ( i
=0; i
<GetPageCount(); i
++ )
1626 wxPropertyGridPage
* page
= GetPage(i
);
1627 page
->DoSetSplitterPositionThisPage( pos
, splitterColumn
);
1630 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1633 // -----------------------------------------------------------------------
1634 // wxPGVIterator_Manager
1635 // -----------------------------------------------------------------------
1637 // Default returned by wxPropertyGridInterface::CreateVIterator().
1638 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1641 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1642 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1644 m_it
.Init(manager
->GetPage(0), flags
);
1646 virtual ~wxPGVIteratorBase_Manager() { }
1655 if ( m_curPage
< m_manager
->GetPageCount() )
1656 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1660 wxPropertyGridManager
* m_manager
;
1662 unsigned int m_curPage
;
1665 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1667 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1670 #endif // wxUSE_PROPGRID