summaryrefslogtreecommitdiff
path: root/examples/gui/calendar
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-03-25 23:35:11 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-03-25 23:35:11 +0000
commit1b038fd4d4700347b001e1651cd0dbd8998a4509 (patch)
tree1a270d81593ffa6aab468aaaf44b5dd8a10cee14 /examples/gui/calendar
parente85577cc7d0688a02cf4cc8098405583966add70 (diff)
downloadfpGUI-1b038fd4d4700347b001e1651cd0dbd8998a4509.tar.xz
* Calendar demo project has been modified to draw a Calendar to the console window. This is a prototype to implemente Starting Day Of Week for our actual calendar component.
Diffstat (limited to 'examples/gui/calendar')
-rw-r--r--examples/gui/calendar/calendartest.lpr81
1 files changed, 74 insertions, 7 deletions
diff --git a/examples/gui/calendar/calendartest.lpr b/examples/gui/calendar/calendartest.lpr
index 9783e0e8..a38e3727 100644
--- a/examples/gui/calendar/calendartest.lpr
+++ b/examples/gui/calendar/calendartest.lpr
@@ -11,7 +11,7 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, gfxbase, fpgfx, gui_form, gui_popupcalendar, gui_edit,
- gui_button, gui_label, gfx_popupwindow, gui_combobox, gui_checkbox;
+ gui_button, gui_label, gfx_popupwindow, gui_combobox, gui_checkbox, dateutils;
type
TMainForm = class(TfpgForm)
@@ -23,6 +23,7 @@ type
procedure btnMaxDateClicked(Sender: TObject);
procedure DoDropDown;
procedure cbCloseOnSelectChanged(Sender: TObject);
+ procedure DrawCalendar(month, year: integer);
public
{@VFD_HEAD_BEGIN: MainForm}
edtName1: TfpgEdit;
@@ -57,6 +58,68 @@ begin
cal.CloseOnSelect := TfpgCheckBox(Sender).Checked;
end;
+type
+ TStartDay = (wdSun, wdMon, wdTue, wdWed, wdThu, wdFri, wdSat);
+
+procedure TMainForm.DrawCalendar(month, year: integer);
+var
+ weekstartday: TStartDay;
+ i: integer;
+ dayIndex: Byte;
+ startingPos: integer;
+ days: integer;
+ currentDay: integer;
+ s: string;
+begin
+ weekstartday := wdMon; // 0=Sun, 1=Mon, 2=Tue etc.
+ weekstartday := TStartDay(Ord(cbName1.FocusItem-1));
+
+ // Month and year
+ writeln('');
+ writeln(LongMonthNames[month], ' ', year);
+
+ // draw day-of-week header
+ for i := Ord(weekstartday) to Ord(weekstartday)+6 do
+ begin
+ if (i < 7) then
+ dayIndex := i
+ else
+ dayIndex := i - 7;
+
+ write(ShortDayNames[dayIndex+1] + ' ');
+ end;
+ writeln('');
+
+ startingPos := DayOfTheWeek(EncodeDate(year, month, 1)-Ord(weekstartday))-1;
+ days := DaysInAMonth(year, month);
+// writeln('startingpos:', startingPos, ' days:', days);
+
+ // draw blanks before first of month
+ if not (startingPos = 6) then
+ for i := 0 to startingPos do
+ write(' ');
+
+ // draw days of month
+ currentDay := 1;
+ i := startingPos;
+ //for i := startingPos to days do
+ while currentDay <= days do
+ begin
+ i := i + 1;
+ if ((i mod 7) = 0) and (currentDay <> 1) then
+ writeln('');
+ if currentDay <= 9 then
+ s := ' '
+ else
+ s := '';
+ write(currentDay, ' ' + s);
+ currentDay := currentDay + 1;
+ end;
+
+ writeln('');
+ writeln('-----');
+end;
+
procedure TMainForm.btnDownClicked(Sender: TObject);
begin
DoDropDown;
@@ -89,6 +152,7 @@ procedure TMainForm.btnMaxDateClicked(Sender: TObject);
var
old: string;
begin
+{
old := ShortDateFormat;
ShortDateFormat := 'yyyy-mm-dd';
try
@@ -96,6 +160,8 @@ begin
finally
ShortDateFormat := old;
end;
+ }
+ DrawCalendar(StrToInt(edtMaxDate.Text), 2008);
end;
procedure TMainForm.DoDropDown;
@@ -168,12 +234,13 @@ begin
Name := 'cbName1';
SetPosition(132, 144, 120, 23);
FontDesc := '#List';
- Items.Add('line1');
- Items.Add('line2');
- Items.Add('line3');
- Items.Add('line4');
- Items.Add('line5');
- Items.Add('line6');
+ Items.Add('Sun');
+ Items.Add('Mon');
+ Items.Add('Tue');
+ Items.Add('Wed');
+ Items.Add('Thu');
+ Items.Add('Fri');
+ Items.Add('Sat');
TabOrder := 4;
end;