diff --git a/components/richmemo/richmemo.pas b/components/richmemo/richmemo.pas index 717ba4a6b..1c380ee6d 100644 --- a/components/richmemo/richmemo.pas +++ b/components/richmemo/richmemo.pas @@ -211,9 +211,10 @@ end; function TCustomRichMemo.GetStyleRange(CharOfs: Integer; var RangeStart, RangeLen: Integer): Boolean; begin - if HandleAllocated then - Result := TWSCustomRichMemoClass(WidgetSetClass).GetStyleRange(Self, CharOfs, RangeStart, RangeLen) - else begin + if HandleAllocated then begin + Result := TWSCustomRichMemoClass(WidgetSetClass).GetStyleRange(Self, CharOfs, RangeStart, RangeLen); + if Result and (RangeLen = 0) then RangeLen := 1; + end else begin RangeStart := -1; RangeLen := -1; Result := false; diff --git a/components/richmemo/win32/win32richmemo.pas b/components/richmemo/win32/win32richmemo.pas index 75b0531e5..9361e9dc9 100644 --- a/components/richmemo/win32/win32richmemo.pas +++ b/components/richmemo/win32/win32richmemo.pas @@ -42,6 +42,8 @@ type TWin32WSCustomRichMemo = class(TWSCustomRichMemo) published + class procedure SetColor(const AWinControl: TWinControl); override; + class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override; class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override; @@ -92,6 +94,13 @@ end; { TWin32WSCustomRichMemo } +class procedure TWin32WSCustomRichMemo.SetColor(const AWinControl: TWinControl); +begin + // this methos is implemented, because Win32RichMemo doesn't use + // default LCL WM_PAINT message! + SendMessage(AWinControl.Handle, EM_SETBKGNDCOLOR, 0, AWinControl.Color); +end; + class procedure TWin32WSCustomRichMemo.SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); var range : Tcharrange; @@ -151,8 +160,10 @@ begin Flags := Flags and not WS_HSCROLL else Flags := Flags or ES_AUTOHSCROLL; + if ACustomMemo.BorderStyle=bsSingle then FlagsEx := FlagsEx or WS_EX_CLIENTEDGE; + pClassName := @RichClass[1]; WindowTitle := StrCaption; end; @@ -185,19 +196,23 @@ begin RichEditManager.SetSelectedTextStyle(AWinControl.Handle, Params); end; -class function TWin32WSCustomRichMemo.GetTextAttributes( - const AWinControl: TWinControl; TextStart: Integer; var Params: TIntFontParams - ): Boolean; +class function TWin32WSCustomRichMemo.GetTextAttributes(const AWinControl: TWinControl; + TextStart: Integer; var Params: TIntFontParams): Boolean; var OrigStart : Integer; OrigLen : Integer; NeedLock : Boolean; + eventmask : LongWord; begin + writeln('[GetTextAttributes] begin'); if not Assigned(RichEditManager) or not Assigned(AWinControl) then begin Result := false; Exit; end; + eventmask := SendMessage(AWinControl.Handle, EM_GETEVENTMASK, 0, 0); + SendMessage(AWinControl.Handle, EM_SETEVENTMASK, 0, 0); + RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen); NeedLock := (OrigStart <> TextStart); @@ -207,8 +222,14 @@ begin Result := RichEditManager.GetSelectedTextStyle(AWinControl.Handle, Params ); RichEditManager.SetSelection(AWinControl.Handle, OrigStart, OrigLen); UnlockRedraw(AWinControl.Handle); - end else + end else begin + LockRedraw(AWinControl.Handle); Result := RichEditManager.GetSelectedTextStyle(AWinControl.Handle, Params); + UnlockRedraw(AWinControl.Handle); + end; + + SendMessage(AWinControl.Handle, EM_SETEVENTMASK, 0, eventmask); + writeln('[GetTextAttributes] end'); end; @@ -236,12 +257,16 @@ var vInfo : TScrollInfo; hVisible : Boolean; vVisible : Boolean; + eventmask : longword; begin if not Assigned(RichEditManager) or not Assigned(AWinControl) then begin Result := false; Exit; end; + eventmask := SendMessage(AWinControl.Handle, EM_GETEVENTMASK, 0, 0); + SendMessage(AWinControl.Handle, EM_SETEVENTMASK, 0, 0); + RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen); LockRedraw(AWinControl.Handle); InitScrollInfo(hInfo); @@ -261,6 +286,8 @@ begin if vVisible then SetScrollInfo(AWinControl.Handle, SB_Vert, vInfo, false); RichEditManager.SetSelection(AWinControl.Handle, OrigStart, OrigLen); UnlockRedraw(AWinControl.Handle, false); + + SendMessage(AWinControl.Handle, EM_SETEVENTMASK, 0, eventmask); end; class function TWin32WSCustomRichMemo.LoadRichText( diff --git a/components/richmemo/win32/win32richmemoproc.pas b/components/richmemo/win32/win32richmemoproc.pas index 6b2da1e9b..8f82cce9a 100644 --- a/components/richmemo/win32/win32richmemoproc.pas +++ b/components/richmemo/win32/win32richmemoproc.pas @@ -48,7 +48,6 @@ type class procedure SetHideSelection(RichEditWnd: Handle; AValue: Boolean); virtual; class function LoadRichText(RichEditWnd: Handle; ASrc: TStream): Boolean; virtual; class function SaveRichText(RichEditWnd: Handle; ADst: TStream): Boolean; virtual; - end; TRichManagerClass = class of TRichEditManager; @@ -77,13 +76,14 @@ end; function InitRichEdit: Boolean; begin if GlobalRichClass = '' then begin - if LoadLibrary('Msftedit.dll') <> 0 then begin - GlobalRichClass := 'RichEdit50W' + if LoadLibrary('Msftedit.dll') <> 0 then begin + GlobalRichClass := 'RichEdit50W'; end else if LoadLibrary('RICHED20.DLL') <> 0 then begin if UnicodeEnabledOS then GlobalRichClass := 'RichEdit20W' else GlobalRichClass := 'RichEdit20A' - end else if LoadLibrary('RICHED32.DLL') <> 0 then + end else if LoadLibrary('RICHED32.DLL') <> 0 then begin GlobalRichClass := 'RichEdit'; + end; if not Assigned(RichEditManager) then RichEditManager := TRichEditManager; @@ -208,7 +208,7 @@ begin Result := false; if RichEditWnd = 0 then Exit; - textlen.flags := GTL_DEFAULT or GTL_NUMCHARS; + textlen.flags := GTL_NUMCHARS or GTL_USECRLF or GTL_PRECISE; textlen.codepage := CP_UNICODE; len := SendMessage(RichEditWnd, EM_GETTEXTLENGTHEX, WPARAM(@textlen), 0);