]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/foldbar/foldpanelitem.cpp
corrected version number extraction
[wxWidgets.git] / contrib / src / foldbar / foldpanelitem.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: foldpanelitem.cpp
3 // Purpose:
4 // Author: Jorgen Bodde
5 // Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6 // : wxWidgets coding standards
7 // Created: 22/06/2004
8 // RCS-ID: $Id$
9 // Copyright: (c) Jorgen Bodde
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif
23
24 #include "wx/foldbar/foldpanelbar.h"
25
26 #include <wx/arrimpl.cpp>
27 WX_DEFINE_OBJARRAY(wxFoldWindowItemArray);
28
29 //----------------------------------------------------------------------------
30 // wxFoldPanelItem
31 //----------------------------------------------------------------------------
32
33 IMPLEMENT_CLASS( wxFoldPanelItem, wxPanel )
34
35 BEGIN_EVENT_TABLE(wxFoldPanelItem,wxPanel)
36 EVT_CAPTIONBAR(wxID_ANY, wxFoldPanelItem::OnPressCaption)
37 EVT_PAINT(wxFoldPanelItem::OnPaint)
38 //EVT_SIZE(wxFoldPanelItem::OnSize)
39 END_EVENT_TABLE()
40
41 wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons, bool collapsedInitially,
42 const wxCaptionBarStyle &style )
43 : m_controlCreated(false)
44 , m_userSize(0)
45 , m_panelSize(0)
46 , m_lastInsertPos(0)
47 , m_itemPos(0)
48 , m_userSized(false)
49 {
50 wxCHECK2(parent, return);
51
52 wxPanel::Create(parent, wxID_ANY);
53
54 // create the caption bar, in collapsed or expanded state
55
56 m_captionBar = new wxCaptionBar(this, caption, icons, wxID_ANY, style, wxPoint(0,0));
57 //m_captionBar->SetBoldFont();
58
59 if(collapsedInitially)
60 m_captionBar->Collapse();
61
62 m_controlCreated = true;
63
64 // make initial size for component, if collapsed, the
65 // size is determined on the panel height and won't change
66
67 wxSize size = m_captionBar->GetSize();
68 m_panelSize = IsVertical()?size.GetHeight():size.GetWidth();
69 m_lastInsertPos = m_panelSize;
70 }
71
72 void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing)
73 {
74 wxASSERT(window);
75
76 wxFoldWindowItem *wi = new wxFoldWindowItem(window, flags, ySpacing, leftSpacing, rightSpacing);
77 m_items.Add(wi);
78
79 bool vertical = this->IsVertical();
80
81 window->SetSize( vertical ? leftSpacing : m_lastInsertPos + ySpacing,
82 vertical ? m_lastInsertPos + ySpacing : leftSpacing,
83 wxDefaultCoord,
84 wxDefaultCoord,
85 wxSIZE_USE_EXISTING);
86
87 m_lastInsertPos += wi->GetWindowLength( vertical );
88
89 ResizePanel();
90 }
91
92 void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing)
93 {
94 wxFoldWindowItem *wi = new wxFoldWindowItem(m_lastInsertPos, color, ySpacing, leftSpacing, rightSpacing);
95 m_items.Add(wi);
96
97 m_lastInsertPos += wi->GetWindowLength( this->IsVertical() );
98
99 ResizePanel();
100 }
101
102
103 wxFoldPanelItem::~wxFoldPanelItem()
104 {
105 m_items.Clear();
106 }
107
108 void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent &event)
109 {
110 // tell the upper container we are responsible
111 // for this event, so it can fold the panel item
112 // and do a refresh
113
114 event.SetTag((void *)this);
115 event.Skip();
116 }
117
118 /* Inactive */
119 void wxFoldPanelItem::OnSize(wxSizeEvent &event)
120 {
121 // deny access to pointers (yet)
122
123 if(!m_controlCreated)
124 {
125 event.Skip();
126 return;
127 }
128
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
131
132 //wxRect rect = GetRect();
133
134 //wxSize size(0,wxDefaultCoord);
135 //size.SetWidth(rect.GetWidth());
136 //m_captionBar->SetSize(size);
137
138 }
139
140 int wxFoldPanelItem::Reposition(int pos)
141 {
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
145
146 Freeze();
147
148 bool vertical = this->IsVertical();
149
150 SetSize( vertical ? wxDefaultCoord : pos,
151 vertical ? pos : wxDefaultCoord,
152 wxDefaultCoord,
153 wxDefaultCoord,
154 wxSIZE_USE_EXISTING);
155
156 m_itemPos = pos;
157
158 Thaw();
159
160 return GetPanelLength();
161 }
162
163 void wxFoldPanelItem::ResizePanel()
164 {
165 bool vertical = IsVertical();
166
167 // prevent unnecessary updates by blocking repaints for a sec
168
169 Freeze();
170
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
173
174 wxSize size;
175 if(m_captionBar->IsCollapsed())
176 {
177 size = m_captionBar->GetSize();
178 m_panelSize = vertical ? size.GetHeight() : size.GetWidth();
179 }
180 else
181 {
182 size = GetBestSize();
183 m_panelSize = vertical ? size.GetHeight() : size.GetWidth();
184
185 if(m_userSized)
186 {
187 if ( vertical )
188 size.SetHeight(m_userSize);
189 else
190 size.SetWidth(m_userSize);
191 }
192 }
193
194 wxSize pnlsize = GetParent()->GetSize();
195 if ( vertical )
196 size.SetWidth(pnlsize.GetWidth());
197 else
198 size.SetHeight(pnlsize.GetHeight());
199
200 // resize caption bar
201 m_captionBar->SetSize( vertical ? size.GetWidth() : wxDefaultCoord,
202 vertical ? wxDefaultCoord : size.GetHeight());
203
204 // resize the panel
205 SetSize(size);
206
207 // go by all the controls and call Layout
208
209 for(size_t i = 0; i < m_items.GetCount(); i++)
210 m_items.Item(i).ResizeItem( vertical ? size.GetWidth() : size.GetHeight() , vertical );
211
212 // and draw all
213
214 Thaw();
215 }
216
217 void wxFoldPanelItem::OnPaint(wxPaintEvent& WXUNUSED(event))
218 {
219 // draw all the items that are lines
220 wxPaintDC dc(this);
221 bool vertical = IsVertical();
222
223 for(size_t i = 0; i < m_items.GetCount(); i++)
224 {
225 wxFoldWindowItem &item = m_items.Item(i);
226 wxPen pen(item.GetLineColour(), 1, wxSOLID);
227 if(item.GetType() == wxFoldWindowItem::SEPARATOR)
228 {
229 dc.SetPen(pen);
230 int a = item.GetLeftSpacing();
231 int b = item.GetLineY() + item.GetSpacing();
232 int c = item.GetLineLength();
233 int d = a + c;
234 if (vertical)
235 dc.DrawLine(a, b, d, b);
236 else
237 dc.DrawLine(b, a, b, d);
238 }
239 }
240 }
241
242 bool wxFoldPanelItem::IsVertical() const
243 {
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();
251 }