Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

WndPanel.cpp

Go to the documentation of this file.
00001 //
00002 // WndPanel.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "WndPanel.h"
00026 #include "CoolInterface.h"
00027 #include "Skin.h"
00028 #include "SkinWindow.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 IMPLEMENT_DYNCREATE(CPanelWnd, CChildWnd)
00037 
00038 BEGIN_MESSAGE_MAP(CPanelWnd, CChildWnd)
00039         //{{AFX_MSG_MAP(CPanelWnd)
00040         ON_WM_NCPAINT()
00041         ON_WM_NCCALCSIZE()
00042         ON_WM_NCHITTEST()
00043         ON_WM_NCACTIVATE()
00044         ON_WM_CREATE()
00045         ON_WM_SIZE()
00046         ON_WM_NCLBUTTONDOWN()
00047         ON_WM_SETCURSOR()
00048         //}}AFX_MSG_MAP
00049         ON_MESSAGE(WM_SETTEXT, OnSetText)
00050 END_MESSAGE_MAP()
00051 
00052 #define CAPTION_HEIGHT  20
00053 #define CLOSEBOX                10
00054 
00055 
00057 // CPanelWnd construction
00058 
00059 CPanelWnd::CPanelWnd(BOOL bTabMode, BOOL bGroupMode)
00060 {
00061         m_bPanelMode = Settings.General.GUIMode != GUI_WINDOWED;
00062 
00063         if ( m_bPanelMode )
00064         {
00065                 m_bTabMode |= bTabMode;
00066                 m_bGroupMode |= bGroupMode;
00067         }
00068 
00069         m_bPanelClose = ( m_bPanelMode && ! m_bTabMode );
00070 }
00071 
00072 CPanelWnd::~CPanelWnd()
00073 {
00074 }
00075 
00077 // CPanelWnd message handlers
00078 
00079 int CPanelWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00080 {
00081         if ( CChildWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00082 
00083         return 0;
00084 }
00085 
00086 void CPanelWnd::OnSize(UINT nType, int cx, int cy)
00087 {
00088         if ( m_bPanelMode && ! m_pSkin && CCoolInterface::IsNewWindows() && ! IsIconic() )
00089         {
00090                 CRect rc;
00091                 GetWindowRect( &rc );
00092                 rc.OffsetRect( -rc.left, -rc.top );
00093                 rc.right++; rc.bottom++;
00094                 SetWindowRgn( CreateRectRgnIndirect( &rc ), TRUE );
00095         }
00096 
00097         CChildWnd::OnSize( nType, cx, cy );
00098 }
00099 
00100 void CPanelWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
00101 {
00102         if ( m_bPanelMode && m_pSkin == NULL )
00103         {
00104                 NCCALCSIZE_PARAMS* pSize = (NCCALCSIZE_PARAMS*)lpncsp;
00105                 pSize->rgrc[0].top += CAPTION_HEIGHT;
00106                 return; // ( bCalcValidRects ) ? WVR_REDRAW|WVR_ALIGNTOP|WVR_ALIGNLEFT : 0;
00107         }
00108 
00109         CChildWnd::OnNcCalcSize( bCalcValidRects, lpncsp );
00110 }
00111 
00112 UINT CPanelWnd::OnNcHitTest(CPoint point)
00113 {
00114         if ( m_bPanelMode && ! m_pSkin )
00115         {
00116                 CRect rc;
00117                 GetWindowRect( &rc );
00118                 rc.bottom = rc.top + CAPTION_HEIGHT;
00119                 return rc.PtInRect( point ) ? HTCAPTION : HTCLIENT;
00120         }
00121 
00122         return CChildWnd::OnNcHitTest( point );
00123 }
00124 
00125 void CPanelWnd::OnNcPaint()
00126 {
00127         if ( m_bPanelMode && ! m_pSkin )
00128         {
00129                 CWindowDC dc( this );
00130                 PaintCaption( dc );
00131         }
00132         else
00133         {
00134                 CChildWnd::OnNcPaint();
00135         }
00136 }
00137 
00138 BOOL CPanelWnd::OnNcActivate(BOOL bActive)
00139 {
00140         if ( m_bPanelMode && ! m_pSkin )
00141         {
00142                 CWindowDC dc( this );
00143                 PaintCaption( dc );
00144                 return TRUE;
00145         }
00146 
00147         return CChildWnd::OnNcActivate( bActive );
00148 }
00149 
00150 LONG CPanelWnd::OnSetText(WPARAM wParam, LPARAM lParam)
00151 {
00152         if ( m_pSkin )
00153         {
00154                 BOOL bVisible = IsWindowVisible();
00155                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00156                 LONG lResult = Default();
00157                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00158 
00159                 if ( m_pSkin ) m_pSkin->OnSetText( this );
00160 
00161                 return lResult;
00162         }
00163         else if ( m_bPanelMode )
00164         {
00165                 BOOL bVisible = IsWindowVisible();
00166                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00167                 LONG lResult = Default();
00168                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00169 
00170                 CWindowDC dc( this );
00171                 PaintCaption( dc );
00172 
00173                 return lResult;
00174         }
00175         else
00176         {
00177                 return Default();
00178         }
00179 }
00180 
00181 void CPanelWnd::PaintCaption(CDC& dc)
00182 {
00183         CString strCaption;
00184         CRect rc, rcWnd;
00185 
00186         GetWindowRect( &rcWnd );
00187         rc.SetRect( 0, 0, rcWnd.Width(), CAPTION_HEIGHT );
00188         GetWindowText( strCaption );
00189 
00190         CDC* pBuffer = CoolInterface.GetBuffer( dc, rc.Size() );
00191 
00192         if ( ! CoolInterface.DrawWatermark( pBuffer, &rc, &Skin.m_bmPanelMark, 0, 0 ) )
00193         {
00194                 pBuffer->FillSolidRect( &rc, Skin.m_crPanelBack );
00195         }
00196 
00197         int nIconY = rc.Height() / 2 - 8;
00198         DrawIconEx( pBuffer->GetSafeHdc(), 4, nIconY,
00199                 GetIcon( FALSE ), 16, 16, 0, NULL, DI_NORMAL );
00200 
00201         CFont* pOldFont = (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntCaption );
00202         CSize szCaption = pBuffer->GetTextExtent( strCaption );
00203 
00204         pBuffer->SetBkMode( TRANSPARENT );
00205 
00206         if ( Skin.m_crPanelBorder != CLR_NONE )
00207         {
00208                 pBuffer->SetTextColor( Skin.m_crPanelBorder );
00209                 pBuffer->ExtTextOut( 8 + 16 - 1, rc.Height() / 2 - szCaption.cy / 2 - 1,
00210                         ETO_CLIPPED, &rc, strCaption, NULL );
00211                 pBuffer->ExtTextOut( 8 + 16 + 1, rc.Height() / 2 - szCaption.cy / 2 - 1,
00212                         ETO_CLIPPED, &rc, strCaption, NULL );
00213                 pBuffer->ExtTextOut( 8 + 16, rc.Height() / 2 - szCaption.cy / 2 - 1 - 1,
00214                         ETO_CLIPPED, &rc, strCaption, NULL );
00215                 pBuffer->ExtTextOut( 8 + 16, rc.Height() / 2 - szCaption.cy / 2 - 1 + 1,
00216                         ETO_CLIPPED, &rc, strCaption, NULL );
00217         }
00218 
00219         pBuffer->SetTextColor( Skin.m_crPanelText );
00220         pBuffer->ExtTextOut( 8 + 16, rc.Height() / 2 - szCaption.cy / 2 - 1,
00221                 ETO_CLIPPED, &rc, strCaption, NULL );
00222 
00223         if ( m_bPanelClose )
00224         {
00225                 pBuffer->SelectObject( &theApp.m_gdiFont );
00226                 CString strText = _T("Close");
00227                 CSize szText    = pBuffer->GetTextExtent( strText );
00228 
00229                 m_rcClose.SetRect( rc.right - szText.cx - 8, rc.top, rc.right, rc.bottom );
00230                 pBuffer->ExtTextOut( m_rcClose.left + 2,
00231                         ( m_rcClose.top + m_rcClose.bottom ) / 2 - szText.cy / 2 - 1,
00232                         ETO_CLIPPED, &m_rcClose, strText, NULL );
00233                 m_rcClose.OffsetRect( rcWnd.left, rcWnd.top );
00234         }
00235 
00236         pBuffer->SelectObject( pOldFont );
00237 
00238         dc.BitBlt( rc.left, rc.top, rc.Width(), rc.Height(), pBuffer, 0, 0, SRCCOPY );
00239 }
00240 
00241 BOOL CPanelWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00242 {
00243         if ( nHitTest == HTCAPTION && m_bGroupMode && m_pGroupParent )
00244         {
00245                 SetCursor( AfxGetApp()->LoadStandardCursor( IDC_SIZENS ) );
00246                 return TRUE;
00247         }
00248         else if ( nHitTest == HTCAPTION && m_bPanelClose && m_pSkin == NULL )
00249         {
00250                 CPoint pt;
00251                 GetCursorPos( &pt );
00252 
00253                 if ( m_rcClose.PtInRect( pt ) )
00254                 {
00255                         SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00256                         return TRUE;
00257                 }
00258         }
00259 
00260         return CChildWnd::OnSetCursor( pWnd, nHitTest, message );
00261 }
00262 
00263 void CPanelWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
00264 {
00265         if ( nHitTest == HTCAPTION && m_bGroupMode && m_pGroupParent )
00266         {
00267                 PanelSizeLoop();
00268                 return;
00269         }
00270         else if ( nHitTest == HTCAPTION && m_bPanelClose && m_pSkin == NULL )
00271         {
00272                 if ( m_rcClose.PtInRect( point ) )
00273                 {
00274                         PostMessage( WM_SYSCOMMAND, SC_CLOSE );
00275                         return;
00276                 }
00277         }
00278 
00279         CChildWnd::OnNcLButtonDown( nHitTest, point );
00280 }
00281 
00282 void CPanelWnd::PanelSizeLoop()
00283 {
00284         MSG* pMsg = &AfxGetThreadState()->m_msgCur;
00285 
00286         float nOffset = 10;
00287         CPoint point;
00288         CRect rcMDI;
00289 
00290         SendMessage( WM_ENTERSIZEMOVE );
00291 
00292         GetParent()->GetWindowRect( &rcMDI );
00293         GetParent()->SetCapture();
00294         ClipCursor( &rcMDI );
00295 
00296         while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
00297         {
00298                 while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) );
00299 
00300                 if ( ! AfxGetThread()->PumpMessage() )
00301                 {
00302                         AfxPostQuitMessage( 0 );
00303                         break;
00304                 }
00305 
00306                 GetCursorPos( &point );
00307                 if ( point.y < rcMDI.top ) point.y = rcMDI.top;
00308                 if ( point.y > rcMDI.bottom ) point.y = rcMDI.bottom;
00309 
00310                 float nSplitter = (float)( point.y - rcMDI.top ) / (float)rcMDI.Height();
00311 
00312                 if ( nOffset == 10 ) nOffset = m_pGroupParent->m_nGroupSize - nSplitter;
00313                 nSplitter += nOffset;
00314 
00315                 if ( nSplitter < 0.1f ) nSplitter = 0.1f;
00316                 if ( nSplitter > 0.9f ) nSplitter = 0.9f;
00317 
00318                 if ( nSplitter >= 0.47f && nSplitter <= 0.53f ) nSplitter = 0.5f;
00319 
00320                 if ( nSplitter != m_pGroupParent->m_nGroupSize )
00321                 {
00322                         m_pGroupParent->m_nGroupSize = nSplitter;
00323                         GetParent()->SendMessage( WM_SIZE, 1982 );
00324                 }
00325         }
00326 
00327         ReleaseCapture();
00328         ClipCursor( NULL );
00329         SendMessage( WM_EXITSIZEMOVE );
00330 }

Generated on Thu Dec 15 10:39:53 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2