Err ZDicFontRelease ( UInt16 refNum, ZDicFontType* fontP ) { #pragma unused(refNum) Err err = errNone; //Release the phonic font resource when app quits. if ( fontP->phonicSmallFontH != NULL ) { MemHandleUnlock ( fontP->phonicSmallFontH ); DmReleaseResource ( fontP->phonicSmallFontH ); } if ( fontP->phonicLargeFontH != NULL ) { MemHandleUnlock ( fontP->phonicLargeFontH ); DmReleaseResource ( fontP->phonicLargeFontH ); } if ( fontP->fontLibP != 0 ) { err = DmCloseDatabase ( fontP->fontLibP ); } return err; }
/*********************************************************************** * * FUNCTION: ZDicFontInit * * DESCRIPTION: Initial all font resource * * PARAMETERS: nothing * * RETURN: errNone if success else fail. * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * ZhongYuanHuan 14/Aug/04 Initial Revision * ***********************************************************************/ Err ZDicFontInit ( UInt16 refNum, ZDicFontType* fontP, Boolean bUseSysFont ) { #pragma unused(refNum) UInt32 version; Err err; MemSet ( fontP, sizeof ( ZDicFontType ), 0 ); fontP->smallFontID = stdFont; fontP->largeFontID = largeFont; if ( bUseSysFont ) return errNone; fontP->fontLibP = DmOpenDatabaseByTypeCreator ( ZDicFontTypeID, ZDicFontCreatorID, dmModeReadOnly ); if ( fontP->fontLibP == 0 ) { err = DmGetLastErr (); return err; } // Load the phonic font resource and assign it a font ID. err = FtrGet(sysFtrCreator, sysFtrNumWinVersion, &version); if (!err && version >= 4 ) { // the screen is double density so use double density of phonetic font. fontP->phonicSmallFontH = DmGetResource('nfnt', PhonicSmallFontHight); fontP->phonicLargeFontH = DmGetResource('nfnt', PhonicLargeFontHight); } if (fontP->phonicSmallFontH == NULL || fontP->phonicLargeFontH == NULL) { if (fontP->phonicSmallFontH != NULL) DmReleaseResource(fontP->phonicSmallFontH); if (fontP->phonicLargeFontH != NULL) DmReleaseResource(fontP->phonicLargeFontH); // the screen is low desity so use low density of phonetic font. fontP->phonicSmallFontH = DmGetResource(fontRscType, PhonicSmallFontLow); fontP->phonicLargeFontH = DmGetResource(fontRscType, PhonicLargeFontLow); } fontP->phonicSmallFontP = (FontType *)MemHandleLock(fontP->phonicSmallFontH); fontP->phonicLargeFontP = (FontType *)MemHandleLock(fontP->phonicLargeFontH); err = FntDefineFont(kPHONIC_SMALL_FONT_ID, fontP->phonicSmallFontP); err = FntDefineFont(kPHONIC_LARGE_FONT_ID, fontP->phonicLargeFontP); fontP->smallFontID = kPHONIC_SMALL_FONT_ID; fontP->largeFontID = kPHONIC_LARGE_FONT_ID; return errNone; }
static void ModSetStack(UInt32 newSize, UInt16 cardNo, LocalID dbID) { DmOpenRef dbRef = DmOpenDatabase(cardNo, dbID, dmModeReadWrite); if (dbRef) { MemHandle pref = DmGetResource('pref',0); UInt32 size = 0; if (pref) { SysAppPrefsType *data = (SysAppPrefsType *)MemHandleLock(pref); size = data->stackSize; if (newSize) { SysAppPrefsType newData; MemMove(&newData, data, sizeof(SysAppPrefsType)); newData.stackSize = newSize; DmWrite(data, 0, &newData, sizeof(SysAppPrefsType)); } MemPtrUnlock(data); DmReleaseResource(pref); } DmCloseDatabase(dbRef); } }
void String_Init() { MemHandle Resource; DmResID Id; context* p = Context(); StringAlloc(); for (Id=1000;Id<1000+32;++Id) { Resource = DmGetResource('lang',Id); if (Resource) { int Size = MemHandleSize(Resource); void* Data = MemHandleLock(Resource); if (Size && Data && StringAddBinary(Data,Size)) ArrayAppend(&p->StrModule,&Resource,sizeof(Resource),16); else { if (Data) MemHandleUnlock(Resource); DmReleaseResource(Resource); } } } }
/* ** DrawBitmap */ static void DrawBitmap(UInt16 bitmapID, Coord x, Coord y) { const MemHandle bitmapH = DmGetResource(bitmapRsc, bitmapID); WinDrawBitmap(MemHandleLock(bitmapH), x, y); /* Clean up */ MemHandleUnlock(bitmapH); DmReleaseResource(bitmapH); }
/* DrawBitmap -- Places a bitmap at a specified location * Args: * Word BitmapID -- ID for bitmap, see the cwimp.rpc file * int formX -- X location on the form * int formY -- Y location on the form * Returns: None */ void DrawBitmap (Word BitmapID, int formX, int formY) { VoidHand resourceHandle; BitmapPtr bitmapPntr; resourceHandle = DmGetResource(bitmapRsc, BitmapID); bitmapPntr = MemHandleLock(resourceHandle); WinDrawBitmap(bitmapPntr, formX, formY); MemPtrUnlock(bitmapPntr); DmReleaseResource(resourceHandle); }
void String_Done() { MemHandle *i; context* p = Context(); StringFree(); for (i=ARRAYBEGIN(p->StrModule,MemHandle);i!=ARRAYEND(p->StrModule,MemHandle);++i) { MemHandleUnlock(*i); DmReleaseResource(*i); } ArrayClear(&p->StrModule); }
void Graphics::drawBitmap(uint_t bitmapId, const Point& topLeft) { MemHandle handle=DmGet1Resource(bitmapRsc, bitmapId); if (handle) { BitmapType* bmp=static_cast<BitmapType*>(MemHandleLock(handle)); if (bmp) { WinDrawBitmap(bmp, topLeft.x, topLeft.y); MemHandleUnlock(handle); } DmReleaseResource(handle); } }
static Int16 LoadIcon(Int16 start) { FormPtr frmP = FrmGetActiveForm(); Int8 i; Int16 num; Int16 iconButtonID = IconSelectIcon1Button; BitmapPtr pbmp; MemHandle h; Int16 x, y; RectangleType r; num = DmNumResources(IconDB); if (start > num) start = 0; for (i = 0; i < 9*8; i++) { UInt16 idx = FrmGetObjectIndex(frmP, iconButtonID + i); FrmGetObjectPosition(frmP, idx, &x, &y); FrmGetObjectBounds(frmP, idx, &r); r.topLeft.x = x; r.topLeft.y = y; WinEraseRectangle(&r, 0); if (i+start <num) { h = (MemPtr)GetIconByIndex(IconDB, i + start); pbmp = (h) ? MemHandleLock(h) : NULL; if (pbmp) { WinDrawBitmap(pbmp, x, y); MemHandleUnlock(h); DmReleaseResource(h); ShowObject(frmP, iconButtonID + i); } else { HideObject(frmP, iconButtonID + i); } } else { HideObject(frmP, iconButtonID + i); } } return num; }
/* ** DrawPlugBitmap */ static void DrawPlugBitmap(Int16 plugindex, UInt16 rscID, Coord x, Coord y) { SysDBListItemType *pluglistP = MemHandleLock(d.xfer.pluglistH); DmOpenRef dbR = DmOpenDatabase(pluglistP[plugindex].cardNo, pluglistP[plugindex].dbID, dmModeReadOnly); MemHandle plugH = DmGet1Resource('BooG', rscID); ASSERT(dbR); ASSERT(plugH); WinDrawBitmap(MemHandleLock(plugH), x, y); /* Clean up */ MemHandleUnlock(d.xfer.pluglistH); MemHandleUnlock(plugH); DmReleaseResource(plugH); DmCloseDatabase(dbR); }
/* Release a font resource */ void ReleaseFontResource ( MemHandle handle, FontResourceKind kind ) { if ( handle == NULL ) return; #ifdef SUPPORT_VFS_FONTS if ( kind == fontResourceVFS ) { MemHandleFree( handle ); } else #endif { DmReleaseResource( handle ); } return; }
static Int16 DrawIconBitmap(UInt16 iconID, Coord x, Coord y) { MemHandle pointH; BitmapPtr pbmp; if (IconDB) { pointH = DmGet1Resource('Tbmp', iconID); pbmp = (pointH) ? MemHandleLock(pointH) : NULL; if (pbmp) { WinDrawBitmap(pbmp, x, y); MemHandleUnlock(pointH); DmReleaseResource(pointH); return 1; } } return 0; }
static Boolean RulesFormHandleEvent(EventPtr event) { Boolean handled = false; switch (event->eType) { case ctlRepeatEvent: switch (event->data.ctlRepeat.controlID) { case rulesScrollUp: RulesScroll (winUp, false); break; case rulesScrollDown: RulesScroll (winDown, false); break; } break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case rulesScrollUp: RulesScroll (winUp, false); break; case rulesScrollDown: RulesScroll (winDown, false); break; } break; case keyDownEvent: switch (event->data.keyDown.chr) { case pageDownChr: RulesScroll (winDown, true); handled = true; break; case pageUpChr: RulesScroll (winUp, true); handled = true; break; } break; default: } return handled; } void Rules (void) { FieldPtr field; VoidHand rulesH; rulesH = DmGetResource ('tSTR', ricochetRulesText); if (rulesH) { rulesFrm = FrmInitForm (rulesForm); field = FrmGetObjectPtr (rulesFrm, FrmGetObjectIndex (rulesFrm, rulesText)); FldSetInsPtPosition (field, 0); FldSetTextHandle (field, (Handle) rulesH); RulesSetScrolling (); FrmSetEventHandler (rulesFrm, RulesFormHandleEvent); FrmDoDialog (rulesFrm); FldSetTextHandle (field, 0); DmReleaseResource (rulesH); FrmDeleteForm (rulesFrm); } }
Boolean CBiddingForm::OnNilEvent(EventPtr pEvent, Boolean& bHandled) { if ( gManager->Status() == GetHandBids ) { HighlightActiveBidder(); FormPtr frmP = FrmGetActiveForm(); Int16 player_index = (*gManager->tbl->current_bidder)->playerIndex; // // if this is a human player, we need to render the screen widgets for their bid // if ( player_index == gManager->humanIndex && player_has_bid == false ) { player_hand.Render(true); Int16 current_bid = 0; if ( (*gManager->tbl->dealer)->playerIndex != gManager->humanIndex || ! gManager->dealer_take_bid ) { current_bid = gManager->tbl->high_bid; } else { current_bid = gManager->tbl->high_bid - 1; } if ( (*gManager->tbl->dealer)->playerIndex == gManager->humanIndex && gManager->tbl->high_bid < 2 ) { CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), "-Pass-"); } else { switch (current_bid) { case 5: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), "-S-"); case 4: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); case 3: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); case 2: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), "-2-"); } } } // if if ( player_index == 3 && player_has_bid == false ) // // handle processing actual bids here - get one automatically if this player isn't // a human, or if the human has already bid // if ( player_index != gManager->humanIndex || player_has_bid == true ) { Boolean player_did_bid = gManager->GetNextBid(gManager->trk, false ); Int16 tmp_bid = (*gManager->tbl->current_bidder)->Bid(); if ( player_did_bid && gManager->tbl->current_bidder == gManager->tbl->winning_bidder && (tmp_bid >= 2) ) { char x[10]; StrPrintF(x, "bids %d", tmp_bid ); bidstr = x; } else { bidstr = "passes"; } bids[(*gManager->tbl->current_bidder)->playerIndex].Replace(bidstr); // // if we just got the dealer's bid, then we are all done // if ( gManager->tbl->current_bidder == gManager->tbl->dealer ) { // // at this point we need to set trump... // gManager->Status(SetHandTrump); if ( (*gManager->tbl->winning_bidder)->playerIndex == gManager->humanIndex ) { CPlayerTrumpForm frmPlayerTrump; frmPlayerTrump.DoModal(); } FrmDrawForm(frmP); // // ... and display the final results // Card::suit_t foo = (*gManager->tbl->winning_bidder)->Trump(); gManager->tbl->trump = foo; gManager->trk->no_trump_first_trick = (*gManager->tbl->winning_bidder)->NoTrumpFirstTrickP(); MemHandle hRsc; BitmapType* bitmapP; switch ( gManager->tbl->trump ) { case Card::heart: hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily ); break; case Card::diamond: hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily ); break; case Card::club: hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily ); break; case Card::spade: hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily ); break; } if ( gManager->trk->no_trump_first_trick ) { FrmCustomAlert(NoTrumpFirstTrickAlert, (*gManager->tbl->winning_bidder)->name, "", ""); } RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, BiddingTrumpGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); WinPaintChars("Trump Is: ", StrLen("Trump Is: "), bounds.topLeft.x, bounds.topLeft.y ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); bitmapP = (BitmapType*) MemHandleLock(hRsc); WinDrawBitmap (bitmapP, bounds.topLeft.x + 40, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); UInt32 hsStatusVersion; if (FtrGet (hsFtrCreator, hsFtrIDNavigationSupported, &hsStatusVersion) == 0) { FrmGlueNavObjectTakeFocus(FrmGetActiveForm(), BiddingOKButton ); } } // if ( dealer bid ) else { // move along to the next player gManager->tbl->current_bidder = gManager->getNextPlayerIter(gManager->tbl->current_bidder); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); // pause here // SysTaskDelay(SysTicksPerSecond()); gManager->ShortDelay(); } } // if ( player_index != 3 || player_has_bid == true ) } // if GetHandBids bHandled = false; return true; }
int wxMessageDialog::ShowModal() { int AlertID=1000; int Result=0; int wxResult=wxID_OK; const long style = GetMessageDialogStyle(); // Handle to the currently running application database DmOpenRef AppDB; SysGetModuleDatabase(SysGetRefNum(), NULL, &AppDB); // Translate wx styles into Palm OS styles if (style & wxYES_NO) { if (style & wxCANCEL) AlertID=1300; // Yes No Cancel else AlertID=1200; // Yes No } if (style & wxOK) { if (style & wxCANCEL) AlertID=1100; // Ok Cancel else AlertID=1000; // Ok } // Add the icon styles if (style & wxICON_EXCLAMATION) AlertID=AlertID+0; // Warning else if (style & wxICON_HAND) AlertID=AlertID+1; // Error else if (style & wxICON_INFORMATION) AlertID=AlertID+2; // Information else if (style & wxICON_QUESTION) AlertID=AlertID+3; // Confirmation // The Palm OS Dialog API does not support custom titles in a dialog box. // So we have to set the title by manipulating the resource. // Get the alert resource char *AlertPtr; MemHandle AlertHandle; AlertHandle=DmGetResource(AppDB,'Talt',AlertID); AlertPtr=(char *)MemHandleLock(AlertHandle); AlertPtr+=8; // Clear out any old title. This must be done with a static array of chars // because using MemSet is not supported on resources and could result in // crashes or unpredictable behaviour. char ClearTitle[25]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; MemMove(AlertPtr,&ClearTitle,25); // Get the title length and make sure it is not too long int TitleLength=m_caption.length(); if(TitleLength>25) TitleLength=25; // Center the title in the window int BufferLength=(25-TitleLength)/2; AlertPtr+=BufferLength; // Copy the title MemMove(AlertPtr,m_caption.c_str(),TitleLength); // Release the resource MemHandleUnlock(AlertHandle); DmReleaseResource(AlertHandle); // Display the dialog Result=FrmCustomAlert(AppDB,AlertID,m_message.c_str(),"",""); // Convert the Palm OS result to wxResult if(AlertID<1100) { // Ok wxResult=wxID_OK; } else if(AlertID<1200) { // Ok Cancel if(Result==0) wxResult=wxID_OK; else wxResult=wxID_CANCEL; } else if(AlertID<1300) { // Yes No if(Result==0) wxResult=wxID_YES; else wxResult=wxID_NO; } else { // Yes No Cancel if(Result==0) wxResult=wxID_YES; else if(Result==1) wxResult=wxID_NO; else wxResult=wxID_CANCEL; } return wxResult; }
/* Palm OS does not have good dynamic menu support. About all you can do with * the standard API calls is to add new items to an existing drop-down menu and * hide/show items in a drop-down menu. It is impossible to add, hide, or * change the label on a drop-down menu. * * The easiest and simplest way around this limitation is to modify the Palm OS * MenuBarType structure directly. This gives limited ability to change the * label on a drop-down menu. I have not been able to find a safe way to add, * delete, or resize drop-down menus in OS 6. * * The following routine attempt to work around these limitations present in the * Palm OS API to provide limited dynamic menu support. This solution is far * from perfect, but the only other option is to wait for PalmSource to add full * dynamic menu support, or to recreate the Palm OS menu system from scratch. * * This system is limited in that no more than 4 drop-down menus are allowed per * menu bar, and the label for each drop-down menu is limited to 8 characters of * text. However, this menu system should work for most applications. * * Basically the menu routines select one of four menu bars, depending on * whether or not the requested menu bar has one, two, three, or four drop-down * menus. * * These four "template" menu bars contain one, two, three, or four drop-down * menus. Each menu has a dummy menu item attached to it to allow the Palm OS * MenuAddItem function to add the real items. * * The labels on the drop-down menus are then replaced with the labels of the * real menus. * * The menu is then attached to the active window and the MenuAddItem API * function is called to add the items to each drop-down menu. Finally, * MenuHideItem is called to remove the dummy items from each drop-down menu. */ void wxMenuBar::LoadMenu() { int i=0; int j=0; // Handle to the currently running application database DmOpenRef AppDB; // Get app database reference - needed for some Palm OS Menu API calls. SysGetModuleDatabase(SysGetRefNum(), NULL, &AppDB); // Get the number of menus int NumMenus=GetMenuCount(); // Set up the pointers and handles char *PalmOSMenuBarPtr; MemHandle PalmOSMenuBar; // Load the menu template and set up the menu pointers if(NumMenus==1) { PalmOSMenuBar=DmGetResource(AppDB,'MBAR',1000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=74; } else if(NumMenus==2) { PalmOSMenuBar=DmGetResource(AppDB,'MBAR',2000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=116; } else if(NumMenus==3) { PalmOSMenuBar=DmGetResource(AppDB,'MBAR',3000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=158; } else { // We support a maximum of 4 menus, so make sure that do not create // more than we can handle. NumMenus=4; PalmOSMenuBar=DmGetResource(AppDB,'MBAR',4000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=200; } // Set the proper names for the drop-down triggers. for(i=0;i<NumMenus;i++) { // Clear out the old label char buffer[8]={' ',' ',' ',' ',' ',' ',' ',' '}; MemMove(PalmOSMenuBarPtr,buffer,8); wxString MenuTitle=m_titles.Item(i); // Make sure we don't copy more than 8 bytes for the label int LengthToCopy=MenuTitle.length(); if(LengthToCopy>8) LengthToCopy=8; MemMove(PalmOSMenuBarPtr,MenuTitle,LengthToCopy); PalmOSMenuBarPtr+=11; } // We are done with the menu pointer. MemHandleUnlock(PalmOSMenuBar); DmReleaseResource(PalmOSMenuBar); // We must make the menu active before we can add items to the drop-down // triggers. FrmSetMenu(FrmGetActiveForm(),AppDB,NumMenus*1000); /* Add the menu items to the drop-down triggers. This must be done after * setting the triggers, because setting the names of drop-down triggers * that have a variable number of items requires carefull calculation of * the offsets in the MenuBarType structure. Setting the triggers first * avoids this. */ for(i=0;i<NumMenus;i++) { wxMenu *CurrentMenu=GetMenu(i); for(j=0;j<CurrentMenu->GetMenuItemCount();j++) { wxMenuItem *CurrentItem=CurrentMenu->FindItemByPosition(j); wxString ItemLabel=CurrentItem->GetLabel(); if(CurrentItem->IsSeparator()==true) { char Separator=MenuSeparatorChar; if(j==0) MenuAddItem(9000+i,((i*1000)+1000)+j,0x00,&Separator); else MenuAddItem(((i*1000)+1000)+j-1,((i*1000)+1000)+j,0x00,&Separator); } else { if(j==0) MenuAddItem(9000+i,((i*1000)+1000)+j,0x00,ItemLabel); else MenuAddItem(((i*1000)+1000)+j-1,((i*1000)+1000)+j,0x00,ItemLabel); } } // Hide the dummy menu item, since we don't need it anymore. MenuHideItem(9000+i); } }
/* Draw the actual buttons onto blank bitmaps, and set them as valid templates on the silkscreen */ static void DrawButtons( void ) { Err err; BitmapPtr silkBitmap; BitmapPtr silkBitmapInv; WinHandle silkWindow; WinHandle silkWindowInv; WinHandle origWindow; UInt16 i; Coord currentX; Coord currentY; Coord silkX; Coord silkY; origWindow = WinGetDrawWindow(); if ( currentSilkStatus == HANDERA_SILK_UP ) { SilkGetTemplateBitmaps( &silkBitmap, &silkBitmapInv, NULL, NULL ); } else { SilkGetTemplateBitmaps( NULL, NULL, &silkBitmap, &silkBitmapInv ); } BmpGlueGetDimensions( silkBitmap, &silkX, &silkY, NULL ); silkWindow = WinCreateOffscreenWindow( silkX, silkY, screenFormat, &err ); silkWindowInv = WinCreateOffscreenWindow( silkX, silkY, screenFormat, &err); WinSetDrawWindow( silkWindow ); WinDrawBitmap( silkBitmap, 0, 0 ); WinSetDrawWindow( silkWindowInv ); WinDrawBitmap( silkBitmapInv, 0, 0 ); /* We need to move down the existing silkscreen to make room for our own toolbar's buttons */ if ( currentSilkStatus == HANDERA_SILK_UP ) { RectangleType area; UInt16 moveY; area.topLeft.x = 40; area.topLeft.y = 1; area.extent.x = 200; area.extent.y = 18; moveY = 14; WinCopyRectangle( silkWindow, silkWindow, &area, area.topLeft.x, moveY, winPaint ); WinCopyRectangle( silkWindowInv, silkWindowInv, &area, area.topLeft.x, moveY, winPaint ); area.extent.y = moveY; WinSetDrawWindow( silkWindow ); WinEraseRectangle( &area, 0 ); WinSetDrawWindow( silkWindowInv ); WinEraseRectangle( &area, 0 ); } currentX = TOOLBAR_START_X; currentY = TOOLBAR_START_Y; for ( i = 0; i < TOTAL_ICONS; i++ ) { MemHandle bitmapH; BitmapPtr bitmap; Coord width; Coord height; if ( iconList[ i ].resourceId == 0 ) { /* This is just a placeholder for our '0' resourced offset image */ width = 22; height = 13; } else { bitmapH = DmGetResource( bitmapRsc, iconList[ i ].resourceId ); bitmap = MemHandleLock( bitmapH ); BmpGlueGetDimensions( bitmap, &width, &height, NULL ); WinSetDrawWindow( silkWindow ); WinDrawBitmap( bitmap, currentX, currentY ); WinSetDrawWindow( silkWindowInv ); WinDrawBitmap( bitmap, currentX, currentY ); MemPtrUnlock( bitmap ); DmReleaseResource( bitmapH ); } iconList[ i ].bounds[ currentSilkStatus ].topLeft.x = currentX; iconList[ i ].bounds[ currentSilkStatus ].topLeft.y = currentY; iconList[ i ].bounds[ currentSilkStatus ].extent.x = width; iconList[ i ].bounds[ currentSilkStatus ].extent.y = height; WinInvertRectangle( &( iconList[ i ].bounds[ currentSilkStatus ]), 0 ); /* Because some icons are meant to appear right beside each other, they're defined here up top. Everything else is spaced so it fits nicely */ switch ( iconList[ i ].resourceId ) { case bmpFind: case bmpAutoscrollDecr: case bmpAutoscrollStop: case bmpLeft: case bmpHome: currentX += width; break; default: currentX += width; if ( currentSilkStatus == HANDERA_SILK_UP ) currentX += 3; else if ( currentSilkStatus == HANDERA_SILK_DOWN ) currentX += 7; break; } } WinSetDrawWindow( origWindow ); silkBitmap = WinGetBitmap( silkWindow ); silkBitmapInv = WinGetBitmap( silkWindowInv ); if ( currentSilkStatus == HANDERA_SILK_UP ) SilkSetTemplateBitmaps( silkBitmap, silkBitmapInv, NULL, NULL ); else SilkSetTemplateBitmaps( NULL, NULL, silkBitmap, silkBitmapInv ); WinDeleteWindow( silkWindow, false ); WinDeleteWindow( silkWindowInv, false ); }
void CGameForm::OnDraw() { played_cards.Render(true); player_hand.Render(true); char bid_trump_str[2]; StrPrintF(bid_trump_str, "%d", gManager->tbl->bid ); FormPtr frmP = FrmGetActiveForm(); /* RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex( frmP, MainBidTrumpGadget ); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); // draw the bid char bidval = bid_trump_str[0]; WinPaintChar( bidval, bounds.topLeft.x, bounds.topLeft.y ); Card foo(gManager->trk->getTrump(), (Card::face_t)1 ); // now, draw the suit MemHandle hRsc = DmGetResource(bitmapRsc, foo.SuitBitmap(false) ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); BitmapType* bitmapP = (BitmapType*) MemHandleLock(hRsc); WinPaintBitmap (bitmapP, bounds.topLeft.x + 6, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); */ // handle MainBidTrumpGadget here also MemHandle hRsc; BitmapType* bitmapP; switch ( gManager->tbl->trump ) { case Card::heart: hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily ); break; case Card::diamond: hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily ); break; case Card::club: hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily ); break; case Card::spade: hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily ); break; } RectangleType bounds; // FormPtr frmP = FrmGetActiveForm(); UInt16 gadgetIndex = FrmGetObjectIndex(frmP, MainBidTrumpGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); char bidstr[4]; StrPrintF(bidstr, "%d", gManager->tbl->bid); WinPaintChar(bidstr[0], bounds.topLeft.x, bounds.topLeft.y ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); bitmapP = (BitmapType*) MemHandleLock(hRsc); WinDrawBitmap (bitmapP, bounds.topLeft.x + FntCharWidth(bidstr[0]) + 1, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); }
/* Find pattern in text string */ static Boolean DoSearch ( Char* text, /* text string */ UInt16 size, /* size of text */ Char* pattern, /* pattern to search for */ UInt8 matchMode, /* indicates if the search should be case-sensitive or not */ UInt16 xlitMode, /* how should we transliterate? */ UInt16* pos, /* start position, will contain the position of the pattern if found */ UInt16* endFound, /* end of position where pattern is found */ Int16 depth /* depth of this page */ ) { Int16 startPos; Int16 charsize; Int16 topcharsize; UInt16 patternLen; UInt16 wplen; Int16 i; Int16 j; Int16 top; WChar ch; WChar wpattern[ 2 * ( MAX_PATTERN_LEN+1 ) ]; Boolean guaranteed8Bits; #ifdef BUILD_ARMLETS Boolean useArmlet; void* DoSearchArmlet; ArmSearchType armData; MemHandle armChunkH = NULL; #endif static UInt8 lastMatchMode = SEARCH_UNINITIALIZED; static UInt16 lastXlitMode = 0; static Char xlat[ 256 ]; static Boolean multibyteCharFix; static WChar multibyteCharFixTo; #ifdef SUPPORT_TRANSLITERATION static Boolean symmetricXlit; #endif multibyteCharFix = false; if ( lastMatchMode != matchMode || xlitMode != lastXlitMode ) { #ifdef SUPPORT_TRANSLITERATION symmetricXlit = SetTransliteration( xlitMode, xlat, &multibyteCharFix, &multibyteCharFixTo ); #else for ( i = 0 ; i < 256 ; i++ ) { xlat[ i ] = i; } #endif if ( ! ( matchMode & SEARCH_CASESENSITIVE ) ) { for ( i = 0; i < 256; i++ ) xlat[ i ] = TxtGlueLowerChar( ( UInt8 )xlat[ i ] ); } lastMatchMode = matchMode; } startPos = *pos; charsize = 1; patternLen = StrLen( pattern ); /* expand wchar string in advance*/ i = wplen = 0; while ( i < patternLen ) { charsize = TxtGlueGetNextChar( pattern, i, &ch ); if ( charsize == 1 ) { #ifdef SUPPORT_TRANSLITERATION if ( symmetricXlit ) { #endif ch = xlat[ (UInt8) ch ]; #ifdef SUPPORT_TRANSLITERATION } else if ( ! ( matchMode & SEARCH_CASESENSITIVE ) ) { ch = TxtGlueLowerChar( (UInt8) ch ); } #endif } else if ( multibyteCharFix ) ch = multibyteCharFixTo; wpattern[ wplen ] = ch; i += charsize; wplen += 1; } guaranteed8Bits = DeviceUses8BitChars(); #ifdef BUILD_ARMLETS useArmlet = false; DoSearchArmlet = NULL; if ( SupportArmlets() && guaranteed8Bits ) { armChunkH = DmGetResource( ArmletResourceType, armDoSearch ); if ( armChunkH != NULL ) { DoSearchArmlet = MemHandleLock( armChunkH ); armData.size = size; armData.depth = depth; armData.text = text; armData.wpattern = wpattern; armData.wplen = wplen; armData.xlat = xlat; useArmlet = true; } } #endif i = top = *pos; j = 0; topcharsize = 0; while ( j < wplen && i < size ) { #ifdef BUILD_ARMLETS if ( useArmlet ) { armData.i = i; armData.j = j; armData.top = top; ch = (WChar) PceNativeCall( DoSearchArmlet, &armData ); i = armData.i; j = armData.j; top = armData.top; if ( wplen <= j || size <= i ) break; charsize = topcharsize = 1; } else #endif if ( guaranteed8Bits ) { ch = DoSearch8BitText( text, size, wpattern, wplen, xlat, &i, &j, &top, 0 < depth ); if ( wplen <= j || size <= i ) break; charsize = topcharsize = 1; } else charsize = TxtGlueGetNextChar( text, i, &ch ); if ( j == 0 ) topcharsize = charsize; if ( ch == '\0' ) { if ( 0 < depth ) { /* if function is anchor, store it to queue */ if ( text[ i + 1 ] == 0x0A /* ANCHOR_START */ ){ UInt16 reference; Int16 q; Int16 listSize; reference = 256 * (UInt8)text[ i + 2 ] + (UInt8)text[ i + 3 ]; listSize = ListSize( searchQueue ); for ( q = 0; q < listSize; q ++ ){ /*look up in queue, append if not exist*/ QueueNode *node; node = ListGet( searchQueue, q + 1 ); if ( node->reference == reference ) break; } if ( q == listSize ) AddReference( reference, depth ); } } i += 2 + ( text[ i + 1 ] & 0x07 ); top = i; j = 0; continue; } if ( charsize == 1 ) ch = xlat[ (UInt8) ch ]; else if ( multibyteCharFix ) ch = multibyteCharFixTo; if ( ch != wpattern[ j ] ) { top += topcharsize; i = top; j = 0; continue; } i += charsize; j += 1; } #ifdef BUILD_ARMLETS if ( armChunkH != NULL ) { MemHandleUnlock( armChunkH ); DmReleaseResource( armChunkH ); } #endif if ( j == wplen ) { *pos = top; *endFound = i; return true; } else { return false; } }