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

📄 engine.c

📁 是一个手机功能的模拟程序
💻 C
字号:
/*
 * Copyright (C) AU-System AB, 2000.
 * All rights reserved.
 *
 * This software is covered by the license agreement between
 * the end user and AU-System AB, and may be used and copied
 * only in accordance with the terms of the said agreement.
 *
 * AU-System AB does not assume any responsibility or 
 * liability for any errors or inaccuracies in this 
 * software, or any consequential, incidental or indirect 
 * damage arising out of the use of the Generic Layout Engine 
 * software.
 */

/* intern includes from gle */
#include "engine.h"
#include "gleelem.h"
#include "glebreak.h"
#include "glefset.h"
#include "gledef.h"
#include "ansilibs.h"
#ifdef SHOW_KEYS_IN_CONTENT
	#include "glekey.h"
#endif
#include "gleimage.h"
#include "gleinput.h"
#include "gleselct.h"
#include "gleoptn.h"
#include "gleparag.h"
#include "gletable.h"
#include "gletext.h"

#include "aapigle.h"
#include "capigle.h"
#include "gleview.h"
/*****************************/

/*** GWC includes   *********/
#include "aapimmi.h"
#include "capimmi.h"

VOID* WIPAlloc(UINT32 size);
VOID WIPFree( VOID* memory );
  
/*****************************/

GleViewType* gGleViewList=0;
BOOL gAllViewsDisplayImages=FALSE;
BOOL gAllViewsUpdateImages=FALSE;

#ifdef BITMAP_POSITION_CLICK
	UINT16 gGleImageClickXInputID = 0;
	UINT16 gGleImageClickYInputID = 0;
	UINT16 gGleImageClickXCoord = 0;
	UINT16 gGleImageClickYCoord = 0;
#endif

#ifdef DISPLAY_GLEELEMENTLIST_SIZE_IN_CONTENT
	extern WCHAR* char_2_wChar_strcpy(WCHAR* dst, const CHAR* src);
#endif

VOID GLEc_setIntConfig (UINT8 viewId, ConfigInt kind, UINT32 value){
	GleViewType* viewP;
#if (WIPVRSN_1 >= 4)
	//#if (GWCVERSION == 0400)
	if(viewId == ALL_USER_AGENT )
#elif (WIPVRSN_1 > 1)
	if(viewId == GENERAL_VIEW)
#else
	if(1) // Set config for all views if WIPVRSN_1 == 1
#endif
		{
			#if (WIPVRSN_1 > 1)
				CALL_GWC_API(CLNTc_setIntConfig(viewId,kind,value));
			#else
				CALL_GWC_API(CLNTc_setIntConfig(kind,value));
			#endif
			if(kind==configDISPLAY_IMAGES)
				gAllViewsDisplayImages=value;
			else if(kind==configUPDATE_IMAGES)
				gAllViewsUpdateImages=value;
			if(kind==configDISPLAY_IMAGES || kind==configUPDATE_IMAGES){
				// Set value for all current views:
				viewP = gGleViewList;
				while(viewP){
					if(!viewP->mMIa_wait) {
						if(kind==configDISPLAY_IMAGES)
							viewP->displayImages = value;
						else if(kind==configUPDATE_IMAGES)
							viewP->updateImages = value;
						}
					viewP=viewP->next;
					}
				}
		}
	else if(kind==configDISPLAY_IMAGES || kind==configUPDATE_IMAGES){
		viewP = GleViewSearchByViewId(viewId);
		if(!viewP->mMIa_wait) {
			if(kind==configDISPLAY_IMAGES)
				viewP->displayImages = value;
			else if(kind==configUPDATE_IMAGES)
				viewP->updateImages = value;
			#if (WIPVRSN_1 > 1)
				CALL_GWC_API(CLNTc_setIntConfig(viewId,kind,value));
			#else
				CALL_GWC_API(CLNTc_setIntConfig(kind,value));
			#endif
			}
		}
	else {
		viewP = GleViewSearchByViewId(viewId);
		if(viewP)
			if(!viewP->mMIa_wait) 
				#if (WIPVRSN_1 > 1)
					CALL_GWC_API(CLNTc_setIntConfig(viewId,kind,value));
				#else
					CALL_GWC_API(CLNTc_setIntConfig(kind,value));
				#endif
		}
	}
	
BOOL GLEc_formatStringValid(const WCHAR* format, INT16* length, FormatInfoType* info, BOOL* containsConstantChars){
	const WCHAR* f = format;
	WCHAR firstFormat = 0;
	BOOL allSameFormat = TRUE;
	*length=-1;
	*containsConstantChars=FALSE;

	if(!f)
		return FALSE;
	if(!*f)
		return FALSE;
	while(*f){
		if(*f=='\\'){
			*containsConstantChars=TRUE;
			if(!*++f)
				return FALSE;
			else 
				f++;
			}
		else if (*f=='*'){				/* "*f" */

			f++;
			if(!*f)						/* Missing f */
				return FALSE;
			else if (!IS_FORMAT(*f))	/* Invalid f */
				return FALSE;
			else if(*++f != 0)			/* Something after f */
				return FALSE;
			else { 						/* Format string is correct*/
				*length = 0; 			/*Will become -1 after the loop, return FALSE must have *length==-1*/
				break;
				}
			/*else 						
				return(*++f == 0);*/
			}
		else if(IS_DIGIT_1_TO_9(*f)) {	/* "[1-9]f" */
			if(!*++f) 					/* Missing f */
				return FALSE;			
			else {
				if(!IS_FORMAT(*f)) 		/* Invalid f */
					return FALSE;		
				else if(*++f != 0)		/* Something after f */
					return FALSE;
				else 					/* Format string is correct*/
					break;
				/*else 						
					return(*++f == 0);*/
				}
			}
		else
			if(!IS_FORMAT(*f))
				return FALSE;
		while (IS_FORMAT(*f)){f++;}
		}
	/* Format string is valid, now get length... */
	if(!*length)
		*length=-1;
	else 
		*length=0;
		
	f = format;
	if(*length != -1){
		while(*f && !IS_DIGIT_1_TO_9(*f)){
			if(*f=='\\')
				f++;
			(*length)++;
			f++;
			}
		if(IS_DIGIT_1_TO_9(*f))
			(*length) += *f - '0';
		}
	f = format;
	while(*f && !firstFormat){
		if(IS_FORMAT(*f))
			firstFormat = *f;
		f++;
		}
	/* ...and now info */
	if(!firstFormat)
		*info = PureConstant;
	else{
		while(*f && allSameFormat){
			if(IS_FORMAT(*f) && *f!=firstFormat)
				allSameFormat = FALSE;
			f++;
			}
		if(allSameFormat)
			switch(firstFormat){
				case 'A':
					*info = Only_A;
					break;
				case 'a':
					*info = Only_a;
					break;
				case 'N':
					*info = Only_N;
					break;
				case 'X':
					*info = Only_X;
					break;
				case 'x':
					*info = Only_x;
					break;
				case 'M':
					*info = Only_M;
					break;
				case 'm':
					*info = Only_m;
					break;
				}
		else
			*info = Mixed;	
		}
	return TRUE;
	}
	
BOOL GLEc_inputStringValid(const WCHAR* str, const WCHAR* format, FormatErrorType* error){
	BOOL anyNumberOf = FALSE;
	const WCHAR* f = format;
	UINT16 n=0;

	if(!str) {
		*error = NullPointer;
		return FALSE;
		}
		
	while ( (!anyNumberOf && *f) || (anyNumberOf && *str) ){
		
		if (*f==(WCHAR)'*'){ /* *f=='*' any number of characters with the following format is accepted*/
			anyNumberOf = TRUE;
			if(!*str)
				return TRUE;
			f++;
			}
		else if (!anyNumberOf && !*str){ /* str ended before format did*/
			*error = ToShort;
			return FALSE; 
			}
		if (IS_FORMAT_N(*f)){ /* *f==n where n is a character between 1 and 9*/
				n=*f-'0';
				f++;
				}
		else if (*f==(WCHAR)'\\'){ /* *f=='\', means constant character follows*/
			f++;
			if(*f++ != *str++) {
				*error = ConstantReplaced;
				return FALSE;
				}
			}
		else {
			switch (*f) {
				case (WCHAR)'A':
					if(IS_FORMAT_UPPERCASE_A(*str))
						str++; 
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				case (WCHAR)'a':
					if(IS_FORMAT_LOWERCASE_A(*str))
						str++; 
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				case (WCHAR)'N':
					if(IS_FORMAT_N(*str))
						str++;
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				case (WCHAR)'X':
					if(IS_FORMAT_UPPERCASE_X(*str))
						str++;
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				case (WCHAR)'x':
					if(IS_FORMAT_LOWERCASE_X(*str))
						str++;
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				case (WCHAR)'M':
					if(IS_FORMAT_UPPERCASE_M(*str))
						str++;
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				case (WCHAR)'m':
					if(IS_FORMAT_LOWERCASE_M(*str))
						str++;
					else{
						*error = WrongFormat;
						return FALSE;
						}
					break;
				default:
					/*default means an error in this function*/
					break;
				}
			
			if (n){
				n--;
				if(!n)
					return(*str==0);
				}
			else if (!anyNumberOf)
				f++;
			}
		} 
		
	if(*str){
		*error = ToLong;
		return FALSE;
		}
	else
		return TRUE;
	}

INT16 SizeOfGleList(VOID) {
/*	GleElement* p = gFirstGleElement;
	INT16 sum = 0;
	while(p) {		
		sum += p->chunkSize;
		p = p->next;		
		}
*/	return 0;
	}


VOID GleRctSetRectangle (const GleRectanglePtr r, const INT16 left, const INT16 top, const INT16 width, const INT16 height)
{
	r->topLeft.x = left;
	r->topLeft.y = top;
	r->extent.x = width;
	r->extent.y = height;
}

BOOL GleRctPtInRectangle (const INT16 x, const INT16 y, const GleRectanglePtr r)
{
	return (x >= r->topLeft.x &&
			  y >= r->topLeft.y &&
			  x < r->topLeft.x + r->extent.x &&
			  y < r->topLeft.y + r->extent.y);
}

VOID GleRctGetIntersection (const GleRectanglePtr r1, const GleRectanglePtr r2, GleRectanglePtr r3)
{
	INT16 left, right, top, bottom;
	
	left = max (r1->topLeft.x, r2->topLeft.x);
	top = max (r1->topLeft.y, r2->topLeft.y);
	right = min (r1->topLeft.x + r1->extent.x, r2->topLeft.x + r2->extent.x);
	bottom = min (r1->topLeft.y + r1->extent.y, r2->topLeft.y + r2->extent.y);
	
	if ((left < right) && top < bottom)
		GleRctSetRectangle (r3, left, top, right - left, bottom - top);
	else
		GleRctSetRectangle (r3, 0, 0, 0, 0);
}

VOID GleAddToGleList(GleViewType* viewP, GleElement* p)
	{
	if (!viewP->firstGleElement) {
		viewP->firstGleElement=p;
		p->prev=0;
		}		
	else {
		p->prev = viewP->lastGleElement;
		viewP->lastGleElement->next=p;
		}
	viewP->lastGleElement=p;
	p->next=0;
	}

VOID GleGetLinkInfo(GleViewType* viewP, GleElement* p){
	GleText* myText;
	GleImage* myImage;
#ifdef SHOW_KEYS_IN_CONTENT
	GleKey* myKey;
#endif
	GleOption* myOption;
	switch (p->type){
		case Text:
			myText = (GleText*)p;
			if(myText->isLink) {
				if(!myText->image)
					CALL_GWC_API(MMIc_linkInfo(viewP->viewId, WIDGET_TEXTLINK, myText->textId));
				else
					CALL_GWC_API(MMIc_linkInfo(viewP->viewId, WIDGET_IMAGELINK, myText->textId));
				}
			break;
		case Image:
			myImage = (GleImage*)p;
			if(myImage->isLink) 
				CALL_GWC_API(MMIc_linkInfo(viewP->viewId, WIDGET_IMAGELINK, myImage->imageId));
			break;
#ifdef SHOW_KEYS_IN_CONTENT
		case Key:
			myKey = (GleKey*)p;
			CALL_GWC_API(MMIc_linkInfo(viewP->viewId, WIDGET_DOLINK, myKey->keyId));
			break;
#endif
		case Option:
			myOption = (GleOption*)p;
			CALL_GWC_API(MMIc_linkInfo(viewP->viewId, WIDGET_OPTIONLINK, myOption->optionId));
			break;
		}
	}

VOID GleDeleteCard(GleViewType* viewP) {
	GleElement* tempP;
	while (viewP->firstGleElement) {
		tempP = viewP->firstGleElement->next;
		viewP->firstGleElement->Destruct(viewP->firstGleElement);
		viewP->firstGleElement=tempP;
		}
	viewP->markedGleElement = 0;
	}	

BOOL GleRenderCard(GleViewType* viewP, INT16 *xSize, INT16 *ySize) {
	INT16 xSum=0;
	INT16 ySum=0;
	INT16 ascentMax=0;
	INT16 descenderMax=0;
    INT16 columnLeftX=0;
    INT16 columnWidth = viewP->width;

	GleElementType gleType=Break;
	INT16 currentFontLineHeight=14;

	INT16 nbrObjects=0;
	INT8 align=ALIGN_LEFT;
	INT8 alignNext=ALIGN_LEFT;
	BOOL wrap=TRUE;
	INT16 xOffset=0;
	GleText* multipleRowTextPtr=0;
	GleElement* p = viewP->firstGleElement;
	GleElement* p2;
	GleElement* rowStart=0;
	GleElement* fieldSetPtr=0;
	GleElement* GleFieldSetPtr = 0;
	UINT16 k;
	
	*xSize = 0;
	*ySize = 0;
	while (p)
		{
		rowStart=p;
		ascentMax=0;
		descenderMax = 0;
		nbrObjects=0;

		if (multipleRowTextPtr)
			{ /* Uppdatera ascentMax och rowHeightmax f鰎 eventuella andra object p

⌨️ 快捷键说明

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