]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/foldbar/foldpanelitem.cpp
Rebaked (build/bakefiles/common.bkl 1.95->1.96 change)
[wxWidgets.git] / contrib / src / foldbar / foldpanelitem.cpp
CommitLineData
957f5ab7 1/////////////////////////////////////////////////////////////////////////////
f857e441
WS
2// Name: foldpanelitem.cpp
3// Purpose:
4// Author: Jorgen Bodde
5// Modified by:
6// Created: 22/06/2004
7// RCS-ID: $Id$
8// Copyright: (c) Jorgen Bodde
9// Licence: wxWindows licence
957f5ab7
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#include "wx/foldbar/foldpanelitem.h"
20
21#include <wx/arrimpl.cpp>
22WX_DEFINE_OBJARRAY(wxFoldWindowItemArray);
23
24//----------------------------------------------------------------------------
25// wxFoldPanelItem
26//----------------------------------------------------------------------------
27
28IMPLEMENT_CLASS( wxFoldPanelItem, wxPanel )
29
30BEGIN_EVENT_TABLE(wxFoldPanelItem,wxPanel)
f857e441
WS
31 EVT_CAPTIONBAR(wxID_ANY, wxFoldPanelItem::OnPressCaption)
32 EVT_PAINT(wxFoldPanelItem::OnPaint)
33 //EVT_SIZE(wxFoldPanelItem::OnSize)
957f5ab7
VZ
34END_EVENT_TABLE()
35
f857e441
WS
36wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons, bool collapsedInitially,
37 const wxCaptionBarStyle &style )
38 : _controlCreated(false)
39 , _yUserSize(0)
40 , _yPanelSize(0)
9cf662c4 41 , _yLastInsertPos(0)
f857e441
WS
42 , _yPos(0)
43 , _userSized(false)
957f5ab7
VZ
44{
45 wxCHECK2(parent, return);
f857e441
WS
46
47 wxPanel::Create(parent, wxID_ANY);
48
49 // create the caption bar, in collapsed or expanded state
50
51 _captionBar = new wxCaptionBar(this, caption, icons, wxID_ANY, style, wxPoint(0,0));
52 //_captionBar->SetBoldFont();
53
54 if(collapsedInitially)
55 _captionBar->Collapse();
56
57 _controlCreated = true;
58
59 // make initial size for component, if collapsed, the
60 // size is determined on the panel height and won't change
61
62 wxSize size = _captionBar->GetSize();
63 _yPanelSize = size.GetHeight();
64 _yLastInsertPos = _yPanelSize;
957f5ab7 65}
f857e441 66
957f5ab7
VZ
67void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing)
68{
f857e441
WS
69 wxASSERT(window);
70
71 wxFoldWindowItem *wi = new wxFoldWindowItem(window, flags, ySpacing, leftSpacing, rightSpacing);
72 _items.Add(wi);
73
74 window->SetSize(leftSpacing, _yLastInsertPos + ySpacing, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING);
75 _yLastInsertPos += wi->GetWindowHeight();
76
77 ResizePanel();
957f5ab7
VZ
78}
79
80void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing)
f857e441
WS
81{
82 wxFoldWindowItem *wi = new wxFoldWindowItem(_yLastInsertPos, color, ySpacing, leftSpacing, rightSpacing);
83 _items.Add(wi);
84
85 _yLastInsertPos += wi->GetWindowHeight();
957f5ab7 86
f857e441 87 ResizePanel();
957f5ab7
VZ
88}
89
90
91wxFoldPanelItem::~wxFoldPanelItem()
92{
93 _items.Clear();
94}
95
96void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent &event)
97{
f857e441
WS
98 // tell the upper container we are responsible
99 // for this event, so it can fold the panel item
100 // and do a refresh
957f5ab7 101
f857e441
WS
102 event.SetTag((void *)this);
103 event.Skip();
957f5ab7
VZ
104}
105
106/* Inactive */
107void wxFoldPanelItem::OnSize(wxSizeEvent &event)
108{
f857e441 109 // deny access to pointers (yet)
957f5ab7 110
f857e441
WS
111 if(!_controlCreated)
112 {
113 event.Skip();
114 return;
115 }
957f5ab7 116
f857e441
WS
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
957f5ab7 119
f857e441
WS
120 //wxRect rect = GetRect();
121
122 //wxSize size(0,wxDefaultCoord);
123 //size.SetWidth(rect.GetWidth());
124 //_captionBar->SetSize(size);
957f5ab7
VZ
125
126}
127
128int wxFoldPanelItem::Reposition(int y)
129{
f857e441
WS
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
133
134 Freeze();
135
136 SetSize(wxDefaultCoord, y, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING);
137 _yPos = y;
138
139 Thaw();
140
141 return GetPanelHeight();
957f5ab7
VZ
142}
143
144void wxFoldPanelItem::ResizePanel()
145{
f857e441
WS
146 // prevent unnecessary updates by blocking repaints for a sec
147
148 Freeze();
957f5ab7 149
f857e441
WS
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
957f5ab7 152
f857e441
WS
153 wxSize size;
154 if(_captionBar->IsCollapsed())
155 {
156 size = _captionBar->GetSize();
157 _yPanelSize = size.GetHeight();
158 }
159 else
160 {
161 size = GetBestSize();
162 _yPanelSize = size.GetHeight();
957f5ab7 163
f857e441
WS
164 if(_userSized)
165 size.SetHeight(_yUserSize);
166 }
957f5ab7 167
f857e441
WS
168 wxSize pnlsize = GetParent()->GetSize();
169 size.SetWidth(pnlsize.GetWidth());
957f5ab7 170
f857e441
WS
171 // resize caption bar
172 _captionBar->SetSize(wxSize(size.GetWidth(), wxDefaultCoord));
957f5ab7 173
f857e441
WS
174 // resize the panel
175 SetSize(size);
957f5ab7 176
f857e441 177 // go by all the controls and call Layout
957f5ab7 178
f857e441
WS
179 for(size_t i = 0; i < _items.GetCount(); i++)
180 _items.Item(i).ResizeItem(size.GetWidth());
957f5ab7 181
f857e441 182 // and draw all
957f5ab7 183
f857e441 184 Thaw();
957f5ab7
VZ
185}
186
187void wxFoldPanelItem::OnPaint(wxPaintEvent& WXUNUSED(event))
188{
f857e441
WS
189 // draw all the items that are lines
190
191 wxPaintDC dc(this);
192
193 for(size_t i = 0; i < _items.GetCount(); i++)
194 {
195 wxFoldWindowItem &item = _items.Item(i);
196 wxPen pen(item.GetLineColour(), 1, wxSOLID);
197 if(item.GetType() == wxFoldWindowItem::SEPARATOR)
198 {
199 dc.SetPen(pen);
200 dc.DrawLine(item.GetLeftSpacing(), item.GetLineY() + item.GetYSpacing(),
201 item.GetLineWidth() + item.GetLeftSpacing(), item.GetLineY() + item.GetYSpacing());
202 }
203 }
957f5ab7 204}