| View previous topic :: View next topic |
| Author |
Message |
satabau General User

Joined: 12 Mar 2012 Posts: 34
|
Posted: Mon May 21, 2012 7:59 am Post subject: How to get the cursor position in Calc after click on a cell |
|
|
I've made this
| Code: | public class SelectionChangeListener implements XSelectionChangeListener{
public void selectionChanged(com.sun.star.lang.EventObject arg0){
System.out.println("LISTENER");
}
public void disposing(com.sun.star.lang.EventObject arg0){}
} |
and this:
| Code: |
XSelectionSupplier xSelectionSupplier = (XSelectionSupplier)UnoRuntime.queryInterface(XSelectionSupplier.class, xSpreadsheetView);
SelectionChangeListener temp = new SelectionChangeListener();
xSelectionSupplier.addSelectionChangeListener(temp);
|
and everytime I click on my opened sheet, it prints the string "LISTENER".
After clicking, the cursor is in a new position and I want to know that position.
Can you help me? |
|
| Back to top |
|
 |
karolus OOo Advocate

Joined: 22 Jun 2011 Posts: 208
|
Posted: Mon May 21, 2012 8:29 am Post subject: |
|
|
Hi
I m copy and paste from Mri ( thisComponent.CurrentSelection.Position ) :
| Code: | import com.sun.star.awt.Point;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.frame.XModel;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.XInterface;
public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
try
{
XModel xModel = UnoRuntime.queryInterface(
XModel.class, oInitialTarget);
XInterface oXInterface = xModel.getCurrentSelection();
XPropertySet xPropSet = UnoRuntime.queryInterface(
XPropertySet.class, oXInterface);
Point aPoint = (Point) AnyConverter.toObject(Point.class, xPropSet.getPropertyValue("Position"));
int nX = aPoint.X;
int nY = aPoint.Y;
}
catch (WrappedTargetException e1)
{
// getPropertyValue
e1.printStackTrce();
}
catch (IllegalArgumentException e2)
{
//
e2.printStackTrce();
}
catch (UnknownPropertyException e3)
{
// getPropertyValue
e3.printStackTrce();
}
} |
|
|
| Back to top |
|
 |
satabau General User

Joined: 12 Mar 2012 Posts: 34
|
Posted: Mon May 21, 2012 9:03 am Post subject: |
|
|
Thanks for the answer but I have a com.sun.star.beans.UnknownPropertyException.
I've printed all the properties and there's no property called "Position".
1) TableBorder
2) ParaAdjust
3) CharFontNameComplex
4) CharFontStyleNameAsian
5) TopBorder
6) ChartRowAsLabel
7) ShadowFormat
CharOverline
9) LeftBorder
10) CharFontPitchComplex
11) CharWeight
12) CharFont
13) CharCrossedOut
14) VertJustify
15) IsTextWrapped
16) RotateAngle
17) ChartColumnAsLabel
1 CharFontNameAsian
19) CharFontCharSetComplex
20) CharFontFamilyComplex
21) IsCellBackgroundTransparent
22) CharPosture
23) HoriJustify
24) CharFontCharSetAsian
25) CharOverlineHasColor
26) CharContoured
27) CharUnderline
2 CharFontFamily
29) ParaLastLineAdjust
30) CharFontStyleName
31) ParaIsHangingPunctuation
32) ParaIsCharacterDistance
33) AbsoluteName
34) CharHeightComplex
35) CellBackColor
36) CharStrikeout
37) ParaIsHyphenation
3 AsianVerticalMode
39) CharHeightAsian
40) ParaRightMargin
41) CharRelief
42) CharFontStyleNameComplex
43) CharShadowed
44) CharWeightAsian
45) ConditionalFormatLocal
46) BottomBorder
47) ConditionalFormatXML
4 CharFontFamilyAsian
49) CharOverlineColor
50) CharWeightComplex
51) ParaIndent
52) DiagonalTLBR
53) CharFontName
54) CharEmphasis
55) CharLocale
56) ParaTopMargin
57) CharUnderlineColor
5 ParaIsForbiddenRules
59) Validation
60) CharPostureAsian
61) UserDefinedAttributes
62) CellStyle
63) ParaBottomMargin
64) WritingMode
65) CharUnderlineHasColor
66) ValidationXML
67) CharFontPitch
6 CharFontCharSet
69) CharLocaleComplex
70) CharFontPitchAsian
71) ValidationLocal
72) ConditionalFormat
73) RotateReference
74) RightBorder
75) CharWordMode
76) NumberingRules
77) ParaLeftMargin
7 Orientation
79) CharColor
80) NumberFormat
81) DiagonalBLTR
82) ShrinkToFit
83) CellProtection
84) CharHeight
85) CharPostureComplex
86) CharLocaleAsian |
|
| Back to top |
|
 |
karolus OOo Advocate

Joined: 22 Jun 2011 Posts: 208
|
Posted: Mon May 21, 2012 10:15 am Post subject: |
|
|
Hi
I know nothing about java, .... but the Python-code below works for me, it prints X- and Y-position from Current Cell ( →The Cell i have clicked )
| Code: | def snippet( oInitialTarget ):
""" """
try:
oCurrentSelection = oInitialTarget.getCurrentSelection()
aPosition = oCurrentSelection.Position
nX = aPosition.X
nY = aPosition.Y
print nX, nY
except WrappedTargetException as e:
# getPropertyValue
print(e)
except UnknownPropertyException as e:
# getPropertyValue
print(e)
|
I call it from inside another Python function with:
| Code: | | snippet( XSCRIPTCONTEXT.getDocument()) |
Karo |
|
| Back to top |
|
 |
satabau General User

Joined: 12 Mar 2012 Posts: 34
|
Posted: Mon May 21, 2012 12:23 pm Post subject: |
|
|
I tried this
| Code: |
XModel xDocModel = (XModel) UnoRuntime.queryInterface(XModel.class, ProblemSolving.xSpreadsheetDocument);
XInterface oXInterface = (XInterface) xDocModel.getCurrentSelection();
XPropertySet srcProps = UnoRuntime.queryInterface(XPropertySet.class, oXInterface);
String cell = (String) srcProps.getPropertyValue("AbsoluteName");
|
The string is something like : "$Sheet1.$A$0" and I extracted column and cell from that string. Surely it's not the best way to get the position, but the others didn't work.
Thank you all |
|
| Back to top |
|
 |
cristena3 Newbie

Joined: 24 May 2012 Posts: 1
|
Posted: Thu May 24, 2012 2:43 am Post subject: just the info i want thanks |
|
|
| just the info i want thanks |
|
| Back to top |
|
 |
|