Style changing back to undefined after multiple clicking

  • hi there

    i am setting styles (boldface) on a button:

    Code
    procedure TForm6.Button1Click(Sender: TObject);begin  wprichtext1.CurrAttr.TextStyle([afsBold], true);  refreshstylelabel;end;

    then i click into the wp-component, several times, and
    the style "all of a sudden" gets reverted back to undefined.
    i receive a OnCharacterAttrChange and in that i do a style refresh:

    Code
    procedure TForm6.WPRichText1CharacterAttrChange(Sender: TObject;  Attribute: TWPSetModeControl);begin  refreshstylelabel;end;

    where refreshstylelabel is:


    is this expected and if so why?

    full source: https://polypoint.egnyte.com/h-s/20111024/519d046e8fbe45b4

  • I have checked the "SelLength" on the "TextCursor", and it is always 0.

    To be clear, I have an empty WpRichtext (so SelLength=0 makes sense).
    I click the Button to set a Bold Style. I doubleclick (by accident) into the wprichtext (ahead of the cursor), and the style switches back. Similar, if I
    click (ahead of the cursor) but keep the mouse button pressed for a second or two, then release it. => the style switches back.

  • Ok I have isolated it further. All it takes is a single click (no wild clicking or button pressed).

    If I click into the wp-component "above" the textcursor, everything behaves fine.
    If I click into the wp-component at the same height (left or right makes no difference), then the style info gets lost.
    If I click below the textcursor, the style info gets lost as well.

    How can I work around this? I don't think this is expected or meant to be, but it causes me some serious trouble with a text-editor that is using wp as its richtext-component. :(

  • I can reproduce the problem properly now.
    A demo app (incl source) can be found at:
    https://polypoint.egnyte.com/h-s/20111026/88c319f91cb74ab7

    There are two basic cases:
    a) wprichtext is empty (no text)
    b) wprichtext has some text in it

    I am setting the style using three different ways:
    1) currattr
    2) writingattr
    3) cursor.writingattr
    They should all be equal as far as I can see, since I do not use text selection at all.

    In all scenario the cppos is at the very end of the text. I click into the wp-component beyond that point (right bottom corner, just not on top of the cursor).

    I check the style setting using wprichtext.writingattr and curattr. In my tests, both of them always return the same. The "GetStyles" method returns false in the cases where the style switches (this is expected, the style cannot be evaluated).

    Case a):
    1. set the style (either using 1),2),3))
    2. click into the wpcomponent (bottom right)
    => if set by currattr 1) => style switches
    => if set by the other two 2)3) => style stays

    case b):
    1. enter text
    2. set the style (ditto 1),2),3))
    3. click into wpcomponent (bottom right)
    => style switches for all three ways

    Why does it switch back? What am I missing in my demo program? The trouble is, this is a normal use case. The user clicks "boldface" and starts to type. It should stay "boldface", not switch back.

    Any clues?

    • Offizieller Beitrag

    If you click on the text it will read the Attribute from current text - if there is no bold text at the position of cursor, WritingTextAttr.GetStyle will return false. Thats normal and intended.


    Some notes:

    This code has no effect since the Cursor is an object which stays the same
    if wprichtext1.Memo.RTFData.Cursor <>pOldCursor then


    The TSpeedButton must have the ability to stay down - set GroupIndex and AllowAllUp in the Action.

    If there are no styles, GetFontStyle(fntStyle); fails.

    You need some code to delete a style, otherwise it cannot work.

    You seem to use RichEdit actions here - they don't work on WPTools.

    I am using this action:

    Code
    object BoldAction: TAction  Caption = 'BoldAction'  Checked = True  GroupIndex = 3  OnExecute = BoldActionExecuteend


    And this methods:

    As you probably noted, writingattr is the same as cursor.writingattr - Press ALT and click on WPRichText1.WritingAttr and you are there:

    function TWPCustomRtfEdit.WritingAttr: TWPCurrentWritingmodeAttrInterface;
    begin
    Result := FMemo.RTFData.Cursor.WritingTextAttr;
    end;