menupack.c

Go to the documentation of this file.
00001 
00002 /*  $Id: menupack.c 1236 2006-04-09 11:28:08Z 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 "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "memory.h"
00032 #include "font.h"
00033 #include "cursor.h"
00034 #include "quickdraw.h"
00035 #include "scrap.h"
00036 #include "frontierwindows.h"
00037 #include "op.h"
00038 #include "opinternal.h"
00039 #include "menueditor.h"
00040 #include "menuinternal.h"
00041 #include "byteorder.h"  /* 2006-04-08 aradke: endianness conversion macros */
00042 
00043     
00044 
00045 boolean megetmenuiteminfo (hdlheadrecord hnode, tymenuiteminfo *item) {
00046     
00047     if (!opgetrefcon (hnode, item, sizeof (tymenuiteminfo)))
00048         return (false);
00049     
00050     disktomemlong ((*item).linkedscript.adrlink);
00051     
00052     return (true);
00053     } /*megetmenuiteminfo*/
00054 
00055 
00056 boolean mesetmenuiteminfo (hdlheadrecord hnode, const tymenuiteminfo *item) {
00057     
00058     tymenuiteminfo info = *item;
00059 
00060     memtodisklong (info.linkedscript.adrlink);
00061     
00062     return (opsetrefcon (hnode, &info, sizeof (info)));
00063     } /*mesetmenuiteminfo*/
00064 
00065 
00066 boolean mecopyrefconroutine (hdlheadrecord hsource, hdlheadrecord hdest) {
00067     
00068     /*
00069     5.0a3 dmb: use meloadscriptoutline, not meloadoutline. the latter loads
00070     the main menubar outline, not script outlines. I don't know why it didn't 
00071     break in 4.x, but it breaks now.
00072     */
00073     
00074     hdloutlinerecord ho;
00075     tymenuiteminfo item;
00076     hdloutlinerecord hcopy;
00077     dbaddress adr;
00078     boolean flignore;
00079     
00080     (**hdest).hrefcon = nil; /*default*/
00081     
00082     if ((**hsource).hrefcon == nil)
00083         return (true);
00084     
00085     megetmenuiteminfo (hsource, &item);
00086     
00087     ho = item.linkedscript.houtline;
00088     
00089     if (ho != nil) { /*copy the in-memory version*/
00090             
00091         if (!opcopyoutlinerecord (ho, &hcopy))
00092             return (false);
00093         }
00094         
00095     else { /*load the original in from disk*/
00096         
00097         adr = item.linkedscript.adrlink;
00098         
00099         if (adr == nildbaddress) /*no script linked into this line*/
00100             hcopy = nil;
00101             
00102         else {
00103             hdlmenurecord hm = (hdlmenurecord) (**outlinedata).outlinerefcon;
00104             
00105             if (!meloadscriptoutline (hm, hsource, &hcopy, &flignore)) // 5.0a3 dmb - was: meloadoutline (adr, &hcopy)
00106                 return (false);
00107             }
00108         }
00109     
00110     if (hcopy != nil)
00111         (**hcopy).fldirty = true; /*force save on this guy's script*/
00112     
00113     item.linkedscript.houtline = hcopy;
00114     
00115     item.linkedscript.adrlink = nildbaddress; /*hasn't been allocated yet*/
00116     
00117     mesetmenuiteminfo (hdest, &item);
00118     
00119     return (true);
00120     } /*mecopyrefconroutine*/
00121 
00122 
00123 static boolean headleveloffsetvisit (hdlheadrecord hnode, ptrvoid refcon) {
00124     
00125     long *headleveloffset = (long *) refcon;
00126     
00127     (**hnode).headlevel += *headleveloffset;
00128     
00129     return (true);
00130     } /*headleveloffsetvisit*/
00131 
00132 
00133 boolean metextualizerefconroutine (hdlheadrecord hnode, Handle htext) {
00134     
00135     /*
00136     5.1.5b16 dmb: get menu record from outlinedata, not global
00137     */
00138     
00139     register hdloutlinerecord ho;
00140     register boolean fl;
00141     register hdlheadrecord hsummit;
00142     hdloutlinerecord houtline;
00143     boolean fljustloaded;
00144     long headleveloffset;
00145     hdlmenurecord hm = (hdlmenurecord) (**outlinedata).outlinerefcon;
00146     
00147     if (!meloadscriptoutline (hm, hnode, &houtline, &fljustloaded)) 
00148         return (false);
00149     
00150     ho = houtline; /*move into register*/
00151     
00152     if (ho == nil) /*no script linked into the menu item*/
00153         return (true);
00154     
00155     hsummit = (**ho).hsummit;
00156     
00157     headleveloffset = (**hnode).headlevel + 1; /*add extra indentation for clipboard*/
00158     
00159     opsiblingvisiter (hsummit, false, &headleveloffsetvisit, &headleveloffset);
00160     
00161     fl = opoutlinetotextscrap (ho, false, htext);
00162     
00163     if (fljustloaded)
00164         opdisposeoutline (ho, false);
00165     
00166     else {
00167         
00168         headleveloffset = -headleveloffset; /*prepare for reversal*/
00169         
00170         opsiblingvisiter (hsummit, false, &headleveloffsetvisit, &headleveloffset);
00171         }
00172     
00173     return (fl);
00174     } /*metextualizerefconroutine*/
00175 
00176 
00177 boolean mereleaserefconroutine (hdlheadrecord hnode, boolean fldisk) {
00178     
00179     /*
00180     5.1.4 dmb: set the right database when fldisk
00181     */
00182 
00183     tymenuiteminfo item;
00184     hdlmenurecord hm = (hdlmenurecord) (**outlinedata).outlinerefcon;
00185 
00186     megetmenuiteminfo (hnode, &item);
00187     
00188     opdisposeoutline (item.linkedscript.houtline, fldisk);
00189     
00190     if (fldisk) {
00191     
00192         dbpushdatabase (megetdatabase (hm));
00193 
00194         dbpushreleasestack (item.linkedscript.adrlink, outlinevaluetype);
00195 
00196         dbpopdatabase ();
00197         }
00198     
00199     return (true);
00200     } /*mereleaserefconroutine*/
00201 
00202 
00203 typedef struct typackinfo {
00204 
00205     Handle hpackedscripts; /*for pack/unpackscriptvisit routines*/
00206 
00207     long ixpackedscripts; /*for unpacking only*/
00208     } typackinfo, *ptrpackinfo;
00209 
00210 
00211 static boolean mesavescriptvisit (hdlheadrecord hnode, ptrvoid refcon) {
00212 #pragma unused (refcon)
00213 
00214     register hdlheadrecord h = hnode;
00215     //ptrpackinfo packinfo = (ptrpackinfo) refcon;
00216     register hdloutlinerecord ho;
00217     tymenuiteminfo item;
00218     
00219     rollbeachball ();
00220     
00221     assert (menudata != nil);
00222     
00223     if (!megetmenuiteminfo (h, &item)) /*nothing linked, keep visiting*/
00224         return (true);
00225     
00226     ho = item.linkedscript.houtline; /*copy into register*/
00227     
00228     if (ho == nil) /*if nil, nothing to worry about saving*/
00229         return (true);
00230     
00231     if ((**ho).fldirty) { /*needs saving*/
00232         
00233         if (!mesaveoutline (ho, &item.linkedscript.adrlink)) /*memory or disk error, stop visiting*/
00234             return (false);
00235         }
00236     
00237     if (ho != (**menudata).scriptoutline) { /*don't reclaim the active scriptÉ*/
00238         
00239         opdisposeoutline (ho, false); /*reclaim the script*/
00240     
00241         item.linkedscript.houtline = nil; /*force us to look to disk*/
00242         }
00243         
00244     else { /*Éjust clear its madechanges bit*/
00245         
00246         windowsetchanges ((**menudata).scriptwindow, false);
00247         
00248         (**ho).fldirty = false;
00249         }
00250     
00251     return (mesetmenuiteminfo (h, &item));
00252     } /*mesavescriptvisit*/
00253     
00254 
00255 static boolean mesaveasscriptvisit (hdlheadrecord hnode, ptrvoid refcon) {
00256 #pragma unused (refcon)
00257 
00258     /*
00259     for save as, we need to write a packed version of every script to 
00260     the new file.  db.c takes care of redirecting reads & writes as 
00261     necessary
00262     */
00263     
00264     register hdlheadrecord h = hnode;
00265     hdloutlinerecord ho;
00266     tymenuiteminfo item;
00267     dbaddress adr;
00268     boolean fltempload = false;
00269     
00270     rollbeachball ();
00271     
00272     if (!megetmenuiteminfo (h, &item)) /*nothing linked, keep visiting*/
00273         return (true);
00274     
00275     ho = item.linkedscript.houtline; /*copy into register*/
00276     
00277     if (flconvertingolddatabase)
00278         if (!meloadscriptoutline (menudata, h, &ho, &fltempload)) /*error loading script*/
00279             return (false);
00280     
00281     if (ho != nil) {
00282     
00283         if (!mesaveoutline (ho, &adr)) /*memory or disk error, stop visiting*/
00284             return (false);
00285         }
00286     else {
00287         if (!dbcopy (item.linkedscript.adrlink, &adr)) /*copy packed version to new file*/
00288             return (false);
00289         }
00290     
00291     if (fltempload)
00292         opdisposeoutline (ho, false);
00293     
00294     item.linkedscript.adrlink = adr; /*link in current database will be restored by caller*/
00295     
00296     return (mesetmenuiteminfo (h, &item));
00297     } /*mesaveasscriptvisit*/
00298 
00299 
00300 static boolean mepackscriptvisit (hdlheadrecord hnode, ptrvoid refcon) {
00301     
00302     /*
00303     if there's a script attached to hnode, pack it onto the end of 
00304     the hpackedscripts handle.
00305     */
00306     
00307     register hdlheadrecord h = hnode;
00308     ptrpackinfo packinfo = (ptrpackinfo) refcon;
00309     register hdloutlinerecord ho;
00310     tymenuiteminfo item;
00311     Handle hpackedoutline;
00312     register dbaddress adr;
00313     boolean fl;
00314     
00315     if (!megetmenuiteminfo (h, &item)) /*nothing linked, keep visiting*/
00316         return (true);
00317     
00318     ho = item.linkedscript.houtline; /*copy into register*/
00319     
00320     if (ho != nil)
00321         return (oppackoutline (ho, &(*packinfo).hpackedscripts));
00322     
00323     adr = item.linkedscript.adrlink;
00324     
00325     if (adr == nildbaddress) /*no linked script*/
00326         return (true);
00327     
00328     if (!dbrefhandle (adr, &hpackedoutline)) 
00329         return (false);
00330     
00331     fl = pushhandle (hpackedoutline, (*packinfo).hpackedscripts);
00332     
00333     disposehandle (hpackedoutline);
00334     
00335     return (fl);
00336     } /*mepackscriptvisit*/
00337 
00338 
00339 static boolean mesavemenustructure (tysavedmenuinfo *info, dbaddress *adr) {
00340     
00341     /*
00342     everything has already been set up:  everything pushed and dehoisted.  
00343     save all of the data associated with the menubar, by visiting every 
00344     node in the menu structure, saving off all linked scripts, and then 
00345     saving the menubar outline itself
00346     
00347     after a script is saved, we dispose of the in-memory structure, unless it
00348     is the active script, or we're doing a Save As.
00349     */
00350     
00351     hdlheadrecord hsummit;
00352     register boolean fl;
00353     
00354     opoutermostsummit (&hsummit);
00355     
00356     if (fldatabasesaveas)
00357         fl = opsiblingvisiter (hsummit, false, &mesaveasscriptvisit, nil);
00358     else
00359         fl = opsiblingvisiter (hsummit, false, &mesavescriptvisit, nil);
00360     
00361     assert (opvalidate (outlinedata));
00362     
00363     if (!fl)
00364         return (false);
00365 
00366     disktomemlong ((*info).adroutline);
00367     
00368     if (!mesaveoutline (outlinedata, &(*info).adroutline))
00369         return (false);
00370     
00371     memtodisklong ((*info).adroutline);
00372     
00373     return (dbassign (adr, sizeof (tysavedmenuinfo), info));
00374     } /*mesavemenustructure*/
00375 
00376 
00377 boolean mepackmenustructure (tysavedmenuinfo *info, Handle *hpacked) {
00378     
00379     /*
00380     analogous to mesavemenustructure above, except we're packing everything 
00381     into memory.
00382     
00383     10/6/91 dmb: mergehandles now consumes both source handles.
00384     
00385     4.1b7 dmb: oppack was fixed so that it won't dispose of the handle we 
00386     allocated if it fails. so we must dispose it here on error.
00387     */
00388     
00389     register boolean fl;
00390     Handle hpackedmenu;
00391     hdlheadrecord hsummit;
00392     typackinfo packinfo;
00393     
00394     if (!newemptyhandle (&packinfo.hpackedscripts)) /*handle where scripts will be saved*/
00395         return (false);
00396     
00397     opoutermostsummit (&hsummit);
00398     
00399     fl = opsiblingvisiter (hsummit, false, &mepackscriptvisit, &packinfo);
00400     
00401     assert (opvalidate (outlinedata));
00402     
00403     if (fl)
00404         fl = newfilledhandle (info, sizeof (tysavedmenuinfo), &hpackedmenu);
00405     
00406     if (fl) {
00407         
00408         fl = oppack (&hpackedmenu);
00409         
00410         if (fl)
00411             fl = mergehandles (hpackedmenu, packinfo.hpackedscripts, hpacked);
00412         else
00413             disposehandle (hpackedmenu); /*4.1b7 dmb*/
00414         
00415         packinfo.hpackedscripts = nil; /*it's been consumed*/
00416         }
00417     
00418     disposehandle (packinfo.hpackedscripts);
00419     
00420     return (fl);
00421     } /*mepackmenustructure*/
00422 
00423 
00424 boolean mesavemenurecord (hdlmenurecord hmenurecord, boolean flpreservelinks, boolean flmemory, dbaddress *adr, Handle *hpacked) {
00425     
00426     /*
00427     save the menu record handle in the database.
00428     
00429     dmb 9/21/90:  unfortunately, menudata global is heavily entrenched, set it at the
00430     beginning of the routine.
00431     
00432     dmb 10/23/90: the new flmemory parameter determines whether we're saving to disk 
00433     (using adr), or packing to memory (using hpacked)
00434     */
00435     
00436     register hdlmenurecord hm = hmenurecord;
00437     register hdloutlinerecord ho = (**hm).menuoutline;
00438     register boolean fl;
00439     hdlheadrecord hcursor;
00440     tysavedmenuinfo info;
00441     register WindowPtr w;
00442     Rect r;
00443     long lnumcursor;
00444     
00445     opvalidate (ho);
00446     
00447     menudata = hm; 
00448     
00449     clearbytes (&info, sizeof (info));
00450     
00451     info.versionnumber = conditionalshortswap (1);
00452     
00453     info.adroutline = conditionallongswap ((**hm).adroutline);
00454     
00455     info.vertmin = conditionalshortswap ((**ho).vertscrollinfo.min);
00456     
00457     info.vertmax = conditionalshortswap ((**ho).vertscrollinfo.max);
00458     
00459     info.vertcurrent = conditionalshortswap ((**ho).vertscrollinfo.cur);
00460     
00461     w = (**hm).scriptwindow;
00462     
00463     if (w == nil) 
00464         r = (**hm).scriptwindowrect;
00465     else
00466         getglobalwindowrect (w, &r);
00467     
00468     recttodiskrect (&r, &info.scriptwindowrect);
00469     
00470     if ((**hm).flautosmash)
00471         info.flags |= flautosmash_mask;
00472     
00473     recttodiskrect (&(**hm).menuwindowrect, &info.menuwindowrect);
00474     
00475     diskgetfontname ((**hm).defaultscriptfontnum, info.defaultscriptfontname);
00476     
00477     info.defaultscriptfontsize = conditionalshortswap ((**hm).defaultscriptfontsize);
00478     
00479     oppushoutline (ho);
00480     
00481     hcursor = (**ho).hbarcursor;
00482     
00483     opgetnodeline (hcursor, &lnumcursor);
00484 
00485     info.lnumcursor = conditionalshortswap (loword (lnumcursor));
00486     
00487     oppopallhoists (); /*pop hoists, save state to be restored after saving*/
00488     
00489     (**ho).hbarcursor = hcursor; /*scotch tape!*/
00490     
00491     fl = true;
00492     
00493     if (flpreservelinks) {
00494         
00495         /*
00496         we're saving to another file, and need to preserve the memory version 
00497         of the menubar.  we'll make a copy that we can traverse and save 
00498         with the refcon links set up for the destination file.
00499         since we don't want to copy the scripts, and don't want them disposed 
00500         when we dispose the copy, we need to patch in op's default refcon
00501         callbacks while we do the copy.
00502         */
00503         
00504         hdloutlinerecord hcopy;
00505         
00506         (**ho).copyrefconcallback = &opcopyrefconroutine;
00507         
00508         (**ho).releaserefconcallback = &opdefaultreleaserefconroutine;
00509         
00510         opsaveeditbuffer ();
00511         
00512         fl = opcopyoutlinerecord (ho, &hcopy);
00513         
00514         oprestoreeditbuffer ();
00515         
00516         (**ho).copyrefconcallback = &mecopyrefconroutine;
00517         
00518         (**ho).releaserefconcallback = &mereleaserefconroutine;
00519         
00520         if (!fl)
00521             goto exit;
00522         
00523         ho = opsetoutline (hcopy); /*work on copy*/
00524         }
00525     
00526     if (fl) {
00527     
00528         if (flmemory) {
00529             
00530             dbpushdatabase (megetdatabase (hm));
00531             
00532             fl = mepackmenustructure (&info, hpacked);
00533             
00534             dbpopdatabase ();
00535             }
00536         else {
00537             fl = mesavemenustructure (&info, adr);
00538             
00539             if (fl && (!fldatabasesaveas))
00540                 (**hm).adroutline = conditionallongswap(info.adroutline);
00541             }
00542         }
00543     
00544     if (flpreservelinks) {
00545         
00546         opdisposeoutline (ho, false); /*dispose copy*/
00547         
00548         opsetoutline ((**hm).menuoutline); /*restore original*/
00549         }
00550     
00551     exit:
00552     
00553     oprestorehoists (); /*restore the hoist state*/
00554     
00555     oppopoutline (); /*pop outline globals*/
00556     
00557     return (fl);
00558     } /*mesavemenurecord*/
00559 
00560 
00561 boolean mesetupmenurecord (tysavedmenuinfo *info, hdloutlinerecord houtline, hdlmenurecord *hmenurecord) { 
00562     
00563     /*
00564     create a new menu record with the given outline and setup info
00565     
00566     2/26/91 dmb: commented-out assignment into outline's vertical scroll 
00567     position, and use of info.lnumcursor.  all this stuff should already 
00568     be saved with the outline.  note: if it turns out that we need to 
00569     assign lnumcursor into movecursorto, we need to defeat it during 
00570     searches
00571     
00572     4/22/91 dmb: menu outline now points to menu variable
00573     */
00574     
00575     register tysavedmenuinfo *lpi = info;
00576     register hdlmenurecord hm;
00577     register hdloutlinerecord ho;
00578     short fontnum;
00579     
00580     if (!newclearhandle (sizeof (tymenurecord), (Handle *) hmenurecord))
00581         return (false);
00582     
00583     hm = *hmenurecord; /*copy into register*/
00584     
00585     ho = houtline; /*copy into register*/
00586     
00587     mesetcallbacks (ho); /*link in callback routines*/
00588     
00589     (**hm).menuoutline = ho; 
00590     
00591     (**ho).outlinerefcon = (long) hm; /*pointing is mutual*/
00592     
00593     (**hm).adroutline = conditionallongswap((*lpi).adroutline); /*keep address around for save*/
00594     
00595     diskrecttorect (&(*lpi).scriptwindowrect, &(**hm).scriptwindowrect);
00596     
00597     (**hm).flautosmash = ((*lpi).flags & flautosmash_mask) != 0;
00598     
00599     diskrecttorect (&(*lpi).menuwindowrect, &(**hm).menuwindowrect);
00600     
00601     diskgetfontnum ((*lpi).defaultscriptfontname, &fontnum);
00602     
00603     (**hm).defaultscriptfontnum = fontnum;
00604     
00605     (**hm).defaultscriptfontsize = conditionalshortswap((*lpi).defaultscriptfontsize);
00606     
00607     (**hm).menuactiveitem = menuoutlineitem;
00608     
00609     return (true);
00610     } /*mesetupmenurecord*/
00611 
00612 
00613 static boolean meunpackscriptvisit (hdlheadrecord hnode, ptrvoid refcon) {
00614     
00615     /*
00616     4/30/91 dmb: set dirty bit on outline to make sure it gets saved
00617     */
00618     
00619     register hdlheadrecord h = hnode;
00620     ptrpackinfo packinfo = (ptrpackinfo) refcon;
00621     hdloutlinerecord houtline;
00622     tymenuiteminfo item;
00623     
00624     if (!megetmenuiteminfo (h, &item)) /*nothing linked, keep visiting*/
00625         return (true);
00626     
00627     if (!item.linkedscript.adrlink && !item.linkedscript.houtline) /*no linked script*/
00628         return (true);
00629     
00630     if (!opunpack ((*packinfo).hpackedscripts, &(*packinfo).ixpackedscripts, &houtline)) /*memory error, stop visiting*/
00631         return (false);
00632     
00633     (**houtline).fldirty = true; /*make sure it gets saved*/
00634     
00635     item.linkedscript.houtline = houtline; /*in memory*/
00636     
00637     item.linkedscript.adrlink = nildbaddress; /*never saved to disk*/
00638     
00639     return (mesetmenuiteminfo (h, &item));
00640     } /*meunpackscriptvisit*/
00641 
00642 
00643 boolean meunpackmenustructure (Handle hpacked, hdlmenurecord *hmenurecord) {
00644     
00645     /*
00646     analagous to meloadmenurecord below, except the entire structure is 
00647     to be unpacked from the handle hpacked.
00648     
00649     9/25/91 dmb: use new testheapspace instead of haveheapspace for preflighting. 
00650     the latter doesn't generate an error, so we could have failed silently.
00651     */
00652     
00653     Handle hpackedmenu;
00654     hdlheadrecord hsummit;
00655     hdloutlinerecord ho;
00656     register boolean fl;
00657     tysavedmenuinfo info;
00658     long ix = 0;
00659     typackinfo packinfo;
00660     
00661     assert (sizeof (tysavedmenuinfo) == sizeof (tyOLD42savedmenuinfo));
00662     
00663     if (!unmergehandles (hpacked, &hpackedmenu, &packinfo.hpackedscripts)) /*consumes hpacked*/
00664         return (false);
00665     
00666 //  oppushoutline (nil); /*preserve global*/
00667     
00668     fl = loadfromhandle (hpackedmenu, &ix, sizeof (info), &info);
00669     
00670     info.adroutline = nildbaddress; /*never been saved*/
00671     
00672     if (fl)
00673         fl = opunpack (hpackedmenu, &ix, &ho);
00674     
00675 //  ho = outlinedata; /*save in register.  may be nil*/
00676     
00677     disposehandle (hpackedmenu);
00678     
00679     if (fl)
00680         fl = mesetupmenurecord (&info, ho, hmenurecord);
00681     
00682     if (fl)
00683         fl = testheapspace (gethandlesize (packinfo.hpackedscripts)); /*a little preflighting*/
00684     
00685     if (fl) {
00686         
00687         packinfo.ixpackedscripts = 0; /*offset into hpackedscripts*/
00688         
00689         oppushoutline (ho);
00690         
00691         opoutermostsummit (&hsummit);
00692         
00693         fl = opsiblingvisiter (hsummit, false, &meunpackscriptvisit, &packinfo);
00694         
00695         oppopoutline ();
00696         }
00697     
00698     disposehandle (packinfo.hpackedscripts);
00699     
00700     if (!fl)
00701         opdisposeoutline (ho, false); /*checks for nil*/
00702     
00703 //  oppopoutline (); /*restore global*/
00704     
00705     return (fl);
00706     } /*meunpackmenustructure*/
00707 
00708 
00709 boolean meloadmenurecord (dbaddress adr, hdlmenurecord *hmenurecord) { 
00710     
00711     hdloutlinerecord houtline;
00712     tysavedmenuinfo info;
00713     
00714     if (!dbreference (adr, sizeof (info), &info))
00715         return (false);
00716     
00717     if (!meloadoutline (conditionallongswap (info.adroutline), &houtline))
00718         return (false);
00719     
00720     if (!mesetupmenurecord (&info, houtline, hmenurecord)) {
00721         
00722         opdisposeoutline (houtline, false);
00723         
00724         return (false);
00725         }
00726     
00727     return (true);
00728     } /*meloadmenurecord*/
00729 
00730 
00731 static void medisposescrap (hdloutlinerecord houtline) {
00732     
00733     opdisposeoutline (houtline, false);
00734     } /*medisposescrap*/
00735 
00736 
00737 static boolean meexportscrap (hdloutlinerecord houtline, tyscraptype totype, Handle *hexport, boolean *fltempscrap) {
00738     
00739     tysavedmenuinfo info;
00740     boolean fl;
00741     
00742     *fltempscrap = true; /*usually the case*/
00743     
00744     switch (totype) {
00745         
00746         case menuscraptype: /*export flat version for system scrap*/
00747             
00748             oppushoutline (houtline);
00749             
00750             clearbytes (&info, sizeof (info));
00751             
00752             fl = mepackmenustructure (&info, hexport);
00753             
00754             oppopoutline ();
00755             
00756             return (fl);
00757         
00758         case opscraptype:
00759             *hexport = (Handle) houtline; /*op and script scraps are the same*/
00760             
00761             *fltempscrap = false; /*it's the original, not a copy*/
00762             
00763             return (true);
00764         
00765         case textscraptype:
00766             return (opoutlinetonewtextscrap (houtline, hexport));
00767         
00768         default:
00769             return (false);
00770         }
00771     } /*meexportscrap*/
00772 
00773 
00774 boolean mesetscraproutine (hdloutlinerecord houtline) {
00775     
00776     return (shellsetscrap ((Handle) houtline, menuscraptype,
00777                                 (shelldisposescrapcallback) &medisposescrap,
00778                                 (shellexportscrapcallback) &meexportscrap));
00779     } /*mesetscraproutine*/
00780 
00781 
00782 boolean megetscraproutine (hdloutlinerecord *houtline, boolean *fltempscrap) {
00783     
00784     Handle hscrap;
00785     tyscraptype scraptype;
00786     
00787     if (!shellgetscrap (&hscrap, &scraptype))
00788         return (false);
00789     
00790     if (scraptype == menuscraptype) {
00791         
00792         *houtline = (hdloutlinerecord) hscrap;
00793         
00794         *fltempscrap = false; /*we're returning a handle to the actual scrap*/
00795         
00796         return (true);
00797         }
00798     
00799     return (shellconvertscrap (opscraptype, (Handle *) houtline, fltempscrap));
00800     } /*megetscraproutine*/
00801 
00802 
00803 boolean mescraphook (Handle hscrap) {
00804     
00805     /*
00806     if our private type is on the external clipboard, set the internal 
00807     scrap to it.
00808     */
00809     
00810     if (getscrap (menuscraptype, hscrap)) {
00811         
00812         hdlmenurecord hmenurecord;
00813         
00814         if (meunpackmenustructure (hscrap, &hmenurecord)) {
00815             
00816             mesetscraproutine ((**hmenurecord).menuoutline);
00817             
00818             (**hmenurecord).menuoutline = nil;
00819             
00820             medisposemenurecord (hmenurecord, false);
00821             }
00822         
00823         return (false); /*don't call any more hooks*/
00824         }
00825     
00826     return (true); /*keep going*/
00827     } /*mescraphook*/
00828 
00829 

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