Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pane.cpp

Go to the documentation of this file.
00001 
00002 // Name:        pane.cpp
00003 // Purpose:     wxPaneBase implementation.
00004 // Author:      Mark McCormack
00005 // Modified by:
00006 // Created:     28/12/03
00007 // RCS-ID:      $Id: pane.cpp,v 1.6 2005/05/12 14:04:48 frm Exp $       $Id: pane.cpp,v 1.6 2005/05/12 14:04:48 frm Exp $
00008 // Copyright:   (c) 2004 Mark McCormack
00009 // Licence:     wxWindows license
00011 
00012 #include <wx/pane.h>
00013 #include <wx/toolbutton.h>
00014 #include <wx/settings.h>
00015 #include <wx/gdi.h>
00016 #include <wx/dcclient.h>
00017 
00018 //#include <algorithm>
00019 //using std::max;
00020 
00021 #ifndef min
00022 #define min(a,b) ((a) < (b) ? (a) : (b))
00023 #endif
00024 #ifndef max
00025 #define max(a,b) ((a) > (b) ? (a) : (b))
00026 #endif
00027 
00028 // ----------------------------------------------------------------------------
00029 // wxPaneBase constants & wx-macros
00030 // ----------------------------------------------------------------------------
00031 
00032 BEGIN_EVENT_TABLE( wxPaneBase, wxPanel )
00033     EVT_SIZE( wxPaneBase::OnSize )
00034     EVT_BUTTON( 0, wxPaneBase::OnCloseButton )
00035     EVT_ERASE_BACKGROUND( wxPaneBase::OnErase )
00036     EVT_PAINT( wxPaneBase::OnPaint )
00037 END_EVENT_TABLE()
00038 
00039 DEFINE_EVENT_TYPE( wxEVT_PANE_CLOSED )
00040 
00041 IMPLEMENT_ABSTRACT_CLASS( wxPaneBase, wxPanel )
00042 
00043 const wxSize DEFAULT_BUTTON_SIZE( 17, 16 );
00044 const int DEFAULT_BUTTON_IMAGE_SIZE = 9;
00045 
00046 const int HEADER_BORDER = 2;    // distance around outside of header
00047 
00048 // ----------------------------------------------------------------------------
00049 // wxPaneBase implementation
00050 // ----------------------------------------------------------------------------
00051 
00052 bool wxPaneBase::Create( wxWindow *parent, wxWindowID id, const wxString& name, const wxPoint& pos, const wxSize& size, long style ) {
00053     bool result = wxPanel::Create( parent, id, pos, size, style, name );
00054 
00055     // create toolbutton (the close button)
00056     m_toolButtonSize = DEFAULT_BUTTON_SIZE;
00057     m_pCloseButton = new wxToolButton( this, 0, wxDefaultPosition, m_toolButtonSize );
00058     m_pCloseButton->SetDrawSize( DEFAULT_BUTTON_IMAGE_SIZE );
00059     m_pCloseButton->SetToolTip( wxT("Close") );
00060     wxASSERT(m_pCloseButton);
00061 
00062     CalcHeaderSize();
00063 
00064     return result;
00065 }
00066 
00067 void wxPaneBase::Init() {
00068     m_visibilityOnParent = false;
00069     m_orientation = wxHORIZONTAL;
00070     m_headerSize = 0;
00071     m_toolButtonSize.x = 0;
00072     m_toolButtonSize.y = 0;
00073     m_pCloseButton = NULL;
00074     m_pClient = NULL;
00075     m_showHeader = true;
00076     m_showClosebutton = true;
00077 }
00078 
00079 bool wxPaneBase::Show( bool state ) {
00080     if( m_visibilityOnParent ) {
00081         // visibility on parent
00082         return GetParent()->Show( state );
00083     }
00084     else {
00085         // visibility on self
00086         return wxPanel::Show( state );
00087     }
00088 }
00089 
00090 void wxPaneBase::ShowHeader( bool state ) {
00091     m_showHeader = state;
00092     UpdateSize();
00093 }
00094 
00095 wxWindow * wxPaneBase::SetClient( wxWindow * pClient, bool WXUNUSED(removeBorder) ) {
00096     // set the pane's client window
00097     wxWindow * pOldClient = m_pClient;
00098     m_pClient = pClient;
00099     if( m_pClient ) {
00100         // force reparent
00101         m_pClient->Reparent( this );
00102         UpdateSize();
00103     }
00104     return pOldClient;
00105 }
00106 
00107 void wxPaneBase::SetOrientation( wxOrientation orientation ) {
00108     // set pane's header orientation
00109     m_orientation = orientation;
00110     UpdateSize();
00111 }
00112 
00113 void wxPaneBase::SetVisibilityOnParent( bool state ) {
00114     // set whether visibility commands to the pane are re-directed to the parent window
00115     m_visibilityOnParent = state;
00116 }
00117 
00118 void wxPaneBase::ShowCloseButton( bool state ) {
00119     wxASSERT(m_pCloseButton);
00120     m_showClosebutton = state;
00121     m_pCloseButton->Show( state );
00122 }
00123 
00124 wxWindow * wxPaneBase::GetClient() {
00125     return m_pClient;
00126 }
00127 
00128 void wxPaneBase::UpdateSize() {
00129     // update the layout
00130     wxRect r = GetClientRect();
00131     UpdateLayout( r.width, r.height );
00132 }
00133 
00134 void wxPaneBase::OnSize( wxSizeEvent& WXUNUSED(event) ) {
00135     // size event - do internal update
00136     UpdateSize();
00137 }
00138 
00139 void wxPaneBase::OnCloseButton( wxCommandEvent& WXUNUSED(event) ) {
00140     // create a close event
00141     wxCommandEvent closeEvent( wxEVT_PANE_CLOSED );
00142     closeEvent.SetEventObject( this );
00143     GetEventHandler()->ProcessEvent( closeEvent );
00144 }
00145 
00146 void wxPaneBase::OnErase( wxEraseEvent& WXUNUSED(event) ) {
00147  // just skip
00148 }
00149 
00150 void wxPaneBase::OnPaint( wxPaintEvent& WXUNUSED(event) ) {
00151     wxPaintDC dc(this);
00152 
00153     int headerSize = GetHeaderSize();
00154 
00155     // draw header
00156     wxRect hr = GetClientRect();
00157     if( m_orientation == wxVERTICAL ) {
00158         hr.SetRight( hr.x + headerSize );
00159     } else {
00160         hr.SetBottom( hr.y + headerSize );
00161     }
00162 
00163  // create a clipping region to exclude the close button
00164  if( m_pCloseButton && m_showClosebutton ) {
00165   dc.DestroyClippingRegion();
00166   wxRegion region( hr );
00167   wxRect sr = m_pCloseButton->GetRect();
00168   region.Subtract( sr );
00169   dc.SetClippingRegion( region );
00170  }
00171 
00172  g_gdi.DrawHeader( dc, hr, m_orientation, GetName(), GetTitleFont() );
00173 
00174     // draw contents
00175     wxRect cr = GetClientRect();
00176     if( m_orientation == wxVERTICAL ) {
00177         cr.x += headerSize;
00178     }
00179     else {
00180         cr.y += headerSize;
00181     }
00182 
00183  // create a clipping region to exclude the child window
00184  dc.DestroyClippingRegion();
00185  wxRegion region( cr );
00186  if( m_pClient ) {
00187   wxRect sr = m_pClient->GetRect();
00188   region.Subtract( sr );
00189  }
00190  dc.SetClippingRegion( region );
00191 
00192     g_gdi.DrawEmptyWorkspace( dc, cr, true );
00193 }
00194 
00195 int wxPaneBase::GetHeaderSize() {
00196     return m_showHeader ? m_headerSize : 0;
00197 }
00198 
00199 void wxPaneBase::UpdateLayout( int cxWidth, int cyHeight ) {
00200     // update the components position & size
00201     wxRect rect;
00202     int headerSize = GetHeaderSize();
00203 
00204     if( m_orientation == wxVERTICAL )
00205     {
00206         // vertical positioning
00207         rect = wxRect( 0, 0, headerSize, cyHeight );
00208         if( m_pCloseButton ) {
00209             m_pCloseButton->SetSize( (headerSize/2)-(m_toolButtonSize.x/2), HEADER_BORDER, m_toolButtonSize.x, m_toolButtonSize.y );
00210         }
00211 
00212         if( m_pClient ) {
00213             m_pClient->SetSize( headerSize, 0, (cxWidth -  headerSize), cyHeight );
00214         } else {
00215             rect.SetRight( cxWidth );
00216         }
00217     }
00218     else {
00219         // horizontal positioning
00220         rect = wxRect( 0, 0, cxWidth, headerSize );
00221         if( m_pCloseButton ) {
00222             m_pCloseButton->SetSize( (rect.GetRight() - m_toolButtonSize.x - HEADER_BORDER), (headerSize/2)-(m_toolButtonSize.y/2), m_toolButtonSize.x, m_toolButtonSize.y );
00223         }
00224 
00225         if( m_pClient ) {
00226             m_pClient->SetSize( 0, headerSize, cxWidth, (cyHeight  - headerSize) );
00227         } else {
00228             rect.SetBottom( cyHeight );
00229         }
00230     }
00231     if( m_pCloseButton ) m_pCloseButton->Show( (m_showHeader & m_showClosebutton) ? true : false );
00232 
00233     Refresh();
00234 }
00235 
00236 void wxPaneBase::CalcHeaderSize() {
00237     // header size calculation
00238     wxFont font = GetTitleFont();
00239     int cyFont = font.GetPointSize() + (HEADER_BORDER*2);
00240     int cyBtn = m_toolButtonSize.y + (HEADER_BORDER*2);
00241 
00242     // which is largest, text height or button height?
00243     m_headerSize = max( cyFont, cyBtn );
00244 }
00245 
00246 const wxFont & wxPaneBase::GetTitleFont() {
00247     static wxFont font;
00248     font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
00249     return font;
00250 }

Generated on Sat May 14 14:54:39 2005 for wxDockIt by  doxygen 1.4.2