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

📄 wdefcust.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
*
*                            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 <stdlib.h>

#include "wdeglbl.h"
#include "wdemem.h"
#include "wdemsgs.gh"
#include "wderes.h"
#include "wdeopts.h"
#include "wdestat.h"
#include "wdedefin.h"
#include "wdeactn.h"
#include "wdemain.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;
    WdeCustControl   *cust_info;
    UINT              cust_type;
} 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 * );
extern WORD  WINEXPORT WdeIDToStr             ( WORD, LPSTR, WORD );
extern DWORD WINEXPORT WdeStrToID             ( LPSTR );


/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static void WdeChooseCustControlFromList ( LIST *, WdeDialogBoxControl *,
                                           WdeCustControl **, UINT * );
static BOOL WdeChooseCustControlType ( WdeCustControl *, WdeDialogBoxControl *,
                                       WdeCustControl **, UINT *, uint_32 * );
static OBJPTR WdeMakeCustom          ( OBJPTR, RECT *, OBJPTR, int );
static OBJPTR WdeCustomCreater       ( OBJPTR, RECT *, OBJPTR, OBJ_ID,
                                       WdeDialogBoxControl *,
                                       WdeCustControl *, 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 FARPROC                  WdeStr2ID;
static FARPROC                  WdeID2Str;
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,
                                    WdeCustControl **rinfo, UINT *rtype )
{
    LIST           *ilist;
    WdeCustControl *info;
    uint_32         min_hd;
    BOOL            found;
    char            temp[5];

    min_hd = 32;
    *rinfo = NULL;

    found = FALSE;

    if ( info_list != NULL ) {
        for ( ilist = info_list; ilist; ilist = ListNext(ilist) ) {
            info = (WdeCustControl *) ListElement(ilist);
            found = WdeChooseCustControlType ( info, control, rinfo, rtype,
                                               &min_hd );
            if ( found ) {
                break;
            }
        }
    }

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

    return;
}

BOOL WdeChooseCustControlType ( WdeCustControl *info,
                                WdeDialogBoxControl *control,
                                WdeCustControl **rinfo, UINT *rtype,
                                uint_32 *min_hd )
{
    uint_16 type;
    BOOL    found;
    uint_32 s1;
    uint_32 s2;
    uint_32 new_min;

    /* if this class just has one type ASSUME (YIKES!!) that this is the
     * one we are looking for.
     */
    if ( info->control_info.ms.wCtlTypes <= 1 ) {
        *rinfo = info;
        *rtype = 0;
        return ( TRUE );
    }

    found = FALSE;

    for ( type = 0; type < info->control_info.ms.wCtlTypes; type++ ) {
        if ( info->ms_lib ) {
            s1 = info->control_info.ms.Type[type].dwStyle;
        } else {
            s1 = info->control_info.bor.Type[type].dwStyle;
        }
        s1 &= 0x0000ffff;
        s2 = GETCTL_STYLE( control ) & 0x0000ffff;
        if ( s1 == s2 ) {
            found = TRUE;
            break;
        }
        new_min = WdeHammingDistance ( s1, s2 );
        if ( new_min < *min_hd ) {
            *rinfo = info;
            *rtype = type;
            *min_hd = new_min;
        }
    }

    if ( found ) {
        *rinfo = info;
        *rtype = type;
    }

    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, WdeCustControl *cust_info,
                           UINT cust_type, RECT *obj_rect )
{
    uint_32             width;
    uint_32             height;
    WdeResizeRatio      r;

    if( !parent || !cust_info || !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 );
    }

    if( cust_info->ms_lib ) {
        width = cust_info->control_info.ms.Type[cust_type].wWidth;
        height = cust_info->control_info.ms.Type[cust_type].wHeight;
    } else {
        width = cust_info->control_info.bor.Type[cust_type].wWidth;
        height = cust_info->control_info.bor.Type[cust_type].wHeight;
    }

    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;
    WdeCustControl      *cust_info;
    UINT                cust_type;
    char                *class_name;
    WdeDialogBoxControl *control;
    LIST                *info_list;

    info_list = NULL;
    cust_info = NULL;
    cust_type = 0;

    if ( handle == NULL ) {
        WdeGetCurrentCustControl ( which, &cust_info, &cust_type );

        if ( cust_info == NULL ) {
            if ( !WdeSetCurrentCustControl (which) ) {
                WdeWriteTrail("WdeMakeCustom: "
                              "WdeSetCurrentCustControl failed!");
                return ( NULL );
            }
            WdeGetCurrentCustControl ( which, &cust_info, &cust_type );
        }

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

        if ( cust_info->ms_lib ) {
            style = cust_info->control_info.ms.Type[cust_type].dwStyle;
            SETCTL_TEXT( WdeDefaultCustom,
                    ResStrToNameOrOrd( cust_info->control_info.ms.szTitle ) );
            SETCTL_CLASSID( WdeDefaultCustom,
                    WdeStrToControlClass( cust_info->control_info.ms.szClass ) );
        } else {
            style = cust_info->control_info.bor.Type[cust_type].dwStyle;
            SETCTL_TEXT( WdeDefaultCustom,
                    ResStrToNameOrOrd ( cust_info->control_info.bor.szTitle ) );
            SETCTL_CLASSID( WdeDefaultCustom,
                    WdeStrToControlClass ( cust_info->control_info.bor.szClass ) );
        }

        SETCTL_ID( WdeDefaultCustom, WdeGetNextControlID() );

        style &= ~WS_POPUP;
        style |= ( WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP );

⌨️ 快捷键说明

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