📄 toupperda.c
字号:
/*************************************************************************** ToUpperDA : ToUpper/ToLower function DA (Desk Accessory) Copyright (C) 1999-2002 Koichi TERADA, All Rights Reserved. > email: kterada@mcn.ne.jp > web: http://www04.u-page.so-net.ne.jp/zd5/kterada 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 of 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 <PalmCompatibility.h>/*#include <Pilot.h>#include <Common.h>#include <System/SysAll.h>#include <UI/UIAll.h>#include <Hardware/Hardware.h>*/#include "ToUpperDA_res.h"#include "ToUpperDA.h"void start(){ FormPtr form; FormPtr orgForm; VoidHand handle; Param *param; DWord featureValue; orgForm = FrmGetActiveForm(); if( FtrGet( ToUpperAppID, 0, &featureValue ) == 0 ) { FrmAlert( QuitAlert ); return; } FtrSet( ToUpperAppID, 0, 0 ); handle = MemHandleNew( sizeof( Param )); param = MemHandleLock( handle ); LoadFromPrefs( param ); param->moving = false; param->rootWindow = WinGetDisplayWindow(); if( getSelectedText( param->buf1, param ) != 0 ) { form = FrmInitForm( MainForm ); form->window.windowBounds.topLeft.x = param->lastX; form->window.windowBounds.topLeft.y = param->lastY; FrmSetActiveForm( form ); setAndDrawFields( param ); EventMainLoop( param ); FrmEraseForm( form ); FrmDeleteForm( form ); if( *(param->buf2) != '\0' ) { FrmSetActiveForm( orgForm ); // InsPtEnable( false ); putSelectedText( param->buf2, param ); // InsPtEnable( true ); } } SaveToPrefs( param ); MemHandleUnlock( handle ); MemHandleFree( handle ); FtrUnregister( ToUpperAppID, 0 );}static int EventMainLoop( Param *param ){ EventType event; Word error; Boolean done = false; do { EvtGetEvent (&event, -1); if (! SysHandleEvent (&event)) if (! MenuHandleEvent (NULL, &event, &error)) { if ( param->moving || !FrmHandleEvent(FrmGetActiveForm(), &event)) done = HandleMainEvent(&event, param); } } while ((event.eType != appStopEvent) && !done); return done;}static Boolean HandleMainEvent(EventPtr event, Param *param){ Boolean handled = false; Boolean done = false; FormPtr form; Word ch; SWord moveX, moveY; //char str[10]; *(param->buf2) = '\0'; switch (event->eType) { case appStopEvent: EvtAddEventToQueue(event); done= true; handled = true; break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case mainButtonCancelButton: done= true; handled = true; break; case mainButtonUpperButton: strToUpper( (uchar *)param->buf2, (uchar *)param->buf1, param->mode ); done= true; handled = true; break; case mainButtonLowerButton: strToLower( (uchar *)param->buf2, (uchar *)param->buf1, param->mode ); done= true; handled = true; break; case mainButtonCapsButton: strToCaps( (uchar *)param->buf2, (uchar *)param->buf1, param->mode ); done= true; handled = true; break; case mainButtonJPPushButton: param->mode = event->data.ctlSelect.on ? MODE_JP : 0; setAndDrawFields( param ); handled = true; break; case mainButtonUSPushButton: param->mode = event->data.ctlSelect.on ? MODE_US : 0; setAndDrawFields( param ); handled = true; break; case mainButtonEUPushButton: param->mode = event->data.ctlSelect.on ? MODE_EU : 0; setAndDrawFields( param ); handled = true; break; default: break; } break; case keyDownEvent: ch = event->data.keyDown.chr; if (chrIsHardKey(ch)) { /* maybe 'HotSync!' button pressed ? */ EvtAddEventToQueue(event); done = true; handled = true; } switch( event->data.keyDown.chr ) { case 'u': case 'U': strToUpper( (uchar *)param->buf2, (uchar *)param->buf1, param->mode ); done= true; handled = true; break; case 'l': case 'L': strToLower( (uchar *)param->buf2, (uchar *)param->buf1, param->mode ); done= true; handled = true; break; case 'c': case 'C': strToCaps( (uchar *)param->buf2, (uchar *)param->buf1, param->mode ); done= true; handled = true; break; default: break; } break; /* Following implements 'Draggable' feature */ case penDownEvent: form = FrmGetActiveForm(); if (IsInside(&form->window.windowBounds, event->screenX, event->screenY)) { /* Start Drag */ param->fromX = event->screenX + form->window.windowBounds.topLeft.x; param->fromY = event->screenY + form->window.windowBounds.topLeft.y; param->moving = true; FrmEraseForm(form); /* this enables DA to drag, both on OS 3.5+ and the OS before */ WinSetDrawWindow(param->rootWindow); /* Draw only frame as dragging */ ExorFrame(param->lastX, param->lastY); //WinDrawChars( StrIToA(str, param->fromX), 3, 0, 22 ); //WinDrawChars( StrIToA(str, param->fromY), 3, 0, 32 ); handled = true; } else if (IsOutside(&form->window.windowBounds, event->screenX, event->screenY)) { /* Pen tapped on Outside of form -- quit */ done = true; handled = true; } break; case penMoveEvent: if (param->moving) { form = FrmGetActiveForm(); moveX = event->screenX - param->fromX; moveY = event->screenY - param->fromY; /* Erase previous frame */ ExorFrame(param->lastX, param->lastY); /* Compute new form position */ if (moveX < FrameWidth - param->lastX) { moveX = FrameWidth - param->lastX; } else if (moveX + mainFormWidth + FrameWidth > hwrDisplayWidth - param->lastX) { moveX = hwrDisplayWidth - param->lastX - mainFormWidth - FrameWidth; } if (moveY < FrameWidth - param->lastY) { moveY = FrameWidth - param->lastY; } else if (moveY + mainFormHeight + FrameWidth > hwrDisplayHeight - param->lastY) { moveY = hwrDisplayHeight - param->lastY - mainFormHeight - FrameWidth; } //WinDrawChars( StrIToA(str, param->fromX), 3, 0, 22 ); //WinDrawChars( StrIToA(str, param->fromY), 3, 0, 32 ); /* Draw new frame */ param->lastX += moveX; param->lastY += moveY; param->fromX = event->screenX; param->fromY = event->screenY; ExorFrame(param->lastX, param->lastY); handled = true; } break; case penUpEvent: form = FrmGetActiveForm(); if (param->moving) { /* Erase last frame */ ExorFrame(param->lastX, param->lastY); /* Save last position into preference */// param->lastX = form->window.windowBounds.topLeft.x;// param->lastY = form->window.windowBounds.topLeft.y; param->moving = false; /* Redraw the form at the new position */ form->window.windowBounds.topLeft.x = param->lastX; form->window.windowBounds.topLeft.y = param->lastY; FrmDrawForm(form); setAndDrawFields( param ); handled = true; } break; default: break; }/* if (!handled) { FrmHandleEvent(FrmGetActiveForm(), event); }*/ return done;}static Boolean IsInside(RectanglePtr r, SWord x, SWord y){ return (0 <= x && x <= r->extent.x && 0 <= y && y <= r->extent.y);}static Boolean IsOutside(RectanglePtr r, SWord x, SWord y){ return (!IsInside(r, x, y));}static void ExorFrame(Word topLeftX, Word topLeftY){ RectangleType r; r.topLeft.x = topLeftX + 2; r.topLeft.y = topLeftY + 2; r.extent.x = mainFormWidth - 4; r.extent.y = mainFormHeight - 4; WinInvertRectangleFrame(boldRoundFrame, &r);}static void putSelectedText(CharPtr buf, Param *param){ FieldAttrType attr; FldGetAttributes( param->fieldptr, &attr ); if( param->fieldptr != NULL && attr.editable ) {// FldInsert( param->fieldptr, buf, StrLen( buf ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -