trichview.com

trichview.support




Re: Reset textstyle after inserting a hyperlink


Return to index


Author

Message

Sergey Tkachenko

Posted: 12/18/2004 21:02:57


A good idea is to close the hyperlink when user presses Enter or Space

characters at the end of the hyperlink.

Demos\CBuilder\Assorted\Hypertext\URLs\ works in this way.

RichViewActions also have method for that (and it's used in the ActionTest

demo).


But you need to know which text style to use for normal text.

I assume your code is based on the CreateHyperlink demo. This demo uses a

fixed set of styles, and the fixed style (with index = 4) for hyperlinks. If

you really want to work in this way, you can reset the current text style to

0.


void __fastcall TForm1::rveKeyDown(TObject *Sender, WORD &Key,

TShiftState Shift)

{

  if (Key==VK_SPACE || Key==VK_RETURN)

  {

    if (rve->CurTextStyleNo==rve->CurItemStyle &&

       rve->Style->TextStyles->Items[rve->CurTextStyleNo]->Jump &&

      ! rve->SelectionExists())

    {

      TCustomRichViewEdit* rve2 = rve->TopLevelEditor;

      if (rve2->OffsetInCurItem>=rve2->GetOffsAfterItem(rve2->CurItemNo))

        rve2->CurTextStyleNo = 0;

     }

  }

}


But if you want to change styles dynamically (for example, to implement

commands like "make bold", "apply font", etc.), using 0 for normal text and

4 for hypertext is not very good. For example, user may expect that new

hyperlinks have all attributes of the current text but blue and underlined.


There is an improved version of the CreateHyperlink demo:

http://www.trichview.com/support/files/createhyperlink.zip

The updated demo shows:

- how to create document with hyperlinks

- how to make hyperlink from the selected text (hyperlink is blue and

underlined)

- how to remove hyperlinks from the selected text (if user entered empty

hyperlink target)

- how to close hyperlinks when user presses Space or Enter key.


The old demo used a predefined hypertext text style (with index = 4).

This demo creates it dynamically, basing on the atributes of the selected

text (just makes it blue and underlined).


Unfortunately, it's available only for Delphi. Let me know if you have

problems in translation it in C++.




>

> Dear Sergey,

>

> Thank you for your support. It works!

>

> Still I have a problem:

> When I move the cursor around and start typing behind the hyperlink again,

> the style changes back to the hyperlinkstyle... :(

>

> Do you have a solution??

>

> Do I have to set a code in the OnChange event??

>

> Thanks.

>

> Pieter E.

>

> "Sergey Tkachenko" <[email protected]> wrote:

> >int OldStyleNo = rve->CurTextStyleNo;

> >rve->CurTextStyleNo = 4;

> >rve->ApplyTextStyle(rve->CurTextStyleNo);

> >rve->InsertStringTag(Edit2->Text, Integer(StrNew(Edit1->Text.c_str())));

> >rve->CurTextStyleNo = OldStyleNo;

> >

> >

>





Powered by ABC Amber Outlook Express Converter