📄 common.c
字号:
// MobyPalm
// Copyright (C) 2005 Olivier Burgard
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <PalmOS.h>
#include "Common.h"
static char* code = "0123456789ABCDEF";
void UpdateStatus(char *message) {
RectangleType rect;
rect.topLeft.x = 70;
rect.topLeft.y = 2;
rect.extent.x = 160 - rect.topLeft.x;
rect.extent.y = 11;
WinEraseRectangle(&rect, 0);
if (message != NULL)
WinPaintChars(message, StrLen(message), rect.topLeft.x, rect.topLeft.y);
}
void VerticalDraw(int x, int y, char* message) {
int i;
WinSetDrawMode(winOverlay);
for (i=0; i<StrLen(message); i++) {
WinPaintChars(message+i*sizeof(char), 1, x, y+i*7);
}
WinSetDrawMode(winPaint);
}
void SetLabelText(UInt16 FrmID, UInt16 ObjID, char *text)
{
FormType *frmP = FrmGetFormPtr(FrmID);
FrmCopyLabel(frmP, ObjID, text);
}
void SetPopup(int listObjID, int popupObjID, char **list, int listSize, int selection)
{
ControlPtr ctlP;
FormType *pForm = FrmGetActiveForm();
ListType* lstP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, listObjID));
LstSetListChoices(lstP, list, listSize);
LstSetSelection(lstP, selection);
LstMakeItemVisible(lstP, selection);
ctlP = (ControlPtr)FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, popupObjID));
CtlSetLabel(ctlP, list[selection]);
}
void setFieldText(int FldID, char* txt){
MemHandle h, oldHandle;
char *p;
FieldType* fldP;
FormType* frmP;
frmP = FrmGetActiveForm();
h = MemHandleNew(50);
p = (char *) MemHandleLock(h);
StrCopy(p, txt);
MemHandleResize(h, StrLen(p)+1);
MemHandleUnlock(h);
fldP = (FieldType *) FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, FldID));
oldHandle = FldGetTextHandle(fldP);
FldSetTextHandle(fldP, h);
if (oldHandle)
MemHandleFree(oldHandle);
FldDrawField(fldP);
}
char* GetSerialErrorText(Err err, char* szError)
{
switch (err)
{
case serErrAlreadyOpen:
StrCopy(szError,"Already Open");
break;
case serErrBadPort:
StrCopy(szError,"This port doesn't exist");
break;
case serErrNotOpen:
StrCopy(szError,"The port is not open");
break;
case serErrTimeOut:
StrCopy(szError,"Timeout");
break;
case serErrNotSupported:
StrCopy(szError,"Not supported");
break;
case serErrBadParam:
StrCopy(szError,"Bad Param");
break;
case serErrLineErr:
StrCopy(szError,"Line Error");
break;
case serErrNoDevicesAvail :
StrCopy(szError,"No serial devices");
break;
default:
StrCopy(szError,"Unknown error");
break;
}
return szError;
}
void convertHexToChars(char hex[], int nbr, char dest[]) {
int i;
for (i=0; i<nbr; i++) {
dest[2*i] = code[(hex[i] >> 4) & 0x0f];
dest[2*i+1] = code[(hex[i]) & 0x0f];
}
dest[2*nbr]=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -