Full headers, Unicode markup, whitespaces, wxID_ANY, wxDefaultCoord conventions applied.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28600 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-08-03 11:55:18 +00:00
parent 957f5ab77a
commit c2a4197860
4 changed files with 742 additions and 712 deletions

View File

@@ -1,227 +1,238 @@
/////////////////////////////////////////////////////////////////////////////
// Name: captionbar.h
// Purpose: wxFoldPanel
// Author: Jorgen Bodde
// Modified by:
// Created: 22/06/2004
// RCS-ID: $Id$
// Copyright: (c) Jorgen Bodde
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __FOLDPANELBAR_H__ #ifndef __FOLDPANELBAR_H__
#define __FOLDPANELBAR_H__ #define __FOLDPANELBAR_H__
#define wxFPB_EXTRA_X 10 #define wxFPB_EXTRA_X 10
#define wxFPB_EXTRA_Y 4 #define wxFPB_EXTRA_Y 4
#define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space #define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space
enum enum
{ {
/** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient /** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient
starts with first colour, and ends with second colour */ starts with first colour, and ends with second colour */
wxCAPTIONBAR_GRADIENT_V = 1, wxCAPTIONBAR_GRADIENT_V = 1,
/** Specifies the gradient going from left to right. The gradient starts with first colour, and /** Specifies the gradient going from left to right. The gradient starts with first colour, and
ends with second colour on the right */ ends with second colour on the right */
wxCAPTIONBAR_GRADIENT_H, wxCAPTIONBAR_GRADIENT_H,
/** Fills the captionbar with a single colour. The first colour is used for this fill */ /** Fills the captionbar with a single colour. The first colour is used for this fill */
wxCAPTIONBAR_SINGLE, wxCAPTIONBAR_SINGLE,
/** Draws a rectangle only using the second colour. The first colour is not used*/ /** Draws a rectangle only using the second colour. The first colour is not used*/
wxCAPTIONBAR_RECTANGLE, wxCAPTIONBAR_RECTANGLE,
/** Fills the captionbar with a single colour (first colour) and draws a rectangle around it /** Fills the captionbar with a single colour (first colour) and draws a rectangle around it
using the second colour. */ using the second colour. */
wxCAPTIONBAR_FILLED_RECTANGLE wxCAPTIONBAR_FILLED_RECTANGLE
}; };
/** \class wxCaptionBarStyle /** \class wxCaptionBarStyle
This class encapsulates the styles you wish to set for the wxCaptionBar (this is the part of the wxFoldPanel This class encapsulates the styles you wish to set for the wxCaptionBar (this is the part of the wxFoldPanel
where the caption is displayed). It can either be applied at creation time be reapplied when styles need to where the caption is displayed). It can either be applied at creation time be reapplied when styles need to
be changed. be changed.
At construction time, all styles are set to their default transparency. This means none of the styles will be At construction time, all styles are set to their default transparency. This means none of the styles will be
applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e
the color, font or panel style, these styles become active to be used. the color, font or panel style, these styles become active to be used.
*/ */
class wxCaptionBarStyle class wxCaptionBarStyle
{ {
private: private:
// boolean flags for default transparency on styles // boolean flags for default transparency on styles
bool _firstColourUsed, bool _firstColourUsed,
_secondColourUsed, _secondColourUsed,
_textColourUsed, _textColourUsed,
_captionFontUsed, _captionFontUsed,
_captionStyleUsed; _captionStyleUsed;
wxFont _captionFont; wxFont _captionFont;
wxColour _firstColour, _secondColour, _textColour; wxColour _firstColour, _secondColour, _textColour;
int _captionStyle; int _captionStyle;
public: public:
/** Default constructor for this class */ /** Default constructor for this class */
wxCaptionBarStyle() { wxCaptionBarStyle() {
ResetDefaults(); ResetDefaults();
}; };
~wxCaptionBarStyle() { ~wxCaptionBarStyle() {
}; };
void ResetDefaults() { void ResetDefaults() {
_firstColourUsed = false; _firstColourUsed = false;
_secondColourUsed = false; _secondColourUsed = false;
_textColourUsed = false; _textColourUsed = false;
_captionFontUsed = false; _captionFontUsed = false;
_captionStyleUsed = false; _captionStyleUsed = false;
_captionStyle = wxCAPTIONBAR_GRADIENT_V; _captionStyle = wxCAPTIONBAR_GRADIENT_V;
}; };
/** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other
styles are not copied */ styles are not copied */
void operator=(const wxCaptionBarStyle &s) { void operator=(const wxCaptionBarStyle &s) {
if(s._captionStyleUsed) if(s._captionStyleUsed)
{ {
_captionStyleUsed = true; _captionStyleUsed = true;
_captionStyle = s._captionStyle; _captionStyle = s._captionStyle;
} }
if(s._captionFontUsed) if(s._captionFontUsed)
{ {
_captionFontUsed = true; _captionFontUsed = true;
_captionFont = s._captionFont; _captionFont = s._captionFont;
} }
if(s._firstColourUsed) if(s._firstColourUsed)
{ {
_firstColourUsed = true; _firstColourUsed = true;
_firstColour = s._firstColour; _firstColour = s._firstColour;
} }
if(s._secondColourUsed) if(s._secondColourUsed)
{ {
_secondColourUsed = true; _secondColourUsed = true;
_secondColour = s._secondColour; _secondColour = s._secondColour;
} }
if(s._textColourUsed) if(s._textColourUsed)
{ {
_textColourUsed = true; _textColourUsed = true;
_textColour = s._textColour; _textColour = s._textColour;
} }
}; };
// ------- CaptionBar Font ------- // ------- CaptionBar Font -------
/** Set font for the caption bar. If this is not set, the font property is undefined /** Set font for the caption bar. If this is not set, the font property is undefined
and will not be used. Use CaptionFontUsed() to check if this style is used */ and will not be used. Use CaptionFontUsed() to check if this style is used */
void SetCaptionFont(const wxFont &font) { void SetCaptionFont(const wxFont &font) {
_captionFont = font; _captionFont = font;
_captionFontUsed = true; _captionFontUsed = true;
}; };
/** Checks if the caption bar font is set */ /** Checks if the caption bar font is set */
bool CaptionFontUsed() const { bool CaptionFontUsed() const {
return _captionFontUsed; return _captionFontUsed;
}; };
/** Returns the font for the caption bar. Please be warned this will result in an assertion failure when /** Returns the font for the caption bar. Please be warned this will result in an assertion failure when
this property is not previously set this property is not previously set
\sa SetCaptionFont(), CaptionFontUsed() */ \sa SetCaptionFont(), CaptionFontUsed() */
wxFont GetCaptionFont() const { wxFont GetCaptionFont() const {
wxASSERT(_captionFontUsed); wxASSERT(_captionFontUsed);
return _captionFont; return _captionFont;
}; };
// ------- FirstColour ------- // ------- FirstColour -------
/** Set first colour for the caption bar. If this is not set, the colour property is /** Set first colour for the caption bar. If this is not set, the colour property is
undefined and will not be used. Use FirstColourUsed() to check if this undefined and will not be used. Use FirstColourUsed() to check if this
style is used */ style is used */
void SetFirstColour(const wxColour &col) { void SetFirstColour(const wxColour &col) {
_firstColour = col; _firstColour = col;
_firstColourUsed = true; _firstColourUsed = true;
}; };
/** Checks if the first colour of the caption bar is set */ /** Checks if the first colour of the caption bar is set */
bool FirstColourUsed() const { bool FirstColourUsed() const {
return _firstColourUsed; return _firstColourUsed;
}; };
/** Returns the first colour for the caption bar. Please be warned this will /** Returns the first colour for the caption bar. Please be warned this will
result in an assertion failure when this property is not previously set. result in an assertion failure when this property is not previously set.
\sa SetCaptionFirstColour(), CaptionFirstColourUsed() */ \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */
wxColour GetFirstColour() const { wxColour GetFirstColour() const {
wxASSERT(_firstColourUsed); wxASSERT(_firstColourUsed);
return _firstColour; return _firstColour;
}; };
// ------- SecondColour ------- // ------- SecondColour -------
/** Set second colour for the caption bar. If this is not set, the colour property is undefined and /** Set second colour for the caption bar. If this is not set, the colour property is undefined and
will not be used. Use SecondColourUsed() to check if this style is used */ will not be used. Use SecondColourUsed() to check if this style is used */
void SetSecondColour(const wxColour &col) { void SetSecondColour(const wxColour &col) {
_secondColour = col; _secondColour = col;
_secondColourUsed = true; _secondColourUsed = true;
}; };
/** Checks if the second colour of the caption bar is set */ /** Checks if the second colour of the caption bar is set */
bool SecondColourUsed() const { bool SecondColourUsed() const {
return _secondColourUsed; return _secondColourUsed;
}; };
/** Returns the second colour for the caption bar. Please be warned this will result in /** Returns the second colour for the caption bar. Please be warned this will result in
an assertion failure when this property is not previously set. an assertion failure when this property is not previously set.
\sa SetSecondColour(), SecondColourUsed() */ \sa SetSecondColour(), SecondColourUsed() */
wxColour GetSecondColour() const { wxColour GetSecondColour() const {
wxASSERT(_secondColourUsed); wxASSERT(_secondColourUsed);
return _secondColour; return _secondColour;
}; };
// ------- Caption Text Colour ------- // ------- Caption Text Colour -------
/** Set caption colour for the caption bar. If this is not set, the colour property is /** Set caption colour for the caption bar. If this is not set, the colour property is
undefined and will not be used. Use CaptionColourUsed() to check if this style is used */ undefined and will not be used. Use CaptionColourUsed() to check if this style is used */
void SetCaptionColour(const wxColour &col) { void SetCaptionColour(const wxColour &col) {
_textColour = col; _textColour = col;
_textColourUsed = true; _textColourUsed = true;
}; };
/** Checks if the caption colour of the caption bar is set */ /** Checks if the caption colour of the caption bar is set */
bool CaptionColourUsed() const { bool CaptionColourUsed() const {
return _textColourUsed; return _textColourUsed;
}; };
/** Returns the caption colour for the caption bar. Please be warned this will /** Returns the caption colour for the caption bar. Please be warned this will
result in an assertion failure when this property is not previously set. result in an assertion failure when this property is not previously set.
\sa SetCaptionColour(), CaptionColourUsed() */ \sa SetCaptionColour(), CaptionColourUsed() */
wxColour GetCaptionColour() const { wxColour GetCaptionColour() const {
wxASSERT(_textColourUsed); wxASSERT(_textColourUsed);
return _textColour; return _textColour;
}; };
// ------- CaptionStyle ------- // ------- CaptionStyle -------
/** Set caption style for the caption bar. If this is not set, the property is /** Set caption style for the caption bar. If this is not set, the property is
undefined and will not be used. Use CaptionStyleUsed() to check if this style is used. undefined and will not be used. Use CaptionStyleUsed() to check if this style is used.
The following styles can be applied: The following styles can be applied:
- wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom - wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom
- wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right - wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right
- wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption - wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption
- wxCAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption - wxCAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption
- wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it - wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it
*/ */
void SetCaptionStyle(int style) { void SetCaptionStyle(int style) {
_captionStyle = style; _captionStyle = style;
_captionStyleUsed = true; _captionStyleUsed = true;
}; };
/** Checks if the caption style of the caption bar is set */ /** Checks if the caption style of the caption bar is set */
bool CaptionStyleUsed() const { bool CaptionStyleUsed() const {
return _captionStyleUsed; return _captionStyleUsed;
}; };
/** Returns the caption style for the caption bar. Please be warned this will /** Returns the caption style for the caption bar. Please be warned this will
result in an assertion failure when this property is not previously set. result in an assertion failure when this property is not previously set.
\sa SetCaptionStyle(), CaptionStyleUsed() */ \sa SetCaptionStyle(), CaptionStyleUsed() */
int GetCaptionStyle() const { int GetCaptionStyle() const {
wxASSERT(_captionStyleUsed); wxASSERT(_captionStyleUsed);
return _captionStyle; return _captionStyle;
}; };
}; };
#ifndef _NO_CAPTIONBAR_ #ifndef _NO_CAPTIONBAR_
/** \class wxCaptionBar /** \class wxCaptionBar
This class is a graphical caption component that consists of a caption and a clickable arrow. This class is a graphical caption component that consists of a caption and a clickable arrow.
The wxCaptionBar fires an event EVT_CAPTIONBAR which is a wxCaptionBarEvent. This event can be caught The wxCaptionBar fires an event EVT_CAPTIONBAR which is a wxCaptionBarEvent. This event can be caught
and the parent window can act upon the collapsed or expanded state of the bar (which is actually just and the parent window can act upon the collapsed or expanded state of the bar (which is actually just
the icon which changed). The parent panel can reduce size or expand again. the icon which changed). The parent panel can reduce size or expand again.
*/ */
#include <wx/imaglist.h> #include <wx/imaglist.h>
@@ -232,134 +243,134 @@ public:
class wxCaptionBar: public wxWindow class wxCaptionBar: public wxWindow
{ {
private: private:
wxString _caption; wxString _caption;
wxImageList *_foldIcons; wxImageList *_foldIcons;
wxSize _oldSize; wxSize _oldSize;
//wxFont _captionFont; //wxFont _captionFont;
int _rightIndent; int _rightIndent;
int _iconWidth, _iconHeight; int _iconWidth, _iconHeight;
//int _captionStyle; //int _captionStyle;
//wxColour _firstColour, _secondColour, _textColour; //wxColour _firstColour, _secondColour, _textColour;
/** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */ /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
bool _collapsed; bool _collapsed;
wxCaptionBarStyle _style; wxCaptionBarStyle _style;
/** Fills the background of the caption with either a gradient, or a solid color */ /** Fills the background of the caption with either a gradient, or a solid color */
void FillCaptionBackground(wxPaintDC &dc); void FillCaptionBackground(wxPaintDC &dc);
/* Draw methods */ /* Draw methods */
void DrawHorizontalGradient(wxDC &dc, const wxRect &rect ); void DrawHorizontalGradient(wxDC &dc, const wxRect &rect );
void DrawVerticalGradient(wxDC &dc, const wxRect &rect ); void DrawVerticalGradient(wxDC &dc, const wxRect &rect );
void DrawSingleColour(wxDC &dc, const wxRect &rect ); void DrawSingleColour(wxDC &dc, const wxRect &rect );
void DrawSingleRectangle(wxDC &dc, const wxRect &rect ); void DrawSingleRectangle(wxDC &dc, const wxRect &rect );
void RedrawIconBitmap(); void RedrawIconBitmap();
void ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault); void ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault);
public: public:
/** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list /** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list
which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to
represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */ represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */
wxCaptionBar(wxWindow* parent, const wxString &caption, wxImageList *images, wxCaptionBar(wxWindow* parent, const wxString &caption, wxImageList *images,
wxWindowID id = -1, const wxCaptionBarStyle &cbstyle = wxEmptyCaptionBarStyle, wxWindowID id = wxID_ANY, const wxCaptionBarStyle &cbstyle = wxEmptyCaptionBarStyle,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxNO_BORDER); const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxNO_BORDER);
~wxCaptionBar(); ~wxCaptionBar();
/** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you /** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you
set applyDefault to true, all other (not defined) styles will be set to default. If it is false, set applyDefault to true, all other (not defined) styles will be set to default. If it is false,
the styles which are not set in the wxCaptionBarStyle will be ignored */ the styles which are not set in the wxCaptionBarStyle will be ignored */
void SetCaptionStyle(bool applyDefault, wxCaptionBarStyle style = wxEmptyCaptionBarStyle) { void SetCaptionStyle(bool applyDefault, wxCaptionBarStyle style = wxEmptyCaptionBarStyle) {
ApplyCaptionStyle(style, applyDefault); ApplyCaptionStyle(style, applyDefault);
Refresh(); Refresh();
}; };
/** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
changes. */ changes. */
wxCaptionBarStyle GetCaptionStyle() { wxCaptionBarStyle GetCaptionStyle() {
return _style; return _style;
}; };
#if 0 #if 0
/** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap. /** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap.
The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will
be used and if they all have their own bitmap resources it will eat up more memory then needed. It will be used and if they all have their own bitmap resources it will eat up more memory then needed. It will
also ease the use of shared icon change, when there is any need to. also ease the use of shared icon change, when there is any need to.
If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel
will work to collapse / expand. will work to collapse / expand.
The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the
collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and
widht is calculated. widht is calculated.
The bitmaps must be the second thing to be done before using it (SetRightIndent should be the first thing), The bitmaps must be the second thing to be done before using it (SetRightIndent should be the first thing),
make sure if the icons are larger than the font, that the parent of this window gets a Fit call to resize make sure if the icons are larger than the font, that the parent of this window gets a Fit call to resize
all the windows accordingly */ all the windows accordingly */
void SetFoldIcons(wxImageList *images) { void SetFoldIcons(wxImageList *images) {
_foldIcons = images; _foldIcons = images;
_iconWidth = _iconHeight = 0; _iconWidth = _iconHeight = 0;
if(_foldIcons) if(_foldIcons)
_foldIcons->GetSize(0, _iconWidth, _iconHeight); _foldIcons->GetSize(0, _iconWidth, _iconHeight);
Refresh(); Refresh();
}; };
#endif #endif
/** Returns wether the status of the bar is expanded or collapsed */ /** Returns wether the status of the bar is expanded or collapsed */
bool IsCollapsed() const { bool IsCollapsed() const {
return _collapsed; return _collapsed;
}; };
/** Sets the amount of pixels on the right from which the bitmap is trailing. If this is 0, it will be /** Sets the amount of pixels on the right from which the bitmap is trailing. If this is 0, it will be
drawn all the way to the right, default is equal to wxFPB_BMP_RIGHTSPACE. Assign this before drawn all the way to the right, default is equal to wxFPB_BMP_RIGHTSPACE. Assign this before
assigning an image list to prevent a redraw */ assigning an image list to prevent a redraw */
void SetRightIndent(int pixels) { void SetRightIndent(int pixels) {
wxCHECK2(pixels >= 0, return); wxCHECK2(pixels >= 0, return);
_rightIndent = pixels; _rightIndent = pixels;
// issue a refresh (if we have a bmp) // issue a refresh (if we have a bmp)
if(_foldIcons) if(_foldIcons)
Refresh(); Refresh();
}; };
/** Return the best size for this panel, based upon the font assigned to this window, and the /** Return the best size for this panel, based upon the font assigned to this window, and the
caption string */ caption string */
wxSize DoGetBestSize() const; wxSize DoGetBestSize() const;
/** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent
to be sent to the parent */ to be sent to the parent */
void Collapse() { void Collapse() {
_collapsed = true; _collapsed = true;
RedrawIconBitmap(); RedrawIconBitmap();
}; };
/** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent
to be sent to the parent */ to be sent to the parent */
void Expand() { void Expand() {
_collapsed = false; _collapsed = false;
RedrawIconBitmap(); RedrawIconBitmap();
}; };
void SetBoldFont() { void SetBoldFont() {
GetFont().SetWeight(wxBOLD); GetFont().SetWeight(wxBOLD);
}; };
void SetNormalFont() { void SetNormalFont() {
GetFont().SetWeight(wxNORMAL); GetFont().SetWeight(wxNORMAL);
}; };
private: private:
/** The paint event for flat or gradient fill */ /** The paint event for flat or gradient fill */
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
/** For clicking the icon, the mouse event must be intercepted */ /** For clicking the icon, the mouse event must be intercepted */
void OnMouseEvent(wxMouseEvent& event); void OnMouseEvent(wxMouseEvent& event);
@@ -367,7 +378,7 @@ private:
/** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */ /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
protected: protected:
@@ -378,60 +389,60 @@ protected:
/***********************************************************************************************************/ /***********************************************************************************************************/
/** \class wxCaptionBarEvent /** \class wxCaptionBarEvent
This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent
that the bar is now in collapsed or expanded state. The parent should re-arrange the associated that the bar is now in collapsed or expanded state. The parent should re-arrange the associated
windows accordingly */ windows accordingly */
class WXDLLEXPORT wxCaptionBarEvent : public wxCommandEvent class WXDLLEXPORT wxCaptionBarEvent : public wxCommandEvent
{ {
private: private:
bool _collapsed; bool _collapsed;
wxCaptionBar *_bar; wxCaptionBar *_bar;
void *_tag; void *_tag;
public: public:
wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0) wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
: wxCommandEvent(commandType, id) : wxCommandEvent(commandType, id)
, _collapsed(false) , _collapsed(false)
, _bar(0) , _bar(0)
, _tag(0) , _tag(0)
{ } { }
/** Constructor for clone copy */ /** Constructor for clone copy */
wxCaptionBarEvent(const wxCaptionBarEvent &event); wxCaptionBarEvent(const wxCaptionBarEvent &event);
/** Clone function */ /** Clone function */
virtual wxEvent *Clone() const { virtual wxEvent *Clone() const {
return new wxCaptionBarEvent(*this); return new wxCaptionBarEvent(*this);
}; };
/** Returns wether the bar is expanded or collapsed. True means expanded */ /** Returns wether the bar is expanded or collapsed. True means expanded */
bool GetFoldStatus() const { bool GetFoldStatus() const {
wxCHECK(_bar, false); wxCHECK(_bar, false);
return !_bar->IsCollapsed(); return !_bar->IsCollapsed();
}; };
/** Returns the bar associated with this event */ /** Returns the bar associated with this event */
wxCaptionBar *GetBar() const { wxCaptionBar *GetBar() const {
return _bar; return _bar;
}; };
void SetTag(void *tag) { void SetTag(void *tag) {
_tag = tag; _tag = tag;
}; };
void *GetTag() const { void *GetTag() const {
return _tag; return _tag;
}; };
/** Sets the bar associated with this event, should not used /** Sets the bar associated with this event, should not used
by any other then the originator of the event */ by any other then the originator of the event */
void SetBar(wxCaptionBar *bar) { void SetBar(wxCaptionBar *bar) {
_bar = bar; _bar = bar;
}; };
DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent) DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent)
}; };
@@ -443,7 +454,7 @@ typedef void (wxEvtHandler::*wxCaptionBarEventFunction)(wxCaptionBarEvent&);
#define EVT_CAPTIONBAR(id, fn) \ #define EVT_CAPTIONBAR(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \ DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_CAPTIONBAR, id, -1, \ wxEVT_CAPTIONBAR, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction)(wxCaptionBarEventFunction) \ (wxObjectEventFunction)(wxEventFunction)(wxCaptionBarEventFunction) \
& fn, \ & fn, \
(wxObject *) NULL \ (wxObject *) NULL \

View File

@@ -1,55 +1,66 @@
/////////////////////////////////////////////////////////////////////////////
// Name: doc_mainpage.h
// Purpose: wxFoldPanel
// Author: Jorgen Bodde
// Modified by:
// Created: 22/06/2004
// RCS-ID: $Id$
// Copyright: (c) Jorgen Bodde
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/** \author Jorgen Bodde /** \author Jorgen Bodde
\mainpage \mainpage
This is the wxFoldPanel documentation guide. This control is written for wxWidgets (http://www.wxwidgets.com), and
can be used as a side bar with managed panels which can collapse and expand.
The wxFoldPanelBar is very easy in it's use and allows great flexibility in manipulating it even after creation. It can
be created in two modes:
- In place folding: This means that the panels which are collapsed, stay where they are.
- To bottom folding: This means that the panels are collapsed to the bottom
The caption bars are managed by another stand alone control (which I will fix up to be released soon), called the
wxCaptionBar. You as user don't have to do much with this control right now, all styles are rerouted through the
wxFoldPanelBar. The only class of interest is wxCaptionBarStyle which takes care of the visual style of the
bar. The caption bar can be drawn in the following modes:
- Gradient horizontal fill
- Gradient vertical fill
- Single flat colour
- Single colour with border
- Single border with background fill
wxFoldPanelBar is freeware and distributed under the wxWidgets license. wxWidgets is THE toolkit for
(cross platform) C++ / Python programming!
\section things_done Things to be done This is the wxFoldPanel documentation guide. This control is written for wxWidgets (http://www.wxwidgets.com), and
can be used as a side bar with managed panels which can collapse and expand.
I would like to add the following features when time allows me. When you really like one of these features to be in the
next release, you can either make that clear to me, or help me with it. They aren't that hard.
- Single fold which means all other panels are collapsed automatically
- Smart size of panels when only one is open, take the whole space, or use sizers to proportionally size
- Small icons next to the caption for clarity and make it a bit more visually nice
- A bottom bar with visual icon when the bar cannot be completely shown to aid the user that there is more then can be seen
- Panels can be hidden. This feature will also need the bottom bar, so that the icons of hidden panels will apear there
- Resizable panels, the user can manually size the panels bigger or smaller
\section how_work How does it work? The wxFoldPanelBar is very easy in it's use and allows great flexibility in manipulating it even after creation. It can
be created in two modes:
The internals of the wxFoldPanelBar is a list of wxFoldPanelItem classes. Through the reference of wxFoldPanel these
panels can be controlled by adding new controls to a wxFoldPanel or adding new wxFoldPanels to the wxFoldPanelBar. The - In place folding: This means that the panels which are collapsed, stay where they are.
wxCaptionBar fires events to the parent (container of all panel items) when a sub-panel needs resizing (either folding - To bottom folding: This means that the panels are collapsed to the bottom
or expanding). The fold or expand process is simply a resize of the panel so it looks like all controls on it are gone.
All controls are still child of the wxFoldPanel they are located on. If they don't handle the event (and they won't) The caption bars are managed by another stand alone control (which I will fix up to be released soon), called the
then the owner of the wxFoldPanelBar gets the events. This is what you need to handle the controls. There isn't much to it wxCaptionBar. You as user don't have to do much with this control right now, all styles are rerouted through the
just a lot of calculations to see what panel belongs where. There are no sizers involved in the panels, everything is wxFoldPanelBar. The only class of interest is wxCaptionBarStyle which takes care of the visual style of the
purely xy positioning. bar. The caption bar can be drawn in the following modes:
\section what_dp What can it do and what not? - Gradient horizontal fill
- Gradient vertical fill
What it can do: - Single flat colour
- Single colour with border
- Single border with background fill
wxFoldPanelBar is freeware and distributed under the wxWidgets license. wxWidgets is THE toolkit for
(cross platform) C++ / Python programming!
\section things_done Things to be done
I would like to add the following features when time allows me. When you really like one of these features to be in the
next release, you can either make that clear to me, or help me with it. They aren't that hard.
- Single fold which means all other panels are collapsed automatically
- Smart size of panels when only one is open, take the whole space, or use sizers to proportionally size
- Small icons next to the caption for clarity and make it a bit more visually nice
- A bottom bar with visual icon when the bar cannot be completely shown to aid the user that there is more then can be seen
- Panels can be hidden. This feature will also need the bottom bar, so that the icons of hidden panels will apear there
- Resizable panels, the user can manually size the panels bigger or smaller
\section how_work How does it work?
The internals of the wxFoldPanelBar is a list of wxFoldPanelItem classes. Through the reference of wxFoldPanel these
panels can be controlled by adding new controls to a wxFoldPanel or adding new wxFoldPanels to the wxFoldPanelBar. The
wxCaptionBar fires events to the parent (container of all panel items) when a sub-panel needs resizing (either folding
or expanding). The fold or expand process is simply a resize of the panel so it looks like all controls on it are gone.
All controls are still child of the wxFoldPanel they are located on. If they don't handle the event (and they won't)
then the owner of the wxFoldPanelBar gets the events. This is what you need to handle the controls. There isn't much to it
just a lot of calculations to see what panel belongs where. There are no sizers involved in the panels, everything is
purely xy positioning.
\section what_dp What can it do and what not?
What it can do:
- Run-time addition of panels (no deletion just yet) - Run-time addition of panels (no deletion just yet)
- Run time addition of controls to the panel (it will be resized accordingly) - Run time addition of controls to the panel (it will be resized accordingly)
@@ -57,12 +68,12 @@
- Various modes of caption behaviour and filling to make it more appealing - Various modes of caption behaviour and filling to make it more appealing
- Panels can be folded and collapsed (or all of them) to allow more space - Panels can be folded and collapsed (or all of them) to allow more space
What it cannot do: What it cannot do:
- Selection of a panel like in a list ctrl - Selection of a panel like in a list ctrl
- Dragging and dropping the panels - Dragging and dropping the panels
- Re-ordering the panels (not yet) - Re-ordering the panels (not yet)
Special thanks to Julian Smart et al. for making this great toolkit! Special thanks to Julian Smart et al. for making this great toolkit!
*/ */

View File

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

View File

@@ -1,8 +1,12 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wxFoldPanelItem.h // Name: foldpanelitem.h
// Author: XX // Purpose: wxFoldPanel
// Created: Tuesday, June 22, 2004 21:01:02 // Author: Jorgen Bodde
// Copyright: XX // Modified by:
// Created: 22/06/2004
// RCS-ID: $Id$
// Copyright: (c) Jorgen Bodde
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __WXFOLDPANELITEM_H__ #ifndef __WXFOLDPANELITEM_H__
@@ -27,119 +31,119 @@
class wxFoldWindowItem class wxFoldWindowItem
{ {
private: private:
wxWindow *_wnd; wxWindow *_wnd;
int _type, _flags; int _type, _flags;
int _leftSpacing, int _leftSpacing,
_rightSpacing, _rightSpacing,
_ySpacing; _ySpacing;
int _lineWidth, _lineY; int _lineWidth, _lineY;
wxColour _sepLineColour; wxColour _sepLineColour;
public: public:
enum enum
{ {
WINDOW = 0, WINDOW = 0,
SEPARATOR SEPARATOR
}; };
// wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int ySpacing = wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing = wxFPB_DEFAULT_RIGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _ySpacing(ySpacing)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _flags(flags)
, _lineWidth(0)
, _lineY(0)
{
};
// separator constructor. This initialises the class as a separator type // wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int ySpacing = wxFPB_DEFAULT_YSPACING, wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int ySpacing = wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING, int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing = wxFPB_DEFAULT_RIGHTSPACING)
int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING) : _wnd(wnd)
: _wnd(0) , _type(WINDOW)
, _type(SEPARATOR) , _ySpacing(ySpacing)
, _ySpacing(ySpacing) , _leftSpacing(leftSpacing)
, _leftSpacing(leftSpacing) , _rightSpacing(rightSpacing)
, _rightSpacing(rightSpacing) , _flags(flags)
, _flags(wxFPB_ALIGN_WIDTH) , _lineWidth(0)
, _sepLineColour(lineColor) , _lineY(0)
, _lineWidth(0) {
, _lineY(y) };
{
};
// TODO: Make a c'tor for a captioned splitter // separator constructor. This initialises the class as a separator type
wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int ySpacing = wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING)
: _wnd(0)
, _type(SEPARATOR)
, _ySpacing(ySpacing)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _flags(wxFPB_ALIGN_WIDTH)
, _sepLineColour(lineColor)
, _lineWidth(0)
, _lineY(y)
{
};
int GetType() const { // TODO: Make a c'tor for a captioned splitter
return _type;
};
int GetLineY() const { int GetType() const {
return _lineY; return _type;
}; };
int GetLineWidth() const { int GetLineY() const {
return _lineWidth; return _lineY;
}; };
const wxColour &GetLineColour() const { int GetLineWidth() const {
return _sepLineColour; return _lineWidth;
}; };
int GetLeftSpacing() const { const wxColour &GetLineColour() const {
return _leftSpacing; return _sepLineColour;
}; };
int GetRightSpacing() const { int GetLeftSpacing() const {
return _rightSpacing; return _leftSpacing;
}; };
int GetYSpacing() const { int GetRightSpacing() const {
return _ySpacing; return _rightSpacing;
}; };
// returns the window height if type is wxFoldWindowItem::WINDOW int GetYSpacing() const {
// and returns the total size plus the extra spacing return _ySpacing;
};
int GetWindowHeight() const { // returns the window height if type is wxFoldWindowItem::WINDOW
int value = 0; // and returns the total size plus the extra spacing
if(_type == WINDOW)
{
wxCHECK(_wnd, 0);
wxSize size = _wnd->GetSize();
value = size.GetHeight() + _ySpacing;
}
else if(_type == SEPARATOR)
value = 1 + _ySpacing;
return value; int GetWindowHeight() const {
}; int value = 0;
if(_type == WINDOW)
{
wxCHECK(_wnd, 0);
wxSize size = _wnd->GetSize();
value = size.GetHeight() + _ySpacing;
}
else if(_type == SEPARATOR)
value = 1 + _ySpacing;
// resize the element, whatever it is. A separator or return value;
// line will be always alligned by width };
void ResizeItem(int width) { // resize the element, whatever it is. A separator or
if((_flags & wxFPB_ALIGN_WIDTH)) // line will be always alligned by width
{
// allign by taking full width void ResizeItem(int width) {
int myWidth = width - _leftSpacing - _rightSpacing; if((_flags & wxFPB_ALIGN_WIDTH))
{
if(myWidth < 0) // allign by taking full width
myWidth = 10; // can't have negative width int myWidth = width - _leftSpacing - _rightSpacing;
if(_type == SEPARATOR) if(myWidth < 0)
_lineWidth = myWidth; myWidth = 10; // can't have negative width
else
{ if(_type == SEPARATOR)
wxCHECK2(_wnd, return); _lineWidth = myWidth;
_wnd->SetSize(wxSize(myWidth, -1)); else
} {
} wxCHECK2(_wnd, return);
}; _wnd->SetSize(wxSize(myWidth, wxDefaultCoord));
}
}
};
}; };
@@ -150,104 +154,104 @@ WX_DECLARE_OBJARRAY(wxFoldWindowItem, wxFoldWindowItemArray);
/** \wxFoldPanelItem /** \wxFoldPanelItem
This class is a child sibling of the wxFoldPanelBar class. It will be containing a wxCaptionBar class This class is a child sibling of the wxFoldPanelBar class. It will be containing a wxCaptionBar class
for receiving of events, and a the rest of the area can be populated by a wxPanel derived class. for receiving of events, and a the rest of the area can be populated by a wxPanel derived class.
*/ */
class wxFoldPanelItem: public wxPanel class wxFoldPanelItem: public wxPanel
{ {
private: private:
wxCaptionBar *_captionBar; wxCaptionBar *_captionBar;
bool _controlCreated; bool _controlCreated;
int _yUserSize, int _yUserSize,
_yPanelSize, _yPanelSize,
_yLastInsertPos; _yLastInsertPos;
int _yPos; int _yPos;
bool _userSized; bool _userSized;
private: private:
DECLARE_CLASS( wxFoldPanelItem ) DECLARE_CLASS( wxFoldPanelItem )
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private: private:
wxFoldWindowItemArray _items; wxFoldWindowItemArray _items;
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
void OnPressCaption(wxCaptionBarEvent &event); void OnPressCaption(wxCaptionBarEvent &event);
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
public: public:
// constructors and destructors // constructors and destructors
wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons = 0, bool collapsedInitially = false, wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons = 0, bool collapsedInitially = false,
const wxCaptionBarStyle &style = wxEmptyCaptionBarStyle); const wxCaptionBarStyle &style = wxEmptyCaptionBarStyle);
virtual ~wxFoldPanelItem(); virtual ~wxFoldPanelItem();
/** Add a window item to the list of items on this panel. The flags are wxFPB_ALIGN_LEFT for a non sizing /** Add a window item to the list of items on this panel. The flags are wxFPB_ALIGN_LEFT for a non sizing
window element, and wxFPB_ALIGN_WIDTH for a width alligned item. The ySpacing parameter reserves a number window element, and wxFPB_ALIGN_WIDTH for a width alligned item. The ySpacing parameter reserves a number
of pixels before the window element, and leftSpacing is an indent. rightSpacing is only relevant when the of pixels before the window element, and leftSpacing is an indent. rightSpacing is only relevant when the
style wxFPB_ALIGN_WIDTH is chosen. */ style wxFPB_ALIGN_WIDTH is chosen. */
void AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing); void AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing);
void AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing); void AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing);
/** Repositions this wxFoldPanelBar and reports the height occupied for the next wxFoldPanelBar in the /** Repositions this wxFoldPanelBar and reports the height occupied for the next wxFoldPanelBar in the
list */ list */
int Reposition(int y); int Reposition(int y);
void ResizePanel(); void ResizePanel();
/** Return expanded or collapsed status. If the panel is expanded, true is returned */ /** Return expanded or collapsed status. If the panel is expanded, true is returned */
bool IsExpanded() const { bool IsExpanded() const {
return !_captionBar->IsCollapsed(); return !_captionBar->IsCollapsed();
}; };
/** Return Y pos */ /** Return Y pos */
int GetY() const { int GetY() const {
return _yPos; return _yPos;
}; };
// this should not be called by the user, because it doesn't trigger the parent // this should not be called by the user, because it doesn't trigger the parent
// to tell it that we are collapsed or expanded, it only changes visual state // to tell it that we are collapsed or expanded, it only changes visual state
void Collapse() { void Collapse() {
_captionBar->Collapse(); _captionBar->Collapse();
ResizePanel(); ResizePanel();
}; };
// this should not be called by the user, because it doesn't trigger the parent // this should not be called by the user, because it doesn't trigger the parent
// to tell it that we are collapsed or expanded, it only changes visual state // to tell it that we are collapsed or expanded, it only changes visual state
void Expand() { void Expand() {
_captionBar->Expand(); _captionBar->Expand();
ResizePanel(); ResizePanel();
}; };
/* Return size of panel */ /* Return size of panel */
int GetPanelHeight() const { int GetPanelHeight() const {
if(_captionBar->IsCollapsed()) if(_captionBar->IsCollapsed())
return GetCaptionHeight(); return GetCaptionHeight();
else if(_userSized) else if(_userSized)
return _yUserSize; return _yUserSize;
return _yPanelSize; return _yPanelSize;
}; };
// returns height of caption only. This is for folding calulation // returns height of caption only. This is for folding calulation
// purposes // purposes
int GetCaptionHeight() const { int GetCaptionHeight() const {
wxSize size = _captionBar->GetSize(); wxSize size = _captionBar->GetSize();
return size.GetHeight(); return size.GetHeight();
}; };
void ApplyCaptionStyle(const wxCaptionBarStyle &style) { void ApplyCaptionStyle(const wxCaptionBarStyle &style) {
wxCHECK2(_captionBar, return); wxCHECK2(_captionBar, return);
_captionBar->SetCaptionStyle(false, style); _captionBar->SetCaptionStyle(false, style);
}; };
wxCaptionBarStyle GetCaptionStyle() { wxCaptionBarStyle GetCaptionStyle() {
wxCHECK(_captionBar, wxEmptyCaptionBarStyle); wxCHECK(_captionBar, wxEmptyCaptionBarStyle);
return _captionBar->GetCaptionStyle(); return _captionBar->GetCaptionStyle();
}; };
}; };