landruntime.c

Go to the documentation of this file.
00001 
00002 /*  $Id: landruntime.c 355 2005-01-11 22:48:55Z andreradke $    */
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 "landinternal.h"
00029 #include <processes.h>
00030 
00031 
00032 
00033 
00034 static landgetscriptid (tyapplicationid *id) {
00035     
00036     /*
00037     makes it easy to direct messages to the scripting system.
00038     
00039     7/3/91 dmb: removed call to landapprunning.  it justs adds IAC traffic, 
00040     and would doesn't add any additional error handle capabilities.  (besides, 
00041     none of the callers were checking the result of this fuction)
00042     */
00043     
00044     *id = idappscriptrunner;
00045     
00046     /*
00047     return (landapprunning (*id));
00048     */
00049     } /*landgetscriptid*/
00050 
00051 
00052 static short landcountmenuarray (hdlmenuarray hmenuarray) {
00053     
00054     /*
00055     returns the number of menus in the menu array.
00056     */
00057     
00058     if (hmenuarray == nil)
00059         return (0);
00060         
00061     return ((short) (landgethandlesize ((Handle) hmenuarray) / longsizeof (tyruntimemenurecord)));
00062     } /*landcountmenuarray*/
00063 
00064 
00065 pascal boolean landinstallmenuarray (short idmenuafter, hdlmenuarray hmenuarray) {
00066     
00067     /*
00068     Calls the Macintosh Menu Manager InsertMenu routine once for each menu in the 
00069     hdlmenuarray structure. All the menus are inserted before the menu id passed in 
00070     as the first parameter according to the conventions of InsertMenu.  Pass in zero 
00071     for the first parameter to install the menus to the right of all other menus.
00072     
00073     Does not call DrawMenuBar.
00074     
00075     Always returns true.
00076     */
00077     
00078     register hdllandglobals hg = landgetglobals ();
00079     register hdlmenuarray hm = hmenuarray;
00080     register short i, ct;
00081     tyruntimemenurecord item;
00082     
00083     ct = landcountmenuarray (hm);
00084     
00085     for (i = 0; i < ct; i++) {
00086         
00087         item = (**hm) [i];
00088         
00089         if (item.flhierarchic)
00090             InsertMenu (item.hmenu, -1);
00091         else
00092             InsertMenu (item.hmenu, idmenuafter);
00093         
00094         (**hm) [i].flinserted = true;
00095         } /*for*/
00096     
00097     (**hg).fldirtyruntimemenus = false;
00098     
00099     return (true);
00100     } /*landinstallmenuarray*/
00101 
00102 
00103 static boolean landgetmenuhandles (hdlmenuarray hmenuarray) {
00104     
00105     register hdllandglobals hg = landgetglobals ();
00106     register short i, ct;
00107     register boolean fl;
00108     hdlverbrecord hverb;
00109     typaramrecord param;
00110     bigstring bserror;
00111     short iderror;
00112     tyapplicationid id;
00113     
00114     ct = landcountmenuarray (hmenuarray);
00115     
00116     landgetscriptid (&id);
00117     
00118     for (i = 0; i < ct; i++) {
00119         
00120         if (!landnewverb (id, id, getmenuhandletoken, 2, &hverb))
00121             return (false);
00122         
00123         if (!landpushlongparam (hverb, (**hg).applicationid, idmenuprogram))
00124             return (false);
00125         
00126         if (!landpushintparam (hverb, i, idarrayindex))
00127             return (false);
00128         
00129         if (!landsendverb (hverb, &param, bserror, &iderror))
00130             return (false);
00131         
00132         fl = false;
00133         
00134         if (param.type == binarytype) {
00135         
00136             (**hmenuarray) [i].hmenu = (MenuHandle) param.val.binaryvalue;
00137             
00138             param.val.binaryvalue = nil; /*keep it from being disposed*/
00139             
00140             fl = true;
00141             }
00142             
00143         landdisposeparamrecord (&param);
00144         
00145         if (!fl)
00146             return (false);
00147         } /*for*/
00148         
00149     return (true);
00150     } /*landgetmenuhandles*/
00151 
00152 
00153 pascal boolean landgetmenuarray (short firstresource, hdlmenuarray *hmenuarray) {
00154     
00155     /*
00156     Sends an IAC-message to Frontier asking for an array of menu information about the 
00157     menu bar.  ItÕs passed back as a binary IAC message. The resulting array is returned
00158     in the second parameter.
00159     
00160     The first parameter is the starting resource number for menu allocation.  
00161     
00162     Returns false if Runtime wasnÕt running, or if there are no menus for your 
00163     application, or if one of the menus wasnÕt successfully loaded.
00164     */
00165     
00166     register hdllandglobals hg = landgetglobals ();
00167     hdlverbrecord hverb;
00168     typaramrecord param;
00169     bigstring bserror;
00170     short iderror;
00171     register boolean fl;
00172     tyapplicationid id;
00173     
00174     iderror = 0;
00175     
00176     setemptystring (bserror);
00177     
00178     landgetscriptid (&id);
00179     
00180     if (!landnewverb (id, id, getmenuarraytoken, 2, &hverb))
00181         return (false);
00182     
00183     if (!landpushlongparam (hverb, (**hg).applicationid, idmenuprogram))
00184         return (false);
00185         
00186     if (!landpushintparam (hverb, firstresource, idstartingresource))
00187         return (false);
00188         
00189     if (!landsendverb (hverb, &param, bserror, &iderror))
00190         return (false);
00191     
00192     fl = false;
00193     
00194     if (param.type == binarytype) {
00195     
00196         *hmenuarray = (hdlmenuarray) param.val.binaryvalue;
00197         
00198         param.val.binaryvalue = nil; /*keep it from being disposed*/
00199         
00200         fl = true;
00201         }
00202         
00203     landdisposeparamrecord (&param);
00204     
00205     if (!fl)
00206         return (false);
00207     
00208     return (landgetmenuhandles (*hmenuarray));
00209     } /*landgetmenuarray*/
00210 
00211 
00212 pascal boolean landremovemenuarray (hdlmenuarray hmenuarray) {
00213     
00214     /*
00215     Removes the menus in the specified menu array from the menu bar.  Does not 
00216     dispose of the menus or menu array. Returns true if it was able to remove the 
00217     menus.
00218     */
00219 
00220     register hdlmenuarray hm = hmenuarray;
00221     register short i;
00222     register short ctmenus;
00223     
00224     ctmenus = landcountmenuarray (hm);
00225     
00226     for (i = 0; i < ctmenus; i++) {
00227         
00228         DeleteMenu ((**hm) [i].idmenu);
00229         
00230         (**hm) [i].flinserted = false;
00231         }
00232     
00233     return (true);
00234     } /*landremovemenuarray*/
00235 
00236 
00237 pascal boolean landdisposemenuarray (hdlmenuarray hmenuarray) {
00238     
00239     /*
00240     Diposes of the menus in the specified menu array and frees the memory 
00241     associated with the menu array. Returns true if it was able to dispose 
00242     of the menus and menu array memory.
00243     */
00244     
00245     register hdlmenuarray hm = hmenuarray;
00246     register short i;
00247     register short ctmenus;
00248     tyruntimemenurecord item;
00249     
00250     if (hm == nil) /*defensive driving*/
00251         return (false);
00252     
00253     ctmenus = landcountmenuarray (hm);
00254     
00255     for (i = 0; i < ctmenus; i++) {
00256         
00257         item = (**hm) [i];
00258         
00259         if (item.flinserted)
00260             DeleteMenu (item.idmenu);
00261         
00262         DisposeMenu (item.hmenu);
00263         } /*for*/
00264     
00265     DisposHandle ((Handle) hm);
00266     
00267     return (true);
00268     } /*landdisposemenuarray*/
00269 
00270 
00271 pascal boolean landenablemenuarray (hdlmenuarray hmenuarray, boolean flenable) {
00272     
00273     /*
00274     7/3/91 dmb: Enables or disables the the menus in the specified menu array.
00275     
00276     Always returns true.
00277     */
00278     
00279     register hdlmenuarray hm = hmenuarray;
00280     register short i;
00281     register short ctmenus;
00282     register MenuHandle hmenu;
00283     
00284     ctmenus = landcountmenuarray (hm);
00285     
00286     for (i = 0; i < ctmenus; i++) {
00287         
00288         hmenu = (**hm) [i].hmenu;
00289         
00290         if (flenable)
00291             EnableItem (hmenu, 0);
00292         else
00293             DisableItem (hmenu, 0);
00294         } /*for*/
00295     
00296     DrawMenuBar ();
00297     
00298     return (true);
00299     } /*landenablemenuarray*/
00300 
00301 
00302 pascal boolean landrunmenuitem (idmenu, iditem, hmenuarray) short idmenu, iditem; hdlmenuarray hmenuarray; {
00303     
00304     /*
00305     Sends an IAC message to Frontier to run the script linked into the indicated 
00306     menu item.  The first parameter is the id of the menu, the second is the menu 
00307     item number. Returns true if it was able to send the message to Runtime.
00308     */
00309     
00310     register hdllandglobals hg = landgetglobals ();
00311     register hdlverbrecord hv;
00312     register long idscript;
00313     hdlverbrecord hverb;
00314     typaramrecord param;
00315     bigstring bserror;
00316     short iderror;
00317     tyapplicationid id;
00318     
00319     (**hg).idmenuscript = 0; /*indicate no script running*/
00320     
00321     (**hg).hmenuarray = nil; 
00322     
00323     (**hg).flscriptcancelled = false; 
00324     
00325     iderror = 0;
00326     
00327     setemptystring (bserror);
00328     
00329     landgetscriptid (&id);
00330     
00331     if (!landnewverb (id, id, idrunmenuitem, 3, &hverb))
00332         return (false);
00333     
00334     hv = hverb; /*copy into register*/
00335     
00336     if (!landpushlongparam (hv, (**hg).applicationid, idmenuprogram))
00337         return (false);
00338     
00339     if (!landpushintparam (hv, idmenu, idmenuidvalue))
00340         return (false);
00341     
00342     if (!landpushintparam (hv, iditem, idmenuitemvalue))
00343         return (false);
00344     
00345     if (!landsendverb (hv, &param, bserror, &iderror))
00346         return (false);
00347         
00348     idscript = param.val.longvalue;
00349     
00350     (**hg).idmenuscript = idscript;
00351     
00352     if (idscript != 0) { /*a script is actually running*/
00353     
00354         HiliteMenu (0); /*un-highlight any highlighted menus*/
00355             
00356         landenablemenuarray (hmenuarray, false); /*disable menus while script running*/
00357         
00358         (**hg).hmenuarray = hmenuarray;
00359         }
00360         
00361     landdisposeparamrecord (&param); /*it might have heap-allocated stuff linked in*/
00362     
00363     return (true);
00364     } /*landrunmenuitem*/
00365 
00366 
00367 pascal boolean landmenuhit (short idmenu, hdlmenuarray hmenuarray) {
00368     
00369     /*
00370     Returns true if the menu whose id (the first parameter) is in the menuarray 
00371     (the 2nd parameter).  Call this in your menu handling routine to decide if you 
00372     should pass the command to Frontier using landrunmenuitem.  
00373     */
00374     
00375     register short ct, i;
00376     tyruntimemenurecord item;
00377     
00378     ct = landcountmenuarray (hmenuarray);
00379     
00380     for (i = 0; i < ct; i++) {
00381         
00382         item = (**hmenuarray) [i];
00383         
00384         if (item.idmenu == idmenu)
00385             return (true);
00386         } /*for*/
00387         
00388     return (false);
00389     } /*landmenuhit*/
00390 
00391 
00392 pascal boolean landcancelmenuscript (void) {
00393     
00394     /*
00395     call this routine to kill the menu script that's running.   
00396     
00397     it just sets a flag in the toolkit globals record.  the next IAC verb that's 
00398     received returns with an error saying that the user cancelled the script.  
00399     Frontier will avoid putting up an error window on this particular error.
00400     
00401     returns false if no script is running.
00402     */
00403     
00404     register hdllandglobals hg = landgetglobals ();
00405     
00406     if ((**hg).idmenuscript == 0) /*no script running*/
00407         return (false);
00408         
00409     (**hg).flscriptcancelled = true;
00410     
00411     return (true);
00412     } /*landcancelmenuscript*/
00413     
00414     
00415 pascal boolean landmenuneedsupdate (void) {
00416 
00417     register hdllandglobals hg = landgetglobals ();
00418     
00419     return ((**hg).fldirtyruntimemenus);
00420     } /*landmenuneedsupdate*/
00421 
00422 
00423 pascal boolean landmenuscriptcompleted (void) { 
00424 
00425     register hdllandglobals hg = landgetglobals ();
00426     
00427     if ((**hg).idmenuscript == 0) /*no script running*/
00428         return (false);
00429     
00430     (*(**hg).menuscriptcompleteroutine) ();
00431     
00432     (**hg).idmenuscript = 0; /*no script running anymore*/
00433     
00434     landenablemenuarray ((**hg).hmenuarray, true);
00435     
00436     (**hg).hmenuarray = nil;
00437     
00438     (**hg).flscriptcancelled = false; 
00439     
00440     return (true);
00441     } /*landmenuscriptcompleted*/
00442             
00443 
00444 

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