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.4 2006/08/14 23:24:00 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
23 Revision 1.3 2004/07/26 05:44:08 shersche
24 remove extraneous debug statement
26 Revision 1.2 2004/07/13 21:24:21 rpantos
27 Fix for <rdar://problem/3701120>.
29 Revision 1.1 2004/06/18 04:34:59 rpantos
30 Move to Clients from mDNSWindows
32 Revision 1.1 2004/01/30 03:01:56 bradley
33 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
42 #include "DebugServices.h"
46 #include "ExplorerBar.h"
54 static char THIS_FILE
[] = __FILE__
;
57 //===========================================================================================================================
59 //===========================================================================================================================
60 #define LENGTHOF(a) (sizeof(a) == sizeof(&*a)) ? 0 : (sizeof(a) / sizeof(*a))
64 //===========================================================================================================================
66 //===========================================================================================================================
68 ExplorerBar::ExplorerBar( void )
81 //===========================================================================================================================
83 //===========================================================================================================================
85 ExplorerBar::~ExplorerBar( void )
89 mWebBrowser
->Release();
103 #pragma mark == IUnknown implementation ==
106 //===========================================================================================================================
108 //===========================================================================================================================
110 STDMETHODIMP
ExplorerBar::QueryInterface( REFIID inID
, LPVOID
*outResult
)
114 if( IsEqualIID( inID
, IID_IUnknown
) ) // IUnknown
118 else if( IsEqualIID( inID
, IID_IOleWindow
) ) // IOleWindow
120 *outResult
= (IOleWindow
*) this;
122 else if( IsEqualIID( inID
, IID_IDockingWindow
) ) // IDockingWindow
124 *outResult
= (IDockingWindow
*) this;
126 else if( IsEqualIID( inID
, IID_IDeskBand
) ) // IDeskBand
128 *outResult
= (IDeskBand
*) this;
130 else if( IsEqualIID( inID
, IID_IInputObject
) ) // IInputObject
132 *outResult
= (IInputObject
*) this;
134 else if( IsEqualIID( inID
, IID_IObjectWithSite
) ) // IObjectWithSite
136 *outResult
= (IObjectWithSite
*) this;
138 else if( IsEqualIID( inID
, IID_IPersistStream
) ) // IPersistStream
140 *outResult
= (IPersistStream
*) this;
142 else if( IsEqualIID( inID
, IID_IContextMenu
) ) // IContextMenu
144 *outResult
= (IContextMenu
*) this;
153 ( *( (LPUNKNOWN
*) outResult
) )->AddRef();
160 //===========================================================================================================================
162 //===========================================================================================================================
164 STDMETHODIMP_( DWORD
) ExplorerBar::AddRef( void )
166 return( ++mRefCount
);
169 //===========================================================================================================================
171 //===========================================================================================================================
173 STDMETHODIMP_( DWORD
) ExplorerBar::Release( void )
187 #pragma mark == IOleWindow implementation ==
190 //===========================================================================================================================
192 //===========================================================================================================================
194 STDMETHODIMP
ExplorerBar::GetWindow( HWND
*outWindow
)
196 *outWindow
= mWindow
.GetSafeHwnd();
200 //===========================================================================================================================
201 // ContextSensitiveHelp
202 //===========================================================================================================================
204 STDMETHODIMP
ExplorerBar::ContextSensitiveHelp( BOOL inEnterMode
)
206 DEBUG_UNUSED( inEnterMode
);
213 #pragma mark == IDockingWindow implementation ==
216 //===========================================================================================================================
218 //===========================================================================================================================
220 STDMETHODIMP
ExplorerBar::ShowDW( BOOL inShow
)
222 if( mWindow
.GetSafeHwnd() )
224 mWindow
.ShowWindow( inShow
? SW_SHOW
: SW_HIDE
);
229 //===========================================================================================================================
231 //===========================================================================================================================
233 STDMETHODIMP
ExplorerBar::CloseDW( DWORD inReserved
)
235 DEBUG_UNUSED( inReserved
);
238 if( mWindow
.GetSafeHwnd() )
240 mWindow
.SendMessage( WM_CLOSE
);
245 //===========================================================================================================================
247 //===========================================================================================================================
249 STDMETHODIMP
ExplorerBar::ResizeBorderDW( LPCRECT inBorder
, IUnknown
*inPunkSite
, BOOL inReserved
)
251 DEBUG_UNUSED( inBorder
);
252 DEBUG_UNUSED( inPunkSite
);
253 DEBUG_UNUSED( inReserved
);
260 #pragma mark == IDeskBand implementation ==
263 //===========================================================================================================================
265 //===========================================================================================================================
267 STDMETHODIMP
ExplorerBar::GetBandInfo( DWORD inBandID
, DWORD inViewMode
, DESKBANDINFO
*outInfo
)
271 require_action( outInfo
, exit
, err
= E_INVALIDARG
);
274 mViewMode
= inViewMode
;
276 if( outInfo
->dwMask
& DBIM_MINSIZE
)
278 outInfo
->ptMinSize
.x
= 100;
279 outInfo
->ptMinSize
.y
= 100;
281 if( outInfo
->dwMask
& DBIM_MAXSIZE
)
283 // Unlimited max size.
285 outInfo
->ptMaxSize
.x
= -1;
286 outInfo
->ptMaxSize
.y
= -1;
288 if( outInfo
->dwMask
& DBIM_INTEGRAL
)
290 outInfo
->ptIntegral
.x
= 1;
291 outInfo
->ptIntegral
.y
= 1;
293 if( outInfo
->dwMask
& DBIM_ACTUAL
)
295 outInfo
->ptActual
.x
= 0;
296 outInfo
->ptActual
.y
= 0;
298 if( outInfo
->dwMask
& DBIM_TITLE
)
303 ok
= s
.LoadString( IDS_NAME
);
304 require_action( ok
, exit
, err
= kNoResourcesErr
);
307 lstrcpyn( outInfo
->wszTitle
, s
, sizeof_array( outInfo
->wszTitle
) );
311 nChars
= MultiByteToWideChar( CP_ACP
, 0, s
, -1, outInfo
->wszTitle
, sizeof_array( outInfo
->wszTitle
) );
312 err
= translate_errno( nChars
> 0, (OSStatus
) GetLastError(), kUnknownErr
);
313 require_noerr( err
, exit
);
316 if( outInfo
->dwMask
& DBIM_MODEFLAGS
)
318 outInfo
->dwModeFlags
= DBIMF_NORMAL
| DBIMF_VARIABLEHEIGHT
;
321 // Force the default background color.
323 outInfo
->dwMask
&= ~DBIM_BKCOLOR
;
332 #pragma mark == IInputObject implementation ==
335 //===========================================================================================================================
337 //===========================================================================================================================
339 STDMETHODIMP
ExplorerBar::UIActivateIO( BOOL inActivate
, LPMSG inMsg
)
341 DEBUG_UNUSED( inMsg
);
350 //===========================================================================================================================
352 //===========================================================================================================================
354 STDMETHODIMP
ExplorerBar::HasFocusIO( void )
356 if( mWindow
.GetFocus()->GetSafeHwnd() == mWindow
.GetSafeHwnd() )
363 //===========================================================================================================================
364 // TranslateAcceleratorIO
365 //===========================================================================================================================
367 STDMETHODIMP
ExplorerBar::TranslateAcceleratorIO( LPMSG inMsg
)
369 DEBUG_UNUSED( inMsg
);
376 #pragma mark == IObjectWithSite implementation ==
379 //===========================================================================================================================
381 //===========================================================================================================================
383 STDMETHODIMP
ExplorerBar::SetSite( IUnknown
*inPunkSite
)
385 AFX_MANAGE_STATE( AfxGetStaticModuleState() );
389 // Release the old interfaces.
393 mWebBrowser
->Release();
402 // A non-NULL site means we're setting the site. Otherwise, the site is being released (done above).
410 // Get the parent window.
412 IOleWindow
* oleWindow
;
414 mParentWindow
= NULL
;
415 err
= inPunkSite
->QueryInterface( IID_IOleWindow
, (LPVOID
*) &oleWindow
);
416 require( SUCCEEDED( err
), exit
);
418 err
= oleWindow
->GetWindow( &mParentWindow
);
419 oleWindow
->Release();
420 require_noerr( err
, exit
);
421 require_action( mParentWindow
, exit
, err
= E_FAIL
);
423 // Get the IInputObject interface.
425 err
= inPunkSite
->QueryInterface( IID_IInputObjectSite
, (LPVOID
*) &mSite
);
426 require( SUCCEEDED( err
), exit
);
429 // Get the IWebBrowser2 interface.
431 IOleCommandTarget
* oleCommandTarget
;
433 err
= inPunkSite
->QueryInterface( IID_IOleCommandTarget
, (LPVOID
*) &oleCommandTarget
);
434 require( SUCCEEDED( err
), exit
);
436 IServiceProvider
* serviceProvider
;
438 err
= oleCommandTarget
->QueryInterface( IID_IServiceProvider
, (LPVOID
*) &serviceProvider
);
439 oleCommandTarget
->Release();
440 require( SUCCEEDED( err
), exit
);
442 err
= serviceProvider
->QueryService( SID_SWebBrowserApp
, IID_IWebBrowser2
, (LPVOID
*) &mWebBrowser
);
443 serviceProvider
->Release();
444 require( SUCCEEDED( err
), exit
);
446 // Create the main window.
449 require_noerr( err
, exit
);
455 //===========================================================================================================================
457 //===========================================================================================================================
459 STDMETHODIMP
ExplorerBar::GetSite( REFIID inID
, LPVOID
*outResult
)
464 require_action( mSite
, exit
, err
= E_FAIL
);
466 err
= mSite
->QueryInterface( inID
, outResult
);
474 #pragma mark == IPersistStream implementation ==
478 // IPersistStream implementation
480 // This is only supported to allow the desk band to be dropped on the desktop and to prevent multiple instances of
481 // the desk band from showing up in the context menu. This desk band doesn't actually persist any data.
484 //===========================================================================================================================
486 //===========================================================================================================================
488 STDMETHODIMP
ExplorerBar::GetClassID( LPCLSID outClassID
)
490 *outClassID
= CLSID_ExplorerBar
;
494 //===========================================================================================================================
496 //===========================================================================================================================
498 STDMETHODIMP
ExplorerBar::IsDirty( void )
503 //===========================================================================================================================
505 //===========================================================================================================================
507 STDMETHODIMP
ExplorerBar::Load( LPSTREAM inStream
)
509 DEBUG_UNUSED( inStream
);
514 //===========================================================================================================================
516 //===========================================================================================================================
518 STDMETHODIMP
ExplorerBar::Save( LPSTREAM inStream
, BOOL inClearDirty
)
520 DEBUG_UNUSED( inStream
);
521 DEBUG_UNUSED( inClearDirty
);
526 //===========================================================================================================================
528 //===========================================================================================================================
530 STDMETHODIMP
ExplorerBar::GetSizeMax( ULARGE_INTEGER
*outSizeMax
)
532 DEBUG_UNUSED( outSizeMax
);
538 //===========================================================================================================================
540 //===========================================================================================================================
542 STDMETHODIMP
ExplorerBar::QueryContextMenu(HMENU hShellContextMenu
, UINT iContextMenuFirstItem
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
544 DEBUG_UNUSED( idCmdLast
);
545 DEBUG_UNUSED( uFlags
);
549 menubar
.LoadMenu(IDR_CONTEXT_MENU
);
550 CMenu
* menu
= menubar
.GetSubMenu(0);
554 shellmenu
.Attach(hShellContextMenu
);
556 UINT iShellItem
= iContextMenuFirstItem
; //! remove plus one
557 UINT idShellCmd
= idCmdFirst
;
559 int n
= menu
->GetMenuItemCount();
561 for (int i
=0; i
<n
; ++i
)
566 ZeroMemory(&mii
, sizeof(mii
));
567 mii
.fMask
= MIIM_TYPE
| MIIM_ID
;
568 mii
.fType
= MFT_STRING
;
569 mii
.cbSize
= sizeof(mii
);
570 mii
.cch
= LENGTHOF(sz
);
573 menu
->GetMenuItemInfo(i
, &mii
, TRUE
);
575 mii
.wID
= idShellCmd
++;
577 shellmenu
.InsertMenuItem(iShellItem
++, &mii
, TRUE
);
586 //===========================================================================================================================
588 //===========================================================================================================================
590 // Not called for explorer bars
591 STDMETHODIMP
ExplorerBar::GetCommandString(UINT idCmd
, UINT uType
, UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
593 DEBUG_UNUSED( idCmd
);
594 DEBUG_UNUSED( uType
);
595 DEBUG_UNUSED( pwReserved
);
596 DEBUG_UNUSED( pszName
);
597 DEBUG_UNUSED( cchMax
);
602 //===========================================================================================================================
604 //===========================================================================================================================
606 // The shell sends either strings or indexes
607 // IE never sends strings
608 // The indexes are into an array of my commands
609 // So the verb for the first command I added to the menu is always 0x0000
610 // Here - because I don't have any submenus -
611 // I can treat the 'verb' as an menu item position
612 STDMETHODIMP
ExplorerBar::InvokeCommand(LPCMINVOKECOMMANDINFO lpici
)
614 // IE doesn't send string commands
615 if (HIWORD(lpici
->lpVerb
) != 0) return 0;
626 #pragma mark == Other ==
629 //===========================================================================================================================
631 //===========================================================================================================================
633 OSStatus
ExplorerBar::SetupWindow( void )
641 window
= CWnd::FromHandle( mParentWindow
);
643 window
->GetClientRect( rect
);
645 ok
= s
.LoadString( IDS_NAME
);
646 require_action( ok
, exit
, err
= kNoResourcesErr
);
648 ok
= mWindow
.Create( NULL
, s
, WS_CHILD
| WS_VISIBLE
, rect
, window
, 100 ) != 0;
649 require_action( ok
, exit
, err
= kNoResourcesErr
);
651 mWindow
.SetOwner( this );
658 //===========================================================================================================================
660 //===========================================================================================================================
662 OSStatus
ExplorerBar::GoToURL( const CString
&inURL
)
668 s
= inURL
.AllocSysString();
669 require_action( s
, exit
, err
= kNoMemoryErr
);
671 VariantInit( &empty
);
672 err
= mWebBrowser
->Navigate( s
, &empty
, &empty
, &empty
, &empty
);
674 require_noerr( err
, exit
);