⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wdesvdlg.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                helpsymbol = WdeMemAlloc(32);
                if (control->HelpId > 0) {
                    sprintf(helpsymbol, "%ld", control->HelpId);
                } else {
                    *helpsymbol = '\0';   /* empty help id if 0 */
                }
            }

            if( cid ) {
                fprintf( fp, "%s %s, \"%s\", %s, %d, %d, %d, %d",
                         ControlStr, cid, cclass, cstyle,
                         GETCTL_SIZEX(control), GETCTL_SIZEY(control),
                         GETCTL_SIZEW(control), GETCTL_SIZEH(control) );
            } else {
                fprintf( fp, "%s %d, \"%s\", %s, %d, %d, %d, %d",
                         ControlStr, (GETCTL_ID(control) == 0xffff) ? -1 : GETCTL_ID(control),
                         cclass, cstyle,
                         GETCTL_SIZEX(control), GETCTL_SIZEY(control),
                         GETCTL_SIZEW(control), GETCTL_SIZEH(control) );
            }

#if __NT__XX
            WdeSetEXFlagText( GETCTL_EXSTYLE(control), &ExStyle );
#endif
            /* put out the extended styles */
            if (ExStyle) {
                fprintf(fp, ", %s", ExStyle);
            } else if (*helpsymbol) {
                fprintf(fp, ", 0");    // or a 0 if help id follows
            }


            /* put out the help id, if its there */
            if (*helpsymbol)
                fprintf(fp, ", %s", helpsymbol);
            fprintf(fp, "\n");

            /* free the help symbol */
            WdeMemFree(helpsymbol);

        } else {
            /* standard control */
            if( cid ) {
                fprintf( fp, "%s %s, \"%s\", %s, %d, %d, %d, %d\n",
                         ControlStr, cid, cclass, cstyle,
                         GETCTL_SIZEX(control), GETCTL_SIZEY(control),
                         GETCTL_SIZEW(control), GETCTL_SIZEH(control) );
            } else {
                fprintf( fp, "%s %d, \"%s\", %s, %d, %d, %d, %d\n",
                         ControlStr, (GETCTL_ID(control) == 0xffff) ? -1 : GETCTL_ID(control),
                         cclass, cstyle,
                         GETCTL_SIZEX(control), GETCTL_SIZEY(control),
                         GETCTL_SIZEW(control), GETCTL_SIZEH(control) );
            }
        }
        if( ControlStr ) {
            WdeMemFree(ControlStr);
        }
    }

    if( n ) {
        WdeMemFree( n );
    }

    if( ctext_alloc && ctext ) {
        WdeMemFree( ctext );
    }

    if( cclass ) {
        WdeMemFree( cclass );
    }

    if( cstyle ) {
        WdeMemFree( cstyle );
    }

#if __NT__XX
    if( ExStyle ) {
        WdeMemFree( ExStyle );
    }
#endif

    if( cid_alloc && cid ) {
        WdeMemFree( cid );
    }

    return( ok );
}

Bool WdeWriteDlgHeader( WdeResInfo *rinfo, WdeResDlgItem *ditem, FILE *fp )
{
    DialogSizeInfo      size;
    DialogStyle         style;
    ResNameOrOrdinal    *rname;
    char                *name;
    char                *str;
    Bool                ok;
    WdeDialogBoxHeader  *dhptr = ditem->dialog_info->dialog_header;
    uint_32             ExStyle;

    name = NULL;
    ok = ( rinfo && ditem && fp );

    if( ok ) {
        if( ditem->dialog_info->dialog_header->symbol ) {
            name = WdeStrDup( ditem->dialog_info->dialog_header->symbol );
        } else {
            if( rinfo->hash_table && !ditem->dialog_name->IsName ) {
                name = WdeResolveValue( rinfo->hash_table,
                                        ditem->dialog_name->ID.Num );
            }
        }
        if( name == NULL ) {
            name = WResIDToStr( ditem->dialog_name );
        }
        ok = ( name != NULL );
    }

    if( ok ) {
        str = NULL;
        ok = WdeSetMemFlagsText( ditem->dialog_info->MemoryFlags, &str );
    }

    if( ok ) {
        size = GETHDR_SIZE( dhptr );
        /* check if this is a 32 bit extended dialog */
        if (dhptr->is32bitEx)
        {
            char *helpsymbol;

            /* build a help symbol for the DialogEx line */
            if (dhptr->helpsymbol) {
                helpsymbol = WdeStrDup(dhptr->helpsymbol);
            } else {
                helpsymbol = WdeMemAlloc(32);
                if (dhptr->HelpId > 0) {
                    sprintf(helpsymbol, "%ld", dhptr->HelpId);
                } else {
                    *helpsymbol = '\0';
                }
            }

            if( str ) {
                fprintf( fp, "%s DIALOGEX %s %d, %d, %d, %d",
                         name, str, size.x, size.y, size.width, size.height);
                WdeMemFree( str );
                str = NULL;
            } else {
                fprintf( fp, "%s DIALOGEX %d, %d, %d, %d",
                         name, size.x, size.y, size.width, size.height);
            }
            if (*helpsymbol)
                fprintf(fp, ", %s", helpsymbol);
            fprintf(fp, "\n");

            /* free the help symbol */
            WdeMemFree(helpsymbol);

        } else {
            /* standard dialog */
            if( str ) {
                fprintf( fp, "%s DIALOG %s %d, %d, %d, %d\n",
                         name, str, size.x, size.y, size.width, size.height );
                WdeMemFree( str );
                str = NULL;
            } else {
                fprintf( fp, "%s DIALOG %d, %d, %d, %d\n",
                         name, size.x, size.y, size.width, size.height );
            }
        }
        style = GETHDR_STYLE( ditem->dialog_info->dialog_header );
        ok = ( WdeSetDialogFlagText( style, &str ) && str );
        WdeMemFree( name );
        name = NULL;
    }

    if( ok ) {
        if( str ) {
            fprintf( fp, "STYLE %s\n", str );
            WdeMemFree( str );
            str = NULL;
        }
        rname = GETHDR_CLASSNAME( ditem->dialog_info->dialog_header );
        if( rname ) {
            str = WdeResNameOrOrdinalToStr ( rname, 10 );
            if( str ) {
                if( *str ) {
                    fprintf( fp, "CLASS \"%s\"\n", str );
                }
                WdeMemFree( str );
                str = NULL;
            }
        }
        if( style & WS_CAPTION ) {
            if( GETHDR_CAPTION( ditem->dialog_info->dialog_header ) ) {
                str = WRConvertStringFrom( GETHDR_CAPTION( ditem->dialog_info->dialog_header ), "\t\n\"", "tn\"" );
                if( str ) {
                    fprintf( fp, "CAPTION \"%s\"\n", str );
                    WdeMemFree( str );
                    str = NULL;
                }
            }
        }

        ExStyle = 0;
#if __NT__XX
        ExStyle = GETHDR_EXSTYLE( ditem->dialog_info->dialog_header );
        WdeSetEXFlagText( ExStyle, &str );
        if( str ) {
            fprintf( fp, "EXSTYLE %s\n", str );
            WdeMemFree( str );
            str = NULL;
        }
#endif

        rname = GETHDR_MENUNAME( ditem->dialog_info->dialog_header );
        if( rname ) {
            str = WdeResNameOrOrdinalToStr ( rname, 10 );
            if( str ) {
                if( *str ) {
                    fprintf( fp, "MENU %s\n", str );
                }
                WdeMemFree( str );
                str = NULL;
            }
        }
        if( ( style & DS_SETFONT ) &&
            GETHDR_FONTNAME( ditem->dialog_info->dialog_header ) ) {
            fprintf( fp, "FONT %d, \"%s\"\n",
                     GETHDR_POINTSIZE( ditem->dialog_info->dialog_header ),
                     GETHDR_FONTNAME( ditem->dialog_info->dialog_header ) );
        }
    }

    return( ok );
}

char *WdeConstructDLGInclude( WdeResInfo *rinfo )
{
    char        *include;
    int         len;

    if( !rinfo || !rinfo->sym_name ) {
        return( NULL );
    }

    len = strlen( rinfo->sym_name );
    len += 1 + 1 + 2 + 2; // for a nullchar, tab, 2 double quotes, and "\0"
    include = WdeMemAlloc( len );
    if( include == NULL ) {
        return( NULL );
    }
    strcpy( include, "\t\"" );
    strcat( include, rinfo->sym_name );
    strcat( include, "\\0\"" );

    return( include );
}

void WdeWriteDLGInclude( WdeResInfo *rinfo, FILE *fp )
{
    char        *include;

    if( !rinfo || !rinfo->sym_name || !fp ) {
        return;
    }

    include = WdeConstructDLGInclude( rinfo );
    if( include == NULL ) {
        return;
    }

    fwrite( "DLGINCLUDE RCDATA DISCARDABLE\n", sizeof(char), 30, fp );
    fwrite( "BEGIN\n", sizeof(char), 6, fp );
    fwrite( include, sizeof(char), strlen(include), fp );
    fwrite( "\nEND\n\n", sizeof(char), 6, fp );

    WdeMemFree( include );
}

Bool WdeSaveDlgItemToRC( WdeResInfo *rinfo, WdeResDlgItem *ditem, FILE *fp )
{
    Bool                ok;
    Bool                wrote_begin;
    LIST                *clist;
    WdeDialogBoxControl *control;
    uint_16             nlen;
    char                *ctext;

    wrote_begin = FALSE;
    ok = ( rinfo && ditem && ditem->dialog_info && fp );

    if( ok ) {
        ok = WdeWriteDlgHeader( rinfo, ditem, fp );
    }

    if( ok ) {
        // find the longest control text
        nlen = 0;
        ctext = NULL;
        clist = ditem->dialog_info->control_list;
        while( clist ) {
            control = (WdeDialogBoxControl *) ListElement( clist );
            if( GETCTL_TEXT(control) ) {
                ctext = WdeResNameOrOrdinalToStr( GETCTL_TEXT(control), 10 );
                if (ctext) {
                    if (strlen(ctext) > nlen) {
                        nlen = strlen(ctext);
                    }
                    WdeMemFree( ctext );
                    ctext = NULL;
                }
            }
            clist = ListNext( clist );
        }

        fwrite( "BEGIN\n", sizeof(char), 6, fp );
        wrote_begin = TRUE;
        clist = ditem->dialog_info->control_list;
        while( ok && clist ) {
            control = (WdeDialogBoxControl *) ListElement( clist );
            ok = WdeWriteDlgControl( rinfo, control, ditem->dialog_info->dialog_header->is32bitEx, fp, nlen );
            clist = ListNext( clist );
        }
    }

    if( wrote_begin ) {
        fwrite( "END\n\n", sizeof(char), 5, fp );
    }

    return( ok );
}

Bool WdeCreateItemDBI( WdeResInfo *rinfo, WdeResDlgItem *ditem )
{
    if( !rinfo || !ditem ) {
        return( FALSE );
    }

    if( ditem->object ) {
        if( WdeGetItemDBI( ditem ) == NULL ) {
            return( FALSE );
        }
    } else if( !ditem->dialog_info ) {
        ditem->dialog_info = WdeLoadDialogFromRes( rinfo, ditem->lnode, ditem->is32bit );
        if( ditem->dialog_info == NULL ) {
            return( FALSE );
        }
        if( !ditem->dialog_name ) {
            ditem->dialog_name = WdeCopyWResID( &ditem->rnode->Info.ResName );
            if( !ditem->dialog_name ) {
                return( FALSE );
            }
        }
    }

    return( TRUE );
}

Bool WdeSaveResInfoToRC( char *filename, WdeResInfo *rinfo, Bool append )
{
    FILE                *fp;
    Bool                ok;
    LIST                *dlist;
    WdeResDlgItem       *ditem;

    fp = NULL;
    ok = ( rinfo && rinfo->info && filename );

    if( ok ) {
        if( append ) {
            fp = fopen( filename, "at" );
        } else {
            fp = fopen( filename, "wt" );
        }
        ok = ( fp != NULL );
        dlist = rinfo->dlg_item_list;
    }

//    if( ok ) {
//      WdeWriteDLGInclude( rinfo, fp );
//    }

    while( ok && dlist ) {
        ditem = (WdeResDlgItem *) ListElement ( dlist );
        ok = WdeCreateItemDBI( rinfo, ditem );
        ok = ok && WdeSaveDlgItemToRC( rinfo, ditem, fp );
        dlist = ListNext ( dlist );
    }

    if( fp ) {
        fclose ( fp );
    }

    return( ok );
}

Bool WdeSaveObjectToRC( char *filename, WdeResInfo *rinfo,
                        WdeResDlgItem *ditem, Bool append )
{
    FILE                *fp;
    Bool                ok;

    fp = NULL;
    ok = ( rinfo && ditem && filename );

    if( ok ) {
        if( append ) {
            fp = fopen( filename, "at" );
        } else {
            fp = fopen( filename, "wt" );
        }
        ok = ( fp != NULL );
    }

    if( ok ) {
        ok = WdeSaveDlgItemToRC( rinfo, ditem, fp );
    }

    if( fp ) {
        fclose ( fp );
    }

    return( ok );
}

Bool WdeSaveRC( char *filename, WdeResInfo *res_info )
{
    Bool        ok;

    ok = ( filename && res_info );

    if( ok && res_info->info && res_info->info->file_name ) {
        ok = WRUpdateTmp( res_info->info );
    }

    if( ok ) {
        ok = WdeSaveResInfoToRC( filename, res_info, FALSE );
    }

    return( ok );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -