ioabutton.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioabutton.c 1254 2006-04-12 20:27:14Z sethdill $    */
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 "quickdraw.h"
00032 #include <ioa.h>
00033 
00034 #if TARGET_API_MAC_CARBON == 1
00035 
00036     #include "memory.h"
00037     
00038 #endif
00039 
00040 
00041 #define textvertinset 2
00042 
00043 
00044 static boolean cleanbutton (hdlobject h, short height, short width, Rect *r) {
00045     
00046     /*
00047     dmb 1.0b20 -- don't alter font-based measurements for standard system 
00048     font buttons. i.e. use the height that is passed to us.
00049     */
00050     
00051     hdlcard hc = (**h).owningcard;
00052     short gridunits = (**hc).gridunits;
00053 
00054     width = IOAmakemultiple (width + 6, gridunits);
00055     
00056     width = max (width, 60); /*apply minimum button width*/
00057     
00058     (*r).right = (*r).left + width;
00059     
00060     if (((**h).objectfont == systemFont) && ((**h).objectfontsize == 12))
00061         (*r).bottom = (*r).top + height;
00062     else
00063         (*r).bottom = (*r).top + IOAmakemultiple (height - (2 * textvertinset) + 6, gridunits);
00064     
00065     return (true);
00066     } /*cleanbutton*/
00067     
00068 
00069 static boolean canreplicatebutton (hdlobject h) {
00070 #pragma unused(h)
00071 
00072     return (true); /*it can be replicated*/
00073     } /*canreplicatebutton*/
00074     
00075 
00076 static boolean getbuttoneditrect (hdlobject h, Rect *r) {
00077     
00078     short height, width, extrapixels, offtop;
00079     
00080     *r = (**h).objectrect;
00081         
00082     IOAgetobjectsize (h, &height, &width);
00083     
00084     extrapixels = ((*r).bottom - (*r).top) - height;
00085     
00086     offtop = extrapixels / 2;
00087     
00088     (*r).top += offtop;
00089     
00090     (*r).bottom -= extrapixels - offtop;
00091     
00092     return (true); /*can be edited*/
00093     } /*getbuttoneditrect*/
00094     
00095 
00096 static boolean getbuttonvalue (hdlobject h, Handle *hvalue) {
00097     
00098     return (IOAgetstringvalue (h, hvalue));
00099     } /*getbuttonvalue*/
00100     
00101 
00102 static boolean debugbutton (hdlobject h, bigstring errorstring) {
00103 #pragma unused(h)
00104 
00105     setstringlength (errorstring, 0);
00106     
00107     return (true);
00108     } /*debugbutton*/
00109     
00110 
00111 #if TARGET_API_MAC_CARBON == 1
00112 
00113 static void
00114 MyThemeButtonDrawCallback (
00115     const Rect                  *bounds,
00116     ThemeButtonKind              kind,
00117     const ThemeButtonDrawInfo   *info,
00118     UInt32                       refcon,
00119     SInt16                       depth,
00120     Boolean                      isColorDev)
00121 {
00122 #pragma unused(kind, info, depth, isColorDev)
00123 
00124     /*
00125      7.0b48 PBS: draw the label for a popup menu.
00126      */
00127         
00128         Handle htext = (Handle) refcon;
00129         ThemeFontID idfont;
00130         bigstring fontname, bs;
00131         short fontsize;
00132         Style fontstyle;
00133         Rect r = *bounds;
00134         
00135         texthandletostring (htext, bs);
00136         
00137         GetThemeFont (kThemePushButtonFont, smSystemScript, fontname, &fontsize, &fontstyle);
00138         
00139         fontgetnumber (fontname, (short *)(&idfont));
00140         
00141         pushstyle (geneva, 9, bold);
00142 
00143         //movepento ((*bounds).left, (*bounds).top + 10);
00144         
00145         r = *bounds;
00146         r.top = r.top + 3;
00147         
00148         centerbuttonstring (&r, bs, false);
00149         
00150         popstyle ();
00151         } /*MyThemeButtonDrawCallback*/
00152         
00153 #endif
00154 
00155 static boolean drawbutton (hdlobject h) { 
00156     
00157     /*
00158     DW 8/15/93: commented the pushing of the frame color before drawing
00159     the button outline. use the text color as set by the shell. makes 
00160     disabled buttons look right.
00161     
00162     2002-10-13 AR: Reorganized variable declarations
00163     to eliminate compiler warnings about unused variables.
00164     */
00165     
00166     hdlcard hc = (**h).owningcard;
00167     Rect r;
00168     boolean flbold;
00169     Handle htext;
00170     
00171     htext = (**h).objectvalue;
00172     
00173     r = (**h).objectrect;
00174     
00175     flbold = (**h).objectflag;
00176     
00177     #if TARGET_API_MAC_CARBON == 1
00178     
00179         {
00180         ThemeButtonDrawInfo drawinfo;
00181         ThemeButtonDrawUPP drawupp;
00182         
00183         InsetRect (&r, -2, 0);
00184         
00185         drawupp = NewThemeButtonDrawUPP (MyThemeButtonDrawCallback);
00186 
00187         drawinfo.state = kThemeButtonOn;
00188         
00189         drawinfo.value = kThemeStateActive;
00190         
00191         if ((**hc).tracking && (**hc).trackerpressed)
00192             drawinfo.value = kThemeStatePressed;
00193         
00194         drawinfo.adornment = 0;
00195         
00196         if (flbold) /*default item*/
00197             drawinfo.adornment = kThemeAdornmentDefault;
00198         
00199         DrawThemeButton (&r, kThemePushButton, &drawinfo, nil, nil, drawupp, (unsigned long) htext); 
00200         
00201         //DisposeThemeButtonDrawUPP (MyThemeButtonDrawCallback);
00202         DisposeThemeButtonDrawUPP (drawupp);        
00203         }
00204 
00205     #else
00206         
00207         {
00208         Rect routset;
00209 
00210         if (!(**h).objecttransparent)
00211             EraseRoundRect (&r, 9, 9);
00212                 
00213         routset = r;
00214         
00215         if (flbold)
00216             InsetRect (&routset, -4, -4);
00217             
00218         if (!(**hc).flskiptext) {
00219         
00220             Rect redit;
00221             
00222             getbuttoneditrect (h, &redit);
00223             
00224             IOAeditdrawtexthandle (htext, redit, (**h).objectjustification);
00225             }
00226                 
00227         /*IOApushforecolor (&(**h).objectframecolor);*/
00228         
00229         FrameRoundRect (&r, 9, 9); /*must be after text drawing, 4/27/92 DW*/
00230         
00231         if (flbold) {
00232         
00233             PenState x;
00234             
00235             GetPenState (&x); /*save the old pen state*/
00236             
00237             PenSize (3, 3); /*make the pen fatter*/
00238             
00239             FrameRoundRect (&routset, 16, 16); /*draw the ring*/
00240             
00241             SetPenState (&x); /*restore the pen state*/
00242             }
00243             
00244         /*IOApopforecolor ();*/
00245             
00246         if ((**hc).tracking && (**hc).trackerpressed) {
00247         
00248             Rect rinvert = r;
00249             
00250             InsetRect (&rinvert, 1, 1);
00251             
00252             InvertRoundRect (&rinvert, 9, 9);
00253             }
00254         }
00255         
00256     #endif
00257     
00258     return (true);
00259     } /*drawbutton*/
00260     
00261 
00262 static boolean flbold;
00263 
00264 
00265 static boolean initbuttonvisit (hdlobject h) {
00266     
00267     if ((**h).objectflag) {
00268         
00269         flbold = false; /*already is a bold button*/
00270         
00271         return (false); /*stop the traversal*/
00272         }
00273         
00274     return (true); /*keep looking*/
00275     } /*initbuttonvisit*/
00276     
00277     
00278 static boolean initbutton (tyobject *obj) {
00279     
00280     hdlcard hc = (*obj).owningcard;
00281     
00282     flbold = true;
00283     
00284     IOAvisitobjects ((**hc).objectlist, &initbuttonvisit);
00285     
00286     (*obj).objectflag = flbold; 
00287             
00288     (*obj).objectjustification = centerjustified;
00289     
00290     return (true); /*we do want to edit it*/
00291     } /*initbutton*/
00292     
00293     
00294 static boolean getbuttoninvalrect (hdlobject h, Rect *r) {
00295     
00296     *r = (**h).objectrect;
00297     
00298     if ((**h).objectflag)
00299         InsetRect (r, -4, -4);
00300     
00301     return (true);
00302     } /*getbuttoninvalrect*/
00303     
00304     
00305 static boolean recalcbutton (hdlobject h, boolean flmajorrecalc) {
00306 #pragma unused(flmajorrecalc)
00307 
00308     bigstring errorstring;
00309     Handle hvalue;
00310     
00311     if (!IOAevalscript (h, (**h).objectrecalcscript, &hvalue, (**h).objectlanguage, errorstring))
00312         return (false);
00313         
00314     IOAsetobjectvalue (h, hvalue); 
00315     
00316     IOAinvalobject (h);
00317     
00318     return (true); 
00319     } /*recalcbutton*/
00320 
00321 
00322 static boolean clickbutton (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
00323 #pragma unused(listhead, pt, flshiftkey, fl2click)
00324 
00325     IOArunbuttonscript (h);
00326     
00327     return (true); /*do a minor recalc*/
00328     } /*clickbutton*/
00329     
00330     
00331 static boolean catchreturnbutton (hdlobject h) {
00332     
00333     return ((**h).objectflag); /*if the button is bold, we want the Return key*/
00334     } /*catchreturnbutton*/
00335     
00336 
00337 void setupbutton (tyioaconfigrecord *);
00338 
00339 
00340 void setupbutton (tyioaconfigrecord *config) {
00341     
00342     IOAcopystring ("\pButton", (*config).objectTypeName);
00343     
00344     IOAcopystring ("\pDefault Button", (*config).objectFlagName);
00345     
00346     (*config).objectTypeID = buttontype;
00347     
00348     (*config).frameWhenEditing = false;
00349     
00350     (*config).canEditValue = true;
00351     
00352     (*config).toggleFlagWhenHit = false;
00353     
00354     (*config).mutuallyExclusive = false;
00355     
00356     (*config).speaksForGroup = false;
00357     
00358     (*config).hasSpecialCard = true;
00359 
00360     (*config).initObjectCallback = initbutton;
00361     
00362     (*config).drawObjectCallback = drawbutton;
00363     
00364     (*config).clickObjectCallback = clickbutton;
00365     
00366     (*config).cleanupObjectCallback = cleanbutton;
00367     
00368     (*config).recalcObjectCallback = recalcbutton;
00369     
00370     (*config).canReplicateObjectCallback = canreplicatebutton;
00371     
00372     (*config).catchReturnCallback = catchreturnbutton;
00373     
00374     (*config).getObjectInvalRectCallback = getbuttoninvalrect;
00375     
00376     (*config).getObjectEditRectCallback = getbuttoneditrect;
00377     
00378     (*config).getValueForScriptCallback = getbuttonvalue;
00379     
00380     (*config).debugObjectCallback = debugbutton;
00381     } /*setupconfig*/
00382     
00383     

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