00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _WX_PROPGRID_MANAGER_H_
00013 #define _WX_PROPGRID_MANAGER_H_
00014
00015 #include <wx/propgrid/propgrid.h>
00016
00017 #if wxPG_INCLUDE_MANAGER || defined(DOXYGEN)
00018
00019 #include <wx/dcclient.h>
00020 #include <wx/scrolwin.h>
00021 #include <wx/toolbar.h>
00022 #include <wx/stattext.h>
00023 #include <wx/button.h>
00024 #include <wx/textctrl.h>
00025 #include <wx/dialog.h>
00026
00027
00028
00029 #ifndef SWIG
00030 extern WXDLLIMPEXP_PG const wxChar *wxPropertyGridManagerNameStr;
00031 #endif
00032
00068 class WXDLLIMPEXP_PG wxPropertyGridPage : public wxEvtHandler,
00069 public wxPropertyGridInterface,
00070 public wxPropertyGridState
00071 {
00072 friend class wxPropertyGridManager;
00073 #ifndef SWIG
00074 DECLARE_CLASS(wxPropertyGridPage)
00075 #endif
00076 public:
00077
00078 wxPropertyGridPage();
00079 virtual ~wxPropertyGridPage();
00080
00083 virtual void Clear();
00084
00097 wxSize FitColumns();
00098
00101 inline int GetIndex() const;
00102
00105 int GetSplitterPosition( int col = 0 ) const { return GetStatePtr()->DoGetSplitterPosition(col); }
00106
00110 wxPGProperty* GetRoot() const { return GetStatePtr()->DoGetRoot(); }
00111
00114 wxPropertyGridState* GetStatePtr()
00115 {
00116 return this;
00117 }
00118
00121 const wxPropertyGridState* GetStatePtr() const
00122 {
00123 return this;
00124 }
00125
00128 int GetToolId() const
00129 {
00130 return m_id;
00131 }
00132
00138 virtual void Init() {}
00139
00143 virtual bool IsHandlingAllEvents() const { return true; }
00144
00148 virtual void OnShow();
00149
00150 virtual void RefreshProperty( wxPGProperty* p );
00151
00158 void SetSplitterPosition( int splitterPos, int col = 0 );
00159
00160 protected:
00161
00164 virtual void DoSetSplitterPosition( int pos,
00165 int splitterColumn = 0,
00166 bool allPages = false,
00167 bool fromAutoCenter = false );
00168
00173 wxString m_label;
00174
00175 #ifndef SWIG
00176
00177
00178
00179 wxPropertyGridManager* m_manager;
00180
00181 int m_id;
00182
00183 private:
00184 bool m_isDefault;
00185
00186 private:
00187 DECLARE_EVENT_TABLE()
00188 #endif
00189 };
00190
00191
00192
00235
00236 class WXDLLIMPEXP_PG wxPropertyGridManager : public wxPanel, public wxPropertyGridInterface
00237 {
00238 #ifndef SWIG
00239 DECLARE_CLASS(wxPropertyGridManager)
00240 #endif
00241 friend class wxPropertyGridPage;
00242 public:
00243
00244 #ifdef SWIG
00245 %pythonAppend wxPropertyGridManager {
00246 self._setOORInfo(self)
00247 self.DoDefaultTypeMappings()
00248 self.edited_objects = {}
00249 self.DoDefaultValueTypeMappings()
00250 if not hasattr(self.__class__,'_vt2setter'):
00251 self.__class__._vt2setter = {}
00252 }
00253 %pythonAppend wxPropertyGridManager() ""
00254
00255 wxPropertyGridManager( wxWindow *parent, wxWindowID id = wxID_ANY,
00256 const wxPoint& pos = wxDefaultPosition,
00257 const wxSize& size = wxDefaultSize,
00258 long style = wxPGMAN_DEFAULT_STYLE,
00259 const wxChar* name = wxPyPropertyGridManagerNameStr );
00260 %RenameCtor(PrePropertyGridManager, wxPropertyGridManager());
00261
00262 #else
00263
00267 wxPropertyGridManager();
00268
00273 wxPropertyGridManager( wxWindow *parent, wxWindowID id = wxID_ANY,
00274 const wxPoint& pos = wxDefaultPosition,
00275 const wxSize& size = wxDefaultSize,
00276 long style = wxPGMAN_DEFAULT_STYLE,
00277 const wxChar* name = wxPropertyGridManagerNameStr );
00278
00280 virtual ~wxPropertyGridManager();
00281
00282 #endif
00283
00301 int AddPage( const wxString& label = wxEmptyString,
00302 const wxBitmap& bmp = wxPG_NULL_BITMAP,
00303 wxPropertyGridPage* pageObj = (wxPropertyGridPage*) NULL )
00304 {
00305 return InsertPage(-1,label,bmp,pageObj);
00306 }
00307
00312 bool CanClose()
00313 {
00314 return m_pPropGrid->CanClose();
00315 }
00316
00317 void ClearModifiedStatus ( wxPGPropArg id );
00318
00319 void ClearModifiedStatus ()
00320 {
00321 m_pPropGrid->ClearModifiedStatus();
00322 }
00323
00326 virtual void Clear();
00327
00330 void ClearPage( int page );
00331
00335 bool CommitChangesFromEditor( wxUint32 flags = 0 )
00336 {
00337 return m_pPropGrid->CommitChangesFromEditor(flags);
00338 }
00339
00345 bool Create( wxWindow *parent, wxWindowID id = wxID_ANY,
00346 const wxPoint& pos = wxDefaultPosition,
00347 const wxSize& size = wxDefaultSize,
00348 long style = wxPGMAN_DEFAULT_STYLE,
00349 const wxChar* name = wxPropertyGridManagerNameStr );
00350
00354 bool EnableCategories( bool enable )
00355 {
00356 long fl = m_windowStyle | wxPG_HIDE_CATEGORIES;
00357 if ( enable ) fl = m_windowStyle & ~(wxPG_HIDE_CATEGORIES);
00358 SetWindowStyleFlag(fl);
00359 return true;
00360 }
00361
00365 bool EnsureVisible( wxPGPropArg id );
00366
00368 size_t GetChildrenCount()
00369 {
00370 return GetChildrenCount( m_pPropGrid->m_pState->m_properties );
00371 }
00372
00374 size_t GetChildrenCount( int pageIndex );
00375
00380 size_t GetChildrenCount( wxPGPropArg id ) const
00381 {
00382 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0)
00383 return p->GetChildCount();
00384 }
00385
00388 int GetColumnCount( int page = -1 ) const;
00389
00391 int GetDescBoxHeight() const;
00392
00397 wxPropertyGrid* GetGrid()
00398 {
00399 wxASSERT(m_pPropGrid);
00400 return m_pPropGrid;
00401 };
00402
00403 const wxPropertyGrid* GetGrid() const
00404 {
00405 wxASSERT(m_pPropGrid);
00406 return (const wxPropertyGrid*)m_pPropGrid;
00407 };
00408
00414 wxPropertyGridIterator GetIterator( int flags = wxPG_ITERATE_DEFAULT, wxPGProperty* firstProp = NULL )
00415 {
00416 wxFAIL_MSG(wxT("Please only iterate through individual pages or use CreateVIterator()"));
00417 return wxPropertyGridInterface::GetIterator( flags, firstProp );
00418 }
00419
00420 wxPropertyGridConstIterator GetIterator( int flags = wxPG_ITERATE_DEFAULT, wxPGProperty* firstProp = NULL ) const
00421 {
00422 wxFAIL_MSG(wxT("Please only iterate through individual pages or use CreateVIterator()"));
00423 return wxPropertyGridInterface::GetIterator( flags, firstProp );
00424 }
00425
00431 wxPropertyGridIterator GetIterator( int flags, int startPos )
00432 {
00433 wxFAIL_MSG(wxT("Please only iterate through individual pages or use CreateVIterator()"));
00434 return wxPropertyGridInterface::GetIterator( flags, startPos );
00435 }
00436
00437 wxPropertyGridConstIterator GetIterator( int flags, int startPos ) const
00438 {
00439 wxFAIL_MSG(wxT("Please only iterate through individual pages or use CreateVIterator()"));
00440 return wxPropertyGridInterface::GetIterator( flags, startPos );
00441 }
00442
00447 virtual wxPGVIterator GetVIterator( int flags ) const;
00448
00449 #if wxPG_COMPATIBILITY_1_2_0
00450
00457 wxPGProperty* GetLastChild( wxPGPropArg id )
00458 {
00459 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
00460 if ( !p->GetChildCount() ) return wxNullProperty;
00461 return p->Last();
00462 }
00463
00464 #endif // wxPG_COMPATIBILITY_1_2_0
00465
00468 wxPropertyGridPage* GetCurrentPage() const
00469 {
00470 return GetPage(m_selPage);
00471 }
00472
00475 wxPropertyGridPage* GetLastPage() const
00476 {
00477 return GetPage((unsigned int)m_arrPages.size()-1);
00478 }
00479
00482 wxPropertyGridPage* GetPage( unsigned int ind ) const
00483 {
00484 return (wxPropertyGridPage*)m_arrPages.Item(ind);
00485 }
00486
00489 wxPropertyGridPage* GetPage( const wxString& name ) const
00490 {
00491 return GetPage(GetPageByName(name));
00492 }
00493
00495 int GetPageByName( const wxString& name ) const;
00496
00500 int GetPageByState( const wxPropertyGridState* pstate ) const;
00501
00504 virtual wxPropertyGridState* GetPageState( int page ) const;
00505
00507 size_t GetPageCount() const;
00508
00510 const wxString& GetPageName( int index ) const;
00511
00515 wxPGProperty* GetPageRoot( int index ) const;
00516
00522 wxPGProperty* GetPropertyByLabel( const wxString& name,
00523 wxPropertyGridState** ppState = (wxPropertyGridState**)NULL ) const;
00524
00526 wxColour GetPropertyColour( wxPGPropArg id ) const
00527 {
00528 return m_pPropGrid->GetPropertyColour(id);
00529 }
00530
00532 wxColour GetPropertyTextColour( wxPGPropArg id ) const
00533 {
00534 return m_pPropGrid->GetPropertyTextColour(id);
00535 }
00536
00538 int GetSelectedPage() const { return m_selPage; }
00539
00541 wxPGProperty* GetSelectedProperty() const
00542 {
00543 return m_pPropGrid->GetSelection();
00544 }
00545
00547 int GetSelection() const { return m_selPage; }
00548
00549 #if wxPG_COMPATIBILITY_1_2_0
00550
00553 wxDEPRECATED( int GetTargetPage() const );
00554 #endif
00555
00558 wxToolBar* GetToolBar() const { return m_pToolbar; }
00559
00575 virtual int InsertPage( int index, const wxString& label, const wxBitmap& bmp = wxNullBitmap,
00576 wxPropertyGridPage* pageObj = (wxPropertyGridPage*) NULL );
00577
00579 bool IsAnyModified() const;
00580
00582 bool IsFrozen() const { return (m_pPropGrid->m_frozen>0)?true:false; }
00583
00585 bool IsPageModified( size_t index ) const;
00586
00591 virtual bool IsPropertySelected( wxPGPropArg id ) const;
00592
00593 virtual void Refresh( bool eraseBackground = true,
00594 const wxRect* rect = (const wxRect*) NULL );
00595
00596 #if wxPG_COMPATIBILITY_1_2_0
00597 void RegisterAdvancedPropertyClasses() { }
00598 #endif
00599
00604 virtual bool RemovePage( int page );
00605
00611 void SelectPage( int index );
00612
00614 void SelectPage( const wxString& label )
00615 {
00616 int index = GetPageByName(label);
00617 wxCHECK_RET( index >= 0, wxT("No page with such name") );
00618 SelectPage( index );
00619 }
00620
00622 void SelectPage( wxPropertyGridPage* ptr )
00623 {
00624 SelectPage( GetPageByState(ptr) );
00625 }
00626
00628 bool SelectProperty( wxPGPropArg id, bool focus = false )
00629 {
00630 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
00631 return p->GetParentState()->DoSelectProperty(p, focus);
00632 }
00633
00636 void SetColumnCount( int colCount, int page = -1 );
00637
00640 void SetDescription( const wxString& label, const wxString& content );
00641
00644 void SetCaptionTextColour( wxPGPropArg id, const wxColour& col )
00645 {
00646 m_pPropGrid->SetCaptionTextColour( id, col );
00647 }
00648
00650 void SetDescBoxHeight( int ht, bool refresh = true );
00651
00656 void SetPropertyAttributeAll( const wxString& name, wxVariant value );
00657
00658 #if wxPG_COMPATIBILITY_1_2_0
00659
00666 wxDEPRECATED( void SetPropertyColour( wxPGPropArg id, const wxColour& col ) );
00667 #endif
00668
00673 void SetPropertyBackgroundColour( wxPGPropArg id, const wxColour& col )
00674 {
00675 m_pPropGrid->SetPropertyBackgroundColour( id, col );
00676 }
00677
00680 void SetPropertyTextColour( wxPGPropArg id, const wxColour& col )
00681 {
00682 m_pPropGrid->SetPropertyTextColour( id, col );
00683 }
00684
00686 void SetPropertyColourToDefault( wxPGPropArg id )
00687 {
00688 m_pPropGrid->SetPropertyColourToDefault(id);
00689 }
00690
00699 void SetSplitterLeft( bool subProps = false, bool allPages = true );
00700
00702 void SetPageSplitterPosition( int page, int pos, int column = 0 )
00703 {
00704 GetPage(page)->DoSetSplitterPosition( pos, column );
00705 }
00706
00713 void SetSplitterPosition( int pos, int column = 0 );
00714
00716 void SetStringSelection( const wxChar* name )
00717 {
00718 SelectPage( GetPageByName(name) );
00719 }
00720
00721 #if wxPG_COMPATIBILITY_1_2_0
00722
00725 wxDEPRECATED( void SetTargetPage( int ) );
00726 wxDEPRECATED( void SetTargetPage( const wxChar* ) );
00727 #endif
00728
00733 bool ClearSelection()
00734 {
00735 return m_pPropGrid->ClearSelection();
00736 }
00737
00738 #ifdef SWIG
00739 %pythoncode {
00740 def GetValuesFromPage(self,page,dict_=None,as_strings=False):
00741 "Same as GetValues, but returns values from specific page only. For argument descriptions, see GetValues."
00742
00743 if dict_ is None:
00744 dict_ = {}
00745 elif hasattr(dict_,'__dict__'):
00746 dict_ = dict_.__dict__
00747
00748 if not as_strings:
00749 getter = self.GetPropertyValue
00750 else:
00751 getter = self.GetPropertyValueAsString
00752
00753 root = self.GetPageRoot(page)
00754 self._GetValues(root,self.GetFirstChild(root),dict_,getter)
00755
00756 return dict_
00757
00758
00759 def GetValues(self,dict_=None,as_strings=False,inc_attributes=False):
00760 "Returns values in the grid."
00761 ""
00762 "dict_: if not given, then a new one is created. dict_ can be"
00763 " object as well, in which case it's __dict__ is used."
00764 "as_strings: if True, then string representations of values"
00765 " are fetched instead of native types. Useful for config and such."
00766 ""
00767 "Return value: dictionary with values. It is always a dictionary,"
00768 "so if dict_ was object with __dict__ attribute, then that attribute"
00769 "is returned."
00770 ""
00771
00772 if dict_ is None:
00773 dict_ = {}
00774 elif hasattr(dict_,'__dict__'):
00775 dict_ = dict_.__dict__
00776
00777 if not as_strings:
00778 getter = self.GetPropertyValue
00779 else:
00780 getter = self.GetPropertyValueAsString
00781
00782 for page in range(0,self.GetPageCount()):
00783 root = self.GetPageRoot(page)
00784 self._GetValues(root,self.GetFirstChild(root),dict_,getter,inc_attributes)
00785
00786 return dict_
00787
00788 GetPropertyValues = GetValues
00789
00790 }
00791 #endif
00792
00793 protected:
00794
00795
00796
00797
00798
00805 virtual wxPropertyGrid* CreatePropertyGrid() const;
00806
00807 virtual void RefreshProperty( wxPGProperty* p );
00808
00809 public:
00810
00811 #ifndef DOXYGEN
00812
00813
00814
00815
00816
00817 virtual wxSize DoGetBestSize() const;
00818 void SetId( wxWindowID winid );
00819
00820 virtual void Freeze();
00821 virtual void Thaw();
00822 virtual void SetExtraStyle ( long exStyle );
00823 virtual bool SetFont ( const wxFont& font );
00824 virtual void SetWindowStyleFlag ( long style );
00825 virtual bool Reparent( wxWindowBase *newParent );
00826
00827 protected:
00828
00829 public:
00830
00831 #ifndef SWIG
00832
00833
00834
00835
00836 void OnMouseMove( wxMouseEvent &event );
00837 void OnMouseClick( wxMouseEvent &event );
00838 void OnMouseUp( wxMouseEvent &event );
00839 void OnMouseEntry( wxMouseEvent &event );
00840
00841 void OnPaint( wxPaintEvent &event );
00842
00843 void OnToolbarClick( wxCommandEvent &event );
00844 void OnResize( wxSizeEvent& event );
00845 void OnPropertyGridSelect( wxPropertyGridEvent& event );
00846
00847 protected:
00848
00849 wxPropertyGrid* m_pPropGrid;
00850
00851 wxArrayPtrVoid m_arrPages;
00852
00853 #if wxUSE_TOOLBAR
00854 wxToolBar* m_pToolbar;
00855 #endif
00856 wxStaticText* m_pTxtHelpCaption;
00857 wxStaticText* m_pTxtHelpContent;
00858
00859 wxPropertyGridPage* m_emptyPage;
00860
00861 long m_iFlags;
00862
00863
00864 int m_selPage;
00865
00866 int m_width;
00867
00868 int m_height;
00869
00870 int m_extraHeight;
00871
00872 int m_splitterY;
00873
00874 int m_splitterHeight;
00875
00876 int m_nextTbInd;
00877
00878 int m_dragOffset;
00879
00880 wxCursor m_cursorSizeNS;
00881
00882 int m_nextDescBoxSize;
00883
00884 wxWindowID m_baseId;
00885
00886 unsigned char m_dragStatus;
00887
00888 unsigned char m_onSplitter;
00889
00890
00891
00892 virtual wxPGProperty* DoGetPropertyByName( wxPGPropNameStr name ) const;
00893
00895 virtual bool DoSelectPage( int index );
00896
00897
00898 void Init1();
00899
00900
00901 void Init2( int style );
00902
00903
00904
00905
00906
00910 void RecalculatePositions( int width, int height );
00911
00913 void RecreateControls();
00914
00915 void UpdateDescriptionBox( int new_splittery, int new_width, int new_height );
00916
00917 void RepaintSplitter( wxDC& dc, int new_splittery, int new_width, int new_height, bool desc_too );
00918
00919 void SetDescribedProperty( wxPGProperty* p );
00920
00921
00922 virtual bool SetEditableStateItem( const wxString& name, wxVariant value );
00923 virtual wxVariant GetEditableStateItem( const wxString& name ) const;
00924
00925 virtual bool ProcessEvent( wxEvent& event );
00926
00927 private:
00928 DECLARE_EVENT_TABLE()
00929 #endif // #ifndef SWIG
00930 #endif // #ifndef DOXYGEN
00931 };
00932
00933
00934
00935 inline int wxPropertyGridPage::GetIndex() const
00936 {
00937 if ( !m_manager )
00938 return wxNOT_FOUND;
00939 return m_manager->GetPageByState(this);
00940 }
00941
00942
00943
00944 #endif // wxPG_INCLUDE_MANAGER
00945
00946 #endif // _WX_PROPGRID_MANAGER_H_