Hi', I'm some what new to PalmOS development, I have read about some APIs which I think I need to do what I want. However I seem to get a crash in my code when do.
I've added the main files, the prc-tool GUI design, and the main form event handler, with some custom drawings. All my 81 fields can max contain 1 charater and they can only be a number, it's, if couldn't guess it, for a sudoku interface, and I'd like to know how to handle the charater input as it happens. I've read that this isn't the preferable way to do things when working with fields but the other way doesn't seem to apply in my case. My guess is to use the "FldHandleEvent()" function, but how and where? My Thanks for any help in this matter. René Kjellerup -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
#include "graphic.h"
#include "test.h"
static void draw_board(FormPtr frmP) {
RGBColorType sysColor;
RGBColorType mycolor;
mycolor.r = 250;
mycolor.g = 0;
mycolor.b = 160;
WinSetForeColorRGB(&mycolor, &sysColor);
// horisontal lines.
WinPaintLine( 5, 30,116, 30);
WinPaintLine( 5, 31,116, 31);
WinPaintLine( 5, 43,116, 43);
WinPaintLine( 5, 55,116, 55);
WinPaintLine( 5, 67,116, 67);
WinPaintLine( 5, 68,116, 68);
WinPaintLine( 5, 80,116, 80);
WinPaintLine( 5, 92,116, 92);
WinPaintLine( 5,104,116,104);
WinPaintLine( 5,105,116,105);
WinPaintLine( 5,117,116,117);
WinPaintLine( 5,129,116,129);
WinPaintLine( 5,141,116,141);
WinPaintLine( 5,142,116,142);
// vertical lines.
WinPaintLine( 5, 30, 5,142);
WinPaintLine( 6, 30, 6,142);
WinPaintLine( 18, 30, 18,142);
WinPaintLine( 30, 30, 30,142);
WinPaintLine( 42, 30, 42,142);
WinPaintLine( 43, 30, 43,142);
WinPaintLine( 55, 30, 55,142);
WinPaintLine( 67, 30, 67,142);
WinPaintLine( 79, 30, 79,142);
WinPaintLine( 80, 30, 80,142);
WinPaintLine( 92, 30, 92,142);
WinPaintLine(104, 30,104,142);
WinPaintLine(116, 30,116,142);
WinPaintLine(117, 30,117,142);
// WinPaintLine( 5,100,105,100); */
WinSetForeColorRGB(&sysColor,&mycolor);
}
void sudo_ins(FormPtr frmP, FieldPtr fldP, int val) {
UInt16 idx = FrmGetObjectIndexFromPtr(frmP,(void*)fldP);
UInt16 ID = FrmGetObjectId(frmP,idx);
int x = (ID-1)%9;
int y = (ID-1)/9;
if(!SB->ins(x,y,val)) {
FldSetTextPtr(fldP,"");
}
}
Boolean mainFrmEvtHnd(EventPtr event) {
Boolean handled = false;
FormPtr frmP = FrmGetActiveForm();
ControlPtr lbl;
UInt16 idx;
FieldPtr fldP;
switch (event->eType) {
case frmOpenEvent:
FrmDrawForm ( frmP);
draw_board( frmP );
handled = true;
break;
case frmUpdateEvent: // To do any custom drawing here, first call FrmDrawForm(),
FrmDrawForm ( frmP ); // then do your drawing, and then set handled to true.
draw_board( frmP );
idx = FrmGetObjectIndex( frmP, Lab01 );
lbl = (ControlPtr)FrmGetObjectPtr(frmP, idx );
CtlSetLabel(lbl, "Form Update");
handled = true;
break;
case frmCloseEvent:
handled = true;
break;
/* case fldEnterEvent:
FrmSetFocus
sudo_ins(frmP,event->data.fldEnter.pField);
handled = true;
break; */
case keyDownEvent:
idx = FrmGetObjectIndex( frmP, Lab01 );
lbl = (ControlPtr)FrmGetObjectPtr(frmP, idx );
CtlSetLabel(lbl, "Key Down");
break;
CtlSetLabel(lbl, "Field changed");
case fldChangedEvent:
idx = FrmGetObjectIndex( frmP, Lab01 );
lbl = (ControlPtr)FrmGetObjectPtr(frmP, idx );
break;
case fldEnterEvent:
idx = FrmGetObjectIndex( frmP, Lab01 );
lbl = (ControlPtr)FrmGetObjectPtr(frmP, idx );
CtlSetLabel(lbl, "Field Enter");
/* fldP = event->data.fldChanged.pField;
FldHandleEvent(fldP,event);
switch(event->eType) {
case keyDownEvent:
WChar wch = event->data.keyDown.chr;
if(TxtCharIsDigit(wch)) {
Char str[2];
str[0] = wch;
str[1] = 0;
int val = StrAToI(str);
sudo_ins(frmP,fldP,val);
handled = true;
}
break;
} */
break;
default:
break;
}
return handled;
}
formz.rcp
Description: Binary data
