2006-05-25 05:41:32 +02:00
|
|
|
/* -*- fill-column: 77; c-basic-offset: 4; compile-command: "make TARGET_OS=wince DEBUG=TRUE" -*- */
|
2003-11-20 17:26:35 +01:00
|
|
|
/*
|
2009-10-25 16:00:06 +01:00
|
|
|
* Copyright 2002-2009 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.
|
|
|
|
*/
|
|
|
|
|
2009-10-01 06:15:18 +02:00
|
|
|
#include <windowsx.h>
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "cestrbx.h"
|
|
|
|
#include "cemain.h"
|
|
|
|
#include "ceutil.h"
|
2009-10-01 06:15:18 +02:00
|
|
|
#include "cedebug.h"
|
|
|
|
|
|
|
|
typedef struct StrBoxState {
|
|
|
|
CeDlgHdr dlgHdr;
|
|
|
|
const wchar_t* title;
|
2009-10-25 16:00:06 +01:00
|
|
|
#ifndef _WIN32_WCE
|
2009-10-01 06:15:18 +02:00
|
|
|
HFONT font;
|
2009-10-25 16:00:06 +01:00
|
|
|
#endif
|
2009-10-01 06:15:18 +02:00
|
|
|
XWStreamCtxt* stream;
|
|
|
|
XP_U16 result;
|
|
|
|
XP_Bool isQuery;
|
|
|
|
XP_Bool textIsSet;
|
|
|
|
} StrBoxState;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
static void
|
2008-06-05 06:29:28 +02:00
|
|
|
stuffTextInField( HWND hDlg, StrBoxState* state )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2008-06-05 06:29:28 +02:00
|
|
|
XP_U16 nBytes = stream_getSize(state->stream);
|
2006-05-23 04:01:26 +02:00
|
|
|
XP_U16 len, crlen;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_UCHAR* sbuf;
|
|
|
|
wchar_t* wbuf;
|
|
|
|
|
2009-12-03 04:05:35 +01:00
|
|
|
sbuf = XP_MALLOC( state->dlgHdr.globals->mpool, nBytes + 1 );
|
2008-06-05 06:29:28 +02:00
|
|
|
stream_getBytes( state->stream, sbuf, nBytes );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-05-23 04:01:26 +02:00
|
|
|
crlen = strlen(XP_CR);
|
|
|
|
if ( 0 == strncmp( XP_CR, &sbuf[nBytes-crlen], crlen ) ) {
|
|
|
|
nBytes -= crlen;
|
|
|
|
}
|
|
|
|
sbuf[nBytes] = '\0';
|
|
|
|
|
2009-10-17 06:14:01 +02:00
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, sbuf, nBytes, NULL, 0 );
|
2009-12-03 04:05:35 +01:00
|
|
|
wbuf = XP_MALLOC( state->dlgHdr.globals->mpool, (len+1) * sizeof(*wbuf) );
|
2009-10-17 06:14:01 +02:00
|
|
|
MultiByteToWideChar( CP_UTF8, 0, sbuf, nBytes, wbuf, len );
|
2009-12-04 03:19:58 +01:00
|
|
|
XP_FREE( state->dlgHdr.globals->mpool, sbuf );
|
2006-05-23 04:01:26 +02:00
|
|
|
wbuf[len] = 0;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
SetDlgItemText( hDlg, ID_EDITTEXT, wbuf );
|
2009-12-04 03:19:58 +01:00
|
|
|
XP_FREE( state->dlgHdr.globals->mpool, wbuf );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* stuffTextInField */
|
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2006-05-27 19:18:42 +02:00
|
|
|
LRESULT handled = FALSE;
|
2008-06-05 06:29:28 +02:00
|
|
|
StrBoxState* state;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 id;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
2008-09-27 17:05:26 +02:00
|
|
|
SetWindowLongPtr( hDlg, GWL_USERDATA, (long)lParam );
|
2008-06-05 06:29:28 +02:00
|
|
|
state = (StrBoxState*)lParam;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
if ( !!state->title ) {
|
|
|
|
SendMessage( hDlg, WM_SETTEXT, 0, (long)state->title );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2009-10-25 16:00:06 +01:00
|
|
|
#ifndef _WIN32_WCE
|
|
|
|
SendDlgItemMessage( hDlg, ID_EDITTEXT, WM_SETFONT,
|
2009-10-01 06:15:18 +02:00
|
|
|
(WPARAM)state->font, 0L );
|
2009-10-25 16:00:06 +01:00
|
|
|
#endif
|
2008-06-05 06:29:28 +02:00
|
|
|
if ( !state->isQuery ) {
|
2004-02-14 07:07:52 +01:00
|
|
|
ceShowOrHide( hDlg, IDCANCEL, XP_FALSE );
|
|
|
|
}
|
|
|
|
|
2008-12-07 17:24:26 +01:00
|
|
|
ceDlgSetup( &state->dlgHdr, hDlg,
|
2008-12-13 05:39:06 +01:00
|
|
|
state->isQuery? DLG_STATE_NONE : DLG_STATE_OKONLY );
|
2006-05-27 19:18:42 +02:00
|
|
|
|
|
|
|
handled = TRUE;
|
2003-11-20 17:26:35 +01:00
|
|
|
} else {
|
2008-09-27 17:05:26 +02:00
|
|
|
state = (StrBoxState*)GetWindowLongPtr( hDlg, GWL_USERDATA );
|
2008-06-05 06:29:28 +02:00
|
|
|
|
|
|
|
if ( !!state ) {
|
|
|
|
if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) {
|
|
|
|
handled = TRUE;
|
|
|
|
} else {
|
|
|
|
switch (message) {
|
|
|
|
|
2009-10-25 16:03:12 +01:00
|
|
|
case WM_COMMAND:
|
2008-06-05 06:29:28 +02:00
|
|
|
|
|
|
|
/* If I add the text above in the WM_INITDIALOG section it
|
|
|
|
shows up selected though selStart and selEnd are 0. */
|
2009-10-25 16:03:12 +01:00
|
|
|
if ( !state->textIsSet ) {
|
|
|
|
state->textIsSet = XP_TRUE;
|
|
|
|
stuffTextInField( hDlg, state );
|
|
|
|
}
|
2008-06-05 06:29:28 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-27 19:18:42 +02:00
|
|
|
return handled;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* StrBox */
|
2009-10-01 06:15:18 +02:00
|
|
|
|
|
|
|
XP_Bool
|
|
|
|
WrapStrBox( CEAppGlobals* globals, const wchar_t* title,
|
|
|
|
XWStreamCtxt* stream, XP_U16 buttons )
|
|
|
|
{
|
|
|
|
StrBoxState state;
|
|
|
|
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) );
|
|
|
|
|
|
|
|
state.title = title;
|
|
|
|
state.stream = stream;
|
|
|
|
state.isQuery = (buttons & ~MB_ICONMASK) != MB_OK;
|
|
|
|
state.dlgHdr.globals = globals;
|
|
|
|
|
2009-10-25 16:00:06 +01:00
|
|
|
#ifndef _WIN32_WCE
|
2009-10-01 06:15:18 +02:00
|
|
|
LOGFONT fontInfo;
|
|
|
|
XP_MEMSET( &fontInfo, 0, sizeof(fontInfo) );
|
|
|
|
fontInfo.lfHeight = 14;
|
|
|
|
fontInfo.lfQuality = PROOF_QUALITY;
|
|
|
|
wcscpy( fontInfo.lfFaceName, IS_SMARTPHONE(globals)?
|
|
|
|
L"Segoe Condensed" : L"Tahoma" );
|
|
|
|
state.font = CreateFontIndirect( &fontInfo );
|
2009-10-25 16:00:06 +01:00
|
|
|
#endif
|
2009-10-01 06:15:18 +02:00
|
|
|
|
|
|
|
assertOnTop( globals->hWnd );
|
|
|
|
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_STRBOX, globals->hWnd,
|
|
|
|
(DLGPROC)StrBox, (long)&state );
|
|
|
|
|
2009-10-25 16:00:06 +01:00
|
|
|
#ifndef _WIN32_WCE
|
2009-10-01 06:15:18 +02:00
|
|
|
DeleteObject( state.font );
|
2009-10-25 16:00:06 +01:00
|
|
|
#endif
|
2009-10-01 06:15:18 +02:00
|
|
|
|
|
|
|
return state.result == IDOK;
|
|
|
|
}
|