Recent

Author Topic: [SOLVED] [RichMemo] how to change the default font color ?  (Read 8574 times)

ROCABDEL

  • New Member
  • *
  • Posts: 41
hi everyone  :)
thank you skalogryz for your good work.
a little question how to change the default font color without using
SetRangeColor or SetTextAttributes.. ?
« Last Edit: May 28, 2015, 11:23:13 pm by ROCABDEL »
Processor:IntelCore 2 2.19GHz - RAM 2GB
(Lazarus1.0.4 / fpc2.6.0 / qt4.7.3 at4pas2.5 / Xcode4.0)
-Windows 7/8-Intel Mac OS X 10.6.8-Haiku-Openidiana,Solaris11-PC-BSD,GhostBSD-openSUSE,Ubuntu,Fedora,mageia,Sabayon,Chakra..

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2291
    • havefunsoft.com
Re: [RichMemo] how to chance the default font color ?
« Reply #1 on: May 21, 2015, 09:36:02 pm »
If RichMemo is empty (not text) you could assign value to Font property. It would do the trick.

There's no equal replacement for TRichEdit's DefAttributes in RichMemo (yet).

Rich-edit components typically use the font "under" the cursor. Thus "default" font would always apply at the end of the text.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

ROCABDEL

  • New Member
  • *
  • Posts: 41
Re: [RichMemo] how to chance the default font color ?
« Reply #2 on: May 22, 2015, 01:16:31 pm »
I did the test under Windows unfortunately, the trick does not work .
may be if I manage to understand RTF I could find a light solution to do  ( edit RTF code directly)  :)
Processor:IntelCore 2 2.19GHz - RAM 2GB
(Lazarus1.0.4 / fpc2.6.0 / qt4.7.3 at4pas2.5 / Xcode4.0)
-Windows 7/8-Intel Mac OS X 10.6.8-Haiku-Openidiana,Solaris11-PC-BSD,GhostBSD-openSUSE,Ubuntu,Fedora,mageia,Sabayon,Chakra..

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2291
    • havefunsoft.com
Re: [RichMemo] how to chance the default font color ?
« Reply #3 on: May 22, 2015, 04:17:39 pm »
I did the test under Windows unfortunately, the trick does not work .
Are you looking for Windows only solution?  ::)
« Last Edit: May 22, 2015, 04:50:38 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

ROCABDEL

  • New Member
  • *
  • Posts: 41
Re: [RichMemo] how to chance the default font color ?
« Reply #4 on: May 22, 2015, 08:44:48 pm »
Gtk2 and qt on windows work like a charm, in linux I can change color through Object Inspector  :)  I encounter the problem only under win32 Widget.
thank you again Mr skalogryz  ;)
Processor:IntelCore 2 2.19GHz - RAM 2GB
(Lazarus1.0.4 / fpc2.6.0 / qt4.7.3 at4pas2.5 / Xcode4.0)
-Windows 7/8-Intel Mac OS X 10.6.8-Haiku-Openidiana,Solaris11-PC-BSD,GhostBSD-openSUSE,Ubuntu,Fedora,mageia,Sabayon,Chakra..

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2291
    • havefunsoft.com
Re: [RichMemo] how to chance the default font color ?
« Reply #5 on: May 22, 2015, 10:15:59 pm »
could you please try the following test?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

ROCABDEL

  • New Member
  • *
  • Posts: 41
Re: [RichMemo] how to chance the default font color ?
« Reply #6 on: May 23, 2015, 08:46:53 am »
I tried it, and I added this line
Code: [Select]
RichMemo1.Font.Color:= clBlue;On win32 widget change the font Color it does not work for me  ;D
Processor:IntelCore 2 2.19GHz - RAM 2GB
(Lazarus1.0.4 / fpc2.6.0 / qt4.7.3 at4pas2.5 / Xcode4.0)
-Windows 7/8-Intel Mac OS X 10.6.8-Haiku-Openidiana,Solaris11-PC-BSD,GhostBSD-openSUSE,Ubuntu,Fedora,mageia,Sabayon,Chakra..

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: [RichMemo] how to chance the default font color ?
« Reply #7 on: May 23, 2015, 01:10:52 pm »
Richmemo needs a small addition I think (not 100% sure skalogryz should confirm) do the following
1) locate the TCustomRichMemo class in the RichMemo.pas file
2) add the following line in the classes protected section.
Code: [Select]
procedure FontChanged(Sender :TObject); override;
3) add the following implementation in the implementation section of the unit/
Code: [Select]
procedure TCustomRichMemo.FontChanged(Sender :TObject);
var
  vTmp : TFontParams;
  procedure FontToParams;
  begin
    vTmp.Name := Font.Name;
    vTmp.Size := Font.Size;
    vTmp.Color := Font.Color;
    vTmp.Style := Font.Style;
  end;

begin
  inherited FontChanged(Sender);
  GetTextAttributes(SelStart,vTmp);
  FontToParams;
  SetTextAttributes(SelStart, SelLength, vTmp);
end;
and do your test to see if the default font properties are changed.

Disclaimer :
Although the code was compiled it was never tested so be ready to fiddle around with it.
« Last Edit: May 23, 2015, 01:13:27 pm by taazz »
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

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2291
    • havefunsoft.com
Re: [RichMemo] how to chance the default font color ?
« Reply #8 on: May 24, 2015, 06:50:03 am »
2 ROCABDEL: please try r4148.

2 taazz: in general the suggested approach is good, however, since the issue with win32 only, I see no need to put such code into TCustomRichMemo. It could be resolved in win32 only.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: [RichMemo] how to chance the default font color ?
« Reply #9 on: May 24, 2015, 01:25:52 pm »
since I have your attention let me ask one more thing, add a CanPaste method. In most cases an enumeration of the existing clipboard formats to find a compatible one should be run although I think that on windows some kind of message might exists to answer that specific question.
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

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2291
    • havefunsoft.com
Re: [RichMemo] how to chance the default font color ?
« Reply #10 on: May 24, 2015, 05:51:22 pm »
since I have your attention let me ask one more thing, add a CanPaste method. In most cases an enumeration of the existing clipboard formats to find a compatible one should be run although I think that on windows some kind of message might exists to answer that specific question.
Hmm.. what's the purpose of CanPaste? Isn't fine to call Paste and let it fail?

The reason I'm asking is that I don't want to implement CanPaste, if it's implementable in Windows only :)
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: [RichMemo] how to chance the default font color ?
« Reply #11 on: May 24, 2015, 06:33:43 pm »
since I have your attention let me ask one more thing, add a CanPaste method. In most cases an enumeration of the existing clipboard formats to find a compatible one should be run although I think that on windows some kind of message might exists to answer that specific question.
Hmm.. what's the purpose of CanPaste? Isn't fine to call Paste and let it fail?

The reason I'm asking is that I don't want to implement CanPaste, if it's implementable in Windows only :)
enable/disable any menu /toolbar items assotiated with the a TRichMemoPasteAction class. In its simplest form that would be enabled if the clipboard has any kind of contents or it is empty.
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

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2291
    • havefunsoft.com
Re: [RichMemo] how to chance the default font color ?
« Reply #12 on: May 25, 2015, 03:02:24 am »
enable/disable any menu /toolbar items assotiated with the a TRichMemoPasteAction class. In its simplest form that would be enabled if the clipboard has any kind of contents or it is empty.
r4149. The method canPaste in introduced. Supposed to work in Win32. All other widgetsets would return true not matter what.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: [RichMemo] how to chance the default font color ?
« Reply #13 on: May 25, 2015, 10:10:28 am »
thank you for your efforts.
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

ROCABDEL

  • New Member
  • *
  • Posts: 41
Re: [RichMemo] how to chance the default font color ?
« Reply #14 on: May 25, 2015, 05:57:29 pm »
@taazz: thank you for your attention and for you constructive contributions  :)
@skalogryz: many thanks for your great support  ;)

Processor:IntelCore 2 2.19GHz - RAM 2GB
(Lazarus1.0.4 / fpc2.6.0 / qt4.7.3 at4pas2.5 / Xcode4.0)
-Windows 7/8-Intel Mac OS X 10.6.8-Haiku-Openidiana,Solaris11-PC-BSD,GhostBSD-openSUSE,Ubuntu,Fedora,mageia,Sabayon,Chakra..