2005-07-23 17:31:21 +02:00
|
|
|
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2006-01-08 02:25:02 +01:00
|
|
|
* Copyright 2005 by Eric House (xwords@eehouse.org). All rights reserved.
|
2005-07-23 17:31:21 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
#include "cecondlg.h"
|
|
|
|
#include "ceutil.h"
|
2006-01-28 20:03:10 +01:00
|
|
|
#include "debhacks.h"
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
static void
|
2008-12-20 05:25:41 +01:00
|
|
|
ceControlsToAddrRec( HWND hDlg, CeConnDlgState* state )
|
2005-07-23 17:31:21 +02:00
|
|
|
{
|
|
|
|
XP_U16 len;
|
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
if ( state->addrRec.conType == COMMS_CONN_RELAY ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2008-12-20 05:25:41 +01:00
|
|
|
len = sizeof(state->addrRec.u.ip_relay.hostName);
|
2006-10-28 16:56:04 +02:00
|
|
|
ceGetDlgItemText( hDlg, RELAYNAME_EDIT,
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.u.ip_relay.hostName, &len );
|
|
|
|
state->addrRec.u.ip_relay.port =
|
2006-10-28 16:56:04 +02:00
|
|
|
(XP_U16)ceGetDlgItemNum( hDlg, RELAYPORT_EDIT );
|
2008-12-20 05:25:41 +01:00
|
|
|
len = sizeof(state->addrRec.u.ip_relay.cookie);
|
|
|
|
ceGetDlgItemText( hDlg, COOKIE_EDIT, state->addrRec.u.ip_relay.cookie,
|
2006-10-28 16:56:04 +02:00
|
|
|
&len );
|
|
|
|
#endif
|
2008-12-20 05:25:41 +01:00
|
|
|
} else if ( state->addrRec.conType == COMMS_CONN_BT ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2008-12-20 05:25:41 +01:00
|
|
|
if ( state->role == SERVER_ISCLIENT ) {
|
|
|
|
len = sizeof(state->addrRec.u.bt.hostName);
|
2006-10-28 16:56:04 +02:00
|
|
|
ceGetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.u.bt.hostName, &len );
|
2006-10-28 16:56:04 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
} /* ceControlsToAddrRec */
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
static void
|
2008-12-20 05:25:41 +01:00
|
|
|
adjustForConnType( HWND hDlg, const CeConnDlgState* state )
|
2005-07-23 17:31:21 +02:00
|
|
|
{
|
2006-10-28 16:56:04 +02:00
|
|
|
XP_U16 relayIds[] = {
|
|
|
|
IDC_COOKIE_LAB,
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
COOKIE_EDIT,IDC_CRELAYHINT_LAB,IDC_CRELAYNAME_LAB,RELAYNAME_EDIT,
|
|
|
|
IDC_CRELAYPORT_LAB, RELAYPORT_EDIT,
|
|
|
|
#endif
|
|
|
|
0 };
|
|
|
|
XP_U16 btIds[] = {
|
|
|
|
IDC_BLUET_ADDR_LAB,
|
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
|
|
|
IDC_BLUET_ADDR_EDIT, IDC_BLUET_ADDR_BROWSE,
|
|
|
|
#endif
|
|
|
|
0 };
|
|
|
|
XP_U16* allIDs[] = { relayIds, btIds };
|
|
|
|
XP_U16* on = NULL;
|
2006-09-15 09:39:57 +02:00
|
|
|
XP_U16 i;
|
2006-10-28 16:56:04 +02:00
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
if ( state->addrRec.conType == COMMS_CONN_RELAY ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
on = relayIds;
|
2008-12-20 05:25:41 +01:00
|
|
|
} else if ( state->addrRec.conType == COMMS_CONN_BT ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
on =
|
2006-09-15 09:39:57 +02:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2008-12-20 05:25:41 +01:00
|
|
|
state->role != SERVER_ISCLIENT ? NULL:
|
2006-09-15 09:39:57 +02:00
|
|
|
#endif
|
2006-10-28 16:56:04 +02:00
|
|
|
btIds; /* we want the "disabled" message */
|
|
|
|
}
|
|
|
|
|
2007-05-26 16:03:07 +02:00
|
|
|
for ( i = 0; i < VSIZE(allIDs); ++i ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
XP_U16* ids = allIDs[i];
|
|
|
|
XP_Bool enable = ids == on;
|
|
|
|
while ( *ids != 0 ) {
|
|
|
|
ceShowOrHide( hDlg, *(ids++), enable );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* adjustForConnType */
|
|
|
|
|
|
|
|
static XP_U16
|
|
|
|
conTypeToIndex( CommsConnType conType )
|
|
|
|
{
|
|
|
|
XP_U16 index = 0;
|
|
|
|
switch( conType ) {
|
|
|
|
case COMMS_CONN_RELAY:
|
|
|
|
index = 1;
|
|
|
|
break;
|
|
|
|
case COMMS_CONN_BT:
|
|
|
|
index = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CommsConnType
|
|
|
|
indexToConType( XP_U16 index )
|
|
|
|
{
|
2007-12-14 14:06:44 +01:00
|
|
|
CommsConnType conType = COMMS_CONN_NONE;
|
2006-10-28 16:56:04 +02:00
|
|
|
switch( index ) {
|
|
|
|
case 0:
|
|
|
|
conType = COMMS_CONN_BT; break;
|
|
|
|
case 1:
|
|
|
|
conType = COMMS_CONN_RELAY; break;
|
|
|
|
default:
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
return conType;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-20 05:25:41 +01:00
|
|
|
ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* state )
|
2006-10-28 16:56:04 +02:00
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
wchar_t* strs[] = {
|
|
|
|
L"Bluetooth"
|
|
|
|
, L"WiFi/Cellular data"
|
2006-09-15 09:39:57 +02:00
|
|
|
};
|
2005-07-23 17:31:21 +02:00
|
|
|
|
2007-05-26 16:03:07 +02:00
|
|
|
for ( i = 0; i < VSIZE(strs); ++i ) {
|
2006-09-15 09:39:57 +02:00
|
|
|
SendDlgItemMessage( hDlg, IDC_CONNECTCOMBO, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)strs[i] );
|
2005-07-23 17:31:21 +02:00
|
|
|
}
|
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
SendDlgItemMessage( hDlg, IDC_CONNECTCOMBO, CB_SETCURSEL,
|
2008-12-20 05:25:41 +01:00
|
|
|
conTypeToIndex(state->addrRec.conType), 0L );
|
2006-10-28 16:56:04 +02:00
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
if ( state->addrRec.conType == COMMS_CONN_RELAY ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
ceSetDlgItemText( hDlg, RELAYNAME_EDIT,
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.u.ip_relay.hostName );
|
2006-10-28 16:56:04 +02:00
|
|
|
ceSetDlgItemNum( hDlg, RELAYPORT_EDIT,
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.u.ip_relay.port );
|
2006-10-28 16:56:04 +02:00
|
|
|
ceSetDlgItemText( hDlg, COOKIE_EDIT,
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.u.ip_relay.cookie );
|
2006-10-28 16:56:04 +02:00
|
|
|
#endif
|
2008-12-20 05:25:41 +01:00
|
|
|
} else if ( state->addrRec.conType == COMMS_CONN_BT ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2008-12-20 05:25:41 +01:00
|
|
|
if ( state->role == SERVER_ISCLIENT ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
ceSetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.u.bt.hostName );
|
2006-10-28 16:56:04 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
2005-07-23 17:31:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK
|
|
|
|
ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
LRESULT result = FALSE;
|
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
CeConnDlgState* state;
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
2008-09-27 17:05:26 +02:00
|
|
|
SetWindowLongPtr( hDlg, GWL_USERDATA, lParam );
|
2008-12-20 05:25:41 +01:00
|
|
|
state = (CeConnDlgState*)lParam;
|
2005-07-23 17:31:21 +02:00
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
adjustForConnType( hDlg, state );
|
2006-10-28 16:56:04 +02:00
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
ceControlsFromAddrRec( hDlg, state );
|
2006-05-25 05:41:32 +02:00
|
|
|
|
2008-12-20 05:25:41 +01:00
|
|
|
ceDlgSetup( &state->dlgState, hDlg, DLG_STATE_NONE );
|
2006-05-25 05:41:32 +02:00
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
result = TRUE;
|
|
|
|
} else {
|
2008-12-20 05:25:41 +01:00
|
|
|
state = (CeConnDlgState*)GetWindowLongPtr( hDlg, GWL_USERDATA );
|
|
|
|
if ( !!state ) {
|
|
|
|
CEAppGlobals* globals = state->dlgHdr.globals;
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
if ( message == WM_COMMAND ) {
|
|
|
|
XP_U16 id = LOWORD(wParam);
|
|
|
|
|
|
|
|
switch( id ) {
|
2006-10-28 16:56:04 +02:00
|
|
|
|
|
|
|
case IDC_CONNECTCOMBO:
|
|
|
|
if ( HIWORD(wParam) == CBN_SELCHANGE ) {
|
|
|
|
XP_S16 sel;
|
|
|
|
sel = SendDlgItemMessage( hDlg, IDC_CONNECTCOMBO,
|
|
|
|
CB_GETCURSEL, 0, 0L );
|
2008-12-20 05:25:41 +01:00
|
|
|
state->addrRec.conType = indexToConType( sel );
|
|
|
|
adjustForConnType( hDlg, state );
|
2006-10-28 16:56:04 +02:00
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
case IDOK:
|
2008-12-20 05:25:41 +01:00
|
|
|
ceControlsToAddrRec( hDlg, state );
|
2005-07-23 17:31:21 +02:00
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, id);
|
2008-12-20 05:25:41 +01:00
|
|
|
state->userCancelled = id == IDCANCEL;
|
2005-07-23 17:31:21 +02:00
|
|
|
result = TRUE;
|
|
|
|
}
|
2008-03-24 13:41:12 +01:00
|
|
|
} else if ( message == WM_VSCROLL ) {
|
|
|
|
if ( !IS_SMARTPHONE(globals) ) {
|
2008-03-31 02:23:07 +02:00
|
|
|
ceDoDlgScroll( hDlg, wParam );
|
2008-03-24 13:41:12 +01:00
|
|
|
}
|
2005-07-23 17:31:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* ConnsDlg */
|
|
|
|
|
|
|
|
XP_Bool
|
|
|
|
WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, const CommsAddrRec* addrRec,
|
2007-02-02 09:34:37 +01:00
|
|
|
DeviceRole role, CeConnDlgState* state )
|
2005-07-23 17:31:21 +02:00
|
|
|
{
|
|
|
|
XP_Bool result;
|
|
|
|
XP_MEMSET( state, 0, sizeof( *state ) );
|
|
|
|
|
|
|
|
state->globals = globals;
|
2006-10-28 16:56:04 +02:00
|
|
|
state->role = role;
|
2005-07-23 17:31:21 +02:00
|
|
|
XP_MEMCPY( &state->addrRec, addrRec, sizeof(state->addrRec) );
|
|
|
|
|
2006-03-20 05:13:40 +01:00
|
|
|
DialogBoxParam( globals->hInst, (LPCTSTR)IDD_CONNSSDLG, hDlg,
|
2006-10-28 16:56:04 +02:00
|
|
|
(DLGPROC)ConnsDlg, (long)state );
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
result = !state->userCancelled;
|
|
|
|
return result;
|
|
|
|
} /* WrapConnsDlg */
|
|
|
|
|
|
|
|
#endif
|