ioaradio.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioaradio.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 <ioa.h>
00032 
00033 
00034 #define radioinset 5 /*the number of pixels to skip between oval and text*/
00035 
00036 
00037 #define textvertinset 2
00038 
00039 
00040 static void getradiorect (hdlobject h, Rect r, Rect *rbox) {
00041     
00042     hdlcard hc = (**h).owningcard;
00043     short objectfontsize = (**h).objectfontsize;
00044     FontInfo fi = (**hc).fontinfo;
00045     short lineheight;
00046     short extrapixels;
00047     
00048     lineheight = fi.ascent + fi.descent + fi.leading;
00049     
00050     extrapixels = (lineheight - objectfontsize) / 2;
00051     
00052     r.top += textvertinset;
00053     
00054     if (extrapixels > 0)
00055         r.top += (lineheight - objectfontsize) - extrapixels;
00056     
00057     r.bottom = r.top + objectfontsize;
00058     
00059     r.left += 3;
00060     
00061     r.right = r.left + objectfontsize;
00062     
00063     *rbox = r;
00064     } /*getradiorect*/
00065     
00066 
00067 static boolean cleanradio (hdlobject h, short height, short width, Rect *r) {
00068 
00069     hdlcard hc = (**h).owningcard;
00070     short gridunits = (**hc).gridunits;
00071     
00072     width = IOAmakemultiple (width + 3 + (**h).objectfontsize + radioinset, gridunits);
00073     
00074     (*r).right = (*r).left + width;
00075     
00076     (*r).bottom = (*r).top + height;
00077     
00078     return (true);
00079     } /*cleanradio*/
00080     
00081 
00082 static boolean canreplicateradio (hdlobject h) {
00083 #pragma unused(h)
00084 
00085     return (true); /*it can be replicated*/
00086     } /*canreplicateradio*/
00087     
00088 
00089 static boolean getradioeditrect (hdlobject h, Rect *r) {
00090 
00091     *r = (**h).objectrect;
00092         
00093     (*r).left += 3 + (**h).objectfontsize + radioinset;
00094     
00095     return (true); /*it can be edited*/
00096     } /*getradioeditrect*/
00097     
00098 
00099 static boolean getradiovalue (hdlobject h, Handle *hvalue) {
00100     
00101     return (IOAgetbooleanvalue (h, hvalue)); 
00102     } /*getradiovalue*/
00103     
00104 
00105 static boolean setradiovalue (hdlobject h, Handle hvalue) {
00106     
00107     return (IOAsetbooleanvalue (h, hvalue));
00108     } /*setradiovalue*/
00109     
00110     
00111 static boolean debugradio (hdlobject h, bigstring errorstring) {
00112 #pragma unused(h)
00113 
00114     setstringlength (errorstring, 0);
00115     
00116     return (true);
00117     } /*debugradio*/
00118 
00119     
00120 #if TARGET_API_MAC_CARBON == 1
00121 
00122     static void MyThemeButtonDrawCallback (const Rect *bounds, ThemeButtonKind kind, const ThemeButtonDrawInfo *info,
00123         UInt32 refcon, SInt16 depth, Boolean isColorDev) {
00124 #pragma unused(bounds, kind, info, refcon, depth, isColorDev)
00125 
00126         //StringPtr bs = (StringPtr) refcon;
00127         
00128         //pushstyle (geneva, 10, 0);
00129 
00130         //movepento ((*bounds).left, (*bounds).top + 10);
00131         
00132         //pendrawstring (bs);
00133         
00134         //popstyle ();
00135         } /*MyThemeButtonDrawCallback*/
00136 
00137 #endif
00138 
00139 
00140 static boolean drawradio (hdlobject h) {
00141     
00142     hdlcard hc = (**h).owningcard;
00143     Rect rbox;
00144     Handle htext;
00145     Rect r;
00146     
00147     htext = (**h).objectvalue;
00148     
00149     r = (**h).objectrect;
00150     
00151     getradiorect (h, r, &rbox);
00152     
00153     #if TARGET_API_MAC_CARBON == 1
00154     
00155         {
00156         ThemeButtonDrawUPP drawupp;
00157         ThemeButtonDrawInfo drawinfo;
00158         
00159         drawupp = NewThemeButtonDrawUPP (MyThemeButtonDrawCallback);
00160         
00161         if ((**h).objectflag)       
00162             drawinfo.state = kThemeButtonOn;
00163         else
00164             drawinfo.state = kThemeButtonOff;
00165         
00166         drawinfo.value = kThemeStateActive;
00167         
00168         drawinfo.adornment = 0;
00169                 
00170         DrawThemeButton (&r, kThemeRadioButton, &drawinfo, nil, nil, drawupp, (unsigned long) nil);
00171         
00172         DisposeThemeButtonDrawUPP (drawupp);
00173         }
00174         
00175     #else
00176     
00177     if (!(**h).objecttransparent)
00178         EraseRect (&r);
00179     
00180     FrameOval (&rbox);
00181     
00182     if ((**hc).tracking && (**hc).trackerpressed) {
00183         
00184         Rect rinset = rbox;
00185         
00186         InsetRect (&rinset, 1, 1);
00187         
00188         FrameOval (&rinset);
00189         }
00190     
00191     if ((**h).objectflag) {
00192         
00193         Rect rblack = rbox;
00194         
00195         InsetRect (&rblack, 3, 3);
00196         #if TARGET_API_MAC_CARBON == 1
00197         {
00198         Pattern black;
00199         GetQDGlobalsBlack(&black);
00200         FillOval (&rblack, &black);
00201         }
00202         #else
00203         FillOval (&rblack, &quickdrawglobal (black));
00204         #endif
00205         
00206         }
00207     
00208     #endif
00209     
00210     if (!(**hc).flskiptext) {
00211     
00212         Rect rtext;
00213     
00214         getradioeditrect (h, &rtext);
00215         
00216         IOAeditdrawtexthandle (htext, rtext, (**h).objectjustification);
00217         }
00218         
00219     return (true);
00220     } /*drawradio*/
00221     
00222 
00223 static boolean initradio (tyobject *obj) {
00224 #pragma unused(obj)
00225 
00226     return (true); /*nothing special, we do want to edit it*/
00227     } /*initradio*/
00228     
00229     
00230 static boolean recalcradio (hdlobject h, boolean flmajorrecalc) {
00231 #pragma unused(flmajorrecalc)
00232 
00233     bigstring errorstring;
00234     Handle hboolvalue;
00235     
00236     if (!IOAevalscript (h, (**h).objectrecalcscript, &hboolvalue, (**h).objectlanguage, errorstring))
00237         return (false);
00238         
00239     setradiovalue (h, hboolvalue); /*also disposes of hboolvalue*/
00240     
00241     return (true); 
00242     } /*recalcradio*/
00243     
00244 
00245 static boolean clickradio (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
00246 #pragma unused(pt, flshiftkey, fl2click)
00247 
00248     /*
00249     the one you hit goes on, all others go off
00250     */
00251                     
00252     hdlobject nomad = listhead;
00253     boolean newflag;
00254     
00255     while (nomad != nil) {
00256         
00257         if ((**nomad).objecttype == radiobuttontype) {
00258         
00259             newflag = (nomad == h) && (**nomad).objectenabled;
00260             
00261             if ((**nomad).objectflag != newflag) {
00262                 
00263                 (**nomad).objectflag = newflag;
00264                 
00265                 IOAinvalobject (nomad);
00266                 
00267                 (**(**nomad).owningcard).runtimevaluechanged = true; /*DW 9/19/95*/
00268                 
00269                 /*runmodeupdate ();*/
00270                 }
00271             }
00272         
00273         nomad = (**nomad).nextobject;
00274         } /*while*/
00275 
00276     IOArunbuttonscript (h); /*1.0b15 -- run the action script*/
00277     
00278     return (true); /*cause a minor recalc*/
00279     } /*clickradio*/
00280     
00281 
00282 void setupradio (tyioaconfigrecord *);
00283 
00284     
00285 void setupradio (tyioaconfigrecord *config) {
00286 
00287     IOAcopystring ("\pRadio button", (*config).objectTypeName);
00288     
00289     IOAcopystring ("\pSelected", (*config).objectFlagName);
00290     
00291     (*config).objectTypeID = radiobuttontype;
00292     
00293     (*config).frameWhenEditing = true;
00294     
00295     (*config).canEditValue = true;
00296     
00297     (*config).toggleFlagWhenHit = true;
00298     
00299     (*config).mutuallyExclusive = true;
00300     
00301     (*config).speaksForGroup = true;
00302     
00303     (*config).initObjectCallback = initradio;
00304     
00305     (*config).drawObjectCallback = drawradio;
00306     
00307     (*config).clickObjectCallback = clickradio;
00308     
00309     (*config).cleanupObjectCallback = cleanradio;
00310     
00311     (*config).recalcObjectCallback = recalcradio;
00312     
00313     (*config).canReplicateObjectCallback = canreplicateradio;
00314     
00315     (*config).getObjectEditRectCallback = getradioeditrect;
00316     
00317     (*config).getValueForScriptCallback = getradiovalue;
00318     
00319     (*config).setValueFromScriptCallback = setradiovalue;
00320     
00321     (*config).debugObjectCallback = debugradio;
00322     } /*setupradio*/
00323     
00324     

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