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

WndChild.cpp

Go to the documentation of this file.
00001 //
00002 // WndChild.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 "CoolInterface.h"
00026 #include "WndChild.h"
00027 #include "WndMain.h"
00028 #include "Skin.h"
00029 #include "SkinWindow.h"
00030 
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #undef THIS_FILE
00034 static char THIS_FILE[] = __FILE__;
00035 #endif
00036 
00037 IMPLEMENT_DYNCREATE(CChildWnd, CMDIChildWnd)
00038 
00039 BEGIN_MESSAGE_MAP(CChildWnd, CMDIChildWnd)
00040         //{{AFX_MSG_MAP(CChildWnd)
00041         ON_WM_CREATE()
00042         ON_WM_DESTROY()
00043         ON_WM_ERASEBKGND()
00044         ON_WM_SIZE()
00045         ON_WM_SYSCOMMAND()
00046         ON_WM_MDIACTIVATE()
00047         ON_WM_NCRBUTTONUP()
00048         ON_WM_NCCALCSIZE()
00049         ON_WM_NCHITTEST()
00050         ON_WM_NCPAINT()
00051         ON_WM_NCACTIVATE()
00052         ON_WM_NCLBUTTONDOWN()
00053         ON_WM_NCLBUTTONUP()
00054         ON_WM_NCMOUSEMOVE()
00055         ON_WM_NCLBUTTONDBLCLK()
00056         //}}AFX_MSG_MAP
00057         ON_MESSAGE(WM_SETTEXT, OnSetText)
00058 END_MESSAGE_MAP()
00059 
00060 CChildWnd* CChildWnd::m_pCmdMsg = NULL;
00061 
00062 
00064 // CChildWnd construction
00065 
00066 CChildWnd::CChildWnd()
00067 {
00068         m_nResID                = 0;
00069         m_bTabMode              = FALSE;
00070         m_bGroupMode    = FALSE;
00071         m_pGroupParent  = NULL;
00072         m_nGroupSize    = 0.5f;
00073         m_bPanelMode    = FALSE;
00074         m_bAlert                = FALSE;
00075         m_pSkin                 = NULL;
00076         m_pCmdMsg               = NULL;
00077 }
00078 
00079 CChildWnd::~CChildWnd()
00080 {
00081 }
00082 
00084 // CChildWnd operations
00085 
00086 BOOL CChildWnd::Create(UINT nID, BOOL bVisible)
00087 {
00088         m_nResID = nID;
00089 
00090         CString strCaption;
00091         LoadString( strCaption, m_nResID );
00092 
00093         return CMDIChildWnd::Create( NULL, strCaption, WS_CHILD |
00094                  WS_OVERLAPPEDWINDOW | ( bVisible ? WS_VISIBLE : 0 ) );
00095 }
00096 
00097 CMainWnd* CChildWnd::GetMainWnd()
00098 {
00099         return (CMainWnd*)GetMDIFrame();
00100 }
00101 
00102 CWindowManager* CChildWnd::GetManager()
00103 {
00104         return &GetMainWnd()->m_pWindows;
00105 }
00106 
00107 BOOL CChildWnd::IsActive(BOOL bFocused)
00108 {
00109         CMainWnd* pMainWnd = GetMainWnd();
00110 
00111         if ( bFocused && GetForegroundWindow() != pMainWnd ) return FALSE;
00112 
00113         CChildWnd* pActive = (CChildWnd*)pMainWnd->MDIGetActive();
00114 
00115         if ( pActive == this ) return TRUE;
00116         if ( bFocused ) return FALSE;
00117 
00118         return  ( pActive != NULL && m_pGroupParent == pActive ) ||
00119                         ( pActive != NULL && pActive->m_pGroupParent == this );
00120 }
00121 
00122 BOOL CChildWnd::IsPartiallyVisible()
00123 {
00124         if ( IsWindowVisible() == FALSE || IsIconic() == TRUE ) return FALSE;
00125 
00126         CRect rc;
00127         GetClientRect( &rc );
00128         ClientToScreen( &rc );
00129 
00130         return  TestPoint( rc.CenterPoint() )                                           ||
00131                         TestPoint( CPoint( rc.left + 1, rc.top + 1 ) )          ||
00132                         TestPoint( CPoint( rc.right - 1, rc.top + 1 ) )         ||
00133                         TestPoint( CPoint( rc.left + 1, rc.bottom - 2 ) )       ||
00134                         TestPoint( CPoint( rc.right - 2, rc.bottom - 2 ) );
00135 }
00136 
00137 BOOL CChildWnd::TestPoint(const CPoint& ptScreen)
00138 {
00139         CWnd* pHit = WindowFromPoint( ptScreen );
00140 
00141         if ( pHit == NULL ) return FALSE;
00142         if ( pHit == this ) return TRUE;
00143 
00144         if ( pHit->GetTopLevelParent() != GetTopLevelParent() ) return FALSE;
00145 
00146         CPoint ptChild( ptScreen );
00147         pHit->ScreenToClient( &ptChild );
00148 
00149         CWnd* pChild = pHit->ChildWindowFromPoint( ptChild, CWP_SKIPINVISIBLE );
00150         if ( pChild == NULL ) pChild = pHit;
00151 
00152         while ( pChild != NULL )
00153         {
00154                 if ( pChild == this ) return TRUE;
00155                 pChild = pChild->GetParent();
00156         }
00157 
00158         return FALSE;
00159 }
00160 
00161 void CChildWnd::TrackPopupMenu(LPCTSTR pszMenu, const CPoint& point, UINT nDefaultID)
00162 {
00163         Skin.TrackPopupMenu( pszMenu, point, nDefaultID );
00164 }
00165 
00166 BOOL CChildWnd::LoadState(LPCTSTR pszName, BOOL bDefaultMaximise)
00167 {
00168         CRect rcParent, rcChild;
00169         GetParent()->GetClientRect( &rcParent );
00170 
00171         if ( ! m_bPanelMode && Settings.LoadWindow( pszName, this ) )
00172         {
00173                 if ( rcParent.Width() > 64 && rcParent.Height() > 32 )
00174                 {
00175                         GetWindowRect( &rcChild );
00176                         GetParent()->ScreenToClient( &rcChild );
00177 
00178                         if ( rcChild.right > rcParent.right || rcChild.bottom > rcParent.bottom )
00179                         {
00180                                 rcChild.right   = min( rcChild.right, rcParent.right );
00181                                 rcChild.bottom  = min( rcChild.bottom, rcParent.bottom );
00182                                 MoveWindow( &rcChild );
00183                         }
00184                 }
00185 
00186                 OnSkinChange();
00187 
00188                 return TRUE;
00189         }
00190         else if ( m_bPanelMode || bDefaultMaximise )    // was m_bGroupMode
00191         {
00192                 if ( m_bTabMode )
00193                 {
00194                         CString strName = ( pszName != NULL ) ? CString( pszName ) : CString( GetRuntimeClass()->m_lpszClassName );
00195                         strName += _T(".Splitter");
00196                         m_nGroupSize = (float)theApp.GetProfileInt( _T("Windows"), strName, 500 ) / 1000;
00197                 }
00198 
00199                 if ( rcParent.Width() > 64 && rcParent.Height() > 32 )
00200                 {
00201                         MoveWindow( &rcParent );
00202                 }
00203         }
00204 
00205         OnSkinChange();
00206 
00207         return FALSE;
00208 }
00209 
00210 BOOL CChildWnd::SaveState(LPCTSTR pszName)
00211 {
00212         if ( m_bTabMode && m_pGroupParent == NULL )
00213         {
00214                 CString strName = ( pszName != NULL ) ? CString( pszName ) : CString( GetRuntimeClass()->m_lpszClassName );
00215                 strName += _T(".Splitter");
00216                 theApp.WriteProfileInt( _T("Windows"), strName, (int)( m_nGroupSize * 1000 ) );
00217                 return TRUE;
00218         }
00219         else if ( ! m_bPanelMode )
00220         {
00221                 Settings.SaveWindow( pszName, this );
00222                 return TRUE;
00223         }
00224         else
00225         {
00226                 return FALSE;
00227         }
00228 }
00229 
00230 BOOL CChildWnd::SetAlert(BOOL bAlert)
00231 {
00232         if ( m_bAlert == bAlert ) return FALSE;
00233 
00234         CMainWnd* pMainWnd = GetMainWnd();
00235 
00236         if ( bAlert && pMainWnd->MDIGetActive() == this ) return FALSE;
00237 
00238         m_bAlert = bAlert;
00239 
00240         pMainWnd->OnUpdateFrameTitle( FALSE );
00241 
00242         return TRUE;
00243 }
00244 
00246 // CChildWnd message handlers
00247 
00248 int CChildWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00249 {
00250         if ( CMDIChildWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00251 
00252         m_bAlert = 1982;
00253         CChildWnd::OnSkinChange();
00254         m_bAlert = FALSE;
00255 
00256         GetManager()->Add( this );
00257 
00258         return 0;
00259 }
00260 
00261 void CChildWnd::OnDestroy()
00262 {
00263         GetManager()->Remove( this );
00264 
00265         CMDIChildWnd::OnDestroy();
00266 }
00267 
00268 BOOL CChildWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00269 {
00270         if ( m_pCmdMsg == this ) return FALSE;
00271 
00272         if ( CMDIChildWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00273 
00274         if ( m_pCmdMsg != NULL ) return FALSE;
00275 
00276         m_pCmdMsg = this;
00277         BOOL bResult = GetMainWnd()->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00278         m_pCmdMsg = NULL;
00279 
00280         return bResult;
00281 }
00282 
00283 BOOL CChildWnd::OnEraseBkgnd(CDC* pDC)
00284 {
00285         return TRUE;
00286 }
00287 
00288 void CChildWnd::OnSize(UINT nType, int cx, int cy)
00289 {
00290         if ( m_pSkin ) m_pSkin->OnSize( this );
00291 
00292         CMDIChildWnd::OnSize( nType, cx, cy );
00293 
00294         BOOL bMinimized = IsIconic();
00295         BOOL bVisible   = IsWindowVisible();
00296 
00297         if ( bMinimized && bVisible )
00298                 ShowWindow( SW_HIDE );
00299         else if ( ! bMinimized && ! bVisible )
00300                 ShowWindow( SW_SHOW );
00301 }
00302 
00303 void CChildWnd::SizeListAndBar(CWnd* pList, CWnd* pBar)
00304 {
00305         CRect rc;
00306         GetClientRect( &rc );
00307 
00308         rc.bottom -= 28;
00309         HDWP hPos = BeginDeferWindowPos( 2 );
00310         DeferWindowPos( hPos, pBar->GetSafeHwnd(), NULL,
00311                 rc.left, rc.bottom, rc.Width(), 28, SWP_NOZORDER|SWP_SHOWWINDOW );
00312         DeferWindowPos( hPos, pList->GetSafeHwnd(), NULL,
00313                 rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW );
00314         EndDeferWindowPos( hPos );
00315 }
00316 
00317 void CChildWnd::OnSysCommand(UINT nID, LPARAM lParam)
00318 {
00319         CRect rc;
00320 
00321         switch ( nID & 0xFFF0 )
00322         {
00323         case SC_MINIMIZE:
00324                 if ( m_bTabMode ) break;
00325                 ShowWindow( SW_HIDE );
00326                 ShowWindow( SW_MINIMIZE );
00327                 break;
00328         case SC_MAXIMIZE:
00329                 if ( m_bTabMode ) break;
00330                 if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 )
00331                 {
00332                         CMDIChildWnd::OnSysCommand( nID, lParam );
00333                 }
00334                 else
00335                 {
00336                         ShowWindow( SW_SHOWNORMAL );
00337                         GetParent()->GetClientRect( &rc );
00338                         MoveWindow( &rc );
00339                 }
00340                 break;
00341         case SC_MOVE:
00342         case SC_SIZE:
00343         // case SC_PREVWINDOW:
00344         // case SC_NEXTWINDOW:
00345                 if ( m_bPanelMode || m_bTabMode ) break;
00346                 CMDIChildWnd::OnSysCommand( nID, lParam );
00347                 break;
00348         case SC_CLOSE:
00349                 if ( m_bTabMode )
00350                         PostMessage( WM_SYSCOMMAND, SC_NEXTWINDOW );
00351                 else
00352                         CMDIChildWnd::OnSysCommand( nID, lParam );
00353                 break;
00354         default:
00355                 CMDIChildWnd::OnSysCommand( nID, lParam );
00356                 break;
00357         }
00358 }
00359 
00360 void CChildWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
00361 {
00362         if ( GetManager()->m_bIgnoreActivate ) return;
00363 
00364         if ( bActivate && m_bAlert ) SetAlert( FALSE );
00365 
00366         CMDIChildWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
00367 
00368         if ( bActivate && m_bGroupMode )
00369         {
00370                 GetManager()->ActivateGrouped( this );
00371         }
00372 }
00373 
00374 void CChildWnd::OnNcRButtonUp(UINT nHitTest, CPoint point)
00375 {
00376         if ( nHitTest == HTCAPTION )
00377         {
00378                 CWnd* pWnd = ( Settings.General.GUIMode != GUI_WINDOWED ? this : (CWnd*)GetMainWnd() );
00379                 pWnd->PostMessage( WM_CONTEXTMENU, (WPARAM)pWnd->GetSafeHwnd(), MAKELONG( point.x, point.y ) );
00380                 return;
00381         }
00382 
00383         CMDIChildWnd::OnNcRButtonUp( nHitTest, point );
00384 }
00385 
00387 // CChildWnd skin forwarders
00388 
00389 void CChildWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
00390 {
00391         if ( m_pSkin )
00392                 m_pSkin->OnNcCalcSize( this, bCalcValidRects, lpncsp );
00393         else
00394                 CMDIChildWnd::OnNcCalcSize( bCalcValidRects, lpncsp );
00395 }
00396 
00397 UINT CChildWnd::OnNcHitTest(CPoint point)
00398 {
00399         if ( m_pSkin )
00400                 return m_pSkin->OnNcHitTest( this, point, ! m_bPanelMode );
00401         else
00402                 return CMDIChildWnd::OnNcHitTest( point );
00403 }
00404 
00405 void CChildWnd::OnNcPaint()
00406 {
00407         if ( m_pSkin )
00408                 m_pSkin->OnNcPaint( this );
00409         else
00410                 CMDIChildWnd::OnNcPaint();
00411 }
00412 
00413 BOOL CChildWnd::OnNcActivate(BOOL bActive)
00414 {
00415         // if ( bActive ) OnMDIActivate( TRUE, this, NULL );
00416 
00417         if ( m_pSkin != NULL )
00418         {
00419                 BOOL bVisible = IsWindowVisible();
00420                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00421                 BOOL bResult = CMDIChildWnd::OnNcActivate( bActive );
00422                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00423                 m_pSkin->OnNcActivate( this, bActive || ( m_nFlags & WF_STAYACTIVE ) );
00424                 return bResult;
00425         }
00426         else
00427         {
00428                 return CMDIChildWnd::OnNcActivate( bActive );
00429         }
00430 }
00431 
00432 void CChildWnd::OnNcMouseMove(UINT nHitTest, CPoint point)
00433 {
00434         if ( m_pSkin ) m_pSkin->OnNcMouseMove( this, nHitTest, point );
00435         CMDIChildWnd::OnNcMouseMove(nHitTest, point);
00436 }
00437 
00438 void CChildWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
00439 {
00440         if ( m_pSkin && m_pSkin->OnNcLButtonDown( this, nHitTest, point ) ) return;
00441         CMDIChildWnd::OnNcLButtonDown( nHitTest, point );
00442 }
00443 
00444 void CChildWnd::OnNcLButtonUp(UINT nHitTest, CPoint point)
00445 {
00446         if ( m_pSkin && m_pSkin->OnNcLButtonUp( this, nHitTest, point ) ) return;
00447         CMDIChildWnd::OnNcLButtonUp( nHitTest, point );
00448 }
00449 
00450 void CChildWnd::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
00451 {
00452         if ( m_pSkin && m_pSkin->OnNcLButtonDblClk( this, nHitTest, point ) ) return;
00453         CMDIChildWnd::OnNcLButtonDblClk( nHitTest, point );
00454 }
00455 
00456 LONG CChildWnd::OnSetText(WPARAM wParam, LPARAM lParam)
00457 {
00458         if ( m_pSkin != NULL )
00459         {
00460                 BOOL bVisible = IsWindowVisible();
00461                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00462                 LONG lResult = Default();
00463                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00464                 if ( m_pSkin ) m_pSkin->OnSetText( this );
00465                 return lResult;
00466         }
00467         else
00468         {
00469                 return Default();
00470         }
00471 }
00472 
00474 // CChildWnd event handlers
00475 
00476 void CChildWnd::OnSkinChange()
00477 {
00478         m_pSkin = Skin.GetWindowSkin( this );
00479 
00480         if ( m_nResID )
00481         {
00482                 HICON hIcon = CoolInterface.ExtractIcon( m_nResID );
00483 
00484                 if ( NULL == hIcon )
00485                 {
00486                         hIcon = (HICON)LoadImage( AfxGetResourceHandle(),
00487                                 MAKEINTRESOURCE( m_nResID ), IMAGE_ICON, 16, 16, 0 );
00488                 }
00489                 
00490                 SetIcon( theApp.m_bRTL ? CreateMirroredIcon( hIcon ) : hIcon, FALSE );
00491 
00492                 CString strCaption;
00493                 LoadString( strCaption, m_nResID );
00494 
00495                 SetWindowText( _T("") );
00496                 SetWindowText( strCaption );
00497         }
00498 
00499         if ( m_bAlert != 1982 )
00500         {
00501                 SetWindowRgn( NULL, FALSE );
00502                 SetWindowPos( NULL, 0, 0, 0, 0,
00503                         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED );
00504                 if ( m_pSkin ) m_pSkin->OnSize( this );
00505         }
00506 }
00507 
00508 void CChildWnd::OnQuerySearch(CQuerySearch* pSearch)
00509 {
00510 }
00511 
00512 BOOL CChildWnd::OnQueryHits(CQueryHit* pHits)
00513 {
00514         return FALSE;
00515 }
00516 
00517 BOOL CChildWnd::OnPush(GGUID* pClientID, CConnection* pConnection)
00518 {
00519         return FALSE;
00520 }
00521 
00522 HRESULT CChildWnd::GetGenericView(IGenericView** ppView)
00523 {
00524         *ppView = NULL;
00525         return S_FALSE;
00526 }
00527 
00528 BOOL CChildWnd::OnDropFiles(CStringList& pFiles, const CPoint& ptScreen, BOOL bDrop)
00529 {
00530         return FALSE;
00531 }

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