Detecting if a character is an InsertPoint

  • There are several functions within my application that need, as a part of them, to determine if a position's attribute is afsInsertPoint or afsAutomatic.

    In WPTools 3, I would do something like:

    Code
    if( afsIsInsertPoint in <TWPRichText>CPAttr^.Style ) then  CPMoveNext


    or

    Code
    WPRichText1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    var
      pa : PTAttr;
    begin
      pa := GetAttrAtXY(x,y);
      if( not ( ( afsIsInsertpoint in pa^.style ) or
                ( afsAutomatic     in pa^.style ) or
                ( afsIsObject in pa^.Style ) ) ) then
              DisplayLineAndCol;
    end;

    How would the above operations be done in WPTools 5?

    Grüsse,
    diamond

  • Julian,

    Yes, I'm talking to myself, well, answering myself. Please, correct any of this that's wrong.

    After I posted the question, I looked a bit through WPPRrtf.Pas and saw some code that might answer my question, at least in part:

    Code
    var
       obj : TWPTextObj;
    begin
      obj := RtfTextEdit.CPAttr.GetObject;
      if (obj<>nil) and (obj.ObjType=wpobjMergeField) then
         CPMoveNext


    Is there a different, or more elegant, way to achieve the same thing?

    There's still the question of my second situation (the GetAttrAtXY instance).

    diamond

    • Offizieller Beitrag

    Hi Diamond,

    Your solution is 100% correct.

    An alternative is
    obj := WPRichText.TextObjects.AtCP

    or my favourite:
    WPRichText1.TextCursor.ObjAtCP
    There is also NextObjAtCP and PrevObjAtCP (which move the cursor)

    Please note: To check for afsAutomatic the above won't work. afsAutomatic is not used anymore. Text which is inside of a fields (always two insertpoints) has to be detected by
    function OpenCodeAt(par: TParagraph; PosInPar: Integer;
    CheckedCodes: TWPTextObjTypes): TWPTextObj;
    or
    function OpenCodesAtCP(List: TWPTextObjList; Code: TWPTextObjType): TWPTextObj;

    The 'code' functions usually expect a SET to select the object type you are interested in, such as [wpobjMergeField]


    To get the insertpoint at a certain X,Y position use

    function TWPRichText.CodeObjectAtXY(x, y: Integer; var Code: TWPTextObj): Boolean;

    Julian

  • Thank you for this!

    As a follow-up to the question of afsAutomatic, at some places in my code, if the user has the text cursor somewhere in a merge field, I need to advance the cursor to the end of the field before I perform the appropriate operation. How would this work in WPTools 5?

    And just to be sure, you say "Text which is inside of a fields (always two insertpoints) has to be detected by...". Is that (the "always two insertpoints" statement) equally true with documents already created with WPTools 3, or is that the case only with newly created documents?

    diamond

    • Offizieller Beitrag

    Hi,

    >> at some places in my code, if the user has the text cursor somewhere in a merge field, I need to advance the cursor to the end of the field before I perform the appropriate operation. How would this work in WPTools 5? <<

    Each 'Code' (which the TWPTextObjects for merge fields, hyperlinks etc) are also called (see the Code.. functions in WPCtrMemo) has a property 'EndTag'.

    This EndTag is also a TWPTextObj and of course can be nil. Assign EndTag to TextObjects.AtCP and the cursor will sit in front of it.

    Please note that the TWPTextObj class has properties for the host paragraph and the position in it.

    Julian Ziersch