如何从鼠标单击OpenOffice BASIC宏中获取文档坐标 [英] How to get Document-Coordinates from a Mouse Click in an OpenOffice BASIC Macro

查看:190
本文介绍了如何从鼠标单击OpenOffice BASIC宏中获取文档坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在鼠标单击或悬停的位置粘贴(例如[CTRL + V])任何东西(最好是图像,形状)(使用按键激活时)。我不知道如何获得我单击的文档(X,Y)上的位置

I want to paste (like [CTRL+V]) anything (preferably image, shape) at the position I click or hover with the mouse (when using a key to activate). I don't know how to get the position on the document (X, Y) I clicked.

(Apache OpenOffice,SDraw文档,OpenOffice BASIC宏)

(Apache OpenOffice, SDraw-Document, OpenOffice BASIC Macro)


  • 提示/提示方式从文档上的鼠标单击/鼠标位置获取位置。 (我需要哪个类,侦听器,组件)

注释
类似 com.sun.star.awt.XMouseClickHandler 是完美的,如果给定的 oEvent 给了我X + Y文档,我点击的位置。
(也许您知道如何激活 PopupTrigger ?( com.sun.star.awt.MouseEvent ))

Notes: Something like a com.sun.star.awt.XMouseClickHandler would be perfect, if the given oEvent gave me the X+Y of the document, where I clicked. (Maybe you know how to "activate" PopupTrigger? (com.sun.star.awt.MouseEvent))

我尝试使用提到的 XMouseClickHandler 获取X + Y。
不幸的是,X + Y是指窗口的相对位置,而不是形状或文本在文档上的实际位置。

I tried using the mentioned XMouseClickHandler to get X+Y. Sadly, X+Y refer to the relative position of the window and not the actual position a shape or text would have on the document.

执行:我的Sub Main 是通过顶部的菜单按钮执行的。
然后单击任意位置(通过MsgBox)将输出该单击的坐标。

Execution: My Sub Main is executed via a Menu-Button at the top. Then clicking anywhere will output (via MsgBox) the coordinates of that click.

唯一的问题:坐标相对于角

Global gListener As Object

Sub Main
  gListener = CreateUnoListener("Listener_","com.sun.star.awt.XMouseClickHandler")
  ThisComponent.CurrentController.addMouseClickHandler(gListener) 
End Sub

Sub Listener_mousePressed(oMouseEvent) As Boolean
   ThisComponent.CurrentController.removeMouseClickHandler(gListener)

   Msg = "Position: "
   Msg = Msg & oMouseEvent.X & "/" & oMouseEvent.Y
   MsgBox(Msg)

   REM :: I want something like:
   REM :: Msg = "Position: " & oMouseEvent.PositionOnDocument.X
   REM :: Msg = Msg & "/" & oMouseEvent.PositionOnDocument.Y
   REM :: MsgBox(Msg)
End Sub



我的参考文献:



由于我的所有搜索都没有发现任何帮助,因此到目前为止,我的所有信息均来自官方参考文献/文档。

My references:

All my information come from the official references/docs so far, since all my searches did not find anything helpful.

  • Class-List: http://api.libreoffice.org/docs/idl/ref/annotated.html Here you can see docs for the used classes (com.sun.star.awt.XMouseClickHandler, com.sun.star.awt.MouseEvent)
  • Infos about listener: https://help.libreoffice.org/3.6/Basic/CreateUnoListener_Function_Runtime

预先感谢。

推荐答案

我终于找到了一种方法来获取鼠标单击的确切坐标(相对于文档)
我设法从底部的StatusBar获取信息,该信息通常显示坐标(对我来说以厘米为单位)。

I finally found a way to get the exact coordinates of a mouse click (relative to the document). I managed to get the information from the StatusBar at the bottom, which usually shows the coordinates (for me in centimeters).

这是我现在使用的函数用来获取位置(X / Y):

Here is the function I now use to get the position (X / Y):

REM // Warning: If there is currently a selection, the returning Point will instead show the coordinates of the selection!
Sub GetMousePositionOnDocument as com.sun.star.awt.Point
  Dim aPosition As New com.sun.star.awt.Point
  Dim o1, o2, o3, o4, o5, o6

  REM // First get AccessibleContext of the Window of the active Frame of the Application
  o1 = StarDesktop.ActiveFrame.ContainerWindow.AccessibleContext

  REM // 7th AC of o1 is the StatusBar at the bottom;
  o2 = o1.GetAccessibleChild(6).AccessibleContext

  REM // 2nd AC of o2 is the Position + Size of the Selection (e.g: "10,95 / 14,980,00 x 0,00") 
  o3 = o2.GetAccessibleChild(1)
  o4 = o3.GetText()

  REM // Taking out only the coordinates from o4
  REM // TODO: Check for negatives (longer)
  o5 = LEFT(o4, 4)
  o6 = MID(o4, 8, 5)

  aPosition.X = o5
  aPosition.Y = o6

  REM // Return
  GetMousePositionOnDocument = aPosition
End Sub

注意:此函数在我之前的 Listener_mousePressed 内部调用。

Note: This function is called inside my previous Listener_mousePressed from above.

希望这对其他人也有用。

Hopefully this will work for others, too.

我花了很多钱在调试器中手动检查ThisComponent和StarDesktop窗口的每个ApplicationContext的时间很长。

I spent very much time on checking every single ApplicationContext of the Window(s) of ThisComponent and StarDesktop manually in the debugger.

这是在需要时遍历ThisDesktop的起点其他值。
ThisComponent.CurrentController.Frame.ComponentWindow.AccessibleContext

This is the starting point for iterating through ThisDesktop if needed for other values. ThisComponent.CurrentController.Frame.ComponentWindow.AccessibleContext

我知道 GetAccessibleChild()函数的索引,因为我检查了调试器。当然,到达 o3 还有更好的方法,您不应该期望每个人都有相同的AccessibleContext。

I "know" the indexes for the GetAccessibleChild()-Function because I inspected the debugger. There certainly are better ways to get to o3 and you should not expect everyone to have the same AccessibleContext's.

这篇关于如何从鼠标单击OpenOffice BASIC宏中获取文档坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆