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

ComToolbar.cpp

Go to the documentation of this file.
00001 //
00002 // ComToolbar.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 "Application.h"
00026 #include "ComToolbar.h"
00027 #include "CtrlCoolBar.h"
00028 
00029 #ifdef _DEBUG
00030 #define new DEBUG_NEW
00031 #undef THIS_FILE
00032 static char THIS_FILE[] = __FILE__;
00033 #endif
00034 
00035 BEGIN_MESSAGE_MAP(CComToolbar, CComObject)
00036         //{{AFX_MSG_MAP(CComToolbar)
00037         //}}AFX_MSG_MAP
00038 END_MESSAGE_MAP()
00039 
00040 BEGIN_INTERFACE_MAP(CComToolbar, CComObject)
00041         INTERFACE_PART(CComToolbar, IID_ISToolbar, SToolbar)
00042         INTERFACE_PART(CComToolbar, IID_ISToolbarItem, SToolbarItem)
00043         INTERFACE_PART(CComToolbar, IID_IEnumVARIANT, EnumVARIANT)
00044 END_INTERFACE_MAP()
00045 
00046 
00048 // CComToolbar construction
00049 
00050 CComToolbar::CComToolbar(CCoolBarCtrl* pBar, CCoolBarItem* pItem)
00051 {
00052         m_pBar  = pBar;
00053         m_pItem = pItem;
00054 
00055         if ( pItem )
00056                 EnableDispatch( IID_ISToolbarItem );
00057         else
00058                 EnableDispatch( IID_ISToolbar );
00059 }
00060 
00061 CComToolbar::~CComToolbar()
00062 {
00063 }
00064 
00066 // CComToolbar operations
00067 
00068 ISToolbar* CComToolbar::Wrap(CCoolBarCtrl* pBar)
00069 {
00070         CComToolbar* pWrap = new CComToolbar( pBar, NULL );
00071         return (ISToolbar*)pWrap->GetInterface( IID_ISToolbar, FALSE );
00072 }
00073 
00074 ISToolbarItem* CComToolbar::Wrap(CCoolBarCtrl* pBar, CCoolBarItem* pItem)
00075 {
00076         CComToolbar* pWrap = new CComToolbar( pBar, pItem );
00077         return (ISToolbarItem*)pWrap->GetInterface( IID_ISToolbarItem, FALSE );
00078 }
00079 
00081 // CComToolbar ISMenu
00082 
00083 IMPLEMENT_DISPATCH(CComToolbar, SToolbar)
00084 
00085 STDMETHODIMP CComToolbar::XSToolbar::get_Application(IApplication FAR* FAR* ppApplication)
00086 {
00087         METHOD_PROLOGUE( CComToolbar, SToolbar )
00088         *ppApplication = Application.GetApp();
00089         return S_OK;
00090 }
00091 
00092 STDMETHODIMP CComToolbar::XSToolbar::get_UserInterface(IUserInterface FAR* FAR* ppUserInterface)
00093 {
00094         METHOD_PROLOGUE( CComToolbar, SToolbar )
00095         *ppUserInterface = Application.GetUI();
00096         return S_OK;
00097 }
00098 
00099 STDMETHODIMP CComToolbar::XSToolbar::get__NewEnum(IUnknown FAR* FAR* ppEnum)
00100 {
00101         METHOD_PROLOGUE( CComToolbar, SToolbar )
00102         if ( pThis->m_pBar == NULL ) return E_UNEXPECTED;
00103 
00104         AddRef();
00105         *ppEnum = &pThis->m_xEnumVARIANT;
00106         pThis->m_xEnumVARIANT.m_nIndex = 0;
00107 
00108         return S_OK;
00109 }
00110 
00111 STDMETHODIMP CComToolbar::XSToolbar::get_Item(VARIANT vIndex, ISToolbarItem FAR* FAR* ppItem)
00112 {
00113         METHOD_PROLOGUE( CComToolbar, SToolbar )
00114         if ( pThis->m_pBar == NULL ) return E_UNEXPECTED;
00115 
00116         VARIANT va;
00117         VariantInit( &va );
00118 
00119         if ( FAILED( VariantChangeType( &va, (VARIANT FAR*)&vIndex, 0, VT_I4 ) ) )
00120         {
00121                 *ppItem = NULL;
00122                 return E_FAIL;
00123         }
00124 
00125         if ( va.lVal >= 0 && va.lVal < pThis->m_pBar->GetCount() )
00126         {
00127                 *ppItem = CComToolbar::Wrap( pThis->m_pBar, pThis->m_pBar->GetIndex( va.lVal ) );
00128                 return S_OK;
00129         }
00130 
00131         if ( CCoolBarItem* pItem = pThis->m_pBar->GetID( va.lVal ) )
00132         {
00133                 *ppItem = CComToolbar::Wrap( pThis->m_pBar, pItem );
00134                 return S_OK;
00135         }
00136 
00137         *ppItem = NULL;
00138 
00139         return S_OK;
00140 }
00141 
00142 STDMETHODIMP CComToolbar::XSToolbar::get_Count(LONG FAR* pnCount)
00143 {
00144         METHOD_PROLOGUE( CComToolbar, SToolbar )
00145         if ( pThis->m_pBar == NULL ) return E_UNEXPECTED;
00146         *pnCount = pThis->m_pBar->GetCount();
00147         return S_OK;
00148 }
00149 
00150 STDMETHODIMP CComToolbar::XSToolbar::InsertSeparator(LONG nPosition)
00151 {
00152         METHOD_PROLOGUE( CComToolbar, SToolbar )
00153         if ( pThis->m_pBar == NULL ) return E_UNEXPECTED;
00154         pThis->m_pBar->Add( ID_SEPARATOR );
00155         return S_OK;
00156 }
00157 
00158 STDMETHODIMP CComToolbar::XSToolbar::InsertButton(LONG nPosition, LONG nCommandID, BSTR sText, ISToolbarItem FAR* FAR* ppItem)
00159 {
00160         METHOD_PROLOGUE( CComToolbar, SToolbar )
00161         if ( pThis->m_pBar == NULL ) return E_UNEXPECTED;
00162 
00163         CCoolBarItem* pItem = pThis->m_pBar->Add( (UINT)nCommandID, CString( sText ), (int)nPosition );
00164         if ( ppItem ) *ppItem = CComToolbar::Wrap( pThis->m_pBar, pItem );
00165 
00166         return S_OK;
00167 }
00168 
00170 // CComToolbar ISToolbarItem
00171 
00172 IMPLEMENT_DISPATCH(CComToolbar, SToolbarItem)
00173 
00174 STDMETHODIMP CComToolbar::XSToolbarItem::get_Application(IApplication FAR* FAR* ppApplication)
00175 {
00176         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00177         *ppApplication = Application.GetApp();
00178         return S_OK;
00179 }
00180 
00181 STDMETHODIMP CComToolbar::XSToolbarItem::get_UserInterface(IUserInterface FAR* FAR* ppUserInterface)
00182 {
00183         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00184         *ppUserInterface = Application.GetUI();
00185         return S_OK;
00186 }
00187 
00188 STDMETHODIMP CComToolbar::XSToolbarItem::get_Toolbar(ISToolbar FAR* FAR* ppToolbar)
00189 {
00190         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00191         if ( pThis->m_pBar == NULL ) return E_UNEXPECTED;
00192         *ppToolbar = CComToolbar::Wrap( pThis->m_pBar );
00193         return E_NOTIMPL;
00194 }
00195 
00196 STDMETHODIMP CComToolbar::XSToolbarItem::get_ItemType(SToolbarType FAR* pnType)
00197 {
00198         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00199         if ( pThis->m_pItem == NULL ) return E_UNEXPECTED;
00200 
00201         if ( pThis->m_pItem->m_nCtrlID )
00202                 *pnType = tbControl;
00203         else if ( pThis->m_pItem->m_nID == ID_SEPARATOR )
00204                 *pnType = tbSeparator;
00205         else
00206                 *pnType = tbButton;
00207 
00208         return S_OK;
00209 }
00210 
00211 STDMETHODIMP CComToolbar::XSToolbarItem::get_CommandID(LONG FAR* pnCommandID)
00212 {
00213         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00214         if ( pThis->m_pItem == NULL ) return E_UNEXPECTED;
00215         *pnCommandID = (LONG)pThis->m_pItem->m_nID;
00216         return S_OK;
00217 }
00218 
00219 STDMETHODIMP CComToolbar::XSToolbarItem::put_CommandID(LONG nCommandID)
00220 {
00221         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00222         if ( pThis->m_pItem == NULL ) return E_UNEXPECTED;
00223         pThis->m_pItem->m_nID = (UINT)nCommandID;
00224         pThis->m_pItem->SetImage( pThis->m_pItem->m_nID );
00225         return S_OK;
00226 }
00227 
00228 STDMETHODIMP CComToolbar::XSToolbarItem::get_Text(BSTR FAR* psText)
00229 {
00230         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00231         if ( pThis->m_pItem == NULL ) return E_UNEXPECTED;
00232         pThis->m_pItem->m_sText.SetSysString( psText );
00233         return S_OK;
00234 }
00235 
00236 STDMETHODIMP CComToolbar::XSToolbarItem::put_Text(BSTR sText)
00237 {
00238         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00239         if ( pThis->m_pItem == NULL ) return E_UNEXPECTED;
00240         pThis->m_pItem->SetText( CString( sText ) );
00241         return S_OK;
00242 }
00243 
00244 STDMETHODIMP CComToolbar::XSToolbarItem::Remove()
00245 {
00246         METHOD_PROLOGUE( CComToolbar, SToolbarItem )
00247         if ( pThis->m_pItem == NULL ) return E_UNEXPECTED;
00248         return E_NOTIMPL;
00249 }
00250 
00252 // CComToolbar::XEnumVARIANT enumerator
00253 
00254 IMPLEMENT_UNKNOWN( CComToolbar, EnumVARIANT )
00255 
00256 STDMETHODIMP CComToolbar::XEnumVARIANT::Next(ULONG celt, VARIANT FAR* rgvar, ULONG FAR* pceltFetched)
00257 {
00258         METHOD_PROLOGUE( CComToolbar, EnumVARIANT )
00259 
00260         if ( pceltFetched ) *pceltFetched = 0;
00261         else if ( celt > 1 ) return E_INVALIDARG;
00262 
00263         VariantInit( &rgvar[0] );
00264 
00265         if ( m_nIndex >= (UINT)pThis->m_pBar->GetCount() ) return S_FALSE;
00266 
00267         rgvar[0].vt                     = VT_DISPATCH;
00268         rgvar[0].pdispVal       = (IDispatch*)CComToolbar::Wrap(
00269                 pThis->m_pBar, pThis->m_pBar->GetIndex( m_nIndex ) );
00270 
00271         m_nIndex++;
00272         if ( pceltFetched ) (*pceltFetched)++;
00273 
00274         return S_OK;
00275 }
00276 
00277 STDMETHODIMP CComToolbar::XEnumVARIANT::Skip(ULONG celt)
00278 {
00279     METHOD_PROLOGUE( CComToolbar, EnumVARIANT )
00280 
00281         int nCount = pThis->m_pBar->GetCount();
00282 
00283         while ( celt-- && m_nIndex++ < (UINT)nCount );
00284 
00285     return ( celt == 0 ? S_OK : S_FALSE );
00286 }
00287 
00288 STDMETHODIMP CComToolbar::XEnumVARIANT::Reset()
00289 {
00290     METHOD_PROLOGUE( CComToolbar, EnumVARIANT )
00291         m_nIndex = 0;
00292     return S_OK;
00293 }
00294 
00295 STDMETHODIMP CComToolbar::XEnumVARIANT::Clone(IEnumVARIANT FAR* FAR* ppenum)
00296 {
00297     METHOD_PROLOGUE( CComToolbar, EnumVARIANT )
00298     return E_NOTIMPL;
00299 }
00300 

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