-- initially building the calendar form on screen and registering the different button procedures
DIRECTORY
BasicTime USING [ Unpack, GMT, Unpacked, Update, nullGMT],
Buttons USING [ Button],
Calendar USING [ Date, Years, Months, Days, Weekdays],
CalForm USING [ RepetitionDescriptor, ColWidth, CharWidth, RowHeight, FormWidth, FormHeight, YearTable, MonthTable, DayTable, Row1, Row234, Row5, Row6, Row7, MenuTable, CalForm, CurSelection, YearSelection, MonthSelection, DaySelection, ChangeRepetitionSelection, ChangeGroupSelection, ScrollGroupMenu, calForm, curSelection],
CalStorage USING [ protData],
CalSupport USING [ GetMonthInfo, GetMonthName, CreateTextViewer, CreateButton, M2I, I2R, I2M, GetRowCol],
Containers USING [ Container, Create],
Hickory USING [ RepetitionType, ListGroups, GroupSet, EventTuple, ProtectionType],
IO USING [ PutFR, int],
Labels USING [ Set, Label],
Menus USING [ MenuProc, MouseButton],
Rope USING [ ROPE, Concat],
RopeSets USING [ RopeSetEl, IsSetEmpty, IsValueInSet],
Tempus USING [ MakeRope],
ViewerClasses USING [ Viewer, ViewerRec],
ViewerOps USING [ PaintViewer],
ViewerTools USING [ SetSelection],
VTables USING [ VTable, Create, SetTableEntry, Install, Border, GetTableEntry]
;
Creating the calendar form on the screen
CreateCalFormCont:
PUBLIC INTERNAL
PROCEDURE [ myParent: ViewerClasses.Viewer, ev:
REF Hickory.EventTuple] =
BEGIN
here we build the contents of the calViewer, while in Enter or Query mode. This is
rather lengthy...
view: ViewerClasses.ViewerRec;
BEGIN
OPEN view;
ww ← FormWidth;
wh ← FormHeight;
scrollable ← FALSE;
iconic ← FALSE;
border ← TRUE;
parent ← myParent; -- calViewer...
END; -- OPEN
calForm.container ← Containers.Create[ view, FALSE];
CreateRow1[ curSelection.date];
CreateRow2[ ev];
CreateRow3[ ev];
CreateRow4[ ev];
CreateRow5[ curSelection.repetition];
CreateRow6[ curSelection.groups];
CreateRow7[ ev];
CreateRow8[ curSelection.protection, curSelection.reminder];
ViewerOps.PaintViewer[ calViewer, all];
END; -- CreateCalFormCont
CreateRow1:
INTERNAL
PROCEDURE [ date: Date] =
BEGIN
create the three tables in first row
CreateYearTable[ date.Year];
CreateMonthTable[ date.Month];
CreateDayTable[ date];
END; -- CreateRow1
CreateYearTable:
INTERNAL
PROCEDURE [ y: Years] =
BEGIN
OPEN calForm.row1.yearTable;
table ← VTables.Create[ rows: rows, columns: cols, h: height, w: width, x: xOff, y: yOff, parent: calForm.container];
VTables.SetTableEntry[ table: table, row: 0, column: 0, flavor: $Label, name: " Year ", useMaxSize: TRUE];
VTables.Install[ table, FALSE];
FOR i:
INT
IN [ 1..rows)
DO
yy: Years ← y - ( rows-1)/2 + i;
yr: Rope.ROPE ← IO.PutFR[ " %4g ", IO.int[ yy]];
buttons[ i] ← CalSupport.CreateButton[ title: yr, myParent: table, hi: height/rows-2, wi: width/cols-2, proc: YearSelect, clientData: NEW[ Years ← yy], displayStyle: IF yy = y THEN $BlackOnGrey ELSE $BlackOnWhite];
VTables.SetTableEntry[ table: table, row: i, column: 0, flavor: $Viewer, clientData: buttons[ i]];
VTables.Install[ table, FALSE];
ENDLOOP;
CreateMonthTable:
INTERNAL
PROCEDURE [ m: Months] =
BEGIN
OPEN calForm.row1.monthTable;
table ← VTables.Create[ rows: rows, columns: cols, h: height, w: width, x: xOff, y: yOff, parent: calForm.container];
VTables.SetTableEntry[ table: table, row: 0, column: 0, flavor: $Label, name: " Month", w: table.cw/rows];
VTables.Install[ table, FALSE];
FOR i: Months
IN [ January..December]
DO
row: INT ← CalSupport.M2I[ i] + 1; -- 1..12
mr: Rope.ROPE ← CalSupport.GetMonthName[ i];
mr ← Rope.Concat[ " ", mr];
buttons[ row] ← CalSupport.CreateButton[ title: mr, myParent: table, hi: height/rows-2, wi: width/cols-2, proc: MonthSelect, clientData: NEW[ INT ← row-1], displayStyle: IF i = m THEN $BlackOnGrey ELSE $BlackOnWhite];
VTables.SetTableEntry[ table: table, row: row, column: 0, flavor: $Viewer, clientData: buttons[ row]];
VTables.Install[ table, FALSE];
ENDLOOP;
END; -- CreateMonthTable
CreateDayTable:
INTERNAL
PROCEDURE [ date: Date] =
BEGIN
OPEN calForm.row1.dayTable;
table ← VTables.Create[ rows: rows, columns: cols, h: height, w: width, x: xOff, y: yOff, parent: calForm.container];
TitleDayTable[ table];
FillDayTable[ table, date];
VTables.Install[ table, FALSE];
TitleDayTable:
INTERNAL
PROCEDURE [ table: VTables.VTable] =
BEGIN
fill row 0 with labels..
OPEN calForm.row1.dayTable;
FOR d: Weekdays
IN [ Monday..Sunday]
DO
dr: Rope.ROPE; col: INT;
SELECT d
FROM
Sunday => { dr ← " Sun"; col ← 0;};
Monday => { dr ← " Mon"; col ← 1;};
Tuesday => { dr ← " Tue"; col ← 2;};
Wednesday => { dr ← " Wed"; col ← 3;};
Thursday => { dr ← " Thu"; col ← 4;};
Friday => { dr ← " Fri"; col ← 5;};
Saturday => { dr ← " Sat"; col ← 6;};
ENDCASE;
VTables.SetTableEntry[ table: table, row: 0, column: col, name: dr, flavor: $Label, useMaxSize: TRUE];
VTables.Install[ table, FALSE];
ENDLOOP;
END; -- TitleDayTable
FillDayTable:
PUBLIC
INTERNAL
PROCEDURE [ table: VTables.VTable, date: Date] =
BEGIN
to fill the rest of day table i.e. rows 1..6, is funct. of year, month..
OPEN calForm.row1.dayTable;
row, col: CARDINAL;
firstDay: Weekdays;
nbrOfDays: Days;
[ nbrOfDays, firstDay] ← CalSupport.GetMonthInfo[ date.Month, date.Year];
erase first and last rows in day table
FOR c:
INT
IN [ 0..cols)
DO
VTables.SetTableEntry[ table: table, row: 1, column: c, useMaxSize: TRUE, name: "", flavor: $Label];
VTables.SetTableEntry[ table: table, row: rows-1, column: c, useMaxSize: TRUE, name: "", flavor: $Label];
VTables.SetTableEntry[ table: table, row: rows-2, column: c, useMaxSize: TRUE, name: "", flavor: $Label];
ENDLOOP;
VTables.Install[ table, FALSE];
FOR d: Days
IN [1..nbrOfDays]
DO
i: INT ← d;
dispStyle: ATOM;
IF d = date.Day THEN dispStyle ← $BlackOnGrey
ELSE dispStyle ← $BlackOnWhite;
[ row, col] ← CalSupport.GetRowCol[ d, firstDay];
buttons[ row] [col] ← CalSupport.CreateButton[ title: IO.PutFR[ " %02g", IO.int[ i]], myParent: table, wi: width/cols-2, hi: height/rows-2, displayStyle: dispStyle, clientData: NEW[ INT ← i], proc: DaySelect];
VTables.SetTableEntry[ table: table, row: row+1, column: col, flavor: $Viewer, clientData: buttons[ row][ col]];
VTables.Install[ table, FALSE];
ENDLOOP;
END; -- FillDayTable
CreateRow2:
INTERNAL
PROCEDURE [ ev: REF Hickory.EventTuple] =
BEGIN
second row: event start and end times specification
OPEN calForm.row2;
table ← VTables.Create[ columns: cols, rows: rows, w: width, h: height, parent: calForm.container, x: xOff, y: yOff];
IF ev = NIL THEN txtViewer ← FillRow234Tables[ 2, " Times", 7, table]
ELSE txtViewer ← FillRow234Tables[ 2, " Times", 7, table, ExtractTimeSpec[ ev.EventTime, ev.Duration]];
END; -- CreateRow2
CreateRow3:
INTERNAL
PROCEDURE [ ev: REF Hickory.EventTuple] =
BEGIN
third row: event reminder text
OPEN calForm.row3;
table ← VTables.Create[ columns: cols, rows: rows, w: width, h: height, parent: calForm.container, x: xOff, y: yOff];
IF ev = NIL THEN txtViewer ← FillRow234Tables[ 3, " Text", 6, table]
ELSE txtViewer ← FillRow234Tables[ 3, " Text", 6, table, ev.Text];
END; -- CreateRow3
CreateRow4:
INTERNAL
PROCEDURE [ ev: REF Hickory.EventTuple] =
BEGIN
fourth row: event place
OPEN calForm.row4;
table ← VTables.Create[ columns: cols, rows: rows, w: width, h: height, parent: calForm.container, x: xOff, y: yOff];
IF ev = NIL THEN txtViewer ← FillRow234Tables[ 4, " Place", 7, table]
ELSE txtViewer ← FillRow234Tables[ 4, " Place", 7, table, ev.Place];
END; -- CreateRow4
FillRow234Tables:
INTERNAL
PROCEDURE [ index: [2..4], label: Rope.
ROPE, nbrOfChar:
INT, parentTable: VTables.VTable, txtCont: Rope.ROPE ← NIL]
RETURNS [ txtViewer: ViewerClasses.Viewer] =
BEGIN
fill the rows 2, 3, 4 with a label and a text viewer, return the latter
VTables.SetTableEntry[ table: parentTable, row: 0, column: 0, name: label, flavor: $Button, w: nbrOfChar*CharWidth, border: [ TRUE, TRUE, FALSE, FALSE], proc: RowButtProc, clientData: NEW[ INT ← index]];
VTables.Install[ parentTable, FALSE];
txtViewer ← CalSupport.CreateTextViewer[ parentTable, parentTable.cw-nbrOfChar*CharWidth, parentTable.ch, txtCont];
VTables.SetTableEntry[ table: parentTable, row: 0, column: 1, name: NIL, flavor: $Viewer, clientData: txtViewer, border: [ TRUE, TRUE, FALSE, TRUE]];
VTables.Install[ parentTable, FALSE];
RETURN[ txtViewer];
END; -- FillRow234Tables
CreateRow5:
INTERNAL
PROCEDURE [ rep: RepetitionDescriptor] =
BEGIN
fifth row: repetition specification
OPEN calForm.row5;
table ← VTables.Create[ columns: cols, rows: rows, x: xOff, y: yOff, w: width, h: height, parent: calForm.container];
VTables.SetTableEntry[ table: table, row: 0, column: 0, name: " Repetition", flavor: $Button, useMaxSize: TRUE, border: [ TRUE, FALSE, FALSE, TRUE], proc: RowButtProc, clientData: NEW[ INT ← 5]];
VTables.Install[ table, FALSE];
menuTable ← CreateRepeatMenu[ myParent: table, menu: menuTable, wi: table.cw - 11*CharWidth, xOff: 11*CharWidth, rt: rep.RepeatType];
txtViewer ← CalSupport.CreateTextViewer[ table, table.cw-11*CharWidth, RowHeight, rep.RepeatTime];
VTables.SetTableEntry[ table: table, row: 0, column: 1, flavor: $Viewer, clientData: menuTable.table, w: menuTable.width, h: menuTable.height];
VTables.Install[ table, FALSE];
VTables.SetTableEntry[ table: table, row: 1, column: 1, flavor: $Viewer, clientData: txtViewer, w: txtViewer.ww, h: txtViewer.wh];
VTables.Install[ table, FALSE];
END; -- CreateRow5
GetBorder:
INTERNAL
PROCEDURE [ index, cols:
INT]
RETURNS [ border: VTables.Border] =
INLINE
BEGIN
noRightBorder: VTables.Border ← [ FALSE, FALSE, TRUE, FALSE];
noLeftBorder: VTables.Border ← [ FALSE, FALSE, FALSE, TRUE];
IF index = 0 THEN RETURN[ noLeftBorder]
ELSE IF index = cols-1 THEN RETURN[ noRightBorder]
ELSE RETURN[ [ FALSE, FALSE, TRUE, TRUE]];
END; -- GetBorder
CreateRepeatMenu:
INTERNAL
PROCEDURE [ myParent: VTables.VTable, menu: MenuTable, wi, xOff:
CARDINAL, rt: Hickory.RepetitionType]
RETURNS [ updateMenu: MenuTable] =
BEGIN
to create menu table for repetition types
OPEN menu;
dispStyle: ATOM;
width ← wi;
table ← VTables.Create[ columns: cols, rows: rows, parent: myParent, w: width, h: height, y: 0, x: xOff];
FOR r: Hickory.RepetitionType
IN [ Hourly..Yearly]
DO
rr: Rope.ROPE; col: INT;
SELECT r
FROM
Hourly => { rr ← " Hourly"; col ← 0};
Daily => { rr ← " Daily"; col ← 1};
Weekdays => { rr ← " Weekdays"; col ← 2};
Weekly => { rr ← " Weekly"; col ← 3};
Monthly => { rr ← " Monthly"; col ← 4};
Yearly => { rr ← " Yearly"; col ← 5};
ENDCASE;
IF r = rt THEN dispStyle ← $BlackOnGrey ELSE dispStyle ← $BlackOnWhite;
buttons[ col] ← CalSupport.CreateButton[ myParent: table, title: rr, hi: height/rows-2, wi: width/cols-2, proc: SelectRepetition, clientData: NEW[ INT ← col+1], displayStyle: dispStyle];
VTables.SetTableEntry[ table: table, row: 0, column: col, flavor: $Viewer, clientData: buttons[ col], border: GetBorder[ col, cols]];
VTables.Install[ table, FALSE];
ENDLOOP;
RETURN[ menu];
END; -- CreateRepeatMenu
CreateRow6:
INTERNAL
PROCEDURE [ groups: Hickory.GroupSet] =
BEGIN
sixth row: group specification
OPEN calForm.row6;
table ← VTables.Create[ columns: cols, rows: rows, x: xOff, y: yOff, w: width, h: height, parent: calForm.container];
VTables.SetTableEntry[ table: table, row: 0, column: 0, name: " Groups", flavor: $Button, w: 7*CharWidth, useMaxSize: TRUE, border: [ TRUE, FALSE, FALSE, TRUE], proc: RowButtProc, clientData: NEW[ INT ← 6]];
VTables.Install[ table, FALSE];
menuTable ← CreateGroupMenu[ table, menuTable, table.cw-7*CharWidth, 7*CharWidth, groups];
txtViewer ← CalSupport.CreateTextViewer[ table, table.cw-ColWidth, RowHeight];
VTables.SetTableEntry[ table: table, row: 0, column: 1, flavor: $Viewer, clientData: menuTable.table, w: menuTable.width, h: menuTable.height];
VTables.Install[ table, FALSE];
VTables.SetTableEntry[ table: table, row: 1, column: 1, flavor: $Viewer, clientData: txtViewer, w: txtViewer.ww, h: txtViewer.wh];
VTables.Install[ table, FALSE];
END; -- CreateRow6
CreateGroupMenu:
INTERNAL
PROCEDURE [ myParent: VTables.VTable, menu: MenuTable, wi, xOff:
CARDINAL, evGroups: Hickory.GroupSet ← [
NIL,
NIL]]
RETURNS [ updatedMenu: MenuTable] =
BEGIN
to create the group menu in row 6. evGroups: groups in which the inital event participates
OPEN menu;
groups: Hickory.GroupSet ← [ NIL, NIL];
cur: REF RopeSets.RopeSetEl ← NIL;
dispStyle: ATOM;
groups ← GetHickoryGroups[]; -- all the groups of hickory
cur ← groups.Head;
width ← wi;
table ← VTables.Create[ columns: cols, rows: rows, parent: myParent, w: width, h: height, y: 0, x: xOff];
FOR i:
INT
IN [ 0..cols)
DO
IF cur #
NIL
THEN
BEGIN
IF RopeSets.IsValueInSet[ cur.Value, evGroups] THEN dispStyle ← $BlackOnGrey
ELSE dispStyle ← $BlackOnWhite;
buttons[ i] ← CalSupport.CreateButton[ myParent: table, title: cur.Value, hi: height/rows-2, wi: width/cols-2, proc: SelectGroup, clientData: NEW[ INT ← i], displayStyle: dispStyle];
cur ← cur.Next
END
ELSE
buttons[ i] ← CalSupport.CreateButton[ myParent: table, title: " ", hi: height/rows-2, wi: width/cols-2, proc: SelectGroup, clientData: NEW[ INT ← i], displayStyle: $BlackOnWhite];
VTables.SetTableEntry[ table: table, row: 0, column: i, flavor: $Viewer, clientData: buttons[ i], border: GetBorder[ i, cols]];
VTables.Install[ table, FALSE];
ENDLOOP;
RETURN[ menu];
END; -- CreateGroupMenu
GetHickoryGroups:
INTERNAL
PROCEDURE
RETURNS [ groupSet: Hickory.GroupSet] =
BEGIN
to get a list of groups from hickory if necessary and register those in row6!
OPEN calForm.row6;
IF RopeSets.IsSetEmpty[ groups]
THEN
BEGIN
groups ← Hickory.ListGroups[];
groupHead ← groups.Head;
END;
RETURN[ groups];
CreateRow7:
INTERNAL
PROCEDURE [ ev:
REF Hickory.EventTuple] =
BEGIN
seventh row: repeat until and keep until specs...
OPEN calForm.row7;
txtViewer: ViewerClasses.Viewer;
table ← VTables.Create[ columns: cols, rows: rows, x: xOff, y: yOff, parent: calForm.container];
VTables.SetTableEntry[ table: table, row: 0, column: 0, name: " RepeatUntil", flavor: $Button, border: [ TRUE, TRUE, FALSE, FALSE], proc: RowButtProc, clientData: NEW[ INT ← 71]];
VTables.Install[ table, FALSE];
IF ev = NIL THEN txtViewer ← CalSupport.CreateTextViewer[ table, 2*ColWidth, height]
ELSE
IF ev.RepeatUntil # BasicTime.nullGMT
THEN
txtViewer ← CalSupport.CreateTextViewer[ table, 2*ColWidth, height, Tempus.MakeRope[ ev.RepeatUntil]]
ELSE txtViewer ← CalSupport.CreateTextViewer[ table, 2*ColWidth, height];
txtViewers[ 1] ← txtViewer;
VTables.SetTableEntry[ table: table, row: 0, column: 1, flavor: $Viewer, clientData: txtViewer, border: [ TRUE, TRUE, FALSE, TRUE]];
VTables.Install[ table, FALSE];
VTables.SetTableEntry[ table: table, row: 0, column: 2, name: " KeepUntil", flavor: $Button, border: [ TRUE, TRUE, FALSE, FALSE], proc: RowButtProc, clientData: NEW[ INT ← 72]];
VTables.Install[ table, FALSE];
IF ev = NIL THEN txtViewer ← CalSupport.CreateTextViewer[ table, 2*ColWidth, height]
ELSE
IF ev.KeepUntil # BasicTime.nullGMT
THEN
txtViewer ← CalSupport.CreateTextViewer[ table, 2*ColWidth, height, Tempus.MakeRope[ ev.KeepUntil]]
ELSE txtViewer ← CalSupport.CreateTextViewer[ table, 2*ColWidth, height];
txtViewers[ 2] ← txtViewer;
VTables.SetTableEntry[ table: table, row: 0, column: 3, flavor: $Viewer, clientData: txtViewer, border: [ TRUE, TRUE, FALSE, TRUE]];
VTables.Install[ table, FALSE];
END; -- CreateRow7
CreateRow8:
INTERNAL
PROCEDURE [ prot: Hickory.ProtectionType, rem:
BOOLEAN] =
BEGIN
eigth row: set of button for Protection, Reminder
OPEN calForm.row8;
table ← VTables.Create[ columns: cols, rows: rows, x: xOff, y: yOff, parent: calForm.container, w: width, h: height];
VTables.SetTableEntry[ table: table, row: 0, column: 0, name: " Protection", flavor: $Button, border: [ TRUE, TRUE, TRUE, FALSE], proc: RowButtProc, clientData: NEW[ INT ← 81]];
VTables.Install[ table, FALSE];
IF prot = Private
THEN
VTables.SetTableEntry[ table: table, row: 0, column: 1, name: " Private", flavor: $Label, border: [ TRUE, TRUE, FALSE, TRUE]]
ELSE VTables.SetTableEntry[ table: table, row: 0, column: 1, name: " Public", flavor: $Label, border: [ TRUE, TRUE, FALSE, FALSE]];
VTables.Install[ table, FALSE];
VTables.SetTableEntry[ table: table, row: 0, column: 2, name: " Reminder", flavor: $Button, border: [ TRUE, TRUE, TRUE, FALSE], proc: RowButtProc, clientData: NEW[ INT ← 82]];
VTables.Install[ table, FALSE];
IF rem
THEN
VTables.SetTableEntry[ table: table, row: 0, column: 3, name: " Yes", flavor: $Label, border: [ TRUE, TRUE, FALSE, TRUE]]
ELSE VTables.SetTableEntry[ table: table, row: 0, column: 3, name: " No", flavor: $Label, border: [ TRUE, TRUE, FALSE, TRUE]];
VTables.Install[ table, FALSE];
END; -- CreateRow8
Initially
BEGIN
OPEN calForm;
BEGIN
OPEN row1;
height ← 13*RowHeight; width ← FormWidth;
yOff ← 0; xOff ← 0;
BEGIN
OPEN yearTable;
rows ← 7; cols ← 1;
height ← rows*RowHeight; width ← 6*CharWidth;
xOff ← 20;
yOff ← 20;
END; -- yearTable
BEGIN
OPEN monthTable;
rows ← 13; cols ← 1;
height ← rows*RowHeight; width ← 9*CharWidth;
xOff ← 20 + 6*CharWidth + 20; yOff ← 2;
END; -- monthTable
BEGIN
OPEN dayTable;
rows ← 7; cols ← 7;
height ← rows*RowHeight; width ← 35*CharWidth;
xOff ← 20 + 6*CharWidth + 20 + 9*CharWidth + 20;
yOff ← 20;
END; -- dayTable
END; -- row1
BEGIN
OPEN row2;
rows ← 1; cols ← 2;
height ← rows*RowHeight; width ← FormWidth;
xOff ← 0; yOff ← row1.height + row1.yOff;
END; -- row2
BEGIN
OPEN row3;
rows ← 1; cols ← 2;
height ← rows*RowHeight; width ← FormWidth;
xOff ← 0; yOff ← row2.height + row2.yOff;
END; -- row3
BEGIN
OPEN row4;
rows ← 1; cols ← 2;
height ← rows*RowHeight; width ← FormWidth;
xOff ← 0; yOff ← row3.height + row3.yOff;
END; -- row4
BEGIN
OPEN row5;
rows ← 2; cols ← 2;
height ← rows*RowHeight; width ← FormWidth;
xOff ← 0; yOff ← row4.height + row4.yOff;
BEGIN
OPEN menuTable;
rows ← 1; cols ← 6;
height ← rows*RowHeight; width ← 0; -- set dynamically
END; -- menuTable
END; -- row5
BEGIN
OPEN row6;
groupHead ← NIL; groups.Head ← NIL; groups.Tail ← NIL;
rows ← 2; cols ← 2;
height ← rows*RowHeight; width ← FormWidth;
xOff ← 0; yOff ← row5.height + row5.yOff;
BEGIN
OPEN menuTable;
rows ← 1; cols ← 6;
height ← rows*RowHeight; width ← 0; -- set dynamically
END; -- menuTable
END; -- row6
BEGIN
OPEN row7;
rows ← 1; cols ← 4;
height ← rows*RowHeight; width ← FormWidth;
xOff ← 0; yOff ← row6.height + row6.yOff;
END; -- row7
BEGIN
OPEN row8;
rows ← 1; cols ← 4;
height ← rows*RowHeight; width ← cols*(FormWidth/8);
xOff ← 20 + 6*CharWidth + 20 + 9*CharWidth + 20;
yOff ← row1.dayTable.height + row1.dayTable.yOff + 20;
END; -- row8
END; -- OPEN calForm
END.