tablecallbacks.c

Go to the documentation of this file.
00001 
00002 /*  $Id: tablecallbacks.c 355 2005-01-11 22:48:55Z andreradke $    */
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 <standard.h>
00029 #include "font.h"
00030 #include "kb.h"
00031 #include "icon.h"
00032 #include "mouse.h"
00033 #include "ops.h"
00034 #include "quickdraw.h"
00035 #include "smallicon.h"
00036 #include "sounds.h"
00037 #include "strings.h"
00038 #include "shellhooks.h"
00039 #include "langexternal.h"
00040 #include "tableinternal.h"
00041 #include "tableverbs.h"
00042 
00043 
00044 
00045 void tablegettitlestring (short col, bigstring bstitle) {
00046     
00047     if ((col >= namecolumn) && (col <= kindcolumn))
00048         tablegetstringlist (nametitlestring + col, bstitle);
00049     else
00050         tablegetstringlist (questionmarksstring, bstitle);
00051     } /*tablegettitlestring*/
00052 
00053 
00054 static void tablesettitlestyle (short col) {
00055     
00056     register hdltableformats hf = tableformatsdata;
00057     short fontstyle;
00058     
00059     if (col == (**hf).sortorder)
00060         fontstyle = bold + underline;
00061     else
00062         fontstyle = bold;
00063     
00064     setfontsizestyle ((**hf).fontnum, (**hf).fontsize, fontstyle);
00065     } /*tablesettitlestyle*/
00066 
00067 
00068 static boolean tableadjustcolwidthcallback (short col, short cellwidth) {
00069     
00070     /*
00071     called after the user resized the indicated column.  after setting the
00072     colwith, we adjust the widths of all columns to the right.  they maintain
00073     their previous proportions to each other, but fill all the space to
00074     the right of the column that was resized.
00075     
00076     this rule makes sense for tables that don't have a horizontal scrollbar,
00077     but you still want to allow for column resizing.
00078     
00079     6/22/92 dmb: canned the proportional auto-adjustment logic.  with the new, 
00080     improved auto-column sizing, dragging column widths should take user's  
00081     actions as literally as possible.
00082     */
00083     
00084     register hdltableformats hf = tableformatsdata;
00085     register long leftoverwidth;
00086     register short i;
00087     short colwidth;
00088     short ctcols = (**hf).ctcols;
00089     
00090     tablesetcolwidth (col, cellwidth, true);
00091     
00092     for (i = col + 1; i < ctcols; i++) {
00093         
00094         tablegetcolwidth (i, &colwidth);
00095         
00096         leftoverwidth = tableavailwidth () - tablesumcolwidths (0, ctcols);
00097         
00098         tablesetcolwidth (i, colwidth + leftoverwidth, true);
00099         }
00100     
00101     /*
00102     if (col == lastcol)
00103         return (true);
00104     
00105     col += 1; /*adjustment begin with next column%/
00106     
00107     sum = tablesumcolwidths (col, (**hf).ctcols - col);
00108     
00109     leftoverwidth = tableavailwidth () - tablesumcolwidths (0, col);
00110     
00111     for (i = col; i < lastcol; i++) {
00112         
00113         register long x; /*do math in longs, avoid overflow%/
00114         
00115         tablegetcolwidth (i, &colwidth);
00116         
00117         x = colwidth;
00118         
00119         x *= leftoverwidth;
00120         
00121         if (sum > 0)
00122             x /= sum;
00123         
00124         tablesetcolwidth (i, (short) x, true);
00125         } /*for%/
00126     
00127     tablesetcolwidth (lastcol, tableavailwidth () - tablesumcolwidths (0, lastcol), false);
00128     */
00129     
00130     return (true);
00131     } /*tableadjustcolwidthcallback*/
00132     
00133 
00134 static boolean tablegetcellstring (short row, short col, bigstring bs) {
00135     
00136     /*
00137     1/8/91 dmb: push/pophashtable around call to hashvaltostrings, since 
00138     we can no longer assume that the root table is always set
00139     */
00140     
00141     bigstring bstype, bssize;
00142     tyvaluerecord val;
00143     hdlhashtable htable;
00144     
00145     tablegetstringlist (questionmarksstring, bs);
00146     
00147     htable = tablegetlinkedhashtable ();
00148     
00149     if (!hashgetiteminfo (htable, row, bs, &val))
00150         return (false);
00151     
00152     if (col == namecolumn) 
00153         return (true); /*with bs set to the name of the variable*/
00154     
00155     shellpusherrorhook ((errorhookcallback) &falsenoop);
00156     
00157     pushhashtable (htable);
00158     
00159     hashvaltostrings (val, bstype, bs, bssize); /*accept error values on failure*/
00160     
00161     pophashtable ();
00162     
00163     shellpoperrorhook ();
00164     
00165     if (col == valuecolumn) 
00166         return (true); /*with bs set to the value of the variable*/
00167         
00168     if (stringlength (bssize) > 0) { /*non-trivial size, show it*/
00169         
00170         pushstring ("\p [", bstype);
00171         
00172         pushstring (bssize, bstype);
00173         
00174         pushchar (']', bstype);
00175         }
00176     
00177     copystring (bstype, bs);
00178     
00179     return (true);
00180     } /*tablegetcellstring*/
00181     
00182     
00183 static boolean tabledrawcellcallback (short row, short col, Rect rcell) {
00184     
00185     bigstring bs;
00186     
00187     if ((**tableformatsdata).fleditingcell)
00188         if (tableeditdrawcell (row, col))
00189             return (true);
00190     
00191     if (!tablegetcellstring (row, col, bs))
00192         return (false);
00193     
00194     pendrawstring (bs);
00195     
00196     return (true);
00197     } /*tabledrawcellcallback*/
00198 
00199 
00200 static boolean tablecellcontentwidth (short row, short col, short *width) {
00201     
00202     bigstring bs;
00203     
00204     if (!tablegetcellstring (row, col, bs)) /*error*/
00205         return (false);
00206     
00207     *width = stringpixels (bs);
00208     
00209     return (true);
00210     } /*tablecellcontentwidth*/
00211 
00212 
00213 static boolean tablekeystrokecallback (void) {
00214     
00215     /*
00216     return true to consume keystroke, false to pass it thru to the table
00217     displayer.  we let up and down arrow move us thru the table in bar
00218     cursor mode.
00219     
00220     2.1b2 dmb: only capture modified returns -- don't ouch unconditionally
00221     */
00222     
00223     if ((keyboardstatus.chkb == chenter) && (keyboardstatus.ctmodifiers > 0)) {
00224         
00225         if (keyboardstatus.flcmdkey) {
00226             
00227             if (keyboardstatus.flshiftkey)
00228                 tablesurface ();
00229             else
00230                 tabledive ();
00231                 
00232             return (true);
00233             }
00234         
00235         ouch (); /*we're reserving the rest of the modified enter keystrokes*/
00236             
00237         return (true); /*consume the keystroke*/
00238         }
00239     
00240     if (keyboardstatus.chkb == chreturn) {
00241         
00242         if (keyboardstatus.ctmodifiers > 0) {
00243             
00244             tablemakenewvalue ();
00245             
00246             return (true);
00247             }
00248         }
00249     
00250     return (tableeditkeystroke ());
00251     } /*tablekeystrokecallback*/
00252     
00253     
00254 static boolean tableadjustcursorcallback (short row, short col) {
00255     
00256     return (tableeditadjustcursor (row, col));
00257     } /*tableadjustcursorcallback*/
00258 
00259 
00260 static boolean tablecellclickcallback (Point pt, short row, short col) {
00261     
00262     if (tableeditmousedown (pt, row, col))
00263         return (true);
00264     
00265     if ((col == valuecolumn) && mousedoubleclick ())
00266         return (tablezoomfromcell (row, valuecolumn));
00267     
00268     return (false);
00269     
00270     /*
00271     return (tableeditmousedown (pt, row, col));
00272     */
00273     } /*tablecellclickcallback*/
00274 
00275 
00276 static Rect titlerect;
00277 
00278 static void tableinverttitle (boolean flinrectnow) {
00279     
00280     invertrect (titlerect);
00281     } /*tableinverttitle*/
00282 
00283 
00284 static boolean tabletitleclickcallback (Point pt, short col) {
00285     
00286     bigstring bs;
00287     
00288     tablegettitlerect (col, &titlerect);
00289     
00290     tablegettitlestring (col, bs);
00291     
00292     tablesettitlestyle (col);
00293     
00294     titlerect.right = titlerect.left + stringpixels (bs) + 4;
00295     
00296     insetrect (&titlerect, 1, 1);
00297     
00298     if (pointinrect (pt, titlerect))
00299         if (trackicon (titlerect, &tableinverttitle))
00300             tablesetsortorder (col);
00301     
00302     return (true);
00303     } /*tabletitleclickcallback*/
00304 
00305 
00306 static void tabledirtycallback (void) {
00307     
00308     register hdlhashtable ht = (hdlhashtable) (**tableformatsdata).hdata;
00309     
00310     (**ht).fldirty = true;
00311     } /*tabledirtycallback*/
00312     
00313 
00314 static boolean tabledrawtitlecallback (short col, Rect r) {
00315     
00316     /*
00317     12/12/90 dmb: only underline title that corresponds to sortorder.  note
00318     that we don't need to preserve the font/size/style in this routine
00319     */
00320     
00321     bigstring bs;
00322     
00323     tablegettitlestring (col, bs);
00324     
00325     tablesettitlestyle (col);
00326     
00327     pendrawstring (bs);
00328     
00329     return (true);
00330     } /*tabledrawtitlecallback*/
00331     
00332 
00333 static boolean tableverbislinked (short row) {
00334     
00335     /*
00336     return true if the table row has an item linked into it -- governs the display
00337     of smallicons in the table displayer, and the dimming or not dimming of one of the
00338     buttons.
00339     */
00340     
00341     bigstring bsname;
00342     tyvaluerecord val;
00343     
00344     if (!tablegetiteminfo (row, bsname, &val)) 
00345         return (false);
00346     
00347     return (val.valuetype == externalvaluetype);
00348     } /*tableverbislinked*/
00349 
00350 
00351 /*
00352 boolean tablegetwedgeicon (row, iconlist, iconnum) short *iconlist, *iconnum; {
00353     
00354     /*
00355     11/11/90 DW: tried to get it to work just like the outline processor, but...
00356     
00357     when a window closes it's very hard to know which icon needs updating, going
00358     from black to gray.  
00359     
00360     rationalization: our icons are black even when a window is open because
00361     double clicking on them does something meaningful.  you can put that in 
00362     the brochure for the goddam product!
00363     
00364     11/15/90 DW: we're going to try again.  it requires that each external window
00365     manager call a table routine when it closes its window to inval the icon
00366     in front of the line we zoomed from.
00367     %/
00368 
00369     *iconlist = leadersmalliconlist;
00370     
00371     *iconnum = tablegrayicon;
00372     
00373     if (tableverbislinked (row)) {
00374         
00375         if (!tableverbwindowopen (row)) {
00376         
00377             *iconnum = tableblackicon;
00378             }
00379         }
00380         
00381     return (true);
00382     } /*tablegetwedgeicon%/
00383 */
00384 
00385     
00386 static boolean tablegetcircleicon (short row, short *iconlist, short *iconnum) {
00387     
00388     register hdltableformats hf = tableformatsdata;
00389     register short x;
00390     
00391     if (tableverbislinked (row)) 
00392         x = tablefullicon;
00393     else
00394         x = tableemptyicon;
00395     
00396     if (!(**hf).flprinting)
00397         if (row == (**hf).rowcursor)
00398             x += 2;
00399     
00400     *iconnum = x;
00401     
00402     return (true);
00403     } /*tablegetcircleicon*/
00404     
00405 /*
00406 static boolean tablegetfileicon (short row, short *iconlist, short *iconnum) {
00407     
00408     bigstring bs;
00409     tyvaluerecord val;
00410     register short x;
00411     
00412     if (!tablegetiteminfo (row, bs, &val))
00413         return (false);
00414     
00415     *iconlist = tablesmalliconlist;
00416     
00417     if (val.valuetype != externalvaluetype) {
00418     
00419         x = scalaricon;
00420         
00421         goto exit;
00422         }
00423         
00424     switch ((**(hdlexternalhandle) val.data.externalvalue).id) {
00425     
00426         case idtableprocessor:
00427             x = tableicon; 
00428             
00429             break;
00430         
00431         case idwordprocessor:
00432             x = wordicon; 
00433             
00434             break;
00435         
00436         case idpictprocessor:
00437             x = picticon; 
00438             
00439             break;
00440         
00441         case idoutlineprocessor:
00442             x = outlineicon; 
00443             
00444             break;
00445         
00446         case idscriptprocessor:
00447             x = scripticon; 
00448             
00449             break;
00450         
00451         case idmenuprocessor:
00452             x = menuicon; 
00453             
00454             break;
00455             
00456         default:
00457             x = unknownicon;
00458             
00459             break;
00460         } /*switch%/
00461     
00462     exit:
00463     
00464     *iconnum = x;
00465     
00466     return (true);
00467     } /*tablegetfileicon*/
00468     
00469 
00470 static boolean tablegeticoncallback (short row, short *iconlist, short *iconnum) {
00471     
00472     /*
00473     11/15/90 DW: experimenting with different kinds of icons -- this front-end
00474     makes it easy for us to switch back and forth depending on the mood.
00475     */
00476     
00477     return (tablegetcircleicon (row, iconlist, iconnum));
00478     } /*tablegeticoncallback*/
00479 
00480 
00481 static boolean tableiconhitcallback (short row, Rect ricon) {
00482     
00483     if (!mousedoubleclick ())
00484         return (true);
00485     
00486     tableupdatenow (); /*show new state*/
00487     
00488     invalrect (ricon); /*state of icon probably changing*/
00489     
00490     if (!tablezoomfromcell (row, -1))
00491         return (false);
00492     
00493     return (true);
00494     } /*tableiconhitcallback*/
00495 
00496 
00497 /*
00498 boolean tableiconhitcallback (short row, boolean flzoom, Rect ricon) {
00499     
00500     tableeditleavecell (); /*if editing, save off%/
00501     
00502     if (flzoom) {
00503         
00504         tableupdatenow (); /*show new state%/
00505         
00506         invalrect (ricon); /*state of icon probably changed%/
00507         
00508         if (!tablezoomfromcell (row, 0))
00509             return (false);
00510         
00511         return (true);
00512         }
00513     
00514     return (true);
00515     } /*tableiconhitcallback*/
00516     
00517     
00518 static boolean tableleavecellcallback (void) {
00519 
00520     return (tableeditleavecell ()); 
00521     } /*tableleavecellcallback*/
00522     
00523 
00524 static boolean tablesetscrollbarcallback (void) {
00525     
00526     register ptrtableformats pf = *tableformatsdata;
00527     register ptrwindowinfo pi = *tableformatswindowinfo;
00528     
00529     (*pi).vertmin = (*pf).vertmin;
00530     
00531     (*pi).vertmax = (*pf).vertmax;
00532     
00533     (*pi).vertcurrent = (*pf).vertcurrent;
00534     
00535     (*pi).fldirtyscrollbars = true; /*force a refresh of scrollbars by the shell*/
00536     
00537     return (true);
00538     } /*tablesetscrollbarcallback*/
00539 
00540 
00541 static boolean tablepostmovecallback (void) {
00542     
00543     register hdltableformats hf = tableformatsdata;
00544     register hdlextrainfo hi = (hdlextrainfo) (**hf).hextrainfo;
00545             
00546     shellforcecursoradjust (); /*context change may require new cursor shape*/
00547     
00548     if (!tableeditleavecell ()) /*if in edit mode, accept new entry*/
00549         return (false);
00550         
00551     /***tablecheckzoombutton (); /*maybe inval it if state changed*/
00552     
00553     /*
00554     invalrect ((**hi).kindpopuprect);
00555     */
00556     
00557     tableinvalicon ((**hf).rowcursor);
00558     
00559     return (true);
00560     } /*tablepostmovecallback*/
00561 
00562 
00563 static boolean tablepremovecallback (void) {
00564     
00565     tableinvalicon ((**tableformatsdata).rowcursor);
00566     
00567     return (tableeditleavecell ());
00568     } /*tablepremovecallback*/
00569 
00570 
00571 static boolean tableresetcellrectscallback (void) {
00572     
00573     /*
00574     after a scroll, resize, font change, etc., the rect for any given cell 
00575     may change.  this callback allows the table client to adjust anything 
00576     that depends on a cell's rect
00577     */
00578     
00579     tableeditsetbufferrect ();
00580     
00581     return (true);
00582     } /*tableresetcellrectscallback*/
00583 
00584 
00585 void tableinstallcallbacks (hdltableformats hformats) {
00586     
00587     register hdltableformats hf = hformats;
00588     
00589     (**hf).cellcontentwidthroutine = (callback) &tablecellcontentwidth;
00590     
00591     (**hf).drawcellroutine = (callback) &tabledrawcellcallback;
00592     
00593     (**hf).drawtitleroutine = (callback) &tabledrawtitlecallback;
00594     
00595     (**hf).adjustcolwidthroutine = (callback) &tableadjustcolwidthcallback;
00596     
00597     (**hf).precursormoveroutine = &tablepremovecallback;
00598     
00599     (**hf).postcursormoveroutine = &tablepostmovecallback;
00600     
00601     (**hf).cellclickroutine = (callback) &tablecellclickcallback;
00602     
00603     (**hf).titleclickroutine = (callback) &tabletitleclickcallback;
00604     
00605     (**hf).poststylechangeroutine = &tableeditpoststylechange;
00606     
00607     (**hf).dirtyroutine = &tabledirtycallback;
00608     
00609     (**hf).geticonroutine = (callback) &tablegeticoncallback;
00610     
00611     (**hf).iconhitroutine = (callback) &tableiconhitcallback;
00612     
00613     (**hf).islinkedroutine = (callback) &tableverbislinked;
00614     
00615     (**hf).setscrollbarsroutine = &tablesetscrollbarcallback;
00616     
00617     (**hf).adjustcursorroutine = (callback) &tableadjustcursorcallback;
00618     
00619     (**hf).keystrokeroutine = &tablekeystrokecallback;
00620     
00621     (**hf).leavecellroutine = &tableleavecellcallback;
00622     
00623     (**hf).resetcellrectsroutine = &tableresetcellrectscallback;
00624     } /*tableinstallcallbacks*/
00625 
00626 
00627 

Generated on Wed May 31 18:20:02 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6