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

📄 wdefbutt.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 "wdeglbl.h"
#include "wdemem.h"
#include "wderesiz.h"
#include "wderesin.h"
#include "wdeobjid.h"
#include "wdemain.h"
#include "wdedefin.h"
#include "wdedebug.h"
#include "wdeoinfo.h"
#include "wdefutil.h"
#include "wdedefsz.h"
#include "wdetxtsz.h"
#include "wde_rc.h"
#include "wde_wres.h"
#include "wdecctl.h"
#include "wdefbutt.h"

/****************************************************************************/
/* macro definitions                                                        */
/****************************************************************************/
#define WDE_GBOX_BORDER_SIZE WDE_BORDER_SIZE

/****************************************************************************/
/* type definitions                                                         */
/****************************************************************************/
typedef struct {
    FARPROC     dispatcher;
    OBJPTR      object_handle;
    OBJ_ID      object_id;
    OBJPTR      control;
} WdeButtonObject;

/****************************************************************************/
/* external function prototypes                                             */
/****************************************************************************/
extern BOOL    WINEXPORT WdeButtonDispatcher( ACTION, WdeButtonObject *,
                                              void *, void *);
extern LRESULT WINEXPORT WdeButtonSuperClassProc (HWND, UINT, WPARAM, LPARAM);

/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static OBJPTR   WdeMakeButton           ( OBJPTR, RECT *, OBJPTR, DialogStyle,
                                          char *, OBJ_ID );
static OBJPTR   WdeButtonCreate         ( OBJPTR, RECT *, OBJPTR,
                                          OBJ_ID, WdeDialogBoxControl *);
static BOOL     WdeButtonDestroy        ( WdeButtonObject *, BOOL *, void *);
static BOOL     WdeButtonValidateAction ( WdeButtonObject *, ACTION *, void *);
static BOOL     WdeButtonCopyObject     ( WdeButtonObject *,
                                          WdeButtonObject **,
                                          WdeButtonObject *);
static BOOL     WdeButtonIdentify       ( WdeButtonObject *, OBJ_ID *, void *);
static BOOL     WdeButtonGetWndProc     ( WdeButtonObject *, WNDPROC *, void * );
static BOOL     WdeButtonGetWindowClass ( WdeButtonObject *, char **, void *);
static BOOL     WdeButtonDefine         ( WdeButtonObject *, POINT *, void *);
static void     WdeButtonSetDefineInfo  ( WdeDefineObjectInfo *, HWND );
static void     WdeButtonGetDefineInfo  ( WdeDefineObjectInfo *, HWND );

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/
static HINSTANCE                WdeApplicationInstance;
static FARPROC                  WdeButtonDispatch;
static WdeDialogBoxControl      *WdeDefaultButton = NULL;
static int                      WdeButtonWndExtra;
static WNDPROC                  WdeOriginalButtonProc;
//static WNDPROC                        WdeButtonProc;

static DISPATCH_ITEM WdeButtonActions[] = {
    { DESTROY           ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonDestroy             }
,   { COPY              ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonCopyObject          }
,   { VALIDATE_ACTION   ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonValidateAction      }
,   { IDENTIFY          ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonIdentify            }
,   { GET_WINDOW_CLASS  ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonGetWindowClass      }
,   { DEFINE            ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonDefine              }
,   { GET_WND_PROC      ,  (BOOL (*)(OBJPTR, void *, void *))WdeButtonGetWndProc          }
};

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

OBJPTR WINEXPORT WdePButtonCreate ( OBJPTR parent, RECT *obj_rect,
                                    OBJPTR handle)
{
    if ( handle == NULL ) {
        return (WdeMakeButton ( parent, obj_rect, handle,
                                BS_PUSHBUTTON,
                                "Push",
                                PBUTTON_OBJ));
    } else {
        return ( WdeButtonCreate ( parent, obj_rect, NULL, PBUTTON_OBJ,
                                   (WdeDialogBoxControl *) handle) );
    }
}

OBJPTR WINEXPORT WdeCButtonCreate ( OBJPTR parent, RECT *obj_rect,
                                    OBJPTR handle)
{
    if ( handle == NULL ) {
        return (WdeMakeButton ( parent, obj_rect, handle,
                                BS_AUTOCHECKBOX,
                                "Check",
                                CBUTTON_OBJ));
    } else {
        return ( WdeButtonCreate ( parent, obj_rect, NULL,
                                   CBUTTON_OBJ, (WdeDialogBoxControl *) handle) );
    }
}

OBJPTR WINEXPORT WdeRButtonCreate ( OBJPTR parent, RECT *obj_rect,
                                    OBJPTR handle)
{
    if ( handle == NULL ) {
        return (WdeMakeButton ( parent, obj_rect, handle,
                                BS_AUTORADIOBUTTON,
                                "Radio",
                                RBUTTON_OBJ));
    } else {
        return ( WdeButtonCreate ( parent, obj_rect, NULL,
                                   RBUTTON_OBJ, (WdeDialogBoxControl *) handle) );
    }
}

OBJPTR WINEXPORT WdeGButtonCreate ( OBJPTR parent, RECT *obj_rect,
                                    OBJPTR handle)
{
    if ( handle == NULL ) {
        return (WdeMakeButton ( parent, obj_rect, handle,
                                BS_GROUPBOX,
                                "Group",
                                GBUTTON_OBJ));
    } else {
        return ( WdeButtonCreate ( parent, obj_rect, NULL,
                                   GBUTTON_OBJ, (WdeDialogBoxControl *) handle) );
    }
}

OBJPTR WdeMakeButton ( OBJPTR parent, RECT *obj_rect, OBJPTR handle,
                       DialogStyle style, char *text, OBJ_ID id )
{
    OBJPTR new;

    style |= WS_VISIBLE | WS_CHILD;
    if ( ( id == PBUTTON_OBJ ) || ( id == CBUTTON_OBJ ) ) {
        style |= WS_TABSTOP;
    }
    SETCTL_STYLE( WdeDefaultButton, style );
    SETCTL_TEXT( WdeDefaultButton, ResStrToNameOrOrd( text ) );
    SETCTL_ID( WdeDefaultButton, WdeGetNextControlID () );

    WdeChangeSizeToDefIfSmallRect( parent, id, obj_rect );

    new = WdeButtonCreate ( parent, obj_rect, handle, id, WdeDefaultButton );

    WdeMemFree( GETCTL_TEXT(WdeDefaultButton) );
    SETCTL_TEXT( WdeDefaultButton, NULL );

    return ( new );
}

OBJPTR WdeButtonCreate ( OBJPTR parent, RECT *obj_rect, OBJPTR handle,
                         OBJ_ID id, WdeDialogBoxControl *info)
{
    WdeButtonObject *new;
    Bool             b;

    WdeDebugCreate("Button", parent, obj_rect, handle);

    if ( parent == NULL ) {
        WdeWriteTrail("WdeButtonCreate: Button has no parent!");
        return ( NULL );
    }

    new = (WdeButtonObject *) WdeMemAlloc ( sizeof(WdeButtonObject) );
    if ( new == NULL ) {
        WdeWriteTrail("WdeButtonCreate: Object malloc failed");
        return ( NULL );
    }

    new->dispatcher = WdeButtonDispatch;

    new->object_id = id;

    if ( handle ==  NULL ) {
        new->object_handle = new;
    } else {
        new->object_handle = handle;
    }

    new->control = Create( CONTROL_OBJ, parent, obj_rect, new->object_handle);

    if (new->control == NULL) {
        WdeWriteTrail("WdeButtonCreate: CONTROL_OBJ not created!");
        WdeMemFree ( new );
        return ( NULL );
    }

    if ( id == GBUTTON_OBJ ) {
        b = TRUE;
        if (!Forward ( new->object_handle, SET_CLEAR_INT, &b, NULL ) ) {
            WdeWriteTrail("WdeButtonCreate: SET_CLEAR_INT failed!");
            Destroy ( new->control, FALSE );
            WdeMemFree ( new );
            return ( NULL );
        }
    }

    if (!Forward ( new->object_handle, SET_OBJECT_INFO, info, NULL) ) {
        WdeWriteTrail("WdeButtonCreate: SET_OBJECT_INFO failed!");
        Destroy ( new->control, FALSE );
        WdeMemFree ( new );
        return ( NULL );
    }

    if (!Forward ( new->object_handle, CREATE_WINDOW, NULL, NULL) ) {
        WdeWriteTrail("WdeButtonCreate: CREATE_WINDOW failed!");
        Destroy ( new->control, FALSE );
        WdeMemFree ( new );
        return ( NULL );
    }

    return ( new );
}

BOOL WINEXPORT WdeButtonDispatcher ( ACTION act, WdeButtonObject *obj,
                                     void *p1, void *p2)
{
    int     i;

    WdeDebugDispatch("Button", act, obj, p1, p2);

    for ( i = 0; i < MAX_ACTIONS; i++ ) {
        if( WdeButtonActions[i].id == act ) {
            return( (WdeButtonActions[i].rtn)( obj, p1, p2 ) );
        }
    }

    return (Forward ((OBJPTR)obj->control, act, p1, p2));
}

Bool WdeButtonInit( Bool first )
{
    WNDCLASS    wc;

    WdeApplicationInstance = WdeGetAppInstance();
    GetClassInfo( (HINSTANCE)NULL, "BUTTON", &wc );
    WdeOriginalButtonProc = wc.lpfnWndProc;
    WdeButtonWndExtra = wc.cbWndExtra;

    if( first ) {
#if 0
        if ( wc.style & CS_GLOBALCLASS ) {
            wc.style ^= CS_GLOBALCLASS;
        }
        if ( wc.style & CS_PARENTDC ) {
            wc.style ^= CS_PARENTDC;
        }
        wc.style |= ( CS_HREDRAW | CS_VREDRAW );
        wc.hInstance     = WdeApplicationInstance;
        wc.lpszClassName = "wdebutton";
        wc.cbWndExtra    += sizeof( OBJPTR );
        //wc.lpfnWndProc        = WdeButtonSuperClassProc;
        if( !RegisterClass( &wc ) ) {
            WdeWriteTrail("WdeButtonInit: RegisterClass failed.");
        }
#endif
    }

    WdeDefaultButton = WdeAllocDialogBoxControl ();
    if( !WdeDefaultButton ) {
        WdeWriteTrail ("WdeButtonInit: Alloc of control failed!");
        return( FALSE );
    }

    /* set up the default control structure */
    SETCTL_STYLE( WdeDefaultButton, 0 );
    SETCTL_ID( WdeDefaultButton, 0 );

⌨️ 快捷键说明

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