📄 diasample.c
字号:
/***********************************************************************
*
Sample Code Disclaimer
Copyright ?2002 PalmSource, Inc. or its subsidiaries. All
rights reserved.
You may incorporate this sample code (the "Code") into your applications
for Palm OS(R) platform products and may use the Code to develop
such applications without restriction. The Code is provided to you on
an "AS IS" basis and the responsibility for its operation is 100% yours.
PALMSOURCE, INC. AND ITS SUBSIDIARIES (COLLECTIVELY, "PALMSOURCE") DISCLAIM
ALL WARRANTIES, TERMS AND CONDITIONS WITH RESPECT TO THE CODE, EXPRESS,
IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WARRANTIES, TERMS OR
CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
NONINFRINGEMENT AND SATISFACTORY QUALITY. You are not permitted to
redistribute the Code on a stand-alone basis and you may only
redistribute the Code in object code form as incorporated into your
applications. TO THE FULL EXTENT ALLOWED BY LAW, PALMSOURCE ALSO EXCLUDES ANY
LIABILITY, WHETHER BASED IN CONTRACT OR TORT (INCLUDING NEGLIGENCE), FOR
INCIDENTAL, CONSEQUENTIAL, INDIRECT, SPECIAL OR PUNITIVE DAMAGES OF ANY
KIND, OR FOR LOSS OF REVENUE OR PROFITS, LOSS OF BUSINESS, LOSS OF
INFORMATION OR DATA, OR OTHER FINANCIAL LOSS ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THE CODE. The Code is subject
to Restricted Rights for U.S. government users and export regulations.
SAMPLE NAME: DIASample
FILE: DIASample.c
DATE: 4/8/2004
DESCRIPTION: Source Code
Requires Palm OS 4 SDK or later
*
*
*****************************************************************************/
#include <PalmOS.h>
#include <PalmOSGlue.h>
#include <Window.h>
#include <Form.h>
#include <PenInputMgr.h>
#include "DIASample.h"
#include "DIASample_Rsc.h"
/*********************************************************************
* Entry Points
*********************************************************************/
/*********************************************************************
* Global variables
*********************************************************************/
/*
* g_prefs
* cache for application preferences during program execution
*/
DIASamplePreferenceType g_prefs;
/*********************************************************************
* Internal Constants
*********************************************************************/
/* Define the minimum OS version we support */
#define ourMinVersion sysMakeROMVersion(3,0,0,sysROMStageDevelopment,0)
#define kPalmOS20Version sysMakeROMVersion(2,0,0,sysROMStageDevelopment,0)
/*********************************************************************
* Internal Functions
*********************************************************************/
/*
* FUNCTION: GetObjectPtr
*
* DESCRIPTION:
*
* This routine returns a pointer to an object in the current form.
*
* PARAMETERS:
*
* formId
* id of the form to display
*
* RETURNED:
* address of object as a void pointer
*/
static void * GetObjectPtr(UInt16 objectID)
{
FormType * frmP;
frmP = FrmGetActiveForm();
return FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID));
}
/*
* FUNCTION: MainFormInit
*
* DESCRIPTION: This routine initializes the MainForm form.
*
* PARAMETERS:
*
* frm
* pointer to the MainForm form.
*/
static void MainFormInit(FormType *frmP)
{
FieldType *field;
TableType *table;
const char *wizardDescription;
UInt16 fieldIndex, tableIndex,i,j;
Char *data= "hello";
fieldIndex = FrmGetObjectIndex(frmP, MainDescriptionField);
field = (FieldType *)FrmGetObjectPtr(frmP, fieldIndex);
FrmSetFocus(frmP, fieldIndex);
wizardDescription =
"C application\n"
"Creator Code: STRT\n"
"\n"
"Other SDKs:\n"
;
/* dont stack FldInsert calls, since each one generates a
* fldChangedEvent, and multiple uses can overflow the event queue */
FldInsert(field, wizardDescription, StrLen(wizardDescription));
}
/*
* FUNCTION: MainFormDoCommand
*
* DESCRIPTION: This routine performs the menu command specified.
*
* PARAMETERS:
*
* command
* menu item id
*/
static Boolean MainFormDoCommand(UInt16 command)
{
Boolean handled = false;
switch (command)
{
case OptionsPreferences:
FrmGotoForm (PrefsForm);
break;
#if 0
{
FormType * frmP;
ControlType * cbox = NULL;
FieldType * field = NULL;
UInt16 controlID = 0;
MemHandle handle = 0;
/* Clear the menu status from the display */
MenuEraseStatus(0);
/* Initialize the preference form. */
frmP = FrmInitForm (PrefsForm);
/*
* Set the controls in the preference dialog to reflect our
* preference data structure
*/
cbox = (ControlType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PrefsSetting1Checkbox));
if (cbox)
CtlSetValue(cbox, g_prefs.pref1);
field = (FieldType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PrefsSetting2Field));
if (field && (g_prefs.pref2[0] != '\0'))
{
MemPtr text = NULL;
UInt32 len = StrLen(g_prefs.pref2);
handle = FldGetTextHandle(field);
if (!handle)
handle = MemHandleNew(len + 1);
else
MemHandleResize(handle, len + 1);
text = MemHandleLock(handle);
if (text)
StrCopy((char *)text, g_prefs.pref2);
MemHandleUnlock(handle);
FldSetTextHandle(field, handle);
handle = 0;
}
/*
* Display the preferences dialog. The call will block until
* the dialog is dismissed
*/
controlID = FrmDoDialog (frmP);
/* controlID contains the ID of the button used to dismiss the dialog */
if (controlID == PrefsOKButton)
{
/*
* The user hit the OK button. Get the value of the controls
* and store them in our pref struct
*/
if (cbox)
g_prefs.pref1 = CtlGetValue(cbox);
if (field)
{
handle = FldGetTextHandle(field);
if (handle)
{
MemPtr text = MemHandleLock(handle);
if (text)
{
/* Guard against the field text being longer than our pref's buffer */
UInt32 len = StrLen((const char *)text);
UInt32 count = (len > (sizeof(g_prefs.pref2) - 1)) ? (sizeof(g_prefs.pref2) - 1) : len;
MemMove(g_prefs.pref2, text, count);
g_prefs.pref2[count] = '\0';
}
MemHandleUnlock(handle);
}
}
}
/* Clean up */
FrmDeleteForm (frmP);
handled = true;
break;
}
#endif
}
return handled;
}
void PerfsFormResizeForm(FormType *frmP,RectangleType* fromBoundsP, RectangleType* toBoundsP)
{
Int16 heightDelta, widthDelta;
UInt16 numObjects, i;
Coord x, y;
RectangleType objBounds;
FieldType* fldP;
heightDelta = widthDelta = 0;
numObjects = 0;
x = y = 0;
// Determine the amount of the change
heightDelta=(toBoundsP->extent.y - toBoundsP->topLeft.y) -
(fromBoundsP->extent.y - fromBoundsP->topLeft.y);
widthDelta=(toBoundsP->extent.x - toBoundsP->topLeft.x) -
(fromBoundsP->extent.x - fromBoundsP->topLeft.x);
// Iterate through objects and re-position them.
// This form consists of a big text field and
// command buttons. We move the command buttons to the
// bottom and resize the text field to display more data.
numObjects = FrmGetNumberOfObjects(frmP);
for (i = 0; i < numObjects; i++) {
switch (FrmGetObjectType(frmP, i)) {
case frmListObj:
FrmGetObjectBounds(frmP, i, &objBounds);
objBounds.extent.x += widthDelta;
objBounds.extent.y += heightDelta;
FrmSetObjectBounds(frmP, i, &objBounds);
break;
default:
FrmGetObjectPosition(frmP, i, &x, &y);
FrmSetObjectPosition(frmP, i, x + widthDelta, y +
heightDelta);
break;
}
}
}
void MaintFormResizeForm(FormType *frmP,RectangleType* fromBoundsP, RectangleType* toBoundsP)
{
Int16 heightDelta, widthDelta;
UInt16 numObjects, i;
Coord x, y;
RectangleType objBounds;
FieldType* fldP;
heightDelta = widthDelta = 0;
numObjects = 0;
x = y = 0;
// Determine the amount of the change
heightDelta=(toBoundsP->extent.y - toBoundsP->topLeft.y) -
(fromBoundsP->extent.y - fromBoundsP->topLeft.y);
widthDelta=(toBoundsP->extent.x - toBoundsP->topLeft.x) -
(fromBoundsP->extent.x - fromBoundsP->topLeft.x);
// Iterate through objects and re-position them.
// This form consists of a big text field and
// command buttons. We move the command buttons to the
// bottom and resize the text field to display more data.
numObjects = FrmGetNumberOfObjects(frmP);
for (i = 0; i < numObjects; i++) {
switch (FrmGetObjectType(frmP, i)) {
case frmControlObj:
case frmGraffitiStateObj:
FrmGetObjectPosition(frmP, i, &x, &y);
FrmSetObjectPosition(frmP, i, x + widthDelta, y +
heightDelta);
break;
case frmFieldObj:
FrmGetObjectBounds(frmP, i, &objBounds);
objBounds.extent.x += widthDelta;
objBounds.extent.y += heightDelta;
FrmSetObjectBounds(frmP, i, &objBounds);
fldP = (FieldType*) FrmGetObjectPtr(frmP, i);
FldRecalculateField(fldP, false);
break;
case frmScrollBarObj:
case frmListObj:
case frmTableObj:
FrmGetObjectBounds(frmP, i, &objBounds);
objBounds.extent.x += widthDelta;
objBounds.extent.y += heightDelta;
FrmSetObjectBounds(frmP, i, &objBounds);
break;
}
}
}
/*
* FUNCTION: MainFormHandleEvent
*
* DESCRIPTION:
*
* This routine is the event handler for the "MainForm" of this
* application.
*
* PARAMETERS:
*
* eventP
* a pointer to an EventType structure
*
* RETURNED:
* true if the event was handled and should not be passed to
* FrmHandleEvent
*/
static Boolean MainFormHandleEvent(EventType * eventP)
{
Boolean handled = false;
FormType * frmP;
switch (eventP->eType)
{
case menuEvent:
return MainFormDoCommand(eventP->data.menu.itemID);
case frmOpenEvent:
frmP = FrmGetActiveForm();
FrmDrawForm(frmP);
MainFormInit(frmP);
handled = true;
break;
case frmUpdateEvent:
/*
* To do any custom drawing here, first call
* FrmDrawForm(), then do your drawing, and
* then set handled to true.
*/
break;
case ctlSelectEvent:
{
if (eventP->data.ctlSelect.controlID == MainClearTextButton)
{
/* The "Clear" button was hit. Clear the contents of the field. */
FieldType * field = (FieldType*)GetObjectPtr(MainDescriptionField);
if (field)
{
FldDelete(field, 0, 0xFFFF);
FldDrawField(field);
}
break;
}
else if (eventP->data.ctlSelect.controlID == MainHideControlBarButton)
{
UInt16 state;
UInt32 data;
state = PINGetInputAreaState();
if (state == 0) PINSetInputAreaState(1);
else if (state == 1)
{
StatGetAttribute(statAttrBarVisible,&data);
if (data == 0) StatShow();
else if (data == 1) StatHide();
}
break;
}
break;
}
case winDisplayChangedEvent:
{
RectangleType curBounds,displayBounds;
// get the current bounds for the form
frmP = FrmGetActiveForm();
WinGetBounds (FrmGetWindowHandle(frmP), &curBounds);
// get the new display window bounds
WinGetBounds(WinGetDisplayWindow(), &displayBounds);
// This should be added here.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -