menu.c

Go to the documentation of this file.
00001 
00002 /*  $Id: menu.c 1201 2006-04-05 22:31:38Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #ifdef WIN95VERSION
00032     #include "font.h"
00033 #endif
00034 
00035 #include "cursor.h"
00036 #include "error.h"
00037 #include "menu.h"
00038 #include "memory.h"
00039 #include "strings.h"
00040 #include "threads.h"
00041 
00042 
00043 #define idtempmenu 3000 /*use this ID to create a temporary menu*/
00044 
00045 
00046 static boolean isseparatorstring (bigstring bs) {
00047 
00048     byte bsseparator [4];
00049     
00050     setstringwithchar ('-', bsseparator);
00051 
00052     return (equalstrings (bs, STR_menuseparator) || equalstrings (bs, bsseparator));
00053     } /*isseparatorstring*/
00054 
00055 
00056 #ifdef WIN95VERSION
00057 
00058 extern HWND shellframewindow;
00059 extern HINSTANCE shellinstance;
00060 extern HANDLE hAccel; /*FrontierWinMain.c*/
00061 static Handle haccelerators = NULL;
00062 
00063 
00064 static void updateaccelerators (void) {
00065     
00066     HANDLE newAccel;
00067     long ctaccelerators = gethandlesize (haccelerators) / sizeof (ACCEL); 
00068 
00069     newAccel = CreateAcceleratorTable ((LPACCEL) *haccelerators, ctaccelerators);
00070     
00071     if (newAccel != NULL) {
00072 
00073         DestroyAcceleratorTable (hAccel);
00074 
00075         hAccel = newAccel;
00076         }
00077     } /*updateaccelerators*/
00078 
00079 
00080 static void removeaccelerators (long idmenu, short ixstart) {
00081     
00082     /*
00083     remove all accelerators to items in the indicated menu.
00084     */
00085 
00086     int ctaccelerators;
00087     int i;
00088     
00089     ctaccelerators = gethandlesize (haccelerators) / sizeof (ACCEL); 
00090     
00091     for (i = ctaccelerators; --i >= 0; ) {
00092         
00093         if (((LPACCEL) *haccelerators) [i].cmd / 100 * 100 == idmenu) {
00094             
00095             if (((LPACCEL) *haccelerators) [i].cmd % 100 >= ixstart)
00096                 pullfromhandle (haccelerators, i * sizeof (ACCEL), sizeof (ACCEL), NULL);
00097             }
00098         }
00099     } /*removeaccelerators*/
00100 
00101 
00102 static boolean findaccelerator (long id, short *ixaccel) {
00103     
00104     short ctaccelerators;
00105     short i;
00106 
00107     // search for a existing accelerator
00108     ctaccelerators = (short) gethandlesize (haccelerators) / sizeof (ACCEL); 
00109     
00110     for (i = 0; i < ctaccelerators; ++i) {
00111         
00112         if (((LPACCEL) *haccelerators) [i].cmd == id) {
00113             
00114             *ixaccel = i;
00115 
00116             return (true);
00117             }
00118         }
00119 
00120     return (false);
00121     } /*findaccelerator*/
00122 
00123 
00124 static void setupaccelrecord (short key, long cmd, ACCEL *accel) {
00125 
00126     UINT virtcode = VkKeyScan ((TCHAR) key);
00127 
00128     if (virtcode == -1) { // didn't map to a virtual key
00129         
00130         (*accel).fVirt = FCONTROL;
00131 
00132         (*accel).key = getlower (key);
00133         }
00134     else {
00135         (*accel).fVirt = FCONTROL | FVIRTKEY;
00136         
00137         (*accel).key = virtcode & (0x00FF);
00138         }
00139     
00140     (*accel).cmd = (WORD) cmd;
00141     } /*setupaccelrecord*/
00142 
00143 
00144 static boolean insertaccelerator (const ACCEL *accel) {
00145     
00146     /*
00147     5.0a25 dmb: insert at beginning of table, and insert 
00148     two copies, the second with the shift key
00149     */
00150     
00151     ACCEL ac [2];
00152     
00153     ac [0] = *accel;
00154     
00155     ac [1] = *accel;
00156     
00157     ac [1].fVirt |= FSHIFT;
00158     
00159     return (insertinhandle (haccelerators, 0, ac, 2 * sizeof (ACCEL)));
00160     } /*insertaccelrecord*/
00161 
00162 
00163 static boolean pushvirtkeystring (UINT virtcode, bigstring bs, boolean flpushplus) {
00164     
00165     char keybuf [32];
00166     UINT scancode;
00167     
00168     scancode = MapVirtualKey (virtcode, 0);
00169     
00170     GetKeyNameText (scancode << 16, keybuf, 32L);
00171     
00172     convertcstring (keybuf);
00173     
00174     if (isemptystring (keybuf))
00175         return (false);
00176 
00177     pushstring (keybuf, bs);
00178 
00179     if (flpushplus)
00180         pushchar ('+', bs);
00181 
00182     return (true);
00183     } /*pushvirtkeystring*/
00184 
00185 
00186 static void pushaccelstring (ACCEL *ac, bigstring bs) {
00187     
00188     /*
00189     5.0a18 dmb: pull out this code now, for future enhancement. 
00190     someday, we might offer non-Control keys. Plus, we should use
00191     the system to get the string for the keystroke.
00192     */
00193 
00194     nthword (bs, 1, chtab, bs);
00195 
00196     if ((*ac).key > 0) {
00197         
00198         pushchar (chtab, bs);
00199         
00200         if ((*ac).fVirt & FCONTROL)
00201             pushvirtkeystring (VK_CONTROL, bs, true);
00202         
00203         if ((*ac).fVirt & FALT)
00204             pushvirtkeystring (VK_MENU, bs, true);
00205         
00206         if ((*ac).fVirt & FSHIFT)
00207             pushvirtkeystring (VK_SHIFT, bs, true);
00208 
00209         if ((*ac).fVirt & FVIRTKEY)
00210             pushvirtkeystring ((*ac).key, bs, false);
00211         else
00212             pushchar ((byte) (*ac).key, bs);
00213         }
00214     } /*pushaccelstring*/
00215 
00216 
00217 static boolean addaccelerators (hdlmenu hmenu, long idmenu, short ixstart) {
00218     
00219     ACCEL accel;
00220     short i, ctitems;
00221     MENUITEMINFO info;
00222     bigstring menuname;
00223     short ixaccel;
00224     
00225     info.cbSize = sizeof (info);
00226     info.fMask = MIIM_TYPE;
00227     
00228     ctitems = GetMenuItemCount (hmenu);
00229     
00230     for (i = ixstart - 1; i < ctitems; ++i) {
00231         
00232         info.dwTypeData = &menuname[0];
00233         info.cch = 128;
00234 
00235         GetMenuItemInfo (hmenu, i, true, &info);
00236         
00237         if (info.cch == 0)
00238             continue;
00239         
00240         convertcstring (menuname);
00241         
00242         if (stringfindchar (chtab, menuname)) {
00243             
00244             // add new item to the accelerator table
00245             setupaccelrecord ((short) lastchar (menuname), idmenu + i + 1, &accel);
00246             
00247             if (!findaccelerator (accel.cmd, &ixaccel)) {
00248 
00249                 if (!insertaccelerator (&accel))
00250                     return (false);
00251                 }
00252             }
00253         }
00254     
00255     updateaccelerators ();
00256     
00257     return (true);
00258     } /*addaccelerators*/
00259 
00260 
00261 boolean adjustitemcommands (hdlmenu hmenu, long idmenu, short ixmenu) {
00262     
00263     /*
00264     an item has been inserted or deleted from the menu. we must 
00265     adjust the command id for the following items to match thier
00266     new index in the menu.
00267 
00268     hmenu is the actual pulldown or popup, not the parent menu
00269 
00270     5.0b15 dmb: "ixmenu" is 1-based
00271     */
00272     
00273     MENUITEMINFO info;
00274     short ix, ctitems;
00275     
00276     info.cbSize = sizeof (info);
00277     info.fMask = MIIM_ID;
00278     
00279     ctitems = GetMenuItemCount (hmenu);
00280     
00281     for (ix = ixmenu - 1; ix < ctitems; ++ix) {
00282         
00283         info.wID = idmenu + ix + 1;
00284         
00285         SetMenuItemInfo (hmenu, ix, true, &info); // get the actual popup and it's id
00286         }
00287 
00288     return (true);
00289     } /*adjustitemcommands*/
00290 
00291 #endif
00292 
00293 boolean getcommandkeystring (byte chkey, tykeyflags keyflags, bigstring bscmdkey) {
00294     
00295     #ifdef MACVERSION
00296         setemptystring (bscmdkey);
00297     
00298         if (keyflags & keycommand)
00299             pushstring ("\pCmd-", bscmdkey);
00300         
00301         if (keyflags & keyshift)
00302             pushstring ("\pShift-", bscmdkey);
00303         
00304         if (keyflags & keyoption)
00305             pushstring ("\pOption-", bscmdkey);
00306         
00307         if (chkey != chnul)
00308             pushchar (chkey, bscmdkey);
00309     #endif
00310     
00311     #ifdef WIN95VERSION
00312         ACCEL ac;
00313         
00314         setemptystring (bscmdkey);
00315         
00316         ac.fVirt = 0;
00317         
00318         if (keyflags & keycommand)
00319             ac.fVirt |= FCONTROL;
00320         
00321         if (keyflags & keyoption)
00322             ac.fVirt |= FALT;
00323         
00324         if (keyflags & keyshift)
00325             ac.fVirt |= FSHIFT;
00326         
00327         ac.key = chkey;
00328         
00329         pushaccelstring (&ac, bscmdkey);
00330         
00331         popleadingchars (bscmdkey, chtab);
00332     #endif
00333     
00334     return  (true);
00335     } /*getcommandkeystring*/
00336 
00337 
00338 void drawmenubar (void) {
00339     
00340     #ifdef MACVERSION
00341         DrawMenuBar ();
00342     #endif
00343 
00344     #ifdef WIN95VERSION
00345         releasethreadglobals ();
00346         
00347         DrawMenuBar (shellframewindow);
00348         
00349         grabthreadglobals ();
00350     #endif
00351     } /*drawmenubar*/
00352 
00353 
00354 hdlmenu getresourcemenu (short id) {
00355 
00356     #ifdef MACVERSION
00357     
00358         /*Code change by Timothy Paustian Saturday, July 22, 2000 10:26:47 PM
00359         /code to conditionalize the quit menu.*/
00360         
00361         #if TARGET_API_MAC_CARBON == 1
00362         
00363             if (id == 2 || id == 4) { /*PBS 7.1b5: conditionalize Window menu also*/
00364             
00365             /*we are loading the file menu.
00366             check to see if we are in OS X if so change the id
00367             of the file menu*/
00368             
00369                 SInt32  result;
00370                 
00371                 Gestalt (gestaltMenuMgrAttr, &result);
00372                 
00373                 if (result & gestaltMenuMgrAquaLayoutMask) {
00374                     
00375                     if (id == 2) /*File menu*/
00376                         id = 412;
00377                         
00378                     if (id == 4) /*Window menu*/
00379                         id = 413;
00380                     } /*if*/
00381             } /*if*/
00382             
00383         #endif
00384         
00385         return (GetMenu (id));
00386         
00387     #endif
00388 
00389     #ifdef WIN95VERSION
00390         hdlmenu hmenu;
00391         MENUITEMINFO info;
00392         
00393         hmenu = LoadMenu (shellinstance, MAKEINTRESOURCE (id));
00394         
00395         // set the id of the actual popup to match its resource id
00396         info.cbSize = sizeof (info);
00397         info.fMask = MIIM_ID;
00398         info.wID = id;
00399         
00400         SetMenuItemInfo (hmenu, 0, true, &info);
00401         
00402         return (hmenu);
00403     #endif
00404     } /*getresourcemenu*/
00405 
00406 //Code change by Timothy Paustian Saturday, April 29, 2000 9:33:29 PM
00407 //Changed for UH 3.3.1 to avoid conflict with Menus.h
00408 hdlmenu Newmenu (short idmenu, bigstring bstitle) {
00409 
00410     /*
00411     4.18.97 dmb: for win95, we must actually create a parent menu with 
00412     a single item that is the actual (pulldown or popup) popup menu that
00413     we will be using. this accomplishes two things:
00414 
00415     1. it matches the structure of getresourcemenu, which actually returns 
00416     a menubar
00417 
00418     2. it gives us a place to maintain the name and command number of the 
00419     new menu -- in the item info for the parent's 0th (and only) item
00420 
00421     All other entrypoints in this file must account for this two-tiered 
00422     structure.
00423     */
00424 
00425     #ifdef MACVERSION
00426         return (NewMenu (idmenu, bstitle));
00427     #endif
00428 
00429     #ifdef WIN95VERSION
00430         hdlmenu hparent = CreateMenu ();
00431 
00432         if (hparent != NULL) {
00433 
00434             MENUITEMINFO info;
00435             char menuname [256];
00436 
00437 
00438             info.cbSize = sizeof (info);
00439             info.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_ID;
00440 
00441             info.fType = MFT_STRING;
00442             info.dwTypeData = menuname;
00443             copyptocstring (bstitle, menuname);
00444 
00445             info.hSubMenu = CreatePopupMenu ();
00446             
00447             info.wID = idmenu;
00448             
00449             if (!InsertMenuItem (hparent, 0, true, &info)) {
00450                 
00451                 DestroyMenu (info.hSubMenu);
00452 
00453                 DestroyMenu (hparent);
00454 
00455                 return (NULL);
00456                 }
00457             }
00458         
00459         return (hparent);
00460     #endif
00461     } /*newmenu*/
00462 
00463 
00464 void disposemenu (hdlmenu hmenu) {
00465     
00466     /*
00467     4.18.97 dmb: for win95, mirror logic of newmenu
00468     */
00469 
00470     #ifdef MACVERSION
00471         DisposeMenu (hmenu);
00472     #endif
00473 
00474     #ifdef WIN95VERSION
00475         DeleteMenu (hmenu, 0, MF_BYPOSITION); // destroy the actual menu
00476         
00477         DestroyMenu (hmenu); // destroy the menu holder
00478     #endif
00479     } /*disposemenu*/
00480 
00481 
00482 hdlmenu getmenuhandle (short id) {
00483 
00484     #ifdef MACVERSION
00485         return (GetMenuHandle (id));
00486     #endif
00487 
00488     #ifdef WIN95VERSION
00489         MENUITEMINFO info;
00490         HMENU menubar = GetMenu (shellframewindow);
00491         
00492         info.cbSize = sizeof (info);
00493         info.fMask = MIIM_SUBMENU; 
00494         
00495         GetMenuItemInfo (menubar, id, false, &info);
00496 
00497         return (info.hSubMenu);
00498     #endif
00499     } /*getmenuhandle*/
00500 
00501 
00502 boolean insertmenu (hdlmenu hmenu, long idbefore) {
00503     
00504     #ifdef MACVERSION
00505         if (idbefore == insertatend)
00506             idbefore = 0;
00507         
00508         InsertMenu (hmenu, idbefore);
00509 
00510         return (true);
00511     #endif
00512 
00513     #ifdef WIN95VERSION
00514         MENUITEMINFO info;
00515         HMENU menubar = GetMenu (shellframewindow);
00516         char menuname[128];
00517         boolean fl;
00518         DWORD err;
00519 
00520         if (idbefore == insertsubmenu) // under windows, hierarchicals aren't inserted into the menubar
00521             return (true);
00522 
00523         info.cbSize = sizeof (info);
00524         info.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_ID;
00525         info.dwTypeData = menuname;
00526         info.cch = 128;
00527         
00528         GetMenuItemInfo (hmenu, 0, true, &info); // get the actual popup and all of it's info
00529         
00530         addaccelerators (info.hSubMenu, info.wID, 1);
00531         
00532         if (idbefore == insertatend) {
00533             
00534             fl = InsertMenuItem (menubar, 99, true, &info);
00535         //  fl = AppendMenu (menubar, MF_POPUP, (UINT)info.hSubMenu, info.dwTypeData);
00536             }
00537         else {
00538         
00539             fl = InsertMenuItem (menubar, idbefore, false, &info);
00540             }
00541         
00542         if (!fl)
00543             err = GetLastError();
00544 
00545     //  drawmenubar ();
00546 
00547         return (fl);
00548     #endif
00549     } /*insertmenu*/
00550 
00551 
00552 boolean inserthierarchicmenu (hdlmenu hmenu, short idmenu) {
00553 #ifdef MACVERSION
00554 #   pragma unused (idmenu)
00555 
00556     InsertMenu (hmenu, insertsubmenu);
00557 
00558     return (true);
00559 #endif
00560 
00561     #ifdef WIN95VERSION
00562         HMENU menubar = GetMenu (shellframewindow);
00563         MENUITEMINFO info;
00564         
00565     //  hmenu = GetSubMenu (hmenu, 0); // get actual popup
00566         info.cbSize = sizeof (info);
00567         info.fMask = MIIM_SUBMENU | MIIM_ID;
00568         
00569         GetMenuItemInfo (hmenu, 0, true, &info); // get the actual popup and all of it's info
00570         
00571         addaccelerators (info.hSubMenu, info.wID, 1);
00572 
00573     //  info.fMask = MIIM_SUBMENU; 
00574         
00575         return (SetMenuItemInfo (menubar, idmenu, false, &info));
00576     #endif
00577     } /*inserthierarchicmenu*/
00578 
00579 
00580 void removemenu (short idmenu) {
00581     
00582     #ifdef MACVERSION
00583         DeleteMenu (idmenu); // (**hmenu).menuID
00584     #endif
00585 
00586     #ifdef WIN95VERSION
00587         HMENU menubar = GetMenu (shellframewindow);
00588         
00589         removeaccelerators (idmenu, 1);
00590         
00591         RemoveMenu (menubar, idmenu, MF_BYCOMMAND);
00592         
00593         updateaccelerators ();
00594     #endif
00595     } /*removemenu*/
00596 
00597 
00598 #if defined(MACVERSION) && !flruntime
00599 
00600 long trackmenu (Point mousept) {
00601     
00602     /*
00603     11/20/91 dmb: track the user's menu selection.  return the result 
00604     encoded in the high and low words of the long result.
00605     
00606     if no valid item is selected, but the mouse was released over a 
00607     disabled item (possibly the parent of a hierarchical menu), return 
00608     the negative of the item value (encoded as usual w/the menu id)
00609     */
00610     
00611     long menucode;
00612     short menu;
00613     short item;
00614     //Code change by Timothy Paustian Tuesday, August 29, 2000 1:32:04 PM
00615     //No using direct trap address in OS X or carbon. Use the MenuChoice 
00616     //routine, that's what it is for.
00617     //#define MenuDisable (*(long *)0x0B54)
00618     
00619     menucode = MenuSelect (mousept);
00620     
00621     item = LoWord (menucode);
00622     
00623     if (item == 0) { /*no enable item selected*/
00624         
00625         //old code
00626         //menucode = MenuDisable; 
00627         //new code, why was the old stuff left in?
00628         menucode = MenuChoice ();
00629         
00630         item = -LoWord (menucode);
00631         }
00632     
00633     menu = HiWord (menucode);
00634     
00635     return ((long) menu << 16) + (unsigned short) item;
00636     } /*trackmenu*/
00637 
00638 #endif
00639 
00640 boolean sethierarchicalmenuitem (hdlmenu hmenu, short itemnumber, hdlmenu hsubmenu, short idsubmenu) {
00641 
00642     #ifdef MACVERSION
00643         #pragma unused (hsubmenu)   
00644         short cmdchar, markchar;
00645 
00646         if (hsubmenu != nil) {
00647 
00648             cmdchar = hMenuCmd; /*$1B*/
00649             
00650             markchar = idsubmenu;
00651             }
00652         else {
00653             
00654             cmdchar = noMark;
00655             
00656             markchar = 0;
00657             }
00658         
00659         SetItemCmd (hmenu, itemnumber, cmdchar);
00660 
00661         SetItemMark (hmenu, itemnumber, markchar);
00662         
00663         return (true);
00664     #endif
00665 
00666     #ifdef WIN95VERSION
00667 
00668         MENUITEMINFO info;
00669         
00670         info.cbSize = sizeof (info);
00671         info.fMask = MIIM_SUBMENU; 
00672         info.hSubMenu = GetSubMenu (hsubmenu, 0); // get actual submenu
00673         
00674         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00675 
00676         return (SetMenuItemInfo (hmenu, itemnumber - 1, true, &info));
00677     #endif
00678     } /*sethierarchicalmenuitem*/
00679 
00680 
00681 boolean gethierarchicalmenuitem (hdlmenu hmenu, short ixmenu, hdlmenu *hsubmenu) {
00682 
00683     #ifdef MACVERSION
00684         
00685         short cmdchar;
00686         short idsub;
00687         
00688         GetItemCmd (hmenu, ixmenu, &cmdchar);
00689         
00690         if (cmdchar == hMenuCmd) {
00691             
00692             GetItemMark (hmenu, ixmenu, &idsub);
00693             
00694             *hsubmenu = GetMenuHandle (idsub);
00695             }
00696     #endif
00697 
00698     #ifdef WIN95VERSION
00699 
00700         MENUITEMINFO info;
00701         
00702         info.cbSize = sizeof (info);
00703         info.fMask = MIIM_SUBMENU; 
00704         
00705         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00706 
00707         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
00708 
00709         *hsubmenu = info.hSubMenu;
00710 
00711     #endif
00712 
00713     return (*hsubmenu != NULL);
00714     } /*gethierarchicalmenuitem*/
00715 
00716 
00717 void setmenutitleenable (hdlmenu hmenu, short idmenu, boolean fl) {
00718 #if MACVERSION
00719 #   pragma unused (idmenu)
00720 #endif
00721     /*
00722     enable or disable a menu or a menu item.  if fl is true we enable the item,
00723     if false we disable it.
00724     
00725     if item == 0 we enable or disable the entire menu.
00726     
00727     dmb 8/1/90:  check for dummy items (negative item numbers)
00728     */
00729     //Code change by Timothy Paustian Friday, June 9, 2000 9:44:07 PM
00730     //Changed to Modern calls for Enabling and Disabling menu items
00731 #ifdef MACVERSION
00732     if (fl) {
00733 #   if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00734         EnableMenuItem (hmenu, 0);
00735 #   else
00736         EnableItem (hmenu, 0);
00737 #   endif
00738     } else {
00739 #   if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00740         DisableMenuItem (hmenu, 0);
00741 #   else
00742         DisableItem (hmenu, 0);
00743 #   endif
00744     }
00745 #endif
00746 
00747 #ifdef WIN95VERSION
00748     HMENU menubar = GetMenu (shellframewindow);
00749 
00750     assert (idmenu >= 0);
00751 
00752         EnableMenuItem (menubar, idmenu, MF_BYCOMMAND | (fl? MF_ENABLED : MF_DISABLED));
00753 #endif
00754     } /*setmenutitleenable*/
00755     
00756     
00757 void setmenuitemenable (hdlmenu hmenu, short item, boolean fl) {
00758     
00759     /*
00760     enable or disable a menu or a menu item.  if fl is true we enable the item,
00761     if false we disable it.
00762     
00763     if item == 0 we enable or disable the entire menu.
00764     
00765     dmb 8/1/90:  check for dummy items (negative item numbers)
00766     */
00767     
00768     #ifdef MACVERSION
00769         if (item < 0) /*this item has been dummied out -- do nothing*/
00770             return;
00771         //Code change by Timothy Paustian Monday, May 1, 2000 9:10:06 PM
00772         //Changed to Opaque call for Carbon
00773         //updated the call from EnableItem and DisableItem
00774         if (fl)
00775             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00776             EnableMenuItem (hmenu, item);
00777             #else
00778             EnableItem(hmenu,item);
00779             #endif
00780         else
00781             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00782             DisableMenuItem (hmenu, item);
00783             #else
00784             DisableItem(hmenu,item);
00785             #endif
00786     #endif
00787 
00788     #ifdef WIN95VERSION
00789         if (item < 0) /*this item has been dummied out -- do nothing*/
00790             return;
00791         
00792         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00793 
00794         EnableMenuItem (hmenu, item - 1, MF_BYPOSITION | (fl? MF_ENABLED : MF_GRAYED));
00795     #endif
00796     } /*setmenuitemenable*/
00797     
00798     
00799 boolean getmenutitleenable (hdlmenu hmenu, short idmenu) {
00800     
00801     /*
00802     */
00803     
00804 #ifdef MACVERSION
00805 #   pragma unused (idmenu)
00806 #   if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00807 
00808     return IsMenuItemEnabled(hmenu, 0);
00809 
00810 #   else
00811 
00812     //old code
00813     return (((**hmenu).enableFlags & (0x01)) != 0);
00814 
00815 #   endif
00816 #endif
00817 
00818     #ifdef WIN95VERSION
00819         MENUITEMINFO info;
00820         HMENU menubar = GetMenu (shellframewindow);
00821         
00822         info.cbSize = sizeof (info);
00823         info.fMask = MIIM_STATE; 
00824 
00825         GetMenuItemInfo (menubar, idmenu, false, &info);
00826 
00827         return ((info.fState | MFS_ENABLED) != 0);
00828     #endif
00829     } /*getmenuitemenable*/
00830     
00831     
00832 boolean getmenuitemenable (hdlmenu hmenu, short item) {
00833     
00834     #ifdef MACVERSION
00835         assert (item >= 0);
00836         //Code change by Timothy Paustian Monday, May 1, 2000 9:16:32 PM
00837         //Changed to Opaque call for Carbon
00838         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00839         return IsMenuItemEnabled(hmenu, item);
00840         #else
00841         //old code
00842         return (((**hmenu).enableFlags & (0x01 << item)) != 0);
00843         #endif
00844     #endif
00845 
00846     #ifdef WIN95VERSION
00847         MENUITEMINFO info;
00848         
00849         info.cbSize = sizeof (info);
00850         info.fMask = MIIM_STATE; 
00851 
00852         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00853 
00854         GetMenuItemInfo (hmenu, item - 1, true, &info);
00855 
00856         return ((info.fState | MFS_ENABLED) != 0);
00857     #endif
00858     } /*getmenuitemenable*/
00859     
00860     
00861 void disablemenuitem (hdlmenu hmenu, short item) {
00862     
00863     setmenuitemenable (hmenu, item, false);
00864     } /*disablemenuitem*/
00865 
00866 void enablemenuitem (hdlmenu hmenu, short item) {
00867     
00868     setmenuitemenable (hmenu, item, true);
00869     } /*enablemenuitem*/
00870 
00871 
00872 short countmenuitems (hdlmenu hmenu) {
00873     
00874     #ifdef MACVERSION
00875         return (CountMenuItems (hmenu));
00876     #endif
00877 
00878     #ifdef WIN95VERSION
00879         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00880 
00881         return (GetMenuItemCount (hmenu));
00882     #endif
00883     } /*countmenuitems*/
00884 
00885 
00886 void enableallmenuitems (hdlmenu hmenu, boolean fl) {
00887     
00888     register short lastitem;
00889     register short i;
00890     
00891     lastitem = countmenuitems (hmenu);
00892     
00893     for (i = 1; i <= lastitem; i++) 
00894         setmenuitemenable (hmenu, i, fl);
00895     } /*enableallmenuitems*/
00896     
00897 
00898 void hilitemenu (short id) {
00899 
00900     #ifdef MACVERSION
00901         HiliteMenu (id);
00902     #endif
00903     } /*hilitemenu*/
00904 
00905 
00906 void checkmenuitem (hdlmenu hmenu, short ixmenu, boolean fl) {
00907     
00908     /*
00909     5.0a23 dmb: preserve other fState bits [Win]
00910     */
00911     
00912     #ifdef MACVERSION
00913         //Code change by Timothy Paustian Friday, June 9, 2000 9:44:37 PM
00914         //Changed to Modern call.
00915         CheckMenuItem (hmenu, ixmenu, fl);
00916     #endif
00917 
00918     #ifdef WIN95VERSION
00919         MENUITEMINFO info;
00920         
00921         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00922 
00923         info.cbSize = sizeof (info);
00924         info.fMask = MIIM_STATE;
00925 
00926         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
00927         
00928         if (fl)
00929             info.fState |= MFS_CHECKED;
00930         else
00931             info.fState &= ~MFS_CHECKED;
00932 
00933         SetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
00934     #endif
00935     } /*checkmenuitem*/
00936     
00937     
00938 boolean menuitemmarked (hdlmenu hmenu, short ixmenu) {
00939     
00940     #ifdef MACVERSION
00941         short mark = 0;
00942         
00943         GetItemMark (hmenu, ixmenu, &mark);
00944         
00945         return (mark != 0);
00946     #endif
00947 
00948     #ifdef WIN95VERSION
00949         MENUITEMINFO info;
00950         
00951         info.cbSize = sizeof (info);
00952         info.fMask = MIIM_STATE; 
00953         
00954         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00955 
00956         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
00957 
00958         return ((info.fState & MFS_CHECKED) != 0);
00959 
00960     #endif
00961     } /*menuitemmarked*/
00962 
00963 
00964 void markmenuitem (hdlmenu hmenu, short ixmenu, short mark) {
00965     
00966     #ifdef MACVERSION
00967 
00968         /*
00969         5.0a23 dmb: preserve other fState bits [Win]
00970         */
00971 
00972         SetItemMark (hmenu, ixmenu, mark);
00973     #endif
00974 
00975     #ifdef WIN95VERSION
00976         MENUITEMINFO info;
00977         
00978         hmenu = GetSubMenu (hmenu, 0); // get actual popup
00979 
00980         info.cbSize = sizeof (info);
00981         info.fMask = MIIM_STATE;
00982 
00983         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
00984         
00985         if (mark)
00986             info.fState |= MFS_CHECKED;
00987         else
00988             info.fState &= ~MFS_CHECKED;
00989 
00990         // *** need to set hbmpChecked for non-checkmarks
00991         
00992         SetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
00993     #endif
00994     } /*markmenuitem*/
00995 
00996 
00997 void stylemenuitem (hdlmenu hmenu, short ixmenu, short style) {
00998     
00999     #ifdef MACVERSION
01000         SetItemStyle (hmenu, ixmenu, style);
01001     #endif
01002 
01003     #ifdef WIN95VERSION
01004         
01005     #endif
01006     } /*stylemenuitem*/
01007     
01008 
01009 #ifdef WIN95VERSION
01010 static short matchsubmenu (hdlmenu hmenu, hdlmenu hmatchmenu, hdlmenu * hreturn)
01011     {
01012     short cnt, i, ret;
01013     hdlmenu hm;
01014 
01015     cnt = GetMenuItemCount (hmenu);
01016 
01017     for (i = 0; i< cnt; i++)
01018         {
01019         hm = GetSubMenu (hmenu, i);
01020         if (hm == hmatchmenu)
01021             {
01022             *hreturn = hmenu;
01023             return (i);
01024             }
01025         if (hm != NULL)
01026             {
01027             ret = matchsubmenu (hm, hmatchmenu, hreturn);
01028             if (ret >= 0)
01029                 return (ret);
01030             }
01031         }
01032 
01033     return (-1);
01034     } /*matchsubmenu*/
01035 #endif
01036 
01037     
01038 boolean setmenutitle (hdlmenu hmenu, bigstring bs) {
01039     
01040     #ifdef MACVERSION
01041         SetMenuItemText (hmenu, 0, bs);
01042         
01043         return (true);
01044     #endif
01045 
01046     #ifdef WIN95VERSION
01047         hdlmenu mainmenu, hreturn;
01048         MENUITEMINFO mi;
01049         short itempos;
01050 
01051         hmenu = GetSubMenu (hmenu, 0); // get actual popup
01052 
01053         mainmenu = GetMenu (shellframewindow);
01054         itempos = matchsubmenu (mainmenu, hmenu, &hreturn);
01055         
01056         if (itempos == -1)
01057             return (false);
01058 
01059         mi.cbSize = sizeof (mi);
01060         mi.fMask = MIIM_ID;
01061 
01062         GetMenuItemInfo (hreturn, itempos, TRUE, &mi);
01063         
01064         ModifyMenu (hreturn, itempos, MF_BYPOSITION | MF_STRING, mi.wID, stringbaseaddress(bs));
01065 
01066         return (true);
01067     #endif
01068     } /*setmenutitle*/
01069 
01070 
01071 static boolean getmenutitle (hdlmenu hmenu, bigstring bs) {
01072     
01073     #ifdef MACVERSION
01074         //Code change by Timothy Paustian Monday, May 1, 2000 9:15:51 PM
01075         //Changed to Opaque call for Carbon
01076         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
01077         Str255  menuTitle;
01078         GetMenuTitle(hmenu, menuTitle);
01079         copystring (menuTitle, bs);
01080         #else
01081         //old code
01082         copystring ((ptrstring) (**hmenu).menuData, bs);
01083         #endif
01084         return (true);
01085     #endif
01086 
01087     #ifdef WIN95VERSION
01088         hdlmenu mainmenu, hreturn;
01089         MENUITEMINFO info;
01090         char menuname[128];
01091         short itempos;
01092 
01093         hmenu = GetSubMenu (hmenu, 0); // get actual popup
01094 
01095         mainmenu = GetMenu (shellframewindow);
01096         itempos = matchsubmenu (mainmenu, hmenu, &hreturn);
01097         
01098         if (itempos == -1)
01099             return (false);
01100         
01101         info.cbSize = sizeof (info);
01102         info.fMask = MIIM_TYPE;
01103         info.dwTypeData = &menuname[0];
01104         info.cch = 128;
01105         
01106         GetMenuItemInfo (hreturn, itempos, TRUE, & info);
01107         
01108         assert (info.fType == MFT_STRING);
01109 
01110         copyctopstring (info.dwTypeData, bs);
01111 
01112         return (true);
01113     #endif
01114     } /*getmenutitle*/
01115 
01116 
01117 boolean setmenuitem (hdlmenu hmenu, short ixmenu, bigstring bs) {
01118     
01119     /*
01120     4/29/91 dmb: check for empty string
01121 
01122     5.0a23 dmb: maintain accelerator string [Win]
01123     */
01124     
01125     #ifdef MACVERSION
01126         if (ixmenu <= 0)
01127             return (false);
01128         
01129         if (isemptystring (bs))
01130             SetMenuItemText (hmenu, ixmenu, "\p ");
01131         else
01132             SetMenuItemText (hmenu, ixmenu, bs);
01133             
01134         return (true);
01135     #endif
01136 
01137     #ifdef WIN95VERSION
01138         MENUITEMINFO info;
01139         char item [256];
01140         short ixaccel = -1;
01141         
01142         if (ixmenu <= 0)
01143             return (false);
01144         
01145         // get the item info
01146         info.cbSize = sizeof (info);
01147         info.fMask = MIIM_TYPE | MIIM_ID;
01148         info.dwTypeData = &item[0];
01149         info.cch = 128;
01150         
01151         hmenu = GetSubMenu (hmenu, 0); // get actual popup
01152         
01153         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
01154         
01155         findaccelerator (info.wID, &ixaccel);
01156         
01157         if (ixaccel >= 0) { //an accelerator exists. modify the new item text accordingly
01158             
01159             ACCEL ac = ((LPACCEL) *haccelerators) [ixaccel];
01160             
01161             pushaccelstring (&ac, bs);
01162             }
01163 
01164         copyptocstring (bs, item);
01165         
01166         if (isseparatorstring (bs))
01167             info.fType = MFT_SEPARATOR;
01168         else {
01169         
01170             info.fType = MFT_STRING;
01171             
01172             info.dwTypeData = item;
01173             }
01174         
01175         return (SetMenuItemInfo (hmenu, ixmenu - 1, true, &info));
01176     #endif
01177     } /*setmenuitem*/
01178 
01179 
01180 boolean getmenuitem (hdlmenu hmenu, short ixmenu, bigstring bs) {
01181     
01182     #ifdef WIN95VERSION
01183         MENUITEMINFO info;
01184         char menuname[128];
01185     #endif
01186 
01187     if (ixmenu < 0)
01188         return (false);
01189     
01190     if (ixmenu == 0)
01191         return (getmenutitle (hmenu, bs));
01192 
01193     #ifdef MACVERSION
01194         GetMenuItemText (hmenu, ixmenu, bs);
01195         
01196         return (true);
01197     #endif
01198 
01199     #ifdef WIN95VERSION
01200         info.cbSize = sizeof (info);
01201         info.fMask = MIIM_TYPE;
01202         info.dwTypeData = &menuname[0];
01203         info.cch = 128;
01204         
01205         hmenu = GetSubMenu (hmenu, 0); // get actual popup
01206 
01207         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
01208         
01209         assert (info.fType == MFT_STRING);
01210 
01211         copyctopstring (info.dwTypeData, bs);
01212 
01213         return (true);
01214     #endif
01215     } /*getmenuitem*/
01216 
01217 
01218 boolean setmenuitemcommandkey (hdlmenu hmenu, short ixmenu, short key) {
01219 
01220 #ifdef MACVERSION
01221     SetItemCmd (hmenu, ixmenu, key);
01222 
01223     return (true);
01224 #endif
01225 
01226 #ifdef WIN95VERSION
01227     MENUITEMINFO info;
01228     char menuname[128];
01229     ACCEL accel;
01230     LPACCEL paccelerators;
01231     short ixaccel = -1;
01232     bigstring bs;
01233 
01234     if (ixmenu < 0)
01235         return (false);
01236     
01237     // get the item info
01238     info.cbSize = sizeof (info);
01239     info.fMask = MIIM_TYPE | MIIM_ID;
01240     info.dwTypeData = &menuname[0];
01241     info.cch = 128;
01242     
01243     hmenu = GetSubMenu (hmenu, 0); // get actual popup
01244     
01245     GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
01246     
01247     if (info.cch == 0)
01248         setemptystring (bs);
01249     else
01250         copyctopstring (info.dwTypeData, bs);
01251     
01252     // set up the accel structure
01253     setupaccelrecord (key, info.wID, &accel);
01254     
01255     // search for a existing accelerator
01256     findaccelerator (info.wID, &ixaccel);
01257 
01258     paccelerators = (LPACCEL) *haccelerators;
01259     
01260     // if it an accelerator exists, change it in place. or remove it
01261     if (ixaccel >= 0) {
01262 
01263         if (paccelerators [ixaccel].key == key)
01264             ; // it isn't changing, we may still need to added accel item text
01265         
01266         else {
01267             
01268             if (key > 0) {  
01269                 // we're setting an accelerator, change it
01270                 paccelerators [ixaccel] = accel;
01271                 
01272                 ++ixaccel;
01273                 
01274                 if (paccelerators [ixaccel].cmd == info.wID) { // 2nd copy, w/shift
01275                     
01276                     paccelerators [ixaccel] = accel;
01277                     
01278                     paccelerators [ixaccel].fVirt |= FSHIFT;
01279                     }
01280                 }
01281             
01282             else {          
01283                 // remove the existing one
01284                 pullfromhandle (haccelerators, ixaccel * sizeof (ACCEL), sizeof (ACCEL), NULL);
01285                 
01286                 if (paccelerators [ixaccel].cmd == info.wID) // 2nd copy, w/shift
01287                     pullfromhandle (haccelerators, ixaccel * sizeof (ACCEL), sizeof (ACCEL), NULL);
01288                 }
01289             }
01290         }
01291     // otherwise, add the new accelerator to the table and the item text
01292     else {
01293         // if we're not adding an accelerator, we're done
01294         if (key == 0)
01295             return (true);
01296         
01297         // add new item to the accelerator table
01298         if (!insertaccelerator (&accel))
01299             return (false);
01300         }
01301 
01302     // put the changed table and menu item into effect
01303     updateaccelerators ();
01304 
01305     // add the key to the menu item text
01306     pushaccelstring (&accel, bs);
01307 
01308     copyptocstring (bs, info.dwTypeData);
01309     
01310     return (SetMenuItemInfo (hmenu, ixmenu - 1, true, &info));
01311 #endif
01312     } /*setmenuitemcommandkey*/
01313 
01314 
01315 void getmenuitemcommandkey (hdlmenu hmenu, short ixmenu, short *key) {
01316 
01317     #ifdef MACVERSION
01318         GetItemCmd (hmenu, ixmenu, key);
01319     #endif
01320 
01321     #ifdef WIN95VERSION
01322         MENUITEMINFO info;
01323         short ixaccel;
01324         
01325         *key = 0; // default return
01326         
01327         // get the item info
01328         info.cbSize = sizeof (info);
01329         info.fMask = MIIM_ID;
01330         
01331         hmenu = GetSubMenu (hmenu, 0); // get actual popup
01332         
01333         GetMenuItemInfo (hmenu, ixmenu - 1, true, &info);
01334         
01335         if (findaccelerator (info.wID, &ixaccel)) {
01336             
01337             ACCEL ac = ((LPACCEL) *haccelerators) [ixaccel];
01338             
01339             if (ac.fVirt & FVIRTKEY)
01340                 *key = MapVirtualKey (ac.key, 2) & 0x00ff;
01341             else
01342                 *key = ac.key;
01343             }
01344     #endif
01345     } /*getmenuitemcommandkey*/
01346 
01347 
01348 #if !flruntime  
01349 //Code change by Timothy Paustian Saturday, April 29, 2000 9:33:29 PM
01350 //Changed for UH 3.3.1 to avoid conflict with Menus.h
01351 boolean Insertmenuitem (hdlmenu hmenu, short ixmenu, bigstring bs) {
01352     
01353     /*
01354     3/26/91 dmb: added logic to handle meta-characters
01355     
01356     12/31/96 dmb: added idmenu parameter. under windows, the command
01357     for the new menu has the menu id in the high byte, the item number
01358     in the low byte
01359     */
01360     
01361 #ifdef MACVERSION
01362      /*to allow meta-characters in bs, append blank item, then set item text*/
01363     bigstring bsspace;
01364     
01365     if (equalstrings (bs, STR_menuseparator)) /*take disabled seperator as is*/
01366         InsertMenuItem (hmenu, bs, ixmenu - 1);
01367         
01368     else {
01369         setstringwithchar (chspace, bsspace);
01370         
01371     //  AppendMenu (hmenu, bsspace);
01372         InsertMenuItem (hmenu, bsspace, ixmenu - 1);
01373         
01374         if (!isemptystring (bs))
01375             SetMenuItemText (hmenu, ixmenu, bs);
01376         }
01377     
01378     return (true);
01379 #endif
01380 
01381 #ifdef WIN95VERSION
01382     MENUITEMINFO info;
01383     char item [256];
01384     short idmenu;
01385     boolean fl;
01386     
01387     info.cbSize = sizeof (info);
01388     info.fMask = MIIM_SUBMENU | MIIM_ID;
01389     
01390     GetMenuItemInfo (hmenu, 0, true, &info); // get the actual popup and it's id
01391     
01392     hmenu = info.hSubMenu;
01393     
01394     idmenu = info.wID;
01395     
01396     assert ((idmenu % 100) == 0);
01397     
01398     removeaccelerators (idmenu, ixmenu);
01399     
01400     info.wID += ixmenu;
01401 
01402     info.fMask = MIIM_TYPE | MIIM_ID;
01403     
01404     if (isseparatorstring (bs))
01405         info.fType = MFT_SEPARATOR;
01406     
01407     else {
01408         copyptocstring (bs, item);
01409         
01410         info.fType = MFT_STRING;
01411         info.dwTypeData = item;
01412         }
01413     
01414     fl = InsertMenuItem (hmenu, ixmenu - 1, true, &info);
01415     
01416     adjustitemcommands (hmenu, idmenu, ixmenu);
01417 
01418     addaccelerators (hmenu, idmenu, ixmenu);
01419     
01420     return (fl);
01421 #endif
01422     } /*insertmenuitem*/
01423 
01424 
01425 boolean deletemenuitem (hdlmenu hmenu, short ixmenu) {
01426 
01427 #ifdef MACVERSION
01428     DeleteMenuItem (hmenu, ixmenu);
01429     
01430     return (true);
01431 #endif
01432 
01433 #ifdef WIN95VERSION 
01434     MENUITEMINFO info;
01435     boolean fl;
01436     
01437 //  hmenu = GetSubMenu (hmenu, 0); // get actual popup
01438     info.cbSize = sizeof (info);
01439     info.fMask = MIIM_SUBMENU | MIIM_ID;
01440     
01441     GetMenuItemInfo (hmenu, 0, true, &info); // get the actual popup and all of it's info
01442     
01443     removeaccelerators (info.wID, ixmenu);
01444     
01445     fl = RemoveMenu (info.hSubMenu, ixmenu - 1, MF_BYPOSITION);
01446     
01447     adjustitemcommands (info.hSubMenu, info.wID, ixmenu);
01448 
01449     addaccelerators (info.hSubMenu, info.wID, ixmenu);
01450     
01451     return (fl);
01452 #endif
01453     } /*deletemenuitem*/
01454 
01455 
01456 boolean deleteallmenuitems (hdlmenu hmenu, short afteritem) {
01457     
01458     register short ct, i;
01459     
01460     ct = countmenuitems (hmenu);
01461     
01462     for (i = ct; i > afteritem; i--)
01463         if (!deletemenuitem (hmenu, i))
01464             return (false);
01465         
01466     return (true);
01467     } /*deleteallmenuitems*/
01468     
01469     
01470 boolean deletelastmenuitem (hdlmenu hmenu) {
01471     
01472     return (deletemenuitem (hmenu, countmenuitems (hmenu)));
01473     } /*deletelastmenuitem*/
01474 
01475 #endif
01476 
01477 boolean pushmenuitem (hdlmenu hmenu, short idmenu, bigstring bs, short commandid) {
01478     
01479     /*
01480     3/26/91 dmb: added logic to handle meta-characters
01481     
01482     12/31/96 dmb: added idmenu parameter. under windows, the command
01483     for the new menu has the menu id in the high byte, the item number
01484     in the low byte
01485 
01486     7.1b23 PBS: new parameter commandid allows one to specify the commandid.
01487     If it's < 1, then calculate the commandid.
01488     */
01489     
01490 #ifdef MACVERSION
01491 #   pragma unused (idmenu)
01492     bigstring bsspace;
01493     
01494     if (isseparatorstring (bs)) /*take disabled seperator as is*/
01495         AppendMenu (hmenu, bs);
01496     
01497     else { /*to allow meta-characters in bs, append blank item, then set item text*/
01498         
01499         setstringwithchar (chspace, bsspace);
01500         
01501         AppendMenu (hmenu, bsspace);
01502         
01503         if (!isemptystring (bs))
01504             SetMenuItemText (hmenu, countmenuitems (hmenu), bs);
01505         
01506         if (commandid > 0) /*7.1b23 PBS: allow caller to specify commandid*/
01507             SetMenuItemCommandID (hmenu, countmenuitems (hmenu), commandid);
01508             
01509         }
01510     
01511     return (true);
01512 #endif
01513 
01514 #ifdef WIN95VERSION
01515     boolean fl;
01516     
01517     hmenu = GetSubMenu (hmenu, 0); // get actual popup
01518     
01519     if (isseparatorstring (bs))
01520         fl = AppendMenu (hmenu, MF_SEPARATOR, 0, NULL);
01521     
01522     else {
01523         short command = idmenu + GetMenuItemCount (hmenu) + 1;
01524         char item [256];
01525 
01526         if (commandid > 0)          /*7.1b23 PBS: allow caller to specify commandid*/
01527             command = commandid;
01528         
01529         copyptocstring (bs, item);
01530 
01531         fl = AppendMenu (hmenu, MF_STRING, command, item);
01532         }
01533 
01534     return (fl);
01535 #endif
01536     } /*pushmenuitem*/
01537 
01538 
01539 boolean pushresourcemenuitems (hdlmenu hmenu, short idmenu, OSType restype) {
01540 
01541 #ifdef MACVERSION
01542 #   pragma unused (idmenu)
01543     //Code change by Timothy Paustian Wednesday, June 28, 2000 4:27:19 PM
01544     //You can't do this in carbon.
01545     //#if !TARGET_API_MAC_CARBON    
01546     AppendResMenu (hmenu, restype);
01547     //#endif
01548         
01549     return (true);
01550 #endif
01551 
01552 #ifdef WIN95VERSION
01553     if (restype == 'FONT') {
01554 
01555         short i;
01556         bigstring bsfont;
01557         extern short globalFontCount;
01558         
01559         deleteallmenuitems (hmenu, 0);
01560 
01561         for (i = 1; i <= globalFontCount; ++i) {
01562 
01563             fontgetname (i, bsfont);
01564 
01565             pushmenuitem (hmenu, idmenu, bsfont, 0);
01566             }
01567         }
01568 
01569     return true;
01570 #endif
01571     } /*pushresourcemenuitems*/
01572 
01573 
01574 #if !flruntime
01575     
01576 boolean pushdottedlinemenuitem (hdlmenu hmenu) {
01577     
01578     /*
01579     push a disabled dotted line at the end of the indicated menu.
01580     */
01581     
01582     return (pushmenuitem (hmenu, 0, STR_menuseparator, 0));
01583     } /*pushdottedlinemenuitem*/
01584     
01585 
01586 /*
01587 boolean newtempmenu (hdlmenu *hmenu, short *idmenu) {
01588     
01589     register hdlmenu h;
01590     
01591     h = NewMenu (idtempmenu, (ptrstring) "\pš"); /%name is irrelevent in a popup%/
01592     
01593     if (h == nil) { /%error allocating new menu%/
01594         
01595         sysbeep ();
01596         
01597         return (false);
01598         }
01599     
01600     *hmenu = h;
01601     
01602     *idmenu = idtempmenu;
01603     
01604     return (true);
01605     } /%newtempmenu%/
01606 */
01607     
01608     
01609 short getprevmenuitem (hdlmenu hmenu) {
01610     
01611     register hdlmenu hm = hmenu;
01612     register short ct;
01613     register short i;
01614     
01615     ct = countmenuitems (hmenu);
01616     
01617     for (i = ct; i >= 1; i--) {
01618         
01619         if (menuitemmarked (hm, i)) {
01620             
01621             if (i == 1) /*first item checked, wrap to bottom*/
01622                 return (ct);
01623             else
01624                 return (i - 1);
01625             }
01626         } /*for*/
01627     
01628     return (1); /*no item checked*/
01629     } /*getprevmenuitem*/
01630 
01631     
01632 short getnextmenuitem (hdlmenu hmenu) {
01633     
01634     register hdlmenu hm = hmenu;
01635     register short ct;
01636     register short i;
01637     
01638     ct = countmenuitems (hmenu);
01639     
01640     for (i = 1; i <= ct; i++) {
01641         
01642         if (menuitemmarked (hm, i)) {
01643             
01644             if (i == ct) /*last item checked, wrap to top*/
01645                 return (1);
01646             else
01647                 return (i + 1);
01648             }
01649         } /*for*/
01650         
01651     return (1); /*no item checked*/
01652     } /*getnextmenuitem*/
01653 
01654 #endif
01655 
01656 boolean initmenusystem (void) {
01657 
01658     #ifdef WIN95VERSION
01659         /*
01660         creator an in-memory version of the oringal, resource-loaded
01661         accelerator table. this allows us to modify it more easily.
01662         */
01663 
01664         int ctaccelerators;
01665 
01666         ctaccelerators = CopyAcceleratorTable (hAccel, NULL, 0); 
01667         
01668         if (!newhandle (ctaccelerators * sizeof (ACCEL), &haccelerators))
01669             return (false);
01670         
01671         CopyAcceleratorTable (hAccel, (LPACCEL) *haccelerators, ctaccelerators);
01672         
01673         lockhandle (haccelerators);
01674 
01675         hAccel = CreateAcceleratorTable ((LPACCEL) *haccelerators, ctaccelerators);
01676 
01677         unlockhandle (haccelerators);
01678     #endif
01679 
01680     return (true);
01681     } /*initmenusystem*/
01682 
01683 
01684 boolean deletemenuitems (hdlmenu hmenu, short firstitem, short itemcount) {
01685 
01686     /*
01687     2005-10-01 creedon: created, delete menu items starting at firstitem for itemcount
01688     
01689     2006-02-19 aradke: switched to platform-agnostic code
01690     */
01691 
01692     short ctitems = countmenuitems (hmenu);
01693     short i;
01694     
01695     if (itemcount > ctitems)
01696         itemcount = ctitems;
01697     
01698     for (i = itemcount; i >= firstitem; i--) {
01699         if (!deletemenuitem (hmenu, i)) {
01700             return (false);
01701             }           
01702         } /*for*/
01703         
01704     return (true);
01705     } /* deletemenuitems */
01706 
01707 
01708 void disableallmenuitems (hdlmenu hmenu) {
01709 
01710     /*
01711     2005-10-01 creedon: created
01712     
01713     2006-02-19 aradke: switched to platform-agnostic code
01714     */
01715 
01716     short ct = countmenuitems (hmenu);
01717     short i;
01718 
01719     for (i = ct; i > 0; i--)
01720         disablemenuitem (hmenu, i);
01721     
01722     } /* disableallmenuitems */
01723 

Generated on Wed May 31 18:19:55 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6