Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-10

How to draw text in a edit (GTK2)

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hi,

In Windows is very easy:

(...)
var
  VCanvas: TControlCanvas;
begin
  VCanvas := TControlCanvas.Create;
  try
    VCanvas.Control := Edit1;
    VCanvas.TextOut(0, 0, 'Test');
  finally
    VCanvas.Free;
  end;
end;
(...)

But, this code don't works in Linux (Ubuntu 11.04 / GTK2).

What the alternative to draw text in a TWinControl (GTK2)?

Thx.

Silvio Cl?cio =============================================== Blog - <silvioprog.com.br> Twitter - <twitter.com/silvioprog> Facebook - <facebook.com/silvioprog> LazSolutions - <code.google.com/p/lazsolutions> LazWebSolutions - <code.google.com/p/lazwebsolutions> Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR> =============================================== ? ?* Conhe?a nosso canal IRC sobre Lazarus: #lazarus-br * ===============================================

Reply by email

silvioprog
to Hans-Peter Diettrich: It most probably doesn't work on a Mac, where painting is allowed only in during WM_PAINT.

2011/10/3 Hans-Peter Diettrich :
[...]

Invalidate the control, and wait for it's OnPaint request. DoDi

OnPaint in TWinControl?

Silvio Cl?cio =============================================== Blog - <silvioprog.com.br> Twitter - <twitter.com/silvioprog> Facebook - <facebook.com/silvioprog> LazSolutions - <code.google.com/p/lazsolutions> LazWebSolutions - <code.google.com/p/lazwebsolutions> Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR> =============================================== ? ?* Conhe?a nosso canal IRC sobre Lazarus: #lazarus-br * ===============================================

Reply by email

silvioprog
to silvioprog

2011/10/3 silvioprog :

Show quoted text 7 lines
2011/10/3 Hans-Peter Diettrich : [...] > Invalidate the control, and wait for it's OnPaint request. > > DoDi OnPaint in TWinControl?

So, I tried with WMPaint, but, without sucess too. X(

Silvio Cl?cio =============================================== Blog - <silvioprog.com.br> Twitter - <twitter.com/silvioprog> Facebook - <facebook.com/silvioprog> LazSolutions - <code.google.com/p/lazsolutions> LazWebSolutions - <code.google.com/p/lazwebsolutions> Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR> =============================================== ? ?* Conhe?a nosso canal IRC sobre Lazarus: #lazarus-br * ===============================================

Reply by email

silvioprog
to Hans-Peter Diettrich: It most probably doesn't work on a Mac, where painting is allowed only in during WM_PAINT.

My test in attached.

Work only in Windows. x(

Win: http://imagebin.org/177323
Linux: http://imagebin.org/177324

Silvio Cl?cio =============================================== Blog - <silvioprog.com.br> Twitter - <twitter.com/silvioprog> Facebook - <facebook.com/silvioprog> LazSolutions - <code.google.com/p/lazsolutions> LazWebSolutions - <code.google.com/p/lazwebsolutions> Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR> =============================================== ? ?* Conhe?a nosso canal IRC sobre Lazarus: #lazarus-br * =============================================== -------------- next part -------------- A non-text attachment was scrubbed... Name: canvas.zip Type: application/zip Size: 2467 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111003/490be213/attachment.zip>

Reply by email

Hans-Peter Diettrich
to silvioprog: In Windows is very easy: (...) var VCanvas: TControlCanvas; begin VCanvas :=…
Show quoted text 19 lines
Hi, In Windows is very easy: (...) var VCanvas: TControlCanvas; begin VCanvas := TControlCanvas.Create; try VCanvas.Control := Edit1; VCanvas.TextOut(0, 0, 'Test'); finally VCanvas.Free; end; end; (...) But, this code don't works in Linux (Ubuntu 11.04 / GTK2).

It most probably doesn't work on a Mac, where painting is allowed only in during WM_PAINT.

What the alternative to draw text in a TWinControl (GTK2)?

Invalidate the control, and wait for it's OnPaint request.

DoDi

Reply by email

zeljko
to silvioprog: My test in attached. Work only in Windows. x( Win: http://imagebin.org/177323 Linux:…
silvioprog wrote
My test in attached. Work only in Windows. x(

Yes, because widgetsets draws it's native controls, and some doesn't support painting outside of paint event (carbon, qt).
But even with that you can do such things. There's example on my wiki page how to paint whatever over TEdit control with qt widgetset (bottom of page). http://wiki.lazarus.freepascal.org/User:Zeljan

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111004/510bf73d/attachment.html>

Reply by email

Felipe Monteiro de Carvalho
to silvioprog: In Windows is very easy: (...) var VCanvas: TControlCanvas; begin VCanvas :=…
silvioprog wrote
What the alternative to draw text in a TWinControl (GTK2)?

I would say that you should never try to draw anything or do any other attempt to customize a native control. If you do, you are guaranting that your code will not work in all widgetsets.

The real solution is to not use TEdit for this case, but instead create a TCDEdit which would be a custom drawn version of TEdit. There are already many custom drawn controls here:

http://wiki.lazarus.freepascal.org/Lazarus_Custom_Drawn_Controls

But not currently TCDEdit, but patches are welcome.

Felipe Monteiro de Carvalho

Reply by email

silvioprog
to zeljko: Yes, because widgetsets draws it's native controls, and some doesn't support painting…

2011/10/4 zeljko :

Show quoted text 10 lines
Yes, because widgetsets draws it's native controls, and some doesn't support painting outside of paint event (carbon, qt). But even with that you can do such things. There's example on my wiki page how to paint whatever over TEdit control with qt widgetset (bottom of page). http://wiki.lazarus.freepascal.org/User:Zeljan zeljko

I saw the Qt code, but don't know how to do this in GTK.

My intention was to create a placeholder without working in methods RealGetText/RealSetText. In Windows I can easily do with:

(...)
const
  ECM_FIRST = $1500;
  EM_SETCUEBANNER = ECM_FIRST + 1;
begin
  Edit1.Perform(EM_SETCUEBANNER, 0, LParam(PWideChar(WideString('Test'))));
end;
(...)

I gave up trying to do in GTK, with canvas. x(

Thanks to all.

Silvio Cl?cio =============================================== Blog - <silvioprog.com.br> Twitter - <twitter.com/silvioprog> Facebook - <facebook.com/silvioprog> LazSolutions - <code.google.com/p/lazsolutions> LazWebSolutions - <code.google.com/p/lazwebsolutions> Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR> =============================================== ? ?* Conhe?a nosso canal IRC sobre Lazarus: #lazarus-br * ===============================================

Reply by email

zeljko
to silvioprog
silvioprog wrote 5 lines
2011/10/4 zeljko : I saw the Qt code, but don't know how to do this in GTK. My intention was to create a placeholder without working in methods RealGetText/RealSetText. In Windows I can easily do with:

Point is clear: WS must draw controll, after that you must be able to do some custom paints over it, or you can completely draw control. Some time ago I've thinking about adding 2 flags into TWinControl TControlStyle - csOwnerDraw and csOwnerDrawFull. They are valid only for ws controls which are fully painted from widgetset.
1.csOwnerDraw - control is painted by ws but after that paint message is delivered to LCL, so you can edd eg. small red triangle in TEdit corner. 2.csOwnerDrawFull - control is fully drawn by you, when an paint event occurs it's delivered to LCL, but stopped for ws, so it won't do any additional paintings.

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111005/4bb7184a/attachment.html>

Reply by email