Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

palm/sony_support.c

Go to the documentation of this file.
00001 
00007 #include <PalmTypes.h>
00008 #include <FeatureMgr.h>
00009 #include <ErrorBase.h>
00010 #include <ErrorMgr.h>
00011 #include <SystemMgr.h>
00012 
00013 #ifndef SONY_CLIE
00014 
00015 #else /* SONY_CLIE */
00016 
00017 #include <resCompat.h>
00018 #include <sony_support.h>
00019 #include <palmutils.h>
00020 #include <logging.h>
00021 
00027 static UInt16 hires;
00029 static UInt8 didl;
00030 
00032 static Int16 silk_ref = -1;
00034 static Int8 silk_ver = -1;
00035 
00037 static void (*holdCB)(UInt32 held);
00038 
00044 static Err
00045 PrvHoldNotificationHandler(SysNotifyParamType *npp)
00046 {
00047         UInt32 held;
00048 
00049         if (npp->broadcaster != sonySysNotifyBroadcasterCode)
00050                 return (errNone);
00051         held = ((SonySysNotifyHoldStatusChangeDetailsP)
00052             (npp->notifyDetailsP))->holdOn;
00053         ErrFatalDisplayIf(holdCB == NULL,
00054             "Received hold call without valid handler");
00055         if (holdCB != NULL)
00056                 holdCB(held);
00057         return (errNone);
00058 }
00059 
00060 void
00061 hookHoldSwitch(void (*CallBack)(UInt32))
00062 {
00063         Err err;
00064         UInt32 val;
00065 
00066         err = FtrGet(sysFtrCreator, sysFtrNumNotifyMgrVersion, &val);
00067         if (!err && val) {
00068                 UInt16 CardNo;
00069                 LocalID dbID;
00070                 SysCurAppDatabase(&CardNo, &dbID);
00071                 SysNotifyRegister(CardNo, dbID,
00072                     sonySysNotifyHoldStatusChangeEvent,
00073                     PrvHoldNotificationHandler, sysNotifyNormalPriority, NULL);
00074                 holdCB = CallBack;
00075         }
00076 }
00077 
00078 void
00079 unhookHoldSwitch(void)
00080 {
00081         Err err;
00082         UInt32 val;
00083 
00084         err = FtrGet(sysFtrCreator, sysFtrNumNotifyMgrVersion, &val);
00085         if (!err && val) {
00086                 UInt16 CardNo;
00087                 LocalID dbID;
00088                 DmSearchStateType state;
00089                 DmGetNextDatabaseByTypeCreator(true, &state, 'appl',
00090                     GetCreatorID(), true, &CardNo, &dbID);
00091                 SysNotifyUnregister(CardNo, dbID,
00092                     sonySysNotifyHoldStatusChangeEvent,
00093                     sysNotifyNormalPriority);
00094                 holdCB = NULL;
00095         }
00096 }
00097 
00098 Err
00099 goHires(void)
00100 {
00101         Err result;
00102         UInt32 width;
00103         UInt32 height;
00104 
00105         width = sWidth;
00106         height = sHeight;
00107 
00108         result = _WinScreenMode(winScreenModeSet, &width, &height,
00109             NULL, NULL);
00110         return (result);
00111 }
00112 
00113 Err
00114 loadHiRes(void)
00115 {
00116         SonySysFtrSysInfoP sonySysFtrSysInfoP;
00117         Err error = 0;
00118         UInt16 refNum;
00119 
00120         if (highDensityFeatureSet() != 0)
00121                 return (errNone);
00122         if ((error = FtrGet(sonySysFtrCreator,
00123                 sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP))) {
00124                 /* Not CLIE: maybe not available */
00125         } else {
00126                 if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrHR) {
00127                         /* HR available */
00128                         if ((error = SysLibFind(sonySysLibNameHR, &refNum))) {
00129                                 if (error == sysErrLibNotFound) {
00130                                 /* couldn't find lib */
00131                                 error = SysLibLoad('libr', sonySysFileCHRLib,
00132                                     &refNum);
00133                                 }
00134                                 if (!error) didl = 1;
00135                         }
00136                         if (!error) {
00137                                 hires = refNum;
00138                                 /* Now we can use HR lib */
00139                                 HROpen(hires);
00140                         }
00141                         ErrFatalDisplayIf(error, "could not load hires lib");
00142                 }
00143         }
00144         if (!error)
00145                 error = goHires();
00146 
00147         return (error);
00148 }
00149 
00150 Err
00151 unloadHiRes(void)
00152 {
00153         Err rv = 0;
00154         if (hires != 0) {
00155                 rv = HRClose(hires);
00156                 if (didl)
00157                         SysLibRemove(hires);
00158                 didl = 0;
00159                 hires = 0;
00160         }
00161         return (rv);
00162 }
00163 
00164 Boolean
00165 sonyCanHires(void)
00166 {
00167         if (hires == 0) {
00168                 loadHiRes();
00169                 if (hires != 0) {
00170                         HRClose(hires);
00171                         SysLibRemove(hires);
00172                         hires = 0;
00173                         return (true);
00174                 } else
00175                         return (false);
00176         } else
00177                 return (true);
00178 }
00179 
00180 Boolean
00181 sonyHires(void)
00182 {
00183         return  (hires != 0);
00184 }
00185 
00186 Err
00187 _WinScreenMode(WinScreenModeOperation op, UInt32 *width, UInt32 *height,
00188     UInt32 *depth, Boolean *enableColor)
00189 {
00190         if (hires)
00191                 return (HRWinScreenMode(hires, op, width, height, depth,
00192                     enableColor));
00193         else
00194                 return (WinScreenMode(op, width, height, depth, enableColor));
00195 }
00196 
00197 void
00198 _WinDrawRectangle(RectangleType *r, UInt16 cornerDiam)
00199 {
00200         if (hires)
00201                 HRWinDrawRectangle(hires, r, cornerDiam);
00202         else
00203                 WinDrawRectangle(r, cornerDiam);
00204 }
00205 
00206 void
00207 _WinEraseRectangle(RectangleType *r, UInt16 cornerDiam)
00208 {
00209         if (hires)
00210                 HRWinEraseRectangle(hires, r, cornerDiam);
00211         else
00212                 WinEraseRectangle(r, cornerDiam);
00213 }
00214 
00215 void
00216 _WinDrawBitmap(BitmapPtr bmp, Coord x, Coord y)
00217 {
00218         if (hires) {
00219                 HRWinDrawBitmap(hires, bmp, x, y);
00220         } else {
00221                 WinDrawBitmap(bmp, x, y);
00222         }
00223 }
00224 
00225 BitmapType *
00226 _BmpCreate(Coord width, Coord height, UInt8 depth, ColorTableType *clut,
00227     UInt16 *error)
00228 {
00229         if (hires)
00230                 return (HRBmpCreate(hires, width, height, depth, clut, error));
00231         else
00232                 return (BmpCreate(width, height, depth, clut, error));
00233 }
00234 
00235 WinHandle
00236 _WinCreateBitmapWindow(BitmapType *pBitmap, UInt16 *err)
00237 {
00238         if (hires)
00239                 return (HRWinCreateBitmapWindow(hires, pBitmap, err));
00240         else
00241                 return (WinCreateBitmapWindow(pBitmap, err));
00242 }
00243 
00244 WinHandle
00245 _WinCreateOffscreenWindow(Coord width, Coord height, WindowFormatType format,
00246     UInt16 *error)
00247 {
00248         if (hires)
00249                 return (HRWinCreateOffscreenWindow(hires, width, height,
00250                     format, error));
00251         else
00252                 return (WinCreateOffscreenWindow(width, height, format, error));
00253 }
00254 
00255 void
00256 _WinCopyRectangle(WinHandle srcWin, WinHandle dstWin, RectangleType *srcRect,
00257     Coord destX, Coord destY, WinDrawOperation mode)
00258 {
00259         if (hires)
00260                 HRWinCopyRectangle(hires, srcWin, dstWin, srcRect,
00261                     destX, destY, mode);
00262         else
00263                 WinCopyRectangle(srcWin, dstWin, srcRect, destX, destY, mode);
00264 }
00265 
00266 void
00267 _WinDrawChars(const Char *chars, Int16 len, Coord x, Coord y)
00268 {
00269         if (hires)
00270                 HRWinDrawChars(hires, chars, len, x, y);
00271         else
00272                 WinDrawChars(chars, len, x, y);
00273 }
00274 
00275 void
00276 _WinDrawRectangleFrame(FrameType frame, RectangleType *rP)
00277 {
00278         if (hires)
00279                 HRWinDrawRectangleFrame(hires, frame, rP);
00280         else
00281                 WinDrawRectangleFrame(frame, rP);
00282 }
00283 
00284 void
00285 _FntSetFont(FontID font)
00286 {
00287         if (hires)
00288                 HRFntSetFont(hires, font);
00289         else
00290                 FntSetFont(font);
00291 }
00292 
00293 void
00294 _WinDrawPixel(Coord x, Coord y)
00295 {
00296         if (hires)
00297                 HRWinDrawPixel(hires, x, y);
00298         else
00299                 WinDrawPixel(x, y);
00300 }
00301 
00302 void
00303 _WinGetDrawWindowBounds(RectangleType *rP)
00304 {
00305         if (hires)
00306                 HRWinGetWindowBounds(hires, rP);
00307         else
00308                 WinGetDrawWindowBounds(rP);
00309 }
00310 
00311 int
00312 IsDrawWindowMostOfScreen()
00313 {
00314         RectangleType rt;
00315         _WinGetDrawWindowBounds(&rt);
00316         return (((UInt32)rt.extent.x * rt.extent.y * 12) >=
00317             ((UInt32)sWidth * sHeight * 10));
00318 }
00319 
00320 Boolean
00321 IsSony(void)
00322 {
00323         static int tested = -1;
00324         UInt32 val;
00325 
00326         if (tested != -1)
00327                 return (tested == 1);
00328         tested = 0;
00329         if (!FtrGet(sysFtrCreator, sysFtrNumOEMCompanyID, &val)) {
00330                 if (val == sonyHwrOEMCompanyID_Sony)
00331                         tested = 1;
00332         }
00333         return (tested == 1);
00334 }
00335 
00341 static Err
00342 SonyNotifyHook(SysNotifyParamType *notifyParamsP __attribute__((unused)))
00343 {
00344         EventType ev;
00345 
00346         MemSet(&ev, sizeof(ev), 0);
00347         ev.eType = winDisplayChangedEvent;
00348         EvtAddUniqueEventToQueue(&ev, 0,  true);
00349         return (0);
00350 }
00351 
00352 Boolean
00353 SonySilk(void)
00354 {
00355         Err error = errNone;
00356         UInt32 version;
00357         UInt16          cardNo;
00358         LocalID         dbID;
00359 
00360         if (silk_ref != -1)
00361                 return (silk_ref != 0);
00362 
00363         if (SysLibFind(sonySysLibNameSilk, &silk_ref)) {
00364                 error = SysLibLoad('libr', sonySysFileCSilkLib, &silk_ref);
00365         }
00366         if (error == sysErrLibNotFound || silk_ref == -1) {
00367                 silk_ref = 0;
00368                 return (0);
00369         }
00370         WriteLog("found sony silk library ");
00371 
00372         error = FtrGet(sonySysFtrCreator, sonySysFtrNumVskVersion, &version);
00373         if (error) {
00374                 silk_ver = 0;
00375                 SilkLibOpen(silk_ref);
00376         } else {
00377                 VskOpen(silk_ref);
00378                 silk_ver = 1;
00379         }
00380 
00381         WriteLog("version: %d\n", silk_ver);
00382 
00383         SonySetSilkResizable(true);
00384 
00385         SysCurAppDatabase(&cardNo, &dbID);
00386         SysNotifyRegister(cardNo, dbID, sysNotifyDisplayChangeEvent,
00387             SonyNotifyHook, sysNotifyNormalPriority, NULL);
00388 
00389 
00390         return (silk_ref != 0);
00391 }
00392 
00393 void
00394 SonyEndSilk(void)
00395 {
00396         UInt16 cardNo;
00397         LocalID dbID;
00398 
00399         if (silk_ref <= 0)
00400                 return;
00401 
00402         WriteLog("Will Close\n");
00403         if (silk_ver == 0) {
00404                 //SilkLibResizeDispWin(silk_ref, silkResizeNormal);
00405                 //SilkLibDisableResize(silk_ref);
00406                 SilkLibClose(silk_ref);
00407         } else {
00408                 //VskSetState(silk_ref, vskStateResize, vskResizeMin);
00409                 //VskSetState(silk_ref, vskStateEnable, 0);
00410                 VskClose(silk_ref);
00411         }
00412         silk_ref = -1;
00413         SysCurAppDatabase(&cardNo, &dbID);
00414         SysNotifyUnregister(cardNo, dbID, sysNotifyDisplayChangeEvent,
00415             sysNotifyNormalPriority);
00416 }
00417 
00418 void
00419 SonySetSilkResizable(UInt8 state)
00420 {
00421         if (silk_ver == -1)
00422                 return;
00423         if (silk_ver == 0) {
00424                 if (state) {
00425                         SilkLibEnableResize(silk_ref);
00426                 } else {
00427                         SilkLibResizeDispWin(silk_ref, silkResizeNormal);
00428                         SilkLibDisableResize(silk_ref);
00429                 }
00430         } else {
00431                 if (!state)
00432                         VskSetState(silk_ref, vskStateEnable, state);
00433                 else if (VskGetAPIVersion(silk_ref) >= 0x03)
00434                         VskSetState(silk_ref, vskStateEnable, 
00435                             vskResizeVertically | vskResizeHorizontally);
00436                 else
00437                         VskSetState(silk_ref, vskStateEnable, 1);
00438         }
00439 }
00440 
00441 void
00442 SonyCollapsePreRedraw(FormPtr form)
00443 {
00444         if (silk_ver == 0)
00445                 FrmEraseForm(form);
00446 }
00447 
00448 #endif /* SONY_CLIE */

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