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

📄 wdefcust.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 <win1632.h>
#include <string.h>
#include <stdlib.h>

#include "wdeglbl.h"
#include "wdemem.h"
#include "wdemsgs.gh"
#include "wderesin.h"
#include "wdeopts.h"
#include "wdestat.h"
#include "wdedefin.h"
#include "wdeactn.h"
#include "wdemain.h"
#include "wderes.h"
#include "wdesdup.h"
#include "wdecust.h"
#include "wdelist.h"
#include "wdedebug.h"
#include "wde_wres.h"
#include "wdefutil.h"
#include "wdedefsz.h"
#include "wdefcust.h"

/****************************************************************************/
/* type definitions                                                         */
/****************************************************************************/
typedef struct {
    FARPROC      dispatcher;
    WNDPROC      win_proc;
    int          win_extra;
    char        *win_class;
    OBJPTR       object_handle;
    OBJ_ID       object_id;
    OBJPTR       control;
    WdeCustLib  *cust_lib;
    UINT         cust_index;
} WdeCustomObject;

typedef struct {
    char    *class;
    char    *new_name;
    int      win_extra;
    WNDPROC  win_proc;
} WdeCustClassNode;

/****************************************************************************/
/* external function prototypes                                             */
/****************************************************************************/
extern LRESULT WINEXPORT WdeCustomSuperClassProc (HWND, UINT, WPARAM, LPARAM);
extern BOOL WINEXPORT WdeCustomDispatcher     ( ACTION, WdeCustomObject *,
                                                void *, void * );

/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static void WdeChooseCustControlFromList ( LIST *, WdeDialogBoxControl *,
                                           WdeCustLib **, UINT * );
static BOOL WdeChooseCustControlType ( LPCCINFO, WdeDialogBoxControl *,
                                       WdeCustLib **, UINT *, uint_32 * );
static OBJPTR WdeMakeCustom          ( OBJPTR, RECT *, OBJPTR, int );
static OBJPTR WdeCustomCreater       ( OBJPTR, RECT *, OBJPTR, OBJ_ID,
                                       WdeDialogBoxControl *,
                                       WdeCustLib *, UINT );
static BOOL WdeCustomDestroy         ( WdeCustomObject *, BOOL *, void *);
static BOOL WdeCustomValidateAction  ( WdeCustomObject *, ACTION *, void *);
static BOOL WdeCustomCopyObject      ( WdeCustomObject *, WdeCustomObject **,
                                       WdeCustomObject * );
static BOOL WdeCustomIdentify        ( WdeCustomObject *, OBJ_ID *, void *);
static BOOL WdeCustomGetWndProc      ( WdeCustomObject *, WNDPROC *, void * );
static BOOL WdeCustomGetWindowClass  ( WdeCustomObject *, char **, void *);
static BOOL WdeCustomDefine          ( WdeCustomObject *, POINT *, void *);
static Bool WdeAddNewClassToList     ( char *, char *, int, WNDPROC );
static LIST *WdeFindClassInList      ( char *);
static Bool WdeCustomRegisterClass   ( char *, HINSTANCE, char **,
                                       int *, WNDPROC *);
static void WdeFreeClassList         ( void );
static void WdeFreeClassNode         ( WdeCustClassNode *);

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/
static HINSTANCE                WdeApplicationInstance;
static FARPROC                  WdeCustomDispatch;
static WdeDialogBoxControl      *WdeDefaultCustom = NULL;
static LIST                     *WdeCustClassList = NULL;
static char                     WdeClassName[MAX_NAME];

static DISPATCH_ITEM WdeCustomActions[] = {
    { DESTROY           ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomDestroy        }
,   { COPY              ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomCopyObject     }
,   { VALIDATE_ACTION   ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomValidateAction }
,   { IDENTIFY          ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomIdentify       }
,   { GET_WINDOW_CLASS  ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomGetWindowClass }
,   { DEFINE            ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomDefine         }
,   { GET_WND_PROC      ,  (BOOL (*)(OBJPTR, void *, void *))WdeCustomGetWndProc     }
};

#define MAX_ACTIONS      (sizeof(WdeCustomActions)/sizeof (DISPATCH_ITEM))

void WdeChooseCustControlFromList ( LIST *info_list,
                                    WdeDialogBoxControl *control,
                                    WdeCustLib **lib, UINT *index )
{
    LIST       *ilist;
    LPCCINFO    lpcci;
    uint_32     min_hd;
    BOOL        found;
    char        temp[5];

    min_hd = 32;
    *lib   = NULL;
    *index = 0;

    found = FALSE;

    if ( info_list ) {
        for ( ilist = info_list; ilist; ilist = ListNext(ilist) ) {
            lpcci = (LPCCINFO) ListElement(ilist);
            found = WdeChooseCustControlType ( lpcci, control, lib, index,
                                               &min_hd );
            if ( found ) {
                break;
            }
        }
    }

    if ( !found && min_hd ) {
        ultoa ( min_hd, temp, 10 );
        WdeWriteTrail("WdeChooseCustControlFromList: "
                      "Selected custom with hamming distance:");
        WdeWriteTrail(temp);
    }

    return;
}

BOOL WdeChooseCustControlType ( LPCCINFO lpcci, WdeDialogBoxControl *control,
                                WdeCustLib **lib, UINT *index,
                                uint_32 *min_hd )
{
    BOOL    found;
    uint_32 s1;
    uint_32 s2;
    uint_32 new_min;

    found = FALSE;

    s1  = lpcci->flStyleDefault;
    s1 &= 0x0000ffff;

    s2  = GETCTL_STYLE( control ) & 0x0000ffff;

    if ( s1 == s2 ) {
        found = WdeFindLibIndexFromInfo ( lpcci, lib, index );
    } else {
        new_min = WdeHammingDistance ( s1, s2 );
        if ( new_min < *min_hd ) {
            WdeFindLibIndexFromInfo ( lpcci, lib, index );
            *min_hd = new_min;
        }
    }

    return ( found );
}

OBJPTR WINEXPORT WdeCustomCreate1 ( OBJPTR parent, RECT *obj_rect,
                                    OBJPTR handle)
{
    return ( WdeMakeCustom ( parent, obj_rect, handle, 0 ) );
}

OBJPTR WINEXPORT WdeCustomCreate2 ( OBJPTR parent, RECT *obj_rect,
                                    OBJPTR handle)
{
    return ( WdeMakeCustom ( parent, obj_rect, handle, 1 ) );
}

Bool WdeCheckForSmallRect( OBJPTR parent, WdeCustLib *cust_lib,
                           UINT cust_index, RECT *obj_rect )
{
    UINT                width;
    UINT                height;
    WdeResizeRatio      r;

    if( !parent || !cust_lib || !obj_rect ) {
        return ( FALSE );
    }

    /* check if the objects size is greater than min allowed */
    if( ( ( obj_rect->right  - obj_rect->left ) >= MIN_X ) ||
        ( ( obj_rect->bottom - obj_rect->top  ) >= MIN_Y ) ) {
        return ( TRUE );
    }

    width = cust_lib->lpcci[cust_index].cxDefault;
    height = cust_lib->lpcci[cust_index].cyDefault;

    if( !Forward( parent, GET_RESIZER, &r, NULL ) ) {
        return( FALSE );
    }

    WdeMapCustomSize( &width, &height, &r );

    obj_rect->right  = obj_rect->left + width;
    obj_rect->bottom = obj_rect->top  + height;

    return( TRUE );
}

OBJPTR WdeMakeCustom ( OBJPTR parent, RECT *obj_rect,
                       OBJPTR handle, int which )
{
    DialogStyle         style;
    OBJPTR              ret;
    WdeCustLib          *cust_lib;
    UINT                cust_index;
    char                *class_name;
    WdeDialogBoxControl *control;
    LIST                *info_list;

    info_list  = NULL;
    cust_lib   = NULL;
    cust_index = 0;

    if ( handle == NULL ) {
        WdeGetCurrentCustControl ( which, &cust_lib, &cust_index );

        if ( !cust_lib ) {
            if ( !WdeSetCurrentCustControl (which) ) {
                WdeWriteTrail("WdeMakeCustom: "
                              "WdeSetCurrentCustControl failed!");
                return ( NULL );
            }
            WdeGetCurrentCustControl ( which, &cust_lib, &cust_index );
        }

        if ( cust_lib == NULL ) {
            WdeWriteTrail("WdeMakeCustom: No custom controls!");
            return ( NULL );
        }

        style = cust_lib->lpcci[cust_index].flStyleDefault;
        style &= ~WS_POPUP;
        style |= ( WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP );
        SETCTL_STYLE( WdeDefaultCustom, style );
        SETCTL_TEXT( WdeDefaultCustom,
                     ResStrToNameOrOrd(
                         cust_lib->lpcci[cust_index].szTextDefault ) );
        SETCTL_CLASSID( WdeDefaultCustom,
                     WdeStrToControlClass(
                         cust_lib->lpcci[cust_index].szClass ) );

        SETCTL_ID( WdeDefaultCustom, WdeGetNextControlID() );

        control = WdeDefaultCustom;
    } else {
        control = (WdeDialogBoxControl *) handle;
        class_name = WdeControlClassToStr ( GETCTL_CLASSID( control ) );
        if( class_name ) {
            WdeFindClassInAllCustLibs ( class_name, &info_list );
            WdeMemFree ( class_name );
        }
        if( !info_list ) {
            WdeSetStatusByID( -1, WDE_NOCUSTOMFORCLASS );
            return( NULL );
        }
        WdeChooseCustControlFromList ( info_list, control,
                                       &cust_lib, &cust_index );
        if( !cust_lib ) {
            WdeWriteTrail("WdeMakeCustom: "
                          "No custom control fits this class & style!");
            WdeSetStatusByID( -1, WDE_CANTFINDCUSTOM );
            return( NULL );
        }
    }

    WdeCheckForSmallRect( parent, cust_lib, cust_index, obj_rect );

    ret = WdeCustomCreater( parent, obj_rect, NULL,
                            ( CUSTCNTL1_OBJ + which ),
                            control, cust_lib, cust_index );

    if( handle == NULL ) {
        WdeMemFree( GETCTL_TEXT( WdeDefaultCustom ) );
        WdeMemFree( GETCTL_CLASSID( WdeDefaultCustom ) );
    }

    SETCTL_STYLE( WdeDefaultCustom, 0 );
    SETCTL_TEXT( WdeDefaultCustom, NULL );
    SETCTL_CLASSID( WdeDefaultCustom, NULL );

    return( ret );
}

void WdeFreeClassList ( void )
{
    LIST             *clist;
    WdeCustClassNode *node;

    for ( clist = WdeCustClassList; clist; clist = ListNext( clist ) ) {
        node = (WdeCustClassNode *) ListElement ( clist );
        WdeFreeClassNode ( node );
    }

    return;
}

void WdeFreeClassNode ( WdeCustClassNode *node )
{
    if ( node != NULL ) {
        if ( node->class != NULL ) {
            WdeMemFree ( node->class );
        }
        if ( node->new_name != NULL ) {
            WdeMemFree ( node->new_name );
        }
        WdeMemFree ( node );
    }
}

Bool WdeAddNewClassToList ( char *class, char *new_name,
                            int win_extra, WNDPROC win_proc )
{
    WdeCustClassNode *node;
    char             *str;

    node = (WdeCustClassNode *) WdeMemAlloc ( sizeof (WdeCustClassNode) );
    if ( node == NULL ) {
        WdeWriteTrail("WdeAddNewClassToList: node alloc failed!");
        return ( FALSE );
    }

    str = WdeStrDup ( class );
    if ( str == NULL ) {
        WdeWriteTrail("WdeAddNewClassToList: class strdup failed!");
        WdeMemFree ( node );
        return ( FALSE );
    }
    node->class     = str;

    str = WdeStrDup ( new_name );
    if ( str == NULL ) {
        WdeWriteTrail("WdeAddNewClassToList: new_name alloc failed!");
        WdeMemFree ( node->class );
        WdeMemFree ( node );
        return ( FALSE );
    }
    node->new_name  = str;

    node->win_extra = win_extra;
    node->win_proc  = win_proc;

    WdeInsertObject ( &WdeCustClassList, (void *)node );

    return ( TRUE );
}

LIST *WdeFindClassInList ( char *class )
{
    LIST             *clist;
    WdeCustClassNode *node;

    for ( clist = WdeCustClassList; clist; clist = ListNext( clist ) ) {
        node = (WdeCustClassNode *) ListElement ( clist );
        if ( !strcmpi ( node->class, class ) ) {
            break;
        }
    }

    return ( clist );
}

Bool WdeCustomRegisterClass( char *class, HINSTANCE inst, char **new_name,
                             int *win_extra, WNDPROC *win_proc )
{
    WdeCustClassNode *node;
    WNDCLASS          wc;
    LIST             *clist;

    if( ( clist = WdeFindClassInList ( class ) ) != NULL ) {
        node = (WdeCustClassNode *) ListElement( clist );
        *win_extra = node->win_extra;
        *win_proc  = node->win_proc;

⌨️ 快捷键说明

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