]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/foldbar/foldpanelbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxFoldPanelBar.cpp
4 // Created: Tuesday, June 22, 2004 20:40:00
6 /////////////////////////////////////////////////////////////////////////////
8 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/foldbar/foldpanelbar.h"
16 #include "icon_collapsed.xpm"
17 #include "icon_expanded.xpm"
18 #include "icon_theresmore.xpm"
20 //----------------------------------------------------------------------------
22 //----------------------------------------------------------------------------
24 IMPLEMENT_CLASS( wxFoldPanelBar
, wxPanel
)
26 BEGIN_EVENT_TABLE(wxFoldPanelBar
,wxPanel
)
27 EVT_SIZE(wxFoldPanelBar::OnSizePanel
)
28 //EVT_PAINT(wxFoldPanelBar::OnPaint)
29 EVT_CAPTIONBAR(-1, wxFoldPanelBar::OnPressCaption
)
32 wxFoldPanelBar::wxFoldPanelBar()
37 wxFoldPanelBar::wxFoldPanelBar( wxWindow
*parent
, wxWindowID id
, const wxPoint
&position
,
38 const wxSize
& size
, long style
, long extraStyle
)
41 , _controlCreated(false)
43 Create( parent
, id
, position
, size
, style
, extraStyle
);
46 void wxFoldPanelBar::Create( wxWindow
*parent
, wxWindowID id
, const wxPoint
&position
,
47 const wxSize
& size
, long style
, long extraStyle
)
50 _extraStyle
= extraStyle
;
52 // create the panel (duh!). This causes a size event, which we are going
53 // to skip when we are not initialised
55 wxPanel::Create(parent
, id
, position
, size
, style
);
57 // the fold panel area
59 _foldPanel
= new wxPanel(this, -1, wxDefaultPosition
, wxDefaultSize
, wxNO_BORDER
|wxTAB_TRAVERSAL
);
61 // the extra area for some icons / context menu etc
64 _bottomPanel
= new wxPanel(this, -1, wxDefaultPosition
, wxSize(-1,22), wxNO_BORDER
|wxTAB_TRAVERSAL
);
65 _bottomPanel
->SetBackgroundColour(*wxWHITE
);
68 // create the fold icons to be used in the captions
70 _images
= new wxImageList(16, 16);
72 wxBitmap
*bmp
= new wxBitmap(icon_expanded
);
76 bmp
= new wxBitmap(icon_collapsed
);
80 _moreBmp
= new wxBitmap(icon_theresmore
);
82 // do this as last, to check if create is already called
84 _controlCreated
= true;
87 wxFoldPanelBar::~wxFoldPanelBar()
93 wxFoldPanel
wxFoldPanelBar::AddFoldPanel(const wxString
&caption
, bool collapsedInitially
, const wxCaptionBarStyle
&style
)
95 wxASSERT(_controlCreated
);
97 // create a fold panel item, which is first only the caption.
98 // the user can now add a panel area which will be folded in
101 wxFoldPanelItem
*item
= new wxFoldPanelItem(_foldPanel
, caption
, _images
, collapsedInitially
, style
);
103 // look at the last added one and reposition this one
105 if(_panels
.GetCount() > 0)
106 y
= _panels
.Last()->GetY() + _panels
.Last()->GetPanelHeight();
111 //return wxFoldPanel(item);
112 return wxFoldPanel(item
);
115 int wxFoldPanelBar::AddFoldPanelWindow(const wxFoldPanel
&panel
, wxWindow
*window
, int flags
, int ySpacing
, int leftSpacing
,
118 wxCHECK(panel
.IsOk(), -1);
119 panel
.GetItem()->AddWindow(window
, flags
, ySpacing
, leftSpacing
, rightSpacing
);
121 // TODO: Take old and new height, and if difference, reposition all the lower panels
122 // this is because the user can add new wxWindow controls somewhere in between
123 // when other panels are already present.
128 int wxFoldPanelBar::AddFoldPanelSeperator(const wxFoldPanel
&panel
, const wxColour
&color
, int ySpacing
, int leftSpacing
,
131 wxCHECK(panel
.IsOk(), -1);
132 panel
.GetItem()->AddSeparator(color
, ySpacing
, leftSpacing
, rightSpacing
);
137 void wxFoldPanelBar::OnSizePanel(wxSizeEvent
&event
)
139 // skip all stuff when we are not initialised yet
147 // now size the fold panel area and the
148 // lower bar in such a way that the bar is always
151 wxRect foldrect
= GetRect();
153 // fold panel itself. If too little space,
157 if(foldrect
.GetHeight() < 23)
158 foldrect
.SetHeight(0);
160 foldrect
.SetHeight(foldrect
.GetHeight() - 22);
165 _foldPanel
->SetSize(foldrect
);
167 if(_extraStyle
& wxFPB_COLLAPSE_TO_BOTTOM
)
169 wxRect rect
= RepositionCollapsedToBottom();
170 if(rect
.GetHeight() > 0)
174 // TODO: A smart way to check wether the old - new width of the
175 // panel changed, if so no need to resize the fold panel items
177 RedisplayFoldPanelItems();
179 // tool panel for icons and other stuff
182 wxRect bottomrect
= GetRect();
183 if(bottomrect
.GetHeight() < 22)
186 bottomrect
.SetY(bottomrect
.GetHeight() - 22);
188 bottomrect
.SetHeight(22);
190 _bottomPanel
->SetSize(bottomrect
);
192 // TODO: redraw the bitmap properly
193 // use the captionbar algorithm for that
195 _bottomPanel
->Refresh();
199 void wxFoldPanelBar::OnPaint(wxPaintEvent
&event
)
204 // paint the bottom panel only, where the
205 // arrow is shown when there is more to show the user
206 // just as informative icon
208 wxPaintDC
dc(_bottomPanel
);
210 wxSize size
= _bottomPanel
->GetSize();
211 int offset
= (size
.GetHeight() - _moreBmp
->GetHeight()) / 2;
213 dc
.DrawBitmap(*_moreBmp
, size
.GetWidth() - _moreBmp
->GetWidth() - 2, offset
, true);
219 void wxFoldPanelBar::OnPressCaption(wxCaptionBarEvent
&event
)
221 // act upon the folding or expanding status of the bar
222 // to expand or collapse the panel(s)
224 if(event
.GetFoldStatus())
225 Collapse(wxFoldPanel((wxFoldPanelItem
*)event
.GetTag()));
227 Expand(wxFoldPanel((wxFoldPanelItem
*)event
.GetTag()));
230 void wxFoldPanelBar::RefreshPanelsFrom(wxFoldPanelItem
*item
)
234 size_t i
= _panels
.Index(item
);
236 RefreshPanelsFrom(i
);
239 void wxFoldPanelBar::RefreshPanelsFrom(size_t i
)
243 // if collapse to bottom is on, the panels that are not expanded
244 // should be drawn at the bottom. All panels that are expanded
245 // are drawn on top. The last expanded panel gets all the extra space
247 if(_extraStyle
& wxFPB_COLLAPSE_TO_BOTTOM
)
251 for(size_t j
= 0; j
< _panels
.GetCount(); j
++)
253 if(_panels
.Item(j
)->IsExpanded())
254 offset
+= _panels
.Item(j
)->Reposition(offset
);
257 // put all non collapsed panels at the bottom where there is space, else
258 // put them right behind the expanded ones
260 RepositionCollapsedToBottom();
264 int y
= _panels
.Item(i
)->GetY() + _panels
.Item(i
)->GetPanelHeight();
265 for(i
++; i
< _panels
.GetCount(); i
++)
266 y
+= _panels
.Item(i
)->Reposition(y
);
271 void wxFoldPanelBar::RedisplayFoldPanelItems()
273 // resize them all. No need to reposition
275 wxFoldPanelItem
*item
;
276 for(size_t i
= 0; i
< _panels
.GetCount(); i
++)
278 item
= _panels
.Item(i
);
285 wxRect
wxFoldPanelBar::RepositionCollapsedToBottom()
287 wxRect
value(0,0,0,0);
289 // determine wether the number of panels left
290 // times the size of their captions is enough
291 // to be placed in the left over space
293 int expanded
= 0, collapsed
= 0, offset
;
294 GetPanelsHeight(collapsed
, expanded
);
296 // if no room stick them behind the normal ones, else
299 if((GetSize().GetHeight() - expanded
- collapsed
) < 0)
303 // value is the region which is left unpainted
304 // I will send it back as 'slack' so it does not need to
308 value
.SetY(expanded
);
309 value
.SetHeight(GetSize().GetHeight() - expanded
);
310 value
.SetWidth(GetSize().GetWidth());
312 offset
= GetSize().GetHeight() - collapsed
;
318 for(size_t i
= 0; i
< _panels
.GetCount(); i
++)
320 if(!_panels
.Item(i
)->IsExpanded())
321 offset
+= _panels
.Item(i
)->Reposition(offset
);
327 int wxFoldPanelBar::GetPanelsHeight(int &collapsed
, int &expanded
)
329 int value
= 0, offset
= 0;
331 // assumed here that all the panels that are expanded
332 // are positioned after eachother from 0,0 to end.
334 for(size_t j
= 0; j
< _panels
.GetCount(); j
++)
336 offset
= _panels
.Item(j
)->GetPanelHeight();
338 if(_panels
.Item(j
)->IsExpanded())