richedit to richviewedit

General TRichView support forum. Please post your questions here
Post Reply
sr1111
Posts: 27
Joined: Thu Jan 31, 2008 12:18 pm

richedit to richviewedit

Post by sr1111 »

this procedure runner for richedit but
How can I convert to richviewedit

I want to make in the richviewedit1 in the text, only as this url http://www.islamharfleri.com/risale/ris ... _6_01.html


procedure TForm1.richedit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
Pt: TPoint;
s: string;
begin
with TRichEdit(Sender) do
begin
Pt := Point(X, Y);
iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
if iCharIndex < 0 then Exit;
iLineIndex := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
if Lines.Count - 1 < iLineIndex then Exit;
s := Lines[iLineIndex];
i := iCharOffset + 1;
while (i > 0) and (s <> ' ') do Dec(i);
j := iCharOffset + 1;
while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
Caption := Copy(s, i, j - i);
end;
end;
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If I understand correctly, you need a word (characters between spaces) below the mouse pointer.

Code: Select all

procedure TForm1.RichViewEdit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 
var delim: String;
begin
  delim := RichViewEdit1.Delimiters;
  RichViewEdit1.Delimiters := ' '; // using only space chars as delimiters
  Caption := RichViewEdit1.GetWordAt(X, Y);
  RichViewEdit1.Delimiters := delim;
end;
sr1111
Posts: 27
Joined: Thu Jan 31, 2008 12:18 pm

Post by sr1111 »

I see as some bug

could you research

1-GetWordAtW(X, Y) or GetWordAt(X, Y) not support arabic charset, unicode


2- X,Y not correct origin

sRichViewEdit1.RichViewEdit.GetWordAt(X, Y); x,y not correct

(x,y) = (X+50, Y+20) origin
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

These method support Arabic and Unicode (GetWordAt returns String, so for Delphi 4-2007 Unicode text is converted to ANSI). Some versions of TRichView had problem with this method, but in version 11 it must be ok.

The code I gave to you was to TRichView/TRichViewEdit. For ScaleRichView, convert coordinates from ScaleRichView coordinates to coordinates of internal TRichViewEdit:

Code: Select all

procedure TForm3.SRichViewEdit1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
var pt: TPoint;
  InPageArea, InLeftArea, InTextArea: Boolean;
  Delim: String;
begin
  pt := SRichViewEdit1.ConvertSRVtoRV(Point(X, Y), InTextArea, InLeftArea, InPageArea);
  if InTextArea then begin
    Delim := SRichViewEdit1.RichViewEdit.Delimiters;
    SRichViewEdit1.RichViewEdit.Delimiters := ' ';
    Caption := SRichViewEdit1.RichViewEdit.GetWordAt(pt.X, pt.Y);
    SRichViewEdit1.RichViewEdit.Delimiters := Delim;
  end;
end;
sr1111
Posts: 27
Joined: Thu Jan 31, 2008 12:18 pm

Post by sr1111 »

I do test it .rtf files not support Arabic but rvf files support GetWordAtW and GetWordAt for delphi 2009 and Trial version TRichView 11.0.2, RichViewActions 1.69.1, ScaleRichView 2.0.3

and

convert coordinates from ScaleRichView, very good runner

thanks
Last edited by sr1111 on Tue Dec 30, 2008 4:04 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please send me arabic text as RVF file, I'll try to see what's wrong.
There must not be difference if the text is Arabic or English for this method.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I tried ScaleRichView ActionTest demo in Delphi 2009, loaded arabic.rtf (you sent to me previously), and this code worked correctly.
But you must be sure that RTF text is loaded as Unicode text. Make sure that SRichViewEdit1.RTFReadProperties.UnicodeMode = rvruOnlyUnicode.
This value is set by default in new Delphi/C++Builder 2009 project, but when you load existing project, it may be set to a different value.
sr1111
Posts: 27
Joined: Thu Jan 31, 2008 12:18 pm

Post by sr1111 »

thanks, thanks

I do now test it
UnicodeMode = rvruOnlyUnicode support nice
but UnicodeMode = rvruMixed not support


question
how can I appply textout command or alternative a way this up procedure(SRichViewEdit1MouseMove)
as this url
http://www.islamharfleri.com/risale/ris ... _6_01.html
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for "mixed" mode. In this mode, RTF text was loaded as ANSI. So when you call Unicode version of GetWordAt, text is converted from ANSI to Unicode. For this conversion, a code page specified in SRichViewEdit.RichViewEdit.Style.DefCodePage is used. By default it is CP_ACP, i.e. the default system code page is used. If it is not the Arabic code page, Arabic word will not be returned properly.
I just changed the code to use the text charset, if specified. So in the next update the code will work both for "only unicode" and "mixed" modes, regardless of the system code page.
---
You can try using custom drawing events, for example TRVStyle.OnDrawStyleText. To assign TRVStyle events at design time, place TRVStyle component on the form, and assign it to SRichViewEdit1.ExternalRVStyle property.
Note that s parameter is TRVRawByteString, not String. To convert it to String, use this function

Code: Select all

{$I RV_Defs.inc}
// Converting text from internal representation to String
function ConvertItemTextToString(const ItemText: TRVRawByteString;
  UnicodeItem: Boolean; CodePage: Cardinal): String;
begin
  {$IFDEF RVUNICODESTR} // <-- declared in RV_Defs.inc
  // Delphi 2009+: String is Unicode
  if UnicodeItem then
    Result := RVU_RawUnicodeToWideString(ItemText)
  else
    Result := RVU_RawUnicodeToWideString(
      RVU_AnsiToUnicode(CodePage, ItemText));
  {$ELSE}
  // Delphi 4-2007: String is ANSI
  if UnicodeItem then
    Result := RVU_UnicodeToAnsi(CodePage, ItemText)
  else
    Result := ItemText;
  {$ENDIF}
end;

Code: Select all

procedure TForm1.RVStyle1DrawStyleText(Sender: TRVStyle;
  const s: TRVRawByteString; Canvas: TCanvas; StyleNo, SpaceBefore, Left,
  Top, Width, Height: Integer; DrawState: TRVTextDrawStates;
  var DoDefault: Boolean);
var Text: String;
begin
  Text := ConvertItemTextToString(s, Sender.TextStyles[StyleNo].Unicode, Sender.DefCodePage);
  ...
end;
Post Reply