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

CtrlSharedFolder.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlSharedFolder.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 "Library.h"
00026 #include "LibraryFolders.h"
00027 #include "SharedFolder.h"
00028 #include "ShellIcons.h"
00029 #include "CtrlSharedFolder.h"
00030 #include "Skin.h"
00031 
00032 #ifdef _DEBUG
00033 #define new DEBUG_NEW
00034 #undef THIS_FILE
00035 static char THIS_FILE[] = __FILE__;
00036 #endif
00037 
00038 BEGIN_MESSAGE_MAP(CLibraryFolderCtrl, CTreeCtrl)
00039         //{{AFX_MSG_MAP(CLibraryFolderCtrl)
00040         ON_WM_LBUTTONDOWN()
00041         ON_WM_KEYDOWN()
00042         ON_WM_CREATE()
00043         ON_WM_LBUTTONDBLCLK()
00044         ON_WM_LBUTTONUP()
00045         ON_NOTIFY_REFLECT(TVN_ITEMEXPANDEDW, OnItemExpanded)
00046         ON_NOTIFY_REFLECT(TVN_ITEMEXPANDEDA, OnItemExpanded)
00047         ON_NOTIFY_REFLECT(TVN_SELCHANGEDW, OnSelChanged)
00048         ON_NOTIFY_REFLECT(TVN_SELCHANGEDA, OnSelChanged)
00049         ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
00050         ON_WM_RBUTTONDOWN()
00051         ON_WM_NCPAINT()
00052         //}}AFX_MSG_MAP
00053 END_MESSAGE_MAP()
00054 
00055 
00057 // CLibraryFolderCtrl construction
00058 
00059 CLibraryFolderCtrl::CLibraryFolderCtrl()
00060 {
00061         m_bFirstClick   = TRUE;
00062         m_bMultiSelect  = TRUE;
00063         m_bSaveExpand   = FALSE;
00064 }
00065 
00066 CLibraryFolderCtrl::~CLibraryFolderCtrl()
00067 {
00068 }
00069 
00071 // CLibraryFolderCtrl operations
00072 
00073 BOOL CLibraryFolderCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
00074 {
00075         dwStyle |= WS_CHILD|/*TVS_PRIVATEIMAGELISTS|*/TVS_HASLINES|TVS_LINESATROOT;
00076         dwStyle |= TVS_HASBUTTONS|TVS_SHOWSELALWAYS;
00077         return CTreeCtrl::Create( dwStyle, rect, pParentWnd, nID );
00078 }
00079 
00080 void CLibraryFolderCtrl::SetMultiSelect(BOOL bMultiSelect)
00081 {
00082         m_bMultiSelect = bMultiSelect;
00083 }
00084 
00085 void CLibraryFolderCtrl::SetSaveExpand(BOOL bSaveExpand)
00086 {
00087         m_bSaveExpand = bSaveExpand;
00088 }
00089 
00090 void CLibraryFolderCtrl::Update(DWORD nUpdateCookie)
00091 {
00092         CPtrList pAlready;
00093 
00094         for ( HTREEITEM hItem = GetChildItem( m_hRoot ) ; hItem ; )
00095         {
00096                 HTREEITEM hNext = GetNextSiblingItem( hItem );
00097 
00098                 CLibraryFolder* pFolder = (CLibraryFolder*)GetItemData( hItem );
00099 
00100                 if ( LibraryFolders.CheckFolder( pFolder ) )
00101                 {
00102                         Update( pFolder, hItem, NULL, nUpdateCookie, FALSE );
00103                         pAlready.AddTail( pFolder );
00104                 }
00105                 else
00106                 {
00107                         DeleteItem( hItem );
00108                 }
00109 
00110                 hItem = hNext;
00111         }
00112 
00113         for ( POSITION pos = LibraryFolders.GetFolderIterator() ; pos ; )
00114         {
00115                 CLibraryFolder* pFolder = LibraryFolders.GetNextFolder( pos );
00116 
00117                 if ( pAlready.Find( pFolder ) == NULL )
00118                 {
00119                         Update( pFolder, NULL, m_hRoot, nUpdateCookie, FALSE );
00120                 }
00121         }
00122 }
00123 
00124 void CLibraryFolderCtrl::Update(CLibraryFolder* pFolder, HTREEITEM hFolder, HTREEITEM hParent, DWORD nUpdateCookie, BOOL bRecurse)
00125 {
00126         if ( ! hFolder )
00127         {
00128                 DWORD dwStyle = INDEXTOOVERLAYMASK( pFolder->IsShared() ? 0 : SHI_O_LOCKED );
00129 
00130                 if ( pFolder->m_sPath.CompareNoCase( Settings.Downloads.CompletePath ) == 0 ) dwStyle |= TVIS_BOLD;
00131 
00132                 if ( m_bMultiSelect && GetFirstSelectedItem() == NULL ) dwStyle |= TVIS_SELECTED;
00133                 if ( pFolder->m_bExpanded ) dwStyle |= TVIS_EXPANDED;
00134 
00135                 CString strName = pFolder->m_sName;
00136 
00137                 if ( pFolder->m_pParent == NULL )
00138                 {
00139                         CString strDrive;
00140                         if ( pFolder->m_sPath.Find( _T(":\\") ) == 1 || pFolder->m_sPath.GetLength() == 2 )
00141                                 strDrive.Format( _T(" (%c:)"), pFolder->m_sPath[0] );
00142                         else
00143                                 strDrive = _T(" (Net)");
00144 
00145                         strName += strDrive;
00146                         dwStyle |= TVIS_EXPANDED;
00147                 }
00148 
00149                 hFolder = InsertItem( TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_STATE,
00150                         strName, SHI_FOLDER_CLOSED, SHI_FOLDER_CLOSED, dwStyle,
00151                         TVIS_EXPANDED|TVIS_SELECTED|TVIS_OVERLAYMASK, (LPARAM)pFolder, hParent, TVI_SORT );
00152         }
00153         else
00154         {
00155                 DWORD dwMask = TVIS_OVERLAYMASK | TVIS_BOLD;
00156                 DWORD dwStyle = INDEXTOOVERLAYMASK( pFolder->IsShared() ? 0 : SHI_O_LOCKED );
00157 
00158                 if ( pFolder->m_sPath.CompareNoCase( Settings.Downloads.CompletePath ) == 0 ) dwStyle |= TVIS_BOLD;
00159 
00160                 DWORD dwExisting = GetItemState( hFolder, dwMask ) & dwMask;
00161 
00162                 if ( dwExisting != dwStyle ) SetItemState( hFolder, dwStyle, dwMask );
00163         }
00164 
00165         if ( nUpdateCookie )
00166         {
00167                 if ( bRecurse || ( GetItemState( hFolder, TVIS_SELECTED ) & TVIS_SELECTED ) )
00168                 {
00169                         pFolder->m_nSelectCookie = nUpdateCookie;
00170                         bRecurse |= ( GetItemState( hFolder, TVIS_EXPANDED ) & TVIS_EXPANDED ) == 0;
00171                 }
00172         }
00173 
00174         CPtrList pAlready;
00175 
00176         for ( HTREEITEM hItem = GetChildItem( hFolder ) ; hItem ; )
00177         {
00178                 HTREEITEM hNext = GetNextSiblingItem( hItem );
00179 
00180                 CLibraryFolder* pChild = (CLibraryFolder*)GetItemData( hItem );
00181 
00182                 if ( pFolder->CheckFolder( pChild ) )
00183                 {
00184                         Update( pChild, hItem, NULL, nUpdateCookie, bRecurse );
00185                         pAlready.AddTail( pChild );
00186                 }
00187                 else
00188                 {
00189                         DeleteItem( hItem );
00190                 }
00191 
00192                 hItem = hNext;
00193         }
00194 
00195         for ( POSITION pos = pFolder->GetFolderIterator() ; pos ; )
00196         {
00197                 CLibraryFolder* pChild = pFolder->GetNextFolder( pos );
00198 
00199                 if ( pAlready.Find( pChild ) == NULL )
00200                 {
00201                         Update( pChild, NULL, hFolder, nUpdateCookie, bRecurse );
00202                 }
00203         }
00204 
00205         int nOldImage1, nOldImage2;
00206         GetItemImage( hFolder, nOldImage1, nOldImage2 );
00207 
00208         int nImage = ItemHasChildren( hFolder ) && ( GetItemState( hFolder, TVIS_EXPANDED ) & TVIS_EXPANDED );
00209         nImage = nImage ? SHI_FOLDER_OPEN : SHI_FOLDER_CLOSED;
00210         if ( nOldImage1 != nImage ) SetItemImage( hFolder, nImage, nImage );
00211 }
00212 
00213 void CLibraryFolderCtrl::SetSelectedCookie(DWORD nUpdateCookie, HTREEITEM hParent, BOOL bSelect)
00214 {
00215         if ( ! hParent ) hParent = m_hRoot;
00216 
00217         for ( HTREEITEM hItem = GetChildItem( hParent ) ; hItem ; )
00218         {
00219                 BOOL bRecurse = bSelect;
00220 
00221                 if ( bSelect || ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) )
00222                 {
00223                         CLibraryFolder* pFolder = (CLibraryFolder*)GetItemData( hItem );
00224                         pFolder->m_nSelectCookie = nUpdateCookie;
00225                         if ( ( GetItemState( hItem, TVIS_EXPANDED ) & TVIS_EXPANDED ) == 0 ) bRecurse = TRUE;
00226                 }
00227 
00228                 SetSelectedCookie( nUpdateCookie, hItem, bRecurse );
00229 
00230                 hItem = GetNextSiblingItem( hItem );
00231         }
00232 }
00233 
00234 POSITION CLibraryFolderCtrl::GetSelectedFolderIterator() const
00235 {
00236         return (POSITION)GetFirstSelectedItem();
00237 }
00238 
00239 CLibraryFolder* CLibraryFolderCtrl::GetNextSelectedFolder(POSITION& pos) const
00240 {
00241         CLibraryFolder* pFolder = NULL;
00242 
00243         do
00244         {
00245                 if ( pos == NULL ) return NULL;
00246 
00247                 HTREEITEM hItem = (HTREEITEM)pos;
00248                 pos = (POSITION)GetNextSelectedItem( hItem );
00249 
00250                 if ( hItem == m_hRoot ) continue;
00251 
00252                 CPtrList pTree;
00253 
00254                 while ( hItem != m_hRoot )
00255                 {
00256                         pTree.AddHead( (LPVOID)hItem );
00257                         hItem = GetParentItem( hItem );
00258                 }
00259 
00260                 CLibraryFolder* pLastFolder = NULL;
00261 
00262                 for ( POSITION posTree = pTree.GetHeadPosition() ; posTree ; pLastFolder = pFolder )
00263                 {
00264                         hItem = (HTREEITEM)pTree.GetNext( posTree );
00265                         pFolder = (CLibraryFolder*)GetItemData( hItem );
00266 
00267                         if ( pLastFolder )
00268                         {
00269                                 if ( pLastFolder->CheckFolder( pFolder ) ) continue;
00270                         }
00271                         else
00272                         {
00273                                 if ( LibraryFolders.CheckFolder( pFolder ) ) continue;
00274                         }
00275 
00276                         pFolder = NULL;
00277                         break;
00278                 }
00279         }
00280         while ( pFolder == NULL );
00281 
00282         return pFolder;
00283 }
00284 
00286 // CLibraryFolderCtrl message handlers
00287 
00288 int CLibraryFolderCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
00289 {
00290         if ( CTreeCtrl::OnCreate( lpCreateStruct ) == -1 ) return -1;
00291 
00292         SetImageList( ShellIcons.GetObject( 16 ), TVSIL_NORMAL );
00293 
00294         m_hRoot                         = GetRootItem();
00295         m_hFirstSelected        = NULL;
00296 
00297         return 0;
00298 }
00299 
00300 void CLibraryFolderCtrl::OnLButtonDown(UINT nFlags, CPoint point)
00301 {
00302         UINT nItemFlags = 0;
00303         HTREEITEM hItem = HitTest( point, &nItemFlags );
00304 
00305         if ( nItemFlags == TVHT_ONITEMBUTTON )
00306         {
00307                 CTreeCtrl::OnLButtonDown( nFlags, point );
00308                 return;
00309         }
00310 
00311         if ( ( nFlags & MK_CONTROL ) && m_bMultiSelect )
00312         {
00313                 if ( hItem )
00314                 {
00315                         UINT nNewState = GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ?
00316                                 0 : TVIS_SELECTED;
00317 
00318                         SetItemState( hItem, nNewState,  TVIS_SELECTED );
00319                         m_hFirstSelected = NULL;
00320                         NotifySelectionChanged();
00321                 }
00322         }
00323         else if ( ( nFlags & MK_SHIFT ) && m_bMultiSelect )
00324         {
00325                 HTREEITEM hItem = HitTest( point );
00326 
00327                 if ( ! m_hFirstSelected ) m_hFirstSelected = GetFirstSelectedItem();
00328 
00329                 if ( hItem ) SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
00330 
00331                 if ( m_hFirstSelected ) SelectItems( m_hFirstSelected, hItem );
00332 
00333                 NotifySelectionChanged();
00334         }
00335         else
00336         {
00337                 BOOL bChanged = FALSE;
00338 
00339                 BOOL bSelected = hItem && ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED );
00340 
00341                 if ( ! bSelected || ( nFlags & MK_RBUTTON ) == 0 )
00342                 {
00343                         if ( m_bFirstClick && hItem != GetRootItem() )
00344                         {
00345                                 Select( hItem, TVGN_CARET );
00346                         }
00347 
00348                         bChanged = ClearSelection( hItem );
00349                         m_hFirstSelected = NULL;
00350                 }
00351 
00352                 if ( hItem )
00353                 {
00354                         if ( ! bSelected )
00355                         {
00356                                 SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
00357                                 bChanged = TRUE;
00358                         }
00359                 }
00360 
00361                 if ( bChanged ) NotifySelectionChanged();
00362         }
00363 
00364         m_bFirstClick = FALSE;
00365 
00366         SetFocus();
00367 }
00368 
00369 void CLibraryFolderCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
00370 {
00371         UINT nItemFlags = 0;
00372         HTREEITEM hItem = HitTest( point, &nItemFlags );
00373 
00374         if ( ( nItemFlags & (TVHT_ONITEMINDENT|TVHT_ONITEMRIGHT|TVHT_NOWHERE) ) && m_bMultiSelect )
00375         {
00376                 SelectAll();
00377         }
00378         else
00379         {
00380                 NMHDR pNM = { GetSafeHwnd(), GetDlgCtrlID(), NM_DBLCLK };
00381                 GetParent()->SendMessage( WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&pNM );
00382         }
00383 }
00384 
00385 void CLibraryFolderCtrl::OnLButtonUp(UINT nFlags, CPoint point)
00386 {
00387 }
00388 
00389 void CLibraryFolderCtrl::OnRButtonDown(UINT nFlags, CPoint point)
00390 {
00391         OnLButtonDown( nFlags, point );
00392         OnLButtonUp( nFlags, point );
00393         CTreeCtrl::OnRButtonDown( nFlags, point );
00394 }
00395 
00396 void CLibraryFolderCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
00397 {
00398         if ( ( nChar == VK_UP || nChar == VK_DOWN ) && ( GetKeyState( VK_SHIFT ) & 0x8000 ) && m_bMultiSelect )
00399         {
00400                 if ( ! m_hFirstSelected )
00401                 {
00402                         m_hFirstSelected = GetFirstSelectedItem();
00403                         ClearSelection( m_hFirstSelected );
00404                 }
00405 
00406                 HTREEITEM hItemPrevSel = GetSelectedItem();
00407                 HTREEITEM hItemNext;
00408 
00409                 if ( nChar == VK_UP )
00410                         hItemNext = GetPrevVisibleItem( hItemPrevSel );
00411                 else
00412                         hItemNext = GetNextVisibleItem( hItemPrevSel );
00413 
00414                 if ( hItemNext )
00415                 {
00416                         BOOL bReselect = ! ( GetItemState( hItemNext, TVIS_SELECTED ) & TVIS_SELECTED );
00417 
00418                         SelectItem( hItemNext );
00419 
00420                         if ( bReselect ) SetItemState( hItemPrevSel, TVIS_SELECTED, TVIS_SELECTED );
00421                 }
00422 
00423                 NotifySelectionChanged();
00424 
00425                 return;
00426         }
00427         else if ( nChar >= VK_SPACE )
00428         {
00429                 m_hFirstSelected = NULL;
00430                 ClearSelection();
00431         }
00432         else if ( nChar == 'A' && ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ) && m_bMultiSelect )
00433         {
00434                 BOOL bChanged = FALSE;
00435 
00436                 for ( HTREEITEM hItem = GetRootItem() ; hItem != NULL ; hItem = GetNextItem( hItem, TVGN_NEXTVISIBLE ) )
00437                 {
00438                         if ( ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) == 0 )
00439                         {
00440                                 SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
00441                                 bChanged = TRUE;
00442                         }
00443                 }
00444 
00445                 if ( bChanged ) NotifySelectionChanged();
00446                 return;
00447         }
00448 
00449         CTreeCtrl::OnKeyDown( nChar, nRepCnt, nFlags );
00450 }
00451 
00452 BOOL CLibraryFolderCtrl::ClearSelection(HTREEITEM hExcept, HTREEITEM hItem, BOOL bSelect)
00453 {
00454         BOOL bChanged = FALSE;
00455 
00456         if ( hItem == NULL ) hItem = GetRootItem();
00457 
00458         for ( ; hItem != NULL ; hItem = GetNextItem( hItem, TVGN_NEXT ) )
00459         {
00460                 BOOL bIsSelected = ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) ? TRUE : FALSE;
00461 
00462                 if ( hItem != hExcept && ( bIsSelected != bSelect ) )
00463                 {
00464                         SetItemState( hItem, bSelect ? TVIS_SELECTED : 0, TVIS_SELECTED );
00465                         bChanged = TRUE;
00466                 }
00467 
00468                 HTREEITEM hChild = GetChildItem( hItem );
00469                 if ( hChild != NULL ) bChanged |= ClearSelection( hExcept, hChild, bSelect );
00470         }
00471 
00472         return bChanged;
00473 }
00474 
00475 BOOL CLibraryFolderCtrl::SelectAll(HTREEITEM hExcept)
00476 {
00477         if ( ClearSelection( hExcept, NULL, TRUE ) )
00478         {
00479                 NotifySelectionChanged();
00480                 return TRUE;
00481         }
00482         return FALSE;
00483 }
00484 
00485 BOOL CLibraryFolderCtrl::SelectItems(HTREEITEM hItemFrom, HTREEITEM hItemTo)
00486 {
00487         HTREEITEM hItem = GetRootItem();
00488 
00489         while ( hItem && hItem != hItemFrom && hItem != hItemTo )
00490         {
00491                 hItem = GetNextVisibleItem( hItem );
00492                 SetItemState( hItem, 0, TVIS_SELECTED );
00493         }
00494 
00495         if ( ! hItem ) return FALSE;
00496 
00497         if ( hItem == hItemTo )
00498         {
00499                 hItemTo         = hItemFrom;
00500                 hItemFrom       = hItem;
00501         }
00502 
00503         BOOL bSelect = TRUE;
00504 
00505         while ( hItem )
00506         {
00507                 SetItemState( hItem, bSelect ? TVIS_SELECTED : 0, TVIS_SELECTED );
00508                 if( hItem == hItemTo ) bSelect = FALSE;
00509                 hItem = GetNextVisibleItem( hItem );
00510         }
00511 
00512         return TRUE;
00513 }
00514 
00515 BOOL CLibraryFolderCtrl::SelectFolder(CLibraryFolder* pFolder, HTREEITEM hItem)
00516 {
00517         if ( hItem == NULL ) hItem = GetRootItem();
00518 
00519         for ( ; hItem != NULL ; hItem = GetNextItem( hItem, TVGN_NEXT ) )
00520         {
00521                 if ( pFolder == (CLibraryFolder*)GetItemData( hItem ) )
00522                 {
00523                         SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
00524                         return TRUE;
00525                 }
00526 
00527                 HTREEITEM hChild = GetChildItem( hItem );
00528                 if ( hChild != NULL && SelectFolder( pFolder, hChild ) ) return TRUE;
00529         }
00530 
00531         return FALSE;
00532 }
00533 
00534 HTREEITEM CLibraryFolderCtrl::GetFirstSelectedItem() const
00535 {
00536         for ( HTREEITEM hItem = GetRootItem() ; hItem != NULL ; hItem = GetNextItem( hItem, TVGN_NEXTVISIBLE ) )
00537         {
00538                 if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) return hItem;
00539         }
00540 
00541         return NULL;
00542 }
00543 
00544 HTREEITEM CLibraryFolderCtrl::GetNextSelectedItem(HTREEITEM hItem) const
00545 {
00546         for ( hItem = GetNextItem( hItem, TVGN_NEXTVISIBLE ) ; hItem != NULL ; hItem = GetNextItem( hItem, TVGN_NEXTVISIBLE ) )
00547         {
00548                 if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) return hItem;
00549         }
00550 
00551         return NULL;
00552 }
00553 
00554 void CLibraryFolderCtrl::OnItemExpanded(NMHDR* pNMHDR, LRESULT* pResult)
00555 {
00556         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
00557 
00558         HTREEITEM hItem = pNMTreeView->itemNew.hItem;
00559         int nImage              = ItemHasChildren( hItem ) && pNMTreeView->itemNew.state & TVIS_EXPANDED;
00560         nImage = nImage ? SHI_FOLDER_OPEN : SHI_FOLDER_CLOSED;
00561         SetItemImage( hItem, nImage, nImage );
00562 
00563         CSingleLock oLock( &Library.m_pSection );
00564         if ( m_bSaveExpand && oLock.Lock( 50 ) )
00565         {
00566                 CLibraryFolder* pFolder = (CLibraryFolder*)GetItemData( hItem );
00567 
00568                 if ( LibraryFolders.CheckFolder( pFolder, TRUE ) )
00569                 {
00570                         pFolder->m_bExpanded = ( nImage == 1 );
00571                 }
00572 
00573         }
00574 }
00575 
00576 void CLibraryFolderCtrl::OnSelChanged(NMHDR* pNMHDR, LRESULT* pResult)
00577 {
00578         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
00579         NotifySelectionChanged();
00580         *pResult = 0;
00581 }
00582 
00583 void CLibraryFolderCtrl::NotifySelectionChanged()
00584 {
00585         GetParent()->PostMessage( WM_TIMER, 2 );
00586 }
00587 
00588 void CLibraryFolderCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
00589 {
00590         NMTVCUSTOMDRAW* pDraw = (NMTVCUSTOMDRAW*)pNMHDR;
00591 
00592         if ( pDraw->nmcd.dwDrawStage == CDDS_PREPAINT )
00593         {
00594                 *pResult = CDRF_NOTIFYITEMDRAW;
00595         }
00596         else if ( pDraw->nmcd.dwDrawStage == (CDDS_ITEM|CDDS_PREPAINT) )
00597         {
00598                 BOOL bSelected          = GetItemState( (HTREEITEM)pDraw->nmcd.dwItemSpec, TVIS_SELECTED ) & TVIS_SELECTED ? TRUE : FALSE;
00599                 pDraw->clrText          = GetSysColor( bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT );
00600                 pDraw->clrTextBk        = GetSysColor( bSelected ? COLOR_HIGHLIGHT : COLOR_WINDOW );
00601                 *pResult = CDRF_DODEFAULT;
00602         }
00603 }
00604 
00605 void CLibraryFolderCtrl::OnNcPaint()
00606 {
00607         CWnd::OnNcPaint();
00608 
00609         if ( GetStyle() & WS_BORDER )
00610         {
00611                 CWindowDC dc( this );
00612                 CRect rc;
00613 
00614                 COLORREF crBorder = GetSysColor( COLOR_ACTIVECAPTION );
00615 
00616                 GetWindowRect( &rc );
00617                 rc.OffsetRect( -rc.left, -rc.top );
00618                 dc.Draw3dRect( &rc, crBorder, crBorder );
00619         }
00620 }

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