📄 wedit.c
字号:
} else {
// if the flags are zero - indicating a normal item - and the
// id is also zero then change it to the default
// flag == id == 0 indicates a separator
if( flags == 0 && id == 0 ) {
id = DEFAULT_MENU_ID;
}
entry->item->Item.Normal.ItemText = text;
entry->item->Item.Normal.ItemID = id;
entry->item->Item.Normal.ItemFlags = flags;
}
entry->symbol = symbol;
} else {
if( symbol != NULL ) {
WMemFree( symbol );
}
if( text != NULL ) {
WMemFree( text );
}
}
return( ok );
}
Bool WSetEditWindowText( HWND dlg, MenuFlags flags, char *text )
{
Bool ok;
char *t;
char *n;
ok = ( dlg != (HWND) NULL );
if ( ok ) {
if( flags & MENU_SEPARATOR ) {
t = "";
} else {
t = text;
if ( t == NULL ) {
t = "";
}
}
}
if ( ok ) {
n = WConvertStringFrom( t, "\t\x8", "ta" );
if( n ) {
ok = WSetEditWithStr ( GetDlgItem ( dlg, IDM_MENUEDTEXT ), n );
WMemFree( n );
} else {
ok = WSetEditWithStr ( GetDlgItem ( dlg, IDM_MENUEDTEXT ), t );
}
}
return ( ok );
}
Bool WGetEditWindowText ( HWND dlg, char **text )
{
Bool ok;
char *n;
ok = ( ( dlg != (HWND) NULL ) && ( text != NULL ) );
if ( ok ) {
n = WGetStrFromEdit ( GetDlgItem ( dlg, IDM_MENUEDTEXT ), NULL );
if( n && !*n ) {
WMemFree( n );
n = NULL;
}
*text = WConvertStringTo( n, "\t\x8", "ta" );
if( n ) {
WMemFree( n );
}
ok = ( *text != NULL );
}
return ( ok );
}
Bool WSetEditWindowID( HWND dlg, uint_16 id, Bool is_pop_sep, char *symbol )
{
Bool ok;
ok = ( dlg != (HWND) NULL );
if( ok ) {
if( is_pop_sep ) {
ok = WSetEditWithStr( GetDlgItem( dlg, IDM_MENUEDID ), "" );
} else {
if( symbol ) {
ok = WSetEditWithStr( GetDlgItem( dlg, IDM_MENUEDID ), symbol );
} else {
ok = WSetEditWithSINT32( GetDlgItem( dlg, IDM_MENUEDID ),
(int_32)id, 10 );
}
}
}
if( ok ) {
if( is_pop_sep ) {
ok = WSetEditWithStr( GetDlgItem( dlg, IDM_MENUEDNUM ), "" );
} else {
ok = WSetEditWithSINT32( GetDlgItem( dlg, IDM_MENUEDNUM ),
(int_32)id, 10 );
}
}
return( ok );
}
Bool WGetEditWindowID( HWND dlg, char **symbol, uint_16 *id,
WRHashTable *symbol_table, Bool combo_change )
{
int_32 val;
char *ep;
WRHashValue hv;
WRHashEntry *new_entry;
BOOL dup;
if( dlg == (HWND)NULL ) {
return( FALSE );
}
if( combo_change ) {
*symbol = WGetStrFromComboLBox( GetDlgItem( dlg, IDM_MENUEDID ), -1 );
} else {
*symbol = WGetStrFromEdit( GetDlgItem( dlg, IDM_MENUEDID ), NULL );
}
if( *symbol == NULL ) {
return( FALSE );
}
if( !**symbol ) {
*symbol = WGetStrFromEdit( GetDlgItem( dlg, IDM_MENUEDNUM ), NULL );
}
if( *symbol == NULL ) {
return( FALSE );
}
strupr( *symbol );
// check if the string has a numeric representation
val = (int_32)strtol( *symbol, &ep, 0 );
if( *ep ) {
// the string did not have a numeric representation
// so lets look it up in the hash table
if( WRLookupName( symbol_table, *symbol, &hv ) ) {
*id = (uint_16)hv;
} else {
dup = FALSE;
new_entry = WRAddDefHashEntry( symbol_table, *symbol, &dup );
if( new_entry != NULL ) {
*id = (uint_16)new_entry->value;
if( !dup ) {
SendDlgItemMessage( dlg, IDM_MENUEDID, CB_ADDSTRING,
0, (LPARAM)(LPCSTR)new_entry->name );
SendDlgItemMessage( dlg, IDM_MENUEDID, CB_SETITEMDATA,
0, (LPARAM)new_entry );
}
} else {
*id = 0;
WMemFree( *symbol );
*symbol = NULL;
return( FALSE );
}
}
} else {
// the string did have a numeric representation
*id = (uint_16)val;
WMemFree( *symbol );
*symbol = NULL;
}
return( TRUE );
}
Bool WSetEditWindowFlags ( HWND dlg, MenuFlags flags, Bool reset )
{
Bool ok;
ok = ( dlg != (HWND) NULL );
if ( ok ) {
#if 0
EnableWindow( GetDlgItem( dlg, IDM_MENUEDPOPUP ), ( (flags & MENU_POPUP) != 0 ) );
EnableWindow( GetDlgItem( dlg, IDM_MENUEDSEP ), ( (flags & MENU_SEPARATOR) != 0 ) );
EnableWindow( GetDlgItem( dlg, IDM_MENUEDNORMAL ), ( !(flags & MENU_POPUP) && !(flags & MENU_SEPARATOR) ) );
#endif
CheckDlgButton( dlg, IDM_MENUEDPOPUP, reset || ( (flags & MENU_POPUP) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDSEP, !reset && ( (flags & MENU_SEPARATOR) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDNORMAL, !reset && ( !(flags & MENU_POPUP) && !(flags & MENU_SEPARATOR) ) );
CheckDlgButton( dlg, IDM_MENUEDCHECKED, !reset && ( (flags & MENU_CHECKED) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDGRAYED, !reset && ( (flags & MENU_GRAYED) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDINACTIVE, !reset && ( (flags & MENU_INACTIVE) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDHELP, !reset && ( (flags & MENU_HELP) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDMENU, !reset && ( (flags & MENU_MENUBREAK) != 0 ) );
CheckDlgButton( dlg, IDM_MENUEDMENUBAR, !reset && ( (flags & MENU_MENUBARBREAK) != 0 ) );
}
return ( ok );
}
Bool WResetEditWindowFlags( HWND dlg )
{
Bool ok;
ok = ( dlg != (HWND) NULL );
if ( ok ) {
ok = WSetEditWindowFlags ( dlg, 0, TRUE );
}
return ( ok );
}
Bool WGetEditWindowFlags( HWND dlg, MenuFlags *flags )
{
Bool ok;
ok = ( ( dlg != (HWND) NULL ) && flags );
if( ok ) {
*flags = 0;
if( IsDlgButtonChecked ( dlg, IDM_MENUEDPOPUP ) ) {
*flags |= MENU_POPUP;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDSEP ) ) {
*flags |= MENU_SEPARATOR;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDCHECKED ) ) {
*flags |= MENU_CHECKED;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDGRAYED ) ) {
*flags |= MENU_GRAYED;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDINACTIVE ) ) {
*flags |= MENU_INACTIVE;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDHELP ) ) {
*flags |= MENU_HELP;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDMENU ) ) {
*flags |= MENU_MENUBREAK;
}
if( IsDlgButtonChecked ( dlg, IDM_MENUEDMENUBAR ) ) {
*flags |= MENU_MENUBARBREAK;
}
}
return( ok );
}
Bool WSetEditWinResName ( WMenuEditInfo *einfo )
{
if ( einfo && einfo->edit_dlg && einfo->info->res_name ) {
return ( WSetEditWithWResID ( GetDlgItem ( einfo->edit_dlg,
IDM_MENUEDRNAME ),
einfo->info->res_name ) );
}
return ( TRUE );
}
Bool WInitEditWindowListBox ( WMenuEditInfo *einfo )
{
Bool ok;
HWND lbox;
int pos;
ok = ( einfo && einfo->edit_dlg && einfo->menu );
if ( ok ) {
pos = 0;
lbox = GetDlgItem ( einfo->edit_dlg, IDM_MENUEDLIST );
ok = ( lbox != (HWND)NULL );
}
if( ok ) {
SendMessage ( lbox, WM_SETREDRAW, FALSE, 0 );
SendMessage ( lbox, LB_RESETCONTENT, FALSE, 0 );
ok = WAddMenuEntriesToLBox ( lbox, einfo->menu->first_entry, &pos );
SendMessage ( lbox, WM_SETREDRAW, TRUE, 0 );
InvalidateRect( lbox, NULL, TRUE );
}
if( ok ) {
ok = WResetPrevWindowMenu( einfo );
}
return ( ok );
}
Bool WInitEditWindow ( WMenuEditInfo *einfo )
{
HWND lbox;
Bool ok;
ok = ( einfo && einfo->edit_dlg );
if ( ok ) {
ok = WSetEditWinResName ( einfo );
}
if( ok ) {
ok = WInitEditWindowListBox( einfo );
}
if( ok ) {
WSetEditWindowControls( einfo, einfo->menu->first_entry );
if( einfo->menu->first_entry ) {
ok = WSetEditWindowMenuEntry( einfo, einfo->menu->first_entry );
if( ok ) {
lbox = GetDlgItem( einfo->edit_dlg, IDM_MENUEDLIST );
ok = ( SendMessage( lbox, LB_SETCURSEL, 0, 0 ) != LB_ERR );
einfo->current_entry = einfo->menu->first_entry;
einfo->current_pos = 0;
}
} else {
CheckDlgButton( einfo->edit_dlg, IDM_MENUEDPOPUP, TRUE );
}
}
return( ok );
}
Bool WPasteMenuItem( WMenuEditInfo *einfo )
{
WMenuEntry *entry;
void *data;
uint_32 dsize;
Bool ok;
data = NULL;
ok = ( einfo != NULL );
if( ok ) {
ok = WGetClipData( einfo->win, WItemClipbdFormat, &data, &dsize );
}
if( ok ) {
entry = WMakeMenuEntryFromClipData( data, dsize );
ok = ( entry != NULL );
}
if( ok ) {
ok = WResolveEntries( entry, einfo->info->symbol_table );
}
if( ok ) {
ok = WInsertMenuEntry( einfo, entry, TRUE );
}
if( data ) {
WMemFree( data );
}
return( ok );
}
Bool WClipMenuItem( WMenuEditInfo *einfo, Bool cut )
{
HWND lbox;
LRESULT index;
void *data;
uint_32 dsize;
WMenuEntry *entry;
Bool ok;
data = NULL;
ok = ( einfo != NULL );
if( ok ) {
lbox = GetDlgItem( einfo->edit_dlg, IDM_MENUEDLIST );
ok = ( lbox != (HWND)NULL );
}
if( ok ) {
index = SendMessage( lbox, LB_GETCURSEL, 0, 0 );
ok = ( index != LB_ERR );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -