Break blank dialog out of palmmain and replace old macros in palmbt so

can compile debug 68K version again.  Organizational change only, no
code/behavior.
This commit is contained in:
ehouse 2009-09-28 03:59:59 +00:00
parent c2dd21fc4a
commit e1eac23a3c
5 changed files with 198 additions and 146 deletions

View file

@ -221,6 +221,7 @@ OBJS_68K = $(PLATFORM)/palmmain.o \
$(PLATFORM)/palmbt.o \
$(PLATFORM)/prefsdlg.o \
$(PLATFORM)/connsdlg.o \
$(PLATFORM)/palmblnk.o \
$(PLATFORM)/palmdbg.o \
$(COMMONOBJ)

160
xwords4/palm/palmblnk.c Normal file
View file

@ -0,0 +1,160 @@
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; compile-command: "make ARCH=ARM_ONLY MEMDEBUG=TRUE"; -*- */
/*
* Copyright 1999 - 2009 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* 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.
*/
#include "palmutil.h"
#include "LocalizedStrIncludes.h"
static Boolean
handleKeysInBlank( EventPtr event )
{
Boolean handled = false;
if ( event->eType == keyDownEvent ) {
char ch = event->data.keyDown.chr;
if ( ch >= 'a' && ch <= 'z' ) {
ch += 'A' - 'a';
}
if ( ch >= 'A' && ch <= 'Z' ) {
ListPtr lettersList = getActiveObjectPtr( XW_BLANK_LIST_ID );
XP_U16 nItems;
XP_U16 ii;
XP_ASSERT( !!lettersList );
nItems = LstGetNumberOfItems( lettersList );
for ( ii = 0; ii < nItems; ++ii ) {
XP_UCHAR* itext = LstGetSelectionText( lettersList, ii );
if ( !!itext && (itext[0] == ch) ) {
LstSetSelection( lettersList, ii );
LstMakeItemVisible( lettersList, ii );
handled = true;
break;
}
}
} else if ( ch == '\n' ) {
EventType eventToPost;
eventToPost.eType = ctlSelectEvent;
eventToPost.data.ctlSelect.controlID = XW_BLANK_OK_BUTTON_ID;
eventToPost.data.ctlSelect.pControl =
getActiveObjectPtr( XW_BLANK_OK_BUTTON_ID );
EvtAddEventToQueue( &eventToPost );
}
}
return handled;
} /* handleKeysInBlank */
XP_S16
askBlankValue( PalmAppGlobals* globals, XP_U16 playerNum, const PickInfo* pi,
XP_U16 nTiles, const XP_UCHAR** texts )
{
FormPtr form, prevForm;
ListPtr lettersList;
ListData ld;
XP_U16 i;
XP_S16 chosen;
XP_UCHAR labelBuf[96];
XP_UCHAR* name;
const XP_UCHAR* labelFmt;
FieldPtr fld;
XP_U16 tapped;
#ifdef FEATURE_TRAY_EDIT
XP_Bool forBlank = pi->why == PICK_FOR_BLANK;
#endif
initListData( MEMPOOL &ld, nTiles );
for ( i = 0; i < nTiles; ++i ) {
addListTextItem( MEMPOOL &ld, texts[i] );
}
prevForm = FrmGetActiveForm();
form = FrmInitForm( XW_BLANK_DIALOG_ID );
FrmSetActiveForm( form );
#ifdef FEATURE_TRAY_EDIT
disOrEnable( form, XW_BLANK_PICK_BUTTON_ID, !forBlank );
disOrEnable( form, XW_BLANK_BACKUP_BUTTON_ID,
!forBlank && pi->thisPick > 0 );
#endif
lettersList = getActiveObjectPtr( XW_BLANK_LIST_ID );
setListChoices( &ld, lettersList, NULL );
LstSetSelection( lettersList, 0 );
name = globals->gameInfo.players[playerNum].name;
labelFmt = getResString( globals,
#ifdef FEATURE_TRAY_EDIT
!forBlank? STRS_PICK_TILE:
#endif
STR_PICK_BLANK );
XP_SNPRINTF( labelBuf, sizeof(labelBuf), labelFmt, name );
#ifdef FEATURE_TRAY_EDIT
if ( !forBlank ) {
const char* cur = getResString( globals, STR_PICK_TILE_CUR );
XP_U16 lenSoFar;
XP_U16 i;
lenSoFar = XP_STRLEN(labelBuf);
lenSoFar += XP_SNPRINTF( labelBuf + lenSoFar,
sizeof(labelBuf) - lenSoFar,
" (%d/%d)\n%s", pi->thisPick+1, pi->nTotal,
cur );
for ( i = 0; i < pi->nCurTiles; ++i ) {
lenSoFar += XP_SNPRINTF( labelBuf+lenSoFar,
sizeof(labelBuf)-lenSoFar, "%s%s",
i==0?": ":", ", pi->curTiles[i] );
}
}
#endif
fld = getActiveObjectPtr( XW_BLANK_LABEL_FIELD_ID );
FldSetTextPtr( fld, labelBuf );
FldRecalculateField( fld, false );
FrmDrawForm( form );
FrmSetEventHandler( form, handleKeysInBlank );
tapped = FrmDoDialog( form );
if ( 0 ) {
#ifdef FEATURE_TRAY_EDIT
} else if ( tapped == XW_BLANK_PICK_BUTTON_ID ) {
chosen = PICKER_PICKALL;
} else if ( tapped == XW_BLANK_BACKUP_BUTTON_ID ) {
chosen = PICKER_BACKUP;
#endif
} else {
chosen = LstGetSelection( lettersList );
}
FrmDeleteForm( form );
FrmSetActiveForm( prevForm );
freeListData( MEMPOOL &ld );
return chosen;
} /* askBlankValue */

28
xwords4/palm/palmblnk.h Normal file
View file

@ -0,0 +1,28 @@
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
/*
* Copyright 2001-2009 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* 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.
*/
#ifndef _PALMBLNK_H_
#define _PALMBLNK_H_
XP_S16
askBlankValue( PalmAppGlobals* globals, XP_U16 playerNum, const PickInfo* pi,
XP_U16 nTiles, const XP_UCHAR** texts );
#endif

View file

@ -366,7 +366,7 @@ palm_bt_getStats( PalmAppGlobals* globals, XWStreamCtxt* stream )
{
PalmBTStuff* btStuff = globals->btStuff;
if ( !btStuff ) {
stream_putString( stream, "bt not initialized" );
stream_catString( stream, "bt not initialized" );
} else {
char buf[64];
XP_U16 cur;
@ -374,29 +374,29 @@ palm_bt_getStats( PalmAppGlobals* globals, XWStreamCtxt* stream )
XP_SNPRINTF( buf, sizeof(buf), "Role: %s\n",
btStuff->picoRole == PBT_MASTER? "master":
(btStuff->picoRole == PBT_SLAVE? "slave":"unknown") );
stream_putString( stream, buf );
stream_catString( stream, buf );
XP_SNPRINTF( buf, sizeof(buf), "State: %s\n",
stateToStr( GET_STATE(btStuff)) );
stream_putString( stream, buf );
stream_catString( stream, buf );
XP_SNPRINTF( buf, sizeof(buf), "%d actions queued:\n",
btStuff->queueLen );
stream_putString( stream, buf );
stream_catString( stream, buf );
for ( cur = 0; cur < btStuff->queueLen; ++cur ) {
XP_SNPRINTF( buf, sizeof(buf), " - %s\n",
actToStr( btStuff->actQueue[cur] ) );
stream_putString( stream, buf );
stream_catString( stream, buf );
}
XP_SNPRINTF( buf, sizeof(buf), "total sent: %ld\n",
btStuff->stats.totalSent );
stream_putString( stream, buf );
stream_catString( stream, buf );
XP_SNPRINTF( buf, sizeof(buf), "total rcvd: %ld\n",
btStuff->stats.totalRcvd );
stream_putString( stream, buf );
stream_catString( stream, buf );
XP_SNPRINTF( buf, sizeof(buf), "max act queue len seen: %d\n",
btStuff->stats.maxQueueLen );
stream_putString( stream, buf );
stream_catString( stream, buf );
}
}
#endif

View file

@ -62,6 +62,7 @@
#include "connsdlg.h"
#include "gameutil.h"
#include "dictui.h"
#include "palmblnk.h"
#include "LocalizedStrIncludes.h"
#ifdef XWFEATURE_FIVEWAY
@ -3518,144 +3519,6 @@ askPassword( PalmAppGlobals* globals, const XP_UCHAR* name, XP_Bool isNew,
return result;
} /* askPassword */
static Boolean
handleKeysInBlank( EventPtr event )
{
Boolean handled = false;
if ( event->eType == keyDownEvent ) {
char ch = event->data.keyDown.chr;
if ( ch >= 'a' && ch <= 'z' ) {
ch += 'A' - 'a';
}
if ( ch >= 'A' && ch <= 'Z' ) {
ListPtr lettersList = getActiveObjectPtr( XW_BLANK_LIST_ID );
XP_U16 nItems;
XP_U16 i;
XP_ASSERT( !!lettersList );
nItems = LstGetNumberOfItems( lettersList );
for ( i = 0; i < nItems; ++i ) {
XP_UCHAR* itext = LstGetSelectionText( lettersList, i );
if ( !!itext && (itext[0] == ch) ) {
LstSetSelection( lettersList, i );
LstMakeItemVisible( lettersList, i );
handled = true;
break;
}
}
} else if ( ch == '\n' ) {
EventType eventToPost;
eventToPost.eType = ctlSelectEvent;
eventToPost.data.ctlSelect.controlID = XW_BLANK_OK_BUTTON_ID;
eventToPost.data.ctlSelect.pControl =
getActiveObjectPtr( XW_BLANK_OK_BUTTON_ID );
EvtAddEventToQueue( &eventToPost );
}
}
return handled;
} /* handleKeysInBlank */
static XP_S16
askBlankValue( PalmAppGlobals* globals, XP_U16 playerNum, const PickInfo* pi,
XP_U16 nTiles, const XP_UCHAR** texts )
{
FormPtr form, prevForm;
ListPtr lettersList;
ListData ld;
XP_U16 i;
XP_S16 chosen;
XP_UCHAR labelBuf[96];
XP_UCHAR* name;
const XP_UCHAR* labelFmt;
FieldPtr fld;
XP_U16 tapped;
#ifdef FEATURE_TRAY_EDIT
XP_Bool forBlank = pi->why == PICK_FOR_BLANK;
#endif
initListData( MEMPOOL &ld, nTiles );
for ( i = 0; i < nTiles; ++i ) {
addListTextItem( MEMPOOL &ld, texts[i] );
}
prevForm = FrmGetActiveForm();
form = FrmInitForm( XW_BLANK_DIALOG_ID );
FrmSetActiveForm( form );
#ifdef FEATURE_TRAY_EDIT
disOrEnable( form, XW_BLANK_PICK_BUTTON_ID, !forBlank );
disOrEnable( form, XW_BLANK_BACKUP_BUTTON_ID,
!forBlank && pi->thisPick > 0 );
#endif
lettersList = getActiveObjectPtr( XW_BLANK_LIST_ID );
setListChoices( &ld, lettersList, NULL );
LstSetSelection( lettersList, 0 );
name = globals->gameInfo.players[playerNum].name;
labelFmt = getResString( globals,
#ifdef FEATURE_TRAY_EDIT
!forBlank? STRS_PICK_TILE:
#endif
STR_PICK_BLANK );
XP_SNPRINTF( labelBuf, sizeof(labelBuf), labelFmt, name );
#ifdef FEATURE_TRAY_EDIT
if ( !forBlank ) {
const char* cur = getResString( globals, STR_PICK_TILE_CUR );
XP_U16 lenSoFar;
XP_U16 i;
lenSoFar = XP_STRLEN(labelBuf);
lenSoFar += XP_SNPRINTF( labelBuf + lenSoFar,
sizeof(labelBuf) - lenSoFar,
" (%d/%d)\n%s", pi->thisPick+1, pi->nTotal,
cur );
for ( i = 0; i < pi->nCurTiles; ++i ) {
lenSoFar += XP_SNPRINTF( labelBuf+lenSoFar,
sizeof(labelBuf)-lenSoFar, "%s%s",
i==0?": ":", ", pi->curTiles[i] );
}
}
#endif
fld = getActiveObjectPtr( XW_BLANK_LABEL_FIELD_ID );
FldSetTextPtr( fld, labelBuf );
FldRecalculateField( fld, false );
FrmDrawForm( form );
FrmSetEventHandler( form, handleKeysInBlank );
tapped = FrmDoDialog( form );
if ( 0 ) {
#ifdef FEATURE_TRAY_EDIT
} else if ( tapped == XW_BLANK_PICK_BUTTON_ID ) {
chosen = PICKER_PICKALL;
} else if ( tapped == XW_BLANK_BACKUP_BUTTON_ID ) {
chosen = PICKER_BACKUP;
#endif
} else {
chosen = LstGetSelection( lettersList );
}
FrmDeleteForm( form );
FrmSetActiveForm( prevForm );
freeListData( MEMPOOL &ld );
return chosen;
} /* askBlankValue */
/*****************************************************************************
* Callbacks
****************************************************************************/