1///////////////////////////////////////////////////////////////////////////// 2// Name: foldpanelitem.h 3// Purpose: wxFoldPanel 4// Author: Jorgen Bodde 5// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation 6// : wxWidgets coding standards 7// Created: 22/06/2004 8// RCS-ID: $Id: foldpanelitem.h 34972 2005-07-28 23:23:27Z VZ $ 9// Copyright: (c) Jorgen Bodde 10// Licence: wxWindows licence 11///////////////////////////////////////////////////////////////////////////// 12 13#ifndef __WXFOLDPANELITEM_H__ 14#define __WXFOLDPANELITEM_H__ 15 16#include "wx/foldbar/captionbar.h" 17 18#define wxFPB_ALIGN_LEFT 0 19#define wxFPB_ALIGN_WIDTH 1 20 21#define wxFPB_DEFAULT_LEFTSPACING 5 22#define wxFPB_DEFAULT_RIGHTSPACING 10 23#define wxFPB_DEFAULT_SPACING 8 24 25#define wxFPB_DEFAULT_LEFTLINESPACING 2 26#define wxFPB_DEFAULT_RIGHTLINESPACING 2 27 28class wxFoldWindowItem 29{ 30private: 31 wxWindow *m_wndItem; 32 int m_type, m_flags; 33 int m_leftSpacing, 34 m_rightSpacing, 35 m_Spacing; 36 int m_lineLength, m_lineY; 37 wxColour m_sepLineColour; 38 39public: 40 enum 41 { 42 WINDOW = 0, 43 SEPARATOR 44 }; 45 46 // wxWindow constructor. This initialises the class as a wxWindow type 47 wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int Spacing = wxFPB_DEFAULT_SPACING, 48 int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing = wxFPB_DEFAULT_RIGHTSPACING) 49 : m_wndItem(wnd) 50 , m_type(WINDOW) 51 , m_flags(flags) 52 , m_leftSpacing(leftSpacing) 53 , m_rightSpacing(rightSpacing) 54 , m_Spacing(Spacing) 55 , m_lineLength(0) 56 , m_lineY(0) 57 { 58 }; 59 60 // separator constructor. This initialises the class as a separator type 61 wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int Spacing = wxFPB_DEFAULT_SPACING, 62 int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING, 63 int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING) 64 : m_wndItem(NULL) 65 , m_type(SEPARATOR) 66 , m_flags(wxFPB_ALIGN_WIDTH) 67 , m_leftSpacing(leftSpacing) 68 , m_rightSpacing(rightSpacing) 69 , m_Spacing(Spacing) 70 , m_lineLength(0) 71 , m_lineY(y) 72 , m_sepLineColour(lineColor) 73 { 74 }; 75 76 // TODO: Make a c'tor for a captioned splitter 77 78 int GetType() const { 79 return m_type; 80 }; 81 82 int GetLineY() const { 83 return m_lineY; 84 }; 85 86 int GetLineLength() const { 87 return m_lineLength; 88 }; 89 90 const wxColour &GetLineColour() const { 91 return m_sepLineColour; 92 }; 93 94 int GetLeftSpacing() const { 95 return m_leftSpacing; 96 }; 97 98 int GetRightSpacing() const { 99 return m_rightSpacing; 100 }; 101 102 int GetSpacing() const { 103 return m_Spacing; 104 }; 105 106 // returns space needed by the window if type is wxFoldWindowItem::WINDOW 107 // and returns the total size plus the extra spacing 108 109 int GetWindowLength(bool vertical) const { 110 int value = 0; 111 if(m_type == WINDOW) 112 { 113 wxCHECK(m_wndItem, 0); 114 wxSize size = m_wndItem->GetSize(); 115 value = ( vertical ? size.GetHeight() : size.GetWidth() ) + m_Spacing; 116 } 117 else if(m_type == SEPARATOR) 118 value = 1 + m_Spacing; 119 120 return value; 121 }; 122 123 // resize the element, whatever it is. A separator or 124 // line will be always aligned by width or height 125 // depending on orientation of the whole panel 126 127 void ResizeItem(int size, bool vertical) { 128 if(m_flags & wxFPB_ALIGN_WIDTH) 129 { 130 // align by taking full width 131 int mySize = size - m_leftSpacing - m_rightSpacing; 132 133 if(mySize < 0) 134 mySize = 10; // can't have negative width 135 136 if(m_type == SEPARATOR) 137 m_lineLength = mySize; 138 else 139 { 140 wxCHECK2(m_wndItem, return); 141 m_wndItem->SetSize(vertical?mySize:wxDefaultCoord, vertical?wxDefaultCoord:mySize); 142 } 143 } 144 }; 145 146}; 147 148#include <wx/dynarray.h> 149WX_DECLARE_OBJARRAY_WITH_DECL(wxFoldWindowItem, wxFoldWindowItemArray, class WXDLLIMPEXP_FOLDBAR); 150 151#ifndef _NO_DOXYGEN_ 152 153/** \wxFoldPanelItem 154 This class is a child sibling of the wxFoldPanelBar class. It will be containing a wxCaptionBar class 155 for receiving of events, and a the rest of the area can be populated by a wxPanel derived class. 156*/ 157 158class WXDLLIMPEXP_FOLDBAR wxFoldPanelItem: public wxPanel 159{ 160private: 161 wxCaptionBar *m_captionBar; 162 163 bool m_controlCreated; 164 int m_userSize, 165 m_panelSize, 166 m_lastInsertPos; 167 int m_itemPos; 168 bool m_userSized; 169 170private: 171 DECLARE_CLASS( wxFoldPanelItem ) 172 DECLARE_EVENT_TABLE() 173 174private: 175 wxFoldWindowItemArray m_items; 176 177 void OnSize(wxSizeEvent &event); 178 void OnPressCaption(wxCaptionBarEvent &event); 179 void OnPaint(wxPaintEvent &event); 180 181public: 182 // constructors and destructors 183 wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons = 0, bool collapsedInitially = false, 184 const wxCaptionBarStyle &style = wxEmptyCaptionBarStyle); 185 virtual ~wxFoldPanelItem(); 186 187 /** Add a window item to the list of items on this panel. The flags are wxFPB_ALIGN_LEFT for a non sizing 188 window element, and wxFPB_ALIGN_WIDTH for a width aligned item. The ySpacing parameter reserves a number 189 of pixels before the window element, and leftSpacing is an indent. rightSpacing is only relevant when the 190 style wxFPB_ALIGN_WIDTH is chosen. */ 191 void AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing); 192 193 void AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing); 194 195 /** Repositions this wxFoldPanelBar and reports the length occupied for the next wxFoldPanelBar in the 196 list */ 197 int Reposition(int pos); 198 199 void ResizePanel(); 200 201 /** Return expanded or collapsed status. If the panel is expanded, true is returned */ 202 bool IsExpanded() const { 203 return !m_captionBar->IsCollapsed(); 204 }; 205 206 /** Return Y pos */ 207 208 int GetItemPos() const { 209 return m_itemPos; 210 }; 211 212 // this should not be called by the user, because it doesn't trigger the parent 213 // to tell it that we are collapsed or expanded, it only changes visual state 214 void Collapse() { 215 m_captionBar->Collapse(); 216 ResizePanel(); 217 }; 218 219 // this should not be called by the user, because it doesn't trigger the parent 220 // to tell it that we are collapsed or expanded, it only changes visual state 221 void Expand() { 222 m_captionBar->Expand(); 223 ResizePanel(); 224 }; 225 226 /* Return size of panel */ 227 228 int GetPanelLength() const { 229 if(m_captionBar->IsCollapsed()) 230 return GetCaptionLength(); 231 else if(m_userSized) 232 return m_userSize; 233 return m_panelSize; 234 }; 235 236 bool IsVertical() const; 237 238 // returns space of caption only. This is for folding calulation 239 // purposes 240 241 int GetCaptionLength() const { 242 wxSize size = m_captionBar->GetSize(); 243 return IsVertical() ? size.GetHeight() : size.GetWidth(); 244 }; 245 246 void ApplyCaptionStyle(const wxCaptionBarStyle &style) { 247 wxCHECK2(m_captionBar, return); 248 m_captionBar->SetCaptionStyle(false, style); 249 }; 250 251 wxCaptionBarStyle GetCaptionStyle() { 252 wxCHECK(m_captionBar, wxEmptyCaptionBarStyle); 253 return m_captionBar->GetCaptionStyle(); 254 }; 255}; 256 257 258#endif // _NO_DOXYGEN_ 259 260#endif // __WXFOLDPANELITEM_H__ 261