xwords/wince/cestrbx.c

118 lines
3.8 KiB
C
Raw Normal View History

/* -*- fill-column: 77; c-basic-offset: 4; compile-command: "make TARGET_OS=wince DEBUG=TRUE" -*- */
2003-11-20 17:26:35 +01:00
/*
* Copyright 2002-2006 by Eric House (xwords@eehouse.org). All rights reserved.
2003-11-20 17:26:35 +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.
*/
#include "cestrbx.h"
#include "cemain.h"
#include "ceutil.h"
static void
stuffTextInField( HWND hDlg, StrBoxState* state )
2003-11-20 17:26:35 +01:00
{
XP_U16 nBytes = stream_getSize(state->stream);
XP_U16 len, crlen;
2003-11-20 17:26:35 +01:00
XP_UCHAR* sbuf;
wchar_t* wbuf;
#ifdef MEM_DEBUG
CEAppGlobals* globals = state->dlgHdr.globals;
#endif
2003-11-20 17:26:35 +01:00
sbuf = XP_MALLOC( globals->mpool, nBytes + 1 );
stream_getBytes( state->stream, sbuf, nBytes );
2003-11-20 17:26:35 +01:00
crlen = strlen(XP_CR);
if ( 0 == strncmp( XP_CR, &sbuf[nBytes-crlen], crlen ) ) {
nBytes -= crlen;
}
sbuf[nBytes] = '\0';
2003-11-20 17:26:35 +01:00
len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, sbuf, nBytes,
NULL, 0 );
wbuf = XP_MALLOC( globals->mpool, (len+1) * sizeof(*wbuf) );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, sbuf, nBytes,
wbuf, len );
XP_FREE( globals->mpool, sbuf );
wbuf[len] = 0;
2003-11-20 17:26:35 +01:00
SetDlgItemText( hDlg, ID_EDITTEXT, wbuf );
2004-02-27 07:13:45 +01:00
XP_FREE( globals->mpool, wbuf );
2003-11-20 17:26:35 +01:00
} /* stuffTextInField */
LRESULT CALLBACK
StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT handled = FALSE;
StrBoxState* state;
2003-11-20 17:26:35 +01:00
XP_U16 id;
if ( message == WM_INITDIALOG ) {
SetWindowLongPtr( hDlg, GWL_USERDATA, (long)lParam );
state = (StrBoxState*)lParam;
2003-11-20 17:26:35 +01:00
if ( !!state->title ) {
SendMessage( hDlg, WM_SETTEXT, 0, (long)state->title );
2003-11-20 17:26:35 +01:00
}
if ( !state->isQuery ) {
2004-02-14 07:07:52 +01:00
ceShowOrHide( hDlg, IDCANCEL, XP_FALSE );
/* also want to expand the text box to the bottom */
/* ceIsLandscape() is going away.... */
/* if ( !ceIsLandscape( state->dlgHdr.globals ) ) { */
/* ceCenterCtl( hDlg, IDOK ); */
/* } */
2004-02-14 07:07:52 +01:00
}
ceDlgSetup( &state->dlgHdr, hDlg,
state->isQuery? DLG_STATE_NONE : DLG_STATE_OKONLY );
handled = TRUE;
2003-11-20 17:26:35 +01:00
} else {
state = (StrBoxState*)GetWindowLongPtr( hDlg, GWL_USERDATA );
if ( !!state ) {
if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) {
handled = TRUE;
} else {
switch (message) {
case WM_COMMAND:
/* If I add the text above in the WM_INITDIALOG section it
shows up selected though selStart and selEnd are 0. */
if ( !state->textIsSet ) {
state->textIsSet = XP_TRUE;
stuffTextInField( hDlg, state );
}
id = LOWORD(wParam);
switch( id ) {
case IDOK:
case IDCANCEL:
state->result = id;
EndDialog(hDlg, id);
handled = TRUE;
}
break;
2004-05-26 06:46:57 +02:00
}
2003-11-20 17:26:35 +01:00
}
}
}
return handled;
2003-11-20 17:26:35 +01:00
} /* StrBox */