home *** CD-ROM | disk | FTP | other *** search
- /*
- Ghardeno: Information Gardening for PalmOS
- Copyright (C) 2000 Laurent Moussault
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- #include <Common.h>
- #include <System/SysAll.h>
- #include <UI/UIAll.h>
-
- #include "DBC.h"
- #include "Resources.h"
- #include "Ghardeno.h"
- #include "Database.h"
-
-
- ////
- /// Constantes
- //
-
-
- #define dbFontMask 3
- #define dbStrokeMask 4
-
- static const FontID dbFonts[] = {stdFont, boldFont, largeFont};
- static Word dbHeights[3];
-
- void DbInit() {
- int i;
- for(i = 0; i < 3; i++) {
- FntSetFont(dbFonts[i]);
- dbHeights[i] = FntLineHeight();
- }
- }
-
- void DbLoadRecord (VoidHand h, FontID *fid, Word *yh) {
- Char *r = 0;
- REQUIRE(h != 0);
- REQUIRE(fid != 0);
- REQUIRE(yh != 0);
- r = MemHandleLock(h); CHECK(r != 0);
- *fid = dbFonts[*r & dbFontMask];
- *yh = dbHeights[*r & dbFontMask];
- MemHandleUnlock(h);
- }
-
-
- ////
- /// Drawing
- //
-
- /*
- * Draw the record inside the bounds 'b', in edit mode if 'e' is true.
- */
- void DbDrawRecord (VoidHand h, RectangleType *b, Boolean e) {
- int xx, yy;
- Char *r = 0;
- FormType *f = 0;
- FieldType *fi = 0;
- Word foi = 0;
- Word lh = 0, lx = 0;
- int l = 0;
- RectangleType bb;
- REQUIRE(h != 0);
- r = MemHandleLock(h);
- lh = dbHeights[*r & dbFontMask];
- WinEraseRectangle(b,0);
- RctCopyRectangle (b, &bb);
- bb.topLeft.x += 2;
- bb.topLeft.y += (lh)/2 - 2;
- bb.extent.x = 5;
- bb.extent.y = 5;
- WinDrawRectangle (&bb, 3);
- if(e) {
- f = FrmGetActiveForm();
- foi = FrmGetObjectIndex(f,id_field);
- fi = FrmGetObjectPtr(f,foi);
- FrmSetFocus(f,noFocus);
- RctCopyRectangle(b,&fi->rect);
- fi->rect.topLeft.x += bulletWidth;
- fi->rect.extent.x -= bulletWidth;
- fi->fontID = dbFonts[*r & dbFontMask];
- FrmShowObject(f,foi);
- FldDrawField(fi);
- FrmSetFocus(f,foi);
- } else {
- FntSetFont(dbFonts[*r & dbFontMask]);
- for(l = 0;
- l <= StrLen(&(r[1])) && FntLineWidth(&(r[1]),l) < (b->extent.x - bulletWidth);
- l++ )
- ;
- if(l>0) {
- l--;
- }
- WinDrawChars(&(r[1]),l, b->topLeft.x+bulletWidth, b->topLeft.y );
- if(*r & dbStrokeMask) {
- lx = FntLineWidth(&(r[1]),l);
- WinDrawLine(b->topLeft.x+bulletWidth-1,b->topLeft.y+(lh+1)/2,
- b->topLeft.x+bulletWidth+lx, b->topLeft.y+(lh+1)/2);
- WinDrawLine(b->topLeft.x+bulletWidth-1,b->topLeft.y+(lh+1)/2+1,
- b->topLeft.x+bulletWidth+lx,b->topLeft.y+(lh+1)/2+1);
- /*
- for (xx = b->topLeft.x-b->extent.y+1; xx < b->topLeft.x+b->extent.x; xx += 2)
- WinEraseLine (xx, b->topLeft.y+b->extent.y-1, xx+b->extent.y-1, b->topLeft.y);
- */
- }
- }
- MemHandleUnlock(h);
- }
-
-
- ////
- ///
- //
-
- Word DbPurgeStrokenItems(DmOpenRef d, Word c) {
- VoidHand h = 0;
- Char *r = 0;
- Word n = 0;
- Word i = 0;
- Boolean p = false;
- REQUIRE(d != 0);
- h = DmQueryNextInCategory(d,&i,c);
- while(h != 0) {
- r = MemHandleLock(h); CHECK(r != 0);
- p = *r & dbStrokeMask;
- MemHandleUnlock(h);
- if(p) {
- DmDeleteRecord(d,i);
- DmMoveRecord (d,i,DmNumRecords(d));
- n++;
- } else {
- i++;
- }
- h = DmQueryNextInCategory(d,&i,c);
- }
- return n;
- }
-