2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
25 $Log: ExplorerBar.cpp,v $
26 Revision 1.3 2004/07/26 05:44:08 shersche
27 remove extraneous debug statement
29 Revision 1.2 2004/07/13 21:24:21 rpantos
30 Fix for <rdar://problem/3701120>.
32 Revision 1.1 2004/06/18 04:34:59 rpantos
33 Move to Clients from mDNSWindows
35 Revision 1.1 2004/01/30 03:01:56 bradley
36 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
45 #include "DebugServices.h"
49 #include "ExplorerBar.h"
57 static char THIS_FILE
[] = __FILE__
;
60 //===========================================================================================================================
62 //===========================================================================================================================
63 #define LENGTHOF(a) (sizeof(a) == sizeof(&*a)) ? 0 : (sizeof(a) / sizeof(*a))
67 //===========================================================================================================================
69 //===========================================================================================================================
71 ExplorerBar::ExplorerBar( void )
84 //===========================================================================================================================
86 //===========================================================================================================================
88 ExplorerBar::~ExplorerBar( void )
92 mWebBrowser
->Release();
106 #pragma mark == IUnknown implementation ==
109 //===========================================================================================================================
111 //===========================================================================================================================
113 STDMETHODIMP
ExplorerBar::QueryInterface( REFIID inID
, LPVOID
*outResult
)
117 if( IsEqualIID( inID
, IID_IUnknown
) ) // IUnknown
121 else if( IsEqualIID( inID
, IID_IOleWindow
) ) // IOleWindow
123 *outResult
= (IOleWindow
*) this;
125 else if( IsEqualIID( inID
, IID_IDockingWindow
) ) // IDockingWindow
127 *outResult
= (IDockingWindow
*) this;
129 else if( IsEqualIID( inID
, IID_IDeskBand
) ) // IDeskBand
131 *outResult
= (IDeskBand
*) this;
133 else if( IsEqualIID( inID
, IID_IInputObject
) ) // IInputObject
135 *outResult
= (IInputObject
*) this;
137 else if( IsEqualIID( inID
, IID_IObjectWithSite
) ) // IObjectWithSite
139 *outResult
= (IObjectWithSite
*) this;
141 else if( IsEqualIID( inID
, IID_IPersistStream
) ) // IPersistStream
143 *outResult
= (IPersistStream
*) this;
145 else if( IsEqualIID( inID
, IID_IContextMenu
) ) // IContextMenu
147 *outResult
= (IContextMenu
*) this;
156 ( *( (LPUNKNOWN
*) outResult
) )->AddRef();
163 //===========================================================================================================================
165 //===========================================================================================================================
167 STDMETHODIMP_( DWORD
) ExplorerBar::AddRef( void )
169 return( ++mRefCount
);
172 //===========================================================================================================================
174 //===========================================================================================================================
176 STDMETHODIMP_( DWORD
) ExplorerBar::Release( void )
190 #pragma mark == IOleWindow implementation ==
193 //===========================================================================================================================
195 //===========================================================================================================================
197 STDMETHODIMP
ExplorerBar::GetWindow( HWND
*outWindow
)
199 *outWindow
= mWindow
.GetSafeHwnd();
203 //===========================================================================================================================
204 // ContextSensitiveHelp
205 //===========================================================================================================================
207 STDMETHODIMP
ExplorerBar::ContextSensitiveHelp( BOOL inEnterMode
)
209 DEBUG_UNUSED( inEnterMode
);
216 #pragma mark == IDockingWindow implementation ==
219 //===========================================================================================================================
221 //===========================================================================================================================
223 STDMETHODIMP
ExplorerBar::ShowDW( BOOL inShow
)
225 if( mWindow
.GetSafeHwnd() )
227 mWindow
.ShowWindow( inShow
? SW_SHOW
: SW_HIDE
);
232 //===========================================================================================================================
234 //===========================================================================================================================
236 STDMETHODIMP
ExplorerBar::CloseDW( DWORD inReserved
)
238 DEBUG_UNUSED( inReserved
);
241 if( mWindow
.GetSafeHwnd() )
243 mWindow
.SendMessage( WM_CLOSE
);
248 //===========================================================================================================================
250 //===========================================================================================================================
252 STDMETHODIMP
ExplorerBar::ResizeBorderDW( LPCRECT inBorder
, IUnknown
*inPunkSite
, BOOL inReserved
)
254 DEBUG_UNUSED( inBorder
);
255 DEBUG_UNUSED( inPunkSite
);
256 DEBUG_UNUSED( inReserved
);
263 #pragma mark == IDeskBand implementation ==
266 //===========================================================================================================================
268 //===========================================================================================================================
270 STDMETHODIMP
ExplorerBar::GetBandInfo( DWORD inBandID
, DWORD inViewMode
, DESKBANDINFO
*outInfo
)
274 require_action( outInfo
, exit
, err
= E_INVALIDARG
);
277 mViewMode
= inViewMode
;
279 if( outInfo
->dwMask
& DBIM_MINSIZE
)
281 outInfo
->ptMinSize
.x
= 100;
282 outInfo
->ptMinSize
.y
= 100;
284 if( outInfo
->dwMask
& DBIM_MAXSIZE
)
286 // Unlimited max size.
288 outInfo
->ptMaxSize
.x
= -1;
289 outInfo
->ptMaxSize
.y
= -1;
291 if( outInfo
->dwMask
& DBIM_INTEGRAL
)
293 outInfo
->ptIntegral
.x
= 1;
294 outInfo
->ptIntegral
.y
= 1;
296 if( outInfo
->dwMask
& DBIM_ACTUAL
)
298 outInfo
->ptActual
.x
= 0;
299 outInfo
->ptActual
.y
= 0;
301 if( outInfo
->dwMask
& DBIM_TITLE
)
306 ok
= s
.LoadString( IDS_NAME
);
307 require_action( ok
, exit
, err
= kNoResourcesErr
);
310 lstrcpyn( outInfo
->wszTitle
, s
, sizeof_array( outInfo
->wszTitle
) );
314 nChars
= MultiByteToWideChar( CP_ACP
, 0, s
, -1, outInfo
->wszTitle
, sizeof_array( outInfo
->wszTitle
) );
315 err
= translate_errno( nChars
> 0, (OSStatus
) GetLastError(), kUnknownErr
);
316 require_noerr( err
, exit
);
319 if( outInfo
->dwMask
& DBIM_MODEFLAGS
)
321 outInfo
->dwModeFlags
= DBIMF_NORMAL
| DBIMF_VARIABLEHEIGHT
;
324 // Force the default background color.
326 outInfo
->dwMask
&= ~DBIM_BKCOLOR
;
335 #pragma mark == IInputObject implementation ==
338 //===========================================================================================================================
340 //===========================================================================================================================
342 STDMETHODIMP
ExplorerBar::UIActivateIO( BOOL inActivate
, LPMSG inMsg
)
344 DEBUG_UNUSED( inMsg
);
353 //===========================================================================================================================
355 //===========================================================================================================================
357 STDMETHODIMP
ExplorerBar::HasFocusIO( void )
359 if( mWindow
.GetFocus()->GetSafeHwnd() == mWindow
.GetSafeHwnd() )
366 //===========================================================================================================================
367 // TranslateAcceleratorIO
368 //===========================================================================================================================
370 STDMETHODIMP
ExplorerBar::TranslateAcceleratorIO( LPMSG inMsg
)
372 DEBUG_UNUSED( inMsg
);
379 #pragma mark == IObjectWithSite implementation ==
382 //===========================================================================================================================
384 //===========================================================================================================================
386 STDMETHODIMP
ExplorerBar::SetSite( IUnknown
*inPunkSite
)
388 AFX_MANAGE_STATE( AfxGetStaticModuleState() );
392 // Release the old interfaces.
396 mWebBrowser
->Release();
405 // A non-NULL site means we're setting the site. Otherwise, the site is being released (done above).
413 // Get the parent window.
415 IOleWindow
* oleWindow
;
417 mParentWindow
= NULL
;
418 err
= inPunkSite
->QueryInterface( IID_IOleWindow
, (LPVOID
*) &oleWindow
);
419 require( SUCCEEDED( err
), exit
);
421 err
= oleWindow
->GetWindow( &mParentWindow
);
422 oleWindow
->Release();
423 require_noerr( err
, exit
);
424 require_action( mParentWindow
, exit
, err
= E_FAIL
);
426 // Get the IInputObject interface.
428 err
= inPunkSite
->QueryInterface( IID_IInputObjectSite
, (LPVOID
*) &mSite
);
429 require( SUCCEEDED( err
), exit
);
432 // Get the IWebBrowser2 interface.
434 IOleCommandTarget
* oleCommandTarget
;
436 err
= inPunkSite
->QueryInterface( IID_IOleCommandTarget
, (LPVOID
*) &oleCommandTarget
);
437 require( SUCCEEDED( err
), exit
);
439 IServiceProvider
* serviceProvider
;
441 err
= oleCommandTarget
->QueryInterface( IID_IServiceProvider
, (LPVOID
*) &serviceProvider
);
442 oleCommandTarget
->Release();
443 require( SUCCEEDED( err
), exit
);
445 err
= serviceProvider
->QueryService( SID_SWebBrowserApp
, IID_IWebBrowser2
, (LPVOID
*) &mWebBrowser
);
446 serviceProvider
->Release();
447 require( SUCCEEDED( err
), exit
);
449 // Create the main window.
452 require_noerr( err
, exit
);
458 //===========================================================================================================================
460 //===========================================================================================================================
462 STDMETHODIMP
ExplorerBar::GetSite( REFIID inID
, LPVOID
*outResult
)
467 require_action( mSite
, exit
, err
= E_FAIL
);
469 err
= mSite
->QueryInterface( inID
, outResult
);
477 #pragma mark == IPersistStream implementation ==
481 // IPersistStream implementation
483 // This is only supported to allow the desk band to be dropped on the desktop and to prevent multiple instances of
484 // the desk band from showing up in the context menu. This desk band doesn't actually persist any data.
487 //===========================================================================================================================
489 //===========================================================================================================================
491 STDMETHODIMP
ExplorerBar::GetClassID( LPCLSID outClassID
)
493 *outClassID
= CLSID_ExplorerBar
;
497 //===========================================================================================================================
499 //===========================================================================================================================
501 STDMETHODIMP
ExplorerBar::IsDirty( void )
506 //===========================================================================================================================
508 //===========================================================================================================================
510 STDMETHODIMP
ExplorerBar::Load( LPSTREAM inStream
)
512 DEBUG_UNUSED( inStream
);
517 //===========================================================================================================================
519 //===========================================================================================================================
521 STDMETHODIMP
ExplorerBar::Save( LPSTREAM inStream
, BOOL inClearDirty
)
523 DEBUG_UNUSED( inStream
);
524 DEBUG_UNUSED( inClearDirty
);
529 //===========================================================================================================================
531 //===========================================================================================================================
533 STDMETHODIMP
ExplorerBar::GetSizeMax( ULARGE_INTEGER
*outSizeMax
)
535 DEBUG_UNUSED( outSizeMax
);
541 //===========================================================================================================================
543 //===========================================================================================================================
545 STDMETHODIMP
ExplorerBar::QueryContextMenu(HMENU hShellContextMenu
, UINT iContextMenuFirstItem
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
547 DEBUG_UNUSED( idCmdLast
);
548 DEBUG_UNUSED( uFlags
);
552 menubar
.LoadMenu(IDR_CONTEXT_MENU
);
553 CMenu
* menu
= menubar
.GetSubMenu(0);
557 shellmenu
.Attach(hShellContextMenu
);
559 UINT iShellItem
= iContextMenuFirstItem
; //! remove plus one
560 UINT idShellCmd
= idCmdFirst
;
562 int n
= menu
->GetMenuItemCount();
564 for (int i
=0; i
<n
; ++i
)
569 ZeroMemory(&mii
, sizeof(mii
));
570 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
571 mii
.fType
= MFT_STRING
;
572 mii
.cbSize
= sizeof(mii
);
573 mii
.cch
= LENGTHOF(sz
);
576 menu
->GetMenuItemInfo(i
, &mii
, TRUE
);
578 mii
.wID
= idShellCmd
++;
580 shellmenu
.InsertMenuItem(iShellItem
++, &mii
, TRUE
);
589 //===========================================================================================================================
591 //===========================================================================================================================
593 // Not called for explorer bars
594 STDMETHODIMP
ExplorerBar::GetCommandString(UINT idCmd
, UINT uType
, UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
596 DEBUG_UNUSED( idCmd
);
597 DEBUG_UNUSED( uType
);
598 DEBUG_UNUSED( pwReserved
);
599 DEBUG_UNUSED( pszName
);
600 DEBUG_UNUSED( cchMax
);
605 //===========================================================================================================================
607 //===========================================================================================================================
609 // The shell sends either strings or indexes
610 // IE never sends strings
611 // The indexes are into an array of my commands
612 // So the verb for the first command I added to the menu is always 0x0000
613 // Here - because I don't have any submenus -
614 // I can treat the 'verb' as an menu item position
615 STDMETHODIMP
ExplorerBar::InvokeCommand(LPCMINVOKECOMMANDINFO lpici
)
617 // IE doesn't send string commands
618 if (HIWORD(lpici
->lpVerb
) != 0) return 0;
629 #pragma mark == Other ==
632 //===========================================================================================================================
634 //===========================================================================================================================
636 OSStatus
ExplorerBar::SetupWindow( void )
644 window
= CWnd::FromHandle( mParentWindow
);
646 window
->GetClientRect( rect
);
648 ok
= s
.LoadString( IDS_NAME
);
649 require_action( ok
, exit
, err
= kNoResourcesErr
);
651 ok
= mWindow
.Create( NULL
, s
, WS_CHILD
| WS_VISIBLE
, rect
, window
, 100 ) != 0;
652 require_action( ok
, exit
, err
= kNoResourcesErr
);
654 mWindow
.SetOwner( this );
661 //===========================================================================================================================
663 //===========================================================================================================================
665 OSStatus
ExplorerBar::GoToURL( const CString
&inURL
)
671 s
= inURL
.AllocSysString();
672 require_action( s
, exit
, err
= kNoMemoryErr
);
674 VariantInit( &empty
);
675 err
= mWebBrowser
->Navigate( s
, &empty
, &empty
, &empty
, &empty
);
677 require_noerr( err
, exit
);