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

Application.cpp

Go to the documentation of this file.
00001 //
00002 // Application.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 "CoolInterface.h"
00027 #include "Library.h"
00028 #include "Plugins.h"
00029 #include "Skin.h"
00030 #include "ComMenu.h"
00031 #include "ComToolbar.h"
00032 #include "WndMain.h"
00033 #include "WndChild.h"
00034 #include "WndPlugin.h"
00035 
00036 #include "XML.h"
00037 #include "XMLCOM.h"
00038 
00039 #ifdef _DEBUG
00040 #define new DEBUG_NEW
00041 #undef THIS_FILE
00042 static char THIS_FILE[] = __FILE__;
00043 #endif
00044 
00045 BEGIN_MESSAGE_MAP(CApplication, CComObject)
00046         //{{AFX_MSG_MAP(CApplication)
00047         //}}AFX_MSG_MAP
00048 END_MESSAGE_MAP()
00049 
00050 BEGIN_INTERFACE_MAP(CApplication, CComObject)
00051         INTERFACE_PART(CApplication, IID_IApplication, Application)
00052         INTERFACE_PART(CApplication, IID_IUserInterface, UserInterface)
00053 END_INTERFACE_MAP()
00054 
00055 CApplication Application;
00056 
00057 
00059 // CApplication construction
00060 
00061 CApplication::CApplication()
00062 {
00063         EnableDispatch( IID_IApplication );
00064         EnableDispatch( IID_IUserInterface );
00065 }
00066 
00067 CApplication::~CApplication()
00068 {
00069 }
00070 
00072 // CApplication operations
00073 
00074 IApplication* CApplication::GetApp()
00075 {
00076         return (IApplication*)GetInterface( IID_IApplication, TRUE );
00077 }
00078 
00079 IUserInterface* CApplication::GetUI()
00080 {
00081         return (IUserInterface*)GetInterface( IID_IUserInterface, TRUE );
00082 }
00083 
00085 // CApplication IApplication
00086 
00087 IMPLEMENT_DISPATCH(CApplication, Application)
00088 
00089 STDMETHODIMP CApplication::XApplication::get_Application(IApplication FAR* FAR* ppApplication)
00090 {
00091         METHOD_PROLOGUE( CApplication, Application )
00092         if ( ppApplication == NULL ) return E_INVALIDARG;
00093         *ppApplication = (IApplication*)pThis->GetInterface( IID_IApplication, TRUE );
00094         return S_OK;
00095 }
00096 
00097 STDMETHODIMP CApplication::XApplication::get_Version(BSTR FAR* psVersion)
00098 {
00099         METHOD_PROLOGUE( CApplication, Application )
00100         if ( psVersion == NULL ) return E_INVALIDARG;
00101         theApp.m_sVersion.SetSysString( psVersion );
00102         return S_OK;
00103 }
00104 
00105 STDMETHODIMP CApplication::XApplication::CheckVersion(BSTR sVersion)
00106 {
00107         METHOD_PROLOGUE( CApplication, Application )
00108         if ( sVersion == NULL ) return E_INVALIDARG;
00109 
00110         int nDesired[4];
00111 
00112         if ( swscanf( sVersion, L"%i.%i.%i.%i", &nDesired[3], &nDesired[2],
00113                 &nDesired[1], &nDesired[0] ) != 4 ) return E_INVALIDARG;
00114 
00115         // NOTE: Assumes each version component is 8 bit
00116         BOOL bOk = ( theApp.m_nVersion[0] << 24 ) + ( theApp.m_nVersion[1] << 16 ) + ( theApp.m_nVersion[2] << 8 ) + theApp.m_nVersion[3]
00117                         >= ( nDesired[3] << 24 ) + ( nDesired[2] << 16 ) + ( nDesired[1] << 8 ) + nDesired[0];
00118 
00119         return bOk ? S_OK : S_FALSE;
00120 }
00121 
00122 STDMETHODIMP CApplication::XApplication::CreateXML(ISXMLElement FAR* FAR* ppXML)
00123 {
00124         METHOD_PROLOGUE( CApplication, Application )
00125         if ( ppXML == NULL ) return E_INVALIDARG;
00126         CXMLElement* pXML = new CXMLElement();
00127         *ppXML = (ISXMLElement*)CXMLCOM::Wrap( pXML, IID_ISXMLElement );
00128         return S_OK;
00129 }
00130 
00131 STDMETHODIMP CApplication::XApplication::get_UserInterface(IUserInterface FAR* FAR* ppUserInterface)
00132 {
00133         METHOD_PROLOGUE( CApplication, Application )
00134         if ( ppUserInterface == NULL ) return E_INVALIDARG;
00135         *ppUserInterface = (IUserInterface*)pThis->GetInterface( IID_IUserInterface, TRUE );
00136         return S_OK;
00137 }
00138 
00139 STDMETHODIMP CApplication::XApplication::get_Library(ILibrary FAR* FAR* ppLibrary)
00140 {
00141         METHOD_PROLOGUE( CApplication, Application )
00142         if ( ppLibrary == NULL ) return E_INVALIDARG;
00143         *ppLibrary = (ILibrary*)Library.GetInterface( IID_ILibrary, TRUE );
00144         return S_OK;
00145 }
00146 
00148 // CApplication IUserInterface
00149 
00150 IMPLEMENT_DISPATCH(CApplication, UserInterface)
00151 
00152 STDMETHODIMP CApplication::XUserInterface::get_Application(IApplication FAR* FAR* ppApplication)
00153 {
00154         METHOD_PROLOGUE( CApplication, UserInterface )
00155         if ( ppApplication == NULL ) return E_INVALIDARG;
00156         *ppApplication = (IApplication*)pThis->GetInterface( IID_IApplication, TRUE );
00157         return S_OK;
00158 }
00159 
00160 STDMETHODIMP CApplication::XUserInterface::get_UserInterface(IUserInterface FAR* FAR* ppUserInterface)
00161 {
00162         METHOD_PROLOGUE( CApplication, UserInterface )
00163         if ( ppUserInterface == NULL ) return E_INVALIDARG;
00164         *ppUserInterface = (IUserInterface*)pThis->GetInterface( IID_IUserInterface, TRUE );
00165         return S_OK;
00166 }
00167 
00168 STDMETHODIMP CApplication::XUserInterface::NewWindow(BSTR bsName, IPluginWindowOwner FAR* pOwner, IPluginWindow FAR* FAR* ppWindow)
00169 {
00170         METHOD_PROLOGUE( CApplication, UserInterface )
00171 
00172         if ( bsName == NULL || pOwner == NULL || ppWindow == NULL ) return E_INVALIDARG;
00173         if ( theApp.SafeMainWnd() == NULL ) return E_UNEXPECTED;
00174 
00175         IPluginWindowOwner* pOwner2;
00176         if ( FAILED( pOwner->QueryInterface( IID_IPluginWindowOwner, (void**)&pOwner2 ) ) ) return E_NOINTERFACE;
00177 
00178         CPluginWnd* pWnd = new CPluginWnd( CString( bsName ), pOwner2 );
00179         pOwner2->Release();
00180 
00181         *ppWindow = (IPluginWindow*)pWnd->GetInterface( &IID_IPluginWindow );
00182 
00183         return S_OK;
00184 }
00185 
00186 STDMETHODIMP CApplication::XUserInterface::get_MainWindowHwnd(HWND FAR* phWnd)
00187 {
00188         METHOD_PROLOGUE( CApplication, UserInterface )
00189         if ( phWnd == NULL ) return E_INVALIDARG;
00190         if ( theApp.SafeMainWnd() == NULL ) return E_UNEXPECTED;
00191         *phWnd = theApp.SafeMainWnd()->GetSafeHwnd();
00192         return S_OK;
00193 }
00194 
00195 STDMETHODIMP CApplication::XUserInterface::get_ActiveView(IGenericView FAR* FAR* ppView)
00196 {
00197         METHOD_PROLOGUE( CApplication, UserInterface )
00198 
00199         if ( ppView == NULL ) return E_INVALIDARG;
00200         *ppView = NULL;
00201 
00202         CMainWnd* pMainWnd = (CMainWnd*)theApp.SafeMainWnd();
00203         if ( pMainWnd == NULL ) return E_UNEXPECTED;
00204         CChildWnd* pChildWnd = pMainWnd->m_pWindows.GetActive();
00205         if ( pChildWnd == NULL ) return S_FALSE;
00206 
00207         return pChildWnd->GetGenericView( ppView );
00208 }
00209 
00210 STDMETHODIMP CApplication::XUserInterface::RegisterCommand(BSTR bsName, HICON hIcon, UINT* pnCommandID)
00211 {
00212         METHOD_PROLOGUE( CApplication, UserInterface )
00213         if ( pnCommandID == NULL ) return E_INVALIDARG;
00214         *pnCommandID = Plugins.GetCommandID();
00215         if ( bsName != NULL ) CoolInterface.NameCommand( *pnCommandID, CString( bsName ) );
00216         if ( hIcon ) CoolInterface.AddIcon( *pnCommandID, hIcon );
00217         return S_OK;
00218 }
00219 
00220 STDMETHODIMP CApplication::XUserInterface::AddFromString(BSTR sXML)
00221 {
00222         METHOD_PROLOGUE( CApplication, UserInterface )
00223         if ( sXML == NULL ) return E_INVALIDARG;
00224         return Skin.LoadFromString( CString( sXML ), Settings.General.Path + '\\' ) ? S_OK : E_FAIL;
00225 }
00226 
00227 STDMETHODIMP CApplication::XUserInterface::AddFromResource(HINSTANCE hInstance, UINT nID)
00228 {
00229         METHOD_PROLOGUE( CApplication, UserInterface )
00230         if ( hInstance == NULL || nID == 0 ) return E_INVALIDARG;
00231         return Skin.LoadFromResource( hInstance, nID ) ? S_OK : E_FAIL;
00232 }
00233 
00234 STDMETHODIMP CApplication::XUserInterface::AddFromXML(ISXMLElement FAR* pXML)
00235 {
00236         METHOD_PROLOGUE( CApplication, UserInterface )
00237         CXMLElement* pBase = CXMLCOM::Unwrap( pXML );
00238         if ( pBase == NULL ) return E_INVALIDARG;
00239         return Skin.LoadFromXML( pBase, Settings.General.Path + '\\' ) ? S_OK : E_FAIL;
00240 }
00241 
00242 STDMETHODIMP CApplication::XUserInterface::GetMenu(BSTR bsName, VARIANT_BOOL bCreate, ISMenu FAR* FAR* ppMenu)
00243 {
00244         METHOD_PROLOGUE( CApplication, UserInterface )
00245 
00246         if ( bsName == NULL || ppMenu == NULL ) return E_INVALIDARG;
00247         *ppMenu = NULL;
00248 
00249         CMenu* pMenu = Skin.GetMenu( CString( bsName ) );
00250 
00251         if ( pMenu == NULL )
00252         {
00253                 if ( bCreate == VARIANT_FALSE ) return E_FAIL;
00254                 pMenu = new CMenu();
00255                 pMenu->CreatePopupMenu();
00256                 Skin.m_pMenus.SetAt( CString( bsName ), pMenu );
00257         }
00258 
00259         *ppMenu = CComMenu::Wrap( pMenu->GetSafeHmenu() );
00260 
00261         return S_OK;
00262 }
00263 
00264 STDMETHODIMP CApplication::XUserInterface::GetToolbar(BSTR bsName, VARIANT_BOOL bCreate, ISToolbar FAR* FAR* ppToolbar)
00265 {
00266         METHOD_PROLOGUE( CApplication, UserInterface )
00267 
00268         if ( bsName == NULL || ppToolbar == NULL ) return E_INVALIDARG;
00269         *ppToolbar = NULL;
00270 
00271         CCoolBarCtrl* pBar = NULL;
00272 
00273         Skin.m_pToolbars.Lookup( CString( bsName ), (void*&)pBar );
00274 
00275         if ( pBar == NULL )
00276         {
00277                 if ( bCreate == VARIANT_FALSE ) return E_FAIL;
00278                 pBar = new CCoolBarCtrl();
00279                 Skin.m_pToolbars.SetAt( CString( bsName ), pBar );
00280         }
00281 
00282         *ppToolbar = CComToolbar::Wrap( pBar );
00283 
00284         return S_OK;
00285 }

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