00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00019
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
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;
00047
00048
00049
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
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
00082 return GetParent()->Show( state );
00083 }
00084 else {
00085
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
00097 wxWindow * pOldClient = m_pClient;
00098 m_pClient = pClient;
00099 if( m_pClient ) {
00100
00101 m_pClient->Reparent( this );
00102 UpdateSize();
00103 }
00104 return pOldClient;
00105 }
00106
00107 void wxPaneBase::SetOrientation( wxOrientation orientation ) {
00108
00109 m_orientation = orientation;
00110 UpdateSize();
00111 }
00112
00113 void wxPaneBase::SetVisibilityOnParent( bool state ) {
00114
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
00130 wxRect r = GetClientRect();
00131 UpdateLayout( r.width, r.height );
00132 }
00133
00134 void wxPaneBase::OnSize( wxSizeEvent& WXUNUSED(event) ) {
00135
00136 UpdateSize();
00137 }
00138
00139 void wxPaneBase::OnCloseButton( wxCommandEvent& WXUNUSED(event) ) {
00140
00141 wxCommandEvent closeEvent( wxEVT_PANE_CLOSED );
00142 closeEvent.SetEventObject( this );
00143 GetEventHandler()->ProcessEvent( closeEvent );
00144 }
00145
00146 void wxPaneBase::OnErase( wxEraseEvent& WXUNUSED(event) ) {
00147
00148 }
00149
00150 void wxPaneBase::OnPaint( wxPaintEvent& WXUNUSED(event) ) {
00151 wxPaintDC dc(this);
00152
00153 int headerSize = GetHeaderSize();
00154
00155
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
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
00175 wxRect cr = GetClientRect();
00176 if( m_orientation == wxVERTICAL ) {
00177 cr.x += headerSize;
00178 }
00179 else {
00180 cr.y += headerSize;
00181 }
00182
00183
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
00201 wxRect rect;
00202 int headerSize = GetHeaderSize();
00203
00204 if( m_orientation == wxVERTICAL )
00205 {
00206
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
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
00238 wxFont font = GetTitleFont();
00239 int cyFont = font.GetPointSize() + (HEADER_BORDER*2);
00240 int cyBtn = m_toolButtonSize.y + (HEADER_BORDER*2);
00241
00242
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 }