OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to get the cursor position in Calc after click on a cell

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
satabau
General User
General User


Joined: 12 Mar 2012
Posts: 34

PostPosted: Mon May 21, 2012 7:59 am    Post subject: How to get the cursor position in Calc after click on a cell Reply with quote

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
View user's profile Send private message
karolus
OOo Advocate
OOo Advocate


Joined: 22 Jun 2011
Posts: 210

PostPosted: Mon May 21, 2012 8:29 am    Post subject: Reply with quote

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
View user's profile Send private message
satabau
General User
General User


Joined: 12 Mar 2012
Posts: 34

PostPosted: Mon May 21, 2012 9:03 am    Post subject: Reply with quote

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
Cool CharOverline
9) LeftBorder
10) CharFontPitchComplex
11) CharWeight
12) CharFont
13) CharCrossedOut
14) VertJustify
15) IsTextWrapped
16) RotateAngle
17) ChartColumnAsLabel
1Cool CharFontNameAsian
19) CharFontCharSetComplex
20) CharFontFamilyComplex
21) IsCellBackgroundTransparent
22) CharPosture
23) HoriJustify
24) CharFontCharSetAsian
25) CharOverlineHasColor
26) CharContoured
27) CharUnderline
2Cool CharFontFamily
29) ParaLastLineAdjust
30) CharFontStyleName
31) ParaIsHangingPunctuation
32) ParaIsCharacterDistance
33) AbsoluteName
34) CharHeightComplex
35) CellBackColor
36) CharStrikeout
37) ParaIsHyphenation
3Cool AsianVerticalMode
39) CharHeightAsian
40) ParaRightMargin
41) CharRelief
42) CharFontStyleNameComplex
43) CharShadowed
44) CharWeightAsian
45) ConditionalFormatLocal
46) BottomBorder
47) ConditionalFormatXML
4Cool CharFontFamilyAsian
49) CharOverlineColor
50) CharWeightComplex
51) ParaIndent
52) DiagonalTLBR
53) CharFontName
54) CharEmphasis
55) CharLocale
56) ParaTopMargin
57) CharUnderlineColor
5Cool ParaIsForbiddenRules
59) Validation
60) CharPostureAsian
61) UserDefinedAttributes
62) CellStyle
63) ParaBottomMargin
64) WritingMode
65) CharUnderlineHasColor
66) ValidationXML
67) CharFontPitch
6Cool CharFontCharSet
69) CharLocaleComplex
70) CharFontPitchAsian
71) ValidationLocal
72) ConditionalFormat
73) RotateReference
74) RightBorder
75) CharWordMode
76) NumberingRules
77) ParaLeftMargin
7Cool Orientation
79) CharColor
80) NumberFormat
81) DiagonalBLTR
82) ShrinkToFit
83) CellProtection
84) CharHeight
85) CharPostureComplex
86) CharLocaleAsian
Back to top
View user's profile Send private message
karolus
OOo Advocate
OOo Advocate


Joined: 22 Jun 2011
Posts: 210

PostPosted: Mon May 21, 2012 10:15 am    Post subject: Reply with quote

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
View user's profile Send private message
satabau
General User
General User


Joined: 12 Mar 2012
Posts: 34

PostPosted: Mon May 21, 2012 12:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
cristena3
Newbie
Newbie


Joined: 24 May 2012
Posts: 1

PostPosted: Thu May 24, 2012 2:43 am    Post subject: just the info i want thanks Reply with quote

just the info i want thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group