interpreting styles in the program

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
toolwiz
Posts: 150
Joined: Wed Nov 30, 2005 3:27 am

interpreting styles in the program

Post by toolwiz »

Usually when I've worked with RichViews, I have a Style component on the form. I can see what's there and know how to find things in it.

Using SRV, if the user highlights a selection, I can call GetSelectionBounds and identify the item that's been selected. In most cases, in my current app, this'll be a word or phrase that's within one or that spans two items, since the input has been broken into one item per line.

What I need now is when someone highlights a word or phrase that is either a URL, email address, or that represents a URL or email address. Usually I'd test to see if its style# is the same as the one in the Style component that's designated as a URL or Hotlink or something.

But all of the styles in the SRV are embedded inside and they can't be accessed directly (from the IDE).

So ... how do you find out if a given ItemNo selected in the SRV window represents a word or phrase that has a URL or email address attached to it?

Is there a "standard Styles list" defined somewhere? Or are they named?

In my case, the contents of the RVE are normally being created as a result of an Insert File... and reading something like a Word document. It's also possible that they can be created directly within the document itself.

I need to be able to have my program recognize a selection as a URL or "anchor tag" and edit the underlying link. Also, if a URL is typed directly into the document, and someone later selects it, I need to be able to edit it.

That's through my own dialog box, not the built-in "hyperlink" button.

(The built-in "hyperlink" button doesn't seem to recognize that a selected item IS a hyperlink, even though it's displayed in blue with an underline. That is, when I select a hyperlink and click that button, there's no link in the edit box; it's empty. So _something_ is recognizing URLs and email addresses, but not the button you'd expect to do so.)


I also need to know how to set up hyperlinks behind an image -- so when you click on an image, it acts like a text hyperlink.

eg., <a href="myurl"><img href="image"></a>

I don't know if this is a different style, or a property of the image, or something else.

Thanks
-David
proxy3d
ScaleRichView Developer
Posts: 307
Joined: Mon Aug 07, 2006 9:37 am

Post by proxy3d »

RvStyle1 - external component TRVStyle on the form.

procedure TForm1. FormCreate (Sender: TObject);
begin
SRV.RichViewEdit.Style: = RvStyle1;
....
proxy3d
ScaleRichView Developer
Posts: 307
Joined: Mon Aug 07, 2006 9:37 am

Post by proxy3d »

Now I have finished adaptation of examples RichView under ScaleRichView. Together with new release, examples SRV will be updated all.

modified example delphidemos\Delphi\Tutorial\2 Items-Checkpoints-Tags-Hypertext\5 Hypertext ID

Code: Select all

unit Unit1;

interface

{==============================================================================}
{ Demo of basic using of hypertext                                             }
{ In this demo were modified styles: RVStyle1.TextStyles[4] and                }
{ RVStyle.TextStyles[5]                                                        }
{ Setting RVStyle.TextStyles[i].Jump to True turns this text style into        }
{ a hypertext style.                                                           }
{ Properties of text styles affecting hypertext appearance:                    }
{ - HoverColor (color of hypertext under mouse (clNone for not changing)       }
{ - HoverBackColor (color of hypertext background under mouse (clNone for      }
{   transparent)                                                               }
{ - JumpCursor                                                                 }
{------------------------------------------------------------------------------}
{ Key events and properties:                                                   }
{ - OnJump, OnRVMouseMove                                                      }
{ - FirstJumpNo                                                                }
{------------------------------------------------------------------------------}

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, RVStyle, RVScroll, RichView, SclRView;

type
  TForm1 = class(TForm)
    RVStyle1: TRVStyle;
    Label1: TLabel;
    Panel1: TPanel;
    srv: TSRichViewEdit;
    procedure FormCreate(Sender: TObject);
    procedure srvJump(Sender: TObject; id: Integer);
    procedure srvRVMouseMove(Sender: TObject; id: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  srv.SetMargin(5, 5, 5, 5);
  srv.RichViewEdit.Style := RVStyle1;
  srv.RichViewEdit.ReadOnly := True;

  // RVStyle1.TextStyles[4].Jump = RVStyle1.TextStyles[5].Jump = True
  // This causes these styles to represent hypertext
  srv.RichViewEdit.AddNL('Hypertext',1,1);
  srv.RichViewEdit.AddNL('Some text styles can be chosen as hypertext styles. ',0,0);
  srv.RichViewEdit.AddNL('Like this one.',4,-1);
  srv.RichViewEdit.AddNL(' You can have as many hypertext styles as you want.  ',0,-1);
  srv.RichViewEdit.AddNL('Here is one more.',5,-1);
  srv.RichViewEdit.Format;

  {
    The basic method to use hypertext is "hypertext IDs".
    All hypertext links are numbered sequentially (0,1,...) from the top of
    document to the bottom. These numbers are called "hypertext IDs".
    Hypertext id is passed in OnJump and OnRVMouseMove events.
  }
  {
    More correct, jumps are numbered as FirstJumpNo, FirstJumpNo+1,
    FirstJumpNo+2,...
    FirstJumpNo is a property of RichView, 0 by default
  }
end;

procedure TForm1.srvJump(Sender: TObject; id: Integer);
begin
  Panel1.Caption := 'Clicked: '+IntToStr(id);
end;

procedure TForm1.srvRVMouseMove(Sender: TObject; id: Integer);
begin
  // id=-1 when mouse leaves hypertext jump area
  if id<>-1 then
    Label1.Caption := IntToStr(id)
  else
    Label1.Caption := '---';
end;

end.
Post Reply