Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

palm/palmutils.c

Go to the documentation of this file.
00001 
00005 #define ALLOW_ACCESS_TO_INTERNALS_OF_BITMAPS
00006 #include <PalmTypes.h>
00007 #include <FeatureMgr.h>
00008 #include <ErrorBase.h>
00009 #include <ErrorMgr.h>
00010 #include <SystemMgr.h>
00011 #include <SysUtils.h>
00012 #include <StringMgr.h>
00013 #include <Form.h>
00014 
00015 #include <resCompat.h>
00016 #include <simcity_resconsts.h>
00017 #include <simcity.h>
00018 #include <palmutils.h>
00019 #include <logging.h>
00020 #include <mem_compat.h>
00021 
00022 /* included the TRG magic numbers :( */
00023 #define TRGSysFtrID     'TRG '
00024 #define TRGVgaFtrNum    2
00025 
00026 /* included Palm Zire (old) magic numbers */
00027 #define PalmOEMCompanyID        'Palm'
00028 #define ZireOriginalDeviceID    'Cubs'
00029 
00030 void
00031 RearrangeObjectOnly(FormPtr form, UInt16 oID, Int16 offsetX, Int16 offsetY,
00032     Int16 resizeX, Int16 resizeY)
00033 {
00034         RectangleType objrect;
00035 
00036         WriteLog("Move/resize: %d -> delta:%d,%d grow:%d,%d\n", (int)oID,
00037             (int)offsetX, (int)offsetY, (int)resizeX, (int)resizeY);
00038         FrmGetObjectBounds(form, FrmGetObjectIndex(form, oID), &objrect);
00039 
00040         objrect.topLeft.x += offsetX;
00041         objrect.topLeft.y += offsetY;
00042         objrect.extent.x += resizeX;
00043         objrect.extent.y += resizeY;
00044 
00045         FrmSetObjectBounds(form, FrmGetObjectIndex(form, oID), &objrect);
00046 }
00047 
00048 void
00049 RearrangeBitmap(FormPtr form, UInt16 oID, Int16 offsetX, Int16 offsetY)
00050 {
00051         Coord x, y;
00052 
00053         FrmGetObjectPosition(form, FrmGetObjectIndex(form, oID), &x, &y);
00054         x += offsetX;
00055         y += offsetY;
00056         FrmSetObjectPosition(form, FrmGetObjectIndex(form, oID), x, y);
00057 }
00058 
00059 Boolean
00060 isHandEra(void)
00061 {
00062         UInt32 version;
00063         if (FtrGet(TRGSysFtrID, TRGVgaFtrNum, &version) == 0)
00064                 if (sysGetROMVerMajor(version) >= 1)
00065                         return (true);
00066         return (false);
00067 }
00068 
00069 Boolean
00070 isZireOld(void)
00071 {
00072         UInt32 vcl;
00073         static UInt16 rv = 3;
00074 
00075         if (rv != 3)
00076                 return ((Boolean)(rv == 1));
00077         if ((FtrGet(sysFtrCreator, sysFtrNumOEMCompanyID, &vcl) == 0) &&
00078             (vcl == PalmOEMCompanyID) &&
00079             (FtrGet(sysFtrCreator, sysFtrNumOEMDeviceID, &vcl) == 0) &&
00080             (vcl == ZireOriginalDeviceID)) {
00081                 rv = 1;
00082         } else {
00083                 rv = 0;
00084         }
00085         return ((Boolean)(rv == 1));
00086 }
00087 
00088 UInt32
00089 getDepth(void)
00090 {
00091         static UInt32 avd = 0;
00092         if (avd != 0) {
00093                 WriteLog("Depth: saved == %ld\n", (long)avd);
00094                 return (avd);
00095         }
00096         if (Is35ROM()) {
00097                 (void) _WinScreenMode(winScreenModeGet, NULL, NULL, &avd, NULL);
00098         } else {
00099                 avd = 1;
00100         }
00101         WriteLog("Depth: == %ld\n", (long)avd);
00102         return (avd);
00103 }
00104 
00110 static UInt32
00111 hibit(UInt32 x)
00112 {
00113         int r = 0;
00114         if (x & 0xffff0000)  { x >>= 16; r += 16; }
00115         if (x & 0x0000ff00)  { x >>=  8; r +=  8; }
00116         if (x & 0x000000f0)  { x >>=  4; r +=  4; }
00117         if (x & 0x0000000c)  { x >>=  2; r +=  2; }
00118         if (x & 0x00000002)  { r +=  1; }
00119         return (r);
00120 }
00121 
00122 Err
00123 changeDepthRes(UInt32 ndepth, Boolean tryHigh)
00124 {
00125         UInt32 depth = ndepth;
00126         Boolean enablecol = 1;
00127         UInt32 dep = 0;
00128         UInt32 cdep;
00129         UInt32 width;
00130         UInt32 height;
00131         Err result;
00132 
00133         if (tryHigh) {
00134                 (void) loadHiRes();
00135                 setScreenRes();
00136         } else {
00137                 SETWIDTH(BASEWIDTH);
00138                 SETWIDTH(BASEHEIGHT);
00139         }
00140         
00141         (void) _WinScreenMode(winScreenModeGetSupportsColor, NULL, NULL, NULL,
00142             &enablecol);
00143         (void) _WinScreenMode(winScreenModeGetSupportedDepths, NULL, NULL,
00144             &dep, NULL);
00145         /* in theory there's 16color _as well as_ 16grays */
00146         cdep = 1 + hibit(dep);
00147         if ((cdep >= ndepth) && (ndepth > 1)) {
00148                 do {
00149                         cdep = hibit(dep);
00150                         if ((cdep+1) & ndepth) {
00151                                 depth = cdep + 1;
00152                                 break;
00153                         }
00154                         dep = dep & ~(1 << cdep);
00155                 } while (dep);
00156 
00157                 /* Could not match... */
00158                 if (!dep) {
00159                         depth = 1;
00160                         enablecol = 0;
00161                 }
00162         } else {
00163                 enablecol = 0;
00164                 depth = 1;
00165         }
00166 
00167         width = sWidth;
00168         height = sHeight;
00169 
00170         if (isHandEra())
00171                 result = _WinScreenMode(winScreenModeSet, NULL, NULL,
00172                     &depth, &enablecol);
00173         else
00174                 result = _WinScreenMode(winScreenModeSet, &width, &height,
00175                     &depth, &enablecol);
00176 
00177 #if defined(LOGGING)
00178         if (result != errNone)
00179                 WriteLog("Could not set resolution to (%d,%d)\n", (int)width,
00180                     (int)height);
00181         else
00182                 WriteLog("Resolution set to (%d,%d)\n", (int)width,
00183                     (int)height);
00184 #endif
00185         return (result);
00186 }
00187 
00188 Err
00189 restoreDepthRes(void)
00190 {
00191         Err rv;
00192 
00193         if (0 != (rv = WinScreenMode(winScreenModeSetToDefaults, NULL, NULL,
00194                     NULL, NULL)))
00195                 return (rv);
00196         if (0 != (rv = unloadHiRes()))
00197                 return (rv);
00198         return (0);
00199 }
00200 
00201 Boolean
00202 canColor(UInt16 nbits)
00203 {
00204         UInt32 de;
00205         UInt32 wi;
00206         UInt32 he;
00207         Boolean ec;
00208 
00209         WinScreenMode(winScreenModeGetSupportedDepths,
00210             &wi, &he, &de, &ec);
00211         if (de & (1<<(nbits-1)))
00212                 return (true);
00213         return (false);
00214 }
00215 
00216 /*
00217 UInt32
00218 GetCreatorID(void)
00219 {
00220         static UInt32 nCreatorID = 0;
00221 
00222         if (nCreatorID == 0) {
00223                 UInt16 nCard;
00224                 LocalID LocalDB;
00225                 Err err;
00226                 err = SysCurAppDatabase(&nCard, &LocalDB);
00227                 ErrFatalDisplayIf(err, "Could not get current app database.");
00228                 err = DmDatabaseInfo(nCard, LocalDB, 0, 0, 0, 0, 0, 0, 0, 0,
00229                     0, 0, &nCreatorID);
00230                 ErrFatalDisplayIf(err,
00231                     "Could not get app database info, looking for creator ID");
00232         }
00233 
00234         return (nCreatorID);
00235 }
00236 */
00237 UInt32
00238 GetCreatorID(void)
00239 {
00240         return (PROGTOKEN);
00241 }
00242 
00243 #if defined(LOGGING)
00244 
00245 void
00246 DangerWillRobinson(char *information, char *file, int line)
00247 {
00248         char buffer[80];
00249         StrPrintF(buffer, "%s(%d)", file, line);
00250         FrmCustomAlert(alertID_programmingNiggle, information, buffer, NULL);
00251 }
00252 
00253 #endif
00254 
00255 Char **
00256 FillStringList(UInt16 resID, UInt16 *length)
00257 {
00258         UInt16 max = 0;
00259         UInt16 atitem = 0;
00260         Char *foo = NULL;
00261         Char **rv = NULL;
00262         Char *lom;
00263         Char item[201];
00264         UInt32 maxlen = 0;
00265 
00266         do {
00267                 foo = SysStringByIndex(resID, max, item, 200);
00268                 if (*foo != '\0') {
00269                         maxlen += 1 + StrLen(item);
00270                         max++;
00271                 } else break;
00272         } while (foo);
00273         rv = (Char **)MemPtrNew(sizeof (*rv) * (max + 1));
00274         MemSet(rv, sizeof (*rv) * (max + 1), 0);
00275         lom = (Char *)MemPtrNew(sizeof (*lom) * maxlen);
00276         MemSet(lom, sizeof (*lom) * maxlen, 0);
00277         rv[0] = lom;
00278         while (atitem < max) {
00279                 UInt16 sli;
00280                 SysStringByIndex(resID, atitem, item, 200);
00281                 sli = StrLen(item);
00282                 StrNCopy(rv[atitem], item, (Int16)sli);
00283                 rv[atitem + 1] = rv[atitem] + (sli + 1);
00284                 atitem++;
00285         }
00286         *length = max;
00287         return (rv);
00288 }
00289 
00290 void
00291 FreeStringList(Char **list)
00292 {
00293         MemPtrFree(list[0]);
00294         MemPtrFree(list);
00295 }
00296 
00297 void *
00298 GetObjectPtr(FormType *form, UInt16 index)
00299 {
00300         return (FrmGetObjectPtr(form,
00301             FrmGetObjectIndex(form, index)));
00302 }
00303 
00304 void
00305 compatBmpGetDimensions(BitmapPtr pBmp, Coord *pWidth, Coord *pHeight,
00306     UInt16 *pRowBytes)
00307 {
00308         if (!Is40ROM()) {
00309                 if (pWidth != NULL) *pWidth = (Coord)pBmp->width;
00310                 if (pHeight != NULL) *pHeight = (Coord)pBmp->height;
00311                 if (pRowBytes != NULL) *pRowBytes = pBmp->rowBytes;
00312         } else
00313                 BmpGetDimensions(pBmp, pWidth, pHeight, pRowBytes);
00314 }
00315 

Generated on Mon Aug 30 19:44:15 2004 for pocketcity by doxygen1.2.18