diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-17 08:46:12 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-17 08:46:12 +0000 |
commit | 482f9a1521471b8386fdaa8b6f2f59dab5a9a1de (patch) | |
tree | 2f3b891801abc7733a60fceb1b6ce34c31898f83 | |
parent | 15a63a5f5f65ab65ccd21c8c69e51c259b371d6b (diff) | |
download | fpGUI-482f9a1521471b8386fdaa8b6f2f59dab5a9a1de.tar.xz |
* Applied patch form Antonio added Today button in CalendarCombo component.
* Added new resource strings for days of the week and months of the year.
* fpGUI based applications now set the internal Day and Month arrays from FPC to the correct locale. CalendarCombo now displays the days and months in the correct language.
* UI Designer failed to save a form that has a CalendarCombo on it. This is now fixed.
-rw-r--r-- | examples/apps/uidesigner/vfdmain.pas | 5 | ||||
-rw-r--r-- | examples/gui/calendar/calendartest.lpr | 53 | ||||
-rw-r--r-- | src/corelib/fpgfx.pas | 54 | ||||
-rw-r--r-- | src/corelib/lang_afrikaans.inc | 51 | ||||
-rw-r--r-- | src/corelib/lang_english.inc | 27 | ||||
-rw-r--r-- | src/corelib/lang_french.inc | 25 | ||||
-rw-r--r-- | src/corelib/lang_german.inc | 25 | ||||
-rw-r--r-- | src/corelib/lang_italian.inc | 26 | ||||
-rw-r--r-- | src/corelib/lang_portuguese.inc | 25 | ||||
-rw-r--r-- | src/corelib/lang_russian.inc | 25 | ||||
-rw-r--r-- | src/corelib/lang_spanish.inc | 25 | ||||
-rw-r--r-- | src/gui/gui_popupcalendar.pas | 109 |
12 files changed, 398 insertions, 52 deletions
diff --git a/examples/apps/uidesigner/vfdmain.pas b/examples/apps/uidesigner/vfdmain.pas index 6c1e8a6f..afdab0fe 100644 --- a/examples/apps/uidesigner/vfdmain.pas +++ b/examples/apps/uidesigner/vfdmain.pas @@ -82,7 +82,8 @@ implementation uses vfdformparser, - gui_iniutils; + gui_iniutils, + gfx_utils; { TMainDesigner } @@ -191,7 +192,7 @@ begin EditedFileName := fname; - if FileExists(fname) then + if fpgFileExists(fname) then begin FFile.LoadFile(fname); FFile.GetBlocks; diff --git a/examples/gui/calendar/calendartest.lpr b/examples/gui/calendar/calendartest.lpr index 264fac9e..9783e0e8 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_button, gui_label, gfx_popupwindow, gui_combobox, gui_checkbox; type TMainForm = class(TfpgForm) @@ -22,6 +22,7 @@ type procedure btnMinDateClicked(Sender: TObject); procedure btnMaxDateClicked(Sender: TObject); procedure DoDropDown; + procedure cbCloseOnSelectChanged(Sender: TObject); public {@VFD_HEAD_BEGIN: MainForm} edtName1: TfpgEdit; @@ -41,6 +42,7 @@ type edtMaxDate: TfpgEdit; btnMinDate: TfpgButton; btnMaxDate: TfpgButton; + cbCloseOnSelect: TfpgCheckBox; {@VFD_HEAD_END: MainForm} FDropDown: TfpgPopupCalendar; procedure AfterCreate; override; @@ -50,6 +52,11 @@ type { TMainForm } +procedure TMainForm.cbCloseOnSelectChanged(Sender: TObject); +begin + cal.CloseOnSelect := TfpgCheckBox(Sender).Checked; +end; + procedure TMainForm.btnDownClicked(Sender: TObject); begin DoDropDown; @@ -132,6 +139,7 @@ begin Text := ''; FontDesc := '#Label1'; ImageName := 'sys.sb.down'; + TabOrder := 1; OnClick := @btnDownClicked; end; @@ -140,17 +148,17 @@ begin begin Name := 'lblName1'; SetPosition(16, 32, 80, 16); - Text := 'Enter a date:'; FontDesc := '#Label1'; + Text := 'Enter a date:'; end; lblName2 := TfpgLabel.Create(self); with lblName2 do begin Name := 'lblName2'; - SetPosition(68, 100, 276, 16); - Text := '***** This still needs some testing *****'; + SetPosition(16, 100, 276, 16); FontDesc := '#Label2'; + Text := '***** This still needs some testing *****'; TextColor := clRed; end; @@ -159,13 +167,14 @@ begin 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'); - FontDesc := '#List'; + TabOrder := 4; end; cal := TfpgCalendarCombo.Create(self); @@ -174,6 +183,7 @@ begin Name := 'cal'; SetPosition(132, 196, 120, 23); FontDesc := '#List'; + TabOrder := 5; DateFormat := 'yyyy-mm-dd'; end; @@ -185,6 +195,7 @@ begin Text := 'Set Format'; FontDesc := '#Label1'; ImageName := ''; + TabOrder := 6; OnClick := @btnDateFormatClicked; end; @@ -192,7 +203,8 @@ begin with edtDateFormat do begin Name := 'edtDateFormat'; - SetPosition(288, 148, 92, 21); + SetPosition(288, 148, 92, 22); + TabOrder := 7; Text := 'yy-mm-d'; FontDesc := '#Edit1'; end; @@ -202,8 +214,8 @@ begin begin Name := 'lblName3'; SetPosition(160, 48, 287, 15); - Text := '<---- This one is fake. It only used the'; FontDesc := '#Label1'; + Text := '<---- This one is fake. It only used the'; TextColor := clBlue; end; @@ -212,8 +224,8 @@ begin begin Name := 'lblName4'; SetPosition(12, 148, 96, 15); - Text := 'Normal Combo:'; FontDesc := '#Label1'; + Text := 'Normal Combo:'; end; lblName5 := TfpgLabel.Create(self); @@ -221,8 +233,8 @@ begin begin Name := 'lblName5'; SetPosition(12, 200, 104, 15); - Text := 'Calendar Combo:'; FontDesc := '#Label1'; + Text := 'Calendar Combo:'; end; btnToday := TfpgButton.Create(self); @@ -233,6 +245,7 @@ begin Text := 'Today'; FontDesc := '#Label1'; ImageName := ''; + TabOrder := 11; OnClick := @btnTodayClicked; end; @@ -241,15 +254,16 @@ begin begin Name := 'lblName6'; SetPosition(192, 63, 246, 16); - Text := 'calendar window part.'; FontDesc := '#Label1'; + Text := 'calendar window part.'; end; edtMinDate := TfpgEdit.Create(self); with edtMinDate do begin Name := 'edtMinDate'; - SetPosition(288, 176, 92, 21); + SetPosition(288, 176, 92, 22); + TabOrder := 13; Text := '2005-01-01'; FontDesc := '#Edit1'; end; @@ -258,7 +272,8 @@ begin with edtMaxDate do begin Name := 'edtMaxDate'; - SetPosition(288, 204, 92, 21); + SetPosition(288, 204, 92, 22); + TabOrder := 14; Text := '2009-01-01'; FontDesc := '#Edit1'; end; @@ -271,6 +286,7 @@ begin Text := 'Min Date'; FontDesc := '#Label1'; ImageName := ''; + TabOrder := 15; OnClick := @btnMinDateClicked; end; @@ -282,9 +298,22 @@ begin Text := 'Max Date'; FontDesc := '#Label1'; ImageName := ''; + TabOrder := 16; OnClick := @btnMaxDateClicked; end; + cbCloseOnSelect := TfpgCheckBox.Create(self); + with cbCloseOnSelect do + begin + Name := 'cbCloseOnSelect'; + SetPosition(328, 88, 120, 20); + Checked := True; + FontDesc := '#Label1'; + TabOrder := 17; + Text := 'Close on select'; + OnChange := @cbCloseOnSelectChanged; + end; + {@VFD_BODY_END: MainForm} end; diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index 29ea9bdf..dd9a6d28 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -186,6 +186,8 @@ type { TfpgApplication } TfpgApplication = class(TfpgApplicationImpl) + private + procedure SetupLocalizationStrings; protected FDisplayParams: string; FScreenWidth: integer; @@ -323,7 +325,8 @@ uses gfx_imgfmt_bmp, gfx_stdimages, gfx_extinterpolation, // only so that it get auto compiled - gfx_translations; + gfx_translations, + gfx_constants; var fpgTimers: TList; @@ -828,6 +831,54 @@ begin RunMessageLoop; end; +procedure TfpgApplication.SetupLocalizationStrings; +begin + // setup internal FPC arrays with localized values + ShortDayNames[1] := rsShortSun; + ShortDayNames[2] := rsShortMon; + ShortDayNames[3] := rsShortTue; + ShortDayNames[4] := rsShortWed; + ShortDayNames[5] := rsShortThu; + ShortDayNames[6] := rsShortFri; + ShortDayNames[7] := rsShortSat; + + LongDayNames[1] := rsLongSun; + LongDayNames[2] := rsLongMon; + LongDayNames[3] := rsLongTue; + LongDayNames[4] := rsLongWed; + LongDayNames[5] := rsLongThu; + LongDayNames[6] := rsLongFri; + LongDayNames[7] := rsLongSat; + + ShortMonthNames[1] := rsShortJan; + ShortMonthNames[2] := rsShortFeb; + ShortMonthNames[3] := rsShortMar; + ShortMonthNames[4] := rsShortApr; + ShortMonthNames[5] := rsShortMay; + ShortMonthNames[6] := rsShortJun; + ShortMonthNames[7] := rsShortJul; + ShortMonthNames[8] := rsShortAug; + ShortMonthNames[9] := rsShortSep; + ShortMonthNames[10] := rsShortOct; + ShortMonthNames[11] := rsShortNov; + ShortMonthNames[12] := rsShortDec; + + LongMonthNames[1] := rsLongJan; + LongMonthNames[2] := rsLongFeb; + LongMonthNames[3] := rsLongMar; + LongMonthNames[4] := rsLongApr; + LongMonthNames[5] := rsLongMay; + LongMonthNames[6] := rsLongJun; + LongMonthNames[7] := rsLongJul; + LongMonthNames[8] := rsLongAug; + LongMonthNames[9] := rsLongSep; + LongMonthNames[10] := rsLongOct; + LongMonthNames[11] := rsLongNov; + LongMonthNames[12] := rsLongDec; + + +end; + procedure TfpgApplication.FreeFontRes(afontres: TfpgFontResource); var n: integer; @@ -852,6 +903,7 @@ begin // This will process Application and fpGUI Toolkit translation (*.po) files TranslateResourceStrings(ApplicationName, ExtractFilePath(ParamStr(0)), ''); + SetupLocalizationStrings; end; procedure TfpgApplication.Flush; diff --git a/src/corelib/lang_afrikaans.inc b/src/corelib/lang_afrikaans.inc index 78115662..c2161a50 100644 --- a/src/corelib/lang_afrikaans.inc +++ b/src/corelib/lang_afrikaans.inc @@ -110,20 +110,45 @@ rsErrNotAssigned = '<%s> not assigned'; // Calendar Combo & Dialog -rsShortMon = 'Mon'; -rsShortTue = 'Tue'; -rsShortWed = 'Wed'; -rsShortThu = 'Thu'; -rsShortFri = 'Fri'; +rsShortMon = 'Maa'; +rsShortTue = 'Din'; +rsShortWed = 'Woe'; +rsShortThu = 'Don'; +rsShortFri = 'Vry'; rsShortSat = 'Sat'; -rsShortSun = 'Sun'; -rsLongMon = 'Monday'; -rsLongTue = 'Tuesday'; -rsLongWed = 'Wednesday'; -rsLongThu = 'Thursday'; -rsLongFri = 'Friday'; -rsLongSat = 'Saturday'; -rsLongSun = 'Sunday'; +rsShortSun = 'Son'; +rsLongMon = 'Maandag'; +rsLongTue = 'Dinsdag'; +rsLongWed = 'Woensdag'; +rsLongThu = 'Donderdag'; +rsLongFri = 'Vrydag'; +rsLongSat = 'Saterdag'; +rsLongSun = 'Sondag'; +rsToday = 'Vandag'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'Mei'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Okt'; +rsShortNov = 'Nov'; +rsShortDec = 'Des'; +rsLongJan = 'Januarie'; +rsLongFeb = 'Februarie'; +rsLongMar = 'Maart'; +rsLongApr = 'April'; +rsLongMay = 'Mei'; +rsLongJun = 'Junie'; +rsLongJul = 'Julie'; +rsLongAug = 'Augustus'; +rsLongSep = 'September'; +rsLongOct = 'Oktober'; +rsLongNov = 'November'; +rsLongDec = 'Desember'; diff --git a/src/corelib/lang_english.inc b/src/corelib/lang_english.inc index ec2b85a7..fa1bcd91 100644 --- a/src/corelib/lang_english.inc +++ b/src/corelib/lang_english.inc @@ -100,6 +100,7 @@ rsUserName = 'User name'; rsPassword = 'Password'; rsDatabase = 'Database'; + // Error messages rsErrListMustBeEmpty = 'List must be empty'; rsErrCouldNotOpenDir = 'Could not open the directory <%s>'; @@ -123,6 +124,30 @@ rsLongThu = 'Thursday'; rsLongFri = 'Friday'; rsLongSat = 'Saturday'; rsLongSun = 'Sunday'; - +rsToday = 'Today'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/corelib/lang_french.inc b/src/corelib/lang_french.inc index 385a2271..a6cb7986 100644 --- a/src/corelib/lang_french.inc +++ b/src/corelib/lang_french.inc @@ -124,6 +124,31 @@ rsLongThu = 'Jeudi'; rsLongFri = 'Vendredi'; rsLongSat = 'Samedi'; rsLongSun = 'Dimanche'; +rsToday = 'Today'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/corelib/lang_german.inc b/src/corelib/lang_german.inc index 45b736fc..61c82f1e 100644 --- a/src/corelib/lang_german.inc +++ b/src/corelib/lang_german.inc @@ -124,6 +124,31 @@ rsLongThu = 'Thursday'; rsLongFri = 'Friday'; rsLongSat = 'Saturday'; rsLongSun = 'Sunday'; +rsToday = 'Today'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/corelib/lang_italian.inc b/src/corelib/lang_italian.inc index e0fb8a35..13060823 100644 --- a/src/corelib/lang_italian.inc +++ b/src/corelib/lang_italian.inc @@ -100,6 +100,7 @@ rsUserName = 'Nome utente'; rsPassword = 'Password'; rsDatabase = 'Archivi'; + // Error messages rsErrListMustBeEmpty = 'Elenco deve essere vuoto'; rsErrCouldNotOpenDir = 'Impossibile aprire la cartella <%s>'; @@ -123,6 +124,31 @@ rsLongThu = 'Giovedì'; rsLongFri = 'Venerdì'; rsLongSat = 'Sabato'; rsLongSun = 'Domenica'; +rsToday = 'Oggi'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/corelib/lang_portuguese.inc b/src/corelib/lang_portuguese.inc index 9accff06..85f303c6 100644 --- a/src/corelib/lang_portuguese.inc +++ b/src/corelib/lang_portuguese.inc @@ -124,6 +124,31 @@ rsLongThu = 'Thursday'; rsLongFri = 'Friday'; rsLongSat = 'Saturday'; rsLongSun = 'Sunday'; +rsToday = 'Today'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/corelib/lang_russian.inc b/src/corelib/lang_russian.inc index 32dd7380..68245788 100644 --- a/src/corelib/lang_russian.inc +++ b/src/corelib/lang_russian.inc @@ -124,6 +124,31 @@ rsLongThu = 'Четверг'; rsLongFri = 'Пятница'; rsLongSat = 'Суббота'; rsLongSun = 'Воскресенье'; +rsToday = 'Today'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/corelib/lang_spanish.inc b/src/corelib/lang_spanish.inc index f7dbbda4..63026cfc 100644 --- a/src/corelib/lang_spanish.inc +++ b/src/corelib/lang_spanish.inc @@ -124,6 +124,31 @@ rsLongThu = 'Jueves'; rsLongFri = 'Viernes'; rsLongSat = 'Sábado'; rsLongSun = 'Domingo'; +rsToday = 'Today'; +rsShortJan = 'Jan'; +rsShortFeb = 'Feb'; +rsShortMar = 'Mar'; +rsShortApr = 'Apr'; +rsShortMay = 'May'; +rsShortJun = 'Jun'; +rsShortJul = 'Jul'; +rsShortAug = 'Aug'; +rsShortSep = 'Sep'; +rsShortOct = 'Oct'; +rsShortNov = 'Nov'; +rsShortDec = 'Dec'; +rsLongJan = 'January'; +rsLongFeb = 'February'; +rsLongMar = 'March'; +rsLongApr = 'April'; +rsLongMay = 'May'; +rsLongJun = 'June'; +rsLongJul = 'July'; +rsLongAug = 'August'; +rsLongSep = 'September'; +rsLongOct = 'October'; +rsLongNov = 'November'; +rsLongDec = 'December'; diff --git a/src/gui/gui_popupcalendar.pas b/src/gui/gui_popupcalendar.pas index cf70b2be..d2129ce8 100644 --- a/src/gui/gui_popupcalendar.pas +++ b/src/gui/gui_popupcalendar.pas @@ -35,7 +35,6 @@ unit gui_popupcalendar; { todo: Support custom colors. } { todo: Must be able to switch the first day of the week. } { todo: Create a TfpgDateTimeEdit component with options for Date, Time or Date & Time. } -{ todo: Create a 'Jump to Today' property for TfpgCalendarCombo. } { todo: Changing months and checking min/max limits takes into account the original date, not the selected day in the grid. It should use the selected day in grid. } @@ -55,6 +54,8 @@ type TfpgOnDateSetEvent = procedure(Sender: TObject; const ADate: TDateTime) of object; + { TfpgPopupCalendar } + TfpgPopupCalendar = class(TfpgPopupWindow) private FMonthOffset: integer; @@ -63,6 +64,7 @@ type FMinDate: TDateTime; FCallerWidget: TfpgWidget; FOnValueSet: TfpgOnDateSetEvent; + FCloseOnSelect: boolean; {@VFD_HEAD_BEGIN: fpgPopupCalendar} edtYear: TfpgEdit; btnYearUp: TfpgButton; @@ -70,6 +72,7 @@ type edtMonth: TfpgEdit; btnMonthUp: TfpgButton; btnMonthDown: TfpgButton; + btnToday: TfpgButton; grdName1: TfpgStringGrid; {@VFD_HEAD_END: fpgPopupCalendar} function GetDateElement(Index: integer): Word; @@ -80,11 +83,13 @@ type procedure SetDateValue(const AValue: TDateTime); procedure SetMaxDate(const AValue: TDateTime); procedure SetMinDate(const AValue: TDateTime); + procedure SetCloseOnSelect(const AValue: boolean); procedure UpdateCalendar; procedure btnYearUpClicked(Sender: TObject); procedure btnYearDownClicked(Sender: TObject); procedure btnMonthUpClicked(Sender: TObject); procedure btnMonthDownClicked(Sender: TObject); + procedure btnTodayClicked(Sender: TObject); procedure grdName1DoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); procedure grdName1KeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); procedure TearDown; @@ -98,6 +103,7 @@ type public constructor Create(AOwner: TComponent; AOrigFocusWin: TfpgWidget); reintroduce; procedure AfterCreate; + property CloseOnSelect: boolean read FCloseOnSelect write SetCloseOnSelect default True; property Day: Word index 1 read GetDateElement write SetDateElement; property Month: Word index 2 read GetDateElement write SetDateElement; property Year: Word index 3 read GetDateElement write SetDateElement; @@ -109,12 +115,15 @@ type end; + { TfpgCalendarCombo } + TfpgCalendarCombo = class(TfpgAbstractComboBox) private FDate: TDateTime; FDateFormat: string; FMaxDate: TDateTime; FMinDate: TDateTime; + FCloseOnSelect: boolean; procedure InternalOnValueSet(Sender: TObject; const ADate: TDateTime); procedure SetDateFormat(const AValue: string); procedure SetDateValue(const AValue: TDateTime); @@ -122,6 +131,7 @@ type procedure SetMinDate(const AValue: TDateTime); procedure SetText(const AValue: string); override; function GetText: string; override; + procedure SetCloseOnSelect(const AValue: boolean); protected function HasText: boolean; override; procedure DoDropDown; override; @@ -134,6 +144,9 @@ type property FontDesc; property MinDate: TDateTime read FMinDate write SetMinDate; property MaxDate: TDateTime read FMaxDate write SetMaxDate; + { Clicking on calendar Today button will close the popup calendar by default } + property CloseOnSelect: boolean read FCloseOnSelect write SetCloseOnSelect default True; + property TabOrder; property OnChange; end; @@ -143,7 +156,8 @@ implementation uses gui_scrollbar - ,gfx_constants; + ,gfx_constants + ; {@VFD_NEWFORM_IMPL} @@ -203,7 +217,8 @@ begin {$IFDEF DEBUG} writeln('Selected date: ', FormatDateTime('yyyy-mm-dd', DateValue)); {$ENDIF} - Close; + if CloseOnSelect then + Close; end; end; @@ -316,6 +331,13 @@ begin end; end; +procedure TfpgPopupCalendar.SetCloseOnSelect(const AValue: boolean); +begin + if FCloseOnSelect = AValue then + exit; + FCloseOnSelect := AValue; +end; + procedure TfpgPopupCalendar.UpdateCalendar; var lD, lM, lY: Word; @@ -369,6 +391,15 @@ begin DateValue := d; end; +procedure TfpgPopupCalendar.btnTodayClicked(Sender: TObject); +begin + if Now >= FMinDate then + begin + DateValue := Now; + TearDown; + end; +end; + procedure TfpgPopupCalendar.HandlePaint; begin Canvas.BeginDraw; @@ -471,14 +502,14 @@ begin FocusRootWidget.SetFocus; end; -constructor TfpgPopupCalendar.Create(AOwner: TComponent; - AOrigFocusWin: TfpgWidget); +constructor TfpgPopupCalendar.Create(AOwner: TComponent; AOrigFocusWin: TfpgWidget); begin inherited Create(AOwner); FOrigFocusWin := AOrigFocusWin; AfterCreate; FDate := Date; FMonthOffset := 0; + FCloseOnSelect := True; UpdateCalendar; end; @@ -486,18 +517,16 @@ procedure TfpgPopupCalendar.AfterCreate; begin {@VFD_BODY_BEGIN: fpgPopupCalendar} Name := 'fpgPopupCalendar'; - Width := 233; - Height := 142; -// SetPosition(285, 249, 233, 142); + SetPosition(285, 249, 233, 142); // WindowTitle := 'fpgPopupCalendar'; -// WindowPosition := wpUser; // Sizeable := False; +// WindowPosition := wpUser; edtYear := TfpgEdit.Create(self); with edtYear do begin Name := 'edtYear'; - SetPosition(0, 0, 72, 22); + SetPosition(0, 0, 52, 22); Text := ''; FontDesc := '#Edit1'; Focusable := False; @@ -508,7 +537,7 @@ begin with btnYearUp do begin Name := 'btnYearUp'; - SetPosition(72, 0, 13, 11); + SetPosition(52, 0, 13, 11); Text := ''; Embedded := True; FontDesc := '#Label1'; @@ -522,7 +551,7 @@ begin with btnYearDown do begin Name := 'btnYearDown'; - SetPosition(72, 11, 13, 11); + SetPosition(52, 11, 13, 11); Text := ''; Embedded := True; FontDesc := '#Label1'; @@ -536,7 +565,7 @@ begin with edtMonth do begin Name := 'edtMonth'; - SetPosition(85, 0, 135, 22); + SetPosition(65, 0, 115, 22); Text := ''; FontDesc := '#Edit1'; Focusable := False; @@ -547,7 +576,7 @@ begin with btnMonthUp do begin Name := 'btnMonthUp'; - SetPosition(220, 0, 13, 11); + SetPosition(180, 0, 13, 11); Text := ''; Embedded := True; FontDesc := '#Label1'; @@ -561,7 +590,7 @@ begin with btnMonthDown do begin Name := 'btnMonthDown'; - SetPosition(220, 11, 13, 11); + SetPosition(180, 11, 13, 11); Text := ''; Embedded := True; FontDesc := '#Label1'; @@ -570,29 +599,50 @@ begin Focusable := False; OnClick := @btnMonthDownClicked; end; + + btnToday := TfpgButton.Create(self); + with btnToday do + begin + Name := 'btnToday'; + SetPosition(194, 0, 40, 22); + Text := 'Today'; + FontDesc := '#Label1'; + Focusable := True; + OnClick := @btnTodayClicked; + end; grdName1 := TfpgStringGrid.Create(self); with grdName1 do begin Name := 'grdName1'; SetPosition(0, 23, 233, 119); - AddColumn(rsShortMon, 33, taCenter); - AddColumn(rsShortTue, 32, taCenter); - AddColumn(rsShortWed, 33, taCenter); - AddColumn(rsShortThu, 32, taCenter); - AddColumn(rsShortFri, 33, taCenter); - AddColumn(rsShortSat, 32, taCenter); - AddColumn(rsShortSun, 33, taCenter); + AddColumn('Sun', 33, taCenter); + AddColumn('Mon', 32, taCenter); + AddColumn('Tue', 33, taCenter); + AddColumn('Wed', 32, taCenter); + AddColumn('Thu', 33, taCenter); + AddColumn('Fri', 32, taCenter); + AddColumn('Sat', 33, taCenter); FontDesc := '#Grid'; HeaderFontDesc := '#GridHeader'; RowCount := 6; ScrollBarStyle := ssNone; -// ColResizing := False; OnDoubleClick := @grdName1DoubleClick; OnKeyPress := @grdName1KeyPress; end; {@VFD_BODY_END: fpgPopupCalendar} + + // Setup localization + // UI Designer doesn't support resource strings yet! + grdName1.ColumnTitle[1] := rsShortSun; + grdName1.ColumnTitle[2] := rsShortMon; + grdName1.ColumnTitle[3] := rsShortTue; + grdName1.ColumnTitle[4] := rsShortWed; + grdName1.ColumnTitle[5] := rsShortThu; + grdName1.ColumnTitle[6] := rsShortFri; + grdName1.ColumnTitle[7] := rsShortSat; + btnToday.Text := rsToday; end; @@ -657,6 +707,13 @@ begin Result := FormatDateTime(FDateFormat, FDate); end; +procedure TfpgCalendarCombo.SetCloseOnSelect(const AValue: boolean); +begin + if FCloseOnSelect = AValue then + Exit; //==> + FCloseOnSelect := AValue; +end; + function TfpgCalendarCombo.HasText: boolean; begin Result := FDate >= FMinDate; @@ -668,6 +725,7 @@ begin FMinDate := EncodeDate(1900, 01, 01); FMaxDate := EncodeDate(2100, 01, 31); FDate := Now; + FCloseOnSelect := True; DateFormat := ShortDateFormat; end; @@ -710,11 +768,16 @@ begin begin FDropDown := TfpgPopupCalendar.Create(nil, FocusRootWidget); ddw := TfpgPopupCalendar(FDropDown); + { Set to false CloseOnSelect to leave opened popup calendar menu} + ddw.CloseOnSelect := CloseOnSelect; ddw.CallerWidget := self; ddw.MinDate := FMinDate; ddw.MaxDate := FMaxDate; ddw.DateValue := FDate; ddw.ShowAt(Parent, Left, Top+Height); +{ I added this call to UpdateCalendar because sometimes after btnTodayClicked event, + reopeing the dropdown menu gave an empty calendar} + ddw.UpdateCalendar; //slapshot ddw.PopupFrame := True; ddw.OnValueSet := @InternalOnValueSet; end |