Recent

Author Topic: Frame Based Calendar.  (Read 17472 times)

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Frame Based Calendar.
« on: July 27, 2012, 04:29:43 pm »
I started making a Frame based Calendar control due to this thread -> http://80.123.225.56/index.php/topic,17589.0.html

Because Lazarus uses the Widgetset of the OS, there can be inconsistency between OS's.
The Calendars also don't support RightToLeft.

To save my updates flooding this thread I thought it best I start a new one in ThirdParty.

Please note this isn't a Component as such, but kind of acts like one.  The advantage is you can just drop into your existing project without having to register a new set of Components.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Frame Based Calendar.
« Reply #1 on: July 27, 2012, 05:45:28 pm »
I am having a tough time figuring this one out.  When I run it under my English LogIn, it looks like it should.  But in my Hebrew LogIn, some of the English Chars are replaced with '???'.  The Hebrew looks perfect.  At first I thought it might be font that doesn't support Hebrew so I tried one that I know does.  I got the same result so that isn't it.
« Last Edit: July 27, 2012, 05:48:59 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Frame Based Calendar.
« Reply #2 on: July 27, 2012, 06:12:05 pm »
Yes, just changed to Hebrew to test, and like you say it comes out ???.

In fact just doing. ->
Code: [Select]
label2.caption := FormatSettings.ShortDayNames[1] ;

Doesn't appear to work, I even tried doing SysToUTF8 etc, but doesn't still look correct.  I wonder if FormatSettings isn't working correctly?.

And easy workaround is to have some more events for them, like the one I've done for DayNames.  This will be handy anyway as your wanting to have Hebrew Calendar on English locale.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12718
  • FPC developer.
Re: Frame Based Calendar.
« Reply #3 on: July 27, 2012, 06:15:28 pm »
If on *nix, you do include unit "clocale" ?

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Frame Based Calendar.
« Reply #4 on: July 27, 2012, 06:20:36 pm »
Hi @Marcov,

This is happening in Windows, not sure about Linux..

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Frame Based Calendar.
« Reply #5 on: July 27, 2012, 07:17:06 pm »
I see the same problem on my french system with month names. FormatSettings gets the info from the system in the system code page encoding.  The following works for me (add to uCalendar):

Code: [Select]
var i:integer;
initialization
for i:=1 to 12 do
  begin
  FormatSettings.LongMonthNames[i]:=SysToUTF8(FormatSettings.LongMonthNames[i]);
  end;
for i:=1 to 7 do
  begin
  FormatSettings.ShortDayNames[i]:=SysToUTF8(FormatSettings.ShortDayNames[i]);
  end;
On 2.7.1 you can also put that block in TfCalendar.Create even when multiple calendars are created. 2.7.1 stores the codepage with the string so the 2nd time SysToUTF8 is called it converts an utf8 char to utf8 which is fine. I haven't tested this on 2.6.0 and have put it in the initialization section to be on the safe side.

BTW. The top right corner of the year is cut off. Probably caused by the italic char set. Image attached.


KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Frame Based Calendar.
« Reply #6 on: July 27, 2012, 09:09:42 pm »
@ludob: 

Cheers, I did try the sysToUtf8, but for Hebrew it didn't seem to work..  I double checked & used your code and still no joy :(

Quote
BTW. The top right corner of the year is cut off. Probably caused by the italic char set. Image attached.
Yeah, I can see that on you screenshot, but not sure why that would happen as the TLabel is extended to the full width & auto-size is turned off.   eg. If I change the TLabel to have a red background it extends the full width. eg.
Code: [Select]
constructor TfCalendar.Create(Aowner: TComponent);
.. 
  lbMonthYear := NewLabel;
  lbMonthYear.Color:=clred;  //add this
  lbMonthyear.font.Style := [fsItalic]; 

Attached is what it looks like with the sysToUtf8 & setting lbMonthYear color to red.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Frame Based Calendar.
« Reply #7 on: July 27, 2012, 09:40:53 pm »
KpjComp, now I'm feeling like a jerk.  You helped a guy with a specific question and I had to open my mouth and bring up the RightToLeft issue.  It was never my intent to take up so much of your time.  :-[
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Frame Based Calendar.
« Reply #8 on: July 27, 2012, 09:47:34 pm »
No, don't worry Avishai,

It's a bit like a puzzle,  I've never really had to deal with RightToLeft, or different languages so it's interesting stuff. :)

I'm learning too..

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Frame Based Calendar.
« Reply #9 on: July 27, 2012, 09:54:42 pm »
I can't believe you set up a Hebrew account just for this  :o  How can you even find your way around in it!?  Lazarus, by default comes up in Hebrew! along with a lot of other stuff.  And if you're using Windows Ultimate, the whole environment is mirrored.  You are a brave man  :)
Lazarus Trunk / fpc 2.6.2 / Win32

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Frame Based Calendar.
« Reply #10 on: July 28, 2012, 09:00:16 am »
Quote
Attached is what it looks like with the sysToUtf8 & setting lbMonthYear color to red.
The extend of the red bar is identical. Found that this is a font issue. Dropping a label on a form with the default autosize I see that setting fsItalic doesn't change the width of the label. Tried plain arial and the width changes when setting fsItalic and no cut off occurs. Tried several fonts and it appears that only fonts that have a native italic version are OK. Arial has a Arial Italic but Arial Unicode MS which doesn't have a italic version fails. So somewhere the "calculated" italic is causing the problem. This seems to be a windows problem. Tried this in MSWord with the same fonts and 20121234 at 36 points is correctly spaced with Arial but with Arial Unicode MS the 2 touches the 1.
Quote
I did try the sysToUtf8, but for Hebrew it didn't seem to work
I had seen that in your previous message. But unless your calendar is for the English/Hebrew market only, showing correct labels for the rest of the western world would be useful.

Perhaps Avishai can tell us what function he uses to convert the Hebrew code (1255 ?) page to utf8.
I did some experimenting on 2.7.1, without changing my system to Hebrew, with cp 1255 and the following transforms the special French characters to Hebrew.
Code: [Select]
for i:=1 to 12 do
  begin
  s:=FormatSettings.LongMonthNames[i];
  SetCodePage(s,1255,false);
  FormatSettings.LongMonthNames[i]:=SysToUTF8(s);
  end;
If that works then or the default codepage detection is wrong or the codepage is not set correctly when filling in the FormatSettings strings. What is DefaultCodePage and StringCodePage(FormatSettings.LongMonthNames[1]) returning on a Hebrew system?

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Frame Based Calendar.
« Reply #11 on: July 28, 2012, 10:06:33 am »
I can confirm the Font issue, although it is odd.  If the text is Left Aligned, it displays correctly.  But when it is Center Aligned, it gets cut off as you said.  I only checked with Arial Unicode MS.

As for converting to Hebrew CodePage.  I don't have to do anything.  Perhaps because I have the Hebrew Keyboard installed and simply add my strings in Hebrew. 'First Name = שם פרטי'.

I don't know if this its the answer you are looking for but in both English and Hebrew LogIns, I tried:  'Label1.Caption:= IntToStr(Label1.Font.CharSet);' and both returned '1' for DEFAULT_CHARSET and 177 for HEBREW_CHARSET.

I tried your 'SetCodePage(s,1255,false)' but 'SetCodePage' returns 'Identifier not found' and so far I haven't been able to determine what I need to add to the Uses Statement.  I hope I can find it because that routine looks like it could be very useful.

I hope that maybe some part of this has been useful.

Edit: I never set Font.CHARSET to HEBREW_CHARSET.  I leave it as DEFAULT_CHARSET.
« Last Edit: July 28, 2012, 10:17:34 am by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Frame Based Calendar.
« Reply #12 on: July 28, 2012, 10:25:49 am »
@ludob, tried the setlocale, still no joy.

But I've managed to get something I believe is working on Windows.

I had to use a customized version of UnicodeToUtf8 & FormatDatTime, I'm not sure UnicodeToUTF8 is working correctly.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Frame Based Calendar.
« Reply #13 on: July 28, 2012, 11:10:46 am »
@Avishai

Keyboard is rarely a problem. I was more thinking about what you need to do to convert Hebrew characters in file names when you use FindFirst/FindNext for example.

SetCodePage is fpc 2.7.1 only.

@KpjComp

Yep that works, at least on a French system. And using the windows unicode API to do the conversion will probably work on all systems. Since you used directly the windows api you could have used also WideCharToMultiByte with CP_UTF8 instead of re-writing UnicodeToUtf8.
 

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Frame Based Calendar.
« Reply #14 on: July 28, 2012, 01:16:34 pm »
@ludob, Ah, I see now what you were asking.  For that type of thing I use TStringList.CustomSort.  There is likely a better solution, but once I find something that works I move on to something else.  I'm still trying to understand how people are able to live with 'Standard' sort when it isn't Case Sensitive.  It results in a kind of Semi-Sort :)

@KpjComp, that is some amazing work.  I looked at your 'function UnicodeToUtf8' and didn't understand much of it, but it seems to work.  On the Hebrew LogIn it works perfectly for Hebrew but 'Sun, Mon, Tue...' get translated back to Hebrew as 'יום א, יום ב, יוםג...' (Translation: Day 1, Day 2, Day 3) which is correct, it's just not English.  But honestly, I'm ok with that.  I hate to see you wasting your time on this when I'm sure you have better things to do.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018