Hi,
comments see below:
Am 10.06.2009 15:37, schrieb Marcelle7:
Hello,
I'm trying do find text frames in the selected text range. My code
recognizes paragraphs and texttables in the selection. I need to add
textframes recognision.
I've tried to check if xInterface supports service "TextFrame", but it
doesn't (regardless of the anchor type).
I've tried using XTextFramesSupplier but it's null.
This is my code:
XSelectionSupplier xSelSupplier = (XSelectionSupplier)
UnoRuntime.queryInterface(
XSelectionSupplier.class, xController);
Object oSelection = xSelSupplier.getSelection();
XServiceInfo xServInfo = (XServiceInfo) UnoRuntime.queryInterface(
XServiceInfo.class, oSelection);
if (xServInfo.supportsService(
"com.sun.star.text.TextRanges")) {
com.sun.star.container.XIndexAccess xIndexAccess =
(com.sun.star.container.XIndexAccess) UnoRuntime.queryInterface(
com.sun.star.container.XIndexAccess.class, oSelection);
int count = xIndexAccess.getCount();
com.sun.star.text.XTextRange xTextRange = null;
for (int i = 0; i< count; i++) {
try {
xTextRange = (com.sun.star.text.XTextRange)
UnoRuntime.queryInterface(
com.sun.star.text.XTextRange.class,
xIndexAccess.getByIndex(i));
{
XEnumerationAccess xEnumerationAccess =
(XEnumerationAccess) UnoRuntime.queryInterface(
XEnumerationAccess.class, xTextRange);
if (!xEnumerationAccess.equals(null)) {
XEnumeration xParaEnum =
xEnumerationAccess.createEnumeration();
if (!xParaEnum.equals(null)) {
while (xParaEnum.hasMoreElements()) {
XInterface xInterface = null;
try {
xInterface = (XInterface)
UnoRuntime.queryInterface(XInterface.class, xParaEnum.nextElement());
} catch (NoSuchElementException ex) {
Logger.getLogger(SWriter.class.getName()).log(Level.SEVERE, null, ex);
}
if (!xInterface.equals(null)) {
XServiceInfo xServiceInfo =
(XServiceInfo) UnoRuntime.queryInterface(
XServiceInfo.class,
xInterface);
if (!xServiceInfo.equals(null)) {
if
(xServiceInfo.supportsService("com.sun.star.text.TextTable")) {
//do something with the
text table
} else {
if
(xServiceInfo.supportsService("com.sun.star.text.Paragraph")) {
//do something with the
paragraph
}
...
}
you have to query for the XPropertySetInfo:
e.g.
if (object instanceof XTextRange) {XPropertySet xPropertySet =
(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, object);
XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo();
XTextSection xTextSection = null;
XTextFrame xTextFrame = null;
XCell xCell = null;
if (xPropertySetInfo.hasPropertyByName("TextSection")) {
xTextSection = (XTextSection)
UnoRuntime.queryInterface(XTextSection.class,
xPropertySet.getPropertyValue("TextSection"));
}
if (xPropertySetInfo.hasPropertyByName("TextFrame")) {
xTextFrame = (XTextFrame) UnoRuntime.queryInterface(XTextFrame.class,
xPropertySet.getPropertyValue("TextFrame"));
}
if (xPropertySetInfo.hasPropertyByName("Cell")) {
xCell = (XCell) UnoRuntime.queryInterface(XCell.class,
xPropertySet.getPropertyValue("Cell"));
}
}
Regards
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]