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

WndPlugin.cpp

Go to the documentation of this file.
00001 //
00002 // WndPlugin.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 "WndPlugin.h"
00026 #include "WindowManager.h"
00027 #include "CoolInterface.h"
00028 #include "Skin.h"
00029 #include "SkinWindow.h"
00030 #include "ComToolbar.h"
00031 
00032 #ifdef _DEBUG
00033 #define new DEBUG_NEW
00034 #undef THIS_FILE
00035 static char THIS_FILE[] = __FILE__;
00036 #endif
00037 
00038 IMPLEMENT_DYNAMIC(CPluginWnd, CPanelWnd)
00039 
00040 BEGIN_MESSAGE_MAP(CPluginWnd, CPanelWnd)
00041         //{{AFX_MSG_MAP(CPluginWnd)
00042         ON_WM_CREATE()
00043         ON_WM_SIZE()
00044         //}}AFX_MSG_MAP
00045 END_MESSAGE_MAP()
00046 
00047 BEGIN_INTERFACE_MAP(CPluginWnd, CPanelWnd)
00048         INTERFACE_PART(CPluginWnd, IID_IPluginWindow, PluginWindow)
00049 END_INTERFACE_MAP()
00050 
00051 
00053 // CPluginWnd construction
00054 
00055 CPluginWnd::CPluginWnd(LPCTSTR pszName, IPluginWindowOwner* pOwner)
00056 {
00057         m_pOwner        = pOwner;
00058         m_sName         = pszName;
00059         m_pHandled      = NULL;
00060         m_nHandled      = NULL;
00061         m_pToolbar      = NULL;
00062         m_bAccel        = TRUE;
00063 
00064         m_pOwner->AddRef();
00065         InternalAddRef();
00066 }
00067 
00068 CPluginWnd::~CPluginWnd()
00069 {
00070         m_pOwner->Release();
00071         if ( m_pHandled ) delete [] m_pHandled;
00072         if ( m_pToolbar ) delete m_pToolbar;
00073 }
00074 
00076 // CPluginWnd message handlers
00077 
00078 BOOL CPluginWnd::PreTranslateMessage(MSG* pMsg)
00079 {
00080         if ( m_bAccel && pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST )
00081         {
00082                 HRESULT hr = m_pOwner->OnTranslate( pMsg );
00083                 if ( S_OK == hr ) return TRUE;
00084                 if ( E_NOTIMPL == hr ) m_bAccel = FALSE;
00085         }
00086 
00087         return CPanelWnd::PreTranslateMessage( pMsg );
00088 }
00089 
00090 LRESULT CPluginWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00091 {
00092         UINT* pHandled = m_pHandled;
00093         DWORD nHandled = m_nHandled;
00094 
00095         while ( nHandled-- )
00096         {
00097                 if ( *pHandled++ == message )
00098                 {
00099                         LRESULT lResult;
00100                         if ( S_OK == m_pOwner->OnMessage( message, wParam, lParam, &lResult ) )
00101                                 return lResult;
00102                         break;
00103                 }
00104         }
00105 
00106         return CPanelWnd::WindowProc( message, wParam, lParam );
00107 }
00108 
00109 int CPluginWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00110 {
00111         if ( CMDIChildWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00112 
00113         m_bAlert = 1982;
00114         OnSkinChange();
00115         m_bAlert = FALSE;
00116 
00117         GetManager()->Add( this );
00118 
00119         return 0;
00120 }
00121 
00122 void CPluginWnd::OnSize(UINT nType, int cx, int cy)
00123 {
00124         if ( nType != 1982 ) CPanelWnd::OnSize( nType, cx, cy );
00125 
00126         if ( m_pToolbar != NULL )
00127         {
00128                 CRect rc;
00129                 GetClientRect( &rc );
00130 
00131                 if ( m_nToolbar == 1 )
00132                 {
00133                         m_pToolbar->SetWindowPos( NULL, 0, 0, rc.right, 28, SWP_NOZORDER );
00134                 }
00135                 else if ( m_nToolbar == 2 )
00136                 {
00137                         m_pToolbar->SetWindowPos( NULL, 0, rc.bottom - 28, rc.Width(), 28, SWP_NOZORDER );
00138                 }
00139         }
00140 }
00141 
00142 void CPluginWnd::OnSkinChange()
00143 {
00144         m_pSkin = Skin.GetWindowSkin( m_sName );
00145         if ( m_pSkin == NULL ) m_pSkin = Skin.GetWindowSkin( this );
00146 
00147         if ( m_nResID )
00148         {
00149                 HICON hIcon = CoolInterface.ExtractIcon( m_nResID );
00150 
00151                 if ( ! hIcon )
00152                 {
00153                         hIcon = (HICON)LoadImage( AfxGetResourceHandle(),
00154                                 MAKEINTRESOURCE( m_nResID ), IMAGE_ICON, 16, 16, 0 );
00155                 }
00156 
00157                 SetIcon( theApp.m_bRTL ? CreateMirroredIcon( hIcon ) : hIcon, FALSE );
00158 
00159                 CString strCaption;
00160                 Skin.LoadString( strCaption, m_nResID );
00161 
00162                 SetWindowText( _T("") );
00163                 SetWindowText( strCaption );
00164         }
00165 
00166         if ( m_bAlert != 1982 )
00167         {
00168                 SetWindowRgn( NULL, FALSE );
00169                 SetWindowPos( NULL, 0, 0, 0, 0,
00170                         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED );
00171 
00172                 if ( m_pSkin ) m_pSkin->OnSize( this );
00173 
00174                 LRESULT lResult = 0;
00175                 m_pOwner->OnMessage( WM_SKINCHANGED, 0, 0, &lResult );
00176         }
00177 }
00178 
00179 HRESULT CPluginWnd::GetGenericView(IGenericView** ppView)
00180 {
00181         if ( m_pOwner == NULL ) return S_FALSE;
00182         return m_pOwner->QueryInterface( IID_IGenericView, (void**)ppView ) ? S_OK : S_FALSE;
00183 }
00184 
00186 // CPluginWnd IPluginWindow
00187 
00188 IMPLEMENT_UNKNOWN(CPluginWnd, PluginWindow)
00189 
00190 STDMETHODIMP CPluginWnd::XPluginWindow::ListenForSingleMessage(UINT nMessage)
00191 {
00192         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00193 
00194         UINT* pHandled = new UINT[ pThis->m_nHandled + 1 ];
00195         if ( pThis->m_pHandled )
00196         {
00197                 CopyMemory( pHandled, pThis->m_pHandled, sizeof(UINT) * pThis->m_nHandled );
00198                 delete [] pThis->m_pHandled;
00199         }
00200         pThis->m_pHandled = pHandled;
00201         pThis->m_pHandled[ pThis->m_nHandled++ ] = nMessage;
00202 
00203         return S_OK;
00204 }
00205 
00206 STDMETHODIMP CPluginWnd::XPluginWindow::ListenForMultipleMessages(SAFEARRAY FAR* pMessages)
00207 {
00208         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00209 
00210         if ( SafeArrayGetDim( pMessages ) != 1 ) return E_INVALIDARG;
00211         if ( SafeArrayGetElemsize( pMessages ) != sizeof(UINT) ) return E_INVALIDARG;
00212 
00213         DWORD nCount;
00214         SafeArrayGetUBound( pMessages, 1, (LONG*)&nCount );
00215         nCount++;
00216 
00217         UINT* pHandled = new UINT[ pThis->m_nHandled + nCount ];
00218         if ( pThis->m_pHandled )
00219         {
00220                 CopyMemory( pHandled, pThis->m_pHandled, sizeof(UINT) * pThis->m_nHandled );
00221                 delete [] pThis->m_pHandled;
00222         }
00223         pThis->m_pHandled = pHandled;
00224 
00225         UINT* pSource;
00226         SafeArrayAccessData( pMessages, (void**)&pSource );
00227         while ( nCount-- ) pThis->m_pHandled[ pThis->m_nHandled++ ] = *pSource++;
00228         SafeArrayUnaccessData( pMessages );
00229 
00230         return S_OK;
00231 }
00232 
00233 STDMETHODIMP CPluginWnd::XPluginWindow::Create1(BSTR bsCaption, HICON hIcon, VARIANT_BOOL bPanel, VARIANT_BOOL bTabbed)
00234 {
00235         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00236 
00237         pThis->m_bPanelMode     = ( Settings.General.GUIMode != GUI_WINDOWED && ( bPanel == VARIANT_TRUE ) );
00238         pThis->m_bTabMode       = ( pThis->m_bPanelMode && ( bTabbed == VARIANT_TRUE ) );
00239 
00240         if ( ! pThis->CMDIChildWnd::Create( NULL, NULL,
00241                 WS_CHILD|WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN ) ) return E_FAIL;
00242 
00243         if ( hIcon != NULL ) pThis->SetIcon( hIcon, FALSE );
00244         pThis->SetWindowText( CString( bsCaption ) );
00245 
00246         return S_OK;
00247 }
00248 
00249 STDMETHODIMP CPluginWnd::XPluginWindow::Create2(UINT nCommandID, VARIANT_BOOL bPanel, VARIANT_BOOL bTabbed)
00250 {
00251         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00252 
00253         pThis->m_bPanelMode     = ( Settings.General.GUIMode != GUI_WINDOWED && ( bPanel == VARIANT_TRUE ) );
00254         pThis->m_bTabMode       = ( pThis->m_bPanelMode && ( bTabbed == VARIANT_TRUE ) );
00255 
00256         if ( ! pThis->Create( nCommandID, FALSE ) ) return E_FAIL;
00257 
00258         return S_OK;
00259 }
00260 
00261 STDMETHODIMP CPluginWnd::XPluginWindow::GetHwnd(HWND FAR* phWnd)
00262 {
00263         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00264         *phWnd = pThis->GetSafeHwnd();
00265         return S_OK;
00266 }
00267 
00268 STDMETHODIMP CPluginWnd::XPluginWindow::HandleMessage(LRESULT* plResult)
00269 {
00270         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00271 
00272         if ( MSG const * pMsg = pThis->GetCurrentMessage() )
00273         {
00274                 *plResult = pThis->CPanelWnd::WindowProc( pMsg->message, pMsg->wParam, pMsg->lParam );
00275                 return S_OK;
00276         }
00277         else
00278         {
00279                 return E_UNEXPECTED;
00280         }
00281 }
00282 
00283 STDMETHODIMP CPluginWnd::XPluginWindow::LoadState(VARIANT_BOOL bMaximise)
00284 {
00285         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00286         pThis->LoadState( pThis->m_sName, bMaximise == VARIANT_TRUE );
00287         return S_OK;
00288 }
00289 
00290 STDMETHODIMP CPluginWnd::XPluginWindow::SaveState()
00291 {
00292         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00293         pThis->SaveState( pThis->m_sName );
00294         return S_OK;
00295 }
00296 
00297 STDMETHODIMP CPluginWnd::XPluginWindow::ThrowMenu(BSTR sName, LONG nDefaultID, POINT FAR* pPoint)
00298 {
00299         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00300         CPoint pt;
00301         if ( pPoint ) pt = *pPoint;
00302         else GetCursorPos( &pt );
00303         pThis->TrackPopupMenu( CString( sName ), pt, (UINT)nDefaultID );
00304         return S_OK;
00305 }
00306 
00307 STDMETHODIMP CPluginWnd::XPluginWindow::AddToolbar(BSTR sName, LONG nPosition, HWND FAR* phWnd, ISToolbar FAR* FAR* ppToolbar)
00308 {
00309         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00310 
00311         if ( pThis->m_pToolbar != NULL ) delete pThis->m_pToolbar;
00312 
00313         pThis->m_nToolbar = nPosition ? nPosition : 2;
00314 
00315         pThis->m_pToolbar = new CCoolBarCtrl();
00316         pThis->m_pToolbar->Create( pThis, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR );
00317         pThis->m_pToolbar->SetBarStyle( pThis->m_pToolbar->GetBarStyle() | CBRS_TOOLTIPS );
00318         pThis->m_pToolbar->SetOwner( AfxGetMainWnd() );
00319 
00320         if ( pThis->m_nToolbar & 1 )
00321         {
00322                 pThis->m_pToolbar->SetBarStyle( pThis->m_pToolbar->GetBarStyle() | CBRS_BORDER_BOTTOM );
00323         }
00324 
00325         if ( pThis->m_nToolbar & 2 )
00326         {
00327                 pThis->m_pToolbar->SetBarStyle( pThis->m_pToolbar->GetBarStyle() | CBRS_BORDER_TOP );
00328         }
00329 
00330         Skin.CreateToolBar( CString( sName ), pThis->m_pToolbar );
00331 
00332         if ( phWnd ) *phWnd = pThis->m_pToolbar->GetSafeHwnd();
00333         if ( ppToolbar ) *ppToolbar = CComToolbar::Wrap( pThis->m_pToolbar );
00334 
00335         pThis->SendMessage( WM_SIZE, 1982, 0 );
00336 
00337         return S_OK;
00338 }
00339 
00340 STDMETHODIMP CPluginWnd::XPluginWindow::AdjustWindowRect(RECT FAR* pRect, VARIANT_BOOL bClientToWindow)
00341 {
00342         METHOD_PROLOGUE( CPluginWnd, PluginWindow )
00343 
00344         if ( pThis->m_pSkin != NULL )
00345         {
00346                 pThis->m_pSkin->CalcWindowRect( pRect, bClientToWindow ? FALSE : TRUE );
00347         }
00348         else
00349         {
00350                 pThis->CalcWindowRect( pRect );
00351         }
00352 
00353         return NOERROR;
00354 }
00355 

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