2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 Change History (most recent first):
27 $Log: BrowserDialog.cpp,v $
28 Revision 1.1 2003/08/21 02:16:10 bradley
29 Rendezvous Browser for HTTP services for Windows CE/PocketPC.
35 #include "Application.h"
37 #include "DNSServices.h"
39 #include "BrowserDialog.h"
44 static char THIS_FILE
[] = __FILE__
;
47 //===========================================================================================================================
49 //===========================================================================================================================
51 BEGIN_MESSAGE_MAP(BrowserDialog
, CDialog
)
52 //{{AFX_MSG_MAP(BrowserDialog)
56 static DWORD
UTF8StringToStringObject( const char *inUTF8
, CString
&inObject
);
58 //===========================================================================================================================
60 //===========================================================================================================================
62 BrowserDialog::BrowserDialog( CWnd
*inParent
)
63 : CDialog( BrowserDialog::IDD
, inParent
)
65 //{{AFX_DATA_INIT(BrowserDialog)
66 // NOTE: the ClassWizard will add member initialization here
69 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32.
71 mIcon
= AfxGetApp()->LoadIcon( IDR_MAINFRAME
);
74 //===========================================================================================================================
76 //===========================================================================================================================
78 void BrowserDialog::DoDataExchange( CDataExchange
*pDX
)
80 CDialog::DoDataExchange(pDX
);
81 //{{AFX_DATA_MAP(BrowserDialog)
82 DDX_Control(pDX
, IDC_BROWSE_LIST
, mBrowserList
);
86 //===========================================================================================================================
88 //===========================================================================================================================
90 BOOL
BrowserDialog::OnInitDialog()
94 CDialog::OnInitDialog();
96 // Set the icon for this dialog. The framework does this automatically when the application's main window is not a dialog.
98 SetIcon( mIcon
, TRUE
); // Set big icon
99 SetIcon( mIcon
, FALSE
); // Set small icon
101 CenterWindow( GetDesktopWindow() );
107 s
.LoadString( IDS_BROWSER_LIST_COLUMN_NAME
);
108 mBrowserList
.GetWindowRect( rect
);
109 mBrowserList
.InsertColumn( 0, s
, LVCFMT_LEFT
, rect
.Width() - 8 );
111 // Start browsing for services.
115 err
= DNSBrowserCreate( 0, BrowserCallBack
, this, &mBrowser
);
118 AfxMessageBox( IDP_SOCKETS_INIT_FAILED
);
122 err
= DNSBrowserStartServiceSearch( mBrowser
, 0, "_http._tcp", NULL
);
125 AfxMessageBox( IDP_SOCKETS_INIT_FAILED
);
133 //===========================================================================================================================
134 // BrowserCallBack [static]
135 //===========================================================================================================================
138 BrowserDialog::BrowserCallBack(
141 DNSStatus inStatusCode
,
142 const DNSBrowserEvent
* inEvent
)
144 BrowserDialog
* dialog
;
146 DNS_UNUSED( inStatusCode
);
147 dialog
= reinterpret_cast < BrowserDialog
* > ( inContext
);
149 switch( inEvent
->type
)
151 case kDNSBrowserEventTypeAddService
:
152 dialog
->BrowserAddService( inEvent
->data
.addService
.name
);
155 case kDNSBrowserEventTypeRemoveService
:
156 dialog
->BrowserRemoveService( inEvent
->data
.removeService
.name
);
164 //===========================================================================================================================
166 //===========================================================================================================================
168 void BrowserDialog::BrowserAddService( const char *inName
)
170 BrowserEntry newEntry
;
174 UTF8StringToStringObject( inName
, newEntry
.name
);
176 n
= mBrowserEntries
.GetSize();
177 for( i
= 0; i
< n
; ++i
)
179 BrowserEntry
& entry
= mBrowserEntries
.ElementAt( i
);
181 if( entry
.name
.CompareNoCase( newEntry
.name
) == 0 )
188 mBrowserEntries
.Add( newEntry
);
189 mBrowserList
.InsertItem( i
, newEntry
.name
);
193 //===========================================================================================================================
194 // BrowserRemoveService
195 //===========================================================================================================================
197 void BrowserDialog::BrowserRemoveService( const char *inName
)
199 BrowserEntry newEntry
;
203 UTF8StringToStringObject( inName
, newEntry
.name
);
205 n
= mBrowserEntries
.GetSize();
206 for( i
= 0; i
< n
; ++i
)
208 BrowserEntry
& entry
= mBrowserEntries
.ElementAt( i
);
210 if( entry
.name
.CompareNoCase( newEntry
.name
) == 0 )
217 mBrowserEntries
.RemoveAt( i
);
218 mBrowserList
.DeleteItem( i
);
226 //===========================================================================================================================
227 // UTF8StringToStringObject
228 //===========================================================================================================================
230 static DWORD
UTF8StringToStringObject( const char *inUTF8
, CString
&inObject
)
238 n
= MultiByteToWideChar( CP_UTF8
, 0, inUTF8
, -1, NULL
, 0 );
241 unicode
= (wchar_t *) malloc( (size_t)( n
* sizeof( wchar_t ) ) );
242 if( !unicode
) { err
= ERROR_INSUFFICIENT_BUFFER
; goto exit
; };
244 n
= MultiByteToWideChar( CP_UTF8
, 0, inUTF8
, -1, unicode
, n
);