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

📄 wdesdlg.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <windows.h>
#include <string.h>

#include "win1632.h"

#include "wdeglbl.h"
#include "wdemem.h"
#include "wdeactn.h"
#include "wdeobjid.h"
#include "wderes.h"
#include "wdemain.h"
#include "wdefdlg.h"
#include "wdeldres.h"
#include "wdelist.h"
#include "wdefdiag.h"
#include "wdedebug.h"
#include "wde_wres.h"
#include "wdefutil.h"
#include "wdemsgbx.h"
#include "wdemsgs.gh"
#include "wdewait.h"
#include "wdegoto.h"
#include "wdectl3d.h"
#include "wde_rc.h"
#include "wde_wres.h"
#include "wdei2mem.h"
#include "wdesdlg.h"
#include "jdlg.h"

/****************************************************************************/
/* type definitions                                                         */
/****************************************************************************/
typedef struct {
    WdeResInfo *res_info;
    LIST       *selection;
    Bool        remove;
} WdeDialogSelectInfo;

/****************************************************************************/
/* external function prototypes                                             */
/****************************************************************************/
extern BOOL WINEXPORT WdeSelectDialogProc ( HWND, UINT, WPARAM, LPARAM );

/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static LIST  *WdeSelectDialogs        ( WdeResInfo *, Bool );
static Bool   WdeSetSelectInfo        ( HWND, WdeDialogSelectInfo * );
static Bool   WdeGetSelectInfo        ( HWND, WdeDialogSelectInfo * );
static Bool   WdeInitSelectListBox    ( WdeResInfo *, HWND );
static char  *WdeResolveDialogName    ( WdeResInfo *, WResID * );
static Bool   WdeAddControlToDialog   ( WdeResInfo *, OBJPTR,
                                        WdeDialogBoxControl *, POINT *, HWND );
static Bool   WdeAddControlsToDialog  ( WdeResInfo *, OBJPTR,
                                        WdeDialogBoxInfo * );
static OBJ_ID WdeGetOBJIDFromControl  ( WdeDialogBoxControl * );
static OBJ_ID WdeGetOBJIDFromClassNum ( uint_8, uint_32);

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/

Bool WdeResInfoHasDialogs ( WdeResInfo *res_info )
{
    return ( res_info->dlg_item_list != NULL );
}

Bool WdeSelectDialog( WdeResInfo *res_info )
{
    LIST          *selection;
    WdeResDlgItem *ditem;
    LIST          *slist;
    Bool           ok;
    Bool           last;

    if( ListCount( res_info->dlg_item_list ) == 1 ) {
        ok = WdeOpenSelectedDialog(
                res_info, ListElement( res_info->dlg_item_list ), TRUE );
        return( ok );
    }

    selection = WdeSelectDialogs( res_info, FALSE );

    ok = TRUE;

    WdeSetWaitCursor( TRUE );

    for( slist = selection; slist; slist = ListConsume( slist ) ) {
        ditem = (WdeResDlgItem *) ListElement( slist );
        last = ( ListNext(slist) == NULL );
        if( !WdeOpenSelectedDialog( res_info, ditem, last ) ) {
            WdeWriteTrail( "WdeSelectDialog: open failed!" );
            ok = FALSE;
        }
    }

    WdeSetWaitCursor( FALSE );

    return( ok );
}

Bool WdeRemoveDialog( WdeResInfo *res_info )
{
    LIST          *selection;
    WdeResDlgItem *ditem;
    LIST          *slist;
    Bool           ok;

    selection = WdeSelectDialogs ( res_info, TRUE );

    ok = TRUE;

    for ( slist = selection; slist; slist = ListConsume ( slist ) ) {
        ditem = (WdeResDlgItem *) ListElement ( slist );
        ok = WdeRemoveDialogFromResInfo ( res_info, ditem, TRUE );
    }

    Notify ( GetMainObject(), PRIMARY_OBJECT, NULL );

    return ( ok );
}

LIST *WdeSelectDialogs ( WdeResInfo *res_info, Bool remove )
{
    int                 ret;
    HINSTANCE           inst;
    FARPROC             proc;
    WdeDialogSelectInfo si;

    if ( !res_info ) {
        return ( FALSE );
    }

    inst = WdeGetAppInstance();

    proc = MakeProcInstance ( (FARPROC) WdeSelectDialogProc, inst );

    if ( proc == NULL ) {
        return ( FALSE );
    }

    si.res_info  = res_info;
    si.selection = NULL;
    si.remove    = remove;

    ret = JDialogBoxParam( inst, "WdeSelectDialog", res_info->res_win,
                           (DLGPROC) proc, (LPARAM) &si );

    FreeProcInstance( proc );

    /* if the window could not be created return FALSE */
    if ( ret == -1 ) {
        WdeWriteTrail("WdeSelectDialogs: dialog not created!");
        return ( NULL );
    }

    UpdateWindow ( WdeGetMainWindowHandle() );

    InitState( res_info->forms_win );

    return ( si.selection );
}

Bool WdeSetSelectInfo ( HWND hDlg, WdeDialogSelectInfo *si )
{
    HWND        win;
    char        *text;

    if( !si || !si->res_info || !WdeResInfoHasDialogs ( si->res_info ) ) {
        return( FALSE );
    }

    if( si->remove ) {
        text = WdeAllocRCString( WDE_REMOVEDIALOGS );
        SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM)text );
        if( text ) {
            WdeFreeRCString( text );
        }
    }

    win = GetDlgItem ( hDlg, IDB_SELECT_LISTBOX );

    return ( WdeInitSelectListBox ( si->res_info, win ) );
}

Bool WdeGetSelectInfo( HWND hDlg, WdeDialogSelectInfo *si )
{
    LRESULT        count;
    int           *sel;
    Bool           ok;
    LRESULT        ret;
    HWND           win;
    WdeResDlgItem *ditem;

    if( !si || !si->res_info ) {
        return( FALSE );
    }

    win = GetDlgItem( hDlg, IDB_SELECT_LISTBOX );

    count = SendMessage( win, LB_GETSELCOUNT, 0, 0 );

    if( !count ) {
        return( TRUE );
    }

    sel = (int *) WdeMemAlloc( count * sizeof(int) );
    if( !sel ) {
        WdeWriteTrail( "WdeGetSelectInfo: alloc failed!" );
        return( FALSE );
    }
    memset( sel, 0, count * sizeof(int) );

    ret = SendMessage( win, LB_GETSELITEMS, count, (LPARAM) sel );

    if( !ret || ( ret == LB_ERR ) ) {
        WdeWriteTrail( "WdeGetSelectInfo: LB_GETSELITEMS failed!" );
        return( FALSE );
    }

    if( ret != count ) {
        WdeWriteTrail( "WdeGetSelectInfo: Inconsistency detected!" );
    }

    ok  = TRUE;
    for( ; count > 0; count-- ) {
        ret = SendMessage( win, LB_GETITEMDATA, sel[count-1], 0 );
        if( ret != LB_ERR ) {
            ditem = WdeFindDialogInResInfo( si->res_info, (int)ret );
            if( !ditem ) {
                ok = FALSE;
                break;
            }
            ListAddElt( &(si->selection), ditem );
        }
    }

    if( sel ) {
        WdeMemFree( sel );
    }

    return( ok );
}

Bool WdeInitSelectListBox ( WdeResInfo *res_info, HWND win )
{
    char          *name;
    LIST          *dlist;
    WdeResDlgItem *ditem;
    WResID        *id;
    LRESULT        index;
    int            count;

    if ( !win ) {
        return ( FALSE );
    }

    dlist = res_info->dlg_item_list;

    SendMessage ( win, WM_SETREDRAW, FALSE, 0 );

    count = 0;

    while ( dlist ) {

        ditem = (WdeResDlgItem *) ListElement ( dlist );
        id    = NULL;

        if ( ditem->object || ditem->dialog_info ) {
            if ( ditem->object ) {
                Forward ( ditem->object, GET_OBJECT_INFO, NULL, &id );
            } else if ( ditem->dialog_name ) {
                id = ditem->dialog_name;
            }
        } else if ( ditem->rnode ) {
            id = &ditem->rnode->Info.ResName;
        }

        if ( !id ) {
            return ( FALSE );
        }

        name = WdeResolveDialogName ( res_info, id );

        if ( !name ) {
            return ( FALSE );
        }

        /* add the name to the list box */
        index = SendMessage ( win, LB_ADDSTRING, 0, (LPARAM) (LPCSTR) name );
        SendMessage ( win, LB_SETITEMDATA, index, (LPARAM) count );

        WdeMemFree ( name );

        count++;

        dlist = ListNext ( dlist );
    }

    SendMessage    ( win, WM_SETREDRAW, TRUE, 0 );
    InvalidateRect ( win, NULL, TRUE );

    return ( TRUE );
}

char *WdeResolveDialogName ( WdeResInfo *res_info, WResID *id )
{
    char *name;

    name = NULL;

    if ( ( res_info->hash_table ) && ( !id->IsName ) ) {
        name = WdeResolveValue ( res_info->hash_table,
                                 (WdeHashValue) id->ID.Num );
    }

    if ( !name ) {
        name = WResIDToStr ( id );
    }

    return ( name );

⌨️ 快捷键说明

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