home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
linuxmafia.com 2016
/
linuxmafia.com.tar
/
linuxmafia.com
/
pub
/
palmos
/
progect-src-0.20.tar.gz
/
progect-src-0.20.tar
/
progect-0.20
/
progect.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-10-26
|
117KB
|
4,833 lines
/* -*-Mode:C; tab-width:4; indent-tabs-mode:t; c-file-style:"stroustrup";-*- */
/* Main code for Project */
//#define ERROR_CHECK_LEVEL 2
#include <PalmOS.h>
#include <DateGlue.h>
#include <TxtGlue.h>
#include <FntGlue.h>
#include <TsmGlue.h>
#include <WinGlue.h>
#include "link.h"
#include "task.h"
#include "progectdb.h"
#include "progectRsc.h"
#include "progect.h"
#include "flat.h"
#include "btm.h"
// icon support
#include "icon.h"
// ToDo export support
#include "ToDoDB.h"
// Memo linking support
#include "MemoDB.h"
// address linking support
#include "AddressDB.h"
// Doc export support
#include "doc.h"
// not used yet
typedef enum {tblRedrawAll, tblRedrawTable, tblUpdateRedrawAll,
tblUpdateRedrawTable} redrawTableType;
// prototypes
// events
void ProgressHandleEvent(void) UISECT;
void PriorityHandleEvent(EventPtr e) UISECT;
UInt16 SelectRange(void) UISECT;
Boolean FrmMainMenuHandleEvent(EventPtr e) UISECT;
Boolean FrmMainCtlSelectHandleEvent(EventPtr e) UISECT;
Boolean FrmMainKeyDownHandleEvent(EventPtr e) UISECT;
static Boolean FrmMainHandleEvent (EventPtr e) UISECT;
static void UpdateIconButton(void) UISECT;
static Boolean FrmTaskEditHandleEvent (EventPtr e) UISECT;
static Boolean FrmProjectListHandleEvent (EventPtr e) UISECT;
Boolean HandleChooseNameButtonOK(void) UISECT;
static Boolean FrmChooseNameHandleEvent (EventPtr e) UISECT;
static Boolean FrmProjectPropertiesHandleEvent (EventPtr e) UISECT;
static Boolean FrmMemoExportPropertiesHandleEvent (EventPtr e) UISECT;
Boolean EditMenuHandleEvent(UInt16 menuid, FieldPtr fld) UISECT;
void FrmNoteEditUpdateScroll(void) UISECT;
void FrmNoteEditScrollPage(WinDirectionType direction) UISECT;
static Boolean FrmNoteEditHandleEvent (EventPtr e) UISECT;
Boolean FrmFlatCtlSelectHandleEvent(EventPtr e) UISECT;
void ProjectFlatTableUpdate(void) UISECT;
static Boolean FrmFlatHandleEvent (EventPtr e) UISECT;
static Boolean FrmFlatFilterHandleEvent (EventPtr e) UISECT;
static Boolean FrmDirectLinkHandleEvent (EventPtr e) UISECT;
static Boolean FrmDisplayPropertiesHandleEvent (EventPtr e) UISECT;
static Boolean FrmTaskDefaultsHandleEvent (EventPtr e) UISECT;
static Boolean ApplicationHandleEvent(EventPtr e);
static UInt16 StartApplication(void);
static void StopApplication(void);
static void EventLoop(void);
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags);
static void Search(FindParamsPtr findParams);
// icons
#define IconNum 13
MemHandle gIconHandle[IconNum]; // to hold handles to the bitmaps
// Globals
OSCaps_t OSCaps = {
false, false, false, false, false, false,
0, 0, 0, false
};
DmOpenRef gdbP = NULL; // actual database
DmOpenRef gClip = NULL; // clipboard database
UInt16 gActualTask = 0; // selected task
UInt16 gLastSelected = 0; // last selected task
UInt32 gFlatOffset = 0; // flat view offset of first item
TaskType gEmptyTask = {{{0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}},
6, 0, {0, 0, 0}, "", ""};
DateType gNoDate = {0, 0, 0};
Char gDateStr[10]; // to store a date string
UInt8 gLevelOffset = 0; // for horizontal scroll and subtree viewing
UInt16 gParentTask = 0; // the parent of all tasks for viewing purposes only
UInt8 gRefLevel = 0; // level of gParentTask;
Int16 gLastDownX, gLastDownY;
TablePtr gTable; // main form table
LocalID gdbID = 0; // id of opened database (set by OpenDB and CloseDB)
Char* namesData = NULL; // used by list selector
Char** names = NULL; // used by list selector
// used for date differences calculations
UInt8 gLimits[] = { 0, 1, 2, 3, 4, 5, 6, 7, 14, 21, 28 }; // UInt8 is to saving memory.
DateType gToday;
UInt32 gTodayDays; // to speed up day comparaisons calculations
UInt16 gCurrentSelection = 0; // current selection in project list
Char* docName; // use by FrmChooseName
UInt8 ChooseNameFunction = ChooseNameCreate;
// Preferences
DateFormatType gDateFormat; // actual date format (from palm, StartApplication)
ProjectPrefsType gProjectPrefs =
{
18, // format
0, // reserved
false, // hideDoneTasks
true, // displayDueDates
true, // displayPriorities
false, // displayYear
false, // useFatherStatus
true, // autoSyncToDo
true, // flatHideDone
2, // flatDated (0 = no, 1 = yes, 2 = not used)
3, // flatMinPriority
true, // flatOr
true, // flatMin
0, // boldMinPriority
0, // boldMinDays
false, // strikeDoneTasks
false, // hideDoneProgress
false, // hideProgress
// taskDefaults
{{{0, 0, 0, 0, 0, 0}}, {{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}},
6, 0, {0, 0, 0}, "", ""},
noSort, // flatSorted
0, // flatDateLimit
true // completionDate
};
CurrentPrefsType gCurrentPrefs; // current prefs, used to restore applic state
SavedPrefsType gSavedPrefs = {true}; // saved prefs, used to restore global
// application prefs
MemoExportOptionsType gMemoExportPrefs =
{
true, // exportDone;
true, // exportProgress;
true, // exportDueDate;
true, // exportPriority;
false, // exportNote;
false // exportOnlyTerminals;
};
static UInt16 wVerticalLines[11];
/****************************************************************************
* Name : GetObjectPtr
* Desc : get a pointer to an object of the current form
* Parm :
* -> ID of object to get a pointer to
* Out : ptr
* Auth : lb, 06.08.2000
***************************************************************************/
MemPtr GetObjectPtr(UInt16 ObjID)
{
FormPtr frm = FrmGetActiveForm();
return FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, ObjID));
} // MemPtr GetObjectPtr(UInt16 ObjID)
/****************************************************************************
* Name : Today
* Desc : return today's date
* Parm :
* Out : today's date
* Auth : lb, 06.08.2000
***************************************************************************/
DateType Today(void)
{
DateType date;
DateSecondsToDate(TimGetSeconds(), &date);
return date;
} // DateType Today(void)
/****************************************************************************
* Name : DateInLimit
* Desc : return true if passed date is within limit
* Parm :
* -> date to test
* -> offset in limits tab
* Out : date is in limit
* Auth : lb, 04.10.2000, from a modified version of seagull's original code
***************************************************************************/
Boolean DateInLimit(DateType date, UInt8 offset)
{
static UInt8 limits[] = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 14, 21, 28 }; // UInt8 is to saving memory.
UInt32 days = DateToDays(date);
Boolean overdue = (days < gTodayDays);
UInt32 diff = days > gTodayDays ?
days - gTodayDays : gTodayDays - days;
if (!offset)
return false;
return ((diff < (UInt32)limits[offset]) || overdue);
} // Boolean DateInLimit(DateType date, UInt8 offset)
/****************************************************************************
* Name : PrintDueDate
* Desc : print the date at given y pos
* Parm :
* -> the record
* -> the y position
* <-> the x position (in = right pos, out = left pos)
* Out :
* Auth : lb, 29.08.2000
***************************************************************************/
void PrintDueDate(TaskRecordType *p, UInt16 *datePos, UInt16 y)
{
Char dateStrMem[10]; // complete date + '!' + '\0'
Char* dateStr = dateStrMem;
UInt16 dateLen;
DateToAscii(p->dueDate.month, p->dueDate.day,
p->dueDate.year + YEAR_OFFSET, gDateFormat, dateStrMem); // start 1904
// calc the date length
if (!gProjectPrefs.displayYear)
{
switch(gDateFormat)
{
case dfYMDWithSlashes:
case dfYMDWithDots:
case dfYMDWithDashes:
dateStr += 3;
break;
default:
dateStr[StrLen(dateStr) - 3] = '\0';
break;
}
}
dateLen = StrLen(dateStr);
if (gTodayDays > DateToDays(p->dueDate))
{
// if the task is completed, don't write the !
if (p->completed != 10 && p->completed != ACTION_OK)
{
dateStr[dateLen++] = '!';
dateStr[dateLen] = '\0';
}
}
*datePos -= FntCharsWidth(dateStr, dateLen);
WinDrawChars(dateStr, dateLen, *datePos, y); // just draw days and month
} // void PrintDueDate(TaskRecordType *p, UInt16 &datePos, UInt16 y)
/****************************************************************************
* Name : SetFormTitle
* Desc : set the title of the given form
* Parm :
* Out :
* Auth : lb, 31.08.2000
***************************************************************************/
void SetFormTitle (FormPtr frm, Char *title)
{
Char titleArray[33];
UInt8 i;
// if prepended, skip prepend
if (StrStr(title, gPrepend) == title)
{
title += 5;
}
for (i = 0; i < 32 && *title; i++)
{
titleArray[i] = *title++;
}
titleArray[i] = '\0';
FrmCopyTitle(frm, titleArray);
} // void SetFormTitle (FormPtr frm, Char *title)
/****************************************************************************
* Name : DrawTruncText
* Desc : draw a text, trunc if too long
* Parm :
* -> string to draw
* -> x and y pos to draw
* -> x limit
* Out : -
* Auth : lb, 12.09.2000
***************************************************************************/
void DrawTruncText(Char *c, UInt16 x, UInt16 y, UInt16 limit)
{
Char * ptr = StrChr (c, linefeedChr);
UInt16 titleLen = (ptr == NULL ? StrLen (c) : (UInt16) (ptr - c));
if (OSCaps.ver32)
// best choise. complete nationalized. and got wide screen.
WinDrawTruncChars(c, titleLen, x, y, limit);
else if (OSCaps.ver30)
{ // 99% nationalized. and lost screen width.
Int16 length = titleLen;
Int16 len = length;
Int16 width = limit;
Boolean fitInWidth = false;
FntCharsInWidth(c, &width, &len, &fitInWidth);
if (fitInWidth)
WinDrawChars(c, length, x, y);
else
{
width = limit - TxtGlueCharWidth('.');
len = length;
fitInWidth = false;
FntCharsInWidth(c, &width, &len, &fitInWidth);
WinDrawChars(c, len, x, y);
WinDrawChars("...", 3, x + width, y);
}
}
else
{ // 0% nationalized. but best fit with many PalmOS versions.
Char *string = c;
UInt16 textWidth = 0;
Boolean trunc = false;
while (*c && *c != linefeedChr)
{
textWidth += FntCharWidth(*c);
if (textWidth > limit)
{
trunc = true;
break;
}
c++;
}
// now textwidth is in chars !!!
textWidth = (UInt16)(c - string);
WinDrawChars(string, textWidth, x, y);
if (trunc)
WinDrawChars("...", 3,
x + FntCharsWidth(string, textWidth), y);
}
} // void DrawTruncText(Char *c, UInt16 x, UInt16 y, UInt16 limit)
/****************************************************************************
* Name : ProjectDrawExtendedItemDesc
* Desc : draw an item desription
* Parm :
* -> pointer to the item
* -> x and y pos to draw
* Out : -
* Auth : lb, 12.09.2000
***************************************************************************/
void ProjectDrawExtendedItemDesc(TaskExtendedRecordType *p, UInt16 x, UInt16 y)
{
UInt16 datePos = 160;
UInt8 textPos = 0;
UInt16 limit;
Char* pDesc = NULL;
// draw note icon (if a note exist)
if (p->format.bits.hasNote)
{
datePos -= 6;
FntSetFont(symbolFont);
WinGlueDrawChar(symbolNote, datePos, y);
FntSetFont(stdFont);
datePos--;
}
// draw link-via icon
if (p->format.bits.hasLink)
{
MemHandle h = gIconHandle[BtmLinkMaster - BtmOffset];
BitmapPtr bitmap = (BitmapPtr)MemHandleLock(h);
datePos -= 8;
WinDrawBitmap(bitmap, datePos, y + 2);
MemHandleUnlock(h);
datePos--;
}
x += textPos;
limit = datePos - x - 7;
//
// draw attached icon
//
{
UInt16 iconid;
UInt16 size = sizeof(iconid);
if (pgOK == TaskGetExtraChunkByTaskPtr(p, Extra_Icon, 0,
&iconid, &size) &&
size == sizeof(iconid) &&
iconid < getNumIconsLoaded() )
{
drawIcon(iconid, x, y);
x += getIconWidth(iconid) + 2;
}
}
// draw the description (truncated)
pDesc = TaskGetDescriptionByTaskPtr(p);
FntSetFont(stdFont);
// if it's a direct link, and the destination is not existing anymore,
// nothing to print.
if (pDesc)
{
DrawTruncText(pDesc, x, y, limit);
MemPtrFree(pDesc);
}
} // void ProjectDrawExtendedItemDesc(TaskRecordType *p, UInt16 x, UInt16 y)
/****************************************************************************
* Name : ProjectDrawItemDesc
* Desc : draw an item desription
* Parm :
* -> pointer to the item
* -> x and y pos to draw
* Out : -
* Auth : lb, 12.09.2000
***************************************************************************/
void ProjectDrawItemDesc(TaskRecordType *p, UInt16 x, UInt16 y)
{
UInt16 datePos = 160;
UInt8 textPos = 0;
UInt16 limit;
RectangleType rectBounds;
// draw note icon (if a note exist)
if (p->format.bits.hasNote)
{
datePos -= 6;
FntSetFont(symbolFont);
WinGlueDrawChar(symbolNote, datePos, y);
datePos--;
}
// draw link-via icon
if (p->format.bits.hasLink)
{
MemHandle h = gIconHandle[BtmLinkMaster - BtmOffset];
BitmapPtr bitmap = (BitmapPtr)MemHandleLock(h);
datePos -= 8;
WinDrawBitmap(bitmap, datePos, y + 2);
MemHandleUnlock(h);
datePos--;
}
// draw the due date
// if no date, don't try to print a date
// if DisplayDueDates if false, don't print the date (preference)
if (p->dueDate.month != 0 && gProjectPrefs.displayDueDates)
{
FntSetFont(stdFont);
PrintDueDate(p, &datePos, y);
}
//
// draw progresses
//
if (!((gProjectPrefs.hideDoneProgress == true &&
(p->completed == ACTION_OK || p->completed == 10)) ||
gProjectPrefs.hideProgress))
{
// draw progress item
if (p->completed > ACTION)
{
if (OSCaps.ver32 || p->completed == ACTION_NO)
{
FntSetFont(symbol11Font);
WinGlueDrawChar( (p->completed == ACTION_OK) ?
symbolCheckboxOn : symbolCheckboxOff, x - 3, y);
FntSetFont(stdFont);
}
else
{
// get ToDo link icon
MemHandle h = gIconHandle[BtmCheckedBox - BtmOffset];
BitmapPtr bitmap = (BitmapPtr)MemHandleLock(h);
// draw it
WinDrawBitmap(bitmap, x - 2, y);
MemHandleUnlock(h);
}
}
else
{
// draw progress bar
RctSetRectangle(&rectBounds, x - 1, y + 4, 10, 3);
WinDrawRectangleFrame(simpleFrame, &rectBounds);
RctSetRectangle(&rectBounds, x - 1, y + 4, p->completed, 3);
WinDrawRectangle(&rectBounds, 0);
}
textPos += 13;
if (gProjectPrefs.displayPriorities && p->priority > 0 &&
p->priority < 6)
{
FntSetFont(stdFont);
WinGlueDrawChar('[', x + 12, y);
FntSetFont(boldFont);
WinGlueDrawChar(p->priority + '0', x + 15, y);
FntSetFont(stdFont);
WinGlueDrawChar(']', x + 22, y);
textPos += 13;
}
}
// High priority task draw bold font.
// I wish color to red.
FntSetFont(stdFont); // Initialy
if (p->completed != ACTION_OK && p->completed != 10) // don't hilight done task
{
if (p->priority > 0 && p->priority <= gProjectPrefs.boldMinPriority)
FntSetFont(boldFont);
else if (p->format.bits.hasDueDate && gProjectPrefs.boldMinDays != 0 &&
p->dueDate.month != 0)
{
if (DateInLimit(p->dueDate, gProjectPrefs.boldMinDays))
FntSetFont(boldFont);
}
}
x += textPos;
//
// draw attached icon
//
{
UInt16 iconid;
UInt16 size = sizeof(iconid);
if (pgOK == TaskGetExtraChunkByTaskPtr((TaskExtendedRecordType*)p,
Extra_Icon, 0,
&iconid, &size) &&
size == sizeof(iconid) &&
iconid < getNumIconsLoaded() )
{
drawIcon(iconid, x, y + 6 - getIconHeight(iconid) / 2);
x += getIconWidth(iconid) + 2;
}
}
// draw the description (truncated)
limit = datePos - x; // - 7;
DrawTruncText(&p->description, x, y, limit);
// strike out done tasks
// but, I needs gray color or gray pattern ...
if (gProjectPrefs.strikeDoneTasks &&
(p->completed == 10 || p->completed == ACTION_OK) )
{
WinDrawLine(x, y + 6, x + limit, y + 6);
}
// resume to default. (to safety)
FntSetFont(stdFont);
} // void ProjectDrawItemDesc(TaskRecordType *p, UInt16 x, UInt16 y)
/****************************************************************************
* Name : ProjectItemDraw
* Desc : callback to draw the project table
* In : not called by the user, it's a callback
* Out : -
* Auth : lb, 31.07.2000
* Mod : lb, 06.08.2000
* support for date right aligning
***************************************************************************/
void ProjectItemDraw(MemPtr table, UInt16 row, UInt16 column, RectanglePtr bounds)
{
BitmapPtr bitmap;
UInt16 bitmapId = 0;
MemHandle h, taskH;
UInt16 i, id, x;
UInt16 y = row*11 + 15;
TaskRecordType *p;
FormType *frm;
RectangleType rectBounds;
UInt8 level;
id = TblGetItemInt(table, row, column);
frm = FrmGetActiveForm();
// erase the row
RctSetRectangle(&rectBounds, 0, y, 160, 11);
WinEraseRectangle(&rectBounds, 0);
// don't do anything more if id is -1
if (id == -1) return;
// get the task
taskH = DmQueryRecord(gdbP, id);
p = MemHandleLock(taskH);
// get its level
level = gCurrentPrefs.view == flatView ? 1 : (p->attr.bits.level);
if (gCurrentPrefs.view == flatView)
{
// extended task can't link to ToDo. because it's buggy.
if (! p->format.bits.extendedType)
{
// get ToDo link icon
h = gIconHandle[
(p->format.bits.hasToDo? BtmLinkOn: BtmLinkOff) - BtmOffset];
bitmap = (BitmapPtr)MemHandleLock(h);
// draw it
WinDrawBitmap(bitmap, 1, y + 2);
MemHandleUnlock(h);
}
x = 13;
}
#if 0
// test implement... but this is BAD idea...
else if (gProjectPrefs.nIndentWidth <= 1)
{ // for short or very short indent
x = (level - gRefLevel - 1) * 2;
if (p->attr.bits.hasChild || gProjectPrefs.nIndentWidth == 1)
{
h = gIconHandle[(p->attr.bits.opened? BtmMinusAlone : BtmPlusAlone) - BtmOffset];
bitmap = (BitmapPtr)MemHandleLock(h);
if (p->attr.bits.hasChild)
WinDrawBitmap(bitmap, x, y);
x += bitmap->width + 1;
MemHandleUnlock(h);
}
}
#endif
else
{
// one bitmap per level of the task
for (i = gRefLevel + 1; i <= level; i++)
{
// choose the good icon (final icon)
if (i == level)
{
if (p->attr.bits.hasChild)
bitmapId =
(p->attr.bits.opened)? BtmMinusAlone: BtmPlusAlone;
else if (p->attr.bits.hasPrev)
bitmapId =
(p->attr.bits.hasNext)? BtmItemMiddle: BtmItemBottom;
else
bitmapId =
(p->attr.bits.hasNext)? BtmItemFirst: BtmItemAlone;
}
else
{
if (!(p->attr.bits.hasPrev) && i == level - 1)
bitmapId = (wVerticalLines[row] & (1 << (i - 1))) ?
BtmItemChild : BtmItemChildNo;
// if there is a bitmap to draw
// init bitmapId to BtmNull if prev of level i has no next
else
bitmapId = (wVerticalLines[row] & (1 << (i - 1))) ?
BtmItemNo: BtmNull;
}
if (bitmapId != BtmNull)
{
// ok, draw this icon
// retreive the good bitmap
h = gIconHandle[bitmapId - BtmOffset];
bitmap = (BitmapPtr)MemHandleLock(h);
// draw it
WinDrawBitmap(bitmap, (i - 1 - gRefLevel) * 11, y);
MemHandleUnlock(h);
}
}
// time optimizations
// TODO : recalc these
x = (level - gRefLevel) * 11 + 2;
}
// write the item description (with priority, due date, progress bar...)
if (p->format.bits.extendedType)
{
ProjectDrawExtendedItemDesc((TaskExtendedRecordType*)p, x, y);
}
else
{
ProjectDrawItemDesc(p, x, y);
}
MemHandleUnlock(taskH);
} // static void ProjectItemDraw(MemPtr table, UInt16 row, UInt16 column, RectanglePtr bounds)
/*
* Table init
*/
void ProjectTableInit(void)
{
TablePtr table;
UInt16 numRows;
UInt16 i;
table = GetObjectPtr(ProjectTable);
numRows = TblGetNumberOfRows(table);
for (i = 0; i < numRows; i++)
{
TblSetItemStyle(table, i, 0, customTableItem);
TblSetItemInt(table, i, 0, i + 1); // begin at task 1, never display task 0
}
TblSetColumnUsable(table, 0, true);
TblSetCustomDrawProcedure(table, 0, (TableDrawItemFuncPtr)ProjectItemDraw);
TblSetItemInt(table, 0, 0, gCurrentPrefs.topTask);
} // static void ProjectTableInit(void)
void ProjectTableEmpty(void)
{
TablePtr table;
UInt16 numRows;
UInt16 i;
table = GetObjectPtr(ProjectTable);
numRows = TblGetNumberOfRows(table);
for (i = 0; i < numRows; i++)
{
// fill with empty items
TblSetItemInt(table, i, 0, -1);
TblSetRowSelectable(table, i, false);
wVerticalLines[i] = 0;
}
}
void ProjectTableUpdate(void)
{
TablePtr table;
UInt16 numRows;
UInt16 i;
Int32 next;
UInt8 level;
table = GetObjectPtr(ProjectTable);
numRows = TblGetNumberOfRows(table);
// need to set the first one selectable for when we come back of an empty
// subview
TblSetRowSelectable(table, 0, true);
// special case, db empty (just task 0)
if (DmNumRecords(gdbP) == 1)
{
ProjectTableEmpty();
return;
}
// special case, the first row's item is -1, check
if (TblGetItemInt(table, 0, 0) == -1 ||
TblGetItemInt(table, 0, 0) >= DmNumRecords(gdbP))
{
if (gParentTask + 1 < DmNumRecords(gdbP) &&
TaskGetLevel(gdbP, gParentTask + 1) > gRefLevel)
{
TblSetItemInt(table, 0, 0, gParentTask + 1);
TblSetRowSelectable(table, 0, true);
}
else
{
ProjectTableEmpty();
return;
}
}
// first item change if it is now invisible
while (gProjectPrefs.hideDoneTasks && (next = TblGetItemInt(table, 0, 0)) != -1 && TaskGetIsDone(gdbP, next))
{
next = TaskGetNextRelativeIndex(gdbP, next);
if (next == 0)
{
ProjectTableEmpty();
return;
}
TblSetItemInt(table, 0, 0, next);
TblSetRowSelectable(table, 0, true);
}
if (TaskGetLevel(gdbP, TblGetItemInt(table, 0, 0)) <= gRefLevel)
{
ProjectTableEmpty();
return;
}
//
// calc vertical line for first row.
//
next = TblGetItemInt(table, 0, 0);
level = TaskGetLevel(gdbP, next);
wVerticalLines[0] = TaskGetHasNext(gdbP, next)? (1 << (level - 1)) : 0;
for (i = gRefLevel + 1; i < level; i++)
{
UInt16 prev;
if ( ( !TaskGetHasPrev(gdbP, next) && i == level - 1 && TaskGetHasNext(gdbP, next - 1) ) ||
( (prev = TaskGetPrevIndexByLevel(gdbP, next, i)) != dmMaxRecordIndex && TaskGetHasNext(gdbP, prev) ) )
wVerticalLines[0] |= 1 << (i - 1);
}
// other items
for (i = 1; i < numRows; i++)
{
// get the previous item
next = TblGetItemInt(table, i-1, 0);
if (next != -1)
{
// if he is not opened
if (TaskGetHasChild(gdbP, next) && !TaskIsOpened(gdbP, next))
{
// get the next
next = TaskGetNextRelativeIndex(gdbP, next);
if (next == 0)
next = -1;
}
else
{
// just go to the next
next++;
// if it's past the last record
if (next >= DmNumRecords(gdbP))
next = -1;
}
// if he must not be drawn
while (gProjectPrefs.hideDoneTasks && next > 0 && TaskGetIsDone(gdbP, next))
next = TaskGetNextRelativeIndex(gdbP, next);
if (next <= 0)
next = -1;
// if we are drawing a subtree, stop when we reach the last child
if (gParentTask != 0 && next != -1)
{
UInt8 levA;
if ((levA = TaskGetLevel(gdbP, next)) <= (gRefLevel) ||
( levA == gRefLevel + 1 &&
TaskGetFatherIndex(gdbP, next) != gParentTask) )
next = -1;
}
}
// calc vertical line.
if (next == -1)
wVerticalLines[i] = 0;
else
{
UInt16 mask = 1 << (TaskGetLevel(gdbP, next) - 1);
if (TaskGetHasNext(gdbP, next))
wVerticalLines[i] = wVerticalLines[i - 1] | mask;
else
wVerticalLines[i] = wVerticalLines[i - 1] & ~mask;
}
TblSetItemInt(table, i, 0, next);
TblSetRowSelectable(table, i, next == -1 ? false : true);
}
gCurrentPrefs.topTask = TblGetItemInt(table, 0, 0);
} // void ProjectTableUpdate(void)
/****************************************************************************
* Name : Scroll
* Desc : update the form to scroll up or down
* Parm :
* -> scroll type (scrollUp, scrollDown)
* -> scroll step
* Out :
* Auth : lb, 02.08.2000
* Mod : lb, 18.08.2000
* fixed scroll up bug that displayed father in sub view
***************************************************************************/
void Scroll(scrollType s, UInt8 step)
{
UInt16 value;
TablePtr table;
table = GetObjectPtr(ProjectTable);
switch (s)
{
case scrollDown:
if ((value = TblGetItemInt(table, step, 0)) != -1)
{
TblSetItemInt(table, 0, 0, value);
//FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
ProjectTableUpdate();
}
else
{
step--;
while (step > 0)
{
if ((value = TblGetItemInt(table, step, 0)) != -1)
{
TblSetItemInt(table, 0, 0, value);
//FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
ProjectTableUpdate();
break;
}
step--;
}
}
break;
case scrollUp:
value = TblGetItemInt(table, 0, 0);
if (value == -1)
return;
if (value > step + gParentTask)
{
UInt8 count = step;
while (value > gParentTask + 1 && count)
{
value--;
if (TaskIsVisible(gdbP, value))
{
count--;
}
else
{
if (gProjectPrefs.hideDoneTasks)
value--;
else
value = TaskGetFatherIndex(gdbP, value);
if (value == gParentTask)
{
value = gParentTask + 1;
}
if (TaskIsVisible(gdbP, value))
{
count--;
}
}
}
TblSetItemInt(table, 0, 0, value);
//FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
ProjectTableUpdate();
}
else
{
TblSetItemInt(table, 0, 0, gParentTask + 1); // never display task 0
ProjectTableUpdate();
//FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case scrollTop:
if (TaskGetHasChild(gdbP, gParentTask))
TblSetItemInt(table, 0, 0, gParentTask + 1);
else
TblSetItemInt(table, 0, 0, -1);
// update done in Btn_Sub
//FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
default:
break;
}
} // void Scroll(scrollType s, UInt8 step)
/****************************************************************************
* Name : FrmTaskEditUpdateDateTrigger
* Desc : update the date trigger
* Parm :
* -> trigger pointer
* -> date to print
* Out :
* Auth : lb, 06.08.2000
***************************************************************************/
void FrmTaskEditUpdateDateTrigger(MemPtr trigger, DateType p)
{
Char* date;
date = (Char*)CtlGetLabel(trigger);
if (p.month == 0)
{
StrCopy(date, "No date");
}
else
{
DateToAscii(p.month, p.day, p.year + YEAR_OFFSET, gDateFormat, date);
}
CtlSetLabel(trigger, date);
} // void FrmTaskEditUpdateDateTrigger(MemPtr trigger, DateType p)
/****************************************************************************
* Name : SelectActualTask
* Desc : select the tbl case of gActualTask. Move the screen if necessary
* expand a branch if necessary
* Parm :
* -> move (must the actual task be on screen)
* Out :
* Auth : lb, 09.08.2000
***************************************************************************/
void SelectActualTask(Boolean move)
{
TablePtr table = GetObjectPtr(ProjectTable);
UInt8 i = 0, numRows = TblGetNumberOfRows(table);
gLastSelected = 0;
TblUnhighlightSelection(table);
if (gActualTask == 0)
return;
// ensure the branch is expanded
if (move && !TaskIsVisible(gdbP, gActualTask))
TaskMakeVisible(gdbP, gActualTask);
// is actual task on screen ?
while (i < numRows && TblGetItemInt(table, i, 0) != gActualTask)
{
i++;
}
if (i == numRows && move)
{
TblSetItemInt(table, 0, 0, gActualTask);
// center it
Scroll(scrollUp, 5);
// where is it now
i = 0;
while (i < numRows && TblGetItemInt(table, i, 0) != gActualTask)
{
i++;
}
}
if (i != numRows)
{
TblSelectItem(table, i, 0);
gLastSelected = gActualTask;
}
else
{
gLastSelected = gActualTask = 0;
}
} // void SelectActualTask(Boolean move)
/****************************************************************************
* Name : InitFrmTaskEdit
* Desc : init the form to edit the actual selected task
* Parm :
* Out :
* Auth : lb, 03.08.2000
***************************************************************************/
void InitFrmTaskEdit(void)
{
FieldPtr fld = GetObjectPtr(TaskDesc);
MemHandle h;
TaskRecordType *p;
MemHandle textH = FldGetTextHandle(fld);
Char *textP;
UInt16 l;
UInt8 priority, value;
DateType dueDate;
// if there's already a handle, destroy it
if (textH)
{
FldSetTextHandle(fld, NULL);
MemHandleFree(textH);
}
h = DmQueryRecord(gdbP, gActualTask);
p = MemHandleLock(h);
l = StrLen(&p->description);
textH = MemHandleNew(l+1);
textP = MemHandleLock(textH);
StrCopy(textP, &p->description);
MemHandleUnlock(h);
MemHandleUnlock(textH);
FldSetTextHandle(fld, textH);
// see if we're synchronized with a ToDo
if (TaskGetFormat(gdbP, gActualTask).hasToDo)
{
pgErr err;
// check the status in ToDo and update this task
err = TaskGetToDoStatus(gdbP, gActualTask, &value, &priority, &dueDate);
if (err == pgOK)
{
TaskSetCompleted(gdbP, gActualTask, value);
TaskSetDueDate(gdbP, gActualTask, dueDate);
TaskSetPriority(gdbP, gActualTask, priority);
CtlSetValue(GetObjectPtr(Chk_Edit_ToDo_Link), 1);
}
}
// get the action value and set it on the form
CtlSetValue(GetObjectPtr(Chk_Edit_Action), TaskGetActionState(gdbP, gActualTask));
// get the date and set the selector trigger
FrmTaskEditUpdateDateTrigger(GetObjectPtr(Pop_Due_Date), TaskGetDueDate(gdbP, gActualTask));
// get the priority and set it on the form
priority = TaskGetPriority(gdbP, gActualTask);
// to be compatible with not initialised db
if (priority > 0 && priority < 7)
{
CtlSetValue(GetObjectPtr(Btn_Priority_X + priority - 1), true);
}
// initialize category popup trigger
{
UInt16 attr;
Char* name = (Char*)CtlGetLabel(GetObjectPtr(Pop_Category));
DmRecordInfo(gdbP, gActualTask, &attr, NULL, NULL);
CategoryGetName(gdbP, (attr & dmRecAttrCategoryMask), name);
CategorySetTriggerLabel(GetObjectPtr(Pop_Category), name);
}
} // void InitFrmTaskEdit(void)
/****************************************************************************
* Name : CleanUpFrmTaskEdit
* Desc : clean up the form, save the work done
* Parm :
* Out :
* Auth : lb, 03.08.2000
***************************************************************************/
void CleanUpFrmTaskEdit(void)
{
FieldPtr fld = GetObjectPtr(TaskDesc);
MemHandle h, hNew;
TaskRecordType *p, *pNew;
MemHandle textH = FldGetTextHandle(fld);
Char *textP, *note;
UInt32 uniqueID;
UInt16 index = dmMaxRecordIndex;
UInt16 attr;
TaskFormatType format;
UInt32 noteSize = 0;
MemPtr extraBlock = NULL;
UInt32 extraSize;
note = TaskGetNote(gdbP, gActualTask);
if (note)
noteSize = StrLen(note);
extraSize = TaskGetExtraBlock(gdbP, gActualTask, NULL);
if (extraSize)
{
extraBlock = MemPtrNew(extraSize);
TaskGetExtraBlock(gdbP, gActualTask, extraBlock);
}
FldCompactText(fld);
textP = MemHandleLock(textH);
// create a new record at last position, this is easier to update the note
hNew = DmNewRecord(gdbP, &index,
TaskRecordTypeSize + StrLen(textP) + noteSize + extraSize);
if (!hNew)
{
MessageBox(StrNoMemorySpaces);
MemHandleUnlock(textH);
return;
}
h = DmQueryRecord(gdbP, gActualTask);
p = MemHandleLock(h);
pNew = MemHandleLock(hNew);
DmWrite(pNew, 0, p, sizeof(TaskRecordType) - 1);
DmStrCopy(pNew, OffsetOf(TaskRecordType, description), textP);
DmStrCopy(pNew,
OffsetOf(TaskRecordType, description) + StrLen(&pNew->description) + 1,
&p->description + StrLen(&p->description) + 1);
// clean the newTask bit
format = p->format.bits;
format.newTask = 0;
DmWrite(pNew, OffsetOf(TaskRecordType, format), &format, sizeof(UInt16));
if (extraSize)
{
DmWrite(pNew,
OffsetOf(TaskRecordType, description) + StrLen(&pNew->description)
+ StrLen(note) + 2,
extraBlock, extraSize);
MemPtrFree(extraBlock);
}
MemHandleUnlock(hNew);
MemHandleUnlock(h);
MemHandleUnlock(textH);
DmReleaseRecord(gdbP, DmNumRecords(gdbP) - 1, true);
// to allow sync
// get the unique ID of original task
DmRecordInfo(gdbP, gActualTask, &attr, &uniqueID, NULL);
// delete original task
DmRemoveRecord(gdbP, gActualTask);
// move the new task to the good index
DmMoveRecord(gdbP, DmNumRecords(gdbP) - 1, gActualTask);
// set the unique ID of the new task
DmSetRecordInfo(gdbP, gActualTask, &attr, &uniqueID);
} // void CleanUpFrmTaskEdit(void)
/****************************************************************************
* Name : InitFrmNoteEdit
* Desc : init the form to edit the actual selected task
* Parm :
* Out :
* Auth : lb, 22.08.2000
***************************************************************************/
void InitFrmNoteEdit(void)
{
FieldPtr fld = GetObjectPtr(TaskNote);
MemHandle textH = FldGetTextHandle(fld);
Char *textP;
UInt16 l;
Char *note;
FormPtr frm = FrmGetActiveForm();
// get the name of db, set it in titlebar
if (StrStr(gCurrentPrefs.openDBName, gPrepend) == gCurrentPrefs.openDBName)
{
// without prepanding chars
FrmCopyTitle(frm, &gCurrentPrefs.openDBName[5]);
}
else
{
// old name format support (without prepanding)
FrmCopyTitle(frm, gCurrentPrefs.openDBName);
}
// if there's already a handle, destroy it
if (textH)
{
FldSetTextHandle(fld, NULL);
MemHandleFree(textH);
}
note = TaskGetNote(gdbP, gActualTask);
// if there's a description already
if (note)
{
l = StrLen(note);
textH = MemHandleNew(l+1);
textP = MemHandleLock(textH);
// could change as we allocated memory
note = TaskGetNote(gdbP, gActualTask);
StrCopy(textP, note);
MemHandleUnlock(textH);
FldSetTextHandle(fld, textH);
}
else
{
// set as empty string.
char* p;
textH = MemHandleNew(1);
p = MemHandleLock(textH);
*p = '\0';
MemHandleUnlock(textH);
FldSetTextHandle(fld, textH);
}
} // void InitFrmNoteEdit(void)
/****************************************************************************
* Name : CleanUpFrmNoteEdit
* Desc : clean up the form, save the work done
* Parm :
* Out :
* Auth : lb, 22.08.2000
***************************************************************************/
void CleanUpFrmNoteEdit(void)
{
FieldPtr fld = GetObjectPtr(TaskNote);
MemHandle textH = FldGetTextHandle(fld);
Char *textP;
FldCompactText(fld);
textP = MemHandleLock(textH);
TaskSetNote(gdbP, gActualTask, textP);
MemHandleUnlock(textH);
// set texthandle as NULL, or it'll be destroyed by the close event
FldSetTextHandle(fld, NULL);
MemHandleFree(textH);
} // void CleanUpFrmNoteEdit(void)
/****************************************************************************
* Name : FrmProjectListInit
* Desc : init FrmProjectList
* Parm :
* Out :
* Auth : lb, 08.08.2000
* Rem : no error handling
***************************************************************************/
void FrmProjectListInit(void)
{
UInt16 num = 0;
DmSearchStateType stateInfo;
LocalID dbID;
ListPtr listP;
UInt16 cardNo = 0;
UInt16 offset = 0;
//DmOpenRef projDB = NULL;
//const Char *projDBName = "ProjectsDB";
listP = GetObjectPtr(Lst_Project_List);
//LstSetSelection(listP, -1);
LstEraseList(listP);
// project link tree creation
//CreateDB(projDBName); // this is possible as no DB is open yet
//OpenDB(projDBName, &projDB);
// search the number of databases
// begin the search
if (DmGetNextDatabaseByTypeCreator(true, &stateInfo, 'DATA', CREATOR,
false, &cardNo, &dbID) == errNone)
{
//UInt16 index;
num++;
//index = num;
//AddLinkRecord(projDB, 0, &index, );
// continue the search
while (DmGetNextDatabaseByTypeCreator(false, &stateInfo, 'DATA', CREATOR,
false, &cardNo, &dbID) == errNone)
{
num++;
}
}
//else
//{
// nothing to initialize if there's no database
//return;
//}
// deallocate old lists if necessary
if (namesData)
{
MemPtrFree(namesData);
}
if (names)
{
MemPtrFree(names);
}
// allocate enough space for the names (+1 for NULL, used by GlobalFlat)
namesData = MemPtrNew(num * 32);
names = MemPtrNew((num+1)*sizeof(char*));
names[num] = NULL; // terminate names array
num = 0;
// get the names in our array
// initial name
if (DmGetNextDatabaseByTypeCreator(true, &stateInfo, 'DATA', CREATOR,
false, &cardNo, &dbID) == errNone)
{
DmDatabaseInfo(cardNo, dbID, namesData, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
// if the name is prepended (new databases since V0.10)
if (StrStr(namesData, gPrepend) == namesData)
{
MemMove(namesData, namesData + StrLen(gPrepend),
StrLen(namesData+StrLen(gPrepend)) + 1);
}
names[num++] = namesData;
offset += StrLen(namesData) + 1;
while (DmGetNextDatabaseByTypeCreator(false, &stateInfo,
'DATA', CREATOR,
false, &cardNo, &dbID) == errNone)
{
DmDatabaseInfo(cardNo, dbID, &namesData[offset], NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL);
// if the name is prepended (new databases since V0.10)
if (StrStr(&namesData[offset], gPrepend) == &namesData[offset])
{
MemMove(&namesData[offset],
&namesData[offset] + StrLen(gPrepend),
StrLen(&namesData[offset]+StrLen(gPrepend)) + 1);
}
names[num++] = &namesData[offset];
offset += StrLen(&namesData[offset]) + 1;
}
}
// set the names in the list
LstSetListChoices(listP, names, num);
// draw the list
LstDrawList(listP);
// if the list is empty, deselect it
if (num == 0)
{
LstSetSelection(listP, -1);
}
} // void FrmProjectListInit(void)
/****************************************************************************
* Name : FrmProjectListCleanUp
* Desc : clean up the form
* Parm :
* Out :
* Auth : lb, 08.08.2000
***************************************************************************/
void FrmProjectListCleanUp(void)
{
} // void FrmProjectListCleanUp(void)
/****************************************************************************
* Name : MessageBox
* Desc : display a message for the user, just OK
* Parm :
* -> message id
* Out :
* Auth : lb, 11.09.2000
***************************************************************************/
void MessageBox(UInt16 id)
{
MemHandle h;
char* p;
UInt16 respond;
h = DmGetResource('tSTR', id);
p = MemHandleLock(h);
respond = FrmCustomAlert(AltEmpty, p, "", "");
MemHandleUnlock(h);
DmReleaseResource(h);
} // void MessageBox(UInt16 id)
/****************************************************************************
* Name : GetLastInSub
* Desc : return the last index of the parent's sub
* Parm :
* -> parent
* Out :
* Auth : lb, 21.10.2000
***************************************************************************/
UInt16 GetLastInSub(UInt16 parent)
{
UInt16 i = parent + 1;
UInt8 refLevel = (parent == 1 ? 0 : TaskGetLevel(gdbP, parent));
while (i < DmNumRecords(gdbP) - 1 &&
TaskGetLevel(gdbP, i) > refLevel)
{
i++;
}
return i - 1;
} // UInt16 GetLastInSub(UInt16 parent)
/****************************************************************************
* Name : ConfirmCustom
* Desc : display a custom confirmation message
* Parm :
* -> action id (StrActionDelete || StrActionResetDates
* -> message id
* Out : button pressed
* Auth : seagull, 09.09.2000
* Mod : burgbach, 21.10.2000 -> custom message (not only delete messages)
***************************************************************************/
UInt16 ConfirmCustom(UInt16 idAction, UInt16 id)
{
MemHandle h1, h2;
char *p1, *p2;
UInt16 respond;
h1 = DmGetResource('tSTR', idAction);
h2 = DmGetResource('tSTR', id);
p1 = MemHandleLock(h1);
p2 = MemHandleLock(h2);
respond = FrmCustomAlert(AltConfirmCustom, p1, p2, "");
MemHandleUnlock(h1);
DmReleaseResource(h1);
MemHandleUnlock(h2);
DmReleaseResource(h2);
return respond;
} // UInt16 ConfirmCustom(UInt16 idAction, UInt16 id)
/****************************************************************************
* Name : ProgressHandleEvent
* Desc : update the progress of the actualtask
* Parm :
* Out :
* Auth : burgbach, 19.10.2000
***************************************************************************/
void ProgressHandleEvent(void)
{
// only for leaves
// not for directlink types
TaskFormatType format;
if (!gActualTask)
return;
format = TaskGetFormat(gdbP, gActualTask);
if (!TaskGetHasChild(gdbP, gActualTask) &&
!format.isMemo && !format.isContact && !format.isAppointement &&
!format.isToDo)
{
if (TaskGetActionState(gdbP, gActualTask))
{
TaskSetCompleted(gdbP, gActualTask,
TaskGetCompleted(gdbP, gActualTask) == ACTION_OK ?
ACTION_NO : ACTION_OK );
if (format.hasToDo)
{
TaskSetToDoStatus(gdbP, gActualTask, toDoComplete,
TaskGetCompleted(gdbP, gActualTask), 0,
gNoDate);
// record completion date (always for ToDo linked tasks)
if (TaskGetIsDone(gdbP, gActualTask))
TaskSetToDoStatus(gdbP, gActualTask, toDoDueDate,
0, 0,
gToday);
}
}
else
{
Int16 TInt16;
ListPtr listP = GetObjectPtr(Lst_Percent);
LstSetSelection(listP,
TaskGetCompleted(gdbP, gActualTask));
TInt16 = LstPopupList(listP);
if (TInt16 != -1)
{
TaskSetCompleted(gdbP, gActualTask, TInt16);
}
}
// record completion date
if (TaskGetIsDone(gdbP, gActualTask) && gProjectPrefs.completionDate)
TaskSetDueDate(gdbP, gActualTask, gToday);
// update fathers
if (TaskGetLevel(gdbP, gActualTask) > 1)
{
TaskCalcCompleted(gdbP,
TaskGetFatherIndex(gdbP, gActualTask));
}
FrmUpdateForm(FrmGetActiveFormID(), frmRedrawUpdateCode);
}
}
/****************************************************************************
* Name : PriorityHandleEvent
* Desc : update the priority of the actualtask
* Parm :
* Out :
* Auth : burgbach, 19.10.2000
***************************************************************************/
void PriorityHandleEvent(EventPtr e)
{
Coord lx, ly;
// edit it in place
Int16 TInt16;
ListPtr listP = GetObjectPtr(Lst_Priority);
TaskFormatType format;
format = TaskGetFormat(gdbP, gActualTask);
if (format.isMemo || format.isContact || format.isAppointement ||
format.isToDo)
{
return;
}
// init lx and ly depending on the active form
if (FrmGetActiveFormID() == FrmFlat)
{
lx = 25;
ly = 15 + e->data.tblSelect.row * 11;
}
else
{
lx = 4 + (1 + TaskGetLevel(gdbP, gActualTask) -
gRefLevel) * 11;
ly = 15 + e->data.tblSelect.row * 11;
}
LstSetSelection(listP,
TaskGetPriority(gdbP, gActualTask) - 1);
ly -= (TaskGetPriority(gdbP, gActualTask) - 1) * 11;
// don't get out the screen
ly = ly < 1 ? 1 : ly;
ly = ly > 103 ? 103 : ly;
LstSetPosition(listP, lx, ly);
TInt16 = LstPopupList(listP);
if (TInt16 != -1)
{
TaskSetPriority(gdbP, gActualTask, TInt16 + 1);
FrmUpdateForm(FrmGetActiveFormID(), frmRedrawUpdateCode);
}
if (TaskGetFormat(gdbP, gActualTask).hasToDo)
{
TaskSetToDoStatus(gdbP, gActualTask, toDoPriority,
0, TaskGetPriority(gdbP, gActualTask),
gNoDate);
}
} // void PriorityHandleEvent(EventPtr e)
/****************************************************************************
* Name : SelectRange
* Desc : popup a user form to ask for subview or all
* Parm :
* Out : Btn_Sub_All or Btn_Sub_Sub or Btn_Sub_Cancel
* Auth : burgbach, 21.10.2000
***************************************************************************/
UInt16 SelectRange(void)
{
UInt16 temp = Btn_Sub_All;
if (gParentTask) // if actual subview is not the total view
{
FormPtr frmSub = FrmInitForm(FrmSubOrAll);
temp = FrmDoDialog(frmSub);
FrmDeleteForm(frmSub);
}
return temp;
} // UInt16 SelectRange(void)
Boolean FrmMainMenuHandleEvent(EventPtr e)
{
FormPtr frm;
frm = FrmGetActiveForm();
switch(e->data.menu.itemID) {
case MenuMainNewTask:
MessageBox(StrNewTask);
break;
case MenuMainTop:
gActualTask = gParentTask + 1;
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainBottom:
if (gRefLevel == 0)
gActualTask = DmNumRecords(gdbP) - 1;
else
{
gActualTask = GetLastInSub(gParentTask);
}
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainRepair:
TaskRepairTree(gdbP, 0, 0);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainReInit:
switch (SelectRange())
{
case Btn_Sub_All:
if (ConfirmCustom(StrActionDelete, StrAllTasks) == 0)
{
while (DmNumRecords(gdbP) > 1)
{
TaskRemove(gdbP, 1);
}
gParentTask = gRefLevel = 0;
// erase the up button
CtlHideControl(GetObjectPtr(Btn_Sub_Up));
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case Btn_Sub_Sub:
if (ConfirmCustom(StrActionDelete,
StrAllDoneTasksInThisView) == 0)
{
TaskRemoveChildren(gdbP, gParentTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
default:
break;
}
break;
case MenuMainSyncToDo:
TaskSyncAll();
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainResetDates:
FrmPopupForm(FrmSetReset);
break;
case MenuMainDeleteChildren:
if (gActualTask && TaskGetHasChild(gdbP, gActualTask))
{
if (ConfirmCustom(StrActionDelete,
StrAllChildrenOfSelectedTask) == 0)
{
TaskRemoveChildren(gdbP, gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
break;
case MenuMainDeleteTask:
if (gActualTask)
{
if (TaskGetHasChild(gdbP, gActualTask))
{
if (ConfirmCustom(StrActionDelete, StrTaskAndChildren) == 0)
{
// remember the father
UInt16 father =
TaskGetFatherIndex(gdbP, gActualTask);
// remove the task
TaskRemove(gdbP, gActualTask);
// if father isn't a father anymore
if (father != 0 && !TaskGetHasChild(gdbP, father))
{
// set its precentage to 0%
TaskSetCompleted(gdbP, father, 0);
// find his father
father = TaskGetFatherIndex(gdbP, father);
}
// if it exists, calc its percentage
if (father != 0)
{
TaskCalcCompleted(gdbP, father);
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
else
{
Boolean deleteOK = true;
if (gSavedPrefs.deleteWarn)
{
// get the description for the warning
char* desc = TaskGetDescription(gdbP, gActualTask);
if (FrmCustomAlert(AltConfirmDelete, desc, "", "") != 0)
deleteOK = false;
MemPtrFree(desc);
}
if (deleteOK)
{
// remember the father
UInt16 father =
TaskGetFatherIndex(gdbP, gActualTask);
// remove the task
TaskRemove(gdbP, gActualTask);
// if father isn't a father anymore
if (father != 0 && !TaskGetHasChild(gdbP, father))
{
// set its precentage to 0%
TaskSetCompleted(gdbP, father, 0);
// find his father
father = TaskGetFatherIndex(gdbP, father);
}
// if it exists, calc its percentage
if (father != 0)
{
TaskCalcCompleted(gdbP, father);
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
}
break;
case MenuMainDeleteDoneTask:
switch (SelectRange())
{
case Btn_Sub_All:
if (ConfirmCustom(StrActionDelete, StrAllDoneTasks) == 0)
{
// to be sure the percentages are correct
TaskCalcCompletedAll(gdbP);
TaskRemoveDone(gdbP);
TaskCalcCompletedAll(gdbP);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case Btn_Sub_Sub:
if (ConfirmCustom(StrActionDelete,
StrAllDoneTasksInThisView) == 0)
{
// to be sure the percentages are correct
TaskCalcCompletedAll(gdbP);
TaskRemoveDoneChildren(gdbP, gParentTask);
TaskCalcCompletedAll(gdbP);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
default:
break;
}
break;
case MenuMainExpandAll:
TaskExpand(gdbP, 0);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainCollapseAll:
TaskCollapse(gdbP, 0);
Scroll(scrollTop, 0);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainExpandOne:
TaskExpand(gdbP, gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainCollapseOne:
TaskCollapse(gdbP, gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuMainPreferences:
FrmPopupForm(FrmProjectProperties);
break;
case MenuMainDisplayPreferences:
FrmPopupForm(FrmDisplayProperties);
break;
case MenuMainFlatFilter:
FrmPopupForm(FrmFlatFilter);
break;
case MenuMainClose:
FrmGotoForm(FrmProjectList);
CloseDB(gdbP);
gActualTask = gLastSelected = 0;
break;
case MenuMainViewSub:
break;
case MenuMainViewAll:
gParentTask = 0;
gRefLevel = 0;
// erase the up button
CtlHideControl(GetObjectPtr(Btn_Sub_Up));
SetFormTitle(frm, gCurrentPrefs.openDBName);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuEditCut:
if (gActualTask)
{
TaskToClipboard(gdbP, gActualTask, true);
TaskRemove(gdbP, gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case MenuEditCopy:
if (gActualTask)
{
TaskToClipboard(gdbP, gActualTask, true);
}
break;
case MenuEditCopyChildren:
if (gActualTask && TaskGetHasChild(gdbP, gActualTask))
{
TaskToClipboard(gdbP, gActualTask, false);
}
break;
case MenuEditPaste:
if (gActualTask || DmNumRecords(gdbP) == 1 ||
!TaskGetHasChild(gdbP, gParentTask))
{
if (!gActualTask)
{
TaskFromClipboard(gdbP, gParentTask, true);
}
else
{
TaskFromClipboard(gdbP, gActualTask, false);
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case MenuEditPasteAsChildren:
if (gActualTask)
{
TaskFromClipboard(gdbP, gActualTask, true);
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case MenuEditAddNote:
if (gActualTask)
{
FrmPopupForm(FrmNoteEdit);
}
break;
case MenuNewLink:
if (gActualTask)
{
FrmPopupForm(FrmDirectLink);
}
else
{
MessageBox(StrSelectTask);
}
break;
case MenuMainTaskDefaults:
FrmPopupForm(FrmTaskDefaults);
break;
case MenuProjectListAbout:
FrmCustomAlert(ProgectAbout, VERSION, "", "");
break;
case MenuMainMemoExport:
FrmPopupForm(FrmMemoExportProperties);
break;
case MenuPublishLinkMaster:
if (gActualTask > 0)
PublishToLinkMaster(gdbP, gActualTask);
break;
case MenuLinkViaLinkMaster:
if (gActualTask > 0)
RequestLinkViaLinkMaster(gCurrentPrefs.openDBName, gActualTask);
break;
case MenuRemoveLinkViaLinkMaster:
if (gActualTask > 0)
{
RemoveLinkViaLinkMaster(gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
}
return true;
} // Boolean FrmMainMenuHandleEvent(EventPtr e)
Boolean FrmMainCtlSelectHandleEvent(EventPtr e)
{
FormPtr frm;
frm = FrmGetActiveForm();
switch(e->data.ctlSelect.controlID) {
case Btn_Left:
if (gActualTask)
{
TaskToLeft(gdbP, gActualTask);
// TODO verify how to bypass this one
ProjectTableUpdate();
SelectActualTask(true);
}
break;
case Btn_Right:
if (gActualTask)
{
TaskToRight(gdbP, gActualTask);
SelectActualTask(true);
}
break;
case Btn_Up:
if (gActualTask)
{
TaskUp(gdbP, gActualTask);
SelectActualTask(true);
}
break;
case Btn_Down:
if (gActualTask)
{
TaskDown(gdbP, gActualTask);
SelectActualTask(true);
}
break;
case Btn_Sub:
// New, be able to see the sub of a terminal task
if (gActualTask)
{
char* p;
gParentTask = gActualTask;
gRefLevel = TaskGetLevel(gdbP, gParentTask);
Scroll(scrollTop, 0);
gActualTask = 0;
// show the up button
CtlShowControl(GetObjectPtr(Btn_Sub_Up));
// update the titlebar
p = TaskGetDescription(gdbP, gParentTask);
SetFormTitle(frm, p);
MemPtrFree(p);
if (TaskGetHasChild(gdbP, gParentTask))
{
gActualTask = gParentTask + 1;
SelectActualTask(true);
}
}
break;
case Btn_Sub_Up:
TblSetItemInt(gTable, 0, 0, gParentTask);
gParentTask = TaskGetFatherIndex(gdbP, gParentTask);
if (!gParentTask)
{
gRefLevel = 0;
}
else
{
gRefLevel = TaskGetLevel(gdbP, gParentTask);
}
//this is done by the next update
//if (gActualTask)
//{
//ProjectTableUpdate();
//SelectActualTask(false);
//}
// if we're at top level
if (!gParentTask)
{
// erase the up button
CtlHideControl(GetObjectPtr(Btn_Sub_Up));
SetFormTitle(frm, gCurrentPrefs.openDBName);
}
else
{
char* p = TaskGetDescription(gdbP, gParentTask);
SetFormTitle(frm, p);
MemPtrFree(p);
}
break;
case Btn_Done:
FrmGotoForm(FrmProjectList);
CloseDB(gdbP);
gActualTask = gLastSelected = gRefLevel = gParentTask = 0;
break;
case Btn_Main_Hierarchical:
break;
case Btn_Main_Flat:
FrmGotoForm(FrmFlat);
break;
default:
break;
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
return true;
} // Boolean FrmMainCtlSelectHandleEvent(EventPtr e)
Boolean FrmMainKeyDownHandleEvent(EventPtr e)
{
switch (e->data.keyDown.chr)
{
case vchrPageDown:
Scroll(scrollDown, 5);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case vchrPageUp:
Scroll(scrollUp, 5);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case chrSpace:
TaskToRight(gdbP, gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case chrBackspace:
TaskToLeft(gdbP, gActualTask);
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case chrLeftArrow:
if (gActualTask)
{
TaskUp(gdbP, gActualTask);
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case chrRightArrow:
if (gActualTask)
{
TaskDown(gdbP, gActualTask);
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case chrUpArrow:
if (gActualTask > gParentTask + 1)
{
UInt16 prev = gActualTask - 1;
while (prev > gParentTask && !TaskIsVisible(gdbP, prev))
prev--;
if (prev > gParentTask)
{
gActualTask = prev;
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
break;
case chrDownArrow:
if ((gActualTask + 1 < DmNumRecords(gdbP)) &&
TaskGetLevel(gdbP, gActualTask + 1) > gRefLevel)
{
UInt16 next = gActualTask + 1, numRec = DmNumRecords(gdbP);
while (next < numRec && !TaskIsVisible(gdbP, next))
next++;
if (next < numRec)
{
gActualTask = next;
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
break;
case chrPlusSign:
if (gActualTask)
{
TaskSetOpened(gdbP, gActualTask, true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
case chrHyphenMinus:
if (gActualTask && TaskGetHasChild(gdbP, gActualTask))
{
TaskSetOpened(gdbP, gActualTask, false);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
break;
default:
// keyDown is alnum, then create a new task
if (TxtGlueCharIsAlNum(e->data.keyDown.chr))
{
if (gActualTask || DmNumRecords(gdbP) == 1 ||
!TaskGetHasChild(gdbP, gParentTask))
{
TaskType NewTask = gEmptyTask;
Char firstChar[2];
firstChar[0] =
(Char)TxtGlueUpperChar(e->data.keyDown.chr);
firstChar[1] = '\0';
NewTask.description = firstChar;
// special case when there's no existing task
if (DmNumRecords(gdbP) == 1 ||
!TaskGetHasChild(gdbP, gParentTask))
{
gActualTask = gParentTask;
}
AddRecord(gdbP, &NewTask, &gActualTask);
// recalc fathers progressbar
if (TaskGetLevel(gdbP, gActualTask) > 1)
{
TaskCalcCompleted(gdbP,
TaskGetFatherIndex(gdbP, gActualTask));
}
FrmPopupForm(FrmTaskEdit);
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
// keydown is tab or return, create a new subtask
// (space is treaded already)
if (TxtGlueCharIsSpace(e->data.keyDown.chr))
{
if (gActualTask)
{
if (e->data.keyDown.chr == chrCarriageReturn ||
e->data.keyDown.chr == chrLineFeed)
{
AddRecordSub(gdbP, &gEmptyTask, &gActualTask);
// recalc fathers progressbar
if (TaskGetLevel(gdbP, gActualTask) > 1)
{
TaskCalcCompleted(gdbP,
TaskGetFatherIndex(gdbP, gActualTask));
}
FrmPopupForm(FrmTaskEdit);
SelectActualTask(true);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
else if (e->data.keyDown.chr == chrHorizontalTabulation)
{
// edit the task (keyboard shortcut)
FrmPopupForm(FrmTaskEdit);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
}
}
}
break;
}
return true;
} // Boolean FrmMainKeyDownHandleEvent(EventPtr e)
static Boolean FrmMainHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
Int16 x;
TaskFormatType format;
frm = FrmGetActiveForm();
gTable = GetObjectPtr(ProjectTable);
switch (e->eType) {
case frmUpdateEvent:
switch(e->data.frmUpdate.updateCode)
{
case frmRedrawUpdateCode:
ProjectTableUpdate();
FrmDrawForm(frm);
SelectActualTask(false);
handled = true;
break;
default:
break;
}
break;
case frmOpenEvent:
gCurrentPrefs.view = normalView;
ProjectTableInit();
ProjectTableUpdate();
SetFormTitle(frm, gCurrentPrefs.openDBName);
FrmDrawForm(frm);
SelectActualTask(true); // show on screen.
gTable = GetObjectPtr(ProjectTable);
CtlSetValue(GetObjectPtr(Btn_Main_Hierarchical), true);
if (gRefLevel)
{
Char *p;
// show the up button
CtlShowControl(GetObjectPtr(Btn_Sub_Up));
// update the titlebar
p = TaskGetDescription(gdbP, gParentTask);
SetFormTitle(frm, p);
MemPtrFree(p);
if (TaskGetHasChild(gdbP, gParentTask))
{
gActualTask = gParentTask + 1;
SelectActualTask(true);
}
}
handled = true;
break;
case menuEvent:
MenuEraseStatus(NULL);
handled = FrmMainMenuHandleEvent(e);
break;
// remember the screen coords
case tblEnterEvent:
gLastDownX = e->screenX;
gLastDownY = e->screenY;
// deselect all
gActualTask = 0;
break;
case ctlSelectEvent:
handled = FrmMainCtlSelectHandleEvent(e);
break;
case ctlRepeatEvent:
switch (e->data.ctlRepeat.controlID)
{
case Btn_Scroll_Up:
Scroll(scrollUp, 1);
break;
case Btn_Scroll_Down:
Scroll(scrollDown, 1);
break;
default:
break;
}
// not handled, or I don't get the repeated event
//handled = true;
// FrmUpdateForm(FrmMain, wUpdateCode);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case tblSelectEvent:
gActualTask = TblGetItemInt(gTable, e->data.tblSelect.row, 0);
if (gActualTask == -1)
gActualTask = 0;
format = TaskGetFormat(gdbP, gActualTask);
x = gLastDownX / 11 + 1 - TaskGetLevel(gdbP, gActualTask) + gRefLevel;
if (gActualTask) // this is for all the switch
switch (x)
{
case 0:
/**************************************************************
* Code for open buttons
*************************************************************/
TaskToggleIsOpened(gdbP, gActualTask);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case 1:
/**************************************************************
* Code for progress buttons
*************************************************************/
ProgressHandleEvent();
break;
default:
//////////////////////////////////////////////////////////////
// Code for note or follow link
//////////////////////////////////////////////////////////////
if (gLastDownX > 153 && format.hasNote)
{
FrmPopupForm(FrmNoteEdit);
}
else if (gLastDownX > (153 - (format.hasNote? 8 : 0))
&& format.hasLink)
{
FollowLinkViaLinkMaster(gActualTask);
}
// if a priority is visible
else if (x == 2 && TaskGetPriority(gdbP, gActualTask) != 6 &&
gProjectPrefs.displayPriorities)
{
PriorityHandleEvent(e);
}
// edit text if click on the right side
else if (x > 0)
{
if (gLastSelected == gActualTask)
{
if (format.isMemo || format.isContact)
{
DirectLinkFollow(gdbP, gActualTask);
}
else
{
FrmPopupForm(FrmTaskEdit);
}
}
else
{
gLastSelected = gActualTask;
}
}
else
{
// left part
// nothing to do for now
}
break;
}
handled = true;
break;
// TODO : put this '5' in prefs (scroll step)
case keyDownEvent:
handled = FrmMainKeyDownHandleEvent(e);
break;
default:
break;
}
return handled;
} // static Boolean FrmMainHandleEvent (EventPtr e)
static void UpdateIconButton(void)
{
FormPtr frm = FrmGetActiveForm();
UInt16 iconid;
UInt16 size = sizeof(iconid);
if (!TaskGetExtraChunk(gdbP, gActualTask, Extra_Icon, 0,
&iconid, &size) &&
size == sizeof(iconid) &&
iconid < getNumIconsLoaded() )
{
Coord x, y;
CtlSetLabel(GetObjectPtr(Btn_SelectIcon), "");
FrmGetObjectPosition(frm,
FrmGetObjectIndex(frm, Btn_SelectIcon),
&x, &y);
drawIcon(iconid, x + 10, y + 2);
}
else
{
MemHandle h;
char* p;
h = DmGetResource('tSTR', StrIconButton);
p = MemHandleLock(h);
CtlSetLabel(GetObjectPtr(Btn_SelectIcon), p);
MemHandleUnlock(h);
DmReleaseResource(h);
}
}
static Boolean FrmTaskEditHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
DateType date;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
TaskSave(gActualTask);
InitFrmTaskEdit();
FrmDrawForm(frm);
UpdateIconButton();
FrmSetFocus(frm, FrmGetObjectIndex(frm, TaskDesc));
handled = true;
break;
case frmCloseEvent:
CleanUpFrmTaskEdit();
TaskRemoveSaved();
// link the todo
if (CtlGetValue(GetObjectPtr(Chk_Edit_ToDo_Link)))
{
TaskPublishToDo(gdbP, gActualTask);
}
else
{
TaskRemoveHasToDo(gdbP, gActualTask);
}
TaskUpdateToDo(gdbP, gActualTask);
break;
case frmUpdateEvent:
switch(e->data.frmUpdate.updateCode)
{
case frmTaskEditReturnFromIconSelect:
FrmDrawForm(frm);
UpdateIconButton();
case frmTaskEditReturnFromNote:
FrmSetFocus(frm, FrmGetObjectIndex(frm, TaskDesc));
handled = true;
break;
}
break;
case menuEvent:
handled = EditMenuHandleEvent(e->data.menu.itemID,
GetObjectPtr(TaskDesc));
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Pop_Due_Date:
switch (LstPopupList(GetObjectPtr(Lst_Date)))
{
case 0: // today
TaskSetDueDate(gdbP, gActualTask, gToday);
break;
case 1: // tomorrow
date = gToday;
DateAdjust(&date, 1);
TaskSetDueDate(gdbP, gActualTask, date);
break;
case 2: // in one week
date = gToday;
DateAdjust(&date, 7);
TaskSetDueDate(gdbP, gActualTask, date);
break;
case 3: // no date
TaskSetDueDate(gdbP, gActualTask, gNoDate);
break;
case 4: // choose date
TaskInputDueDate(gdbP, gActualTask);
break;
default:
break;
}
date = TaskGetDueDate(gdbP, gActualTask);
FrmTaskEditUpdateDateTrigger(GetObjectPtr(Pop_Due_Date), date);
handled = true;
break;
case Pop_Category:
{
UInt16 attr;
UInt16 categ;
Char* name = (Char*)CtlGetLabel(GetObjectPtr(Pop_Category));
DmRecordInfo(gdbP, gActualTask, &attr, NULL, NULL);
categ = attr & dmRecAttrCategoryMask;
CategorySelect(gdbP, frm, Pop_Category, Lst_Category, false,
&categ, name,
1, categoryDefaultEditCategoryString);
attr &= ~dmRecAttrCategoryMask;
attr |= categ & dmRecAttrCategoryMask;
DmSetRecordInfo(gdbP, gActualTask, &attr, NULL);
CtlSetLabel(GetObjectPtr(Pop_Category), name);
}
handled = true;
break;
case Btn_Edit_Note:
CleanUpFrmTaskEdit();
FrmPopupForm(FrmNoteEdit);
handled = true;
break;
case Btn_Edit_Ok:
CleanUpFrmTaskEdit();
TaskRemoveSaved();
// link the todo
if (CtlGetValue(GetObjectPtr(Chk_Edit_ToDo_Link)))
{
TaskPublishToDo(gdbP, gActualTask);
}
else
{
TaskRemoveHasToDo(gdbP, gActualTask);
}
TaskUpdateToDo(gdbP, gActualTask);
FrmReturnToForm(0);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
handled = true;
break;
case Btn_Edit_Cancel:
CleanUpFrmTaskEdit();
TaskGetSaved(gActualTask);
if (TaskGetFormat(gdbP, gActualTask).newTask)
{
TaskRemove(gdbP, gActualTask);
}
FrmReturnToForm(0);
if (! OSCaps.ver35)
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
handled = true;
break;
case Chk_Edit_Action:
if (CtlGetValue(GetObjectPtr(Chk_Edit_ToDo_Link)))
{
CtlSetValue(GetObjectPtr(Chk_Edit_Action), true);
TaskSetActionState(gdbP, gActualTask, true);
}
else
{
TaskSetActionState(gdbP, gActualTask,
CtlGetValue(GetObjectPtr(Chk_Edit_Action)));
}
handled = true;
break;
case Btn_SelectIcon:
if (getNumIconsLoaded() != 0)
{
CleanUpFrmTaskEdit();
FrmPopupForm(FrmIconSelect);
}
handled = true;
break;
case Chk_Edit_ToDo_Link:
// real job is done by OK button
CtlSetValue(GetObjectPtr(Chk_Edit_Action), true);
TaskSetActionState(gdbP, gActualTask, true);
handled = true;
break;
case Btn_Priority_1:
case Btn_Priority_2:
case Btn_Priority_3:
case Btn_Priority_4:
case Btn_Priority_5:
case Btn_Priority_No:
TaskSetPriority(gdbP, gActualTask, e->data.ctlSelect.controlID - Btn_Priority_X + 1);
handled = true;
default:
break;
}
break;
case keyDownEvent:
switch (e->data.keyDown.chr)
{
// on return, close form
case chrCarriageReturn:
case chrLineFeed:
CleanUpFrmTaskEdit();
TaskRemoveSaved();
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
FrmReturnToForm(0);
handled = true;
break;
case chrHorizontalTabulation:
{
UInt8 priority;
// get the priority and set it on the form
priority = TaskGetPriority(gdbP, gActualTask);
CtlSetValue(GetObjectPtr(Btn_Priority_X + priority - 1),
false);
priority++;
if (priority > 6)
priority = 1;
TaskSetPriority(gdbP, gActualTask, priority);
CtlSetValue(GetObjectPtr(Btn_Priority_X + priority - 1),
true);
}
handled = true;
break;
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmTaskEditHandleEvent (EventPtr e)
static Boolean FrmProjectListHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
ListPtr listP;
static UInt16 nLastSelectedProject = noListSelection;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmUpdateEvent:
switch(e->data.frmUpdate.updateCode)
{
case frmRedrawUpdateCode:
FrmDrawForm(frm);
FrmProjectListInit();
handled = true;
break;
default:
break;
}
break;
case frmOpenEvent:
LstNewList((void**)&frm, Lst_Project_List, 1, 18, 158, 121, 0, 11, 0);
FrmDrawForm(frm);
FrmProjectListInit();
nLastSelectedProject = LstGetSelection(GetObjectPtr(Lst_Project_List));
handled = true;
break;
case frmCloseEvent:
FrmRemoveObject(&frm, FrmGetObjectIndex(frm, Lst_Project_List));
// deallocate old lists if necessary
if (namesData)
{
MemPtrFree(namesData);
namesData = NULL;
}
if (names)
{
MemPtrFree(names);
names = NULL;
}
// handled = true ??
break;
case menuEvent:
MenuEraseStatus(NULL);
switch(e->data.menu.itemID) {
case MenuProjectListAbout:
FrmCustomAlert(ProgectAbout, VERSION, "", "");
break;
case MenuProjectListDuplicate:
listP = GetObjectPtr(Lst_Project_List);
// if we have a selection
if (LstGetSelection(listP) != noListSelection)
{
ChooseNameFunction = ChooseNameDuplicate;
FrmPopupForm(FrmChooseName);
}
else
{
DEBUG1("Please select a project to duplicate first");
}
break;
}
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_List_Open:
listP = GetObjectPtr(Lst_Project_List);
// if we have a selection
if (listP && LstGetSelection(listP) != noListSelection)
{
OpenDB(LstGetSelectionText(listP, LstGetSelection(listP)), &gdbP);
FrmGotoForm(FrmMain);
}
handled = true;
break;
case Btn_List_New:
ChooseNameFunction = ChooseNameCreate;
FrmPopupForm(FrmChooseName);
handled = true;
break;
case Btn_List_Del:
listP = GetObjectPtr(Lst_Project_List);
// if we have a selection
if (LstGetSelection(listP) != noListSelection)
{
if (FrmCustomAlert(
AltConfirmDelete, LstGetSelectionText(listP, LstGetSelection(listP)), "", "") == 0)
{
RemoveDB(LstGetSelectionText(listP, LstGetSelection(listP)));
FrmUpdateForm(FrmProjectList, frmRedrawUpdateCode);
}
}
handled = true;
break;
case Btn_List_Rename:
listP = GetObjectPtr(Lst_Project_List);
// if we have a selection
if (LstGetSelection(listP) != noListSelection)
{
ChooseNameFunction = ChooseNameRename;
gCurrentSelection = LstGetSelection(listP);
FrmPopupForm(FrmChooseName);
}
handled = true;
default:
break;
}
break;
case lstSelectEvent:
if (nLastSelectedProject == e->data.lstSelect.selection
&& e->data.lstSelect.selection != noListSelection)
{
OpenDB(LstGetSelectionText(e->data.lstSelect.pList, e->data.lstSelect.selection), &gdbP);
FrmGotoForm(FrmMain);
return true;
}
nLastSelectedProject = e->data.lstSelect.selection;
break;
case keyDownEvent:
switch (e->data.keyDown.chr)
{
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmProjectListHandleEvent (EventPtr e)
Boolean HandleChooseNameButtonOK(void)
{
FormPtr frm;
Char DBName[dmDBNameLength];
Err err;
Boolean handled = false;
FieldPtr fldPtr = GetObjectPtr(Fld_Project_Name);
Char *name = FldGetTextPtr(fldPtr);
frm = FrmGetActiveForm();
if (FldDirty(fldPtr)) {
switch (ChooseNameFunction)
{
case ChooseNameCreate:
if (*name) {
UInt16 attr;
StrNCopy(DBName, name, dmDBNameLength);
err = CreateDB(DBName);
if (err) {
FrmCustomAlert(AltAlreadyExists, name, NULL, NULL);
FldSetSelection(fldPtr, 0, StrLen(name));
break;
}
// to get gdbID (without manually prepending)
OpenDB(DBName, &gdbP);
// Backup by default
DmDatabaseInfo(0, gdbID, NULL, &attr, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
attr = attr | dmHdrAttrBackup;
DmSetDatabaseInfo(0, gdbID, NULL, &attr, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
CloseDB(gdbP);
} else
break;
FrmReturnToForm(FrmProjectList);
FrmUpdateForm(FrmProjectList, frmRedrawUpdateCode);
handled = true;
break;
case ChooseNameRename:
if (*name)
{
FormPtr listFrm = FrmGetFormPtr(FrmProjectList);
ListPtr listP = FrmGetObjectPtr(listFrm,
FrmGetObjectIndex(listFrm, Lst_Project_List));
StrNCopy(DBName, name, dmDBNameLength);
err = RenameDB(LstGetSelectionText(listP,
LstGetSelection(listP)), DBName);
if (err) {
FrmCustomAlert(AltAlreadyExists, name, NULL, NULL);
FldSetSelection(fldPtr, 0, StrLen(name));
break;
}
} else
break;
FrmReturnToForm(FrmProjectList);
FrmUpdateForm(FrmProjectList, frmRedrawUpdateCode);
handled = true;
break;
case ChooseNameDuplicate:
if (*name)
{
Char srcName[32];
FormPtr listFrm = FrmGetFormPtr(FrmProjectList);
ListPtr listP = FrmGetObjectPtr(listFrm,
FrmGetObjectIndex(listFrm, Lst_Project_List));
StrNCopy(DBName, name, dmDBNameLength);
StrCopy(srcName,
LstGetSelectionText(listP, LstGetSelection(listP)));
err = DuplicateDB(srcName, DBName);
if (err) {
FrmCustomAlert(AltAlreadyExists, name, NULL, NULL);
FldSetSelection(fldPtr, 0, StrLen(name));
break;
}
} else
break;
FrmReturnToForm(FrmProjectList);
FrmUpdateForm(FrmProjectList, frmRedrawUpdateCode);
handled = true;
break;
default:
break;
}
}
if (ChooseNameFunction == ChooseNameDoc)
{
if (*name)
{
switch (SelectRange())
{
case Btn_Sub_All:
ExportToDoc(0, name,
1, DmNumRecords(gdbP) - 1);
break;
case Btn_Sub_Sub:
ExportToDoc(0, name,
gParentTask, GetLastInSub(gParentTask));
break;
default:
break;
}
}
handled = true;
FrmReturnToForm(0);
}
return handled;
} // void HandleCreateNewButtonOK(void)
static Boolean FrmChooseNameHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
if (ChooseNameFunction == ChooseNameRename)
{
FieldPtr fldPtr = GetObjectPtr(Fld_Project_Name);
FldSetSelection(fldPtr, 0, 0);
FldInsert(fldPtr, names[gCurrentSelection],
StrLen(names[gCurrentSelection]));
FldSetSelection(fldPtr, 0, StrLen(names[gCurrentSelection]));
FldSetDirty(fldPtr, false);
}
if (ChooseNameFunction == ChooseNameDoc)
{
FieldPtr fldPtr = GetObjectPtr(Fld_Project_Name);
FldSetSelection(fldPtr, 0, 0);
FldInsert(fldPtr, gCurrentPrefs.openDBName + 5,
StrLen(gCurrentPrefs.openDBName + 5));
FldSetSelection(fldPtr, 0, StrLen(gCurrentPrefs.openDBName + 5));
FldSetDirty(fldPtr, false);
}
FrmDrawForm(frm);
FrmSetFocus(frm, FrmGetObjectIndex(frm, Fld_Project_Name));
handled = true;
break;
case frmCloseEvent:
// handled = true ??
break;
case menuEvent:
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_Choose_Name_Ok:
handled = HandleChooseNameButtonOK();
break;
case Btn_Choose_Name_Cancel:
FrmReturnToForm(0);
handled = true;
break;
default:
break;
}
break;
case keyDownEvent:
switch (e->data.keyDown.chr)
{
case chrCarriageReturn:
case chrLineFeed:
HandleChooseNameButtonOK();
handled = true;
break;
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmChooseNameHandleEvent (EventPtr e)
static Boolean FrmFlatFilterHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
Int16 TInt16;
ListPtr listP = NULL;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
// set the controls based on the actual prefs
CtlSetValue(GetObjectPtr(Chk_Flat_Hide),
gProjectPrefs.flatHideDone);
CtlSetValue(GetObjectPtr(Btn_No_Date + gProjectPrefs.flatDated), true);
CtlSetValue(GetObjectPtr(Btn_Min + !gProjectPrefs.flatMin), true);
CtlSetValue(GetObjectPtr(
Btn_Priority_X + gProjectPrefs.flatMinPriority - 1)
, true);
CtlSetValue(GetObjectPtr(Btn_And + gProjectPrefs.flatOr), true);
CtlSetValue(GetObjectPtr(Btn_No_Sort + gProjectPrefs.flatSorted), true);
LstSetSelection(GetObjectPtr(List_DaysToBold),
gProjectPrefs.flatDateLimit);
CtlSetLabel(GetObjectPtr(Pop_DaysToBold),
LstGetSelectionText(GetObjectPtr(List_DaysToBold),
gProjectPrefs.flatDateLimit) );
FrmDrawForm(frm);
handled = true;
break;
case frmCloseEvent:
// handled = true ??
break;
case menuEvent:
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Pop_DaysToBold:
listP = GetObjectPtr(e->data.ctlSelect.controlID + 1);
TInt16 = LstPopupList(listP);
if (TInt16 != -1)
{
CtlSetLabel(GetObjectPtr(e->data.ctlSelect.controlID),
LstGetSelectionText(listP, TInt16));
}
handled = true;
break;
case Btn_Prop_Ok:
// modify the prefs
gProjectPrefs.flatHideDone =
CtlGetValue(GetObjectPtr(Chk_Flat_Hide));
gProjectPrefs.flatDated =
FrmGetObjectId(frm, FrmGetControlGroupSelection(frm, 3)) -
Btn_No_Date;
gProjectPrefs.flatMinPriority =
FrmGetObjectId(frm, FrmGetControlGroupSelection(frm, 1)) -
Btn_Priority_X + 1;
gProjectPrefs.flatOr =
FrmGetObjectId(frm, FrmGetControlGroupSelection(frm, 2)) -
Btn_And;
gProjectPrefs.flatMin =
!(FrmGetObjectId(frm, FrmGetControlGroupSelection(frm, 4)) -
Btn_Min);
gProjectPrefs.flatSorted =
FrmGetObjectId(frm, FrmGetControlGroupSelection(frm, 5)) -
Btn_No_Sort;
gProjectPrefs.flatDateLimit =
LstGetSelection(GetObjectPtr(List_DaysToBold));
if (gCurrentPrefs.view == flatView)
{
// reconstruct the list
FlatCreateList(gdbP);
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
}
// fall through
case Btn_Prop_Cancel:
// return to caller without modifying the prefs
FrmReturnToForm(0);
handled = true;
break;
default:
break;
}
break;
case keyDownEvent:
break;
default:
break;
}
return handled;
} // static Boolean FrmFlatFilterHandleEvent (EventPtr e)
static Boolean FrmDirectLinkHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
//ListPtr listP;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
FrmDrawForm(frm);
LstDrawList(GetObjectPtr(Lst_Link_Type));
CtlSetLabel(GetObjectPtr(Sel_Link_To), "---");
handled = true;
break;
case frmCloseEvent:
break;
case frmUpdateEvent:
switch(e->data.frmUpdate.updateCode)
{
default:
break;
}
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Sel_Link_To:
switch(LstGetSelection(GetObjectPtr(Lst_Link_Type)))
{
case 0:
LinkCreateLinkTree(gdbP, memoLink);
break;
case 1:
LinkCreateLinkTree(gdbP, addressLink);
break;
case 2:
DEBUG1("Not implemented yet");
break;
}
handled = true;
break;
case Btn_Ok:
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
// fall down
case Btn_Cancel:
FrmReturnToForm(0);
handled = true;
break;
default:
break;
}
break;
case keyDownEvent:
switch (e->data.keyDown.chr)
{
// on return, close form
case chrCarriageReturn:
case chrLineFeed:
FrmReturnToForm(0);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
handled = true;
break;
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmDirectLinkHandleEvent (EventPtr e)
static Boolean FrmProjectPropertiesHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
UInt16 attr;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
// set the controls based on the actual prefs
CtlSetValue(GetObjectPtr(Chk_Prop_Hide),
gProjectPrefs.hideDoneTasks);
CtlSetValue(GetObjectPtr(Chk_Prop_Display_Due_Dates),
gProjectPrefs.displayDueDates);
CtlSetValue(GetObjectPtr(Chk_Prop_Display_Priorities),
gProjectPrefs.displayPriorities);
CtlSetValue(GetObjectPtr(Chk_Prop_Display_Year),
gProjectPrefs.displayYear);
CtlSetValue(GetObjectPtr(Chk_Prop_Delete_Warn),
gSavedPrefs.deleteWarn);
CtlSetValue(GetObjectPtr(Chk_Prop_Father_Status),
gProjectPrefs.useFatherStatus);
CtlSetValue(GetObjectPtr(Chk_Prop_Auto_Sync_ToDo),
gProjectPrefs.autoSyncToDo);
CtlSetValue(GetObjectPtr(Chk_Prop_Comp_Date),
gProjectPrefs.completionDate);
// read database attr
DmDatabaseInfo(0, gdbID, NULL, &attr, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
CtlSetValue(GetObjectPtr(Chk_Prop_Save_DB), attr & dmHdrAttrBackup);
FrmDrawForm(frm);
handled = true;
break;
case frmCloseEvent:
// handled = true ??
break;
case menuEvent:
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_Prop_Ok:
// modify the prefs
gProjectPrefs.hideDoneTasks =
CtlGetValue(GetObjectPtr(Chk_Prop_Hide));
gProjectPrefs.displayDueDates =
CtlGetValue(GetObjectPtr(Chk_Prop_Display_Due_Dates));
gProjectPrefs.displayPriorities =
CtlGetValue(GetObjectPtr(Chk_Prop_Display_Priorities));
gProjectPrefs.displayYear =
CtlGetValue(GetObjectPtr(Chk_Prop_Display_Year));
gProjectPrefs.useFatherStatus =
CtlGetValue(GetObjectPtr(Chk_Prop_Father_Status));
gProjectPrefs.autoSyncToDo =
CtlGetValue(GetObjectPtr(Chk_Prop_Auto_Sync_ToDo));
gSavedPrefs.deleteWarn =
CtlGetValue(GetObjectPtr(Chk_Prop_Delete_Warn));
gProjectPrefs.completionDate =
CtlGetValue(GetObjectPtr(Chk_Prop_Comp_Date));
// read database attr
DmDatabaseInfo(0, gdbID, NULL, &attr, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
attr = attr | CtlGetValue(GetObjectPtr(Chk_Prop_Save_DB)) ?
dmHdrAttrBackup : 0;
DmSetDatabaseInfo(0, gdbID, NULL, &attr, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
// return to caller
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
// fall through
case Btn_Prop_Cancel:
// return to caller without modifying the prefs
FrmReturnToForm(0);
handled = true;
break;
default:
break;
}
break;
case keyDownEvent:
break;
default:
break;
}
return handled;
} // static Boolean FrmProjectPropertiesHandleEvent (EventPtr e)
static Boolean FrmMemoExportPropertiesHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
// set the controls based on the actual prefs
CtlSetValue(GetObjectPtr(Chk_Exp_Done),
gMemoExportPrefs.exportDone);
CtlSetValue(GetObjectPtr(Chk_Exp_Due_Dates),
gMemoExportPrefs.exportDueDate);
CtlSetValue(GetObjectPtr(Chk_Exp_Priorities),
gMemoExportPrefs.exportPriority);
CtlSetValue(GetObjectPtr(Chk_Exp_Progress),
gMemoExportPrefs.exportProgress);
CtlSetValue(GetObjectPtr(Chk_Exp_Note),
gMemoExportPrefs.exportNote);
CtlSetValue(GetObjectPtr(Chk_Exp_Flat),
gMemoExportPrefs.exportFlat);
FrmDrawForm(frm);
handled = true;
break;
case frmCloseEvent:
// handled = true ??
break;
case menuEvent:
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_ToMemo:
case Btn_ToDoc:
// modify the prefs
gMemoExportPrefs.exportDone =
CtlGetValue(GetObjectPtr(Chk_Exp_Done));
gMemoExportPrefs.exportDueDate =
CtlGetValue(GetObjectPtr(Chk_Exp_Due_Dates));
gMemoExportPrefs.exportPriority =
CtlGetValue(GetObjectPtr(Chk_Exp_Priorities));
gMemoExportPrefs.exportProgress =
CtlGetValue(GetObjectPtr(Chk_Exp_Progress));
gMemoExportPrefs.exportNote =
CtlGetValue(GetObjectPtr(Chk_Exp_Note));
gMemoExportPrefs.exportFlat =
CtlGetValue(GetObjectPtr(Chk_Exp_Flat));
if (e->data.ctlSelect.controlID == Btn_ToMemo)
{
if (ExportToMemo(gdbP, gMemoExportPrefs))
DEBUG1("Problem during export");
else
DEBUG1("Ok");
}
else
{
ChooseNameFunction = ChooseNameDoc;
FrmPopupForm(FrmChooseName);
}
// fall through
case Btn_Cancel:
FrmReturnToForm(0);
handled = true;
break;
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmMemoExportPropertiesHandleEvent (EventPtr e)
static Boolean FrmSetResetHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
UInt16 first, last, i, idRange;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
// set the controls based on the actual prefs
CtlSetValue(GetObjectPtr(Chk_Reset_Dates), false);
CtlSetValue(GetObjectPtr(Chk_Reset_Progress), false);
CtlSetValue(GetObjectPtr(Chk_Reset_Priority), false);
CtlSetValue(GetObjectPtr(Chk_ToDo_Unlink), false);
CtlSetValue(GetObjectPtr(Chk_ToDo_Link), false);
FrmDrawForm(frm);
handled = true;
break;
case frmCloseEvent:
// handled = true ??
break;
case menuEvent:
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_Ok:
switch (SelectRange())
{
case Btn_Sub_All:
first = 1;
last = DmNumRecords(gdbP);
idRange = StrAllTasks;
break;
case Btn_Sub_Sub:
first = gParentTask + 1;
last = GetLastInSub(gParentTask) + 1;
idRange = StrAllTasksInThisSubview;
break;
default:
return true;
break;
}
if (ConfirmCustom(StrActionModify, idRange))
return true;
// modify the prefs
for (i = first; i < last; i++)
{
if (CtlGetValue(GetObjectPtr(Chk_Reset_Dates)))
TaskSetDueDate(gdbP, i, gNoDate);
if (CtlGetValue(GetObjectPtr(Chk_Reset_Progress)))
TaskSetCompleted(gdbP, i,
TaskGetActionState(gdbP, i) ? ACTION_NO : 0);
if (CtlGetValue(GetObjectPtr(Chk_Reset_Priority)))
TaskSetPriority(gdbP, i, 6);
if (CtlGetValue(GetObjectPtr(Chk_ToDo_Unlink)) &&
TaskGetFormat(gdbP, i).hasToDo)
TaskRemoveHasToDo(gdbP, i);
if (CtlGetValue(GetObjectPtr(Chk_ToDo_Link)) &&
!TaskGetHasChild(gdbP, i))
{
UInt8 comp = TaskGetCompleted(gdbP, i);
if (comp < ACTION)
TaskSetCompleted(gdbP, i,
comp == 10 ? ACTION_OK : ACTION_NO);
TaskPublishToDo(gdbP, i);
if (TaskGetPriority(gdbP, i) == 6)
TaskSetPriority(gdbP, i, 5);
}
TaskUpdateToDo(gdbP, i);
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
// fall through
case Btn_Cancel:
FrmReturnToForm(0);
handled = true;
break;
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmSetResetHandleEvent (EventPtr e)
//
// Event handler for display property dialog.
//
static Boolean FrmDisplayPropertiesHandleEvent (EventPtr e)
{
Int16 TInt16;
ListPtr listP;
Boolean handled = false;
switch (e->eType) {
case frmOpenEvent:
LstSetSelection(GetObjectPtr(List_PriorityToBold),
gProjectPrefs.boldMinPriority);
CtlSetLabel(GetObjectPtr(Pop_PriorityToBold),
LstGetSelectionText(GetObjectPtr(List_PriorityToBold),
gProjectPrefs.boldMinPriority) );
LstSetSelection(GetObjectPtr(List_DaysToBold),
gProjectPrefs.boldMinDays);
CtlSetLabel(GetObjectPtr(Pop_DaysToBold),
LstGetSelectionText(GetObjectPtr(List_DaysToBold),
gProjectPrefs.boldMinDays) );
CtlSetValue(GetObjectPtr(Chk_StrikeDoneTasks),
gProjectPrefs.strikeDoneTasks);
CtlSetValue(GetObjectPtr(Chk_HideDoneProgress),
gProjectPrefs.hideDoneProgress);
CtlSetValue(GetObjectPtr(Chk_HideAllProgress),
gProjectPrefs.hideProgress);
FrmDrawForm(FrmGetActiveForm());
handled = true;
break;
case menuEvent:
handled = true;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Pop_PriorityToBold:
case Pop_DaysToBold:
listP = GetObjectPtr(e->data.ctlSelect.controlID + 1);
TInt16 = LstPopupList(listP);
if (TInt16 != -1)
{
CtlSetLabel(GetObjectPtr(e->data.ctlSelect.controlID),
LstGetSelectionText(listP, TInt16));
}
handled = true;
break;
case Btn_Ok:
gProjectPrefs.boldMinPriority =
LstGetSelection(GetObjectPtr(List_PriorityToBold));
gProjectPrefs.boldMinDays =
LstGetSelection(GetObjectPtr(List_DaysToBold));
gProjectPrefs.strikeDoneTasks =
CtlGetValue(GetObjectPtr(Chk_StrikeDoneTasks));
gProjectPrefs.hideDoneProgress =
CtlGetValue(GetObjectPtr(Chk_HideDoneProgress));
gProjectPrefs.hideProgress =
CtlGetValue(GetObjectPtr(Chk_HideAllProgress));
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
// fall down
case Btn_Cancel: // return to caller without modifying the prefs
FrmReturnToForm(0);
handled = true;
break;
}
default:
break;
}
return handled;
} // static Boolean FrmDisplayPropertiesHandleEvent (EventPtr e)
/* this function from oreilly's palm programming book */
Boolean EditMenuHandleEvent(UInt16 menuid, FieldPtr fld)
{
switch (menuid) {
case MenuEditUndo:
case MenuEditCut:
case MenuEditCopy:
case MenuEditPaste:
case MenuEditSelectAll:
if (!fld)
return false;
if (menuid==MenuEditUndo)
FldUndo(fld);
else if (menuid==MenuEditCut)
FldCut(fld);
else if (menuid==MenuEditCopy)
FldCopy(fld);
else if (menuid==MenuEditPaste)
FldPaste(fld);
else if (menuid==MenuEditSelectAll)
FldSetSelection(fld, 0, FldGetTextLength(fld));
return true;
case MenuEditKeyboard:
SysKeyboardDialog(kbdDefault);
return true;
case MenuEditGraffiti:
SysGraffitiReferenceDialog(referenceDefault);
return true;
default:
return false;
};
} // Boolean EditMenuHandleEvent(UInt16 menuid)
void FrmNoteEditUpdateScroll(void)
{
UInt16 textHeight, fieldHeight, scrollPos, maxValue;
FieldPtr fld = GetObjectPtr(TaskNote);
ScrollBarPtr bar = GetObjectPtr(Scr_Note_Edit);
FldGetScrollValues(fld, &scrollPos, &textHeight, &fieldHeight);
if (textHeight > fieldHeight)
maxValue = (textHeight - fieldHeight) + FldGetNumberOfBlankLines (fld);
else if (scrollPos)
maxValue = scrollPos;
else
maxValue = 0;
SclSetScrollBar (bar, scrollPos, 0, maxValue, fieldHeight-1);
} // void FrmNoteEditUpdateScroll(void)
void FrmNoteEditScrollPage(WinDirectionType direction)
{
UInt16 textHeight, fieldHeight, scrollPos, maxValue;
FieldPtr fld = GetObjectPtr(TaskNote);
ScrollBarPtr bar = GetObjectPtr(Scr_Note_Edit);
UInt16 step = 10;
FldGetScrollValues(fld, &scrollPos, &textHeight, &fieldHeight);
switch (direction)
{
case winUp:
if (scrollPos - step < 0)
{
step = scrollPos;
scrollPos = 0;
}
else
scrollPos -= step;
break;
case winDown:
if (scrollPos + step > textHeight)
{
step = textHeight - scrollPos;
scrollPos = textHeight;
}
else
scrollPos += step;
break;
default:
break;
}
FldScrollField(fld, step, direction);
FldGetScrollValues(fld, &scrollPos, &textHeight, &fieldHeight);
if (textHeight > fieldHeight)
maxValue = textHeight - fieldHeight;
else if (scrollPos)
maxValue = scrollPos;
else
maxValue = 0;
SclSetScrollBar (bar, scrollPos, 0, maxValue,
fieldHeight-1);
} // void FrmNoteEditScrollPage(void)
static Boolean FrmNoteEditHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
MemHandle h;
TaskRecordType *p;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
InitFrmNoteEdit();
h = DmQueryRecord(gdbP, gActualTask);
p = MemHandleLock(h);
SetFormTitle(frm, (Char*)&p->description);
MemHandleUnlock(h);
FrmDrawForm(frm);
// set the focus
FrmSetFocus(frm, FrmGetObjectIndex(frm, TaskNote));
FrmNoteEditUpdateScroll();
handled = true;
break;
case frmCloseEvent:
CleanUpFrmNoteEdit(); // save the note !!!
// handled = true ??
break;
case menuEvent:
handled = EditMenuHandleEvent(e->data.menu.itemID,
GetObjectPtr(TaskNote));
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_Note_Ok:
// save
CleanUpFrmNoteEdit();
case Btn_Note_Cancel:
// return to caller
FrmUpdateForm(FrmTaskEdit, frmTaskEditReturnFromNote);
FrmReturnToForm(0);
handled = true;
break;
case Btn_Note_Delete:
if (ConfirmCustom(StrActionDelete, StrThisNote) == 0)
{
FieldPtr fld = GetObjectPtr(TaskNote);
MemHandle textH = FldGetTextHandle(fld);
Char* textP;
textP = MemHandleLock(textH);
StrCopy(textP, "\0");
MemHandleUnlock(textH);
FldCompactText(fld);
// save
CleanUpFrmNoteEdit();
// return to caller
FrmUpdateForm(FrmTaskEdit, frmTaskEditReturnFromNote);
FrmReturnToForm(0);
handled = true;
}
break;
default:
break;
}
break;
case keyDownEvent:
switch (e->data.keyDown.chr)
{
case vchrPageDown:
FrmNoteEditScrollPage(winDown);
handled = true;
break;
case vchrPageUp:
FrmNoteEditScrollPage(winUp);
handled = true;
break;
default:
break;
}
break;
case fldChangedEvent:
FrmNoteEditUpdateScroll();
handled = true;
break;
case sclRepeatEvent:
FldScrollField(GetObjectPtr(TaskNote),
abs(e->data.sclRepeat.value - e->data.sclRepeat.newValue),
e->data.sclRepeat.value > e->data.sclRepeat.newValue ?
winUp : winDown);
break;
default:
break;
}
return handled;
} // static Boolean FrmNoteEditHandleEvent (EventPtr e)
Boolean FrmFlatCtlSelectHandleEvent(EventPtr e)
{
FormPtr frm;
frm = FrmGetActiveForm();
switch(e->data.ctlSelect.controlID) {
case Btn_Done:
FrmGotoForm(FrmProjectList);
CloseDB(gdbP);
gActualTask = gLastSelected = gRefLevel = gParentTask = 0;
break;
case Btn_Main_Hierarchical:
FrmGotoForm(FrmMain);
break;
case Btn_Main_Flat:
FrmPopupForm(FrmFlatFilter);
break;
default:
break;
}
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
return true;
} // Boolean FrmFlatCtlSelectHandleEvent(EventPtr e)
void ProjectFlatTableUpdate(void)
{
TablePtr table;
UInt16 numRows;
UInt16 i, index;
UInt16 cardNo = 0;
LocalID sortInfoID;
UInt32 *p;
UInt32 size = 0;
table = GetObjectPtr(ProjectTable);
numRows = TblGetNumberOfRows(table);
// get the sort info block
DmDatabaseInfo(cardNo, gdbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, &sortInfoID, NULL, NULL);
p = MemLocalIDToLockedPtr(sortInfoID, cardNo);
size = MemPtrSize(p) / sizeof(UInt32);
// if gdbP contains at least one task, there is at least one terminal task
// special case, db empty (just task 0)
if ((DmNumRecords(gdbP) == 1) || (*p == 0))
{
ProjectTableEmpty();
MemPtrUnlock(p);
return;
}
if (gFlatOffset >= size)
gFlatOffset = size - 1;
// first item
DmFindRecordByID(gdbP, p[gFlatOffset], &index);
if (index)
TblSetItemInt(table, 0, 0, index);
else
TblSetItemInt(table, 0, 0, -1);
// first item change if it is now invisible
// TODO
// other items
// TODO : end detection code, etc...
for (i = 1; i < numRows; i++)
{
if (gFlatOffset + i >= size)
TblSetItemInt(table, i, 0, -1);
else
{
DmFindRecordByID(gdbP, p[gFlatOffset + i], &index);
if (index)
TblSetItemInt(table, i, 0, index);
else
TblSetItemInt(table, i, 0, -1);
}
}
MemPtrUnlock(p);
gCurrentPrefs.topTask = TblGetItemInt(table, 0, 0);
} // void ProjectFlatTableUpdate(void)
Boolean FrmFlatKeyDownHandleEvent(EventPtr e)
{
switch (e->data.keyDown.chr)
{
case vchrPageDown:
gFlatOffset += 5;
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
break;
case vchrPageUp:
if (gFlatOffset < 5)
gFlatOffset = 0;
else
gFlatOffset -= 5;
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
break;
// this code don't work well at all !
// no time to correct yet
// case chrUpArrow:
// if (gActualTask)
// {
// UInt16 prev = gActualTask - 1;
// while (prev && !FlatFilter(gdbP, prev))
// prev--;
// if (prev)
// {
// gActualTask = prev;
// SelectActualTask(true);
// FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
// }
// }
// break;
// case chrDownArrow:
// if ((gActualTask + 1 < DmNumRecords(gdbP)))
// {
// UInt16 next = gActualTask + 1, numRec = DmNumRecords(gdbP);
// while (next < numRec && !FlatFilter(gdbP, next))
// next++;
// if (next < numRec)
// {
// gActualTask = next;
// SelectActualTask(true);
// FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
// }
// }
// break;
default:
break;
}
return true;
} // Boolean FrmFlatKeyDownHandleEvent(EventPtr e)
static Boolean FrmFlatHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
Int16 x;
TaskFormatType format;
frm = FrmGetActiveForm();
gTable = GetObjectPtr(ProjectTable);
switch (e->eType) {
case frmUpdateEvent:
switch(e->data.frmUpdate.updateCode)
{
case frmRedrawUpdateCode:
ProjectFlatTableUpdate();
FrmDrawForm(frm);
SelectActualTask(false);
handled = true;
break;
default:
break;
}
break;
case frmOpenEvent:
gCurrentPrefs.view = flatView;
ProjectTableInit();
SetFormTitle(frm, gCurrentPrefs.openDBName);
FlatCreateList(gdbP);
ProjectFlatTableUpdate();
FrmDrawForm(frm);
gTable = GetObjectPtr(ProjectTable);
gParentTask = 0;
gRefLevel = 0;
CtlSetValue(GetObjectPtr(Btn_Main_Flat), true);
handled = true;
break;
case menuEvent:
MenuEraseStatus(NULL);
switch(e->data.menu.itemID) {
case MenuMainPreferences:
FrmPopupForm(FrmProjectProperties);
break;
case MenuMainDisplayPreferences:
FrmPopupForm(FrmDisplayProperties);
break;
case MenuMainFlatFilter:
FrmPopupForm(FrmFlatFilter);
break;
case MenuPublishLinkMaster:
if (gActualTask > 0)
PublishToLinkMaster(gdbP, gActualTask);
break;
case MenuLinkViaLinkMaster:
if (gActualTask > 0)
RequestLinkViaLinkMaster(gCurrentPrefs.openDBName, gActualTask);
break;
case MenuRemoveLinkViaLinkMaster:
if (gActualTask > 0)
RemoveLinkViaLinkMaster(gActualTask);
break;
case MenuEditAddNote:
if (gActualTask)
{
FrmPopupForm(FrmNoteEdit);
}
break;
case MenuLinkAll:
FlatLinkAll(gdbP, true);
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
break;
case MenuUnlinkAll:
FlatLinkAll(gdbP, false);
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
break;
}
handled = true;
break;
// remember the screen coords
case tblEnterEvent:
gLastDownX = e->screenX;
gLastDownY = e->screenY;
// deselect all
gActualTask = 0;
break;
case ctlSelectEvent:
handled = FrmFlatCtlSelectHandleEvent(e);
break;
case ctlRepeatEvent:
switch (e->data.ctlRepeat.controlID)
{
case Btn_Scroll_Up:
if (gFlatOffset > 0)
gFlatOffset--;
break;
case Btn_Scroll_Down:
gFlatOffset++;
break;
default:
break;
}
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
break;
case tblSelectEvent:
gActualTask = TblGetItemInt(gTable, e->data.tblSelect.row, 0);
if (gActualTask == -1)
gActualTask = 0;
format = TaskGetFormat(gdbP, gActualTask);
x = gLastDownX/11;
if (gActualTask) // this is for all the switch
switch (x)
{
case 0:
/**************************************************************
* Code for ToDo Link
*************************************************************/
if (! format.extendedType)
{
if (format.hasToDo)
TaskRemoveHasToDo(gdbP, gActualTask);
else
{
UInt8 comp = TaskGetCompleted(gdbP, gActualTask);
if (comp < ACTION)
{
TaskSetCompleted(gdbP, gActualTask,
comp == 10 ? ACTION_OK : ACTION_NO);
}
TaskPublishToDo(gdbP, gActualTask);
}
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
}
break;
case 1:
/**************************************************************
* Code for progress buttons
*************************************************************/
ProgressHandleEvent();
break;
default:
//////////////////////////////////////////////////////////////
// Code for note
//////////////////////////////////////////////////////////////
if (gLastDownX > 153 && format.hasNote)
{
FrmPopupForm(FrmNoteEdit);
}
else if (gLastDownX > (153 - (format.hasNote? 8 : 0))
&& format.hasLink)
{
FollowLinkViaLinkMaster(gActualTask);
}
// if a priority is visible
else if (x == 2)
{
PriorityHandleEvent(e);
}
// edit text if click on the right side
else if (x > 0)
{
if (gLastSelected == gActualTask)
{
FrmPopupForm(FrmTaskEdit);
}
else
{
gLastSelected = gActualTask;
}
}
else
{
// left part
// nothing to do for now
}
break;
}
handled = true;
break;
// TODO : put this '5' in prefs (scroll step)
case keyDownEvent:
handled = FrmFlatKeyDownHandleEvent(e);
break;
default:
break;
}
return handled;
} // static Boolean FrmFlatHandleEvent (EventPtr e)
static Boolean FrmTaskDefaultsHandleEvent (EventPtr e)
{
Boolean handled = false;
FormPtr frm;
frm = FrmGetActiveForm();
switch (e->eType) {
case frmOpenEvent:
FrmDrawForm(frm);
// some older releases modified these fields, resulting in initial
// corrupted notes
gEmptyTask.note = "";
gEmptyTask.description = "";
gProjectPrefs.taskDefaults.note = "";
gProjectPrefs.taskDefaults.description = "";
// get the action value and set it on the form
CtlSetValue(GetObjectPtr(Chk_Edit_Action),
gEmptyTask.completed);
// to be compatible with not initialised db
if (gEmptyTask.priority > 0 && gEmptyTask.priority < 7)
{
CtlSetValue(GetObjectPtr(Btn_Priority_X + gEmptyTask.priority - 1),
true);
}
handled = true;
break;
case ctlSelectEvent:
switch(e->data.ctlSelect.controlID) {
case Btn_Edit_Ok:
gProjectPrefs.taskDefaults = gEmptyTask;
FrmReturnToForm(0);
handled = true;
break;
case Btn_Edit_Cancel:
gEmptyTask = gProjectPrefs.taskDefaults;
FrmReturnToForm(0);
handled = true;
break;
case Chk_Edit_Action:
gEmptyTask.completed = gEmptyTask.completed > 10 ?
0 : ACTION_NO;
break;
case Btn_Priority_1:
case Btn_Priority_2:
case Btn_Priority_3:
case Btn_Priority_4:
case Btn_Priority_5:
case Btn_Priority_No:
gEmptyTask.priority = e->data.ctlSelect.controlID -
Btn_Priority_X + 1;
default:
break;
}
break;
default:
break;
}
return handled;
} // static Boolean FrmTaskDefaultsHandleEvent (EventPtr e)
static Boolean ApplicationHandleEvent(EventPtr e)
{
if (e->eType == frmLoadEvent)
{
UInt16 formId = e->data.frmLoad.formID;
struct tag_HandlerMap {
UInt16 id;
Boolean (*proc)(EventPtr e);
};
static struct tag_HandlerMap hm[] = {
{ FrmMain, FrmMainHandleEvent },
{ FrmTaskEdit, FrmTaskEditHandleEvent },
{ FrmProjectList, FrmProjectListHandleEvent },
{ FrmChooseName, FrmChooseNameHandleEvent },
{ FrmProjectProperties, FrmProjectPropertiesHandleEvent },
{ FrmDisplayProperties, FrmDisplayPropertiesHandleEvent },
{ FrmNoteEdit, FrmNoteEditHandleEvent },
{ FrmFlat, FrmFlatHandleEvent },
{ FrmFlatFilter, FrmFlatFilterHandleEvent },
{ FrmDirectLink, FrmDirectLinkHandleEvent },
{ FrmTaskDefaults, FrmTaskDefaultsHandleEvent },
{ FrmMemoExportProperties, FrmMemoExportPropertiesHandleEvent },
{ FrmIconSelect, FrmIconSelectHandleEvent },
{ FrmSetReset, FrmSetResetHandleEvent },
{ 0, NULL }
};
static struct tag_HandlerMap* p;
for (p = hm; p->proc != NULL && p->id != formId; p++)
;
if (p->proc != NULL)
{
FormPtr frm = FrmInitForm(formId);
FrmSetActiveForm(frm);
FrmSetEventHandler(frm, p->proc);
return true;
}
}
return false;
} // static Boolean ApplicationHandleEvent(EventPtr e)
/* Get preferences, open (or create) app database */
static UInt16 StartApplication(void)
{
UInt8 i;
//
// get PalmOS features and settings.
//
// Detect PalmOS version to know OS features
UInt32 version;
if (! FtrGet(sysFtrCreator, sysFtrNumROMVersion, &version))
{
#define ver(a,b) sysMakeROMVersion(a, b, 0, sysROMStageRelease, 0)
OSCaps.ver30 = (version >= ver(3, 0));
OSCaps.ver31 = (version >= ver(3, 1));
OSCaps.ver32 = (version >= ver(3, 2));
OSCaps.ver33 = (version >= ver(3, 3));
OSCaps.ver34 = (version >= ver(3, 4));
OSCaps.ver35 = (version >= ver(3, 5));
#undef ver
}
// NOTE: for test only..
WinScreenMode(winScreenModeGetDefaults,
&OSCaps.nScreenWidth, &OSCaps.nScreenHeight,
&OSCaps.nScreenDepth, &OSCaps.enableColor);
// load icon data
initializeIcon();
// get date format
gDateFormat = PrefGetPreference(prefDateFormat);
gToday = Today();
gTodayDays = DateToDays(gToday);
// init the icons handles array
for (i = 0; i < IconNum; i++)
{
gIconHandle[i] = (MemHandle)DmGetResource('Tbmp', BtmOffset + i);
}
// read the current prefs
if (!LoadAppPrefs(false))
{
gCurrentPrefs.openDB = false;
gCurrentPrefs.topTask = -1;
gActualTask = 0;
gParentTask = 0;
gRefLevel = 0;
}
else
{
gActualTask = gCurrentPrefs.actualTask;
gParentTask = gCurrentPrefs.parentTask;
gRefLevel = gCurrentPrefs.refLevel;
}
// read the global prefs
LoadAppPrefs(true);
return 0;
} // static UInt16 StartApplication(void)
/* Save preferences, close forms, close app database */
static void StopApplication(void)
{
UInt8 i;
gCurrentPrefs.actualTask = gActualTask;
gCurrentPrefs.parentTask = gParentTask;
gCurrentPrefs.refLevel = gRefLevel;
SaveAppPrefs(false); // current prefs
SaveAppPrefs(true); // saved prefs
FrmSaveAllForms();
FrmCloseAllForms();
if (gdbP)
{
CloseDB(gdbP);
gdbP = NULL;
}
// release the icons handles array
for (i = 0; i < IconNum; i++)
{
DmReleaseResource(gIconHandle[i]);
}
// clear the clipboard
NewClipboard();
CloseClipboard();
} // static void StopApplication(void)
/* The main event loop */
static void EventLoop(void)
{
Err err;
EventType e;
do {
EvtGetEvent(&e, evtWaitForever);
if (! SysHandleEvent (&e))
if (! MenuHandleEvent (NULL, &e, &err))
if (! ApplicationHandleEvent (&e))
FrmDispatchEvent (&e);
} while (e.eType != appStopEvent);
} // static void EventLoop(void)
static void switchView(viewType view)
{
gCurrentPrefs.view = view;
switch (view)
{
case normalView:
FrmGotoForm(FrmMain);
FrmUpdateForm(FrmMain, frmRedrawUpdateCode);
break;
case flatView:
FrmGotoForm(FrmFlat);
FrmUpdateForm(FrmFlat, frmRedrawUpdateCode);
break;
default:
break;
}
}
/****************************************************************************
* Name : GoToItem
* Desc : open database and select task specified by gotoparams.
* Parm :
* -> item info
* -> just launching now?
* Out :
* Auth : seagull, 22.09.2000 JST
***************************************************************************/
static void GoToItem(GoToParamsPtr gotoparams, Boolean launchapp)
{
UInt16 recordNum = gotoparams->recordNum;
if (! launchapp)
{ // app is now on running.
UInt32 uniqueID;
if (gdbP)
{
UInt16 cardNo;
LocalID dbID;
DmOpenDatabaseInfo(gdbP, &dbID, 0, 0, &cardNo, 0);
if (cardNo == gotoparams->dbCardNo && dbID == gotoparams->dbID)
{ // require same database
DmRecordInfo(gdbP, recordNum, NULL, &uniqueID, NULL);
FrmCloseAllForms();
DmFindRecordByID(gdbP, uniqueID, &recordNum);
}
else
{ // switch to other database
FrmCloseAllForms();
CloseDB(gdbP);
OpenDBByID(gotoparams->dbCardNo, gotoparams->dbID, &gdbP);
if (! gdbP)
{
FrmGotoForm(FrmProjectList);
return;
}
}
}
}
// OK, the database was opened successflly. select view and record.
// NOTE: ummm..I want a view for link published time, not a last selected.
gLastSelected = gActualTask = recordNum;
switchView(gCurrentPrefs.view);
} // static void GoToItem(GoToParamsPtr gotoparams, Boolean launchapp)
/* Main entry point; it is unlikely you will need to change this except to
handle other launch command codes */
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
Err err;
if (cmd == sysAppLaunchCmdNormalLaunch ||
cmd == sysAppLaunchCmdOpenDB ||
cmd == linkAppLaunchFollowLink ||
cmd == linkAppLaunchReturnLink ||
cmd == linkAppLaunchRequestLink )
{
err = StartApplication();
if (err) return err;
//
// Open database (,and goto item)
//
if (cmd == sysAppLaunchCmdNormalLaunch ||
cmd == linkAppLaunchRequestLink)
{
if (gCurrentPrefs.openDB && ! OpenDB(gCurrentPrefs.openDBName, &gdbP))
switchView(gCurrentPrefs.view);
else
FrmGotoForm(FrmProjectList);
}
else if (cmd == sysAppLaunchCmdOpenDB)
{
SysAppLaunchCmdOpenDBType* db = (SysAppLaunchCmdOpenDBType*)cmdPBP;
err = OpenDBByID(db->cardNo, db->dbID, &gdbP);
if (err) return err; // Failed to open that database.
switchView(gCurrentPrefs.view);
}
else if (cmd == linkAppLaunchFollowLink)
{
GoToParamsPtr gotoparams = LinkSimpleToGoToParams((LinkSimplePtr)cmdPBP);
if (gotoparams)
{
err = OpenDBByID(gotoparams->dbCardNo, gotoparams->dbID, &gdbP);
if (!err)
GoToItem(gotoparams, false);
MemPtrFree(gotoparams);
}
else return 0;
}
else if (cmd == linkAppLaunchReturnLink)
{
LinkSimplePtr p1 = (LinkSimplePtr)cmdPBP;
LinkInfoPtr p2 = (LinkInfoPtr)((LinkInfoPtr)cmdPBP + 1);
if (! OpenDB(p1->db_name, &gdbP))
{
SetLinkMasterLink(p1, p2);
DmFindRecordByID(gdbP, p1->record_id, &gActualTask);
switchView(gCurrentPrefs.view);
}
else
FrmGotoForm(FrmProjectList);
}
EventLoop();
StopApplication();
}
else if (cmd == linkAppLaunchFollowLinkSubCall)
{
GoToParamsPtr gotoparams;
if (launchFlags & sysAppLaunchFlagNewGlobals)
{
gotoparams = LinkSimpleToGoToParams((LinkSimplePtr)cmdPBP);
if (gotoparams)
{
GoToItem(gotoparams, false);
MemPtrFree(gotoparams);
}
}
else
{
DmSearchStateType state;
UInt16 card;
LocalID db;
if (DmGetNextDatabaseByTypeCreator(true, &state, sysFileTApplication,
CREATOR, false, &card, &db) == 0)
SysUIAppSwitch(card, db, linkAppLaunchFollowLink, cmdPBP);
}
}
else if (cmd == sysAppLaunchCmdFind)
{
Search ((FindParamsPtr)cmdPBP);
// open first database
// if it doesn't exist
// findParams->more = false;
// exit
// while we've got a database
// scan each record
// search for the next database
// exit
return 0;
}
else if (cmd == sysAppLaunchCmdGoTo)
{
GoToParamsPtr gotoparams = (GoToParamsPtr)cmdPBP;
Boolean launched = launchFlags & sysAppLaunchFlagNewGlobals;
if (launched)
{
err = StartApplication();
if (err) return err;
err = OpenDBByID(gotoparams->dbCardNo, gotoparams->dbID, &gdbP);
if (! err)
{
GoToItem(gotoparams, launched);
EventLoop();
StopApplication();
}
}
else GoToItem(gotoparams, launched);
}
// else
// return sysErrParamErr;
return 0;
} // UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
/*
* based on MemoMain.c from Palm
* adapted by L. Burgbacher for Progect
*/
static void DrawProjectTitle (Char * memo, Int16 x, Int16 y, Int16 width)
{
Char * ptr = StrChr (memo, linefeedChr);
UInt16 titleLen = (ptr == NULL ? StrLen (memo) : (UInt16) (ptr - memo));
if (FntWidthToOffset (memo, titleLen, width, NULL, NULL) == titleLen)
{
WinDrawChars (memo, titleLen, x, y);
}
else
{
Int16 titleWidth;
titleLen = FntWidthToOffset (memo, titleLen, width - FntCharWidth (chrEllipsis), NULL, &titleWidth);
WinDrawChars (memo, titleLen, x, y);
WinDrawChar (chrEllipsis, x + titleWidth, y);
}
}
/*
* based on MemoMain.c from Palm
* adapted by L. Burgbacher for Progect
*/
static void Search(FindParamsPtr findParams)
{
UInt16 pos;
Char * header;
UInt16 recordNum;
MemHandle h;
MemHandle headerStringH;
RectangleType r;
Boolean done;
Boolean match;
DmOpenRef dbP;
DmSearchStateType searchState;
Err err;
UInt16 cardNo = 0;
LocalID dbID, currentDbID;
TaskRecordType *p;
UInt32 longPos;
UInt16 matchLength;
Char searchDbName[] = "lbPG-GlobalSearch";
LocalID searchID = 0;
LocalID *IDPtr = NULL;
DmOpenRef searchDb = NULL;
Boolean firstTime = true;
// if this is a continuation, find the last opened database
if (findParams->continuation)
{
searchID = DmFindDatabase(cardNo, searchDbName);
if (!searchID)
{
// this denotes a problem...
findParams->more = false;
return;
}
searchDb = DmOpenDatabase(cardNo, searchID, dmModeReadWrite);
if (!searchDb)
{
// this denotes a problem...
findParams->more = false;
return;
}
h = DmQueryRecord(searchDb, 0);
if (h)
{
currentDbID = *(LocalID*)(MemHandleLock(h));
MemHandleUnlock(h);
DmCloseDatabase(searchDb);
}
else
{
findParams->more = false;
DmCloseDatabase(searchDb);
DmDeleteDatabase(cardNo, searchID);
return;
}
}
else
{
// init currentDbID for first time
DmGetNextDatabaseByTypeCreator (true, &searchState, 'DATA',
CREATOR, false, &cardNo, ¤tDbID);
}
// find the actual searched db
while (dbID != currentDbID)
{
// Find the application's data file.
err = DmGetNextDatabaseByTypeCreator (firstTime, &searchState, 'DATA',
CREATOR, false, &cardNo, &dbID);
firstTime = false;
if (err)
{
findParams->more = false;
if (searchID)
DmDeleteDatabase(cardNo, searchID);
return;
}
}
// Open the first database.
dbP = DmOpenDatabase(cardNo, dbID, findParams->dbAccesMode);
if (!dbP)
{
findParams->more = false;
if (searchID)
DmDeleteDatabase(cardNo, searchID);
return;
}
// Display the heading line.
headerStringH = DmGetResource('tSTR', StrFindHeader);
header = MemHandleLock(headerStringH);
done = FindDrawHeader(findParams, header);
MemHandleUnlock(headerStringH);
DmReleaseResource(headerStringH);
if (done)
goto Exit;
// Search the memos for the "find" string.
recordNum = findParams->recordNum;
while (true)
{
// Because applications can take a long time to finish a find when
// the result may be on the screen or for other reasons, users like
// to be able to stop the find. Stop the find if an event is pending.
// This stops if the user does something with the device. Because
// this call slows winDown the search we perform it every so many
// records instead of every record. The response time should still
// be Int16 without introducing much extra work to the search.
if ((recordNum & 0x000f) == 0 && // every 16th record
EvtSysEventAvail(true))
{
// Stop the search process.
findParams->more = true;
break;
}
h = DmQueryRecord(dbP, recordNum);
// Have we run out of records?
while (!h)
{
// search the next database
err = DmGetNextDatabaseByTypeCreator (false, &searchState, 'DATA',
CREATOR, false, &cardNo, &dbID);
if (err)
{
findParams->more = false;
if (searchID)
DmDeleteDatabase(cardNo, searchID);
break;
}
DmCloseDatabase(dbP);
dbP = DmOpenDatabase(cardNo, dbID, findParams->dbAccesMode);
if (!dbP)
{
findParams->more = false;
if (searchID)
DmDeleteDatabase(cardNo, searchID);
break;
}
recordNum = 1;
findParams->recordNum = 1;
h = DmQueryRecord(dbP, recordNum);
}
if (!h) break;
p = MemHandleLock(h);
// don't treat extended types yet.
if (p->format.bits.extendedType)
{
recordNum++;
MemHandleUnlock(h);
continue;
}
// Search for the string passed, if it's found display the title
// of the project.
// match = TxtGlueFindString (&(p->description), findParams->strToFind, &longPos, &matchLength);
match = TxtFindString(&(p->description), findParams->strToFind, &longPos, &matchLength);
pos = longPos;
if (match)
{
// Add the match to the find paramter block, if there is no room to
// display the match the following function will return true.
done = FindSaveMatch (findParams, recordNum, pos, 0, matchLength, cardNo, dbID);
if (!done)
{
Char dbname[32];
// Get the bounds of the region where we will draw the results.
FindGetLineBounds (findParams, &r);
DmDatabaseInfo(cardNo, dbID, dbname, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
// Display the title of the description.
DrawProjectTitle (&dbname[5], r.topLeft.x+1, r.topLeft.y,
r.extent.x-2);
findParams->lineNumber++;
}
}
MemHandleUnlock(h);
if (done) break;
recordNum++;
}
Exit:
if (dbP)
DmCloseDatabase (dbP);
if (findParams->more)
{
// create the searchdatabase and init it
err = DmCreateDatabase(cardNo, searchDbName, CREATOR, 'SRCH', false);
if ((err == dmErrAlreadyExists) || !err)
{
UInt16 index = 0;
searchID = DmFindDatabase(cardNo, searchDbName);
if (!searchID) return;
searchDb = DmOpenDatabase(cardNo, searchID, dmModeReadWrite);
if (!searchDb) return;
while (DmNumRecords(searchDb))
{
DmRemoveRecord(searchDb, 0);
}
h = DmNewRecord(searchDb, &index, sizeof(LocalID));
if (h)
IDPtr = MemHandleLock(h);
if (IDPtr)
{
DmWrite(IDPtr, 0, &dbID, sizeof(LocalID));
MemHandleUnlock(h);
DmReleaseRecord(searchDb, index, true);
}
DmCloseDatabase(searchDb);
}
}
}