ioaframe.c

Go to the documentation of this file.
00001 
00002 /*  $Id: ioaframe.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 frametype -4
00035 
00036 #define textvertinset 2
00037 #define texthorizinset 2
00038 #define mintextwidth 25
00039 
00040 #define textleftinset ((**(**h).owningcard).gridunits-texthorizinset)
00041 #define textrightinset (3*textleftinset)
00042 
00043 
00044 
00045 static short frametextwidth (hdlobject h) {
00046     
00047     Handle htext = (**h).objectvalue;
00048     short tw;
00049 
00050     tw = TextWidth (*htext, 0, GetHandleSize (htext)) + 2;
00051     
00052     if (tw < mintextwidth)
00053         tw = mintextwidth;
00054         
00055     return (tw);
00056     } /*frametextwidth*/
00057     
00058     
00059 static short frametextheight (void) {
00060     
00061     FontInfo fi;
00062     short lh;
00063     
00064     GetFontInfo (&fi);
00065     
00066     lh = fi.ascent + fi.descent + (2 * textvertinset);
00067     
00068     if ((lh % 2) == 1) /*round up*/
00069         lh++;
00070     
00071     return (lh);
00072     } /*frametextheight*/
00073 
00074 
00075 typedef struct tycleanframe {
00076     
00077     Rect objectrect;
00078     
00079     Rect newobjectrect;
00080     } tycleanframe;
00081     
00082 tycleanframe cleanup;
00083 
00084     
00085 static boolean cleanframevisit (hdlobject h) {
00086     
00087     Rect r = (**h).objectrect;
00088     Rect rsect;
00089     
00090     if (SectRect (&r, &cleanup.objectrect, &rsect))
00091         UnionRect (&r, &cleanup.newobjectrect, &cleanup.newobjectrect);
00092         
00093     return (true);
00094     } /*cleanframevisit*/
00095         
00096     
00097 static boolean cleanframe (hdlobject h, short height, short width, Rect *robject) {
00098     
00099     hdlcard hc = (**h).owningcard;
00100     short gridunits = (**hc).gridunits;
00101     short minheight, minwidth;
00102     Rect r;
00103     
00104     cleanup.objectrect = (**h).objectrect;
00105     
00106     cleanup.newobjectrect = (**h).objectrect;
00107     
00108     IOAvisitobjects ((**hc).objectlist, &cleanframevisit);
00109     
00110     if (cleanup.newobjectrect.left != cleanup.objectrect.left)  
00111         cleanup.newobjectrect.left -= textleftinset;
00112     
00113     if (cleanup.newobjectrect.right != cleanup.objectrect.right)    
00114         cleanup.newobjectrect.right += textleftinset;
00115     
00116     r = cleanup.newobjectrect;
00117     
00118     minheight = frametextheight ();
00119     
00120     if ((r.bottom - r.top) < minheight)
00121         r.bottom = r.top + minheight;
00122     
00123     minwidth = width + textleftinset + textrightinset;
00124     
00125     if ((r.right - r.left) < minwidth)
00126         r.right = r.left + minwidth;
00127         
00128     width = IOAmakemultiple (r.right - r.left, gridunits);
00129     
00130     height = IOAmakemultiple (r.bottom - r.top, gridunits);
00131     
00132     r.right = r.left + width;
00133 
00134     r.bottom = r.top + height;
00135 
00136     *robject = r;
00137     
00138     return (true);
00139     } /*cleanframe*/
00140     
00141 
00142 static boolean canreplicateframe (hdlobject h) {
00143     
00144     hdlcard hc = (**h).owningcard;
00145     boolean flediting = (**hc).activetextobject != nil;
00146     
00147     return (!flediting); /*only replicate if we're not in edit mode*/
00148     } /*canreplicateframe*/
00149     
00150 
00151 static boolean getframeeditrect (hdlobject h, Rect *rframe) {
00152     
00153     Rect r = (**h).objectrect;
00154     short fth = frametextheight ();
00155     
00156     r.top -= fth / 2;
00157     
00158     r.bottom = r.top + fth;
00159     
00160     r.left += textleftinset;
00161             
00162     r.right -= textrightinset;
00163     
00164     *rframe = r;
00165             
00166     return (true); /*can be edited, edit rect is the same as the object's rect*/
00167     } /*getframeeditrect*/
00168     
00169 
00170 static boolean getframevalue (hdlobject h, Handle *hvalue) {
00171     
00172     return (IOAgetstringvalue (h, hvalue));
00173     } /*getframevalue*/
00174     
00175 
00176 static boolean debugframe (hdlobject h, bigstring errorstring) {
00177 #pragma unused(h)
00178 
00179     setstringlength (errorstring, 0);
00180     
00181     return (true);
00182     } /*debugframe*/
00183     
00184 
00185 static boolean drawframe (hdlobject h) {
00186     
00187     hdlcard hc = (**h).owningcard;
00188     boolean notediting = !(**hc).flskiptext;
00189     Handle htext = (**h).objectvalue;
00190     Rect r, rtext;
00191     PenState ps;
00192     
00193     r = (**h).objectrect;
00194     
00195     if (!(**h).objecttransparent)
00196         EraseRect (&r);
00197     
00198     getframeeditrect (h, &rtext);
00199     
00200     if (notediting) 
00201         rtext.right = rtext.left + frametextwidth (h) + (2 * texthorizinset);
00202     
00203     IOApushforecolor (&(**h).objectframecolor);
00204     
00205     GetPenState (&ps);
00206     //Code change by Timothy Paustian Sunday, June 25, 2000 10:50:33 PM
00207     //changed to use opaque calls.
00208     #if TARGET_API_MAC_CARBON == 1
00209     if ((**h).objectselected)
00210     {
00211         Pattern black;
00212         GetQDGlobalsBlack(&black);
00213         PenPat (&black);
00214     }
00215     else
00216     {
00217         Pattern gray;
00218         GetQDGlobalsBlack(&gray);
00219         PenPat (&gray);
00220     }
00221     #else   
00222     if ((**h).objectselected)
00223         PenPat (&quickdrawglobal (black));
00224     else
00225         PenPat (&quickdrawglobal (gray));
00226     #endif
00227             
00228     FrameRect (&r);
00229     
00230     /*
00231     rframe = r;
00232     
00233     rframe.right--; rframe.bottom--;
00234     
00235     MoveTo (rframe.left, rframe.top);
00236     
00237     LineTo (rframe.left + textleftinset, rframe.top);
00238     
00239     MoveTo (rtext.right, rframe.top);
00240     
00241     LineTo (rframe.right, rframe.top);
00242     
00243     LineTo (rframe.right, rframe.bottom);
00244     
00245     LineTo (rframe.left, rframe.bottom);
00246     
00247     LineTo (rframe.left, rframe.top);
00248     */
00249     
00250     SetPenState (&ps);
00251     
00252     IOApopforecolor ();
00253     
00254     if (notediting) 
00255         IOAeditdrawtexthandle (htext, rtext, (**h).objectjustification);
00256         
00257     (**h).objecttmpbit = true; /*tell the framework not to draw the object's frame*/
00258     
00259     return (true);
00260     } /*drawframe*/
00261     
00262 
00263 static boolean initframe (tyobject *obj) {
00264     
00265     (*obj).objecttransparent = true;
00266     
00267     return (true); /*we do want to edit it*/
00268     } /*initframe*/
00269     
00270     
00271 static boolean recalcframe (hdlobject h, boolean flmajorrecalc) {
00272 #pragma unused(flmajorrecalc)
00273 
00274     return (IOArecalcobjectvalue (h));
00275     } /*recalcframe*/
00276     
00277     
00278 static boolean getframeinvalrect (hdlobject h, Rect *r) {
00279     
00280     *r = (**h).objectrect;
00281     
00282     (*r).top -= frametextheight () / 2;
00283     
00284     return (true);
00285     } /*getframeinvalrect*/
00286     
00287     
00288 void setupframe (tyioaconfigrecord *);
00289 
00290 
00291 void setupframe (tyioaconfigrecord *config) {
00292 
00293     IOAcopystring ("\pFrame", (*config).objectTypeName);
00294     
00295     (*config).objectTypeID = frametype;
00296     
00297     (*config).frameWhenEditing = true;
00298     
00299     (*config).canEditValue = true;
00300     
00301     (*config).toggleFlagWhenHit = false;
00302     
00303     (*config).mutuallyExclusive = false;
00304     
00305     (*config).speaksForGroup = false;
00306     
00307     (*config).initObjectCallback = initframe;
00308     
00309     (*config).drawObjectCallback = drawframe;
00310     
00311     (*config).cleanupObjectCallback = cleanframe;
00312     
00313     (*config).recalcObjectCallback = recalcframe;
00314     
00315     (*config).canReplicateObjectCallback = canreplicateframe;
00316     
00317     (*config).getObjectEditRectCallback = getframeeditrect;
00318     
00319     (*config).getValueForScriptCallback = getframevalue;
00320     
00321     (*config).debugObjectCallback = debugframe;
00322     
00323     (*config).getObjectInvalRectCallback = getframeinvalrect;
00324     } /*setupframe*/
00325     
00326     

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