[lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter
Hi all,
Probably the most requested feature for tappytux is that the entry line where 
users type answers needs to be bigger (I mean huge) and prettier, using 
something like Comic Sans font at size 32 should do it, but of course lazarus 
provides no means of setting fonts and gtkrc seems to only be able to do it 
globally - not for one widget type only.

Which is why I am thinking that what I would need to do is create a component 
that is canvas drawn and knows how to output text in the font type of your 
choosing, in fact I think textout to a color-painted region might almost do 
it, however there is a catch, the component HAS to be UTF-8 enabled because 
tappytux is VERY internationalised and UTF is just about the only way to do 
that cleanly.
Now for the most part textout DOES display UTF-8 but the hard bit is input.
I have no idea how UTF-8 is mapped to keycodes, if I know how to handle an 
onkeydown event for a component in such a way as to ensure that the character 
displayed is what was actually TYPED (which includes handling things like Del 
and Backspace right) then my problem is solved. Of course such a component is 
sufficiently generically usefull that I imagine others would bennifit as well 
and as always I will lgpl it.

Any advice on how it should work ? What it should be descended from and how to 
get from input to screen ?

Ciao
A.J.
-- 
80% Of a hardware engineer's job is application of the uncertainty principle.
80% of a software engineer's job is pretending this isn't so.
A.J. Venter
Chief Software Architect
OpenLab International
http://www.getopenlab.com   | +27 82 726 5103 (South Africa)
http://www.silentcoder.co.za| +55 118 162 2079 (Brazil)

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter
On Monday 27 February 2006 10:47, Micha Nelissen wrote:
 A.J. Venter wrote:
  Hi all,
  Probably the most requested feature for tappytux is that the entry line
  where users type answers needs to be bigger (I mean huge) and prettier,
  using something like Comic Sans font at size 32 should do it, but of
  course lazarus provides no means of setting fonts and gtkrc seems to only
  be able to do it globally - not for one widget type only.

 Are you sure gtk is really incapable of showing a different font for
 certain widgets ? IIRC Darek implemented Color property for some
 widgets, so I guess fonts should be possible as well. (But I have no gtk
 experience).

 If this is possible, then this is *the* way to go.

I spent about 4 hours last night reading gtkrc howto´s and studying existing 
theme files and thus far I cannot find anything to do this, even then it 
STILL requires an external gtkrc file, I think a component for those cases 
where you do need it would be very usefull, the same way a tstatictext can be 
used instead of a tlabel when you just need output.

A.J.
-- 
80% Of a hardware engineer's job is application of the uncertainty principle.
80% of a software engineer's job is pretending this isn't so.
A.J. Venter
Chief Software Architect
OpenLab International
http://www.getopenlab.com   | +27 82 726 5103 (South Africa)
http://www.silentcoder.co.za| +55 118 162 2079 (Brazil)

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter
On Monday 27 February 2006 11:40, Mattias Gaertner wrote:
 On Mon, 27 Feb 2006 11:15:03 +0200

 A.J. Venter [EMAIL PROTECTED] wrote:
  On Monday 27 February 2006 10:47, Micha Nelissen wrote:
   A.J. Venter wrote:
Hi all,
Probably the most requested feature for tappytux is that the entry
line where users type answers needs to be bigger (I mean huge) and
prettier, using something like Comic Sans font at size 32 should do
it, but of course lazarus provides no means of setting fonts and
gtkrc seems to only be able to do it globally - not for one widget
type only.
  
   Are you sure gtk is really incapable of showing a different font for
   certain widgets ? IIRC Darek implemented Color property for some
   widgets, so I guess fonts should be possible as well. (But I have no
   gtk experience).
  
   If this is possible, then this is *the* way to go.
 
  I spent about 4 hours last night reading gtkrc howto´s and studying
  existing  theme files and thus far I cannot find anything to do this,
  even then it  STILL requires an external gtkrc file, I think a component
  for those cases  where you do need it would be very usefull, the same way
  a tstatictext can be  used instead of a tlabel when you just need output.

 I just tried under linux/gtk1: Setting a TEdit font size to 30 gave a a
 huge font.

Then this may be the right way, although I am using GTK2 here (I need the 
pango UTF support), and gtk_rc_parse will allow me to force a specific theme 
file. 
How exactly does your line look ? Any idea how I need ot change it to use 
GTK2 ? Or did you do this in code ?

A.J.
-- 
80% Of a hardware engineer's job is application of the uncertainty principle.
80% of a software engineer's job is pretending this isn't so.
A.J. Venter
Chief Software Architect
OpenLab International
http://www.getopenlab.com   | +27 82 726 5103 (South Africa)
http://www.silentcoder.co.za| +55 118 162 2079 (Brazil)

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread Mattias Gaertner
On Mon, 27 Feb 2006 12:08:26 +0200
A.J. Venter [EMAIL PROTECTED] wrote:

 On Monday 27 February 2006 11:40, Mattias Gaertner wrote:
  On Mon, 27 Feb 2006 11:15:03 +0200
 
  A.J. Venter [EMAIL PROTECTED] wrote:
   On Monday 27 February 2006 10:47, Micha Nelissen wrote:
A.J. Venter wrote:
 Hi all,
 Probably the most requested feature for tappytux is that the entry
 line where users type answers needs to be bigger (I mean huge) and
 prettier, using something like Comic Sans font at size 32 should
 do it, but of course lazarus provides no means of setting fonts
 and gtkrc seems to only be able to do it globally - not for one
 widget type only.
   
Are you sure gtk is really incapable of showing a different font for
certain widgets ? IIRC Darek implemented Color property for some
widgets, so I guess fonts should be possible as well. (But I have no
gtk experience).
   
If this is possible, then this is *the* way to go.
  
   I spent about 4 hours last night reading gtkrc howto´s and studying
   existing  theme files and thus far I cannot find anything to do this,
   even then it  STILL requires an external gtkrc file, I think a
   component for those cases  where you do need it would be very usefull,
   the same way a tstatictext can be  used instead of a tlabel when you
   just need output.
 
  I just tried under linux/gtk1: Setting a TEdit font size to 30 gave a a
  huge font.
 
 Then this may be the right way, although I am using GTK2 here (I need the 
 pango UTF support), and gtk_rc_parse will allow me to force a specific
 theme  file. 
 How exactly does your line look ? 

As a TEdit with a big font.


 Any idea how I need ot change it to use GTK2 ? Or did you do this in code
 ?

I did it in the designer and it works at runtime with gtk1.
For gtk2:
This needs to be implemented in gtkobject.inc TGtkWidgetSet.SetWidgetFont.


Mattias

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter


  Any idea how I need ot change it to use GTK2 ? Or did you do this in code
  ?

 I did it in the designer and it works at runtime with gtk1.
 For gtk2:
 This needs to be implemented in gtkobject.inc TGtkWidgetSet.SetWidgetFont.

I am studying that file now, thinking off it, my way wouldn´t work anyway, 
without SetWidgetFont there isn´t any real way for a custom component to 
force it´s font either (except perhaps for direct GTK2 calls in which case I 
may as well just do it for the LCL and be done with it).

Not being a GTK guru I am a little lost but mostly understanding what the code 
is meant to be doing and I am fairly certain that (some of) the code in 
PangoDrawText can be used to implement this (since I need it, I am happy to 
try at least), what I do need however is some idea of how it should work, 
where is it defined ? Procedure ? Function (result type) ?

Unfortunately the lazarus-ccr seems to be down (could be my ISP though) so I 
cannot look it up there and I cannot find such a function in the GTK1 file of 
the same name at all. 

I assume it´s specified somewhere else ? Presumably the same place where the 
debugln for setWidgetFont comes from.

Anybody up for helping me ?

A.J.
-- 
80% Of a hardware engineer's job is application of the uncertainty principle.
80% of a software engineer's job is pretending this isn't so.
A.J. Venter
Chief Software Architect
OpenLab International
http://www.getopenlab.com   | +27 82 726 5103 (South Africa)
http://www.silentcoder.co.za| +55 118 162 2079 (Brazil)

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter
Well I did some research and the GTK way of doing it is really very simple, 
except that the method (modify_font) doesn´t seem to exist in PGTKWidget 
which I surmise is because the definition of THAT is taken from the GTK1 
definition.
According to the GTK2 docs, all GTK2 widgets derive from GTKWidget and should 
inherrit modify_font which can set any pangoFontDescription, the only 
remaining part is to convert a tfont TO a PangoFontDescription (well 
PPangoFontDescription actually).

So the RIGHT way I believe is to enable the method, presumably by descending 
PGTKWidget to create PGTK2Widget (oddly TGK2Widget exists but TGKWidget does 
not) - which may have the inadvertent side effect of meaning that damn near 
every bit of GTK needs to have it´s type definitions altered to call and use 
the derived class, either that or GTK2 should simply overWRITE the PGTKWidget 
definition with it´s own version that enables the GTK2 specific features.

Thoughts anyone ?

Ciao
A.J.
-- 
80% Of a hardware engineer's job is application of the uncertainty principle.
80% of a software engineer's job is pretending this isn't so.
A.J. Venter
Chief Software Architect
OpenLab International
http://www.getopenlab.com   | +27 82 726 5103 (South Africa)
http://www.silentcoder.co.za| +55 118 162 2079 (Brazil)

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter

 
  If this is possible, then this is *the* way to go.

 At least I know it is possible for gtk2 - I implemented dynamic fonts in
 one of my (C++, unfortunately) programs. The documentation seems to talk
 about the font code as something New and Improved (tm), so I'd say it's
 quite hard in gtk1.
Well I could find the documentation on how to do it, but the actual method 
isn't implemented somewhere, it is not impossible that the PLACE where it is 
missing is in the FPC units, but since those were autogenerated my gutt tells 
me that it is more likely to be somewhere in the LCL.

I am not exactly sure how the GTK2 objects were turned into OP classes for the 
LCL, I would have to look at the wrapper code first, my feeling however is 
that the likely scenario is that somewhere an external declaration needs to 
be added that can enable GTKWidget.Modify_font from the GTK2 libs.

GTK1 already has support for this, and if I I didn't REALLY need UTF-8 support 
for text-out I would have just compiled my app for GTK1 instead but since I 
don't know how, and it would be GREAT if this works, I am happy to help write 
code to make it happen, if I can get help from some of the gtk2 guru's it 
would just happen faster. 

My current code:
In gtk2object.inc add this (I put mine just above TGTKWidget.SetCallBack):
Procedure TGTK2WidgetSet.SetWidgetFont(const AWidget: PGTK2Widget; const 
Afont: tFont);
Var
  PangoDescStr,DescOpts : String;
  NewFontDescription : PPangoFontDescription;

Begin
{$IFDEF GTK2}
PangoDescStr := AFont.Name;
DescOpts := '';
  If FSBold in AFont.Style then
DescOpts := DescOpts + ' bold';
  If FSItalic in AFont.Style then
DescOpts := DescOpts + ' italic';
  If FSUnderline in AFont.Style then
DescOpts := DescOpts + ' underline';
  If FSStrikeOut in AFont.Style then
DescOpts := DescOpts + ' strikethrough';

   PangoDescStr := PangoDescStr+DescOpts+' '+intToStr(Afont.Size);
//Pango does not appear to have a way to set the character set in the
//font description but seems to default to UTF-8 this probably
//requires some or other todo item.
try
NewFontDescription := PPangoFontDescription(PangoDescStr);
AWidget.Modify_Font(NewFontDescription);

except
debugln('COULD NOT SET FONT');
end;
{$ENDIF}
end;


In GTK2Int.pas  change
  protected
procedure AppendText(Sender: TObject; Str: PChar);
to:
  protected
procedure SetWidgetFont(const AWidget: PGTK2Widget; const Afont: tFont);
procedure AppendText(Sender: TObject; Str: PChar);

Note that the current code DOES NOT COMPILE due to the missing Modify_Font.

PS. Thanks Darek, I managed to get THIS far by studying your patch and will 
look at it again when doing the per-widget bits.

PPS. As you can see, right now tfont.color is NOT yet handled at all.

Ciao
A.J.

-- 
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread Mattias Gaertner
On Mon, 27 Feb 2006 16:42:06 +0200
A.J. Venter [EMAIL PROTECTED] wrote:

 Well I did some research and the GTK way of doing it is really very
 simple,  except that the method (modify_font) doesn´t seem to exist in
 PGTKWidget  which I surmise is because the definition of THAT is taken
 from the GTK1  definition.
 According to the GTK2 docs, all GTK2 widgets derive from GTKWidget and
 should  inherrit modify_font which can set any pangoFontDescription, the
 only  remaining part is to convert a tfont TO a PangoFontDescription (well
 PPangoFontDescription actually).

Correct. 
There must be already such a function, but I'm not sure if it works good.
There are a lot of font issues in the gtk2 interface. 

 
 So the RIGHT way I believe is to enable the method, presumably by
 descending  PGTKWidget to create PGTK2Widget (oddly TGK2Widget exists but
 TGKWidget does  not) - which may have the inadvertent side effect of
 meaning that damn near  every bit of GTK needs to have it´s type
 definitions altered to call and use  the derived class, either that or
 GTK2 should simply overWRITE the PGTKWidget  definition with it´s own
 version that enables the GTK2 specific features.

I'm not sure what this TGTK2Widget is.


Mattias

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter

 Correct.
 There must be already such a function, but I'm not sure if it works good.
 There are a lot of font issues in the gtk2 interface.
Well if it's there, it's not there under the same name :)

  So the RIGHT way I believe is to enable the method, presumably by
  descending  PGTKWidget to create PGTK2Widget (oddly TGK2Widget exists but
  TGKWidget does  not) - which may have the inadvertent side effect of
  meaning that damn near  every bit of GTK needs to have it´s type
  definitions altered to call and use  the derived class, either that or
  GTK2 should simply overWRITE the PGTKWidget  definition with it´s own
  version that enables the GTK2 specific features.

 I'm not sure what this TGTK2Widget is.
It is defined in gtk2int.pas and seems to to be the parent widget for gtk2 
widgets, except it's a LOT shorter than the TGTKWidget definition in 
gtkint.pas (this was where I had to add the procedure definition for 
setWidgetFont), and it doesn't seem to be derived, 
I have not found any reference to PGTK2Widget however leading me to presume it 
doesn't exist, the procedure reference right now uses PGTKWidget since that 
is what I got from Darek's patch, but I am fairly certain that it DOES need 
to change to be a pointer to a TGK2Widget, I am still trying to figure out 
where to DO that though, it is not impossible that defining PGTK2Widget and 
making whatever changes is needed to allow SetWidgetFont calls under GTK2 to 
pass the right type will solve the problem entirely - of course a GTK2 only 
method won't exist if we are using a GTK1 class definition to refer to the 
widget objects in calls. 


Ciao
A.J.
-- 
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter

  try
  NewFontDescription := PPangoFontDescription(PangoDescStr);
  AWidget.Modify_Font(NewFontDescription);

 I will take a look ...

Mucios Gracias Amigo.

A.J.

-- 
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread A.J. Venter
On Monday 27 February 2006 18:51, Mattias Gaertner wrote:
   font_desc:=pango_font_description_from_string(PChar(PangoDescStr));
   gtk_widget_modify_font(AWidget,font_desc);
   pango_font_description_free(font_desc);          

Right my patch is ALL BUT complete, one thing is missing though, 
This code FAILS is tfont.name is set to Default, I need to CATCH that and give 
it a SANE default font name in that case,
what should I use ? 
Ideally it should be whatever lazarus normally uses.

A.J.

-- 
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] Pretty looking TEdit

2006-02-27 Thread Mattias Gaertner
On Mon, 27 Feb 2006 19:59:02 +0200
A.J. Venter [EMAIL PROTECTED] wrote:

 On Monday 27 February 2006 18:51, Mattias Gaertner wrote:
    font_desc:=pango_font_description_from_string(PChar(PangoDescStr));
    gtk_widget_modify_font(AWidget,font_desc);
    pango_font_description_free(font_desc);          
 
 Right my patch is ALL BUT complete, one thing is missing though, 
 This code FAILS is tfont.name is set to Default, I need to CATCH that and
 give  it a SANE default font name in that case,
 what should I use ? 
 Ideally it should be whatever lazarus normally uses.

Make this: ... whatever gtk2 uses.
I just tested: 'default 29' works here.
Maybe you can use 

  Style:=gtk_widget_get_style(AWidget);
  if Stylenil then begin
font_desc:=Style^.font_desc;

  end;

Mattias

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives