Recent

Author Topic: [SOLVED] RichMemo bug clearing background colour, linux only  (Read 3597 times)

dbannon

  • Hero Member
  • *****
  • Posts: 602
    • tomboy-ng, a rewrite of the classic Tomboy
[SOLVED] RichMemo bug clearing background colour, linux only
« on: August 05, 2017, 03:13:49 am »
Hi Folks,
I find that RichMemo1.SetRangeParams() is unable to clear a background colour after it has been set. Here is simple test case, on a clear form, drop a RichMemo and a button, make the button code look like this -

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.      TP : TFontParams;
  4. begin
  5.     RichMemo1.Clear;
  6.     RichMemo1.Append('Some text, lets highlight');
  7.     TP.BkColor:= clYellow;
  8.     TP.HasBkClr := true;
  9.     RichMemo1.SetRangeParams(3,15,[tmm_BackColor], TP, [], []);
  10.     TP.HasBkClr := false;
  11.     RichMemo1.SetRangeParams(5,13,[tmm_BackColor], TP, [], []);
  12. end;
Under linux (Ubuntu mate, gtk2) the middle section remains highlighted, on windows its restored to unhighlighted, or normal text.

Any thoughts ?

Davo
« Last Edit: August 09, 2017, 10:41:40 am by dbannon »
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2242
    • havefunsoft.com
Re: RichMemo bug clearing background colour, linux only
« Reply #1 on: August 05, 2017, 03:34:52 am »
Instead of setting HasBKColor to false, try to setup bkColor to clDefault
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

dbannon

  • Hero Member
  • *****
  • Posts: 602
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo bug clearing background colour, linux only
« Reply #2 on: August 05, 2017, 04:44:13 am »
Quote
....try to setup bkColor to clDefault

yeah, good idea. Actually, clDefault seems to be black, but $FFFFFF does, apparently achieve what I want. I'm reading the actual text properties to turn it into some xml so I'll need to fiddle to ensure no background colour is the same as a background colour of $FFFFFF but this gets me going again.

Thanks skalogryz.

By the way, are you aware that the certificate for havefunsoft.com has expired ?
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2242
    • havefunsoft.com
Re: RichMemo bug clearing background colour, linux only
« Reply #3 on: August 05, 2017, 05:00:39 am »
Historical note: HasBkColor is a flag to indicate if Params structure has background color field populated or should it be ignored.
Thus in order to clear the background, hasBKColor must be set to true.


Thanks. I got notifications about certificate exporation, several weeks ago, but got lazy. Besides I was planning to change the issuing authority. Should fix it this weekend
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

dbannon

  • Hero Member
  • *****
  • Posts: 602
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo bug clearing background colour, linux only
« Reply #4 on: August 05, 2017, 05:24:15 am »
Quote
Thus in order to clear the background, hasBKColor must be set to true.

Ah, that makes sense. Thanks.

Are you really doing this at 5 am ?   :o

David
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2242
    • havefunsoft.com
Re: RichMemo bug clearing background colour, linux only
« Reply #5 on: August 05, 2017, 05:28:27 am »
It's much more quiet overnight
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

dbannon

  • Hero Member
  • *****
  • Posts: 602
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo bug clearing background colour, linux only
« Reply #6 on: August 09, 2017, 10:41:10 am »
OK Folks, for the record, this is what I do, it works under both Linux and Windows.
This gets called after a user has selected some text, it toggles on and off.

Quote
if RichMemo1.GetTextAttributes(RichMemo1.SelStart, TP) then begin
          TP.HasBkClr := true;
          if  TP.BkColor = clYellow then
              TP.BkColor := $FFFFFF
          else  TP.BkColor := clYellow;
          RichMemo1.SetRangeParams( RichMemo1.SelStart,RichMemo1.SelLength, [tmm_BackColor], TP, [], []);
end; 
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng