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

CtrlNetworkCombo.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlNetworkCombo.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 "CtrlNetworkCombo.h"
00025 
00026 IMPLEMENT_DYNAMIC(CNetworkCombo, CComboBox)
00027 
00028 BEGIN_MESSAGE_MAP(CNetworkCombo, CComboBox)
00029         ON_WM_CREATE()
00030 END_MESSAGE_MAP()
00031 
00032 
00034 // CNetworkCombo construction
00035 
00036 CNetworkCombo::CNetworkCombo()
00037 {
00038 }
00039 
00040 CNetworkCombo::~CNetworkCombo()
00041 {
00042 }
00043 
00045 // CNetworkCombo operations
00046 
00047 BOOL CNetworkCombo::Create(DWORD dwStyle, CWnd* pParentWnd, UINT nID)
00048 {
00049         CRect rect( 0, 0, 0, 0 );
00050         dwStyle |= WS_CHILD|WS_VSCROLL|CBS_DROPDOWNLIST|CBS_OWNERDRAWFIXED|CBS_HASSTRINGS;
00051         return CComboBox::Create( dwStyle, rect, pParentWnd, nID );
00052 }
00053 
00054 int CNetworkCombo::GetNetwork()
00055 {
00056         int nSel = GetCurSel();
00057         return nSel >= 0 ? GetItemData( nSel ) : PROTOCOL_NULL;
00058 }
00059 
00060 void CNetworkCombo::SetNetwork(int nProtocol)
00061 {
00062         for ( int nItem = 0 ; nItem < GetCount() ; nItem ++ )
00063         {
00064                 if ( GetItemData( nItem ) == nProtocol )
00065                 {
00066                         SetCurSel( nItem );
00067                         break;
00068                 }
00069         }
00070 }
00071 
00073 // CNetworkCombo message handlers
00074 
00075 int CNetworkCombo::OnCreate(LPCREATESTRUCT lpCreateStruct)
00076 {
00077         if ( CComboBox::OnCreate( lpCreateStruct ) == -1 ) return -1;
00078 
00079         CBitmap bmProtocols;
00080         bmProtocols.LoadBitmap( IDB_PROTOCOLS );
00081         if ( theApp.m_bRTL )
00082                 bmProtocols.m_hObject = CreateMirroredBitmap( (HBITMAP)bmProtocols.m_hObject );
00083 
00084         if ( ! m_gdiImageList.Create( 16, 16, ILC_COLOR32|ILC_MASK, 6, 1 ) )
00085                 m_gdiImageList.Create( 16, 16, ILC_COLOR16|ILC_MASK, 6, 1 );
00086 
00087         m_gdiImageList.Add( AfxGetApp()->LoadIcon( IDR_MAINFRAME ) );
00088         m_gdiImageList.Add( &bmProtocols, RGB( 0, 255, 0 ) );
00089 
00090         CString str;
00091         LoadString( str, IDS_SEARCH_ALL_NETWORKS );
00092 
00093         SetItemData( AddString( str ), PROTOCOL_NULL );
00094         SetItemData( AddString( _T("Gnutella2") ), PROTOCOL_G2 );
00095         SetItemData( AddString( _T("Gnutella1") ), PROTOCOL_G1 );
00096         SetItemData( AddString( _T("eDonkey2000") ), PROTOCOL_ED2K );
00097         SetCurSel( 0 );
00098 
00099         return 0;
00100 }
00101 
00102 void CNetworkCombo::OnSkinChange()
00103 {
00104         CString str;
00105         LoadString( str, IDS_SEARCH_ALL_NETWORKS );
00106         BOOL bSel = GetCurSel() == 0;
00107         DeleteString( 0 );
00108         InsertString( 0, str );
00109         SetItemData( 0, PROTOCOL_NULL );
00110         if ( bSel ) SetCurSel( 0 );
00111 }
00112 
00113 void CNetworkCombo::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00114 {
00115         lpMeasureItemStruct->itemWidth  = 1024;
00116         lpMeasureItemStruct->itemHeight = 18;
00117 }
00118 
00119 void CNetworkCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
00120 {
00121         if ( lpDrawItemStruct->itemID == (UINT)-1 ) return;
00122         if ( ( lpDrawItemStruct->itemAction & ODA_SELECT ) == 0 &&
00123                  ( lpDrawItemStruct->itemAction & ODA_DRAWENTIRE ) == 0 ) return;
00124 
00125         CRect rcItem( &lpDrawItemStruct->rcItem );
00126         CPoint pt( rcItem.left + 1, rcItem.top + 1 );
00127         CDC dc;
00128 
00129         dc.Attach( lpDrawItemStruct->hDC );
00130         if ( theApp.m_bRTL ) theApp.m_pfnSetLayout( dc.m_hDC, LAYOUT_RTL );
00131 
00132         CFont* pOldFont = (CFont*)dc.SelectObject( lpDrawItemStruct->itemData == 0 ?
00133                 &theApp.m_gdiFontBold : &theApp.m_gdiFont );
00134 
00135         dc.SetTextColor( GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00136                 ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
00137 
00138         /*dc.FillSolidRect( &rcItem, GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00139                         ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );*/
00140         if ( IsWindowEnabled() )
00141         {
00142                 if ( lpDrawItemStruct->itemState & ODS_SELECTED )
00143                         dc.FillSolidRect( &rcItem, GetSysColor( COLOR_HIGHLIGHT ) );
00144                 else
00145                         dc.FillSolidRect( &rcItem, GetSysColor( COLOR_WINDOW));
00146         }
00147         else
00148                 dc.FillSolidRect( &rcItem, GetBkColor(lpDrawItemStruct->hDC) );
00149 
00150         dc.SetBkMode( TRANSPARENT );
00151 
00152 
00153         int nImage = (int)lpDrawItemStruct->itemData;
00154         if ( nImage ) nImage ++;
00155 
00156         if ( theApp.m_bRTL && nImage ) nImage = m_gdiImageList.GetImageCount() - nImage;
00157         m_gdiImageList.Draw( &dc, nImage, pt,
00158                 ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? ILD_SELECTED : ILD_NORMAL );
00159 
00160         rcItem.left += 20; rcItem.right -= 2;
00161 
00162         CString str;
00163         GetLBText( lpDrawItemStruct->itemID, str );
00164         dc.DrawText( str, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX );
00165 
00166         dc.SelectObject( pOldFont );
00167 
00168         dc.Detach();
00169 }

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