📄 wdefcntl.c
字号:
/****************************************************************************
*
* 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 "wdeactn.h"
#include "wde_wres.h"
#include "wdemem.h"
#include "wderes.h"
#include "wdeinfo.h"
#include "wdelist.h"
#include "wdesdup.h"
#include "wdefmenu.h"
#include "wdefdiag.h"
#include "wdectool.h"
#include "wdefont.h"
#include "wdemain.h"
#include "wdecust.h"
#include "wdefutil.h"
#include "wdetxtsz.h"
#include "wdedefsz.h"
#include "wdefordr.h"
#include "wdezordr.h"
#include "wdectl3d.h"
#include "wdeopts.h"
#include "wdedebug.h"
#include "wde_rc.h"
#include "wdefcntl.h"
#include "wdefbase.h"
#include "windlg.h"
#include "windlg32.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define WDE_CONTROL_MIN_WIDTH 1
#define WDE_CONTROL_MIN_HEIGHT 1
#define WDE_SIZE_TO_TEXT_PAD 2
#define WDE_CKECK_RADIO_ADJUST 16
/****************************************************************************/
/* type definitions */
/****************************************************************************/
typedef struct {
FARPROC dispatcher;
HWND window_handle;
HWND parent_handle;
OBJPTR object_handle;
OBJPTR parent;
OBJPTR o_item;
Bool sizeable;
Bool clear_interior;
HFONT font;
char *window_class;
char *symbol;
char *helpsymbol;
WdeDialogBoxControl *control_info;
WdeResInfo *res_info;
OBJPTR base_obj;
HWND tag;
WdeOrderMode mode;
WNDPROC old_proc;
} WdeControlObject;
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
extern BOOL WINEXPORT WdeControlDispatcher ( ACTION, WdeControlObject *,
void *, void *);
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static BOOL WdeControlTest ( WdeControlObject *, GLOBALHANDLE *, void *);
static BOOL WdeControlTestEX ( WdeControlObject *, GLOBALHANDLE *, void *);
static BOOL WdeControlDraw ( WdeControlObject *, RECT *, HDC *);
static BOOL WdeControlResolveSymbol ( WdeControlObject *, Bool *, Bool *);
static BOOL WdeControlResolveHelpSymbol( WdeControlObject *, Bool *, Bool *);
static BOOL WdeControlOnTop ( WdeControlObject *, void *, void *);
static BOOL WdeControlCreateWindow ( WdeControlObject *, void *, void *);
static BOOL WdeControlDestroyWindow ( WdeControlObject *, Bool *, Bool *);
static BOOL WdeControlShowWindow ( WdeControlObject *, Bool *, void *);
static BOOL WdeControlIsMarkValid ( WdeControlObject *, BOOL *, void *);
static BOOL WdeControlDestroy ( WdeControlObject *, BOOL *, void *);
static BOOL WdeControlSetFont ( WdeControlObject *, HFONT *, WdeResizeRatio *);
static BOOL WdeControlGetResizeInfo ( WdeControlObject *, RESIZE_ID *, void *);
static BOOL WdeControlValidateAction ( WdeControlObject *, ACTION *, void *);
static BOOL WdeControlGetWindowHandle ( WdeControlObject *, HWND *, void *);
static BOOL WdeControlResize ( WdeControlObject *, RECT *, BOOL *);
static BOOL WdeControlMove ( WdeControlObject *, POINT *, BOOL *);
static BOOL WdeControlNotify ( WdeControlObject *, NOTE_ID*, void *);
static BOOL WdeControlFirstChild ( WdeControlObject *, void *, void *);
static BOOL WdeControlPasteObject ( WdeControlObject *, OBJPTR, POINT *);
static BOOL WdeControlCutObject ( WdeControlObject *, WdeControlObject **, void *);
static BOOL WdeControlCopyObject ( WdeControlObject *, WdeControlObject **, WdeControlObject *);
static BOOL WdeControlGetObjectInfo ( WdeControlObject *, WdeDialogBoxControl **, char **);
static BOOL WdeControlSetObjectInfo ( WdeControlObject *, WdeDialogBoxControl *, char *);
static BOOL WdeControlSetObjectHelpInfo( WdeControlObject *, WdeDialogBoxControl *, char *);
static BOOL WdeControlGetObjectHelpInfo( WdeControlObject *, WdeDialogBoxControl **, char **);
static BOOL WdeControlSetClearInt ( WdeControlObject *, BOOL *, void *);
static BOOL WdeControlGetClearInt ( WdeControlObject *, BOOL *, void *);
static BOOL WdeChangeControlSize ( WdeControlObject *, BOOL, BOOL );
static BOOL WdeOffsetDialogUnits ( WdeControlObject *, WdeResizeRatio *);
static void WdeBringControlToTop ( WdeControlObject * );
static void WdeSetClearObjectPos ( WdeControlObject * );
static void WdeFreeControlObject ( WdeControlObject * );
static void WdeWriteControlToInfo ( WdeControlObject * );
static BOOL WdeControlModifyInfo ( WdeControlObject *, WdeInfoStruct *, void * );
static Bool WdeControlSetOrderMode ( WdeControlObject *, WdeOrderMode *,
WdeSetOrderLists ** );
static Bool WdeControlGetOrderMode ( WdeControlObject *, WdeOrderMode *, void *);
static BOOL WdeControlSizeToText ( WdeControlObject *, void *, void * );
/****************************************************************************/
/* static variables */
/****************************************************************************/
static FARPROC WdeControlDispatch;
static HINSTANCE WdeAppInst;
static DISPATCH_ITEM WdeControlActions[] = {
{ MOVE , (BOOL (*)(OBJPTR, void *, void *))WdeControlMove }
, { NOTIFY , (BOOL (*)(OBJPTR, void *, void *))WdeControlNotify }
, { RESIZE , (BOOL (*)(OBJPTR, void *, void *))WdeControlResize }
, { DRAW , (BOOL (*)(OBJPTR, void *, void *))WdeControlDraw }
, { ADD_SUBOBJECT , (BOOL (*)(OBJPTR, void *, void *))NULL }
, { DESTROY , (BOOL (*)(OBJPTR, void *, void *))WdeControlDestroy }
, { COPY , (BOOL (*)(OBJPTR, void *, void *))WdeControlCopyObject }
, { CUT , (BOOL (*)(OBJPTR, void *, void *))WdeControlCutObject }
, { PASTE , (BOOL (*)(OBJPTR, void *, void *))WdeControlPasteObject }
, { VALIDATE_ACTION , (BOOL (*)(OBJPTR, void *, void *))WdeControlValidateAction }
, { RESIZE_INFO , (BOOL (*)(OBJPTR, void *, void *))WdeControlGetResizeInfo }
, { GET_WINDOW_HANDLE , (BOOL (*)(OBJPTR, void *, void *))WdeControlGetWindowHandle }
, { CREATE_WINDOW , (BOOL (*)(OBJPTR, void *, void *))WdeControlCreateWindow }
, { DESTROY_WINDOW , (BOOL (*)(OBJPTR, void *, void *))WdeControlDestroyWindow }
, { SHOW_WIN , (BOOL (*)(OBJPTR, void *, void *))WdeControlShowWindow }
, { GET_OBJECT_INFO , (BOOL (*)(OBJPTR, void *, void *))WdeControlGetObjectInfo }
, { SET_OBJECT_INFO , (BOOL (*)(OBJPTR, void *, void *))WdeControlSetObjectInfo }
, { GET_OBJECT_HELPINFO, (BOOL (*)(OBJPTR, void *, void *))WdeControlGetObjectHelpInfo}
, { SET_OBJECT_HELPINFO, (BOOL (*)(OBJPTR, void *, void *))WdeControlSetObjectHelpInfo}
, { SET_FONT , (BOOL (*)(OBJPTR, void *, void *))WdeControlSetFont }
, { GET_FONT , (BOOL (*)(OBJPTR, void *, void *))NULL }
, { GET_NC_SIZE , (BOOL (*)(OBJPTR, void *, void *))NULL }
, { GET_NC_SIZE , (BOOL (*)(OBJPTR, void *, void *))NULL }
, { ON_TOP , (BOOL (*)(OBJPTR, void *, void *))WdeControlOnTop }
, { TEST , (BOOL (*)(OBJPTR, void *, void *))WdeControlTest }
, { TESTEX , (BOOL (*)(OBJPTR, void *, void *))WdeControlTestEX }
, { BECOME_FIRST_CHILD , (BOOL (*)(OBJPTR, void *, void *))WdeControlFirstChild }
, { GET_RESIZE_INC , (BOOL (*)(OBJPTR, void *, void *))NULL }
, { GET_SCROLL_RECT , (BOOL (*)(OBJPTR, void *, void *))NULL }
, { SET_CLEAR_INT , (BOOL (*)(OBJPTR, void *, void *))WdeControlSetClearInt }
, { IS_OBJECT_CLEAR , (BOOL (*)(OBJPTR, void *, void *))WdeControlGetClearInt }
, { IS_MARK_VALID , (BOOL (*)(OBJPTR, void *, void *))WdeControlIsMarkValid }
, { RESOLVE_SYMBOL , (BOOL (*)(OBJPTR, void *, void *))WdeControlResolveSymbol }
, { RESOLVE_HELPSYMBOL , (BOOL (*)(OBJPTR, void *, void *))WdeControlResolveHelpSymbol}
, { MODIFY_INFO , (BOOL (*)(OBJPTR, void *, void *))WdeControlModifyInfo }
, { SET_ORDER_MODE , (BOOL (*)(OBJPTR, void *, void *))WdeControlSetOrderMode }
, { GET_ORDER_MODE , (BOOL (*)(OBJPTR, void *, void *))WdeControlGetOrderMode }
, { SIZE_TO_TEXT , (BOOL (*)(OBJPTR, void *, void *))WdeControlSizeToText }
, { GET_RESIZER , (BOOL (*)(OBJPTR, void *, void *))NULL }
};
#define MAX_ACTIONS (sizeof(WdeControlActions)/sizeof (DISPATCH_ITEM))
void WdeControlModified ( WdeControlObject *obj )
{
if ( obj && obj->parent && ( obj->parent != obj->base_obj ) ) {
WdeDialogModified ( obj->parent );
}
}
void WdeBringControlToTop ( WdeControlObject *obj )
{
WdeBringWindowToTop ( obj->window_handle );
//WdeSOP ( obj, obj->parent );
}
void WdeSetClearObjectPos ( WdeControlObject *obj )
{
WdeBringWindowToTop ( obj->window_handle );
//WdeSOP ( obj, obj->parent );
}
OBJPTR WINEXPORT WdeControlCreate( OBJPTR parent, RECT *obj_rect,
OBJPTR handle)
{
OBJPTR ancestor;
OBJ_ID id;
WdeControlObject *new;
Bool ok;
WdeOrderMode mode;
WdeDebugCreate("Control", parent, obj_rect, handle);
new = NULL;
if ( !( ok = ( parent != NULL ) ) ) {
WdeWriteTrail("WdeControlCreate: Control has no parent!");
}
if( ok ) {
ok = ( !Forward( parent, GET_ORDER_MODE, &mode, NULL ) ||
( mode == WdeSelect ) );
}
if ( ok && !( ok = ( handle != NULL ) ) ) {
WdeWriteTrail("WdeControlCreate: Control cant use its own handle!");
}
if ( ok ) {
new = (WdeControlObject *) WdeMemAlloc ( sizeof(WdeControlObject) );
if ( !( ok = ( new != NULL ) ) ) {
WdeWriteTrail("WdeControlCreate: Object malloc failed");
} else {
memset ( new, 0, sizeof(WdeControlObject) );
}
}
if ( ok ) {
/* make sure we are setting the correct parent */
ancestor = parent;
Forward ((OBJPTR)ancestor, IDENTIFY, &id, NULL);
while ( (id != DIALOG_OBJ) &&
(id != BASE_OBJ) ) {
GetObjectParent(ancestor, &ancestor);
Forward ((OBJPTR)ancestor, IDENTIFY, &id, NULL);
}
new->parent = ancestor;
new->dispatcher = WdeControlDispatch;
new->sizeable = TRUE;
new->mode = WdeSelect;
if ( handle ) {
new->object_handle = handle;
} else {
new->object_handle = new;
}
new->base_obj = GetMainObject ();
new->res_info = WdeGetCurrentRes ();
if ( !( ok = ( new->base_obj && new->res_info ) ) ) {
WdeWriteTrail("WdeControlCreate: Bad base_obj or res_info!");
}
}
if ( ok && !( ok = Forward ( new->parent, GET_WINDOW_HANDLE,
&new->parent_handle, NULL ) ) ) {
WdeWriteTrail("WdeControlCreate: Couldn't get parent window handle!");
}
if ( ok && !( ok = Forward ( new->parent, GET_FONT,
&new->font, NULL ) ) ) {
WdeWriteTrail("WdeControlCreate: Couldn't get parent font!");
}
if ( ok ) {
new->o_item = Create( OBJ_ITEM, new->parent,
obj_rect, new->object_handle);
if ( !( ok = ( new->o_item != NULL ) ) ) {
WdeWriteTrail("WdeControlCreate: OITEM not created!");
}
}
if( ok ) {
ok = Forward( new->object_handle, GET_WINDOW_CLASS,
&new->window_class, NULL );
if( !ok ) {
WdeWriteTrail("WdeControlCreate: Couldn't get window class!");
}
}
if ( ok ) {
WdeControlModified ( new );
if ( !WdeGetStickyMode() ) {
WdeSetBaseObject ( IDM_SELECT_MODE );
}
} else {
if ( new ) {
if ( new->control_info ) {
WdeFreeDialogBoxControl( &new->control_info );
}
WdeMemFree ( new );
new = NULL;
}
}
return ( new );
}
BOOL WINEXPORT WdeControlDispatcher ( ACTION act, WdeControlObject *obj,
void *p1, void *p2)
{
int i;
WdeDebugDispatch("Control", act, obj, p1, p2);
for ( i = 0; i < MAX_ACTIONS; i++ ) {
if ( WdeControlActions[i].id == act ) {
if ( WdeControlActions[i].rtn ) {
return( ( WdeControlActions[i].rtn ) ( obj, p1, p2 ) );
} else {
return ( Forward ( obj->parent, act, p1, p2 ) );
}
}
}
return (Forward ((OBJPTR)obj->o_item, act, p1, p2));
}
Bool WdeControlInit( Bool first )
{
_wde_touch(first);
WdeAppInst = WdeGetAppInstance();
WdeControlDispatch =
MakeProcInstance( (FARPROC) WdeControlDispatcher, WdeAppInst );
return( TRUE );
}
void WdeControlFini ( void )
{
FreeProcInstance ( WdeControlDispatch );
}
BOOL WdeControlTest ( WdeControlObject *obj, GLOBALHANDLE *template,
void *p2 )
{
char *Text;
char *Class;
uint_32 style;
uint_16 ID;
/* touch unused vars to get rid of warning */
_wde_touch(p2);
Text = WdeResNameOrOrdinalToStr( GETCTL_TEXT( obj->control_info ), 10 );
if ( !Text ) {
Text = WdeStrDup ( "" );
if ( !Text ) {
return ( FALSE );
}
}
Class = WdeControlClassToStr( GETCTL_CLASSID( obj->control_info ) );
if ( !Class ) {
Class = WdeStrDup ( "" );
if ( !Class ) {
WdeMemFree ( Text );
return ( FALSE );
}
}
style = GETCTL_STYLE( obj->control_info );
ID = GETCTL_ID( obj->control_info );
if( !stricmp(obj->window_class,"combobox") ) {
style = style &
( 0xffffffff ^ ( CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE ) );
} else if( !stricmp(obj->window_class,"wde_borbtn") ) {
if( !WdeIsBorBtnIDSupported( GETCTL_ID( obj->control_info ) ) ) {
ID = WDE_PREVIEW_ID;
}
}
*template =
AddControl( *template,
GETCTL_SIZEX( obj->control_info ),
GETCTL_SIZEY( obj->control_info ),
GETCTL_SIZEW( obj->control_info ),
GETCTL_SIZEH( obj->control_info ),
ID,
style,
Class,
Text,
0, NULL );
WdeMemFree(Text);
WdeMemFree(Class);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -