trichview.support
Re: Insert Hyperlink to selected text or Image |
Author |
Message |
Eric |
Posted: 12/02/2004 11:57:27 The code will make the whole text item hyperlinked, but if I just wanna add hyperlink to the "selected" text, it won't work right. "Sergey Tkachenko" <svt@trichview.com> wrote: >Look at the demo in Demos\Delphi\Assorted\Hypertext\CreateHyperlink. >This demo is simple. > >RichViewActions' code is much more complicated because they do a lot of >additional work such as: >- smart adjusting selection bounds when calling this action; >- creating a hyperlink style basing on the style of the current text >(TrvActionInsertHyperlink.GetHyperlinkStyleNo) instead of using a style with >the predefined index; >- allowing to implement custom forms instead of the standard one; >- working with pictures; >- inserting new hyperlink, if the selection is empty (even after the smart >adjustment) >- removing the hyperlink (if the target is empty) > >The CreateHyperlink demo assumes that there is only text in the editor. >You can modify its procedure: > >procedure TForm1.SetURLToSelection(const URL: String); >var i, StartNo, EndNo, StartOffs, EndOffs: Integer; > rve: TCustomRichViewEdit; >begin > rve := RichViewEdit1.TopLevelEditor; > rve.GetSelectionBounds(StartNo, StartOffs, EndNo, EndOffs, True); > if StartOffs >= rve.GetOffsAfterItem(StartNo) then > inc(StartNo); > if EndOffs <= rve.GetOffsBeforeItem(EndNo) then > dec(EndNo); > rve.BeginUndoGroup(rvutTag); > rve.SetUndoGroupMode(True); > for i := StartNo to EndNo do > begin > if rve.GetItemStyle(i)=rvsPicture then begin > rve.ConvertToHotPicture(i); > rve.SetItemTagEd(i, Integer(StrNew(PChar(URL)))); > end > else if rve.GetItemStyle(i)>=0 then > rve.SetItemTagEd(i, Integer(StrNew(PChar(URL)))); > end; > rve.SetUndoGroupMode(False); >end; > >Note: this procedure must be called only if the selection is not empty. > > > >> The code in the RVAction seems like doing a lot of things but I can't >really >> find out all the usage of it. Can someone provide a more simple but detail >> demo for hyperlink? > > |
Powered by ABC Amber Outlook Express Converter