applettextedit.c

Go to the documentation of this file.
00001 
00002 /*  $Id: applettextedit.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 #include "frontier.h"
00007 #include "standard.h"
00008 
00009 #include "shelltypes.h"
00010 #include "appletdefs.h"
00011 #include "appletmemory.h"
00012 #include "appletfont.h"
00013 #include "appletstrings.h"
00014 #include "appletquickdraw.h"
00015 #include "applettextedit.h"
00016 
00017 
00018 
00019 typedef struct tyscrolldata {
00020     
00021     Rect origdestrect;
00022     
00023     short origlen;
00024     } tyscrolldata;
00025     
00026 tyscrolldata scrolldata;
00027 
00028 
00029 
00030 
00031 static boolean getmacbuffer (hdleditrecord hbuffer, TEHandle *macbuffer) {
00032 
00033     if (hbuffer == nil)
00034         return (false);
00035         
00036     *macbuffer = (**hbuffer).macbuffer;
00037     
00038     return (*macbuffer != nil);
00039     } /*getmacbuffer*/
00040     
00041 
00042 static void editprescroll (hdleditrecord hbuffer) {
00043 
00044     TEHandle macbuffer;
00045     
00046     if (!getmacbuffer (hbuffer, &macbuffer))
00047         return;
00048 
00049     scrolldata.origdestrect = (**macbuffer).destRect;
00050     
00051     scrolldata.origlen = (**macbuffer).teLength;
00052     } /*editprescroll*/
00053     
00054     
00055 static void editsetscrollvalues (hdleditrecord hbuffer) {
00056 
00057     TEHandle macbuffer;
00058     Rect destrect, viewrect;
00059     boolean flscrolled;
00060     
00061     if (!getmacbuffer (hbuffer, &macbuffer))
00062         return;
00063     
00064     flscrolled = scrolldata.origlen != (**macbuffer).teLength;
00065     
00066     if (!flscrolled)
00067         flscrolled = !equalrects (scrolldata.origdestrect, (**macbuffer).destRect);
00068     
00069     if (!(**hbuffer).flscrolled) /*DW 12/4/94*/
00070         (**hbuffer).flscrolled = flscrolled;
00071     
00072     destrect = (**macbuffer).destRect;
00073     
00074     viewrect = (**macbuffer).viewRect;
00075     
00076     (**hbuffer).vertcurrent = viewrect.top - destrect.top;
00077     
00078     (**hbuffer).horizcurrent = viewrect.left - destrect.left;
00079     } /*editsetscrollvalues*/
00080     
00081     
00082 static short getTEjustification (tyjustification justification) {
00083     
00084     switch (justification) {
00085         
00086         case leftjustified:
00087             return (teJustLeft);
00088             
00089         case centerjustified:
00090             return (teJustCenter);
00091             
00092         case rightjustified:
00093             return (teJustRight);
00094         
00095         default:
00096             return (teJustLeft);
00097         } /*switch*/
00098     } /*getTEjustification*/
00099     
00100 
00101 boolean editnewbuffer (Rect r, boolean flwordwrap, bigstring bs, hdleditrecord *hrecord) {
00102     
00103     hdleditrecord h;
00104     TEHandle macbuffer;
00105     
00106     if (!newclearhandle (longsizeof (tyeditrecord), (Handle *) hrecord))
00107         return (false);
00108         
00109     h = *hrecord; /*copy into register*/
00110     
00111     InsetRect (&r, texthorizinset, textvertinset);
00112         
00113     macbuffer = TENew (&r, &r);
00114     
00115     if (macbuffer == nil) { /*memory error*/
00116         
00117         disposehandle ((Handle) h);
00118         
00119         *hrecord = nil;
00120         
00121         return (false);
00122         }
00123         
00124     if (flwordwrap)
00125         (**macbuffer).crOnly = 1;
00126     else
00127         (**macbuffer).crOnly = -1;
00128 
00129     TESetText (&bs [1], (long) stringlength (bs), macbuffer);
00130     
00131     TEActivate (macbuffer);
00132     
00133     (**h).macbuffer = macbuffer;
00134     
00135     return (true);
00136     } /*editnewbuffer*/
00137     
00138     
00139 static boolean rectneedsupdate (Rect r) {
00140     
00141     boolean retVal;
00142     //Code change by Timothy Paustian Sunday, May 7, 2000 9:11:35 PM
00143     //Changed to Opaque call for Carbon
00144     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00145     {
00146         CGrafPtr thePort = GetQDGlobalsThePort();
00147         RgnHandle   visRgn = NewRgn();
00148         GetPortVisibleRegion(thePort, visRgn);
00149         retVal = RectInRgn(&r, visRgn);
00150         DisposeRgn(visRgn);
00151         return retVal;
00152     }
00153     #else
00154     WindowPtr w = (WindowPtr) quickdrawglobal (thePort);
00155     retVal = RectInRgn (&r, (*w).visRgn);
00156     return retVal;
00157     #endif
00158     } /*rectneedsupdate*/
00159     
00160     
00161 void editupdate (hdleditrecord hbuffer) {
00162     
00163     TEHandle macbuffer;
00164     Rect r, rerase;
00165     
00166     if (!getmacbuffer (hbuffer, &macbuffer))
00167         return;
00168         
00169     r = (**macbuffer).viewRect;
00170     
00171     if ((**macbuffer).teLength == 0)
00172         EraseRect (&r);
00173     
00174     TEUpdate (&r, macbuffer);
00175     
00176     InsetRect (&r, -(texthorizinset - 1), -(textvertinset - 1));
00177     
00178     /*erase the top sliver*/ {
00179     
00180         rerase = r; 
00181     
00182         rerase.bottom = rerase.top + textvertinset;
00183     
00184         if (rectneedsupdate (rerase)) 
00185             eraserect (rerase);
00186         }
00187     
00188     /*erase the bottom sliver*/ {
00189     
00190         rerase = r; 
00191     
00192         rerase.top = rerase.bottom - textvertinset;
00193     
00194         if (rectneedsupdate (rerase)) 
00195             eraserect (rerase);
00196         }
00197     
00198     /*erase the left sliver*/ {
00199     
00200         rerase = r; 
00201     
00202         rerase.right = rerase.left + texthorizinset;
00203         
00204         if (rectneedsupdate (rerase)) 
00205             eraserect (rerase);
00206         }
00207     
00208     /*erase the right sliver*/ {
00209     
00210         rerase = r; 
00211     
00212         rerase.left = rerase.right - texthorizinset;
00213         
00214         #if false /*DW 2/15/95 live with the schmutz for now -- it's breaking other things*/
00215         
00216             /*DW 1/28/95 hack for LSE -- noticed schmutz on the right edge when you resize to make the window narrower*/
00217             
00218             /*DW 1/6/96 -- LSE is no longer supported, no app record in MacBird Runtime
00219             
00220             if (app.creator == 'CAML')
00221                 rerase.right++; 
00222             */
00223         #endif
00224     
00225         if (rectneedsupdate (rerase)) 
00226             eraserect (rerase);
00227         }
00228     } /*editupdate*/
00229     
00230     
00231 void editupdateport (hdleditrecord hbuffer, Rect rport, WindowPtr w) {
00232     
00233     /*
00234     8/26/92 DW: update the TE handle, but do it in a port different from the
00235     one it lives inside of. need this to support printing in MinApp.
00236     
00237     9/3/92 DW: add "rport" parameter, to allow the caller to determine the
00238     temporary viewRect for the TE buffer.
00239     */
00240     
00241     TEHandle macbuffer;
00242     Rect oldview, olddest;
00243     WindowPtr oldport;
00244     
00245     if (!getmacbuffer (hbuffer, &macbuffer))
00246         return;
00247         
00248     oldview = (**macbuffer).viewRect; 
00249     
00250     olddest = (**macbuffer).destRect; 
00251     
00252     oldport = (WindowPtr) (**macbuffer).inPort; /* inPort is a GrafPtr */
00253     
00254     (**macbuffer).viewRect = rport;
00255     
00256     (**macbuffer).destRect = rport;
00257     
00258     (**macbuffer).inPort = (GrafPtr) w;
00259     
00260     TEUpdate (&rport, macbuffer);
00261     
00262     (**macbuffer).viewRect = oldview;
00263     
00264     (**macbuffer).destRect = olddest;
00265     
00266     (**macbuffer).inPort = (GrafPtr) oldport;
00267     } /*editupdateport*/
00268     
00269     
00270 void editactivate (hdleditrecord hbuffer, boolean flactive) {
00271     
00272     TEHandle macbuffer;
00273     
00274     if (!getmacbuffer (hbuffer, &macbuffer))
00275         return;
00276         
00277     if (flactive)
00278         TEActivate (macbuffer);
00279     else
00280         TEDeactivate (macbuffer);
00281     } /*editactivate*/
00282     
00283     
00284 void editsetrect (hdleditrecord hbuffer, Rect r) {
00285 
00286     TEHandle macbuffer;
00287 
00288     if (!getmacbuffer (hbuffer, &macbuffer))
00289         return;
00290         
00291     InsetRect (&r, texthorizinset, textvertinset);
00292             
00293     (**macbuffer).viewRect = r;
00294     
00295     /*if (!(**hbuffer).flwindowbased) -- commented DW 1/16/95 -- for Little Script Editor*/
00296         (**macbuffer).destRect = r;
00297     
00298     TECalText (macbuffer);
00299     
00300     /*editupdate (hbuffer);*/
00301     } /*editsetrect*/
00302     
00303     
00304 void editsetfont (hdleditrecord hbuffer, short fontnum, short fontsize) {
00305 
00306     TEHandle macbuffer;
00307 
00308     if (!getmacbuffer (hbuffer, &macbuffer))
00309         return;
00310         
00311     editprescroll (hbuffer);
00312     
00313     (**macbuffer).txFont = fontnum;
00314     
00315     (**macbuffer).txSize = fontsize;
00316     
00317     pushstyle (fontnum, fontsize, (**macbuffer).txFace);
00318     
00319     (**macbuffer).fontAscent = globalfontinfo.ascent;
00320     
00321     (**macbuffer).lineHeight = globalfontinfo.ascent + globalfontinfo.descent + globalfontinfo.leading;
00322     
00323     popstyle ();
00324         
00325     TECalText (macbuffer);
00326     
00327     editsetscrollvalues (hbuffer);
00328     
00329     (**hbuffer).flscrolled = true;
00330     } /*editsetfont*/
00331     
00332     
00333 void editautoscroll (hdleditrecord hbuffer) {
00334 
00335     TEHandle macbuffer;
00336 
00337     if (!getmacbuffer (hbuffer, &macbuffer))
00338         return;
00339         
00340     TEAutoView (true, macbuffer);
00341     } /*editautoscroll*/
00342     
00343     
00344 void editsetwordwrap (hdleditrecord hbuffer, boolean fl) {
00345     
00346     TEHandle macbuffer;
00347     short cronly;
00348 
00349     if (!getmacbuffer (hbuffer, &macbuffer))
00350         return;
00351     
00352     if (fl)
00353         cronly = 1; /*word-wrap on*/
00354     else
00355         cronly = -1; /*no word-wrap*/
00356         
00357     (**macbuffer).crOnly = cronly; 
00358     } /*editsetwordwrap*/
00359     
00360     
00361 void editrewrap (hdleditrecord hbuffer) {
00362 
00363     TEHandle macbuffer;
00364 
00365     if (!getmacbuffer (hbuffer, &macbuffer))
00366         return;
00367         
00368     editprescroll (hbuffer);
00369     
00370     TECalText (macbuffer);
00371     
00372     editsetscrollvalues (hbuffer);
00373     
00374     (**hbuffer).flscrolled = true;
00375     } /*editrewrap*/
00376     
00377 
00378 void editdispose (hdleditrecord hbuffer) {
00379     
00380     TEHandle macbuffer;
00381     
00382     if (!getmacbuffer (hbuffer, &macbuffer))
00383         return;
00384     
00385     TEDeactivate (macbuffer); /*remove the caret cursor, or unhighlight selection*/
00386     
00387     TEDispose (macbuffer);
00388         
00389     disposehandle ((Handle) hbuffer);
00390     } /*editdispose*/
00391 
00392 
00393 void editdrawtext (bigstring bs, Rect r, tyjustification justification) {
00394     
00395     InsetRect (&r, texthorizinset, textvertinset);
00396     
00397     TETextBox (&bs [1], stringlength (bs), &r, getTEjustification (justification));
00398     } /*editdrawtext*/
00399     
00400 
00401 void editdrawtexthandle (Handle htext, Rect r, tyjustification justification) {
00402     
00403     if (htext == nil)
00404         return;
00405         
00406     InsetRect (&r, texthorizinset, textvertinset);
00407     
00408     lockhandle (htext);
00409     
00410     TETextBox (*htext, GetHandleSize (htext), &r, getTEjustification (justification));
00411     
00412     unlockhandle (htext);
00413     } /*editdrawtexthandle*/
00414     
00415 
00416 void editcut (hdleditrecord hbuffer) {
00417     
00418     #ifdef onlineOutliner
00419         Handle htext;
00420         TEHandle macbuffer;
00421         
00422         if (editgetselectedtexthandle (hbuffer, &htext)) {
00423         
00424             ZeroScrap ();
00425         
00426             PutScrap (GetHandleSize (htext), 'TEXT', *htext);
00427         
00428             DisposeHandle (htext);
00429                     
00430             getmacbuffer (hbuffer, &macbuffer);
00431             
00432             if ((**macbuffer).selStart != (**macbuffer).selEnd)
00433                 TEDelete (macbuffer);
00434             }
00435     #else
00436         TEHandle macbuffer;
00437         
00438         if (!getmacbuffer (hbuffer, &macbuffer))
00439             return;
00440     
00441         editprescroll (hbuffer);
00442         
00443         TECut (macbuffer);
00444         //Code change by Timothy Paustian Sunday, June 25, 2000 9:52:36 PM
00445         //Update to new scrap manager API
00446         #if TARGET_API_MAC_CARBON == 1
00447         ClearCurrentScrap();
00448         #else
00449         ZeroScrap (); /*dmb 1.0b24*/
00450         #endif
00451         
00452         
00453         TEToScrap (); /*dmb 1.0b24*/
00454         
00455         editsetscrollvalues (hbuffer);
00456     #endif
00457     } /*editcut*/
00458 
00459 
00460 void editcopy (hdleditrecord hbuffer) {
00461     
00462     #ifdef onlineOutliner
00463         Handle htext;
00464         
00465         if (editgetselectedtexthandle (hbuffer, &htext)) {
00466             //Code change by Timothy Paustian Sunday, June 25, 2000 9:52:36 PM
00467         //Update to new scrap manager API
00468         #if TARGET_API_MAC_CARBON == 1
00469             ClearCurrentScrap();
00470             
00471             ScrapRef            theScrap;
00472             OSStatus            status;
00473             ScrapFlavorType     flavorType = (ScrapFlavorType) scraptype;
00474             ScrapFlavorFlags    flavorFlags = kScrapFlavorMaskNone;
00475             Size                flavorSize = GetHandleSize(hscrap);
00476             
00477             status = GetCurrentScrap(&theScrap);
00478             //I don't think this should be fatal, just beep to notify the user.
00479             if(status != noErr)
00480             {
00481                 SysBeep(30);
00482                 return;
00483             }
00484             HLock(hscrap);
00485             status = PutScrapFlavor (theScrap, 'TEXT', flavorFlags, flavorSize, *hscrap);
00486             HUnlock(hscrap);
00487             if(status != noErr)
00488             {
00489                 SysBeep(30);
00490                 return;
00491             }
00492             #else
00493             ZeroScrap ();
00494             PutScrap (GetHandleSize (htext), 'TEXT', *htext);
00495             #endif
00496             DisposeHandle (htext);
00497             }
00498     #else
00499         TEHandle macbuffer;
00500     
00501         if (!getmacbuffer (hbuffer, &macbuffer))
00502             return;
00503 
00504         TECopy (macbuffer);
00505         #if TARGET_API_MAC_CARBON == 1
00506         ClearCurrentScrap();
00507         #else   
00508         ZeroScrap (); /*dmb 1.0b24*/
00509         #endif
00510         TEToScrap (); /*dmb 1.0b24*/
00511         
00512     #endif
00513     } /*editcopy*/
00514 
00515 
00516 void editpaste (hdleditrecord hbuffer) {
00517     
00518     TEHandle macbuffer;
00519     
00520     if (!getmacbuffer (hbuffer, &macbuffer))
00521         return;
00522 
00523     editprescroll (hbuffer);
00524     
00525     TEFromScrap (); /*DW 4/8/95*/
00526         
00527     TEPaste (macbuffer);
00528     
00529     editsetscrollvalues (hbuffer);
00530     } /*editpaste*/
00531     
00532     
00533 boolean editgettext (hdleditrecord hbuffer, bigstring bs) {
00534 
00535     TEHandle macbuffer;
00536     short len;
00537     
00538     setstringlength (bs, 0);
00539     
00540     if (!getmacbuffer (hbuffer, &macbuffer))
00541         return (false);
00542 
00543     len = (**macbuffer).teLength;
00544     
00545     if (len > lenbigstring) /*8/17/93 DW*/
00546         len = lenbigstring;
00547         
00548     setstringlength (bs, len);
00549             
00550     moveleft (*(**macbuffer).hText, &bs [1], (long) len);
00551     
00552     return (true);
00553     } /*editgettext*/
00554 
00555 
00556 void editkeystroke (char chkb, hdleditrecord hbuffer) {
00557 
00558     TEHandle macbuffer;
00559     
00560     if (!getmacbuffer (hbuffer, &macbuffer))
00561         return;
00562     
00563     editprescroll (hbuffer);
00564     
00565     TEKey (chkb, macbuffer);
00566     
00567     editsetscrollvalues (hbuffer);
00568     } /*editkeystroke*/
00569     
00570     
00571 void editclick (Point pt, boolean flshiftkey, hdleditrecord hbuffer) {
00572 
00573     TEHandle macbuffer;
00574     
00575     if (!getmacbuffer (hbuffer, &macbuffer))
00576         return;
00577         
00578     editprescroll (hbuffer);
00579 
00580     pushclip ((**macbuffer).viewRect);
00581     
00582     TEClick (pt, flshiftkey, macbuffer);
00583     
00584     popclip ();
00585     
00586     editsetscrollvalues (hbuffer);
00587     } /*editclick*/
00588     
00589 
00590 boolean editsetselection (hdleditrecord hbuffer, short selstart, short selend) {
00591 
00592     TEHandle macbuffer;
00593     
00594     if (!getmacbuffer (hbuffer, &macbuffer))
00595         return (false);
00596         
00597     editprescroll (hbuffer);
00598 
00599     TESetSelect (selstart, selend, macbuffer);
00600     
00601     editsetscrollvalues (hbuffer);
00602         
00603     return (true);
00604     } /*editsetselection*/
00605     
00606     
00607 boolean editvisiselection (hdleditrecord hbuffer) { /*DW 1/16/95 -- new feature*/
00608 
00609     TEHandle macbuffer;
00610     
00611     if (!getmacbuffer (hbuffer, &macbuffer))
00612         return (false);
00613         
00614     editprescroll (hbuffer);
00615 
00616     TESelView (macbuffer);
00617     
00618     editsetscrollvalues (hbuffer);
00619         
00620     return (true);
00621     } /*editvisiselection*/
00622 
00623 
00624 void editselectall (hdleditrecord hbuffer) {
00625     
00626     editsetselection (hbuffer, 0, 32767);
00627     } /*editselectall*/
00628     
00629 
00630 void editidle (hdleditrecord hbuffer) {
00631     
00632     TEHandle macbuffer;
00633     
00634     if (!getmacbuffer (hbuffer, &macbuffer))
00635         return;
00636     
00637     if ((**hbuffer).flselectall) {
00638         
00639         editselectall (hbuffer);
00640         
00641         (**hbuffer).flselectall = false;
00642         }
00643     
00644     TEIdle (macbuffer);
00645     } /*editidle*/
00646     
00647     
00648 boolean editgetselection (hdleditrecord hbuffer, short *selstart, short *selend) {
00649 
00650     TEHandle macbuffer;
00651     
00652     if (!getmacbuffer (hbuffer, &macbuffer))
00653         return (false);
00654         
00655     *selstart = (**macbuffer).selStart;
00656     
00657     *selend = (**macbuffer).selEnd;
00658     
00659     return (true);
00660     } /*editgetselection*/
00661 
00662 
00663 boolean editpointinrect (Point pt, hdleditrecord hbuffer) {
00664 
00665     TEHandle macbuffer;
00666     
00667     if (!getmacbuffer (hbuffer, &macbuffer))
00668         return (false);
00669 
00670     return (PtInRect (pt, &(**macbuffer).viewRect));
00671     } /*editpointinrect*/
00672     
00673 
00674 boolean editreplace (bigstring bs, hdleditrecord hbuffer) {
00675 
00676     TEHandle macbuffer;
00677     
00678     if (!getmacbuffer (hbuffer, &macbuffer))
00679         return (false);
00680     
00681     editprescroll (hbuffer);
00682     
00683     if ((**macbuffer).selStart != (**macbuffer).selEnd)
00684         TEDelete (macbuffer);
00685     
00686     if (stringlength (bs) > 0)
00687         TEInsert (&bs [1], stringlength (bs), macbuffer);
00688     
00689     editsetscrollvalues (hbuffer);
00690     
00691     return (true); /*TE gives no way to return an error*/
00692     } /*editreplace*/
00693     
00694     
00695 void editsetjustification (tyjustification justification, hdleditrecord hbuffer) {
00696 
00697     TEHandle macbuffer;
00698     
00699     if (!getmacbuffer (hbuffer, &macbuffer))
00700         return;
00701     
00702     TESetAlignment (getTEjustification (justification), macbuffer);
00703     } /*editsetjustification*/
00704 
00705 
00706 void editgetsize (Handle htext, short *height, short *width) {
00707     
00708     /*
00709     return the size of a rectangle that could contain the indicated string
00710     observing the defaults for inset both vertically and horizontally, and 
00711     a minimum width for text display.
00712     
00713     assumes that the font/size/style info are correct in globalfontinfo.
00714     
00715     8/8/92 DW: upgrade to not use a bigstring to hold the text to be measured.
00716     we were encountering lines that were longer than 255 chars.
00717     
00718     12/30/92 DW: if you just deleted the last char of the buffer and it
00719     was a carriage return, we'd tell you that you have one more line than
00720     you actually have. I was tempted to fix the i <= textlength thing in 
00721     the for loop, but it broke other things. the klooginess is contained
00722     within this routine.
00723     */
00724     
00725     long textlength;
00726     long i;
00727     short ctlines = 1;
00728     short maxwidth = 0;
00729     short vertpixels;
00730     short ixlinestart = 0, linelength = 0;
00731     
00732     textlength = GetHandleSize (htext);
00733         
00734     for (i = 0; i <= textlength; i++) {
00735         
00736         char ch = (*htext) [i];
00737             
00738         if ((ch == chreturn) || (i == textlength)) {
00739             
00740             short w;
00741             
00742             HLock(htext);
00743             w = TextWidth (*htext, ixlinestart, linelength);
00744             HUnlock(htext);
00745             if (w > maxwidth)
00746                 maxwidth = w;
00747             
00748             if (i != textlength) { /*don't count the char after the last valid char*/
00749 
00750                 if (ch == chreturn)
00751                     ctlines++;
00752                 }
00753             
00754             ixlinestart += linelength + 1;
00755             
00756             linelength = 0;
00757             }
00758         else
00759             linelength++;
00760         } /*for*/
00761 
00762     maxwidth = max (maxwidth, mintextwidth);
00763     
00764     maxwidth += 2 * texthorizinset;
00765     
00766     maxwidth++; /*ask for one extra pixel, work around TE display anomaly*/
00767     
00768     *width = maxwidth;
00769     
00770     vertpixels = ctlines * (globalfontinfo.ascent + globalfontinfo.descent + globalfontinfo.leading);
00771     
00772     *height = vertpixels + (2 * textvertinset);
00773     } /*editgetsize*/
00774     
00775     
00776 void editgetbuffersize (hdleditrecord hbuffer, short *height, short *width) {
00777     
00778     /*
00779     8/8/92 DW for Snuffy: can't rely on the value for height returned by editgetsize, 
00780     since it doesn't take word-wrapping into account.
00781     */
00782     
00783     TEHandle macbuffer;
00784     char lastchar;
00785     
00786     if (!getmacbuffer (hbuffer, &macbuffer))
00787         return;
00788     
00789     editgetsize ((**macbuffer).hText, height, width);
00790     
00791     if ((**hbuffer).flwindowbased) {
00792     
00793         *height = ((**macbuffer).nLines * (**macbuffer).lineHeight) + globalfontinfo.descent;
00794         
00795         lastchar = (*(**macbuffer).hText) [(**macbuffer).teLength - 1];
00796         
00797         if (lastchar != chreturn) /*a quirk of TE*/
00798             *height += (**macbuffer).lineHeight;
00799         
00800         if ((**macbuffer).crOnly == 1) { /*word-wrapping turned on*/
00801         
00802             Rect r = (**macbuffer).destRect;
00803         
00804             *width = r.right - r.left;
00805             }
00806         }
00807         
00808     *width += 2 * texthorizinset;
00809     
00810     *height += 2 * textvertinset;
00811     } /*editgetbuffersize*/
00812     
00813     
00814 boolean editgettexthandle (hdleditrecord hbuffer, Handle *htext) {
00815     
00816     /*
00817     return the text handle from the edit buffer. do not dispose the handle or
00818     alter the length of the text.
00819     */
00820 
00821     TEHandle macbuffer;
00822     
00823     if (!getmacbuffer (hbuffer, &macbuffer))
00824         return (false);
00825         
00826     *htext = (**macbuffer).hText;
00827     
00828     return (true);
00829     } /*editgettexthandle*/
00830 
00831 
00832 boolean editnewbufferfromhandle (Rect r, boolean flwordwrap, Handle htext, hdleditrecord *hrecord) {
00833     
00834     hdleditrecord h;
00835     TEHandle macbuffer;
00836     
00837     if (!newclearhandle (longsizeof (tyeditrecord), (Handle *) hrecord))
00838         return (false);
00839         
00840     h = *hrecord; /*copy into register*/
00841     
00842     InsetRect (&r, texthorizinset, textvertinset);
00843         
00844     macbuffer = TENew (&r, &r);
00845     
00846     if (macbuffer == nil) { /*memory error*/
00847         
00848         disposehandle ((Handle) h);
00849         
00850         *hrecord = nil;
00851         
00852         return (false);
00853         }
00854         
00855     if (flwordwrap)
00856         (**macbuffer).crOnly = 1;
00857     else
00858         (**macbuffer).crOnly = -1;
00859 
00860     lockhandle (htext);
00861     
00862     TESetText (*htext, GetHandleSize (htext), macbuffer);
00863     
00864     unlockhandle (htext);
00865     
00866     TEActivate (macbuffer);
00867     
00868     (**h).macbuffer = macbuffer;
00869     
00870     return (true);
00871     } /*editnewbufferfromhandle*/
00872     
00873     
00874 boolean editsettexthandle (hdleditrecord hrecord, Handle htext, boolean flselectall) {
00875     
00876     /*
00877     if (!getmacbuffer (hrecord, &macbuffer))
00878         return (false);
00879     
00880     editprescroll (hrecord);
00881     
00882     lockhandle (htext);
00883     
00884     TESetText (*htext, GetHandleSize (htext), macbuffer);
00885     
00886     unlockhandle (htext);
00887     
00888     editsetscrollvalues (hrecord);
00889     */
00890     
00891     /*
00892     1.0b20 dmb: new implementation. The old version would not update 
00893     active text.
00894     */
00895     
00896     if (!editsetselection (hrecord, 0, infinity))
00897         return (false);
00898     
00899     if (!editreplacehandle (htext, hrecord))
00900         return (false);
00901     
00902     if (flselectall) 
00903         (**hrecord).flselectall = true;
00904     
00905     return (true);
00906     } /*editsettexthandle*/
00907     
00908     
00909 boolean editgettexthandlecopy (hdleditrecord hbuffer, Handle *htext) {
00910     
00911     /*
00912     caller must dispose of the handle we allocate.
00913     
00914     7/8/92 DW: if there is no text, return true with htext == nil.
00915     */
00916 
00917     TEHandle macbuffer;
00918     Handle h;
00919     
00920     if (!getmacbuffer (hbuffer, &macbuffer))
00921         return (false);
00922     
00923     h = (**macbuffer).hText;
00924     
00925     if (GetHandleSize (h) == 0) {
00926     
00927         *htext = nil;
00928         
00929         return (true);
00930         }
00931     
00932     return (copyhandle (h, htext));
00933     } /*editgettexthandlecopy*/
00934 
00935 
00936 boolean edithaveselection (hdleditrecord hbuffer) {
00937 
00938     TEHandle macbuffer;
00939     
00940     if (!getmacbuffer (hbuffer, &macbuffer))
00941         return (false);
00942     
00943     return ((**macbuffer).selStart != (**macbuffer).selEnd);
00944     } /*edithaveselection*/
00945     
00946     
00947 boolean editscroll (hdleditrecord hbuffer, short dh, short dv) {
00948 
00949     TEHandle macbuffer;
00950     
00951     if ((dh != 0) || (dv != 0)) {
00952     
00953         if (!getmacbuffer (hbuffer, &macbuffer))
00954             return (false);
00955             
00956         editprescroll (hbuffer);
00957         
00958         TEScroll (dh, dv, macbuffer);
00959         
00960         editsetscrollvalues (hbuffer);
00961         }
00962     
00963     return (true);
00964     } /*edithaveselection*/
00965     
00966     
00967 void editscrollto (hdleditrecord hbuffer, short h, short v) {
00968         
00969     TEHandle macbuffer;
00970     
00971     if (!getmacbuffer (hbuffer, &macbuffer))
00972         return;
00973     
00974     editsetscrollvalues (hbuffer);
00975     
00976     editscroll (hbuffer, (**hbuffer).horizcurrent - h, (**hbuffer).vertcurrent - v);
00977     } /*editscrollto*/
00978 
00979 
00980 boolean editreplacehandle (Handle htext, hdleditrecord hbuffer) {
00981 
00982     TEHandle macbuffer;
00983     
00984     if (!getmacbuffer (hbuffer, &macbuffer))
00985         return (false);
00986     
00987     editprescroll (hbuffer);
00988     
00989     if ((**macbuffer).selStart != (**macbuffer).selEnd)
00990         TEDelete (macbuffer);
00991         
00992     lockhandle (htext);
00993     
00994     TEInsert (*htext, GetHandleSize (htext), macbuffer);
00995     
00996     unlockhandle (htext);
00997     
00998     editsetscrollvalues (hbuffer);
00999     
01000     return (true); /*TE gives no way to return an error*/
01001     } /*editreplacehandle*/
01002     
01003     
01004 boolean editgetselectedtexthandle (hdleditrecord hbuffer, Handle *htext) {
01005 
01006     TEHandle macbuffer;
01007     short selstart, selend;
01008     short lensel;
01009     Handle h;
01010     boolean fl;
01011     
01012     if (!getmacbuffer (hbuffer, &macbuffer))
01013         return (false);
01014         
01015     selstart = (**macbuffer).selStart;
01016     
01017     selend = (**macbuffer).selEnd;
01018     
01019     lensel = selend - selstart;
01020     
01021     if (lensel < 0)
01022         lensel = 0;
01023         
01024     h = (**macbuffer).hText;
01025     
01026     lockhandle (h);
01027     
01028     fl = newfilledhandle (&((*h) [selstart]), (long) lensel, htext);
01029     
01030     unlockhandle (h);
01031     
01032     return (fl);
01033     } /*editgetselectedtexthandle*/
01034 
01035 
01036 
01037     
01038     

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