From 957f5ab77abb14c70c60f18196e1e0d39292ee59 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Aug 2004 11:18:36 +0000 Subject: [PATCH] added foldbar contrib git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/build/foldbar/foldbar.bkl | 36 ++ contrib/include/wx/foldbar/captionbar.h | 454 +++++++++++++++ contrib/include/wx/foldbar/doc_mainpage.h | 68 +++ contrib/include/wx/foldbar/foldpanelbar.h | 281 +++++++++ contrib/include/wx/foldbar/foldpanelitem.h | 256 +++++++++ contrib/samples/foldbar/extended/extended.cpp | 532 ++++++++++++++++++ contrib/samples/foldbar/extended/extended.h | 106 ++++ .../foldbar/foldpanelbar/foldpanelbartest.cpp | 208 +++++++ .../foldbar/foldpanelbar/foldpanelbartest.rc | 4 + .../samples/foldbar/foldpanelbar/foldtest.bkl | 28 + .../foldbar/foldpanelbar/foldtestpanel.cpp | 168 ++++++ .../foldbar/foldpanelbar/foldtestpanel.h | 114 ++++ .../foldbar/foldpanelbar/layouttest.cpp | 145 +++++ .../samples/foldbar/foldpanelbar/layouttest.h | 101 ++++ contrib/samples/foldbar/foldpanelbar/test.cpp | 211 +++++++ contrib/samples/foldbar/foldpanelbar/test.h | 115 ++++ contrib/src/foldbar/captionbar.cpp | 391 +++++++++++++ contrib/src/foldbar/foldpanelbar.cpp | 346 ++++++++++++ contrib/src/foldbar/foldpanelitem.cpp | 200 +++++++ contrib/src/foldbar/icon_collapsed.old.xpm | 22 + contrib/src/foldbar/icon_collapsed.xpm | 36 ++ contrib/src/foldbar/icon_expanded.old.xpm | 22 + contrib/src/foldbar/icon_expanded.xpm | 36 ++ contrib/src/foldbar/icon_theresmore.xpm | 30 + 24 files changed, 3910 insertions(+) create mode 100644 contrib/build/foldbar/foldbar.bkl create mode 100644 contrib/include/wx/foldbar/captionbar.h create mode 100644 contrib/include/wx/foldbar/doc_mainpage.h create mode 100644 contrib/include/wx/foldbar/foldpanelbar.h create mode 100644 contrib/include/wx/foldbar/foldpanelitem.h create mode 100644 contrib/samples/foldbar/extended/extended.cpp create mode 100644 contrib/samples/foldbar/extended/extended.h create mode 100644 contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp create mode 100644 contrib/samples/foldbar/foldpanelbar/foldpanelbartest.rc create mode 100644 contrib/samples/foldbar/foldpanelbar/foldtest.bkl create mode 100644 contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp create mode 100644 contrib/samples/foldbar/foldpanelbar/foldtestpanel.h create mode 100644 contrib/samples/foldbar/foldpanelbar/layouttest.cpp create mode 100644 contrib/samples/foldbar/foldpanelbar/layouttest.h create mode 100644 contrib/samples/foldbar/foldpanelbar/test.cpp create mode 100644 contrib/samples/foldbar/foldpanelbar/test.h create mode 100644 contrib/src/foldbar/captionbar.cpp create mode 100644 contrib/src/foldbar/foldpanelbar.cpp create mode 100644 contrib/src/foldbar/foldpanelitem.cpp create mode 100644 contrib/src/foldbar/icon_collapsed.old.xpm create mode 100644 contrib/src/foldbar/icon_collapsed.xpm create mode 100644 contrib/src/foldbar/icon_expanded.old.xpm create mode 100644 contrib/src/foldbar/icon_expanded.xpm create mode 100644 contrib/src/foldbar/icon_theresmore.xpm diff --git a/contrib/build/foldbar/foldbar.bkl b/contrib/build/foldbar/foldbar.bkl new file mode 100644 index 0000000000..acdbe5bed2 --- /dev/null +++ b/contrib/build/foldbar/foldbar.bkl @@ -0,0 +1,36 @@ + + + + + + + + + captionbar.cpp + foldpanelbar.cpp + foldpanelitem.cpp + + + + + wx/foldbar/captionbar.h + wx/foldbar/foldpanelbar.h + wx/foldbar/foldpanelitem.h + + + + + WXUSINGDLL + WXMAKINGDLL_FOLDBAR + $(FOLDBAR_SRC) + core + base + + + + $(FOLDBAR_SRC) + + + foldbar=foldbarlib+foldbardll + + diff --git a/contrib/include/wx/foldbar/captionbar.h b/contrib/include/wx/foldbar/captionbar.h new file mode 100644 index 0000000000..bf54618544 --- /dev/null +++ b/contrib/include/wx/foldbar/captionbar.h @@ -0,0 +1,454 @@ +#ifndef __FOLDPANELBAR_H__ +#define __FOLDPANELBAR_H__ + +#define wxFPB_EXTRA_X 10 +#define wxFPB_EXTRA_Y 4 +#define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space + +enum +{ + /** 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 + 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 + 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 + 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. +*/ +class wxCaptionBarStyle +{ +private: + // boolean flags for default transparency on styles + bool _firstColourUsed, + _secondColourUsed, + _textColourUsed, + _captionFontUsed, + _captionStyleUsed; + + wxFont _captionFont; + wxColour _firstColour, _secondColour, _textColour; + + int _captionStyle; + +public: + /** Default constructor for this class */ + wxCaptionBarStyle() { + ResetDefaults(); + }; + + ~wxCaptionBarStyle() { + + }; + + 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 + styles are not copied */ + void operator=(const wxCaptionBarStyle &s) { + if(s._captionStyleUsed) + { + _captionStyleUsed = true; + _captionStyle = s._captionStyle; + } + if(s._captionFontUsed) + { + _captionFontUsed = true; + _captionFont = s._captionFont; + } + if(s._firstColourUsed) + { + _firstColourUsed = true; + _firstColour = s._firstColour; + } + if(s._secondColourUsed) + { + _secondColourUsed = true; + _secondColour = s._secondColour; + } + if(s._textColourUsed) + { + _textColourUsed = true; + _textColour = s._textColour; + } + }; + + // ------- CaptionBar Font ------- + + /** 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; + }; + + /** Checks if the caption bar font is set */ + bool CaptionFontUsed() const { + return _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 + \sa SetCaptionFont(), CaptionFontUsed() */ + wxFont GetCaptionFont() const { + wxASSERT(_captionFontUsed); + return _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 + style is used */ + void SetFirstColour(const wxColour &col) { + _firstColour = col; + _firstColourUsed = true; + }; + + /** Checks if the first colour of the caption bar is set */ + bool FirstColourUsed() const { + return _firstColourUsed; + }; + + /** 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; + }; + + // ------- SecondColour ------- + + /** 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; + }; + + /** Checks if the second colour of the caption bar is set */ + bool SecondColourUsed() const { + return _secondColourUsed; + }; + + /** 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; + }; + + // ------- Caption Text Colour ------- + + /** 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; + }; + + /** Checks if the caption colour of the caption bar is set */ + bool CaptionColourUsed() const { + return _textColourUsed; + }; + + /** 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; + }; + + // ------- 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. + 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 + - wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw 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 + */ + void SetCaptionStyle(int style) { + _captionStyle = style; + _captionStyleUsed = true; + }; + + /** Checks if the caption style of the caption bar is set */ + bool CaptionStyleUsed() const { + return _captionStyleUsed; + }; + + /** 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; + }; +}; + +#ifndef _NO_CAPTIONBAR_ + +/** \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. +*/ + +#include + +/** Defines an empty captionbar style */ +#define wxEmptyCaptionBarStyle wxCaptionBarStyle() + +class wxCaptionBar: public wxWindow +{ +private: + wxString _caption; + wxImageList *_foldIcons; + wxSize _oldSize; + //wxFont _captionFont; + int _rightIndent; + int _iconWidth, _iconHeight; + //int _captionStyle; + + //wxColour _firstColour, _secondColour, _textColour; + + /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */ + bool _collapsed; + + wxCaptionBarStyle _style; + + /** Fills the background of the caption with either a gradient, or a solid color */ + void FillCaptionBackground(wxPaintDC &dc); + + /* Draw methods */ + void DrawHorizontalGradient(wxDC &dc, const wxRect &rect ); + void DrawVerticalGradient(wxDC &dc, const wxRect &rect ); + void DrawSingleColour(wxDC &dc, const wxRect &rect ); + void DrawSingleRectangle(wxDC &dc, const wxRect &rect ); + + void RedrawIconBitmap(); + + void ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault); + +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 + 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, + wxWindowID id = -1, 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 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 + changes. */ + wxCaptionBarStyle GetCaptionStyle() { + return _style; + }; + +#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 + 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 + collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and + widht is calculated. + + 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 + all the windows accordingly */ + + void SetFoldIcons(wxImageList *images) { + _foldIcons = images; + _iconWidth = _iconHeight = 0; + if(_foldIcons) + _foldIcons->GetSize(0, _iconWidth, _iconHeight); + + Refresh(); + }; + +#endif + + /** Returns wether the status of the bar is expanded or collapsed */ + bool IsCollapsed() const { + return _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 + assigning an image list to prevent a redraw */ + + void SetRightIndent(int pixels) { + wxCHECK2(pixels >= 0, return); + _rightIndent = pixels; + // issue a refresh (if we have a bmp) + if(_foldIcons) + Refresh(); + }; + + + /** 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; + 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; + RedrawIconBitmap(); + }; + + void SetBoldFont() { + GetFont().SetWeight(wxBOLD); + }; + + void SetNormalFont() { + GetFont().SetWeight(wxNORMAL); + }; + + +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); + + void OnSize(wxSizeEvent &event); + + +protected: + DECLARE_NO_COPY_CLASS(wxCaptionBar) + DECLARE_EVENT_TABLE() +}; + +/***********************************************************************************************************/ + +/** \class wxCaptionBarEvent + 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 */ + +class WXDLLEXPORT wxCaptionBarEvent : public wxCommandEvent +{ + +private: + bool _collapsed; + wxCaptionBar *_bar; + void *_tag; + +public: + wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0) + : wxCommandEvent(commandType, id) + , _collapsed(false) + , _bar(0) + , _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(); + }; + + /** Returns the bar associated with this event */ + wxCaptionBar *GetBar() const { + return _bar; + }; + + void SetTag(void *tag) { + _tag = tag; + }; + + void *GetTag() const { + return _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; + }; + + DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent) + +}; + +BEGIN_DECLARE_EVENT_TYPES() + DECLARE_EVENT_TYPE(wxEVT_CAPTIONBAR, 7777) +END_DECLARE_EVENT_TYPES() + +typedef void (wxEvtHandler::*wxCaptionBarEventFunction)(wxCaptionBarEvent&); + +#define EVT_CAPTIONBAR(id, fn) \ + DECLARE_EVENT_TABLE_ENTRY( \ + wxEVT_CAPTIONBAR, id, -1, \ + (wxObjectEventFunction)(wxEventFunction)(wxCaptionBarEventFunction) \ + & fn, \ + (wxObject *) NULL \ + ), + +#endif // _NO_CAPTIONBAR_ + +#endif diff --git a/contrib/include/wx/foldbar/doc_mainpage.h b/contrib/include/wx/foldbar/doc_mainpage.h new file mode 100644 index 0000000000..96659199b9 --- /dev/null +++ b/contrib/include/wx/foldbar/doc_mainpage.h @@ -0,0 +1,68 @@ +/** \author Jorgen Bodde + \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 + + 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 controls to the panel (it will be resized accordingly) + - Creating panels in collapsed mode or expanded mode + - 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 + + What it cannot do: + + - Selection of a panel like in a list ctrl + - Dragging and dropping the panels + - Re-ordering the panels (not yet) + + Special thanks to Julian Smart et al. for making this great toolkit! +*/ + diff --git a/contrib/include/wx/foldbar/foldpanelbar.h b/contrib/include/wx/foldbar/foldpanelbar.h new file mode 100644 index 0000000000..505229df2f --- /dev/null +++ b/contrib/include/wx/foldbar/foldpanelbar.h @@ -0,0 +1,281 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxFoldPanelBar.h +// Author: XX +// Created: Tuesday, June 22, 2004 20:40:00 +// Copyright: XX +///////////////////////////////////////////////////////////////////////////// + +#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 */ +#define wxFPB_SINGLE_FOLD 0x0001 + +/** All panels are stacked to the bottom. When they are expanded again they show up at the top */ +#define wxFPB_COLLAPSE_TO_BOTTOM 0x0002 + +/** 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 + +/** Default style of the wxFoldPanelBar */ +#define wxFPB_DEFAULT_EXTRASTYLE 0 + +#define wxFPB_DEFAULT_STYLE wxTAB_TRAVERSAL | wxNO_BORDER + +/** \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() + to obtain a parent window reference to create the controls on you want to add with wxFoldPanelBar::AddFoldPanelWindow().

+*/ + +class wxFoldPanel +{ +private: + wxFoldPanelItem *_item; + +public: + /** Constructor, usually not directly used by the developer. */ + wxFoldPanel(wxFoldPanelItem *item) + : _item(item) + { + } + + /** Returns true if this is a valid wxFoldPanelItem reference. */ + bool IsOk() const { + return (_item != 0); + }; + + /** Copy operator to assign one instance to the other, this is needed because these classes are passed + as instance not by reference. */ + virtual void operator=(const wxFoldPanel &item) { + _item = item._item; + }; + +#ifndef _NO_DOXYGEN_ + // not allowed to be seen by doxygen + wxFoldPanelItem *GetItem() const { + return _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("Test me", false); + _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), -1, "Press Me")); + \endcode + */ + wxFoldPanelItem *GetParent() const { + wxASSERT(_item); + return _item; + }; + + +}; + +#include +WX_DEFINE_ARRAY(wxFoldPanelItem *, wxFoldPanelItemArray); + +/** \class wxFoldPanelBar + The wxFoldPanelBar is a class which can maintain a list of collapsable panels. Once a panel is collapsed, only + it's panel bar is visible to the user. This will provide more space for the other panels, or allow the user to + close panels which are not used often to get the most out of the work area. + + 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 + 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 + the panels by doubleclicking on the bar or single click on the arrow, which will indicate the collapsed or + expanded state. +*/ + +class wxFoldPanelBar: public wxPanel +{ +private: + DECLARE_CLASS( wxFoldPanelBar ) + DECLARE_EVENT_TABLE() + + wxImageList *_images; + wxFoldPanelItemArray _panels; + wxBoxSizer* _panelSizer; + wxPanel *_foldPanel, *_bottomPanel; + wxFlexGridSizer* _mainSizer; + bool _controlCreated; + wxBitmap *_moreBmp; + int _extraStyle; + +private: + /** Refreshes all the panels from given index down to last one */ + void RefreshPanelsFrom(size_t i); + + /** 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 + the collapsed panels. */ + int GetPanelsHeight(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 + slack area left between last repositioned panel and the bottom panels. This needs to + get a refresh */ + wxRect RepositionCollapsedToBottom(); + +public: + /** 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! */ + wxFoldPanelBar(); + /** One step creation. Look at wxPanel for the argument and style flags. The extraStyle flags are + - wxFPB_DEFAULT_EXTRASTYLE : Takes default styles. + - wxFPB_COLLAPSE_TO_BOTTOM : When panels are collapsed, they are put at the bottom of the area. */ + wxFoldPanelBar( wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = wxFPB_DEFAULT_STYLE, + long extraStyle = wxFPB_DEFAULT_EXTRASTYLE); + + /** wxFoldPanelBar destructor */ + virtual ~wxFoldPanelBar(); + + /** 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! */ + virtual void Create( wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = wxFPB_DEFAULT_STYLE, + long extraStyle = wxFPB_DEFAULT_EXTRASTYLE); + + /** 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 + 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 + wxFoldPanelBar::AddFoldPanelSeparator() how to add wxWindow items to the panels. */ + wxFoldPanel AddFoldPanel(const wxString &caption, bool collapsedInitially = false, + const wxCaptionBarStyle &style = wxEmptyCaptionBarStyle); + + + /** Adds a wxWindow derived class to the referenced wxFoldPanel. IMPORTANT: Make the to be created window, + child of the wxFoldPanel. See example that follows. The flags to be used are: + - 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. + - 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. + + The wxWindow to be added can be slightly indented from left and right so it is more visibly placed + in the wxFoldPanel. Use ySpacing > 0 to give the control an y offset from the previous wxWindow added, + use leftSpacing to give it a slight indent from the left, and rightSpacing also reserves a little space + 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 + to the wxFoldPanel: + + \code + + // create the wxFoldPanelBar + _pnl = new wxFoldPanelBar(this, -1, 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("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, "Collapse Me")); + + // add a separator between the two controls. This is purely a visual line that can have a certain + // color and also the indents and width alligning like a control. + _pnl->AddFoldPanelSeperator(item); + + // now add a text ctrl. Also very easy. Allign this on width so that when the control gets wider + // the text control also sizes along. + _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), -1, "Comment"), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 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 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 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(); + }; + + /** 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(i >= 0 && i < GetCount(), wxFoldPanel(0)); + return wxFoldPanel(_panels.Item(i)); + }; + + /** Collapses the given wxFoldPanel reference, and updates the foldpanel bar. In the wxFPB_COLLAPSE_TO_BOTTOM + style, all collapsed captions are put at the bottom of the control. In the normal mode, they stay where + they are */ + void Collapse(const wxFoldPanel &item) { + wxCHECK2(item.IsOk(), return); + item.GetItem()->Collapse(); + + RefreshPanelsFrom(item.GetItem()); + }; + + /** 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. */ + void Expand(const wxFoldPanel &item) { + wxCHECK2(item.IsOk(), return); + item.GetItem()->Expand(); + + RefreshPanelsFrom(item.GetItem()); + }; + + /** 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 + what captionbar you want to apply the style to. To apply one style to all wxCaptionBar items, use + ApplyCaptionStyleAll() */ + void ApplyCaptionStyle(wxFoldPanel &fp, const wxCaptionBarStyle &style) { + wxCHECK2(fp.IsOk(), return); + fp.GetItem()->ApplyCaptionStyle(style); + }; + + /** Sets the style of all the caption bars of the wxFoldPanel. The changes are applied immediately */ + void ApplyCaptionStyleAll(const wxCaptionBarStyle &style) { + for(size_t i = 0; i < GetCount(); i++) + { + wxFoldPanel item = Item(i); + ApplyCaptionStyle(item, style); + } + }; + + /** Returns the currently used caption style for the wxFoldPanel. It is returned as a wxCaptionBarStyle class. + after modifying it, it can be set again */ + wxCaptionBarStyle GetCaptionStyle(wxFoldPanel &fp) const { + wxCHECK2(fp.IsOk(), wxEmptyCaptionBarStyle); + return fp.GetItem()->GetCaptionStyle(); + }; + + +private: + void OnPressCaption(wxCaptionBarEvent &event); + void OnSizePanel(wxSizeEvent &event); + + /** Resize the fold panels so they match the width */ + void RedisplayFoldPanelItems(); + + void OnPaint(wxPaintEvent &event); +}; + +#endif // __WXFOLDPANELBAR_H__ diff --git a/contrib/include/wx/foldbar/foldpanelitem.h b/contrib/include/wx/foldbar/foldpanelitem.h new file mode 100644 index 0000000000..623b7b6c68 --- /dev/null +++ b/contrib/include/wx/foldbar/foldpanelitem.h @@ -0,0 +1,256 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxFoldPanelItem.h +// Author: XX +// Created: Tuesday, June 22, 2004 21:01:02 +// Copyright: XX +///////////////////////////////////////////////////////////////////////////// + +#ifndef __WXFOLDPANELITEM_H__ +#define __WXFOLDPANELITEM_H__ + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "captionbar.h" + +#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_LEFTLINESPACING 2 +#define wxFPB_DEFAULT_RIGHTLINESPACING 2 + +class wxFoldWindowItem +{ +private: + wxWindow *_wnd; + int _type, _flags; + int _leftSpacing, + _rightSpacing, + _ySpacing; + int _lineWidth, _lineY; + wxColour _sepLineColour; + +public: + 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) + , _ySpacing(ySpacing) + , _leftSpacing(leftSpacing) + , _rightSpacing(rightSpacing) + , _flags(flags) + , _lineWidth(0) + , _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) + , _ySpacing(ySpacing) + , _leftSpacing(leftSpacing) + , _rightSpacing(rightSpacing) + , _flags(wxFPB_ALIGN_WIDTH) + , _sepLineColour(lineColor) + , _lineWidth(0) + , _lineY(y) + { + }; + + // TODO: Make a c'tor for a captioned splitter + + int GetType() const { + return _type; + }; + + int GetLineY() const { + return _lineY; + }; + + int GetLineWidth() const { + return _lineWidth; + }; + + const wxColour &GetLineColour() const { + return _sepLineColour; + }; + + int GetLeftSpacing() const { + return _leftSpacing; + }; + + int GetRightSpacing() const { + return _rightSpacing; + }; + + int GetYSpacing() const { + return _ySpacing; + }; + + // returns the window height if type is wxFoldWindowItem::WINDOW + // and returns the total size plus the extra spacing + + 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; + + return value; + }; + + // resize the element, whatever it is. A separator or + // line will be always alligned by width + + void ResizeItem(int width) { + if((_flags & wxFPB_ALIGN_WIDTH)) + { + // allign by taking full width + int myWidth = width - _leftSpacing - _rightSpacing; + + if(myWidth < 0) + myWidth = 10; // can't have negative width + + if(_type == SEPARATOR) + _lineWidth = myWidth; + else + { + wxCHECK2(_wnd, return); + _wnd->SetSize(wxSize(myWidth, -1)); + } + } + }; + +}; + +#include +WX_DECLARE_OBJARRAY(wxFoldWindowItem, wxFoldWindowItemArray); + +#ifndef _NO_DOXYGEN_ + +/** \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. +*/ + +class wxFoldPanelItem: public wxPanel +{ +private: + wxCaptionBar *_captionBar; + + bool _controlCreated; + int _yUserSize, + _yPanelSize, + _yLastInsertPos; + int _yPos; + bool _userSized; + +private: + DECLARE_CLASS( wxFoldPanelItem ) + DECLARE_EVENT_TABLE() + +private: + wxFoldWindowItemArray _items; + + void OnSize(wxSizeEvent &event); + void OnPressCaption(wxCaptionBarEvent &event); + void OnPaint(wxPaintEvent &event); + +public: + // constructors and destructors + 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 + list */ + int Reposition(int y); + + void ResizePanel(); + + /** Return expanded or collapsed status. If the panel is expanded, true is returned */ + bool IsExpanded() const { + return !_captionBar->IsCollapsed(); + }; + + /** Return Y pos */ + + int GetY() const { + return _yPos; + }; + + // 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(); + ResizePanel(); + }; + + // 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(); + ResizePanel(); + }; + + /* Return size of panel */ + + int GetPanelHeight() const { + if(_captionBar->IsCollapsed()) + return GetCaptionHeight(); + else if(_userSized) + return _yUserSize; + return _yPanelSize; + }; + + // returns height of caption only. This is for folding calulation + // purposes + + int GetCaptionHeight() const { + wxSize size = _captionBar->GetSize(); + return size.GetHeight(); + }; + + void ApplyCaptionStyle(const wxCaptionBarStyle &style) { + wxCHECK2(_captionBar, return); + _captionBar->SetCaptionStyle(false, style); + }; + + wxCaptionBarStyle GetCaptionStyle() { + wxCHECK(_captionBar, wxEmptyCaptionBarStyle); + return _captionBar->GetCaptionStyle(); + }; +}; + + +#endif // _NO_DOXYGEN_ + +#endif // __WXFOLDPANELITEM_H__ diff --git a/contrib/samples/foldbar/extended/extended.cpp b/contrib/samples/foldbar/extended/extended.cpp new file mode 100644 index 0000000000..e67f8c2e16 --- /dev/null +++ b/contrib/samples/foldbar/extended/extended.cpp @@ -0,0 +1,532 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: expended.cpp +// Purpose: Layout/foldpanelbar sample +// Author: Jorgen Bodde +// Modified by: +// Created: 24/07/2004 +// Copyright: (c) Jorgen Bodde based upon FoldPanelBarTest (c) Julian Smart +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#include "wx/mdi.h" +#endif + +#include "wx/toolbar.h" +#include "wx/laywin.h" +#include +#include + +#include "extended.h" + +MyFrame *frame = NULL; +wxList my_children; + +IMPLEMENT_APP(MyApp) + +// For drawing lines in a canvas +long xpos = -1; +long ypos = -1; + +int winNumber = 1; + +// Initialise this in OnInit, not statically +bool MyApp::OnInit(void) +{ + // Create the main frame window + + frame = new MyFrame(NULL, -1, _T("FoldPanelBar Extended Demo"), wxPoint(-1, -1), wxSize(500, 600), + wxDEFAULT_FRAME_STYLE | + wxNO_FULL_REPAINT_ON_RESIZE | + wxHSCROLL | wxVSCROLL); + + // Give it an icon (this is ignored in MDI mode: uses resources) + +#ifdef __WXMSW__ + frame->SetIcon(wxIcon(_T("sashtest_icn"))); +#endif + + // Associate the menu bar with the frame + frame->SetMenuBar(CreateMenuBar(false)); + + frame->CreateStatusBar(); + + frame->Show(TRUE); + + SetTopWindow(frame); + + return TRUE; +} + +BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame) + EVT_MENU(FPBTEST_ABOUT, MyFrame::OnAbout) + EVT_MENU(FPBTEST_NEW_WINDOW, MyFrame::OnNewWindow) + EVT_SIZE(MyFrame::OnSize) + EVT_MENU(FPBTEST_QUIT, MyFrame::OnQuit) + EVT_MENU(FPBTEST_TOGGLE_WINDOW, MyFrame::OnToggleWindow) + EVT_SASH_DRAGGED_RANGE(ID_WINDOW_TOP, ID_WINDOW_BOTTOM, MyFrame::OnFoldPanelBarDrag) + EVT_MENU(FPB_BOTTOM_STICK, MyFrame::OnCreateBottomStyle) + EVT_MENU(FPB_SINGLE_FOLD, MyFrame::OnCreateNormalStyle) + EVT_BUTTON(ID_COLLAPSEME, MyFrame::OnCollapseMe) + EVT_BUTTON(ID_APPLYTOALL, MyFrame::OnExpandMe) + EVT_SCROLL(MyFrame::OnSlideColour) + EVT_RADIOBUTTON(ID_USE_HGRADIENT, MyFrame::OnStyleChange) + EVT_RADIOBUTTON(ID_USE_VGRADIENT, MyFrame::OnStyleChange) + EVT_RADIOBUTTON(ID_USE_SINGLE, MyFrame::OnStyleChange) + EVT_RADIOBUTTON(ID_USE_RECTANGLE, MyFrame::OnStyleChange) + EVT_RADIOBUTTON(ID_USE_FILLED_RECTANGLE, MyFrame::OnStyleChange) +END_EVENT_TABLE() + + +// Define my frame constructor +MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, + const long style) + : wxMDIParentFrame(parent, id, title, pos, size, style) + , _flags(0) +{ + m_leftWindow1 = new wxSashLayoutWindow(this, ID_WINDOW_LEFT1, + wxDefaultPosition, wxSize(200, 30), + wxNO_BORDER | wxSW_3D | wxCLIP_CHILDREN); + + m_leftWindow1->SetDefaultSize(wxSize(160, 1000)); + m_leftWindow1->SetOrientation(wxLAYOUT_VERTICAL); + m_leftWindow1->SetAlignment(wxLAYOUT_LEFT); + m_leftWindow1->SetSashVisible(wxSASH_RIGHT, TRUE); + m_leftWindow1->SetExtraBorderSize(0); + + _pnl = 0; + ReCreateFoldPanel(0); +} + +void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) +{ + Close(TRUE); +} + +void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) +{ + (void)wxMessageBox(_T("wxWidgets 2.0 FoldPanelBar Demo\nAuthor: Julian Smart (c) 1998"), _T("About FoldPanelBar Demo")); +} + +void MyFrame::OnToggleWindow(wxCommandEvent& WXUNUSED(event)) +{ + m_leftWindow1->Show(!m_leftWindow1->IsShown()); + wxLayoutAlgorithm layout; + layout.LayoutMDIFrame(this); +} + +void MyFrame::OnFoldPanelBarDrag(wxSashEvent& event) +{ + if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE) + return; + + if(event.GetId() == ID_WINDOW_LEFT1) + m_leftWindow1->SetDefaultSize(wxSize(event.GetDragRect().width, 1000)); + + wxLayoutAlgorithm layout; + layout.LayoutMDIFrame(this); + + // Leaves bits of itself behind sometimes + GetClientWindow()->Refresh(); +} + +void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) +{ + // Make another frame, containing a canvas + MyChild *subframe = new MyChild(frame, _T("Canvas Frame"), + wxPoint(10, 10), wxSize(300, 300), + wxDEFAULT_FRAME_STYLE | + wxNO_FULL_REPAINT_ON_RESIZE); + + subframe->SetTitle(wxString::Format(_T("Canvas Frame %d"), winNumber)); + winNumber ++; + + // Give it an icon (this is ignored in MDI mode: uses resources) +#ifdef __WXMSW__ + subframe->SetIcon(wxIcon(_T("sashtest_icn"))); +#endif + + // Give it a status line + subframe->CreateStatusBar(); + + // Associate the menu bar with the frame + subframe->SetMenuBar(CreateMenuBar(true)); + + int width, height; + subframe->GetClientSize(&width, &height); + MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); + canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); + subframe->canvas = canvas; + + // Give it scrollbars + canvas->SetScrollbars(20, 20, 50, 50); + + subframe->Show(TRUE); +} + +void MyFrame::ReCreateFoldPanel(int fpb_flags) +{ + // delete earlier panel + m_leftWindow1->DestroyChildren(); + + // recreate the foldpanelbar + + _pnl = new wxFoldPanelBar(m_leftWindow1, -1, wxDefaultPosition, wxSize(-1,-1), wxFPB_DEFAULT_STYLE, fpb_flags); + + wxFoldPanel item = _pnl->AddFoldPanel("Caption colours", false); + + _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), -1, _T("Adjust the first colour")), + wxFPB_ALIGN_WIDTH, 5, 20); + + // RED color spin control + _rslider1 = new wxSlider(item.GetParent(), -1, 0, 0, 255); + _pnl->AddFoldPanelWindow(item, _rslider1, wxFPB_ALIGN_WIDTH, + 2, 20); + + // GREEN color spin control + _gslider1 = new wxSlider(item.GetParent(), -1, 0, 0, 255); + _pnl->AddFoldPanelWindow(item, _gslider1, wxFPB_ALIGN_WIDTH, + 0, 20); + + // BLUE color spin control + _bslider1 = new wxSlider(item.GetParent(), -1, 0, 0, 255); + _pnl->AddFoldPanelWindow(item, _bslider1, wxFPB_ALIGN_WIDTH, + 0, 20); + + _pnl->AddFoldPanelSeperator(item); + + _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), -1, _T("Adjust the second colour")), + wxFPB_ALIGN_WIDTH, 5, 20); + + // RED color spin control + _rslider2 = new wxSlider(item.GetParent(), -1, 0, 0, 255); + _pnl->AddFoldPanelWindow(item, _rslider2, wxFPB_ALIGN_WIDTH, + 2, 20); + + // GREEN color spin control + _gslider2 = new wxSlider(item.GetParent(), -1, 0, 0, 255); + _pnl->AddFoldPanelWindow(item, _gslider2, wxFPB_ALIGN_WIDTH, + 0, 20); + + // BLUE color spin control + _bslider2 = new wxSlider(item.GetParent(), -1, 0, 0, 255); + _pnl->AddFoldPanelWindow(item, _bslider2, wxFPB_ALIGN_WIDTH, + 0, 20); + + _pnl->AddFoldPanelSeperator(item); + + _btn = new wxButton(item.GetParent(), ID_APPLYTOALL, "Apply to all"); + _pnl->AddFoldPanelWindow(item, _btn); + + // read back current gradients and set the sliders + // for the colour which is now taken as default + + wxCaptionBarStyle style = _pnl->GetCaptionStyle(item); + wxColour col = style.GetFirstColour(); + _rslider1->SetValue(col.Red()); + _gslider1->SetValue(col.Green()); + _bslider1->SetValue(col.Blue()); + + col = style.GetSecondColour(); + _rslider2->SetValue(col.Red()); + _gslider2->SetValue(col.Green()); + _bslider2->SetValue(col.Blue()); + + // put down some caption styles from which the user can + // select to show how the current or all caption bars will look like + + item = _pnl->AddFoldPanel("Caption style", false); + + wxRadioButton *currStyle = new wxRadioButton(item.GetParent(), ID_USE_VGRADIENT, "&Vertical gradient"); + _pnl->AddFoldPanelWindow(item, currStyle, wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + currStyle->SetValue(true); + + _pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_HGRADIENT, "&Horizontal gradient"), + wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + _pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_SINGLE, "&Single colour"), + wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + _pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_RECTANGLE, "&Rectangle box"), + wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + _pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_FILLED_RECTANGLE, "&Filled rectangle box"), + wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + + _pnl->AddFoldPanelSeperator(item); + + _single = new wxCheckBox(item.GetParent(), -1, "&Only this caption"); + _pnl->AddFoldPanelWindow(item, _single, wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + + + // one more panel to finish it + + wxCaptionBarStyle cs; + cs.SetCaptionStyle(wxCAPTIONBAR_RECTANGLE); + + item = _pnl->AddFoldPanel("Misc stuff", true, cs); + + _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, "Collapse All")); + + _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), -1, _T("Enter some comments")), + wxFPB_ALIGN_WIDTH, 5, 20); + + _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), -1, "Comments"), + wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 10); + + m_leftWindow1->SizeWindows(); + +} + +void MyFrame::OnCreateBottomStyle(wxCommandEvent& event) +{ + // recreate with style collapse to bottom, which means + // all panels that are collapsed are placed at the bottom, + // or normal + + if(event.IsChecked()) + _flags |= wxFPB_COLLAPSE_TO_BOTTOM; + else + _flags &= ~wxFPB_COLLAPSE_TO_BOTTOM; + + ReCreateFoldPanel(_flags); +} + +void MyFrame::OnCreateNormalStyle(wxCommandEvent& event) +{ + // receate with style where only one panel at the time is + // allowed to be opened + + // TODO: Not yet implemented! + + if(event.IsChecked()) + _flags |= wxFPB_SINGLE_FOLD; + else + _flags &= ~wxFPB_SINGLE_FOLD; + + ReCreateFoldPanel(_flags); +} + +void MyFrame::OnCollapseMe(wxCommandEvent &event) +{ + wxFoldPanel item(0); + for(size_t i = 0; i < _pnl->GetCount(); i++) + { + item = _pnl->Item(i); + _pnl->Collapse(item); + } +} + +void MyFrame::OnExpandMe(wxCommandEvent &event) +{ + wxColour col1(_rslider1->GetValue(), _gslider1->GetValue(), _bslider1->GetValue()), + col2(_rslider2->GetValue(), _gslider2->GetValue(), _bslider2->GetValue()); + + wxCaptionBarStyle style; + + style.SetFirstColour(col1); + style.SetSecondColour(col2); + + _pnl->ApplyCaptionStyleAll(style); +} + +wxMenuBar *CreateMenuBar(bool with_window) +{ + // Make a menubar + wxMenu *file_menu = new wxMenu; + + file_menu->Append(FPBTEST_NEW_WINDOW, _T("&New window")); + if(with_window) + file_menu->Append(FPBTEST_CHILD_QUIT, _T("&Close child")); + + file_menu->AppendSeparator(); + file_menu->Append(FPBTEST_QUIT, _T("&Exit")); + + wxMenu *option_menu = 0; + if(with_window) + { + // Dummy option + option_menu = new wxMenu; + option_menu->Append(FPBTEST_REFRESH, _T("&Refresh picture")); + } + + // make fold panel menu + + wxMenu *fpb_menu = new wxMenu; + fpb_menu->AppendCheckItem(FPB_BOTTOM_STICK, _T("Create with &wxFPB_COLLAPSE_TO_BOTTOM")); + //fpb_menu->AppendCheckItem(FPB_SINGLE_FOLD, _T("Create with &wxFPB_SINGLE_FOLD")); + + fpb_menu->AppendSeparator(); + fpb_menu->Append(FPBTEST_TOGGLE_WINDOW, _T("&Toggle FoldPanelBar")); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(FPBTEST_ABOUT, _T("&About")); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, _T("&File")); + menu_bar->Append(fpb_menu, _T("&FoldPanel")); + if(option_menu) + menu_bar->Append(option_menu, _T("&Options")); + menu_bar->Append(help_menu, _T("&Help")); + + return menu_bar; +} + +void MyFrame::OnSlideColour(wxScrollEvent &event) +{ + wxColour col1(_rslider1->GetValue(), _gslider1->GetValue(), _bslider1->GetValue()), + col2(_rslider2->GetValue(), _gslider2->GetValue(), _bslider2->GetValue()); + //_btn->SetBackgroundColour(col); + + wxCaptionBarStyle style; + + style.SetFirstColour(col1); + style.SetSecondColour(col2); + + wxFoldPanel item = _pnl->Item(0); + _pnl->ApplyCaptionStyle(item, style); +} + +void MyFrame::OnStyleChange(wxCommandEvent &event) +{ + wxCaptionBarStyle style; + switch(event.GetId()) + { + case ID_USE_HGRADIENT: + style.SetCaptionStyle(wxCAPTIONBAR_GRADIENT_H); + break; + + case ID_USE_VGRADIENT: + style.SetCaptionStyle(wxCAPTIONBAR_GRADIENT_V); + break; + + case ID_USE_SINGLE: + style.SetCaptionStyle(wxCAPTIONBAR_SINGLE); + break; + + case ID_USE_RECTANGLE: + style.SetCaptionStyle(wxCAPTIONBAR_RECTANGLE); + break; + + case ID_USE_FILLED_RECTANGLE: + style.SetCaptionStyle(wxCAPTIONBAR_FILLED_RECTANGLE); + break; + + default: + break; + } + + if(_single->GetValue()) + { + wxFoldPanel item = _pnl->Item(1); + _pnl->ApplyCaptionStyle(item, style); + } + else + _pnl->ApplyCaptionStyleAll(style); + +} + +/* ----------------------------------------------------------------------------------------------- */ + +BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) + EVT_MOUSE_EVENTS(MyCanvas::OnEvent) +END_EVENT_TABLE() + +// Define a constructor for my canvas +MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size) + : wxScrolledWindow(parent, -1, pos, size, + wxSUNKEN_BORDER | wxNO_FULL_REPAINT_ON_RESIZE) +{ + SetBackgroundColour(* wxWHITE); +} + +// Define the repainting behaviour +void MyCanvas::OnDraw(wxDC& dc) +{ + dc.SetFont(*wxSWISS_FONT); + dc.SetPen(*wxGREEN_PEN); + dc.DrawLine(0, 0, 200, 200); + dc.DrawLine(200, 0, 0, 200); + + dc.SetBrush(*wxCYAN_BRUSH); + dc.SetPen(*wxRED_PEN); + dc.DrawRectangle(100, 100, 100, 50); + dc.DrawRoundedRectangle(150, 150, 100, 50, 20); + + dc.DrawEllipse(250, 250, 100, 50); +#if wxUSE_SPLINES + dc.DrawSpline(50, 200, 50, 100, 200, 10); +#endif // wxUSE_SPLINES + dc.DrawLine(50, 230, 200, 230); + dc.DrawText(_T("This is a test string"), 50, 230); + + wxPoint points[3]; + points[0].x = 200; points[0].y = 300; + points[1].x = 100; points[1].y = 400; + points[2].x = 300; points[2].y = 400; + + dc.DrawPolygon(3, points); +} + +// This implements a tiny doodling program! Drag the mouse using +// the left button. +void MyCanvas::OnEvent(wxMouseEvent& event) +{ + wxClientDC dc(this); + PrepareDC(dc); + + wxPoint pt(event.GetLogicalPosition(dc)); + + if (xpos > -1 && ypos > -1 && event.Dragging()) + { + dc.SetPen(*wxBLACK_PEN); + dc.DrawLine(xpos, ypos, pt.x, pt.y); + } + xpos = pt.x; + ypos = pt.y; +} + +void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event)) +{ + wxLayoutAlgorithm layout; + layout.LayoutMDIFrame(this); +} + +// Note that FPBTEST_NEW_WINDOW and FPBTEST_ABOUT commands get passed +// to the parent window for processing, so no need to +// duplicate event handlers here. + +BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) + EVT_MENU(FPBTEST_CHILD_QUIT, MyChild::OnQuit) +END_EVENT_TABLE() + +MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, +const long style): + wxMDIChildFrame(parent, -1, title, pos, size, style) +{ + canvas = NULL; + my_children.Append(this); +} + +MyChild::~MyChild(void) +{ + my_children.DeleteObject(this); +} + +void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) +{ + Close(TRUE); +} + +void MyChild::OnActivate(wxActivateEvent& event) +{ + if (event.GetActive() && canvas) + canvas->SetFocus(); +} + diff --git a/contrib/samples/foldbar/extended/extended.h b/contrib/samples/foldbar/extended/extended.h new file mode 100644 index 0000000000..a30c6222c1 --- /dev/null +++ b/contrib/samples/foldbar/extended/extended.h @@ -0,0 +1,106 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: extended.h +// Purpose: Layout/foldpanelbar sample +// Author: Jorgen Bodde +// Modified by: +// Created: 24/07/2004 +// Copyright: Jorgen Bodde based upon FoldPanelBar sample (c) Julian Smart +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include "wx/toolbar.h" +#include "foldpanelbar.h" + +wxMenuBar *CreateMenuBar(bool with_window); + +enum +{ + ID_COLLAPSEME = 10000, + ID_APPLYTOALL, + ID_USE_HGRADIENT, + ID_USE_VGRADIENT, + ID_USE_SINGLE, + ID_USE_RECTANGLE, + ID_USE_FILLED_RECTANGLE +}; + +// Define a new application +class MyApp: public wxApp +{ + public: + bool OnInit(void); +}; + +class MyCanvas: public wxScrolledWindow +{ + public: + MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size); + virtual void OnDraw(wxDC& dc); + void OnEvent(wxMouseEvent& event); + + DECLARE_EVENT_TABLE() +}; + +// Define a new frame +class MyFrame: public wxMDIParentFrame +{ + public: + + MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); + + void OnSize(wxSizeEvent& event); + void OnAbout(wxCommandEvent& event); + void OnNewWindow(wxCommandEvent& event); + void OnQuit(wxCommandEvent& event); + void OnToggleWindow(wxCommandEvent& event); + void OnFoldPanelBarDrag(wxSashEvent& event); + void OnCreateBottomStyle(wxCommandEvent& event); + void OnCreateNormalStyle(wxCommandEvent& event); + + void OnCollapseMe(wxCommandEvent &event); + void OnExpandMe(wxCommandEvent &event); + + void OnSlideColour(wxScrollEvent &event); + + void OnStyleChange(wxCommandEvent &event); + +protected: + wxSashLayoutWindow* m_leftWindow1; + +private: + void ReCreateFoldPanel(int fpb_flags); + wxFoldPanelBar *_pnl; + wxButton *_btn; + wxCheckBox *_single; + wxSlider *_rslider1, *_gslider1, *_bslider1, *_rslider2, *_gslider2, *_bslider2; + int _flags; + +DECLARE_EVENT_TABLE() +}; + +class MyChild: public wxMDIChildFrame +{ + public: + MyCanvas *canvas; + MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); + ~MyChild(void); + void OnActivate(wxActivateEvent& event); + void OnQuit(wxCommandEvent& event); + +DECLARE_EVENT_TABLE() +}; + +#define FPBTEST_QUIT 1 +#define FPBTEST_NEW_WINDOW 2 +#define FPBTEST_REFRESH 3 +#define FPBTEST_CHILD_QUIT 4 +#define FPBTEST_ABOUT 5 +#define FPBTEST_TOGGLE_WINDOW 6 +#define FPB_BOTTOM_STICK 7 +#define FPB_SINGLE_FOLD 8 + +#define ID_WINDOW_TOP 100 +#define ID_WINDOW_LEFT1 101 +#define ID_WINDOW_LEFT2 102 +#define ID_WINDOW_BOTTOM 103 + diff --git a/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp b/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp new file mode 100644 index 0000000000..69a3bed261 --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp @@ -0,0 +1,208 @@ + +///////////////////////////////////////////////////////////////////////////// +// Name: FoldPanelBarTest.cpp +// Purpose: FoldPanelBarTest Test application +// Created: 06/18/04 +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +enum +{ + ID_COLLAPSEME = 10000, + ID_EXPANDME +}; + +#include "wx/foldbar/foldpanelbar.h" +#include "foldtestpanel.h" + +// ---------------------------------------------------------------------------- +// resources +// ---------------------------------------------------------------------------- + +// the application icon (under Windows and OS/2 it is in resources) +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__) + #include "mondrian.xpm" +#endif + +// ---------------------------------------------------------------------------- +// MyApp Class +// ---------------------------------------------------------------------------- + +class MyApp : public wxApp +{ +public: + virtual bool OnInit(); +}; + +// ---------------------------------------------------------------------------- +// MyAppFrame Class +// ---------------------------------------------------------------------------- + +class MyAppFrame : public wxFrame +{ +public: + MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, + long style = wxDEFAULT_FRAME_STYLE); + +private: + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + + // extra handlers for the bar, to show how it works + + void OnCollapseMe(wxCommandEvent &event); + void OnExpandMe(wxCommandEvent &event); + +private: + wxMenuBar *CreateMenuBar(); + wxFoldPanelBar *_pnl; + +private: + DECLARE_EVENT_TABLE() +}; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +enum +{ + // menu items + FoldPanelBarTest_Quit = 1, + FoldPanelBarTest_About = wxID_ABOUT +}; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +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) +END_EVENT_TABLE() + +IMPLEMENT_APP(MyApp) + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// MyApp Implementation +// ---------------------------------------------------------------------------- + +bool MyApp::OnInit() +{ + MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWindows Test Application"), + wxPoint(50, 50), wxSize(200, 500)); + + SetTopWindow(frame); + + frame->Show(TRUE); + return TRUE; +} + +// ---------------------------------------------------------------------------- +// MyAppFrame Implementation +// ---------------------------------------------------------------------------- + +MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) + : wxFrame(NULL, -1, title, pos, size, style) +{ + SetIcon(wxICON(mondrian)); + + SetMenuBar(CreateMenuBar()); + + CreateStatusBar(2); + SetStatusText(_T("Welcome to wxWindows!")); + + _pnl = new wxFoldPanelBar(this, -1, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, wxFPB_COLLAPSE_TO_BOTTOM); + + wxFoldPanel item = _pnl->AddFoldPanel("Test me", false); + _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, "Collapse Me")); + + item = _pnl->AddFoldPanel("Test me too!", true); + _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, "Expand first one")); + _pnl->AddFoldPanelSeperator(item); + _pnl->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), -1)); + + _pnl->AddFoldPanelSeperator(item); + + _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), -1, "Comment"), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20); + + item = _pnl->AddFoldPanel("Some opinions ...", false); + _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "I like this")); + _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "And also this")); + _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "And gimme this too")); + + _pnl->AddFoldPanelSeperator(item); + + _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "Check this too if you like")); + _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "What about this")); + + + item = _pnl->AddFoldPanel("Choose one ...", false); + _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), -1, "Enter your comment")); + _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), -1, "Comment"), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20); + +} + +wxMenuBar *MyAppFrame::CreateMenuBar() +{ + wxMenuBar *value = 0; + + wxMenu *menuFile = new wxMenu; + menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); + + wxMenu *helpMenu = new wxMenu; + helpMenu->Append(FoldPanelBarTest_About, _T("&About...\tF1"), _T("Show about dialog")); + + value = new wxMenuBar(); + value->Append(menuFile, _T("&File")); + value->Append(helpMenu, _T("&Help")); + + return value; +} + +// event handlers + + + +void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) +{ + // TRUE is to force the frame to close + Close(TRUE); +} + +void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) +{ + wxString msg; + msg.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n") + _T("Welcome to %s"), wxVERSION_STRING); + + wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this); +} + +void MyAppFrame::OnCollapseMe(wxCommandEvent &event) +{ + wxFoldPanel item = _pnl->Item(0); + _pnl->Collapse(item); +} + +void MyAppFrame::OnExpandMe(wxCommandEvent &event) +{ + _pnl->Expand(_pnl->Item(0)); + _pnl->Collapse(_pnl->Item(1)); +} diff --git a/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.rc b/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.rc new file mode 100644 index 0000000000..545d02f478 --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/foldpanelbartest.rc @@ -0,0 +1,4 @@ +mondrian ICON "mondrian.ico" + +#define FOLDPANELBARTEST_QUIT 1 +#define FOLDPANELBARTEST_ABOUT 102 diff --git a/contrib/samples/foldbar/foldpanelbar/foldtest.bkl b/contrib/samples/foldbar/foldpanelbar/foldtest.bkl new file mode 100644 index 0000000000..ff150a2eee --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/foldtest.bkl @@ -0,0 +1,28 @@ + + + + $(SRCDIR)/../../../include + + + + + foldpanelbartest.cpp + foldtestpanel.cpp + layouttest.cpp + test.cpp + + foldbar + core + base + foldpanelbartest.rc + + + + $(BUILDDIR) + $(SRCDIR) + + mondrian.ico + + + + diff --git a/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp new file mode 100644 index 0000000000..d8688d0489 --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.cpp @@ -0,0 +1,168 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: foldtestpanel.cpp +// Purpose: +// Author: Jorgen Bodde +// Modified by: +// Created: 06/18/04 22:37:15 +// RCS-ID: +// Copyright: +// Licence: +///////////////////////////////////////////////////////////////////////////// + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma implementation "foldtestpanel.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +////@begin includes +////@end includes + +#include "foldtestpanel.h" + + +////@begin XPM images +////@end XPM images + +/*! + * FoldTestPanel type definition + */ + +IMPLEMENT_CLASS( FoldTestPanel, wxPanel ) + +/*! + * FoldTestPanel event table definition + */ +BEGIN_EVENT_TABLE( FoldTestPanel, wxPanel ) + +////@begin FoldTestPanel event table entries +////@end FoldTestPanel event table entries + + //EVT_CAPTIONBAR(-1, FoldTestPanel::OnCaptionPanel) + EVT_CAPTIONBAR(wxID_ANY, FoldTestPanel::OnCaptionPanel) + + +END_EVENT_TABLE() + +/*! + * FoldTestPanel constructors + */ + +FoldTestPanel::FoldTestPanel( ) +{ + delete _images; +} + +FoldTestPanel::FoldTestPanel( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) +{ + Create(parent, id, caption, pos, size, style); +} + +/*! + * FoldTestPanel creator + */ + +bool FoldTestPanel::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) +{ +////@begin FoldTestPanel member initialisation + blaat = NULL; +////@end FoldTestPanel member initialisation + +////@begin FoldTestPanel creation + SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS); + wxPanel::Create( parent, id, pos, size, style ); + + CreateControls(); + GetSizer()->Fit(this); + GetSizer()->SetSizeHints(this); + Centre(); +////@end FoldTestPanel creation + return TRUE; +} + +/*! + * Control creation for FoldTestPanel + */ + +void FoldTestPanel::CreateControls() +{ + +////@begin FoldTestPanel content construction + + FoldTestPanel* item1 = this; + + wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL); + blaat = item2; + item1->SetSizer(item2); + item1->SetAutoLayout(TRUE); + /* wxPanel* item3 = new wxPanel( item1, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL ); */ + wxPanel* item3 = new wxPanel( item1, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL ); + item2->Add(item3, 1, wxGROW|wxADJUST_MINSIZE, 5); + wxBoxSizer* item4 = new wxBoxSizer(wxVERTICAL); + item3->SetSizer(item4); + item3->SetAutoLayout(TRUE); + wxString item5Strings[] = { + _("One"), + _("Two"), + _("Three") + }; + wxChoice* item5 = new wxChoice( item3, ID_CHOICE, wxDefaultPosition, wxDefaultSize, 3, item5Strings, 0 ); + item4->Add(item5, 0, wxGROW|wxALL, 5); + wxTextCtrl* item6 = new wxTextCtrl( item3, ID_TEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); + item4->Add(item6, 1, wxGROW|wxALL, 5); + wxRadioButton* item7 = new wxRadioButton( item3, ID_RADIOBUTTON, _("I like this"), wxDefaultPosition, wxDefaultSize, 0 ); + item7->SetValue(TRUE); + item4->Add(item7, 0, wxALIGN_LEFT|wxALL, 5); + wxRadioButton* item8 = new wxRadioButton( item3, ID_RADIOBUTTON1, _("I hate it"), wxDefaultPosition, wxDefaultSize, 0 ); + item8->SetValue(FALSE); + item4->Add(item8, 0, wxALIGN_LEFT|wxALL, 5); +////@end FoldTestPanel content construction +} + +void FoldTestPanel::OnCaptionPanel(wxCaptionBarEvent &event) +{ + // TODO: What else +} + +/*! + * Should we show tooltips? + */ + +bool FoldTestPanel::ShowToolTips() +{ + return TRUE; +} + +/*! + * Get bitmap resources + */ + +wxBitmap FoldTestPanel::GetBitmapResource( const wxString& name ) +{ + // Bitmap retrieval +////@begin FoldTestPanel bitmap retrieval + return wxNullBitmap; +////@end FoldTestPanel bitmap retrieval +} + +/*! + * Get icon resources + */ + +wxIcon FoldTestPanel::GetIconResource( const wxString& name ) +{ + // Icon retrieval +////@begin FoldTestPanel icon retrieval + return wxNullIcon; +////@end FoldTestPanel icon retrieval +} + diff --git a/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h new file mode 100644 index 0000000000..ef00ec4b16 --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/foldtestpanel.h @@ -0,0 +1,114 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: foldtestpanel.h +// Purpose: +// Author: Jorgen Bodde +// Modified by: +// Created: 06/18/04 22:37:15 +// RCS-ID: +// Copyright: +// Licence: +///////////////////////////////////////////////////////////////////////////// + +#ifndef _FOLDTESTPANEL_H_ +#define _FOLDTESTPANEL_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "foldtestpanel.cpp" +#endif + +/*! + * Includes + */ + +#include "wx/foldbar/captionbar.h" + +////@begin includes +////@end includes + +/*! + * Forward declarations + */ + +////@begin forward declarations +class wxBoxSizer; +////@end forward declarations + +/*! + * Control identifiers + */ + +////@begin control identifiers +#define ID_TESTPANEL 10000 +#define SYMBOL_FOLDTESTPANEL_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX +#define SYMBOL_FOLDTESTPANEL_TITLE _("FoldTestPanel") +#define SYMBOL_FOLDTESTPANEL_IDNAME ID_TESTPANEL +#define SYMBOL_FOLDTESTPANEL_SIZE wxSize(400, 300) +#define SYMBOL_FOLDTESTPANEL_POSITION wxDefaultPosition +#define ID_PANEL 10002 +#define ID_CHOICE 10003 +#define ID_TEXTCTRL 10016 +#define ID_RADIOBUTTON 10004 +#define ID_RADIOBUTTON1 10005 +////@end control identifiers + +/*! + * Compatibility + */ + +#ifndef wxCLOSE_BOX +#define wxCLOSE_BOX 0x1000 +#endif +#ifndef wxFIXED_MINSIZE +#define wxFIXED_MINSIZE 0 +#endif + +/*! + * FoldTestPanel class declaration + */ + +class FoldTestPanel: public wxPanel +{ + DECLARE_CLASS( FoldTestPanel ) + DECLARE_EVENT_TABLE() + +private: + wxImageList *_images; + wxRect _oldsize; + + void OnCaptionPanel(wxCaptionBarEvent &event); + +public: + /// Constructors + FoldTestPanel( ); + FoldTestPanel( wxWindow* parent, wxWindowID id = SYMBOL_FOLDTESTPANEL_IDNAME, const wxString& caption = SYMBOL_FOLDTESTPANEL_TITLE, const wxPoint& pos = SYMBOL_FOLDTESTPANEL_POSITION, const wxSize& size = SYMBOL_FOLDTESTPANEL_SIZE, long style = SYMBOL_FOLDTESTPANEL_STYLE ); + + /// Creation + bool Create( wxWindow* parent, wxWindowID id = SYMBOL_FOLDTESTPANEL_IDNAME, const wxString& caption = SYMBOL_FOLDTESTPANEL_TITLE, const wxPoint& pos = SYMBOL_FOLDTESTPANEL_POSITION, const wxSize& size = SYMBOL_FOLDTESTPANEL_SIZE, long style = SYMBOL_FOLDTESTPANEL_STYLE ); + + /// Creates the controls and sizers + void CreateControls(); + +////@begin FoldTestPanel event handler declarations + +////@end FoldTestPanel event handler declarations + +////@begin FoldTestPanel member function declarations + + + /// Retrieves bitmap resources + wxBitmap GetBitmapResource( const wxString& name ); + + /// Retrieves icon resources + wxIcon GetIconResource( const wxString& name ); +////@end FoldTestPanel member function declarations + + /// Should we show tooltips? + static bool ShowToolTips(); + +////@begin FoldTestPanel member variables + wxBoxSizer* blaat; +////@end FoldTestPanel member variables +}; + +#endif + // _FOLDTESTPANEL_H_ diff --git a/contrib/samples/foldbar/foldpanelbar/layouttest.cpp b/contrib/samples/foldbar/foldpanelbar/layouttest.cpp new file mode 100644 index 0000000000..c0a23bff8f --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/layouttest.cpp @@ -0,0 +1,145 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: layouttest.cpp +// Purpose: +// Author: Jorgen Bodde +// Modified by: +// Created: 06/25/04 19:48:57 +// RCS-ID: +// Copyright: +// Licence: +///////////////////////////////////////////////////////////////////////////// + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma implementation "layouttest.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +////@begin includes +////@end includes + +#include "layouttest.h" + +////@begin XPM images +////@end XPM images + +/*! + * LayoutTest type definition + */ + +IMPLEMENT_CLASS( LayoutTest, wxPanel ) + +/*! + * LayoutTest event table definition + */ + +BEGIN_EVENT_TABLE( LayoutTest, wxPanel ) + +////@begin LayoutTest event table entries +////@end LayoutTest event table entries + +END_EVENT_TABLE() + +/*! + * LayoutTest constructors + */ + +LayoutTest::LayoutTest( ) +{ +} + +LayoutTest::LayoutTest( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) +{ + Create(parent, id, caption, pos, size, style); +} + +/*! + * LayoutTest creator + */ + +bool LayoutTest::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) +{ +////@begin LayoutTest member initialisation +////@end LayoutTest member initialisation + +////@begin LayoutTest creation + SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS); + wxPanel::Create( parent, id, pos, size, style ); + + CreateControls(); + GetSizer()->Fit(this); + GetSizer()->SetSizeHints(this); + Centre(); +////@end LayoutTest creation + return TRUE; +} + +/*! + * Control creation for LayoutTest + */ + +void LayoutTest::CreateControls() +{ +////@begin LayoutTest content construction + + LayoutTest* item1 = this; + + wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL); + item1->SetSizer(item2); + item1->SetAutoLayout(TRUE); + wxStaticText* item3 = new wxStaticText( item1, wxID_STATIC, _("lbaaaaaa"), wxDefaultPosition, wxDefaultSize, 0 ); + item3->SetBackgroundColour(wxColour(139, 139, 139)); + item2->Add(item3, 0, wxGROW|wxALL|wxADJUST_MINSIZE, 5); + wxPanel* item4 = new wxPanel( item1, ID_PANEL1, wxDefaultPosition, wxSize(100, 80), wxTAB_TRAVERSAL ); + item2->Add(item4, 0, wxGROW, 5); + wxBoxSizer* item5 = new wxBoxSizer(wxVERTICAL); + item4->SetSizer(item5); + item4->SetAutoLayout(TRUE); + wxStaticText* item6 = new wxStaticText( item4, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); + item5->Add(item6, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); + wxButton* item7 = new wxButton( item4, ID_BUTTON, _("Button"), wxDefaultPosition, wxDefaultSize, 0 ); + item5->Add(item7, 0, wxALIGN_LEFT|wxALL, 5); +////@end LayoutTest content construction +} + +/*! + * Should we show tooltips? + */ + +bool LayoutTest::ShowToolTips() +{ + return TRUE; +} + +/*! + * Get bitmap resources + */ + +wxBitmap LayoutTest::GetBitmapResource( const wxString& name ) +{ + // Bitmap retrieval +////@begin LayoutTest bitmap retrieval + return wxNullBitmap; +////@end LayoutTest bitmap retrieval +} + +/*! + * Get icon resources + */ + +wxIcon LayoutTest::GetIconResource( const wxString& name ) +{ + // Icon retrieval +////@begin LayoutTest icon retrieval + return wxNullIcon; +////@end LayoutTest icon retrieval +} diff --git a/contrib/samples/foldbar/foldpanelbar/layouttest.h b/contrib/samples/foldbar/foldpanelbar/layouttest.h new file mode 100644 index 0000000000..96b44f7c04 --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/layouttest.h @@ -0,0 +1,101 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: layouttest.h +// Purpose: +// Author: Jorgen Bodde +// Modified by: +// Created: 06/25/04 19:48:57 +// RCS-ID: +// Copyright: +// Licence: +///////////////////////////////////////////////////////////////////////////// + +#ifndef _LAYOUTTEST_H_ +#define _LAYOUTTEST_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "layouttest.cpp" +#endif + +/*! + * Includes + */ + +////@begin includes +////@end includes + +/*! + * Forward declarations + */ + +////@begin forward declarations +////@end forward declarations + +/*! + * Control identifiers + */ + +////@begin control identifiers +#define ID_DIALOG 10001 +#define SYMBOL_LAYOUTTEST_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX +#define SYMBOL_LAYOUTTEST_TITLE _("Layout Test") +#define SYMBOL_LAYOUTTEST_IDNAME ID_DIALOG +#define SYMBOL_LAYOUTTEST_SIZE wxSize(400, 300) +#define SYMBOL_LAYOUTTEST_POSITION wxDefaultPosition +#define ID_PANEL1 10006 +#define ID_BUTTON 10007 +////@end control identifiers + +/*! + * Compatibility + */ + +#ifndef wxCLOSE_BOX +#define wxCLOSE_BOX 0x1000 +#endif +#ifndef wxFIXED_MINSIZE +#define wxFIXED_MINSIZE 0 +#endif + +/*! + * LayoutTest class declaration + */ + +class LayoutTest: public wxPanel +{ + DECLARE_CLASS( LayoutTest ) + DECLARE_EVENT_TABLE() + +public: + /// Constructors + LayoutTest( ); + LayoutTest( wxWindow* parent, wxWindowID id = SYMBOL_LAYOUTTEST_IDNAME, const wxString& caption = SYMBOL_LAYOUTTEST_TITLE, const wxPoint& pos = SYMBOL_LAYOUTTEST_POSITION, const wxSize& size = SYMBOL_LAYOUTTEST_SIZE, long style = SYMBOL_LAYOUTTEST_STYLE ); + + /// Creation + bool Create( wxWindow* parent, wxWindowID id = SYMBOL_LAYOUTTEST_IDNAME, const wxString& caption = SYMBOL_LAYOUTTEST_TITLE, const wxPoint& pos = SYMBOL_LAYOUTTEST_POSITION, const wxSize& size = SYMBOL_LAYOUTTEST_SIZE, long style = SYMBOL_LAYOUTTEST_STYLE ); + + /// Creates the controls and sizers + void CreateControls(); + +////@begin LayoutTest event handler declarations + +////@end LayoutTest event handler declarations + +////@begin LayoutTest member function declarations + + + /// Retrieves bitmap resources + wxBitmap GetBitmapResource( const wxString& name ); + + /// Retrieves icon resources + wxIcon GetIconResource( const wxString& name ); +////@end LayoutTest member function declarations + + /// Should we show tooltips? + static bool ShowToolTips(); + +////@begin LayoutTest member variables +////@end LayoutTest member variables +}; + +#endif + // _LAYOUTTEST_H_ diff --git a/contrib/samples/foldbar/foldpanelbar/test.cpp b/contrib/samples/foldbar/foldpanelbar/test.cpp new file mode 100644 index 0000000000..710a9f0942 --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/test.cpp @@ -0,0 +1,211 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: test.cpp +// Purpose: +// Author: Jorgen Bodde +// Modified by: +// Created: 06/27/04 13:34:20 +// RCS-ID: +// Copyright: +// Licence: +///////////////////////////////////////////////////////////////////////////// + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma implementation "test.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +////@begin includes +////@end includes + +#include "test.h" + +////@begin XPM images +////@end XPM images + +/*! + * TestTest type definition + */ + +IMPLEMENT_CLASS( TestTest, wxDialog ) + +/*! + * TestTest event table definition + */ + +BEGIN_EVENT_TABLE( TestTest, wxDialog ) + +////@begin TestTest event table entries +////@end TestTest event table entries + +END_EVENT_TABLE() + +/*! + * TestTest constructors + */ + +TestTest::TestTest( ) +{ +} + +TestTest::TestTest( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) +{ + Create(parent, id, caption, pos, size, style); +} + +/*! + * TestTest creator + */ + +bool TestTest::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) +{ +////@begin TestTest member initialisation + blaat = NULL; + blaat = NULL; +////@end TestTest member initialisation + +////@begin TestTest creation + SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS); + wxDialog::Create( parent, id, caption, pos, size, style ); + + CreateControls(); + GetSizer()->Fit(this); + GetSizer()->SetSizeHints(this); + Centre(); +////@end TestTest creation + return TRUE; +} + +/*! + * Control creation for TestTest + */ + +void TestTest::CreateControls() +{ +////@begin TestTest content construction + + TestTest* item1 = this; + + wxFlexGridSizer* item2 = new wxFlexGridSizer(2, 1, 0, 0); + item2->AddGrowableRow(0); + item2->AddGrowableCol(0); + item1->SetSizer(item2); + item1->SetAutoLayout(TRUE); + wxPanel* item3 = new wxPanel( item1, ID_PANEL7, wxDefaultPosition, wxSize(100, 50), wxNO_BORDER|wxTAB_TRAVERSAL ); + item2->Add(item3, 1, wxGROW|wxGROW|wxADJUST_MINSIZE, 5); + wxBoxSizer* item4 = new wxBoxSizer(wxVERTICAL); + item3->SetSizer(item4); + item3->SetAutoLayout(TRUE); + wxPanel* item5 = new wxPanel( item3, ID_PANEL6, wxDefaultPosition, wxSize(100, 80), wxSUNKEN_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL ); + item4->Add(item5, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5); + wxFlexGridSizer* item6 = new wxFlexGridSizer(2, 1, 0, 0); + item6->AddGrowableRow(1); + item6->AddGrowableCol(0); + item5->SetSizer(item6); + item5->SetAutoLayout(TRUE); + wxStaticText* item7 = new wxStaticText( item5, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); + item6->Add(item7, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL|wxADJUST_MINSIZE, 5); + wxPanel* item8 = new wxPanel( item5, ID_PANEL3, wxDefaultPosition, wxSize(100, 80), wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); + item6->Add(item8, 1, wxGROW|wxGROW|wxALL, 5); + wxBoxSizer* item9 = new wxBoxSizer(wxVERTICAL); + blaat = item9; + item8->SetSizer(item9); + item8->SetAutoLayout(TRUE); + wxPanel* item10 = new wxPanel( item8, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL ); + item9->Add(item10, 1, wxGROW, 5); + wxBoxSizer* item11 = new wxBoxSizer(wxVERTICAL); + item10->SetSizer(item11); + item10->SetAutoLayout(TRUE); + wxString item12Strings[] = { + _("One"), + _("Two"), + _("Three") + }; + wxChoice* item12 = new wxChoice( item10, ID_CHOICE, wxDefaultPosition, wxDefaultSize, 3, item12Strings, 0 ); + item11->Add(item12, 0, wxGROW|wxALL, 5); + wxRadioButton* item13 = new wxRadioButton( item10, ID_RADIOBUTTON, _("I like this"), wxDefaultPosition, wxDefaultSize, 0 ); + item13->SetValue(TRUE); + item11->Add(item13, 0, wxALIGN_LEFT|wxALL, 5); + wxRadioButton* item14 = new wxRadioButton( item10, ID_RADIOBUTTON1, _("I hate it"), wxDefaultPosition, wxDefaultSize, 0 ); + item14->SetValue(FALSE); + item11->Add(item14, 0, wxALIGN_LEFT|wxALL, 5); + wxPanel* item15 = new wxPanel( item3, ID_PANEL2, wxDefaultPosition, wxSize(100, 80), wxSUNKEN_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL ); + item4->Add(item15, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5); + wxFlexGridSizer* item16 = new wxFlexGridSizer(2, 1, 0, 0); + item16->AddGrowableRow(1); + item16->AddGrowableCol(0); + item15->SetSizer(item16); + item15->SetAutoLayout(TRUE); + wxStaticText* item17 = new wxStaticText( item15, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); + item16->Add(item17, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL|wxADJUST_MINSIZE|wxFIXED_MINSIZE, 5); + wxPanel* item18 = new wxPanel( item15, ID_PANEL4, wxDefaultPosition, wxSize(100, 80), wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); + item16->Add(item18, 0, wxGROW|wxGROW|wxALL, 5); + wxBoxSizer* item19 = new wxBoxSizer(wxVERTICAL); + blaat = item19; + item18->SetSizer(item19); + item18->SetAutoLayout(TRUE); + wxPanel* item20 = new wxPanel( item18, ID_PANEL5, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL ); + item19->Add(item20, 1, wxGROW, 5); + wxBoxSizer* item21 = new wxBoxSizer(wxVERTICAL); + item20->SetSizer(item21); + item20->SetAutoLayout(TRUE); + wxString item22Strings[] = { + _("One"), + _("Two"), + _("Three") + }; + wxChoice* item22 = new wxChoice( item20, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 3, item22Strings, 0 ); + item21->Add(item22, 0, wxGROW|wxALL, 5); + wxRadioButton* item23 = new wxRadioButton( item20, ID_RADIOBUTTON2, _("I like this"), wxDefaultPosition, wxDefaultSize, 0 ); + item23->SetValue(TRUE); + item21->Add(item23, 0, wxALIGN_LEFT|wxALL, 5); + wxRadioButton* item24 = new wxRadioButton( item20, ID_RADIOBUTTON3, _("I hate it"), wxDefaultPosition, wxDefaultSize, 0 ); + item24->SetValue(FALSE); + item21->Add(item24, 0, wxALIGN_LEFT|wxALL, 5); + wxPanel* item25 = new wxPanel( item1, ID_PANEL1, wxDefaultPosition, wxSize(100, 20), wxNO_BORDER|wxTAB_TRAVERSAL ); + item25->SetBackgroundColour(wxColour(98, 98, 98)); + item2->Add(item25, 0, wxGROW|wxGROW|wxFIXED_MINSIZE, 5); +////@end TestTest content construction +} + +/*! + * Should we show tooltips? + */ + +bool TestTest::ShowToolTips() +{ + return TRUE; +} + +/*! + * Get bitmap resources + */ + +wxBitmap TestTest::GetBitmapResource( const wxString& name ) +{ + // Bitmap retrieval +////@begin TestTest bitmap retrieval + return wxNullBitmap; +////@end TestTest bitmap retrieval +} + +/*! + * Get icon resources + */ + +wxIcon TestTest::GetIconResource( const wxString& name ) +{ + // Icon retrieval +////@begin TestTest icon retrieval + return wxNullIcon; +////@end TestTest icon retrieval +} diff --git a/contrib/samples/foldbar/foldpanelbar/test.h b/contrib/samples/foldbar/foldpanelbar/test.h new file mode 100644 index 0000000000..1acf964b5a --- /dev/null +++ b/contrib/samples/foldbar/foldpanelbar/test.h @@ -0,0 +1,115 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: test.h +// Purpose: +// Author: Jorgen Bodde +// Modified by: +// Created: 06/27/04 13:34:20 +// RCS-ID: +// Copyright: +// Licence: +///////////////////////////////////////////////////////////////////////////// + +#ifndef _TEST_H_ +#define _TEST_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "test.cpp" +#endif + +/*! + * Includes + */ + +////@begin includes +////@end includes + +/*! + * Forward declarations + */ + +////@begin forward declarations +class wxBoxSizer; +////@end forward declarations + +/*! + * Control identifiers + */ + +////@begin control identifiers +#define ID_DIALOG 10001 +#define SYMBOL_TESTTEST_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX +#define SYMBOL_TESTTEST_TITLE _("Test Me") +#define SYMBOL_TESTTEST_IDNAME ID_DIALOG +#define SYMBOL_TESTTEST_SIZE wxSize(400, 200) +#define SYMBOL_TESTTEST_POSITION wxDefaultPosition +#define ID_PANEL7 10015 +#define ID_PANEL6 10014 +#define ID_PANEL3 10008 +#define ID_PANEL 10002 +#define ID_CHOICE 10003 +#define ID_RADIOBUTTON 10004 +#define ID_RADIOBUTTON1 10005 +#define ID_PANEL2 10007 +#define ID_PANEL4 10009 +#define ID_PANEL5 10010 +#define ID_CHOICE1 10011 +#define ID_RADIOBUTTON2 10012 +#define ID_RADIOBUTTON3 10013 +#define ID_PANEL1 10006 +////@end control identifiers + +/*! + * Compatibility + */ + +#ifndef wxCLOSE_BOX +#define wxCLOSE_BOX 0x1000 +#endif +#ifndef wxFIXED_MINSIZE +#define wxFIXED_MINSIZE 0 +#endif + +/*! + * TestTest class declaration + */ + +class TestTest: public wxDialog +{ + DECLARE_CLASS( TestTest ) + DECLARE_EVENT_TABLE() + +public: + /// Constructors + TestTest( ); + TestTest( wxWindow* parent, wxWindowID id = SYMBOL_TESTTEST_IDNAME, const wxString& caption = SYMBOL_TESTTEST_TITLE, const wxPoint& pos = SYMBOL_TESTTEST_POSITION, const wxSize& size = SYMBOL_TESTTEST_SIZE, long style = SYMBOL_TESTTEST_STYLE ); + + /// Creation + bool Create( wxWindow* parent, wxWindowID id = SYMBOL_TESTTEST_IDNAME, const wxString& caption = SYMBOL_TESTTEST_TITLE, const wxPoint& pos = SYMBOL_TESTTEST_POSITION, const wxSize& size = SYMBOL_TESTTEST_SIZE, long style = SYMBOL_TESTTEST_STYLE ); + + /// Creates the controls and sizers + void CreateControls(); + +////@begin TestTest event handler declarations + +////@end TestTest event handler declarations + +////@begin TestTest member function declarations + + + /// Retrieves bitmap resources + wxBitmap GetBitmapResource( const wxString& name ); + + /// Retrieves icon resources + wxIcon GetIconResource( const wxString& name ); +////@end TestTest member function declarations + + /// Should we show tooltips? + static bool ShowToolTips(); + +////@begin TestTest member variables + wxBoxSizer* blaat; +////@end TestTest member variables +}; + +#endif + // _TEST_H_ diff --git a/contrib/src/foldbar/captionbar.cpp b/contrib/src/foldbar/captionbar.cpp new file mode 100644 index 0000000000..e95402feba --- /dev/null +++ b/contrib/src/foldbar/captionbar.cpp @@ -0,0 +1,391 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: captionbar.cpp +// Purpose: wxCaptionBar class belonging to the wxFoldPanel (but can be used independent) +// Author: Jorgen Bodde +// Modified by: +// Created: June 18, 2004 +// RCS-ID: +// Copyright: (c) Jorgen Bodde +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) +#pragma implementation "foldpanelbar.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/dcmemory.h" +#include "wx/dcclient.h" +#endif + +#include + +#include "wx/foldbar/captionbar.h" + +/* + * wxCaptionBar + */ + +BEGIN_EVENT_TABLE(wxCaptionBar, wxWindow) + EVT_PAINT(wxCaptionBar::OnPaint) + EVT_CHAR(wxCaptionBar::OnChar) + EVT_MOUSE_EVENTS(wxCaptionBar::OnMouseEvent) + EVT_SIZE(wxCaptionBar::OnSize) +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) + , _collapsed(false) + , _foldIcons(images) + , _rightIndent(wxFPB_BMP_RIGHTSPACE) + , _iconWidth(16) + , _iconHeight(16) +{ + // do initialisy thingy stuff + + ApplyCaptionStyle(cbstyle, true); + + // set initial size + if(_foldIcons) + { + wxASSERT(_foldIcons->GetImageCount() > 1); + _foldIcons->GetSize(0, _iconWidth, _iconHeight); + } +} + +wxCaptionBar::~wxCaptionBar() +{ + +} + +void wxCaptionBar::ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault) +{ + wxASSERT(GetParent()); + + wxCaptionBarStyle newstyle = cbstyle; + + // set defaults in newly created style copy if needed + if(applyDefault) + { + // get first colour from style or make it default + if(!newstyle.FirstColourUsed()) + newstyle.SetFirstColour(*wxWHITE); + + // get second colour from style or make it default + if(!newstyle.SecondColourUsed()) + { + // make the second colour slightly darker then the background + wxColour col = GetParent()->GetBackgroundColour(); + col.Set((col.Red() >> 1) + 20, (col.Green() >> 1) + 20, (col.Blue() >> 1) + 20); + newstyle.SetSecondColour(col); + } + + // get text colour + if(!newstyle.CaptionColourUsed()) + newstyle.SetCaptionColour(*wxBLACK); + + // get font colour + if(!newstyle.CaptionFontUsed()) + newstyle.SetCaptionFont(GetParent()->GetFont()); + + // apply caption style + if(!newstyle.CaptionStyleUsed()) + newstyle.SetCaptionStyle(wxCAPTIONBAR_GRADIENT_V); + } + + // apply the style + _style = newstyle; +} + +void wxCaptionBar::OnPaint(wxPaintEvent& WXUNUSED(event)) +{ + wxPaintDC dc(this); + + // 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 + + // draw basics + + FillCaptionBackground(dc); + + dc.SetFont(_style.GetCaptionFont()); + dc.DrawText(_caption, 4, (wxFPB_EXTRA_Y / 2)); + + // draw small icon, either collapsed or expanded + // based on the state of the bar. If we have + // any bmp's + + if(_foldIcons) + { + wxCHECK2(_foldIcons->GetImageCount() > 1, return); + + int index = 0; + if(_collapsed) + index = 1; + + wxRect wndRect = GetRect(); + _foldIcons->Draw(index, dc, wndRect.GetRight() - _iconWidth - _rightIndent, (wndRect.GetHeight() - _iconHeight) / 2, + wxIMAGELIST_DRAW_TRANSPARENT); + } +} + +void wxCaptionBar::FillCaptionBackground(wxPaintDC &dc) +{ + // dispatch right style for caption drawing + + switch(_style.GetCaptionStyle()) + { + case wxCAPTIONBAR_GRADIENT_V: + DrawVerticalGradient(dc, GetRect()); + break; + case wxCAPTIONBAR_GRADIENT_H: + DrawHorizontalGradient(dc, GetRect()); + break; + case wxCAPTIONBAR_SINGLE: + DrawSingleColour(dc, GetRect()); + break; + case wxCAPTIONBAR_RECTANGLE: + case wxCAPTIONBAR_FILLED_RECTANGLE: + DrawSingleRectangle(dc, GetRect()); + break; + default: + break; + } +} + +void wxCaptionBar::OnMouseEvent(wxMouseEvent& event) +{ + // if clicked on the arrow (single) or double on the caption + // we change state and an event must be fired to let this + // panel collapse or expand + + bool send_event = false; + + if (event.LeftDown() && _foldIcons) + { + wxPoint pt(event.GetPosition()); + wxRect rect = GetRect(); + + if(pt.x > (rect.GetWidth() - _iconWidth - _rightIndent)) + send_event = true; + } + else if(event.LeftDClick()) + send_event = true; + + // send the collapse, expand event to the parent + + if(send_event) + { + wxCaptionBarEvent event(wxEVT_CAPTIONBAR); + event.SetBar(this); + + ::wxPostEvent(this, event); + + } +} + +void wxCaptionBar::OnChar(wxKeyEvent &event) +{ + // TODO: Anything here? + + event.Skip(); +} + +wxSize wxCaptionBar::DoGetBestSize() const +{ + int x,y; + + GetTextExtent(_caption, &x, &y); + + if(x < _iconWidth) + x = _iconWidth; + + if(y < _iconHeight) + y = _iconHeight; + + // TODO: The extra wxFPB_EXTRA_X constants should be adjustable as well + + return wxSize(x + wxFPB_EXTRA_X, y + wxFPB_EXTRA_Y); +} + + +void wxCaptionBar::DrawVerticalGradient(wxDC &dc, const wxRect &rect ) +{ + // gradient fill from colour 1 to colour 2 with top to bottom + + if(rect.height < 1 || rect.width < 1) + return; + + dc.SetPen(*wxTRANSPARENT_PEN); + + + // calculate gradient coefficients + wxColour col2 = _style.GetSecondColour(), + col1 = _style.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; + + wxColour currCol; + for(int y = rect.y; y < rect.y + rect.height; y++) + { + currCol.Set(col1.Red() + rf, col1.Green() + gf, col1.Blue() + bf); + dc.SetBrush( wxBrush( currCol, wxSOLID ) ); + dc.DrawRectangle( rect.x, rect.y + (y - rect.y), rect.width, rect.height ); + //currCol.Set(currCol.Red() + rstep, currCol.Green() + gstep, currCol.Blue() + bstep); + rf += rstep; gf += gstep; bf += bstep; + } +} + +void wxCaptionBar::DrawHorizontalGradient(wxDC &dc, const wxRect &rect ) +{ + // gradient fill from colour 1 to colour 2 with left to right + + if(rect.height < 1 || rect.width < 1) + return; + + dc.SetPen(*wxTRANSPARENT_PEN); + + // calculate gradient coefficients + wxColour col2 = _style.GetSecondColour(), + col1 = _style.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; + + wxColour currCol; + for(int x = rect.x; x < rect.x + rect.width; x++) + { + currCol.Set(col1.Red() + rf, col1.Green() + gf, col1.Blue() + bf); + dc.SetBrush( wxBrush( currCol, wxSOLID ) ); + dc.DrawRectangle( rect.x + (x - rect.x), rect.y, 1, rect.height ); + rf += rstep; gf += gstep; bf += bstep; + } +} + +void wxCaptionBar::DrawSingleColour(wxDC &dc, const wxRect &rect ) +{ + // single colour fill. This is the most easy one to find + + if(rect.height < 1 || rect.width < 1) + return; + + dc.SetPen(*wxTRANSPARENT_PEN); + + // draw simple rectangle + dc.SetBrush( wxBrush( _style.GetFirstColour(), wxSOLID ) ); + dc.DrawRectangle( rect.x, rect.y, rect.width, rect.height ); +} + +void wxCaptionBar::DrawSingleRectangle(wxDC &dc, const wxRect &rect ) +{ + wxASSERT(GetParent()); + + // single colour fill. This is the most easy one to find + + if(rect.height < 2 || rect.width < 1) + return; + + // single frame, set up internal fill colour + + wxBrush br; + br.SetStyle(wxSOLID); + + if(_style.GetCaptionStyle() == wxCAPTIONBAR_RECTANGLE) + br.SetColour(GetParent()->GetBackgroundColour()); + else + br.SetColour(_style.GetFirstColour()); + + // setup the pen frame + + wxPen pen(_style.GetSecondColour()); + dc.SetPen(pen); + + dc.SetBrush( br ); + dc.DrawRectangle( rect.x, rect.y, rect.width, rect.height - 1); + + wxPen bgpen(GetParent()->GetBackgroundColour()); + dc.SetPen(bgpen); + dc.DrawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1); +} + + +void wxCaptionBar::OnSize(wxSizeEvent &event) +{ + wxSize size = event.GetSize(); + + if(_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, + // I don't need a bitmap calulation in it, or do I ? The bitmap needs redrawing anyway. Leave it + // like this until I figured it out + + // set rect to redraw as old bitmap area which is entitled to redraw + + wxRect rect(size.GetWidth() - _iconWidth - _rightIndent, 0, _iconWidth + _rightIndent, + _iconWidth + _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(); + if(diffX > 1) + { + // adjust the rect with all the crap to redraw + + rect.SetWidth(rect.GetWidth() + diffX + 10); + rect.SetX(rect.GetX() - diffX - 10); + } + + RefreshRect(rect); + } + else + { + wxRect rect = GetRect(); + RefreshRect(rect); + } + + _oldSize = size; +} + +void wxCaptionBar::RedrawIconBitmap() +{ + if(_foldIcons) + { + // invalidate the bitmap area and force a redraw + + wxRect rect = GetRect(); + + rect.SetX(rect.GetWidth() - _iconWidth - _rightIndent); + rect.SetWidth(_iconWidth + _rightIndent); + RefreshRect(rect); + } +} + +/* + * wxCaptionBarEvent + */ + +DEFINE_EVENT_TYPE(wxEVT_CAPTIONBAR) + +wxCaptionBarEvent::wxCaptionBarEvent(const wxCaptionBarEvent &event) + : wxCommandEvent(event) +{ + _bar = event._bar; +} + +//DEFINE_EVENT_TYPE(wxEVT_CAPTIONBAR) +//IMPLEMENT_DYNAMIC_CLASS(wxCaptionBarEvent, wxEvent) +IMPLEMENT_DYNAMIC_CLASS(wxCaptionBarEvent, wxCommandEvent) diff --git a/contrib/src/foldbar/foldpanelbar.cpp b/contrib/src/foldbar/foldpanelbar.cpp new file mode 100644 index 0000000000..f9f067e2cd --- /dev/null +++ b/contrib/src/foldbar/foldpanelbar.cpp @@ -0,0 +1,346 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxFoldPanelBar.cpp +// Author: XX +// Created: Tuesday, June 22, 2004 20:40:00 +// Copyright: XX +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/foldbar/foldpanelbar.h" +#include "icon_collapsed.xpm" +#include "icon_expanded.xpm" +#include "icon_theresmore.xpm" + +//---------------------------------------------------------------------------- +// wxFoldPanelBar +//---------------------------------------------------------------------------- + +IMPLEMENT_CLASS( wxFoldPanelBar, wxPanel ) + +BEGIN_EVENT_TABLE(wxFoldPanelBar,wxPanel) + EVT_SIZE(wxFoldPanelBar::OnSizePanel) + //EVT_PAINT(wxFoldPanelBar::OnPaint) + EVT_CAPTIONBAR(-1, wxFoldPanelBar::OnPressCaption) +END_EVENT_TABLE() + +wxFoldPanelBar::wxFoldPanelBar() +{ + +} + +wxFoldPanelBar::wxFoldPanelBar( wxWindow *parent, wxWindowID id, const wxPoint &position, + const wxSize& size, long style, long extraStyle) + : _foldPanel(0) + , _bottomPanel(0) + , _controlCreated(false) +{ + Create( parent, id, position, size, style, extraStyle); +} + +void wxFoldPanelBar::Create( wxWindow *parent, wxWindowID id, const wxPoint &position, + const wxSize& size, long style, long extraStyle ) +{ + + _extraStyle = extraStyle; + + // create the panel (duh!). This causes a size event, which we are going + // to skip when we are not initialised + + wxPanel::Create(parent, id, position, size, style); + + // the fold panel area + + _foldPanel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL); + + // the extra area for some icons / context menu etc + +#if 0 + _bottomPanel = new wxPanel(this, -1, wxDefaultPosition, wxSize(-1,22), wxNO_BORDER|wxTAB_TRAVERSAL); + _bottomPanel->SetBackgroundColour(*wxWHITE); +#endif + + // create the fold icons to be used in the captions + + _images = new wxImageList(16, 16); + + wxBitmap *bmp = new wxBitmap(icon_expanded); + _images->Add(*bmp); + delete bmp; + + bmp = new wxBitmap(icon_collapsed); + _images->Add(*bmp); + delete bmp; + + _moreBmp = new wxBitmap(icon_theresmore); + + // do this as last, to check if create is already called + + _controlCreated = true; +} + +wxFoldPanelBar::~wxFoldPanelBar() +{ + delete _images; + delete _moreBmp; +} + +wxFoldPanel wxFoldPanelBar::AddFoldPanel(const wxString &caption, bool collapsedInitially, const wxCaptionBarStyle &style) +{ + wxASSERT(_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); + + // look at the last added one and reposition this one + int y = 0; + if(_panels.GetCount() > 0) + y = _panels.Last()->GetY() + _panels.Last()->GetPanelHeight(); + + item->Reposition(y); + _panels.Add(item); + + //return wxFoldPanel(item); + return wxFoldPanel(item); +} + +int wxFoldPanelBar::AddFoldPanelWindow(const wxFoldPanel &panel, wxWindow *window, int flags, int ySpacing, int leftSpacing, + int rightSpacing) +{ + wxCHECK(panel.IsOk(), -1); + panel.GetItem()->AddWindow(window, flags, ySpacing, leftSpacing, rightSpacing); + + // TODO: Take old and new height, and if difference, reposition all the lower panels + // this is because the user can add new wxWindow controls somewhere in between + // when other panels are already present. + + return 0; +} + +int wxFoldPanelBar::AddFoldPanelSeperator(const wxFoldPanel &panel, const wxColour &color, int ySpacing, int leftSpacing, + int rightSpacing) +{ + wxCHECK(panel.IsOk(), -1); + panel.GetItem()->AddSeparator(color, ySpacing, leftSpacing, rightSpacing); + + return 0; +} + +void wxFoldPanelBar::OnSizePanel(wxSizeEvent &event) +{ + // skip all stuff when we are not initialised yet + + if(!_controlCreated) + { + event.Skip(); + return; + } + + // now size the fold panel area and the + // lower bar in such a way that the bar is always + // visible + + wxRect foldrect = GetRect(); + + // fold panel itself. If too little space, + // don't show it + +#if 0 + if(foldrect.GetHeight() < 23) + foldrect.SetHeight(0); + else + foldrect.SetHeight(foldrect.GetHeight() - 22); +#endif + + foldrect.SetX(0); + foldrect.SetY(0); + _foldPanel->SetSize(foldrect); + + if(_extraStyle & wxFPB_COLLAPSE_TO_BOTTOM) + { + wxRect rect = RepositionCollapsedToBottom(); + if(rect.GetHeight() > 0) + RefreshRect(rect); + } + + // TODO: A smart way to check wether the old - new width of the + // panel changed, if so no need to resize the fold panel items + + RedisplayFoldPanelItems(); + + // tool panel for icons and other stuff + +#if 0 + wxRect bottomrect = GetRect(); + if(bottomrect.GetHeight() < 22) + bottomrect.SetY(0); + else + bottomrect.SetY(bottomrect.GetHeight() - 22); + + bottomrect.SetHeight(22); + bottomrect.SetX(0); + _bottomPanel->SetSize(bottomrect); + + // TODO: redraw the bitmap properly + // use the captionbar algorithm for that + + _bottomPanel->Refresh(); +#endif +} + +void wxFoldPanelBar::OnPaint(wxPaintEvent &event) +{ + if(!_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); + + wxSize size = _bottomPanel->GetSize(); + int offset = (size.GetHeight() - _moreBmp->GetHeight()) / 2; + + dc.DrawBitmap(*_moreBmp, size.GetWidth() - _moreBmp->GetWidth() - 2, offset, true); +#endif + + event.Skip(); +} + +void wxFoldPanelBar::OnPressCaption(wxCaptionBarEvent &event) +{ + // act upon the folding or expanding status of the bar + // to expand or collapse the panel(s) + + if(event.GetFoldStatus()) + Collapse(wxFoldPanel((wxFoldPanelItem *)event.GetTag())); + else + Expand(wxFoldPanel((wxFoldPanelItem *)event.GetTag())); +} + +void wxFoldPanelBar::RefreshPanelsFrom(wxFoldPanelItem *item) +{ + wxASSERT(item); + + size_t i = _panels.Index(item); + if(i != wxNOT_FOUND) + RefreshPanelsFrom(i); +} + +void wxFoldPanelBar::RefreshPanelsFrom(size_t i) +{ + Freeze(); + + // if collapse to bottom is on, the panels that are not expanded + // 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) + { + int offset = 0; + + for(size_t j = 0; j < _panels.GetCount(); j++) + { + if(_panels.Item(j)->IsExpanded()) + offset += _panels.Item(j)->Reposition(offset); + } + + // put all non collapsed panels at the bottom where there is space, else + // put them right behind the expanded ones + + RepositionCollapsedToBottom(); + } + else + { + int y = _panels.Item(i)->GetY() + _panels.Item(i)->GetPanelHeight(); + for(i++; i < _panels.GetCount(); i++) + y += _panels.Item(i)->Reposition(y); + } + Thaw(); +} + +void wxFoldPanelBar::RedisplayFoldPanelItems() +{ + // resize them all. No need to reposition + + wxFoldPanelItem *item; + for(size_t i = 0; i < _panels.GetCount(); i++) + { + item = _panels.Item(i); + wxASSERT(item); + + item->ResizePanel(); + } +} + +wxRect wxFoldPanelBar::RepositionCollapsedToBottom() +{ + wxRect value(0,0,0,0); + + // 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); + + // if no room stick them behind the normal ones, else + // at the bottom + + if((GetSize().GetHeight() - expanded - collapsed) < 0) + offset = expanded; + else + { + // value is the region which is left unpainted + // 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.SetWidth(GetSize().GetWidth()); + + offset = GetSize().GetHeight() - collapsed; + } + + + // go reposition + + for(size_t i = 0; i < _panels.GetCount(); i++) + { + if(!_panels.Item(i)->IsExpanded()) + offset += _panels.Item(i)->Reposition(offset); + } + + return value; +} + +int wxFoldPanelBar::GetPanelsHeight(int &collapsed, int &expanded) +{ + int value = 0, offset = 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++) + { + offset = _panels.Item(j)->GetPanelHeight(); + value += offset; + if(_panels.Item(j)->IsExpanded()) + expanded += offset; + else + collapsed += offset; + } + + return value; + +} \ No newline at end of file diff --git a/contrib/src/foldbar/foldpanelitem.cpp b/contrib/src/foldbar/foldpanelitem.cpp new file mode 100644 index 0000000000..0b632863ba --- /dev/null +++ b/contrib/src/foldbar/foldpanelitem.cpp @@ -0,0 +1,200 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxFoldPanelItem.cpp +// Author: XX +// Created: Tuesday, June 22, 2004 21:01:02 +// Copyright: XX +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/foldbar/foldpanelitem.h" + +#include +WX_DEFINE_OBJARRAY(wxFoldWindowItemArray); + +//---------------------------------------------------------------------------- +// wxFoldPanelItem +//---------------------------------------------------------------------------- + +IMPLEMENT_CLASS( wxFoldPanelItem, wxPanel ) + +BEGIN_EVENT_TABLE(wxFoldPanelItem,wxPanel) + EVT_CAPTIONBAR(-1, wxFoldPanelItem::OnPressCaption) + EVT_PAINT(wxFoldPanelItem::OnPaint) + //EVT_SIZE(wxFoldPanelItem::OnSize) +END_EVENT_TABLE() + +wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons, bool collapsedInitially, + const wxCaptionBarStyle &style ) + : _controlCreated(false) + , _yUserSize(0) + , _yPanelSize(0) + , _yPos(0) + , _userSized(false) + , _yLastInsertPos(0) +{ + wxCHECK2(parent, return); + + wxPanel::Create(parent, -1); + + // create the caption bar, in collapsed or expanded state + + _captionBar = new wxCaptionBar(this, caption, icons, -1, style, wxPoint(0,0)); + //_captionBar->SetBoldFont(); + + if(collapsedInitially) + _captionBar->Collapse(); + + _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; +} + +void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing) +{ + wxASSERT(window); + + wxFoldWindowItem *wi = new wxFoldWindowItem(window, flags, ySpacing, leftSpacing, rightSpacing); + _items.Add(wi); + + window->SetSize(leftSpacing, _yLastInsertPos + ySpacing, -1, -1, wxSIZE_USE_EXISTING); + _yLastInsertPos += wi->GetWindowHeight(); + + 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); + + _yLastInsertPos += wi->GetWindowHeight(); + + ResizePanel(); +} + + +wxFoldPanelItem::~wxFoldPanelItem() +{ + _items.Clear(); +} + +void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent &event) +{ + // tell the upper container we are responsible + // for this event, so it can fold the panel item + // and do a refresh + + event.SetTag((void *)this); + event.Skip(); +} + +/* Inactive */ +void wxFoldPanelItem::OnSize(wxSizeEvent &event) +{ + // deny access to pointers (yet) + + if(!_controlCreated) + { + event.Skip(); + return; + } + + // calculate the size needed for this window, so + // we get the parent size, and determine the size for the caption and the panel + + //wxRect rect = GetRect(); + + //wxSize size(0,-1); + //size.SetWidth(rect.GetWidth()); + //_captionBar->SetSize(size); + +} + +int wxFoldPanelItem::Reposition(int y) +{ + // NOTE: Call Resize before Reposition when an item is added, because the new + // size needed will be calculated by Resize. Ofcourse the relative position + // of the controls have to be correct in respect to the caption bar + + Freeze(); + + SetSize(-1, y, -1, -1, wxSIZE_USE_EXISTING); + _yPos = y; + + Thaw(); + + return GetPanelHeight(); +} + +void wxFoldPanelItem::ResizePanel() +{ + // prevent unnecessary updates by blocking repaints for a sec + + Freeze(); + + // force this panel to take the width of the parent panel and the y of the + // user or calulated width (which will be recalculated by the contents here + + wxSize size; + if(_captionBar->IsCollapsed()) + { + size = _captionBar->GetSize(); + _yPanelSize = size.GetHeight(); + } + else + { + size = GetBestSize(); + _yPanelSize = size.GetHeight(); + + if(_userSized) + size.SetHeight(_yUserSize); + } + + wxSize pnlsize = GetParent()->GetSize(); + size.SetWidth(pnlsize.GetWidth()); + + // resize caption bar + _captionBar->SetSize(wxSize(size.GetWidth(), -1)); + + // 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()); + + // and draw all + + Thaw(); +} + +void wxFoldPanelItem::OnPaint(wxPaintEvent& WXUNUSED(event)) +{ + // draw all the items that are lines + + wxPaintDC dc(this); + + for(size_t i = 0; i < _items.GetCount(); i++) + { + wxFoldWindowItem &item = _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()); + } + } +} diff --git a/contrib/src/foldbar/icon_collapsed.old.xpm b/contrib/src/foldbar/icon_collapsed.old.xpm new file mode 100644 index 0000000000..583b47da9b --- /dev/null +++ b/contrib/src/foldbar/icon_collapsed.old.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * icon_collapsed[] = { +"16 16 3 1", +" c #00FFFF", +". c None", +"+ c #000000", +"................", +"................", +".......+........", +".......+........", +"......+++.......", +"......+++.......", +".....+++++......", +".....+++++......", +"....+++++++.....", +"....+++++++.....", +"...+++++++++....", +"...+++++++++....", +"..+++++++++++...", +"..+++++++++++...", +"................", +"................"}; diff --git a/contrib/src/foldbar/icon_collapsed.xpm b/contrib/src/foldbar/icon_collapsed.xpm new file mode 100644 index 0000000000..e8e1b1443d --- /dev/null +++ b/contrib/src/foldbar/icon_collapsed.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *icon_collapsed[] = { +"16 16 16 2", +"00 c black", +"01 c #800000", +"02 c #008000", +"03 c #808000", +"04 c #000080", +"05 c #800080", +"06 c #008080", +"07 c #C0C0C0", +"08 c #808080", +"09 c red", +"10 c green", +"11 c yellow", +"12 c blue", +"13 c none", +"14 c cyan", +"15 c gray100", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313001313131313131313", +"13131313131313001313131313131313", +"13131313131300000013131313131313", +"13131313131300000013131313131313", +"13131313130000000000131313131313", +"13131313130000000000131313131313", +"13131313000000000000001313131313", +"13131313000000000000001313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313" +}; diff --git a/contrib/src/foldbar/icon_expanded.old.xpm b/contrib/src/foldbar/icon_expanded.old.xpm new file mode 100644 index 0000000000..2d6b0130a4 --- /dev/null +++ b/contrib/src/foldbar/icon_expanded.old.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * icon_expanded[] = { +"16 16 3 1", +" c #00FFFF", +". c None", +"+ c #000000", +"................", +"................", +"..+++++++++++...", +"..+++++++++++...", +"...+++++++++....", +"...+++++++++....", +"....+++++++.....", +"....+++++++.....", +".....+++++......", +".....+++++......", +"......+++.......", +"......+++.......", +".......+........", +".......+........", +"................", +"................"}; diff --git a/contrib/src/foldbar/icon_expanded.xpm b/contrib/src/foldbar/icon_expanded.xpm new file mode 100644 index 0000000000..fd1e138bf9 --- /dev/null +++ b/contrib/src/foldbar/icon_expanded.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *icon_expanded[] = { +"16 16 16 2", +"00 c black", +"01 c #800000", +"02 c #008000", +"03 c #808000", +"04 c #000080", +"05 c #800080", +"06 c #008080", +"07 c #C0C0C0", +"08 c #808080", +"09 c red", +"10 c green", +"11 c yellow", +"12 c blue", +"13 c none", +"14 c cyan", +"15 c gray100", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313000000000000001313131313", +"13131313000000000000001313131313", +"13131313130000000000131313131313", +"13131313130000000000131313131313", +"13131313131300000013131313131313", +"13131313131300000013131313131313", +"13131313131313001313131313131313", +"13131313131313001313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313", +"13131313131313131313131313131313" +}; diff --git a/contrib/src/foldbar/icon_theresmore.xpm b/contrib/src/foldbar/icon_theresmore.xpm new file mode 100644 index 0000000000..82b35b22a4 --- /dev/null +++ b/contrib/src/foldbar/icon_theresmore.xpm @@ -0,0 +1,30 @@ +/* XPM */ +static char *icon_theresmore[] = { +"7 10 16 2", +"00 c black", +"01 c none", +"02 c gray100", +"03 c gray100", +"04 c gray100", +"05 c gray100", +"06 c gray100", +"07 c gray100", +"08 c gray100", +"09 c gray100", +"10 c gray100", +"11 c gray100", +"12 c gray100", +"13 c gray100", +"14 c gray100", +"15 c gray100", +"01010101010101", +"01010100010101", +"01010000000101", +"01000001000001", +"00000101010000", +"00010100010100", +"01010000000101", +"01000001000001", +"00000101010000", +"00010101010100" +}; -- 2.47.2