1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Event" script:
language=
"StarBasic">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- CLASS ROOT FIELDS ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 Private _Type As String
' Must be EVENT
18 Private _EventSource As Object
19 Private _EventType As String
20 Private _EventName As String
21 Private _SubComponentName As String
22 Private _SubComponentType As Long
23 Private _ContextShortcut As String
24 Private _ButtonLeft As Boolean
' com.sun.star.awt.MouseButton.XXX
25 Private _ButtonRight As Boolean
26 Private _ButtonMiddle As Boolean
27 Private _XPos As Variant
' Null or Long
28 Private _YPos As Variant
' Null or Long
29 Private _ClickCount As Long
30 Private _KeyCode As Integer
' com.sun.star.awt.Key.XXX
31 Private _KeyChar As String
32 Private _KeyFunction As Integer
' com.sun.star.awt.KeyFunction.XXX
33 Private _KeyAlt As Boolean
34 Private _KeyCtrl As Boolean
35 Private _KeyShift As Boolean
36 Private _FocusChangeTemporary As Boolean
' False if user action in same window
37 Private _RowChangeAction As Long
' com.sun.star.sdb.RowChangeAction.XXX
38 Private _Recommendation As String
' "IGNORE
" or
""
40 REM -----------------------------------------------------------------------------------------------------------------------
41 REM --- CONSTRUCTORS / DESTRUCTORS ---
42 REM -----------------------------------------------------------------------------------------------------------------------
43 Private Sub Class_Initialize()
45 _EventSource = Nothing
46 _EventType =
""
47 _EventName =
""
48 _SubComponentName =
""
49 _SubComponentType = -
1
50 _ContextShortcut =
""
51 _ButtonLeft = False
' See com.sun.star.awt.MouseButton.XXX
58 _KeyChar =
""
59 _KeyFunction = com.sun.star.awt.KeyFunction.DONTKNOW
63 _FocusChangeTemporary = False
65 _Recommendation =
""
66 End Sub
' Constructor
68 REM -----------------------------------------------------------------------------------------------------------------------
69 Private Sub Class_Terminate()
70 On Local Error Resume Next
71 Call Class_Initialize()
72 End Sub
' Destructor
74 REM -----------------------------------------------------------------------------------------------------------------------
76 Call Class_Terminate()
77 End Sub
' Explicit destructor
79 REM -----------------------------------------------------------------------------------------------------------------------
80 REM --- CLASS GET/LET/SET PROPERTIES ---
81 REM -----------------------------------------------------------------------------------------------------------------------
82 Property Get ButtonLeft() As Variant
83 ButtonLeft = _PropertyGet(
"ButtonLeft
")
84 End Property
' ButtonLeft (get)
86 REM -----------------------------------------------------------------------------------------------------------------------
87 Property Get ButtonMiddle() As Variant
88 ButtonMiddle = _PropertyGet(
"ButtonMiddle
")
89 End Property
' ButtonMiddle (get)
91 REM -----------------------------------------------------------------------------------------------------------------------
92 Property Get ButtonRight() As Variant
93 ButtonRight = _PropertyGet(
"ButtonRight
")
94 End Property
' ButtonRight (get)
96 REM -----------------------------------------------------------------------------------------------------------------------
97 Property Get ClickCount() As Variant
98 ClickCount = _PropertyGet(
"ClickCount
")
99 End Property
' ClickCount (get)
101 REM -----------------------------------------------------------------------------------------------------------------------
102 Property Get ContextShortcut() As Variant
103 ContextShortcut = _PropertyGet(
"ContextShortcut
")
104 End Property
' ContextShortcut (get)
106 REM -----------------------------------------------------------------------------------------------------------------------
107 Property Get EventName() As Variant
108 EventName = _PropertyGet(
"EventName
")
109 End Property
' EventName (get)
111 REM -----------------------------------------------------------------------------------------------------------------------
112 Property Get EventSource() As Variant
113 EventSource = _PropertyGet(
"EventSource
")
114 End Property
' EventSource (get)
116 REM -----------------------------------------------------------------------------------------------------------------------
117 Property Get EventType() As Variant
118 EventType = _PropertyGet(
"EventType
")
119 End Property
' EventType (get)
121 REM -----------------------------------------------------------------------------------------------------------------------
122 Property Get FocusChangeTemporary() As Variant
123 FocusChangeTemporary = _PropertyGet(
"FocusChangeTemporary
")
124 End Property
' FocusChangeTemporary (get)
126 REM -----------------------------------------------------------------------------------------------------------------------
127 Property Get KeyAlt() As Variant
128 KeyAlt = _PropertyGet(
"KeyAlt
")
129 End Property
' KeyAlt (get)
131 REM -----------------------------------------------------------------------------------------------------------------------
132 Property Get KeyChar() As Variant
133 KeyChar = _PropertyGet(
"KeyChar
")
134 End Property
' KeyChar (get)
136 REM -----------------------------------------------------------------------------------------------------------------------
137 Property Get KeyCode() As Variant
138 KeyCode = _PropertyGet(
"KeyCode
")
139 End Property
' KeyCode (get)
141 REM -----------------------------------------------------------------------------------------------------------------------
142 Property Get KeyCtrl() As Variant
143 KeyCtrl = _PropertyGet(
"KeyCtrl
")
144 End Property
' KeyCtrl (get)
146 REM -----------------------------------------------------------------------------------------------------------------------
147 Property Get KeyFunction() As Variant
148 KeyFunction = _PropertyGet(
"KeyFunction
")
149 End Property
' KeyFunction (get)
151 REM -----------------------------------------------------------------------------------------------------------------------
152 Property Get KeyShift() As Variant
153 KeyShift = _PropertyGet(
"KeyShift
")
154 End Property
' KeyShift (get)
156 REM -----------------------------------------------------------------------------------------------------------------------
157 Property Get ObjectType() As String
158 ObjectType = _PropertyGet(
"ObjectType
")
159 End Property
' ObjectType (get)
161 REM -----------------------------------------------------------------------------------------------------------------------
162 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
164 ' a Collection object if pvIndex absent
165 ' a Property object otherwise
167 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
168 vPropertiesList = _PropertiesList()
169 sObject = Utils._PCase(_Type)
170 If IsMissing(pvIndex) Then
171 vProperty = PropertiesGet._Properties(sObject,
"", vPropertiesList)
173 vProperty = PropertiesGet._Properties(sObject,
"", vPropertiesList, pvIndex)
174 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
178 Set Properties = vProperty
180 End Function
' Properties
182 REM -----------------------------------------------------------------------------------------------------------------------
183 Property Get Recommendation() As Variant
184 Recommendation = _PropertyGet(
"Recommendation
")
185 End Property
' Recommendation (get)
187 REM -----------------------------------------------------------------------------------------------------------------------
188 Property Get RowChangeAction() As Variant
189 RowChangeAction = _PropertyGet(
"RowChangeAction
")
190 End Property
' RowChangeAction (get)
192 REM -----------------------------------------------------------------------------------------------------------------------
193 Public Function Source() As Variant
194 ' Return the object having fired the event: Form, Control or SubForm
195 ' Else return the root Database object
196 Source = _PropertyGet(
"Source
")
197 End Function
' Source (get)
199 REM -----------------------------------------------------------------------------------------------------------------------
200 Property Get SubComponentName() As String
201 SubComponentName = _PropertyGet(
"SubComponentName
")
202 End Property
' SubComponentName (get)
204 REM -----------------------------------------------------------------------------------------------------------------------
205 Property Get SubComponentType() As Long
206 SubComponentType = _PropertyGet(
"SubComponentType
")
207 End Property
' SubComponentType (get)
209 REM -----------------------------------------------------------------------------------------------------------------------
210 Property Get XPos() As Variant
211 XPos = _PropertyGet(
"XPos
")
212 End Property
' XPos (get)
214 REM -----------------------------------------------------------------------------------------------------------------------
215 Property Get YPos() As Variant
216 YPos = _PropertyGet(
"YPos
")
217 End Property
' YPos (get)
219 REM -----------------------------------------------------------------------------------------------------------------------
220 REM --- CLASS METHODS ---
221 REM -----------------------------------------------------------------------------------------------------------------------
222 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
223 ' Return property value of psProperty property name
225 Utils._SetCalledSub(
"Form.getProperty
")
226 If IsMissing(pvProperty) Then Call _TraceArguments()
227 getProperty = _PropertyGet(pvProperty)
228 Utils._ResetCalledSub(
"Form.getProperty
")
230 End Function
' getProperty
232 REM -----------------------------------------------------------------------------------------------------------------------
233 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
234 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
236 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
239 End Function
' hasProperty
241 REM -----------------------------------------------------------------------------------------------------------------------
242 REM --- PRIVATE FUNCTIONS ---
243 REM -----------------------------------------------------------------------------------------------------------------------
244 Public Sub _Initialize(poEvent As Object)
246 Dim oObject As Object, i As Integer
247 Dim sShortcut As String, sAddShortcut As String, sArray() As String
248 Dim sImplementation As String, oSelection As Object
249 Dim iCurrentDoc As Integer, oDoc As Object
250 Const cstDatabaseForm =
"com.sun.star.comp.forms.ODatabaseForm
"
252 If _ErrorHandler() Then On Local Error Goto Error_Function
254 Set oObject = poEvent.Source
255 _EventSource = oObject
256 sArray = Split(Utils._getUNOTypeName(poEvent),
".
")
257 _EventType = UCase(sArray(UBound(sArray))
258 If Utils._hasUNOProperty(poEvent,
"EventName
") Then _EventName = poEvent.EventName
260 Select Case _EventType
261 Case
"DOCUMENTEVENT
"
262 'SubComponent processing
263 Select Case UCase(_EventName)
264 Case UCase(
"OnSubComponentClosed
"), UCase(
"OnSubComponentOpened
")
265 Set oSelection = poEvent.ViewController.getSelection()(
0)
266 _SubComponentName = oSelection.Name
267 With com.sun.star.sdb.application.DatabaseObject
268 Select Case oSelection.Type
269 Case .TABLE : _SubComponentType = acTable
270 Case .QUERY : _SubComponentType = acQuery
271 Case .FORM : _SubComponentType = acForm
272 Case .REPORT : _SubComponentType = acReport
278 Case
"EVENTOBJECT
"
279 Case
"ACTIONEVENT
"
280 Case
"FOCUSEVENT
"
281 _FocusChangeTemporary = poEvent.Temporary
282 Case
"ITEMEVENT
"
283 Case
"INPUTEVENT
",
"KEYEVENT
"
284 _KeyCode = poEvent.KeyCode
285 _KeyChar = poEvent.KeyChar
286 _KeyFunction = poEvent.KeyFunc
287 _KeyAlt = Utils._BitShift(poEvent.Modifiers, com.sun.star.awt.KeyModifier.MOD2)
288 _KeyCtrl = Utils._BitShift(poEvent.Modifiers, com.sun.star.awt.KeyModifier.MOD1)
289 _KeyShift = Utils._BitShift(poEvent.Modifiers, com.sun.star.awt.KeyModifier.SHIFT)
290 Case
"MOUSEEVENT
"
291 _ButtonLeft = Utils._BitShift(poEvent.Buttons, com.sun.star.awt.MouseButton.LEFT)
292 _ButtonRight = Utils._BitShift(poEvent.Buttons, com.sun.star.awt.MouseButton.RIGHT)
293 _ButtonMiddle = Utils._BitShift(poEvent.Buttons, com.sun.star.awt.MouseButton.MIDDLE)
296 _ClickCount = poEvent.ClickCount
297 Case
"ROWCHANGEEVENT
"
298 _RowChangeAction = poEvent.Action
299 Case
"TEXTEVENT
"
300 Case
"ADJUSTMENTEVENT
",
"DOCKINGEVENT
",
"ENDDOCKINGEVENT
",
"ENDPOPUPMODEEVENT
",
"ENHANCEDMOUSEEVENT
" _
301 ,
"MENUEVENT
",
"PAINTEVENT
",
"SPINEVENT
",
"VCLCONTAINEREVENT
",
"WINDOWEVENT
"
307 ' Evaluate ContextShortcut
308 sShortcut =
""
309 sImplementation = Utils._ImplementationName(oObject)
312 Case sImplementation =
"stardiv.Toolkit.UnoDialogControl
" ' Dialog
313 _ContextShortcut =
"Dialogs!
" & _EventSource.Model.Name
315 Case Left(sImplementation,
16) =
"stardiv.Toolkit.
" ' Control in Dialog
316 _ContextShortcut =
"Dialogs!
" & _EventSource.Context.Model.Name _
317 & "!
" & _EventSource.Model.Name
322 iCurrentDoc = _A2B_.CurrentDocIndex(, False)
323 If iCurrentDoc
< 0 Then Goto Exit_Function
324 Set oDoc = _A2B_.CurrentDocument(iCurrentDoc)
326 ' To manage
2x triggers of
"Before record action
" form event
327 If _EventType =
"ROWCHANGEEVENT
" And sImplementation
<> "com.sun.star.comp.forms.ODatabaseForm
" Then _Recommendation =
"IGNORE
"
329 Do While sImplementation
<> "SwXTextDocument
"
330 sAddShortcut =
""
331 Select Case sImplementation
332 Case
"com.sun.star.comp.forms.OFormsCollection
" ' Do nothing
334 If Utils._hasUNOProperty(oObject,
"Model
") Then
335 If oObject.Model.Name
<> "MainForm
" And oObject.Model.Name
<> "Form
" Then sAddShortcut = Utils._Surround(oObject.Model.Name)
336 ElseIf Utils._hasUNOProperty(oObject,
"Name
") Then
337 If oObject.Name
<> "MainForm
" And oObject.Name
<> "Form
" Then sAddShortcut = Utils._Surround(oObject.Name)
339 If sAddShortcut
<> "" Then
340 If sImplementation = cstDatabaseForm And oDoc.DbConnect = DBCONNECTBASE Then sAddShortcut = sAddShortcut
& ".Form
"
341 sShortcut = sAddShortcut
& Iif(Len(sShortcut)
> 0,
"!
" & sShortcut,
"")
345 Case Utils._hasUNOProperty(oObject,
"Model
")
346 Set oObject = oObject.Model.Parent
347 Case Utils._hasUNOProperty(oObject,
"Parent
")
348 Set oObject = oObject.Parent
352 sImplementation = Utils._ImplementationName(oObject)
354 ' Add Forms! prefix
355 ' Select Case oDoc.DbConnect
356 ' Case DBCONNECTBASE
357 If Utils._hasUNOProperty(oObject,
"Args
") Then
' Current object is a SwXTextDocument
358 For i =
0 To UBound(oObject.Args)
359 If oObject.Args(i).Name =
"DocumentTitle
" Then
360 sAddShortcut = Utils._Surround(oObject.Args(i).Value)
365 sShortcut =
"Forms!
" & sAddShortcut
& "!
" & sShortcut
366 ' Case DBCONNECTFORM
367 ' sShortcut =
"Forms!
0!
" & sShortcut
370 sArray = Split(sShortcut,
"!
")
371 ' If presence of
"Forms!myform!myform.Form
", eliminate
2nd element
372 ' Eliminate anyway blanco subcomponents (e.g; Forms!!myForm)
373 If UBound(sArray)
>=
2 Then
374 If UCase(sArray(
1))
& ".FORM
" = UCase(sArray(
2)) Then sArray(
1) =
""
375 sArray = Utils._TrimArray(sArray)
377 ' If first element ends with .Form, remove suffix
378 If UBound(sArray)
>=
1 Then
379 If Len(sArray(
1))
> 5 And Right(sArray(
1),
5) =
".Form
" Then sArray(
1) = left(sArray(
1), Len(sArray(
1)) -
5)
380 sShortcut = Join(sArray,
"!
")
382 If Len(sShortcut)
>=
2 Then
383 If Right(sShortcut,
1) =
"!
" Then
384 _ContextShortcut = Left(sShortcut, Len(sShortcut) -
1)
386 _ContextShortcut = sShortcut
393 TraceError(TRACEWARNING, Err,
"Event.Initialize
", Erl)
395 End Sub
' _Initialize V0.9
.1
397 REM -----------------------------------------------------------------------------------------------------------------------
398 Private Function _PropertiesList() As Variant
400 Dim sSubComponentName As String, sSubComponentType As String
401 sSubComponentName = Iif(_SubComponentType
> -
1,
"SubComponentName
",
"")
402 sSubComponentType = Iif(_SubComponentType
> -
1,
"SubComponentType
",
"")
403 Dim sXPos As String, sYPos As String
404 sXPos = Iif(IsNull(_XPos),
"",
"XPos
")
405 sYPos = Iif(IsNull(_YPos),
"",
"YPos
")
407 _PropertiesList = Utils._TrimArray(Array( _
408 "ButtonLeft
",
"ButtonRight
",
"ButtonMiddle
",
"ClickCount
" _
409 ,
"ContextShortcut
",
"EventName
",
"EventType
",
"FocusChangeTemporary
", _
410 ,
"KeyAlt
",
"KeyChar
",
"KeyCode
",
"KeyCtrl
",
"KeyFunction
",
"KeyShift
" _
411 ,
"ObjectType
",
"Recommendation
",
"RowChangeAction
",
"Source
" _
412 , sSubComponentName, sSubComponentType, sXPos, sYPos _
415 End Function
' _PropertiesList
417 REM -----------------------------------------------------------------------------------------------------------------------
418 Private Function _PropertyGet(ByVal psProperty As String) As Variant
419 ' Return property value of the psProperty property name
421 If _ErrorHandler() Then On Local Error Goto Error_Function
422 Utils._SetCalledSub(
"Event.get
" & psProperty)
423 Dim vEMPTY As Variant
424 _PropertyGet = vEMPTY
426 Select Case UCase(psProperty)
427 Case UCase(
"ButtonLeft
")
428 _PropertyGet = _ButtonLeft
429 Case UCase(
"ButtonMiddle
")
430 _PropertyGet = _ButtonMiddle
431 Case UCase(
"ButtonRight
")
432 _PropertyGet = _ButtonRight
433 Case UCase(
"ClickCount
")
434 _PropertyGet = _ClickCount
435 Case UCase(
"ContextShortcut
")
436 _PropertyGet = _ContextShortcut
437 Case UCase(
"FocusChangeTemporary
")
438 _PropertyGet = _FocusChangeTemporary
439 Case UCase(
"EventName
")
440 _PropertyGet = _EventName
441 Case UCase(
"EventSource
")
442 _PropertyGet = _EventSource
443 Case UCase(
"EventType
")
444 _PropertyGet = _EventType
445 Case UCase(
"KeyAlt
")
446 _PropertyGet = _KeyAlt
447 Case UCase(
"KeyChar
")
448 _PropertyGet = _KeyChar
449 Case UCase(
"KeyCode
")
450 _PropertyGet = _KeyCode
451 Case UCase(
"KeyCtrl
")
452 _PropertyGet = _KeyCtrl
453 Case UCase(
"KeyFunction
")
454 _PropertyGet = _KeyFunction
455 Case UCase(
"KeyShift
")
456 _PropertyGet = _KeyShift
457 Case UCase(
"ObjectType
")
459 Case UCase(
"Recommendation
")
460 _PropertyGet = _Recommendation
461 Case UCase(
"RowChangeAction
")
462 _PropertyGet = _RowChangeAction
463 Case UCase(
"Source
")
464 If _ContextShortcut =
"" Then
465 _PropertyGet = _EventSource
467 _PropertyGet = getObject(_ContextShortcut)
469 Case UCase(
"SubComponentName
")
470 _PropertyGet = _SubComponentName
471 Case UCase(
"SubComponentType
")
472 _PropertyGet = _SubComponentType
473 Case UCase(
"XPos
")
474 If IsNull(_XPos) Then Goto Trace_Error
476 Case UCase(
"YPos
")
477 If IsNull(_YPos) Then Goto Trace_Error
484 Utils._ResetCalledSub(
"Event.get
" & psProperty)
487 ' Errors are not displayed to avoid display infinite cycling
488 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0, False, psProperty)
489 _PropertyGet = vEMPTY
492 TraceError(TRACEABORT, Err,
"Event._PropertyGet
", Erl)
493 _PropertyGet = vEMPTY
495 End Function
' _PropertyGet V1.1
.0