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 WXUNUSED(fromAutoCenter
) )
215 if ( allPages
&& m_manager
->GetPageCount() )
216 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
218 DoSetSplitterPositionThisPage( pos
, splitterColumn
);
221 // -----------------------------------------------------------------------
222 // wxPropertyGridManager
223 // -----------------------------------------------------------------------
225 // Final default splitter y is client height minus this.
226 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
228 // -----------------------------------------------------------------------
230 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
232 #define ID_ADVTOOLBAR_OFFSET 1
233 #define ID_ADVHELPCAPTION_OFFSET 2
234 #define ID_ADVHELPCONTENT_OFFSET 3
235 #define ID_ADVBUTTON_OFFSET 4
236 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
238 // -----------------------------------------------------------------------
240 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
241 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
242 EVT_SIZE(wxPropertyGridManager::OnResize
)
243 EVT_PAINT(wxPropertyGridManager::OnPaint
)
244 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
245 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
246 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
247 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
250 // -----------------------------------------------------------------------
252 wxPropertyGridManager::wxPropertyGridManager()
258 // -----------------------------------------------------------------------
260 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
265 const wxString
& name
)
269 Create(parent
,id
,pos
,size
,style
,name
);
272 // -----------------------------------------------------------------------
274 bool wxPropertyGridManager::Create( wxWindow
*parent
,
279 const wxString
& name
)
282 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
283 (style
&0xFFFF0000)|wxWANTS_CHARS
,
290 // -----------------------------------------------------------------------
293 // Initialize values to defaults
295 void wxPropertyGridManager::Init1()
298 //m_pPropGrid = (wxPropertyGrid*) NULL;
299 m_pPropGrid
= CreatePropertyGrid();
302 m_pToolbar
= (wxToolBar
*) NULL
;
304 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
305 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
307 m_emptyPage
= (wxPropertyGridPage
*) NULL
;
311 m_width
= m_height
= 0;
313 m_splitterHeight
= 5;
315 m_splitterY
= -1; // -1 causes default to be set.
317 m_nextDescBoxSize
= -1;
325 // -----------------------------------------------------------------------
327 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
329 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
330 wxNO_FULL_REPAINT_ON_RESIZE| \
333 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
334 wxNO_FULL_REPAINT_ON_RESIZE| \
338 // Which flags can be passed to underlying wxPropertyGrid.
339 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
342 // Initialize after parent etc. set
344 void wxPropertyGridManager::Init2( int style
)
347 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
350 m_windowStyle
|= (style
&0x0000FFFF);
352 wxSize csz
= GetClientSize();
354 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
356 // Prepare the first page
357 // NB: But just prepare - you still need to call Add/InsertPage
358 // to actually add properties on it.
359 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
360 pd
->m_isDefault
= true;
361 pd
->m_manager
= this;
362 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
363 state
->m_pPropGrid
= m_pPropGrid
;
364 m_arrPages
.push_back( pd
);
365 m_pPropGrid
->m_pState
= state
;
367 wxWindowID baseId
= GetId();
368 wxWindowID useId
= baseId
;
370 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
375 // Smaller controls on Mac
376 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
379 // Create propertygrid.
380 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
381 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
382 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
384 m_pPropGrid
->m_eventObject
= this;
386 m_pPropGrid
->SetId(useId
);
388 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
390 m_pState
= m_pPropGrid
->m_pState
;
392 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
394 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
397 // Connect to property grid onselect event.
398 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
399 // (see wxPropertyGridManager::ProcessEvent).
400 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
402 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
404 // Connect to toolbar button events.
405 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
406 wxEVT_COMMAND_TOOL_CLICKED
,
407 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
409 // Optional initial controls.
412 m_iFlags
|= wxPG_FL_INITIALIZED
;
416 // -----------------------------------------------------------------------
418 wxPropertyGridManager::~wxPropertyGridManager()
422 m_pPropGrid
->DoSelectProperty(NULL
);
423 m_pPropGrid
->m_pState
= NULL
;
426 for ( i
=0; i
<m_arrPages
.size(); i
++ )
428 delete m_arrPages
[i
];
434 // -----------------------------------------------------------------------
436 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
438 return new wxPropertyGrid();
441 // -----------------------------------------------------------------------
443 void wxPropertyGridManager::SetId( wxWindowID winid
)
445 wxWindow::SetId(winid
);
447 // TODO: Reconnect propgrid event handler(s).
449 m_pPropGrid
->SetId(winid
);
452 // -----------------------------------------------------------------------
454 wxSize
wxPropertyGridManager::DoGetBestSize() const
456 return wxSize(60,150);
459 // -----------------------------------------------------------------------
461 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
463 bool res
= wxWindow::SetFont(font
);
464 m_pPropGrid
->SetFont(font
);
466 // TODO: Need to do caption recacalculations for other pages as well.
468 for ( i
=0; i
<m_arrPages
.size(); i
++ )
470 wxPropertyGridPage
* page
= GetPage(i
);
472 if ( page
!= m_pPropGrid
->GetState() )
473 page
->CalculateFontAndBitmapStuff(-1);
479 // -----------------------------------------------------------------------
481 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
483 wxWindow::SetExtraStyle( exStyle
);
484 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
486 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
491 // -----------------------------------------------------------------------
493 void wxPropertyGridManager::Freeze()
495 m_pPropGrid
->Freeze();
499 // -----------------------------------------------------------------------
501 void wxPropertyGridManager::Thaw()
507 // -----------------------------------------------------------------------
509 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
511 int oldWindowStyle
= GetWindowStyleFlag();
513 wxWindow::SetWindowStyleFlag( style
);
514 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
515 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
517 // Need to re-position windows?
518 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
519 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
525 // -----------------------------------------------------------------------
527 // Actually shows given page.
528 bool wxPropertyGridManager::DoSelectPage( int index
)
530 // -1 means no page was selected
531 //wxASSERT( m_selPage >= 0 );
533 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
535 wxT("invalid page index") );
537 if ( m_selPage
== index
)
540 if ( m_pPropGrid
->m_selected
)
542 if ( !m_pPropGrid
->ClearSelection() )
546 wxPropertyGridPage
* prevPage
;
548 if ( m_selPage
>= 0 )
549 prevPage
= GetPage(m_selPage
);
551 prevPage
= m_emptyPage
;
553 wxPropertyGridPage
* nextPage
;
557 nextPage
= m_arrPages
[index
];
565 m_emptyPage
= new wxPropertyGridPage();
566 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
569 nextPage
= m_emptyPage
;
572 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
574 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
576 m_pState
= m_pPropGrid
->m_pState
;
584 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
586 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
593 // -----------------------------------------------------------------------
595 // Changes page *and* set the target page for insertion operations.
596 void wxPropertyGridManager::SelectPage( int index
)
601 // -----------------------------------------------------------------------
603 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
606 for ( i
=0; i
<GetPageCount(); i
++ )
608 if ( m_arrPages
[i
]->m_label
== name
)
614 // -----------------------------------------------------------------------
616 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
621 for ( i
=0; i
<GetPageCount(); i
++ )
623 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
630 // -----------------------------------------------------------------------
632 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
634 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
635 return m_arrPages
[index
]->m_label
;
638 // -----------------------------------------------------------------------
640 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
642 // Do not change this into wxCHECK because returning NULL is important
643 // for wxPropertyGridInterface page enumeration mechanics.
644 if ( page
>= (int)GetPageCount() )
649 return m_arrPages
[page
];
652 // -----------------------------------------------------------------------
654 void wxPropertyGridManager::Clear()
656 m_pPropGrid
->Freeze();
659 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
663 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
668 // -----------------------------------------------------------------------
670 void wxPropertyGridManager::ClearPage( int page
)
672 wxASSERT( page
>= 0 );
673 wxASSERT( page
< (int)GetPageCount() );
675 if ( page
>= 0 && page
< (int)GetPageCount() )
677 wxPropertyGridPageState
* state
= m_arrPages
[page
];
679 if ( state
== m_pPropGrid
->GetState() )
680 m_pPropGrid
->Clear();
686 // -----------------------------------------------------------------------
688 int wxPropertyGridManager::GetColumnCount( int page
) const
690 wxASSERT( page
>= -1 );
691 wxASSERT( page
< (int)GetPageCount() );
693 return GetPageState(page
)->GetColumnCount();
696 // -----------------------------------------------------------------------
698 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
700 wxASSERT( page
>= -1 );
701 wxASSERT( page
< (int)GetPageCount() );
703 GetPageState(page
)->SetColumnCount( colCount
);
704 GetGrid()->Refresh();
706 // -----------------------------------------------------------------------
708 size_t wxPropertyGridManager::GetPageCount() const
710 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
713 return m_arrPages
.size();
716 // -----------------------------------------------------------------------
718 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
719 const wxString
& label
,
721 wxPropertyGridPage
* pageObj
)
724 index
= GetPageCount();
726 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
727 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
729 bool needInit
= true;
730 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
732 wxASSERT( index
== 0 || isPageInserted
);
736 // No custom page object was given, so we will either re-use the default base
737 // page (if index==0), or create a new default page object.
738 if ( !isPageInserted
)
740 pageObj
= GetPage(0);
741 // Of course, if the base page was custom, we need to delete and
743 if ( !pageObj
->m_isDefault
)
746 pageObj
= new wxPropertyGridPage();
747 m_arrPages
[0] = pageObj
;
753 pageObj
= new wxPropertyGridPage();
755 pageObj
->m_isDefault
= true;
759 if ( !isPageInserted
)
761 // Initial page needs to be deleted and replaced
763 m_arrPages
[0] = pageObj
;
764 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
768 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
770 pageObj
->m_manager
= this;
774 state
->m_pPropGrid
= m_pPropGrid
;
775 state
->InitNonCatMode();
778 if ( label
.length() )
780 wxASSERT_MSG( !pageObj
->m_label
.length(),
781 wxT("If page label is given in constructor, empty label must be given in AddPage"));
782 pageObj
->m_label
= label
;
785 pageObj
->m_id
= m_nextTbInd
;
787 if ( isPageInserted
)
788 m_arrPages
.push_back( pageObj
);
791 if ( m_windowStyle
& wxPG_TOOLBAR
)
796 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
798 wxASSERT( m_pToolbar
);
800 // Add separator before first page.
801 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
802 m_pToolbar
->GetToolsCount() < 3 )
803 m_pToolbar
->AddSeparator();
805 if ( &bmp
!= &wxNullBitmap
)
806 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
807 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
809 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
814 m_pToolbar
->Realize();
821 // If selected page was above the point of insertion, fix the current page index
822 if ( isPageInserted
)
824 if ( m_selPage
>= index
)
831 // Set this value only when adding the first page
837 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
839 wxASSERT( pageObj
->GetGrid() );
844 // -----------------------------------------------------------------------
846 bool wxPropertyGridManager::IsAnyModified() const
849 for ( i
=0; i
<GetPageCount(); i
++ )
851 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
857 // -----------------------------------------------------------------------
859 bool wxPropertyGridManager::IsPageModified( size_t index
) const
861 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
866 // -----------------------------------------------------------------------
868 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
870 wxASSERT( index
>= 0 );
871 wxASSERT( index
< (int)m_arrPages
.size() );
873 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
876 // -----------------------------------------------------------------------
878 bool wxPropertyGridManager::RemovePage( int page
)
880 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
882 wxT("invalid page index") );
884 wxPropertyGridPage
* pd
= m_arrPages
[page
];
886 if ( m_arrPages
.size() == 1 )
888 // Last page: do not remove page entry
889 m_pPropGrid
->Clear();
891 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
895 // Change selection if current is page
896 else if ( page
== m_selPage
)
898 if ( !m_pPropGrid
->ClearSelection() )
901 // Substitute page to select
902 int substitute
= page
- 1;
903 if ( substitute
< 0 )
904 substitute
= page
+ 1;
906 SelectPage(substitute
);
909 // Remove toolbar icon
911 if ( HasFlag(wxPG_TOOLBAR
) )
913 wxASSERT( m_pToolbar
);
915 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
918 // Delete separator as well, for consistency
919 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
920 GetPageCount() == 1 )
921 m_pToolbar
->DeleteToolByPos(2);
923 m_pToolbar
->DeleteToolByPos(toolPos
);
927 if ( m_arrPages
.size() > 1 )
929 m_arrPages
.erase(m_arrPages
.begin() + page
);
933 // Adjust indexes that were above removed
934 if ( m_selPage
> page
)
940 // -----------------------------------------------------------------------
942 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
944 int evtType
= event
.GetEventType();
946 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
947 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
948 // don't really matter.
949 if ( evtType
== wxEVT_PG_SELECTED
)
950 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
952 // Property grid events get special attention
953 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
954 evtType
< (wxPG_MAX_EVT_TYPE
) &&
957 wxPropertyGridPage
* page
= GetPage(m_selPage
);
958 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
960 // Add property grid events to appropriate custom pages
961 // but stop propagating to parent if page says it is
962 // handling everything.
963 if ( pgEvent
&& !page
->m_isDefault
)
965 /*if ( pgEvent->IsPending() )
966 page->AddPendingEvent(event);
968 page
->ProcessEvent(event
);
970 if ( page
->IsHandlingAllEvents() )
971 event
.StopPropagation();
975 return wxPanel::ProcessEvent(event
);
978 // -----------------------------------------------------------------------
980 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
981 int new_height
, bool desc_too
)
983 int use_hei
= new_height
;
986 wxColour bgcol
= GetBackgroundColour();
987 dc
.SetBrush( bgcol
);
989 int rect_hei
= use_hei
-new_splittery
;
991 rect_hei
= m_splitterHeight
;
992 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
993 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
994 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
995 int box_height
= use_hei
-splitter_bottom
;
996 if ( box_height
> 1 )
997 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
999 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
1002 // -----------------------------------------------------------------------
1004 void wxPropertyGridManager::RefreshHelpBox( int new_splittery
, int new_width
, int new_height
)
1006 //if ( new_splittery == m_splitterY && new_width == m_width )
1009 int use_hei
= new_height
;
1012 //wxRendererNative::Get().DrawSplitterSash(this,dc,
1013 //wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
1015 //wxRendererNative::Get().DrawSplitterBorder(this,dc,
1016 // wxRect(0,new_splittery,new_width,m_splitterHeight));
1018 // Fix help control positions.
1019 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1020 int cap_y
= new_splittery
+m_splitterHeight
+5;
1021 int cnt_y
= cap_y
+cap_hei
+3;
1022 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1023 int cnt_hei
= use_hei
-cnt_y
;
1024 if ( sub_cap_hei
> 0 )
1026 cap_hei
-= sub_cap_hei
;
1031 m_pTxtHelpCaption
->Show( false );
1032 m_pTxtHelpContent
->Show( false );
1036 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1037 m_pTxtHelpCaption
->Wrap(-1);
1038 m_pTxtHelpCaption
->Show( true );
1041 m_pTxtHelpContent
->Show( false );
1045 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1046 m_pTxtHelpContent
->Show( true );
1050 wxClientDC
dc(this);
1051 RepaintSplitter( dc
, new_splittery
, new_width
, new_height
, true );
1053 m_splitterY
= new_splittery
;
1055 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1058 // -----------------------------------------------------------------------
1060 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1063 int propgridBottomY
= height
;
1065 // Toolbar at the top.
1071 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1074 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1075 #if defined(__WXMSW__)
1077 #elif defined(__WXGTK__)
1078 tbHeight
= -1; // 22;
1079 #elif defined(__WXMAC__)
1086 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1087 propgridY
+= m_pToolbar
->GetSize().y
;
1092 if ( m_pTxtHelpCaption
)
1094 int new_splittery
= m_splitterY
;
1097 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1099 if ( m_nextDescBoxSize
>= 0 )
1101 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1102 m_nextDescBoxSize
= -1;
1104 new_splittery
+= (height
-m_height
);
1108 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1109 if ( new_splittery
< 32 )
1113 // Check if beyond minimum.
1114 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1115 if ( new_splittery
< nspy_min
)
1116 new_splittery
= nspy_min
;
1118 propgridBottomY
= new_splittery
;
1120 RefreshHelpBox( new_splittery
, width
, height
);
1123 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1125 int pgh
= propgridBottomY
- propgridY
;
1126 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1128 m_extraHeight
= height
- pgh
;
1135 // -----------------------------------------------------------------------
1137 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1139 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1141 if ( ht
!= GetDescBoxHeight() )
1143 m_nextDescBoxSize
= ht
;
1145 RecalculatePositions(m_width
, m_height
);
1150 // -----------------------------------------------------------------------
1152 int wxPropertyGridManager::GetDescBoxHeight() const
1154 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1157 // -----------------------------------------------------------------------
1159 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1163 // Update everything inside the box
1164 wxRect r
= GetUpdateRegion().GetBox();
1166 // Repaint splitter?
1167 int r_bottom
= r
.y
+ r
.height
;
1168 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1169 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1170 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1173 // -----------------------------------------------------------------------
1175 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1177 m_pPropGrid
->Refresh(eraseBackground
);
1178 wxWindow::Refresh(eraseBackground
,rect
);
1181 // -----------------------------------------------------------------------
1183 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1185 wxPropertyGrid
* grid
= p
->GetGrid();
1187 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1188 grid
->RefreshProperty(p
);
1191 // -----------------------------------------------------------------------
1193 void wxPropertyGridManager::RecreateControls()
1196 bool was_shown
= IsShown();
1200 wxWindowID baseId
= m_pPropGrid
->GetId();
1202 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1205 if ( m_windowStyle
& wxPG_TOOLBAR
)
1210 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1211 wxDefaultPosition
,wxDefaultSize
,
1212 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1213 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1215 #if defined(__WXMSW__)
1216 // Eliminate toolbar flicker on XP
1217 // NOTE: Not enabled since it corrupts drawing somewhat.
1220 #ifndef WS_EX_COMPOSITED
1221 #define WS_EX_COMPOSITED 0x02000000L
1224 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1226 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1227 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1232 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1234 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1236 wxString
desc1(_("Categorized Mode"));
1237 wxString
desc2(_("Alphabetic Mode"));
1238 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1239 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1240 desc1
,wxITEM_RADIO
);
1241 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1242 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1243 desc2
,wxITEM_RADIO
);
1244 m_pToolbar
->Realize();
1249 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1251 // Toggle correct mode button.
1252 // TODO: This doesn't work in wxMSW (when changing,
1253 // both items will get toggled).
1254 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1255 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1256 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1258 toggle_but_on_ind
++;
1259 toggle_but_off_ind
--;
1262 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1263 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1271 m_pToolbar
->Destroy();
1272 m_pToolbar
= (wxToolBar
*) NULL
;
1276 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1279 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1281 if ( !m_pTxtHelpCaption
)
1283 m_pTxtHelpCaption
= new wxStaticText (this,baseId
+ID_ADVHELPCAPTION_OFFSET
,wxEmptyString
);
1284 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1285 m_pTxtHelpCaption
->SetCursor ( *wxSTANDARD_CURSOR
);
1287 if ( !m_pTxtHelpContent
)
1289 m_pTxtHelpContent
= new wxStaticText (this,baseId
+ID_ADVHELPCONTENT_OFFSET
,
1290 wxEmptyString
,wxDefaultPosition
,wxDefaultSize
,wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1291 m_pTxtHelpContent
->SetCursor ( *wxSTANDARD_CURSOR
);
1294 SetDescribedProperty(GetSelection());
1299 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1301 if ( m_pTxtHelpCaption
)
1302 m_pTxtHelpCaption
->Destroy();
1304 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
1306 if ( m_pTxtHelpContent
)
1307 m_pTxtHelpContent
->Destroy();
1309 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
1314 GetClientSize(&width
,&height
);
1316 RecalculatePositions(width
,height
);
1322 // -----------------------------------------------------------------------
1324 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1327 for ( i
=0; i
<GetPageCount(); i
++ )
1329 wxPropertyGridPageState
* pState
= m_arrPages
[i
]->GetStatePtr();
1330 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1339 // -----------------------------------------------------------------------
1341 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1343 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1345 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1347 // Select correct page.
1348 if ( m_pPropGrid
->m_pState
!= parentState
)
1349 DoSelectPage( GetPageByState(parentState
) );
1351 return m_pPropGrid
->EnsureVisible(id
);
1354 // -----------------------------------------------------------------------
1356 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1358 int id
= event
.GetId();
1361 int baseId
= m_pPropGrid
->GetId();
1363 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1365 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1367 // Categorized mode.
1368 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1370 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1371 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1372 m_pPropGrid
->EnableCategories( true );
1375 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1378 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1380 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1381 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1383 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1385 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1386 m_pPropGrid
->EnableCategories( false );
1395 wxPropertyGridPage
* pdc
;
1397 // Find page with given id.
1398 for ( i
=0; i
<GetPageCount(); i
++ )
1400 pdc
= m_arrPages
[i
];
1401 if ( pdc
->m_id
== id
)
1408 wxASSERT( index
>= 0 );
1410 if ( DoSelectPage( index
) )
1413 // Event dispatching must be last.
1414 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, (wxPGProperty
*) NULL
);
1419 // TODO: Depress the old button on toolbar.
1426 // -----------------------------------------------------------------------
1428 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1430 if ( name
== wxS("descboxheight") )
1432 SetDescBoxHeight(value
.GetLong(), true);
1438 // -----------------------------------------------------------------------
1440 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1442 if ( name
== wxS("descboxheight") )
1444 return (long) GetDescBoxHeight();
1446 return wxNullVariant
;
1449 // -----------------------------------------------------------------------
1451 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1453 if ( m_pTxtHelpCaption
)
1455 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1456 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1458 m_pTxtHelpCaption
->SetLabel(label
);
1459 m_pTxtHelpContent
->SetLabel(content
);
1461 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1462 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1464 if ( (m_iFlags
& wxPG_FL_DESC_REFRESH_REQUIRED
) || (osz2
.x
<(m_width
-10)) )
1465 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1469 // -----------------------------------------------------------------------
1471 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1473 if ( m_pTxtHelpCaption
)
1477 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1481 m_pTxtHelpCaption
->SetLabel(wxEmptyString
);
1482 m_pTxtHelpContent
->SetLabel(wxEmptyString
);
1487 // -----------------------------------------------------------------------
1489 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1493 m_pPropGrid
->SetSplitterLeft(subProps
);
1497 wxClientDC
dc(this);
1498 dc
.SetFont(m_pPropGrid
->m_font
);
1503 for ( i
=0; i
<GetPageCount(); i
++ )
1505 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1506 maxW
+= m_pPropGrid
->m_marginWidth
;
1507 if ( maxW
> highest
)
1512 m_pPropGrid
->SetSplitterPosition( highest
);
1514 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1518 // -----------------------------------------------------------------------
1520 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1523 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1524 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1526 SetDescribedProperty(event
.GetProperty());
1530 // -----------------------------------------------------------------------
1532 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1536 GetClientSize(&width
,&height
);
1538 if ( m_width
== -12345 )
1541 RecalculatePositions(width
,height
);
1544 // -----------------------------------------------------------------------
1546 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1548 // Correct cursor. This is required atleast for wxGTK, for which
1549 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1550 SetCursor( wxNullCursor
);
1554 // -----------------------------------------------------------------------
1556 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1558 if ( !m_pTxtHelpCaption
)
1563 if ( m_dragStatus
> 0 )
1565 int sy
= y
- m_dragOffset
;
1567 // Calculate drag limits
1568 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1569 int top_limit
= m_pPropGrid
->m_lineHeight
;
1571 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1574 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1577 int change
= sy
- m_splitterY
;
1582 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1583 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1585 m_extraHeight
-= change
;
1586 InvalidateBestSize();
1594 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1596 SetCursor ( m_cursorSizeNS
);
1603 SetCursor ( wxNullCursor
);
1610 // -----------------------------------------------------------------------
1612 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1616 // Click on splitter.
1617 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1619 if ( m_dragStatus
== 0 )
1622 // Begin draggin the splitter
1629 m_dragOffset
= y
- m_splitterY
;
1635 // -----------------------------------------------------------------------
1637 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1639 // No event type check - basicly calling this method should
1640 // just stop dragging.
1642 if ( m_dragStatus
>= 1 )
1645 // End Splitter Dragging
1650 // DO NOT ENABLE FOLLOWING LINE!
1651 // (it is only here as a reminder to not to do it)
1654 // This is necessary to return cursor
1657 // Set back the default cursor, if necessary
1658 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1660 SetCursor ( wxNullCursor
);
1667 // -----------------------------------------------------------------------
1669 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1671 wxASSERT_MSG( GetPageCount(),
1672 wxT("SetSplitterPosition() has no effect until pages have been added") );
1675 for ( i
=0; i
<GetPageCount(); i
++ )
1677 wxPropertyGridPage
* page
= GetPage(i
);
1678 page
->DoSetSplitterPositionThisPage( pos
, splitterColumn
);
1681 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1684 // -----------------------------------------------------------------------
1685 // wxPGVIterator_Manager
1686 // -----------------------------------------------------------------------
1688 // Default returned by wxPropertyGridInterface::CreateVIterator().
1689 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1692 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1693 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1695 m_it
.Init(manager
->GetPage(0), flags
);
1697 virtual ~wxPGVIteratorBase_Manager() { }
1706 if ( m_curPage
< m_manager
->GetPageCount() )
1707 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1711 wxPropertyGridManager
* m_manager
;
1713 unsigned int m_curPage
;
1716 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1718 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1721 #endif // wxUSE_PROPGRID