tableformats.c

Go to the documentation of this file.
00001 
00002 /*  $Id: tableformats.c 1254 2006-04-12 20:27:14Z sethdill $    */
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 "bitmaps.h"
00032 #include "cursor.h"
00033 #include "font.h"
00034 #include "kb.h"
00035 #include "memory.h"
00036 #include "ops.h"
00037 #include "quickdraw.h"
00038 #include "resources.h"
00039 #include "smallicon.h"
00040 #include "opinternal.h"
00041 #include "tabledisplay.h"
00042 #include "tableformats.h"
00043 #include "tableinternal.h"
00044 #include "claybrowserstruc.h"
00045 #include "claybrowserexpand.h"
00046 #include "claycallbacks.h"
00047 #include "claybrowservalidate.h"
00048 #include "timedate.h"
00049 #include "byteorder.h"  /* 2006-04-08 aradke: endianness conversion macros */
00050 
00051 
00052 #define mincolwidth 50
00053 #define maxcolwidth 1000
00054 
00055 #define ctformatstack 5 /*we can remember format contexts up to 5 levels deep*/
00056 
00057 short topformatstack = 0;
00058 
00059 hdltableformats formatstack [ctformatstack];
00060 
00061 
00062 
00063 void tablegettitlestring (short col, bigstring bstitle) {
00064     
00065     if ((col >= namecolumn) && (col <= kindcolumn))
00066         tablegetstringlist (nametitlestring + col, bstitle);
00067     else
00068         tablegetstringlist (questionmarksstring, bstitle);
00069     } /*tablegettitlestring*/
00070 
00071 
00072 boolean tablepushformats (hdltableformats hformats) {
00073     
00074     /*
00075     when you want to temporarily work with a different formats record, call this
00076     routine, do your stuff and then call tablepopformats.
00077     */
00078     
00079     if (topformatstack >= ctformatstack) {
00080         
00081         shellinternalerror (idformatstackfull, BIGSTRING ("\16" "format stack overflow!"));
00082         
00083         return (false);
00084         }
00085     
00086     formatstack [topformatstack++] = tableformatsdata;
00087     
00088     tableformatsdata = hformats;
00089     
00090     oppushoutline ((**hformats).houtline);
00091     
00092     return (true);
00093     } /*tablepushformats*/
00094         
00095 
00096 boolean tablepopformats (void) {
00097     
00098     if (topformatstack <= 0) {
00099         
00100         shellinternalerror (idformatstackempty, BIGSTRING ("\x13" "too many popformats"));
00101         
00102         return (false);
00103         }
00104     
00105     oppopoutline ();
00106     
00107     tableformatsdata = formatstack [--topformatstack];
00108     
00109     return (true);
00110     } /*tablepopformats*/
00111 
00112 
00113 void tabledirty (void) {
00114     
00115     /*
00116     2.1b4 dmb: update timelastsave on each change
00117     */
00118     
00119     register hdltableformats hf = tableformatsdata;
00120     //register hdlhashtable ht = (hdlhashtable) (**hf).htable;
00121     hdloutlinerecord ho = (**hf).houtline;
00122     
00123     // (**ht).fldirty = true; // 2/14/97 dmb: langhash takes care of dirtyness itself
00124     
00125     (**ho).timelastsave = timenow (); /*modification time until saved*/
00126     
00127     windowsetchanges (tableformatswindow, true);
00128     } /*tabledirty*/
00129 
00130 
00131 short tablegetcolwidth (short col) {
00132     
00133     return ((**tableformatsdata).colwidths [col]);
00134     } /*tablegetcolwidth*/
00135 
00136 
00137 static short tablegetmaxwidth (short col) {
00138     
00139     return ((**tableformatsdata).maxwidths [col]);
00140     } /*tablegetmaxwidth*/
00141 
00142 
00143 static short tablelimitcolwidth (short width) {
00144     
00145     register short w = width;
00146     
00147     /*
00148     if odd (w)
00149         w++;
00150     */
00151     
00152     w = max (mincolwidth, w);
00153     
00154     w = min (maxcolwidth, w);
00155     
00156     return (w);
00157     } /*tablelimitcolwidth*/
00158 
00159 
00160 boolean tablesetcolwidth (short col, short width, boolean fllimit) {
00161 
00162     if ((col < 0) || (col >= (**tableformatsdata).ctcols)) /*out of range*/
00163         return (false);
00164     
00165     if (fllimit)
00166         width = tablelimitcolwidth (width);
00167     
00168     (**tableformatsdata).colwidths [col] = width;
00169     
00170     return (true);
00171     } /*tablesetcolwidth*/
00172     
00173 
00174 short tablesumcolwidths (short startcol, short ctcols) {
00175     
00176     register short *pwidth;
00177     short sum = 0;
00178     hdltableformats hf = tableformatsdata;
00179     
00180     /*loop through range in width array, adding values*/
00181     
00182     for (pwidth = (**hf).colwidths + startcol;  --ctcols >= 0;  ++pwidth)
00183         sum += *pwidth;
00184     
00185     return (sum);
00186     } /*tablesumcolwidths*/
00187 
00188 
00189 short tableavailwidth (void) {
00190     
00191     register hdltableformats hc = tableformatsdata;
00192     register Rect *r = &(**hc).tablerect;
00193     register short availwidth;
00194     
00195     availwidth = (*r).right - (*r).left;
00196     
00197     return (availwidth);
00198     } /*tableavailwidth*/
00199 
00200 
00201 short tabletotalcolwidths (void) {
00202     
00203     return (tablesumcolwidths (0, (**tableformatsdata).ctcols));
00204     } /*tabletotalcolwidths*/
00205 
00206 
00207 boolean tablerecalccolwidths (boolean flmustrecalc) {
00208     
00209     /*
00210     the width of the table rectangle has changed.  reallocate the column widths
00211     so that they are optimal for our 3-column database tables.
00212     
00213     9/26/90 dmb: always set the width of the last column to the remaining table width
00214     
00215     6/21/92 dmb: new, object database-specific (3-column) algorithm:
00216     
00217     1.  when widening the table, never narrow a column; when narrowing a table, 
00218         never widen a column
00219     
00220     2.  expand columns 1 & 3 enough to accommodate their contents; column 2 gets the rest
00221     
00222     3.  if there's extra width, divide it among the three evenly
00223     
00224     4.  if there's too little width, column 2 is truncated, down to the minimum limit; 
00225         if there's still too little, columns 3 & 1 absorb it (in that order).
00226     
00227     10/3/92 dmb: if the colwidths already fit the display, do nothing. (currently, no 
00228     caller would insist on the recalc, and this preserves hand-tuning.)
00229     
00230     10/6/92 dmb: added flmustrecalc parameter. (tableresize really wants to ensure recalc; 
00231     it's used after a font/size change as well as resizing.)
00232     
00233     5.0d19 dmb: change rule #3 above. If there's extra width, give it to the name column.
00234 
00235     5.0a5 dmb: another tweak
00236     */
00237     
00238     register hdltableformats hc = tableformatsdata;
00239     long curwidth, newwidth;
00240     short i;
00241     short lastcol = (**hc).ctcols - 1;
00242     short remaining;
00243     short diff;
00244     short extra;
00245     short norm;
00246     long maxwidth, height;
00247     
00248     if (isclaydisplay (hc))
00249         claybrowserinitdraw ();
00250     
00251     assert (lastcol == 2);
00252     
00253     newwidth = tableavailwidth ();
00254     
00255     curwidth = tabletotalcolwidths ();
00256     
00257     diff = newwidth - curwidth; // is table bigger than last time? smaller?*/
00258     
00259     if ((diff == 0) && !flmustrecalc) // nothing to do
00260         return (true);
00261     
00262     tablegetoutlinesize (&maxwidth, &height); // recalcs max col widths
00263     
00264     extra = newwidth - maxwidth;
00265     
00266     remaining = newwidth;
00267     
00268     for (i = 0; i < lastcol; i++) {
00269         
00270         register long w; /*do math in longs, avoid overflow*/
00271         register long x;
00272         
00273         w = tablegetcolwidth (i);
00274         
00275         x = tablegetmaxwidth (i);
00276         
00277         extra = remaining - maxwidth;
00278         
00279         if (curwidth == 0)
00280             norm = x + extra / (lastcol - i);
00281         else
00282             norm = x + extra;
00283         
00284         switch (sgn (diff)) {
00285             
00286             case 1: /*growing the table*/
00287                 w = max (w, min (w + diff, max (x, norm)));
00288                 
00289                 break;
00290             
00291             case -1: /*shrinking the table*/
00292                 w = min (w, max (w + diff, min (x, norm)));
00293                 
00294                 break;
00295             
00296             default:
00297                 w = norm;
00298             }
00299         
00300         w = min (w, remaining - ((lastcol - i) * mincolwidth));
00301         
00302         w = tablelimitcolwidth ((short) w);
00303         
00304         tablesetcolwidth (i, (short) w, false);
00305         
00306         remaining -= w;
00307         
00308         maxwidth -= x;
00309         }
00310     
00311     tablesetcolwidth (lastcol, remaining, false);
00312     
00313     opseteditbufferrect ();
00314     
00315     return (true);
00316     } /*tablerecalccolwidths*/
00317 
00318 
00319 static boolean tablepostfontchange (void) {
00320     
00321     /*
00322     5.0a10 dmb: must dirty table to make sure changes stick
00323     */
00324 
00325     hdltableformats hf = tableformatsdata;
00326     hdlhashtable ht = tablegetlinkedhashtable ();
00327     
00328     if (hf == nil)
00329         return (false);
00330     
00331     oppostfontchange ();
00332     
00333     if (ht != nil)
00334         (**ht).fldirty = true;
00335     
00336     //shelladjustaftergrow (tableformatswindow); /*recalc and redraw the entire display*/
00337     
00338     if (isclaydisplay (hf))
00339         claybrowserinitdraw ();
00340     
00341     return (true);
00342     } /*claypostfontchange*/
00343 
00344 
00345 static boolean tableicon2click (hdlheadrecord hnode) {
00346 
00347     if ((**hnode).flnodeisfolder && !keyboardstatus.flcmdkey)
00348         return (false);
00349     
00350     return (tablezoomfromhead (hnode));
00351     } /*tableicon2click*/
00352 
00353 
00354 static void setuptableoutlinecallbacks (hdloutlinerecord ho) {
00355     
00356     (**ho).fldonterasebackground = true;
00357     
00358     (**ho).flusebitmaps = false; 
00359     
00360     (**ho).pixelsaftericon = 3; /*skip this many pixels between icon and text*/
00361     
00362     (**ho).maxlinelen = 31; /*file names can be at most 31 characters long*/
00363     
00364     (**ho).fllimittextarrows = true;
00365     
00366     (**ho).flstructuredtextkeys = true;
00367     
00368     (**ho).flhorizscrolldisabled = true;
00369     
00370     /*link in the line layout callbacks*/ {
00371     
00372         (**ho).drawlinecallback = tabledrawline;
00373         
00374         (**ho).postdrawlinecallback = tablepostdrawline;
00375         
00376         (**ho).predrawlinecallback = tablepredrawline;
00377         
00378         (**ho).drawiconcallback = tabledrawnodeicon;
00379         
00380         (**ho).gettextrectcallback = tablegettextrect;
00381         
00382         (**ho).getedittextrectcallback = tablegetedittextrect;
00383         
00384         (**ho).geticonrectcallback = tablegeticonrect;
00385         
00386         (**ho).getlineheightcallback = tablegetlineheight;
00387         
00388         (**ho).getlinewidthcallback = tablegetlinewidth;
00389         
00390     //  (**ho).getmaxlinewidthcallback = tablegetmaxlinewidth;
00391         
00392         (**ho).pushstylecallback = tablepushnodestyle;
00393         
00394         (**ho).postfontchangecallback = tablepostfontchange;
00395         
00396         (**ho).getfullrectcallback = (opgefullrectcallback) truenoop;
00397     
00398         }
00399     
00400         /*link in the line layout callbacks/ {
00401     
00402         (**ho).drawlinecallback = &claydrawline;
00403         
00404         (**ho).postdrawlinecallback = &claypostdrawline;
00405         
00406         (**ho).predrawlinecallback = &claypredrawline;
00407         
00408         (**ho).drawiconcallback = &claydrawnodeicon;
00409         
00410         (**ho).gettextrectcallback = &claygettextrect;
00411         
00412         (**ho).geticonrectcallback = &claygeticonrect;
00413         
00414         (**ho).getlineheightcallback = &claygetlineheight;
00415         
00416         (**ho).getlinewidthcallback = &claygetlinewidth;
00417         
00418         (**ho).pushstylecallback = &claypushnodestyle;
00419         
00420         (**ho).postfontchangecallback = (opvoidcallback) &claybrowserinitdraw;
00421         
00422         (**ho).getfullrectcallback = (opgefullrectcallback) &claygetnodeframe;
00423         }*/
00424 
00425     (**ho).preexpandcallback = browserpreexpand;
00426     
00427     (**ho).postcollapsecallback = browserpostcollapse;
00428     
00429     (**ho).hasdynamicsubscallback = browsercanexpand;
00430     
00431     (**ho).textchangedcallback = browsertextchanged;
00432     
00433     (**ho).insertlinecallback = browserlineinserted;
00434     
00435     (**ho).deletelinecallback = browserlinedeleted;
00436     
00437     (**ho).copyrefconcallback = browsercopyrefcon;
00438     
00439     (**ho).textualizerefconcallback = browsertextualizerefcon;
00440     
00441     (**ho).releaserefconcallback = browserreleaserefcon;
00442     
00443     (**ho).setwpedittextcallback = tablesetwpedittext; /*edits the node's headstring*/
00444     
00445     (**ho).getwpedittextcallback = tablegetwpedittext; /*updates the node's headstring*/
00446     
00447     (**ho).validatedragcallback = browservalidatedrag;
00448     
00449     (**ho).predragcallback = browserpredrag;
00450     
00451     (**ho).dragcopycallback = browserdragcopy;
00452     
00453     (**ho).mouseinlinecallback = tablemouseinline;
00454     
00455     (**ho).adjustcursorcallback = tableadjustcursor;
00456     
00457     (**ho).icon2clickcallback = tableicon2click;
00458     
00459     (**ho).validatepastecallback = browservalidatepaste;
00460     
00461 //  (**ho).postpastecallback = browserpostpaste;
00462     
00463     (**ho).validatecopycallback = browservalidatecopy;
00464     
00465 //  (**ho).caneditcallback = browsernodeislocked;
00466     
00467 //  (**ho).returnkeycallback = tablereturnkey;
00468     
00469     (**ho).setscrapcallback = (opsetscrapcallback) browsersetscrap;
00470 
00471     (**ho).getscrapcallback = (opgetscrapcallback) browsergetscrap;
00472     
00473     (**ho).beforeprintpagecallback = tablebeforeprintpage;
00474 
00475     (**ho).afterprintpagecallback = tableafterprintpage;
00476     } /*setuptableoutlinecallbacks*/
00477 
00478 
00479 static boolean duplicateexpansion (hdlheadrecord, hdlheadrecord); // forward
00480 
00481 static boolean duplicateexpansionvisit (hdlheadrecord hnode, ptrvoid refcon) {
00482     
00483     if (opsubheadsexpanded (hnode)) {
00484         
00485         hdlheadrecord hfirstnew = (hdlheadrecord) refcon;
00486         bigstring bs;
00487         hdlheadrecord hmatch;
00488         
00489         opgetheadstring (hnode, bs);
00490         
00491         if (opfindhead (hfirstnew, bs, &hmatch))
00492             duplicateexpansion (hnode, hmatch);
00493         }
00494     
00495     return (true);
00496     } /*duplicateexpansionvisit*/
00497 
00498 
00499 static boolean duplicateexpansion (hdlheadrecord horig, hdlheadrecord hnew) {
00500     
00501     opexpand (hnew, 1, true);
00502     
00503     return (oplistvisit ((**horig).headlinkright, duplicateexpansionvisit, (**hnew).headlinkright));
00504     } /*duplicateexpansion*/
00505 
00506 
00507 static boolean initializetableoutline (hdloutlinerecord ho, hdlhashtable ht) {
00508     
00509     /*
00510     5.0.2b21 dmb: use shellgetdatabase, not databasedata global
00511     
00512     5.1.3 dmb: roll beachball; don't ignore clayfolderloop return value
00513     */
00514 
00515     hdlheadrecord hsummit = (**ho).hsummit;
00516     hdlheadrecord hnewsummit, hlastsummit;
00517     hdlheadrecord nomad, hnext;
00518     tybrowserspec fsroot;
00519     tyexpandinfo expandinfo;
00520     hdlwindowinfo hinfo;
00521     long lnumcursor;
00522     boolean fl = false;
00523     
00524     oppushoutline (ho);
00525     
00526     opgetnodeline ((**ho).hbarcursor, &lnumcursor);
00527     
00528     hlastsummit = hsummit;
00529     
00530     while (opchasedown (&hlastsummit))
00531         ;
00532     
00533     opdisabledisplay ();
00534     
00535     opsetdisplaydefaults (ho);
00536     
00537     expandinfo.hparent = nil; /*special case, see browserfindinsertionpoint*/
00538     
00539     expandinfo.ctlevels = 1;
00540     
00541     expandinfo.flsortnodes = false;
00542     
00543     expandinfo.flsettmpbits = false;
00544     
00545     if (shellfinddatawindow ((Handle) (**ho).outlinerefcon, &hinfo))
00546         shellgetdatabase ((**hinfo).macwindow, &fsroot.vRefNum);
00547     else
00548         fsroot.vRefNum = databasedata;
00549     
00550     fsroot.parID = ht;
00551     
00552     setemptystring (fsroot.name);
00553     
00554     initbeachball (right);
00555     
00556     if (!clayfolderloop (&fsroot, false, browserexpandvisit, (long) &expandinfo))
00557         goto exit;
00558     
00559     hnewsummit = (**hlastsummit).headlinkdown;
00560     
00561     if (hnewsummit == hlastsummit) { // table was empty
00562         
00563         browserlineinserted (hnewsummit);
00564         
00565         (**ho).fltextmode = true;
00566         
00567         opeditsetselection (0, infinity);
00568         }
00569     else { // table was not empty
00570     
00571         opstartinternalchange (); 
00572         
00573         nomad = hsummit;
00574         
00575         hnewsummit = (**hlastsummit).headlinkdown;
00576         
00577         while (true) {
00578             
00579             hnext = (**nomad).headlinkdown;
00580             
00581             duplicateexpansionvisit (nomad, hnewsummit);
00582             
00583             opunlink (nomad);
00584             
00585             opdisposestructure (nomad, false);
00586             
00587             if (hnext == hnewsummit)
00588                 break;
00589             
00590             nomad = hnext;
00591             }
00592         
00593         (**ho).hbarcursor = oprepeatedbump (flatdown, lnumcursor, hnewsummit, true);
00594         
00595         (**ho).hline1 = oprepeatedbump (flatdown, (**ho).vertscrollinfo.cur, hnewsummit, true);
00596         
00597         opendinternalchange ();
00598         
00599         opdirtymeasurements (); //6.0a14 dmb
00600         
00601         opsetctexpanded (ho);
00602         }
00603     
00604     #ifdef fldebug
00605         opvalidate (outlinedata);
00606     #endif
00607     
00608     fl = true;
00609     
00610 exit:
00611     openabledisplay ();
00612     
00613     oppopoutline ();
00614     
00615 //  (**(**ho).hsummit).flnodeisfolder = true;
00616     
00617     return (fl);
00618     } /*initializetableoutline*/
00619 
00620 
00621 static boolean validatetableoutline (hdloutlinerecord ho, hdltableformats hf, hdlhashtable ht) {
00622     
00623     // 5.0d18 dmb: must link table & outline now, so globals can be
00624     // maintained as outline is initialized
00625 
00626     (**hf).houtline = ho;   // point to outline
00627     
00628     (**ho).outlinerefcon = (long) hf; // pointing is mutual
00629     
00630     return (initializetableoutline (ho, ht));
00631     } /*validatetableoutline*/
00632 
00633 
00634 boolean newtableformats (hdltableformats *hformats) {
00635     
00636     /*
00637     allocate a new tableformats record, and set the fields to 
00638     their default values.
00639     
00640     4.0b7 dmb: initialize timelastsave to creation time; it's really a modification date.
00641     
00642     5.0d1 dmb: rewrote. table windows are outlines now. don't allocate
00643     the outline here, however.
00644     */
00645     
00646     register hdltableformats hf;
00647     //Rect r;
00648     
00649     if (!newclearhandle (sizeof (tytableformats), (Handle *) hformats))
00650         return (false);
00651     
00652     hf = *hformats; /*copy into register*/
00653     
00654     (**hf).ctcols = maxtablecols; /* 2005-10-03 creedon - in case more columns are added, just one place to change*/
00655     
00656     //(**hf).defaultcolwidth = (r.right - r.left) / fixedctcols; /*arrgh: slight bias to 3-col tables*/
00657     
00658     return (true);
00659     } /*newtableformats*/
00660 
00661 
00662 void disposetableformats (hdltableformats hformats) {
00663     
00664     if (hformats != nil)
00665         opdisposeoutline ((**hformats).houtline, false);
00666     
00667     disposehandle ((Handle) hformats);
00668     } /*disposetableformats*/
00669 
00670 
00671 static boolean tablenewoutlinerecord (hdltableformats hf, hdlhashtable ht) {
00672     
00673     /*
00674     5.1.3 dmb: handle errors
00675     */
00676     
00677     hdloutlinerecord ho;
00678     
00679     if (!newoutlinerecord (&ho)) {
00680         
00681         disposehandle ((Handle) hf);
00682         
00683         return (false);
00684         }
00685     
00686     (**ho).outlinetype = outlineistable;
00687 
00688     (**ho).fontnum = (**hf).fontnum;
00689     
00690     (**ho).fontsize = (**hf).fontsize;
00691     
00692     (**ho).fontstyle = (**hf).fontstyle;
00693     
00694     // 6.11.97 dmb: must link table & outline now, so globals can be
00695     // maintained as outline is initialized
00696 
00697     (**hf).houtline = ho;   // xxx - point to outline now that's it's been initialized
00698     
00699     (**ho).outlinerefcon = (long) hf; // pointing is mutual
00700     
00701     if (!initializetableoutline (ho, ht)) {
00702         
00703         opdisposeoutline (ho, false);
00704         
00705         disposehandle ((Handle) hf);
00706         
00707         return (false);
00708         }
00709     
00710     setuptableoutlinecallbacks (ho);
00711     
00712     return (true);
00713     } /*tablenewoutlinerecord*/
00714 
00715 
00716 boolean tableprepareoutline (hdltableformats hf) {
00717     
00718     hdlhashtable ht = (**hf).htable;
00719     hdloutlinerecord ho = (**hf).houtline;
00720 
00721     if (ho == nil)
00722         return (tablenewoutlinerecord (hf, ht));
00723     else
00724         return (validatetableoutline (ho, hf, ht));
00725     } /*tableprepareoutline*/
00726 
00727 
00728 void tabledisposeoutline (hdltableformats hf) {
00729 
00730     //hdlhashtable ht = (**hf).htable;
00731     hdloutlinerecord ho = (**hf).houtline;
00732 
00733     if (ho == nil)
00734         return;
00735     
00736     // grab display setting from outline
00737     (**hf).fontnum = (**ho).fontnum;
00738     
00739     (**hf).fontsize = (**ho).fontsize;
00740     
00741     (**hf).fontstyle = (**ho).fontstyle;
00742     
00743     (**hf).vertcurrent = (**ho).vertscrollinfo.cur;
00744     
00745     opgetnodeline ((**ho).hbarcursor, &(**hf).vertcurrent);
00746 
00747     // if we have an auto-generated node, delete the table entry
00748     
00749     /*
00750     hdlheadrecord nomad;
00751     long ctitems;
00752     nomad = (**ho).hsummit;
00753     
00754     if ((**nomad).tmpbit2) {
00755     
00756         hashcountitems (ht, &ctitems);
00757         
00758         if ((ctitems == 1) && (**(**ht).hfirstsort).val.valuetype == novaluetype)
00759             emptyhashtable (ht, true);
00760         }
00761     */
00762     
00763     (**ho).flinternalchange++; // we shouldn't be connected to a window, but just in case...
00764     
00765     browserdeletedummyvalues ((**ho).hsummit);
00766     
00767     // unlink & dispose
00768 //  if (ho == outlinedata)
00769 //      outlinedata = nil;
00770     
00771     (**hf).houtline = nil;
00772     
00773     opdisposeoutline (ho, false);
00774     } /*tabledisposeoutline*/
00775 
00776 
00777 boolean tablenewformatsrecord (hdlhashtable ht, Rect tablerect, hdltableformats *hformats) {
00778 #pragma unused(tablerect)
00779 
00780     /*
00781     allocate a new tableformats and set default and/or initial values of fields of
00782     the record.
00783     */
00784      
00785     register hdltableformats hf = nil;
00786     tyconfigrecord lconfig;
00787     
00788     if (!newtableformats (hformats))
00789         return (false);
00790     
00791     hf = *hformats; /*copy into register*/
00792     
00793     langexternalgetconfig (tablevaluetype, idtableconfig, &lconfig);
00794     
00795     (**hf).windowrect = lconfig.defaultwindowrect;
00796     
00797     (**hf).fontnum = lconfig.defaultfont;
00798     
00799     (**hf).fontsize = lconfig.defaultsize;
00800     
00801     (**hf).fontstyle = lconfig.defaultstyle;
00802     
00803     tableformatsdata = hf; /*set global for displayinfo routine*/
00804     
00805     tablelinkformats (ht, hf); /*link formats record and hashtable*/
00806     
00807     /*
00808     if (!tablenewoutlinerecord (hf, ht)) {
00809         
00810         disposetableformats (hf);
00811         
00812         return (false);
00813         }
00814     
00815     tableresetrects (tablerect);
00816     
00817     x = (tablerect.right - tablerect.left) / ctcols; /%initial column width%/
00818     
00819     x = (**hf).defaultcolwidth = tablelimitcolwidth (x);
00820     
00821     for (i = 0; i < ctcols; i++) 
00822         (**hf).colwidths [i] = x;
00823     */
00824     
00825     //if (isclaydisplay (hf))
00826     //  claybrowserinitdraw (); //sets the computed fields of (**hf).linelayout
00827     
00828     return (true);
00829     } /*tablenewformatsrecord*/
00830 
00831 
00832 static boolean notexpandedvisit (hdlheadrecord hnode, ptrvoid refcon)  {
00833 #pragma unused (refcon)
00834 
00835     return (!opsubheadsexpanded (hnode));
00836     } /*notexpandedvisit*/
00837 
00838 
00839 boolean tableoutlineneedssaving (void) {
00840     
00841     if (outlinedata == nil)
00842         return (false);
00843     
00844     return (!opsummitvisit (notexpandedvisit, nil)); // something expanded
00845     } /*tableoutlineneedssaving*/
00846 
00847 
00848 boolean tablepackformats (Handle *hpacked) {
00849     
00850     /*
00851     pack the data from the current tableformatsdata record into a compact form, suitable
00852     for saving to disk.  we only record the formatting options, it is up to the 
00853     other guy to save the data that's being displayed in the table.
00854 
00855     save font/size/style settings when we're not saving an outline
00856     */
00857     
00858     register hdltableformats hf = tableformatsdata;
00859     hdloutlinerecord ho = outlinedata;
00860     tyversion2tablediskrecord info;
00861     int i;
00862     long vertcurrent, lnumcursor;
00863     
00864     clearbytes (&info, sizeof (info));
00865     
00866     info.versionnumber = conditionalshortswap (0x0010);
00867     
00868     info.recordsize = conditionalshortswap (sizeof (tyversion2tablediskrecord));
00869     
00870     info.ctcols = conditionalshortswap ((**hf).ctcols);
00871     
00872     info.colcursor = conditionalshortswap ((**hf).editcol);
00873     
00874     info.savedoutline = tableoutlineneedssaving ();
00875     
00876     info.savedlinelayout = (**hf).linelayout.flinitted;
00877     
00878 /*  moveleft ((**hf).colwidths, info.colwidths, maxtablecols * sizeof (short)); */
00879 
00880     for (i = 0; i < maxtablecols; i++) {
00881         info.colwidths[i] = conditionalshortswap ((**hf).colwidths[i]);
00882         }
00883     
00884     recttodiskrect (&(**hf).windowrect, &info.windowrect);
00885     
00886     if ((ho != nil) && !info.savedoutline) {
00887         
00888         diskgetfontname ((**ho).fontnum, info.fontname);
00889         
00890         info.fontsize = conditionalshortswap ((**ho).fontsize);
00891         
00892         info.fontstyle = conditionalshortswap ((**ho).fontstyle);
00893         
00894         vertcurrent = (**ho).vertscrollinfo.cur;
00895         
00896         memlongtodiskwords (vertcurrent, info.vertcurrent, info.vertcurrent_hiword);
00897         
00898         opgetnodeline ((**ho).hbarcursor, &lnumcursor);
00899         
00900         memlongtodiskwords (lnumcursor, info.lnumcursor, info.lnumcursor_hiword);
00901         }
00902     else {
00903         
00904         diskgetfontname ((**hf).fontnum, info.fontname);
00905         
00906         info.fontsize = conditionalshortswap ((**hf).fontsize);
00907         
00908         info.fontstyle = conditionalshortswap ((**hf).fontstyle);
00909         }
00910 
00911     if (!newfilledhandle (&info, sizeof (info), hpacked))
00912         return (false);
00913     
00914     if (info.savedoutline) {
00915         
00916         if (!oppack (hpacked))
00917             goto error;
00918         }
00919     
00920     if (info.savedlinelayout) {
00921         
00922         if (!claypacklinelayout (*hpacked))
00923             goto error;
00924         }
00925     
00926     return (true);
00927     
00928     error:
00929         disposehandle (*hpacked);
00930         
00931         *hpacked = nil;
00932     
00933         return (false);
00934     } /*tablepackformats*/
00935 
00936 
00937 static boolean tableunpackversion1formats (Handle hpacked, hdltableformats hformats) {
00938     
00939     /*
00940     5/7/93: added flsavedsorted and introduce new version logic: anything from 
00941     1 to 10 is cool. in the future, to _prevent_ backward compatibility, bump it 
00942     to 11 or higher
00943     */
00944     
00945     register hdltableformats hf = hformats;
00946     long ixhandle = 0;
00947     tyversion1tablediskrecord info;
00948     short fontnum;
00949     hdlhashtable ht = (**hf).htable;
00950     
00951     if (!loadfromhandle (hpacked, &ixhandle, sizeof (info), &info)) {
00952         
00953         shellinternalerror (iderrorloadingformats, BIGSTRING ("\x2b" "error loading table formatting information."));
00954         
00955         return (false);
00956         }
00957     
00958     (**hf).editcol = conditionalshortswap (info.colcursor);
00959     
00960     (**hf).ctcols = max (conditionalshortswap (info.ctcols), (**hf).ctcols);
00961     
00962     (**ht).sortorder = conditionalshortswap (info.sortorder);
00963     
00964     (**ht).timecreated = conditionallongswap (info.timecreated);
00965     
00966     (**ht).timelastsave = conditionallongswap (info.timelastsave);
00967     
00968 //  if (!info.flsavedsorted) {
00969 //      
00970 //      (**hf).fldirty = true; /*old table, wasn't saved sorted*/
00971         
00972 //      if (info.sortorder != sortbyname)
00973 //          (**hf).flneedresort = true;
00974 //      }
00975     
00976     diskrecttorect (&info.windowrect, &(**hf).windowrect);
00977     
00978     disktomemlong (info.sizerowarray);
00979     disktomemlong (info.sizecolarray);
00980 
00981     ixhandle += info.sizerowarray;
00982     
00983     if (info.sizecolarray <= maxtablecols * sizeof (short))
00984         loadfromhandle (hpacked, &ixhandle, info.sizecolarray, (**hf).colwidths);
00985     
00986     diskgetfontnum (info.fontname, &fontnum);
00987     
00988     (**hf).fontnum = fontnum;
00989     
00990     (**hf).fontsize = conditionalshortswap (info.fontsize);
00991     
00992     (**hf).fontstyle = conditionalshortswap (info.fontstyle);
00993     
00994     (**hf).vertcurrent = conditionalshortswap (info.vertcurrent);
00995     
00996     (**hf).lnumcursor = conditionalshortswap (info.rowcursor);
00997     
00998     /*
00999     (**hf).linespacing = info.linespacing;
01000     
01001     (**hf).ctsaves = info.ctsaves;
01002     */
01003     
01004 //  tablepushformats (hf);
01005 //  
01006 //  tablelimitformats (); /*check the colwidths and rowheights arrays*/
01007 //  
01008 //  tablepopformats ();
01009     
01010     return (true);
01011     } /*tableunpackversion1formats*/
01012 
01013 
01014 boolean tableunpackformats (Handle hpacked, hdltableformats hformats) {
01015     
01016     /*
01017     unpack the table formats from the handle.  we take care not to reduce the
01018     size of the table using these formats, rather add the information to the 
01019     set of info we have about the table.
01020     
01021     for example, if we only have column widths for two of four columns, we apply
01022     the information to the two we have, and leave the other two alone.  earlier
01023     versions would have reduced the table size, effectively throwing away 
01024     columns.  this makes it easy for tables to grow, either according to the
01025     wishes of a user, or a using program.
01026     
01027     10/16/91 dmb: added paranoia check to ensure that row and column arrays 
01028     are big enough for the current table size.  an old database bug would 
01029     lead to this not being the case; better safe than sorry!
01030     
01031     5/7/93: added flsavedsorted and introduce new version logic: anything from 
01032     1 to 10 is cool. in the future, to _prevent_ backward compatibility, bump it 
01033     to 11 or higher
01034     */
01035     
01036     register hdltableformats hf = hformats;
01037     hdloutlinerecord ho;
01038     long ixhandle = 0;
01039     tyversion2tablediskrecord info;
01040     short fontnum;
01041     boolean fl;
01042     int i;
01043     #define sizepreload (sizeof (info.versionnumber) + sizeof (info.recordsize))
01044     
01045     if (hpacked == nil) /*defensive driving, return true, default formats*/
01046         return (true);
01047     
01048     // load first field - the record size
01049     if (!loadfromhandle (hpacked, &ixhandle, sizepreload, &info))
01050         goto loaderror;
01051     
01052     disktomemshort (info.versionnumber);
01053 
01054     disktomemshort (info.recordsize);
01055     
01056     //validate version
01057     if (info.versionnumber == 1)
01058         return (tableunpackversion1formats (hpacked, hf));
01059     
01060     if ((info.versionnumber < 1) || (info.versionnumber > 0x001f)) { /*not in handleable range*/
01061         
01062         shellinternalerror (idbadtableformatsversion, BIGSTRING ("\x21" "bad table formats version number."));
01063         
01064         return (false);
01065         }
01066     
01067     // load remaining data in record
01068     if (!loadfromhandle (hpacked, &ixhandle, min (sizeof (info), info.recordsize) - sizepreload, &info.fontname))
01069         goto loaderror;
01070     
01071     //load table outline
01072     if (info.savedoutline) {
01073 
01074         tyconfigrecord lconfig;
01075         
01076         langexternalgetconfig (tablevaluetype, idtableconfig, &lconfig); // force loading of prefs
01077     
01078         fl = opunpack (hpacked, &ixhandle, &ho);
01079         
01080         if (!fl)
01081             return (false);
01082         
01083         setuptableoutlinecallbacks (ho);
01084         
01085     // can't do this here:  validatetableoutline (ho, (**hf).htable);
01086         
01087         (**hf).houtline = ho;
01088         }
01089     else {
01090     
01091         diskgetfontnum (info.fontname, &fontnum);
01092         
01093         if (isemptystring (info.fontname)) //it was munged in beta
01094             (**hf).fontnum = config.defaultfont;
01095         else
01096             (**hf).fontnum = fontnum;
01097         
01098         if (info.fontsize == 0) //it was munged in beta
01099             (**hf).fontsize = config.defaultsize;
01100         else
01101             (**hf).fontsize = conditionalshortswap (info.fontsize);
01102         
01103         (**hf).fontstyle = conditionalshortswap (info.fontstyle);
01104         
01105         (**hf).vertcurrent = diskwordstomemlong (info.vertcurrent, info.vertcurrent_hiword);
01106         
01107         (**hf).lnumcursor = diskwordstomemlong (info.lnumcursor, info.lnumcursor_hiword);
01108         }
01109     
01110     (**hf).editcol = conditionalshortswap (info.colcursor);
01111     
01112     (**hf).ctcols = conditionalshortswap (info.ctcols);
01113     
01114     #ifdef fldebug
01115         /* 2005-10-03 creedon: in case more columns are added, just one place to change */ 
01116         if ((**hf).ctcols != maxtablecols) {
01117         //  assert ((**hf).ctcols == 3); // report it
01118             (**hf).ctcols = maxtablecols;            // fix it
01119             }
01120     #endif
01121     
01122     /* moveleft (info.colwidths, (**hf).colwidths, maxtablecols * sizeof (short));  */
01123 
01124     for (i = 0; i < maxtablecols; i++) {
01125         (**hf).colwidths[i] = conditionalshortswap (info.colwidths[i]);
01126         }
01127     
01128     diskrecttorect (&info.windowrect, &(**hf).windowrect);
01129     
01130     if (info.savedlinelayout) {
01131         
01132         if (!clayunpacklinelayout (hpacked, &ixhandle, hf))
01133             return (false);
01134         }
01135     
01136 //  tablepushformats (hf);
01137 //  
01138 //  tablelimitformats (); /*check the colwidths and rowheights arrays*/
01139 //  
01140 //  tablepopformats ();
01141     
01142     return (true);
01143     
01144     loaderror:
01145         
01146         shellinternalerror (iderrorloadingformats, BIGSTRING ("\x2b" "error loading table formatting information."));
01147         
01148         return (false);
01149     } /*tableunpackformats*/
01150 
01151 

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