1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 Change History (most recent first):
19 $Log: ExplorerBar.cpp,v $
20 Revision 1.5 2009/03/30 18:44:53 herscher
21 <rdar://problem/5925472> Current Bonjour code does not compile on Windows
22 <rdar://problem/5187308> Move build train to Visual Studio 2005
24 Revision 1.4 2006/08/14 23:24:00 cheshire
25 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
27 Revision 1.3 2004/07/26 05:44:08 shersche
28 remove extraneous debug statement
30 Revision 1.2 2004/07/13 21:24:21 rpantos
31 Fix for <rdar://problem/3701120>.
33 Revision 1.1 2004/06/18 04:34:59 rpantos
34 Move to Clients from mDNSWindows
36 Revision 1.1 2004/01/30 03:01:56 bradley
37 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
46 #include "DebugServices.h"
50 #include "ExplorerBar.h"
58 static char THIS_FILE
[] = __FILE__
;
61 //===========================================================================================================================
63 //===========================================================================================================================
64 #define LENGTHOF(a) (sizeof(a) == sizeof(&*a)) ? 0 : (sizeof(a) / sizeof(*a))
68 //===========================================================================================================================
70 //===========================================================================================================================
72 ExplorerBar::ExplorerBar( void )
85 //===========================================================================================================================
87 //===========================================================================================================================
89 ExplorerBar::~ExplorerBar( void )
93 mWebBrowser
->Release();
107 #pragma mark == IUnknown implementation ==
110 //===========================================================================================================================
112 //===========================================================================================================================
114 STDMETHODIMP
ExplorerBar::QueryInterface( REFIID inID
, LPVOID
*outResult
)
118 if( IsEqualIID( inID
, IID_IUnknown
) ) // IUnknown
122 else if( IsEqualIID( inID
, IID_IOleWindow
) ) // IOleWindow
124 *outResult
= (IOleWindow
*) this;
126 else if( IsEqualIID( inID
, IID_IDockingWindow
) ) // IDockingWindow
128 *outResult
= (IDockingWindow
*) this;
130 else if( IsEqualIID( inID
, IID_IDeskBand
) ) // IDeskBand
132 *outResult
= (IDeskBand
*) this;
134 else if( IsEqualIID( inID
, IID_IInputObject
) ) // IInputObject
136 *outResult
= (IInputObject
*) this;
138 else if( IsEqualIID( inID
, IID_IObjectWithSite
) ) // IObjectWithSite
140 *outResult
= (IObjectWithSite
*) this;
142 else if( IsEqualIID( inID
, IID_IPersistStream
) ) // IPersistStream
144 *outResult
= (IPersistStream
*) this;
146 else if( IsEqualIID( inID
, IID_IContextMenu
) ) // IContextMenu
148 *outResult
= (IContextMenu
*) this;
157 ( *( (LPUNKNOWN
*) outResult
) )->AddRef();
164 //===========================================================================================================================
166 //===========================================================================================================================
168 STDMETHODIMP_( DWORD
) ExplorerBar::AddRef( void )
170 return( ++mRefCount
);
173 //===========================================================================================================================
175 //===========================================================================================================================
177 STDMETHODIMP_( DWORD
) ExplorerBar::Release( void )
191 #pragma mark == IOleWindow implementation ==
194 //===========================================================================================================================
196 //===========================================================================================================================
198 STDMETHODIMP
ExplorerBar::GetWindow( HWND
*outWindow
)
200 *outWindow
= mWindow
.GetSafeHwnd();
204 //===========================================================================================================================
205 // ContextSensitiveHelp
206 //===========================================================================================================================
208 STDMETHODIMP
ExplorerBar::ContextSensitiveHelp( BOOL inEnterMode
)
210 DEBUG_UNUSED( inEnterMode
);
217 #pragma mark == IDockingWindow implementation ==
220 //===========================================================================================================================
222 //===========================================================================================================================
224 STDMETHODIMP
ExplorerBar::ShowDW( BOOL inShow
)
226 if( mWindow
.GetSafeHwnd() )
228 mWindow
.ShowWindow( inShow
? SW_SHOW
: SW_HIDE
);
233 //===========================================================================================================================
235 //===========================================================================================================================
237 STDMETHODIMP
ExplorerBar::CloseDW( DWORD inReserved
)
239 DEBUG_UNUSED( inReserved
);
242 if( mWindow
.GetSafeHwnd() )
244 mWindow
.SendMessage( WM_CLOSE
);
249 //===========================================================================================================================
251 //===========================================================================================================================
253 STDMETHODIMP
ExplorerBar::ResizeBorderDW( LPCRECT inBorder
, IUnknown
*inPunkSite
, BOOL inReserved
)
255 DEBUG_UNUSED( inBorder
);
256 DEBUG_UNUSED( inPunkSite
);
257 DEBUG_UNUSED( inReserved
);
264 #pragma mark == IDeskBand implementation ==
267 //===========================================================================================================================
269 //===========================================================================================================================
271 STDMETHODIMP
ExplorerBar::GetBandInfo( DWORD inBandID
, DWORD inViewMode
, DESKBANDINFO
*outInfo
)
275 require_action( outInfo
, exit
, err
= E_INVALIDARG
);
278 mViewMode
= inViewMode
;
280 if( outInfo
->dwMask
& DBIM_MINSIZE
)
282 outInfo
->ptMinSize
.x
= 100;
283 outInfo
->ptMinSize
.y
= 100;
285 if( outInfo
->dwMask
& DBIM_MAXSIZE
)
287 // Unlimited max size.
289 outInfo
->ptMaxSize
.x
= -1;
290 outInfo
->ptMaxSize
.y
= -1;
292 if( outInfo
->dwMask
& DBIM_INTEGRAL
)
294 outInfo
->ptIntegral
.x
= 1;
295 outInfo
->ptIntegral
.y
= 1;
297 if( outInfo
->dwMask
& DBIM_ACTUAL
)
299 outInfo
->ptActual
.x
= 0;
300 outInfo
->ptActual
.y
= 0;
302 if( outInfo
->dwMask
& DBIM_TITLE
)
307 ok
= s
.LoadString( IDS_NAME
);
308 require_action( ok
, exit
, err
= kNoResourcesErr
);
311 lstrcpyn( outInfo
->wszTitle
, s
, sizeof_array( outInfo
->wszTitle
) );
315 nChars
= MultiByteToWideChar( CP_ACP
, 0, s
, -1, outInfo
->wszTitle
, sizeof_array( outInfo
->wszTitle
) );
316 err
= translate_errno( nChars
> 0, (OSStatus
) GetLastError(), kUnknownErr
);
317 require_noerr( err
, exit
);
320 if( outInfo
->dwMask
& DBIM_MODEFLAGS
)
322 outInfo
->dwModeFlags
= DBIMF_NORMAL
| DBIMF_VARIABLEHEIGHT
;
325 // Force the default background color.
327 outInfo
->dwMask
&= ~DBIM_BKCOLOR
;
336 #pragma mark == IInputObject implementation ==
339 //===========================================================================================================================
341 //===========================================================================================================================
343 STDMETHODIMP
ExplorerBar::UIActivateIO( BOOL inActivate
, LPMSG inMsg
)
345 DEBUG_UNUSED( inMsg
);
354 //===========================================================================================================================
356 //===========================================================================================================================
358 STDMETHODIMP
ExplorerBar::HasFocusIO( void )
360 if( mWindow
.GetFocus()->GetSafeHwnd() == mWindow
.GetSafeHwnd() )
367 //===========================================================================================================================
368 // TranslateAcceleratorIO
369 //===========================================================================================================================
371 STDMETHODIMP
ExplorerBar::TranslateAcceleratorIO( LPMSG inMsg
)
373 DEBUG_UNUSED( inMsg
);
380 #pragma mark == IObjectWithSite implementation ==
383 //===========================================================================================================================
385 //===========================================================================================================================
387 STDMETHODIMP
ExplorerBar::SetSite( IUnknown
*inPunkSite
)
389 AFX_MANAGE_STATE( AfxGetStaticModuleState() );
393 // Release the old interfaces.
397 mWebBrowser
->Release();
406 // A non-NULL site means we're setting the site. Otherwise, the site is being released (done above).
414 // Get the parent window.
416 IOleWindow
* oleWindow
;
418 mParentWindow
= NULL
;
419 err
= inPunkSite
->QueryInterface( IID_IOleWindow
, (LPVOID
*) &oleWindow
);
420 require( SUCCEEDED( err
), exit
);
422 err
= oleWindow
->GetWindow( &mParentWindow
);
423 oleWindow
->Release();
424 require_noerr( err
, exit
);
425 require_action( mParentWindow
, exit
, err
= E_FAIL
);
427 // Get the IInputObject interface.
429 err
= inPunkSite
->QueryInterface( IID_IInputObjectSite
, (LPVOID
*) &mSite
);
430 require( SUCCEEDED( err
), exit
);
433 // Get the IWebBrowser2 interface.
435 IOleCommandTarget
* oleCommandTarget
;
437 err
= inPunkSite
->QueryInterface( IID_IOleCommandTarget
, (LPVOID
*) &oleCommandTarget
);
438 require( SUCCEEDED( err
), exit
);
440 IServiceProvider
* serviceProvider
;
442 err
= oleCommandTarget
->QueryInterface( IID_IServiceProvider
, (LPVOID
*) &serviceProvider
);
443 oleCommandTarget
->Release();
444 require( SUCCEEDED( err
), exit
);
446 err
= serviceProvider
->QueryService( SID_SWebBrowserApp
, IID_IWebBrowser2
, (LPVOID
*) &mWebBrowser
);
447 serviceProvider
->Release();
448 require( SUCCEEDED( err
), exit
);
450 // Create the main window.
453 require_noerr( err
, exit
);
459 //===========================================================================================================================
461 //===========================================================================================================================
463 STDMETHODIMP
ExplorerBar::GetSite( REFIID inID
, LPVOID
*outResult
)
468 require_action( mSite
, exit
, err
= E_FAIL
);
470 err
= mSite
->QueryInterface( inID
, outResult
);
478 #pragma mark == IPersistStream implementation ==
482 // IPersistStream implementation
484 // This is only supported to allow the desk band to be dropped on the desktop and to prevent multiple instances of
485 // the desk band from showing up in the context menu. This desk band doesn't actually persist any data.
488 //===========================================================================================================================
490 //===========================================================================================================================
492 STDMETHODIMP
ExplorerBar::GetClassID( LPCLSID outClassID
)
494 *outClassID
= CLSID_ExplorerBar
;
498 //===========================================================================================================================
500 //===========================================================================================================================
502 STDMETHODIMP
ExplorerBar::IsDirty( void )
507 //===========================================================================================================================
509 //===========================================================================================================================
511 STDMETHODIMP
ExplorerBar::Load( LPSTREAM inStream
)
513 DEBUG_UNUSED( inStream
);
518 //===========================================================================================================================
520 //===========================================================================================================================
522 STDMETHODIMP
ExplorerBar::Save( LPSTREAM inStream
, BOOL inClearDirty
)
524 DEBUG_UNUSED( inStream
);
525 DEBUG_UNUSED( inClearDirty
);
530 //===========================================================================================================================
532 //===========================================================================================================================
534 STDMETHODIMP
ExplorerBar::GetSizeMax( ULARGE_INTEGER
*outSizeMax
)
536 DEBUG_UNUSED( outSizeMax
);
542 //===========================================================================================================================
544 //===========================================================================================================================
546 STDMETHODIMP
ExplorerBar::QueryContextMenu(HMENU hShellContextMenu
, UINT iContextMenuFirstItem
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
548 DEBUG_UNUSED( idCmdLast
);
549 DEBUG_UNUSED( uFlags
);
553 menubar
.LoadMenu(IDR_CONTEXT_MENU
);
554 CMenu
* menu
= menubar
.GetSubMenu(0);
558 shellmenu
.Attach(hShellContextMenu
);
560 UINT iShellItem
= iContextMenuFirstItem
; //! remove plus one
561 UINT idShellCmd
= idCmdFirst
;
563 int n
= menu
->GetMenuItemCount();
565 for (int i
=0; i
<n
; ++i
)
570 ZeroMemory(&mii
, sizeof(mii
));
571 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
572 mii
.fType
= MFT_STRING
;
573 mii
.cbSize
= sizeof(mii
);
574 mii
.cch
= LENGTHOF(sz
);
577 menu
->GetMenuItemInfo(i
, &mii
, TRUE
);
579 mii
.wID
= idShellCmd
++;
581 shellmenu
.InsertMenuItem(iShellItem
++, &mii
, TRUE
);
590 //===========================================================================================================================
592 //===========================================================================================================================
594 // Not called for explorer bars
595 STDMETHODIMP
ExplorerBar::GetCommandString(UINT_PTR idCmd
, UINT uType
, UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
597 DEBUG_UNUSED( idCmd
);
598 DEBUG_UNUSED( uType
);
599 DEBUG_UNUSED( pwReserved
);
600 DEBUG_UNUSED( pszName
);
601 DEBUG_UNUSED( cchMax
);
606 //===========================================================================================================================
608 //===========================================================================================================================
610 // The shell sends either strings or indexes
611 // IE never sends strings
612 // The indexes are into an array of my commands
613 // So the verb for the first command I added to the menu is always 0x0000
614 // Here - because I don't have any submenus -
615 // I can treat the 'verb' as an menu item position
616 STDMETHODIMP
ExplorerBar::InvokeCommand(LPCMINVOKECOMMANDINFO lpici
)
618 // IE doesn't send string commands
619 if (HIWORD(lpici
->lpVerb
) != 0) return 0;
630 #pragma mark == Other ==
633 //===========================================================================================================================
635 //===========================================================================================================================
637 OSStatus
ExplorerBar::SetupWindow( void )
645 window
= CWnd::FromHandle( mParentWindow
);
647 window
->GetClientRect( rect
);
649 ok
= s
.LoadString( IDS_NAME
);
650 require_action( ok
, exit
, err
= kNoResourcesErr
);
652 ok
= mWindow
.Create( NULL
, s
, WS_CHILD
| WS_VISIBLE
, rect
, window
, 100 ) != 0;
653 require_action( ok
, exit
, err
= kNoResourcesErr
);
655 mWindow
.SetOwner( this );
662 //===========================================================================================================================
664 //===========================================================================================================================
666 OSStatus
ExplorerBar::GoToURL( const CString
&inURL
)
672 s
= inURL
.AllocSysString();
673 require_action( s
, exit
, err
= kNoMemoryErr
);
675 VariantInit( &empty
);
676 err
= mWebBrowser
->Navigate( s
, &empty
, &empty
, &empty
, &empty
);
678 require_noerr( err
, exit
);