0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
| | Dim oDoc As Object
Dim oForms As Object
Dim oDialog As Object
Sub Main
oDoc = ThisComponent
If oDoc.supportsService("com.sun.star.text.TextDocument") Then
oForms = oDoc.getDrawPage().getForms()
ElseIf oDoc.supportsService("com.sun.star.sheet.SpreadsheetDocument") Then
oForms = oDoc.getCurrentController().getActiveSheet().getDrawPage().getForms()
ElseIf oDoc.supportsService("com.sun.star.drawing.DrawingDocument") Then
oForms = oDoc.getCurrentController().getCurrentPage().getForms()
Else
Exit Sub
End If
oDialog = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oDialogModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValues( _
Array("Height", "PositionX", "PositionY", "Width"), _
Array(200, 50, 50, 130) )
oDialog.setModel(oDialogModel)
oCheckModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
oCheckModel.setPropertyValues(_
Array("Height", "Label", "PositionX", "PositionY", "State", "Width"), _
Array(13, "Auto Close", 1, 187, 1, 40))
oDialogModel.insertByName("AutoClose", oCheckModel)
oCloseBtnModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
oCloseBtnModel.setPropertyValues(_
Array("Height", "Label", "PositionX", "PositionY", "PushButtonType", "Width"), _
Array(13, "~Close", 94, 187, com.sun.star.awt.PushButtonType.CANCEL, 35))
oDialogModel.insertByName("CloseBtn", oCloseBtnModel)
oMRIBtnModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
oMRIBtnModel.setPropertyValues(_
Array("Height", "Label", "PositionX", "PositionY", "PushButtonType", "Width"), _
Array(13, "~MRI", 58, 187, com.sun.star.awt.PushButtonType.STANDARD, 35))
oDialogModel.insertByName("MRIBtn", oMRIBtnModel)
oTreeModel = oDialogModel.createInstance("com.sun.star.awt.tree.TreeControlModel")
oTreeModel.setPropertyValues( _
Array("Height", "PositionX", "PositionY", "SelectionType", "ShowsRootHandles", "Width"), _
Array(186, 1, 1, com.sun.star.view.SelectionType.SINGLE, False, 128) )
oDialogModel.insertByName("Tree", oTreeModel)
oTree = oDialog.getControl("Tree")
oTreeDataModel = CreateUnoService("com.sun.star.awt.tree.MutableTreeDataModel")
oTreeDataModel = CreateUnoService( _
"com.sun.star.awt.tree.MutableTreeDataModel")
oRootNode = oTreeDataModel.createNode("Forms", true)
oRootNode.setCollapsedGraphicURL("private:graphicrepository/res/sx18013.png")
oRootNode.setExpandedGraphicURL("private:graphicrepository/res/sx18013.png")
oTreeDataModel.setRoot(oRootNode)
oTreeModel.DataModel = oTreeDataModel
AddChildren(oForms, oTreeDataModel, oRootNode)
oDialog.setVisible(True)
oButtonListener = CreateUnoListener("ButtonPush_", "com.sun.star.awt.XActionListener")
oMRIBtn = oDialog.getControl("MRIBtn")
oMRIBtn.addActionListener(oButtonListener)
oTree.expandNode(oRootNode) ExpandAllNodes(oTree, oRootNode)
oMouseListener = CreateUnoListener("Mouse_", "com.sun.star.awt.XMouseListener")
oTree.addMouseListener(oMouseListener)
oDialog.execute()
oTree.removeMouseListener(oMouseListener)
oMRIBtn.removeActionListener(oButtonListener)
End Sub
Sub CloseDialog()
If oDialog.getControl("AutoClose").State = 1 Then oDialog.endExecute()
End Sub
Function GetFormControl(oForms As Object, oNode As Object) As Object
Dim oControl As Object
Dim sNames() As String
While NOT IsNull(oNode)
n = UBound(sNames) +1
ReDim Preserve sNames(n)
sNames(n) = CStr(oNode.getDisplayValue())
oNode = oNode.getParent()
WEnd
oControl = oForms
For i = UBound(sNames) -1 to 0 step -1
oControl = oControl.getByName(sNames(i))
Next
GetFormControl = oControl
End Function
Sub SelectControl(oForms As Object, oNode As Object) As Object
oControl = GetFormControl(oForms, oNode)
If IsNull(oControl) Then Exit Sub
oDoc.getCurrentController().select(oControl)
End Sub
Sub OpenWithMRI(oForms As Object, oControl As Object)
oControl = GetFormControl(oForms, oControl)
If IsNull(oControl) Then Exit Sub
oController = ThisComponent.getCurrentController().getControl(oControl)
Globalscope.BasicLibraries.loadLibrary("MRILib")
MRILib.Mri(oController)
End Sub
Sub Mouse_mousePressed(oEv As com.sun.star.awt.MouseEvent)
If oEv.Buttons = com.sun.star.awt.MouseButton.RIGHT Then
oTree = oEv.Source.getContext().getControl("Tree")
oNearNode = oTree.getClosestNodeForLocation(oEv.X,oEv.Y)
If IsNull(oNearNode) Then Exit Sub
aRect = CreateUnoStruct("com.sun.star.awt.Rectangle")
aRect.X = oEv.X + oTree.PosSize.X
aRect.Y = oEv.Y + oTree.PosSize.Y
oPopup = CreateUnoService("stardiv.vcl.PopupMenu")
oPopup.insertItem(1, "Select", 0, 0)
oPopup.insertItem(2, "MRI", 0, 1)
oPopup.setCommand(1, "select")
oPopup.setCommand(2, "mri")
n = oPopup.execute(oTree.getContext().getPeer(), aRect, _
com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT)
If n > 0 Then
sCommand = oPopup.getCommand(n)
Select Case sCommand
Case "select"
SelectControl(oForms, oNearNode)
Case "mri"
OpenWithMRI(oForms, oNearNode)
End Select
CloseDialog()
End If
End If
End Sub
Sub Mouse_mouseReleased(oEv)
If oEv.Buttons = com.sun.star.awt.MouseButton.LEFT and oEv.ClickCount = 2 Then
oTree = oEv.Source.getContext().getControl("Tree")
oNearNode = oTree.getClosestNodeForLocation(oEv.X,oEv.Y)
If IsNull(oNearNode) Then Exit Sub
OpenWithMRI(oForms, oNearNode)
CloseDialog
End If
End Sub
Sub Mouse_mouseEntered(ev)
End Sub
Sub Mouse_mouseExited(ev)
End Sub
Sub Mouse_disposing(ev)
End Sub
Sub ButtonPush_actionPerformed(oEv As com.sun.star.awt.ActionEvent)
Dim oSelected() As Object
oTree = oEv.Source.getContext().getControl("Tree")
oSelected = oTree.getSelection()
If IsArray(oSelected) Then
Exit Sub
Else
OpenWithMRI(oForms, oSelected(0))
CloseDialog
End If
End Sub
Sub ButtonPush_dispose(oEv)
End Sub
Sub AddChildren( oContainer As Object, oDataModel As Object, oParent As Object )
For i = 0 To oContainer.getCount() - 1 step 1
oModel = oContainer.getByIndex(i)
sName = oModel.getName()
sImageURL = GetImageURL(oModel.getServiceName())
If HasUnoInterfaces(oModel, _
"com.sun.star.container.XContainer") Then
oChild = oDataModel.createNode(sName, true)
AddChildren(oContainer.getByName(sName), oDataModel, oChild)
Else
oChild = oDataModel.createNode(sName, false)
End If
oChild.setExpandedGraphicURL(sImageURL)
oChild.setCollapsedGraphicURL(sImageURL)
oParent.appendChild(oChild)
Next
End Sub
Sub ExpandAllNodes(oTree As Object, oParent)
For i = 0 To oParent.getChildCount() - 1 step 1
oChild = oParent.getChildAt(i)
oTree.expandNode(oChild)
If oChild.getChildCount() > 0 Then
ExpandAllNodes(oTree, oChild)
End If
Next
End Sub
Function GetImageURL(sServiceName As String) As String
Dim sName As String
sControlService = Mid(sServiceName, 28)
sServices = Array(_
"CheckBox", "ComboBox", "CommandButton", _
"CurrencyField", "DateField", "Edit", "FileControl", _
"FixedText", "Form", "FormattedField", _
"Grid", "GroupBox", "HiddenControl", _
"ImageButton", "ImageControl", "ListBox", _
"NumericField", "PatternField", "RadioButton", _
"TextField", "TimeField", _
".NavigationToolBar", ".SpinButton", ".ScrollBar")
sNames = Array(_
"sx10596", "sx10601", "sx10594", _
"sx10707", "sx10704", "sx10599", "sx10605", _
"sx10597", "sx10593", "sx10728", _
"sx10603", "sx10598", "sx18022", _
"sx10604", "sx10710", "sx10600", _
"sx10706", "sx10708", "sx10595", _
"sx10599", "sx10705", _
"sx10607", "sx10769", "sx10768")
For i = 0 To UBound(sServices) step 1
If sServices(i) = sControlService Then
sName = sNames(i)
Exit For
End If
Next
GetImageURL = "private:graphicrepository/res/" & sName & ".png"
End Function
|