From 7a8d94185f3d3237861e582c80cf5b7ac43c3c74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Fri, 10 Dec 2004 12:01:04 +0000 Subject: [PATCH] wxFoldBar now also horizontal (with API methods renamed to mean length rather than height) and more with wxWidgets coding standards. Sample adjustement to changing orientation. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/foldbar/captionbar.h | 269 +++++++++--------- contrib/include/wx/foldbar/foldpanelbar.h | 79 ++--- contrib/include/wx/foldbar/foldpanelitem.h | 202 ++++++------- .../foldbar/foldpanelbar/foldpanelbartest.cpp | 148 ++++++---- .../foldbar/foldpanelbar/foldtestpanel.cpp | 7 +- .../foldbar/foldpanelbar/foldtestpanel.h | 9 +- contrib/src/foldbar/captionbar.cpp | 160 +++++++---- contrib/src/foldbar/foldpanelbar.cpp | 134 +++++---- contrib/src/foldbar/foldpanelitem.cpp | 133 ++++++--- 9 files changed, 644 insertions(+), 497 deletions(-) diff --git a/contrib/include/wx/foldbar/captionbar.h b/contrib/include/wx/foldbar/captionbar.h index 46ed80819f..12ef5c1a95 100644 --- a/contrib/include/wx/foldbar/captionbar.h +++ b/contrib/include/wx/foldbar/captionbar.h @@ -2,7 +2,8 @@ // Name: captionbar.h // Purpose: wxFoldPanel // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 22/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -27,44 +28,44 @@ 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 */ 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 */ wxCAPTIONBAR_GRADIENT_H, /** Fills the captionbar with a single colour. The first colour is used for this fill */ wxCAPTIONBAR_SINGLE, /** Draws a rectangle only using the second colour. The first colour is not used*/ 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. */ wxCAPTIONBAR_FILLED_RECTANGLE }; /** \class wxCaptionBarStyle - 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 - be changed. - - At construction time, all styles are set to their default transparency. This means none of the styles will be + 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 + be changed. + + 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 - 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 { private: // boolean flags for default transparency on styles - bool _firstColourUsed, - _secondColourUsed, - _textColourUsed, - _captionFontUsed, - _captionStyleUsed; + bool m_firstColourUsed, + m_secondColourUsed, + m_textColourUsed, + m_captionFontUsed, + m_captionStyleUsed; - wxFont _captionFont; - wxColour _firstColour, _secondColour, _textColour; + wxFont m_captionFont; + wxColour m_firstColour, m_secondColour, m_textColour; - int _captionStyle; + int m_captionStyle; public: /** Default constructor for this class */ @@ -77,41 +78,41 @@ public: }; void ResetDefaults() { - _firstColourUsed = false; - _secondColourUsed = false; - _textColourUsed = false; - _captionFontUsed = false; - _captionStyleUsed = false; - _captionStyle = wxCAPTIONBAR_GRADIENT_V; - }; - - /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other + m_firstColourUsed = false; + m_secondColourUsed = false; + m_textColourUsed = false; + m_captionFontUsed = false; + m_captionStyleUsed = false; + m_captionStyle = wxCAPTIONBAR_GRADIENT_V; + }; + + /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other styles are not copied */ void operator=(const wxCaptionBarStyle &s) { - if(s._captionStyleUsed) + if(s.m_captionStyleUsed) { - _captionStyleUsed = true; - _captionStyle = s._captionStyle; + m_captionStyleUsed = true; + m_captionStyle = s.m_captionStyle; } - if(s._captionFontUsed) + if(s.m_captionFontUsed) { - _captionFontUsed = true; - _captionFont = s._captionFont; + m_captionFontUsed = true; + m_captionFont = s.m_captionFont; } - if(s._firstColourUsed) + if(s.m_firstColourUsed) { - _firstColourUsed = true; - _firstColour = s._firstColour; + m_firstColourUsed = true; + m_firstColour = s.m_firstColour; } - if(s._secondColourUsed) + if(s.m_secondColourUsed) { - _secondColourUsed = true; - _secondColour = s._secondColour; + m_secondColourUsed = true; + m_secondColour = s.m_secondColour; } - if(s._textColourUsed) + if(s.m_textColourUsed) { - _textColourUsed = true; - _textColour = s._textColour; + m_textColourUsed = true; + m_textColour = s.m_textColour; } }; @@ -120,94 +121,94 @@ public: /** 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 */ void SetCaptionFont(const wxFont &font) { - _captionFont = font; - _captionFontUsed = true; + m_captionFont = font; + m_captionFontUsed = true; }; /** Checks if the caption bar font is set */ bool CaptionFontUsed() const { - return _captionFontUsed; + return m_captionFontUsed; }; /** 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() */ wxFont GetCaptionFont() const { - wxASSERT(_captionFontUsed); - return _captionFont; + wxASSERT(m_captionFontUsed); + return m_captionFont; }; // ------- FirstColour ------- - /** 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 + /** 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 style is used */ void SetFirstColour(const wxColour &col) { - _firstColour = col; - _firstColourUsed = true; + m_firstColour = col; + m_firstColourUsed = true; }; /** Checks if the first colour of the caption bar is set */ bool FirstColourUsed() const { - return _firstColourUsed; + return m_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. \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */ wxColour GetFirstColour() const { - wxASSERT(_firstColourUsed); - return _firstColour; + wxASSERT(m_firstColourUsed); + return m_firstColour; }; // ------- 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 */ void SetSecondColour(const wxColour &col) { - _secondColour = col; - _secondColourUsed = true; + m_secondColour = col; + m_secondColourUsed = true; }; /** Checks if the second colour of the caption bar is set */ bool SecondColourUsed() const { - return _secondColourUsed; + return m_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. \sa SetSecondColour(), SecondColourUsed() */ wxColour GetSecondColour() const { - wxASSERT(_secondColourUsed); - return _secondColour; + wxASSERT(m_secondColourUsed); + return m_secondColour; }; // ------- 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 */ void SetCaptionColour(const wxColour &col) { - _textColour = col; - _textColourUsed = true; + m_textColour = col; + m_textColourUsed = true; }; /** Checks if the caption colour of the caption bar is set */ bool CaptionColourUsed() const { - return _textColourUsed; + return m_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. \sa SetCaptionColour(), CaptionColourUsed() */ wxColour GetCaptionColour() const { - wxASSERT(_textColourUsed); - return _textColour; + wxASSERT(m_textColourUsed); + return m_textColour; }; // ------- CaptionStyle ------- - /** 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. + /** 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. The following styles can be applied: - wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom - wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right @@ -216,21 +217,21 @@ public: - wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it */ void SetCaptionStyle(int style) { - _captionStyle = style; - _captionStyleUsed = true; + m_captionStyle = style; + m_captionStyleUsed = true; }; /** Checks if the caption style of the caption bar is set */ bool CaptionStyleUsed() const { - return _captionStyleUsed; + return m_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. \sa SetCaptionStyle(), CaptionStyleUsed() */ int GetCaptionStyle() const { - wxASSERT(_captionStyleUsed); - return _captionStyle; + wxASSERT(m_captionStyleUsed); + return m_captionStyle; }; }; @@ -238,7 +239,7 @@ public: /** \class wxCaptionBar 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 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. @@ -252,20 +253,20 @@ public: class WXDLLIMPEXP_FOLDBAR wxCaptionBar: public wxWindow { private: - wxString _caption; - wxImageList *_foldIcons; - wxSize _oldSize; - //wxFont _captionFont; - int _rightIndent; - int _iconWidth, _iconHeight; - //int _captionStyle; + wxString m_caption; + wxImageList *m_foldIcons; + wxSize m_oldSize; + //wxFont m_captionFont; + int m_rightIndent; + int m_iconWidth, m_iconHeight; + //int m_captionStyle; - //wxColour _firstColour, _secondColour, _textColour; + //wxColour m_firstColour, m_secondColour, m_textColour; /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */ - bool _collapsed; + bool m_collapsed; - wxCaptionBarStyle _style; + wxCaptionBarStyle m_captionStyle; /** Fills the background of the caption with either a gradient, or a solid color */ void FillCaptionBackground(wxPaintDC &dc); @@ -282,38 +283,40 @@ private: public: /** 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. */ - wxCaptionBar(wxWindow* parent, const wxString &caption, wxImageList *images, + wxCaptionBar(wxWindow* parent, const wxString &caption, wxImageList *images, wxWindowID id = wxID_ANY, const wxCaptionBarStyle &cbstyle = wxEmptyCaptionBarStyle, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxNO_BORDER); ~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, the styles which are not set in the wxCaptionBarStyle will be ignored */ void SetCaptionStyle(bool applyDefault, wxCaptionBarStyle style = wxEmptyCaptionBarStyle) { ApplyCaptionStyle(style, applyDefault); 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. */ wxCaptionBarStyle GetCaptionStyle() { - return _style; + return m_captionStyle; }; + bool IsVertical() const; + #if 0 /** 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 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 - 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 + + If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel + 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 collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and widht is calculated. @@ -322,10 +325,10 @@ public: all the windows accordingly */ void SetFoldIcons(wxImageList *images) { - _foldIcons = images; - _iconWidth = _iconHeight = 0; - if(_foldIcons) - _foldIcons->GetSize(0, _iconWidth, _iconHeight); + m_foldIcons = images; + m_iconWidth = m_iconHeight = 0; + if(m_foldIcons) + m_foldIcons->GetSize(0, m_iconWidth, m_iconHeight); Refresh(); }; @@ -334,37 +337,37 @@ public: /** Returns wether the status of the bar is expanded or collapsed */ bool IsCollapsed() const { - return _collapsed; + return m_collapsed; }; - /** 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 + /** 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 assigning an image list to prevent a redraw */ void SetRightIndent(int pixels) { wxCHECK2(pixels >= 0, return); - _rightIndent = pixels; + m_rightIndent = pixels; // issue a refresh (if we have a bmp) - if(_foldIcons) + if(m_foldIcons) 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 */ wxSize DoGetBestSize() const; /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent to be sent to the parent */ void Collapse() { - _collapsed = true; + m_collapsed = true; RedrawIconBitmap(); }; /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent to be sent to the parent */ void Expand() { - _collapsed = false; + m_collapsed = false; RedrawIconBitmap(); }; @@ -380,10 +383,10 @@ public: private: /** The paint event for flat or gradient fill */ void OnPaint(wxPaintEvent& event); - + /** For clicking the icon, the mouse event must be intercepted */ void OnMouseEvent(wxMouseEvent& event); - + /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */ void OnChar(wxKeyEvent& event); @@ -398,7 +401,7 @@ protected: /***********************************************************************************************************/ /** \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 windows accordingly */ @@ -406,49 +409,49 @@ class WXDLLIMPEXP_FOLDBAR wxCaptionBarEvent : public wxCommandEvent { private: - bool _collapsed; - wxCaptionBar *_bar; - void *_tag; + bool m_collapsed; + wxCaptionBar *m_captionBar; + void *m_tag; public: wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0) : wxCommandEvent(commandType, id) - , _collapsed(false) - , _bar(0) - , _tag(0) + , m_collapsed(false) + , m_captionBar(NULL) + , m_tag(0) { } - + /** Constructor for clone copy */ wxCaptionBarEvent(const wxCaptionBarEvent &event); - + /** Clone function */ virtual wxEvent *Clone() const { return new wxCaptionBarEvent(*this); }; /** Returns wether the bar is expanded or collapsed. True means expanded */ - bool GetFoldStatus() const { - wxCHECK(_bar, false); - return !_bar->IsCollapsed(); + bool GetFoldStatus() const { + wxCHECK(m_captionBar, false); + return !m_captionBar->IsCollapsed(); }; /** Returns the bar associated with this event */ - wxCaptionBar *GetBar() const { - return _bar; + wxCaptionBar *GetCaptionBar() const { + return m_captionBar; }; void SetTag(void *tag) { - _tag = tag; + m_tag = tag; }; void *GetTag() const { - return _tag; + return m_tag; }; /** Sets the bar associated with this event, should not used by any other then the originator of the event */ - void SetBar(wxCaptionBar *bar) { - _bar = bar; + void SetCaptionBar(wxCaptionBar *bar) { + m_captionBar = bar; }; DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent) diff --git a/contrib/include/wx/foldbar/foldpanelbar.h b/contrib/include/wx/foldbar/foldpanelbar.h index 6ad9ed0ada..252104b2c5 100644 --- a/contrib/include/wx/foldbar/foldpanelbar.h +++ b/contrib/include/wx/foldbar/foldpanelbar.h @@ -2,7 +2,8 @@ // Name: foldpanelbar.h // Purpose: wxFoldPanel // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 22/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -12,12 +13,6 @@ #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 size left in the client area */ @@ -26,6 +21,10 @@ /** All panels are stacked to the bottom. When they are expanded again they show up at the top */ #define wxFPB_COLLAPSE_TO_BOTTOM 0x0002 +/** Orientation flag **/ +#define wxFPB_HORIZONTAL wxHORIZONTAL /* 0x0004 */ +#define wxFPB_VERTICAL wxVERTICAL /* 0x0008 */ + /** 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 @@ -34,6 +33,8 @@ #define wxFPB_DEFAULT_STYLE wxTAB_TRAVERSAL | wxNO_BORDER +#include "wx/foldbar/foldpanelitem.h" + /** \class wxFoldPanel 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() @@ -43,43 +44,43 @@ class wxFoldPanel { private: - wxFoldPanelItem *_item; + wxFoldPanelItem *m_item; public: /** Constructor, usually not directly used by the developer. */ wxFoldPanel(wxFoldPanelItem *item) - : _item(item) + : m_item(item) { } /** Returns true if this is a valid wxFoldPanelItem reference. */ bool IsOk() const { - return (_item != 0); + return (m_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; + m_item = item.m_item; }; #ifndef _NO_DOXYGEN_ // not allowed to be seen by doxygen wxFoldPanelItem *GetItem() const { - return _item; + return m_item; }; #endif /** Use this method to obtain the wxPanel derived class to which you need to add your components. For example;
\code - wxFoldPanel item = _pnl->AddFoldPanel(wxT("Test me"), false); - _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), wxID_ANY, wxT("Press Me"))); + wxFoldPanel item = m_pnl->AddFoldPanel(wxT("Test me"), false); + m_pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), wxID_ANY, wxT("Press Me"))); \endcode */ wxFoldPanelItem *GetParent() const { - wxASSERT(_item); - return _item; + wxASSERT(m_item); + return m_item; }; @@ -107,14 +108,14 @@ private: DECLARE_CLASS( wxFoldPanelBar ) DECLARE_EVENT_TABLE() - wxImageList *_images; - wxFoldPanelItemArray _panels; - wxBoxSizer* _panelSizer; - wxPanel *_foldPanel, *_bottomPanel; - wxFlexGridSizer* _mainSizer; - bool _controlCreated; - wxBitmap *_moreBmp; - int _extraStyle; + wxImageList *m_images; + wxFoldPanelItemArray m_panels; + wxBoxSizer* m_panelSizer; + wxPanel *m_foldPanel, *m_bottomPanel; + wxFlexGridSizer* m_mainSizer; + bool m_controlCreated; + wxBitmap *m_moreBmp; + int m_extraStyle; private: /** Refreshes all the panels from given index down to last one */ @@ -123,10 +124,10 @@ private: /** Refreshes all the panels from given pointer down to last one in the list */ void RefreshPanelsFrom(wxFoldPanelItem *item); - /** 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 + /** Returns the length 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 (right) to allign the collapsed panels. */ - int GetPanelsHeight(int &collapsed, int &expanded); + int GetPanelsLength(int &collapsed, int &expanded); /** 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 @@ -182,49 +183,54 @@ public: \code // create the wxFoldPanelBar - _pnl = new wxFoldPanelBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, wxFPB_COLLAPSE_TO_BOTTOM); + m_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); + wxFoldPanel item = m_pnl->AddFoldPanel(wxT("Test me"), false); // 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. - _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, wxT("Collapse Me"))); + m_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); + m_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. - _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, wxT("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20); + m_pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, wxT("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20); \endcode */ int AddFoldPanelWindow(const wxFoldPanel &panel, wxWindow *window, int flags = wxFPB_ALIGN_WIDTH, - int ySpacing = wxFPB_DEFAULT_YSPACING, int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, + int Spacing = wxFPB_DEFAULT_SPACING, int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, 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 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(). */ int AddFoldPanelSeperator(const wxFoldPanel &panel, const wxColour &color = wxColour(167,167,167), - int ySpacing = wxFPB_DEFAULT_YSPACING, int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING, + int Spacing = wxFPB_DEFAULT_SPACING, int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING, int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING); /** Returns the number of panels currently present in the wxFoldPanelBar. This is independent if they are visible or hidden. */ size_t GetCount() const { - return _panels.GetCount(); + return m_panels.GetCount(); }; + inline bool IsVertical() const + { + return HasFlag(wxFPB_VERTICAL); + } + /** 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) { wxCHECK((int)i >= 0 && i < GetCount(), wxFoldPanel(0)); - return wxFoldPanel(_panels.Item(i)); + return wxFoldPanel(m_panels.Item(i)); }; /** Collapses the given wxFoldPanel reference, and updates the foldpanel bar. In the wxFPB_COLLAPSE_TO_BOTTOM @@ -271,7 +277,6 @@ public: return fp.GetItem()->GetCaptionStyle(); }; - private: void OnPressCaption(wxCaptionBarEvent &event); void OnSizePanel(wxSizeEvent &event); diff --git a/contrib/include/wx/foldbar/foldpanelitem.h b/contrib/include/wx/foldbar/foldpanelitem.h index 4891e319e5..41dd7e65b5 100644 --- a/contrib/include/wx/foldbar/foldpanelitem.h +++ b/contrib/include/wx/foldbar/foldpanelitem.h @@ -2,7 +2,8 @@ // Name: foldpanelitem.h // Purpose: wxFoldPanel // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 22/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -12,18 +13,14 @@ #ifndef __WXFOLDPANELITEM_H__ #define __WXFOLDPANELITEM_H__ -#ifndef WX_PRECOMP - #include "wx/wx.h" -#endif +#include "wx/foldbar/captionbar.h" -#include "captionbar.h" - -#define wxFPB_ALIGN_LEFT 0 +#define wxFPB_ALIGN_LEFT 0 #define wxFPB_ALIGN_WIDTH 1 #define wxFPB_DEFAULT_LEFTSPACING 5 #define wxFPB_DEFAULT_RIGHTSPACING 10 -#define wxFPB_DEFAULT_YSPACING 8 +#define wxFPB_DEFAULT_SPACING 8 #define wxFPB_DEFAULT_LEFTLINESPACING 2 #define wxFPB_DEFAULT_RIGHTLINESPACING 2 @@ -31,116 +28,117 @@ class wxFoldWindowItem { private: - wxWindow *_wnd; - int _type, _flags; - int _leftSpacing, - _rightSpacing, - _ySpacing; - int _lineWidth, _lineY; - wxColour _sepLineColour; + wxWindow *m_wndItem; + int m_type, m_flags; + int m_leftSpacing, + m_rightSpacing, + m_Spacing; + int m_lineLength, m_lineY; + wxColour m_sepLineColour; public: - enum + enum { WINDOW = 0, 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) - , _flags(flags) - , _leftSpacing(leftSpacing) - , _rightSpacing(rightSpacing) - , _ySpacing(ySpacing) - , _lineWidth(0) - , _lineY(0) + wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int Spacing = wxFPB_DEFAULT_SPACING, + int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing = wxFPB_DEFAULT_RIGHTSPACING) + : m_wndItem(wnd) + , m_type(WINDOW) + , m_flags(flags) + , m_leftSpacing(leftSpacing) + , m_rightSpacing(rightSpacing) + , m_Spacing(Spacing) + , m_lineLength(0) + , m_lineY(0) { }; // 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) - , _flags(wxFPB_ALIGN_WIDTH) - , _leftSpacing(leftSpacing) - , _rightSpacing(rightSpacing) - , _ySpacing(ySpacing) - , _lineWidth(0) - , _lineY(y) - , _sepLineColour(lineColor) + wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int Spacing = wxFPB_DEFAULT_SPACING, + int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING, + int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING) + : m_wndItem(NULL) + , m_type(SEPARATOR) + , m_flags(wxFPB_ALIGN_WIDTH) + , m_leftSpacing(leftSpacing) + , m_rightSpacing(rightSpacing) + , m_Spacing(Spacing) + , m_lineLength(0) + , m_lineY(y) + , m_sepLineColour(lineColor) { }; // TODO: Make a c'tor for a captioned splitter int GetType() const { - return _type; + return m_type; }; int GetLineY() const { - return _lineY; + return m_lineY; }; - int GetLineWidth() const { - return _lineWidth; + int GetLineLength() const { + return m_lineLength; }; const wxColour &GetLineColour() const { - return _sepLineColour; + return m_sepLineColour; }; int GetLeftSpacing() const { - return _leftSpacing; + return m_leftSpacing; }; int GetRightSpacing() const { - return _rightSpacing; + return m_rightSpacing; }; - int GetYSpacing() const { - return _ySpacing; + int GetSpacing() const { + return m_Spacing; }; - // returns the window height if type is wxFoldWindowItem::WINDOW + // returns space needed by the window if type is wxFoldWindowItem::WINDOW // and returns the total size plus the extra spacing - int GetWindowHeight() const { + int GetWindowLength(bool vertical) const { int value = 0; - if(_type == WINDOW) + if(m_type == WINDOW) { - wxCHECK(_wnd, 0); - wxSize size = _wnd->GetSize(); - value = size.GetHeight() + _ySpacing; + wxCHECK(m_wndItem, 0); + wxSize size = m_wndItem->GetSize(); + value = ( vertical ? size.GetHeight() : size.GetWidth() ) + m_Spacing; } - else if(_type == SEPARATOR) - value = 1 + _ySpacing; + else if(m_type == SEPARATOR) + value = 1 + m_Spacing; return value; }; // resize the element, whatever it is. A separator or - // line will be always alligned by width + // line will be always alligned by width or hight + // depending on orientation of the whole panel - void ResizeItem(int width) { - if((_flags & wxFPB_ALIGN_WIDTH)) + void ResizeItem(int size, bool vertical) { + if(m_flags & wxFPB_ALIGN_WIDTH) { // allign by taking full width - int myWidth = width - _leftSpacing - _rightSpacing; + int mySize = size - m_leftSpacing - m_rightSpacing; - if(myWidth < 0) - myWidth = 10; // can't have negative width + if(mySize < 0) + mySize = 10; // can't have negative width - if(_type == SEPARATOR) - _lineWidth = myWidth; + if(m_type == SEPARATOR) + m_lineLength = mySize; else { - wxCHECK2(_wnd, return); - _wnd->SetSize(wxSize(myWidth, wxDefaultCoord)); + wxCHECK2(m_wndItem, return); + m_wndItem->SetSize(vertical?mySize:wxDefaultCoord, vertical?wxDefaultCoord:mySize); } } }; @@ -154,27 +152,27 @@ WX_DECLARE_OBJARRAY(wxFoldWindowItem, wxFoldWindowItemArray); /** \wxFoldPanelItem 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 WXDLLIMPEXP_FOLDBAR wxFoldPanelItem: public wxPanel { private: - wxCaptionBar *_captionBar; + wxCaptionBar *m_captionBar; - bool _controlCreated; - int _yUserSize, - _yPanelSize, - _yLastInsertPos; - int _yPos; - bool _userSized; + bool m_controlCreated; + int m_userSize, + m_panelSize, + m_lastInsertPos; + int m_itemPos; + bool m_userSized; private: DECLARE_CLASS( wxFoldPanelItem ) DECLARE_EVENT_TABLE() - + private: - wxFoldWindowItemArray _items; + wxFoldWindowItemArray m_items; void OnSize(wxSizeEvent &event); void OnPressCaption(wxCaptionBarEvent &event); @@ -182,75 +180,77 @@ private: public: // 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); virtual ~wxFoldPanelItem(); - + /** 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 of pixels before the window element, and leftSpacing is an indent. rightSpacing is only relevant when the style wxFPB_ALIGN_WIDTH is chosen. */ void AddWindow(wxWindow *window, int flags, 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 length occupied for the next wxFoldPanelBar in the list */ - int Reposition(int y); + int Reposition(int pos); void ResizePanel(); /** Return expanded or collapsed status. If the panel is expanded, true is returned */ bool IsExpanded() const { - return !_captionBar->IsCollapsed(); + return !m_captionBar->IsCollapsed(); }; /** Return Y pos */ - int GetY() const { - return _yPos; + int GetItemPos() const { + return m_itemPos; }; - // 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 void Collapse() { - _captionBar->Collapse(); + m_captionBar->Collapse(); 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 void Expand() { - _captionBar->Expand(); + m_captionBar->Expand(); ResizePanel(); }; /* Return size of panel */ - int GetPanelHeight() const { - if(_captionBar->IsCollapsed()) - return GetCaptionHeight(); - else if(_userSized) - return _yUserSize; - return _yPanelSize; + int GetPanelLength() const { + if(m_captionBar->IsCollapsed()) + return GetCaptionLength(); + else if(m_userSized) + return m_userSize; + return m_panelSize; }; - // returns height of caption only. This is for folding calulation + bool IsVertical() const; + + // returns space of caption only. This is for folding calulation // purposes - int GetCaptionHeight() const { - wxSize size = _captionBar->GetSize(); - return size.GetHeight(); + int GetCaptionLength() const { + wxSize size = m_captionBar->GetSize(); + return IsVertical() ? size.GetHeight() : size.GetWidth(); }; void ApplyCaptionStyle(const wxCaptionBarStyle &style) { - wxCHECK2(_captionBar, return); - _captionBar->SetCaptionStyle(false, style); + wxCHECK2(m_captionBar, return); + m_captionBar->SetCaptionStyle(false, style); }; wxCaptionBarStyle GetCaptionStyle() { - wxCHECK(_captionBar, wxEmptyCaptionBarStyle); - return _captionBar->GetCaptionStyle(); + wxCHECK(m_captionBar, wxEmptyCaptionBarStyle); + return m_captionBar->GetCaptionStyle(); }; }; diff --git a/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp b/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp index cd615c7cf6..62ff6abbed 100644 --- a/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp +++ b/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp @@ -2,7 +2,8 @@ // Name: foldpanelbartest.cpp // Purpose: // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 18/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -19,12 +20,6 @@ #include "wx/wx.h" #endif -enum -{ - ID_COLLAPSEME = 10000, - ID_EXPANDME -}; - #include "wx/foldbar/foldpanelbar.h" #include "foldtestpanel.h" @@ -54,12 +49,15 @@ public: class MyAppFrame : public wxFrame { public: - MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, - long style = wxDEFAULT_FRAME_STYLE); + MyAppFrame(const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE); private: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); + void OnOrientation(wxCommandEvent& event); // extra handlers for the bar, to show how it works @@ -68,7 +66,8 @@ private: private: wxMenuBar *CreateMenuBar(); - wxFoldPanelBar *_pnl; + void CreateFoldBar(bool vertical = true); + wxFoldPanelBar *m_pnl; private: DECLARE_EVENT_TABLE() @@ -81,8 +80,12 @@ private: enum { // menu items - FoldPanelBarTest_Quit = 1, - FoldPanelBarTest_About = wxID_ABOUT + FoldPanelBarTest_Quit = wxID_EXIT, + FoldPanelBarTest_About = wxID_ABOUT, + ID_COLLAPSEME = wxID_HIGHEST, + ID_EXPANDME, + FoldPanelBarTest_Horizontal, + FoldPanelBarTest_Vertical }; // ---------------------------------------------------------------------------- @@ -90,10 +93,12 @@ enum // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(MyAppFrame, wxFrame) - EVT_MENU(FoldPanelBarTest_Quit, MyAppFrame::OnQuit) - EVT_MENU(FoldPanelBarTest_About, MyAppFrame::OnAbout) - EVT_BUTTON(ID_COLLAPSEME, MyAppFrame::OnCollapseMe) - EVT_BUTTON(ID_EXPANDME, MyAppFrame::OnExpandMe) + EVT_MENU(FoldPanelBarTest_Quit, MyAppFrame::OnQuit) + EVT_MENU(FoldPanelBarTest_About, MyAppFrame::OnAbout) + EVT_MENU(FoldPanelBarTest_Horizontal, MyAppFrame::OnOrientation) + EVT_MENU(FoldPanelBarTest_Vertical, MyAppFrame::OnOrientation) + EVT_BUTTON(ID_COLLAPSEME, MyAppFrame::OnCollapseMe) + EVT_BUTTON(ID_EXPANDME, MyAppFrame::OnExpandMe) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -108,8 +113,7 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { - MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"), - wxPoint(50, 50), wxSize(200, 500)); + MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application")); SetTopWindow(frame); @@ -122,49 +126,24 @@ bool MyApp::OnInit() // ---------------------------------------------------------------------------- MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) - : wxFrame(NULL, wxID_ANY, title, pos, size, style) + : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL) { SetIcon(wxICON(mondrian)); SetMenuBar(CreateMenuBar()); + CreateFoldBar(); + CreateStatusBar(2); SetStatusText(_T("Welcome to wxWidgets!")); - - _pnl = new wxFoldPanelBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, wxFPB_COLLAPSE_TO_BOTTOM); - - wxFoldPanel item = _pnl->AddFoldPanel(_T("Test me"), false); - _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse Me"))); - - item = _pnl->AddFoldPanel(_T("Test me too!"), true); - _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, _T("Expand first one"))); - _pnl->AddFoldPanelSeperator(item); - _pnl->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), wxID_ANY)); - - _pnl->AddFoldPanelSeperator(item); - - _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20); - - item = _pnl->AddFoldPanel(_T("Some opinions ..."), false); - _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("I like this"))); - _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And also this"))); - _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And gimme this too"))); - - _pnl->AddFoldPanelSeperator(item); - - _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("Check this too if you like"))); - _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("What about this"))); - - - item = _pnl->AddFoldPanel(_T("Choose one ..."), false); - _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter your comment"))); - _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20); - } wxMenuBar *MyAppFrame::CreateMenuBar() { wxMenu *menuFile = new wxMenu; + menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H")); + menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V")); + menuFile->AppendSeparator(); menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); wxMenu *helpMenu = new wxMenu; @@ -177,9 +156,61 @@ wxMenuBar *MyAppFrame::CreateMenuBar() return value; } -// event handlers - - +void MyAppFrame::CreateFoldBar(bool vertical) +{ + if (vertical) + SetSize(200,500); + else + SetSize(900,200); + + wxFoldPanelBar *bar = new wxFoldPanelBar(this, + wxID_ANY, + wxDefaultPosition, + wxDefaultSize, + wxFPB_DEFAULT_STYLE | ( vertical ? wxFPB_VERTICAL : wxFPB_HORIZONTAL ) , + wxFPB_COLLAPSE_TO_BOTTOM); + + wxFoldPanel item = bar->AddFoldPanel(_T("Test me"), false); + bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse Me"))); + + item = bar->AddFoldPanel(_T("Test me too!"), true); + bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, _T("Expand first one"))); + bar->AddFoldPanelSeperator(item); + bar->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), wxID_ANY)); + + bar->AddFoldPanelSeperator(item); + + bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20); + + item = bar->AddFoldPanel(_T("Some opinions ..."), false); + bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("I like this"))); + if( vertical) + { + // do not add this for horizontal for better presentation + bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And also this"))); + bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And gimme this too"))); + } + + bar->AddFoldPanelSeperator(item); + + bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("Check this too if you like"))); + if( vertical) + { + // do not add this for horizontal for better presentation + bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("What about this"))); + } + + item = bar->AddFoldPanel(_T("Choose one ..."), false); + bar->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter your comment"))); + bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20); + + if (m_pnl) m_pnl->Destroy(); + + m_pnl = bar; + + wxSize size = GetClientSize(); + m_pnl->SetSize( 0, 0, size.GetWidth(), size.GetHeight() ); +} void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { @@ -196,14 +227,19 @@ void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this); } +void MyAppFrame::OnOrientation(wxCommandEvent& event) +{ + CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical); +} + void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event)) { - wxFoldPanel item = _pnl->Item(0); - _pnl->Collapse(item); + wxFoldPanel item = m_pnl->Item(0); + m_pnl->Collapse(item); } void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event)) { - _pnl->Expand(_pnl->Item(0)); - _pnl->Collapse(_pnl->Item(1)); + m_pnl->Expand(m_pnl->Item(0)); + m_pnl->Collapse(m_pnl->Item(1)); } diff --git a/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp index 9a8e1bc7f5..1cebceed64 100644 --- a/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp +++ b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp @@ -2,7 +2,8 @@ // Name: foldtestpanel.cpp // Purpose: // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 18/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -17,7 +18,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP @@ -59,7 +60,7 @@ END_EVENT_TABLE() FoldTestPanel::FoldTestPanel( ) { - delete _images; + delete m_images; } FoldTestPanel::FoldTestPanel( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) diff --git a/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h index 5d3b8df730..bdf97b2322 100644 --- a/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h +++ b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h @@ -2,7 +2,8 @@ // Name: foldtestpanel.h // Purpose: // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 18/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -20,7 +21,7 @@ * Includes */ -#include "wx/foldbar/captionbar.h" +#include "wx/foldbar/foldpanelbar.h" ////@begin includes ////@end includes @@ -72,8 +73,8 @@ class FoldTestPanel: public wxPanel DECLARE_EVENT_TABLE() private: - wxImageList *_images; - wxRect _oldsize; + wxImageList *m_images; + wxRect m_oldsize; void OnCaptionPanel(wxCaptionBarEvent &event); diff --git a/contrib/src/foldbar/captionbar.cpp b/contrib/src/foldbar/captionbar.cpp index 9b37b04f63..1731165676 100644 --- a/contrib/src/foldbar/captionbar.cpp +++ b/contrib/src/foldbar/captionbar.cpp @@ -2,7 +2,8 @@ // Name: captionbar.cpp // Purpose: wxCaptionBar class belonging to the wxFoldPanel (but can be used independent) // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 18/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -17,17 +18,14 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/dcmemory.h" -#include "wx/dcclient.h" + #include "wx/wx.h" #endif -#include - -#include "wx/foldbar/captionbar.h" +#include "wx/foldbar/foldpanelbar.h" /* * wxCaptionBar @@ -43,22 +41,22 @@ END_EVENT_TABLE() wxCaptionBar::wxCaptionBar(wxWindow* parent, const wxString &caption, wxImageList *images, wxWindowID id, const wxCaptionBarStyle &cbstyle, const wxPoint& pos, const wxSize& size, long style) : wxWindow(parent, id, pos, size, style) - , _caption(caption) - , _foldIcons(images) - , _rightIndent(wxFPB_BMP_RIGHTSPACE) - , _iconWidth(16) - , _iconHeight(16) - , _collapsed(false) + , m_caption(caption) + , m_foldIcons(images) + , m_rightIndent(wxFPB_BMP_RIGHTSPACE) + , m_iconWidth(16) + , m_iconHeight(16) + , m_collapsed(false) { // do initialisy thingy stuff ApplyCaptionStyle(cbstyle, true); // set initial size - if(_foldIcons) + if(m_foldIcons) { - wxASSERT(_foldIcons->GetImageCount() > 1); - _foldIcons->GetSize(0, _iconWidth, _iconHeight); + wxASSERT(m_foldIcons->GetImageCount() > 1); + m_foldIcons->GetSize(0, m_iconWidth, m_iconHeight); } } @@ -105,12 +103,14 @@ void wxCaptionBar::ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool appl } // apply the style - _style = newstyle; + m_captionStyle = newstyle; } void wxCaptionBar::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); + wxRect wndRect = GetRect(); + bool vertical = IsVertical(); // TODO: Maybe first a memory DC should draw all, and then paint it on the // caption. This way a flickering arrow during resize is not visible @@ -119,24 +119,36 @@ void wxCaptionBar::OnPaint(wxPaintEvent& WXUNUSED(event)) FillCaptionBackground(dc); - dc.SetFont(_style.GetCaptionFont()); - dc.DrawText(_caption, 4, (wxFPB_EXTRA_Y / 2)); + dc.SetFont(m_captionStyle.GetCaptionFont()); + if(vertical) + dc.DrawText(m_caption, 4, (wxFPB_EXTRA_Y / 2)); + else + dc.DrawRotatedText(m_caption, (wxFPB_EXTRA_Y / 2) , wndRect.GetBottom() - 4 , 90 ); // draw small icon, either collapsed or expanded // based on the state of the bar. If we have // any bmp's - if(_foldIcons) + if(m_foldIcons) { - wxCHECK2(_foldIcons->GetImageCount() > 1, return); + wxCHECK2(m_foldIcons->GetImageCount() > 1, return); int index = 0; - if(_collapsed) + if(m_collapsed) index = 1; - wxRect wndRect = GetRect(); - _foldIcons->Draw(index, dc, wndRect.GetRight() - _iconWidth - _rightIndent, (wndRect.GetHeight() - _iconHeight) / 2, - wxIMAGELIST_DRAW_TRANSPARENT); + if(vertical) + m_foldIcons->Draw(index, + dc, + wndRect.GetRight() - m_iconWidth - m_rightIndent, + (wndRect.GetHeight() - m_iconHeight) / 2, + wxIMAGELIST_DRAW_TRANSPARENT); + else + m_foldIcons->Draw(index, + dc, + (wndRect.GetWidth() - m_iconWidth) / 2, + m_rightIndent, + wxIMAGELIST_DRAW_TRANSPARENT); } } @@ -144,13 +156,19 @@ void wxCaptionBar::FillCaptionBackground(wxPaintDC &dc) { // dispatch right style for caption drawing - switch(_style.GetCaptionStyle()) + switch(m_captionStyle.GetCaptionStyle()) { case wxCAPTIONBAR_GRADIENT_V: - DrawVerticalGradient(dc, GetRect()); + if (IsVertical()) + DrawVerticalGradient(dc, GetRect()); + else + DrawHorizontalGradient(dc, GetRect()); break; case wxCAPTIONBAR_GRADIENT_H: - DrawHorizontalGradient(dc, GetRect()); + if (IsVertical()) + DrawHorizontalGradient(dc, GetRect()); + else + DrawVerticalGradient(dc, GetRect()); break; case wxCAPTIONBAR_SINGLE: DrawSingleColour(dc, GetRect()); @@ -172,12 +190,14 @@ void wxCaptionBar::OnMouseEvent(wxMouseEvent& event) bool send_event = false; - if (event.LeftDown() && _foldIcons) + if (event.LeftDown() && m_foldIcons) { wxPoint pt(event.GetPosition()); wxRect rect = GetRect(); + bool vertical = IsVertical(); - if(pt.x > (rect.GetWidth() - _iconWidth - _rightIndent)) + if((vertical && pt.x > (rect.GetWidth() - m_iconWidth - m_rightIndent))|| + (!vertical && pt.y < m_iconHeight + m_rightIndent)) send_event = true; } else if(event.LeftDClick()) @@ -188,7 +208,7 @@ void wxCaptionBar::OnMouseEvent(wxMouseEvent& event) if(send_event) { wxCaptionBarEvent event(wxEVT_CAPTIONBAR); - event.SetBar(this); + event.SetCaptionBar(this); ::wxPostEvent(this, event); @@ -206,13 +226,16 @@ wxSize wxCaptionBar::DoGetBestSize() const { int x,y; - GetTextExtent(_caption, &x, &y); + if(IsVertical()) + GetTextExtent(m_caption, &x, &y); + else + GetTextExtent(m_caption, &y, &x); - if(x < _iconWidth) - x = _iconWidth; + if(x < m_iconWidth) + x = m_iconWidth; - if(y < _iconHeight) - y = _iconHeight; + if(y < m_iconHeight) + y = m_iconHeight; // TODO: The extra wxFPB_EXTRA_X constants should be adjustable as well @@ -227,19 +250,21 @@ void wxCaptionBar::DrawVerticalGradient(wxDC &dc, const wxRect &rect ) if(rect.height < 1 || rect.width < 1) return; + int size = rect.height; + dc.SetPen(*wxTRANSPARENT_PEN); // calculate gradient coefficients - wxColour col2 = _style.GetSecondColour(), - col1 = _style.GetFirstColour(); + wxColour col2 = m_captionStyle.GetSecondColour(), + col1 = m_captionStyle.GetFirstColour(); - double rstep = double((col2.Red() - col1.Red())) / double(rect.height), rf = 0, - gstep = double((col2.Green() - col1.Green())) / double(rect.height), gf = 0, - bstep = double((col2.Blue() - col1.Blue())) / double(rect.height), bf = 0; + double rstep = double((col2.Red() - col1.Red())) / double(size), rf = 0, + gstep = double((col2.Green() - col1.Green())) / double(size), gf = 0, + bstep = double((col2.Blue() - col1.Blue())) / double(size), bf = 0; wxColour currCol; - for(int y = rect.y; y < rect.y + rect.height; y++) + for(int y = rect.y; y < rect.y + size; y++) { currCol.Set( (unsigned char)(col1.Red() + rf), @@ -247,7 +272,7 @@ void wxCaptionBar::DrawVerticalGradient(wxDC &dc, const wxRect &rect ) (unsigned char)(col1.Blue() + bf) ); dc.SetBrush( wxBrush( currCol, wxSOLID ) ); - dc.DrawRectangle( rect.x, rect.y + (y - rect.y), rect.width, rect.height ); + dc.DrawRectangle( rect.x, rect.y + (y - rect.y), rect.width, size ); //currCol.Set(currCol.Red() + rstep, currCol.Green() + gstep, currCol.Blue() + bstep); rf += rstep; gf += gstep; bf += bstep; } @@ -260,18 +285,20 @@ void wxCaptionBar::DrawHorizontalGradient(wxDC &dc, const wxRect &rect ) if(rect.height < 1 || rect.width < 1) return; + int size = rect.width; + dc.SetPen(*wxTRANSPARENT_PEN); // calculate gradient coefficients - wxColour col2 = _style.GetSecondColour(), - col1 = _style.GetFirstColour(); + wxColour col2 = m_captionStyle.GetSecondColour(), + col1 = m_captionStyle.GetFirstColour(); - double rstep = double((col2.Red() - col1.Red())) / double(rect.width), rf = 0, - gstep = double((col2.Green() - col1.Green())) / double(rect.width), gf = 0, - bstep = double((col2.Blue() - col1.Blue())) / double(rect.width), bf = 0; + double rstep = double((col2.Red() - col1.Red())) / double(size), rf = 0, + gstep = double((col2.Green() - col1.Green())) / double(size), gf = 0, + bstep = double((col2.Blue() - col1.Blue())) / double(size), bf = 0; wxColour currCol; - for(int x = rect.x; x < rect.x + rect.width; x++) + for(int x = rect.x; x < rect.x + size; x++) { currCol.Set( (unsigned char)(col1.Red() + rf), @@ -294,7 +321,7 @@ void wxCaptionBar::DrawSingleColour(wxDC &dc, const wxRect &rect ) dc.SetPen(*wxTRANSPARENT_PEN); // draw simple rectangle - dc.SetBrush( wxBrush( _style.GetFirstColour(), wxSOLID ) ); + dc.SetBrush( wxBrush( m_captionStyle.GetFirstColour(), wxSOLID ) ); dc.DrawRectangle( rect.x, rect.y, rect.width, rect.height ); } @@ -312,14 +339,14 @@ void wxCaptionBar::DrawSingleRectangle(wxDC &dc, const wxRect &rect ) wxBrush br; br.SetStyle(wxSOLID); - if(_style.GetCaptionStyle() == wxCAPTIONBAR_RECTANGLE) + if(m_captionStyle.GetCaptionStyle() == wxCAPTIONBAR_RECTANGLE) br.SetColour(GetParent()->GetBackgroundColour()); else - br.SetColour(_style.GetFirstColour()); + br.SetColour(m_captionStyle.GetFirstColour()); // setup the pen frame - wxPen pen(_style.GetSecondColour()); + wxPen pen(m_captionStyle.GetSecondColour()); dc.SetPen(pen); dc.SetBrush( br ); @@ -335,7 +362,7 @@ void wxCaptionBar::OnSize(wxSizeEvent &event) { wxSize size = event.GetSize(); - if(_foldIcons) + if(m_foldIcons) { // What I am doing here is simply invalidating the part of the window exposed. So when I // make a rect with as width the newly exposed part, and the x,y of the old window size origin, @@ -344,13 +371,13 @@ void wxCaptionBar::OnSize(wxSizeEvent &event) // set rect to redraw as old bitmap area which is entitled to redraw - wxRect rect(size.GetWidth() - _iconWidth - _rightIndent, 0, _iconWidth + _rightIndent, - _iconWidth + _rightIndent); + wxRect rect(size.GetWidth() - m_iconWidth - m_rightIndent, 0, m_iconWidth + m_rightIndent, + m_iconWidth + m_rightIndent); // adjust rectangle when more is slided so we need to redraw all // the old stuff but not all (ugly flickering) - int diffX = size.GetWidth() - _oldSize.GetWidth(); + int diffX = size.GetWidth() - m_oldSize.GetWidth(); if(diffX > 1) { // adjust the rect with all the crap to redraw @@ -367,23 +394,32 @@ void wxCaptionBar::OnSize(wxSizeEvent &event) RefreshRect(rect); } - _oldSize = size; + m_oldSize = size; } void wxCaptionBar::RedrawIconBitmap() { - if(_foldIcons) + if(m_foldIcons) { // invalidate the bitmap area and force a redraw wxRect rect = GetRect(); - rect.SetX(rect.GetWidth() - _iconWidth - _rightIndent); - rect.SetWidth(_iconWidth + _rightIndent); + rect.SetX(rect.GetWidth() - m_iconWidth - m_rightIndent); + rect.SetWidth(m_iconWidth + m_rightIndent); RefreshRect(rect); } } +bool wxCaptionBar::IsVertical() const +{ + // parent of wxCaptionBar is wxFoldPanelItem + // default is vertical + wxFoldPanelItem *bar = wxDynamicCast(GetParent(), wxFoldPanelItem); + wxCHECK_MSG( bar, true, _T("wrong parent") ); + return bar->IsVertical(); +} + /* * wxCaptionBarEvent */ @@ -393,7 +429,7 @@ DEFINE_EVENT_TYPE(wxEVT_CAPTIONBAR) wxCaptionBarEvent::wxCaptionBarEvent(const wxCaptionBarEvent &event) : wxCommandEvent(event) { - _bar = event._bar; + m_captionBar = event.m_captionBar; } //DEFINE_EVENT_TYPE(wxEVT_CAPTIONBAR) diff --git a/contrib/src/foldbar/foldpanelbar.cpp b/contrib/src/foldbar/foldpanelbar.cpp index b3d9b30e69..397750e68f 100644 --- a/contrib/src/foldbar/foldpanelbar.cpp +++ b/contrib/src/foldbar/foldpanelbar.cpp @@ -2,7 +2,8 @@ // Name: foldpanelbar.cpp // Purpose: // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 22/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -16,6 +17,10 @@ #pragma hdrstop #endif +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + #include "wx/foldbar/foldpanelbar.h" #include "icon_collapsed.xpm" #include "icon_expanded.xpm" @@ -40,9 +45,9 @@ wxFoldPanelBar::wxFoldPanelBar() wxFoldPanelBar::wxFoldPanelBar( wxWindow *parent, wxWindowID id, const wxPoint &position, const wxSize& size, long style, long extraStyle) - : _foldPanel(0) - , _bottomPanel(0) - , _controlCreated(false) + : m_foldPanel(NULL) + , m_bottomPanel(NULL) + , m_controlCreated(false) { Create( parent, id, position, size, style, extraStyle); } @@ -51,7 +56,11 @@ void wxFoldPanelBar::Create( wxWindow *parent, wxWindowID id, const wxPoint &pos const wxSize& size, long style, long extraStyle ) { - _extraStyle = extraStyle; + m_extraStyle = extraStyle; + + // make sure there is any orientation + if ( ( style & wxFPB_HORIZONTAL ) != wxFPB_HORIZONTAL ) + style |= wxFPB_VERTICAL; // create the panel (duh!). This causes a size event, which we are going // to skip when we are not initialised @@ -60,57 +69,57 @@ void wxFoldPanelBar::Create( wxWindow *parent, wxWindowID id, const wxPoint &pos // the fold panel area - _foldPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL); + m_foldPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL); // the extra area for some icons / context menu etc #if 0 - _bottomPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(wxDefaultCoord,22), wxNO_BORDER|wxTAB_TRAVERSAL); - _bottomPanel->SetBackgroundColour(*wxWHITE); + m_bottomPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(wxDefaultCoord,22), wxNO_BORDER|wxTAB_TRAVERSAL); + m_bottomPanel->SetBackgroundColour(*wxWHITE); #endif // create the fold icons to be used in the captions - _images = new wxImageList(16, 16); + m_images = new wxImageList(16, 16); wxBitmap *bmp = new wxBitmap(icon_expanded); - _images->Add(*bmp); + m_images->Add(*bmp); delete bmp; bmp = new wxBitmap(icon_collapsed); - _images->Add(*bmp); + m_images->Add(*bmp); delete bmp; - _moreBmp = new wxBitmap(icon_theresmore); + m_moreBmp = new wxBitmap(icon_theresmore); // do this as last, to check if create is already called - _controlCreated = true; + m_controlCreated = true; } wxFoldPanelBar::~wxFoldPanelBar() { - delete _images; - delete _moreBmp; + delete m_images; + delete m_moreBmp; } wxFoldPanel wxFoldPanelBar::AddFoldPanel(const wxString &caption, bool collapsedInitially, const wxCaptionBarStyle &style) { - wxASSERT(_controlCreated); + wxASSERT(m_controlCreated); // create a fold panel item, which is first only the caption. // the user can now add a panel area which will be folded in // when pressed. - wxFoldPanelItem *item = new wxFoldPanelItem(_foldPanel, caption, _images, collapsedInitially, style); + wxFoldPanelItem *item = new wxFoldPanelItem(m_foldPanel, caption, m_images, collapsedInitially, style); // look at the last added one and reposition this one - int y = 0; - if(_panels.GetCount() > 0) - y = _panels.Last()->GetY() + _panels.Last()->GetPanelHeight(); + int pos = 0; + if(m_panels.GetCount() > 0) + pos = m_panels.Last()->GetItemPos() + m_panels.Last()->GetPanelLength(); - item->Reposition(y); - _panels.Add(item); + item->Reposition(pos); + m_panels.Add(item); //return wxFoldPanel(item); return wxFoldPanel(item); @@ -142,7 +151,7 @@ void wxFoldPanelBar::OnSizePanel(wxSizeEvent &event) { // skip all stuff when we are not initialised yet - if(!_controlCreated) + if(!m_controlCreated) { event.Skip(); return; @@ -166,12 +175,13 @@ void wxFoldPanelBar::OnSizePanel(wxSizeEvent &event) foldrect.SetX(0); foldrect.SetY(0); - _foldPanel->SetSize(foldrect); + m_foldPanel->SetSize(foldrect); - if(_extraStyle & wxFPB_COLLAPSE_TO_BOTTOM) + if(m_extraStyle & wxFPB_COLLAPSE_TO_BOTTOM) { wxRect rect = RepositionCollapsedToBottom(); - if(rect.GetHeight() > 0) + bool vertical = IsVertical(); + if((vertical && rect.GetHeight() > 0) || (!vertical && rect.GetWidth() > 0)) RefreshRect(rect); } @@ -191,30 +201,30 @@ void wxFoldPanelBar::OnSizePanel(wxSizeEvent &event) bottomrect.SetHeight(22); bottomrect.SetX(0); - _bottomPanel->SetSize(bottomrect); + m_bottomPanel->SetSize(bottomrect); // TODO: redraw the bitmap properly // use the captionbar algorithm for that - _bottomPanel->Refresh(); + m_bottomPanel->Refresh(); #endif } void wxFoldPanelBar::OnPaint(wxPaintEvent &event) { - if(!_controlCreated) + if(!m_controlCreated) return; #if 0 // paint the bottom panel only, where the // arrow is shown when there is more to show the user // just as informative icon - wxPaintDC dc(_bottomPanel); + wxPaintDC dc(m_bottomPanel); - wxSize size = _bottomPanel->GetSize(); - int offset = (size.GetHeight() - _moreBmp->GetHeight()) / 2; + wxSize size = m_bottomPanel->GetSize(); + int offset = (size.GetHeight() - m_moreBmp->GetHeight()) / 2; - dc.DrawBitmap(*_moreBmp, size.GetWidth() - _moreBmp->GetWidth() - 2, offset, true); + dc.DrawBitmap(*m_moreBmp, size.GetWidth() - m_moreBmp->GetWidth() - 2, offset, true); #endif event.Skip(); @@ -235,7 +245,7 @@ void wxFoldPanelBar::RefreshPanelsFrom(wxFoldPanelItem *item) { wxASSERT(item); - int i = _panels.Index(item); + int i = m_panels.Index(item); if(i != wxNOT_FOUND) RefreshPanelsFrom(i); } @@ -248,14 +258,14 @@ void wxFoldPanelBar::RefreshPanelsFrom(size_t i) // should be drawn at the bottom. All panels that are expanded // are drawn on top. The last expanded panel gets all the extra space - if(_extraStyle & wxFPB_COLLAPSE_TO_BOTTOM) + if(m_extraStyle & wxFPB_COLLAPSE_TO_BOTTOM) { int offset = 0; - for(size_t j = 0; j < _panels.GetCount(); j++) + for(size_t j = 0; j < m_panels.GetCount(); j++) { - if(_panels.Item(j)->IsExpanded()) - offset += _panels.Item(j)->Reposition(offset); + if(m_panels.Item(j)->IsExpanded()) + offset += m_panels.Item(j)->Reposition(offset); } // put all non collapsed panels at the bottom where there is space, else @@ -265,9 +275,9 @@ void wxFoldPanelBar::RefreshPanelsFrom(size_t i) } else { - int y = _panels.Item(i)->GetY() + _panels.Item(i)->GetPanelHeight(); - for(i++; i < _panels.GetCount(); i++) - y += _panels.Item(i)->Reposition(y); + int pos = m_panels.Item(i)->GetItemPos() + m_panels.Item(i)->GetPanelLength(); + for(i++; i < m_panels.GetCount(); i++) + pos += m_panels.Item(i)->Reposition(pos); } Thaw(); } @@ -277,9 +287,9 @@ void wxFoldPanelBar::RedisplayFoldPanelItems() // resize them all. No need to reposition wxFoldPanelItem *item; - for(size_t i = 0; i < _panels.GetCount(); i++) + for(size_t i = 0; i < m_panels.GetCount(); i++) { - item = _panels.Item(i); + item = m_panels.Item(i); wxASSERT(item); item->ResizePanel(); @@ -289,18 +299,19 @@ void wxFoldPanelBar::RedisplayFoldPanelItems() wxRect wxFoldPanelBar::RepositionCollapsedToBottom() { wxRect value(0,0,0,0); + bool vertical = IsVertical(); // determine wether the number of panels left // times the size of their captions is enough // to be placed in the left over space int expanded = 0, collapsed = 0, offset; - GetPanelsHeight(collapsed, expanded); + GetPanelsLength(collapsed, expanded); // if no room stick them behind the normal ones, else // at the bottom - if((GetSize().GetHeight() - expanded - collapsed) < 0) + if(((vertical ? GetSize().GetHeight() : GetSize().GetWidth()) - expanded - collapsed) < 0) offset = expanded; else { @@ -308,43 +319,50 @@ wxRect wxFoldPanelBar::RepositionCollapsedToBottom() // I will send it back as 'slack' so it does not need to // be recalulated. - value.SetX(0); - value.SetY(expanded); - value.SetHeight(GetSize().GetHeight() - expanded); + value.SetHeight(GetSize().GetHeight()); value.SetWidth(GetSize().GetWidth()); - offset = GetSize().GetHeight() - collapsed; - } + if(vertical) + { + value.SetY(expanded); + value.SetHeight(value.GetHeight() - expanded); + } + else + { + value.SetX(expanded); + value.SetWidth(value.GetWidth() - expanded); + } + offset = (vertical ? GetSize().GetHeight() : GetSize().GetWidth()) - collapsed; + } // go reposition - for(size_t i = 0; i < _panels.GetCount(); i++) + for(size_t i = 0; i < m_panels.GetCount(); i++) { - if(!_panels.Item(i)->IsExpanded()) - offset += _panels.Item(i)->Reposition(offset); + if(!m_panels.Item(i)->IsExpanded()) + offset += m_panels.Item(i)->Reposition(offset); } return value; } -int wxFoldPanelBar::GetPanelsHeight(int &collapsed, int &expanded) +int wxFoldPanelBar::GetPanelsLength(int &collapsed, int &expanded) { int value = 0; // assumed here that all the panels that are expanded // are positioned after eachother from 0,0 to end. - for(size_t j = 0; j < _panels.GetCount(); j++) + for(size_t j = 0; j < m_panels.GetCount(); j++) { - int offset = _panels.Item(j)->GetPanelHeight(); + int offset = m_panels.Item(j)->GetPanelLength(); value += offset; - if(_panels.Item(j)->IsExpanded()) + if(m_panels.Item(j)->IsExpanded()) expanded += offset; else collapsed += offset; } return value; - } diff --git a/contrib/src/foldbar/foldpanelitem.cpp b/contrib/src/foldbar/foldpanelitem.cpp index 08d606c188..48997c1372 100644 --- a/contrib/src/foldbar/foldpanelitem.cpp +++ b/contrib/src/foldbar/foldpanelitem.cpp @@ -2,7 +2,8 @@ // Name: foldpanelitem.cpp // Purpose: // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 22/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -16,7 +17,11 @@ #pragma hdrstop #endif -#include "wx/foldbar/foldpanelitem.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/foldbar/foldpanelbar.h" #include WX_DEFINE_OBJARRAY(wxFoldWindowItemArray); @@ -35,12 +40,12 @@ END_EVENT_TABLE() wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons, bool collapsedInitially, const wxCaptionBarStyle &style ) - : _controlCreated(false) - , _yUserSize(0) - , _yPanelSize(0) - , _yLastInsertPos(0) - , _yPos(0) - , _userSized(false) + : m_controlCreated(false) + , m_userSize(0) + , m_panelSize(0) + , m_lastInsertPos(0) + , m_itemPos(0) + , m_userSized(false) { wxCHECK2(parent, return); @@ -48,20 +53,20 @@ wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxI // create the caption bar, in collapsed or expanded state - _captionBar = new wxCaptionBar(this, caption, icons, wxID_ANY, style, wxPoint(0,0)); - //_captionBar->SetBoldFont(); + m_captionBar = new wxCaptionBar(this, caption, icons, wxID_ANY, style, wxPoint(0,0)); + //m_captionBar->SetBoldFont(); if(collapsedInitially) - _captionBar->Collapse(); + m_captionBar->Collapse(); - _controlCreated = true; + m_controlCreated = true; // make initial size for component, if collapsed, the // size is determined on the panel height and won't change - wxSize size = _captionBar->GetSize(); - _yPanelSize = size.GetHeight(); - _yLastInsertPos = _yPanelSize; + wxSize size = m_captionBar->GetSize(); + m_panelSize = IsVertical()?size.GetHeight():size.GetWidth(); + m_lastInsertPos = m_panelSize; } void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing) @@ -69,20 +74,27 @@ void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int l wxASSERT(window); wxFoldWindowItem *wi = new wxFoldWindowItem(window, flags, ySpacing, leftSpacing, rightSpacing); - _items.Add(wi); + m_items.Add(wi); + + bool vertical = this->IsVertical(); + + window->SetSize( vertical ? leftSpacing : m_lastInsertPos + ySpacing, + vertical ? m_lastInsertPos + ySpacing : leftSpacing, + wxDefaultCoord, + wxDefaultCoord, + wxSIZE_USE_EXISTING); - window->SetSize(leftSpacing, _yLastInsertPos + ySpacing, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING); - _yLastInsertPos += wi->GetWindowHeight(); + m_lastInsertPos += wi->GetWindowLength( vertical ); ResizePanel(); } void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing) { - wxFoldWindowItem *wi = new wxFoldWindowItem(_yLastInsertPos, color, ySpacing, leftSpacing, rightSpacing); - _items.Add(wi); + wxFoldWindowItem *wi = new wxFoldWindowItem(m_lastInsertPos, color, ySpacing, leftSpacing, rightSpacing); + m_items.Add(wi); - _yLastInsertPos += wi->GetWindowHeight(); + m_lastInsertPos += wi->GetWindowLength( this->IsVertical() ); ResizePanel(); } @@ -90,7 +102,7 @@ void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int left wxFoldPanelItem::~wxFoldPanelItem() { - _items.Clear(); + m_items.Clear(); } void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent &event) @@ -108,7 +120,7 @@ void wxFoldPanelItem::OnSize(wxSizeEvent &event) { // deny access to pointers (yet) - if(!_controlCreated) + if(!m_controlCreated) { event.Skip(); return; @@ -121,11 +133,11 @@ void wxFoldPanelItem::OnSize(wxSizeEvent &event) //wxSize size(0,wxDefaultCoord); //size.SetWidth(rect.GetWidth()); - //_captionBar->SetSize(size); + //m_captionBar->SetSize(size); } -int wxFoldPanelItem::Reposition(int y) +int wxFoldPanelItem::Reposition(int pos) { // NOTE: Call Resize before Reposition when an item is added, because the new // size needed will be calculated by Resize. Ofcourse the relative position @@ -133,16 +145,25 @@ int wxFoldPanelItem::Reposition(int y) Freeze(); - SetSize(wxDefaultCoord, y, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING); - _yPos = y; + bool vertical = this->IsVertical(); + + SetSize( vertical ? wxDefaultCoord : pos, + vertical ? pos : wxDefaultCoord, + wxDefaultCoord, + wxDefaultCoord, + wxSIZE_USE_EXISTING); + + m_itemPos = pos; Thaw(); - return GetPanelHeight(); + return GetPanelLength(); } void wxFoldPanelItem::ResizePanel() { + bool vertical = IsVertical(); + // prevent unnecessary updates by blocking repaints for a sec Freeze(); @@ -151,33 +172,42 @@ void wxFoldPanelItem::ResizePanel() // user or calulated width (which will be recalculated by the contents here wxSize size; - if(_captionBar->IsCollapsed()) + if(m_captionBar->IsCollapsed()) { - size = _captionBar->GetSize(); - _yPanelSize = size.GetHeight(); + size = m_captionBar->GetSize(); + m_panelSize = vertical ? size.GetHeight() : size.GetWidth(); } else { size = GetBestSize(); - _yPanelSize = size.GetHeight(); + m_panelSize = vertical ? size.GetHeight() : size.GetWidth(); - if(_userSized) - size.SetHeight(_yUserSize); + if(m_userSized) + { + if ( vertical ) + size.SetHeight(m_userSize); + else + size.SetWidth(m_userSize); + } } wxSize pnlsize = GetParent()->GetSize(); - size.SetWidth(pnlsize.GetWidth()); + if ( vertical ) + size.SetWidth(pnlsize.GetWidth()); + else + size.SetHeight(pnlsize.GetHeight()); // resize caption bar - _captionBar->SetSize(wxSize(size.GetWidth(), wxDefaultCoord)); + m_captionBar->SetSize( vertical ? size.GetWidth() : wxDefaultCoord, + vertical ? wxDefaultCoord : size.GetHeight()); // resize the panel SetSize(size); // go by all the controls and call Layout - for(size_t i = 0; i < _items.GetCount(); i++) - _items.Item(i).ResizeItem(size.GetWidth()); + for(size_t i = 0; i < m_items.GetCount(); i++) + m_items.Item(i).ResizeItem( vertical ? size.GetWidth() : size.GetHeight() , vertical ); // and draw all @@ -187,18 +217,35 @@ void wxFoldPanelItem::ResizePanel() void wxFoldPanelItem::OnPaint(wxPaintEvent& WXUNUSED(event)) { // draw all the items that are lines - wxPaintDC dc(this); + bool vertical = IsVertical(); - for(size_t i = 0; i < _items.GetCount(); i++) + for(size_t i = 0; i < m_items.GetCount(); i++) { - wxFoldWindowItem &item = _items.Item(i); + wxFoldWindowItem &item = m_items.Item(i); wxPen pen(item.GetLineColour(), 1, wxSOLID); if(item.GetType() == wxFoldWindowItem::SEPARATOR) { dc.SetPen(pen); - dc.DrawLine(item.GetLeftSpacing(), item.GetLineY() + item.GetYSpacing(), - item.GetLineWidth() + item.GetLeftSpacing(), item.GetLineY() + item.GetYSpacing()); + int a = item.GetLeftSpacing(); + int b = item.GetLineY() + item.GetSpacing(); + int c = item.GetLineLength(); + int d = a + c; + if (vertical) + dc.DrawLine(a, b, d, b); + else + dc.DrawLine(b, a, b, d); } } } + +bool wxFoldPanelItem::IsVertical() const +{ + // grandparent of wxFoldPanelItem is wxFoldPanelBar + // default is vertical + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + wxCHECK_MSG( panel, true, _T("wrong parent") ); + wxFoldPanelBar *bar = wxDynamicCast(panel->GetParent(), wxFoldPanelBar); + wxCHECK_MSG( bar, true, _T("wrong parent") ); + return bar->IsVertical(); +} -- 2.45.2