]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/foldbar/foldpanelitem.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: foldpanelitem.cpp
4 // Author: Jorgen Bodde
5 // Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6 // : wxWidgets coding standards
9 // Copyright: (c) Jorgen Bodde
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
24 #include "wx/foldbar/foldpanelbar.h"
26 #include <wx/arrimpl.cpp>
27 WX_DEFINE_OBJARRAY(wxFoldWindowItemArray
);
29 //----------------------------------------------------------------------------
31 //----------------------------------------------------------------------------
33 IMPLEMENT_CLASS( wxFoldPanelItem
, wxPanel
)
35 BEGIN_EVENT_TABLE(wxFoldPanelItem
,wxPanel
)
36 EVT_CAPTIONBAR(wxID_ANY
, wxFoldPanelItem::OnPressCaption
)
37 EVT_PAINT(wxFoldPanelItem::OnPaint
)
38 //EVT_SIZE(wxFoldPanelItem::OnSize)
41 wxFoldPanelItem::wxFoldPanelItem( wxWindow
*parent
, const wxString
&caption
, wxImageList
*icons
, bool collapsedInitially
,
42 const wxCaptionBarStyle
&style
)
43 : m_controlCreated(false)
50 wxCHECK2(parent
, return);
52 wxPanel::Create(parent
, wxID_ANY
);
54 // create the caption bar, in collapsed or expanded state
56 m_captionBar
= new wxCaptionBar(this, caption
, icons
, wxID_ANY
, style
, wxPoint(0,0));
57 //m_captionBar->SetBoldFont();
59 if(collapsedInitially
)
60 m_captionBar
->Collapse();
62 m_controlCreated
= true;
64 // make initial size for component, if collapsed, the
65 // size is determined on the panel height and won't change
67 wxSize size
= m_captionBar
->GetSize();
68 m_panelSize
= IsVertical()?size
.GetHeight():size
.GetWidth();
69 m_lastInsertPos
= m_panelSize
;
72 void wxFoldPanelItem::AddWindow(wxWindow
*window
, int flags
, int ySpacing
, int leftSpacing
, int rightSpacing
)
76 wxFoldWindowItem
*wi
= new wxFoldWindowItem(window
, flags
, ySpacing
, leftSpacing
, rightSpacing
);
79 bool vertical
= this->IsVertical();
81 window
->SetSize( vertical
? leftSpacing
: m_lastInsertPos
+ ySpacing
,
82 vertical
? m_lastInsertPos
+ ySpacing
: leftSpacing
,
87 m_lastInsertPos
+= wi
->GetWindowLength( vertical
);
92 void wxFoldPanelItem::AddSeparator(const wxColour
&color
, int ySpacing
, int leftSpacing
, int rightSpacing
)
94 wxFoldWindowItem
*wi
= new wxFoldWindowItem(m_lastInsertPos
, color
, ySpacing
, leftSpacing
, rightSpacing
);
97 m_lastInsertPos
+= wi
->GetWindowLength( this->IsVertical() );
103 wxFoldPanelItem::~wxFoldPanelItem()
108 void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent
&event
)
110 // tell the upper container we are responsible
111 // for this event, so it can fold the panel item
114 event
.SetTag((void *)this);
119 void wxFoldPanelItem::OnSize(wxSizeEvent
&event
)
121 // deny access to pointers (yet)
123 if(!m_controlCreated
)
129 // calculate the size needed for this window, so
130 // we get the parent size, and determine the size for the caption and the panel
132 //wxRect rect = GetRect();
134 //wxSize size(0,wxDefaultCoord);
135 //size.SetWidth(rect.GetWidth());
136 //m_captionBar->SetSize(size);
140 int wxFoldPanelItem::Reposition(int pos
)
142 // NOTE: Call Resize before Reposition when an item is added, because the new
143 // size needed will be calculated by Resize. Ofcourse the relative position
144 // of the controls have to be correct in respect to the caption bar
148 bool vertical
= this->IsVertical();
150 SetSize( vertical
? wxDefaultCoord
: pos
,
151 vertical
? pos
: wxDefaultCoord
,
154 wxSIZE_USE_EXISTING
);
160 return GetPanelLength();
163 void wxFoldPanelItem::ResizePanel()
165 bool vertical
= IsVertical();
167 // prevent unnecessary updates by blocking repaints for a sec
171 // force this panel to take the width of the parent panel and the y of the
172 // user or calulated width (which will be recalculated by the contents here
175 if(m_captionBar
->IsCollapsed())
177 size
= m_captionBar
->GetSize();
178 m_panelSize
= vertical
? size
.GetHeight() : size
.GetWidth();
182 size
= GetBestSize();
183 m_panelSize
= vertical
? size
.GetHeight() : size
.GetWidth();
188 size
.SetHeight(m_userSize
);
190 size
.SetWidth(m_userSize
);
194 wxSize pnlsize
= GetParent()->GetSize();
196 size
.SetWidth(pnlsize
.GetWidth());
198 size
.SetHeight(pnlsize
.GetHeight());
200 // resize caption bar
201 m_captionBar
->SetSize( vertical
? size
.GetWidth() : wxDefaultCoord
,
202 vertical
? wxDefaultCoord
: size
.GetHeight());
207 // go by all the controls and call Layout
209 for(size_t i
= 0; i
< m_items
.GetCount(); i
++)
210 m_items
.Item(i
).ResizeItem( vertical
? size
.GetWidth() : size
.GetHeight() , vertical
);
217 void wxFoldPanelItem::OnPaint(wxPaintEvent
& WXUNUSED(event
))
219 // draw all the items that are lines
221 bool vertical
= IsVertical();
223 for(size_t i
= 0; i
< m_items
.GetCount(); i
++)
225 wxFoldWindowItem
&item
= m_items
.Item(i
);
226 wxPen
pen(item
.GetLineColour(), 1, wxSOLID
);
227 if(item
.GetType() == wxFoldWindowItem::SEPARATOR
)
230 int a
= item
.GetLeftSpacing();
231 int b
= item
.GetLineY() + item
.GetSpacing();
232 int c
= item
.GetLineLength();
235 dc
.DrawLine(a
, b
, d
, b
);
237 dc
.DrawLine(b
, a
, b
, d
);
242 bool wxFoldPanelItem::IsVertical() const
244 // grandparent of wxFoldPanelItem is wxFoldPanelBar
245 // default is vertical
246 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
247 wxCHECK_MSG( panel
, true, _T("wrong parent") );
248 wxFoldPanelBar
*bar
= wxDynamicCast(panel
->GetParent(), wxFoldPanelBar
);
249 wxCHECK_MSG( bar
, true, _T("wrong parent") );
250 return bar
->IsVertical();