outlineland.c

Go to the documentation of this file.
00001 
00002 /*  $Id: outlineland.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 <Packages.h>
00029 #include <GestaltEqu.h>
00030 #include "op.h"
00031 #include "opinternal.h"
00032 #include "wpengine.h"
00033 #include "outlinewires.h"
00034 #include "outlinefinder.h"
00035 #include "launch.h"
00036 
00037 
00038 
00039 
00040 #define fastinserttoken 'fins'
00041 
00042 #define namecolwidth    180
00043 #define kindcolwidth    40
00044 
00045 #define findersmalliconlist 131 /*miscellaneous small icons*/
00046 
00047 
00048 enum {
00049     
00050     desktopicon = 0,
00051     diskicon,
00052     appleshareicon,
00053     whitefoldericon,
00054     blackfoldericon,
00055     applicationicon,
00056     documenticon,
00057     stationeryicon,
00058     trashcanicon,
00059     macintoshicon,
00060     lockedicon,
00061     whiteopenfoldericon,
00062     blackopenfoldericon
00063     } tyfindericon;
00064 
00065 
00066 
00067 
00068 typedef struct tydata { /*what app.appdata points to*/
00069     
00070     boolean flactive;
00071     
00072     hdloutlinerecord heditrecord;
00073     
00074     boolean displaydirty; /*if true, window is updated on next idle loop*/
00075     
00076     Handle hinsertedtext; /*used in implementing the fast insert event*/
00077     
00078     PicHandle macpicture; /*used for printing*/
00079     } tydata, **hdldata;
00080 
00081 
00082 typedef struct tyoptionsrecord { /*information we save in every data file*/
00083     
00084     short selstart, selend;
00085     
00086     char waste [64];
00087     } tyoptionsrecord, **hdloptionsrecord;
00088 
00089 
00090 
00091     
00092 static boolean setglobals (void) {
00093     
00094     hdldata hd = (hdldata) app.appdata;
00095     
00096     if (hd != nil) { /*a window is open*/
00097     
00098         outlinedata = (**hd).heditrecord;
00099         
00100         outlinewindow = (**app.appwindow).macwindow;
00101         
00102         outlinewindowinfo = app.appwindow;
00103         
00104         if (opeditsetglobals ())
00105             wpsetglobals ();
00106         }
00107     
00108     return (true);
00109     } /*setglobals*/
00110 
00111 
00112 static boolean preexpand (hdlheadrecord hnode, short ctlevels) {
00113     
00114     register hdloutlinerecord ho = outlinedata;
00115     
00116     if ((**hnode).headlinkright != hnode)
00117         return (true);
00118     
00119     if ((**hnode).flfolder) {
00120         
00121         opstartinternalchange ();
00122         
00123         opfinderexpand (hnode, ctlevels);
00124         
00125         opendinternalchange ();
00126         }
00127     
00128     return (true);
00129     } /*preexpand*/
00130 
00131 
00132 static boolean postcollapse (hdlheadrecord hnode) {
00133     
00134     killundo ();
00135     
00136     opstartinternalchange ();
00137     
00138     opdeletesubs (hnode);
00139     
00140     opendinternalchange ();
00141     
00142     return (true);
00143     } /*postcollapse*/
00144 
00145 
00146 static short geticonnum (hdlheadrecord hnode) {
00147     
00148     tyfinderinfo info;
00149     
00150     if (opgetrefcon (hnode, &info, sizeof (info))) {
00151         
00152         if (info.flvolume)
00153             return (diskicon);
00154         
00155         if (info.flfolder)
00156             return (whitefoldericon);
00157         
00158         if (info.filetype == 'APPL')
00159             return (applicationicon);
00160         
00161         if (info.flstationery)
00162             return (stationeryicon);
00163         }
00164     
00165     if (hnode == (**outlinedata).hsummit)
00166         return (macintoshicon);
00167     
00168     return (documenticon);
00169     } /*geticonnum*/
00170 
00171 
00172 static boolean measureline (hdlheadrecord hnode) {
00173     
00174     } /*measureline*/
00175 
00176 
00177 static ostypetostring (OSType type, bigstring bs) {
00178     
00179     bs [0] = 4;
00180     
00181     moveleft (&type, &bs [1], 4);
00182     } /*ostypetostring*/
00183 
00184     
00185 static boolean drawline (hdlheadrecord hnode) {
00186     
00187     register hdlheadrecord h = hnode;
00188     Point pt;
00189     Rect r;
00190     short listnum;
00191     short iconnum;
00192     tyfinderinfo info;
00193     byte typestring [6];
00194     boolean fltextmode = opeditingtext (hnode);
00195     
00196     opgetrefcon (hnode, &info, sizeof (info));
00197     
00198     GetPen (&pt);
00199     
00200     setrect (&r, pt.v - 12, pt.h - 2, pt.v + 4, pt.h + 14);
00201     
00202     listnum = findersmalliconlist;
00203     
00204     if (fltextmode)
00205         ++listnum;
00206     
00207     plotsmallicon (r, listnum, geticonnum (h), false);
00208     
00209     movepento (pt.h + widthsmallicon, pt.v);
00210     
00211     if (info.flalias)       
00212         pushstyle ((**outlinedata).fontnum, (**outlinedata).fontsize, italic);
00213     
00214     if (fltextmode)
00215         opeditupdate ();
00216     else
00217         pendrawstring ((**h).headstring);
00218     
00219     if (info.flalias)
00220         popstyle (); 
00221     
00222     movepento (pt.h + namecolwidth, pt.v);
00223     
00224     ostypetostring (info.filetype, typestring);
00225     
00226     pendrawstring (typestring);
00227     
00228     return (true);
00229     } /*drawline*/
00230 
00231 
00232 static boolean mouseinline (hdlheadrecord hnode) {
00233     
00234     register hdloutlinerecord ho = outlinedata;
00235     Point pt = mousestatus.localpt;
00236     FSSpec fs;
00237     boolean flredraw = false;
00238     
00239     if (!(**ho).fltextmode) { /*changed!*/
00240         
00241         (**ho).flcursorneedsdisplay = true; /*make sure opmoveto does something*/
00242         
00243         (**ho).fltextmode = true;
00244         
00245         flredraw = true;
00246         }
00247     
00248     opclearallmarks ();
00249     
00250     opmoveto (hnode); /*potentially re-position the bar cursor*/ 
00251     
00252     if (flredraw)
00253         opinvalnode (hnode);
00254     
00255     opupdatenow (); /*be sure any changes are visible now*/
00256     
00257     if (pt.h > optextindent (hnode) - 3)
00258         opeditclick (pt);
00259     
00260     else {
00261         if ((**hnode).flhfsnode) {
00262             
00263             opeditselectall ();
00264             
00265             if (mousestatus.fldoubleclick) {
00266                 
00267                 if (opgetfilespec (hnode, &fs))
00268                     launchusingfinder (fs);
00269                 }
00270             }
00271         }
00272     
00273     return (false); /*we've handled it*/
00274     } /*mouseinline*/
00275 
00276     
00277 static boolean hasdynamicsubs (hdlheadrecord hnode) {
00278     
00279     tyfinderinfo info;
00280     
00281     if (opgetrefcon (hnode, &info, sizeof (info)))
00282         return (info.ctfiles > 0);
00283     
00284     return (false);
00285     } /*hasdynamicsubs*/
00286 
00287 
00288 static boolean getlinedisplayinfo (hdlheadrecord hnode, Rect *prect, short *textstart) {
00289     
00290     /*
00291     make adjust rect and textstart to account for our icons
00292     */
00293     
00294     *textstart += widthsmallicon;
00295     
00296     /*
00297     (*prect).right += widthsmallicon;
00298     */
00299     
00300     (*prect).right = *textstart + widthsmallicon + namecolwidth + kindcolwidth;
00301     
00302     return (true);
00303     } /*opgetnodedisplayinfo*/
00304 
00305 
00306 static boolean textchanged (hdlheadrecord hnode, bigstring bsorig) {
00307     
00308     return (opfindertextchanged (hnode, bsorig));
00309     } /*textchanged*/
00310 
00311 
00312 static boolean lineinserted (hdlheadrecord hnode) {
00313     
00314     return (opfinderlineinserted (hnode));
00315     } /*lineinserted*/
00316 
00317 
00318 static boolean linedeleted (hdlheadrecord hnode) {
00319     
00320     return (opfinderlinedeleted (hnode));
00321     } /*linedeleted*/
00322 
00323 
00324 static boolean setscrollbars (void) {
00325     
00326     register hdloutlinerecord ho = outlinedata;
00327     register hdlappwindow ha = app.appwindow;
00328     
00329     setscrollbarinfo ((**ha).vertbar, (**ho).vertmin, (**ho).vertmax, (**ho).vertcurrent);
00330     
00331     setscrollbarinfo ((**ha).horizbar, (**ho).horizmin, (**ho).horizmax, (**ho).horizcurrent);
00332     } /*setscrollbars*/
00333 
00334 
00335 static void setupoutline (void) {
00336     
00337     register hdloutlinerecord ho = outlinedata;
00338     
00339     (**ho).flwindowopen = true;
00340     
00341     (**ho).preexpandcallback = &preexpand;
00342     
00343     (**ho).postcollapsecallback = &postcollapse;
00344     
00345     (**ho).getlinedisplayinfocallback = (callback) &getlinedisplayinfo;
00346     
00347     /*
00348     (**ho).measurelinecallback = (callback) &measureline;
00349     */
00350     
00351     (**ho).drawlinecallback = (callback) &drawline; /*the normal text-drawing routine*/
00352     
00353     (**ho).mouseinlinecallback = &mouseinline;
00354     
00355     (**ho).hasdynamicsubscallback = (callback) &hasdynamicsubs;
00356     
00357     (**ho).textchangedcallback = (callback) &textchanged;
00358     
00359     (**ho).insertlinecallback = (callback) &lineinserted;
00360     
00361     (**ho).deletelinecallback = (callback) &linedeleted;
00362     
00363     (**ho).copyrefconcallback = (callback) &opfindercopyrefcon;
00364     
00365     (**ho).releaserefconcallback = (callback) &opfinderreleaserefcon;
00366     
00367     (**ho).validatedragcallback = &opfindervalidatedrag;
00368     
00369     (**ho).predragcallback = &opfinderpredrag;
00370     
00371     (**ho).dragcopycallback = &opfinderdragcopy;
00372     
00373     (**ho).setscrollbarsroutine = setscrollbars;
00374     
00375     opgetdisplayinfo ();
00376     
00377     (**(**ho).hsummit).flfolder = true;
00378     } /*setupoutline*/
00379 
00380     
00381 static boolean newrecord (void) {
00382     
00383     hdlappwindow ha = app.appwindow;
00384     hdldata hdata = nil;
00385     bigstring bs;
00386     boolean fl;
00387     
00388     if (!newclearhandle (longsizeof (tydata), (Handle *) &hdata))
00389         return (false);
00390     
00391     setstringlength (bs, 0);
00392     
00393     /*
00394     pushstyle ((**ha).defaultfont, (**ha).defaultsize, (**ha).defaultstyle);
00395     */
00396     
00397     outlinewindowinfo = ha;
00398     
00399     fl = opnewrecord ((**ha).contentrect);
00400     
00401     /*
00402     popstyle ();
00403     */
00404     
00405     if (!fl)
00406         goto error;
00407     
00408     /*
00409     (**outlinedata).dirtyroutine = (callback) &madechanges;
00410     */
00411     
00412     (**hdata).heditrecord = outlinedata;
00413     
00414     app.appdata = (Handle) hdata;
00415     
00416     setupoutline ();
00417     return (true);
00418     
00419     error:
00420     
00421     disposehandle ((Handle) hdata);
00422     
00423     return (false);
00424     } /*newrecord*/
00425 
00426 
00427 static boolean disposerecord (void) {
00428     
00429     hdldata hd = (hdldata) app.appdata;
00430     
00431     killundo ();
00432     
00433     opdisposeoutline ((**hd).heditrecord, false);
00434     
00435     disposehandle ((Handle) hd);
00436     
00437     return (true);
00438     } /*disposerecord*/
00439 
00440 
00441 static boolean activate (boolean flactive) {
00442     
00443     hdldata hd = (hdldata) app.appdata;
00444     
00445     (**hd).flactive = flactive;
00446     
00447     opactivate (flactive);
00448     
00449     return (true);
00450     } /*activate*/
00451     
00452     
00453 static boolean update (void) {
00454     
00455     opupdate ();
00456     
00457     return (true);
00458     } /*update*/
00459 
00460 
00461 static short comparestrings (bigstring bs1, bigstring bs2) {
00462 
00463     /*
00464     return zero if the two strings (pascal type, with length-byte) are
00465     equal.  return -1 if bs1 is less than bs2, or +1 if bs1 is greater than
00466     bs2.
00467     
00468     use the Machintosh international utility routine IUCompString, which 
00469     performs dictionary string comparison and accounts for accented characters
00470     */
00471     
00472     return (IUCompString (bs1, bs2));
00473     } /*comparestrings*/
00474 
00475 
00476 static hdlheadrecord op1stsibling (hdlheadrecord hnode) {
00477     
00478     while (opchaseup (&hnode)) {}
00479     
00480     return (hnode);
00481     } /*op1stsibling*/
00482 
00483 
00484 static boolean opfindhead (hdlheadrecord hfirst, bigstring bs, hdlheadrecord *hnode) {
00485     
00486     /*
00487     search starting with hfirst and step through its siblings looking
00488     for a headline that exactly matches bs.
00489     */
00490     
00491     register hdlheadrecord nomad, nextnomad;
00492     bigstring bsnomad;
00493     bigstring bsfind;
00494     bigstring bsbest;
00495     register hdlheadrecord hbest = nil; /*no candidate found*/
00496     
00497     *hnode = nil; /*default returned value*/
00498     
00499     nomad = op1stsibling (hfirst);
00500     
00501     copystring (bs, bsfind); /*work on a copy*/
00502     
00503     alllower (bsfind); /*unicase*/
00504     
00505     while (true) {
00506         
00507         getheadstring (nomad, bsnomad);
00508         
00509         alllower (bsnomad);
00510         
00511         switch (comparestrings (bsnomad, bsfind)) {
00512             
00513             case 0: /*string equal*/
00514                 *hnode = nomad;
00515                 
00516                 return (true);
00517             
00518             case -1: /*key less than name*/
00519                 break;
00520             
00521             case +1: /*key greather than name*/
00522                 if ((hbest == nil) || (comparestrings (bsnomad, bsbest) == -1)) {
00523                     
00524                     copystring (bsnomad, bsbest);
00525                     
00526                     hbest = nomad;
00527                     }
00528             }
00529         
00530         nextnomad = (**nomad).headlinkdown;
00531         
00532         if (nextnomad == nomad)
00533             break;
00534             
00535         nomad = nextnomad;
00536         } /*while*/
00537     
00538     if (hbest == nil) /*didn't find any item that would follow bsname*/
00539         hbest = nomad; /*select last name*/
00540     
00541     *hnode = hbest;
00542     
00543     return (false);
00544     } /*opfindhead*/
00545 
00546 
00547 static boolean opnavigationkey (byte chkey) {
00548     
00549     /*
00550     add chkey to the typing buffer bsselect, resetting the buffer 
00551     depending on elapsed time.  select the table entry that whose name 
00552     starts with a string equal to or greater than the resulting string.
00553     the net effect should be much like typing in standard file.
00554     
00555     note that statics  are used to retain information between calls.
00556     */
00557     
00558     static bigstring bsselection;
00559     static long timelastkey = 0L;
00560     register byte c = chkey;
00561     register long timethiskey;
00562     hdlheadrecord hnode;
00563     
00564     timethiskey = appletevent.when;
00565     
00566     if ((timethiskey - timelastkey) > (2 * KeyThresh)) /*long enough gap, reset*/
00567         setemptystring (bsselection);
00568     
00569     timelastkey = timethiskey; /*set up for next time*/
00570     
00571     pushchar (chkey, bsselection);
00572     
00573     opfindhead ((**outlinedata).hbarcursor, bsselection, &hnode);
00574     
00575     opmoveto (hnode);
00576     
00577     return (true);
00578     } /*opnavigationkey*/
00579 
00580 
00581 static boolean keystroke (void) { 
00582     
00583     register char ch = keyboardstatus.chkb;
00584     
00585     if (isprint (ch) && (keyboardstatus.ctmodifiers == 0)) {
00586         
00587         if (!(**outlinedata).fltextmode) {
00588             
00589             opnavigationkey (ch);
00590             
00591             return (true);
00592             }
00593         }
00594     
00595     opkeystroke ();
00596     
00597     return (true);
00598     } /*keystroke*/
00599     
00600 
00601 static boolean mousedown (void) {
00602     
00603     opmousedown (mousestatus.localpt);
00604     
00605     return (true);
00606     } /*mousedown*/
00607     
00608 
00609 /*
00610 static boolean scrollto (void) {
00611     
00612     hdlappwindow ha = app.appwindow;
00613     short dh, dv;
00614     register hdloutlinerecord ho = outlinedata;
00615     
00616     dh = getscrollbarcurrent ((**ha).horizbar) - (**ho).horizcurrent;
00617     
00618     dv = getscrollbarcurrent ((**ha).vertbar) / getfontheight () - (**ho).vertcurrent;
00619     
00620     switch (sgn (dh)) {
00621         
00622         case 1:
00623             opscroll (left, false, dh);
00624             
00625             break;
00626         
00627         case -1:
00628             opscroll (right, false, -dh);
00629             
00630             break;
00631         }
00632     
00633     switch (sgn (dv)) {
00634         
00635         case 1:
00636             opscroll (up, false, dv);
00637             
00638             break;
00639         
00640         case -1:
00641             opscroll (down, false, -dv);
00642             
00643             break;
00644         }
00645     
00646     return (true);
00647     } /*scrollto*/
00648     
00649 
00650 static boolean packrecord (Handle *hpacked) {
00651     
00652     return (oppack (hpacked));
00653     } /*packrecord*/
00654     
00655     
00656 static boolean unpackrecord (Handle hpacked) {
00657     
00658     /*
00659     In the Applet Toolkit, when a file is opened, the app's newrecord callback is called, 
00660     then the app's unpack callback is called. In Frontier it works differently -- the unpack 
00661     callback is expected to allocate a new record. 
00662     */
00663     
00664     hdldata hd = (hdldata) app.appdata;
00665     register hdlappwindow ha = app.appwindow;
00666     hdloutlinerecord houtline;
00667     long ixload = 0;
00668     hdloutlinerecord ho;
00669     
00670     opdisposeoutline ((**hd).heditrecord, false);
00671     
00672     (**hd).heditrecord = nil;
00673     
00674     if (!opunpack (hpacked, &ixload))
00675         return (false);
00676     
00677     ho = outlinedata;
00678     
00679     (**hd).heditrecord = ho;
00680     
00681     (**ho).windowrect = (**ha).windowrect;
00682     
00683     (**ho).outlinerect = (**ha).contentrect;
00684     
00685     setupoutline ();
00686     
00687     opgetdisplayinfo ();
00688     
00689     /***scrollto (); /*use current values of scrollbar to determine position*/
00690     
00691     return (true);
00692     } /*unpackrecord*/
00693     
00694     
00695 static boolean getcontentsize (void) {
00696     
00697     hdlappwindow ha = app.appwindow;
00698     long height, width;
00699     
00700     opgetoutinesize (&width, &height);
00701     
00702     (**ha).zoomheight = height;
00703     
00704     (**ha).zoomwidth = width;
00705     
00706     return (true);
00707     } /*getcontentsize*/
00708     
00709 
00710 static boolean windowresize (void) {
00711     
00712     hdlappwindow ha = app.appwindow;
00713     Rect r1 = (**ha).contentrect;
00714     Rect r2 = (**ha).oldcontentrect;
00715     
00716     /*
00717     InsetRect (&(**ha).contentrect, texthorizinset, textvertinset);
00718     
00719     InsetRect (&(**ha).oldcontentrect, texthorizinset, textvertinset);
00720     */
00721     
00722     opresize ((**ha).contentrect);
00723     
00724     /*
00725     (**ha).contentrect = r1;
00726     
00727     (**ha).oldcontentrect = r2;
00728     */
00729     
00730     return (true);
00731     } /*windowresize*/
00732     
00733     
00734 static boolean selectall (void) {
00735     
00736     opselectall ();
00737         
00738     return (true);
00739     } /*selectall*/
00740 
00741 
00742 static boolean haveselection (void) {
00743     
00744     return (true);
00745     } /*haveselection*/
00746 
00747 
00748 static boolean setselectioninfo (void) {
00749     
00750     return (opsetselectioninfo ());
00751     } /*setselectioninfo*/
00752     
00753         
00754 static boolean setfont (void) {
00755     
00756     pushundoaction (undoformatstring);
00757     
00758     opsetfont ((**outlinewindowinfo).selectioninfo.fontnum);
00759     
00760     return (true);
00761     } /*setfont*/
00762     
00763     
00764 static boolean setfontsize (void) {
00765     
00766     pushundoaction (undoformatstring);
00767     
00768     opsetsize ((**outlinewindowinfo).selectioninfo.fontsize);
00769     
00770     return (true);
00771     } /*setfontsize*/
00772     
00773     
00774 static boolean setstyle (void) {
00775     
00776     return (false);
00777     } /*setstyle*/
00778 
00779 
00780 static boolean deleteselectedtext (void) {
00781     
00782     opclear ();
00783     
00784     opfindercommitchanges ();
00785     
00786     return (true);
00787     } /*deleteselectedtext*/
00788 
00789 
00790 static boolean copy (Handle *hpacked) {
00791     
00792     Handle hscrap;
00793     tyscraptype type;
00794     boolean flconverted;
00795     
00796     if(!opcopy ())
00797         return (false);
00798     
00799     if (!shellgetscrap (&hscrap, &type))
00800         return (false);
00801     
00802     if (type == opscraptype) /*structure scrap*/
00803         opfinderexportscrap ((hdloutlinerecord) hscrap);
00804     
00805     hscrap = nil;
00806     
00807     if (exportshellscrap (type, &hscrap, &flconverted)) { /*force conversion to contiguous form*/
00808         
00809         assert (flconverted);
00810         
00811         if (enlargehandle (hscrap, sizeof (type), &type))
00812             *hpacked = hscrap;
00813         else
00814             disposehandle (hscrap);
00815         }
00816     
00817     /*shelldisposescrap ();*/ /*leave around for ensuing copytext call*/
00818     
00819     return (true);  
00820     } /*copy*/
00821 
00822 
00823 static boolean paste (Handle hpacked) {
00824     
00825     Handle hscrap;
00826     tyscraptype type;
00827     
00828     /*if (opscraphook (hpacked) && wpscraphook (hpacked)) { /*neither hook bit*/
00829     
00830     if (!shellgetscrap (&hscrap, &type)) {
00831         
00832         if (!popfromhandle (hpacked, sizeof (type), &type))
00833             return (false);
00834         
00835         shellsetscrap (hpacked, type, (callback) &disposehandle, nil);
00836         }
00837     
00838     oppaste ();
00839     
00840     /*shelldisposescrap ();*/
00841     
00842     return (true);
00843     } /*paste*/
00844 
00845 
00846 static boolean copytext (Handle *htext) {
00847     
00848     Handle hscrap = nil;
00849     tyscraptype type;
00850     boolean flconverted = false;
00851     
00852     if (!exportshellscrap (textscraptype, &hscrap, &flconverted)) { /*not part of clipboard sequence*/
00853         
00854         if (!opcopy ())
00855             return (false);
00856         
00857         if (!exportshellscrap (textscraptype, &hscrap, &flconverted))
00858             return (false);
00859         }
00860     
00861     assert (flconverted);
00862     
00863     *htext = hscrap;
00864     
00865     /*shelldisposescrap ();*/
00866     
00867     return (flconverted);
00868     } /*copytext*/
00869 
00870 
00871 static boolean pastetext (Handle htext) {
00872     
00873     shellsetscrap (htext, textscraptype, (callback) &disposehandle, nil);
00874     
00875     oppaste ();
00876     
00877     shelldisposescrap ();
00878     
00879     return (true);
00880     } /*pastetext*/
00881 
00882 static boolean tryhandlefastverb (void) {
00883     
00884     if (app.appwindow == nil)
00885         return (false);
00886     
00887     return (handlefastverb ());
00888     } /*handlefastverb*/
00889 
00890 
00891 static boolean tryhandleverb (void) {
00892     
00893     if (app.appwindow == nil)
00894         return (false);
00895     
00896     return (handleverb ());
00897     } /*handleverb*/
00898 
00899 
00900     
00901 #ifdef xxxx
00902     
00903 static boolean fastinsertverb (void) {
00904     
00905     hdldata hd = (hdldata) app.appdata; 
00906     Handle hnewtext, htext;
00907     boolean fl;
00908     
00909     if (hd == nil) {
00910     
00911         IACreturnerror (1, "\pNo window open.");
00912         
00913         return (false);
00914         }
00915     
00916     if (!IACgettextparam (keyDirectObject, &hnewtext))
00917         return (false);
00918         
00919     htext = (**hd).hinsertedtext;
00920     
00921     if (htext == nil)
00922         fl = copyhandle (hnewtext, &htext);
00923     else
00924         fl = pushhandleonhandle (hnewtext, htext);
00925     
00926     if (!fl) {
00927     
00928         IACreturnerror (1, "\pOut of memory.");
00929         
00930         return (false);
00931         }
00932         
00933     (**hd).hinsertedtext = htext;
00934     
00935     return (IACreturntext (hnewtext));
00936     } /*fastinsertverb*/
00937 
00938 
00939 static boolean fastiacmessage (void) {
00940     
00941     /*
00942     these messages can be processed by system event handlers.
00943     */
00944     
00945     switch (IACgetverbtoken ()) {
00946         
00947         case fastinserttoken:
00948             fastinsertverb (); break;
00949         
00950         } /*switch*/
00951         
00952     return (true);
00953     } /*fastiacmessage*/
00954     
00955     
00956 static boolean getpicture (PicHandle *hpicture) {
00957     
00958     hdldata hd = (hdldata) app.appdata; 
00959     hdlappwindow ha = app.appwindow;
00960     WindowPtr w = (**ha).macwindow;
00961     Rect r;
00962     Point pt;
00963     
00964     *hpicture = nil; /*return value if error*/
00965     
00966     if (hd == nil) /*no data, it can't be our window*/
00967         return (false);
00968     
00969     pushmacport (w);
00970     
00971     r.top = 0;
00972     
00973     r.left = 0;
00974     
00975     r.bottom = infinity;
00976     
00977     r.right = infinity;
00978     
00979     apppushclip (r);
00980     
00981     *hpicture = OpenPicture (&r);
00982     
00983     pt = (**ha).scrollorigin; /*save so we can restore it*/
00984     
00985     (**ha).scrollorigin.h = 0;
00986     
00987     (**ha).scrollorigin.v = 0;
00988     
00989     update ();
00990     
00991     (**ha).scrollorigin = pt;
00992     
00993     ClosePicture ();
00994     
00995     apppopclip ();
00996     
00997     popmacport ();
00998     
00999     return (true);
01000     } /*getpicture*/
01001     
01002     
01003 static boolean pagesetup (void) {
01004     
01005     return (true);
01006     } /*pagesetup*/
01007 
01008 
01009 static boolean openprint (void) {
01010     
01011     hdldata hd = (hdldata) app.appdata; 
01012     Rect rpict, rpaper;
01013     PicHandle hpict;
01014     short ctpages, vpictpixels;
01015     
01016     getpicture (&hpict);
01017     
01018     (**hd).macpicture = hpict;
01019     
01020     rpict = (**hpict).picFrame;
01021     
01022     rpaper = app.printinfo.paperrect;
01023     
01024     vpictpixels = rpict.bottom - rpict.top;
01025     
01026     ctpages = vpictpixels / app.printinfo.vpagepixels;
01027     
01028     if (vpictpixels > (ctpages * app.printinfo.vpagepixels))
01029         ctpages++;
01030     
01031     app.printinfo.ctpages = ctpages;
01032     } /*openprint*/
01033 
01034 
01035 static boolean printpage (short pagenumber) {
01036     
01037     hdldata hd = (hdldata) app.appdata; 
01038     PicHandle macpicture = (**hd).macpicture;
01039     short hoffset, voffset;
01040     Rect rpict, rpaper;
01041     
01042     rpict = (**macpicture).picFrame;
01043     
01044     rpaper = app.printinfo.paperrect;
01045     
01046     hoffset = rpaper.left - rpict.left;
01047     
01048     voffset = (rpaper.top - rpict.top) - ((pagenumber - 1) * app.printinfo.vpagepixels) - 1;
01049     
01050     OffsetRect (&rpict, hoffset, voffset);
01051     
01052     DrawPicture (macpicture, &rpict);
01053     
01054     return (true);
01055     } /*printpage*/
01056     
01057     
01058 static boolean closeprint (void) {
01059     
01060     hdldata hd = (hdldata) app.appdata; 
01061     PicHandle hpict = (**hd).macpicture;
01062     
01063     if (hpict != nil) {
01064         
01065         KillPicture (hpict);
01066         
01067         (**hd).macpicture = nil;
01068         }
01069     } /*closeprint*/
01070 
01071 
01072 #endif
01073 
01074 
01075 static boolean idle (void) {
01076     
01077     /*
01078     this code is guaranteed to be running when minapp is the current context,
01079     not from a fast event handler. so we process display oriented tasks 
01080     generated by fast event handlers in this callback.
01081     */
01082     
01083     hdlappwindow ha = app.appwindow;
01084     hdldata hd = (hdldata) app.appdata;
01085     Point pt = mousestatus.localpt;
01086     
01087     if (hd == nil) {
01088         
01089         setcursortype (cursorisarrow);
01090         
01091         return (true);
01092         }
01093     
01094     opidle ();
01095     
01096     opfindercommitchanges ();
01097     
01098     opsetcursor ();
01099     
01100     return (true);
01101     } /*idle*/
01102 
01103 
01104 static boolean checkgestalts (void) {
01105     
01106     long attrs;
01107     
01108     if (Gestalt (gestaltFindFolderAttr, &attrs) != noErr)
01109         return (false);
01110     
01111     if ((attrs & (1 << gestaltFindFolderPresent)) == 0)
01112         return (false);
01113     
01114     return (true);
01115     } /*checkgestalts*/
01116 
01117 
01118 void main (void) {
01119 
01120     clearbytes (&app, longsizeof (app)); /*init all fields to 0*/
01121     
01122     app.creator = 'USOP';
01123     
01124     app.filetype = 'OPTX';
01125     
01126     app.notsaveable = true;
01127     
01128     app.resizeable = true;
01129     
01130     app.eraseonresize = true;
01131     
01132     app.horizscroll = true;
01133     
01134     app.vertscroll = true;
01135     
01136     app.usecolor = true;
01137     
01138     app.defaultfont = monaco;
01139     
01140     app.defaultsize = 9;
01141     
01142     app.defaultstyle = 0;
01143     
01144     app.setglobalscallback = &setglobals;
01145     
01146     app.newrecordcallback = &newrecord;
01147     
01148     app.updatecallback = &update;
01149     
01150     app.activatecallback = (tyappbooleancallback) &activate;
01151     
01152     app.disposerecordcallback = &disposerecord;
01153     
01154     app.keystrokecallback = &keystroke;
01155     
01156     app.mousecallback = &mousedown;
01157     
01158     app.idlecallback = &idle;
01159 
01160     app.packcallback = &packrecord;
01161     
01162     app.unpackcallback = &unpackrecord;
01163     
01164     app.windowresizecallback = &windowresize;
01165     
01166     /*
01167     app.scrolltocallback = &scrollto;
01168     */
01169     
01170     app.scrollcallback = &opscroll;
01171     
01172     app.resetscrollcallback = &opresetscrollbars;
01173     
01174     app.getcontentsizecallback = &getcontentsize;
01175     
01176     app.selectallcallback = &selectall;
01177     
01178     app.haveselectioncallback = &haveselection;
01179     
01180     app.setselectioninfocallback = &setselectioninfo;
01181     
01182     app.setfontcallback = &setfont;
01183     
01184     app.setsizecallback = &setfontsize;
01185     
01186     app.setstylecallback = &setstyle;
01187     
01188     app.clearcallback = &deleteselectedtext;
01189     
01190     app.copycallback = &copy;
01191     
01192     app.pastecallback = &paste;
01193     
01194     app.gettextcallback = &copytext;
01195     
01196     app.puttextcallback = &pastetext;
01197     
01198     app.getundoglobalscallback = &opeditgetundoglobals;
01199     
01200     app.setundoglobalscallback = &opeditsetundoglobals;
01201     
01202     app.iacmessagecallback = &tryhandleverb;
01203     
01204     app.iacfastmessagecallback = &tryhandlefastverb;
01205     
01206     /*
01207     
01208     app.gettextcallback = &copytext;
01209     
01210     app.puttextcallback = &pastetext;
01211     
01212     app.openprintcallback = &openprint;
01213     
01214     app.pagesetupcallback = &pagesetup;
01215     
01216     app.printpagecallback = (tyappshortcallback) &printpage;
01217     
01218     app.closeprintcallback = &closeprint;
01219     
01220     app.opendoccallback = &snuffyopendoc;
01221     */
01222     
01223     /*
01224     app.menucallback = &snuffymenufilter;
01225     */
01226     
01227     appletinitmanagers ();
01228     
01229     if (!checkgestalts ())
01230         return;
01231     
01232     initprint (); /*wp needs to know how big the paper rectangle is*/
01233     
01234     wpinit ();
01235     
01236     opprefs.fltabkeyreorg = false;
01237     
01238     if (!newappwindow ("\pOutLine Finder", true))
01239         return;
01240     
01241     runapplet ();
01242     
01243     shelldisposescrap ();
01244     } /*main*/
01245 
01246 
01247 

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