]> git.saurik.com Git - apple/mdnsresponder.git/blobdiff - Clients/ExplorerPlugin/ExplorerBarWindow.cpp
mDNSResponder-214.3.2.tar.gz
[apple/mdnsresponder.git] / Clients / ExplorerPlugin / ExplorerBarWindow.cpp
index beb0b35bf7831c5ae44e328fe44e389ca2013f3f..7b5b2ea401070dbae06902e4c46bb727fe993747 100644 (file)
@@ -1,28 +1,58 @@
-/*
+/* -*- Mode: C; tab-width: 4 -*-
+ *
  * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
  *
  * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  * 
  * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ *     http://www.apache.org/licenses/LICENSE-2.0
  * 
  * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
 
     Change History (most recent first):
     
 $Log: ExplorerBarWindow.cpp,v $
 
     Change History (most recent first):
     
 $Log: ExplorerBarWindow.cpp,v $
+Revision 1.23  2009/03/30 18:47:40  herscher
+<rdar://problem/5925472> Current Bonjour code does not compile on Windows
+<rdar://problem/5187308> Move build train to Visual Studio 2005
+
+Revision 1.22  2006/08/14 23:24:00  cheshire
+Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
+
+Revision 1.21  2005/04/06 01:13:07  shersche
+<rdar://problem/4066195> Use the product icon instead of globe icon for 'About' link.
+
+Revision 1.20  2005/03/18 02:43:02  shersche
+<rdar://problem/4046443> Use standard IE website icon for 'About Bonjour', only using globe icon if standard icon cannot be loaded
+
+Revision 1.19  2005/03/16 03:46:27  shersche
+<rdar://problem/4045657> Use Bonjour icon for all discovered sites
+
+Revision 1.18  2005/02/26 01:24:05  shersche
+Remove display lines in tree control
+
+Revision 1.17  2005/02/25 19:57:30  shersche
+<rdar://problem/4023323> Remove FTP browsing from plugin
+
+Revision 1.16  2005/02/08 23:31:06  shersche
+Move "About ..." item underneath WebSites, change icons for discovered sites and "About ..." item
+
+Revision 1.15  2005/01/27 22:38:27  shersche
+add About item to tree list
+
+Revision 1.14  2005/01/25 17:55:39  shersche
+<rdar://problem/3911084> Get bitmaps from non-localizable resource module
+Bug #: 3911084
+
+Revision 1.13  2005/01/06 21:13:09  shersche
+<rdar://problem/3796779> Handle kDNSServiceErr_Firewall return codes
+Bug #: 3796779
+
 Revision 1.12  2004/10/26 00:56:03  cheshire
 Use "#if 0" instead of commenting out code
 
 Revision 1.12  2004/10/26 00:56:03  cheshire
 Use "#if 0" instead of commenting out code
 
@@ -93,6 +123,7 @@ Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within
 #include       "Resource.h"
 
 #include       "ExplorerBarWindow.h"
 #include       "Resource.h"
 
 #include       "ExplorerBarWindow.h"
+#include       "ExplorerPlugin.h"
 
 // MFC Debugging
 
 
 // MFC Debugging
 
@@ -122,6 +153,11 @@ static char THIS_FILE[] = __FILE__;
 
 #define        kTXTRecordKeyPath                               "path"
 
 
 #define        kTXTRecordKeyPath                               "path"
 
+// IE Icon resource
+
+#define kIEIconResource                                        32529
+
+
 #if 0
 #pragma mark == Prototypes ==
 #endif
 #if 0
 #pragma mark == Prototypes ==
 #endif
@@ -183,6 +219,7 @@ int ExplorerBarWindow::OnCreate( LPCREATESTRUCT inCreateStruct )
 {
        AFX_MANAGE_STATE( AfxGetStaticModuleState() );
        
 {
        AFX_MANAGE_STATE( AfxGetStaticModuleState() );
        
+       HINSTANCE               module = NULL;
        OSStatus                err;
        CRect                   rect;
        CBitmap                 bitmap;
        OSStatus                err;
        CRect                   rect;
        CBitmap                 bitmap;
@@ -192,10 +229,9 @@ int        ExplorerBarWindow::OnCreate( LPCREATESTRUCT inCreateStruct )
        require_noerr( err, exit );
        
        GetClientRect( rect );
        require_noerr( err, exit );
        
        GetClientRect( rect );
-       mTree.Create( WS_TABSTOP | WS_VISIBLE | WS_CHILD | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES | TVS_NOHSCROLL , rect, this, 
+       mTree.Create( WS_TABSTOP | WS_VISIBLE | WS_CHILD | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_NOHSCROLL , rect, this, 
                IDC_EXPLORER_TREE );
        
                IDC_EXPLORER_TREE );
        
-       
        ServiceHandlerEntry *           e;
        
        // Web Site Handler
        ServiceHandlerEntry *           e;
        
        // Web Site Handler
@@ -205,63 +241,52 @@ int       ExplorerBarWindow::OnCreate( LPCREATESTRUCT inCreateStruct )
        e->type                         = "_http._tcp";
        e->urlScheme            = "http://";
        e->ref                          = NULL;
        e->type                         = "_http._tcp";
        e->urlScheme            = "http://";
        e->ref                          = NULL;
-       e->treeItem                     = NULL;
-       e->treeFirst            = true;
        e->obj                          = this;
        e->needsLogin           = false;
        mServiceHandlers.Add( e );
        e->obj                          = this;
        e->needsLogin           = false;
        mServiceHandlers.Add( e );
-       
-       s.LoadString( IDS_WEB_SITES );
-       e->treeItem = mTree.InsertItem( s, 0, 0 );
-       mTree.Expand( e->treeItem, TVE_EXPAND );
-       
-       err = DNSServiceBrowse( &e->ref, 0, 0, e->type, NULL, BrowseCallBack, e );
-       require_noerr( err, exit );
 
 
-       err = WSAAsyncSelect((SOCKET) DNSServiceRefSockFD(e->ref), m_hWnd, WM_PRIVATE_SERVICE_EVENT, FD_READ|FD_CLOSE);
-       require_noerr( err, exit );
+       s.LoadString( IDS_ABOUT );
+       m_about = mTree.InsertItem( s, 0, 0 );
 
 
-       m_serviceRefs.push_back(e->ref); 
-
-       // FTP Site Handler
-       
-       e = new ServiceHandlerEntry;
-       check( e );
-       e->type                         = "_ftp._tcp";
-       e->urlScheme            = "ftp://";
-       e->ref                          = NULL;
-       e->treeItem                     = NULL;
-       e->treeFirst            = true;
-       e->obj                          = this;
-       e->needsLogin           = true;
-       mServiceHandlers.Add( e );
-       
-       s.LoadString( IDS_FTP_SITES );
-       e->treeItem = mTree.InsertItem( s, 0, 0 );
-       mTree.Expand( e->treeItem, TVE_EXPAND );
-       
        err = DNSServiceBrowse( &e->ref, 0, 0, e->type, NULL, BrowseCallBack, e );
        require_noerr( err, exit );
 
        err = WSAAsyncSelect((SOCKET) DNSServiceRefSockFD(e->ref), m_hWnd, WM_PRIVATE_SERVICE_EVENT, FD_READ|FD_CLOSE);
        require_noerr( err, exit );
 
        err = DNSServiceBrowse( &e->ref, 0, 0, e->type, NULL, BrowseCallBack, e );
        require_noerr( err, exit );
 
        err = WSAAsyncSelect((SOCKET) DNSServiceRefSockFD(e->ref), m_hWnd, WM_PRIVATE_SERVICE_EVENT, FD_READ|FD_CLOSE);
        require_noerr( err, exit );
 
-       m_serviceRefs.push_back(e->ref); 
+       m_serviceRefs.push_back(e->ref);
 
 
-       m_imageList.Create(16, 16, ILC_COLORDDB, 1, 0);
-       bitmap.LoadBitmap(IDB_LOGO);
-       m_imageList.Add(&bitmap, (CBitmap*) NULL);
+       m_imageList.Create( 16, 16, ILC_MASK | ILC_COLOR16, 2, 0);
+
+       bitmap.Attach( ::LoadBitmap( GetNonLocalizedResources(), MAKEINTRESOURCE( IDB_LOGO ) ) );
+       m_imageList.Add( &bitmap, (CBitmap*) NULL );
+       bitmap.Detach();
 
        mTree.SetImageList(&m_imageList, TVSIL_NORMAL);
        
 exit:
 
 
        mTree.SetImageList(&m_imageList, TVSIL_NORMAL);
        
 exit:
 
+       if ( module )
+       {
+               FreeLibrary( module );
+               module = NULL;
+       }
+
        // Cannot talk to the mDNSResponder service. Show the error message and exit (with kNoErr so they can see it).
        // Cannot talk to the mDNSResponder service. Show the error message and exit (with kNoErr so they can see it).
-       if ( err != kNoErr )
+       if ( err )
        {
        {
-               s.LoadString( IDS_MDNSRESPONDER_NOT_AVAILABLE );
+               if ( err == kDNSServiceErr_Firewall )
+               {
+                       s.LoadString( IDS_FIREWALL );
+               }
+               else
+               {
+                       s.LoadString( IDS_MDNSRESPONDER_NOT_AVAILABLE );
+               }
+               
                mTree.DeleteAllItems();
                mTree.InsertItem( s, 0, 0, TVI_ROOT, TVI_LAST );
                mTree.DeleteAllItems();
                mTree.InsertItem( s, 0, 0, TVI_ROOT, TVI_LAST );
+               
                err = kNoErr;
        }
 
                err = kNoErr;
        }
 
@@ -331,11 +356,25 @@ void      ExplorerBarWindow::OnDoubleClick( NMHDR *inNMHDR, LRESULT *outResult )
        item = mTree.GetSelectedItem();
        require( item, exit );
        
        item = mTree.GetSelectedItem();
        require( item, exit );
        
-       service = reinterpret_cast < ServiceInfo * > ( mTree.GetItemData( item ) );
-       require_quiet( service, exit );
+       // Tell Internet Explorer to go to the URL if it's about item
        
        
-       err = StartResolve( service );
-       require_noerr( err, exit );
+       if ( item == m_about )
+       {
+               CString url;
+
+               check( mOwner );
+
+               url.LoadString( IDS_ABOUT_URL );
+               mOwner->GoToURL( url );
+       }
+       else
+       {
+               service = reinterpret_cast < ServiceInfo * > ( mTree.GetItemData( item ) );
+               require_quiet( service, exit );
+               
+               err = StartResolve( service );
+               require_noerr( err, exit );
+       }
 
 exit:
        *outResult = 0;
 
 exit:
        *outResult = 0;
@@ -346,7 +385,7 @@ exit:
 //     OnServiceEvent
 //===========================================================================================================================
 
 //     OnServiceEvent
 //===========================================================================================================================
 
-LONG
+LRESULT
 ExplorerBarWindow::OnServiceEvent(WPARAM inWParam, LPARAM inLParam)
 {
        if (WSAGETSELECTERROR(inLParam) && !(HIWORD(inLParam)))
 ExplorerBarWindow::OnServiceEvent(WPARAM inWParam, LPARAM inLParam)
 {
        if (WSAGETSELECTERROR(inLParam) && !(HIWORD(inLParam)))
@@ -437,13 +476,13 @@ void DNSSD_API
                err = UTF8StringToStringObject( inName, service->displayName );
                check_noerr( err );
 
                err = UTF8StringToStringObject( inName, service->displayName );
                check_noerr( err );
 
-               service->name = strdup( inName );
+               service->name = _strdup( inName );
                require_action( service->name, exit, err = kNoMemoryErr );
                
                require_action( service->name, exit, err = kNoMemoryErr );
                
-               service->type = strdup( inType );
+               service->type = _strdup( inType );
                require_action( service->type, exit, err = kNoMemoryErr );
                
                require_action( service->type, exit, err = kNoMemoryErr );
                
-               service->domain = strdup( inDomain );
+               service->domain = _strdup( inDomain );
                require_action( service->domain, exit, err = kNoMemoryErr );
                
                service->ifi            = inInterfaceIndex;
                require_action( service->domain, exit, err = kNoMemoryErr );
                
                service->ifi            = inInterfaceIndex;
@@ -510,18 +549,10 @@ LONG      ExplorerBarWindow::OnServiceAdd( ServiceInfo * service )
                
                // Insert the new item in sorted order.
                
                
                // Insert the new item in sorted order.
                
-               afterItem = ( index > 0 ) ? handler->array[ index - 1 ]->item : TVI_FIRST;
+               afterItem = ( index > 0 ) ? handler->array[ index - 1 ]->item : m_about;
                handler->array.InsertAt( index, service );
                handler->array.InsertAt( index, service );
-               service->item = mTree.InsertItem( service->displayName, handler->treeItem, afterItem );
+               service->item = mTree.InsertItem( service->displayName, 0, 0, NULL, afterItem );
                mTree.SetItemData( service->item, (DWORD_PTR) service );
                mTree.SetItemData( service->item, (DWORD_PTR) service );
-               
-               // Make sure the item is visible if this is the first time a service was added.
-       
-               if( handler->treeFirst )
-               {
-                       handler->treeFirst = false;
-                       mTree.EnsureVisible( service->item );
-               }
        }
        return( 0 );
 }
        }
        return( 0 );
 }