home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / hobby / ghardeno / ghardeno.EXE / Database.c < prev    next >
C/C++ Source or Header  |  2000-10-03  |  4KB  |  152 lines

  1. /*
  2.     Ghardeno: Information Gardening for PalmOS
  3.     Copyright (C) 2000 Laurent Moussault
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include <Common.h>
  21. #include <System/SysAll.h>
  22. #include <UI/UIAll.h>
  23.  
  24. #include "DBC.h"
  25. #include "Resources.h"
  26. #include "Ghardeno.h"
  27. #include "Database.h"
  28.  
  29.  
  30. ////
  31. /// Constantes
  32. //
  33.  
  34.  
  35. #define dbFontMask 3
  36. #define dbStrokeMask 4
  37.  
  38. static const FontID dbFonts[] = {stdFont, boldFont, largeFont};
  39. static Word dbHeights[3];
  40.  
  41. void DbInit() {
  42.   int i;
  43.   for(i = 0; i < 3; i++) {
  44.     FntSetFont(dbFonts[i]);
  45.     dbHeights[i] = FntLineHeight();
  46.   }
  47. }
  48.  
  49. void DbLoadRecord (VoidHand h, FontID *fid, Word *yh) {
  50.   Char *r = 0;
  51.   REQUIRE(h != 0);
  52.   REQUIRE(fid != 0);
  53.   REQUIRE(yh != 0);
  54.   r = MemHandleLock(h); CHECK(r != 0);
  55.   *fid = dbFonts[*r & dbFontMask];
  56.   *yh = dbHeights[*r & dbFontMask];
  57.   MemHandleUnlock(h);
  58. }
  59.  
  60.  
  61. ////
  62. /// Drawing
  63. //
  64.  
  65. /*
  66.  * Draw the record inside the bounds 'b', in edit mode if 'e' is true.
  67.  */
  68. void DbDrawRecord (VoidHand h, RectangleType *b, Boolean e) {
  69.   int xx, yy;
  70.   Char *r = 0;
  71.   FormType *f = 0;
  72.   FieldType *fi = 0;
  73.   Word foi = 0;
  74.   Word lh = 0, lx = 0;
  75.   int l = 0;
  76.   RectangleType bb;
  77.   REQUIRE(h != 0);
  78.   r = MemHandleLock(h);
  79.   lh = dbHeights[*r & dbFontMask];
  80.   WinEraseRectangle(b,0);
  81.   RctCopyRectangle (b, &bb);
  82.   bb.topLeft.x += 2;
  83.   bb.topLeft.y += (lh)/2 - 2;
  84.   bb.extent.x = 5;
  85.   bb.extent.y = 5;
  86.   WinDrawRectangle (&bb, 3);
  87.   if(e) {
  88.     f = FrmGetActiveForm();
  89.     foi = FrmGetObjectIndex(f,id_field);
  90.     fi = FrmGetObjectPtr(f,foi);
  91.     FrmSetFocus(f,noFocus);
  92.     RctCopyRectangle(b,&fi->rect);
  93.     fi->rect.topLeft.x += bulletWidth;
  94.     fi->rect.extent.x -= bulletWidth;
  95.     fi->fontID = dbFonts[*r & dbFontMask];
  96.     FrmShowObject(f,foi);
  97.     FldDrawField(fi);
  98.     FrmSetFocus(f,foi);
  99.   } else {
  100.     FntSetFont(dbFonts[*r & dbFontMask]);
  101.     for(l = 0;
  102.     l <= StrLen(&(r[1])) && FntLineWidth(&(r[1]),l) < (b->extent.x - bulletWidth);
  103.     l++ )
  104.       ;
  105.     if(l>0) {
  106.       l--;
  107.     }
  108.     WinDrawChars(&(r[1]),l, b->topLeft.x+bulletWidth, b->topLeft.y );
  109.     if(*r & dbStrokeMask) {
  110.       lx = FntLineWidth(&(r[1]),l);
  111.       WinDrawLine(b->topLeft.x+bulletWidth-1,b->topLeft.y+(lh+1)/2,
  112.           b->topLeft.x+bulletWidth+lx, b->topLeft.y+(lh+1)/2);
  113.       WinDrawLine(b->topLeft.x+bulletWidth-1,b->topLeft.y+(lh+1)/2+1,
  114.           b->topLeft.x+bulletWidth+lx,b->topLeft.y+(lh+1)/2+1);
  115.       /*
  116.       for (xx = b->topLeft.x-b->extent.y+1; xx < b->topLeft.x+b->extent.x; xx += 2)
  117.     WinEraseLine (xx, b->topLeft.y+b->extent.y-1, xx+b->extent.y-1, b->topLeft.y);
  118.       */
  119.     }
  120.   }
  121.   MemHandleUnlock(h);
  122. }
  123.  
  124.  
  125. ////
  126. ///
  127. //
  128.  
  129. Word DbPurgeStrokenItems(DmOpenRef d, Word c) {
  130.   VoidHand h = 0;
  131.   Char *r = 0;
  132.   Word n = 0;
  133.   Word i = 0;
  134.   Boolean p = false;
  135.   REQUIRE(d != 0);
  136.   h = DmQueryNextInCategory(d,&i,c);
  137.   while(h != 0) {
  138.     r = MemHandleLock(h); CHECK(r != 0);
  139.     p = *r & dbStrokeMask;
  140.     MemHandleUnlock(h);
  141.     if(p) {
  142.       DmDeleteRecord(d,i);
  143.       DmMoveRecord (d,i,DmNumRecords(d));
  144.       n++;
  145.     } else {
  146.       i++;
  147.     }
  148.     h = DmQueryNextInCategory(d,&i,c);
  149.   }
  150.   return n;
  151. }
  152.