Recent

Author Topic: Custom date display in TCalendar  (Read 16726 times)

JD

  • Hero Member
  • *****
  • Posts: 1909
Custom date display in TCalendar
« on: August 28, 2012, 06:54:34 pm »
Hi there everyone,

I have an old project that uses a TCalendar to keep track of events. I want to update it so that if an event occurred on a particular date, the date appears different (bold, italic, underline, different colour etc) from the others.

In my head, I think I'll need to play with Canvas, Rect etc but I don't know where to start from because I haven't done work with graphics in a long time.

Using the RxCalendarGrid in place of the TCalendar is another option for me but my problem is still remains.

Any suggestions will be welcome.
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Custom date display in TCalendar
« Reply #1 on: August 28, 2012, 07:00:39 pm »
For which OS?  From what I hear, TCalendar is very different from one OS to the next.  I did what you are talking about long ago in Delphi 6.  TCalendar had the properties to highlight Dates, but I don't know if Lazarus is the same.  I doubt it.  A lot has changed since Delphi 6.
Lazarus Trunk / fpc 2.6.2 / Win32

JD

  • Hero Member
  • *****
  • Posts: 1909
Re: Custom date display in TCalendar
« Reply #2 on: August 28, 2012, 07:03:23 pm »
For which OS?  From what I hear, TCalendar is very different from one OS to the next.  I did what you are talking about long ago in Delphi 6.  TCalendar had the properties to highlight Dates, but I don't know if Lazarus is the same.  I doubt it.  A lot has changed since Delphi 6.

Win32. I'm not really stuck on TCalendar. I think all the calendars use similar methods to display dates so what works for one might work for another with minimal modifications. I selected TCalendar because it is the most common in use.

It's part of an old project that needs a little facelift!  Users always ask for more, alas! :D
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Custom date display in TCalendar
« Reply #3 on: August 28, 2012, 07:04:10 pm »
For which OS?  From what I hear, TCalendar is very different from one OS to the next.  I did what you are talking about long ago in Delphi 6.  TCalendar had the properties to highlight Dates, but I don't know if Lazarus is the same.  I doubt it.  A lot has changed since Delphi 6.

In TOvcCalendar, I see the OnGetHighlight and OnDrawDate events that should allow you to highlight specific dates in the calendar.

Thanks.

-Phil

JD

  • Hero Member
  • *****
  • Posts: 1909
Re: Custom date display in TCalendar
« Reply #4 on: August 28, 2012, 07:05:53 pm »
For which OS?  From what I hear, TCalendar is very different from one OS to the next.  I did what you are talking about long ago in Delphi 6.  TCalendar had the properties to highlight Dates, but I don't know if Lazarus is the same.  I doubt it.  A lot has changed since Delphi 6.

In TOvcCalendar, I see the OnGetHighlight and OnDrawDate events that should allow you to highlight specific dates in the calendar.

Thanks.

-Phil

It has problems with accented text. Works OK in Delphi 2010 but garbles accented characters in Delphi 2006 and Lazarus 1.1/FPC 2.6.1.
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Custom date display in TCalendar
« Reply #5 on: August 28, 2012, 07:07:24 pm »
It has problems with accented text. Works OK in Delphi 2010 but garbles accented characters in Delphi 2006 and Lazarus 1.1/FPC 2.6.1.

Not sure what you're referring to. Are you talking about TOvcCalendar?

Thanks.

-Phil

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Custom date display in TCalendar
« Reply #6 on: August 28, 2012, 07:09:19 pm »
I just checked my very old Delphi 6 code and TCalendar had a property BoldDays that allow highlighting dates.  I don't see that in Lazarus TCalendar.  I think you would have to do a lot of work with TCalendar and I doubt it would be worth it.
Lazarus Trunk / fpc 2.6.2 / Win32

JD

  • Hero Member
  • *****
  • Posts: 1909
Re: Custom date display in TCalendar
« Reply #7 on: August 28, 2012, 07:14:52 pm »
It has problems with accented text. Works OK in Delphi 2010 but garbles accented characters in Delphi 2006 and Lazarus 1.1/FPC 2.6.1.

Not sure what you're referring to. Are you talking about TOvcCalendar?

Thanks.

-Phil

Oh yes. The Orpheus calendar. I can show you screenshots if you want.
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Custom date display in TCalendar
« Reply #8 on: August 28, 2012, 07:16:07 pm »
It has problems with accented text. Works OK in Delphi 2010 but garbles accented characters in Delphi 2006 and Lazarus 1.1/FPC 2.6.1.

Not sure what you're referring to. Are you talking about TOvcCalendar?

Thanks.

-Phil

Oh yes. The Orpheus calendar. I can show you screenshots if you want.

Please do - for Lazarus version.

Thanks.

-Phil

JD

  • Hero Member
  • *****
  • Posts: 1909
Re: Custom date display in TCalendar
« Reply #9 on: August 28, 2012, 07:23:58 pm »
It has problems with accented text. Works OK in Delphi 2010 but garbles accented characters in Delphi 2006 and Lazarus 1.1/FPC 2.6.1.

Not sure what you're referring to. Are you talking about TOvcCalendar?

Thanks.

-Phil

Oh yes. The Orpheus calendar. I can show you screenshots if you want.

Please do - for Lazarus version.

Thanks.

-Phil

Your wish is my command.....  :D This is in French.
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Custom date display in TCalendar
« Reply #10 on: August 28, 2012, 07:48:49 pm »
Your wish is my command.....  :D This is in French.

LCL interface functions like DrawText (used in ovccal.pas) always expect strings to be in UTF8 on most widgetsets. It appears as though FPC LongMonthNames, etc. are returning non-UTF8 strings - hence the resulting display.

Should be easy to fix if you want to try.

Thanks.

-Phil


Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Custom date display in TCalendar
« Reply #11 on: August 28, 2012, 07:51:41 pm »
This may be what you are looking for

Code: [Select]
function GetLongMonthNames(I: Integer): String;
begin
  Result:= SysToUTF8(LongMonthNames[I]);
end;

function GetShortMonthNames(I: Integer): String;
begin
  Result:= SysToUTF8(ShortMonthNames[I]);
end;

I have heard that FPC is in the process of fixing it but haven't relieced it yet.
« Last Edit: August 28, 2012, 07:55:18 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Custom date display in TCalendar
« Reply #12 on: August 28, 2012, 08:57:54 pm »
I have heard that FPC is in the process of fixing it but haven't relieced it yet.

I'm not familiar with SysToUtf8 - that doesn't appear to be in 2.6.0.

AnsiToUtf8 would probably work.

Thanks.

-Phil

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Custom date display in TCalendar
« Reply #13 on: August 28, 2012, 09:14:52 pm »
It's in "..\lazarus\components\lazutils\fileutil.pas" at Line#201.  I tried AnsiToUtf8 and had problems.  I don't remember what the problems were, I just remember getting frustrated :)
Lazarus Trunk / fpc 2.6.2 / Win32

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Custom date display in TCalendar
« Reply #14 on: August 28, 2012, 09:41:12 pm »
It's in "..\lazarus\components\lazutils\fileutil.pas" at Line#201.  I tried AnsiToUtf8 and had problems.  I don't remember what the problems were, I just remember getting frustrated :)

The only thing SysToUtf8 does on Windows is check to see if your system codepage is 65001 (UTF8) - if it is, the function doesn't need to convert to UTF8; if it isn't, the function calls AnsiToUtf8.

Do a WriteLn((GetACP); on Windows to see what your system CP is.

Thanks.

-Phil

 

TinyPortal © 2005-2018