[Trainsched-commit] trainsched abbrevform.c, NONE, 1.1.2.1 abbrevform.h, NONE, 1.1.2.1 notesform.c,
Brought to you by:
philm
|
From: Steve M. <sma...@us...> - 2009-05-04 17:25:01
|
Update of /cvsroot/trainsched/trainsched In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12370 Added Files: Tag: PDB_VER2 abbrevform.c abbrevform.h notesform.c notesform.h Log Message: New forms for Abbreviations and Notes display. --- NEW FILE: notesform.h --- /* notesform.h - display train schedule on Palm Pilot * (C) 2009 Steve Martin <sma...@us...> */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Function Prototypes. Boolean notesFormEventHandler(EventPtr event); void LoadNotes(FormPtr pForm, Boolean Update); //void InitAbbrevTable(FormPtr pForm); --- NEW FILE: abbrevform.h --- /* abbrevform.h - display train schedule on Palm Pilot * (C) 2009 Steve Martin <sma...@us...> */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Table columns #define ABBREVCOL 0 #define DEFFNCOL 1 // Function Prototypes. Boolean abbrevFormEventHandler(EventPtr event); void LoadAbbrevTable(FormPtr pForm, Boolean Update); void InitAbbrevTable(FormPtr pForm); --- NEW FILE: notesform.c --- /* notesform.c - display train schedule on Palm Pilot * (C) 2009 Steve Martin <sma...@us...> */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <PalmOS.h> #include <Window.h> #include "trainsched.h" #include "timetable.h" #include "notesform.h" // Global Variables Int16 fieldHeight=0; // External veriables extern char Notes[NOTESLENGTH]; Boolean notesFormEventHandler(EventPtr event) { Boolean handled = false; FormPtr pForm = FrmGetActiveForm(); UInt16 scrollLines; WinDirectionType direction; Int16 val, min, max, page; WChar c; switch (event->eType) { case frmOpenEvent: LoadNotes(pForm, false); FrmDrawForm(pForm); handled = true; break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case notesFrmOKButton: FrmReturnToForm(0); handled = true; break; default: break; } break; case sclRepeatEvent: if (event->data.sclRepeat.newValue > event->data.sclRepeat.value) { scrollLines = event->data.sclRepeat.newValue - event->data.sclRepeat.value; direction = winDown; } else { scrollLines = event->data.sclRepeat.value - event->data.sclRepeat.newValue; direction = winUp; } FldScrollField(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,notesField)), scrollLines, direction); break; case keyDownEvent: c = event->data.keyDown.chr; if (TxtGlueCharIsVirtual(event->data.keyDown.modifiers, c)) { if ((c == vchrPageUp) || (c == vchrRockerUp)) { SclGetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, notesFieldScrollBar)), &val, &min, &max, &page); if ( val >= min ) { if ((val - min) < page) { scrollLines = val - min; val = min; } else { scrollLines = page; val -= page; } direction = winUp; handled = true; } } else if ((c == vchrPageDown) || (c == vchrRockerDown)) { SclGetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, notesFieldScrollBar)), &val, &min, &max, &page); if (val < max) { if ((max - val) < page) { scrollLines = max - val; val = max; } else { scrollLines = page; val += page; } direction = winDown; handled = true; } } if (handled) { FldScrollField(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,notesField)), scrollLines, direction); SclSetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, notesFieldScrollBar)), val, 0, max, fieldHeight); } } break; default: break; } return handled; } /* Populates and draw abbrevForm table * Update : false if this is the first call, true for a refresh (scrolling...) */ void LoadNotes(FormPtr pForm, Boolean Update) { FieldPtr fieldP; Int16 scrollPos=0, textHeight=0, scrollMax=0; fieldP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,notesField)); FldSetTextPtr(fieldP, Notes); FldRecalculateField(fieldP, true); FldGetScrollValues(fieldP, &scrollPos, &textHeight, &fieldHeight); if (textHeight > fieldHeight) scrollMax = textHeight - fieldHeight; else if (scrollPos) scrollMax = scrollPos; else scrollMax = 0; SclSetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, notesFieldScrollBar)), scrollPos, 0, scrollMax, fieldHeight); } --- NEW FILE: abbrevform.c --- /* abbrevform.c - display train schedule on Palm Pilot * (C) 2009 Steve Martin <sma...@us...> */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <PalmOS.h> #include "trainsched.h" #include "timetable.h" #include "abbrevform.h" // Global Variables Int16 ScrollAbbrevValue=0; // External veriables extern UInt16 numabbrev; extern char Abbreviations[MAX_ABBREVIATIONS][ABBREVLENGTH]; extern char AbbrevDeffs[MAX_ABBREVIATIONS][ABDEFLENGTH]; Boolean abbrevFormEventHandler(EventPtr event) { Boolean handled = false; FormPtr pForm = FrmGetActiveForm(); Int16 val, min, max, page; RectangleType r; TablePtr tableP; WChar c; switch (event->eType) { case frmOpenEvent: InitAbbrevTable(pForm); // Fall through to the frmUpdateEvent. case frmUpdateEvent: FrmDrawForm(pForm); LoadAbbrevTable(pForm, false); /* Draw the outline of the table */ tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,abbrevFrmTable)); TblGetBounds(tableP, &r); WinDrawRectangleFrame( simpleFrame, &r ); handled = true; break; case sclRepeatEvent: ScrollAbbrevValue = event->data.sclRepeat.newValue; LoadAbbrevTable(pForm, false); break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case abbrevFrmOKButton: FrmReturnToForm(0); handled = true; break; default: break; } break; case keyDownEvent: c = event->data.keyDown.chr; if (TxtGlueCharIsVirtual(event->data.keyDown.modifiers, c)) { if ((c == vchrPageUp) || (c == vchrRockerUp)) { SclGetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, abbrevFrmTableScrollBar)), &val, &min, &max, &page); if ( val >= min ) { if ((val - min) < page) ScrollAbbrevValue -= (val - min); else ScrollAbbrevValue -= page; LoadAbbrevTable(pForm, false); } handled = true; } else if ((c == vchrPageDown) || (c == vchrRockerDown)) { SclGetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, abbrevFrmTableScrollBar)), &val, &min, &max, &page); if (val < max) { if ((max - val) < page) ScrollAbbrevValue += (max - val); else ScrollAbbrevValue += page; LoadAbbrevTable(pForm, false); } handled = true; } } break; default: break; } return handled; } /* Draws items in Abbreviation table */ void AbbrevTableDrawItem(void *table, Int16 row, Int16 column, RectanglePtr bounds) { TablePtr tableP = (TablePtr)table; char str[ABDEFLENGTH]; UInt16 data; // Abbreviation number. data = TblGetItemInt(tableP, row, column); if (column == ABBREVCOL) { StrCopy(str, Abbreviations[data]); FntSetFont(stdFont); WinDrawChars(str, StrLen(str), bounds->topLeft.x+2, bounds->topLeft.y); } else { StrCopy(str, AbbrevDeffs[data]); FntSetFont(stdFont); WinDrawChars(str, StrLen(str), bounds->topLeft.x+2, bounds->topLeft.y); } } /* Initialize The abbrevForm Table */ void InitAbbrevTable(FormPtr pForm) { TablePtr tableP; Int32 i; UInt16 numRows=0; tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,abbrevFrmTable)); numRows = TblGetNumberOfRows(tableP); /* Setup the rows of the table */ for(i=0; i<numRows; i++) { TblSetItemStyle(tableP, i, ABBREVCOL, customTableItem); TblSetItemStyle(tableP, i, DEFFNCOL, customTableItem); TblSetRowUsable(tableP, i, false); TblSetRowSelectable(tableP, i, false); } /* Make sure the columns are usable - so they draw */ TblSetColumnUsable(tableP, ABBREVCOL, true); TblSetColumnUsable(tableP, DEFFNCOL, true); TblHasScrollBar(tableP, true); /* Set our custom table item draw callback */ TblSetCustomDrawProcedure(tableP, ABBREVCOL, AbbrevTableDrawItem); TblSetCustomDrawProcedure(tableP, DEFFNCOL, AbbrevTableDrawItem); } /* Populates and draw abbrevForm table * Update : false if this is the first call, true for a refresh (scrolling...) */ void LoadAbbrevTable(FormPtr pForm, Boolean Update) { TablePtr tableP; Int16 i=0, oldscrollvalue=0; UInt16 numRows=0; tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,abbrevFrmTable)); numRows = TblGetNumberOfRows(tableP); oldscrollvalue = ScrollAbbrevValue; /* avoid scrolling too much */ if ((numabbrev - ScrollAbbrevValue) < numRows) { if (numabbrev > numRows) { ScrollAbbrevValue = numabbrev-numRows; } else { ScrollAbbrevValue = 0; } } for (i=0; i<numRows; i++) { if ((i+ScrollAbbrevValue)<numabbrev) { TblSetItemInt(tableP, i, ABBREVCOL, i+ScrollAbbrevValue); TblSetItemInt(tableP, i, DEFFNCOL, i+ScrollAbbrevValue); TblSetRowUsable(tableP, i, true); } else { TblSetRowUsable(tableP, i, false); } } SclSetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, abbrevFrmTableScrollBar)), ScrollAbbrevValue, /* current value */ 0, /* min */ numabbrev > numRows ? numabbrev-numRows : 0, /*max*/ numRows-1 ); /* page size */ TblEraseTable(tableP); TblDrawTable(tableP); } |