1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/manager.h
3 // Purpose: wxPropertyGridManager
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_MANAGER_H_
13 #define _WX_PROPGRID_MANAGER_H_
19 #include "wx/propgrid/propgrid.h"
21 #include "wx/dcclient.h"
22 #include "wx/scrolwin.h"
23 #include "wx/toolbar.h"
24 #include "wx/stattext.h"
25 #include "wx/button.h"
26 #include "wx/textctrl.h"
27 #include "wx/dialog.h"
28 #include "wx/headerctrl.h"
30 // -----------------------------------------------------------------------
33 extern WXDLLIMPEXP_DATA_PROPGRID(const char) wxPropertyGridManagerNameStr
[];
36 /** @class wxPropertyGridPage
38 Holder of property grid page information. You can subclass this and
39 give instance in wxPropertyGridManager::AddPage. It inherits from
40 wxEvtHandler and can be used to process events specific to this
41 page (id of events will still be same as manager's). If you don't
42 want to use it to process all events of the page, you need to
43 return false in the derived wxPropertyGridPage::IsHandlingAllEvents.
45 Please note that wxPropertyGridPage lacks many non-const property
46 manipulation functions found in wxPropertyGridManager. Please use
47 parent manager (m_manager member variable) when needed.
49 Please note that most member functions are inherited and as such not
50 documented on this page. This means you will probably also want to read
51 wxPropertyGridInterface class reference.
53 @section propgridpage_event_handling Event Handling
55 wxPropertyGridPage receives events emitted by its wxPropertyGridManager, but
56 only those events that are specific to that page. If
57 wxPropertyGridPage::IsHandlingAllEvents returns false, then unhandled
58 events are sent to the manager's parent, as usual.
60 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
66 class WXDLLIMPEXP_PROPGRID wxPropertyGridPage
: public wxEvtHandler
,
67 public wxPropertyGridInterface
,
68 public wxPropertyGridPageState
70 friend class wxPropertyGridManager
;
71 DECLARE_CLASS(wxPropertyGridPage
)
75 virtual ~wxPropertyGridPage();
77 /** Deletes all properties on page.
82 Reduces column sizes to minimum possible that contents are still
83 visibly (naturally some margin space will be applied as well).
86 Minimum size for the page to still display everything.
89 This function only works properly if size of containing grid was
92 Note that you can also get calculated column widths by calling
93 GetColumnWidth() immediately after this function returns.
97 /** Returns page index in manager;
99 inline int GetIndex() const;
101 /** Returns x-coordinate position of splitter on a page.
103 int GetSplitterPosition( int col
= 0 ) const
104 { return GetStatePtr()->DoGetSplitterPosition(col
); }
106 /** Returns "root property". It does not have name, etc. and it is not
107 visible. It is only useful for accessing its children.
109 wxPGProperty
* GetRoot() const { return GetStatePtr()->DoGetRoot(); }
111 /** Return pointer to contained property grid state.
113 wxPropertyGridPageState
* GetStatePtr()
118 /** Return pointer to contained property grid state.
120 const wxPropertyGridPageState
* GetStatePtr() const
126 Returns id of the tool bar item that represents this page on
127 wxPropertyGridManager's wxToolBar.
129 int GetToolId() const
134 /** Do any member initialization in this method.
136 - Called every time the page is added into a manager.
137 - You can add properties to the page here.
139 virtual void Init() {}
141 /** Return false here to indicate unhandled events should be
142 propagated to manager's parent, as normal.
144 virtual bool IsHandlingAllEvents() const { return true; }
146 /** Called every time page is about to be shown.
147 Useful, for instance, creating properties just-in-time.
149 virtual void OnShow();
151 virtual void RefreshProperty( wxPGProperty
* p
);
153 /** Sets splitter position on page.
155 Splitter position cannot exceed grid size, and therefore setting it
156 during form creation may fail as initial grid size is often smaller
157 than desired splitter position, especially when sizers are being used.
159 void SetSplitterPosition( int splitterPos
, int col
= 0 );
163 /** Propagate to other pages.
165 virtual void DoSetSplitterPosition( int pos
,
166 int splitterColumn
= 0,
167 int flags
= wxPG_SPLITTER_REFRESH
);
169 /** Page label (may be referred as name in some parts of documentation).
170 Can be set in constructor, or passed in
171 wxPropertyGridManager::AddPage(), but *not* in both.
175 //virtual bool ProcessEvent( wxEvent& event );
177 wxPropertyGridManager
* m_manager
;
179 int m_id
; // toolbar index
182 bool m_isDefault
; // is this base page object?
184 DECLARE_EVENT_TABLE()
187 // -----------------------------------------------------------------------
190 class wxPGHeaderCtrl
;
194 /** @class wxPropertyGridManager
196 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
197 which can optionally have toolbar for mode and page selection, and help
199 Use window flags to select components to include.
201 @section propgridmanager_window_styles_ Window Styles
203 See @ref propgrid_window_styles.
205 @section propgridmanager_event_handling Event Handling
207 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
208 for more information.
213 class WXDLLIMPEXP_PROPGRID
214 wxPropertyGridManager
: public wxPanel
, public wxPropertyGridInterface
216 DECLARE_CLASS(wxPropertyGridManager
)
217 friend class wxPropertyGridPage
;
222 Two step constructor.
223 Call Create when this constructor is called to build up the
224 wxPropertyGridManager.
226 wxPropertyGridManager();
229 /** The default constructor. The styles to be used are styles valid for
231 @see @link wndflags Additional Window Styles@endlink
233 wxPropertyGridManager( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
234 const wxPoint
& pos
= wxDefaultPosition
,
235 const wxSize
& size
= wxDefaultSize
,
236 long style
= wxPGMAN_DEFAULT_STYLE
,
237 const wxString
& name
= wxPropertyGridManagerNameStr
);
240 virtual ~wxPropertyGridManager();
242 /** Creates new property page. Note that the first page is not created
245 A label for the page. This may be shown as a toolbar tooltip etc.
247 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
248 default image is used.
250 wxPropertyGridPage instance. Manager will take ownership of this object.
251 NULL indicates that a default page instance should be created.
254 Returns pointer to created page.
257 If toolbar is used, it is highly recommended that the pages are
258 added when the toolbar is not turned off using window style flag
261 wxPropertyGridPage
* AddPage( const wxString
& label
= wxEmptyString
,
262 const wxBitmap
& bmp
= wxPG_NULL_BITMAP
,
263 wxPropertyGridPage
* pageObj
= NULL
)
265 return InsertPage(-1, label
, bmp
, pageObj
);
268 /** Deletes all all properties and all pages.
270 virtual void Clear();
272 /** Deletes all properties on given page.
274 void ClearPage( int page
);
276 /** Forces updating the value of property from the editor control.
277 Returns true if DoPropertyChanged was actually called.
279 bool CommitChangesFromEditor( wxUint32 flags
= 0 )
281 return m_pPropGrid
->CommitChangesFromEditor(flags
);
286 Whenever the control is created without any parameters, use Create to
287 actually create it. Don't access the control's public methods before
289 @see @link wndflags Additional Window Styles@endlink
291 bool Create( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
292 const wxPoint
& pos
= wxDefaultPosition
,
293 const wxSize
& size
= wxDefaultSize
,
294 long style
= wxPGMAN_DEFAULT_STYLE
,
295 const wxString
& name
= wxPropertyGridManagerNameStr
);
298 Enables or disables (shows/hides) categories according to parameter
301 WARNING: Not tested properly, use at your own risk.
303 bool EnableCategories( bool enable
)
305 long fl
= m_windowStyle
| wxPG_HIDE_CATEGORIES
;
306 if ( enable
) fl
= m_windowStyle
& ~(wxPG_HIDE_CATEGORIES
);
307 SetWindowStyleFlag(fl
);
311 /** Selects page, scrolls and/or expands items to ensure that the
312 given item is visible. Returns true if something was actually done.
314 bool EnsureVisible( wxPGPropArg id
);
316 /** Returns number of columns on given page. By the default,
317 returns number of columns on current page. */
318 int GetColumnCount( int page
= -1 ) const;
320 /** Returns height of the description text box. */
321 int GetDescBoxHeight() const;
323 /** Returns pointer to the contained wxPropertyGrid. This does not change
324 after wxPropertyGridManager has been created, so you can safely obtain
325 pointer once and use it for the entire lifetime of the instance.
327 wxPropertyGrid
* GetGrid()
329 wxASSERT(m_pPropGrid
);
333 const wxPropertyGrid
* GetGrid() const
335 wxASSERT(m_pPropGrid
);
336 return (const wxPropertyGrid
*)m_pPropGrid
;
339 /** Returns iterator class instance.
341 Calling this method in wxPropertyGridManager causes run-time assertion
342 failure. Please only iterate through individual pages or use
345 wxPropertyGridIterator
GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
346 wxPGProperty
* firstProp
= NULL
)
348 wxFAIL_MSG( "Please only iterate through individual pages "
349 "or use CreateVIterator()" );
350 return wxPropertyGridInterface::GetIterator( flags
, firstProp
);
353 wxPropertyGridConstIterator
354 GetIterator(int flags
= wxPG_ITERATE_DEFAULT
,
355 wxPGProperty
* firstProp
= NULL
) const
357 wxFAIL_MSG( "Please only iterate through individual pages "
358 " or use CreateVIterator()" );
359 return wxPropertyGridInterface::GetIterator( flags
, firstProp
);
362 /** Returns iterator class instance.
364 Calling this method in wxPropertyGridManager causes run-time assertion
365 failure. Please only iterate through individual pages or use
368 wxPropertyGridIterator
GetIterator( int flags
, int startPos
)
370 wxFAIL_MSG( "Please only iterate through individual pages "
371 "or use CreateVIterator()" );
373 return wxPropertyGridInterface::GetIterator( flags
, startPos
);
376 wxPropertyGridConstIterator
GetIterator( int flags
, int startPos
) const
378 wxFAIL_MSG( "Please only iterate through individual pages "
379 "or use CreateVIterator()" );
380 return wxPropertyGridInterface::GetIterator( flags
, startPos
);
383 /** Similar to GetIterator, but instead returns wxPGVIterator instance,
384 which can be useful for forward-iterating through arbitrary property
387 virtual wxPGVIterator
GetVIterator( int flags
) const;
389 /** Returns currently selected page.
391 wxPropertyGridPage
* GetCurrentPage() const
393 return GetPage(m_selPage
);
396 /** Returns page object for given page index.
398 wxPropertyGridPage
* GetPage( unsigned int ind
) const
400 return m_arrPages
[ind
];
403 /** Returns page object for given page name.
405 wxPropertyGridPage
* GetPage( const wxString
& name
) const
407 return GetPage(GetPageByName(name
));
411 Returns index for a page name.
413 If no match is found, wxNOT_FOUND is returned.
415 int GetPageByName( const wxString
& name
) const;
417 /** Returns index for a relevant propertygrid state.
419 If no match is found, wxNOT_FOUND is returned.
421 int GetPageByState( const wxPropertyGridPageState
* pstate
) const;
424 /** Returns wxPropertyGridPageState of given page, current page's for -1.
426 virtual wxPropertyGridPageState
* GetPageState( int page
) const;
429 /** Returns number of managed pages. */
430 size_t GetPageCount() const;
432 /** Returns name of given page. */
433 const wxString
& GetPageName( int index
) const;
435 /** Returns "root property" of the given page. It does not have name, etc.
436 and it is not visible. It is only useful for accessing its children.
438 wxPGProperty
* GetPageRoot( int index
) const;
440 /** Returns index to currently selected page. */
441 int GetSelectedPage() const { return m_selPage
; }
443 /** Alias for GetSelection(). */
444 wxPGProperty
* GetSelectedProperty() const
446 return GetSelection();
449 /** Shortcut for GetGrid()->GetSelection(). */
450 wxPGProperty
* GetSelection() const
452 return m_pPropGrid
->GetSelection();
455 /** Returns a pointer to the toolbar currently associated with the
456 wxPropertyGridManager (if any). */
457 wxToolBar
* GetToolBar() const { return m_pToolbar
; }
459 /** Creates new property page. Note that the first page is not created
462 Add to this position. -1 will add as the last item.
464 A label for the page. This may be shown as a toolbar tooltip etc.
466 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
467 default image is used.
469 wxPropertyGridPage instance. Manager will take ownership of this object.
470 If NULL, default page object is constructed.
473 Returns pointer to created page.
475 virtual wxPropertyGridPage
* InsertPage( int index
,
476 const wxString
& label
,
477 const wxBitmap
& bmp
= wxNullBitmap
,
478 wxPropertyGridPage
* pageObj
= NULL
);
481 Returns true if any property on any page has been modified by the user.
483 bool IsAnyModified() const;
486 Returns true if updating is frozen (ie Freeze() called but not yet
489 bool IsFrozen() const { return m_pPropGrid
->m_frozen
> 0; }
492 Returns true if any property on given page has been modified by the
495 bool IsPageModified( size_t index
) const;
498 Returns true if property is selected. Since selection is page
499 based, this function checks every page in the manager.
501 virtual bool IsPropertySelected( wxPGPropArg id
) const;
503 virtual void Refresh( bool eraseBackground
= true,
504 const wxRect
* rect
= (const wxRect
*) NULL
);
508 Returns false if it was not possible to remove page in question.
510 virtual bool RemovePage( int page
);
512 /** Select and displays a given page.
515 Index of page being seleced. Can be -1 to select nothing.
517 void SelectPage( int index
);
519 /** Select and displays a given page (by label). */
520 void SelectPage( const wxString
& label
)
522 int index
= GetPageByName(label
);
523 wxCHECK_RET( index
>= 0, wxT("No page with such name") );
527 /** Select and displays a given page. */
528 void SelectPage( wxPropertyGridPage
* ptr
)
530 SelectPage( GetPageByState(ptr
) );
533 /** Select a property. */
534 bool SelectProperty( wxPGPropArg id
, bool focus
= false )
536 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
537 return p
->GetParentState()->DoSelectProperty(p
, focus
);
541 Sets a column title. Default title for column 0 is "Property",
542 and "Value" for column 1.
544 @remarks If header is not shown yet, then calling this
545 member function will make it visible.
547 void SetColumnTitle( int idx
, const wxString
& title
);
550 Sets number of columns on given page (default is current page).
552 @remarks If you use header, then you should always use this
553 member function to set the column count, instead of
554 ones present in wxPropertyGrid or wxPropertyGridPage.
556 void SetColumnCount( int colCount
, int page
= -1 );
558 /** Sets label and text in description box.
560 void SetDescription( const wxString
& label
, const wxString
& content
);
562 /** Sets y coordinate of the description box splitter. */
563 void SetDescBoxHeight( int ht
, bool refresh
= true );
565 /** Moves splitter as left as possible, while still allowing all
566 labels to be shown in full.
568 If false, will still allow sub-properties (ie. properties which
569 parent is not root or category) to be cropped.
571 If true, takes labels on all pages into account.
573 void SetSplitterLeft( bool subProps
= false, bool allPages
= true );
576 Sets splitter position on individual page.
578 @remarks If you use header, then you should always use this
579 member function to set the splitter position, instead of
580 ones present in wxPropertyGrid or wxPropertyGridPage.
582 void SetPageSplitterPosition( int page
, int pos
, int column
= 0 );
585 Sets splitter position for all pages.
587 @remarks Splitter position cannot exceed grid size, and therefore
588 setting it during form creation may fail as initial grid
589 size is often smaller than desired splitter position,
590 especially when sizers are being used.
592 If you use header, then you should always use this
593 member function to set the splitter position, instead of
594 ones present in wxPropertyGrid or wxPropertyGridPage.
596 void SetSplitterPosition( int pos
, int column
= 0 );
600 Show or hide the property grid header control. It is hidden
603 @remarks Grid may look better if you use wxPG_NO_INTERNAL_BORDER
604 window style when showing a header.
606 void ShowHeader(bool show
= true);
612 // Subclassing helpers
616 Creates property grid for the manager. Reimplement in derived class to
617 use subclassed wxPropertyGrid. However, if you you do this then you
618 must also use the two-step construction (ie. default constructor and
619 Create() instead of constructor with arguments) when creating the
622 virtual wxPropertyGrid
* CreatePropertyGrid() const;
625 virtual void RefreshProperty( wxPGProperty
* p
);
628 // Overridden functions - no documentation required.
631 void SetId( wxWindowID winid
);
633 virtual void Freeze();
635 virtual void SetExtraStyle ( long exStyle
);
636 virtual bool SetFont ( const wxFont
& font
);
637 virtual void SetWindowStyleFlag ( long style
);
638 virtual bool Reparent( wxWindowBase
*newParent
);
641 virtual wxSize
DoGetBestSize() const;
646 void OnMouseMove( wxMouseEvent
&event
);
647 void OnMouseClick( wxMouseEvent
&event
);
648 void OnMouseUp( wxMouseEvent
&event
);
649 void OnMouseEntry( wxMouseEvent
&event
);
651 void OnPaint( wxPaintEvent
&event
);
653 void OnToolbarClick( wxCommandEvent
&event
);
654 void OnResize( wxSizeEvent
& event
);
655 void OnPropertyGridSelect( wxPropertyGridEvent
& event
);
656 void OnPGColDrag( wxPropertyGridEvent
& event
);
659 wxPropertyGrid
* m_pPropGrid
;
661 wxVector
<wxPropertyGridPage
*> m_arrPages
;
664 wxToolBar
* m_pToolbar
;
667 wxPGHeaderCtrl
* m_pHeaderCtrl
;
669 wxStaticText
* m_pTxtHelpCaption
;
670 wxStaticText
* m_pTxtHelpContent
;
672 wxPropertyGridPage
* m_emptyPage
;
674 wxArrayString m_columnLabels
;
678 // Selected page index.
689 int m_splitterHeight
;
695 wxCursor m_cursorSizeNS
;
697 int m_nextDescBoxSize
;
701 unsigned char m_dragStatus
;
703 unsigned char m_onSplitter
;
707 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
709 /** Select and displays a given page. */
710 virtual bool DoSelectPage( int index
);
712 // Sets some members to defaults.
715 // Initializes some members.
716 void Init2( int style
);
719 virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const;
722 virtual bool ProcessEvent( wxEvent
& event
);
724 /** Recalculates new positions for components, according to the
727 void RecalculatePositions( int width
, int height
);
729 /** (Re)creates/destroys controls, according to the window style bits. */
730 void RecreateControls();
732 void UpdateDescriptionBox( int new_splittery
, int new_width
, int new_height
);
734 void RepaintDescBoxDecorations( wxDC
& dc
,
739 void SetDescribedProperty( wxPGProperty
* p
);
741 // Reimplement these to handle "descboxheight" state item
742 virtual bool SetEditableStateItem( const wxString
& name
, wxVariant value
);
743 virtual wxVariant
GetEditableStateItem( const wxString
& name
) const;
746 DECLARE_EVENT_TABLE()
749 // -----------------------------------------------------------------------
751 inline int wxPropertyGridPage::GetIndex() const
755 return m_manager
->GetPageByState(this);
758 // -----------------------------------------------------------------------
760 #endif // wxUSE_PROPGRID
762 #endif // _WX_PROPGRID_MANAGER_H_