2003-11-20 17:26:35 +01:00
|
|
|
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2004-02-27 07:13:45 +01:00
|
|
|
* Copyright 2002-2004 by Eric House (fixin@peak.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
|
2004-02-28 06:21:26 +01:00
|
|
|
stuffTextInField( HWND hDlg, StrBoxInit* init )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2004-02-28 06:21:26 +01:00
|
|
|
XP_U16 nBytes = stream_getSize(init->stream);
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 len;
|
|
|
|
XP_UCHAR* sbuf;
|
|
|
|
wchar_t* wbuf;
|
2004-02-28 06:21:26 +01:00
|
|
|
CEAppGlobals* globals = init->globals;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
sbuf = XP_MALLOC( globals->mpool, nBytes );
|
2004-02-28 06:21:26 +01:00
|
|
|
stream_getBytes( init->stream, sbuf, nBytes );
|
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) );
|
|
|
|
XP_MEMSET( wbuf, 0, (len+1) * sizeof(*wbuf) );
|
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, sbuf, nBytes,
|
|
|
|
wbuf, len );
|
|
|
|
XP_FREE( globals->mpool, sbuf );
|
|
|
|
|
|
|
|
SetDlgItemText( hDlg, ID_EDITTEXT, wbuf );
|
2004-02-27 07:13:45 +01:00
|
|
|
XP_FREE( globals->mpool, wbuf );
|
2004-02-14 07:07:52 +01:00
|
|
|
|
|
|
|
/* This isn't working to stop the highlighting of text */
|
2004-02-27 07:13:45 +01:00
|
|
|
SendDlgItemMessage( hDlg, ID_EDITTEXT, EM_SETSEL, -1, 0L );
|
|
|
|
XP_LOGF( "called SendDlgItemMessage with -1" );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* stuffTextInField */
|
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = NULL;
|
|
|
|
StrBoxInit* init;
|
|
|
|
XP_U16 id;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
2004-02-14 07:07:52 +01:00
|
|
|
SetWindowLong( hDlg, GWL_USERDATA, (long)lParam );
|
2003-11-20 17:26:35 +01:00
|
|
|
init = (StrBoxInit*)lParam;
|
|
|
|
|
|
|
|
globals = init->globals;
|
|
|
|
|
|
|
|
if ( !!init->title ) {
|
|
|
|
SendMessage( hDlg, WM_SETTEXT, 0, (long)init->title );
|
|
|
|
}
|
|
|
|
|
2004-02-14 07:07:52 +01:00
|
|
|
if ( !init->isQuery ) {
|
|
|
|
ceShowOrHide( hDlg, IDCANCEL, XP_FALSE );
|
|
|
|
/* also want to expand the text box to the bottom */
|
|
|
|
/* ceCenterCtl( hDlg, IDOK ); */
|
|
|
|
}
|
2004-02-28 06:21:26 +01:00
|
|
|
init->textIsSet = XP_FALSE; /* postpone to avoid highlight. */
|
2004-02-14 07:07:52 +01:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2004-02-14 07:07:52 +01:00
|
|
|
init = (StrBoxInit*)GetWindowLong( hDlg, GWL_USERDATA );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
switch (message) {
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
2004-02-28 06:21:26 +01:00
|
|
|
if ( !init->textIsSet ) {
|
|
|
|
stuffTextInField( hDlg, init );
|
|
|
|
init->textIsSet = XP_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
id = LOWORD(wParam);
|
|
|
|
switch( id ) {
|
|
|
|
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
2004-02-14 07:07:52 +01:00
|
|
|
init->result = id;
|
2003-11-20 17:26:35 +01:00
|
|
|
EndDialog(hDlg, id);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
} /* StrBox */
|