Link Targets: XLinkTargetSupplier


Link targets, also called "jump marks," can be used to jump directly to a specific location. The document navigator contains a list of link targets. The object method getLinks(), defined by the com.sun.star.document.XLinkTargetSupplier interface, provides access to these link targets. The getLinks() method returns an object that supports the XNameAccess interface. In other words, you can access the links using the methods getByName(), getElementNames(), hasByName(), and hasElements().

The object returned by the getLinks() method does not access the links directly, but rather it provides access to other objects that can. To access all of the individual links, first use the getLinks() method to access the master list of links. Use this returned object to access each "family" of links based on the family name. For example, to obtain an object that can access all of the table links, use oDoc.getLinks().getByName("Tables"). After obtaining a family of links, you can also obtain the individual links by name. At this final step, you have access to both the name of the link and the object that is linked. The macro in Listing 5 obtains all of the link families and the links that they contain, and then displays the link's name.

Listing 5: GetJumpTargets is found in the Generic module in this chapter's source code files as SC12.sxw.
start example
 Sub GetJumpTargets   Dim sLinkNames  'Tables, Text Frames, Headings, Bookmarks, etc...   Dim vOneLink    'One link type   Dim i%          'Index variable   Dim s$          'General string   Dim vtemp   sLinkNames = ThisComponent.getLinks().getElementNames()   MsgBox Join(sLinkNames, Chr$(10))   For i = 0 To UBound(sLinkNames)     vOneLink = ThisComponent.getLinks().getByName(sLinkNames(i))     s = s & sLinkNames(i) & " = "     If IsEmpty(vOneLink) Then       s = s & "Empty"     Else       s = s & Join(vOneLink.getElementNames(), ";")       REM To obtain the actual link object, such as a       REM text table or a graphics object, use the following       REM vtemp = vOneLink.getElementNames()       REM vObj = vOneLink.getByName(vtemp(0))     End If     s = s & CHR$(10)   Next   MsgBox s, 0, "Jump Targets" End Sub 
end example
 

You can use jump marks (link targets) to jump directly to a specific location when a document is loaded. Use jump marks to focus the cursor at a specific location when a document is opened, as shown in Listing 6 . The JumpMark attribute sets the name from the values shown in Figure 4 . Using the value "Sample Dataoutline" causes the cursor to focus at the "Sample Data" heading rather than at the table "Table 1".

Listing 6: Use the JumpMark property to jump to a link target.
start example
 Dim Props(0) Props(0).Name = "JumpMark" Props(0).Value = "Table1table" sUrl = "file://c:/docs/Special_doc.sxw" vDoc = StarDesktop.LoadComponentFromUrl(sUrl, "_blank", 0, Props()) 
end example
 
click to expand
Figure 4: Jump (link) targets in ThisComponent.

You can also use the jump mark as part of the URL (see Listing 7 ) by placing it at the end of the URL separated by an octothorpe character (#). If the jump mark contains any special characters , such as spaces, they must be encoded using standard URL notation. For example, a space is encoded as %20.

Listing 7: Use the JumpMark property to jump to a link target.
start example
 sUrl = "file://c:/docs/Special_doc.sxw#Tableltable" vDoc = StarDesktop.LoadComponentFromUrl(sUrl, "_blank", 0, Props()) 
end example
 
Note  

The character "#" has many names , including: number sign, pound sign, hash, sharp, crunch, hex, grid, pigpen, tic-tac-toe, splat , crosshatch, and octothorpe, to name a few.




OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net