guirdlg.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 676 行 · 第 1/2 页
C
676 行
/****************************************************************************
*
* 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 "guiwind.h"
#include <string.h>
#include <stdlib.h>
#include "guiutil.h"
#include "guixscal.h"
#include "guildstr.h"
#include "watcom.h"
#include "resdiag.h"
#define DLG_X_MULT 4
#define DLG_Y_MULT 14
void GUIFreeDialogBoxControlPtrs( DialogBoxControl *dbc )
{
if( dbc ) {
if( dbc->ClassID ) {
GUIMemFree( dbc->ClassID );
dbc->ClassID = NULL;
}
if( dbc->Text ) {
GUIMemFree( dbc->Text );
dbc->Text = NULL;
}
}
}
void GUIFreeDialogBoxHeader( DialogBoxHeader *hdr )
{
if( hdr ) {
if( hdr->MenuName ) {
GUIMemFree( hdr->MenuName );
hdr->MenuName = NULL;
}
if( hdr->ClassName ) {
GUIMemFree( hdr->ClassName );
hdr->ClassName = NULL;
}
if( hdr->Caption ) {
GUIMemFree( hdr->Caption );
hdr->Caption = NULL;
}
if( hdr->FontName ) {
GUIMemFree( hdr->FontName );
hdr->FontName = NULL;
}
GUIMemFree( hdr );
}
}
static char *ResNameOrOrdinalToStr( ResNameOrOrdinal *name, int base )
{
char temp[15];
char *cp;
bool ok;
cp = NULL;
if( name != NULL ) {
if( name->ord.fFlag == 0xff) {
utoa( name->ord.wOrdinalID, temp, base );
ok = GUIStrDup( temp, &cp );
} else {
ok = GUIStrDup( name->name, &cp );
}
if( !ok || ( cp == NULL ) ) {
return( NULL );
}
}
return( cp );
}
static ControlClass *Data2ControlClass( uint_8 **data )
{
ControlClass *new;
uint_8 *data8;
int stringlen;
int len;
if( !data || !*data ) {
return( NULL );
}
stringlen = 0;
len = sizeof(ControlClass);
data8 = (uint_8 *)*data;
if( ( *data8 & 0x80 ) == 0 ) {
stringlen = strlen( (char *)(*data) ) + 1;
len = stringlen;
}
new = (ControlClass *)GUIMemAlloc( len );
if( new == NULL ) {
return( NULL );
}
if( stringlen == 0 ) {
new->Class = data8[0];
} else {
memcpy( new, *data, len );
}
(*data) += len;
return( new );
}
static ResNameOrOrdinal *Data2NameOrOrdinal( uint_8 **data )
{
ResNameOrOrdinal *new;
uint_8 *data8;
int stringlen;
int len;
if( !data || !*data ) {
return( NULL );
}
data8 = (uint_8 *)(*data);
if( *data8 == 0xff ) {
len = sizeof(ResNameOrOrdinal);
} else {
stringlen = strlen( (char *)data8 ) + 1;
len = max( sizeof(ResNameOrOrdinal), stringlen );
}
new = (ResNameOrOrdinal *)GUIMemAlloc( len );
if( new == NULL ) {
return( NULL );
}
if( *data8 == 0xff ) {
memcpy( new, data8, sizeof(ResNameOrOrdinal) );
*data += len;
} else {
memcpy( &new->name[0], data8, stringlen );
*data += stringlen;
}
return( new );
}
static bool Template2DlgCntl( uint_8 **data, DialogBoxControl *dbc )
{
bool ok;
ok = ( data && *data && dbc );
if( ok ) {
memcpy( dbc, *data, offsetof( DialogBoxControl, ClassID ) );
*data += offsetof( DialogBoxControl, ClassID );
dbc->ClassID = Data2ControlClass( data );
ok = ( dbc->ClassID != NULL );
}
if( ok ) {
dbc->Text = Data2NameOrOrdinal( data );
ok = ( dbc->Text != NULL );
}
if( ok ) {
dbc->ExtraBytes = (uint_8)((*data)[0]);
*data += sizeof(uint_8);
}
if( !ok ) {
GUIFreeDialogBoxControlPtrs( dbc );
}
return( ok );
}
static DialogBoxHeader *Template2DlgHdr( uint_8 **data )
{
DialogBoxHeader *hdr;
bool ok;
uint_8 *p;
hdr = NULL;
ok = ( data && *data );
if( ok ) {
hdr = (DialogBoxHeader *) GUIMemAlloc( sizeof(DialogBoxHeader) );
ok = ( hdr != NULL );
}
if( ok ) {
memcpy( hdr, *data, offsetof( DialogBoxHeader, MenuName ) );
*data += offsetof( DialogBoxHeader, MenuName );
hdr->MenuName = Data2NameOrOrdinal( data );
ok = ( hdr->MenuName != NULL );
}
if( ok ) {
hdr->ClassName = Data2NameOrOrdinal( data );
ok = ( hdr->ClassName != NULL );
}
if( ok ) {
ok = GUIStrDup( (char *)(*data), (char **)&p );
/* Have to do this with a temp because &hdr->Caption is unaligned */
hdr->Caption = (char *)p;
ok = ok && ( p != NULL );
if( ok ) {
*data += ( strlen( (char *)p ) + 1 );
}
}
if( ok ) {
hdr->PointSize = 0;
hdr->FontName = NULL;
if( hdr->Style & DS_SETFONT ) {
// data may not be aligned -- need memcpy for UNIX platforms
memcpy( &hdr->PointSize, *data, sizeof( hdr->PointSize ) );
*data += sizeof(uint_16);
ok = GUIStrDup( (char *)*data, (char **)&p );
/* Have to do this with a temp because &hdr->FontName is unaligned */
hdr->FontName = (char *)p;
ok = ok && ( hdr->FontName != NULL );
if( ok ) {
*data += ( strlen( hdr->FontName ) + 1 );
}
}
}
if( !ok ) {
if( hdr ) {
GUIFreeDialogBoxHeader( hdr );
hdr = NULL;
}
}
return( hdr );
}
static bool Template2Dlg( DialogBoxHeader **hdr, DialogBoxControl **cntls,
uint_8 *data, int size )
{
bool ok;
uint_8 *d;
int index;
ok = ( hdr && cntls && data && size );
if( ok ) {
d = data;
*hdr = NULL;
*cntls = NULL;
*hdr = Template2DlgHdr( &data );
ok = ( *hdr != NULL );
}
if( ok ) {
*cntls = (DialogBoxControl *)
GUIMemAlloc( (*hdr)->NumOfItems * sizeof( DialogBoxControl ) );
ok = ( *cntls != NULL );
}
if( ok ) {
for( index = 0; ok && index < (*hdr)->NumOfItems; index++ ) {
ok = Template2DlgCntl( &data, &((*cntls)[index]) );
}
}
if( ok ) {
ok = ( size >= ( data - d ) );
}
if( !ok ) {
if( *hdr ) {
GUIFreeDialogBoxHeader( *hdr );
*hdr = NULL;
}
if( *cntls ) {
for( index = 0; ok && index < (*hdr)->NumOfItems; index++ ) {
GUIFreeDialogBoxControlPtrs( cntls[index] );
}
GUIMemFree( *cntls );
*cntls = NULL;
}
}
return( ok );
}
static gui_control_styles GetControlStyles( DialogBoxControl *ctl,
gui_control_class control_class )
{
gui_control_styles styles;
styles = GUI_NOSTYLE;
if( ctl->Style & WS_TABSTOP ) {
styles |= GUI_TAB_GROUP;
}
switch( control_class ) {
case GUI_CHECK_BOX:
styles |= GUI_GROUP;
if( ( ctl->Style & 0xf ) == BS_3STATE ) {
styles |= GUI_CONTROL_3STATE;
}
if( ( ctl->Style & 0xf ) == BS_AUTO3STATE ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?