2006-05-19 15:44:05 +02:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
2003-11-01 06:35:29 +01:00
|
|
|
/*
|
2008-01-19 17:03:53 +01:00
|
|
|
* Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights reserved.
|
2003-11-01 06:35:29 +01: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef PLATFORM_GTK
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2005-09-09 04:57:14 +02:00
|
|
|
#include <errno.h>
|
2003-11-01 06:35:29 +01:00
|
|
|
#ifndef CLIENT_ONLY
|
|
|
|
/* # include <prc.h> */
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "linuxmain.h"
|
2006-08-26 23:15:20 +02:00
|
|
|
#include "linuxbt.h"
|
2007-11-26 03:58:25 +01:00
|
|
|
#include "linuxudp.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
/* #include "gtkmain.h" */
|
|
|
|
|
|
|
|
#include "draw.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "gtkask.h"
|
|
|
|
#include "gtknewgame.h"
|
|
|
|
#include "gtkletterask.h"
|
|
|
|
#include "gtkpasswdask.h"
|
2003-11-30 20:08:55 +01:00
|
|
|
#include "gtkntilesask.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
/* #include "undo.h" */
|
|
|
|
#include "gtkdraw.h"
|
|
|
|
#include "memstream.h"
|
|
|
|
#include "filestream.h"
|
|
|
|
|
|
|
|
/* static guint gtkSetupClientSocket( GtkAppGlobals* globals, int sock ); */
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
static void sendOnClose( XWStreamCtxt* stream, void* closure );
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2005-05-29 22:37:35 +02:00
|
|
|
static XP_Bool file_exists( const char* fileName );
|
2003-11-01 06:35:29 +01:00
|
|
|
static void setCtrlsForTray( GtkAppGlobals* globals );
|
|
|
|
static void printFinalScores( GtkAppGlobals* globals );
|
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
#define GTK_TRAY_HT_ROWS 3
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
static XWStreamCtxt*
|
|
|
|
lookupClientStream( GtkAppGlobals* globals, int sock )
|
|
|
|
{
|
|
|
|
short i;
|
|
|
|
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
|
|
|
ClientStreamRec* rec = &globals->clientRecs[i];
|
|
|
|
if ( rec->sock == sock ) {
|
|
|
|
XP_ASSERT( rec->stream != NULL );
|
|
|
|
return rec->stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XP_ASSERT( i < MAX_NUM_PLAYERS );
|
|
|
|
return NULL;
|
|
|
|
} /* lookupClientStream */
|
|
|
|
|
|
|
|
static void
|
|
|
|
rememberClient( GtkAppGlobals* globals, guint key, int sock,
|
|
|
|
XWStreamCtxt* stream )
|
|
|
|
{
|
|
|
|
short i;
|
|
|
|
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
|
|
|
|
ClientStreamRec* rec = &globals->clientRecs[i];
|
|
|
|
if ( rec->stream == NULL ) {
|
|
|
|
XP_ASSERT( stream != NULL );
|
|
|
|
rec->stream = stream;
|
|
|
|
rec->key = key;
|
|
|
|
rec->sock = sock;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XP_ASSERT( i < MAX_NUM_PLAYERS );
|
|
|
|
} /* rememberClient */
|
|
|
|
#endif
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
static void
|
|
|
|
gtkSetAltState( GtkAppGlobals* globals, guint state )
|
|
|
|
{
|
|
|
|
globals->altKeyDown
|
|
|
|
= (state & (GDK_MOD1_MASK|GDK_SHIFT_MASK|GDK_CONTROL_MASK)) != 0;
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static gint
|
2006-08-16 15:44:44 +02:00
|
|
|
button_press_event( GtkWidget* XP_UNUSED(widget), GdkEventButton *event,
|
2003-11-01 06:35:29 +01:00
|
|
|
GtkAppGlobals* globals )
|
|
|
|
{
|
2004-06-27 07:01:18 +02:00
|
|
|
XP_Bool redraw, handled;
|
2004-06-15 03:41:39 +02:00
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
gtkSetAltState( globals, event->state );
|
|
|
|
|
2008-03-09 00:16:21 +01:00
|
|
|
if ( !globals->mouseDown ) {
|
|
|
|
globals->mouseDown = XP_TRUE;
|
|
|
|
redraw = board_handlePenDown( globals->cGlobals.game.board,
|
2005-07-14 04:54:47 +02:00
|
|
|
event->x, event->y, &handled );
|
2008-03-09 00:16:21 +01:00
|
|
|
if ( redraw ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} /* button_press_event */
|
|
|
|
|
|
|
|
static gint
|
2006-08-16 15:44:44 +02:00
|
|
|
motion_notify_event( GtkWidget* XP_UNUSED(widget), GdkEventMotion *event,
|
2004-06-15 03:41:39 +02:00
|
|
|
GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_Bool handled;
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
gtkSetAltState( globals, event->state );
|
|
|
|
|
2004-06-15 03:41:39 +02:00
|
|
|
if ( globals->mouseDown ) {
|
|
|
|
handled = board_handlePenMove( globals->cGlobals.game.board, event->x,
|
|
|
|
event->y );
|
|
|
|
if ( handled ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
handled = XP_FALSE;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
} /* motion_notify_event */
|
|
|
|
|
|
|
|
static gint
|
2006-08-16 15:44:44 +02:00
|
|
|
button_release_event( GtkWidget* XP_UNUSED(widget), GdkEventMotion *event,
|
2004-06-15 03:41:39 +02:00
|
|
|
GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2004-06-15 03:41:39 +02:00
|
|
|
XP_Bool redraw;
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
gtkSetAltState( globals, event->state );
|
|
|
|
|
2004-06-15 03:41:39 +02:00
|
|
|
if ( globals->mouseDown ) {
|
|
|
|
redraw = board_handlePenUp( globals->cGlobals.game.board,
|
|
|
|
event->x,
|
2006-06-27 08:31:36 +02:00
|
|
|
event->y );
|
2004-06-15 03:41:39 +02:00
|
|
|
if ( redraw ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
globals->mouseDown = XP_FALSE;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} /* button_release_event */
|
|
|
|
|
2007-01-07 02:01:20 +01:00
|
|
|
#ifdef KEY_SUPPORT
|
2007-01-06 18:46:02 +01:00
|
|
|
static XP_Key
|
|
|
|
evtToXPKey( GdkEventKey* event, XP_Bool* movesCursorP )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_Key xpkey = XP_KEY_NONE;
|
2006-11-14 07:47:50 +01:00
|
|
|
XP_Bool movesCursor = XP_FALSE;
|
2003-11-01 06:35:29 +01:00
|
|
|
guint keyval = event->keyval;
|
|
|
|
|
2007-01-06 18:46:02 +01:00
|
|
|
switch( keyval ) {
|
2007-01-07 02:01:20 +01:00
|
|
|
#ifdef KEYBOARD_NAV
|
2007-01-06 18:46:02 +01:00
|
|
|
case GDK_Return:
|
|
|
|
xpkey = XP_RETURN_KEY;
|
|
|
|
break;
|
|
|
|
case GDK_space:
|
|
|
|
xpkey = XP_RAISEFOCUS_KEY;
|
|
|
|
break;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
case GDK_Left:
|
|
|
|
xpkey = XP_CURSOR_KEY_LEFT;
|
2006-11-14 07:47:50 +01:00
|
|
|
movesCursor = XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
case GDK_Right:
|
|
|
|
xpkey = XP_CURSOR_KEY_RIGHT;
|
2006-11-14 07:47:50 +01:00
|
|
|
movesCursor = XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
case GDK_Up:
|
|
|
|
xpkey = XP_CURSOR_KEY_UP;
|
2006-11-14 07:47:50 +01:00
|
|
|
movesCursor = XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
case GDK_Down:
|
|
|
|
xpkey = XP_CURSOR_KEY_DOWN;
|
2006-11-14 07:47:50 +01:00
|
|
|
movesCursor = XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
2007-01-07 02:01:20 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
case GDK_BackSpace:
|
|
|
|
XP_LOGF( "... it's a DEL" );
|
|
|
|
xpkey = XP_CURSOR_KEY_DEL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
keyval = keyval & 0x00FF; /* mask out gtk stuff */
|
|
|
|
if ( isalpha( keyval ) ) {
|
|
|
|
xpkey = toupper(keyval);
|
|
|
|
break;
|
2008-05-11 22:29:43 +02:00
|
|
|
#ifdef NUMBER_KEY_AS_INDEX
|
|
|
|
} else if ( isdigit( keyval ) ) {
|
|
|
|
xpkey = keyval;
|
|
|
|
break;
|
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
}
|
2007-01-06 18:46:02 +01:00
|
|
|
*movesCursorP = movesCursor;
|
|
|
|
return xpkey;
|
|
|
|
} /* evtToXPKey */
|
|
|
|
|
2007-01-07 02:01:20 +01:00
|
|
|
#ifdef KEYBOARD_NAV
|
2007-01-06 18:46:02 +01:00
|
|
|
static gint
|
|
|
|
key_press_event( GtkWidget* XP_UNUSED(widget), GdkEventKey* event,
|
|
|
|
GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool handled = XP_FALSE;
|
|
|
|
XP_Bool movesCursor;
|
|
|
|
XP_Key xpkey = evtToXPKey( event, &movesCursor );
|
2007-01-07 05:32:29 +01:00
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
gtkSetAltState( globals, event->state );
|
|
|
|
|
2007-01-06 18:46:02 +01:00
|
|
|
if ( xpkey != XP_KEY_NONE ) {
|
2007-01-07 05:32:29 +01:00
|
|
|
XP_Bool draw = globals->keyDown ?
|
|
|
|
board_handleKeyRepeat( globals->cGlobals.game.board, xpkey,
|
|
|
|
&handled )
|
|
|
|
: board_handleKeyDown( globals->cGlobals.game.board, xpkey,
|
|
|
|
&handled );
|
|
|
|
if ( draw ) {
|
2007-01-06 18:46:02 +01:00
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
}
|
2007-01-07 05:32:29 +01:00
|
|
|
globals->keyDown = XP_TRUE;
|
2007-01-06 18:46:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2007-01-07 02:01:20 +01:00
|
|
|
#endif
|
2007-01-06 18:46:02 +01:00
|
|
|
|
|
|
|
static gint
|
|
|
|
key_release_event( GtkWidget* XP_UNUSED(widget), GdkEventKey* event,
|
|
|
|
GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool handled = XP_FALSE;
|
|
|
|
XP_Bool movesCursor;
|
|
|
|
XP_Key xpkey = evtToXPKey( event, &movesCursor );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
gtkSetAltState( globals, event->state );
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( xpkey != XP_KEY_NONE ) {
|
2006-11-14 07:47:50 +01:00
|
|
|
XP_Bool draw;
|
2007-01-07 02:01:20 +01:00
|
|
|
draw = board_handleKeyUp( globals->cGlobals.game.board, xpkey,
|
|
|
|
&handled );
|
|
|
|
#ifdef KEYBOARD_NAV
|
2007-01-06 18:46:02 +01:00
|
|
|
if ( movesCursor && !handled ) {
|
|
|
|
BoardObjectType order[] = { OBJ_SCORE, OBJ_BOARD, OBJ_TRAY };
|
|
|
|
draw = linShiftFocus( &globals->cGlobals, xpkey, order,
|
|
|
|
NULL ) || draw;
|
2006-11-14 07:47:50 +01:00
|
|
|
}
|
2007-01-07 02:01:20 +01:00
|
|
|
#endif
|
2006-11-14 07:47:50 +01:00
|
|
|
if ( draw ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 00:00:52 +01:00
|
|
|
/* XP_ASSERT( globals->keyDown ); */
|
2007-01-07 05:32:29 +01:00
|
|
|
globals->keyDown = XP_FALSE;
|
|
|
|
|
2007-01-06 18:46:02 +01:00
|
|
|
return handled? 1 : 0; /* gtk will do something with the key if 0 returned */
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* key_release_event */
|
2007-01-07 02:01:20 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
# define MEMPOOL globals->cGlobals.params->util->mpool,
|
|
|
|
#else
|
|
|
|
# define MEMPOOL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static XWStreamCtxt*
|
|
|
|
streamFromFile( GtkAppGlobals* globals, char* name )
|
|
|
|
{
|
|
|
|
XP_U8* buf;
|
|
|
|
struct stat statBuf;
|
|
|
|
FILE* f;
|
|
|
|
XWStreamCtxt* stream;
|
|
|
|
|
|
|
|
(void)stat( name, &statBuf );
|
|
|
|
buf = malloc( statBuf.st_size );
|
|
|
|
f = fopen( name, "r" );
|
|
|
|
fread( buf, statBuf.st_size, 1, f );
|
|
|
|
fclose( f );
|
|
|
|
|
|
|
|
stream = mem_stream_make( MEMPOOL
|
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
globals, CHANNEL_NONE, NULL );
|
|
|
|
stream_putBytes( stream, buf, statBuf.st_size );
|
|
|
|
free( buf );
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
} /* streamFromFile */
|
|
|
|
|
|
|
|
static void
|
2005-05-29 22:37:35 +02:00
|
|
|
createOrLoadObjects( GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XWStreamCtxt* stream = NULL;
|
2006-11-05 17:54:18 +01:00
|
|
|
XP_Bool opened = XP_FALSE;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2007-02-02 09:34:37 +01:00
|
|
|
DeviceRole serverRole = globals->cGlobals.params->serverRole;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Bool isServer = serverRole != SERVER_ISCLIENT;
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
LaunchParams* params = globals->cGlobals.params;
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
globals->draw = (GtkDrawCtx*)gtkDrawCtxtMake( globals->drawing_area,
|
|
|
|
globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( !!params->fileName && file_exists( params->fileName ) ) {
|
|
|
|
|
2005-05-30 02:20:42 +02:00
|
|
|
stream = streamFromFile( globals, params->fileName );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-11-05 17:54:18 +01:00
|
|
|
opened = game_makeFromStream( MEMPOOL stream, &globals->cGlobals.game,
|
|
|
|
&globals->cGlobals.params->gi,
|
|
|
|
params->dict, params->util,
|
|
|
|
(DrawCtx*)globals->draw,
|
|
|
|
&globals->cp,
|
2008-01-19 17:03:53 +01:00
|
|
|
LINUX_SEND, IF_CH(linux_reset) globals );
|
2006-11-05 17:54:18 +01:00
|
|
|
|
2005-05-30 02:20:42 +02:00
|
|
|
stream_destroy( stream );
|
2006-11-05 17:54:18 +01:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-11-05 17:54:18 +01:00
|
|
|
if ( !opened ) {
|
2005-03-19 23:07:53 +01:00
|
|
|
XP_U16 gameID;
|
2003-11-01 06:35:29 +01:00
|
|
|
CommsAddrRec addr;
|
|
|
|
|
2007-11-26 03:58:25 +01:00
|
|
|
XP_MEMSET( &addr, 0, sizeof(addr) );
|
2006-08-26 23:15:20 +02:00
|
|
|
addr.conType = params->conType;
|
|
|
|
|
2005-03-19 23:07:53 +01:00
|
|
|
gameID = (XP_U16)util_getCurSeconds( globals->cGlobals.params->util );
|
|
|
|
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2006-08-26 23:15:20 +02:00
|
|
|
if ( addr.conType == COMMS_CONN_RELAY ) {
|
|
|
|
XP_ASSERT( !!params->connInfo.relay.relayName );
|
2006-09-19 05:39:08 +02:00
|
|
|
globals->cGlobals.defaultServerName
|
2006-08-26 23:15:20 +02:00
|
|
|
= params->connInfo.relay.relayName;
|
|
|
|
}
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
params->gi.gameID = util_getCurSeconds(globals->cGlobals.params->util);
|
2008-03-11 13:24:23 +01:00
|
|
|
XP_STATUSF( "grabbed gameID: %d\n", params->gi.gameID );
|
2005-01-13 05:30:50 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
game_makeNewGame( MEMPOOL &globals->cGlobals.game, ¶ms->gi,
|
|
|
|
params->util, (DrawCtx*)globals->draw,
|
2008-01-19 17:03:53 +01:00
|
|
|
gameID, &globals->cp, LINUX_SEND,
|
2007-11-19 00:43:27 +01:00
|
|
|
IF_CH(linux_reset) globals );
|
2006-08-26 23:15:20 +02:00
|
|
|
|
|
|
|
addr.conType = params->conType;
|
2006-10-10 03:34:37 +02:00
|
|
|
if ( 0 ) {
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
} else if ( addr.conType == COMMS_CONN_RELAY ) {
|
2006-08-26 23:15:20 +02:00
|
|
|
addr.u.ip_relay.ipAddr = 0;
|
|
|
|
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
|
|
|
|
XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName,
|
|
|
|
sizeof(addr.u.ip_relay.hostName) - 1 );
|
|
|
|
XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie,
|
|
|
|
sizeof(addr.u.ip_relay.cookie) - 1 );
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2006-08-26 23:15:20 +02:00
|
|
|
} else if ( addr.conType == COMMS_CONN_BT ) {
|
|
|
|
XP_ASSERT( sizeof(addr.u.bt.btAddr)
|
|
|
|
>= sizeof(params->connInfo.bt.hostAddr));
|
|
|
|
XP_MEMCPY( &addr.u.bt.btAddr, ¶ms->connInfo.bt.hostAddr,
|
|
|
|
sizeof(params->connInfo.bt.hostAddr) );
|
2007-11-26 03:58:25 +01:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_IP_DIRECT
|
|
|
|
} else if ( addr.conType == COMMS_CONN_IP_DIRECT ) {
|
|
|
|
XP_STRNCPY( addr.u.ip.hostName_ip, params->connInfo.ip.hostName,
|
|
|
|
sizeof(addr.u.ip.hostName_ip) - 1 );
|
|
|
|
addr.u.ip.port_ip = params->connInfo.ip.port;
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
2006-08-26 23:15:20 +02:00
|
|
|
}
|
2005-03-19 23:07:53 +01:00
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-03-19 23:07:53 +01:00
|
|
|
/* This may trigger network activity */
|
2005-03-25 04:13:10 +01:00
|
|
|
if ( !!globals->cGlobals.game.comms ) {
|
|
|
|
comms_setAddr( globals->cGlobals.game.comms, &addr );
|
|
|
|
}
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
model_setDictionary( globals->cGlobals.game.model, params->dict );
|
|
|
|
|
2005-05-30 02:20:42 +02:00
|
|
|
/* params->gi.phoniesAction = PHONIES_DISALLOW; */
|
2004-06-18 15:52:49 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
2008-04-08 05:55:53 +02:00
|
|
|
params->gi.allowHintRect = params->allowHintRect;
|
2004-06-18 15:52:49 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( !isServer ) {
|
|
|
|
XWStreamCtxt* stream =
|
|
|
|
mem_stream_make( MEMPOOL params->vtMgr, globals, CHANNEL_NONE,
|
|
|
|
sendOnClose );
|
|
|
|
server_initClientConnection( globals->cGlobals.game.server,
|
|
|
|
stream );
|
|
|
|
}
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2007-11-26 03:58:25 +01:00
|
|
|
if ( !!globals->cGlobals.game.comms ) {
|
|
|
|
comms_start( globals->cGlobals.game.comms );
|
|
|
|
}
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
server_do( globals->cGlobals.game.server );
|
|
|
|
|
|
|
|
} /* createOrLoadObjects */
|
|
|
|
|
|
|
|
/* Create a new backing pixmap of the appropriate size and set up contxt to
|
|
|
|
* draw using that size.
|
|
|
|
*/
|
2005-05-29 22:37:35 +02:00
|
|
|
static gboolean
|
2006-08-16 15:44:44 +02:00
|
|
|
configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
|
2005-05-29 22:37:35 +02:00
|
|
|
GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2007-10-24 14:46:15 +02:00
|
|
|
short bdWidth, bdHeight, leftMargin, topMargin;
|
2003-11-01 06:35:29 +01:00
|
|
|
short timerLeft, timerTop;
|
|
|
|
gint hscale, vscale;
|
|
|
|
gint trayTop;
|
|
|
|
gint boardTop = 0;
|
|
|
|
|
2005-10-30 17:28:52 +01:00
|
|
|
if ( globals->draw == NULL ) {
|
2005-05-29 22:37:35 +02:00
|
|
|
createOrLoadObjects( globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
bdWidth = widget->allocation.width - (GTK_RIGHT_MARGIN
|
|
|
|
+ GTK_BOARD_LEFT_MARGIN);
|
2006-05-09 14:31:41 +02:00
|
|
|
if ( globals->cGlobals.params->verticalScore ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
bdWidth -= GTK_VERT_SCORE_WIDTH;
|
2006-05-09 14:31:41 +02:00
|
|
|
}
|
2008-03-10 01:51:20 +01:00
|
|
|
bdHeight = widget->allocation.height - (GTK_TOP_MARGIN + GTK_BOTTOM_MARGIN)
|
|
|
|
- GTK_MIN_TRAY_SCALEV - GTK_BOTTOM_MARGIN;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
hscale = bdWidth / GTK_NUM_COLS;
|
|
|
|
vscale = (bdHeight / (GTK_NUM_ROWS + GTK_TRAY_HT_ROWS)); /* makd tray
|
|
|
|
height 3x cell
|
|
|
|
height */
|
|
|
|
leftMargin = (bdWidth - (hscale*GTK_NUM_COLS)) / 2;
|
|
|
|
topMargin = (bdHeight - (vscale*(GTK_NUM_ROWS*2))) / 2;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( !globals->cGlobals.params->verticalScore ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
boardTop += GTK_HOR_SCORE_HEIGHT;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
trayTop = boardTop + (vscale * GTK_NUM_ROWS);
|
2006-05-17 08:10:24 +02:00
|
|
|
/* move tray up if part of board's meant to be hidden */
|
|
|
|
trayTop -= vscale * globals->cGlobals.params->nHidden;
|
2008-03-10 01:51:20 +01:00
|
|
|
board_setPos( globals->cGlobals.game.board, GTK_BOARD_LEFT, boardTop,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_FALSE );
|
|
|
|
board_setScale( globals->cGlobals.game.board, hscale, vscale );
|
|
|
|
board_setShowColors( globals->cGlobals.game.board, XP_TRUE );
|
|
|
|
globals->gridOn = XP_TRUE;
|
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
timerTop = GTK_TIMER_TOP;
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( globals->cGlobals.params->verticalScore ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS) + 1;
|
2003-11-01 06:35:29 +01:00
|
|
|
board_setScoreboardLoc( globals->cGlobals.game.board,
|
2006-05-09 14:31:41 +02:00
|
|
|
timerLeft,
|
2008-03-10 01:51:20 +01:00
|
|
|
GTK_VERT_SCORE_TOP,
|
|
|
|
GTK_VERT_SCORE_WIDTH,
|
|
|
|
vscale*GTK_NUM_COLS,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_FALSE );
|
|
|
|
|
|
|
|
} else {
|
2008-03-10 01:51:20 +01:00
|
|
|
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS) - GTK_TIMER_WIDTH;
|
2003-11-01 06:35:29 +01:00
|
|
|
board_setScoreboardLoc( globals->cGlobals.game.board,
|
2008-03-10 01:51:20 +01:00
|
|
|
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP,
|
|
|
|
timerLeft-GTK_BOARD_LEFT,
|
|
|
|
GTK_HOR_SCORE_HEIGHT,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_TRUE );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
board_setTimerLoc( globals->cGlobals.game.board, timerLeft, timerTop,
|
2008-03-10 01:51:20 +01:00
|
|
|
GTK_TIMER_WIDTH, GTK_HOR_SCORE_HEIGHT );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
board_setTrayLoc( globals->cGlobals.game.board, GTK_TRAY_LEFT, trayTop,
|
|
|
|
hscale * GTK_NUM_COLS, vscale * GTK_TRAY_HT_ROWS,
|
2006-05-17 08:10:24 +02:00
|
|
|
GTK_DIVIDER_WIDTH );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
setCtrlsForTray( globals );
|
|
|
|
|
|
|
|
board_invalAll( globals->cGlobals.game.board );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} /* configure_event */
|
|
|
|
|
|
|
|
/* Redraw the screen from the backing pixmap */
|
|
|
|
static gint
|
2006-08-16 15:44:44 +02:00
|
|
|
expose_event( GtkWidget* XP_UNUSED(widget),
|
|
|
|
GdkEventExpose* XP_UNUSED(event),
|
2005-05-29 22:37:35 +02:00
|
|
|
GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
gdk_draw_rectangle( widget->window,//((GtkDrawCtx*)globals->draw)->pixmap,
|
|
|
|
widget->style->white_gc,
|
|
|
|
TRUE,
|
|
|
|
0, 0,
|
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height+widget->allocation.y );
|
|
|
|
*/
|
2005-09-02 08:24:47 +02:00
|
|
|
/* I want to inval only the area that's exposed, but the rect is always
|
|
|
|
empty, even when clearly shouldn't be. Need to investigate. Until
|
|
|
|
fixed, use board_invalAll to ensure board is drawn.*/
|
|
|
|
/* board_invalRect( globals->cGlobals.game.board, (XP_Rect*)&event->area ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-09-02 08:24:47 +02:00
|
|
|
board_invalAll( globals->cGlobals.game.board );
|
2003-11-01 06:35:29 +01:00
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
|
|
|
|
/* gdk_draw_pixmap( widget->window, */
|
|
|
|
/* widget->style->fg_gc[GTK_WIDGET_STATE (widget)], */
|
|
|
|
/* ((GtkDrawCtx*)globals->draw)->pixmap, */
|
|
|
|
/* event->area.x, event->area.y, */
|
|
|
|
/* event->area.x, event->area.y, */
|
|
|
|
/* event->area.width, event->area.height ); */
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
} /* expose_event */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gint
|
|
|
|
handle_client_event( GtkWidget *widget, GdkEventClient *event,
|
|
|
|
GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_LOGF( "handle_client_event called: event->type = " );
|
|
|
|
if ( event->type == GDK_CLIENT_EVENT ) {
|
|
|
|
XP_LOGF( "GDK_CLIENT_EVENT" );
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
XP_LOGF( "%d", event->type );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} /* handle_client_event */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
writeToFile( XWStreamCtxt* stream, void* closure )
|
|
|
|
{
|
|
|
|
void* buf;
|
|
|
|
FILE* file;
|
|
|
|
XP_U16 len;
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)closure;
|
|
|
|
|
|
|
|
len = stream_getSize( stream );
|
|
|
|
buf = malloc( len );
|
|
|
|
stream_getBytes( stream, buf, len );
|
|
|
|
|
|
|
|
file = fopen( globals->cGlobals.params->fileName, "w" );
|
|
|
|
fwrite( buf, 1, len, file );
|
|
|
|
fclose( file );
|
|
|
|
|
|
|
|
free( buf );
|
|
|
|
} /* writeToFile */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
quit( void* XP_UNUSED(dunno), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
if ( !!globals->cGlobals.params->fileName ) {
|
|
|
|
XWStreamCtxt* outStream;
|
|
|
|
|
|
|
|
outStream = mem_stream_make( MEMPOOL globals->cGlobals.params->vtMgr,
|
|
|
|
globals, 0, writeToFile );
|
|
|
|
stream_open( outStream );
|
|
|
|
|
|
|
|
game_saveToStream( &globals->cGlobals.game,
|
|
|
|
&globals->cGlobals.params->gi,
|
|
|
|
outStream );
|
|
|
|
|
|
|
|
stream_destroy( outStream );
|
|
|
|
}
|
|
|
|
|
|
|
|
game_dispose( &globals->cGlobals.game ); /* takes care of the dict */
|
|
|
|
gi_disposePlayerInfo( MEMPOOL &globals->cGlobals.params->gi );
|
2006-08-26 23:15:20 +02:00
|
|
|
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2006-08-26 23:15:20 +02:00
|
|
|
linux_bt_close( &globals->cGlobals );
|
2007-11-26 03:58:25 +01:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_IP_DIRECT
|
|
|
|
linux_udp_close( &globals->cGlobals );
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
vtmgr_destroy( MEMPOOL globals->cGlobals.params->vtMgr );
|
|
|
|
|
|
|
|
mpool_destroy( globals->cGlobals.params->util->mpool );
|
|
|
|
|
|
|
|
gtk_exit( 0 );
|
|
|
|
} /* quit */
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
makeAddSubmenu( GtkWidget* menubar, gchar* label )
|
|
|
|
{
|
|
|
|
GtkWidget* submenu;
|
|
|
|
GtkWidget* item;
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label( label );
|
|
|
|
gtk_menu_bar_append( GTK_MENU_BAR(menubar), item );
|
|
|
|
|
|
|
|
submenu = gtk_menu_new();
|
|
|
|
gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), submenu );
|
|
|
|
|
|
|
|
gtk_widget_show(item);
|
|
|
|
|
|
|
|
return submenu;
|
|
|
|
} /* makeAddSubmenu */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
tile_values( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
if ( !!globals->cGlobals.game.server ) {
|
|
|
|
XWStreamCtxt* stream =
|
|
|
|
mem_stream_make( MEMPOOL
|
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
globals,
|
|
|
|
CHANNEL_NONE,
|
|
|
|
catOnClose );
|
2004-11-09 03:06:32 +01:00
|
|
|
server_formatDictCounts( globals->cGlobals.game.server, stream, 5 );
|
2003-11-01 06:35:29 +01:00
|
|
|
stream_putU8( stream, '\n' );
|
|
|
|
stream_destroy( stream );
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* tile_values */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
game_history( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
catGameHistory( &globals->cGlobals );
|
|
|
|
} /* game_history */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
final_scores( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_Bool gameOver = server_getGameIsOver( globals->cGlobals.game.server );
|
|
|
|
|
|
|
|
if ( gameOver ) {
|
|
|
|
printFinalScores( globals );
|
|
|
|
} else {
|
|
|
|
XP_Bool confirmed;
|
|
|
|
confirmed =
|
2006-08-16 15:44:44 +02:00
|
|
|
gtkask( "Are you sure everybody wants to end the game now?",
|
2003-11-01 06:35:29 +01:00
|
|
|
2, "Yes", "No" ) == 0;
|
|
|
|
|
|
|
|
if ( confirmed ) {
|
|
|
|
server_endGame( globals->cGlobals.game.server );
|
|
|
|
gameOver = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the end game listener will take care of printing the final scores */
|
|
|
|
} /* final_scores */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
new_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
gboolean confirmed;
|
|
|
|
|
2006-06-10 07:50:27 +02:00
|
|
|
confirmed = newGameDialog( globals, XP_TRUE );
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( confirmed ) {
|
|
|
|
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U32 gameID = util_getCurSeconds( globals->cGlobals.params->util );
|
|
|
|
|
|
|
|
XP_STATUSF( "grabbed gameID: %ld\n", gameID );
|
2005-04-03 04:47:08 +02:00
|
|
|
game_reset( MEMPOOL &globals->cGlobals.game, gi,
|
|
|
|
globals->cGlobals.params->util,
|
2008-01-19 17:03:53 +01:00
|
|
|
gameID, &globals->cp, LINUX_SEND,
|
2007-11-19 00:43:27 +01:00
|
|
|
IF_CH(linux_reset) globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( isClient ) {
|
|
|
|
XWStreamCtxt* stream =
|
|
|
|
mem_stream_make( MEMPOOL
|
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
globals,
|
|
|
|
CHANNEL_NONE,
|
|
|
|
sendOnClose );
|
|
|
|
server_initClientConnection( globals->cGlobals.game.server,
|
|
|
|
stream );
|
|
|
|
}
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
(void)server_do( globals->cGlobals.game.server ); /* assign tiles, etc. */
|
|
|
|
board_invalAll( globals->cGlobals.game.board );
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* new_game */
|
|
|
|
|
2006-06-10 07:50:27 +02:00
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
game_info( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2006-06-10 07:50:27 +02:00
|
|
|
{
|
|
|
|
/* Anything to do if OK is clicked? Changed names etc. already saved. Try
|
|
|
|
server_do in case one's become a robot. */
|
|
|
|
if ( newGameDialog( globals, XP_FALSE ) ) {
|
2006-06-14 08:22:21 +02:00
|
|
|
if ( server_do( globals->cGlobals.game.server ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
2006-06-10 07:50:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
load_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* load_game */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
save_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* save_game */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
load_dictionary( GtkWidget* XP_UNUSED(widget),
|
|
|
|
GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* load_dictionary */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_undo( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* handle_undo */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_redo( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* handle_redo */
|
|
|
|
|
2003-11-16 18:28:54 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_trayEditToggle( GtkWidget* XP_UNUSED(widget),
|
|
|
|
GtkAppGlobals* XP_UNUSED(globals),
|
|
|
|
XP_Bool XP_UNUSED(on) )
|
2003-11-16 18:28:54 +01:00
|
|
|
{
|
|
|
|
} /* handle_trayEditToggle */
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_trayEditToggle_on( GtkWidget* widget, GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
handle_trayEditToggle( widget, globals, XP_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_trayEditToggle_off( GtkWidget* widget, GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
handle_trayEditToggle( widget, globals, XP_FALSE );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_resend( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CommsCtxt* comms = globals->cGlobals.game.comms;
|
2005-09-02 08:24:47 +02:00
|
|
|
if ( comms != NULL ) {
|
|
|
|
comms_resendAll( comms );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* handle_resend */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_commstats( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CommsCtxt* comms = globals->cGlobals.game.comms;
|
|
|
|
|
|
|
|
if ( !!comms ) {
|
|
|
|
XWStreamCtxt* stream =
|
|
|
|
mem_stream_make( MEMPOOL
|
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
globals,
|
|
|
|
CHANNEL_NONE, catOnClose );
|
|
|
|
comms_getStats( comms, stream );
|
|
|
|
stream_destroy( stream );
|
|
|
|
}
|
|
|
|
} /* handle_commstats */
|
|
|
|
#endif
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_memstats( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XWStreamCtxt* stream = mem_stream_make( MEMPOOL
|
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
globals,
|
|
|
|
CHANNEL_NONE, catOnClose );
|
|
|
|
mpool_stats( MEMPOOL stream );
|
|
|
|
stream_destroy( stream );
|
|
|
|
|
|
|
|
} /* handle_memstats */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
createAddItem( GtkWidget* parent, gchar* label,
|
2005-05-29 22:37:35 +02:00
|
|
|
GtkSignalFunc handlerFunc, GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkWidget* item = gtk_menu_item_new_with_label( label );
|
|
|
|
|
|
|
|
/* g_print( "createAddItem called with label %s\n", label ); */
|
|
|
|
|
|
|
|
if ( handlerFunc != NULL ) {
|
2005-05-29 22:37:35 +02:00
|
|
|
g_signal_connect( GTK_OBJECT(item), "activate",
|
|
|
|
G_CALLBACK(handlerFunc), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_menu_append( GTK_MENU(parent), item );
|
|
|
|
gtk_widget_show( item );
|
|
|
|
|
|
|
|
return item;
|
|
|
|
} /* createAddItem */
|
|
|
|
|
|
|
|
static GtkWidget*
|
2006-08-16 15:44:44 +02:00
|
|
|
makeMenus( GtkAppGlobals* globals, int XP_UNUSED(argc),
|
|
|
|
char** XP_UNUSED(argv) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkWidget* menubar = gtk_menu_bar_new();
|
|
|
|
GtkWidget* fileMenu;
|
|
|
|
|
|
|
|
fileMenu = makeAddSubmenu( menubar, "File" );
|
|
|
|
(void)createAddItem( fileMenu, "Tile values",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(tile_values), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
(void)createAddItem( fileMenu, "Game history",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(game_history), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
(void)createAddItem( fileMenu, "Final scores",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(final_scores), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
(void)createAddItem( fileMenu, "New game",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(new_game), globals );
|
2006-06-10 07:50:27 +02:00
|
|
|
(void)createAddItem( fileMenu, "Game info",
|
|
|
|
GTK_SIGNAL_FUNC(game_info), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
(void)createAddItem( fileMenu, "Load game",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(load_game), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
(void)createAddItem( fileMenu, "Save game",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(save_game), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
(void)createAddItem( fileMenu, "Load dictionary",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(load_dictionary), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
fileMenu = makeAddSubmenu( menubar, "Edit" );
|
|
|
|
|
|
|
|
(void)createAddItem( fileMenu, "Undo",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(handle_undo), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
(void)createAddItem( fileMenu, "Redo",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(handle_redo), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2003-11-16 18:28:54 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
(void)createAddItem( fileMenu, "Allow tray edit",
|
|
|
|
GTK_SIGNAL_FUNC(handle_trayEditToggle_on), globals );
|
|
|
|
(void)createAddItem( fileMenu, "Dis-allow tray edit",
|
|
|
|
GTK_SIGNAL_FUNC(handle_trayEditToggle_off), globals );
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
fileMenu = makeAddSubmenu( menubar, "Network" );
|
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
(void)createAddItem( fileMenu, "Resend",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(handle_resend), globals );
|
2008-01-19 17:03:53 +01:00
|
|
|
# ifdef DEBUG
|
2003-11-01 06:35:29 +01:00
|
|
|
(void)createAddItem( fileMenu, "Stats",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(handle_commstats), globals );
|
2008-01-19 17:03:53 +01:00
|
|
|
# endif
|
2003-11-01 06:35:29 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
(void)createAddItem( fileMenu, "Mem stats",
|
2005-05-30 02:20:42 +02:00
|
|
|
GTK_SIGNAL_FUNC(handle_memstats), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
#endif
|
|
|
|
|
2005-05-30 02:20:42 +02:00
|
|
|
/* (void)createAddItem( fileMenu, "Print board", */
|
|
|
|
/* GTK_SIGNAL_FUNC(handle_print_board), globals ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-30 02:20:42 +02:00
|
|
|
/* listAllGames( menubar, argc, argv, globals ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
gtk_widget_show( menubar );
|
|
|
|
|
|
|
|
return menubar;
|
|
|
|
} /* makeMenus */
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
static gboolean
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_flip_button( GtkWidget* XP_UNUSED(widget), gpointer _globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2005-05-29 22:37:35 +02:00
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)_globals;
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( board_flip( globals->cGlobals.game.board ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
2005-05-29 22:37:35 +02:00
|
|
|
return TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* handle_flip_button */
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
static gboolean
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_value_button( GtkWidget* XP_UNUSED(widget), gpointer closure )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2005-05-29 22:37:35 +02:00
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)closure;
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( board_toggle_showValues( globals->cGlobals.game.board ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
2005-05-29 22:37:35 +02:00
|
|
|
return TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* handle_value_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_hint_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_Bool redo;
|
2004-06-27 07:01:18 +02:00
|
|
|
if ( board_requestHint( globals->cGlobals.game.board,
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
XP_FALSE,
|
|
|
|
#endif
|
|
|
|
&redo ) ) {
|
2003-11-30 20:08:55 +01:00
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_hint_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_nhint_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-30 20:08:55 +01:00
|
|
|
{
|
|
|
|
XP_Bool redo;
|
|
|
|
|
2004-06-27 07:01:18 +02:00
|
|
|
board_resetEngine( globals->cGlobals.game.board );
|
|
|
|
if ( board_requestHint( globals->cGlobals.game.board,
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
XP_TRUE,
|
|
|
|
#endif
|
|
|
|
&redo ) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_hint_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_colors_button( GtkWidget* XP_UNUSED(widget),
|
|
|
|
GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
/* XP_Bool oldVal = board_getShowColors( globals->cGlobals.game.board ); */
|
|
|
|
/* if ( board_setShowColors( globals->cGlobals.game.board, !oldVal ) ) { */
|
|
|
|
/* board_draw( globals->cGlobals.game.board ); */
|
|
|
|
/* } */
|
|
|
|
} /* handle_colors_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_juggle_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
if ( board_juggleTray( globals->cGlobals.game.board ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_juggle_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_undo_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
if ( server_handleUndo( globals->cGlobals.game.server ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_undo_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_redo_button( GtkWidget* XP_UNUSED(widget),
|
|
|
|
GtkAppGlobals* XP_UNUSED(globals) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* handle_redo_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_trade_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
if ( board_beginTrade( globals->cGlobals.game.board ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_juggle_button */
|
|
|
|
|
2006-11-13 03:02:15 +01:00
|
|
|
static void
|
|
|
|
handle_done_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
if ( board_commitTurn( globals->cGlobals.game.board ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_done_button */
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
|
|
|
scroll_value_changed( GtkAdjustment *adj, GtkAppGlobals* globals )
|
|
|
|
{
|
2008-04-08 05:55:53 +02:00
|
|
|
XP_U16 newValue;
|
2003-11-01 06:35:29 +01:00
|
|
|
gfloat newValueF = adj->value;
|
|
|
|
|
2006-05-17 08:10:24 +02:00
|
|
|
XP_ASSERT( newValueF >= 0.0
|
|
|
|
&& newValueF <= globals->cGlobals.params->nHidden );
|
2003-11-01 06:35:29 +01:00
|
|
|
newValue = (XP_U16)newValueF;
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
if ( board_setYOffset( globals->cGlobals.game.board, newValue ) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* scroll_value_changed */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_grid_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_U16 scaleH, scaleV;
|
|
|
|
XP_Bool gridOn = globals->gridOn;
|
|
|
|
|
|
|
|
board_getScale( globals->cGlobals.game.board, &scaleH, &scaleV );
|
|
|
|
|
|
|
|
if ( gridOn ) {
|
|
|
|
--scaleH;
|
|
|
|
--scaleV;
|
|
|
|
} else {
|
|
|
|
++scaleH;
|
|
|
|
++scaleV;
|
|
|
|
}
|
|
|
|
|
|
|
|
board_setScale( globals->cGlobals.game.board, scaleH, scaleV );
|
|
|
|
globals->gridOn = !gridOn;
|
|
|
|
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
} /* handle_grid_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_hide_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2006-05-12 09:59:21 +02:00
|
|
|
BoardCtxt* board;
|
|
|
|
XP_Bool draw = XP_FALSE;
|
|
|
|
|
2006-05-17 08:10:24 +02:00
|
|
|
if ( globals->cGlobals.params->nHidden > 0 ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
globals->adjustment->page_size = GTK_NUM_ROWS;
|
2006-05-12 09:59:21 +02:00
|
|
|
globals->adjustment->value = 0.0;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-05-12 09:59:21 +02:00
|
|
|
gtk_signal_emit_by_name( GTK_OBJECT(globals->adjustment), "changed" );
|
|
|
|
gtk_adjustment_value_changed( GTK_ADJUSTMENT(globals->adjustment) );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-05-12 09:59:21 +02:00
|
|
|
|
|
|
|
board = globals->cGlobals.game.board;
|
|
|
|
if ( TRAY_REVEALED == board_getTrayVisState( board ) ) {
|
|
|
|
draw = board_hideTray( board );
|
|
|
|
} else {
|
|
|
|
draw = board_showTray( board );
|
|
|
|
}
|
|
|
|
if ( draw ) {
|
|
|
|
board_draw( board );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
} /* handle_hide_button */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
handle_commit_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
if ( board_commitTurn( globals->cGlobals.game.board ) ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
} /* handle_commit_button */
|
|
|
|
|
|
|
|
static void
|
2008-05-24 18:08:13 +02:00
|
|
|
gtkUserError( GtkAppGlobals* XP_UNUSED(globals), const char* format, ... )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start( ap, format );
|
|
|
|
|
|
|
|
vsprintf( buf, format, ap );
|
|
|
|
|
2006-08-16 15:44:44 +02:00
|
|
|
(void)gtkask( buf, 1, "OK" );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
} /* gtkUserError */
|
|
|
|
|
|
|
|
static VTableMgr*
|
|
|
|
gtk_util_getVTManager(XW_UtilCtxt* uc)
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
return globals->cGlobals.params->vtMgr;
|
|
|
|
} /* linux_util_getVTManager */
|
|
|
|
|
2003-11-16 18:28:54 +01:00
|
|
|
static XP_S16
|
2005-01-13 05:30:50 +01:00
|
|
|
gtk_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
|
2003-11-16 18:28:54 +01:00
|
|
|
XP_U16 playerNum,
|
2005-01-13 05:30:50 +01:00
|
|
|
const XP_UCHAR4* texts, XP_U16 nTiles )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2003-11-16 18:28:54 +01:00
|
|
|
XP_S16 chosen;
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
XP_UCHAR* name = globals->cGlobals.params->gi.players[playerNum].name;
|
|
|
|
|
|
|
|
chosen = gtkletterask( pi->why == PICK_FOR_BLANK, name, nTiles, texts );
|
|
|
|
return chosen;
|
|
|
|
} /* gtk_util_userPickTile */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_util_askPassword( XW_UtilCtxt* XP_UNUSED(uc), const XP_UCHAR* name,
|
|
|
|
XP_UCHAR* buf, XP_U16* len )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_Bool ok = gtkpasswdask( name, buf, len );
|
|
|
|
return ok;
|
|
|
|
} /* gtk_util_askPassword */
|
|
|
|
|
|
|
|
static void
|
|
|
|
setCtrlsForTray( GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XW_TrayVisState state =
|
|
|
|
board_getTrayVisState( globals->cGlobals.game.board );
|
2006-05-17 08:10:24 +02:00
|
|
|
XP_S16 nHidden = globals->cGlobals.params->nHidden;
|
|
|
|
|
|
|
|
if ( nHidden != 0 ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
XP_U16 pageSize = GTK_NUM_ROWS;
|
2006-05-17 08:10:24 +02:00
|
|
|
|
|
|
|
if ( state == TRAY_HIDDEN ) { /* we recover what tray covers */
|
2008-03-10 01:51:20 +01:00
|
|
|
nHidden -= GTK_TRAY_HT_ROWS;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-05-17 08:10:24 +02:00
|
|
|
if ( nHidden > 0 ) {
|
|
|
|
pageSize -= nHidden;
|
|
|
|
}
|
|
|
|
globals->adjustment->page_size = pageSize;
|
|
|
|
|
2007-12-02 20:13:25 +01:00
|
|
|
XP_LOGF( "%s: set pageSize = %d", __func__,
|
2006-05-17 08:10:24 +02:00
|
|
|
pageSize );
|
|
|
|
|
|
|
|
globals->adjustment->value =
|
|
|
|
board_getYOffset( globals->cGlobals.game.board );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_signal_emit_by_name( GTK_OBJECT(globals->adjustment), "changed" );
|
|
|
|
}
|
|
|
|
} /* setCtrlsForTray */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState XP_UNUSED(state),
|
|
|
|
XP_U16 XP_UNUSED(nVisibleRows) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
setCtrlsForTray( globals );
|
|
|
|
} /* gtk_util_trayHiddenChange */
|
|
|
|
|
|
|
|
static void
|
2008-03-27 05:12:16 +01:00
|
|
|
gtk_util_yOffsetChange( XW_UtilCtxt* uc, XP_U16 XP_UNUSED(oldOffset),
|
|
|
|
XP_U16 newOffset )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2008-03-27 05:12:16 +01:00
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
XP_ASSERT( globals->cGlobals.params->nHidden > 0 );
|
|
|
|
globals->adjustment->value = newOffset;
|
|
|
|
gtk_adjustment_value_changed( GTK_ADJUSTMENT(globals->adjustment) );
|
2006-05-14 17:26:21 +02:00
|
|
|
} /* gtk_util_yOffsetChange */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
printFinalScores( GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XWStreamCtxt* stream;
|
|
|
|
|
|
|
|
stream = mem_stream_make( MEMPOOL
|
2005-05-30 02:20:42 +02:00
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
globals, CHANNEL_NONE, catOnClose );
|
2003-11-01 06:35:29 +01:00
|
|
|
server_writeFinalScores( globals->cGlobals.game.server, stream );
|
|
|
|
stream_putU8( stream, '\n' );
|
|
|
|
stream_destroy( stream );
|
|
|
|
} /* printFinalScores */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_util_notifyGameOver( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
if ( globals->cGlobals.params->printHistory ) {
|
|
|
|
catGameHistory( &globals->cGlobals );
|
|
|
|
}
|
|
|
|
|
|
|
|
printFinalScores( globals );
|
|
|
|
|
|
|
|
if ( globals->cGlobals.params->quitAfter ) {
|
|
|
|
quit( NULL, globals );
|
|
|
|
} else if ( globals->cGlobals.params->undoWhenDone ) {
|
|
|
|
server_handleUndo( globals->cGlobals.game.server );
|
|
|
|
}
|
|
|
|
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
} /* gtk_util_notifyGameOver */
|
|
|
|
|
|
|
|
/* define this to prevent user events during debugging from stopping the engine */
|
|
|
|
/* #define DONT_ABORT_ENGINE */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
gtk_util_hiliteCell( XW_UtilCtxt* uc, XP_U16 col, XP_U16 row )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
2004-06-27 07:01:18 +02:00
|
|
|
#ifndef DONT_ABORT_ENGINE
|
2003-11-01 06:35:29 +01:00
|
|
|
gboolean pending;
|
2004-06-27 07:01:18 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
board_hiliteCellAt( globals->cGlobals.game.board, col, row );
|
|
|
|
if ( globals->cGlobals.params->sleepOnAnchor ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DONT_ABORT_ENGINE
|
|
|
|
return XP_TRUE; /* keep going */
|
|
|
|
#else
|
|
|
|
pending = gdk_events_pending();
|
2003-11-30 20:08:55 +01:00
|
|
|
if ( pending ) {
|
|
|
|
XP_DEBUGF( "gtk_util_hiliteCell=>%d", pending );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
return !pending;
|
|
|
|
#endif
|
|
|
|
} /* gtk_util_hiliteCell */
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
static XP_Bool
|
|
|
|
gtk_util_altKeyDown( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
return globals->altKeyDown;
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_util_engineProgressCallback( XW_UtilCtxt* XP_UNUSED(uc) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
#ifdef DONT_ABORT_ENGINE
|
|
|
|
return XP_TRUE; /* keep going */
|
|
|
|
#else
|
|
|
|
gboolean pending = gdk_events_pending();
|
|
|
|
|
|
|
|
/* XP_DEBUGF( "gdk_events_pending returned %d\n", pending ); */
|
|
|
|
|
|
|
|
return !pending;
|
|
|
|
#endif
|
|
|
|
} /* gtk_util_engineProgressCallback */
|
|
|
|
|
2005-07-05 22:59:42 +02:00
|
|
|
static void
|
|
|
|
cancelTimer( GtkAppGlobals* globals, XWTimerReason why )
|
|
|
|
{
|
|
|
|
guint src = globals->timerSources[why-1];
|
|
|
|
if ( src != 0 ) {
|
|
|
|
g_source_remove( src );
|
|
|
|
globals->timerSources[why-1] = 0;
|
|
|
|
}
|
|
|
|
} /* cancelTimer */
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static gint
|
|
|
|
pentimer_idle_func( gpointer data )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)data;
|
|
|
|
struct timeval tv;
|
|
|
|
XP_Bool callAgain = XP_TRUE;
|
2007-01-06 18:46:02 +01:00
|
|
|
|
2003-11-01 06:56:24 +01:00
|
|
|
gettimeofday( &tv, NULL );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( (tv.tv_usec - globals->penTv.tv_usec) >= globals->penTimerInterval) {
|
2006-02-18 07:35:48 +01:00
|
|
|
linuxFireTimer( &globals->cGlobals, TIMER_PENDOWN );
|
2003-11-01 06:35:29 +01:00
|
|
|
callAgain = XP_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return callAgain;
|
|
|
|
} /* timer_idle_func */
|
|
|
|
|
|
|
|
static gint
|
|
|
|
score_timer_func( gpointer data )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)data;
|
|
|
|
|
2006-02-18 07:35:48 +01:00
|
|
|
linuxFireTimer( &globals->cGlobals, TIMER_TIMERTICK );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-06-23 06:20:00 +02:00
|
|
|
return XP_FALSE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* score_timer_func */
|
|
|
|
|
2007-11-26 03:58:25 +01:00
|
|
|
#if defined RELAY_HEARTBEAT || defined COMMS_HEARTBEAT
|
2005-06-23 06:20:00 +02:00
|
|
|
static gint
|
|
|
|
heartbeat_timer_func( gpointer data )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)data;
|
|
|
|
|
2005-09-03 17:39:15 +02:00
|
|
|
if ( !globals->cGlobals.params->noHeartbeat ) {
|
2006-02-18 07:35:48 +01:00
|
|
|
linuxFireTimer( &globals->cGlobals, TIMER_HEARTBEAT );
|
2005-09-03 17:39:15 +02:00
|
|
|
}
|
2005-06-23 06:20:00 +02:00
|
|
|
|
|
|
|
return (gint)0;
|
|
|
|
}
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
2005-06-23 06:20:00 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-10-10 03:34:37 +02:00
|
|
|
gtk_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
|
2007-11-26 03:58:25 +01:00
|
|
|
XP_U16 when,
|
2007-05-26 16:14:01 +02:00
|
|
|
XWTimerProc proc, void* closure )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
2005-07-05 22:59:42 +02:00
|
|
|
guint newSrc;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-07-05 22:59:42 +02:00
|
|
|
cancelTimer( globals, why );
|
2005-06-23 06:20:00 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( why == TIMER_PENDOWN ) {
|
2008-03-27 05:12:16 +01:00
|
|
|
/* half a second */
|
|
|
|
globals->penTimerInterval = 50 * 10000;
|
2005-06-23 06:20:00 +02:00
|
|
|
|
2003-11-01 06:56:24 +01:00
|
|
|
(void)gettimeofday( &globals->penTv, NULL );
|
2005-07-05 22:59:42 +02:00
|
|
|
newSrc = g_idle_add( pentimer_idle_func, globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
} else if ( why == TIMER_TIMERTICK ) {
|
2008-03-27 05:12:16 +01:00
|
|
|
/* one second */
|
2003-11-01 06:56:24 +01:00
|
|
|
globals->scoreTimerInterval = 100 * 10000;
|
2005-06-23 06:20:00 +02:00
|
|
|
|
2003-11-01 06:56:24 +01:00
|
|
|
(void)gettimeofday( &globals->scoreTv, NULL );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-07-05 22:59:42 +02:00
|
|
|
newSrc = g_timeout_add( 1000, score_timer_func, globals );
|
2007-11-26 03:58:25 +01:00
|
|
|
#if defined RELAY_HEARTBEAT || defined COMMS_HEARTBEAT
|
2005-06-23 06:20:00 +02:00
|
|
|
} else if ( why == TIMER_HEARTBEAT ) {
|
2005-07-05 22:59:42 +02:00
|
|
|
newSrc = g_timeout_add( 1000 * when, heartbeat_timer_func, globals );
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
2005-06-23 06:20:00 +02:00
|
|
|
} else {
|
|
|
|
XP_ASSERT( 0 );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2005-09-09 05:06:27 +02:00
|
|
|
globals->cGlobals.timerProcs[why] = proc;
|
|
|
|
globals->cGlobals.timerClosures[why] = closure;
|
2005-07-05 22:59:42 +02:00
|
|
|
XP_ASSERT( newSrc != 0 );
|
|
|
|
globals->timerSources[why-1] = newSrc;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_util_setTimer */
|
|
|
|
|
|
|
|
static gint
|
|
|
|
idle_func( gpointer data )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)data;
|
|
|
|
/* XP_DEBUGF( "idle_func called\n" ); */
|
|
|
|
|
|
|
|
/* remove before calling server_do. If server_do puts up a dialog that
|
|
|
|
calls gtk_main, then this idle proc will also apply to that event loop
|
|
|
|
and bad things can happen. So kill the idle proc asap. */
|
|
|
|
gtk_idle_remove( globals->idleID );
|
|
|
|
|
|
|
|
if ( server_do( globals->cGlobals.game.server ) ) {
|
|
|
|
XP_ASSERT( globals->cGlobals.game.board != NULL );
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
|
|
|
return 0; /* 0 will stop it from being called again */
|
|
|
|
} /* idle_func */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_util_requestTime( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
globals->idleID = gtk_idle_add( idle_func, globals );
|
|
|
|
} /* gtk_util_requestTime */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
gtk_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, XP_U16 player,
|
|
|
|
XP_Bool turnLost )
|
|
|
|
{
|
|
|
|
XP_Bool result;
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
char buf[300];
|
|
|
|
|
|
|
|
if ( turnLost ) {
|
2005-05-30 02:20:42 +02:00
|
|
|
char wordsBuf[256];
|
|
|
|
XP_U16 i;
|
|
|
|
XP_UCHAR* name = globals->cGlobals.params->gi.players[player].name;
|
|
|
|
XP_ASSERT( !!name );
|
|
|
|
|
|
|
|
for ( i = 0, wordsBuf[0] = '\0'; ; ) {
|
|
|
|
char wordBuf[18];
|
|
|
|
sprintf( wordBuf, "\"%s\"", bwi->words[i] );
|
|
|
|
strcat( wordsBuf, wordBuf );
|
|
|
|
if ( ++i == bwi->nWords ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strcat( wordsBuf, ", " );
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf( buf, "Player %d (%s) played illegal word[s] %s; loses turn.",
|
|
|
|
player+1, name, wordsBuf );
|
|
|
|
|
|
|
|
if ( globals->cGlobals.params->skipWarnings ) {
|
|
|
|
XP_LOGF( "%s", buf );
|
|
|
|
} else {
|
|
|
|
gtkUserError( globals, buf );
|
|
|
|
}
|
|
|
|
result = XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} else {
|
2005-05-30 02:20:42 +02:00
|
|
|
XP_ASSERT( bwi->nWords == 1 );
|
|
|
|
sprintf( buf, "Word \"%s\" not in the current dictionary. "
|
|
|
|
"Use it anyway?", bwi->words[0] );
|
2006-08-16 15:44:44 +02:00
|
|
|
result = 0 == gtkask( buf, 2, "Ok", "Cancel" );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* gtk_util_warnIllegalWord */
|
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
static XWStreamCtxt*
|
|
|
|
gtk_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
XWStreamCtxt* stream = mem_stream_make( MEMPOOL
|
|
|
|
globals->cGlobals.params->vtMgr,
|
|
|
|
uc->closure, channelNo,
|
|
|
|
sendOnClose );
|
|
|
|
return stream;
|
|
|
|
} /* gtk_util_makeStreamFromAddr */
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2004-06-27 07:01:18 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_util_getTraySearchLimits( XW_UtilCtxt* XP_UNUSED(uc),
|
|
|
|
XP_U16* XP_UNUSED(min), XP_U16* max )
|
2004-06-27 07:01:18 +02:00
|
|
|
{
|
2006-08-16 15:44:44 +02:00
|
|
|
*max = askNTiles( MAX_TRAY_TILES, *max );
|
2004-06-27 07:01:18 +02:00
|
|
|
return XP_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_util_userError( XW_UtilCtxt* uc, UtilErrID id )
|
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
|
2005-09-14 07:11:29 +02:00
|
|
|
XP_Bool silent;
|
2008-05-24 18:08:13 +02:00
|
|
|
const XP_UCHAR* message = linux_getErrString( id, &silent );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2007-12-02 20:13:25 +01:00
|
|
|
XP_LOGF( "%s(%d)", __func__, id );
|
2006-11-11 23:44:31 +01:00
|
|
|
|
2005-09-14 07:11:29 +02:00
|
|
|
if ( silent ) {
|
|
|
|
XP_LOGF( message );
|
|
|
|
} else {
|
|
|
|
gtkUserError( globals, message );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_util_userError */
|
|
|
|
|
2004-02-17 05:00:12 +01:00
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_util_userQuery( XW_UtilCtxt* XP_UNUSED(uc), UtilQueryID id,
|
|
|
|
XWStreamCtxt* stream )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2004-02-17 05:00:12 +01:00
|
|
|
XP_Bool result;
|
2003-11-01 06:35:29 +01:00
|
|
|
char* question;
|
|
|
|
char* answers[3];
|
|
|
|
gint numAnswers = 0;
|
2004-02-17 05:00:12 +01:00
|
|
|
XP_U16 okIndex = 1;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Bool freeMe = XP_FALSE;
|
|
|
|
|
|
|
|
switch( id ) {
|
|
|
|
|
|
|
|
case QUERY_COMMIT_TURN:
|
|
|
|
question = strFromStream( stream );
|
|
|
|
freeMe = XP_TRUE;
|
|
|
|
/* len = stream_getSize( stream ); */
|
|
|
|
/* question = malloc( len + 1 ); */
|
|
|
|
/* stream_getBytes( stream, question, len ); */
|
|
|
|
/* question[len] = '\0'; */
|
|
|
|
answers[numAnswers++] = "Cancel";
|
|
|
|
answers[numAnswers++] = "Ok";
|
|
|
|
break;
|
|
|
|
case QUERY_COMMIT_TRADE:
|
|
|
|
question = "Are you sure you want to trade the selected tiles?";
|
|
|
|
answers[numAnswers++] = "Cancel";
|
|
|
|
answers[numAnswers++] = "Ok";
|
|
|
|
break;
|
|
|
|
case QUERY_ROBOT_MOVE:
|
|
|
|
case QUERY_ROBOT_TRADE:
|
|
|
|
question = strFromStream( stream );
|
|
|
|
freeMe = XP_TRUE;
|
|
|
|
answers[numAnswers++] = "Ok";
|
2004-02-17 05:00:12 +01:00
|
|
|
okIndex = 0;
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
XP_ASSERT( 0 );
|
2004-02-17 05:00:12 +01:00
|
|
|
return XP_FALSE;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2006-08-16 15:44:44 +02:00
|
|
|
result = gtkask( question, numAnswers,
|
2004-02-17 05:00:12 +01:00
|
|
|
answers[0], answers[1], answers[2] ) == okIndex;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( freeMe > 0 ) {
|
|
|
|
free( question );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* gtk_util_userQuery */
|
|
|
|
|
|
|
|
static XP_Bool
|
2005-05-29 22:37:35 +02:00
|
|
|
file_exists( const char* fileName )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
struct stat statBuf;
|
|
|
|
|
|
|
|
int statResult = stat( fileName, &statBuf );
|
|
|
|
return statResult == 0;
|
|
|
|
} /* file_exists */
|
|
|
|
|
|
|
|
static GtkWidget*
|
2005-05-29 22:37:35 +02:00
|
|
|
makeShowButtonFromBitmap( void* closure, const gchar* filename,
|
|
|
|
const gchar* alt, GCallback func )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2005-05-29 22:37:35 +02:00
|
|
|
GtkWidget* widget;
|
2003-11-01 06:35:29 +01:00
|
|
|
GtkWidget* button;
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
if ( file_exists( filename ) ) {
|
|
|
|
widget = gtk_image_new_from_file (filename);
|
2003-11-01 06:35:29 +01:00
|
|
|
} else {
|
2005-05-29 22:37:35 +02:00
|
|
|
widget = gtk_label_new( alt );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2005-05-29 22:37:35 +02:00
|
|
|
gtk_widget_show( widget );
|
|
|
|
|
|
|
|
button = gtk_button_new();
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), widget );
|
|
|
|
gtk_widget_show (button);
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( func != NULL ) {
|
2005-05-29 22:37:35 +02:00
|
|
|
g_signal_connect( GTK_OBJECT(button), "clicked", func, closure );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return button;
|
|
|
|
} /* makeShowButtonFromBitmap */
|
|
|
|
|
|
|
|
static GtkWidget*
|
2006-08-16 15:44:44 +02:00
|
|
|
makeVerticalBar( GtkAppGlobals* globals, GtkWidget* XP_UNUSED(window) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkWidget* vbox;
|
|
|
|
GtkWidget* button;
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
vbox = gtk_vbutton_box_new();
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../flip.xpm", "f",
|
|
|
|
G_CALLBACK(handle_flip_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../value.xpm", "v",
|
|
|
|
G_CALLBACK(handle_value_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../hint.xpm", "?",
|
|
|
|
G_CALLBACK(handle_hint_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../hintNum.xpm", "n",
|
|
|
|
G_CALLBACK(handle_nhint_button) );
|
2003-11-30 20:08:55 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../colors.xpm", "c",
|
|
|
|
G_CALLBACK(handle_colors_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
|
|
|
/* undo and redo buttons */
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../undo.xpm", "u",
|
|
|
|
G_CALLBACK(handle_undo_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../redo.xpm", "r",
|
|
|
|
G_CALLBACK(handle_redo_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
|
|
|
/* the four buttons that on palm are beside the tray */
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../juggle.xpm", "j",
|
|
|
|
G_CALLBACK(handle_juggle_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../trade.xpm", "t",
|
|
|
|
G_CALLBACK(handle_trade_button) );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
2006-11-13 03:02:15 +01:00
|
|
|
button = makeShowButtonFromBitmap( globals, "../done.xpm", "d",
|
|
|
|
G_CALLBACK(handle_done_button) );
|
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), button, FALSE, TRUE, 0 );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
gtk_widget_show( vbox );
|
|
|
|
return vbox;
|
|
|
|
} /* makeVerticalBar */
|
|
|
|
|
|
|
|
static GtkWidget*
|
2006-08-16 15:44:44 +02:00
|
|
|
makeButtons( GtkAppGlobals* globals, int XP_UNUSED(argc),
|
|
|
|
char** XP_UNUSED(argv) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
short i;
|
|
|
|
GtkWidget* hbox;
|
|
|
|
GtkWidget* button;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char* name;
|
2005-05-29 22:37:35 +02:00
|
|
|
GCallback func;
|
2003-11-01 06:35:29 +01:00
|
|
|
} buttons[] = {
|
|
|
|
/* { "Flip", handle_flip_button }, */
|
2005-05-29 22:37:35 +02:00
|
|
|
{ "Grid", G_CALLBACK(handle_grid_button) },
|
|
|
|
{ "Hide", G_CALLBACK(handle_hide_button) },
|
|
|
|
{ "Commit", G_CALLBACK(handle_commit_button) },
|
2003-11-01 06:35:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new( FALSE, 0 );
|
|
|
|
|
|
|
|
for ( i = 0; i < sizeof(buttons)/sizeof(*buttons); ++i ) {
|
|
|
|
button = gtk_button_new_with_label( buttons[i].name );
|
|
|
|
gtk_widget_show( button );
|
2005-05-29 22:37:35 +02:00
|
|
|
g_signal_connect( GTK_OBJECT(button), "clicked",
|
|
|
|
G_CALLBACK(buttons[i].func), globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
gtk_box_pack_start( GTK_BOX(hbox), button, FALSE, TRUE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show( hbox );
|
|
|
|
return hbox;
|
|
|
|
} /* makeButtons */
|
|
|
|
|
|
|
|
static void
|
|
|
|
setupGtkUtilCallbacks( GtkAppGlobals* globals, XW_UtilCtxt* util )
|
|
|
|
{
|
|
|
|
util->vtable->m_util_userError = gtk_util_userError;
|
|
|
|
util->vtable->m_util_userQuery = gtk_util_userQuery;
|
|
|
|
util->vtable->m_util_getVTManager = gtk_util_getVTManager;
|
2003-11-16 18:28:54 +01:00
|
|
|
util->vtable->m_util_userPickTile = gtk_util_userPickTile;
|
2003-11-01 06:35:29 +01:00
|
|
|
util->vtable->m_util_askPassword = gtk_util_askPassword;
|
|
|
|
util->vtable->m_util_trayHiddenChange = gtk_util_trayHiddenChange;
|
|
|
|
util->vtable->m_util_yOffsetChange = gtk_util_yOffsetChange;
|
|
|
|
util->vtable->m_util_notifyGameOver = gtk_util_notifyGameOver;
|
|
|
|
util->vtable->m_util_hiliteCell = gtk_util_hiliteCell;
|
2008-04-08 05:55:53 +02:00
|
|
|
util->vtable->m_util_altKeyDown = gtk_util_altKeyDown;
|
2003-11-01 06:35:29 +01:00
|
|
|
util->vtable->m_util_engineProgressCallback =
|
|
|
|
gtk_util_engineProgressCallback;
|
|
|
|
util->vtable->m_util_setTimer = gtk_util_setTimer;
|
|
|
|
util->vtable->m_util_requestTime = gtk_util_requestTime;
|
|
|
|
util->vtable->m_util_warnIllegalWord = gtk_util_warnIllegalWord;
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
util->vtable->m_util_makeStreamFromAddr = gtk_util_makeStreamFromAddr;
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2004-06-27 07:01:18 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
util->vtable->m_util_getTraySearchLimits = gtk_util_getTraySearchLimits;
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
util->closure = globals;
|
|
|
|
} /* setupGtkUtilCallbacks */
|
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-03-06 19:07:00 +01:00
|
|
|
static gboolean
|
|
|
|
newConnectionInput( GIOChannel *source,
|
|
|
|
GIOCondition condition,
|
|
|
|
gpointer data )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2006-09-08 09:23:19 +02:00
|
|
|
gboolean keepSource;
|
2005-03-06 19:07:00 +01:00
|
|
|
int sock = g_io_channel_unix_get_fd( source );
|
2003-11-01 06:35:29 +01:00
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)data;
|
2005-03-06 19:07:00 +01:00
|
|
|
|
2007-12-02 20:13:25 +01:00
|
|
|
XP_LOGF( "%s:condition = 0x%x", __func__, (int)condition );
|
2005-03-06 19:07:00 +01:00
|
|
|
|
2006-09-08 09:23:19 +02:00
|
|
|
/* XP_ASSERT( sock == globals->cGlobals.socket ); */
|
2005-03-06 19:07:00 +01:00
|
|
|
|
2006-09-08 09:23:19 +02:00
|
|
|
if ( (condition & (G_IO_HUP | G_IO_ERR)) != 0 ) {
|
|
|
|
XP_LOGF( "dropping socket %d", sock );
|
|
|
|
close( sock );
|
2007-11-26 03:58:25 +01:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2005-03-06 19:07:00 +01:00
|
|
|
globals->cGlobals.socket = -1;
|
2007-11-26 03:58:25 +01:00
|
|
|
#endif
|
|
|
|
if ( 0 ) {
|
2006-09-08 09:23:19 +02:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2007-11-26 03:58:25 +01:00
|
|
|
} else if ( COMMS_CONN_BT == globals->cGlobals.params->conType ) {
|
2006-09-08 09:23:19 +02:00
|
|
|
linux_bt_socketclosed( &globals->cGlobals, sock );
|
|
|
|
#endif
|
2007-11-26 03:58:25 +01:00
|
|
|
#ifdef XWFEATURE_IP_DIRECT
|
|
|
|
} else if ( COMMS_CONN_IP_DIRECT == globals->cGlobals.params->conType ) {
|
|
|
|
linux_udp_socketclosed( &globals->cGlobals, sock );
|
|
|
|
#endif
|
|
|
|
}
|
2006-09-08 09:23:19 +02:00
|
|
|
keepSource = FALSE; /* remove the event source */
|
2005-03-06 19:07:00 +01:00
|
|
|
|
|
|
|
} else if ( (condition & G_IO_IN) != 0 ) {
|
|
|
|
ssize_t nRead;
|
|
|
|
unsigned char buf[512];
|
2007-11-26 03:58:25 +01:00
|
|
|
CommsAddrRec addr;
|
|
|
|
CommsAddrRec* addrp = NULL;
|
2005-03-06 19:07:00 +01:00
|
|
|
|
2006-10-10 03:34:37 +02:00
|
|
|
if ( 0 ) {
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
} else if ( globals->cGlobals.params->conType == COMMS_CONN_RELAY ) {
|
2006-08-26 23:15:20 +02:00
|
|
|
nRead = linux_relay_receive( &globals->cGlobals,
|
|
|
|
buf, sizeof(buf) );
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2006-08-26 23:15:20 +02:00
|
|
|
} else if ( globals->cGlobals.params->conType == COMMS_CONN_BT ) {
|
2006-09-08 09:23:19 +02:00
|
|
|
nRead = linux_bt_receive( sock, buf, sizeof(buf) );
|
2007-11-26 03:58:25 +01:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_IP_DIRECT
|
|
|
|
} else if ( globals->cGlobals.params->conType == COMMS_CONN_IP_DIRECT ) {
|
|
|
|
addrp = &addr;
|
|
|
|
nRead = linux_udp_receive( sock, buf, sizeof(buf), addrp, &globals->cGlobals );
|
2006-10-10 03:34:37 +02:00
|
|
|
#endif
|
2006-08-26 23:15:20 +02:00
|
|
|
} else {
|
|
|
|
XP_ASSERT( 0 );
|
|
|
|
}
|
2005-03-06 19:07:00 +01:00
|
|
|
|
|
|
|
if ( !globals->dropIncommingMsgs && nRead > 0 ) {
|
|
|
|
XWStreamCtxt* inboundS;
|
|
|
|
XP_Bool redraw = XP_FALSE;
|
|
|
|
|
|
|
|
inboundS = stream_from_msgbuf( &globals->cGlobals, buf, nRead );
|
|
|
|
if ( !!inboundS ) {
|
2005-03-09 16:12:57 +01:00
|
|
|
if ( comms_checkIncomingStream( globals->cGlobals.game.comms,
|
2007-11-26 03:58:25 +01:00
|
|
|
inboundS, addrp ) ) {
|
2006-08-26 23:15:20 +02:00
|
|
|
redraw =
|
|
|
|
server_receiveMessage(globals->cGlobals.game.server,
|
|
|
|
inboundS );
|
2005-03-06 19:07:00 +01:00
|
|
|
}
|
|
|
|
stream_destroy( inboundS );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2005-03-06 19:07:00 +01:00
|
|
|
/* if there's something to draw resulting from the message, we
|
|
|
|
need to give the main loop time to reflect that on the screen
|
|
|
|
before giving the server another shot. So just call the idle
|
|
|
|
proc. */
|
|
|
|
if ( redraw ) {
|
|
|
|
gtk_util_requestTime( globals->cGlobals.params->util );
|
|
|
|
} else {
|
|
|
|
redraw = server_do( globals->cGlobals.game.server );
|
|
|
|
}
|
|
|
|
if ( redraw ) {
|
|
|
|
board_draw( globals->cGlobals.game.board );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} else {
|
2005-03-06 19:07:00 +01:00
|
|
|
XP_LOGF( "errno from read: %d", errno );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-09-08 09:23:19 +02:00
|
|
|
keepSource = TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-09-08 09:23:19 +02:00
|
|
|
return keepSource; /* FALSE means to remove event source */
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* newConnectionInput */
|
|
|
|
|
2007-11-26 03:58:25 +01:00
|
|
|
typedef struct SockInfo {
|
|
|
|
GIOChannel* channel;
|
|
|
|
guint watch;
|
|
|
|
int socket;
|
|
|
|
} SockInfo;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-03-19 23:07:53 +01:00
|
|
|
static void
|
2007-11-26 03:58:25 +01:00
|
|
|
gtk_socket_changed( void* closure, int oldSock, int newSock, void** storage )
|
2005-03-19 23:07:53 +01:00
|
|
|
{
|
|
|
|
GtkAppGlobals* globals = (GtkAppGlobals*)closure;
|
2007-11-26 03:58:25 +01:00
|
|
|
SockInfo* info = (SockInfo*)*storage;
|
|
|
|
XP_LOGF( "%s(old:%d; new:%d)", __func__, oldSock, newSock );
|
2006-09-08 09:23:19 +02:00
|
|
|
|
2005-03-19 23:07:53 +01:00
|
|
|
if ( oldSock != -1 ) {
|
2007-11-26 03:58:25 +01:00
|
|
|
XP_ASSERT( info != NULL );
|
|
|
|
g_source_remove( info->watch );
|
|
|
|
g_io_channel_unref( info->channel );
|
|
|
|
XP_FREE( globals->cGlobals.params->util->mpool, info );
|
|
|
|
*storage = NULL;
|
|
|
|
XP_LOGF( "Removed socket %d from gtk's list of listened-to sockets", oldSock );
|
2005-03-19 23:07:53 +01:00
|
|
|
}
|
|
|
|
if ( newSock != -1 ) {
|
2007-11-26 03:58:25 +01:00
|
|
|
info = (SockInfo*)XP_MALLOC( globals->cGlobals.params->util->mpool,
|
|
|
|
sizeof(*info) );
|
|
|
|
GIOChannel* channel = g_io_channel_unix_new( newSock );
|
|
|
|
g_io_channel_set_close_on_unref( channel, TRUE );
|
|
|
|
guint result = g_io_add_watch( channel,
|
|
|
|
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI,
|
|
|
|
newConnectionInput,
|
|
|
|
globals );
|
|
|
|
info->channel = channel;
|
|
|
|
info->watch = result;
|
|
|
|
*storage = info;
|
|
|
|
XP_LOGF( "g_io_add_watch(%d) => %d", newSock, result );
|
2005-03-19 23:07:53 +01:00
|
|
|
}
|
2007-11-26 03:58:25 +01:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2006-08-26 23:15:20 +02:00
|
|
|
globals->cGlobals.socket = newSock;
|
2007-11-26 03:58:25 +01:00
|
|
|
#endif
|
2006-11-11 23:44:31 +01:00
|
|
|
/* A hack for the bluetooth case. */
|
|
|
|
CommsCtxt* comms = globals->cGlobals.game.comms;
|
2007-11-26 03:58:25 +01:00
|
|
|
if ( (comms != NULL) && (comms_getConType(comms) == COMMS_CONN_BT) ) {
|
2006-11-11 23:44:31 +01:00
|
|
|
comms_resendAll( comms );
|
|
|
|
}
|
2007-11-26 03:58:25 +01:00
|
|
|
LOG_RETURN_VOID();
|
2005-03-19 23:07:53 +01:00
|
|
|
}
|
|
|
|
|
2006-09-10 21:01:06 +02:00
|
|
|
static gboolean
|
|
|
|
acceptorInput( GIOChannel* source, GIOCondition condition, gpointer data )
|
|
|
|
{
|
|
|
|
gboolean keepSource;
|
|
|
|
CommonGlobals* globals = (CommonGlobals*)data;
|
|
|
|
LOG_FUNC();
|
|
|
|
|
|
|
|
if ( (condition & G_IO_IN) != 0 ) {
|
|
|
|
int listener = g_io_channel_unix_get_fd( source );
|
2007-11-19 00:43:27 +01:00
|
|
|
XP_LOGF( "%s: input on socket %d", __func__, listener );
|
2006-09-10 21:01:06 +02:00
|
|
|
keepSource = (*globals->acceptor)( listener, data );
|
|
|
|
} else {
|
|
|
|
keepSource = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keepSource;
|
2007-11-28 04:59:26 +01:00
|
|
|
} /* acceptorInput */
|
2006-09-10 21:01:06 +02:00
|
|
|
|
|
|
|
static void
|
2007-11-28 04:59:26 +01:00
|
|
|
gtk_socket_acceptor( int listener, Acceptor func, CommonGlobals* globals,
|
|
|
|
void** storage )
|
2006-09-10 21:01:06 +02:00
|
|
|
{
|
2007-11-28 04:59:26 +01:00
|
|
|
SockInfo* info = (SockInfo*)*storage;
|
2006-09-10 21:01:06 +02:00
|
|
|
GIOChannel* channel;
|
2007-11-28 04:59:26 +01:00
|
|
|
guint watch;
|
2006-09-10 21:01:06 +02:00
|
|
|
|
|
|
|
LOG_FUNC();
|
|
|
|
|
2007-11-28 04:59:26 +01:00
|
|
|
if ( listener == -1 ) {
|
|
|
|
XP_ASSERT( !!globals->acceptor );
|
|
|
|
globals->acceptor = NULL;
|
|
|
|
XP_ASSERT( !!info );
|
|
|
|
int oldSock = info->socket;
|
|
|
|
g_source_remove( info->watch );
|
|
|
|
g_io_channel_unref( info->channel );
|
|
|
|
XP_FREE( globals->params->util->mpool, info );
|
|
|
|
*storage = NULL;
|
|
|
|
XP_LOGF( "Removed listener %d from gtk's list of listened-to sockets", oldSock );
|
|
|
|
} else {
|
|
|
|
XP_ASSERT( !globals->acceptor || (func == globals->acceptor) );
|
|
|
|
globals->acceptor = func;
|
2006-09-10 21:01:06 +02:00
|
|
|
|
2007-11-28 04:59:26 +01:00
|
|
|
channel = g_io_channel_unix_new( listener );
|
|
|
|
g_io_channel_set_close_on_unref( channel, TRUE );
|
|
|
|
watch = g_io_add_watch( channel,
|
|
|
|
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI,
|
|
|
|
acceptorInput, globals );
|
|
|
|
g_io_channel_unref( channel ); /* only main loop holds it now */
|
2007-12-02 20:13:25 +01:00
|
|
|
XP_LOGF( "%s: g_io_add_watch(%d) => %d", __func__, listener, watch );
|
2007-11-28 04:59:26 +01:00
|
|
|
|
|
|
|
XP_ASSERT( NULL == info );
|
|
|
|
info = XP_MALLOC( globals->params->util->mpool, sizeof(*info) );
|
|
|
|
info->channel = channel;
|
|
|
|
info->watch = watch;
|
|
|
|
info->socket = listener;
|
|
|
|
*storage = info;
|
|
|
|
}
|
|
|
|
} /* gtk_socket_acceptor */
|
2006-09-10 21:01:06 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
|
|
|
sendOnClose( XWStreamCtxt* stream, void* closure )
|
|
|
|
{
|
|
|
|
XP_S16 result;
|
|
|
|
GtkAppGlobals* globals = closure;
|
|
|
|
|
|
|
|
XP_LOGF( "sendOnClose called" );
|
2005-03-19 23:07:53 +01:00
|
|
|
result = comms_send( globals->cGlobals.game.comms, stream );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* sendOnClose */
|
|
|
|
|
|
|
|
static void
|
|
|
|
drop_msg_toggle( GtkWidget* toggle, GtkAppGlobals* globals )
|
|
|
|
{
|
|
|
|
globals->dropIncommingMsgs = gtk_toggle_button_get_active(
|
|
|
|
GTK_TOGGLE_BUTTON(toggle) );
|
|
|
|
} /* drop_msg_toggle */
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
int
|
2006-08-16 15:44:44 +02:00
|
|
|
gtkmain( LaunchParams* params, int argc, char *argv[] )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
short width, height;
|
|
|
|
GtkWidget* window;
|
|
|
|
GtkWidget* drawing_area;
|
|
|
|
GtkWidget* menubar;
|
|
|
|
GtkWidget* buttonbar;
|
|
|
|
GtkWidget* vbox;
|
|
|
|
GtkWidget* hbox;
|
|
|
|
GtkAppGlobals globals;
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
GtkWidget* dropCheck;
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
memset( &globals, 0, sizeof(globals) );
|
|
|
|
|
|
|
|
globals.cGlobals.params = params;
|
2003-11-30 20:08:55 +01:00
|
|
|
globals.cGlobals.lastNTilesToUse = MAX_TRAY_TILES;
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
# ifdef XWFEATURE_RELAY
|
2005-03-06 19:07:00 +01:00
|
|
|
globals.cGlobals.socket = -1;
|
2008-01-19 17:03:53 +01:00
|
|
|
# endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-03-19 23:07:53 +01:00
|
|
|
globals.cGlobals.socketChanged = gtk_socket_changed;
|
|
|
|
globals.cGlobals.socketChangedClosure = &globals;
|
2006-09-10 21:01:06 +02:00
|
|
|
globals.cGlobals.addAcceptor = gtk_socket_acceptor;
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2005-03-19 23:07:53 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
globals.cp.showBoardArrow = XP_TRUE;
|
|
|
|
globals.cp.showRobotScores = params->showRobotScores;
|
|
|
|
|
|
|
|
setupGtkUtilCallbacks( &globals, params->util );
|
|
|
|
|
|
|
|
/* globals.dictionary = params->dict; */
|
|
|
|
/* globals.trayOverlaps = params->trayOverlaps; */
|
|
|
|
/* globals.askNewGame = params->askNewGame; */
|
|
|
|
/* globals.quitWhenDone = params->quitAfter; */
|
|
|
|
/* globals.sleepOnAnchor = params->sleepOnAnchor; */
|
|
|
|
/* globals.util = params->util; */
|
|
|
|
/* globals.fileName = params->fileName; */
|
|
|
|
|
|
|
|
/* globals.listenPort = params->listenPort; */
|
|
|
|
|
|
|
|
/* Now set up the gtk stuff. This is necessary before we make the
|
|
|
|
draw ctxt */
|
|
|
|
gtk_init( &argc, &argv );
|
|
|
|
|
|
|
|
globals.window = window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
|
|
|
if ( !!params->fileName ) {
|
|
|
|
gtk_window_set_title( GTK_WINDOW(window), params->fileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add( GTK_CONTAINER(window), vbox );
|
|
|
|
gtk_widget_show( vbox );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
g_signal_connect( G_OBJECT (window), "destroy",
|
|
|
|
G_CALLBACK( quit ), &globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
menubar = makeMenus( &globals, argc, argv );
|
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
|
|
|
|
|
2008-01-19 17:03:53 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-05-29 22:37:35 +02:00
|
|
|
dropCheck = gtk_check_button_new_with_label( "drop incoming messages" );
|
|
|
|
g_signal_connect( GTK_OBJECT(dropCheck),
|
|
|
|
"toggled", G_CALLBACK(drop_msg_toggle), &globals );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), dropCheck, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show( dropCheck );
|
2008-01-19 17:03:53 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
buttonbar = makeButtons( &globals, argc, argv );
|
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), buttonbar, FALSE, TRUE, 0);
|
|
|
|
|
|
|
|
drawing_area = gtk_drawing_area_new();
|
2005-05-29 22:37:35 +02:00
|
|
|
globals.drawing_area = drawing_area;
|
|
|
|
gtk_widget_show( drawing_area );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-10 01:51:20 +01:00
|
|
|
width = GTK_HOR_SCORE_WIDTH + GTK_TIMER_WIDTH + GTK_TIMER_PAD;
|
2006-05-09 14:31:41 +02:00
|
|
|
if ( globals.cGlobals.params->verticalScore ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
width += GTK_VERT_SCORE_WIDTH;
|
2006-05-09 14:31:41 +02:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
height = 196;
|
2006-05-17 08:10:24 +02:00
|
|
|
if ( globals.cGlobals.params->nHidden == 0 ) {
|
2008-03-10 01:51:20 +01:00
|
|
|
height += GTK_MIN_SCALE * GTK_TRAY_HT_ROWS;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-05-19 15:44:05 +02:00
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
gtk_widget_set_size_request( GTK_WIDGET(drawing_area), width, height );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new( FALSE, 0 );
|
2005-05-29 22:37:35 +02:00
|
|
|
gtk_box_pack_start( GTK_BOX (hbox), drawing_area, TRUE, TRUE, 0);
|
2006-05-14 17:26:21 +02:00
|
|
|
|
2006-05-17 08:10:24 +02:00
|
|
|
if ( globals.cGlobals.params->nHidden != 0 ) {
|
2006-05-14 17:26:21 +02:00
|
|
|
GtkWidget* vscrollbar;
|
2006-05-17 08:10:24 +02:00
|
|
|
globals.adjustment =
|
2008-03-10 01:51:20 +01:00
|
|
|
(GtkAdjustment*)gtk_adjustment_new( 0, 0, GTK_NUM_ROWS, 1, 2,
|
|
|
|
GTK_NUM_ROWS-globals.cGlobals.params->nHidden );
|
2006-05-14 17:26:21 +02:00
|
|
|
vscrollbar = gtk_vscrollbar_new( globals.adjustment );
|
|
|
|
g_signal_connect( GTK_OBJECT(globals.adjustment), "value_changed",
|
|
|
|
G_CALLBACK(scroll_value_changed), &globals );
|
|
|
|
|
|
|
|
gtk_widget_show( vscrollbar );
|
|
|
|
gtk_box_pack_start( GTK_BOX(hbox), vscrollbar, TRUE, TRUE, 0 );
|
|
|
|
}
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
gtk_box_pack_start( GTK_BOX (hbox),
|
|
|
|
makeVerticalBar( &globals, window ),
|
|
|
|
FALSE, TRUE, 0 );
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_widget_show( hbox );
|
|
|
|
|
2005-05-29 22:37:35 +02:00
|
|
|
gtk_box_pack_start( GTK_BOX(vbox), hbox/* drawing_area */, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
g_signal_connect( GTK_OBJECT(drawing_area), "expose_event",
|
|
|
|
G_CALLBACK(expose_event), &globals );
|
|
|
|
g_signal_connect( GTK_OBJECT(drawing_area),"configure_event",
|
|
|
|
G_CALLBACK(configure_event), &globals );
|
|
|
|
g_signal_connect( GTK_OBJECT(drawing_area), "button_press_event",
|
|
|
|
G_CALLBACK(button_press_event), &globals );
|
|
|
|
g_signal_connect( GTK_OBJECT(drawing_area), "motion_notify_event",
|
|
|
|
G_CALLBACK(motion_notify_event), &globals );
|
|
|
|
g_signal_connect( GTK_OBJECT(drawing_area), "button_release_event",
|
|
|
|
G_CALLBACK(button_release_event), &globals );
|
|
|
|
|
2007-01-07 02:01:20 +01:00
|
|
|
#ifdef KEY_SUPPORT
|
|
|
|
# ifdef KEYBOARD_NAV
|
2007-01-06 18:46:02 +01:00
|
|
|
g_signal_connect( GTK_OBJECT(window), "key_press_event",
|
|
|
|
G_CALLBACK(key_press_event), &globals );
|
2007-01-07 02:01:20 +01:00
|
|
|
# endif
|
2005-05-29 22:37:35 +02:00
|
|
|
g_signal_connect( GTK_OBJECT(window), "key_release_event",
|
|
|
|
G_CALLBACK(key_release_event), &globals );
|
2007-01-07 02:01:20 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
gtk_widget_set_events( drawing_area, GDK_EXPOSURE_MASK
|
|
|
|
| GDK_LEAVE_NOTIFY_MASK
|
|
|
|
| GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_POINTER_MOTION_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK
|
2007-01-07 02:01:20 +01:00
|
|
|
#ifdef KEY_SUPPORT
|
|
|
|
# ifdef KEYBOARD_NAV
|
2003-11-01 06:35:29 +01:00
|
|
|
| GDK_KEY_PRESS_MASK
|
2007-01-07 02:01:20 +01:00
|
|
|
# endif
|
2003-11-01 06:35:29 +01:00
|
|
|
| GDK_KEY_RELEASE_MASK
|
2007-01-07 02:01:20 +01:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
/* | GDK_POINTER_MOTION_HINT_MASK */
|
|
|
|
);
|
|
|
|
|
|
|
|
gtk_widget_show( window );
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
/* MONCONTROL(1); */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} /* gtkmain */
|
|
|
|
|
|
|
|
#endif /* PLATFORM_GTK */
|