00001 00007 #include <PalmOS.h> 00008 #include <StringMgr.h> 00009 #include <Form.h> 00010 #include <MemoryMgr.h> 00011 #include <Field.h> 00012 #include <repeathandler.h> 00013 #include <palmutils.h> 00014 #include <mem_compat.h> 00015 00016 #define BUTTONMAPLEN (sizeof (buttonmappings) / sizeof (buttonmappings[0])) 00017 00018 buttonmapping_t * 00019 getSpinnerFieldIndex(buttonmapping_t *mapping, UInt16 buttonControl, 00020 Boolean isButton) 00021 { 00022 ErrFatalDisplayIf(mapping == NULL, "Bad Function call"); 00023 00024 while (mapping->down != 0 && mapping->up != 0) { 00025 if (isButton) { 00026 if (buttonControl == mapping->down || 00027 buttonControl == mapping->up) 00028 return (mapping); 00029 } else { 00030 if (buttonControl == mapping->field) 00031 return (mapping); 00032 } 00033 mapping++; 00034 } 00035 return (NULL); 00036 } 00037 00038 buttonmapping_t * 00039 processRepeater(buttonmapping_t *map, UInt16 control, 00040 Boolean isButton, bmPostHandler post_handle) 00041 { 00042 buttonmapping_t *bm = getSpinnerFieldIndex(map, control, 00043 isButton); 00044 FieldPtr fp; 00045 MemHandle mh; 00046 MemPtr mp; 00047 Int32 fld; 00048 Boolean limited = false; 00049 00050 if (bm == NULL) return (NULL); 00051 00052 fp = (FieldPtr)GetObjectPtr(FrmGetActiveForm(), bm->field); 00053 mh = FldGetTextHandle(fp); 00054 00055 FldSetTextHandle(fp, NULL); 00056 mp = MemHandleLock(mh); 00057 00058 fld = StrAToI(mp); 00059 00060 if (isButton) { 00061 if (control == bm->down) 00062 fld--; 00063 else 00064 fld++; 00065 } 00066 if (fld < bm->min) { 00067 limited = true; 00068 fld = bm->min; 00069 } else if (fld > bm->max) { 00070 limited = true; 00071 fld = bm->max; 00072 } 00073 00074 if (isButton || (!isButton && limited)) 00075 StrPrintF(mp, "%ld", fld); 00076 00077 MemHandleUnlock(mh); 00078 FldSetTextHandle(fp, mh); 00079 FldDrawField(fp); 00080 00081 if (post_handle != NULL) 00082 post_handle(control, bm, fld); 00083 00084 return (bm); 00085 }