]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/foldbar/foldpanelitem.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: foldpanelitem.cpp
4 // Author: Jorgen Bodde
8 // Copyright: (c) Jorgen Bodde
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/foldbar/foldpanelitem.h"
21 #include <wx/arrimpl.cpp>
22 WX_DEFINE_OBJARRAY(wxFoldWindowItemArray
);
24 //----------------------------------------------------------------------------
26 //----------------------------------------------------------------------------
28 IMPLEMENT_CLASS( wxFoldPanelItem
, wxPanel
)
30 BEGIN_EVENT_TABLE(wxFoldPanelItem
,wxPanel
)
31 EVT_CAPTIONBAR(wxID_ANY
, wxFoldPanelItem::OnPressCaption
)
32 EVT_PAINT(wxFoldPanelItem::OnPaint
)
33 //EVT_SIZE(wxFoldPanelItem::OnSize)
36 wxFoldPanelItem::wxFoldPanelItem( wxWindow
*parent
, const wxString
&caption
, wxImageList
*icons
, bool collapsedInitially
,
37 const wxCaptionBarStyle
&style
)
38 : _controlCreated(false)
45 wxCHECK2(parent
, return);
47 wxPanel::Create(parent
, wxID_ANY
);
49 // create the caption bar, in collapsed or expanded state
51 _captionBar
= new wxCaptionBar(this, caption
, icons
, wxID_ANY
, style
, wxPoint(0,0));
52 //_captionBar->SetBoldFont();
54 if(collapsedInitially
)
55 _captionBar
->Collapse();
57 _controlCreated
= true;
59 // make initial size for component, if collapsed, the
60 // size is determined on the panel height and won't change
62 wxSize size
= _captionBar
->GetSize();
63 _yPanelSize
= size
.GetHeight();
64 _yLastInsertPos
= _yPanelSize
;
67 void wxFoldPanelItem::AddWindow(wxWindow
*window
, int flags
, int ySpacing
, int leftSpacing
, int rightSpacing
)
71 wxFoldWindowItem
*wi
= new wxFoldWindowItem(window
, flags
, ySpacing
, leftSpacing
, rightSpacing
);
74 window
->SetSize(leftSpacing
, _yLastInsertPos
+ ySpacing
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
75 _yLastInsertPos
+= wi
->GetWindowHeight();
80 void wxFoldPanelItem::AddSeparator(const wxColour
&color
, int ySpacing
, int leftSpacing
, int rightSpacing
)
82 wxFoldWindowItem
*wi
= new wxFoldWindowItem(_yLastInsertPos
, color
, ySpacing
, leftSpacing
, rightSpacing
);
85 _yLastInsertPos
+= wi
->GetWindowHeight();
91 wxFoldPanelItem::~wxFoldPanelItem()
96 void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent
&event
)
98 // tell the upper container we are responsible
99 // for this event, so it can fold the panel item
102 event
.SetTag((void *)this);
107 void wxFoldPanelItem::OnSize(wxSizeEvent
&event
)
109 // deny access to pointers (yet)
117 // calculate the size needed for this window, so
118 // we get the parent size, and determine the size for the caption and the panel
120 //wxRect rect = GetRect();
122 //wxSize size(0,wxDefaultCoord);
123 //size.SetWidth(rect.GetWidth());
124 //_captionBar->SetSize(size);
128 int wxFoldPanelItem::Reposition(int y
)
130 // NOTE: Call Resize before Reposition when an item is added, because the new
131 // size needed will be calculated by Resize. Ofcourse the relative position
132 // of the controls have to be correct in respect to the caption bar
136 SetSize(wxDefaultCoord
, y
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
141 return GetPanelHeight();
144 void wxFoldPanelItem::ResizePanel()
146 // prevent unnecessary updates by blocking repaints for a sec
150 // force this panel to take the width of the parent panel and the y of the
151 // user or calulated width (which will be recalculated by the contents here
154 if(_captionBar
->IsCollapsed())
156 size
= _captionBar
->GetSize();
157 _yPanelSize
= size
.GetHeight();
161 size
= GetBestSize();
162 _yPanelSize
= size
.GetHeight();
165 size
.SetHeight(_yUserSize
);
168 wxSize pnlsize
= GetParent()->GetSize();
169 size
.SetWidth(pnlsize
.GetWidth());
171 // resize caption bar
172 _captionBar
->SetSize(wxSize(size
.GetWidth(), wxDefaultCoord
));
177 // go by all the controls and call Layout
179 for(size_t i
= 0; i
< _items
.GetCount(); i
++)
180 _items
.Item(i
).ResizeItem(size
.GetWidth());
187 void wxFoldPanelItem::OnPaint(wxPaintEvent
& WXUNUSED(event
))
189 // draw all the items that are lines
193 for(size_t i
= 0; i
< _items
.GetCount(); i
++)
195 wxFoldWindowItem
&item
= _items
.Item(i
);
196 wxPen
pen(item
.GetLineColour(), 1, wxSOLID
);
197 if(item
.GetType() == wxFoldWindowItem::SEPARATOR
)
200 dc
.DrawLine(item
.GetLeftSpacing(), item
.GetLineY() + item
.GetYSpacing(),
201 item
.GetLineWidth() + item
.GetLeftSpacing(), item
.GetLineY() + item
.GetYSpacing());