appletmenuops.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletmenuops.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletstrings.h"
00008 #include "appletdynamicarrays.h"
00009 #include "appletmenuops.h"
00010 
00011 
00012 tydynamicarray menuarray = {longsizeof (MenuHandle), nil};
00013 
00014 
00015 boolean pushmenuitem (MenuHandle hmenu, bigstring bs, boolean flenabled) {
00016     
00017     short item;
00018     bigstring bstemp;
00019     
00020     item = CountMItems (hmenu) + 1; /*new item will be after current end*/
00021     
00022     if (equalstrings (bs, "\p(-")) /*take disabled seperator as is*/
00023         AppendMenu (hmenu, bs);
00024     
00025     else { /*to allow meta-characters in bs, append blank item, then set item text*/
00026         
00027         setstringwithchar (chspace, bstemp);
00028         
00029         AppendMenu (hmenu, bstemp);
00030         
00031         copystring (bs, bstemp); /*work with a copy*/
00032         
00033         if (equalstrings (bstemp, "\p-")) /*this is one meta-character that it won't ignore*/
00034             copystring ("\p\0-", bstemp);
00035         
00036         if (!isemptystring (bs))
00037             SetItem (hmenu, item, bstemp);
00038         }
00039     
00040     if (!flenabled)
00041         DisableItem (hmenu, item);
00042 
00043     return (true);
00044     } /*pushmenuitem*/
00045     
00046     
00047 void deletemenuitem (MenuHandle hmenu, short ixmenu) {
00048     
00049     DelMenuItem (hmenu, ixmenu);
00050     } /*deletemenuitem*/
00051     
00052 
00053 void deleteallmenuitems (MenuHandle hmenu) {
00054     
00055     short ct, i;
00056     
00057     assert (hmenu != nil);
00058     
00059     ct = countmenuitems (hmenu);
00060     
00061     for (i = ct; i >= 1; i--)
00062         deletemenuitem (hmenu, i);
00063     } /*deleteallmenuitems*/
00064     
00065     
00066 boolean getmenuitem (MenuHandle hmenu, short ixmenu, bigstring bs) {
00067     
00068     if (ixmenu <= 0)
00069         return (false);
00070         
00071     GetItem (hmenu, ixmenu, bs);
00072         
00073     return (true);
00074     } /*getmenuitem*/
00075 
00076 
00077 boolean setmenuitem (MenuHandle hmenu, short ixmenu, bigstring bs) {
00078     
00079     SetItem (hmenu, ixmenu, bs);
00080     
00081     return (true);
00082     } /*setmenuitem*/
00083     
00084     
00085 void checkmenuitem (MenuHandle hmenu, short ixmenu, boolean fl) {
00086         
00087     CheckItem (hmenu, ixmenu, fl);
00088     } /*checkmenuitem*/
00089     
00090 
00091 void setmenuitemmark (MenuHandle hmenu, short ixmenu, char ch) {
00092     
00093     /*
00094     set the "mark character" for the menu, 0 to remove any mark
00095     */
00096     
00097     SetItemMark (hmenu, ixmenu, ch);
00098     } /*setmenuitemmark*/
00099     
00100 
00101 boolean visitonemenu (short idmenu, tymenuvisitcallback visitproc) {
00102     
00103     MenuHandle hmenu;
00104     short i;
00105     short lastitem;
00106     
00107     hmenu = GetMHandle (idmenu);
00108     
00109     if (!hmenu)
00110         return (false);
00111     
00112     lastitem = countmenuitems (hmenu);
00113     
00114     for (i = 1; i <= lastitem; i++) {
00115         
00116         if (!(*visitproc) (hmenu, i))
00117             return (false);
00118         } /*for*/
00119 
00120     return (true);
00121     } /*visitonemenu*/
00122     
00123     
00124 boolean visitallmenus (tymenuvisitcallback visitproc) {
00125     
00126     short ct, i;
00127     MenuHandle hmenu;
00128     
00129     ct = sizedynamicarray (&menuarray);
00130     
00131     for (i = 0; i < ct; i++) {
00132         
00133         indexdynamicarray (i, &menuarray, &hmenu);
00134         
00135         if (hmenu != nil) {
00136         
00137             if (!(*visitproc) (hmenu, 0))
00138                 return (false);
00139             }
00140         } /*for*/
00141     
00142     return (true);
00143     } /*visitallmenus*/
00144     
00145 
00146 static boolean disablemenucallback (MenuHandle hmenu, short num) {
00147     
00148     DisableItem (hmenu, 0);
00149     
00150     return (true);
00151     } /*disablemenucallback*/
00152     
00153     
00154 void disableallmenus (void) {
00155     
00156     HiliteMenu (0); /*make sure no menu is highlighted*/
00157     
00158     visitallmenus (&disablemenucallback);
00159     } /*disableallmenus*/
00160 
00161 
00162 static boolean enablemenucallback (MenuHandle hmenu, short num) {
00163     
00164     EnableItem (hmenu, 0);
00165     
00166     return (true);
00167     } /*enablemenucallback*/
00168     
00169     
00170 void enableallmenus (void) {
00171     
00172     visitallmenus (&enablemenucallback);
00173     } /*enableallmenus*/
00174 
00175 
00176 void stylemenuitem (MenuHandle hmenu, short ixmenu, short style) {
00177     
00178     SetItemStyle (hmenu, ixmenu, style);
00179     } /*stylemenuitem*/
00180     
00181     
00182 void installmenubefore (short idmenu, short idafter, MenuHandle *hmenu) {
00183     
00184     MenuHandle h;
00185     
00186     *hmenu = GetMenu (idmenu); 
00187     
00188     if (*hmenu == nil)
00189         return;
00190     
00191     InsertMenu (*hmenu, idafter);
00192     
00193     h = *hmenu;
00194     
00195     addtodynamicarray (&h, &menuarray);
00196     } /*installmenubefore*/
00197     
00198     
00199 void installmenu (short idmenu, MenuHandle *hmenu) {
00200     
00201     installmenubefore (idmenu, 0, hmenu);
00202     } /*installmenu*/
00203     
00204     
00205 void installhierarchicmenu (short idmenu, MenuHandle *hmenu) {
00206 
00207     installmenubefore (idmenu, -1, hmenu);
00208     } /*installhierarchicmenu*/
00209     
00210     
00211 void deletemenu (short idmenu) {
00212     
00213     removefromdynamicarray ((long) GetMenu (idmenu), &menuarray);
00214     
00215     DeleteMenu (idmenu);
00216     } /*deletemenu*/
00217     
00218     
00219 void setmenuitemenable (MenuHandle hmenu, short item, boolean fl) {
00220     
00221     /*
00222     enable or disable a menu or a menu item.  
00223     
00224     if item == 0 we enable or disable the entire menu.
00225     
00226     dmb 8/1/90:  check for dummy items (negative item numbers)
00227     
00228     DW 8/28/93: if item is 0, and the state didn't change, don't draw the 
00229     menubar. avoids flicker in the menu bar.
00230     */
00231     
00232     boolean flwasenabled;
00233     
00234     assert (hmenu != nil); /*it happened once, it could happen again*/
00235     
00236     if (item < 0) /*this item has been dummied out -- do nothing*/
00237         return;
00238     
00239     flwasenabled = ((**hmenu).enableFlags >> item) & 1;
00240     
00241     if (fl)
00242         EnableItem (hmenu, item);
00243     else
00244         DisableItem (hmenu, item);
00245         
00246     if ((item == 0) && (fl != flwasenabled))
00247         DrawMenuBar ();
00248     } /*setmenuitemenable*/
00249     
00250     
00251 void disablemenuitem (MenuHandle hmenu, short item) {
00252     
00253     setmenuitemenable (hmenu, item, false);
00254     } /*disablemenuitem*/
00255     
00256 
00257 void enablemenuitem (MenuHandle hmenu, short item) {
00258     
00259     setmenuitemenable (hmenu, item, true);
00260     } /*enablemenuitem*/
00261 
00262 
00263 short countmenuitems (MenuHandle hmenu) {
00264     
00265     return (CountMItems (hmenu));
00266     } /*countmenuitems*/
00267     
00268     
00269 void uncheckallmenuitems (MenuHandle hmenu) {
00270     
00271     short i;
00272     short ct;
00273     
00274     ct = countmenuitems (hmenu);
00275     
00276     for (i = 1; i <= ct; i++)
00277         CheckItem (hmenu, i, false);
00278     } /*uncheckallmenuitems*/
00279     
00280     
00281 void disableallmenuitems (MenuHandle hmenu) {
00282     
00283     short i;
00284     short ct;
00285     
00286     ct = countmenuitems (hmenu);
00287     
00288     for (i = 1; i <= ct; i++)
00289         setmenuitemenable (hmenu, i, false);
00290     
00291     setmenuitemenable (hmenu, 0, false);    // and the main item itself - LDR 10/29
00292     } /*disableallmenuitems*/
00293     
00294     
00295 void enableallmenuitems (MenuHandle hmenu) {
00296     
00297     short i;
00298     short ct;
00299     
00300     ct = countmenuitems (hmenu);
00301     
00302     for (i = 1; i <= ct; i++)
00303         setmenuitemenable (hmenu, i, true);
00304 
00305     setmenuitemenable (hmenu, 0, true); // and the main item itself - LDR 10/29
00306     } /*enableallmenuitems*/
00307     
00308     
00309 void disableemptymenuitems (MenuHandle hmenu) {
00310     
00311     short i, j;
00312     short ctmenuitems;
00313     
00314     ctmenuitems = countmenuitems (hmenu);
00315     
00316     for (i = 1; i <= ctmenuitems; i++) {
00317         
00318         boolean flnotempty = false;
00319         bigstring bs;
00320         
00321         getmenuitem (hmenu, i, bs);
00322         
00323         for (j = 1; j <= stringlength (bs); j++) {
00324             
00325             if (bs [j] != ' ') {
00326                 
00327                 flnotempty = true;
00328                 
00329                 break;
00330                 }
00331             } /*for*/
00332     
00333         setmenuitemenable (hmenu, i, flnotempty);
00334         } /*for*/
00335     } /*disableemptymenuitems*/
00336     
00337     
00338 boolean findinmenu (MenuHandle hmenu, bigstring bs, short *item) {
00339 
00340     short lastitem, i;
00341     bigstring bsitem;
00342     
00343     lastitem = countmenuitems (hmenu);
00344 
00345     for (i = 1; i <= lastitem; i++) {
00346         
00347         getmenuitem (hmenu, i, bsitem);
00348         
00349         if (equalstrings (bsitem, bs)) {
00350             
00351             *item = i;
00352             
00353             return (true);
00354             }
00355         } /*for*/
00356 
00357     *item = 1;
00358     
00359     return (false);
00360     } /*findinmenu*/
00361     
00362     

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