ioacheckbox.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioacheckbox.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 checkboxinset 5 /*the number of pixels to skip between checkbox and text*/
00035 #define textvertinset 2
00036 
00037 
00038 
00039 static void getcheckboxrect (hdlobject h, Rect r, Rect *rbox) {
00040     
00041     hdlcard hc = (**h).owningcard;
00042     short objectfontsize = (**h).objectfontsize;
00043     FontInfo fi = (**hc).fontinfo;
00044     short lineheight;
00045     short extrapixels;
00046     
00047     lineheight = fi.ascent + fi.descent + fi.leading;
00048     
00049     extrapixels = (lineheight - objectfontsize) / 2;
00050     
00051     r.top += textvertinset;
00052     
00053     if (extrapixels > 0)
00054         r.top += (lineheight - objectfontsize) - extrapixels;
00055     
00056     r.bottom = r.top + objectfontsize;
00057     
00058     r.left += 3;
00059     
00060     r.right = r.left + objectfontsize;
00061     
00062     *rbox = r;
00063     } /*getcheckboxrect*/
00064     
00065 
00066 static boolean cleancheckbox (hdlobject h, short height, short width, Rect *r) {
00067 
00068     hdlcard hc = (**h).owningcard;
00069     short gridunits = (**hc).gridunits;
00070     
00071     width = IOAmakemultiple (width + 3 + (**h).objectfontsize + checkboxinset, gridunits);
00072     
00073     (*r).right = (*r).left + width;
00074     
00075     (*r).bottom = (*r).top + height;
00076     
00077     return (true);
00078     } /*cleancheckbox*/
00079     
00080 
00081 static boolean canreplicatecheckbox (hdlobject h) {
00082 #pragma unused(h)
00083 
00084     return (true); /*it can be replicated*/
00085     } /*canreplicatecheckbox*/
00086     
00087 
00088 static boolean getcheckboxeditrect (hdlobject h, Rect *r) {
00089 
00090     *r = (**h).objectrect;
00091         
00092     (*r).left += 3 + (**h).objectfontsize + checkboxinset;
00093     
00094     return (true); /*it can be edited*/
00095     } /*getcheckboxeditrect*/
00096     
00097 
00098 static boolean getcheckboxvalue (hdlobject h, Handle *hvalue) {
00099     
00100     return (IOAgetbooleanvalue (h, hvalue)); 
00101     } /*getcheckboxvalue*/
00102     
00103 
00104 static boolean setcheckboxvalue (hdlobject h, Handle hvalue) {
00105     
00106     return (IOAsetbooleanvalue (h, hvalue));
00107     } /*setcheckboxvalue*/
00108     
00109     
00110 static boolean debugcheckbox (hdlobject h, bigstring errorstring) {
00111 #pragma unused(h)
00112 
00113     setstringlength (errorstring, 0);
00114     
00115     return (true);
00116     } /*debugcheckbox*/
00117     
00118 
00119 static boolean drawcheckbox (hdlobject h) {
00120     
00121     hdlcard hc = (**h).owningcard;
00122     Rect rbox;
00123     Rect r;
00124     Handle htext;
00125     
00126     htext = (**h).objectvalue; 
00127     
00128     r = (**h).objectrect;
00129     
00130     getcheckboxrect (h, r, &rbox);
00131     
00132     if (!(**h).objecttransparent)
00133         EraseRect (&r);
00134     
00135     FrameRect (&rbox);
00136     
00137     if ((**hc).tracking && (**hc).trackerpressed) {
00138         
00139         Rect rinset = rbox;
00140         
00141         InsetRect (&rinset, 1, 1);
00142         
00143         FrameRect (&rinset);
00144         }
00145     
00146     if ((**h).objectflag) {
00147         
00148         MoveTo (rbox.left, rbox.top);
00149         
00150         LineTo (rbox.right - 1, rbox.bottom - 1);
00151         
00152         MoveTo (rbox.right - 1, rbox.top);
00153         
00154         LineTo (rbox.left, rbox.bottom - 1);
00155         }
00156         
00157     if (!(**hc).flskiptext) {
00158         
00159         Rect rtext;
00160         
00161         getcheckboxeditrect (h, &rtext);
00162         
00163         IOAeditdrawtexthandle (htext, rtext, (**h).objectjustification);
00164         }
00165     
00166     return (true);
00167     } /*drawcheckbox*/
00168     
00169     
00170 static boolean initcheckbox (tyobject *obj) {
00171 #pragma unused(obj)
00172 
00173     return (true); /*nothing special, we do want to edit it*/
00174     } /*initcheckbox*/
00175     
00176     
00177 static boolean recalccheckbox (hdlobject h, boolean flmajorrecalc) {
00178 #pragma unused(flmajorrecalc)
00179 
00180     bigstring errorstring;
00181     Handle hboolvalue;
00182     
00183     if (!IOAevalscript (h, (**h).objectrecalcscript, &hboolvalue, (**h).objectlanguage, errorstring))
00184         return (false);
00185         
00186     setcheckboxvalue (h, hboolvalue); /*also disposes of hboolvalue*/
00187     
00188     return (true); 
00189     } /*recalccheckbox*/
00190     
00191 
00192 static boolean clickcheckbox (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
00193 #pragma unused(listhead, pt, flshiftkey, fl2click)
00194 
00195     (**h).objectflag = !(**h).objectflag;
00196     
00197     (**(**h).owningcard).runtimevaluechanged = true; /*DW 9/19/95*/
00198     
00199     IOAinvalobject (h);
00200     
00201     IOArunbuttonscript (h); /*1.0b15 -- run the action script*/
00202     
00203     return (true); /*cause a minor recalc*/
00204     } /*clickcheckbox*/
00205     
00206 
00207 void setupcheckbox (tyioaconfigrecord *); /*prototype*/
00208 
00209     
00210 void setupcheckbox (tyioaconfigrecord *config) {
00211 
00212     IOAcopystring ("\pCheckbox", (*config).objectTypeName);
00213     
00214     IOAcopystring ("\pChecked", (*config).objectFlagName);
00215     
00216     (*config).objectTypeID = checkboxtype;
00217     
00218     (*config).frameWhenEditing = true;
00219     
00220     (*config).canEditValue = true;
00221     
00222     (*config).toggleFlagWhenHit = true;
00223     
00224     (*config).mutuallyExclusive = false;
00225     
00226     (*config).speaksForGroup = false;
00227     
00228     (*config).initObjectCallback = initcheckbox;
00229     
00230     (*config).drawObjectCallback = drawcheckbox;
00231     
00232     (*config).clickObjectCallback = clickcheckbox;
00233     
00234     (*config).cleanupObjectCallback = cleancheckbox;
00235     
00236     (*config).recalcObjectCallback = recalccheckbox;
00237     
00238     (*config).canReplicateObjectCallback = canreplicatecheckbox;
00239     
00240     (*config).getObjectEditRectCallback = getcheckboxeditrect;
00241     
00242     (*config).getValueForScriptCallback = getcheckboxvalue;
00243     
00244     (*config).setValueFromScriptCallback = setcheckboxvalue;
00245     
00246     (*config).debugObjectCallback = debugcheckbox;
00247     } /*setupcheckbox*/
00248     
00249     

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