RichView.pas
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:142k
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.DeleteParas(FirstItemNo, LastItemNo: Integer);
- begin
- RVData.DeleteParas(FirstItemNo, LastItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetLineCount: Integer;
- begin
- Result := RVData.Items.Count;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SelectionExists: Boolean;
- begin
- Result := RVData.SelectionExists(True, True);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetSelectedImage: TGraphic;
- begin
- Result := RVData.GetSelectedImage;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetSelText: String;
- begin
- Result := RVData.GetSelText(False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.CopyText;
- begin
- RVData.CopyText;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.CopyTextW;
- begin
- RVData.CopyTextW;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.CopyImage;
- begin
- RVData.CopyImage;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.Copy;
- begin
- RVData.Copy(GetColor, Background);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.IsCopyShortcut(Shift: TShiftState; Key: Word): Boolean;
- begin
- Result := (ssCtrl in Shift) and ((Key = ord('C')) or (Key = VK_INSERT)) and not (ssAlt in Shift);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.IsCutShortcut(Shift: TShiftState; Key: Word): Boolean;
- begin
- Result := ((ssCtrl in Shift) and (Key = ord('X')) and not (ssAlt in Shift)) or
- ((ssShift in Shift) and (Key = VK_DELETE));
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.IsPasteShortcut(Shift: TShiftState; Key: Word): Boolean;
- begin
- Result := ((ssCtrl in Shift) and (Key = ord('V')) and not (ssAlt in Shift)) or
- ((ssShift in Shift) and (Key = VK_INSERT));
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.CopyDef: Boolean;
- begin
- Result := RVData.CopyDef(GetColor, Background);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMCopy(var Message: TWMCopy);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) then begin
- PostMessage(InplaceEditor.Handle, WM_COPY, 0, 0);
- exit;
- end;
- {$ENDIF}
- CopyDef;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.KeyDown(var Key: Word; Shift: TShiftState);
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- var LKey: Word;
- LShift: TShiftState;
- {$ENDIF}
- begin
- inherited KeyDown(Key,Shift);
- if IsCopyShortCut(Shift, Key) then
- SendMessage(Handle, WM_COPY, 0, 0);
- if (TabNavigation<>rvtnNone) and
- ((Key=VK_TAB) and not (ssAlt in Shift) and
- (((ssCtrl in Shift) and (TabNavigation=rvtnCtrlTab)) or
- (not (ssCtrl in Shift) and (TabNavigation=rvtnTab)))) then begin
- Exclude(RVData.State,rvstDoNotTab);
- RVData.DoTabNavigation(ssShift in Shift, Self);
- end;
- if (Key=VK_RETURN) then
- RVData.ExecuteFocused;
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- if TRichViewRVData(RVData.GetAbsoluteRootData).FSmartPopupButton<>nil then begin
- ShortCutToKey(
- TCustomRichView(TRichViewRVData(RVData.GetAbsoluteRootData).RichView).SmartPopupProperties.ShortCut, LKey, LShift);
- if (Key=LKey) and (Shift=LShift) then
- TRichViewRVData(RVData.GetAbsoluteRootData).FSmartPopupButton.Click;
- end;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GenerateMouseMove;
- var State: TShiftState;
- KeyboardState: TKeyboardState;
- p: TPoint;
- begin
- State := [];
- GetKeyboardState(KeyboardState);
- if KeyboardState[VK_SHIFT] and $80 <> 0 then Include(State, ssShift);
- if KeyboardState[VK_CONTROL] and $80 <> 0 then Include(State, ssCtrl);
- if KeyboardState[VK_MENU] and $80 <> 0 then Include(State, ssAlt);
- if KeyboardState[VK_LBUTTON] and $80 <> 0 then Include(State, ssLeft);
- if KeyboardState[VK_RBUTTON] and $80 <> 0 then Include(State, ssRight);
- if KeyboardState[VK_MBUTTON] and $80 <> 0 then Include(State, ssMiddle);
- GetCursorPos(p);
- p := ScreenToClient(p);
- if (p.X>=0) and (p.X<ClientWidth) and
- (p.Y>=0) and (p.Y<ClientHeight) then
- MouseMove(State,p.X,p.Y);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMTimer(var Message: TWMTimer);
- begin
- case Message.TimerID of
- RV_TIMERID_SCROLLING:
- begin
- //if RVData.CaptureMouseItem<>nil then exit;
- if VScrollDelta<>0 then
- VScrollPos := VScrollPos+VScrollDelta;
- if HScrollDelta<>0 then
- SetHPos(HPos+HScrollDelta);
- if (HScrollDelta<>0) or (VScrollDelta<>0) then begin
- {$IFDEF RVDEBUG}{$I Debugf.inc}{$ENDIF}
- RVData.OnTimerScroll;
- GenerateMouseMove;
- end;
- end;
- {$IFNDEF RVDONOTUSEANIMATION}
- RV_TIMERID_ANIMATION:
- begin
- if (TRichViewRVData(RVData).FAnimatorList=nil) or
- (TRichViewRVData(RVData).FAnimatorList.Count=0) then begin
- KillTimer(Handle, RV_TIMERID_ANIMATION);
- exit;
- end;
- TRichViewRVData(RVData).FAnimatorList.TimerEvent;
- if TRichViewRVData(RVData).FAnimatorList.LastMinInterval<>
- TRichViewRVData(RVData).FAnimatorList.MinInterval then begin
- SetTimer(Handle, RV_TIMERID_ANIMATION, TRichViewRVData(RVData).FAnimatorList.MinInterval, nil);
- TRichViewRVData(RVData).FAnimatorList.LastMinInterval :=
- TRichViewRVData(RVData).FAnimatorList.MinInterval
- end;
- end;
- {$ENDIF}
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.Loaded;
- begin
- inherited Loaded;
- UpdatePaletteInfo;
- Format;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.InplaceRedrawing(AllowRedrawItself: Boolean);
- begin
- if AllowRedrawItself then
- Refresh;
- if not FullRedraw or (InplaceEditor=nil) or not (InplaceEditor is TCustomRichView) then
- exit;
- TCustomRichView(InplaceEditor).InplaceRedrawing(True);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetAllowSelection: Boolean;
- begin
- Result := rvoAllowSelection in Options;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetSingleClick: Boolean;
- begin
- Result := rvoSingleClick in Options;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetAllowSelection(const Value: Boolean);
- begin
- if Value then
- Include(FOptions, rvoAllowSelection)
- else
- Exclude(FOptions, rvoAllowSelection)
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetSingleClick(const Value: Boolean);
- begin
- if Value then
- Include(FOptions, rvoSingleClick)
- else
- Exclude(FOptions, rvoSingleClick)
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetTabNavigation:TRVTabNavigationType;
- begin
- Result := RVData.TabNavigation;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetTabNavigation(const Value: TRVTabNavigationType);
- begin
- RVData.TabNavigation := Value;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SearchText(const s: String; SrchOptions: TRVSearchOptions): Boolean;
- begin
- Result := RVData.SearchText(rvsroDown in SrchOptions, rvsroMatchCase in SrchOptions,
- rvsroWholeWord in SrchOptions, s);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemStyle(ItemNo: Integer): Integer;
- begin
- Result := RVData.GetItemStyle(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetBreakInfo(ItemNo: Integer; var AWidth: Byte;
- var AStyle: TRVBreakStyle; var AColor: TColor;
- var ATag: Integer);
- begin
- RVData.GetBreakInfo(ItemNo, AWidth, AStyle, AColor, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetBulletInfo(ItemNo: Integer; var AName: String;
- var AImageIndex: Integer;
- var AImageList: TCustomImageList;
- var ATag: Integer);
- begin
- RVData.GetBulletInfo(ItemNo, AName, AImageIndex, AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetHotspotInfo(ItemNo: Integer; var AName: String;
- var AImageIndex, AHotImageIndex: Integer;
- var AImageList: TCustomImageList;
- var ATag: Integer);
- begin
- RVData.GetHotspotInfo(ItemNo, AName, AImageIndex, AHotImageIndex,AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetPictureInfo(ItemNo: Integer; var AName: String;
- var Agr: TGraphic; var AVAlign: TRVVAlign;
- var ATag: Integer);
- begin
- RVData.GetPictureInfo(ItemNo, AName, Agr, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetControlInfo(ItemNo: Integer; var AName: String;
- var Actrl: TControl; var AVAlign: TRVVAlign;
- var ATag: Integer);
- begin
- RVData.GetControlInfo(ItemNo, AName, Actrl, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetTextInfo(ItemNo: Integer; var AText: String;
- var ATag: Integer);
- begin
- RVData.GetTextInfo(ItemNo, AText, ATag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemTag(ItemNo: Integer): Integer;
- begin
- Result := RVData.GetItemTag(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetBreakInfo(ItemNo: Integer; AWidth: Byte;
- AStyle: TRVBreakStyle; AColor: TColor;
- ATag: Integer);
- begin
- RVData.SetBreakInfo(ItemNo, AWidth, AStyle, AColor, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetBulletInfo(ItemNo: Integer; const AName: String;
- AImageIndex: Integer;
- AImageList: TCustomImageList;
- ATag: Integer);
- begin
- RVData.SetBulletInfo(ItemNo, AName, AImageIndex, AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetHotspotInfo(ItemNo: Integer; const AName: String;
- AImageIndex, AHotImageIndex: Integer;
- AImageList: TCustomImageList;
- ATag: Integer);
- begin
- RVData.SetHotspotInfo(ItemNo, AName, AImageIndex, AHotImageIndex,
- AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SetPictureInfo(ItemNo: Integer; const AName: String;
- Agr: TGraphic; AVAlign: TRVVAlign;
- ATag: Integer): Boolean;
- begin
- Result := RVData.SetPictureInfo(ItemNo, AName, Agr, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SetControlInfo(ItemNo: Integer; const AName: String;
- AVAlign: TRVVAlign; ATag: Integer): Boolean;
- begin
- Result := RVData.SetControlInfo(ItemNo, AName, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetItemTag(ItemNo: Integer; ATag: Integer);
- begin
- RVData.SetItemTag(ItemNo, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetItemText(ItemNo: Integer; const s: String);
- begin
- RVData.Items[ItemNo] := s;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemText(ItemNo: Integer): String;
- begin
- Result := RVData.Items[ItemNo];
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetCheckpointInfo(ItemNo: Integer; ATag: Integer; const AName: String;
- ARaiseEvent: Boolean);
- begin
- RVData.SetCheckpointInfo(ItemNo, ATag, AName, ARaiseEvent);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.RemoveCheckpoint(ItemNo: Integer):Boolean;
- begin
- Result := RVData.RemoveCheckpoint(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetStyle(Value: TRVStyle);
- begin
- FStyle := Value;
- if (csDesigning in ComponentState) or
- (rvoFormatInvalidate in Options) then Invalidate;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.FindControlItemNo(actrl: TControl): Integer;
- begin
- Result := RVData.FindControlItemNo(actrl);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SelectControl(actrl: TControl): Boolean;
- begin
- Result := RVData.SelectControl(actrl);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AfterHScroll;
- begin
- inherited AfterHScroll;
- GenerateMouseMove;
- InplaceRedrawing(False);
- {$IFDEF RVDEBUG}{$I Debuga.inc}{$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AfterVScroll;
- begin
- {$IFDEF RVDEBUG}{$I Debugb.inc}{$ENDIF}
- inherited AfterVScroll;
- GenerateMouseMove;
- RVData.AfterVScroll;
- InplaceRedrawing(False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetSelectionBounds(var StartItemNo, StartItemOffs,
- EndItemNo, EndItemOffs: Integer;
- Normalize: Boolean);
- begin
- RVData.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs,
- Normalize);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetSelectionBounds(StartItemNo, StartItemOffs,
- EndItemNo, EndItemOffs: Integer);
- begin
- RVData.SetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.IsFromNewLine(ItemNo: Integer): Boolean;
- begin
- Result := RVData.IsFromNewLine(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.IsParaStart(ItemNo: Integer): Boolean;
- begin
- Result := RVData.IsParaStart(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemPara(ItemNo: Integer): Integer;
- begin
- Result := RVData.GetItemPara(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetWordAt(X,Y: Integer;
- var RVData: TCustomRVFormattedData; var ItemNo: Integer; var Word: String);
- begin
- Self.RVData.GetWordAt(X, Y, RVData, ItemNo, Word);
- end;
- {------------------------------------------------------------------------------}
- {$IFDEF RICHVIEWDEF4}
- function TCustomRichView.GetWordAt(X,Y: Integer): String;
- var ARVData: TCustomRVFormattedData;
- AItemNo: Integer;
- begin
- RVData.GetWordAt(X, Y, ARVData, AItemNo, Result);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMDestroy(var Message: TWMDestroy);
- begin
- DeactivateScrollTimer;
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMGetDlgCode(var Message: TWMGetDlgCode);
- begin
- Message.Result := DLGC_WANTARROWS;
- if TabNavigation<>rvtnNone then begin
- Message.Result := Message.Result or DLGC_WANTTAB;
- if RVData.TopLevelFocusedRVData<>nil then
- Message.Result := Message.Result or DLGC_WANTALLKEYS; // wants ENTER
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMSetFocus(var Message: TWMSetFocus);
- {....................................}
- function GetFocusedControl(Handle: HWND): TWinControl;
- var NewHandle: HWND;
- begin
- Result := nil;
- if Handle=0 then
- exit;
- NewHandle := Windows.GetParent(Handle);
- if NewHandle=0 then begin
- Result := FindControl(Handle);
- exit;
- end;
- Result := FindControl(NewHandle);
- if not (Result is TComboBox) then
- Result := FindControl(Handle);
- end;
- {....................................}
- begin
- inherited;
- if csDestroying in ComponentState then
- exit;
- if TabNavigation<>rvtnNone then begin
- if Message.FocusedWnd=0 then
- Include(RVData.State,rvstDoNotTab);
- RVData.DoTabNavigation(GetKeyState(VK_SHIFT)<0, GetFocusedControl(Message.FocusedWnd));
- end;
- if (Style<>nil) and
- ((Style.SelTextColor<>Style.InactiveSelTextColor) or
- (Style.SelColor<>Style.InactiveSelColor)) then
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMKillFocus(var Message: TWMKillFocus);
- begin
- inherited;
- if (Style<>nil) and
- ((Style.SelTextColor<>Style.InactiveSelTextColor) or
- (Style.SelColor<>Style.InactiveSelColor)) then
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetSelectionRect: TRect;
- begin
- Result := RVData.GetSelectionRect;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetPageBreaksBeforeItems(Index: Integer): Boolean;
- begin
- Result := RVData.PageBreaksBeforeItems[Index];
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetPageBreaksBeforeItems(Index: Integer; Value: Boolean);
- begin
- RVData.PageBreaksBeforeItems[Index] := Value;
- if rvoShowPageBreaks in Options then
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetAddParagraphMode(AllowNewPara: Boolean);
- begin
- RVData.SetAddParagraphMode(AllowNewPara);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetDocumentHeight: Integer;
- begin
- Result := RVData.DocumentHeight;
- end;
- {----------------------------- Checkpoints ------------------------------------}
- function TCustomRichView.GetFirstCheckpoint: TCheckpointData;
- begin
- Result := RVData.GetFirstCheckpoint;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetNextCheckpoint(CheckpointData: TCheckpointData): TCheckpointData;
- begin
- Result := RVData.GetNextCheckpoint(CheckpointData);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetLastCheckpoint: TCheckpointData;
- begin
- Result := RVData.GetLastCheckpoint;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetPrevCheckpoint(CheckpointData: TCheckpointData): TCheckpointData;
- begin
- Result := RVData.GetPrevCheckpoint(CheckpointData);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetCheckpointInfo(CheckpointData: TCheckpointData;
- var Tag: Integer; var Name: String;
- var RaiseEvent: Boolean);
- begin
- RVData.GetCheckpointInfo(CheckpointData, Tag, Name, RaiseEvent);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetCheckpointXY(CheckpointData: TCheckpointData; var X,Y: Integer);
- begin
- RVData.GetCheckpointXY(CheckpointData, X, Y);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetCheckpointYEx(CheckpointData: TCheckpointData): Integer;
- begin
- Result := RVData.GetCheckpointYEx(CheckpointData);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.FindCheckpointByName(const Name: String): TCheckpointData;
- begin
- Result := RVData.FindCheckpointByName(Name);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.FindCheckpointByTag(Tag: Integer): TCheckpointData;
- begin
- Result := RVData.FindCheckpointByTag(Tag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetCheckpointNo(CheckpointData: TCheckpointData): Integer;
- begin
- Result := RVData.GetCheckpointNo(CheckpointData);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetCheckpointByNo(No: Integer): TCheckpointData;
- begin
- Result := RVData.GetCheckpointByNo(No);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetCheckpointItemNo(CheckpointData: TCheckpointData): Integer;
- begin
- Result := RVData.GetCheckpointItemNo(CheckpointData);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemCheckpoint(ItemNo: Integer): TCheckpointData;
- begin
- Result := RVData.GetItemCheckpoint(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetCheckpointY(no: Integer): Integer;
- begin
- Result := RVData.GetCheckpointYEx(GetCheckpointByNo(No));
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetJumpPointY(id: Integer): Integer;
- begin
- Result := RVData.GetJumpPointY(id);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetJumpPointItemNo(id: Integer): Integer;
- begin
- Result := RVData.GetJumpPointItemNo(id);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.GetJumpPointLocation(id: Integer;
- var RVData: TCustomRVFormattedData; var ItemNo: Integer);
- begin
- Self.RVData.GetJumpPointLocation(id, RVData, ItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemCoords(ItemNo: Integer;var Left,Top: Integer): Boolean;
- begin
- Result := RVData.GetItemCoords(ItemNo, Left,Top);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemClientCoords(ItemNo: Integer;var Left,Top: Integer): Boolean;
- begin
- Result := RVData.GetItemClientCoords(ItemNo, Left,Top);
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSERVF}
- function TCustomRichView.CreateLayoutInfo: TRVLayoutInfo;
- begin
- Result := TRVLayoutInfo.Create;
- Result.LeftMargin := LeftMargin;
- Result.RightMargin := RightMargin;
- Result.BottomMargin := BottomMargin;
- Result.TopMargin := TopMargin;
- Result.MinTextWidth := MinTextWidth;
- Result.MaxTextWidth := MaxTextWidth;
- Result.BiDiMode := BiDiMode;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.ApplyLayoutInfo(Layout: TRVLayoutInfo);
- begin
- LeftMargin := Layout.LeftMargin;
- RightMargin := Layout.RightMargin;
- BottomMargin := Layout.BottomMargin;
- TopMargin := Layout.TopMargin;
- MinTextWidth := Layout.MinTextWidth;
- MaxTextWidth := Layout.MaxTextWidth;
- Include(RVData.State, rvstSkipFormatting);
- try
- BiDiMode := Layout.BiDiMode;
- finally
- Exclude(RVData.State, rvstSkipFormatting);
- end;
- end;
- {-------------------------- Loading RVF ---------------------------------------}
- function TCustomRichView.InsertRVFFromStream(Stream: TStream; Index: Integer):Boolean;
- var AColor: TColor;
- begin
- AColor := Color;
- Result := RVData.InsertRVFFromStream(Stream, Index, AColor, Background, nil, False);
- Color := AColor;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.AppendRVFFromStream(Stream: TStream; ParaNo: Integer):Boolean;
- var AColor: TColor;
- begin
- AColor := Color;
- Result := RVData.AppendRVFFromStream(Stream, ParaNo, AColor, Background);
- Color := AColor;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.LoadRVFFromStream(Stream: TStream):Boolean;
- var AColor: TColor;
- Layout: TRVLayoutInfo;
- begin
- AColor := Color;
- Layout := TRVLayoutInfo.Create;
- Result := RVData.LoadRVFFromStream(Stream, AColor, Background, Layout);
- if Layout.Loaded then
- ApplyLayoutInfo(Layout);
- Layout.Free;
- Color := AColor;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.LoadRVF(const FileName: String):Boolean;
- var AColor: TColor;
- Layout: TRVLayoutInfo;
- begin
- AColor := Color;
- Layout := TRVLayoutInfo.Create;
- Result := RVData.LoadRVF(FileName, AColor, Background, Layout);
- if Layout.Loaded then
- ApplyLayoutInfo(Layout);
- Layout.Free;
- Color := AColor;
- end;
- {--------------------------- Saving RVF ---------------------------------------}
- function TCustomRichView.SaveRVFToStream(Stream: TStream; SelectionOnly: Boolean):Boolean;
- var Layout: TRVLayoutInfo;
- begin
- Layout := CreateLayoutInfo;
- Result := RVData.SaveRVFToStream(Stream, SelectionOnly, Color, Background, Layout);
- Layout.Free;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveRVF(const FileName: String; SelectionOnly: Boolean):Boolean;
- var Layout: TRVLayoutInfo;
- begin
- Layout := CreateLayoutInfo;
- Result := RVData.SaveRVF(FileName, SelectionOnly, Color, Background, Layout);
- Layout.Free;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.CopyRVF;
- begin
- RVData.CopyRVF(Color, Background);
- end;
- {------------------------------------------------------------------------------}
- {$ENDIF}
- {--------------------------- Saving RTF ---------------------------------------}
- {$IFNDEF RVDONOTUSERTF}
- procedure TCustomRichView.CopyRTF;
- begin
- RVData.CopyRTF(Color, Background);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveRTFToStream(Stream: TStream; SelectionOnly: Boolean):Boolean;
- begin
- Result := RVData.SaveRTFToStream(Stream, '', SelectionOnly, 0, Color,
- Background, nil, nil, nil, nil, nil, 0.0);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveRTF(const FileName: String; SelectionOnly: Boolean):Boolean;
- begin
- Result := RVData.SaveRTF(FileName, SelectionOnly, Color, Background);
- end;
- {$ENDIF}
- {------------------------------- HTML methods ---------------------------------}
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function TCustomRichView.LoadRTFFromStream(Stream: TStream):Boolean;
- begin
- RTFReadProperties; // creating if nil
- Result := RVData.LoadRTFFromStream(Stream)=rtf_ec_OK;
- end;
- {------------------------------- HTML methods ---------------------------------}
- function TCustomRichView.LoadRTF(const FileName: String):Boolean;
- begin
- RTFReadProperties; // creating if nil
- Result := RVData.LoadRTF(FileName)=rtf_ec_OK;
- end;
- {------------------------------- HTML methods ---------------------------------}
- {$IFDEF RVUSEWORDDOC}
- function TCustomRichView.LoadWordDoc(const FileName: String):Boolean;
- begin
- RTFReadProperties; // creating if nil
- Result := RVData.LoadWordDoc(FileName)=rtf_ec_OK;
- end;
- {$ENDIF}
- {$ENDIF}
- {------------------------------- HTML methods ---------------------------------}
- {$IFNDEF RVDONOTUSEHTML}
- function TCustomRichView.SaveHTMLEx(const FileName, Title, ImagesPrefix, ExtraStyles,
- ExternalCSS, CPPrefix: String;
- Options: TRVSaveOptions):Boolean;
- begin
- imgSavePrefix := ImagesPrefix;
- SaveOptions := Options;
- imgSaveNo := 0;
- Result := RVData.SaveHTMLEx( FileName, Title, ImagesPrefix,
- ExtraStyles, ExternalCSS, CPPrefix,
- Options, GetColor, CurrentFileColor, imgSaveNo,
- LeftMargin, TopMargin, RightMargin, BottomMargin,
- Background);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveHTMLToStreamEx(Stream: TStream;
- const Path, Title, ImagesPrefix, ExtraStyles,
- ExternalCSS, CPPrefix: String;
- Options: TRVSaveOptions):Boolean;
- begin
- imgSavePrefix := ImagesPrefix;
- SaveOptions := Options;
- imgSaveNo := 0;
- {$IFDEF RVDEBUG}{$I Debugd.inc}{$ENDIF}
- Result := RVData.SaveHTMLToStreamEx(Stream, Path, Title, ImagesPrefix,
- ExtraStyles, ExternalCSS, CPPrefix,
- Options, GetColor, CurrentFileColor, imgSaveNo,
- LeftMargin, TopMargin,
- RightMargin, BottomMargin,
- Background,nil);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveHTML(const FileName,Title,ImagesPrefix: String;
- Options: TRVSaveOptions):Boolean;
- begin
- imgSavePrefix := ImagesPrefix;
- CurrentFileColor := GetColor;
- SaveOptions := Options;
- imgSaveNo := 0;
- Result := RVData.SaveHTML(FileName, Title, ImagesPrefix, Options,
- GetColor, imgSaveNo,
- LeftMargin, TopMargin, RightMargin, BottomMargin,
- Background);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveHTMLToStream(Stream: TStream; const Path, Title,ImagesPrefix: String;
- Options: TRVSaveOptions):Boolean;
- begin
- imgSavePrefix := ImagesPrefix;
- CurrentFileColor := GetColor;
- SaveOptions := Options;
- imgSaveNo := 0;
- Result := RVData.SaveHTMLToStream(Stream, Path, Title, ImagesPrefix, Options,
- GetColor, imgSaveNo,
- LeftMargin, TopMargin, RightMargin, BottomMargin,
- Background,nil);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichView.SavePicture(DocumentSaveFormat: TRVSaveFormat;
- const Path: String;
- gr: TGraphic): String;
- begin
- Result := RVData.SavePicture(DocumentSaveFormat, imgSavePrefix, Path,
- imgSaveNo, rvsoOverrideImages in SaveOptions, CurrentFileColor, gr);
- end;
- {----------------------------- Text Files -------------------------------------}
- function TCustomRichView.LoadText(const FileName: String; StyleNo, ParaNo: Integer;
- AsSingleParagraph: Boolean):Boolean;
- begin
- Result := RVData.LoadText(FileName, StyleNo, ParaNo,AsSingleParagraph);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.LoadTextFromStream(Stream: TStream; StyleNo,
- ParaNo: Integer; AsSingleParagraph: Boolean):Boolean;
- begin
- Result := RVData.LoadTextFromStream(Stream, StyleNo, ParaNo,AsSingleParagraph);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveTextToStream(const Path: String; Stream: TStream;
- LineWidth: Integer; SelectionOnly, TextOnly: Boolean):Boolean;
- begin
- Result := RVData.SaveTextToStream(Path, Stream, LineWidth, SelectionOnly,
- TextOnly, False, False);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveText(const FileName: String; LineWidth: Integer):Boolean;
- begin
- Result := RVData.SaveText(FileName, LineWidth, False);
- end;
- {------------------------------- Unicode --------------------------------------}
- procedure TCustomRichView.AddNLATag(const s: String; StyleNo, ParaNo, Tag: Integer);
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- RVData.AddNLATag(s, StyleNo, ParaNo, Tag);
- {$ELSE}
- RVData.AddNLTag(s, StyleNo, ParaNo, Tag);
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSEUNICODE}
- function TCustomRichView.LoadTextW(const FileName: String; StyleNo, ParaNo: Integer;
- DefAsSingleParagraph: Boolean):Boolean;
- begin
- Result := RVData.LoadTextW(FileName, StyleNo, ParaNo, DefAsSingleParagraph);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.LoadTextFromStreamW(Stream: TStream; StyleNo, ParaNo: Integer;
- DefAsSingleParagraph: Boolean):Boolean;
- begin
- Result := RVData.LoadTextFromStreamW(Stream, StyleNo, ParaNo, DefAsSingleParagraph);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveTextW(const FileName: String; LineWidth: Integer):Boolean;
- begin
- Result := RVData.SaveText(FileName, LineWidth, True);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.SaveTextToStreamW(const Path: String; Stream: TStream;
- LineWidth: Integer; SelectionOnly, TextOnly: Boolean):Boolean;
- begin
- Result := RVData.SaveTextToStream(Path, Stream, LineWidth, SelectionOnly,
- TextOnly, True, False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetItemTextA(ItemNo: Integer; const s: String);
- begin
- RVData.SetItemTextA(ItemNo, s);
- end;
- {------------------------------------------------------------------------------}
- {$IFDEF RICHVIEWCBDEF3}
- procedure TCustomRichView.AddTextNLW(const s: WideString;
- StyleNo, FirstParaNo, OtherParaNo: Integer;
- DefAsSingleParagraph: Boolean);
- var ansis: String;
- LParaNo: Integer;
- begin
- SetLength(ansis, Length(s)*2);
- Move(Pointer(s)^, Pointer(ansis)^, Length(ansis));
- LParaNo := FirstParaNo;
- if (Style<>nil) and (FirstParaNo=-1) and ((StyleNo<0) or (StyleNo=rvsDefStyle)) then begin
- if ItemCount>0 then
- LParaNo := GetItemPara(ItemCount-1)
- else
- LParaNo := 0;
- end;
- if (Style<>nil) and not Style.TextStyles[RVData.GetActualStyle2(StyleNo,LParaNo)].Unicode then begin
- ansis := RVU_UnicodeToAnsi(RVData.GetStyleCodePage(RVData.GetActualStyle2(StyleNo,LParaNo)), ansis);
- if DefAsSingleParagraph then
- AddTextBlockNL(ansis, StyleNo, FirstParaNo)
- else
- AddTextNL(ansis, StyleNo, FirstParaNo, OtherParaNo);
- end
- else
- RVData.AddTextNLW(ansis, StyleNo, FirstParaNo, OtherParaNo, DefAsSingleParagraph);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AddNLWTag(const s: WideString; StyleNo, ParaNo, Tag: Integer);
- begin
- RVData.AddNLWTag(s, StyleNo, ParaNo, Tag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetSelTextW: WideString;
- var s: String;
- begin
- s := RVData.GetSelText(True);
- SetLength(Result, Length(s) div 2);
- if Length(s)<>0 then
- Move(PChar(s)^, Pointer(Result)^, Length(s));
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemTextW(ItemNo: Integer): WideString;
- begin
- Result := RVData.GetItemTextW(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetItemTextW(ItemNo: Integer;
- const s: WideString);
- begin
- RVData.SetItemTextW(ItemNo, s);
- end;
- {$ENDIF}
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemTextA(ItemNo: Integer): String;
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- Result := RVData.GetItemTextA(ItemNo);
- {$ELSE}
- Result := RVData.GetItemText(ItemNo);
- {$ENDIF}
- end;
- {--------------------------- Palette support ---------------------------------}
- procedure TCustomRichView.UpdatePaletteInfo;
- begin
- inherited UpdatePaletteInfo;
- RVData.UpdateItemsPaletteInfo;
- RVData.UpdateBackgroundPaletteInfo(Background);
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItem(ItemNo: Integer): TCustomRVItemInfo;
- begin
- Result := TCustomRVItemInfo(RVData.Items.Objects[ItemNo]);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemNo(Item: TCustomRVItemInfo): Integer;
- begin
- Result := RVData.Items.IndexOfObject(Item);
- end;
- procedure TCustomRichView.GetFocusedItem(var ARVData: TCustomRVFormattedData; var AItemNo: Integer);
- begin
- ARVData := RVData.TopLevelFocusedRVData;
- AItemNo := RVData.TopLevelFocusedItemNo;
- end;
- {$IFDEF RVDEBUG}{$I DebugDecl2.inc}{$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetRTFReadProperties: TRVRTFReaderProperties;
- begin
- if FRTFReadProperties=nil then
- FRTFReadProperties := TRVRTFReaderProperties.Create;
- Result := FRTFReadProperties;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetRTFReadProperties(const Value: TRVRTFReaderProperties);
- begin
- if Value=nil then begin
- FRTFReadProperties.Free;
- FRTFReadProperties := nil;
- end
- else begin
- RTFReadProperties.Assign(Value);
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.RTFReaderAssigned: Boolean;
- begin
- Result := FRTFReadProperties<>nil;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AssignEvents(Source: TCustomRichView);
- begin
- OnSaveComponentToFile := Source.OnSaveComponentToFile;
- OnSaveItemToFile := Source.OnSaveItemToFile;
- OnSaveParaToHTML := Source.OnSaveParaToHTML;
- OnURLNeeded := Source.OnURLNeeded;
- OnSelect := Source.OnSelect;
- OnImportPicture := Source.OnImportPicture;
- OnRVRightClick := Source.OnRVRightClick;
- OnRVFPictureNeeded := Source.OnRVFPictureNeeded;
- OnRVFImageListNeeded := Source.OnRVFImageListNeeded;
- OnRVFControlNeeded := Source.OnRVFControlNeeded;
- OnRVDblClick := Source.OnRVDblClick;
- OnJump := Source.OnJump;
- OnRVMouseMove := Source.OnRVMouseMove;
- OnCopy := Source.OnCopy;
- OnRVMouseDown := Source.OnRVMouseDown;
- OnRVMouseUp := Source.OnRVMouseUp;
- OnControlAction := Source.OnControlAction;
- OnItemAction := Source.OnItemAction;
- OnClick := Source.OnClick;
- OnKeyDown := Source.OnKeyDown;
- OnKeyUp := Source.OnKeyUp;
- OnKeyPress := Source.OnKeyPress;
- OnHTMLSaveImage := Source.OnHTMLSaveImage;
- OnSaveImage2 := Source.OnSaveImage2;
- OnDblClick := Source.OnDblClick;
- OnItemHint := Source.OnItemHint;
- OnReadHyperlink := Source.OnReadHyperlink;
- // OnCheckpointVisible := Source.OnCheckpointVisible;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.DeleteUnusedStyles(TextStyles, ParaStyles, ListStyles: Boolean);
- begin
- RVData.DeleteUnusedStyles(TextStyles, ParaStyles, ListStyles);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.MarkStylesInUse(Data: TRVDeleteUnusedStylesData);
- begin
- RVData.MarkStylesInUse(Data);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.DeleteMarkedStyles(Data: TRVDeleteUnusedStylesData);
- begin
- RVData.DeleteMarkedStyles(Data);
- end;
- {------------------------------------------------------------------------------}
- { Gets item's property of integer type.
- ItemNo - index of item. Prop identifies the property. Value receives a
- property value.
- Returns true is this item type has this property }
- function TCustomRichView.GetItemExtraIntProperty(ItemNo: Integer;
- Prop: TRVExtraItemProperty; var Value: Integer): Boolean;
- begin
- Result := RVData.GetItemExtraIntProperty(ItemNo, Prop, Value);
- end;
- {------------------------------------------------------------------------------}
- { Sets item's property of integer type.
- ItemNo - index of item. Prop identifies the property. Value - new property
- value.
- Returns true is this item type has this property }
- function TCustomRichView.SetItemExtraIntProperty(ItemNo: Integer;
- Prop: TRVExtraItemProperty; Value: Integer): Boolean;
- begin
- Result := RVData.SetItemExtraIntProperty(ItemNo, Prop, Value);
- end;
- {------------------------------------------------------------------------------}
- { Gets item's property of string type.
- ItemNo - index of item. Prop identifies the property. Value receives a
- property value.
- Returns true is this item type has this property }
- function TCustomRichView.GetItemExtraStrProperty(ItemNo: Integer;
- Prop: TRVExtraItemStrProperty; var Value: String): Boolean;
- begin
- Result := RVData.GetItemExtraStrProperty(ItemNo, Prop, Value);
- end;
- {------------------------------------------------------------------------------}
- { Sets item's property of string type.
- ItemNo - index of item. Prop identifies the property. Value - new property
- value.
- Returns true is this item type has this property }
- function TCustomRichView.SetItemExtraStrProperty(ItemNo: Integer;
- Prop: TRVExtraItemStrProperty; const Value: String): Boolean;
- begin
- Result := RVData.SetItemExtraStrProperty(ItemNo, Prop, Value);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AssignSoftPageBreaks(RVPrint: TComponent);
- begin
- RVData.AssignSoftPageBreaks(RVPrint as TCustomRVPrint);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.ClearSoftPageBreaks;
- begin
- if RVData.ClearSoftPageBreaks then
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELISTS}
- function TCustomRichView.SetListMarkerInfo(AItemNo, AListNo, AListLevel,
- AStartFrom, AParaNo: Integer; AUseStartFrom: Boolean): Integer;
- begin
- Result := RVData.SetListMarkerInfo(AItemNo, AListNo, AListLevel, AStartFrom,
- AParaNo, AUseStartFrom)
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.RemoveListMarker(ItemNo: Integer);
- begin
- RVData.RemoveListMarker(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetListMarkerInfo(AItemNo: Integer; var AListNo,
- AListLevel, AStartFrom: Integer; var AUseStartFrom: Boolean): Integer;
- begin
- Result := RVData.GetListMarkerInfo(AItemNo, AListNo, AListLevel, AStartFrom,
- AUseStartFrom);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.RefreshListMarkers;
- var Markers: TRVMarkerList;
- begin
- Markers := RVData.GetMarkers(False);
- if (Markers<>nil) and (Style<>nil) then
- Markers.RecalcDisplayStrings(Style);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetLineNo(ItemNo, ItemOffs: Integer): Integer;
- begin
- Result := RVData.GetLineNo(ItemNo, ItemOffs);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMRVEvent(var Message: TMessage);
- var data: TRVMessageData;
- begin
- data := TRVMessageData(Message.wParam);
- case data.Event of
- rvetDragDrop:
- with TRVDNDMessageData(data) do
- DragDrop(Obj,X,Y);
- rvetEndDrag:
- with TRVDNDMessageData(data) do
- DoEndDrag(Obj,X,Y);
- rvetClick:
- Click;
- rvetDblClick:
- DblClick;
- rvetMouseMove:
- with TRVMouseMoveMessageData(data) do
- MouseMove(Shift, X, Y);
- rvetRVDblClick:
- RVData.DoRVDblClick(TRVDblClickMessageData(data).ClickedWord,
- TRVDblClickMessageData(data).StyleNo);
- rvetJump:
- RVData.DoJump(TRVJumpMessageData(data).id);
- rvetRVMouseUp:
- with TRVMouseUpDownMessageData(data) do
- RVData.DoRVMouseUp(Button,Shift,ItemNo,X,Y);
- rvetRVMouseDown:
- with TRVMouseUpDownMessageData(data) do
- RVData.DoRVMouseDown(Button,Shift,ItemNo,X,Y);
- end;
- data.Free;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetName(const NewName: TComponentName);
- var reg: TRegistry;
- procedure SetRVFOption(Value: Boolean; Option: TRVFOption);
- begin
- if Value then
- RVFOptions := RVFOptions + [Option]
- else
- RVFOptions := RVFOptions - [Option];
- end;
- begin
- if (csDesigning in ComponentState) and
- not (csLoading in ComponentState) and
- (Name=EmptyStr) and
- not (rvstNameSet in RVData.State) then begin
- //Application.MessageBox('Applying!','');
- try
- reg := TRegistry.Create;
- try
- if reg.OpenKey('SoftwareTRichView', False) then begin
- try
- case reg.ReadInteger('Styles') of
- 0:
- begin
- RVFTextStylesReadMode := rvf_sInsertMap;
- RVFParaStylesReadMode := rvf_sInsertMap;
- RVFOptions := RVFOptions-[rvfoSaveTextStyles, rvfoSaveParaStyles];
- RTFReadProperties.TextStyleMode := rvrsUseClosest;
- RTFReadProperties.ParaStyleMode := rvrsUseClosest;
- end;
- 1:
- begin
- RVFTextStylesReadMode := rvf_sInsertMerge;
- RVFParaStylesReadMode := rvf_sInsertMerge;
- RVFOptions := RVFOptions+[rvfoSaveTextStyles, rvfoSaveParaStyles];
- RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
- RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
- end;
- end;
- except;
- RVFTextStylesReadMode := rvf_sInsertMerge;
- RVFParaStylesReadMode := rvf_sInsertMerge;
- RVFOptions := RVFOptions+[rvfoSaveTextStyles, rvfoSaveParaStyles];
- RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
- RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
- end;
- try
- case reg.ReadInteger('Tags') of
- 0:
- begin
- Options := Options-[rvoTagsArePChars];
- end;
- 1:
- begin
- Options := Options+[rvoTagsArePChars];
- end;
- end;
- except;
- end;
- try
- SetRVFOption(reg.ReadBool('rvf01'), rvfoSaveBack);
- SetRVFOption(reg.ReadBool('rvf02'), rvfoSaveLayout);
- SetRVFOption(reg.ReadBool('rvf03'), rvfoSaveBinary);
- SetRVFOption(reg.ReadBool('rvf04'), rvfoSavePicturesBody);
- SetRVFOption(reg.ReadBool('rvf05'), rvfoSaveControlsBody);
- SetRVFOption(reg.ReadBool('rvf06'), rvfoLoadBack);
- SetRVFOption(reg.ReadBool('rvf07'), rvfoLoadLayout);
- SetRVFOption(reg.ReadBool('rvf08'), rvfoIgnoreUnknownPicFmt);
- SetRVFOption(reg.ReadBool('rvf09'), rvfoIgnoreUnknownCtrls);
- SetRVFOption(reg.ReadBool('rvf10'), rvfoConvUnknownStylesToZero);
- SetRVFOption(reg.ReadBool('rvf11'), rvfoConvLargeImageIdxToZero);
- SetRVFOption(reg.ReadBool('rvf12'), rvfoSaveDocProperties);
- SetRVFOption(reg.ReadBool('rvf13'), rvfoLoadDocProperties);
- except;
- end;
- end;
- finally
- reg.Free;
- end;
- except
- end;
- end;
- RVData.State := RVData.State+[rvstNameSet];
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AfterCreateWnd1;
- begin
- if (RVData=nil) or (RVData.Items=nil) or (RVData.Items.Count=0) then
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.AfterCreateWnd2;
- begin
- if (RVData<>nil) and (RVData.Items<>nil) and (RVData.Items.Count>0) then
- Format_(True, False, Canvas, False, False, False)
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.StoreDelimiters: Boolean;
- begin
- Result := FDelimiters<>RVDEFAULTDELIMITERS;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetItemAt(X, Y: Integer;
- var RVData: TCustomRVFormattedData; var ItemNo, OffsetInItem: Integer;
- Strict: Boolean): Boolean;
- var Dummy: Boolean;
- begin
- Self.RVData.GetItemAtEx(X,Y,RVData,ItemNo,OffsetInItem,Strict,Dummy);
- Result := ItemNo<>-1;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMRVDragDrop(var Message: TMessage);
- begin
- {$IFNDEF RVDONOTUSEDRAGDROP}
- RVData.DoDrag;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSEDRAGDROP}
- procedure TCustomRichView.BeginOleDrag;
- begin
- PostMessage(RVData.GetAbsoluteRootData.GetParentControl.Handle, WM_RVDRAGDROP,
- 0, 0);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- { Converts client coordinates (relative to the top left of window)
- to document coordinates (relative to the top left of scrollable area). }
- function TCustomRichView.ClientToDocument(const APoint: TPoint): TPoint;
- var X, Y: Integer;
- begin
- RVData.GetOriginEx(X, Y);
- Result := Point(APoint.X-X+RVData.GetHOffs, APoint.Y-Y+RVData.GetVOffs);
- end;
- {------------------------------------------------------------------------------}
- { Invalidates RichView and all its inplace editors. }
- procedure TCustomRichView.FullInvalidate;
- var rv: TCustomRichView;
- begin
- rv := Self;
- while rv<>nil do begin
- if not rv.HandleAllocated or (csDestroying in rv.ComponentState) then
- exit;
- rv.Invalidate;
- rv := TCustomRichView(rv.InplaceEditor);
- end;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELIVESPELL}
- {------------------------------------------------------------------------------}
- { Clears results of live spelling by calling ClearItemLiveSpellingResults for
- all items. }
- procedure TCustomRichView.DoClearLiveSpellingResults;
- var Dummy1: Integer;
- Dummy2: String;
- begin
- Dummy1 := 0;
- Dummy2 := '';
- RVData.EnumItems(ClearItemLiveSpellingResults, Dummy1, Dummy2);
- end;
- {------------------------------------------------------------------------------}
- { Clears live spelling results for the given item. Called from inside
- RVData.EnumItems from DoClearLiveSpellingResults. }
- procedure TCustomRichView.ClearItemLiveSpellingResults(RVData: TCustomRVData;
- ItemNo: Integer; var UserData1: Integer; const UserData2: String;
- var ContinueEnum: Boolean);
- begin
- RVData.GetItem(ItemNo).ClearLiveSpellingResult;
- end;
- {------------------------------------------------------------------------------}
- { Marks AWord as a valid word: removes misspelling underlines from all
- occurences of this word by calling LiveSpellingValidateWordInItem for all items.
- Case sensitive.
- This procedure should be called after adding this word in a dictinary or
- ignore list.
- Repaints RichView. }
- procedure TCustomRichView.LiveSpellingValidateWord(const AWord: String);
- var Res: Integer;
- begin
- Res := 0;
- RVData.EnumItems(LiveSpellingValidateWordInItem, Res, AWord);
- if Res<>0 then
- FullInvalidate;
- end;
- {------------------------------------------------------------------------------}
- { Marks AWord as a valid word: removes misspelling underlines from all
- occurences of this word in the given item. Called from inside
- RVData.EnumItems from LiveSpellingValidateWord. }
- procedure TCustomRichView.LiveSpellingValidateWordInItem(RVData: TCustomRVData;
- ItemNo: Integer; var UserData1: Integer; const UserData2: String;
- var ContinueEnum: Boolean);
- begin
- if RVData.GetItem(ItemNo).ValidateMisspelledWord(RVData.GetItemTextA(ItemNo),
- UserData2) then
- UserData1 := 1;
- end;
- {------------------------------------------------------------------------------}
- { Starts live spelling. }
- procedure TCustomRichView.StartLiveSpelling;
- begin
- if not (rvflRoot in Flags) or not Assigned(FOnSpellingCheck) or (Style=nil) then
- exit;
- if FWordEnumThread=nil then
- FWordEnumThread := TRVWordEnumThread.Create
- else
- FWordEnumThread.Stop(True);
- DoClearLiveSpellingResults;
- FWordEnumThread.Reset(Self);
- FWordEnumThread.Priority := tpLowest;
- FWordEnumThread.Resume;
- end;
- {------------------------------------------------------------------------------}
- { Clears live spelling results and stops live spelling. }
- procedure TCustomRichView.ClearLiveSpellingResults;
- begin
- if FWordEnumThread<>nil then begin
- //FWordEnumThread.Stop(True);
- //FWordEnumThread.Reset(Self);
- FWordEnumThread.Finish;
- FWordEnumThread.Reset(nil);
- FWordEnumThread := nil;
- DoClearLiveSpellingResults;
- FullInvalidate;
- end;
- end;
- {------------------------------------------------------------------------------}
- { Calls LaterSetBackTo for live spelling thread for absolute root RichView. }
- procedure TCustomRichView.LaterSetBackLiveSpellingTo(RVData: TCustomRVData;
- ItemNo, Offs: Integer);
- var rv: TCustomRichView;
- begin
- rv := TCustomRichView(TRichViewRVData(Self.RVData.GetAbsoluteRootData).RichView);
- if rv.FWordEnumThread<>nil then
- rv.FWordEnumThread.LaterSetBackTo(RVData.GetSourceRVData, ItemNo, Offs);
- end;
- {------------------------------------------------------------------------------}
- { Calls RemoveRVData for live spelling thread for absolute root RichView. }
- procedure TCustomRichView.RemoveRVDataFromLiveSpelling(RVData: TCustomRVData);
- var rv: TCustomRichView;
- begin
- rv := TCustomRichView(TRichViewRVData(Self.RVData.GetAbsoluteRootData).RichView);
- if rv.FWordEnumThread<>nil then
- rv.FWordEnumThread.RemoveRVData(RVData);
- end;
- {------------------------------------------------------------------------------}
- { This method is called when user types character ch. This character was inserted
- in (RVData, ItemNo, Index).
- Adjusts misspellings in item (clears for the affected word, shifts for words
- after it). If delimiter was pressed, or if some misspelling was cleared,
- returns the thread to the caret position. }
- procedure TCustomRichView.AdjustLiveSpellingOnKeyPress(RVData: TCustomRVData;
- ItemNo, Index: Integer; ch: Char);
- var rv: TCustomRichView;
- begin
- rv := TCustomRichView(TRichViewRVData(Self.RVData.GetAbsoluteRootData).RichView);
- if (rv.FWordEnumThread<>nil) and rv.FWordEnumThread.IsChecked(RVData, ItemNo) then begin
- if RVData.GetRVData.GetItem(ItemNo).AdjustWordPaintersOnInsert(Index, ch, RVData) then begin
- rv.FWordEnumThread.HasModifiedWord := False;
- rv.FWordEnumThread.CheckUnchecked := True;
- rv.FWordEnumThread.LaterSetBackTo(RVData.GetSourceRVData, ItemNo, 0);
- end
- else
- rv.FWordEnumThread.HasModifiedWord := True;
- end;
- end;
- {------------------------------------------------------------------------------}
- { This method is called when user deletes Count characters starting from Index
- in (RVData, ItemNo).
- Adjusts misspellings in item (clears for the affected word, shifts for words
- after it). Returns the thread to the caret position. }
- procedure TCustomRichView.AdjustLiveSpellingOnDelete(RVData: TCustomRVData;
- ItemNo, Index, Count: Integer);
- var rv: TCustomRichView;
- begin
- rv := TCustomRichView(TRichViewRVData(Self.RVData.GetAbsoluteRootData).RichView);
- if (rv.FWordEnumThread<>nil) and rv.FWordEnumThread.IsChecked(RVData.GetSourceRVData, ItemNo) then begin
- if RVData.GetItem(ItemNo).AdjustWordPaintersOnDelete(Index, Count) then begin
- rv.FWordEnumThread.HasModifiedWord := False;
- rv.FWordEnumThread.CheckUnchecked := True;
- rv.FWordEnumThread.LaterSetBackTo(RVData.GetSourceRVData, ItemNo, 0);
- end
- else
- rv.FWordEnumThread.HasModifiedWord := True;
- end;
- end;
- {------------------------------------------------------------------------------}
- { Continues live spelling stopped by FWordEnumThread.Stop }
- procedure TCustomRichView.ResumeLiveSpelling;
- begin
- if FWordEnumThread<>nil then begin
- FWordEnumThread.Stop(False);
- FWordEnumThread.ContinueCheck;
- end;
- end;
- {------------------------------------------------------------------------------}
- { Returns live spelling position to the current item (RVData, ItemNo), if
- thread's HasModifiedWord=True.
- This method is called when selection is about to change. }
- procedure TCustomRichView.LiveSpellingCheckCurrentItem(RVData: TCustomRVData;
- ItemNo: Integer);
- var rv: TCustomRichView;
- begin
- rv := TCustomRichView(TRichViewRVData(Self.RVData.GetAbsoluteRootData).RichView);
- if rv.FWordEnumThread<>nil then
- with rv.FWordEnumThread do
- if HasModifiedWord then begin
- Stop(True);
- HasModifiedWord := False;
- CheckUnchecked := True;
- LaterSetBackTo(RVData.GetSourceRVData, ItemNo, 0);
- ContinueCheck;
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- { TCustomRichViewEdit overrides this method to display a popup menu below
- the clicked misspelled word.
- Pt contains coordinates in document. }
- procedure TCustomRichView.AdjustPopupMenuPos(var pt: TPoint);
- begin
- end;
- {$IFNDEF RVDONOTUSEANIMATION}
- {------------------------------------------------------------------------------}
- { Starts playing animation }
- procedure TCustomRichView.StartAnimation;
- begin
- TRichViewRVData(RVData).FPlayingAnimation := True;
- if (TRichViewRVData(RVData).FAnimatorList<>nil) and
- (TRichViewRVData(RVData).FAnimatorList.Count>0) and
- not TRichViewRVData(RVData).FAnimatorList.Active then begin
- TRichViewRVData(RVData).FAnimatorList.Active := True;
- TRichViewRVData(RVData).FAnimatorList.LastMinInterval :=
- TRichViewRVData(RVData).FAnimatorList.MinInterval;
- SetTimer(Handle, RV_TIMERID_ANIMATION, TRichViewRVData(RVData).FAnimatorList.MinInterval, nil);
- end;
- end;
- {------------------------------------------------------------------------------}
- { Stops playing animation }
- procedure TCustomRichView.StopAnimation;
- begin
- TRichViewRVData(RVData).FPlayingAnimation := False;
- if HandleAllocated and
- (TRichViewRVData(RVData).FAnimatorList<>nil) and
- TRichViewRVData(RVData).FAnimatorList.Active then begin
- TRichViewRVData(RVData).FAnimatorList.Active := False;
- KillTimer(Handle, RV_TIMERID_ANIMATION);
- end;
- end;
- {------------------------------------------------------------------------------}
- { Frees all animators }
- procedure TCustomRichView.KillAnimators;
- begin
- StopAnimation;
- if TRichViewRVData(RVData).FAnimatorList<>nil then begin
- TRichViewRVData(RVData).FAnimatorList.FreeAnimators;
- TRichViewRVData(RVData).FAnimatorList.Free;
- TRichViewRVData(RVData).FAnimatorList := nil;
- end;
- end;
- {------------------------------------------------------------------------------}
- { WRITE method for AnimationMode property.
- Assigning to rvaniDisabled, then all animators are freed }
- procedure TCustomRichView.SetAnimationMode(const Value: TRVAnimationMode);
- begin
- if FAnimationMode<>Value then begin
- FAnimationMode := Value;
- case FAnimationMode of
- rvaniDisabled:
- KillAnimators;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.CMColorChanged(var Message: TMessage);
- begin
- if TRichViewRVData(RVData).FAnimatorList<>nil then
- RVData.ResetAniBackground;
- inherited;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELINEARPOSITIONS}
- procedure TCustomRichView.EMGetSel(var Message: TMessage);
- var SelStart, SelLength, Sel1, Sel2: Integer;
- begin
- RVGetSelection(Self, SelStart, SelLength);
- if SelLength>=0 then begin
- Sel1 := SelStart;
- Sel2 := SelStart+SelLength;
- end
- else begin
- Sel1 := SelStart+SelLength;
- Sel2 := SelStart;
- end;
- PInteger(Message.WParam)^ := Sel1;
- PInteger(Message.LParam)^ := Sel2;
- Message.Result := MakeLong(Sel1, Sel2);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.EMSetSel(var Message: TMessage);
- begin
- RVSetSelection(Self, Message.WParam, Message.LParam-Message.WParam);
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- type
- TRVCharRange = record
- cpMin: Longint;
- cpMax: LongInt;
- end;
- TRVTextRange = record
- chrg: TRVCharRange;
- lpstrText: PChar;
- end;
- PRVTextRange = ^TRVTextRange;
- procedure TCustomRichView.EMGetTextRange(var Message: TMessage);
- var ptr: PRVTextRange;
- s: String;
- Len: Integer;
- begin
- Message.Result := 0;
- ptr := PRVTextRange(Message.LParam);
- if ptr.lpstrText=nil then
- exit;
- if ptr.chrg.cpMax<0 then
- Len := -1
- else
- Len := ptr.chrg.cpMax-ptr.chrg.cpMin;
- s := RVGetTextRange(Self, ptr.chrg.cpMin, Len);
- Move(PChar(s)^, Pointer(ptr.lpstrText)^, Length(s)+1);
- Message.Result := Length(s);
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RICHVIEWDEF9}
- procedure TCustomRichView.WMGetText(var Message: TMessage);
- var s: String;
- Len: Integer;
- begin
- if rvflCanProcessGetText in Flags then begin
- if (Message.WParam<=0) or (ItemCount=0) then begin
- Message.Result := 0;
- exit;
- end;
- s := RVGetTextRange(Self, 0, -1);
- Len := Length(s)+1;
- if Message.WParam<Len then
- Len := Message.WParam;
- if Message.LParam<>0 then
- Move(PChar(s)^, Pointer(Message.LParam)^, Len);
- Message.Result := Len-1;
- end
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMGetTextLength(var Message: TMessage);
- begin
- if rvflCanProcessGetText in Flags then begin
- if ItemCount=0 then
- Message.Result := 0
- else
- Message.Result := RVGetTextLength(Self);
- end
- else
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.WMSetText(var Message: TMessage);
- var s: String;
- begin
- if rvflCanProcessGetText in Flags then begin
- if (Message.WParam<=0) or (Message.LParam=0) then begin
- Message.Result := 0;
- exit;
- end;
- SetLength(s, Message.WParam-1);
- Move(Pointer(Message.LParam)^, PChar(s)^, Message.WParam-1);
- Clear;
- AddTextNLA(s, 0, 0, 0);
- Format;
- end
- else
- inherited;
- end;
- {$ENDIF}
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichView.LoadFromStream(Stream: TStream;
- IsTextUnicode: TRVYesNoAuto): Boolean;
- var s: String;
- {...................................................}
- {$IFNDEF RVDONOTUSERTFIMPORT}
- const RTF_START = '{rtf';
- function IsRTF(Stream: TStream): Boolean;
- var DataStart: String;
- begin
- Result := (Stream.Size>5);
- if not Result then
- exit;
- SetLength(DataStart,5);
- Stream.ReadBuffer(PChar(DataStart)^,5);
- Result := DataStart=RTF_START;
- Stream.Position := 0;
- end;
- {$ENDIF}
- {...................................................}
- function AllZero(const s: String):Boolean;
- var i: Integer;
- begin
- Result := False;
- for i := 1 to Length(s) do
- if s[i]<>#0 then
- exit;
- Result := True;
- end;
- {...................................................}
- var StartPos: Integer;
- begin
- Clear;
- StartPos := Stream.Position;
- {$IFNDEF RVDONOTUSERVF}
- Result := LoadRVFFromStream(Stream);
- {$ELSE}
- Result := False;
- {$ENDIF}
- if not Result then begin
- {$IFNDEF RVDONOTUSERTFIMPORT}
- Stream.Position := StartPos;
- Result := IsRTF(Stream) and LoadRTFFromStream(Stream);
- if not Result then
- {$ENDIF}
- begin
- Stream.Position := StartPos;
- SetLength(s, Stream.Size);
- Stream.ReadBuffer(PChar(s)^,Stream.Size);
- if AllZero(s) then
- s := '';
- {$IFNDEF RVDONOTUSEUNICODE}
- case IsTextUnicode of
- rvynaYes:
- RVData.AddTextNLW(s, 0,0,0, False);
- rvynaNo:
- RVData.AddTextNLA(s, 0,0,0);
- rvynaAuto:
- if RV_TestStringUnicode(s)=rvutYes then
- RVData.AddTextNLW(s, 0,0,0, False)
- else
- RVData.AddTextNLA(s, 0,0,0);
- end;
- {$ELSE}
- RVData.AddTextNL(s, 0,0,0);
- {$ENDIF}
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- function TCustomRichView.GetSmartPopupProperties: TRVSmartPopupProperties;
- begin
- if FSmartPopupProperties=nil then begin
- FSmartPopupProperties := TRVSmartPopupProperties.Create;
- FSmartPopupProperties.RichView := Self;
- end;
- Result := FSmartPopupProperties;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetSmartPopupProperties(
- const Value: TRVSmartPopupProperties);
- begin
- if Value=nil then begin
- FSmartPopupProperties.Free;
- FSmartPopupProperties := nil;
- end
- else if Value<>FSmartPopupProperties then
- SmartPopupProperties.Assign(Value);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.HideSmartPopup;
- var RootRVData: TRichViewRVData;
- begin
- RootRVData := TRichViewRVData(RVData.GetAbsoluteRootData);
- RootRVData.FSmartPopupButton.Free;
- RootRVData.FSmartPopupButton := nil;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetSmartPopupTarget;
- begin
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.ShowSmartPopup;
- var RootRVData: TRichViewRVData;
- begin
- RootRVData := TRichViewRVData(RVData.GetAbsoluteRootData);
- if RootRVData.FSmartPopupButton=nil then begin
- RootRVData.FSmartPopupButton := TRVSmartPopupButton.Create(Self);
- RootRVData.FSmartPopupButton.SmartPopupProperties := SmartPopupProperties;
- end;
- SetSmartPopupTarget;
- RootRVData.FSmartPopupButton.Parent := RootRVData.RichView;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichView.GetSmartPopupVisible: Boolean;
- begin
- Result := TRichViewRVData(RVData).FSmartPopupButton<>nil;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichView.SetSmartPopupVisible(const Value: Boolean);
- begin
- if not (csDesigning in ComponentState) and Value then
- ShowSmartPopup
- else
- HideSmartPopup;
- end;
- {$ENDIF}
- initialization
- {$IFDEF RVDEBUG}{$I DebugInit.inc}{$ENDIF}
- {$IFDEF RVDEBUG}{$I DebugFinal.inc}{$ENDIF}
- end.