📄 sem2diag.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: OS/2 Dialog related semantic actions.
*
****************************************************************************/
/*
The data structures for OS/2 dialog templates are as follows:
struct DLGTEMPLATE {
USHORT cbTemplate; // Template size
USHORT type; // Dialog type - always zero?
USHORT codepage; // Dialog codepage
USHORT offadlgti; // Offset to first item
USHORT fsTemplateStatus; // Template status flags
USHORT iItemFocus; // Index to initial focus window
USHORT coffPresParams; // Offset to presentation parameters
DLGTIITEM adlgti[1]; // Array of item templates
}
struct DLGTITEM {
USHORT fsItemStatus; // Item status flags
USHORT cChildren; // Number of child windows
USHORT cchClassName; // Number of chars in class name
USHORT offClassName; // Offset to class name
USHORT cchText; // Number of chars in window text
USHORT offText; // Offset to window text
ULONG flStyle; // Window style
USHORT x; // X coordinate
USHORT y; // Y coordinate
USHORT cx; // Width
USHORT cy; // Height
USHORT id; // Window ID
USHORT offPresParams; // Offset to presentation parameters
USHORT offCtlData; // Offset to class specific data
}
*/
#include <stddef.h>
#include <string.h>
#include "wresall.h"
#include "rcmem.h"
#include "global.h"
#include "errors.h"
#include "ytab2.gh"
#include "semantic.h"
#include "semdiag.h"
#include "reserr.h"
static int ResOS2WriteDlgTemplate( char *tmpldata, int size, WResFileID handle )
/******************************************************************************/
{
int numwrote;
numwrote = WRESWRITE( handle, tmpldata, size );
if( numwrote != size ) {
WRES_ERROR( WRS_WRITE_FAILED );
return( TRUE );
} else {
return( FALSE );
}
}
static void InitOS2DialogBoxHeader( DialogHeaderOS2 *header, uint_32 codepage )
/*****************************************************************************/
{
header->Size = 0;
header->Type = 0;
header->Codepage = codepage;
header->OffsetFirstTmpl = 14;
header->TemplateStatus = 1;
header->ItemFocus = -1;
header->OffsetPresParams = 0;
}
static FullDiagCtrlListOS2 *SemOS2EmptyDiagCtrlList( void )
/*********************************************************/
{
FullDiagCtrlListOS2 *newlist;
newlist = RcMemMalloc( sizeof(FullDiagCtrlListOS2) );
newlist->head = NULL;
newlist->tail = NULL;
newlist->numctrls = 0;
return( newlist );
}
extern FullDiagCtrlListOS2 *SemOS2NewDiagCtrlList( FullDialogBoxControlOS2 *ctrl,
DataElemList *list, PresParamListOS2 *presparams )
/*******************************************************************************/
{
FullDiagCtrlListOS2 *newlist;
newlist = SemOS2EmptyDiagCtrlList();
return( SemOS2AddDiagCtrlList( newlist, ctrl, list, presparams ) );
}
extern FullDiagCtrlListOS2 *SemOS2AddDiagCtrlList( FullDiagCtrlListOS2 *list,
FullDialogBoxControlOS2 *ctrl, DataElemList *dataList,
PresParamListOS2 *presparams )
/***************************************************************************/
{
if( ctrl != NULL ) {
ctrl->dataListHead = dataList;
// ctrl->presParams = presparams;
ResAddLLItemAtEnd( (void **)&(list->head), (void **)&(list->tail), ctrl );
list->numctrls++;
}
return( list );
}
extern FullDialogBoxControlOS2 *SemOS2InitDiagCtrl( void )
/********************************************************/
{
FullDialogBoxControlOS2 *newctrl;
newctrl = RcMemMalloc( sizeof(FullDialogBoxControlOS2) );
newctrl->next = NULL;
newctrl->prev = NULL;
newctrl->children = NULL;
newctrl->framectl = 0;
newctrl->presParams = NULL;
return( newctrl );
}
/* These are the default styles used for OS/2 dialog box controls */
/* statments except the CONTROL statement (see rcos2.y for that). */
#define DEF_AUTOCHECKBOX (OS2_BS_AUTOCHECKBOX|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_AUTORADIOBUTTON (OS2_BS_AUTORADIOBUTTON|OS2_WS_VISIBLE)
#define DEF_CHECKBOX (OS2_BS_CHECKBOX|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_COMBOBOX (OS2_CBS_SIMPLE|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_CONTAINER (OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_CTEXT (OS2_SS_TEXT|OS2_DT_CENTER|OS2_WS_VISIBLE|OS2_WS_GROUP)
#define DEF_DEFPUSHBUTTON (OS2_BS_DEFAULT|OS2_BS_PUSHBUTTON|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_EDITTEXT (OS2_ES_AUTOSCROLL|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_GROUPBOX (OS2_SS_GROUPBOX|OS2_WS_VISIBLE|OS2_WS_GROUP)
#define DEF_ICON (OS2_SS_ICON|OS2_WS_VISIBLE)
#define DEF_LISTBOX (OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_LTEXT (OS2_SS_TEXT|OS2_DT_LEFT|OS2_WS_VISIBLE|OS2_WS_GROUP)
#define DEF_MLE (OS2_MLS_BORDER|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_NOTEBOOK (OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_PUSHBUTTON (OS2_BS_PUSHBUTTON|OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_RADIOBUTTON (OS2_BS_RADIOBUTTON|OS2_WS_VISIBLE)
#define DEF_RTEXT (OS2_SS_TEXT|OS2_DT_RIGHT|OS2_WS_VISIBLE|OS2_WS_GROUP)
#define DEF_SLIDER (OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_SPINBUTTON (OS2_WS_VISIBLE|OS2_WS_TABSTOP)
#define DEF_VALUESET (OS2_WS_VISIBLE|OS2_WS_TABSTOP)
extern FullDialogBoxControlOS2 *SemOS2NewDiagCtrl( uint_8 token,
FullDiagCtrlOptionsOS2 opts,
PresParamListOS2 *presparams )
/****************************************************************/
{
FullDialogBoxControlOS2 *newctrl;
uint_32 style_mask; /* for the style of the control */
uint_32 style_value;
uint_32 defstyle;
uint_32 style;
uint_16 ctlClass;
ControlClass *cont_class;
switch( token ) {
case Y_AUTOCHECKBOX:
ctlClass = OS2_WC_BUTTON;
defstyle = DEF_AUTOCHECKBOX;
break;
case Y_AUTORADIOBUTTON:
ctlClass = OS2_WC_BUTTON;
defstyle = DEF_AUTORADIOBUTTON;
break;
case Y_CHECKBOX:
ctlClass = OS2_WC_BUTTON;
defstyle = DEF_CHECKBOX;
break;
case Y_COMBOBOX:
ctlClass = OS2_WC_COMBOBOX;
defstyle = DEF_COMBOBOX;
break;
case Y_CONTAINER:
ctlClass = OS2_WC_CONTAINER;
defstyle = DEF_CONTAINER;
break;
case Y_CTEXT:
ctlClass = OS2_WC_STATIC;
defstyle = DEF_CTEXT;
break;
case Y_DEFPUSHBUTTON:
ctlClass = OS2_WC_BUTTON;
defstyle = DEF_DEFPUSHBUTTON;
break;
case Y_EDITTEXT:
ctlClass = OS2_WC_ENTRYFIELD;
defstyle = DEF_EDITTEXT;
break;
case Y_GROUPBOX:
ctlClass = OS2_WC_STATIC;
defstyle = DEF_GROUPBOX;
break;
case Y_ICON:
ctlClass = OS2_WC_STATIC;
defstyle = DEF_ICON;
break;
case Y_LISTBOX:
ctlClass = OS2_WC_LISTBOX;
defstyle = DEF_LISTBOX;
break;
case Y_LTEXT:
ctlClass = OS2_WC_STATIC;
defstyle = DEF_LTEXT;
break;
case Y_MLE:
ctlClass = OS2_WC_MLE;
defstyle = DEF_MLE;
break;
case Y_NOTEBOOK:
ctlClass = OS2_WC_NOTEBOOK;
defstyle = DEF_NOTEBOOK;
break;
case Y_PUSHBUTTON:
ctlClass = OS2_WC_BUTTON;
defstyle = DEF_PUSHBUTTON;
break;
case Y_RTEXT:
ctlClass = OS2_WC_STATIC;
defstyle = DEF_RTEXT;
break;
case Y_RADIOBUTTON:
ctlClass = OS2_WC_BUTTON;
defstyle = DEF_RADIOBUTTON;
break;
case Y_SLIDER:
ctlClass = OS2_WC_SLIDER;
defstyle = DEF_SLIDER;
break;
case Y_SPINBUTTON:
ctlClass = OS2_WC_SPINBUTTON;
defstyle = DEF_SPINBUTTON;
break;
case Y_VALUESET:
ctlClass = OS2_WC_VALUESET;
defstyle = DEF_VALUESET;
break;
}
newctrl = SemOS2InitDiagCtrl();
cont_class = ResNumToControlClass( ctlClass );
style_mask = opts.Style.Mask;
style_value = opts.Style.Value;
style = (style_mask & style_value) | (~style_mask & defstyle);
newctrl->ctrl.ID = opts.ID;
newctrl->ctrl.Size = opts.Size;
newctrl->ctrl.Text = opts.Text;
newctrl->ctrl.ClassID = cont_class;
newctrl->ctrl.Style = style;
/* ExtraBytes is 0 for all predefined controls */
newctrl->ctrl.ExtraBytes = 0;
newctrl->presParams = presparams;
return( newctrl );
} /* SemOS2NewDiagCtrl */
static void SemOS2FreePresParamList( PresParamListOS2 *list )
/***********************************************************/
{
PresParamsOS2 *presparam;
PresParamsOS2 *currparam;
if( list == NULL )
return;
presparam = list->head;
while( presparam != NULL ) {
RcMemFree( presparam->Name );
SemFreeDataElemList( presparam->dataList );
currparam = presparam;
presparam = presparam->next;
RcMemFree( currparam );
}
RcMemFree( list );
}
static void SemOS2FreeDiagCtrlList( FullDiagCtrlListOS2 *list )
/*************************************************************/
{
FullDialogBoxControlOS2 *ctrl;
FullDialogBoxControlOS2 *oldctrl;
ctrl = list->head;
while( ctrl != NULL ) {
/* free the contents of pointers within the structure */
if( ctrl->ctrl.ClassID != NULL ) {
RcMemFree( ctrl->ctrl.ClassID );
}
if( ctrl->ctrl.Text != NULL ) {
RcMemFree( ctrl->ctrl.Text );
}
oldctrl = ctrl;
if( ctrl->children != NULL )
SemOS2FreeDiagCtrlList( ctrl->children );
SemFreeDataElemList( ctrl->dataListHead );
SemOS2FreePresParamList( ctrl->presParams );
ctrl = ctrl->next;
RcMemFree( oldctrl );
}
RcMemFree( list );
} /* SemOS2FreeDiagCtrlList */
static uint_16 SemOS2CountBytes( DataElemList *list )
/***************************************************/
{
DataElemList *travptr;
uint_16 bytes = 0;
int i;
for( travptr = list; travptr != NULL; travptr = travptr->next ) {
for( i = 0; i < travptr->count; i++ ) {
if( travptr->data[i].IsString ) {
bytes += travptr->data[i].StrLen + 1;
} else {
bytes += 2;
}
}
}
return( bytes );
}
static uint_16 SemOS2CountPresParams( PresParamListOS2 *list )
/************************************************************/
{
PresParamsOS2 *presparam;
DataElemList *travptr;
uint_16 bytes = 0;
int i;
if( list == NULL )
return 0;
presparam = list->head;
for( presparam = list->head; presparam != NULL; presparam = presparam->next ) {
int parmsize = 0;
bytes += 4; // Presparam ID or name length
if( !(presparam->Name->ord.fFlag == 0xFF) ) // Presparam has name
bytes += strlen( presparam->Name->name ) + 1 + 8;
bytes += 4; // Size of presparam data that follow
for( travptr = presparam->dataList; travptr != NULL; travptr = travptr->next ) {
for( i = 0; i < travptr->count; i++ ) {
if( travptr->data[i].IsString ) {
parmsize += travptr->data[i].StrLen + 1;
} else {
parmsize += 4; // Data elements are ULONGs
}
}
}
bytes += parmsize;
presparam->size = parmsize;
}
list->size = bytes;
return( bytes + 4 ); // Add an ULONG for presparams size
}
static uint_16 SemOS2DumpPresParams( char *ptr, PresParamListOS2 *list )
/**********************************************************************/
{
PresParamsOS2 *presparam;
DataElemList *travptr;
uint_16 bytes = 0;
uint_32 *data;
int i;
int len;
if( list == NULL )
return 0;
// Total size of presparams
data = (uint_32 *)ptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -