]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/foldbar/foldpanelitem.cpp
Full headers, Unicode markup, whitespaces, wxID_ANY, wxDefaultCoord conventions appli...
[wxWidgets.git] / contrib / src / foldbar / foldpanelitem.cpp
1 /////////////////////////////////////////////////////////////////////////////
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
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>
22 WX_DEFINE_OBJARRAY(wxFoldWindowItemArray);
23
24 //----------------------------------------------------------------------------
25 // wxFoldPanelItem
26 //----------------------------------------------------------------------------
27
28 IMPLEMENT_CLASS( wxFoldPanelItem, wxPanel )
29
30 BEGIN_EVENT_TABLE(wxFoldPanelItem,wxPanel)
31 EVT_CAPTIONBAR(wxID_ANY, wxFoldPanelItem::OnPressCaption)
32 EVT_PAINT(wxFoldPanelItem::OnPaint)
33 //EVT_SIZE(wxFoldPanelItem::OnSize)
34 END_EVENT_TABLE()
35
36 wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons, bool collapsedInitially,
37 const wxCaptionBarStyle &style )
38 : _controlCreated(false)
39 , _yUserSize(0)
40 , _yPanelSize(0)
41 , _yPos(0)
42 , _userSized(false)
43 , _yLastInsertPos(0)
44 {
45 wxCHECK2(parent, return);
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;
65 }
66
67 void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing)
68 {
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();
78 }
79
80 void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing)
81 {
82 wxFoldWindowItem *wi = new wxFoldWindowItem(_yLastInsertPos, color, ySpacing, leftSpacing, rightSpacing);
83 _items.Add(wi);
84
85 _yLastInsertPos += wi->GetWindowHeight();
86
87 ResizePanel();
88 }
89
90
91 wxFoldPanelItem::~wxFoldPanelItem()
92 {
93 _items.Clear();
94 }
95
96 void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent &event)
97 {
98 // tell the upper container we are responsible
99 // for this event, so it can fold the panel item
100 // and do a refresh
101
102 event.SetTag((void *)this);
103 event.Skip();
104 }
105
106 /* Inactive */
107 void wxFoldPanelItem::OnSize(wxSizeEvent &event)
108 {
109 // deny access to pointers (yet)
110
111 if(!_controlCreated)
112 {
113 event.Skip();
114 return;
115 }
116
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
119
120 //wxRect rect = GetRect();
121
122 //wxSize size(0,wxDefaultCoord);
123 //size.SetWidth(rect.GetWidth());
124 //_captionBar->SetSize(size);
125
126 }
127
128 int wxFoldPanelItem::Reposition(int y)
129 {
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();
142 }
143
144 void wxFoldPanelItem::ResizePanel()
145 {
146 // prevent unnecessary updates by blocking repaints for a sec
147
148 Freeze();
149
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
152
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();
163
164 if(_userSized)
165 size.SetHeight(_yUserSize);
166 }
167
168 wxSize pnlsize = GetParent()->GetSize();
169 size.SetWidth(pnlsize.GetWidth());
170
171 // resize caption bar
172 _captionBar->SetSize(wxSize(size.GetWidth(), wxDefaultCoord));
173
174 // resize the panel
175 SetSize(size);
176
177 // go by all the controls and call Layout
178
179 for(size_t i = 0; i < _items.GetCount(); i++)
180 _items.Item(i).ResizeItem(size.GetWidth());
181
182 // and draw all
183
184 Thaw();
185 }
186
187 void wxFoldPanelItem::OnPaint(wxPaintEvent& WXUNUSED(event))
188 {
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 }
204 }