2 * Copyright (c) 2002-2003 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: BrowserDialog.cpp,v $
26 Revision 1.1 2003/08/21 02:16:10 bradley
27 Rendezvous Browser for HTTP services for Windows CE/PocketPC.
33 #include "Application.h"
35 #include "DNSServices.h"
37 #include "BrowserDialog.h"
42 static char THIS_FILE
[] = __FILE__
;
45 //===========================================================================================================================
47 //===========================================================================================================================
49 BEGIN_MESSAGE_MAP(BrowserDialog
, CDialog
)
50 //{{AFX_MSG_MAP(BrowserDialog)
54 static DWORD
UTF8StringToStringObject( const char *inUTF8
, CString
&inObject
);
56 //===========================================================================================================================
58 //===========================================================================================================================
60 BrowserDialog::BrowserDialog( CWnd
*inParent
)
61 : CDialog( BrowserDialog::IDD
, inParent
)
63 //{{AFX_DATA_INIT(BrowserDialog)
64 // NOTE: the ClassWizard will add member initialization here
67 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32.
69 mIcon
= AfxGetApp()->LoadIcon( IDR_MAINFRAME
);
72 //===========================================================================================================================
74 //===========================================================================================================================
76 void BrowserDialog::DoDataExchange( CDataExchange
*pDX
)
78 CDialog::DoDataExchange(pDX
);
79 //{{AFX_DATA_MAP(BrowserDialog)
80 DDX_Control(pDX
, IDC_BROWSE_LIST
, mBrowserList
);
84 //===========================================================================================================================
86 //===========================================================================================================================
88 BOOL
BrowserDialog::OnInitDialog()
92 CDialog::OnInitDialog();
94 // Set the icon for this dialog. The framework does this automatically when the application's main window is not a dialog.
96 SetIcon( mIcon
, TRUE
); // Set big icon
97 SetIcon( mIcon
, FALSE
); // Set small icon
99 CenterWindow( GetDesktopWindow() );
105 s
.LoadString( IDS_BROWSER_LIST_COLUMN_NAME
);
106 mBrowserList
.GetWindowRect( rect
);
107 mBrowserList
.InsertColumn( 0, s
, LVCFMT_LEFT
, rect
.Width() - 8 );
109 // Start browsing for services.
113 err
= DNSBrowserCreate( 0, BrowserCallBack
, this, &mBrowser
);
116 AfxMessageBox( IDP_SOCKETS_INIT_FAILED
);
120 err
= DNSBrowserStartServiceSearch( mBrowser
, 0, "_http._tcp", NULL
);
123 AfxMessageBox( IDP_SOCKETS_INIT_FAILED
);
131 //===========================================================================================================================
132 // BrowserCallBack [static]
133 //===========================================================================================================================
136 BrowserDialog::BrowserCallBack(
139 DNSStatus inStatusCode
,
140 const DNSBrowserEvent
* inEvent
)
142 BrowserDialog
* dialog
;
144 DNS_UNUSED( inStatusCode
);
145 dialog
= reinterpret_cast < BrowserDialog
* > ( inContext
);
147 switch( inEvent
->type
)
149 case kDNSBrowserEventTypeAddService
:
150 dialog
->BrowserAddService( inEvent
->data
.addService
.name
);
153 case kDNSBrowserEventTypeRemoveService
:
154 dialog
->BrowserRemoveService( inEvent
->data
.removeService
.name
);
162 //===========================================================================================================================
164 //===========================================================================================================================
166 void BrowserDialog::BrowserAddService( const char *inName
)
168 BrowserEntry newEntry
;
172 UTF8StringToStringObject( inName
, newEntry
.name
);
174 n
= mBrowserEntries
.GetSize();
175 for( i
= 0; i
< n
; ++i
)
177 BrowserEntry
& entry
= mBrowserEntries
.ElementAt( i
);
179 if( entry
.name
.CompareNoCase( newEntry
.name
) == 0 )
186 mBrowserEntries
.Add( newEntry
);
187 mBrowserList
.InsertItem( i
, newEntry
.name
);
191 //===========================================================================================================================
192 // BrowserRemoveService
193 //===========================================================================================================================
195 void BrowserDialog::BrowserRemoveService( const char *inName
)
197 BrowserEntry newEntry
;
201 UTF8StringToStringObject( inName
, newEntry
.name
);
203 n
= mBrowserEntries
.GetSize();
204 for( i
= 0; i
< n
; ++i
)
206 BrowserEntry
& entry
= mBrowserEntries
.ElementAt( i
);
208 if( entry
.name
.CompareNoCase( newEntry
.name
) == 0 )
215 mBrowserEntries
.RemoveAt( i
);
216 mBrowserList
.DeleteItem( i
);
224 //===========================================================================================================================
225 // UTF8StringToStringObject
226 //===========================================================================================================================
228 static DWORD
UTF8StringToStringObject( const char *inUTF8
, CString
&inObject
)
236 n
= MultiByteToWideChar( CP_UTF8
, 0, inUTF8
, -1, NULL
, 0 );
239 unicode
= (wchar_t *) malloc( (size_t)( n
* sizeof( wchar_t ) ) );
240 if( !unicode
) { err
= ERROR_INSUFFICIENT_BUFFER
; goto exit
; };
242 n
= MultiByteToWideChar( CP_UTF8
, 0, inUTF8
, -1, unicode
, n
);