ioascrollbar.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioascrollbar.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 
00034 //Code change by Timothy Paustian Sunday, May 7, 2000 8:55:04 PM
00035 //Changed to Opaque call for Carbon
00036 
00037 typedef struct tyscrollbardata {
00038     
00039     short versionnumber;
00040     
00041     short controlresourceid;
00042     
00043     short controlmin;
00044     
00045     short controlmax;
00046     
00047     short controlinitialvalue;
00048     
00049     ControlHandle hcontrol;
00050     
00051     char waste [16];
00052     } tyscrollbardata, **hdlscrollbardata;
00053 
00054 
00055 static boolean checkcontrolexists (hdlobject h) {
00056 
00057     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00058     hdlcard hcard = (**h).owningcard;
00059     ControlHandle hcontrol = (**hdata).hcontrol;
00060     
00061     if (hcontrol != nil)
00062         return (true);
00063         
00064     hcontrol = GetNewControl ((**hdata).controlresourceid, (**hcard).drawwindow);
00065         
00066     (**hdata).hcontrol = hcontrol;
00067     //Code change by Timothy Paustian Sunday, May 7, 2000 8:46:46 PM
00068     //Changed to Opaque call for Carbon
00069     SetControlMinimum(hcontrol, (**hdata).controlmin);
00070     SetControlMaximum(hcontrol, (**hdata).controlmax);
00071     SetControlValue(hcontrol, (**hdata).controlinitialvalue);
00072     
00073     /*(**hcontrol).contrlMin = (**hdata).controlmin;
00074     
00075     (**hcontrol).contrlMax = (**hdata).controlmax;
00076     
00077     (**hcontrol).contrlValue = (**hdata).controlinitialvalue;*/
00078     
00079     return (hcontrol != nil);
00080     } /*checkcontrolexists*/
00081     
00082 
00083 static boolean cleanscrollbar (hdlobject h, short textheight, short textwidth, Rect *r) {
00084 #pragma unused(textwidth, textheight)
00085 
00086     short height, width;
00087     
00088     if (!checkcontrolexists (h))
00089         return (false);
00090         
00091     height = (*r).bottom - (*r).top;
00092     
00093     width = (*r).right - (*r).left;
00094     
00095     if (height > width) { /*it's a vertical scrollbar*/
00096         
00097         width = IOAclosestmultiple (width, 16);
00098         
00099         (*r).right = (*r).left + width;
00100         }
00101     else { /*it's a horizontal scrollbar*/
00102         
00103         height = IOAclosestmultiple (height, 16);
00104         
00105         (*r).bottom = (*r).top + height;
00106         }
00107         
00108     return (true);
00109     } /*cleanscrollbar*/
00110     
00111 
00112 static pascal void trackscrollarrow (hdlscrollbar sb, short part) {
00113     
00114     short val = GetControlValue(sb);
00115     short minval = GetControlMinimum(sb);
00116     short maxval = GetControlMaximum(sb);
00117     
00118     /*short val = (**sb).contrlValue;
00119     short minval = (**sb).contrlMin;
00120     short maxval = (**sb).contrlMax;*/
00121     short pageamount = (maxval - minval) / 10;
00122     
00123     switch (part) {
00124     
00125         case kControlUpButtonPart:
00126             val--;
00127             
00128             break;
00129             
00130         case kControlDownButtonPart:
00131             val++;
00132             
00133             break;
00134             
00135         case kControlPageUpPart:
00136             val -= pageamount;
00137             
00138             break;
00139                         
00140         case kControlPageDownPart:
00141             val += pageamount;
00142             
00143             break;
00144         } /*switch*/
00145     
00146     if (val < minval)
00147         val = minval;
00148         
00149     if (val > maxval)
00150         val = maxval;
00151         
00152     SetControlValue (sb, val);
00153     } /*trackscrollarrow*/
00154 
00155 
00156     
00157 #if TARGET_RT_MAC_CFM
00158     
00159     #if TARGET_API_MAC_CARBON == 1
00160     //Code change by Timothy Paustian Friday, July 21, 2000 9:55:14 PM
00161     //Is this the right UPP? I think so. I had to move this here so I could create
00162     //the UPP in IOAregistercomponents ioa.c
00163     #define trackscrollarrowUPP (trackscrollarrow)
00164     #else
00165     
00166     static RoutineDescriptor trackscrollarrowDesc = BUILD_ROUTINE_DESCRIPTOR (uppControlActionProcInfo, trackscrollarrow);
00167     
00168     #define trackscrollarrowUPP (&trackscrollarrowDesc)
00169     #endif
00170         
00171 
00172 #else
00173 
00174     #define trackscrollarrowUPP (&trackscrollarrow)
00175     
00176 #endif
00177         
00178 static boolean clickscrollbar (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
00179 #pragma unused(listhead, flshiftkey, fl2click)
00180 
00181     // hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00182     hdlcard hc = (**h).owningcard;
00183     
00184     if (!checkcontrolexists (h))
00185         return (false);
00186             
00187     (**hc).runmodechanges = true; /*indicate that one of the objects in the card changed*/
00188     
00189     (**hc).recalcneeded = true; /*force recalc of all objects that calc when another changes*/
00190     
00191     (**hc).recalctickcount = TickCount (); /*do it asap*/
00192     
00193     /*do the actual tracking*/ {
00194         short scrollbarpart;
00195         ControlHandle sb;
00196         
00197         scrollbarpart = FindControl (pt, (**hc).drawwindow, &sb);
00198         
00199         assert (sb == (**((hdlscrollbardata) (**h).objectdata)).hcontrol);
00200         
00201         if (scrollbarpart == kControlIndicatorPart) 
00202             TrackControl (sb, pt, nil);
00203         else
00204             TrackControl (sb, pt, trackscrollarrowUPP);
00205         }
00206     
00207     return (true);
00208     } /*clickscrollbar*/
00209 
00210 
00211 static boolean drawscrollbar (hdlobject h) {
00212     
00213     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00214     ControlHandle hcontrol;
00215     Rect r = (**h).objectrect;
00216     
00217     if (!checkcontrolexists (h))
00218         return (false);
00219         
00220     hcontrol = (**hdata).hcontrol;
00221         
00222     if (hcontrol == nil) {
00223         //Code change by Timothy Paustian Sunday, June 25, 2000 10:54:09 PM
00224         //
00225         #if TARGET_API_MAC_CARBON == 1
00226         Pattern gray;
00227         GetQDGlobalsBlack(&gray);
00228         FillRect (&r, &gray);
00229         #else
00230         FillRect (&r, &quickdrawglobal(gray));
00231         #endif
00232         return (true);
00233         }
00234     //Code change by Timothy Paustian Sunday, May 7, 2000 8:52:54 PM
00235     //Changed to Opaque call for Carbon
00236     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00237     SetControlBounds(hcontrol, &r);
00238     #else
00239     (**hcontrol).contrlRect = r;
00240     #endif
00241     //Code change by Timothy Paustian Sunday, May 7, 2000 8:53:47 PM
00242     //Changed to Opaque call for Carbon
00243     {
00244         boolean visControl;
00245         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00246         visControl = IsControlVisible(hcontrol);
00247         #else
00248         visControl = (**hcontrol).contrlVis;
00249         #endif
00250         
00251         if(visControl)
00252         {
00253             Draw1Control (hcontrol);
00254         }
00255         else
00256         {
00257             ShowControl (hcontrol);
00258         }   
00259     }
00260     return (true);
00261     } /*drawscrollbar*/
00262     
00263     
00264 static boolean newscrollbardata (hdlscrollbardata *hdata) {
00265 
00266     hdlscrollbardata h;
00267     
00268     h = (hdlscrollbardata) NewHandleClear (longsizeof (tyscrollbardata));
00269     
00270     if (h == nil)
00271         return (false);
00272     
00273     (**h).versionnumber = 1;
00274     
00275     (**h).controlresourceid = 1024;
00276     
00277     (**h).controlmin = 0;
00278     
00279     (**h).controlinitialvalue = 0;
00280     
00281     (**h).controlmax = 99;
00282     
00283     *hdata = h;
00284     
00285     return (true);
00286     } /*newscrollbardata*/
00287     
00288     
00289 static boolean initscrollbar (tyobject *obj) {
00290     
00291     hdlscrollbardata hdata;
00292     
00293     if (!newscrollbardata (&hdata))
00294         return (false);
00295     
00296     (*obj).objectdata = (Handle) hdata;
00297     
00298     return (false); /*we don't want to edit it*/
00299     } /*initscrollbar*/
00300     
00301     
00302 static boolean recalcscrollbar (hdlobject h, boolean flmajorrecalc) {
00303 #pragma unused(flmajorrecalc)
00304 
00305     return (IOArecalcobjectvalue (h));
00306     } /*recalcscrollbar*/
00307     
00308 
00309 static boolean getscrollbarinvalrect (hdlobject h, Rect *r) {
00310     
00311     *r = (**h).objectrect;
00312     
00313     return (true);
00314     } /*getscrollbarinvalrect*/
00315     
00316     
00317 static boolean canreplicatescrollbar (hdlobject h) {
00318 #pragma unused(h)
00319 
00320     return (true); 
00321     } /*canreplicatescrollbar*/
00322     
00323 
00324 static boolean getscrollbareditrect (hdlobject h, Rect *r) {
00325 #pragma unused(h, r)
00326 
00327     return (false); /*can't be edited*/
00328     } /*getscrollbareditrect*/
00329     
00330 
00331 static boolean getscrollbarvalue (hdlobject h, Handle *hvalue) {
00332     
00333     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00334     bigstring bs, bscontrolvalue;
00335     
00336     if (!checkcontrolexists (h))
00337         return (false);
00338         
00339     IOAcopystring ("\p\"", bs);
00340 
00341     NumToString (GetControlValue ((**hdata).hcontrol), bscontrolvalue);
00342     
00343     IOApushstring (bscontrolvalue, bs);
00344     
00345     IOApushstring ("\p\"", bs);
00346     
00347     return (IOAnewtexthandle (bs, hvalue));
00348     } /*getscrollbarvalue*/
00349     
00350 
00351 static boolean debugscrollbar (hdlobject h, bigstring errorstring) {
00352 #pragma unused(h)
00353 
00354     setstringlength (errorstring, 0);
00355     
00356     return (true);
00357     } /*debugscrollbar*/
00358     
00359 
00360 static boolean getscrollbarattributes (hdlobject h, AppleEvent *event) {
00361     
00362     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00363     
00364     IACglobals.event = event; 
00365     
00366     if (!IACpushshortparam ((**hdata).controlresourceid, 'sbid'))
00367         return (false);
00368     
00369     if (!IACpushshortparam ((**hdata).controlmin, 'sbmn'))
00370         return (false);
00371     
00372     if (!IACpushshortparam ((**hdata).controlmax, 'sbmx'))
00373         return (false);
00374     
00375     if (!IACpushshortparam ((**hdata).controlinitialvalue, 'sbin'))
00376         return (false);
00377     
00378     return (true);
00379     } /*getscrollbarattributes*/
00380     
00381     
00382 static boolean setscrollbarattributes (hdlobject h, AppleEvent *event) {
00383     
00384     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00385     tyscrollbardata info = **hdata;
00386     
00387     IACglobals.event = event; 
00388     
00389     IACglobals.nextparamoptional = true;
00390     
00391     IACgetshortparam ('sbid', &info.controlresourceid); IACglobals.nextparamoptional = true;
00392     
00393     IACgetshortparam ('sbmn', &info.controlmin); IACglobals.nextparamoptional = true;
00394     
00395     IACgetshortparam ('sbmx', &info.controlmax); IACglobals.nextparamoptional = true;
00396     
00397     IACgetshortparam ('sbin', &info.controlinitialvalue); IACglobals.nextparamoptional = true;
00398     
00399     **hdata = info;
00400     
00401     /*update the control handle to reflect new numbers*/ {
00402         
00403         ControlHandle hcontrol = (**hdata).hcontrol;
00404         //Code change by Timothy Paustian Sunday, May 7, 2000 8:54:51 PM
00405         //Changed to Opaque call for Carbon
00406         SetControlMinimum(hcontrol, info.controlmin);
00407         SetControlMaximum(hcontrol, info.controlmax);
00408         SetControlValue(hcontrol, info.controlinitialvalue);
00409         /*(**hcontrol).contrlMin = info.controlmin;
00410     
00411         (**hcontrol).contrlMax = info.controlmax;
00412     
00413         (**hcontrol).contrlValue = info.controlinitialvalue;*/
00414         }
00415     
00416     return (true);
00417     } /*setscrollbarattributes*/
00418     
00419     
00420 static boolean disposescrollbardata (hdlobject h) {
00421     
00422     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00423     
00424     if ((**hdata).hcontrol != nil)
00425         DisposeControl ((**hdata).hcontrol);
00426         
00427     return (true);
00428     } /*disposescrollbardata*/
00429     
00430     
00431 static boolean unpackscrollbardata (hdlobject h) {
00432     
00433     hdlscrollbardata hdata = (hdlscrollbardata) (**h).objectdata;
00434     
00435     (**hdata).hcontrol = nil;
00436     
00437     return (true);
00438     } /*unpackscrollbardata*/
00439     
00440     
00441 void setupscrollbar (tyioaconfigrecord *);
00442 
00443 
00444 void setupscrollbar (tyioaconfigrecord *config) {
00445 
00446     IOAcopystring ("\pScrollbar", (*config).objectTypeName);
00447     
00448     (*config).objectTypeID = scrollbartype;
00449     
00450     (*config).frameWhenEditing = false;
00451     
00452     (*config).canEditValue = false;
00453     
00454     (*config).toggleFlagWhenHit = false;
00455     
00456     (*config).mutuallyExclusive = false;
00457     
00458     (*config).speaksForGroup = false;
00459     
00460     (*config).handlesMouseTrack = true; /*allow the control manager to track the mouse*/
00461     
00462     (*config).hasSpecialCard = true; 
00463     
00464     (*config).cantDrawInBitmap = true; /*can't use offscreen bitmap to draw a control*/
00465 
00466     (*config).initObjectCallback = initscrollbar;
00467     
00468     (*config).drawObjectCallback = drawscrollbar;
00469     
00470     (*config).clickObjectCallback = clickscrollbar;
00471     
00472     (*config).recalcObjectCallback = recalcscrollbar;
00473     
00474     (*config).cleanupObjectCallback = cleanscrollbar;
00475     
00476     (*config).canReplicateObjectCallback = canreplicatescrollbar;
00477     
00478     (*config).getObjectEditRectCallback = getscrollbareditrect;
00479     
00480     (*config).getValueForScriptCallback = getscrollbarvalue;
00481     
00482     (*config).debugObjectCallback = debugscrollbar; 
00483     
00484     (*config).getObjectInvalRectCallback = getscrollbarinvalrect;
00485     
00486     (*config).getAttributesCallback = getscrollbarattributes;
00487     
00488     (*config).setAttributesCallback = setscrollbarattributes;
00489     
00490     (*config).unpackDataCallback = unpackscrollbardata;
00491     
00492     (*config).disposeDataCallback = disposescrollbardata;
00493     } /*setupscrollbar*/
00494     
00495     

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