richedit to richviewedit
richedit to richviewedit
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;
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;
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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;
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
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;
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
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.
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
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
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
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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
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;