📄 wedit.c
字号:
lbox = GetDlgItem( einfo->edit_dlg, IDM_STREDLIST );
SendMessage( lbox, WM_SETREDRAW, FALSE, 0 );
SendMessage( lbox, LB_RESETCONTENT, 0, 0 );
block = einfo->tbl->first_block;
while( block && ok ) {
ok = WAddEditWinLBoxBlock( einfo, block, -1 );
block = block->next;
}
SendMessage( lbox, WM_SETREDRAW, TRUE, 0 );
}
return ( ok );
}
Bool WInitEditWindow( WStringEditInfo *einfo )
{
HWND lbox;
Bool ok;
uint_16 first_id;
ok = ( einfo && einfo->edit_dlg );
if ( ok ) {
ok = WInitEditWindowListBox ( einfo );
}
if ( ok ) {
if ( einfo->tbl->first_block ) {
ok = WGetFirstStringInBlock( einfo->tbl->first_block, &first_id );
}
}
if ( ok ) {
if ( einfo->tbl->first_block ) {
ok = WSetEditWindowStringData( einfo, einfo->tbl->first_block, first_id );
if ( ok ) {
lbox = GetDlgItem ( einfo->edit_dlg, IDM_STREDLIST );
ok = ( SendMessage ( lbox, LB_SETCURSEL, 0, 0 ) != LB_ERR );
einfo->current_block = einfo->tbl->first_block;
einfo->current_string = first_id;
einfo->current_pos = 0;
}
}
}
return ( ok );
}
Bool WIsCurrentModified( WStringEditInfo *einfo, char *text, uint_16 id,
char *symbol )
{
char *current_text;
char *s;
Bool mod;
mod = ( einfo && einfo->current_block && text );
if( mod ) {
current_text = WResIDNameToStr( einfo->current_block->block.String[ einfo->current_string & 0xf ] );
}
if( mod ) {
// make sure the symbol info did not change
s = einfo->current_block->symbol[ id & 0xf ];
mod = ( !s && symbol ) || ( s && !symbol );
if( !mod ) {
mod = symbol && stricmp( s, symbol );
if( !mod ) {
mod = ( ( id != einfo->current_string ) ||
( strcmp( text, current_text ) ) );
}
}
}
if( current_text ) {
WMemFree( current_text );
}
return( mod );
}
void WResetEditWindow( WStringEditInfo *einfo )
{
if( einfo ) {
WSetEditWithStr( GetDlgItem(einfo->edit_dlg, IDM_STREDTEXT), "" );
WSetEditWithStr( GetDlgItem(einfo->edit_dlg, IDM_STREDCMDID), "" );
WSetEditWithStr( GetDlgItem(einfo->edit_dlg, IDM_STREDCMDNUM), "" );
}
}
Bool WPasteStringItem( WStringEditInfo *einfo )
{
char *text;
char *symbol;
WRHashValueList *vlist;
uint_32 len;
uint_16 id;
Bool ok;
text = NULL;
symbol = NULL;
ok = ( einfo && einfo->tbl );
if( ok ) {
ok = WGetClipData( einfo->win, CF_TEXT, &text, &len );
}
if( ok ) {
id = WFindLargestStringID( einfo->tbl ) + 1;
}
if( ok ) {
ok = WSetEditWindowText( einfo->edit_dlg, text );
}
if( ok ) {
vlist = WRLookupValue( einfo->info->symbol_table, id );
if( vlist ) {
if( vlist->next == NULL ) {
symbol = WStrDup( vlist->entry->name );
}
WRValueListFree( vlist );
}
}
if( ok ) {
ok = WSetEditWindowID( einfo->edit_dlg, id, symbol );
}
if( ok ) {
ok = WInsertStringEntry( einfo );
}
if( text != NULL ) {
WMemFree( text );
}
return( ok );
}
Bool WClipStringItem( WStringEditInfo *einfo, Bool cut )
{
HWND lbox;
LRESULT pos;
WStringBlock *block;
uint_16 id;
char *text;
uint_32 len;
Bool ok;
block = NULL;
text = NULL;
id = -1;
ok = ( einfo && einfo->tbl );
if( ok ) {
lbox = GetDlgItem ( einfo->edit_dlg, IDM_STREDLIST );
ok = ( lbox != (HWND) NULL );
}
if( ok ) {
pos = SendMessage ( lbox, LB_GETCURSEL, 0, 0 );
ok = ( pos != LB_ERR );
}
if( ok ) {
id = (uint_16 )(void *)
SendMessage ( lbox, LB_GETITEMDATA, (WPARAM) pos, 0 );
block = WFindStringBlock( einfo->tbl, id );
ok = ( block != NULL );
}
if ( ok ) {
text = WResIDNameToStr( block->block.String[ id & 0xf ] );
ok = ( text != NULL );
}
if( ok ) {
len = strlen( text ) + 1;
ok = WCopyClipData( einfo->win, CF_TEXT, text, len );
}
if( ok ) {
if( cut ) {
ok = WDeleteStringEntry( einfo );
}
}
if( text ) {
WMemFree( text );
}
return( ok );
}
static Bool WQueryChangeEntry( WStringEditInfo *einfo )
{
int ret;
UINT style;
char *title;
char *text;
style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;
title = WCreateEditTitle( einfo );
text = WAllocRCString( W_CHANGEMODIFIEDMENUITEM );
ret = MessageBox( einfo->edit_dlg, text, title, style );
if( text ) {
WFreeRCString( text );
}
if( title ) {
WMemFree( title );
}
if( ret == IDYES ) {
return( TRUE );
}
return( FALSE );
}
void WDoHandleSelChange( WStringEditInfo *einfo, Bool change, Bool reset )
{
HWND lbox;
int pos;
char *text;
char *symbol;
uint_16 id;
WStringBlock *block;
Bool mod;
Bool ok;
Bool bdel;
Bool replace;
mod = FALSE;
block = NULL;
text = NULL;
symbol = NULL;
id = -1;
pos = -1;
ok = ( einfo != NULL );
if( ok ) {
lbox = GetDlgItem ( einfo->edit_dlg, IDM_STREDLIST );
ok = ( lbox != (HWND) NULL );
}
if( ok ) {
if( einfo->current_block && !reset ) {
mod = WGetEditWindowStringData( einfo, &text, &symbol, &id );
if( mod ) {
mod = WIsCurrentModified( einfo, text, id, symbol );
}
}
if( mod && ( einfo->current_pos != -1 ) ) {
if( change || WQueryChangeEntry( einfo ) ) {
einfo->info->modified = TRUE;
pos = einfo->current_pos;
SendMessage( lbox, LB_DELETESTRING, pos, 0 );
if( WDeleteStringData( einfo, einfo->current_block,
einfo->current_string, &bdel ) ) {
block = WInsertStringData( einfo, id, text, symbol, &replace );
if( block ) {
pos = WFindStringPos( einfo->tbl, id );
if( pos != -1 ) {
WAddEditWinLBoxEntry( einfo, block, id, pos );
}
}
}
}
}
}
if( !block || ( id == (uint_16)-1 ) || ( pos == -1 ) ) {
pos = (int) SendMessage( lbox, LB_GETCURSEL, 0, 0 );
if( pos != LB_ERR ) {
id = (uint_16) SendMessage( lbox, LB_GETITEMDATA, (WPARAM) pos, 0 );
block = WFindStringBlock( einfo->tbl, id );
if( block == NULL ) {
return;
}
} else {
block = NULL;
id = -1;
}
}
if( block ) {
if( change ) {
WSetEditWindowID( einfo->edit_dlg, id,
block->symbol[ id & 0xf ] );
} else {
WSetEditWindowStringData( einfo, block, id );
}
}
if( ( einfo->current_block != block ) ||
( einfo->current_string != id ) ||
( einfo->current_pos != pos ) ) {
einfo->current_block = block;
einfo->current_string = id;
einfo->current_pos = (pos == LB_ERR) ? -1 : pos;
if( pos != LB_ERR ) {
SendMessage( lbox, LB_SETCURSEL, (WPARAM) pos, 0 );
}
}
if( symbol ) {
WMemFree( symbol );
}
if( text ) {
WMemFree( text );
}
}
void WHandleSelChange( WStringEditInfo *einfo )
{
WDoHandleSelChange( einfo, FALSE, FALSE );
}
LRESULT WINEXPORT WStringEditProc ( HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam )
{
WStringEditInfo *einfo;
LRESULT ret;
WORD wp;
WORD cmd;
ret = FALSE;
einfo = (WStringEditInfo *) GetWindowLong ( hDlg, DWL_USER );
switch ( message ) {
case WM_INITDIALOG:
einfo = (WStringEditInfo *) lParam;
einfo->edit_dlg = hDlg;
SetWindowLong ( hDlg, DWL_USER, (LONG) einfo );
WRAddSymbolsToComboBox( einfo->info->symbol_table, hDlg,
IDM_STREDCMDID, WR_HASHENTRY_ALL );
ret = TRUE;
break;
case WM_SYSCOLORCHANGE:
WCtl3dColorChange ();
break;
#if 0
#ifdef __NT__
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
#else
case WM_CTLCOLOR:
#endif
return( (LRESULT)WCtl3dCtlColorEx( message, wParam, lParam ) );
#endif
#if 0
case WM_PARENTNOTIFY:
{
HWND win;
RECT r;
POINT p;
cmd = GET_WM_PARENTNOTIFY_EVENT(wParam,lParam);
switch( cmd ) {
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
MAKE_POINT( p, lParam );
win = GetDlgItem ( hDlg, IDM_STREDLIST );
GetWindowRect( win, &r );
MapWindowPoints( HWND_DESKTOP, hDlg, (POINT *)&r, 2 );
if( PtInRect( &r, p ) ) {
WHandleSelChange( einfo );
}
break;
}
ret = TRUE;
break;
}
#endif
case WM_COMMAND:
wp = LOWORD(wParam);
cmd = GET_WM_COMMAND_CMD(wParam,lParam);
switch( wp ) {
case IDM_STREDINSERT:
WInsertStringEntry( einfo );
break;
case IDM_STREDCHANGE:
WDoHandleSelChange( einfo, TRUE, FALSE );
break;
case IDM_STREDRESET:
WDoHandleSelChange( einfo, FALSE, TRUE );
break;
case IDM_STREDSETSTR:
if( einfo->tbl && einfo->tbl->first_block ) {
WHandleSelChange( einfo );
} else {
WInsertStringEntry( einfo );
}
break;
#if 0
case IDM_STREDCMDID:
if( cmd == CBN_SELCHANGE ) {
einfo->combo_change = TRUE;
WHandleSelChange( einfo );
einfo->combo_change = FALSE;
}
break;
#endif
case IDM_STREDLIST:
if( cmd == LBN_SELCHANGE ) {
WHandleSelChange( einfo );
}
break;
}
break;
}
return( ret );
}
LRESULT WINEXPORT WTestProc( HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam )
{
RECT r;
_wtouch(wParam);
_wtouch(lParam);
if( message == WM_INITDIALOG ) {
GetWindowRect( hDlg, &r );
appWidth = r.right - r.left + 10;
appHeight = r.bottom - r.top + 85;
DestroyWindow( hDlg );
return( TRUE );
}
return( FALSE );
}
void WInitEditDlg( HINSTANCE inst, HWND parent )
{
FARPROC lpProc;
lpProc = MakeProcInstance( (FARPROC) WTestProc, inst );
JCreateDialog( inst, "WStringEditDLG", parent, (DLGPROC) lpProc );
FreeProcInstance( lpProc );
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -