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

📄 sugarmemotools.c

📁 Palm上著名的背单词软件的源码
💻 C
字号:
#include <PalmOS.h>
#include "SugarMemo.h"
#include "SugarMemoTools.h"

#define DynamicUIStart 6000
#define DynamicFormID 5000

#define DynamicMessageFieldID	5000
#define DynamicInputFieldID		5001
#define DynamicOKButtonID 		5002
#define DynamicCancelButtonID 	5003

#define HorizontalSpace	10

UInt16 gIndex;

Char msg[100];

WinHandle winHandle;
UInt32 ProgressFull = 80;

RectangleType ProgressFrame = {{30, 50}, {100, 50}};
RectangleType ProgressTitleBar = {{32, 52}, {96, 20}};
RectangleType ProgressBar = {{40, 80}, {80, 12}};

static void ToolsDrawField(char* p, UInt16* top, Boolean draw);

void * GetObjectPtr(UInt16 objectID)
{
    FormType * frmP;
	UInt16 index;

    frmP = FrmGetActiveForm();
    
    index = FrmGetObjectIndex(frmP, objectID);
    if (index == frmInvalidObjectId){
    
    	StrPrintF(msg, "%s %d", "Invalid object ID found:", objectID);
    	ErrDisplay(msg);
    	return NULL;
    }
    
    return FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID));
}

UInt16 GetObjectIndex(UInt16 objectID){
	FormType * frmP;
	
	frmP = FrmGetActiveForm();
	return FrmGetObjectIndex(frmP, objectID);
}

void ShowObject(UInt16 objectID){

	FormType * frmP;
	
	frmP = FrmGetActiveForm();
	FrmShowObject(frmP, FrmGetObjectIndex(frmP, objectID));

}

void HideObject(UInt16 objectID){

	FormType * frmP;
	
	frmP = FrmGetActiveForm();
	FrmHideObject(frmP, FrmGetObjectIndex(frmP, objectID));

}

void ToolsDirtyRecord (UInt16 index)
{
	UInt16      attr;

	DmRecordInfo (CurrentDB, index, &attr, NULL, NULL);
	attr |= dmRecAttrDirty;
	DmSetRecordInfo (CurrentDB, index, &attr, NULL);
}

Boolean ZeroDate(DateType date){
	if (date.year == 0 && date.month == 0 && date.day == 0) return true;
	return false;
}

void ProgressPie(UInt32 progress, Char* message){
	
	Err error;
	RectangleType rct = ProgressBar;
	RectangleType rctFrame;
	FontID currFont;
	
	Int16 strWidth;
	Int16 strLength;
	UInt16 xpos, ypos;
	Boolean fit;
	
	if (progress == 0){
		
		winHandle = WinSaveBits(&ProgressFrame, &error);		
		if (winHandle == 0) ErrAlert(error);
		
		WinPushDrawState();
		
		rctFrame.topLeft.x = ProgressFrame.topLeft.x + 2;
		rctFrame.topLeft.y = ProgressFrame.topLeft.y + 2;
		rctFrame.extent.x = ProgressFrame.extent.x - 4;
		rctFrame.extent.y = ProgressFrame.extent.y - 4;
		
		WinSetForeColor(UIColorGetTableEntryIndex(UIObjectSelectedFill));
		
		WinEraseRectangle(&ProgressFrame, 0);
		
		WinPaintRectangleFrame(dialogFrame, &rctFrame);
		
		currFont = FntSetFont(boldFont);
		
		strWidth = rctFrame.extent.x;
		strLength = StrLen(message);
		FntCharsInWidth(message, &strWidth, &strLength, &fit);
		
		xpos = (rctFrame.extent.x - strWidth) / 2 + rctFrame.topLeft.x;
		ypos = (ProgressBar.topLeft.y - rctFrame.topLeft.y - FntLineHeight()) / 2 + rctFrame.topLeft.y;
		
		WinDrawChars(message, strLength, xpos, ypos);
		
		WinPaintRectangleFrame(simpleFrame, &ProgressBar);
			
		return;
	}
	
	else if (progress == ProgressFull){

		rct.extent.x = progress;
		WinPaintRectangle(&rct, 0);
		
		SysTaskDelay(SysTicksPerSecond()/3);
		
		WinRestoreBits(winHandle, ProgressFrame.topLeft.x, ProgressFrame.topLeft.y);
		WinPopDrawState();

	}
	
	else {
		rct.extent.x = progress;
		WinPaintRectangle(&rct, 0);
	}

}

Boolean DoCustomDialog(char* title, char* message, Boolean showInputField, UInt16 maxChars,  
	char* input, Boolean showCancel){
	
	FormType* formP = NULL;
	FormType** formPP = &formP;
	FieldType* messageField;
	FieldType* inputField;
	ControlType* okButton;
	ControlType* cancelButton;
	FontID currFont;
	UInt16 top = 0;
	UInt16 messageTop, messageHeight, inputTop, inputHeight, buttonTop, buttonHeight;
	UInt16 width = 156 - 2 * HorizontalSpace;
	UInt16 length;
	
	char okString[10] = "OK";
	char cancelString[10] = "Cancel";
	char* p;
	
	Boolean result = false;
	
	//	title height + space
	top += 20;
	messageTop = top;
	
	//	calculate message field height
	currFont = FntSetFont(boldFont);
	messageHeight = FntLineHeight() * FldCalcFieldHeight(message, width);
	
	top += messageHeight;
	top += 5;
	
	//	calculate input field height
	if (showInputField) {
		
		inputTop = top;
		
		FntSetFont(stdFont);
		inputHeight = FntLineHeight();
		top += inputHeight;
		top += 5; 	//space
	
	}
	
	top += 3;
	
	//	calculate button field height
	buttonTop = top;
	buttonHeight = 14;
	top += buttonHeight;
	top += 6; 	//button height + space 
	
	//	create form and set title
	formP = FrmNewForm(DynamicFormID, title, 2, 160 - 2 - top, 156, top, true, NULL, NULL, NULL);
		
	//	create message field
	FntSetFont(boldFont);
	messageField = FldNewField((void **)formPP, DynamicMessageFieldID, HorizontalSpace, messageTop, 
		width, messageHeight, boldFont, StrLen(message) + 1, false, false, false, false, leftAlign, 
		false, false, false);
	
	//	set message text and recalculate height
	FldSetTextPtr(messageField, message);
	FldRecalculateField(messageField, true);
	
	//	create input field
	if (showInputField){
		inputField = FldNewField((void **)formPP, DynamicInputFieldID, HorizontalSpace, inputTop, 
			width, inputHeight, stdFont, maxChars, true, true, true, false, leftAlign, false, false, false);
	}
	
	//	create button
	okButton = CtlNewControl((void **)formPP, DynamicOKButtonID, buttonCtl, okString, 
		HorizontalSpace, buttonTop, 32, 12, stdFont, 0, false);

	if (showCancel){
	
		cancelButton = CtlNewControl((void **)formPP, DynamicCancelButtonID, buttonCtl, cancelString,
		HorizontalSpace + 32 + 8, buttonTop, 32, 12, stdFont, 0, false);  
	
	}
	
	FrmDrawForm(*formPP);
	messageField = FrmGetObjectPtr(*formPP, FrmGetObjectIndex(*formPP, DynamicMessageFieldID));
	FldDrawField(messageField);
	
	//	do dialog
	if (DynamicOKButtonID == FrmDoDialog(*formPP)){
		
		result = true;
		
		if (showInputField) {
			
			inputField = FrmGetObjectPtr(*formPP, FrmGetObjectIndex(*formPP, DynamicInputFieldID));
			length = FldGetTextLength(inputField);
					
			if (length > 0){
				p = FldGetTextPtr(inputField);
				StrPrintF(input, "%s", p);
				result = true;
			}
			else result = false;
		} 
	}
	
	//	delete dialog	
	FrmDeleteForm(*formPP);
	
	//	restore font
	FntSetFont(currFont);
	
	return result;
}

void GetObjectBounds(UInt16 objectID, RectangleType* bounds){
	FormType* frmP = FrmGetActiveForm();
	
	FrmGetObjectBounds(frmP, GetObjectIndex(objectID), bounds);
}

void SetObjectBounds(UInt16 objectID, RectangleType* bounds){
	FormType* frmP = FrmGetActiveForm();
	
	FrmSetObjectBounds(frmP, GetObjectIndex(objectID), bounds);
}

⌨️ 快捷键说明

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