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); } }