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
|
|
|
|
ceControlsToAddrRec( HWND hDlg, CeConnDlgState* cState )
|
|
|
|
{
|
|
|
|
XP_U16 len;
|
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
if ( cState->addrRec.conType == COMMS_CONN_RELAY ) {
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
len = sizeof(cState->addrRec.u.ip_relay.hostName);
|
|
|
|
ceGetDlgItemText( hDlg, RELAYNAME_EDIT,
|
|
|
|
cState->addrRec.u.ip_relay.hostName, &len );
|
|
|
|
cState->addrRec.u.ip_relay.port =
|
|
|
|
(XP_U16)ceGetDlgItemNum( hDlg, RELAYPORT_EDIT );
|
|
|
|
len = sizeof(cState->addrRec.u.ip_relay.cookie);
|
|
|
|
ceGetDlgItemText( hDlg, COOKIE_EDIT, cState->addrRec.u.ip_relay.cookie,
|
|
|
|
&len );
|
|
|
|
#endif
|
|
|
|
} else if ( cState->addrRec.conType == COMMS_CONN_BT ) {
|
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
|
|
|
if ( cState->role == SERVER_ISCLIENT ) {
|
|
|
|
len = sizeof(cState->addrRec.u.bt.hostName);
|
|
|
|
ceGetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
|
|
|
|
cState->addrRec.u.bt.hostName, &len );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
} /* ceControlsToAddrRec */
|
2005-07-23 17:31:21 +02:00
|
|
|
|
|
|
|
static void
|
2006-10-28 16:56:04 +02:00
|
|
|
adjustForConnType( HWND hDlg, const CeConnDlgState* cState )
|
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
|
|
|
|
|
|
|
if ( cState->addrRec.conType == COMMS_CONN_RELAY ) {
|
|
|
|
on = relayIds;
|
|
|
|
} else if ( cState->addrRec.conType == COMMS_CONN_BT ) {
|
|
|
|
on =
|
2006-09-15 09:39:57 +02:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2006-10-28 16:56:04 +02:00
|
|
|
cState->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
|
|
|
|
ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* cState )
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
conTypeToIndex(cState->addrRec.conType), 0L );
|
|
|
|
|
|
|
|
if ( cState->addrRec.conType == COMMS_CONN_RELAY ) {
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
ceSetDlgItemText( hDlg, RELAYNAME_EDIT,
|
|
|
|
cState->addrRec.u.ip_relay.hostName );
|
|
|
|
ceSetDlgItemNum( hDlg, RELAYPORT_EDIT,
|
|
|
|
cState->addrRec.u.ip_relay.port );
|
|
|
|
ceSetDlgItemText( hDlg, COOKIE_EDIT,
|
|
|
|
cState->addrRec.u.ip_relay.cookie );
|
|
|
|
#endif
|
|
|
|
} else if ( cState->addrRec.conType == COMMS_CONN_BT ) {
|
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
|
|
|
if ( cState->role == SERVER_ISCLIENT ) {
|
|
|
|
ceSetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
|
|
|
|
cState->addrRec.u.bt.hostName );
|
|
|
|
}
|
|
|
|
#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;
|
|
|
|
|
|
|
|
CeConnDlgState* cState;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
|
|
|
SetWindowLong( hDlg, GWL_USERDATA, lParam );
|
|
|
|
cState = (CeConnDlgState*)lParam;
|
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
adjustForConnType( hDlg, cState );
|
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
ceControlsFromAddrRec( hDlg, cState );
|
2006-05-25 05:41:32 +02:00
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
ceDlgSetup( &cState->dlgState, hDlg, DLG_STATE_NONE );
|
2006-05-25 05:41:32 +02:00
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
result = TRUE;
|
|
|
|
} else {
|
|
|
|
cState = (CeConnDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
|
|
|
|
if ( !!cState ) {
|
2008-06-05 06:29:28 +02:00
|
|
|
CEAppGlobals* globals = cState->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 );
|
|
|
|
cState->addrRec.conType = indexToConType( sel );
|
|
|
|
adjustForConnType( hDlg, cState );
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
case IDOK:
|
|
|
|
ceControlsToAddrRec( hDlg, cState );
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, id);
|
|
|
|
cState->userCancelled = id == IDCANCEL;
|
|
|
|
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
|