ioaicon.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioaicon.c 1311 2006-04-19 08:28:14Z hasseily $    */
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 <appleticons.h>
00034 #include "ioaicon.h"
00035 
00036 
00037 #define iconheight 32
00038 #define iconwidth 32
00039 
00040 #define iconvertinset 3
00041 
00042 #define textvertinset 2
00043 
00044 
00045 typedef struct tyversion1icondata {
00046     
00047     short versionnumber;
00048     
00049     short resnum;
00050     
00051     unsigned short haslabel;
00052     
00053     unsigned short align: 4; /*DW 8/25/93*/
00054     
00055     unsigned short ixlabel: 3; /*DW 8/25/93*/
00056     
00057     /*1 more bit is available here*/
00058     
00059     Handle iconsuite; /*DW 8/25/93 -- if non-nil, it overrides resnum*/
00060     
00061     char waste [2];
00062     } tyversion1icondata, **hdlversion1icondata;
00063 
00064 
00065 
00066 
00067 static boolean cleanicon (hdlobject h, short height, short width, Rect *r) {
00068 
00069     hdlcard hc = (**h).owningcard;
00070     hdlicondata hdata = (hdlicondata) (**h).objectdata;
00071     short gridunits = (**hc).gridunits;
00072     
00073     if ((**hdata).haslabel) {
00074     
00075         width = IOAmakemultiple (width, gridunits);
00076         
00077         if (width < iconwidth)
00078             width = iconwidth;
00079         
00080         height += iconvertinset + iconheight;
00081         }
00082     else {
00083         width = iconwidth;
00084         
00085         height = iconheight;
00086         }
00087     
00088     (*r).right = (*r).left + width;
00089     
00090     (*r).bottom = (*r).top + height;
00091     
00092     return (true);
00093     } /*cleanicon*/
00094     
00095 
00096 static boolean canreplicateicon (hdlobject h) {
00097 #pragma unused(h)
00098 
00099     return (true); /*it can be replicated*/
00100     } /*canreplicateicon*/
00101     
00102 
00103 static boolean geticonvalue (hdlobject h, Handle *hvalue) {
00104     
00105     return (IOAgetstringvalue (h, hvalue));
00106     } /*geticonvalue*/
00107     
00108 
00109 static boolean debugicon (hdlobject h, bigstring errorstring) {
00110 #pragma unused(h)
00111 
00112     setstringlength (errorstring, 0);
00113     
00114     return (true);
00115     } /*debugicon*/
00116     
00117 
00118 static short icontextheight (void) {
00119     
00120     FontInfo fi;
00121     short lh;
00122     
00123     GetFontInfo (&fi);
00124     
00125     lh = fi.ascent + fi.descent + (2 * textvertinset);
00126     
00127     if ((lh % 2) == 1) /*round up*/
00128         lh++;
00129     
00130     return (lh);
00131     } /*icontextheight*/
00132 
00133 
00134 static boolean geticoneditrect (hdlobject h, Rect *redit) {
00135     
00136     hdlicondata hdata = (hdlicondata) (**h).objectdata;
00137     Rect r;
00138     
00139     if (!(**hdata).haslabel) /*can't be edited*/
00140         return (false);
00141     
00142     r = (**h).objectrect;
00143     
00144     r.top = r.bottom - icontextheight ();
00145     
00146     *redit = r;
00147     
00148     return (true); /*it can be edited*/
00149     } /*geticoneditrect*/
00150     
00151 
00152 static boolean drawiconobject (hdlobject h) {
00153     
00154     hdlcard hc = (**h).owningcard;
00155     hdlicondata hdata = (hdlicondata) (**h).objectdata;
00156     boolean haslabel = (**hdata).haslabel;
00157     Rect r, ricon, rcontains, rtext;
00158     boolean flhot = false;
00159     short transform = 0;
00160     
00161     r = (**h).objectrect;
00162     
00163     rcontains = r;
00164     
00165     rcontains.bottom -= icontextheight () + iconvertinset;
00166     
00167     ricon = r;
00168     
00169     ricon.bottom = ricon.top + iconheight;
00170     
00171     ricon.right = ricon.left + iconwidth;
00172     
00173     IOAcenterrect (&ricon, rcontains);
00174     
00175     if (ricon.top < r.top)
00176         ricon.top = r.top;
00177         
00178     if (!haslabel) /*DW 6/15/93*/
00179         ricon = r;
00180         
00181     if ((**hc).tracking && (**hc).trackerpressed) {
00182     
00183         transform = 0x4000; /*display it selected*/
00184         
00185         flhot = true;
00186         }
00187         
00188     transform += ttLabel [(**hdata).ixlabel]; /*color it according to the label*/
00189     
00190     if ((**hdata).iconsuite != nil)
00191         ploticonsuite (&ricon, (**hdata).align, transform, (**hdata).iconsuite);
00192     else
00193         ploticonresource (&ricon, (**hdata).align, transform, (**hdata).resnum);
00194     
00195     if (haslabel) {
00196     
00197         geticoneditrect (h, &rtext);
00198     
00199         IOAeditdrawtexthandle ((**h).objectvalue, rtext, (**h).objectjustification);
00200     
00201         if (flhot) {
00202         
00203             InsetRect (&r, 2, 2);
00204         
00205             InvertRect (&rtext);
00206             }
00207         }
00208         
00209     return (true);
00210     } /*drawiconobject*/
00211     
00212     
00213 static boolean recalciconobject (hdlobject h, boolean flmajorrecalc) {
00214 #pragma unused(flmajorrecalc)
00215 
00216     return (IOArecalcobjectvalue (h));
00217     } /*recalciconobject*/
00218     
00219     
00220 static boolean newicondata (hdlicondata *hdata) {
00221 
00222     hdlicondata h;
00223     
00224     h = (hdlicondata) NewHandleClear (longsizeof (tyicondata));
00225     
00226     if (h == nil)
00227         return (false);
00228     
00229     (**h).versionnumber = 2;
00230     
00231     (**h).resnum = 128;
00232     
00233     (**h).haslabel = true;
00234     
00235     (**h).align = kAlignAbsoluteCenter;
00236     
00237     *hdata = h;
00238     
00239     return (true);
00240     } /*newicondata*/
00241     
00242     
00243 static boolean initicon (tyobject *obj) {
00244     
00245     (*obj).objectautosize = true; /*it's kind of senseless to have wierd sized icons*/
00246     
00247     (*obj).objectfont = geneva;
00248 
00249     (*obj).objectfontsize = 9;
00250 
00251     (*obj).objectjustification = centerjustified;
00252     
00253     newicondata ((hdlicondata *) &(*obj).objectdata);
00254     
00255     return (true); /*we do want to edit it*/
00256     } /*initicon*/
00257     
00258     
00259 static boolean geticonattributes (hdlobject h, AppleEvent *event) {
00260     
00261     hdlicondata hdata = (hdlicondata) (**h).objectdata;
00262     
00263     IACglobals.event = event; 
00264     
00265     if (!IACpushshortparam ((**hdata).resnum, 'rsnm'))
00266         return (false);
00267         
00268     if (!IACpushbooleanparam ((**hdata).haslabel, 'hlbl'))
00269         return (false);
00270         
00271     return (true);
00272     } /*geticonattributes*/
00273     
00274     
00275 static boolean seticonattributes (hdlobject h, AppleEvent *event) {
00276     
00277     hdlicondata hdata = (hdlicondata) (**h).objectdata; 
00278     Boolean haslabel;
00279     short resnum;
00280     
00281     IACglobals.event = event; 
00282     
00283     IACglobals.nextparamoptional = true;
00284 
00285     if (IACgetbooleanparam ('hlbl', &haslabel)) 
00286         (**hdata).haslabel = haslabel; 
00287     
00288     IACglobals.nextparamoptional = true;
00289     
00290     if (IACgetshortparam ('rsnm', &resnum))
00291         (**hdata).resnum = resnum;
00292     
00293     return (true);
00294     } /*seticonattributes*/
00295     
00296     
00297 static boolean unpackicondata (hdlobject h) {
00298 
00299     hdlicondata hdata = (hdlicondata) (**h).objectdata;
00300     
00301     if (hdata == nil) {
00302         
00303         newicondata (&hdata);
00304         
00305         (**h).objectdata = (Handle) hdata;
00306         
00307         return (hdata != nil);
00308         }
00309     
00310     if ((**hdata).versionnumber == 1) { /*convert from version 1 to version 2*/
00311         
00312         tyversion1icondata x;
00313         
00314         BlockMove (*hdata, &x, longsizeof (tyversion1icondata));
00315         
00316         DisposeHandle ((Handle) hdata);
00317         
00318         hdata = (hdlicondata) NewHandleClear (longsizeof (tyicondata));
00319         
00320         BlockMove (&x, *hdata, longsizeof (tyversion1icondata));
00321         
00322         (**hdata).versionnumber = 2;
00323         
00324         (**h).objectdata = (Handle) hdata;
00325         }
00326         
00327     return (true);
00328     } /*unpackicondata*/
00329     
00330     
00331 static boolean clickicon (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
00332 #pragma unused(listhead, pt, flshiftkey)
00333 
00334     hdlicondata hdata = (hdlicondata) (**h).objectdata;
00335     tyiconclickcallback lcallback = (**hdata).iconclick;
00336     
00337     if (lcallback != nil)
00338         return ((*lcallback) (h, fl2click));
00339     
00340     if (fl2click)
00341         IOArunbuttonscript (h);
00342     
00343     return (true); /*do a minor recalc*/
00344     } /*clickicon*/
00345     
00346 
00347 void setupicon (tyioaconfigrecord *);
00348 
00349     
00350 void setupicon (tyioaconfigrecord *config) {
00351 
00352     IOAcopystring ("\pIcon", (*config).objectTypeName);
00353     
00354     (*config).objectTypeID = icontype;
00355     
00356     (*config).frameWhenEditing = true;
00357     
00358     (*config).canEditValue = true;
00359     
00360     (*config).toggleFlagWhenHit = false;
00361     
00362     (*config).mutuallyExclusive = false;
00363     
00364     (*config).speaksForGroup = false;
00365     
00366     (*config).isFontAware = true;
00367     
00368     (*config).hasSpecialCard = true;
00369     
00370     (*config).initObjectCallback = initicon;
00371     
00372     (*config).drawObjectCallback = drawiconobject;
00373     
00374     (*config).clickObjectCallback = clickicon;
00375     
00376     (*config).recalcObjectCallback = recalciconobject;
00377     
00378     (*config).cleanupObjectCallback = cleanicon;
00379     
00380     (*config).canReplicateObjectCallback = canreplicateicon;
00381     
00382     (*config).getObjectEditRectCallback = geticoneditrect;
00383     
00384     (*config).getValueForScriptCallback = geticonvalue;
00385     
00386     (*config).debugObjectCallback = debugicon;
00387     
00388     (*config).getAttributesCallback = geticonattributes;
00389     
00390     (*config).setAttributesCallback = seticonattributes;
00391         
00392     (*config).unpackDataCallback = unpackicondata;
00393     } /*setupicon*/
00394     
00395     

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