Recent

Author Topic: Questions about a new Calendar component.  (Read 71538 times)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Questions about a new Calendar component.
« on: June 05, 2013, 11:02:51 am »
I know what TCalendar is on MSWindows and it's unusable except for English language.  But what is it like on other OS's?  Is it usable?  The reason I ask is because I am thinking about creating a new Calendar component, but that wouldn't make sense if it is only a MSWindows issue.

My idea is to write a component that only displays the Day Numbers per Month/Year and nothing else.  No Day Names, No Month Name, No Year and No 'Today'.  That would make it easy to derive any kind of Calender you want and have some control.

Question 1 is obvious:  Has anyone already done this?
Question 2: If I use a TPanel as the control class and TLabels for the Day numbers, how stable is ChildSizing?
Lazarus Trunk / fpc 2.6.2 / Win32

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Questions about a new Calendar component.
« Reply #1 on: June 05, 2013, 02:04:15 pm »
http://www.lazarus.freepascal.org/index.php/topic,17672.msg98019.html#msg98019

I think that is the last version of a frame based calendar that KpjComp built. Try using that it supports right to left and multiple languages.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #2 on: June 05, 2013, 02:22:39 pm »
Tanks taazz.  I tried that back when he first posted it.  It was very interesting, but as far as I know, no one was able to get it to work except in his Demo.  Still I would like more flexibility.  By making the display of the DayNumbers separate and adding the Calendar functionality, I can add the DayNames, MonthName... any way I want and have a functional Calendar with ease.

Delphi has a component that almost does what I want but it includes the DayNames.  It also uses a Grid that I would like to avoid.  And of course, it's MSWindows only.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #3 on: June 05, 2013, 05:28:49 pm »
With the approach I'm thinking about, I can create a Calendar Holder any way I like.  Then just drop in the CalendarDays, add a few events for changing Year/Month and SelDate and I'm done.

In the attached image, I would simply Drop CalendarDays where it says "MyCalendar" and set it to AlignClient.  If I need one that looks completely different, I don't have to reinvent it.

And best of all (I hope, not sure about ChildSizing) it's cross platform and doesn't care which language you are using.  And it fully supports BiDiMode.

Edit:  Obviously the Image I posted is RightToLeft.  But Edit1 would change the Month, Edit2 would change the Year and lblToday would set SelDate to 'Today'.
« Last Edit: June 05, 2013, 06:12:16 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #4 on: June 06, 2013, 12:09:38 pm »
Almost finished.  Now I can make a Calendar any way I want with different appearance, different controls, different language...  All that remains the same is the display of the Day Numbers.

The top image was built in the IDE and the bottom one is a derived component.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #5 on: June 11, 2013, 12:35:53 pm »
I wish I had thought about this before but it just occurred to me that it might be a good idea to add a TList to hold a list User Definable HighLightColors, FontColors and FontStyles so that the user could HighLight multiple dates with different colors.  Doing that now would mean totally redesigning my Calendar.  Any ideas about this would be appreciated.
Lazarus Trunk / fpc 2.6.2 / Win32

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: Questions about a new Calendar component.
« Reply #6 on: June 11, 2013, 01:48:23 pm »
Why it needs to be new, instead of improving current TCalendar?

Only real problem I have with current TCalendar, property "Date" type is string, but in Delphi TMonthCalendar it's TDate. Ofcourse componentname could also be TMonthCalendar.

Zoran

  • Hero Member
  • *****
  • Posts: 1900
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Questions about a new Calendar component.
« Reply #7 on: June 11, 2013, 02:02:30 pm »
Only real problem I have with current TCalendar, property "Date" type is string, but in Delphi TMonthCalendar it's TDate. Ofcourse componentname could also be TMonthCalendar.

Use TCalendar.DateTime: TDateTime.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #8 on: June 11, 2013, 02:05:42 pm »
Timewarp, the reason for a new Calendar component is that the MSWidows version of TCalendar is so bad that I can't uses it.  Maybe for other OS's it's better but for MSWindows,

1. The only way to change it's size is to change the Font.
2. Colors can only be changed by changing Themes.  Even then I'm not so sure.
3. It does not support BiDiMode. (For some languages, it should be RightToLeft)
4. The only way to change the language is to change your Locale.  Even then the word "Today" is not changed.

You didn't give your Locale in your profile so maybe English works for you, but I need for it to be in Hebrew which is RightToLeft.
« Last Edit: June 11, 2013, 02:07:50 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Zoran

  • Hero Member
  • *****
  • Posts: 1900
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Questions about a new Calendar component.
« Reply #9 on: June 11, 2013, 02:18:32 pm »
It also uses a Grid that I would like to avoid.

Why? In LCL grid is custom drawn and therefore cross-platform and customizeable.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #10 on: June 11, 2013, 02:32:20 pm »
Zoran, I haven't actually checked it but my assumption is that using a grid would bloat the size of the component and it isn't needed.  ChildSizing does what I need and I 'think' it is very small.  Also the ChildSizing approach requires 'almost' no additional code related to Col/Row, Resizing or FontChange.

I also use TPanel for the DayNumbers so HighLighting is only changing the Color of the TPanel and the FontColor/FontStyle.  With Grid is not difficult but it is not that straight forward.
Lazarus Trunk / fpc 2.6.2 / Win32

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Questions about a new Calendar component.
« Reply #11 on: June 12, 2013, 11:44:49 pm »
I asked myself if it were possible to design a calendar using only a TGraphicControl as the ancestor, and do all the drawing without use of further components (arrays of labels/panels; or use of a grid). The attached project is my positive answer to that question, which is consequently independent of any widgetset, and has a smaller memory footprint than most other calendars.
Unlike most calendar components this is resizeable, and designed so it can be client-aligned inside a frame or panel or other container, as well as simply dropped onto a form and manually resized. You can set various colours and display parameters (and it would be fairly easy to add further display customisation), and also set which day of the week the first column of days should refer to. Arrow icons allow change of the current month or year forwards or backwards, and the current date is selected by left-clicking the desired day. A BiDi property is provided, but since I don't read Arabic or Hebrew I have not been able to test this (so it may not work correctly). It also provides an OnDateChange event. It defaults to display of day and month names in the language of the locale, but this can be overridden by supplying text in other languages, as you can see in the attached screenshot. It is offered so that others can adapt and improve the code.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #12 on: June 12, 2013, 11:52:52 pm »
howardpc, that's impressive!  You may have solved my problems with TCalendar and also created a gem for others to users.  I will check out the BiDiMode/RightToLeft capabilities in the morning.  It's after midnight now and I'm an old man well past his bedtime.
« Last Edit: June 13, 2013, 07:40:09 am by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #13 on: June 13, 2013, 06:39:30 am »
howardpc!  That is beautiful!  I've added the Hebrew month names below and I'm sure that someone could provide Arabic/Farsi and other languages as well, but the way you've written it, I doubt that it's needed.  Anyone can very simply add whatever languages they need.  Really nice job.  I wanted to see if the grayed out days of Prev. and Next months could be HighLighted and clicked on one.  What a great feature!  It changed to the Prev./Next month!  I wouldn't have thought of that.

The only problem with RightToLeft that I found is with the "Month, Year" at the top.  For RightToLeft languages the Month should be on the Right and the Year on the Left.  "2013 June"

I hope you plan to submit this to the development team.  This would be a great addition to Lazarus.


HebrewMonths: TMonthNameArray = ('ינואר','פברואר','מרץ','אפריל','מאי','יוני',
    'יולי','אוגוסט','ספטמבר','אוקטובר','נובמבר','דצמבר');



Edit:  In procedure TCalDrawer.DrawTopRow the line

"s:= FOwner.FMonthNames[FThisMonth] + ' ' + IntToStr(FThisYear);"

should be the same for both TRUE and FALSE.  bdRightToLeft takes care of getting the order right.
« Last Edit: June 13, 2013, 06:56:02 am by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Questions about a new Calendar component.
« Reply #14 on: June 13, 2013, 10:28:25 am »
Ah, thanks for that.
I did not realise there was so much capability already built in to bdRightToLeft.
Nor did I realise there were Hebrew equivalents for 'secular' months. The only limited exploration I had done seemed to indicate there was no direct correspondence between the dates of Hebrew months and those in other calendars.
The fact that Lazarus/FPC has an international community is such a boon. Thank you.

 

TinyPortal © 2005-2018