ioaedittext.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioaedittext.c 1197 2006-04-05 22:01:22Z karstenw $    */
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 <iac.h>
00032 #include <ioa.h>
00033 #include <ioaedittext.h>
00034 #include <appletkb.h>
00035 
00036 
00037 
00038 typedef struct typackedtextdata {
00039     
00040     short versionnumber;
00041     
00042     unsigned short bullets;
00043     
00044     long lenrealtext;
00045     
00046     unsigned short numericonly: 1; /*if true, only allow 0-9 to be entered*/
00047     
00048     unsigned short reservedbit1: 1;
00049     
00050     unsigned short reservedbit2: 1;
00051     
00052     unsigned short reservedbit3: 1;
00053     
00054     unsigned short reservedbit4: 1;
00055     
00056     unsigned short reservedbit5: 1;
00057     
00058     unsigned short reservedbit6: 1;
00059     
00060     unsigned short reservedbit7: 1;
00061     
00062     unsigned short reservedbit8: 1;
00063     
00064     unsigned short reservedbit9: 1;
00065     
00066     unsigned short reservedbit10: 1;
00067     
00068     unsigned short reservedbit11: 1;
00069     
00070     unsigned short reservedbit12: 1;
00071     
00072     unsigned short reservedbit13: 1;
00073     
00074     unsigned short reservedbit14: 1;
00075     
00076     unsigned short reservedbit15: 1;
00077     
00078     char waste [8];
00079     } typackedtextdata;
00080     
00081 
00082 
00083 static void disposehandle (Handle h) {
00084     
00085     if (h != nil)
00086         DisposeHandle (h);
00087     } /*disposehandle*/
00088     
00089     
00090 static boolean newtextdata (hdltextdata *hdata) {
00091 
00092     hdltextdata h;
00093     
00094     h = (hdltextdata) NewHandleClear (longsizeof (tytextdata));
00095     
00096     if (h == nil)
00097         return (false);
00098     
00099     (**h).bullets = false;
00100     
00101     (**h).hrealtext = nil;
00102     
00103     *hdata = h;
00104     
00105     return (true);
00106     } /*newtextdata*/
00107     
00108     
00109 static boolean cleanedittext (hdlobject h, short height, short width, Rect *r) {
00110 
00111     hdlcard hc = (**h).owningcard;
00112     short gridunits = (**hc).gridunits;
00113     short origheight = height, origwidth = width;
00114     
00115     width = IOAmakemultiple ((*r).right - (*r).left, gridunits);
00116     
00117     if (width < origwidth)
00118         width = origwidth;
00119     
00120     height = IOAclosestmultiple ((*r).bottom - (*r).top - 4, height);
00121     
00122     if (height < origheight)
00123         height = origheight;
00124     
00125     (*r).right = (*r).left + width;
00126     
00127     (*r).bottom = (*r).top + height;
00128     
00129     return (true);
00130     } /*cleanedittext*/
00131     
00132 
00133 static boolean canreplicateedittext (hdlobject h) {
00134     
00135     hdlcard hc = (**h).owningcard;
00136     boolean flediting = (**hc).activetextobject != nil;
00137     
00138     return (!flediting); /*only replicate if we're not in edit mode*/
00139     } /*canreplicateedittext*/
00140     
00141 
00142 static boolean getedittexteditrect (hdlobject h, Rect *r) {
00143     
00144     *r = (**h).objectrect;
00145         
00146     return (true); /*can be edited, edit rect is the same as the object's rect*/
00147     } /*getedittexteditrect*/
00148     
00149 
00150 static boolean getedittextvalue (hdlobject h, Handle *hvalue) {
00151     
00152     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00153     
00154     if ((**hdata).bullets) {
00155         
00156         char q = '"';
00157         
00158         if (PtrToHand (&q, hvalue, 1) != noErr)
00159             return (false);
00160         
00161         if ((**hdata).hrealtext != nil) {
00162         
00163             if (HandAndHand ((**hdata).hrealtext, *hvalue) != noErr)
00164                 return (false);
00165             }
00166         
00167         if (PtrAndHand (&q, *hvalue, 1) != noErr)
00168             return (false);
00169             
00170         return (true);
00171         }
00172     
00173     return (IOAgetstringvalue (h, hvalue));
00174     } /*getedittextvalue*/
00175     
00176     
00177 boolean gettextbehindbullets (hdlobject h, bigstring bs) {
00178     
00179     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00180     
00181     IOAtexthandletostring ((**hdata).hrealtext, bs);
00182     
00183     return (true);
00184     } /*gettextbehindbullets*/
00185 
00186 
00187 boolean emptytextbehindbullets (hdlobject h) {
00188     
00189     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00190 
00191     if ((**hdata).hrealtext != nil)
00192         SetHandleSize ((**hdata).hrealtext, 0);
00193     
00194     return (true);
00195     } /*emptytextbehindbullets*/
00196     
00197     
00198 boolean settextbehindbullets (hdlobject h, void *pstring) {
00199 
00200     unsigned char *value = (unsigned char *) pstring;
00201     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00202     Handle htext;
00203     
00204     if (!IOAnewtexthandle (value, &htext))
00205         return (false);
00206     
00207     disposehandle ((**hdata).hrealtext);
00208     
00209     (**hdata).hrealtext = htext;
00210 
00211     return (true);
00212     } /*settextbehindbullets*/
00213     
00214 
00215 static boolean debugedittext (hdlobject h, bigstring errorstring) {
00216 #pragma unused(h)
00217 
00218     setstringlength (errorstring, 0);
00219     
00220     return (true);
00221     } /*debugedittext*/
00222     
00223 
00224 static boolean drawedittext (hdlobject h) {
00225     
00226     hdlcard hc = (**h).owningcard;
00227     Rect r;
00228     
00229     r = (**h).objectrect;
00230     
00231     if (!(**h).objecttransparent)
00232         EraseRect (&r);
00233     
00234     #if TARGET_API_MAC_CARBON == 1
00235 
00236         DrawThemeEditTextFrame (&r, kThemeStateActive);
00237         
00238     #else   
00239     
00240         FrameRect (&r);
00241     
00242     #endif
00243     
00244     if (!(**hc).flskiptext) 
00245         IOAeditdrawtexthandle ((**h).objectvalue, r, (**h).objectjustification);
00246     
00247     return (true);
00248     } /*drawedittext*/
00249     
00250 
00251 static boolean initedittext (tyobject *obj) {
00252     
00253     newtextdata ((hdltextdata *) &(*obj).objectdata);
00254     
00255     return (true); /*we do want to edit it*/
00256     } /*initedittext*/
00257     
00258     
00259 static boolean recalcedittext (hdlobject h, boolean flmajorrecalc) {
00260 #pragma unused(flmajorrecalc)
00261 
00262     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00263     
00264     if (!(**hdata).bullets) 
00265         return (IOArecalcobjectvalue (h));
00266         
00267     disposehandle ((**hdata).hrealtext); /*recalcing bulleted text turned off -- 5/5/93 DW*/
00268             
00269     (**hdata).hrealtext = nil; 
00270         
00271     IOAsetobjectvalue (h, nil);
00272     
00273     return (true); 
00274     
00275     /*recalc bulleted text*/ {
00276         
00277         /*
00278         bigstring errorstring;
00279         Handle hrealtext, hbullets;
00280         long ctchars, i;
00281         
00282         if (!IOAevalscript ((**h).objectrecalcscript, &hrealtext, (**h).objectlanguage, errorstring))
00283             return (false);
00284         
00285         ctchars = GetHandleSize (hrealtext);
00286         
00287         hbullets = NewHandleClear (ctchars);
00288         
00289         if (hbullets == nil)
00290             return (false);
00291         
00292         for (i = 0; i < ctchars; i++)
00293             (*hbullets) [i] = '';
00294         
00295         disposehandle ((**hdata).hrealtext);
00296             
00297         (**hdata).hrealtext = hrealtext; 
00298         
00299         IOAsetobjectvalue (h, hbullets);
00300         */
00301         }
00302     } /*recalcedittext*/
00303     
00304     
00305 static boolean clickedittext (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
00306 #pragma unused(listhead, fl2click)
00307 
00308     hdlcard hc = (**h).owningcard;
00309     
00310     if (h != (**hc).activetextobject) {
00311 
00312         IOAclearactivetextobject ();
00313         
00314         IOAsetactivetextobject (h);
00315         }
00316         
00317     IOAeditclick (pt, flshiftkey, IOAgetactiveeditrecord ());
00318     
00319     return (false); /*no recalc needed*/
00320     } /*clickedittext*/
00321     
00322     
00323 static boolean setcursoredittext (hdlobject h, Point pt) {
00324 #pragma unused(h, pt)
00325 
00326     CursHandle hcursor;
00327     
00328     hcursor = GetCursor (iBeamCursor);
00329     
00330     if (hcursor != nil) 
00331         SetCursor (*hcursor);
00332     
00333     return (true); /*we don't want the default cursor*/
00334     } /*setcursoredittext*/
00335     
00336     
00337 static boolean editedittext (hdlobject h, boolean fledit) {
00338     
00339     /*
00340     DW 8/26/93: allow app to set the app bit to avoid selecting
00341     all of the text. the comment window in Clay Basket needs
00342     this feature.
00343     */
00344     
00345     IOAclearactivetextobject ();
00346     
00347     if (fledit) {
00348     
00349         IOAsetactivetextobject (h);
00350         
00351         if (!(**h).appbit1)
00352             IOAeditselectall (IOAgetactiveeditrecord ());
00353         }
00354     
00355     (**h).appbit1 = false;
00356         
00357     return (true);
00358     } /*editedittext*/
00359     
00360     
00361 static boolean idleedittext (hdlobject h) {
00362 #pragma unused(h)
00363 
00364     IOAeditidle (IOAgetactiveeditrecord ());
00365     
00366     return (true);
00367     } /*idleedittext*/
00368     
00369     
00370 static boolean keystrokeedittext (hdlobject h, char ch) {
00371     
00372     /*
00373     1.0b20 dmb: allow cursor keys in numberic-only fields
00374     */
00375     
00376     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00377     Handle hrealtext = (**hdata).hrealtext;
00378     Handle hedit = IOAgetactiveeditrecord ();
00379     hdlcard hc = (**h).owningcard;
00380     
00381     if ((**hdata).numericonly) {
00382         
00383         if (((ch < '0') || (ch > '9')) && (ch != chbackspace) && (ch != '-') && (keystroketodirection (ch) == nodirection))
00384             return (true);
00385         }
00386     
00387     (**hc).runmodechanges = true; /*indicate that one of the objects in the card changed*/
00388     
00389     (**(**h).owningcard).runtimevaluechanged = true; /*DW 10/17/95*/
00390     
00391     if (!(**hdata).bullets) {
00392     
00393         IOAeditkeystroke (ch, hedit);
00394         
00395         return (true);
00396         }
00397         
00398     if (ch == chbackspace) {
00399         
00400         disposehandle (hrealtext);
00401             
00402         (**hdata).hrealtext = nil; 
00403         
00404         IOAeditselectall (hedit);
00405         
00406         IOAeditkeystroke (chbackspace, hedit);
00407         
00408         return (true);
00409         }
00410     
00411     if (hrealtext == nil) {
00412         
00413         hrealtext = NewHandle (1);
00414         
00415         (*hrealtext) [0] = ch;
00416         
00417         (**hdata).hrealtext = hrealtext;
00418         }
00419     else {
00420         long len = GetHandleSize (hrealtext);
00421         
00422         SetHandleSize (hrealtext, len + 1);
00423         
00424         (*hrealtext) [len] = ch;
00425         }
00426     
00427     IOAeditkeystroke ('', hedit);
00428     
00429     return (true);
00430     } /*keystrokeedittext*/
00431         
00432     
00433 static boolean packtextdata (hdlobject hobject, Handle *hpackeddata) {
00434     
00435     hdltextdata hdata = (hdltextdata) (**hobject).objectdata;
00436     Handle hrealtext = (**hdata).hrealtext;
00437     short lenrealtext;
00438     typackedtextdata info;
00439     Handle hpacked;
00440     Ptr p;
00441     
00442     *hpackeddata = nil;
00443     
00444     IOAclearbytes (&info, longsizeof (info));
00445     
00446     info.versionnumber = 1;
00447     
00448     info.bullets = (**hdata).bullets;
00449     
00450     info.numericonly = (**hdata).numericonly;
00451     
00452     if (hrealtext == nil)
00453         lenrealtext = 0;
00454     else
00455         lenrealtext = GetHandleSize (hrealtext);
00456         
00457     info.lenrealtext = lenrealtext;
00458         
00459     hpacked = NewHandle (longsizeof (info) + lenrealtext);
00460     
00461     if (hpacked == nil)
00462         return (false);
00463     
00464     HLock (hpacked);
00465     
00466     p = *hpacked;
00467     
00468     BlockMove (&info, p, longsizeof (info));
00469     
00470     p += longsizeof (info);
00471     
00472     if (lenrealtext > 0) 
00473         BlockMove (*hrealtext, p, lenrealtext);
00474     
00475     HUnlock (hpacked);
00476     
00477     *hpackeddata = hpacked;
00478     
00479     return (true);
00480     } /*packtextdata*/
00481     
00482     
00483 static boolean disposetextdata (hdlobject h) {
00484     
00485     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00486     
00487     disposehandle ((**hdata).hrealtext);
00488     
00489     return (true);
00490     } /*disposetextdata*/
00491     
00492     
00493 static boolean unpacktextdata (hdlobject h) {
00494     
00495     hdltextdata hdata;
00496     Handle hpackeddata;
00497     typackedtextdata info;
00498     Handle hrealtext;
00499     Ptr p;
00500     OSErr ec;
00501         
00502     hpackeddata = (**h).objectdata; 
00503     
00504     if (!newtextdata (&hdata)) 
00505         return (false);
00506         
00507     (**h).objectdata = (Handle) hdata;
00508     
00509     if (hpackeddata == nil) /*it's a pre 1.0b15 edittext object*/
00510         return (true);
00511     
00512     HLock (hpackeddata);
00513     
00514     p = *hpackeddata;
00515     
00516     BlockMove (p, &info, longsizeof (info));
00517     
00518     p += longsizeof (info);
00519     
00520     ec = PtrToHand (p, &hrealtext, info.lenrealtext);
00521         
00522     HUnlock (hpackeddata);
00523     
00524     if (ec != noErr)
00525         return (false);
00526         
00527     (**hdata).hrealtext = hrealtext;
00528     
00529     (**hdata).bullets = info.bullets;
00530     
00531     (**hdata).numericonly = info.numericonly;
00532     
00533     disposehandle (hpackeddata);
00534     
00535     return (true);
00536     } /*unpacktextdata*/
00537     
00538     
00539 static boolean gettextattributes (hdlobject h, AppleEvent *event) {
00540     
00541     hdltextdata hdata = (hdltextdata) (**h).objectdata;
00542     Handle hrealtext;
00543     
00544     IACglobals.event = event; 
00545     
00546     if (!IACpushbooleanparam ((**hdata).bullets, 'pswd'))
00547         return (false);
00548     
00549     if (!IACpushbooleanparam ((**hdata).numericonly, 'nmrc'))
00550         return (false);
00551     
00552     hrealtext = (**hdata).hrealtext;
00553     
00554     if (hrealtext == nil)
00555         hrealtext = NewHandle (0);
00556     else
00557         HandToHand (&hrealtext);
00558     
00559     if (!IACpushtextparam (hrealtext, 'rtxt'))
00560         return (false);
00561         
00562     return (true);
00563     } /*gettextattributes*/
00564     
00565     
00566 static boolean settextattributes (hdlobject h, AppleEvent *event) {
00567     
00568     hdltextdata hdata = (hdltextdata) (**h).objectdata; 
00569     Boolean fl;
00570     Handle hrealtext;
00571     
00572     IACglobals.event = event; 
00573     
00574     IACglobals.nextparamoptional = true;
00575     
00576     if (IACgetbooleanparam ('pswd', &fl))
00577         (**hdata).bullets = fl;
00578     
00579     if (IACgetbooleanparam ('nmrc', &fl))
00580         (**hdata).numericonly = fl;
00581     
00582     if (IACgettextparam ('rtxt', &hrealtext)) {
00583         
00584         disposehandle ((**hdata).hrealtext);
00585         
00586         (**hdata).hrealtext = hrealtext;
00587         }
00588         
00589     return (true);
00590     } /*settextattributes*/
00591     
00592 
00593 void setupedittext (tyioaconfigrecord *);
00594 
00595     
00596 void setupedittext (tyioaconfigrecord *config) {
00597 
00598     IOAcopystring ("\pEditable text", (*config).objectTypeName);
00599     
00600     (*config).objectTypeID = edittexttype;
00601     
00602     (*config).frameWhenEditing = true;
00603     
00604     (*config).canEditValue = true;
00605     
00606     (*config).toggleFlagWhenHit = false;
00607     
00608     (*config).mutuallyExclusive = false;
00609     
00610     (*config).speaksForGroup = false;
00611     
00612     (*config).handlesMouseTrack = true; /*allow TextEdit to track the mouse*/
00613     
00614     (*config).editableInRunMode = true;
00615     
00616     (*config).hasSpecialCard = true;
00617     
00618     (*config).initObjectCallback = initedittext;
00619     
00620     (*config).drawObjectCallback = drawedittext;
00621     
00622     (*config).editObjectCallback = editedittext;
00623     
00624     (*config).idleObjectCallback = idleedittext;
00625     
00626     (*config).keystrokeObjectCallback = keystrokeedittext;
00627     
00628     (*config).clickObjectCallback = clickedittext;
00629     
00630     (*config).cleanupObjectCallback = cleanedittext;
00631     
00632     (*config).recalcObjectCallback = recalcedittext;
00633     
00634     (*config).canReplicateObjectCallback = canreplicateedittext;
00635     
00636     (*config).getObjectEditRectCallback = getedittexteditrect;
00637     
00638     (*config).getValueForScriptCallback = getedittextvalue;
00639     
00640     (*config).debugObjectCallback = debugedittext;
00641     
00642     (*config).setObjectCursorCallback = setcursoredittext;
00643     
00644     (*config).getAttributesCallback = gettextattributes;
00645     
00646     (*config).setAttributesCallback = settextattributes;
00647         
00648     (*config).unpackDataCallback = unpacktextdata;
00649     
00650     (*config).packDataCallback = packtextdata;
00651     
00652     (*config).disposeDataCallback = disposetextdata;
00653     } /*setupedittext*/
00654     
00655     

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