📄 wdefutil.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 <win1632.h>
#include <stdio.h>
#include <string.h>
#include <mbstring.h>
#include <stdlib.h>
#include <ctype.h>
#include "wdeglbl.h"
#include "wdelist.h"
#include "wdemem.h"
#include "wderes.h"
#include "wdemain.h"
#include "wdestyle.h"
#include "wdegeted.h"
#include "wdereq.h"
#include "wdeopts.h"
#include "wdeactn.h"
#include "wdedebug.h"
#include "wdeedit.h"
#include "wdesdup.h"
#include "wdestat.h"
#include "wdedefin.h"
#include "wdefordr.h"
#include "wdecurr.h"
#include "wdectl3d.h"
#include "wdemsgs.gh"
#include "wde_wres.h"
#include "wde_rc.h"
#include "wdecctl.h"
#include "wdefutil.h"
#include "wrstrdup.h"
#include "wrutil.h"
#include "jdlg.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define WDE_START_CONTROL_ID 100
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
extern BOOL WINEXPORT WdeControlDefineProc ( HWND, UINT, WPARAM, LPARAM );
/****************************************************************************/
/* type definitions */
/****************************************************************************/
typedef struct {
Wde_Objects obj_id;
char *proc_name;
} WdeOBJIDToDefineProcItems;
typedef struct {
UINT ncm;
UINT m;
} WdeMouseMapStruct;
typedef struct {
OBJPTR base;
uint_16 id;
} WdeNextIDStruct;
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static WdeNextIDStruct *WdeFindNextIDStruct ( OBJPTR );
static char *WdeGetDefineProcFromOBJID ( Wde_Objects );
static void WdeSetDefineControlInfo ( WdeDefineObjectInfo *, HWND );
static void WdeGetDefineControlInfo ( WdeDefineObjectInfo *, HWND );
static void WdeDefineObjectLookupComboEntry ( HWND, WORD, WdeHashTable * );
static void WdeDefineObjectLookupHelpComboEntry ( HWND, WORD, WdeHashTable * );
/****************************************************************************/
/* static variables */
/****************************************************************************/
static LIST *WdeNextIDList = NULL;
static WdeMouseMapStruct WdeMouseMapper[] =
{
{ WM_NCMOUSEMOVE, WM_MOUSEMOVE }
, { WM_NCLBUTTONDOWN, WM_LBUTTONDOWN }
, { WM_NCLBUTTONUP, WM_LBUTTONUP }
, { WM_NCRBUTTONDOWN, WM_RBUTTONDOWN }
, { WM_NCRBUTTONUP, WM_RBUTTONUP }
, { WM_NCLBUTTONDBLCLK, WM_LBUTTONDBLCLK }
, { WM_NCRBUTTONDBLCLK, WM_RBUTTONDBLCLK }
, { WM_NCMBUTTONDOWN, WM_MBUTTONDOWN }
, { WM_NCMBUTTONUP, WM_MBUTTONUP }
, { WM_NCMBUTTONDBLCLK, WM_MBUTTONDBLCLK }
, { 0, 0 }
};
static WdeOBJIDToDefineProcItems WdeOBJIDToDefineProc[] = {
{ DIALOG_OBJ , "WdeDefineDIALOG" }
, { PBUTTON_OBJ , "WdeDefinePUSH" }
, { CBUTTON_OBJ , "WdeDefineCHECK" }
, { RBUTTON_OBJ , "WdeDefineRADIO" }
, { GBUTTON_OBJ , "WdeDefineGROUPBOX" }
, { FRAME_OBJ , "WdeDefineFRAME" }
, { TEXT_OBJ , "WdeDefineTEXT" }
, { ICON_OBJ , "WdeDefineICON" }
, { EDIT_OBJ , "WdeDefineEDIT" }
, { LISTBOX_OBJ , "WdeDefineLISTBOX" }
, { COMBOBOX_OBJ , "WdeDefineCOMBOBOX" }
, { HSCROLL_OBJ , "WdeDefineHSCROLLBAR" }
, { VSCROLL_OBJ , "WdeDefineVSCROLLBAR" }
, { SIZEBOX_OBJ , "WdeDefineSIZEBOX" }
, { SBAR_OBJ , "WdeDefineSTATUSBAR" }
, { LVIEW_OBJ , "WdeDefineLISTVIEW" }
, { TVIEW_OBJ , "WdeDefineTREEVIEW" }
, { TABCNTL_OBJ , "WdeDefineTABCONTROL" }
, { ANIMATE_OBJ , "WdeDefineANIMATE" }
, { UPDOWN_OBJ , "WdeDefineUPDOWN" }
, { TRACKBAR_OBJ , "WdeDefineTRACKBAR" }
, { PROGRESS_OBJ , "WdeDefinePROGRESSBAR" }
, { HOTKEY_OBJ , "WdeDefineHOTKEY" }
, { HEADER_OBJ , "WdeDefineHEADER" }
, { BASE_OBJ , NULL }
, { CONTROL_OBJ , NULL }
, { LAST__OBJ , NULL }
};
static void WdeSnapPoint( POINT *pt, unsigned vinc, unsigned hinc )
{
pt->x = ((pt->x + (hinc>>1)) / hinc ) * hinc;
pt->y = ((pt->y + (vinc>>1)) / vinc) * vinc;
}
void WdeSnapPointToGrid( POINT *pt )
{
unsigned hinc;
unsigned vinc;
hinc = WdeGetOption( WdeOptReqGridX );
vinc = WdeGetOption( WdeOptReqGridY );
WdeSnapPoint( pt, vinc, hinc );
}
OBJPTR WdeGetNextObject ( Bool up, OBJPTR obj, OBJPTR p )
{
OBJPTR old_current;
if ( !obj ) {
obj = WdeGetCurrObject();
}
if ( obj && ( obj != GetMainObject() ) ) {
old_current = obj;
if ( !p ) {
GetObjectParent ( obj, &p );
}
if ( p ) {
if ( Forward ( p, GET_NEXT_CHILD, &obj, &up ) &&
obj != old_current ) {
return ( obj );
}
}
}
return ( NULL );
}
OBJPTR WdeCloneObject ( OBJPTR obj, POINT *offset )
{
SUBOBJ_REQUEST req;
OBJPTR new;
OBJPTR parent;
RECT rect;
WORD state;
Bool ok;
new = NULL;
ok = ( offset->x || offset->y );
if( ok ) {
state = (WORD)GetKeyState( VK_CONTROL );
#ifdef __NT__
ok = ( ( state & 0x8000 ) != 0x00 );
#else
ok = ( ( state & 0x80 ) != 0x00 );
#endif
}
if ( ok ) {
ok = ( CopyObject ( obj, &new, NULL ) && new );
if ( !ok ) {
WdeWriteTrail ( "WdeCloneObject: CopyObject failed!" );
}
}
if ( ok ) {
Location ( obj, &rect );
OffsetRect ( &rect, offset->x, offset->y );
req.p.ty = BY_POINT;
req.p.pt.x = rect.left;
req.p.pt.y = rect.top;
parent = FindObject ( &req );
ok = ( parent && PasteObject ( new, parent, req.p.pt ) );
if ( !ok ) {
WdeWriteTrail ( "WdeCloneObject: PasteObject failed!" );
}
}
if ( !ok ) {
if ( new ) {
Destroy ( new, FALSE );
new = NULL;
}
}
return ( new );
}
void WdeFreeControlIDs ( void )
{
LIST *olist;
if ( WdeNextIDList ) {
WdeListLastElt ( WdeNextIDList, &olist );
for ( ; olist; olist = ListPrev ( olist ) ) {
WdeMemFree ( ListElement ( olist ) );
}
ListFree ( WdeNextIDList );
}
}
WdeNextIDStruct *WdeFindNextIDStruct ( OBJPTR base )
{
LIST *olist;
WdeNextIDStruct *ids;
for ( olist = WdeNextIDList; olist; olist = ListPrev ( olist ) ) {
ids = ListElement ( olist );
if ( ids->base == base ) {
return ( ids );
}
}
return ( NULL );
}
uint_16 WdeGetNextControlID ( void )
{
WdeNextIDStruct *ids;
OBJPTR base;
uint_16 id;
base = GetMainObject ();
if ( base ) {
if ( ids = WdeFindNextIDStruct ( base ) ) {
if ( ids->id == 0xffff ) {
ids->id = WDE_START_CONTROL_ID;
} else {
ids->id++;
}
} else {
ids = (WdeNextIDStruct *) WdeMemAlloc ( sizeof(WdeNextIDStruct) );
if ( ids ) {
ids->base = base;
ids->id = WDE_START_CONTROL_ID;
ListAddElt ( &WdeNextIDList, ids );
} else {
WdeWriteTrail ( "WdeGetNextControlID: ids alloc failed!" );
return ( WDE_START_CONTROL_ID );
}
}
id = ids->id;
} else {
WdeWriteTrail ( "WdeGetNextControlID: GetMainObject failed!" );
id = WDE_START_CONTROL_ID;
}
return ( id );
}
Bool WdeIsStrSpace ( char *s )
{
if( s ) {
for( ; *s; s=_mbsinc(s) ) {
if( _mbclen( s ) != 1 || ( _mbclen( s ) == 1 && !isspace( *s ) ) ) {
return( FALSE );
}
}
}
return( TRUE );
}
uint_32 WdeHammingDistance ( uint_32 x1, uint_32 x2 )
{
uint_32 d;
uint_32 s;
uint_8 i;
for ( i=0,s=1,d=0; i<32; i++, s<<=1) {
if ( (x1&s) != (x2&s) ) {
d++;
}
}
return ( d );
}
Bool WdeIsClassDefined ( char *class )
{
WNDCLASS wc;
BOOL ret;
HINSTANCE app_inst;
if ( class && *class ) {
app_inst = WdeGetAppInstance();
ret = GetClassInfo ( app_inst, class, &wc );
} else {
ret = FALSE;
}
return ( ret );
}
void WdeShowObjectWindow ( HWND win, Bool flag )
{
uint_32 s;
if ( win != NULL ) {
s = ( uint_32 ) GetWindowLong ( win, GWL_STYLE );
if ( flag ) {
if ( !(s & WS_VISIBLE) ) {
s |= WS_VISIBLE;
SetWindowLong ( win, GWL_STYLE, s );
}
} else {
if ( s & WS_VISIBLE ) {
s ^= WS_VISIBLE;
SetWindowLong ( win, GWL_STYLE, s );
}
}
}
}
void WdeBringWindowToTop ( HWND win )
{
#if 1
SetWindowPos ( win, HWND_TOP, 0,0,0,0,
SWP_NOSIZE | SWP_NOMOVE );
#else
BringWindowToTop ( win );
#endif
}
Bool WdePutObjFirst ( OBJPTR obj, LIST **list )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -