示例#1
0
Bool WGetEditWindowMenuEntry( WMenuEditInfo *einfo, WMenuEntry *entry,
                              Bool test_mod, Bool *reset )
{
    MenuFlags   flags;
    MenuFlags   iflags;
    uint_16     id;
    char        *text;
    char        *symbol;
    Bool        ok;

    flags = 0;
    id = 0;
    text = NULL;
    symbol = NULL;

    if( reset ) {
        *reset = FALSE;
    }

    ok = (einfo != NULL && einfo->edit_dlg != NULL && entry != NULL);

    if( ok ) {
        ok = WGetEditWindowFlags( einfo->edit_dlg, &flags );
    }

    if( ok ) {
        if( !(flags & MENU_SEPARATOR) ) {
            ok = WGetEditWindowText( einfo->edit_dlg, &text );
        }
    }

    if( ok ) {
        if( !(flags & MENU_POPUP) ) {
            ok = WGetEditWindowID( einfo->edit_dlg, &symbol, &id,
                                   einfo->info->symbol_table,
                                   einfo->combo_change );
        }
    }

    /* check if anything was actually modified */
    if( ok ) {
        // make sure the symbol info did not change
        ok = (entry->symbol == NULL && symbol != NULL) ||
             (entry->symbol != NULL && symbol == NULL);
        if( !ok ) {
            ok = symbol && stricmp( entry->symbol, symbol );
            if( !ok ) {
                iflags = entry->item->Item.Popup.ItemFlags;
                iflags &= ~MENU_ENDMENU;
                ok = (iflags != flags);
                if( !ok ) {
                    if( flags & MENU_POPUP ) {
                        ok = strcmp( entry->item->Item.Popup.ItemText, text );
                    } else if( flags & MENU_SEPARATOR ) {
                        ok = FALSE;
                    } else {
                        ok = (entry->item->Item.Normal.ItemID != id ||
                              strcmp( entry->item->Item.Normal.ItemText, text ));
                    }
                }
            }
        }
        if( test_mod ) {
            return( ok );
        }
    }

    if( ok ) {
        if( entry->item->IsPopup ) {
            if( entry->child != NULL && (flags & MENU_POPUP) == 0 ) {
                ok = WQueryNukePopup( einfo );
            }
        }
    }

    if( ok ) {
        if( entry->item->IsPopup ) {
            if( (flags & MENU_POPUP) == 0 ) {
                if( reset ) {
                    *reset = TRUE;
                }
                entry->preview_popup = (HMENU)NULL;
                if( entry->child != NULL ) {
                    WFreeMenuEntries( entry->child );
                    entry->child = NULL;
                }
            }
            if( entry->item->Item.Popup.ItemText ) {
                WMemFree( entry->item->Item.Popup.ItemText );
            }
        } else {
            // if the item is being changed from a normal item into a popup
            // or separator then reset the preview
            if( (flags & MENU_POPUP) != 0 || (flags & MENU_SEPARATOR) != 0 ) {
                if( reset ) {
                    *reset = TRUE;
                }
                entry->preview_popup = (HMENU)NULL;
            }
            if( entry->item->Item.Normal.ItemText ) {
                WMemFree( entry->item->Item.Normal.ItemText );
            }
        }
        if( entry->symbol != NULL ) {
            WMemFree( entry->symbol );
        }
        entry->item->IsPopup = ((flags & MENU_POPUP) != 0);
        if( entry->item->IsPopup ) {
            entry->item->Item.Popup.ItemText = text;
            entry->item->Item.Popup.ItemFlags = flags;
        } 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 );
}
示例#2
0
Bool WInsertStringEntry( WStringEditInfo *einfo )
{
    HWND                lbox;
    Bool                ok;
    Bool                replace;
    WStringBlock        *block;
    uint_16             id;
    char                *text;
    char                *symbol;
    int                 pos;

    text = NULL;
    symbol = NULL;
    replace = FALSE;

    ok = (einfo != NULL && einfo->tbl != NULL && einfo->edit_dlg != NULL);

    if( ok ) {
        lbox = GetDlgItem ( einfo->edit_dlg, IDM_STREDLIST );
        ok = (lbox != NULL);
    }

    if( ok ) {
        ok = WGetEditWindowText( einfo->edit_dlg, &text );
    }

    if( ok ) {
        ok = WGetEditWindowID( einfo->edit_dlg, &symbol, &id,
                               einfo->info->symbol_table, einfo->combo_change );
    }

    if( ok ) {
        if( id == 0 ) {
            id = DEFAULT_STRING_ID;
        }
        block = WInsertStringData( einfo, id, text, symbol, &replace );
        ok = (block != NULL);
    }

    if( ok ) {
        pos = WFindStringPos( einfo->tbl, id );
        ok = (pos != -1);
    }

    if( ok ) {
        if( replace ) {
            SendMessage( lbox, LB_DELETESTRING, pos, 0 );
        }
        ok = WAddEditWinLBoxEntry( einfo, block, id, pos );
    }


    if( ok ) {
        WSetEditWindowID( einfo->edit_dlg, id, block->symbol[id & 0xf] );
        ok = (SendMessage( lbox, LB_SETCURSEL, pos, 0 ) != LB_ERR);
        if( ok ) {
            einfo->current_block = block;
            einfo->current_string = id;
            einfo->current_pos = pos;
#if 0
            einfo->current_block = NULL;
            einfo->current_string = 0;
            einfo->current_pos = -1;
            WHandleSelChange( einfo );
#endif
        }
    }

    if( ok ) {
        SetFocus( GetDlgItem( einfo->edit_dlg, IDM_STREDTEXT ) );
        SendDlgItemMessage( einfo->edit_dlg, IDM_STREDTEXT, EM_SETSEL,
                            GET_EM_SETSEL_MPS( 0, -1 ) );
    }

    if( symbol != NULL ) {
        WMemFree( symbol );
    }

    if( text != NULL ) {
        WMemFree( text );
    }

    return( ok );
}