📄 wrhash.c
字号:
if( ok ) {
strupr( symbol );
entry = WRAddHashEntry( table, symbol, value, &dup, TRUE, TRUE );
ok = ( entry != NULL );
}
if( ok ) {
if( WRFindUnusedHashValue( table, &value, table->next_default_value ) ) {
table->next_default_value = value;
}
}
if( ok && !force && dup ) {
ok = ( !force && dup );
}
if( ok ) {
if( dup ) {
// this is neccessary if the value of the string was moified
index = SendDlgItemMessage( hDlg, IDB_SYM_LISTBOX,
LB_FINDSTRINGEXACT, 0,
(LPARAM)(LPCSTR) symbol );
} else {
index = SendDlgItemMessage( hDlg, IDB_SYM_LISTBOX, LB_ADDSTRING, 0,
(LPARAM) (LPCSTR) symbol );
SendDlgItemMessage( hDlg, IDB_SYM_LISTBOX, LB_SETITEMDATA,
(WPARAM)index, (LPARAM)entry );
}
SendDlgItemMessage( hDlg, IDB_SYM_LISTBOX, LB_SETCURSEL, index, 0 );
WRShowSelectedSymbol( hDlg, table );
}
return( ok );
}
static WRHashEntry *getHashEntry( HWND hDlg )
{
LRESULT index;
LRESULT count;
WRHashEntry *entry;
HWND lbox;
lbox = GetDlgItem( hDlg, IDB_SYM_LISTBOX );
count = SendMessage( lbox, LB_GETCOUNT, 0, 0 );
if( !count || ( count == LB_ERR ) ) {
return( NULL );
}
index = SendMessage( lbox, LB_GETCURSEL, 0, 0 );
if( index == LB_ERR ) {
return( NULL );
}
entry = (WRHashEntry *)SendMessage( lbox, LB_GETITEMDATA, (WPARAM)index, 0 );
return( entry );
}
static BOOL WRAddNewSymbol( HWND hDlg, WRHashTable *table, FARPROC hcb,
BOOL modify )
{
WRAddSymInfo info;
WRHashEntry *entry;
DLGPROC proc_inst;
HINSTANCE inst;
BOOL modified;
BOOL ret;
if( !table ) {
return( FALSE );
}
info.table = table;
info.hcb = hcb;
info.value = 0;
info.modify = modify;
info.symbol = NULL;
if( modify ) {
entry = getHashEntry( hDlg );
if( entry != NULL ) {
info.symbol = entry->name;
}
}
ret = FALSE;
inst = WRGetInstance();
proc_inst = (DLGPROC) MakeProcInstance( (FARPROC)WRAddSymProc, inst );
modified = JDialogBoxParam( inst, "WRAddSymbol", hDlg,
proc_inst, (LPARAM)&info );
FreeProcInstance( (FARPROC)proc_inst );
if( modified == IDOK ) {
ret = WRAddSymbol( hDlg, table, modify, info.symbol, info.value );
}
if( info.symbol ) {
WRMemFree( info.symbol );
}
return( ret );
}
static BOOL WRRemoveSymbol( HWND hDlg, WRHashTable *table )
{
LRESULT index;
LRESULT count;
WRHashEntry *entry;
HWND lbox;
BOOL ret;
lbox = GetDlgItem( hDlg, IDB_SYM_LISTBOX );
count = SendMessage( lbox, LB_GETCOUNT, 0, 0 );
if( !count || ( count == LB_ERR ) ) {
return( TRUE );
}
index = SendMessage( lbox, LB_GETCURSEL, 0, 0 );
entry = (WRHashEntry *)SendMessage( lbox, LB_GETITEMDATA, (WPARAM)index, 0 );
if( entry == NULL ) {
return( FALSE );
}
ret = WRRemoveName( table, entry->name );
if( !ret ) {
return( FALSE );
}
count = SendMessage( lbox, LB_DELETESTRING, index, 0 );
if( count ) {
if( index && ( index == count ) ) {
index--;
}
SendDlgItemMessage( hDlg, IDB_SYM_LISTBOX, LB_SETCURSEL, index, 0 );
}
WRShowSelectedSymbol( hDlg, table );
return( TRUE );
}
static int TextWidth = 0;
static BOOL TextWidthInit = FALSE;
static void InitTextWidth( HWND hDlg )
{
RECT rect;
GetWindowRect( GetDlgItem( hDlg, IDB_SYM_SYMVALUE ), &rect );
TextWidth = rect.left;
GetWindowRect( GetDlgItem( hDlg, IDB_SYM_SYMTEXT ), &rect );
TextWidth -= rect.left;
return;
}
static void WRDrawHashLBItem( DRAWITEMSTRUCT *dis, WRHashEntry *entry )
{
int oldDC;
COLORREF bkcolor;
COLORREF color;
HBRUSH brush;
RECT text_rect;
POINT pt;
char vtext[35];
oldDC = SaveDC( dis->hDC );
// paint the item background
if( ( dis->itemState & ODS_SELECTED ) && entry ) {
bkcolor = GetSysColor( COLOR_HIGHLIGHT );
} else {
bkcolor = GetSysColor( COLOR_WINDOW );
}
brush = CreateSolidBrush( bkcolor );
FillRect( dis->hDC, &dis->rcItem, brush );
DeleteObject( brush );
if( entry && entry->name ) {
// set the correct text color
if( ( dis->itemState & ODS_DISABLED ) ||
( dis->itemState & ODS_GRAYED ) ) {
color = GetSysColor( COLOR_GRAYTEXT );
} else {
if( dis->itemState & ODS_SELECTED ) {
color = GetSysColor( COLOR_HIGHLIGHTTEXT );
} else {
color = GetSysColor( COLOR_WINDOWTEXT );
}
}
SetTextColor( dis->hDC, color );
SetBkColor( dis->hDC, bkcolor );
// set the text rectangle of the listbox item
text_rect.left = dis->rcItem.left + 1;
text_rect.top = dis->rcItem.top + 1;
text_rect.right = text_rect.left + TextWidth - 1;
text_rect.bottom = dis->rcItem.bottom;
// set the text of the listbox item
SelectObject( dis->hDC, GetStockObject( ANSI_VAR_FONT ) );
ExtTextOut( dis->hDC, text_rect.left, text_rect.top,
ETO_CLIPPED, &text_rect,
entry->name, strlen( entry->name ), NULL );
//TextOut( dis->hDC, dis->rcItem.left + 1, dis->rcItem.top + 1,
// entry->name, strlen( entry->name ) );
ltoa( (long)entry->value, vtext, 10 );
// set the value rectangle of the listbox item
text_rect.left = text_rect.right + 2;
text_rect.right = dis->rcItem.right - 1;
//draw the value text
ExtTextOut( dis->hDC, text_rect.left, text_rect.top,
ETO_CLIPPED, &text_rect,
vtext, strlen( vtext ), NULL );
// if the item has been ref'd then draw the checkbox
if( entry->ref_count ) {
SelectObject( dis->hDC, GetStockObject( BLACK_PEN ) );
pt.x = dis->rcItem.right - 4;
pt.y = dis->rcItem.top + 2;
MoveToEx( dis->hDC, pt.x, pt.y, NULL );
//pt.x -= 5;
pt.x -= 4;
pt.y += 10;
LineTo( dis->hDC, pt.x, pt.y );
//pt.x -= 5;
pt.x -= 4;
pt.y -= 5;
LineTo( dis->hDC, pt.x, pt.y );
}
}
if( dis->itemState & ODS_FOCUS ) {
DrawFocusRect( dis->hDC, &dis->rcItem );
}
RestoreDC( dis->hDC, oldDC );
}
static void WRDrawHashListBoxItem( HWND hDlg, DRAWITEMSTRUCT *dis )
{
WRHashEntry *entry;
if( !dis ) {
return;
}
if( !TextWidthInit ) {
InitTextWidth( hDlg );
TextWidthInit = TRUE;
}
entry = NULL;
if( dis->itemID != (UINT)-1 ) {
entry = (WRHashEntry *)dis->itemData;
}
WRDrawHashLBItem( dis, entry );
}
static void WRSetupEditSymDialog( HWND hDlg, WREditSymInfo *info, BOOL first )
{
WRAddSymbolsToListBox( info->table, hDlg, IDB_SYM_LISTBOX, info->flags );
SendDlgItemMessage( hDlg, IDB_SYM_LISTBOX, LB_SETCURSEL, 0, 0 );
WRShowSelectedSymbol( hDlg, info->table );
if( first ) {
CheckDlgButton( hDlg, IDB_SYM_SHOW_STANDARD,
info->flags & WR_HASHENTRY_STANDARD );
// CheckDlgButton( hDlg, IDB_SYM_SHOW_UNUSED,
// info->flags & WR_HASHENTRY_UNUSED );
}
}
static WRHashEntryFlags WRGetEditSymEntryFlags( HWND hDlg )
{
WRHashEntryFlags flags;
flags = 0;
if( IsDlgButtonChecked( hDlg, IDB_SYM_SHOW_STANDARD ) ) {
flags |= WR_HASHENTRY_STANDARD;
}
// if( IsDlgButtonChecked( hDlg, IDB_SYM_SHOW_UNUSED ) ) {
flags |= WR_HASHENTRY_UNUSED;
// }
return( flags );
}
static BOOL WRHandleDELKey( HWND hDlg, WREditSymInfo *info )
{
if( IsWindowEnabled( GetDlgItem( hDlg, IDB_SYM_REMOVE ) ) ) {
if( WRRemoveSymbol( hDlg, info->table ) ) {
info->modified = TRUE;
return( TRUE );
}
}
return( FALSE );
}
BOOL WR_EXPORT WREditSymbolsProc( HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam )
{
WREditSymInfo *info;
BOOL ret;
WORD wp, cmd;
ret = FALSE;
switch( message ) {
case WM_SYSCOLORCHANGE:
WRCtl3dColorChange();
break;
case WM_INITDIALOG:
info = (WREditSymInfo *) lParam;
SetWindowLong( hDlg, DWL_USER, (LONG) info );
if( info == NULL ) {
EndDialog( hDlg, FALSE );
break;
}
WRSetupEditSymDialog( hDlg, info, TRUE );
ret = TRUE;
break;
case WM_DRAWITEM:
WRDrawHashListBoxItem( hDlg, (DRAWITEMSTRUCT *)lParam );
ret = TRUE;
break;
case WM_VKEYTOITEM:
ret = -1;
info = (WREditSymInfo *) GetWindowLong( hDlg, DWL_USER );
if( info && ( LOWORD( wParam ) == VK_DELETE ) ) {
if( WRHandleDELKey( hDlg, info ) ) {
ret = -2;
}
}
break;
case WM_COMMAND:
info = (WREditSymInfo *) GetWindowLong( hDlg, DWL_USER );
wp = LOWORD(wParam);
cmd = GET_WM_COMMAND_CMD(wParam,lParam);
switch( wp ) {
case IDB_SYM_SHOW_STANDARD:
// case IDB_SYM_SHOW_UNUSED:
if( cmd == BN_CLICKED ) {
info->flags = WRGetEditSymEntryFlags( hDlg );
WRSetupEditSymDialog( hDlg, info, FALSE );
}
break;
case IDB_SYM_HELP:
if( info && info->hcb ) {
(*info->hcb)();
}
break;
case IDOK:
if( info ) {
info->flags = WRGetEditSymEntryFlags( hDlg );
}
EndDialog( hDlg, TRUE );
ret = TRUE;
break;
case IDCANCEL:
ret = TRUE;
if( info && info->modified ) {
if( !WRDiscardChangesQuery() ) {
break;
}
}
EndDialog( hDlg, FALSE );
break;
case IDB_SYM_ADD:
case IDB_SYM_MODIFY:
if( !info || !info->table ) {
break;
}
if( WRAddNewSymbol( hDlg,info->table, info->hcb,
wp == IDB_SYM_MODIFY ) ) {
info->modified = TRUE;
}
break;
case IDB_SYM_REMOVE:
if( !info || !info->table ) {
break;
}
if( WRRemoveSymbol( hDlg, info->table ) ) {
info->modified = TRUE;
}
break;
case IDB_SYM_LISTBOX:
switch( cmd ) {
case LBN_SELCHANGE:
if( info && info->table ) {
WRShowSelectedSymbol( hDlg, info->table );
}
break;
}
break;
}
}
return( ret );
}
static void WRSetAddSymInfo( HWND hDlg, WRAddSymInfo *info )
{
WRHashValue value;
char *str;
if( info ) {
if( info->modify ) {
str = WRAllocRCString( WR_MODIFYSYMBOLTITLE );
if( str ) {
SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM)(LPCSTR)str );
WRFreeRCString( str );
}
if( info->symbol ) {
WRSetEditWithStr( info->symbol, hDlg, IDB_ADDSYM_SYM );
}
}
if( !WRFindUnusedHashValue( info->table, &value, info->table->next_default_value ) ) {
value = info->table->next_default_value;
}
WRSetEditWithSLONG( (signed long)value, 10, hDlg, IDB_ADDSYM_VAL );
}
}
static BOOL WRGetAddSymInfo( HWND hDlg, WRAddSymInfo *info )
{
signed long val;
if( !info ) {
return( FALSE );
}
if( !WRGetSLONGFromEdit( hDlg, IDB_ADDSYM_VAL, NULL, &val ) ) {
return( FALSE );
}
info->value = (WRHashValue)val;
info->symbol = WRGetStrFromEdit( hDlg, IDB_ADDSYM_SYM, NULL );
if( !info->symbol ) {
return( FALSE );
}
WRStripSymbol( info->symbol );
if( !WRIsValidSymbol( info->symbol ) ) {
WRMemFree( info->symbol );
info->symbol = NULL;
return( FALSE );
}
return( TRUE );
}
static void WRSetAddSymOK( HWND hDlg )
{
char *str;
signed long val;
BOOL enable;
enable = FALSE;
str = WRGetStrFromEdit( hDlg, IDB_ADDSYM_SYM, NULL );
if( str ) {
WRStripSymbol( str );
enable = WRIsValidSymbol( str );
WRMemFree( str );
}
if( enable ) {
enable = WRGetSLONGFromEdit( hDlg, IDB_ADDSYM_VAL, NULL, &val );
}
EnableWindow( GetDlgItem( hDlg, IDOK ), enable );
}
BOOL WR_EXPORT WRAddSymProc( HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam )
{
WRAddSymInfo *info;
WORD cmd;
BOOL ret;
ret = FALSE;
switch( message ) {
case WM_INITDIALOG:
info = (WRAddSymInfo *)lParam;
SetWindowLong( hDlg, DWL_USER, (LONG)info );
WRSetAddSymInfo( hDlg, info );
WRSetAddSymOK( hDlg );
ret = TRUE;
break;
case WM_SYSCOLORCHANGE:
WRCtl3dColorChange();
break;
case WM_COMMAND:
info = (WRAddSymInfo *)GetWindowLong( hDlg, DWL_USER );
switch( LOWORD(wParam) ) {
case IDB_ADDSYM_HELP:
if( info && info->hcb ) {
(*info->hcb)();
}
break;
case IDB_ADDSYM_SYM:
case IDB_ADDSYM_VAL:
cmd = GET_WM_COMMAND_CMD(wParam,lParam);
switch( cmd ) {
case EN_CHANGE:
WRSetAddSymOK( hDlg );
break;
}
break;
case IDOK:
if( WRGetAddSymInfo( hDlg, info ) ) {
EndDialog( hDlg, TRUE );
}
ret = TRUE;
break;
case IDCANCEL:
EndDialog( hDlg, FALSE );
ret = TRUE;
break;
}
}
return( ret );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -