2004-08-03 07:18:36 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2004-08-03 07:55:18 -04:00
|
|
|
// Name: foldpanelbar.h
|
|
|
|
// Purpose: wxFoldPanel
|
|
|
|
// Author: Jorgen Bodde
|
|
|
|
// Modified by:
|
|
|
|
// Created: 22/06/2004
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Jorgen Bodde
|
|
|
|
// Licence: wxWindows licence
|
2004-08-03 07:18:36 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __WXFOLDPANELBAR_H__
|
|
|
|
#define __WXFOLDPANELBAR_H__
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "foldpanelitem.h"
|
|
|
|
|
|
|
|
/** Not yet supported but added for future reference. Single fold forces other panels to close when
|
|
|
|
they are open, and only opens the current panel. This will allow the open panel to gain the full
|
2004-08-03 07:55:18 -04:00
|
|
|
size left in the client area */
|
2004-08-03 10:33:49 -04:00
|
|
|
#define wxFPB_SINGLE_FOLD 0x0001
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
/** All panels are stacked to the bottom. When they are expanded again they show up at the top */
|
2004-08-03 10:33:49 -04:00
|
|
|
#define wxFPB_COLLAPSE_TO_BOTTOM 0x0002
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
/** Not yet supported, but added for future reference. Single fold plus panels will be stacked at the bottom */
|
2004-08-03 07:55:18 -04:00
|
|
|
#define wxFPB_EXCLUSIVE_FOLD wxFPB_SINGLE_FOLD | wxFPB_COLLAPSE_TO_BOTTOM
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
/** Default style of the wxFoldPanelBar */
|
2004-08-03 07:55:18 -04:00
|
|
|
#define wxFPB_DEFAULT_EXTRASTYLE 0
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
#define wxFPB_DEFAULT_STYLE wxTAB_TRAVERSAL | wxNO_BORDER
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
/** \class wxFoldPanel
|
2004-08-03 07:55:18 -04:00
|
|
|
This class is used to return a reference to the fold panel that is added by wxFoldPanelBar::AddFoldPanel(). Use
|
2004-08-03 10:33:49 -04:00
|
|
|
wxFoldPanel::IsOk() to check wether the result is ok to be used in further operations. Use wxFoldPanel::GetItem()
|
2004-08-03 07:55:18 -04:00
|
|
|
to obtain a parent window reference to create the controls on you want to add with wxFoldPanelBar::AddFoldPanelWindow().<br><br>
|
2004-08-03 07:18:36 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
class wxFoldPanel
|
|
|
|
{
|
|
|
|
private:
|
2004-08-03 07:55:18 -04:00
|
|
|
wxFoldPanelItem *_item;
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
public:
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Constructor, usually not directly used by the developer. */
|
2004-08-03 10:33:49 -04:00
|
|
|
wxFoldPanel(wxFoldPanelItem *item)
|
2004-08-03 07:55:18 -04:00
|
|
|
: _item(item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns true if this is a valid wxFoldPanelItem reference. */
|
|
|
|
bool IsOk() const {
|
|
|
|
return (_item != 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Copy operator to assign one instance to the other, this is needed because these classes are passed
|
|
|
|
as instance not by reference. */
|
|
|
|
virtual void operator=(const wxFoldPanel &item) {
|
|
|
|
_item = item._item;
|
|
|
|
};
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
#ifndef _NO_DOXYGEN_
|
2004-08-03 07:55:18 -04:00
|
|
|
// not allowed to be seen by doxygen
|
|
|
|
wxFoldPanelItem *GetItem() const {
|
|
|
|
return _item;
|
|
|
|
};
|
2004-08-03 07:18:36 -04:00
|
|
|
#endif
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Use this method to obtain the wxPanel derived class to which you need to add your components. For example;<br>
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
\code
|
|
|
|
wxFoldPanel item = _pnl->AddFoldPanel(wxT("Test me"), false);
|
2004-08-03 10:33:49 -04:00
|
|
|
_pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), wxID_ANY, wxT("Press Me")));
|
2004-08-03 07:55:18 -04:00
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
wxFoldPanelItem *GetParent() const {
|
|
|
|
wxASSERT(_item);
|
|
|
|
return _item;
|
|
|
|
};
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#include <wx/dynarray.h>
|
2004-08-04 13:16:13 -04:00
|
|
|
WX_DEFINE_ARRAY_PTR(wxFoldPanelItem *, wxFoldPanelItemArray);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
/** \class wxFoldPanelBar
|
2004-08-03 07:55:18 -04:00
|
|
|
The wxFoldPanelBar is a class which can maintain a list of collapsable panels. Once a panel is collapsed, only
|
|
|
|
it's panel bar is visible to the user. This will provide more space for the other panels, or allow the user to
|
|
|
|
close panels which are not used often to get the most out of the work area.
|
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
This control is easy to use. Simply create it as a child for a panel or sash window, and populate panels with
|
2004-08-03 07:55:18 -04:00
|
|
|
wxFoldPanelBar::AddFoldPanel(). Then use the wxFoldPanelBar::AddFoldPanelWindow() to add wxWindow derived controls
|
2004-08-03 10:33:49 -04:00
|
|
|
to the current fold panel. Use wxFoldPanelBar::AddFoldPanelSeperator() to put separators between the groups of
|
2004-08-03 07:55:18 -04:00
|
|
|
controls that need a visual separator to group them together. After all is constructed, the user can fold
|
2004-08-03 10:33:49 -04:00
|
|
|
the panels by doubleclicking on the bar or single click on the arrow, which will indicate the collapsed or
|
2004-08-03 07:55:18 -04:00
|
|
|
expanded state.
|
2004-08-03 07:18:36 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
class wxFoldPanelBar: public wxPanel
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
DECLARE_CLASS( wxFoldPanelBar )
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
wxImageList *_images;
|
|
|
|
wxFoldPanelItemArray _panels;
|
|
|
|
wxBoxSizer* _panelSizer;
|
|
|
|
wxPanel *_foldPanel, *_bottomPanel;
|
|
|
|
wxFlexGridSizer* _mainSizer;
|
|
|
|
bool _controlCreated;
|
|
|
|
wxBitmap *_moreBmp;
|
|
|
|
int _extraStyle;
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
private:
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Refreshes all the panels from given index down to last one */
|
|
|
|
void RefreshPanelsFrom(size_t i);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Refreshes all the panels from given pointer down to last one in the list */
|
|
|
|
void RefreshPanelsFrom(wxFoldPanelItem *item);
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Returns the height of the panels that are expanded and collapsed. This is useful to determine
|
|
|
|
quickly what size is used to display, and what is left at the bottom to allign
|
|
|
|
the collapsed panels. */
|
|
|
|
int GetPanelsHeight(int &collapsed, int &expanded);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Reposition all the collapsed panels to the bottom. When it is not possible to
|
|
|
|
allign them to the bottom, stick them behind the visible panels. The Rect holds the
|
|
|
|
slack area left between last repositioned panel and the bottom panels. This needs to
|
|
|
|
get a refresh */
|
|
|
|
wxRect RepositionCollapsedToBottom();
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
public:
|
2004-08-03 10:33:49 -04:00
|
|
|
/** Two step constructor used for XRC. Use wxFoldPanelBar::Create() to create the panel. Do not call
|
2004-08-03 07:55:18 -04:00
|
|
|
any other methods before the control is fully created! */
|
2004-08-03 07:18:36 -04:00
|
|
|
wxFoldPanelBar();
|
|
|
|
/** One step creation. Look at wxPanel for the argument and style flags. The extraStyle flags are
|
|
|
|
- wxFPB_DEFAULT_EXTRASTYLE : Takes default styles.
|
|
|
|
- wxFPB_COLLAPSE_TO_BOTTOM : When panels are collapsed, they are put at the bottom of the area. */
|
2004-08-03 07:55:18 -04:00
|
|
|
wxFoldPanelBar( wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
2004-08-03 10:33:49 -04:00
|
|
|
const wxSize& size = wxDefaultSize, long style = wxFPB_DEFAULT_STYLE,
|
2004-08-03 07:55:18 -04:00
|
|
|
long extraStyle = wxFPB_DEFAULT_EXTRASTYLE);
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** wxFoldPanelBar destructor */
|
|
|
|
virtual ~wxFoldPanelBar();
|
2004-08-03 10:33:49 -04:00
|
|
|
|
|
|
|
/** Two step create call. Use this when the control is not created using the wxPanel derived constructor.
|
2004-08-03 07:55:18 -04:00
|
|
|
WARNING: Do not create this component more then once! */
|
2004-08-03 10:33:49 -04:00
|
|
|
virtual void Create( wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
2004-08-03 07:55:18 -04:00
|
|
|
const wxSize& size = wxDefaultSize, long style = wxFPB_DEFAULT_STYLE,
|
|
|
|
long extraStyle = wxFPB_DEFAULT_EXTRASTYLE);
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Adds a fold panel to the list of panels. If the flag collapsedInitially is set to true, the panel
|
2004-08-03 10:33:49 -04:00
|
|
|
is collapsed initially. The wxFoldPanel item which is returned, can be used as a reference to
|
2004-08-03 07:55:18 -04:00
|
|
|
perform actions upon the fold panel like collapsing it, expanding it, or deleting it from the list.
|
2004-08-03 10:33:49 -04:00
|
|
|
|
|
|
|
Use this foldpanel to add windows to it. Please consult wxFoldPanelBar::AddFoldPanelWindow() and
|
2004-08-03 07:55:18 -04:00
|
|
|
wxFoldPanelBar::AddFoldPanelSeparator() how to add wxWindow items to the panels. */
|
2004-08-03 10:33:49 -04:00
|
|
|
wxFoldPanel AddFoldPanel(const wxString &caption, bool collapsedInitially = false,
|
2004-08-03 07:55:18 -04:00
|
|
|
const wxCaptionBarStyle &style = wxEmptyCaptionBarStyle);
|
|
|
|
|
|
|
|
|
|
|
|
/** Adds a wxWindow derived class to the referenced wxFoldPanel. IMPORTANT: Make the to be created window,
|
|
|
|
child of the wxFoldPanel. See example that follows. The flags to be used are:
|
2004-08-03 10:33:49 -04:00
|
|
|
- wxFPB_ALIGN_WIDTH: Which means the wxWindow to be added will be alligned to fit the width of the
|
|
|
|
wxFoldPanel when it is resized. Very handy for sizer items, buttons and text boxes.
|
2004-08-03 07:18:36 -04:00
|
|
|
- wxFPB_ALIGN_LEFT: Alligns left instead of fitting the width of the child window to be added. Use either
|
|
|
|
this one or wxFPB_ALIGN_WIDTH.
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
The wxWindow to be added can be slightly indented from left and right so it is more visibly placed
|
|
|
|
in the wxFoldPanel. Use ySpacing > 0 to give the control an y offset from the previous wxWindow added,
|
|
|
|
use leftSpacing to give it a slight indent from the left, and rightSpacing also reserves a little space
|
2004-08-03 10:33:49 -04:00
|
|
|
on the right so the wxWindow can be properly placed in the wxFoldPanel.
|
2004-08-03 07:55:18 -04:00
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
The following example adds a wxFoldPanel to the wxFoldPanelBar and adds two wxWindow derived controls
|
2004-08-03 07:55:18 -04:00
|
|
|
to the wxFoldPanel:
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
|
|
|
// create the wxFoldPanelBar
|
|
|
|
_pnl = new wxFoldPanelBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, wxFPB_COLLAPSE_TO_BOTTOM);
|
|
|
|
|
|
|
|
// add a foldpanel to the control. "Test me" is the caption and it is initially not collapsed.
|
|
|
|
wxFoldPanel item = _pnl->AddFoldPanel(wxT("Test me"), false);
|
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
// now add a button to the fold panel. Mind that the button should be made child of the
|
|
|
|
// wxFoldPanel and not of the main form.
|
2004-08-03 07:55:18 -04:00
|
|
|
_pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, wxT("Collapse Me")));
|
|
|
|
|
|
|
|
// add a separator between the two controls. This is purely a visual line that can have a certain
|
|
|
|
// color and also the indents and width alligning like a control.
|
|
|
|
_pnl->AddFoldPanelSeperator(item);
|
|
|
|
|
|
|
|
// now add a text ctrl. Also very easy. Allign this on width so that when the control gets wider
|
|
|
|
// the text control also sizes along.
|
2004-08-03 10:33:49 -04:00
|
|
|
_pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, wxT("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20);
|
2004-08-03 07:55:18 -04:00
|
|
|
|
|
|
|
\endcode
|
|
|
|
*/
|
2004-08-03 10:33:49 -04:00
|
|
|
int AddFoldPanelWindow(const wxFoldPanel &panel, wxWindow *window, int flags = wxFPB_ALIGN_WIDTH,
|
|
|
|
int ySpacing = wxFPB_DEFAULT_YSPACING, int leftSpacing = wxFPB_DEFAULT_LEFTSPACING,
|
2004-08-03 07:55:18 -04:00
|
|
|
int rightSpacing = wxFPB_DEFAULT_RIGHTSPACING);
|
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
/** Adds a seperator line to the current wxFoldPanel. The seperator is a simple line which is drawn and is no
|
|
|
|
real component. It can be used to seperate groups of controls which belong to eachother. The colour is
|
2004-08-03 07:55:18 -04:00
|
|
|
adjustable, and it takes the same ySpacing, leftSpacing and rightSpacing as AddFoldPanelWindow(). */
|
2004-08-03 10:33:49 -04:00
|
|
|
int AddFoldPanelSeperator(const wxFoldPanel &panel, const wxColour &color = wxColour(167,167,167),
|
|
|
|
int ySpacing = wxFPB_DEFAULT_YSPACING, int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING,
|
2004-08-03 07:55:18 -04:00
|
|
|
int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING);
|
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
/** Returns the number of panels currently present in the wxFoldPanelBar. This is independent if they are
|
2004-08-03 07:55:18 -04:00
|
|
|
visible or hidden. */
|
|
|
|
size_t GetCount() const {
|
|
|
|
return _panels.GetCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Returns the wxFoldPanel reference belonging to the current index. An empty panel is returned when the
|
|
|
|
index is out of bounds. Use GetCount() to get the amount of panels present. Collapsing and folding the
|
|
|
|
panel does not change the order in which they are indexed. So it is safe enough to keep a reference
|
|
|
|
to the panel by number. */
|
|
|
|
wxFoldPanel Item(size_t i) {
|
2004-08-03 10:33:49 -04:00
|
|
|
wxCHECK((int)i >= 0 && i < GetCount(), wxFoldPanel(0));
|
2004-08-03 07:55:18 -04:00
|
|
|
return wxFoldPanel(_panels.Item(i));
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Collapses the given wxFoldPanel reference, and updates the foldpanel bar. In the wxFPB_COLLAPSE_TO_BOTTOM
|
|
|
|
style, all collapsed captions are put at the bottom of the control. In the normal mode, they stay where
|
|
|
|
they are */
|
|
|
|
void Collapse(const wxFoldPanel &item) {
|
|
|
|
wxCHECK2(item.IsOk(), return);
|
|
|
|
item.GetItem()->Collapse();
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
RefreshPanelsFrom(item.GetItem());
|
|
|
|
};
|
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
/** Expands the given wxFoldPanel reference, and updates the foldpanel bar. In the wxFPB_COLLAPSE_TO_BOTTOM
|
2004-08-03 07:55:18 -04:00
|
|
|
they will be removed from the bottom and the order where the panel originally was placed is restored. */
|
|
|
|
void Expand(const wxFoldPanel &item) {
|
|
|
|
wxCHECK2(item.IsOk(), return);
|
|
|
|
item.GetItem()->Expand();
|
2004-08-03 10:33:49 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
RefreshPanelsFrom(item.GetItem());
|
|
|
|
};
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
/** Sets the style of the caption bar (called wxCaptionBar) of the wxFoldPanel. The changes are applied immediately.
|
2004-08-03 07:55:18 -04:00
|
|
|
All styles not set in the wxCaptionBarStyle class are not applied. Use the wxCaptionBar reference to indicate
|
|
|
|
what captionbar you want to apply the style to. To apply one style to all wxCaptionBar items, use
|
|
|
|
ApplyCaptionStyleAll() */
|
|
|
|
void ApplyCaptionStyle(wxFoldPanel &fp, const wxCaptionBarStyle &style) {
|
|
|
|
wxCHECK2(fp.IsOk(), return);
|
|
|
|
fp.GetItem()->ApplyCaptionStyle(style);
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Sets the style of all the caption bars of the wxFoldPanel. The changes are applied immediately */
|
|
|
|
void ApplyCaptionStyleAll(const wxCaptionBarStyle &style) {
|
|
|
|
for(size_t i = 0; i < GetCount(); i++)
|
|
|
|
{
|
|
|
|
wxFoldPanel item = Item(i);
|
|
|
|
ApplyCaptionStyle(item, style);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-08-03 10:33:49 -04:00
|
|
|
/** Returns the currently used caption style for the wxFoldPanel. It is returned as a wxCaptionBarStyle class.
|
2004-08-03 07:55:18 -04:00
|
|
|
after modifying it, it can be set again */
|
|
|
|
wxCaptionBarStyle GetCaptionStyle(wxFoldPanel &fp) const {
|
|
|
|
wxCHECK2(fp.IsOk(), wxEmptyCaptionBarStyle);
|
|
|
|
return fp.GetItem()->GetCaptionStyle();
|
|
|
|
};
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
2004-08-03 07:55:18 -04:00
|
|
|
void OnPressCaption(wxCaptionBarEvent &event);
|
|
|
|
void OnSizePanel(wxSizeEvent &event);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
/** Resize the fold panels so they match the width */
|
|
|
|
void RedisplayFoldPanelItems();
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 07:55:18 -04:00
|
|
|
void OnPaint(wxPaintEvent &event);
|
2004-08-03 07:18:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __WXFOLDPANELBAR_H__
|