Hi Kent,
Is there any way to get the current values of the
scrollbar for a given document?
there is always a way ;-) ... The question is do you want to step along
it :-)
Ok ... as far as I know the XScrollbar Interface is only implemented by
css.awt.UnoControlScrollBar ... but not anywhere where it would be
helpful to get the Scrollbar of a document.
So the only way I see to gain the information you want is using the
Accessibility API ... a working sample for that would look like follows
------------------------------------------------------------
public static void main(String[] args) {
try {
XComponentContext xContext =
com.sun.star.comp.helper.Bootstrap.bootstrap();
// get the servie manager rom the office
XMultiComponentFactory xMCF = xContext.getServiceManager();
// create a new instance of the the desktop
Object oDesktop = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext );
// query the desktop object for the XComponentLoader
XComponentLoader xCLoader = ( XComponentLoader )
UnoRuntime.queryInterface(
XComponentLoader.class, oDesktop );
PropertyValue LoadArgs[] = new PropertyValue []{};
XComponent xComp = xCLoader.loadComponentFromURL(
"private:factory/swriter", "_blank", 0, LoadArgs );
XModel xModel = (XModel)
UnoRuntime.queryInterface(XModel.class, xComp);
XAccessible xRoot = (XAccessible) UnoRuntime.queryInterface(
XAccessible.class,
xModel.getCurrentController().getFrame().getContainerWindow());
getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLL_BAR);
XAccessibleValue aValue = (XAccessibleValue)
UnoRuntime.queryInterface(
XAccessibleValue.class, SearchedContext);
System.out.println("Scrollbar Value: "+aValue.getCurrentValue());
} catch(Exception e){
System.err.println(" Exception " + e);
e.printStackTrace(System.err);
}
System.out.println("... done");
}
public static XAccessibleContext SearchedContext = null;
public static XAccessible SearchedAccessible = null;
public static void getAccessibleObjectForRole(XAccessible xacc,
short role) {
XAccessibleContext ac = xacc.getAccessibleContext();
boolean isShowing = ac.getAccessibleStateSet()
.contains(
com.sun.star.accessibility.AccessibleStateType.SHOWING);
if ((ac.getAccessibleRole() == role) && isShowing) {
SearchedContext = ac;
SearchedAccessible = xacc;
} else {
int k = ac.getAccessibleChildCount();
if (ac.getAccessibleChildCount() > 100) {
k = 50;
}
for (int i = 0; i < k; i++) {
try {
getAccessibleObjectForRole(
ac.getAccessibleChild(i), role);
if (SearchedContext != null) {
return;
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
System.out.println("Couldn't get Child");
}
}
}
}
------------------------------------------------------------
For sure not overly elegant and you are in trouble when there are two
Scrollbars ;-)
So the question is, can you circumvent the need for the ScrollbarValue
by gaining something else ... and this depends on what you are trying to
achieve.
Hope that helps
Regards
Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]