📄 w_menu.c
字号:
return( TRUE );
}
Bool WInsertEntryIntoMenu ( WMenuEditInfo *einfo, WMenuEntry *after,
WMenuEntry *parent, WMenuEntry *entry,
Bool popup )
{
Bool ok;
ok = ( einfo && einfo->menu && entry );
if ( ok ) {
if ( after ) {
if( popup ) {
ok = WInsertEntryIntoMenu( einfo, NULL, after, entry, FALSE );
} else {
if ( after->next ) {
after->next->prev = entry;
}
entry->next = after->next;
entry->prev = after;
after->next = entry;
entry->parent = after->parent;
ok = WInsertEntryIntoPreview( einfo, entry );
if( !ok ) {
WRemoveMenuEntry( einfo->menu, entry );
}
}
} else {
if( parent ) {
entry->next = parent->child;
parent->child = entry;
} else {
entry->next = einfo->menu->first_entry;
einfo->menu->first_entry = entry;
}
entry->prev = NULL;
entry->parent = parent;
ok = WInsertEntryIntoPreview( einfo, entry );
if( !ok ) {
WRemoveMenuEntry( einfo->menu, entry );
}
}
}
return ( ok );
}
int WGetMenuEntryDepth ( WMenuEntry *entry )
{
int depth;
depth = -1;
while( entry ) {
depth++;
entry = entry->parent;
}
return( depth );
}
int WCountMenuChildren( WMenuEntry *entry )
{
int count;
count = 0;
while( entry ) {
count += WCountMenuChildren( entry->child );
count++;
entry = entry->next;
}
return( count );
}
Bool WResetPreviewID( WMenuEditInfo *einfo, WMenuEntry *entry )
{
Bool ok;
ok = TRUE;
while( ok && entry ) {
entry->preview_id = einfo->first_preview_id;
einfo->first_preview_id++;
if( einfo->first_preview_id == LAST_PREVIEW_ID ) {
return( FALSE );
}
if( entry->child ) {
ok = WResetPreviewID( einfo, entry->child );
}
entry = entry->next;
}
return( ok );
}
Bool WResetPreviewIDs( WMenuEditInfo *einfo )
{
if( einfo == NULL ) {
return( FALSE );
}
einfo->first_preview_id = FIRST_PREVIEW_ID;
return( WResetPreviewID( einfo, einfo->menu->first_entry ) );
}
Bool WAddItemAtPos( HMENU parent, int pos, WMenuEntry *entry )
{
MenuFlags flags;
Bool ok;
ok = ( ( parent != (HMENU)NULL ) && entry );
if( ok ) {
flags = entry->item->Item.Normal.ItemFlags;
flags &= ~MENU_ENDMENU;
if( flags & MENU_POPUP ) {
entry->preview_popup = CreatePopupMenu();
if ( entry->preview_popup == (HMENU)NULL ) {
return( FALSE );
}
ok = InsertMenu( parent, pos, MF_BYPOSITION | flags,
(UINT)entry->preview_popup,
entry->item->Item.Popup.ItemText );
} else if( flags & MENU_SEPARATOR ) {
ok = InsertMenu( parent, pos, MF_BYPOSITION | flags,
entry->preview_id, NULL );
} else {
ok = InsertMenu( parent, pos, MF_BYPOSITION | flags,
entry->preview_id,
entry->item->Item.Normal.ItemText );
}
}
return( ok );
}
Bool WModifyItemAtPos( HMENU parent, int pos, WMenuEntry *entry )
{
MenuFlags flags;
Bool ok;
ok = ( ( parent != (HMENU)NULL ) && entry );
if( ok ) {
flags = entry->item->Item.Normal.ItemFlags;
flags &= ~MENU_ENDMENU;
if( flags & MENU_POPUP ) {
ok = ModifyMenu( parent, pos, MF_BYPOSITION | flags,
(UINT)entry->preview_popup,
entry->item->Item.Popup.ItemText );
} else if( flags & MENU_SEPARATOR ) {
// do nothing
} else {
ok = ModifyMenu( parent, pos, MF_BYPOSITION | flags,
entry->preview_id,
entry->item->Item.Normal.ItemText );
}
}
return( ok );
}
Bool WAddToPreviewMenu( HMENU parent, WMenuEntry *entry )
{
Bool ok;
int pos;
ok = ( ( parent != (HMENU)NULL ) && entry );
pos = 0;
while( ok && entry ) {
ok = WAddItemAtPos( parent, pos, entry );
if( ok && entry->item->IsPopup ) {
if( entry->child ) {
ok = WAddToPreviewMenu( entry->preview_popup, entry->child );
}
}
entry = entry->next;
pos++;
}
return( ok );
}
HMENU WCreatePreviewMenu( WMenuEditInfo *einfo )
{
HMENU menu;
if( einfo == NULL ) {
return( FALSE );
}
menu = CreateMenu();
if( menu == (HMENU)NULL ) {
return( FALSE );
}
WAddToPreviewMenu( menu, einfo->menu->first_entry );
return( menu );
}
WMenuEntry *WFindEntryFromPreviewID( WMenuEntry *entry, WORD id )
{
WMenuEntry *found;
while( entry ) {
if( entry->preview_id == id ) {
return( entry );
}
if( entry->child ) {
found = WFindEntryFromPreviewID( entry->child, id );
if( found ) {
return( found );
}
}
entry = entry->next;
}
return( NULL );
}
WMenuEntry *WFindEntryFromPreviewPopup( WMenuEntry *entry, HMENU popup )
{
WMenuEntry *found;
while( entry ) {
if( entry->preview_popup == popup ) {
return( entry );
}
if( entry->child ) {
found = WFindEntryFromPreviewPopup( entry->child, popup );
if( found ) {
return( found );
}
}
entry = entry->next;
}
return( NULL );
}
Bool WFindEntryLBPos( WMenuEntry *start, WMenuEntry *entry, int *count )
{
while( start ) {
*count = *count + 1;
if( start == entry ) {
return( TRUE );
}
if( start->child ) {
if ( WFindEntryLBPos( start->child, entry, count ) ) {
return( TRUE );
}
}
start = start->next;
}
return( FALSE );
}
Bool WInsertEntryIntoPreview( WMenuEditInfo *einfo, WMenuEntry *entry )
{
int pos;
HMENU menu;
WMenuEntry *start;
if( !einfo || !entry ) {
return( FALSE );
}
if( entry->parent ) {
menu = entry->parent->preview_popup;
start = entry->parent->child;
} else {
menu = GetMenu( einfo->preview_window );
start = einfo->menu->first_entry;
}
if( menu == (HMENU)NULL ) {
return( FALSE );
}
pos = -1;
while( start ) {
pos++;
if( start == entry ) {
break;
}
start = start->next;
}
if( pos == -1 ) {
return( FALSE );
}
entry->preview_id = einfo->first_preview_id;
einfo->first_preview_id++;
if( einfo->first_preview_id == LAST_PREVIEW_ID ) {
return( FALSE );
}
if( !WAddItemAtPos( menu, pos, entry ) ) {
return( FALSE );
}
if( entry->parent == NULL ) {
DrawMenuBar( einfo->preview_window );
}
return( TRUE );
}
Bool WModifyEntryInPreview( WMenuEditInfo *einfo, WMenuEntry *entry )
{
int pos;
HMENU menu;
WMenuEntry *start;
if( !einfo || !entry ) {
return( FALSE );
}
if( entry->parent ) {
menu = entry->parent->preview_popup;
start = entry->parent->child;
} else {
menu = GetMenu( einfo->preview_window );
start = einfo->menu->first_entry;
}
if( menu == (HMENU)NULL ) {
return( FALSE );
}
pos = -1;
while( start ) {
pos++;
if( start == entry ) {
break;
}
start = start->next;
}
if( pos == -1 ) {
return( FALSE );
}
if( !WModifyItemAtPos( menu, pos, entry ) ) {
return( FALSE );
}
if( entry->parent == NULL ) {
DrawMenuBar( einfo->preview_window );
}
return( TRUE );
}
Bool WMakeClipDataFromMenuEntry( WMenuEntry *entry, void **data, uint_32 *dsize )
{
WMenu menu;
WMenuEntry save;
int size;
Bool ok;
ok = ( entry && data && dsize );
if( ok ) {
memcpy( &save, entry, sizeof(WMenuEntry) );
menu.is32bit = entry->is32bit;
menu.first_entry = entry;
entry->next = NULL;
entry->prev = NULL;
entry->parent = NULL;
WMakeDataFromMenu( &menu, data, &size );
*dsize = size;
ok = ( *data && *dsize );
if( ok ) {
((BYTE *)(*data))[0] = entry->is32bit;
}
memcpy( entry, &save, sizeof(WMenuEntry) );
}
return( ok );
}
WMenuEntry *WMakeMenuEntryFromClipData( void *data, uint_32 dsize )
{
WMenuEntry *entry;
int size;
Bool is32bit;
Bool ok;
entry = NULL;
ok = ( data && dsize );
if( ok ) {
is32bit = ((BYTE *)data)[0];
data = ((BYTE *)data) + 2*sizeof(WORD);
dsize -= 2*sizeof(WORD);
size = dsize;
ok = WMakeMenuEntryFromData( &data, &size, NULL, &entry, is32bit );
}
if( !ok ) {
if( entry != NULL ) {
WFreeMenuEntries( entry );
entry = NULL;
}
}
return( entry );
}
Bool WResolveMenuEntries( WMenuEditInfo *einfo )
{
if( einfo->menu == NULL ) {
return( FALSE );
}
if( einfo->menu->first_entry == NULL ) {
return( TRUE );
}
return( WResolveEntries( einfo->menu->first_entry,
einfo->info->symbol_table ) );
}
Bool WResolveEntries( WMenuEntry *entry, WRHashTable *symbol_table )
{
if( !entry || !symbol_table ) {
return( FALSE );
}
while( entry ) {
if( entry->child ) {
WResolveEntries( entry->child, symbol_table );
}
WResolveEntrySymbol( entry, symbol_table );
entry = entry->next;
}
return( TRUE );
}
Bool WResolveEntrySymbol( WMenuEntry *entry, WRHashTable *symbol_table )
{
uint_16 id;
MenuFlags flags;
WRHashValueList *vlist;
Bool ok;
vlist = NULL;
ok = ( entry && symbol_table );
if( ok ) {
if( entry->item->IsPopup ) {
return( TRUE );
}
flags = entry->item->Item.Normal.ItemFlags;
if( flags & MENU_SEPARATOR ) {
return( TRUE );
}
id = entry->item->Item.Normal.ItemID;
vlist = WRLookupValue( symbol_table, id );
ok = ( vlist && !vlist->next );
}
if( ok ) {
if( entry->symbol ) {
WMemFree( entry->symbol );
}
entry->symbol = WStrDup( vlist->entry->name );
ok = ( entry->symbol != NULL );
}
if( vlist != NULL ) {
WRValueListFree( vlist );
}
return( ok );
}
Bool WResolveMenuSymIDs( WMenuEditInfo *einfo )
{
if( einfo->menu == NULL ) {
return( FALSE );
}
if( einfo->menu->first_entry == NULL ) {
return( TRUE );
}
return( WResolveSymIDs( einfo->menu->first_entry,
einfo->info->symbol_table ) );
}
Bool WResolveSymIDs( WMenuEntry *entry, WRHashTable *symbol_table )
{
if( !entry || !symbol_table ) {
return( FALSE );
}
while( entry ) {
if( entry->child ) {
WResolveSymIDs( entry->child, symbol_table );
}
WResolveEntrySymIDs( entry, symbol_table );
entry = entry->next;
}
return( TRUE );
}
Bool WResolveEntrySymIDs( WMenuEntry *entry, WRHashTable *symbol_table )
{
MenuFlags flags;
WRHashValue hv;
Bool ok;
ok = ( entry && symbol_table );
if( ok ) {
if( entry->item->IsPopup ) {
return( TRUE );
}
flags = entry->item->Item.Normal.ItemFlags;
if( flags & MENU_SEPARATOR ) {
return( TRUE );
}
ok = WRLookupName( symbol_table, entry->symbol, &hv );
}
if( ok ) {
entry->item->Item.Normal.ItemID = (uint_16)hv;
}
return( ok );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -