X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f857e441bf68aa9c7585aefd26b64f0728387062..13b22a673807f68da1dffbb8c56614d3f07124f4:/contrib/src/foldbar/foldpanelitem.cpp diff --git a/contrib/src/foldbar/foldpanelitem.cpp b/contrib/src/foldbar/foldpanelitem.cpp index 6f6897b936..48997c1372 100644 --- a/contrib/src/foldbar/foldpanelitem.cpp +++ b/contrib/src/foldbar/foldpanelitem.cpp @@ -2,7 +2,8 @@ // Name: foldpanelitem.cpp // Purpose: // Author: Jorgen Bodde -// Modified by: +// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation +// : wxWidgets coding standards // Created: 22/06/2004 // RCS-ID: $Id$ // Copyright: (c) Jorgen Bodde @@ -16,7 +17,11 @@ #pragma hdrstop #endif -#include "wx/foldbar/foldpanelitem.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/foldbar/foldpanelbar.h" #include WX_DEFINE_OBJARRAY(wxFoldWindowItemArray); @@ -35,12 +40,12 @@ END_EVENT_TABLE() wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons, bool collapsedInitially, const wxCaptionBarStyle &style ) - : _controlCreated(false) - , _yUserSize(0) - , _yPanelSize(0) - , _yPos(0) - , _userSized(false) - , _yLastInsertPos(0) + : m_controlCreated(false) + , m_userSize(0) + , m_panelSize(0) + , m_lastInsertPos(0) + , m_itemPos(0) + , m_userSized(false) { wxCHECK2(parent, return); @@ -48,20 +53,20 @@ wxFoldPanelItem::wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxI // create the caption bar, in collapsed or expanded state - _captionBar = new wxCaptionBar(this, caption, icons, wxID_ANY, style, wxPoint(0,0)); - //_captionBar->SetBoldFont(); + m_captionBar = new wxCaptionBar(this, caption, icons, wxID_ANY, style, wxPoint(0,0)); + //m_captionBar->SetBoldFont(); if(collapsedInitially) - _captionBar->Collapse(); + m_captionBar->Collapse(); - _controlCreated = true; + m_controlCreated = true; // make initial size for component, if collapsed, the // size is determined on the panel height and won't change - wxSize size = _captionBar->GetSize(); - _yPanelSize = size.GetHeight(); - _yLastInsertPos = _yPanelSize; + wxSize size = m_captionBar->GetSize(); + m_panelSize = IsVertical()?size.GetHeight():size.GetWidth(); + m_lastInsertPos = m_panelSize; } void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing) @@ -69,20 +74,27 @@ void wxFoldPanelItem::AddWindow(wxWindow *window, int flags, int ySpacing, int l wxASSERT(window); wxFoldWindowItem *wi = new wxFoldWindowItem(window, flags, ySpacing, leftSpacing, rightSpacing); - _items.Add(wi); + m_items.Add(wi); + + bool vertical = this->IsVertical(); + + window->SetSize( vertical ? leftSpacing : m_lastInsertPos + ySpacing, + vertical ? m_lastInsertPos + ySpacing : leftSpacing, + wxDefaultCoord, + wxDefaultCoord, + wxSIZE_USE_EXISTING); - window->SetSize(leftSpacing, _yLastInsertPos + ySpacing, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING); - _yLastInsertPos += wi->GetWindowHeight(); + m_lastInsertPos += wi->GetWindowLength( vertical ); ResizePanel(); } void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing) { - wxFoldWindowItem *wi = new wxFoldWindowItem(_yLastInsertPos, color, ySpacing, leftSpacing, rightSpacing); - _items.Add(wi); + wxFoldWindowItem *wi = new wxFoldWindowItem(m_lastInsertPos, color, ySpacing, leftSpacing, rightSpacing); + m_items.Add(wi); - _yLastInsertPos += wi->GetWindowHeight(); + m_lastInsertPos += wi->GetWindowLength( this->IsVertical() ); ResizePanel(); } @@ -90,7 +102,7 @@ void wxFoldPanelItem::AddSeparator(const wxColour &color, int ySpacing, int left wxFoldPanelItem::~wxFoldPanelItem() { - _items.Clear(); + m_items.Clear(); } void wxFoldPanelItem::OnPressCaption(wxCaptionBarEvent &event) @@ -108,7 +120,7 @@ void wxFoldPanelItem::OnSize(wxSizeEvent &event) { // deny access to pointers (yet) - if(!_controlCreated) + if(!m_controlCreated) { event.Skip(); return; @@ -121,11 +133,11 @@ void wxFoldPanelItem::OnSize(wxSizeEvent &event) //wxSize size(0,wxDefaultCoord); //size.SetWidth(rect.GetWidth()); - //_captionBar->SetSize(size); + //m_captionBar->SetSize(size); } -int wxFoldPanelItem::Reposition(int y) +int wxFoldPanelItem::Reposition(int pos) { // NOTE: Call Resize before Reposition when an item is added, because the new // size needed will be calculated by Resize. Ofcourse the relative position @@ -133,16 +145,25 @@ int wxFoldPanelItem::Reposition(int y) Freeze(); - SetSize(wxDefaultCoord, y, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING); - _yPos = y; + bool vertical = this->IsVertical(); + + SetSize( vertical ? wxDefaultCoord : pos, + vertical ? pos : wxDefaultCoord, + wxDefaultCoord, + wxDefaultCoord, + wxSIZE_USE_EXISTING); + + m_itemPos = pos; Thaw(); - return GetPanelHeight(); + return GetPanelLength(); } void wxFoldPanelItem::ResizePanel() { + bool vertical = IsVertical(); + // prevent unnecessary updates by blocking repaints for a sec Freeze(); @@ -151,33 +172,42 @@ void wxFoldPanelItem::ResizePanel() // user or calulated width (which will be recalculated by the contents here wxSize size; - if(_captionBar->IsCollapsed()) + if(m_captionBar->IsCollapsed()) { - size = _captionBar->GetSize(); - _yPanelSize = size.GetHeight(); + size = m_captionBar->GetSize(); + m_panelSize = vertical ? size.GetHeight() : size.GetWidth(); } else { size = GetBestSize(); - _yPanelSize = size.GetHeight(); + m_panelSize = vertical ? size.GetHeight() : size.GetWidth(); - if(_userSized) - size.SetHeight(_yUserSize); + if(m_userSized) + { + if ( vertical ) + size.SetHeight(m_userSize); + else + size.SetWidth(m_userSize); + } } wxSize pnlsize = GetParent()->GetSize(); - size.SetWidth(pnlsize.GetWidth()); + if ( vertical ) + size.SetWidth(pnlsize.GetWidth()); + else + size.SetHeight(pnlsize.GetHeight()); // resize caption bar - _captionBar->SetSize(wxSize(size.GetWidth(), wxDefaultCoord)); + m_captionBar->SetSize( vertical ? size.GetWidth() : wxDefaultCoord, + vertical ? wxDefaultCoord : size.GetHeight()); // resize the panel SetSize(size); // go by all the controls and call Layout - for(size_t i = 0; i < _items.GetCount(); i++) - _items.Item(i).ResizeItem(size.GetWidth()); + for(size_t i = 0; i < m_items.GetCount(); i++) + m_items.Item(i).ResizeItem( vertical ? size.GetWidth() : size.GetHeight() , vertical ); // and draw all @@ -187,18 +217,35 @@ void wxFoldPanelItem::ResizePanel() void wxFoldPanelItem::OnPaint(wxPaintEvent& WXUNUSED(event)) { // draw all the items that are lines - wxPaintDC dc(this); + bool vertical = IsVertical(); - for(size_t i = 0; i < _items.GetCount(); i++) + for(size_t i = 0; i < m_items.GetCount(); i++) { - wxFoldWindowItem &item = _items.Item(i); + wxFoldWindowItem &item = m_items.Item(i); wxPen pen(item.GetLineColour(), 1, wxSOLID); if(item.GetType() == wxFoldWindowItem::SEPARATOR) { dc.SetPen(pen); - dc.DrawLine(item.GetLeftSpacing(), item.GetLineY() + item.GetYSpacing(), - item.GetLineWidth() + item.GetLeftSpacing(), item.GetLineY() + item.GetYSpacing()); + int a = item.GetLeftSpacing(); + int b = item.GetLineY() + item.GetSpacing(); + int c = item.GetLineLength(); + int d = a + c; + if (vertical) + dc.DrawLine(a, b, d, b); + else + dc.DrawLine(b, a, b, d); } } } + +bool wxFoldPanelItem::IsVertical() const +{ + // grandparent of wxFoldPanelItem is wxFoldPanelBar + // default is vertical + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + wxCHECK_MSG( panel, true, _T("wrong parent") ); + wxFoldPanelBar *bar = wxDynamicCast(panel->GetParent(), wxFoldPanelBar); + wxCHECK_MSG( bar, true, _T("wrong parent") ); + return bar->IsVertical(); +}