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
, int splitterColumn
, bool allPages
)
212 if ( allPages
&& m_manager
->GetPageCount() )
213 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
215 DoSetSplitterPositionThisPage( pos
, splitterColumn
);
218 // -----------------------------------------------------------------------
219 // wxPropertyGridManager
220 // -----------------------------------------------------------------------
222 // Final default splitter y is client height minus this.
223 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
225 // -----------------------------------------------------------------------
227 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
229 #define ID_ADVTOOLBAR_OFFSET 1
230 #define ID_ADVHELPCAPTION_OFFSET 2
231 #define ID_ADVHELPCONTENT_OFFSET 3
232 #define ID_ADVBUTTON_OFFSET 4
233 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
235 // -----------------------------------------------------------------------
237 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
238 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
239 EVT_SIZE(wxPropertyGridManager::OnResize
)
240 EVT_PAINT(wxPropertyGridManager::OnPaint
)
241 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
242 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
243 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
244 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
247 // -----------------------------------------------------------------------
249 wxPropertyGridManager::wxPropertyGridManager()
255 // -----------------------------------------------------------------------
257 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
262 const wxString
& name
)
266 Create(parent
,id
,pos
,size
,style
,name
);
269 // -----------------------------------------------------------------------
271 bool wxPropertyGridManager::Create( wxWindow
*parent
,
276 const wxString
& name
)
279 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
280 (style
&0xFFFF0000)|wxWANTS_CHARS
,
287 // -----------------------------------------------------------------------
290 // Initialize values to defaults
292 void wxPropertyGridManager::Init1()
295 //m_pPropGrid = (wxPropertyGrid*) NULL;
296 m_pPropGrid
= CreatePropertyGrid();
299 m_pToolbar
= (wxToolBar
*) NULL
;
301 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
302 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
304 m_emptyPage
= (wxPropertyGridPage
*) NULL
;
308 m_width
= m_height
= 0;
310 m_splitterHeight
= 5;
312 m_splitterY
= -1; // -1 causes default to be set.
314 m_nextDescBoxSize
= -1;
322 // -----------------------------------------------------------------------
324 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
326 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
327 wxNO_FULL_REPAINT_ON_RESIZE| \
330 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
331 wxNO_FULL_REPAINT_ON_RESIZE| \
335 // Which flags can be passed to underlying wxPropertyGrid.
336 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
339 // Initialize after parent etc. set
341 void wxPropertyGridManager::Init2( int style
)
344 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
347 m_windowStyle
|= (style
&0x0000FFFF);
349 wxSize csz
= GetClientSize();
351 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
353 // Prepare the first page
354 // NB: But just prepare - you still need to call Add/InsertPage
355 // to actually add properties on it.
356 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
357 pd
->m_isDefault
= true;
358 pd
->m_manager
= this;
359 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
360 state
->m_pPropGrid
= m_pPropGrid
;
361 m_arrPages
.push_back( pd
);
362 m_pPropGrid
->m_pState
= state
;
364 wxWindowID baseId
= GetId();
365 wxWindowID useId
= baseId
;
367 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
372 // Smaller controls on Mac
373 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
376 // Create propertygrid.
377 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
378 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
379 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
381 m_pPropGrid
->m_eventObject
= this;
383 m_pPropGrid
->SetId(useId
);
385 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
387 m_pState
= m_pPropGrid
->m_pState
;
389 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
391 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
394 // Connect to property grid onselect event.
395 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
396 // (see wxPropertyGridManager::ProcessEvent).
397 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
399 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
401 // Connect to toolbar button events.
402 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
403 wxEVT_COMMAND_TOOL_CLICKED
,
404 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
406 // Optional initial controls.
409 m_iFlags
|= wxPG_FL_INITIALIZED
;
413 // -----------------------------------------------------------------------
415 wxPropertyGridManager::~wxPropertyGridManager()
419 m_pPropGrid
->DoSelectProperty(NULL
);
420 m_pPropGrid
->m_pState
= NULL
;
423 for ( i
=0; i
<m_arrPages
.size(); i
++ )
425 delete m_arrPages
[i
];
431 // -----------------------------------------------------------------------
433 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
435 return new wxPropertyGrid();
438 // -----------------------------------------------------------------------
440 void wxPropertyGridManager::SetId( wxWindowID winid
)
442 wxWindow::SetId(winid
);
444 // TODO: Reconnect propgrid event handler(s).
446 m_pPropGrid
->SetId(winid
);
449 // -----------------------------------------------------------------------
451 wxSize
wxPropertyGridManager::DoGetBestSize() const
453 return wxSize(60,150);
456 // -----------------------------------------------------------------------
458 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
460 bool res
= wxWindow::SetFont(font
);
461 m_pPropGrid
->SetFont(font
);
463 // TODO: Need to do caption recacalculations for other pages as well.
465 for ( i
=0; i
<m_arrPages
.size(); i
++ )
467 wxPropertyGridPage
* page
= GetPage(i
);
469 if ( page
!= m_pPropGrid
->GetState() )
470 page
->CalculateFontAndBitmapStuff(-1);
476 // -----------------------------------------------------------------------
478 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
480 wxWindow::SetExtraStyle( exStyle
);
481 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
483 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
488 // -----------------------------------------------------------------------
490 void wxPropertyGridManager::Freeze()
492 m_pPropGrid
->Freeze();
496 // -----------------------------------------------------------------------
498 void wxPropertyGridManager::Thaw()
504 // -----------------------------------------------------------------------
506 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
508 int oldWindowStyle
= GetWindowStyleFlag();
510 wxWindow::SetWindowStyleFlag( style
);
511 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
512 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
514 // Need to re-position windows?
515 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
516 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
522 // -----------------------------------------------------------------------
524 // Actually shows given page.
525 bool wxPropertyGridManager::DoSelectPage( int index
)
527 // -1 means no page was selected
528 //wxASSERT( m_selPage >= 0 );
530 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
532 wxT("invalid page index") );
534 if ( m_selPage
== index
)
537 if ( m_pPropGrid
->m_selected
)
539 if ( !m_pPropGrid
->ClearSelection() )
543 wxPropertyGridPage
* prevPage
;
545 if ( m_selPage
>= 0 )
546 prevPage
= GetPage(m_selPage
);
548 prevPage
= m_emptyPage
;
550 wxPropertyGridPage
* nextPage
;
554 nextPage
= m_arrPages
[index
];
562 m_emptyPage
= new wxPropertyGridPage();
563 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
566 nextPage
= m_emptyPage
;
569 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
571 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
573 m_pState
= m_pPropGrid
->m_pState
;
581 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
583 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
590 // -----------------------------------------------------------------------
592 // Changes page *and* set the target page for insertion operations.
593 void wxPropertyGridManager::SelectPage( int index
)
598 // -----------------------------------------------------------------------
600 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
603 for ( i
=0; i
<GetPageCount(); i
++ )
605 if ( m_arrPages
[i
]->m_label
== name
)
611 // -----------------------------------------------------------------------
613 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
618 for ( i
=0; i
<GetPageCount(); i
++ )
620 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
627 // -----------------------------------------------------------------------
629 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
631 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
632 return m_arrPages
[index
]->m_label
;
635 // -----------------------------------------------------------------------
637 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
639 // Do not change this into wxCHECK because returning NULL is important
640 // for wxPropertyGridInterface page enumeration mechanics.
641 if ( page
>= (int)GetPageCount() )
646 return m_arrPages
[page
];
649 // -----------------------------------------------------------------------
651 void wxPropertyGridManager::Clear()
653 m_pPropGrid
->Freeze();
656 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
660 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
665 // -----------------------------------------------------------------------
667 void wxPropertyGridManager::ClearPage( int page
)
669 wxASSERT( page
>= 0 );
670 wxASSERT( page
< (int)GetPageCount() );
672 if ( page
>= 0 && page
< (int)GetPageCount() )
674 wxPropertyGridPageState
* state
= m_arrPages
[page
];
676 if ( state
== m_pPropGrid
->GetState() )
677 m_pPropGrid
->Clear();
683 // -----------------------------------------------------------------------
685 int wxPropertyGridManager::GetColumnCount( int page
) const
687 wxASSERT( page
>= -1 );
688 wxASSERT( page
< (int)GetPageCount() );
690 return GetPageState(page
)->GetColumnCount();
693 // -----------------------------------------------------------------------
695 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
697 wxASSERT( page
>= -1 );
698 wxASSERT( page
< (int)GetPageCount() );
700 GetPageState(page
)->SetColumnCount( colCount
);
701 GetGrid()->Refresh();
703 // -----------------------------------------------------------------------
705 size_t wxPropertyGridManager::GetPageCount() const
707 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
710 return m_arrPages
.size();
713 // -----------------------------------------------------------------------
715 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
716 const wxString
& label
,
718 wxPropertyGridPage
* pageObj
)
721 index
= GetPageCount();
723 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
724 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
726 bool needInit
= true;
727 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
729 wxASSERT( index
== 0 || isPageInserted
);
733 // No custom page object was given, so we will either re-use the default base
734 // page (if index==0), or create a new default page object.
735 if ( !isPageInserted
)
737 pageObj
= GetPage(0);
738 // Of course, if the base page was custom, we need to delete and
740 if ( !pageObj
->m_isDefault
)
743 pageObj
= new wxPropertyGridPage();
744 m_arrPages
[0] = pageObj
;
750 pageObj
= new wxPropertyGridPage();
752 pageObj
->m_isDefault
= true;
756 if ( !isPageInserted
)
758 // Initial page needs to be deleted and replaced
760 m_arrPages
[0] = pageObj
;
761 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
765 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
767 pageObj
->m_manager
= this;
771 state
->m_pPropGrid
= m_pPropGrid
;
772 state
->InitNonCatMode();
775 if ( label
.length() )
777 wxASSERT_MSG( !pageObj
->m_label
.length(),
778 wxT("If page label is given in constructor, empty label must be given in AddPage"));
779 pageObj
->m_label
= label
;
782 pageObj
->m_id
= m_nextTbInd
;
784 if ( isPageInserted
)
785 m_arrPages
.push_back( pageObj
);
788 if ( m_windowStyle
& wxPG_TOOLBAR
)
793 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
795 wxASSERT( m_pToolbar
);
797 // Add separator before first page.
798 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
799 m_pToolbar
->GetToolsCount() < 3 )
800 m_pToolbar
->AddSeparator();
802 if ( &bmp
!= &wxNullBitmap
)
803 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
804 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
806 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
811 m_pToolbar
->Realize();
818 // If selected page was above the point of insertion, fix the current page index
819 if ( isPageInserted
)
821 if ( m_selPage
>= index
)
828 // Set this value only when adding the first page
834 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
836 wxASSERT( pageObj
->GetGrid() );
841 // -----------------------------------------------------------------------
843 bool wxPropertyGridManager::IsAnyModified() const
846 for ( i
=0; i
<GetPageCount(); i
++ )
848 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
854 // -----------------------------------------------------------------------
856 bool wxPropertyGridManager::IsPageModified( size_t index
) const
858 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
863 // -----------------------------------------------------------------------
865 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
867 wxASSERT( index
>= 0 );
868 wxASSERT( index
< (int)m_arrPages
.size() );
870 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
873 // -----------------------------------------------------------------------
875 bool wxPropertyGridManager::RemovePage( int page
)
877 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
879 wxT("invalid page index") );
881 wxPropertyGridPage
* pd
= m_arrPages
[page
];
883 if ( m_arrPages
.size() == 1 )
885 // Last page: do not remove page entry
886 m_pPropGrid
->Clear();
888 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
892 // Change selection if current is page
893 else if ( page
== m_selPage
)
895 if ( !m_pPropGrid
->ClearSelection() )
898 // Substitute page to select
899 int substitute
= page
- 1;
900 if ( substitute
< 0 )
901 substitute
= page
+ 1;
903 SelectPage(substitute
);
906 // Remove toolbar icon
908 if ( HasFlag(wxPG_TOOLBAR
) )
910 wxASSERT( m_pToolbar
);
912 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
915 // Delete separator as well, for consistency
916 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
917 GetPageCount() == 1 )
918 m_pToolbar
->DeleteToolByPos(2);
920 m_pToolbar
->DeleteToolByPos(toolPos
);
924 if ( m_arrPages
.size() > 1 )
926 m_arrPages
.erase(m_arrPages
.begin() + page
);
930 // Adjust indexes that were above removed
931 if ( m_selPage
> page
)
937 // -----------------------------------------------------------------------
939 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
941 int evtType
= event
.GetEventType();
943 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
944 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
945 // don't really matter.
946 if ( evtType
== wxEVT_PG_SELECTED
)
947 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
949 // Property grid events get special attention
950 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
951 evtType
< (wxPG_MAX_EVT_TYPE
) &&
954 wxPropertyGridPage
* page
= GetPage(m_selPage
);
955 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
957 // Add property grid events to appropriate custom pages
958 // but stop propagating to parent if page says it is
959 // handling everything.
960 if ( pgEvent
&& !page
->m_isDefault
)
962 /*if ( pgEvent->IsPending() )
963 page->AddPendingEvent(event);
965 page
->ProcessEvent(event
);
967 if ( page
->IsHandlingAllEvents() )
968 event
.StopPropagation();
972 return wxPanel::ProcessEvent(event
);
975 // -----------------------------------------------------------------------
977 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
978 int new_height
, bool desc_too
)
980 int use_hei
= new_height
;
983 wxColour bgcol
= GetBackgroundColour();
984 dc
.SetBrush( bgcol
);
986 int rect_hei
= use_hei
-new_splittery
;
988 rect_hei
= m_splitterHeight
;
989 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
990 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
991 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
992 int box_height
= use_hei
-splitter_bottom
;
993 if ( box_height
> 1 )
994 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
996 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
999 // -----------------------------------------------------------------------
1001 void wxPropertyGridManager::RefreshHelpBox( int new_splittery
, int new_width
, int new_height
)
1003 //if ( new_splittery == m_splitterY && new_width == m_width )
1006 int use_hei
= new_height
;
1009 //wxRendererNative::Get().DrawSplitterSash(this,dc,
1010 //wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
1012 //wxRendererNative::Get().DrawSplitterBorder(this,dc,
1013 // wxRect(0,new_splittery,new_width,m_splitterHeight));
1015 // Fix help control positions.
1016 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1017 int cap_y
= new_splittery
+m_splitterHeight
+5;
1018 int cnt_y
= cap_y
+cap_hei
+3;
1019 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1020 int cnt_hei
= use_hei
-cnt_y
;
1021 if ( sub_cap_hei
> 0 )
1023 cap_hei
-= sub_cap_hei
;
1028 m_pTxtHelpCaption
->Show( false );
1029 m_pTxtHelpContent
->Show( false );
1033 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1034 m_pTxtHelpCaption
->Wrap(-1);
1035 m_pTxtHelpCaption
->Show( true );
1038 m_pTxtHelpContent
->Show( false );
1042 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1043 m_pTxtHelpContent
->Show( true );
1047 wxClientDC
dc(this);
1048 RepaintSplitter( dc
, new_splittery
, new_width
, new_height
, true );
1050 m_splitterY
= new_splittery
;
1052 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1055 // -----------------------------------------------------------------------
1057 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1060 int propgridBottomY
= height
;
1062 // Toolbar at the top.
1068 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1071 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1072 #if defined(__WXMSW__)
1074 #elif defined(__WXGTK__)
1075 tbHeight
= -1; // 22;
1076 #elif defined(__WXMAC__)
1083 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1084 propgridY
+= m_pToolbar
->GetSize().y
;
1089 if ( m_pTxtHelpCaption
)
1091 int new_splittery
= m_splitterY
;
1094 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1096 if ( m_nextDescBoxSize
>= 0 )
1098 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1099 m_nextDescBoxSize
= -1;
1101 new_splittery
+= (height
-m_height
);
1105 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1106 if ( new_splittery
< 32 )
1110 // Check if beyond minimum.
1111 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1112 if ( new_splittery
< nspy_min
)
1113 new_splittery
= nspy_min
;
1115 propgridBottomY
= new_splittery
;
1117 RefreshHelpBox( new_splittery
, width
, height
);
1120 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1122 int pgh
= propgridBottomY
- propgridY
;
1123 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1125 m_extraHeight
= height
- pgh
;
1132 // -----------------------------------------------------------------------
1134 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1136 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1138 if ( ht
!= GetDescBoxHeight() )
1140 m_nextDescBoxSize
= ht
;
1142 RecalculatePositions(m_width
, m_height
);
1147 // -----------------------------------------------------------------------
1149 int wxPropertyGridManager::GetDescBoxHeight() const
1151 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1154 // -----------------------------------------------------------------------
1156 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1160 // Update everything inside the box
1161 wxRect r
= GetUpdateRegion().GetBox();
1163 // Repaint splitter?
1164 int r_bottom
= r
.y
+ r
.height
;
1165 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1166 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1167 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1170 // -----------------------------------------------------------------------
1172 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1174 m_pPropGrid
->Refresh(eraseBackground
);
1175 wxWindow::Refresh(eraseBackground
,rect
);
1178 // -----------------------------------------------------------------------
1180 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1182 wxPropertyGrid
* grid
= p
->GetGrid();
1184 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1185 grid
->RefreshProperty(p
);
1188 // -----------------------------------------------------------------------
1190 void wxPropertyGridManager::RecreateControls()
1193 bool was_shown
= IsShown();
1197 wxWindowID baseId
= m_pPropGrid
->GetId();
1199 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1202 if ( m_windowStyle
& wxPG_TOOLBAR
)
1207 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1208 wxDefaultPosition
,wxDefaultSize
,
1209 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1210 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1212 #if defined(__WXMSW__)
1213 // Eliminate toolbar flicker on XP
1214 // NOTE: Not enabled since it corrupts drawing somewhat.
1217 #ifndef WS_EX_COMPOSITED
1218 #define WS_EX_COMPOSITED 0x02000000L
1221 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1223 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1224 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1229 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1231 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1233 wxString
desc1(_("Categorized Mode"));
1234 wxString
desc2(_("Alphabetic Mode"));
1235 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1236 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1237 desc1
,wxITEM_RADIO
);
1238 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1239 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1240 desc2
,wxITEM_RADIO
);
1241 m_pToolbar
->Realize();
1246 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1248 // Toggle correct mode button.
1249 // TODO: This doesn't work in wxMSW (when changing,
1250 // both items will get toggled).
1251 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1252 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1253 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1255 toggle_but_on_ind
++;
1256 toggle_but_off_ind
--;
1259 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1260 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1268 m_pToolbar
->Destroy();
1269 m_pToolbar
= (wxToolBar
*) NULL
;
1273 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1276 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1278 if ( !m_pTxtHelpCaption
)
1280 m_pTxtHelpCaption
= new wxStaticText (this,baseId
+ID_ADVHELPCAPTION_OFFSET
,wxEmptyString
);
1281 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1282 m_pTxtHelpCaption
->SetCursor ( *wxSTANDARD_CURSOR
);
1284 if ( !m_pTxtHelpContent
)
1286 m_pTxtHelpContent
= new wxStaticText (this,baseId
+ID_ADVHELPCONTENT_OFFSET
,
1287 wxEmptyString
,wxDefaultPosition
,wxDefaultSize
,wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1288 m_pTxtHelpContent
->SetCursor ( *wxSTANDARD_CURSOR
);
1291 SetDescribedProperty(GetSelection());
1296 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1298 if ( m_pTxtHelpCaption
)
1299 m_pTxtHelpCaption
->Destroy();
1301 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
1303 if ( m_pTxtHelpContent
)
1304 m_pTxtHelpContent
->Destroy();
1306 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
1311 GetClientSize(&width
,&height
);
1313 RecalculatePositions(width
,height
);
1319 // -----------------------------------------------------------------------
1321 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1324 for ( i
=0; i
<GetPageCount(); i
++ )
1326 wxPropertyGridPageState
* pState
= m_arrPages
[i
]->GetStatePtr();
1327 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1336 // -----------------------------------------------------------------------
1338 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1340 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1342 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1344 // Select correct page.
1345 if ( m_pPropGrid
->m_pState
!= parentState
)
1346 DoSelectPage( GetPageByState(parentState
) );
1348 return m_pPropGrid
->EnsureVisible(id
);
1351 // -----------------------------------------------------------------------
1353 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1355 int id
= event
.GetId();
1358 int baseId
= m_pPropGrid
->GetId();
1360 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1362 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1364 // Categorized mode.
1365 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1367 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1368 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1369 m_pPropGrid
->EnableCategories( true );
1372 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1375 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1377 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1378 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1380 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1382 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1383 m_pPropGrid
->EnableCategories( false );
1392 wxPropertyGridPage
* pdc
;
1394 // Find page with given id.
1395 for ( i
=0; i
<GetPageCount(); i
++ )
1397 pdc
= m_arrPages
[i
];
1398 if ( pdc
->m_id
== id
)
1405 wxASSERT( index
>= 0 );
1407 if ( DoSelectPage( index
) )
1410 // Event dispatching must be last.
1411 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, (wxPGProperty
*) NULL
);
1416 // TODO: Depress the old button on toolbar.
1423 // -----------------------------------------------------------------------
1425 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1427 if ( name
== wxS("descboxheight") )
1429 SetDescBoxHeight(value
.GetLong(), true);
1435 // -----------------------------------------------------------------------
1437 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1439 if ( name
== wxS("descboxheight") )
1441 return (long) GetDescBoxHeight();
1443 return wxNullVariant
;
1446 // -----------------------------------------------------------------------
1448 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1450 if ( m_pTxtHelpCaption
)
1452 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1453 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1455 m_pTxtHelpCaption
->SetLabel(label
);
1456 m_pTxtHelpContent
->SetLabel(content
);
1458 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1459 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1461 if ( (m_iFlags
& wxPG_FL_DESC_REFRESH_REQUIRED
) || (osz2
.x
<(m_width
-10)) )
1462 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1466 // -----------------------------------------------------------------------
1468 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1470 if ( m_pTxtHelpCaption
)
1474 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1478 m_pTxtHelpCaption
->SetLabel(wxEmptyString
);
1479 m_pTxtHelpContent
->SetLabel(wxEmptyString
);
1484 // -----------------------------------------------------------------------
1486 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1490 m_pPropGrid
->SetSplitterLeft(subProps
);
1494 wxClientDC
dc(this);
1495 dc
.SetFont(m_pPropGrid
->m_font
);
1500 for ( i
=0; i
<GetPageCount(); i
++ )
1502 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1503 maxW
+= m_pPropGrid
->m_marginWidth
;
1504 if ( maxW
> highest
)
1509 m_pPropGrid
->SetSplitterPosition( highest
);
1511 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1515 // -----------------------------------------------------------------------
1517 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1520 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1521 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1523 SetDescribedProperty(event
.GetProperty());
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1533 GetClientSize(&width
,&height
);
1535 if ( m_width
== -12345 )
1538 RecalculatePositions(width
,height
);
1541 // -----------------------------------------------------------------------
1543 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1545 // Correct cursor. This is required atleast for wxGTK, for which
1546 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1547 SetCursor( wxNullCursor
);
1551 // -----------------------------------------------------------------------
1553 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1555 if ( !m_pTxtHelpCaption
)
1560 if ( m_dragStatus
> 0 )
1562 int sy
= y
- m_dragOffset
;
1564 // Calculate drag limits
1565 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1566 int top_limit
= m_pPropGrid
->m_lineHeight
;
1568 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1571 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1574 int change
= sy
- m_splitterY
;
1579 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1580 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1582 m_extraHeight
-= change
;
1583 InvalidateBestSize();
1591 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1593 SetCursor ( m_cursorSizeNS
);
1600 SetCursor ( wxNullCursor
);
1607 // -----------------------------------------------------------------------
1609 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1613 // Click on splitter.
1614 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1616 if ( m_dragStatus
== 0 )
1619 // Begin draggin the splitter
1626 m_dragOffset
= y
- m_splitterY
;
1632 // -----------------------------------------------------------------------
1634 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1636 // No event type check - basicly calling this method should
1637 // just stop dragging.
1639 if ( m_dragStatus
>= 1 )
1642 // End Splitter Dragging
1647 // DO NOT ENABLE FOLLOWING LINE!
1648 // (it is only here as a reminder to not to do it)
1651 // This is necessary to return cursor
1654 // Set back the default cursor, if necessary
1655 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1657 SetCursor ( wxNullCursor
);
1664 // -----------------------------------------------------------------------
1666 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1668 wxASSERT_MSG( GetPageCount(),
1669 wxT("SetSplitterPosition() has no effect until pages have been added") );
1672 for ( i
=0; i
<GetPageCount(); i
++ )
1674 wxPropertyGridPage
* page
= GetPage(i
);
1675 page
->DoSetSplitterPositionThisPage( pos
, splitterColumn
);
1678 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1681 // -----------------------------------------------------------------------
1682 // wxPGVIterator_Manager
1683 // -----------------------------------------------------------------------
1685 // Default returned by wxPropertyGridInterface::CreateVIterator().
1686 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1689 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1690 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1692 m_it
.Init(manager
->GetPage(0), flags
);
1694 virtual ~wxPGVIteratorBase_Manager() { }
1703 if ( m_curPage
< m_manager
->GetPageCount() )
1704 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1708 wxPropertyGridManager
* m_manager
;
1710 unsigned int m_curPage
;
1713 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1715 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1718 #endif // wxUSE_PROPGRID