]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/foldbar/foldpanelitem.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxFoldPanelItem.cpp
4 // Created: Tuesday, June 22, 2004 21:01:02
6 /////////////////////////////////////////////////////////////////////////////
8 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/foldbar/foldpanelitem.h"
17 #include <wx/arrimpl.cpp>
18 WX_DEFINE_OBJARRAY(wxFoldWindowItemArray
);
20 //----------------------------------------------------------------------------
22 //----------------------------------------------------------------------------
24 IMPLEMENT_CLASS( wxFoldPanelItem
, wxPanel
)
26 BEGIN_EVENT_TABLE(wxFoldPanelItem
,wxPanel
)
27 EVT_CAPTIONBAR(-1, wxFoldPanelItem::OnPressCaption
)
28 EVT_PAINT(wxFoldPanelItem::OnPaint
)
29 //EVT_SIZE(wxFoldPanelItem::OnSize)
32 wxFoldPanelItem::wxFoldPanelItem( wxWindow
*parent
, const wxString
&caption
, wxImageList
*icons
, bool collapsedInitially
,
33 const wxCaptionBarStyle
&style
)
34 : _controlCreated(false)
41 wxCHECK2(parent
, return);
43 wxPanel::Create(parent
, -1);
45 // create the caption bar, in collapsed or expanded state
47 _captionBar
= new wxCaptionBar(this, caption
, icons
, -1, style
, wxPoint(0,0));
48 //_captionBar->SetBoldFont();
50 if(collapsedInitially
)
51 _captionBar
->Collapse();
53 _controlCreated
= true;
55 // make initial size for component, if collapsed, the
56 // size is determined on the panel height and won't change
58 wxSize size
= _captionBar
->GetSize();
59 _yPanelSize
= size
.GetHeight();
60 _yLastInsertPos
= _yPanelSize
;
63 void wxFoldPanelItem::AddWindow(wxWindow
*window
, int flags
, int ySpacing
, int leftSpacing
, int rightSpacing
)
67 wxFoldWindowItem
*wi
= new wxFoldWindowItem(window
, flags
, ySpacing
, leftSpacing
, rightSpacing
);
70 window
->SetSize(leftSpacing
, _yLastInsertPos
+ ySpacing
, -1, -1, wxSIZE_USE_EXISTING
);
71 _yLastInsertPos
+= wi
->GetWindowHeight();
76 void wxFoldPanelItem::AddSeparator(const wxColour
&color
, int ySpacing
, int leftSpacing
, int rightSpacing
)
78 wxFoldWindowItem
*wi
= new wxFoldWindowItem(_yLastInsertPos
, color
, ySpacing
, leftSpacing
, rightSpacing
);
81 _yLastInsertPos
+= wi
->GetWindowHeight();
87 wxFoldPanelItem::~wxFoldPanelItem()
92 void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent
&event
)
94 // tell the upper container we are responsible
95 // for this event, so it can fold the panel item
98 event
.SetTag((void *)this);
103 void wxFoldPanelItem::OnSize(wxSizeEvent
&event
)
105 // deny access to pointers (yet)
113 // calculate the size needed for this window, so
114 // we get the parent size, and determine the size for the caption and the panel
116 //wxRect rect = GetRect();
119 //size.SetWidth(rect.GetWidth());
120 //_captionBar->SetSize(size);
124 int wxFoldPanelItem::Reposition(int y
)
126 // NOTE: Call Resize before Reposition when an item is added, because the new
127 // size needed will be calculated by Resize. Ofcourse the relative position
128 // of the controls have to be correct in respect to the caption bar
132 SetSize(-1, y
, -1, -1, wxSIZE_USE_EXISTING
);
137 return GetPanelHeight();
140 void wxFoldPanelItem::ResizePanel()
142 // prevent unnecessary updates by blocking repaints for a sec
146 // force this panel to take the width of the parent panel and the y of the
147 // user or calulated width (which will be recalculated by the contents here
150 if(_captionBar
->IsCollapsed())
152 size
= _captionBar
->GetSize();
153 _yPanelSize
= size
.GetHeight();
157 size
= GetBestSize();
158 _yPanelSize
= size
.GetHeight();
161 size
.SetHeight(_yUserSize
);
164 wxSize pnlsize
= GetParent()->GetSize();
165 size
.SetWidth(pnlsize
.GetWidth());
167 // resize caption bar
168 _captionBar
->SetSize(wxSize(size
.GetWidth(), -1));
173 // go by all the controls and call Layout
175 for(size_t i
= 0; i
< _items
.GetCount(); i
++)
176 _items
.Item(i
).ResizeItem(size
.GetWidth());
183 void wxFoldPanelItem::OnPaint(wxPaintEvent
& WXUNUSED(event
))
185 // draw all the items that are lines
189 for(size_t i
= 0; i
< _items
.GetCount(); i
++)
191 wxFoldWindowItem
&item
= _items
.Item(i
);
192 wxPen
pen(item
.GetLineColour(), 1, wxSOLID
);
193 if(item
.GetType() == wxFoldWindowItem::SEPARATOR
)
196 dc
.DrawLine(item
.GetLeftSpacing(), item
.GetLineY() + item
.GetYSpacing(),
197 item
.GetLineWidth() + item
.GetLeftSpacing(), item
.GetLineY() + item
.GetYSpacing());