RVEdit.pas
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:161k
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).RemoveCurrentCheckpoint;
- exit;
- end;
- {$ENDIF}
- RemoveCheckpointEd(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.BeforeChange(FromOutside: Boolean): Boolean;
- begin
- Result := (not ReadOnly) and (Style<>nil) and
- (FromOutside or (RVData.CaptureMouseItem=nil)) and
- DoChanging;
- if Result then begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- if FWordEnumThread<>nil then begin
- FWordEnumThread.Stop(not (rvstKeyPress in TopLevelEditor.RVData.State));
- if not (rvstKeyPress in TopLevelEditor.RVData.State) then
- FWordEnumThread.SetBackToCurItem(TopLevelEditor.RVData.GetSourceRVData,
- TopLevelEditor.CurItemNo);
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- ClearSoftPageBreaks;
- end
- else
- TRVEditRVData(RVData).Beep;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.DoChange(ClearRedo: Boolean);
- begin
- TRVEditRVData(RVData).CreateResizer;
- Modified := True;
- ClearSoftPageBreaks;
- TRVEditRVData(RVData).ClearJumpsCoords;
- if ClearRedo then
- TRVEditRVData(RVData).RedoList.Clear;
- if (GetRootEditor.LockCount<=0) and Assigned(FOnChange) then
- FOnChange(Self);
- {$IFNDEF RVDONOTUSELIVESPELL}
- if (TRVEditRVData(RVData).UndoList.GroupModeCount<=0) and
- (TRVEditRVData(TopLevelEditor.RVData).UndoList.GroupModeCount<=0) then begin
- if FWordEnumThread<>nil then
- ResumeLiveSpelling
- else if LiveSpellingMode=rvlspOnChange then
- StartLiveSpelling;
- end;
- {$ENDIF}
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- HideSmartPopup;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.Change;
- begin
- DoChange(True);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.BeginUpdate;
- begin
- inc(GetRootEditor.LockCount);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EndUpdate;
- begin
- dec(GetRootEditor.LockCount);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.CanPasteRVF: Boolean;
- begin
- Result := Clipboard.HasFormat(CFRV_RVF);
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function TCustomRichViewEdit.CanPasteRTF: Boolean;
- begin
- Result := Clipboard.HasFormat(CFRV_RTF);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.CanPaste: Boolean;
- begin
- Result := (Clipboard.HasFormat(CF_TEXT) or
- {$IFNDEF RVDONOTUSEUNICODE}
- Clipboard.HasFormat(CF_UNICODETEXT) or
- {$ENDIF}
- Clipboard.HasFormat(CF_BITMAP) or
- Clipboard.HasFormat(CF_METAFILEPICT) or
- {$IFNDEF RVDONOTUSERTFIMPORT}
- Clipboard.HasFormat(CFRV_RTF) or
- {$ENDIF}
- Clipboard.HasFormat(CFRV_RVF));
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.Paste;
- {..........................................................}
- procedure PasteRest;
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- if Clipboard.HasFormat(CF_UNICODETEXT) then begin
- if not Style.TextStyles [CurTextStyleNo].Unicode and
- Clipboard.HasFormat(CF_TEXT) then
- PasteText
- else
- PasteTextW;
- end
- else
- {$ENDIF}
- if Clipboard.HasFormat(CF_TEXT) then
- PasteText
- else if Clipboard.HasFormat(CF_BITMAP) then
- PasteBitmap(False)
- else if Clipboard.HasFormat(CF_METAFILEPICT) then
- PasteMetafile(False)
- end;
- {..........................................................}
- var DoDefault: Boolean;
- begin
- if not BeforeChange(False) then exit;
- try
- DoDefault := True;
- if Assigned(FOnPaste) then
- FOnPaste(GetRootEditor, DoDefault);
- if not DoDefault then exit;
- if Clipboard.HasFormat(CFRV_RVF) then
- PasteRVF
- {$IFNDEF RVDONOTUSERTFIMPORT}
- else if Clipboard.HasFormat(CFRV_RTF) then begin
- if not PasteRTF then PasteRest;
- end
- {$ENDIF}
- else
- PasteRest;
- except
- TRVEditRVData(RVData).Beep;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CutDef;
- begin
- if not BeforeChange(False) then exit;
- {$IFDEF RVONCUT}
- if Assigned(FOnCut) then
- FOnCut(GetRootEditor);
- {$ENDIF}
- if CopyDef then DeleteSelection;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMCut(var Message: TWMCut);
- begin
- CutDef;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMPaste(var Message: TWMpaste);
- begin
- Paste;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EMCanPaste(var Message: TMessage);
- begin
- Message.Result := 0;
- if ReadOnly then
- exit;
- case Message.WParam of
- 0:
- Message.Result := Integer(CanPaste);
- CF_BITMAP, CF_TEXT, CF_UNICODETEXT, CF_METAFILEPICT:
- Message.Result := Integer(Clipboard.HasFormat(Message.WParam));
- else
- {$IFNDEF RVDONOTUSERTFIMPORT}
- if UINT(Message.WParam)=CFRV_RTF then
- Message.Result := Integer(CanPasteRTF)
- else
- {$ENDIF}
- if UINT(Message.WParam)=CFRV_RVF then
- Message.Result := Integer(CanPasteRVF)
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.PasteBitmap(TextAsName: Boolean);
- var bmp: TBitmap;
- s: String;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).PasteBitmap(TextAsName);
- exit;
- end;
- {$ENDIF}
- if not BeforeChange(False) then exit;
- if not Clipboard.HasFormat(CF_BITMAP) then exit;
- bmp := TBitmap.Create;
- bmp.Assign(Clipboard);
- if TextAsName and Clipboard.HasFormat(CF_TEXT) then
- s := Clipboard.AsText
- else
- s := '';
- InsertPicture(s,bmp,rvvaBaseline);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.PasteMetafile(TextAsName: Boolean);
- var wmf: TMetafile;
- s: String;
- w,h: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).PasteMetafile(TextAsName);
- exit;
- end;
- {$ENDIF}
- if not BeforeChange(False) then exit;
- if not Clipboard.HasFormat(CF_METAFILEPICT) then exit;
- wmf := TMetafile.Create;
- wmf.Assign(Clipboard);
- {$IFNDEF RVDONOTCORRECTWMFSCALE}
- if wmf.Inch=0 then
- wmf.Inch := 1440;
- {$ENDIF}
- w := wmf.Width;
- h := wmf.Height;
- if TextAsName and Clipboard.HasFormat(CF_TEXT) then
- s := Clipboard.AsText
- else
- s := '';
- InsertPicture(s,wmf,rvvaBaseline);
- if (GetCurrentItem is TRVGraphicItemInfo) and
- (TRVGraphicItemInfo(GetCurrentItem).Image = wmf) then begin
- GetCurrentItem.SetExtraIntProperty(rvepImageWidth, w);
- GetCurrentItem.SetExtraIntProperty(rvepImageHeight, h);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.PasteRVF;
- var Stream: TMemoryStream;
- {$IFNDEF RICHVIEWCBDEF3}
- Stream2: TMemoryStream;
- {$ENDIF}
- mem: Cardinal;
- ptr: Pointer;
- Size: Integer;
- begin
- if not Clipboard.HasFormat(CFRV_RVF) then exit;
- Clipboard.Open;
- Stream := TMemoryStream.Create;
- try
- mem := Clipboard.GetAsHandle(CFRV_RVF);
- Size := GlobalSize(mem);
- Stream.SetSize(Size);
- ptr := GlobalLock(mem);
- Move(ptr^,Stream.Memory^,Size);
- GlobalUnlock(mem);
- Stream.Position := 0;
- Stream.ReadBuffer(Size, SizeOf(Size));
- {$IFDEF RICHVIEWCBDEF3}
- Stream.SetSize(SizeOf(Size)+Size);
- {$ELSE}
- // Delphi2 and Builder1 clear memory streams inside SetSize
- if (Stream.Size<>SizeOf(Size)+Size) then begin
- Stream2 := TMemoryStream.Create;
- try
- Stream.Position := 0;
- Stream2.CopyFrom(Stream,Stream.Size);
- Stream.SetSize(SizeOf(Size)+Size);
- Stream2.Position := 0;
- Stream2.ReadBuffer(Stream.Memory^,SizeOf(Size)+Size);
- finally
- Stream2.Free;
- end;
- end;
- {$ENDIF}
- Stream.Position := SizeOf(Size);
- InsertRVFFromStreamEd(Stream);
- finally
- Stream.Free;
- Clipboard.Close;
- end;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function TCustomRichViewEdit.GetBasePathFromHTMLInClipboard: String;
- var
- mem: Cardinal;
- ptr: Pointer;
- HTML: String;
- http: Boolean;
- p: Integer;
- begin
- Result := '';
- if not Clipboard.HasFormat(CFRV_HTML) then exit;
- Clipboard.Open;
- try
- mem := Clipboard.GetAsHandle(CFRV_HTML);
- SetLength(HTML, GlobalSize(mem));
- ptr := GlobalLock(mem);
- Move(ptr^,PChar(HTML)^, Length(HTML));
- GlobalUnlock(mem);
- finally
- Clipboard.Close;
- end;
- p := Pos(HTMLClipboardSourceURL, HTML);
- if p=0 then
- exit;
- inc(p, Length(HTMLClipboardSourceURL));
- while not (HTML[p] in [#0,#10,#13]) do begin
- Result := Result + HTML[p];
- inc(p);
- end;
- {$IFDEF RICHVIEWCBDEF3}
- Result := UTF8Decode(Result);
- {$ENDIF}
- if Pos('file://', LowerCase(Result))=1 then
- Result := System.Copy(Result, 8, Length(Result));
- http := Pos('http://', LowerCase(Result))=1;
- if http then
- Result := System.Copy(Result, 8, Length(Result));
- for p := 1 to Length(Result) do
- if Result[p]='/' then
- Result[p]:='' ;
- Result := ExtractFilePath(Result);
- if http then begin
- Result := 'http://'+Result;
- for p := 1 to Length(Result) do
- if Result[p]='' then
- Result[p]:='/' ;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.PasteRTF: Boolean;
- var Stream: TMemoryStream;
- mem: Cardinal;
- ptr: Pointer;
- Size: Integer;
- begin
- Result := False;
- if not Clipboard.HasFormat(CFRV_RTF) then exit;
- Clipboard.Open;
- Stream := TMemoryStream.Create;
- try
- mem := Clipboard.GetAsHandle(CFRV_RTF);
- Result := (mem <> 0) and (mem <> INVALID_HANDLE_VALUE);
- if Result then begin
- Size := GlobalSize(mem);
- Stream.SetSize(Size);
- ptr := GlobalLock(mem);
- Move(ptr^,Stream.Memory^,Size);
- GlobalUnlock(mem);
- Stream.Position := 0;
- RTFReadProperties.BasePath := GetBasePathFromHTMLInClipboard;
- try
- InsertRTFFromStreamEd(Stream);
- finally
- RTFReadProperties.BasePath := '';
- end;
- end;
- finally
- Stream.Free;
- Clipboard.Close;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertRTFFromStreamEd(Stream: TStream): Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertRTFFromStreamEd(Stream);
- exit;
- end;
- {$ENDIF}
- Result := True;
- if not BeforeChange(False) then exit;
- if (RVData.PartialSelectedItem<>nil)or not CanDelete then begin
- TRVEditRVData(RVData).Beep;
- exit;
- end;
- TRVEditRVData(RVData).BeginUndoSequence(rvutInsert, True);
- SetUndoGroupMode(True);
- try
- TRVEditRVData(RVData).DeleteSelection_;
- RTFReadProperties;
- Result := TRVEditRVData(RVData).InsertRTFFromStreamEd_(Stream);
- finally
- SetUndoGroupMode(False);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertRTFFromFileEd(const FileName: String): Boolean;
- var Stream: TFileStream;
- begin
- try
- Stream := TFileStream.Create(FileName, fmOpenRead);
- try
- RTFReadProperties.BasePath := ExtractFilePath(FileName);
- Result := InsertRTFFromStreamEd(Stream);
- finally
- Stream.Free;
- RTFReadProperties.BasePath := '';
- end;
- except
- RTFReadProperties.ErrorCode := rtf_ec_FileOpenError;
- Result := False;
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.PasteText;
- begin
- if not BeforeChange(False) then exit;
- if not Clipboard.HasFormat(CF_TEXT) then exit;
- InsertText(Clipboard.AsText, False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentBreakInfo(var AWidth: Byte;
- var AStyle: TRVBreakStyle; var AColor: TColor;
- var ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentBreakInfo(AWidth, AStyle, AColor, ATag);
- exit;
- end;
- {$ENDIF}
- GetBreakInfo(CurItemNo, AWidth, AStyle, AColor, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentBulletInfo(var AName: String;
- var AImageIndex: Integer;
- var AImageList: TCustomImageList;
- var ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentBulletInfo(AName, AImageIndex, AImageList, ATag);
- exit;
- end;
- {$ENDIF}
- GetBulletInfo(CurItemNo, AName, AImageIndex, AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentHotspotInfo(var AName: String;
- var AImageIndex, AHotImageIndex: Integer;
- var AImageList: TCustomImageList;
- var ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentHotspotInfo(AName, AImageIndex, AHotImageIndex, AImageList, ATag);
- exit;
- end;
- {$ENDIF}
- GetHotspotInfo(CurItemNo, AName, AImageIndex, AHotImageIndex, AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentPictureInfo(var AName: String;
- var Agr: TGraphic; var AVAlign: TRVVAlign; var ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentPictureInfo(AName, Agr, AVAlign, ATag);
- exit;
- end;
- {$ENDIF}
- GetPictureInfo(CurItemNo, AName, Agr, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentControlInfo(var AName: String;
- var Actrl: TControl; var AVAlign: TRVVAlign; var ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentControlInfo(AName, Actrl, AVAlign, ATag);
- exit;
- end;
- {$ENDIF}
- GetControlInfo(CurItemNo, AName, Actrl, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentTextInfo(var AText: String; var ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentTextInfo(AText, ATag);
- exit;
- end;
- {$ENDIF}
- GetTextInfo(CurItemNo, AText, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CheckItemClass(ItemNo: Integer; RequiredClass: TCustomRVItemInfoClass);
- begin
- if not (RVData.Items.Objects[ItemNo] is RequiredClass) then
- raise ERichViewError.Create(errRVTypesMismatch);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetBreakInfoEd(ItemNo: Integer; AWidth: Byte;
- AStyle: TRVBreakStyle; AColor: TColor;
- ATag: Integer);
- var item: TRVBreakItemInfo;
- begin
- if not BeforeChange(False) then exit;
- CheckItemClass(ItemNo, TRVBreakItemInfo);
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- item := TRVBreakItemInfo.CreateEx(RVData, AWidth, AStyle, AColor);
- item.Tag := ATag;
- TRVEditRVData(RVData).Do_ModifyItem(ItemNo,'',item);
- Invalidate;
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetBulletInfoEd(ItemNo: Integer; const AName: String;
- AImageIndex: Integer;
- AImageList: TCustomImageList;
- ATag: Integer);
- var item, olditem: TRVBulletItemInfo;
- begin
- if not BeforeChange(False) then exit;
- CheckItemClass(ItemNo, TRVBulletItemInfo);
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- olditem := TRVBulletItemInfo(RVData.Items.Objects[ItemNo]);
- item := TRVBulletItemInfo.CreateEx(RVData, AImageIndex, olditem.ImageList,
- TRVBulletItemInfo(RVData.Items.Objects[ItemNo]).VAlign);
- item.Tag := ATag;
- TRVEditRVData(RVData).Do_ModifyItem(ItemNo, AName, item);
- Invalidate;
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetHotspotInfoEd(ItemNo: Integer; const AName: String;
- AImageIndex, AHotImageIndex: Integer;
- AImageList: TCustomImageList;
- ATag: Integer);
- var item, olditem: TRVHotspotItemInfo;
- begin
- if not BeforeChange(False) then exit;
- CheckItemClass(ItemNo, TRVHotspotItemInfo);
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- olditem := TRVHotspotItemInfo(RVData.Items.Objects[ItemNo]);
- item := TRVHotspotItemInfo.CreateEx(RVData, AImageIndex, AHotImageIndex, olditem.ImageList,
- TRVHotspotItemInfo(RVData.Items.Objects[ItemNo]).VAlign);
- item.Tag := ATag;
- TRVEditRVData(RVData).Do_ModifyItem(ItemNo, AName, item);
- Invalidate;
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetPictureInfoEd(ItemNo: Integer; const AName: String; Agr: TGraphic; AVAlign: TRVVAlign; ATag: Integer);
- var item, olditem: TRVGraphicItemInfo;
- NeedFormat: Boolean;
- OldWidth: Integer;
- begin
- if not BeforeChange(False) then exit;
- CheckItemClass(ItemNo, TRVGraphicItemInfo);
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- olditem := TRVGraphicItemInfo(RVData.Items.Objects[ItemNo]);
- BeginItemModify(ItemNo, OldWidth);
- if olditem.Image = Agr then begin
- Agr := RV_CreateGraphics(TGraphicClass(olditem.Image.ClassType));
- Agr.Assign(olditem.Image);
- end;
- NeedFormat := (Agr.Width<>olditem.Image.Width) or
- (Agr.Height<>olditem.Image.Height) or
- (AValign<>olditem.VAlign);
- item := TRVGraphicItemInfoClass(olditem.ClassType).CreateEx(RVData, nil, AVAlign);
- item.Assign(olditem);
- item.Image.Free;
- item.Image := Agr;
- item.VAlign := AVAlign;
- item.ItemOptions := [];
- item.ParaNo := olditem.ParaNo;
- item.Tag := ATag;
- TRVEditRVData(RVData).Do_ModifyItem(ItemNo, AName, item);
- if NeedFormat then
- EndItemModify(ItemNo, OldWidth);
- Invalidate;
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AdjustControlPlacement(ItemNo: Integer);
- begin
- TRVEditRVData(RVData).AdjustControlPlacement(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AdjustControlPlacement2(Control: TControl);
- var ItemNo: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and
- (InplaceEditor is TCustomRichViewEdit) then
- TCustomRichViewEdit(InplaceEditor).AdjustControlPlacement2(Control);
- {$ENDIF}
- ItemNo := FindControlItemNo(Control);
- if ItemNo=-1 then
- exit;
- if GetItem(ItemNo) is TRVControlItemInfo then
- TRVEditRVData(RVData).AdjustControlPlacement(ItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ResizeControl(ItemNo, NewWidth, NewHeight: Integer);
- begin
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- TRVEditRVData(RVData).Do_Resize(ItemNo, NewWidth, NewHeight, True);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ResizeCurrentControl(NewWidth, NewHeight: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ResizeCurrentControl(NewWidth, NewHeight);
- exit;
- end;
- {$ENDIF}
- ResizeControl(CurItemNo, NewWidth, NewHeight);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetControlInfoEd(ItemNo: Integer; const AName: String;
- AVAlign: TRVVAlign; ATag: Integer);
- var item: TRVControlItemInfo;
- Ref: Boolean;
- begin
- if not BeforeChange(False) then exit;
- CheckItemClass(ItemNo, TRVControlItemInfo);
- item := TRVControlItemInfo(RVData.Items.Objects[ItemNo]);
- Ref := item.VAlign<>AVAlign;
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- SetUndoGroupMode(True);
- TRVEditRVData(RVData).Do_ChangeText(ItemNo, AName);
- TRVEditRVData(RVData).Do_ChangeVAlign(ItemNo, AVAlign);
- SetItemTagEd(ItemNo, ATag);
- SetUndoGroupMode(False);
- if Ref then
- TRVEditRVData(RVData).Reformat(False,False,False,ItemNo,True);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetItemTextEd(ItemNo: Integer; const s: String);
- var Data, StartNo, EndNo, StartOffs, EndOffs: Integer;
- begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- RVData.StoreSelBounds(StartNo, EndNo, StartOffs, EndOffs, False);
- BeginItemModify(ItemNo, Data);
- TRVEditRVData(RVData).Do_ChangeText(ItemNo, s);
- {$IFNDEF RVDONOTUSELIVESPELL}
- TRVEditRVData(RVData).LaterSetBackLiveSpellingTo(ItemNo, 0, True);
- {$ENDIF}
- EndItemModify(ItemNo, Data);
- RVData.RestoreSelBounds(StartNo, EndNo, StartOffs, EndOffs);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentBreakInfo(AWidth: Byte;
- AStyle: TRVBreakStyle; AColor: TColor;
- ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentBreakInfo(AWidth, AStyle, AColor, ATag);
- exit;
- end;
- {$ENDIF}
- SetBreakInfoEd(CurItemNo, AWidth, AStyle, AColor, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentBulletInfo(const AName: String;
- AImageIndex: Integer;
- AImageList: TCustomImageList;
- ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentBulletInfo(AName, AImageIndex, AImageList, ATag);
- exit;
- end;
- {$ENDIF}
- SetBulletInfoEd(CurItemNo, AName, AImageIndex, AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentHotspotInfo(const AName: String;
- AImageIndex, AHotImageIndex: Integer;
- AImageList: TCustomImageList;
- ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentHotspotInfo(AName, AImageIndex, AHotImageIndex,
- AImageList, ATag);
- exit;
- end;
- {$ENDIF}
- SetHotspotInfoEd(CurItemNo, AName, AImageIndex, AHotImageIndex, AImageList, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentPictureInfo(const AName: String; Agr: TGraphic;
- AVAlign: TRVVAlign; ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentPictureInfo(AName, Agr, AVAlign, ATag);
- exit;
- end;
- {$ENDIF}
- SetPictureInfoEd(CurItemNo, AName, Agr, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentControlInfo(const AName: String;
- AVAlign: TRVVAlign; ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentControlInfo(AName, AVAlign, ATag);
- exit;
- end;
- {$ENDIF}
- SetControlInfoEd(CurItemNo, AName, AVAlign, ATag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurrentTag: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentTag;
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- Result := GetItemTag(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurrentItemText: String;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentItemText;
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- Result := GetItemText(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- { Sets value of item property of integer type.
- ItemNo - index of item. Prop identifies the property. Value - new property
- value.
- If AutoReformat is true, document will be reformatted automatically, and
- OnChange event will occur.
- This is an editing-style method. }
- procedure TCustomRichViewEdit.SetItemExtraIntPropertyEd(ItemNo: Integer;
- Prop: TRVExtraItemProperty; Value: Integer; AutoReformat: Boolean);
- var OldValue, Data: Integer;
- begin
- if not GetItemExtraIntProperty(ItemNo, Prop, OldValue) or (Value=OldValue) then
- exit;
- if not BeforeChange(False) then
- exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- if AutoReformat then
- BeginItemModify(ItemNo, Data);
- TRVEditRVData(RVData).Do_ExtraIntProperty(ItemNo, Prop, Value);
- if AutoReformat then begin
- EndItemModify(ItemNo, Data);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- { The same, but sets value of item property of integer type at the position caret -
- in this RVData or in inplace editor. }
- procedure TCustomRichViewEdit.SetCurrentItemExtraIntProperty(
- Prop: TRVExtraItemProperty;
- Value: Integer; AutoReformat: Boolean);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentItemExtraIntProperty(Prop, Value, AutoReformat);
- exit;
- end;
- {$ENDIF}
- SetItemExtraIntPropertyEd(CurItemNo, Prop, Value, AutoReformat);
- end;
- {------------------------------------------------------------------------------}
- { Gets value of item property of integer type at the position caret -
- in this RVData or in inplace editor.
- Prop identifies the property. Value receives a property value.
- Returns True if this item type has this property. }
- function TCustomRichViewEdit.GetCurrentItemExtraIntProperty(
- Prop: TRVExtraItemProperty; var Value: Integer): Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentItemExtraIntProperty(Prop, Value);
- exit;
- end;
- {$ENDIF}
- Result := GetItemExtraIntProperty(CurItemNo, Prop, Value);
- end;
- {------------------------------------------------------------------------------}
- { Sets value of item property of string type.
- ItemNo - index of item. Prop identifies the property. Value - new property
- value.
- If AutoReformat is true, document will be reformatted automatically, and
- OnChange event will occur.
- This is an editing-style method. }
- procedure TCustomRichViewEdit.SetItemExtraStrPropertyEd(ItemNo: Integer;
- Prop: TRVExtraItemStrProperty; const Value: String;
- AutoReformat: Boolean);
- var OldValue: String;
- // Data: Integer;
- begin
- if not GetItemExtraStrProperty(ItemNo, Prop, OldValue) or (Value=OldValue) then
- exit;
- if not BeforeChange(False) then
- exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- //if AutoReformat then
- // BeginItemModify(ItemNo, Data);
- TRVEditRVData(RVData).Do_ExtraStrProperty(ItemNo, Prop, Value);
- if AutoReformat then begin
- // EndItemModify(ItemNo, Data);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- { The same, but sets value of item property of string type at the position caret -
- in this RVData or in inplace editor. }
- procedure TCustomRichViewEdit.SetCurrentItemExtraStrProperty(
- Prop: TRVExtraItemStrProperty; const Value: String; AutoReformat: Boolean);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentItemExtraStrProperty(Prop, Value, AutoReformat);
- exit;
- end;
- {$ENDIF}
- SetItemExtraStrPropertyEd(CurItemNo, Prop, Value, AutoReformat);
- end;
- {------------------------------------------------------------------------------}
- { Gets value of item property of string type at the position caret -
- in this RVData or in inplace editor.
- Prop identifies the property. Value receives a property value.
- Returns True if this item type has this property. }
- function TCustomRichViewEdit.GetCurrentItemExtraStrProperty(
- Prop: TRVExtraItemStrProperty; var Value: String): Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentItemExtraStrProperty(Prop, Value);
- exit;
- end;
- {$ENDIF}
- Result := GetItemExtraStrProperty(CurItemNo, Prop, Value);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetItemTagEd(ItemNo: Integer; ATag: Integer);
- begin
- if TCustomRVItemInfo(RVData.Items.Objects[ItemNo]).Tag=ATag then exit;
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutTag, True);
- TRVEditRVData(RVData).Do_Tag(ItemNo,ATag,True);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentItemText(const s: String);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentItemText(s);
- exit;
- end;
- {$ENDIF}
- SetItemTextEd(CurItemNo, s);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentTag(ATag: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentTag(ATag);
- exit;
- end;
- {$ENDIF}
- if not BeforeChange(False) then exit;
- SetItemTagEd(CurItemNo, ATag);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.SearchText(s: String; SrchOptions: TRVESearchOptions): Boolean;
- begin
- Result := RVData.SearchText(rvseoDown in SrchOptions, rvseoMatchCase in SrchOptions,
- rvseoWholeWord in SrchOptions, s);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AfterVScroll;
- begin
- if Assigned(FOnVScrolled) then FOnVScrolled(Self);
- TRVEditRVData(RVData).ChangeCaret(False,False,False,False);
- GenerateMouseMove;
- InplaceRedrawing(False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AfterHScroll;
- begin
- if Assigned(FOnHScrolled) then FOnHScrolled(Self);
- TRVEditRVData(RVData).ChangeCaret(False,False,False,False);
- GenerateMouseMove;
- InplaceRedrawing(False);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SelectCurrentWord;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SelectCurrentWord;
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).SelectCurrentWord;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SelectCurrentLine;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SelectCurrentLine;
- exit;
- end;
- {$ENDIF}
- RVData.SelectLine(CurItemNo, OffsetInCurItem);
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.InsertPageBreak;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if InplaceEditor<>nil then begin
- Beep;
- exit;
- end;
- {$ENDIF}
- if not BeforeChange(False) then
- exit;
- TRVEditRVData(RVData).InsertPageBreak;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.RemoveCurrentPageBreak;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if InplaceEditor<>nil then begin
- Beep;
- exit;
- end;
- {$ENDIF}
- if not BeforeChange(False) then
- exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutRemovePageBreak, True);
- TRVEditRVData(RVData).Do_PageBreak(CurItemNo,False);
- Change;
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.IsRedoShortcut(Shift: TShiftState;
- Key: Word): Boolean;
- begin
- Result := (ssShift in Shift) and
- (((ssCtrl in Shift) and (Key=ord('Z')) and not (ssAlt in Shift)) or
- ((ssAlt in Shift) and (Key=VK_BACK)));
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.IsUndoShortcut(Shift: TShiftState;
- Key: Word): Boolean;
- begin
- Result := not (ssShift in Shift) and
- (((ssCtrl in Shift) and (Key=ord('Z')) and not (ssAlt in Shift)) or
- ((ssAlt in Shift) and (Key=VK_BACK)));
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetUndoLimit: Integer;
- begin
- Result := TRVEditRVData(RVData).UndoList.Limit;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetUndoLimit(const Value: Integer);
- begin
- TRVEditRVData(RVData).UndoList.Limit := Value;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.BeginUndoCustomGroup(const Name: String);
- begin
- TRVEditRVData(RVData).BeginNamedUndoSequence(rvutCustom, Name, True);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.BeginUndoGroup(UndoType: TRVUndoType);
- begin
- TRVEditRVData(RVData).BeginUndoSequence(UndoType, True);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.RedoAction: TRVUndoType;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- Result:=rvutNone;
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then
- Result := TCustomRichViewEdit(InplaceEditor).RedoAction;
- if Result=rvutNone then
- {$ENDIF}
- Result := TRVEditRVData(RVData).RedoList.CurrentUndoType;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.UndoAction: TRVUndoType;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- Result:=rvutNone;
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then
- Result := TCustomRichViewEdit(InplaceEditor).UndoAction;
- if Result=rvutNone then
- {$ENDIF}
- Result := TRVEditRVData(RVData).UndoList.CurrentUndoType;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.RedoName: String;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) and
- (TCustomRichViewEdit(InplaceEditor).RedoAction<>rvutNone) then begin
- Result := TCustomRichViewEdit(InplaceEditor).RedoName;
- exit;
- end;
- {$ENDIF}
- Result := TRVEditRVData(RVData).RedoList.CurrentUndoCaption;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.UndoName: String;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) and
- (TCustomRichViewEdit(InplaceEditor).UndoAction<>rvutNone) then begin
- Result := TCustomRichViewEdit(InplaceEditor).UndoName;
- exit;
- end;
- {$ENDIF}
- Result := TRVEditRVData(RVData).UndoList.CurrentUndoCaption;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMRedoFromInplace(var Message: TMessage);
- begin
- DestroyInplace;
- Redo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMUndoFromInplace(var Message: TMessage);
- begin
- DestroyInplace;
- Undo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.Redo;
- begin
- if ReadOnly then begin
- Beep;
- exit;
- end;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- if (TCustomRichViewEdit(InplaceEditor).RedoAction<>rvutNone) then begin
- TCustomRichViewEdit(InplaceEditor).Redo;
- exit;
- end;
- if RedoAction<>rvutNone then
- PostMessage(Handle, WM_RVREDOFROMINPLACE,0,0);
- exit;
- end;
- {$ENDIF}
- if RedoAction<>rvutNone then begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- if GetRootEditor.FWordEnumThread<>nil then
- GetRootEditor.FWordEnumThread.Stop(True);
- {$ENDIF}
- TRVEditRVData(RVData).RedoList.Redo(RVData);
- DoChange(False);
- end
- else
- RVData.Beep;
- if Visible then
- SetFocusSilent;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.Undo;
- begin
- if ReadOnly then begin
- Beep;
- exit;
- end;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- if (TCustomRichViewEdit(InplaceEditor).UndoAction<>rvutNone) then begin
- TCustomRichViewEdit(InplaceEditor).Undo;
- exit;
- end;
- if UndoAction<>rvutNone then
- PostMessage(Handle, WM_RVUNDOFROMINPLACE,0,0);
- exit;
- end;
- {$ENDIF}
- if UndoAction<>rvutNone then begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- if GetRootEditor.FWordEnumThread<>nil then
- GetRootEditor.FWordEnumThread.Stop(True);
- {$ENDIF}
- TRVEditRVData(RVData).UndoList.Undo(RVData);
- DoChange(False);
- end
- else
- RVData.Beep;
- if Visible then
- SetFocusSilent;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetUndoGroupMode(GroupUndo: Boolean);
- begin
- TRVEditRVData(RVData).SetUndoGroupMode(GroupUndo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ClearUndo;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then
- TCustomRichViewEdit(InplaceEditor).ClearUndo;
- {$ENDIF}
- with TRVEditRVData(RVData) do begin
- UndoList.Clear;
- RedoList.Clear;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.BeginItemModify(ItemNo: Integer; var ModifyData: Integer);
- begin
- TRVEditRVData(RVData).BeginItemModify(ItemNo, ModifyData);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EndItemModify(ItemNo: Integer; ModifyData: Integer);
- begin
- TRVEditRVData(RVData).EndItemModify(ItemNo, ModifyData);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.BeginCurrentItemModify(var ModifyData: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).BeginCurrentItemModify(ModifyData);
- exit;
- end;
- {$ENDIF}
- BeginItemModify(CurItemNo, ModifyData);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EndCurrentItemModify(ModifyData: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).EndCurrentItemModify(ModifyData);
- exit;
- end;
- {$ENDIF}
- EndItemModify(CurItemNo, ModifyData);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurrentItem: TCustomRVItemInfo;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentItem;
- exit;
- end;
- {$ENDIF}
- Result := GetItem(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurrentItemEx(RequiredClass: TCustomRVItemInfoClass;
- var ItemRichViewEdit: TCustomRichViewEdit;
- var Item: TCustomRVItemInfo): Boolean;
- var Item2: TCustomRVItemInfo;
- ItemRichViewEdit2: TCustomRichViewEdit;
- begin
- if GetItem(CurItemNo) is RequiredClass then begin
- Item := GetItem(CurItemNo);
- ItemRichViewEdit := Self;
- end
- else begin
- Item := nil;
- ItemRichViewEdit := nil;
- end;
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) and
- (TCustomRichViewEdit(InplaceEditor).CurItemNo >= 0) and
- TCustomRichViewEdit(InplaceEditor).GetCurrentItemEx(RequiredClass,
- ItemRichViewEdit2, Item2) then begin
- Item := Item2;
- ItemRichViewEdit := ItemRichViewEdit2;
- end;
- Result := Item<>nil;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.CanChange: Boolean;
- begin
- Result := BeforeChange(True);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetTabNavigation(const Value: TRVTabNavigationType);
- begin
- if Value<>rvtnNone then
- raise ERichViewError.Create(errRViewerOnly);
- end;
- {------------------------------------------------------------------------------}
- {$IFDEF RVUSEIME}
- procedure TCustomRichViewEdit.WMImeStartComposition(var Message: TMessage);
- var
- IMC: HIMC;
- LogFont: TLogFont;
- CF: TCompositionForm;
- begin
- if Style=nil then begin
- inherited;
- exit;
- end;
- Message.Result := 1;
- inherited;
- BeforeUnicode;
- IMC := ImmGetContext(Handle);
- if IMC <> 0 then begin
- Style.TextStyles[CurTextStyleNo].AssignToLogFont(LogFont, Canvas, True);
- ImmSetCompositionFont(IMC, @LogFont);
- CF.dwStyle := CFS_RECT;
- CF.rcArea := ClientRect;
- inc(CF.rcArea.Left, LeftMargin);
- dec(CF.rcArea.Right, RightMargin);
- with Style.ParaStyles[GetCurParaStyleNo] do begin
- inc(CF.rcArea.Left, LeftIndent);
- dec(CF.rcArea.Right, RightIndent);
- end;
- CF.ptCurrentPos := TRVEditRVData(RVData).GetIMEWinCoord;
- if (GetKeyboardLayout(0) and $FFFF)= $0412 then begin// Special support for Korean IME
- CF.rcArea.TopLeft := CF.ptCurrentPos;
- OffsetRect(CF.rcArea,0,1);
- end;
- ImmSetCompositionWindow(IMC, @CF);
- ImmReleaseContext(Handle, IMC);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMImeComposition(var Message: TMessage);
- var
- IMC: HIMC;
- s: String;
- Size: Integer;
- strend: PChar;
- begin
- if BeforeChange(False) and ((Message.LParam and GCS_RESULTSTR) <> 0) then begin
- IMC := ImmGetContext(Handle);
- if IMC<>0 then begin
- if RVNT then begin
- try
- Size := ImmGetCompositionStringW(IMC, GCS_RESULTSTR, nil, 0);
- inc(Size, 2);
- SetLength(s, Size);
- FillChar(PChar(s)^, Size, 0);
- ImmGetCompositionStringW(IMC, GCS_RESULTSTR, PChar(s), Size);
- finally
- ImmReleaseContext(Handle, IMC);
- end;
- strend := RVU_StrScanW(PChar(s), 0, Size div 2);
- if strend<>nil then
- SetLength(s, strend-PChar(s));
- end
- else begin
- // IME support for Win95-98
- // Unfortunately, should properly work not for all versions
- // (you'll get a line of '?')
- try
- Size := ImmGetCompositionStringA(IMC, GCS_RESULTSTR, nil, 0);
- SetLength(s, Size);
- ImmGetCompositionStringA(IMC, GCS_RESULTSTR, PChar(s), Size);
- finally
- ImmReleaseContext(Handle, IMC);
- end;
- s := RVU_KeyToUnicode(s);
- end;
- InsertTextW_(s);
- Message.Result := 0;
- end;
- if (GetKeyboardLayout(0) and $FFFF)= $0412 then // Special support for Korean IME
- PostMessage(Handle, WM_IME_STARTCOMPOSITION,0,0);
- end
- else
- inherited;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AssignEvents(Source: TCustomRichView);
- begin
- inherited AssignEvents(Source);
- if Source is TCustomRichViewEdit then begin
- OnStyleConversion := TCustomRichViewEdit(Source).OnStyleConversion;
- OnParaStyleConversion := TCustomRichViewEdit(Source).OnParaStyleConversion;
- OnPaste := TCustomRichViewEdit(Source).OnPaste;
- {$IFDEF RVONCUT}
- OnCut := TCustomRichViewEdit(Source).OnCut;
- {$ENDIF}
- OnCurParaStyleChanged := TCustomRichViewEdit(Source).OnCurParaStyleChanged;
- OnCurTextStyleChanged := TCustomRichViewEdit(Source).OnCurTextStyleChanged;
- OnCaretMove := TCustomRichViewEdit(Source).OnCaretMove;
- OnDropFiles := TCustomRichViewEdit(Source).OnDropFiles;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- OnOleDragEnter := TCustomRichViewEdit(Source).OnOleDragEnter;
- OnOleDragOver := TCustomRichViewEdit(Source).OnOleDragOver;
- OnOleDrop := TCustomRichViewEdit(Source).OnOleDrop;
- OnOleDragLeave := TCustomRichViewEdit(Source).OnOleDragLeave;
- {$ENDIF}
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.Selecting;
- begin
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AfterCaretMove;
- begin
- if Assigned(FOnCaretMove) and not (csDestroying in ComponentState) then
- FOnCaretMove(Self);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetFReadOnly(Value: Boolean);
- begin
- FReadOnly := Value;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetReadOnly(const Value: Boolean);
- var rve: TCustomRichViewEdit;
- begin
- FReadOnly := Value;
- if FReadOnly then
- TRVEditRVData(RVData).BuildJumpsCoords(True)
- else
- TRVEditRVData(RVData).ClearJumpsCoords;
- rve := Self;
- while (rve.InplaceEditor<>nil) and (rve.InplaceEditor is TCustomRichViewEdit) do
- rve := TCustomRichViewEdit(rve.InplaceEditor);
- TRVEditRVData(rve.RVData).ChangeCaret(False, False, True, False);
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetReadOnly: Boolean;
- begin
- Result := FReadOnly;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELISTS}
- procedure TCustomRichViewEdit.ApplyListStyle(AListNo, AListLevel, AStartFrom: Integer;
- AUseStartFrom, ARecursive: Boolean);
- begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(GetTopLevelEditor.RVData).ApplyListStyle(AListNo, AListLevel, AStartFrom, AUseStartFrom, ARecursive, rvplopChange);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.RemoveLists(ARecursive: Boolean);
- begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(GetTopLevelEditor.RVData).ApplyListStyle(-1, -1, -1, False, ARecursive, rvplopRemove);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ChangeListLevels(LevelDelta: Integer);
- begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(GetTopLevelEditor.RVData).ApplyListStyle(-1, LevelDelta, -1, False, False, rvplopLevel);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.GetCurrentLineCol(var Line, Column: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).GetCurrentLineCol(Line, Column);
- exit;
- end;
- {$ENDIF}
- Line := RVData.GetLineNo(CurItemNo,OffsetInCurItem);
- Column := TRVEditRVData(RVData).CaretOffs+1;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ConvertToHotPicture(ItemNo: Integer);
- var item: TRVHotGraphicItemInfo;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (ItemNo<0) and (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ConvertToHotPicture(ItemNo);
- exit;
- end;
- {$ENDIF}
- if ItemNo<0 then
- ItemNo := CurItemNo;
- if GetItemStyle(ItemNo)<>rvsPicture then
- exit;
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- item := TRVHotGraphicItemInfo.CreateEx(RVData, nil, rvvaBaseline);
- SetUndoGroupMode(True);
- try
- TRVEditRVData(RVData).Do_ReplaceItem(ItemNo, item);
- finally
- SetUndoGroupMode(False);
- end;
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ConvertToPicture(ItemNo: Integer);
- var item: TRVGraphicItemInfo;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (ItemNo<0) and (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ConvertToPicture(ItemNo);
- exit;
- end;
- {$ENDIF}
- if ItemNo<0 then
- ItemNo := CurItemNo;
- if GetItemStyle(ItemNo)<>rvsHotPicture then
- exit;
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyItem, True);
- item := TRVGraphicItemInfo.CreateEx(RVData, nil, rvvaBaseline);
- SetUndoGroupMode(True);
- try
- TRVEditRVData(RVData).Do_ReplaceItem(ItemNo, item);
- finally
- SetUndoGroupMode(False);
- end;
- Change;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetTopLevelEditor: TCustomRichViewEdit;
- begin
- Result := Self;
- {$IFNDEF RVDONOTUSEINPLACE}
- while (Result.InplaceEditor<>nil) and (Result.InplaceEditor is TCustomRichViewEdit) do
- Result := TCustomRichViewEdit(Result.InplaceEditor);
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetRootEditor: TCustomRichViewEdit;
- begin
- Result := RVData.GetAbsoluteRootData.GetParentControl as TCustomRichViewEdit;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.DoChanging: Boolean;
- begin
- Result := True;
- if (GetRootEditor.LockCount<=0) and Assigned(FOnChanging) then
- FOnChanging(GetRootEditor, Result);
- end;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- {------------------------------------------------------------------------------}
- { OLE drag&drop, All these functions are called by FDropTarget:TRVDropTarget,
- related to IDropTarget. }
- {------------------------------------------------------------------------------}
- { Drag cursor is entered into the control. From IDropTarget.DragEnter.
- X,Y - client coordinates.
- Creating RVData.FDragDropCaretInfo, activating scrolling timer,
- calling OleDragOver. }
- function TCustomRichViewEdit.OleDragEnter(X,Y: Integer): Boolean;
- begin
- if (csDesigning in ComponentState) or (Style=nil) or
- (ReadOnly and not (rvflDBRichViewEdit in RVData.GetAbsoluteRootData.Flags)) then begin
- Result := False;
- exit;
- end;
- TRVEditRVData(RVData.GetAbsoluteRootData).CreateDragDropCaretInfo;
- ActivateScrollTimer(True);
- OleDragOver(X, Y);
- TRVEditRVData(TopLevelEditor.RVData).ChangeCaret(False, False, True, False);
- Result := True;
- end;
- {------------------------------------------------------------------------------}
- function ConvertEffect(Effect: Integer): TRVOleDropEffects;
- begin
- Result := [];
- if (DROPEFFECT_COPY and Effect)<>0 then
- Include(Result, rvdeCopy);
- if (DROPEFFECT_MOVE and Effect)<>0 then
- Include(Result, rvdeMove);
- if (DROPEFFECT_LINK and Effect)<>0 then
- Include(Result, rvdeLink);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CallOleDragEnterEvent(const DataObj: IDataObject;
- KeyState: Integer; pt: TPoint; PossibleEffects: Integer; var Effect: Integer);
- var AEffect: TRVOleDropEffect;
- Sender: TCustomRichViewEdit;
- begin
- if Assigned(OnOleDragEnter) then begin
- Sender := RootEditor;
- if Sender<>Self then
- pt := Sender.ScreenToClient(ClientToScreen(pt));
- AEffect := TRVOleDropEffect(Effect and $F);
- OnOleDragEnter(Sender, DataObj, KeysToShiftState(KeyState), pt.X, pt.Y,
- ConvertEffect(PossibleEffects), AEffect);
- Effect := ord(AEffect);
- end;
- end;
- {------------------------------------------------------------------------------}
- { Finished. From IDropTarget.DragLeave
- Deactivating scrolling timer, destroying RVData.FDragDropCaretInfo. }
- procedure TCustomRichViewEdit.OleDragLeave;
- begin
- DeactivateScrollTimer;
- RVData.RemoveDragDropCaret;
- TRVEditRVData(RVData.GetAbsoluteRootData).ReleaseDragDropCaretInfo;
- if RVData.GetDragDropCaretInfo=nil then
- TRVEditRVData(TopLevelEditor.RVData).ChangeCaret(False, False, True, False);
- if Assigned(OnOleDragLeave) then
- OnOleDragLeave(GetRootEditor);
- end;
- {------------------------------------------------------------------------------}
- { Dragging over. From IDropTarget.DragOver.
- X,Y - client coordinates.
- Scrolling if the caret is in 20-pixels area near the top or bottom
- (to-do: scrolling does not work for inplace editor).
- Displaying drag&drop caret. }
- function TCustomRichViewEdit.OleDragOver(X, Y: Integer): Boolean;
- begin
- if Y<20 then
- VScrollDelta := -1
- else if Y>ClientHeight-20 then
- VScrollDelta := +1
- else
- VScrollDelta := 0;
- if (TRVEditRVData(RVData).GetDragDropCaretInfo<>nil) then begin
- RVData.SetDragDropCaretTo(X,Y);
- with TRVEditRVData(RVData).GetDragDropCaretInfo do
- Result := TCustomRVFormattedData(RVData).CanInsertHere(ItemNo, ItemOffs);
- end
- else
- Result := False;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CallOleDragOverEvent(KeyState: Integer; pt: TPoint;
- PossibleEffects: Integer; var Effect: Integer);
- var AEffect: TRVOleDropEffect;
- Sender: TCustomRichViewEdit;
- begin
- if Assigned(OnOleDragOver) then begin
- Sender := RootEditor;
- if Sender<>Self then
- pt := Sender.ScreenToClient(ClientToScreen(pt));
- AEffect := TRVOleDropEffect(Effect and $F);
- OnOleDragOver(Sender, KeysToShiftState(KeyState), pt.X, pt.Y,
- ConvertEffect(PossibleEffects), AEffect);
- Effect := ord(AEffect);
- end;
- end;
- {------------------------------------------------------------------------------}
- { Dropping. From IDropTarget.Drop.
- Known problems:
- - when moving to inplace editor, will be undone in two steps;
- }
- function TCustomRichViewEdit.OleDrop(const DataObj: IDataObject;
- FMove: Boolean; KeyState: Integer; pt: TPoint; PossibleEffects: Integer): Integer;
- var CItemNo, COffs: Integer;
- Format: Word;
- DragDropCaretInfo: TRVDragDropCaretInfo;
- UndoGrouped, Beginning, BeginningIsText, BeforeInsertCalled: Boolean;
- {..............................................}
- procedure BeforeInsert;
- begin
- if BeforeInsertCalled then
- exit;
- BeforeInsertCalled := True;
- if not UndoGrouped then begin
- BeginUndoGroup(rvutInsert);
- SetUndoGroupMode(True);
- //LockWindowUpdate(TopLevelEditor.Handle);
- SendMessage(GetRootEditor.Handle, WM_SETREDRAW, 0, 0);
- UndoGrouped := True;
- end;
- CItemNo := TopLevelEditor.CurItemNo;
- COffs := TopLevelEditor.OffsetInCurItem;
- Beginning := (COffs<=TopLevelEditor.GetOffsBeforeItem(CItemNo));
- if Beginning then
- BeginningIsText := TopLevelEditor.GetItemStyle(CItemNo)>=0;
- end;
- {..............................................}
- procedure AfterInsert;
- var IsText2: Boolean;
- begin
- if UndoGrouped then begin
- //TRVEditRVData(RVData).FinalizeUndoGroup;
- SetUndoGroupMode(False);
- Change;
- end;
- if Beginning then begin
- IsText2 := TopLevelEditor.GetItemStyle(CItemNo)>=0;
- if BeginningIsText and not IsText2 then
- COffs := 0
- else if IsText2 and (COffs=0) then
- COffs := 1;
- end;
- TopLevelEditor.SetSelectionBounds(CItemNo, COffs,
- TopLevelEditor.CurItemNo, TopLevelEditor.OffsetInCurItem);
- if UndoGrouped then begin
- //LockWindowUpdate(0);
- SendMessage(GetRootEditor.Handle, WM_SETREDRAW, 1, 0);
- RefreshAll;
- UndoGrouped := False;
- end;
- end;
- {..............................................}
- function InsertAsRTF: Boolean;
- {$IFNDEF RVDONOTUSERTFIMPORT}
- var Stream : TMemoryStream;
- {$ENDIF}
- begin
- Result := False;
- {$IFNDEF RVDONOTUSERTFIMPORT}
- if not (rvddRTF in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CFRV_RTF) then begin
- Stream := FDropTarget.GetAsStream(DataObj, CFRV_RTF);
- if Stream<>nil then begin
- BeforeInsert;
- try
- InsertRTFFromStreamEd(Stream);
- Result := True;
- finally
- AfterInsert;
- Stream.Free;
- end;
- end;
- end;
- {$ENDIF}
- end;
- {..............................................}
- function InsertAsRVF: Boolean;
- var Stream : TMemoryStream;
- begin
- Result := False;
- if not (rvddRVF in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CFRV_RVF) then begin
- Stream := FDropTarget.GetAsStream(DataObj, CFRV_RVF);
- if Stream<>nil then begin
- BeforeInsert;
- try
- InsertRVFFromStreamEd(Stream);
- Result := True;
- finally
- AfterInsert;
- Stream.Free;
- end;
- end;
- end;
- end;
- {..............................................}
- function InsertAsTextA: Boolean;
- var s: String;
- begin
- Result := False;
- if not (rvddText in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CF_TEXT) and
- FDropTarget.GetAsText(DataObj, CF_TEXT, s) then begin
- BeforeInsert;
- try
- InsertText(s, False);
- Result := True;
- finally
- AfterInsert;
- end;
- end;
- end;
- {..............................................}
- function InsertAsTextW: Boolean;
- {$IFNDEF RVDONOTUSEUNICODE}
- var s: String;
- {$ENDIF}
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEUNICODE}
- if not (rvddUnicodeText in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CF_UNICODETEXT) and
- FDropTarget.GetAsTextW(DataObj, s) then begin
- BeforeInsert;
- try
- InsertTextW_(s);
- Result := True;
- finally
- AfterInsert;
- end;
- end;
- {$ENDIF}
- end;
- {..............................................}
- function InsertAsURL: Boolean;
- var Target, Title: String;
- StyleNo, Tag: Integer;
- StgMedium: TStgMedium;
- PFGD: PFileGroupDescriptor;
- cf: Word;
- begin
- Result := False;
- if not (rvddURL in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CFRV_URL) and
- FDropTarget.GetAsText(DataObj, CFRV_URL, Target) then begin
- Title := Target;
- {
- if FDropTarget.HasFormat(DataObj, CF_HDROP) then begin
- Files := FDropTarget.GetAsFiles(DataObj);
- if (Files.Count=1) and
- (AnsiCompareText(ExtractFileExt(Files[0]), '.url')=0) then
- Title := System.Copy(Files[0], 1, Length(Files[0])-4);
- Files.Free;
- end;
- }
- cf := RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR);
- if FDropTarget.HasFormat(DataObj, cf) and
- FDropTarget.GetMedium(DataObj, cf, StgMedium) then begin
- PFGD := Pointer(GlobalLock(StgMedium.HGlobal));
- Title := pFGD^.fgd[0].cFileName;
- GlobalUnlock(StgMedium.HGlobal);
- if Length(Title)>4 then
- Delete(Title, Length(Title)-3,4)
- else
- Title := Target;
- ReleaseStgMedium(StgMedium);
- end;
- BeforeInsert;
- try
- if Assigned(OnReadHyperlink) then begin
- StyleNo := CurTextStyleNo;
- Tag := 0;
- OnReadHyperlink(Self, Target, '', rvlfURL, StyleNo, Tag, Title);
- CurTextStyleNo := StyleNo;
- InsertStringTag(Title, Tag);
- end
- else
- InsertText(Target, False);
- Result := True;
- finally
- AfterInsert;
- end;
- end;
- end;
- {..............................................}
- function InsertAsText: Boolean;
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- if Style.TextStyles[CurTextStyleNo].Unicode then
- Result := InsertAsTextW or InsertAsTextA
- else
- {$ENDIF}
- Result := InsertAsTextA or InsertAsTextW;
- end;
- {..............................................}
- function InsertAsBitmap: Boolean;
- var bmp: TBitmap;
- begin
- Result := False;
- if not (rvddBitmap in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CF_BITMAP) or
- FDropTarget.HasFormat(DataObj, CF_DIB) then begin
- bmp := FDropTarget.GetAsBitmap(DataObj, Format<>CF_BITMAP);
- if (bmp<>nil) and not bmp.Empty then begin
- BeforeInsert;
- try
- InsertPicture('', bmp, rvvaBaseline);
- Result := True;
- finally
- AfterInsert;
- end;
- end
- else
- bmp.Free;
- end;
- end;
- {..............................................}
- function InsertAsMetafile: Boolean;
- var wmf: TMetafile;
- begin
- Result := False;
- if not (rvddMetafile in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CF_ENHMETAFILE) then begin
- wmf := FDropTarget.GetAsMetafile(DataObj);
- if (wmf<>nil) then begin
- BeforeInsert;
- try
- InsertPicture('', wmf, rvvaBaseline);
- Result := True;
- finally
- AfterInsert;
- end;
- end;
- end;
- end;
- {..............................................}
- function InsertFile(const FileName: String): Boolean;
- var pic: TPicture;
- gr: TGraphic;
- Ext: String;
- begin
- Result := False;
- try
- pic := TPicture.Create;
- try
- pic.LoadFromFile(FileName);
- gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
- gr.Assign(pic.Graphic);
- InsertPicture('', gr, rvvaBaseline);
- Result := True;
- except;
- end;
- pic.Free;
- if Result then
- exit;
- Ext := LowerCase(ExtractFileExt(FileName));
- {$IFNDEF RVDONOTUSERTFIMPORT}
- if Ext='.rtf' then begin
- InsertRTFFromFileEd(FileName);
- Result := True;
- exit;
- end;
- {$ENDIF}
- if Ext='.rvf' then begin
- InsertRVFFromFileEd(FileName);
- Result := True;
- exit;
- end;
- if Ext='.txt' then begin
- InsertTextFromFile(FileName);
- Result := True;
- exit;
- end;
- except
- end;
- end;
- {..............................................}
- function InsertAsFiles: Boolean;
- var Files: TStringList;
- DoDefault: Boolean;
- i: Integer;
- FileAction: TRVDropFileAction;
- begin
- Result := False;
- if not (rvddFiles in AcceptDragDropFormats) then
- exit;
- if FDropTarget.HasFormat(DataObj, CF_HDROP) then begin
- Files := FDropTarget.GetAsFiles(DataObj);
- if (Files<>nil) then begin
- BeforeInsert;
- try
- DoDefault := True;
- FileAction := rvdfNone;
- if Assigned(FOnDropFiles) then
- FOnDropFiles(GetRootEditor, Files, FileAction, DoDefault);
- if DoDefault then begin
- for i := 0 to Files.Count-1 do
- Result := InsertFile(Files[i]) or Result;
- end
- else
- Result := FileAction<>rvdfNone;
- finally
- AfterInsert;
- Files.Free;
- end;
- end;
- end;
- end;
- {..............................................}
- function DoInsert(var DropEffect: TRVOleDropEffect): Boolean;
- var DoDefault: Boolean;
- Sender: TCustomRichViewEdit;
- begin
- DropEffect := rvdeNone;
- if Assigned(FOnOleDrop) then begin
- Result := False;
- if FMove then
- DropEffect := rvdeMove
- else
- DropEffect := rvdeCopy;
- BeforeInsert;
- try
- DoDefault := True;
- Sender := RootEditor;
- if Sender<>Self then
- pt := Sender.ScreenToClient(ClientToScreen(pt));
- FOnOleDrop(Sender, DataObj, KeysToShiftState(KeyState), pt.X, pt.Y,
- ConvertEffect(PossibleEffects), DropEffect, DoDefault);
- Result := not DoDefault;
- finally
- if Result then
- AfterInsert;
- end;
- if Result then
- exit;
- end;
- case Format of
- 0:
- Result := InsertAsRVF or InsertAsRTF or InsertAsURL or InsertAsText or
- InsertAsBitmap or InsertAsMetafile or InsertAsFiles;
- CF_TEXT:
- Result := InsertAsTextA;
- {$IFNDEF RVDONOTUSEUNICODE}
- CF_UNICODETEXT:
- Result := InsertAsTextW;
- {$ENDIF}
- CF_BITMAP:
- Result := InsertAsBitmap;
- CF_ENHMETAFILE:
- Result := InsertAsMetafile;
- else
- begin
- if Format=CFRV_RVF then
- Result := InsertAsRVF
- else if Format=CFRV_RTF then
- Result := InsertAsRTF
- else
- Result := False;
- end;
- end;
- end;
- {..............................................}
- var CustomDropEffect: TRVOleDropEffect;
- begin
- BeforeInsertCalled := False;
- UndoGrouped := False;
- DeactivateScrollTimer;
- RVData.RemoveDragDropCaret;
- DragDropCaretInfo := TRVEditRVData(RVData).GetDragDropCaretInfo;
- if
- not TCustomRVFormattedData(DragDropCaretInfo.RVData).Item_InsideSelection(
- DragDropCaretInfo.ItemNo, DragDropCaretInfo.ItemOffs) then begin
- if TCustomRVFormattedData(DragDropCaretInfo.RVData).CanInsertHere(
- DragDropCaretInfo.ItemNo, DragDropCaretInfo.ItemOffs) then begin
- if RVData.IsDragging then begin
- Format := GetAcceptableRVFormat;
- if Format<>0 then
- if not TRichViewRVData(RVData.GetAbsoluteRootData).FDropSource.StoreData(Format) then
- Format := 0;
- if FMove then begin
- //LockWindowUpdate(TopLevelEditor.Handle);
- SendMessage(GetRootEditor.Handle, WM_SETREDRAW, 0, 0);
- UndoGrouped := True;
- BeginUndoGroup(rvutInsert);
- SetUndoGroupMode(True);
- DeleteSelection;
- RVData.GetAbsoluteRootData.State := RVData.GetAbsoluteRootData.State-
- [rvstCanDragDropDeleteSelection];
- end;
- end
- else
- Format := 0;
- DragDropCaretInfo.RVData := DragDropCaretInfo.RVData.Edit;
- TCustomRVFormattedData(DragDropCaretInfo.RVData).
- SetSelectionBounds(DragDropCaretInfo.ItemNo, DragDropCaretInfo.ItemOffs,
- DragDropCaretInfo.ItemNo, DragDropCaretInfo.ItemOffs);
- if DragDropCaretInfo.RVData is TRVEditRVData then begin
- TRVEditRVData(RVData.GetAbsoluteRootData).ReleaseDragDropCaretInfo;
- if DoInsert(CustomDropEffect) then begin
- if CustomDropEffect=rvdeNone then
- if FMove then
- Result := DROPEFFECT_MOVE
- else
- Result := DROPEFFECT_COPY
- else
- Result := ord(CustomDropEffect)
- end
- else
- Result := DROPEFFECT_NONE;
- end
- else begin
- Result := DROPEFFECT_NONE;
- RVData.Beep;
- end;
- end
- else
- Result := DROPEFFECT_NONE;
- end
- else begin
- DragDropCaretInfo.RVData := DragDropCaretInfo.RVData.Edit;
- TCustomRVFormattedData(DragDropCaretInfo.RVData).
- SetSelectionBounds(DragDropCaretInfo.ItemNo, DragDropCaretInfo.ItemOffs,
- DragDropCaretInfo.ItemNo, DragDropCaretInfo.ItemOffs);
- TCustomRVFormattedData(DragDropCaretInfo.RVData).Invalidate;
- Result := DROPEFFECT_NONE;
- end;
- TRVEditRVData(RVData.GetAbsoluteRootData).ReleaseDragDropCaretInfo;
- {if Result = DROPEFFECT_NONE then
- RVData.Beep;}
- if UndoGrouped then begin
- SetUndoGroupMode(False);
- //LockWindowUpdate(0);
- SendMessage(GetRootEditor.Handle, WM_SETREDRAW, 1, 0);
- RefreshAll;
- end;
- TRVEditRVData(TopLevelEditor.RVData).ChangeCaret(False, False, True, True);
- end;
- {------------------------------------------------------------------------------}
- { Informs about destroying of FDropTarget.
- It is destroyed when ref-count = 0.
- Its ref-count is incremented in WMCreate and decremented in WMDestroy. }
- procedure TCustomRichViewEdit.ReleaseOleDropTargetObject;
- begin
- FDropTarget := nil;
- end;
- {------------------------------------------------------------------------------}
- { Can the format be accepted? }
- function TCustomRichViewEdit.OleCanAcceptFormat(Format: Word): Boolean;
- begin
- case Format of
- CF_TEXT:
- Result := rvddText in AcceptDragDropFormats;
- {$IFNDEF RVDONOTUSEUNICODE}
- CF_UNICODETEXT:
- Result := rvddUnicodeText in AcceptDragDropFormats;
- {$ENDIF}
- CF_BITMAP, CF_DIB:
- Result := rvddBitmap in AcceptDragDropFormats;
- CF_ENHMETAFILE:
- Result := rvddMetafile in AcceptDragDropFormats;
- CF_HDROP:
- Result := rvddFiles in AcceptDragDropFormats;
- else
- begin
- {$IFNDEF RVDONOTUSERTFIMPORT}
- if Format=CFRV_RTF then begin
- Result := rvddRTF in AcceptDragDropFormats;
- exit;
- end;
- {$ENDIF}
- {$IFNDEF RVDONOTUSERVF}
- if Format=CFRV_RVF then begin
- Result := rvddRVF in AcceptDragDropFormats;
- exit;
- end;
- {$ENDIF}
- if Format=CFRV_URL then begin
- Result := rvddURL in AcceptDragDropFormats;
- exit;
- end;
- Result := False;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- { Returns a preferable drag&drop format that can be accepted when dragging
- from itself. }
- function TCustomRichViewEdit.GetAcceptableRVFormat: Word;
- var gr: TGraphic;
- begin
- if rvddRVF in AcceptDragDropFormats then
- Result := CFRV_RVF
- {$IFNDEF RVDONOTUSERTFIMPORT}
- {$IFNDEF RVDONOTUSERTF}
- else
- if rvddRTF in AcceptDragDropFormats then
- Result := CFRV_RTF
- {$ENDIF}
- {$ENDIF}
- else begin
- Result := 0;
- gr := GetSelectedImage;
- if gr<>nil then begin
- if (gr is TBitmap) and (rvddBitmap in AcceptDragDropFormats) then
- Result := CF_BITMAP
- else if (gr is TMetafile) and (rvddMetafile in AcceptDragDropFormats) then
- Result := CF_ENHMETAFILE;
- end;
- if Result=0 then
- {$IFNDEF RVDONOTUSEUNICODE}
- if rvddUnicodeText in AcceptDragDropFormats then
- Result := CF_UNICODETEXT
- else
- {$ENDIF}
- if rvddText in AcceptDragDropFormats then
- Result := CF_TEXT;
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSELIVESPELL}
- { Returns current (at the position of caret) misspelled word and its text style.
- If SelectIt, also selects this word.
- If no selection in the caret position, returns False. }
- function TCustomRichViewEdit.GetCurrentMisspelling(SelectIt: Boolean;
- var Word: String; var StyleNo: Integer): Boolean;
- var ItemNo, Offs, Len: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentMisspelling(SelectIt,
- Word, StyleNo);
- exit;
- end;
- {$ENDIF}
- Result := False;
- ItemNo := CurItemNo;
- Offs := OffsetInCurItem;
- if (GetItemStyle(ItemNo)<0) then begin
- if (ItemNo+1<ItemCount) and not IsFromNewLine(ItemNo+1) and
- (GetItemStyle(ItemNo+1)>=0) then begin
- inc(ItemNo);
- Offs := GetOffsBeforeItem(ItemNo);
- end
- else
- exit;
- end;
- Result := GetItem(ItemNo).GetMisspelling(Offs, Offs, Len);
- if Result then begin
- Word := System.Copy(GetItemTextA(ItemNo), Offs, Len);
- StyleNo := GetItemStyle(ItemNo);
- if SelectIt then begin
- SetSelectionBounds(ItemNo, Offs, ItemNo, Offs+Len);
- Invalidate;
- end;
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- { If misspelled word was clicked, this method adjusts Y coordinate in pt to
- display a popup menu below the misspelled word.
- Pt contains coordinates in document. }
- procedure TCustomRichViewEdit.AdjustPopupMenuPos(var pt: TPoint);
- {$IFNDEF RVDONOTUSELIVESPELL}
- var ItemNo, Offs, Len: Integer;
- {$ENDIF}
- begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- ItemNo := CurItemNo;
- Offs := OffsetInCurItem;
- if (GetItemStyle(ItemNo)<0) then begin
- if (ItemNo+1<ItemCount) and not IsFromNewLine(ItemNo+1) and
- (GetItemStyle(ItemNo+1)>=0) then begin
- inc(ItemNo);
- Offs := GetOffsBeforeItem(ItemNo);
- end
- else
- exit;
- end;
- if GetItem(ItemNo).GetMisspelling(Offs, Offs, Len) then begin
- RVData.Item2DrawItem(ItemNo, Offs, ItemNo, Offs);
- pt.Y := RVData.DrawItems[ItemNo].Top+RVData.DrawItems[ItemNo].Height-RVData.GetVOffs;
- end;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSEDRAGDROP}
- procedure TCustomRichViewEdit.RefreshAll;
- var rve: TCustomRichViewEdit;
- i: Integer;
- begin
- rve := GetRootEditor;
- while rve<>nil do begin
- rve.Refresh;
- for i := 0 to rve.ControlCount-1 do
- if rve.Controls[i]<>rve.InplaceEditor then begin
- rve.Controls[i].Hide;
- rve.Controls[i].Show;
- end;
- rve := TCustomRichViewEdit(rve.InplaceEditor);
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- procedure TCustomRichViewEdit.SetSmartPopupTarget;
- var rve: TCustomRichViewEdit;
- begin
- if TRichViewRVData(RVData).FSmartPopupButton=nil then
- exit;
- rve := TopLevelEditor;
- TRichViewRVData(RVData).FSmartPopupButton.RVData := rve.RVData.GetSourceRVData;
- TRichViewRVData(RVData).FSmartPopupButton.ItemNo := rve.GetCurItemNo;
- TRichViewRVData(RVData).FSmartPopupButton.Item :=
- rve.RVData.GetRVData.GetItem(TRichViewRVData(RVData).FSmartPopupButton.ItemNo);
- TRichViewRVData(RVData).SetSmartPopupCoords;
- end;
- {$ENDIF}
- end.