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=
"SF_FormControl" script:
language=
"StarBasic" script:
moduleType=
"normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFDocuments library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
14 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
15 ''' SF_FormControl
16 ''' ================
17 ''' Manage the controls belonging to a form or subform stored in a document
18 ''' Each instance of the current class represents a single control within a form, a subform or a tablecontrol
19 ''' A prerequisite is that all controls within the same form, subform or tablecontrol must have
20 ''' a unique name. This is also true for the individual radio buttons belonging to the same group.
21 ''' A common group name must identify such a single group.
23 ''' The focus is clearly set on getting and setting the values displayed by the controls of the form,
24 ''' not on their formatting. The latter is easily accessible via the XControlModel and XControlView
25 ''' UNO objects.
26 ''' Essentially a single property
"Value
" maps many alternative UNO properties depending each on
27 ''' the control type.
29 ''' Service invocations:
30 ''' Dim myForm As Object, myControl As Object
31 ''' Set myForm = ... (read the comments in the SF_Form module)
32 ''' Set myControl = myForm.Controls(
"myTextBox
")
33 ''' myControl.Value =
"Current time =
" & Now()
35 ''' REM the control is the subject of an event
36 ''' Sub OnEvent(ByRef poEvent As Object)
37 ''' Dim myControl As Object
38 ''' Set myControl = CreateScriptService(
"SFDocuments.FormEvent
", poEvent)
40 ''' Detailed user documentation:
41 ''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/
03/sf_formcontrol.html?DbPAR=BASIC
43 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
45 REM ================================================================== EXCEPTIONS
47 Private Const FORMCONTROLTYPEERROR =
"FORMCONTROLTYPEERROR
"
49 REM ============================================================= PRIVATE MEMBERS
51 Private [Me] As Object
52 Private [_Parent] As Object
53 Private ObjectType As String
' Must be FORMCONTROL
54 Private ServiceName As String
56 ' Control naming and context
57 Private _Name As String
58 Private _IndexOfNames As Long
' Index in ElementNames array. Used to access SF_Form._ControlCache
59 Private _FormName As String
' Parent form name
60 Private _ParentForm As Object
' Parent form or subform instance
61 Private _ParentIsTable As Boolean
' True when parent is a table control
63 ' Control UNO references
64 Private _ControlModel As Object
' com.sun.star.awt.XControlModel
65 Private _ControlView As Object
' com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
67 ' Control attributes
68 Private _ImplementationName As String
69 Private _ControlType As String
' One of the CTLxxx constants
70 Private _ClassId As Integer
' Numerical type of control
72 ' Cache storage for table controls
73 Private _ControlNames As Variant
' Array of control names
74 Private _ControlCache As Variant
' Array of control objects sorted like ElementNames of XControlModel
76 REM ============================================================ MODULE CONSTANTS
79 Private Const CTLBUTTON =
"Button
" ' 2
80 Private Const CTLCHECKBOX =
"CheckBox
" ' 5
81 Private Const CTLCOMBOBOX =
"ComboBox
" ' 7
82 Private Const CTLCURRENCYFIELD =
"CurrencyField
" ' 18
83 Private Const CTLDATEFIELD =
"DateField
" ' 15
84 Private Const CTLFILECONTROL =
"FileControl
" ' 12
85 Private Const CTLFIXEDTEXT =
"FixedText
" ' 10
86 Private Const CTLFORMATTEDFIELD =
"FormattedField
" ' Idem TextField
87 Private Const CTLGROUPBOX =
"GroupBox
" ' 8
88 Private Const CTLHIDDENCONTROL =
"HiddenControl
" ' 13
89 Private Const CTLIMAGEBUTTON =
"ImageButton
" ' 4
90 Private Const CTLIMAGECONTROL =
"ImageControl
" ' 14
91 Private Const CTLLISTBOX =
"ListBox
" ' 6
92 Private Const CTLNAVIGATIONBAR =
"NavigationBar
" ' 22
93 Private Const CTLNUMERICFIELD =
"NumericField
" ' 17
94 Private Const CTLPATTERNFIELD =
"PatternField
" ' 19
95 Private Const CTLRADIOBUTTON =
"RadioButton
" ' 3
96 Private Const CTLSCROLLBAR =
"ScrollBar
" ' 20
97 Private Const CTLSPINBUTTON =
"SpinButton
" ' 21
98 Private Const CTLTABLECONTROL =
"TableControl
" ' 11
99 Private Const CTLTEXTFIELD =
"TextField
" ' 9
100 Private Const CTLTIMEFIELD =
"TimeField
" ' 16
102 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
104 REM -----------------------------------------------------------------------------
105 Private Sub Class_Initialize()
107 Set [_Parent] = Nothing
108 ObjectType =
"FORMCONTROL
"
109 ServiceName =
"SFDocuments.FormControl
"
112 _FormName =
""
113 _ParentIsTable = False
114 Set _ParentForm = Nothing
115 Set _ControlModel = Nothing
116 Set _ControlView = Nothing
117 _ImplementationName =
""
118 _ControlType =
""
120 _ControlNames = Array()
121 _ControlCache = Array()
122 End Sub
' SFDocuments.SF_FormControl Constructor
124 REM -----------------------------------------------------------------------------
125 Private Sub Class_Terminate()
126 Call Class_Initialize()
127 End Sub
' SFDocuments.SF_FormControl Destructor
129 REM -----------------------------------------------------------------------------
130 Public Function Dispose() As Variant
131 If Not IsNull([_Parent]) And _IndexOfNames
>=
0 Then [_Parent]._ControlCache(_IndexOfNames) = Empty
132 Call Class_Terminate()
133 Set Dispose = Nothing
134 End Function
' SFDocuments.SF_FormControl Explicit Destructor
136 REM ================================================================== PROPERTIES
138 REM -----------------------------------------------------------------------------
139 Property Get Action() As Variant
140 ''' The Action property specifies the action triggered when the button is clicked
141 ''' Accepted values: none, submitForm, resetForm, refreshForm, moveToFirst, moveToLast,
142 ''' moveToNext, moveToPrev, saveRecord, moveToNew, deleteRecord, undoRecord
143 Action = _PropertyGet(
"Action
",
"")
144 End Property
' SFDocuments.SF_FormControl.Action (get)
146 REM -----------------------------------------------------------------------------
147 Property Let Action(Optional ByVal pvAction As Variant)
148 ''' Set the updatable property Action
149 _PropertySet(
"Action
", pvAction)
150 End Property
' SFDocuments.SF_FormControl.Action (let)
152 REM -----------------------------------------------------------------------------
153 Property Get Caption() As Variant
154 ''' The Caption property refers to the text associated with the control
155 Caption = _PropertyGet(
"Caption
",
"")
156 End Property
' SFDocuments.SF_FormControl.Caption (get)
158 REM -----------------------------------------------------------------------------
159 Property Let Caption(Optional ByVal pvCaption As Variant)
160 ''' Set the updatable property Caption
161 _PropertySet(
"Caption
", pvCaption)
162 End Property
' SFDocuments.SF_FormControl.Caption (let)
164 REM -----------------------------------------------------------------------------
165 Property Get ControlSource() As Variant
166 ''' The ControlSource property specifies the rowset field mapped onto the actual control
167 ControlSource = _PropertyGet(
"ControlSource
",
"")
168 End Property
' SFDocuments.SF_FormControl.ControlSource (get)
170 REM -----------------------------------------------------------------------------
171 Property Get ControlType() As String
172 ''' Return the type of the actual control:
"CheckBox
",
"TextField
",
"DateField
", ...
173 ControlType = _PropertyGet(
"ControlType
")
174 End Property
' SFDocuments.SF_FormControl.ControlType
176 REM -----------------------------------------------------------------------------
177 Property Get Default() As Variant
178 ''' The Default property specifies whether a command button is the default (OK) button.
179 Default = _PropertyGet(
"Default
", False)
180 End Property
' SFDocuments.SF_FormControl.Default (get)
182 REM -----------------------------------------------------------------------------
183 Property Let Default(Optional ByVal pvDefault As Variant)
184 ''' Set the updatable property Default
185 _PropertySet(
"Default
", pvDefault)
186 End Property
' SFDocuments.SF_FormControl.Default (let)
188 REM -----------------------------------------------------------------------------
189 Property Get DefaultValue() As Variant
190 ''' The DefaultValue property specifies how the control is initialized in a new record
191 DefaultValue = _PropertyGet(
"DefaultValue
", Null)
192 End Property
' SFDocuments.SF_FormControl.DefaultValue (get)
194 REM -----------------------------------------------------------------------------
195 Property Let DefaultValue(Optional ByVal pvDefaultValue As Variant)
196 ''' Set the updatable property DefaultValue
197 _PropertySet(
"DefaultValue
", pvDefaultValue)
198 End Property
' SFDocuments.SF_FormControl.DefaultValue (let)
200 REM -----------------------------------------------------------------------------
201 Property Get Enabled() As Variant
202 ''' The Enabled property specifies if the control is accessible with the cursor.
203 Enabled = _PropertyGet(
"Enabled
", False)
204 End Property
' SFDocuments.SF_FormControl.Enabled (get)
206 REM -----------------------------------------------------------------------------
207 Property Let Enabled(Optional ByVal pvEnabled As Variant)
208 ''' Set the updatable property Enabled
209 _PropertySet(
"Enabled
", pvEnabled)
210 End Property
' SFDocuments.SF_FormControl.Enabled (let)
212 REM -----------------------------------------------------------------------------
213 Property Get Format() As Variant
214 ''' The Format property specifies the format in which to display dates and times.
215 Format = _PropertyGet(
"Format
",
"")
216 End Property
' SFDocuments.SF_FormControl.Format (get)
218 REM -----------------------------------------------------------------------------
219 Property Let Format(Optional ByVal pvFormat As Variant)
220 ''' Set the updatable property Format
221 ''' NB: Format is read-only for formatted field controls
222 _PropertySet(
"Format
", pvFormat)
223 End Property
' SFDocuments.SF_FormControl.Format (let)
225 REM -----------------------------------------------------------------------------
226 Property Get ListCount() As Long
227 ''' The ListCount property specifies the number of rows in a list box or a combo box
228 ListCount = _PropertyGet(
"ListCount
",
0)
229 End Property
' SFDocuments.SF_FormControl.ListCount (get)
231 REM -----------------------------------------------------------------------------
232 Property Get ListIndex() As Variant
233 ''' The ListIndex property specifies which item is selected in a list box or combo box.
234 ''' In case of multiple selection, the index of the first one is returned or only one is set
235 ListIndex = _PropertyGet(
"ListIndex
", -
1)
236 End Property
' SFDocuments.SF_FormControl.ListIndex (get)
238 REM -----------------------------------------------------------------------------
239 Property Let ListIndex(Optional ByVal pvListIndex As Variant)
240 ''' Set the updatable property ListIndex
241 _PropertySet(
"ListIndex
", pvListIndex)
242 End Property
' SFDocuments.SF_FormControl.ListIndex (let)
244 REM -----------------------------------------------------------------------------
245 Property Get ListSource() As Variant
246 ''' The ListSource property specifies the data contained in a combobox or a listbox
247 ''' as a zero-based array of string values
248 ListSource = _PropertyGet(
"ListSource
",
"")
249 End Property
' SFDocuments.SF_FormControl.ListSource (get)
251 REM -----------------------------------------------------------------------------
252 Property Let ListSource(Optional ByVal pvListSource As Variant)
253 ''' Set the updatable property ListSource
254 _PropertySet(
"ListSource
", pvListSource)
255 End Property
' SFDocuments.SF_FormControl.ListSource (let)
257 REM -----------------------------------------------------------------------------
258 Property Get ListSourceType() As Variant
259 ''' The ListSourceType property specifies the kind of data source used to fill the list data of a listbox or a combobox
260 ListSourceType = _PropertyGet(
"ListSourceType
",
"")
261 End Property
' SFDocuments.SF_FormControl.ListSourceType (get)
263 REM -----------------------------------------------------------------------------
264 Property Let ListSourceType(Optional ByVal pvListSourceType As Variant)
265 ''' Set the updatable property ListSourceType
266 _PropertySet(
"ListSourceType
", pvListSourceType)
267 End Property
' SFDocuments.SF_FormControl.ListSourceType (let)
269 REM -----------------------------------------------------------------------------
270 Property Get Locked() As Variant
271 ''' The Locked property specifies if a control is read-only
272 Locked = _PropertyGet(
"Locked
", False)
273 End Property
' SFDocuments.SF_FormControl.Locked (get)
275 REM -----------------------------------------------------------------------------
276 Property Let Locked(Optional ByVal pvLocked As Variant)
277 ''' Set the updatable property Locked
278 _PropertySet(
"Locked
", pvLocked)
279 End Property
' SFDocuments.SF_FormControl.Locked (let)
281 REM -----------------------------------------------------------------------------
282 Property Get MultiSelect() As Variant
283 ''' The MultiSelect property specifies whether a user can make multiple selections in a listbox
284 MultiSelect = _PropertyGet(
"MultiSelect
", False)
285 End Property
' SFDocuments.SF_FormControl.MultiSelect (get)
287 REM -----------------------------------------------------------------------------
288 Property Let MultiSelect(Optional ByVal pvMultiSelect As Variant)
289 ''' Set the updatable property MultiSelect
290 _PropertySet(
"MultiSelect
", pvMultiSelect)
291 End Property
' SFDocuments.SF_FormControl.MultiSelect (let)
293 REM -----------------------------------------------------------------------------
294 Property Get Name() As String
295 ''' Return the name of the actual control
296 Name = _PropertyGet(
"Name
")
297 End Property
' SFDocuments.SF_FormControl.Name
299 REM -----------------------------------------------------------------------------
300 Property Get OnActionPerformed() As Variant
301 ''' Get the script associated with the OnActionPerformed event
302 OnActionPerformed = _PropertyGet(
"OnActionPerformed
",
"")
303 End Property
' SFDocuments.SF_FormControl.OnActionPerformed (get)
305 REM -----------------------------------------------------------------------------
306 Property Let OnActionPerformed(Optional ByVal pvOnActionPerformed As Variant)
307 ''' Set the updatable property OnActionPerformed
308 _PropertySet(
"OnActionPerformed
", pvOnActionPerformed)
309 End Property
' SFDocuments.SF_FormControl.OnActionPerformed (let)
311 REM -----------------------------------------------------------------------------
312 Property Get OnAdjustmentValueChanged() As Variant
313 ''' Get the script associated with the OnAdjustmentValueChanged event
314 OnAdjustmentValueChanged = _PropertyGet(
"OnAdjustmentValueChanged
",
"")
315 End Property
' SFDocuments.SF_FormControl.OnAdjustmentValueChanged (get)
317 REM -----------------------------------------------------------------------------
318 Property Let OnAdjustmentValueChanged(Optional ByVal pvOnAdjustmentValueChanged As Variant)
319 ''' Set the updatable property OnAdjustmentValueChanged
320 _PropertySet(
"OnAdjustmentValueChanged
", pvOnAdjustmentValueChanged)
321 End Property
' SFDocuments.SF_FormControl.OnAdjustmentValueChanged (let)
323 REM -----------------------------------------------------------------------------
324 Property Get OnApproveAction() As Variant
325 ''' Get the script associated with the OnApproveAction event
326 OnApproveAction = _PropertyGet(
"OnApproveAction
",
"")
327 End Property
' SFDocuments.SF_FormControl.OnApproveAction (get)
329 REM -----------------------------------------------------------------------------
330 Property Let OnApproveAction(Optional ByVal pvOnApproveAction As Variant)
331 ''' Set the updatable property OnApproveAction
332 _PropertySet(
"OnApproveAction
", pvOnApproveAction)
333 End Property
' SFDocuments.SF_FormControl.OnApproveAction (let)
335 REM -----------------------------------------------------------------------------
336 Property Get OnApproveReset() As Variant
337 ''' Get the script associated with the OnApproveReset event
338 OnApproveReset = _PropertyGet(
"OnApproveReset
",
"")
339 End Property
' SFDocuments.SF_FormControl.OnApproveReset (get)
341 REM -----------------------------------------------------------------------------
342 Property Let OnApproveReset(Optional ByVal pvOnApproveReset As Variant)
343 ''' Set the updatable property OnApproveReset
344 _PropertySet(
"OnApproveReset
", pvOnApproveReset)
345 End Property
' SFDocuments.SF_FormControl.OnApproveReset (let)
347 REM -----------------------------------------------------------------------------
348 Property Get OnApproveUpdate() As Variant
349 ''' Get the script associated with the OnApproveUpdate event
350 OnApproveUpdate = _PropertyGet(
"OnApproveUpdate
",
"")
351 End Property
' SFDocuments.SF_FormControl.OnApproveUpdate (get)
353 REM -----------------------------------------------------------------------------
354 Property Let OnApproveUpdate(Optional ByVal pvOnApproveUpdate As Variant)
355 ''' Set the updatable property OnApproveUpdate
356 _PropertySet(
"OnApproveUpdate
", pvOnApproveUpdate)
357 End Property
' SFDocuments.SF_FormControl.OnApproveUpdate (let)
359 REM -----------------------------------------------------------------------------
360 Property Get OnChanged() As Variant
361 ''' Get the script associated with the OnChanged event
362 OnChanged = _PropertyGet(
"OnChanged
",
"")
363 End Property
' SFDocuments.SF_FormControl.OnChanged (get)
365 REM -----------------------------------------------------------------------------
366 Property Let OnChanged(Optional ByVal pvOnChanged As Variant)
367 ''' Set the updatable property OnChanged
368 _PropertySet(
"OnChanged
", pvOnChanged)
369 End Property
' SFDocuments.SF_FormControl.OnChanged (let)
371 REM -----------------------------------------------------------------------------
372 Property Get OnErrorOccurred() As Variant
373 ''' Get the script associated with the OnErrorOccurred event
374 OnErrorOccurred = _PropertyGet(
"OnErrorOccurred
",
"")
375 End Property
' SFDocuments.SF_FormControl.OnErrorOccurred (get)
377 REM -----------------------------------------------------------------------------
378 Property Let OnErrorOccurred(Optional ByVal pvOnErrorOccurred As Variant)
379 ''' Set the updatable property OnErrorOccurred
380 _PropertySet(
"OnErrorOccurred
", pvOnErrorOccurred)
381 End Property
' SFDocuments.SF_FormControl.OnErrorOccurred (let)
383 REM -----------------------------------------------------------------------------
384 Property Get OnFocusGained() As Variant
385 ''' Get the script associated with the OnFocusGained event
386 OnFocusGained = _PropertyGet(
"OnFocusGained
",
"")
387 End Property
' SFDocuments.SF_FormControl.OnFocusGained (get)
389 REM -----------------------------------------------------------------------------
390 Property Let OnFocusGained(Optional ByVal pvOnFocusGained As Variant)
391 ''' Set the updatable property OnFocusGained
392 _PropertySet(
"OnFocusGained
", pvOnFocusGained)
393 End Property
' SFDocuments.SF_FormControl.OnFocusGained (let)
395 REM -----------------------------------------------------------------------------
396 Property Get OnFocusLost() As Variant
397 ''' Get the script associated with the OnFocusLost event
398 OnFocusLost = _PropertyGet(
"OnFocusLost
",
"")
399 End Property
' SFDocuments.SF_FormControl.OnFocusLost (get)
401 REM -----------------------------------------------------------------------------
402 Property Let OnFocusLost(Optional ByVal pvOnFocusLost As Variant)
403 ''' Set the updatable property OnFocusLost
404 _PropertySet(
"OnFocusLost
", pvOnFocusLost)
405 End Property
' SFDocuments.SF_FormControl.OnFocusLost (let)
407 REM -----------------------------------------------------------------------------
408 Property Get OnItemStateChanged() As Variant
409 ''' Get the script associated with the OnItemStateChanged event
410 OnItemStateChanged = _PropertyGet(
"OnItemStateChanged
",
"")
411 End Property
' SFDocuments.SF_FormControl.OnItemStateChanged (get)
413 REM -----------------------------------------------------------------------------
414 Property Let OnItemStateChanged(Optional ByVal pvOnItemStateChanged As Variant)
415 ''' Set the updatable property OnItemStateChanged
416 _PropertySet(
"OnItemStateChanged
", pvOnItemStateChanged)
417 End Property
' SFDocuments.SF_FormControl.OnItemStateChanged (let)
419 REM -----------------------------------------------------------------------------
420 Property Get OnKeyPressed() As Variant
421 ''' Get the script associated with the OnKeyPressed event
422 OnKeyPressed = _PropertyGet(
"OnKeyPressed
",
"")
423 End Property
' SFDocuments.SF_FormControl.OnKeyPressed (get)
425 REM -----------------------------------------------------------------------------
426 Property Let OnKeyPressed(Optional ByVal pvOnKeyPressed As Variant)
427 ''' Set the updatable property OnKeyPressed
428 _PropertySet(
"OnKeyPressed
", pvOnKeyPressed)
429 End Property
' SFDocuments.SF_FormControl.OnKeyPressed (let)
431 REM -----------------------------------------------------------------------------
432 Property Get OnKeyReleased() As Variant
433 ''' Get the script associated with the OnKeyReleased event
434 OnKeyReleased = _PropertyGet(
"OnKeyReleased
",
"")
435 End Property
' SFDocuments.SF_FormControl.OnKeyReleased (get)
437 REM -----------------------------------------------------------------------------
438 Property Let OnKeyReleased(Optional ByVal pvOnKeyReleased As Variant)
439 ''' Set the updatable property OnKeyReleased
440 _PropertySet(
"OnKeyReleased
", pvOnKeyReleased)
441 End Property
' SFDocuments.SF_FormControl.OnKeyReleased (let)
443 REM -----------------------------------------------------------------------------
444 Property Get OnMouseDragged() As Variant
445 ''' Get the script associated with the OnMouseDragged event
446 OnMouseDragged = _PropertyGet(
"OnMouseDragged
",
"")
447 End Property
' SFDocuments.SF_FormControl.OnMouseDragged (get)
449 REM -----------------------------------------------------------------------------
450 Property Let OnMouseDragged(Optional ByVal pvOnMouseDragged As Variant)
451 ''' Set the updatable property OnMouseDragged
452 _PropertySet(
"OnMouseDragged
", pvOnMouseDragged)
453 End Property
' SFDocuments.SF_FormControl.OnMouseDragged (let)
455 REM -----------------------------------------------------------------------------
456 Property Get OnMouseEntered() As Variant
457 ''' Get the script associated with the OnMouseEntered event
458 OnMouseEntered = _PropertyGet(
"OnMouseEntered
",
"")
459 End Property
' SFDocuments.SF_FormControl.OnMouseEntered (get)
461 REM -----------------------------------------------------------------------------
462 Property Let OnMouseEntered(Optional ByVal pvOnMouseEntered As Variant)
463 ''' Set the updatable property OnMouseEntered
464 _PropertySet(
"OnMouseEntered
", pvOnMouseEntered)
465 End Property
' SFDocuments.SF_FormControl.OnMouseEntered (let)
467 REM -----------------------------------------------------------------------------
468 Property Get OnMouseExited() As Variant
469 ''' Get the script associated with the OnMouseExited event
470 OnMouseExited = _PropertyGet(
"OnMouseExited
",
"")
471 End Property
' SFDocuments.SF_FormControl.OnMouseExited (get)
473 REM -----------------------------------------------------------------------------
474 Property Let OnMouseExited(Optional ByVal pvOnMouseExited As Variant)
475 ''' Set the updatable property OnMouseExited
476 _PropertySet(
"OnMouseExited
", pvOnMouseExited)
477 End Property
' SFDocuments.SF_FormControl.OnMouseExited (let)
479 REM -----------------------------------------------------------------------------
480 Property Get OnMouseMoved() As Variant
481 ''' Get the script associated with the OnMouseMoved event
482 OnMouseMoved = _PropertyGet(
"OnMouseMoved
",
"")
483 End Property
' SFDocuments.SF_FormControl.OnMouseMoved (get)
485 REM -----------------------------------------------------------------------------
486 Property Let OnMouseMoved(Optional ByVal pvOnMouseMoved As Variant)
487 ''' Set the updatable property OnMouseMoved
488 _PropertySet(
"OnMouseMoved
", pvOnMouseMoved)
489 End Property
' SFDocuments.SF_FormControl.OnMouseMoved (let)
491 REM -----------------------------------------------------------------------------
492 Property Get OnMousePressed() As Variant
493 ''' Get the script associated with the OnMousePressed event
494 OnMousePressed = _PropertyGet(
"OnMousePressed
",
"")
495 End Property
' SFDocuments.SF_FormControl.OnMousePressed (get)
497 REM -----------------------------------------------------------------------------
498 Property Let OnMousePressed(Optional ByVal pvOnMousePressed As Variant)
499 ''' Set the updatable property OnMousePressed
500 _PropertySet(
"OnMousePressed
", pvOnMousePressed)
501 End Property
' SFDocuments.SF_FormControl.OnMousePressed (let)
503 REM -----------------------------------------------------------------------------
504 Property Get OnMouseReleased() As Variant
505 ''' Get the script associated with the OnMouseReleased event
506 OnMouseReleased = _PropertyGet(
"OnMouseReleased
",
"")
507 End Property
' SFDocuments.SF_FormControl.OnMouseReleased (get)
509 REM -----------------------------------------------------------------------------
510 Property Let OnMouseReleased(Optional ByVal pvOnMouseReleased As Variant)
511 ''' Set the updatable property OnMouseReleased
512 _PropertySet(
"OnMouseReleased
", pvOnMouseReleased)
513 End Property
' SFDocuments.SF_FormControl.OnMouseReleased (let)
515 REM -----------------------------------------------------------------------------
516 Property Get OnResetted() As Variant
517 ''' Get the script associated with the OnResetted event
518 OnResetted = _PropertyGet(
"OnResetted
",
"")
519 End Property
' SFDocuments.SF_FormControl.OnResetted (get)
521 REM -----------------------------------------------------------------------------
522 Property Let OnResetted(Optional ByVal pvOnResetted As Variant)
523 ''' Set the updatable property OnResetted
524 _PropertySet(
"OnResetted
", pvOnResetted)
525 End Property
' SFDocuments.SF_FormControl.OnResetted (let)
527 REM -----------------------------------------------------------------------------
528 Property Get OnTextChanged() As Variant
529 ''' Get the script associated with the OnTextChanged event
530 OnTextChanged = _PropertyGet(
"OnTextChanged
",
"")
531 End Property
' SFDocuments.SF_FormControl.OnTextChanged (get)
533 REM -----------------------------------------------------------------------------
534 Property Let OnTextChanged(Optional ByVal pvOnTextChanged As Variant)
535 ''' Set the updatable property OnTextChanged
536 _PropertySet(
"OnTextChanged
", pvOnTextChanged)
537 End Property
' SFDocuments.SF_FormControl.OnTextChanged (let)
539 REM -----------------------------------------------------------------------------
540 Property Get OnUpdated() As Variant
541 ''' Get the script associated with the OnUpdated event
542 OnUpdated = _PropertyGet(
"OnUpdated
",
"")
543 End Property
' SFDocuments.SF_FormControl.OnUpdated (get)
545 REM -----------------------------------------------------------------------------
546 Property Let OnUpdated(Optional ByVal pvOnUpdated As Variant)
547 ''' Set the updatable property OnUpdated
548 _PropertySet(
"OnUpdated
", pvOnUpdated)
549 End Property
' SFDocuments.SF_FormControl.OnUpdated (let)
551 REM -----------------------------------------------------------------------------
552 Property Get Parent() As Object
553 ''' Return the Parent form or [table]control object of the actual control
554 Parent = _PropertyGet(
"Parent
", Nothing)
555 End Property
' SFDocuments.SF_FormControl.Parent
557 REM -----------------------------------------------------------------------------
558 Property Get Picture() As Variant
559 ''' The Picture property specifies a bitmap or other type of graphic to be displayed on the specified control
560 Picture = _PropertyGet(
"Picture
",
"")
561 End Property
' SFDocuments.SF_FormControl.Picture (get)
563 REM -----------------------------------------------------------------------------
564 Property Let Picture(Optional ByVal pvPicture As Variant)
565 ''' Set the updatable property Picture
566 _PropertySet(
"Picture
", pvPicture)
567 End Property
' SFDocuments.SF_FormControl.Picture (let)
569 REM -----------------------------------------------------------------------------
570 Property Get Required() As Variant
571 ''' A control is said Required when it must not contain a null value
572 Required = _PropertyGet(
"Required
", False)
573 End Property
' SFDocuments.SF_FormControl.Required (get)
575 REM -----------------------------------------------------------------------------
576 Property Let Required(Optional ByVal pvRequired As Variant)
577 ''' Set the updatable property Required
578 _PropertySet(
"Required
", pvRequired)
579 End Property
' SFDocuments.SF_FormControl.Required (let)
581 REM -----------------------------------------------------------------------------
582 Property Get Text() As Variant
583 ''' The Text property specifies the actual content of the control like it is displayed on the screen
584 Text = _PropertyGet(
"Text
",
"")
585 End Property
' SFDocuments.SF_FormControl.Text (get)
587 REM -----------------------------------------------------------------------------
588 Property Get TipText() As Variant
589 ''' The TipText property specifies the text that appears in a screentip when you hold the mouse pointer over a control
590 TipText = _PropertyGet(
"TipText
",
"")
591 End Property
' SFDocuments.SF_FormControl.TipText (get)
593 REM -----------------------------------------------------------------------------
594 Property Let TipText(Optional ByVal pvTipText As Variant)
595 ''' Set the updatable property TipText
596 _PropertySet(
"TipText
", pvTipText)
597 End Property
' SFDocuments.SF_FormControl.TipText (let)
599 REM -----------------------------------------------------------------------------
600 Property Get TripleState() As Variant
601 ''' The TripleState property specifies how a check box will display Null values
602 ''' When True, the control will cycle through states for Yes, No, and Null values. The control appears dimmed (grayed) when its Value property is set to Null.
603 ''' When False, the control will cycle through states for Yes and No values. Null values display as if they were No values.
604 TripleState = _PropertyGet(
"TripleState
", False)
605 End Property
' SFDocuments.SF_FormControl.TripleState (get)
607 REM -----------------------------------------------------------------------------
608 Property Let TripleState(Optional ByVal pvTripleState As Variant)
609 ''' Set the updatable property TripleState
610 _PropertySet(
"TripleState
", pvTripleState)
611 End Property
' SFDocuments.SF_FormControl.TripleState (let)
613 REM -----------------------------------------------------------------------------
614 Property Get Value() As Variant
615 ''' The Value property specifies the data contained in the control
616 Value = _PropertyGet(
"Value
", Empty)
617 End Property
' SFDocuments.SF_FormControl.Value (get)
619 REM -----------------------------------------------------------------------------
620 Property Let Value(Optional ByVal pvValue As Variant)
621 ''' Set the updatable property Value
622 _PropertySet(
"Value
", pvValue)
623 End Property
' SFDocuments.SF_FormControl.Value (let)
625 REM -----------------------------------------------------------------------------
626 Property Get Visible() As Variant
627 ''' The Visible property specifies if the control is accessible with the cursor.
628 Visible = _PropertyGet(
"Visible
", True)
629 End Property
' SFDocuments.SF_FormControl.Visible (get)
631 REM -----------------------------------------------------------------------------
632 Property Let Visible(Optional ByVal pvVisible As Variant)
633 ''' Set the updatable property Visible
634 _PropertySet(
"Visible
", pvVisible)
635 End Property
' SFDocuments.SF_FormControl.Visible (let)
637 REM -----------------------------------------------------------------------------
638 Property Get XControlModel() As Object
639 ''' The XControlModel property returns the model UNO object of the control
640 XControlModel = _PropertyGet(
"XControlModel
", Nothing)
641 End Property
' SFDocuments.SF_FormControl.XControlModel (get)
643 REM -----------------------------------------------------------------------------
644 Property Get XControlView() As Object
645 ''' The XControlView property returns the view UNO object of the control
646 XControlView = _PropertyGet(
"XControlView
", Nothing)
647 End Property
' SFDocuments.SF_FormControl.XControlView (get)
649 REM ===================================================================== METHODS
651 REM -----------------------------------------------------------------------------
652 Public Function Controls(Optional ByVal ControlName As Variant) As Variant
653 ''' Return either
654 ''' - the list of the controls contained in the actual table control
655 ''' - a Form Control object based on its name
656 ''' Args:
657 ''' ControlName: a valid control name as a case-sensitive string. If absent the list is returned
658 ''' Returns:
659 ''' A zero-base array of strings if ControlName is absent
660 ''' An instance of the SF_FormControl class if ControlName exists
661 ''' Exceptions:
662 ''' ControlName is invalid
663 ''' Example:
664 ''' Dim myGrid As Object, myList As Variant, myControl As Object
665 ''' Set myGrid = myForm.Controls(
"myTableControl
")
666 ''' myList = myGrid.Controls()
667 ''' Set myControl = myGrid.Controls(
"myCheckBox
")
669 Dim oControl As Object
' The new control class instance
670 Dim lIndexOfNames As Long
' Index in ElementNames array. Used to access _ControlCache
671 Dim vControl As Variant
' Alias of _ControlCache entry
672 Dim oView As Object
' com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
674 Const cstThisSub =
"SFDocuments.FormControl.Controls
"
675 Const cstSubArgs =
"[ControlName]
"
677 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
678 Set Controls = Nothing
681 If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName =
""
682 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
683 If _ControlType
<> CTLTABLECONTROL Then GoTo Catch
684 If Not [_Parent]._IsStillAlive() Then GoTo Finally
685 If Not ScriptForge.SF_Utils._Validate(ControlName,
"ControlName
", V_STRING) Then GoTo Finally
689 ' Collect all control names if not yet done
690 If UBound(_ControlNames)
< 0 Then
691 _ControlNames = _ControlModel.getElementNames()
692 If UBound(_ControlNames)
>=
0 Then
693 ReDim _ControlCache(
0 To UBound(_ControlNames))
697 ' Return the list of controls or a FormControl instance
698 If Len(ControlName) =
0 Then
699 Controls = _ControlNames
703 If Not _ControlModel.hasByName(ControlName) Then GoTo CatchNotFound
704 lIndexOfNames = ScriptForge.SF_Array.IndexOf(_ControlNames, ControlName, CaseSensitive := True)
705 ' Reuse cache when relevant
706 vControl = _ControlCache(lIndexOfNames)
708 If IsEmpty(vControl) Then
709 ' Not in cache =
> Create the new form control class instance
710 Set oControl = New SF_FormControl
714 Set .[_Parent] = [Me]
715 ._ParentIsTable = True
716 ._IndexOfNames = lIndexOfNames
717 ._FormName = _FormName
718 Set ._ParentForm = _ParentForm
719 ' Get model and view of the current control
720 Set ._ControlModel = _ControlModel.getByName(ControlName)
721 ._ImplementationName = ._ControlModel.ColumnServiceName
' getImplementationName aborts for subcontrols !?
722 ' Bypass to find the control view: cannot be done from the top component
723 If Not IsNull(_ControlView) Then
' Anticipate absence of ControlView in table controls when edit mode
724 For i =
0 to _ControlView.getCount() -
1
725 Set oView = _ControlView.GetByIndex(i)
726 If Not IsNull(oView) Then
727 If oView.getModel.Name = ControlName Then
728 Set ._ControlView = oView
737 Set oControl = vControl
740 Set Controls = oControl
744 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
749 ScriptForge.SF_Utils._Validate(ControlName,
"ControlName
", V_STRING, _ControlModel.getElementNames())
751 End Function
' SFDocuments.SF_FormControl.Controls
753 REM -----------------------------------------------------------------------------
754 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
755 ''' Return the actual value of the given property
756 ''' Args:
757 ''' PropertyName: the name of the property as a string
758 ''' Returns:
759 ''' The actual value of the property
760 ''' If the property does not exist, returns Null
761 ''' Exceptions:
762 ''' see the exceptions of the individual properties
763 ''' Examples:
764 ''' myControl.GetProperty(
"MyProperty
")
766 Dim vDefault As Variant
' Default value when property not applicable on control type
767 Const cstThisSub =
"SFDocuments.FormControl.GetProperty
"
768 Const cstSubArgs =
""
770 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
774 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
775 If Not ScriptForge.SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
779 ' FormControl properties are far from applicable to all control types
780 ' Getting a property must never abort to not interfere with the Basic IDE watch function
781 ' Hence a default value must be provided
782 Select Case UCase(PropertyName)
783 Case UCase(
"Default
") : vDefault = False
784 Case UCase(
"DefaultValue
") : vDefault = Null
785 Case UCase(
"Enabled
") : vDefault = False
786 Case UCase(
"ListCount
") : vDefault =
0
787 Case UCase(
"ListIndex
") : vDefault = -
1
788 Case UCase(
"Locked
") : vDefault = False
789 Case UCase(
"MultiSelect
") : vDefault = False
790 Case UCase(
"Parent
") : vDefault = Nothing
791 Case UCase(
"Required
") : vDefault = False
792 Case UCase(
"TripleState
") : vDefault = False
793 Case UCase(
"Value
") : vDefault = Empty
794 Case UCase(
"Visible
") : vDefault = True
795 Case UCase(
"XControlModel
") : vDefault = Nothing
796 Case UCase(
"XControlView
") : vDefault = Nothing
797 Case Else : vDefault =
""
800 GetProperty = _PropertyGet(PropertyName, vDefault)
803 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
807 End Function
' SFDocuments.SF_FormControl.GetProperty
809 REM -----------------------------------------------------------------------------
810 Public Function Methods() As Variant
811 ''' Return the list of public methods of the FormControl service as an array
814 "AddSubNode
" _
815 ,
"AddSubTree
" _
816 ,
"CreateRoot
" _
817 ,
"FindNode
" _
818 ,
"SetFocus
" _
819 ,
"WriteLine
" _
822 End Function
' SFDocuments.SF_FormControl.Methods
824 REM -----------------------------------------------------------------------------
825 Public Function Properties() As Variant
826 ''' Return the list or properties of the FormControl class as an array
828 Properties = Array( _
830 ,
"Cancel
" _
831 ,
"Caption
" _
832 ,
"ControlSource
" _
833 ,
"ControlType
" _
834 ,
"Default
" _
835 ,
"DefaultValue
" _
836 ,
"Enabled
" _
837 ,
"Format
" _
838 ,
"ListCount
" _
839 ,
"ListIndex
" _
840 ,
"ListSource
" _
841 ,
"ListSourceType
" _
842 ,
"Locked
" _
843 ,
"MultiSelect
" _
845 ,
"OnActionPerformed
" _
846 ,
"OnAdjustmentValueChanged
" _
847 ,
"OnApproveAction
" _
848 ,
"OnApproveReset
" _
849 ,
"OnApproveUpdate
" _
850 ,
"OnChanged
" _
851 ,
"OnErrorOccurred
" _
852 ,
"OnFocusGained
" _
853 ,
"OnFocusLost
" _
854 ,
"OnItemStateChanged
" _
855 ,
"OnKeyPressed
" _
856 ,
"OnKeyReleased
" _
857 ,
"OnMouseDragged
" _
858 ,
"OnMouseEntered
" _
859 ,
"OnMouseExited
" _
860 ,
"OnMouseMoved
" _
861 ,
"OnMousePressed
" _
862 ,
"OnMouseReleased
" _
863 ,
"OnResetted
" _
864 ,
"OnTextChanged
" _
865 ,
"OnUpdated
" _
866 ,
"Parent
" _
867 ,
"Picture
" _
868 ,
"Required
" _
870 ,
"TipText
" _
871 ,
"TripleState
" _
872 ,
"Value
" _
873 ,
"Visible
" _
874 ,
"XControlModel
" _
875 ,
"XControlView
" _
878 End Function
' SFDocuments.SF_FormControl.Properties
880 REM -----------------------------------------------------------------------------
881 Public Function SetFocus() As Boolean
882 ''' Set the focus on the current Control instance
883 ''' Probably called from after an event occurrence
884 ''' Args:
885 ''' Returns:
886 ''' True if focusing is successful
887 ''' Example:
888 ''' Dim oDoc As Object, oForm As Object, oControl As Object
889 ''' Set oDoc = CreateScriptService(
"SFDocuments.Document
", ThisComponent)
890 ''' Set oForm = oDoc.Forms(
0)
891 ''' Set oControl = oForm.Controls(
"thisControl
")
892 ''' oControl.SetFocus()
894 Dim bSetFocus As Boolean
' Return value
895 Dim iColPosition As Integer
' Position of control in table
896 Dim oTableModel As Object
' XControlModel of parent table
897 Dim oControl As Object
' com.sun.star.awt.XControlModel
898 Dim i As Integer, j As Integer
899 Const cstThisSub =
"SFDocuments.FormControl.SetFocus
"
900 Const cstSubArgs =
""
902 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
906 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
907 If Not _ParentForm._IsStillAlive() Then GoTo Finally
911 If Not IsNull(_ControlView) Then
912 If _ParentIsTable Then
' setFocus() method does not work on controlviews in table control ?!?
913 ' Find the column position of the current instance in the parent table control
915 Set oTableModel = [_Parent]._ControlModel
917 For i =
0 To oTableModel.Count -
1
918 Set oControl = oTableModel.getByIndex(i)
919 If Not oControl.Hidden Then j = j +
1 ' Skip hidden columns
920 If oControl.Name = _Name Then
925 If iColPosition
>=
0 Then
926 [_Parent]._ControlView.setFocus()
'Set first focus on table control itself
927 [_Parent]._ControlView.setCurrentColumnPosition(iColPosition)
'Deprecated but no alternative found
930 _ControlView.setFocus()
938 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
942 End Function
' SFControls.SF_FormControl.SetFocus
944 REM -----------------------------------------------------------------------------
945 Public Function SetProperty(Optional ByVal PropertyName As Variant _
946 , Optional ByRef Value As Variant _
948 ''' Set a new value to the given property
949 ''' Args:
950 ''' PropertyName: the name of the property as a string
951 ''' Value: its new value
952 ''' Exceptions
953 ''' ARGUMENTERROR The property does not exist
955 Const cstThisSub =
"SFDocuments.FormControl.SetProperty
"
956 Const cstSubArgs =
"PropertyName, Value
"
958 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
962 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
963 If Not ScriptForge.SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
967 SetProperty = _PropertySet(PropertyName, Value)
970 SF_Utils._ExitFunction(cstThisSub)
974 End Function
' SFDocuments.SF_FormControl.SetProperty
976 REM =========================================================== PRIVATE FUNCTIONS
978 REM -----------------------------------------------------------------------------
979 Private Function _FormatsList() As Variant
980 ''' Return the allowed format entries as a zero-based array for Date and Time control types
982 Dim vFormats() As Variant
' Return value
984 Select Case _ControlType
987 "Standard (short)
" _
988 ,
"Standard (short YY)
" _
989 ,
"Standard (short YYYY)
" _
990 ,
"Standard (long)
" _
991 ,
"DD/MM/YY
" _
992 ,
"MM/DD/YY
" _
993 ,
"YY/MM/DD
" _
994 ,
"DD/MM/YYYY
" _
995 ,
"MM/DD/YYYY
" _
996 ,
"YYYY/MM/DD
" _
997 ,
"YY-MM-DD
" _
998 ,
"YYYY-MM-DD
" _
1002 "24h short
" _
1003 ,
"24h long
" _
1004 ,
"12h short
" _
1005 ,
"12h long
" _
1011 _FormatsList = vFormats
1013 End Function
' SFDocuments.SF_FormControl._FormatsList
1015 REM -----------------------------------------------------------------------------
1016 Public Function _GetEventName(ByVal psProperty As String) As String
1017 ''' Return the LO internal event name derived from the SF property name
1018 ''' The SF property name is not case sensitive, while the LO name is case-sensitive
1019 ' Corrects the typo on ErrorOccur(r?)ed, if necessary
1021 Dim vProperties As Variant
' Array of class properties
1022 Dim sProperty As String
' Correctly cased property name
1024 vProperties = Properties()
1025 sProperty = vProperties(ScriptForge.SF_Array.IndexOf(vProperties, psProperty, SortOrder :=
"ASC
"))
1027 _GetEventName = LCase(Mid(sProperty,
3,
1))
& Right(sProperty, Len(sProperty) -
3)
1029 End Function
' SFDocuments.SF_FormControl._GetEventName
1031 REM -----------------------------------------------------------------------------
1032 Private Function _GetListener(ByVal psEventName As String) As String
1033 ''' Getting/Setting macros triggered by events requires a Listener-EventName pair
1034 ''' Return the X...Listener corresponding with the event name in argument
1036 Select Case UCase(psEventName)
1037 Case UCase(
"OnActionPerformed
")
1038 _GetListener =
"XActionListener
"
1039 Case UCase(
"OnAdjustmentValueChanged
")
1040 _GetListener =
"XAdjustmentListener
"
1041 Case UCase(
"OnApproveAction
")
1042 _GetListener =
"XApproveActionListener
"
1043 Case UCase(
"OnApproveReset
"), UCase(
"OnResetted
")
1044 _GetListener =
"XResetListener
"
1045 Case UCase(
"OnApproveUpdate
"), UCase(
"OnUpdated
")
1046 _GetListener =
"XUpdateListener
"
1047 Case UCase(
"OnChanged
")
1048 _GetListener =
"XChangeListener
"
1049 Case UCase(
"OnErrorOccurred
")
1050 _GetListener =
"XErrorListener
"
1051 Case UCase(
"OnFocusGained
"), UCase(
"OnFocusLost
")
1052 _GetListener =
"XFocusListener
"
1053 Case UCase(
"OnItemStateChanged
")
1054 _GetListener =
"XItemListener
"
1055 Case UCase(
"OnKeyPressed
"), UCase(
"OnKeyReleased
")
1056 _GetListener =
"XKeyListener
"
1057 Case UCase(
"OnMouseDragged
"), UCase(
"OnMouseMoved
")
1058 _GetListener =
"XMouseMotionListener
"
1059 Case UCase(
"OnMouseEntered
"), UCase(
"OnMouseExited
"), UCase(
"OnMousePressed
"), UCase(
"OnMouseReleased
")
1060 _GetListener =
"XMouseListener
"
1061 Case UCase(
"OnTextChanged
")
1062 _GetListener =
"XTextListener
"
1065 End Function
' SFDocuments.SF_FormControl._GetListener
1067 REM -----------------------------------------------------------------------------
1068 Public Sub _Initialize()
1069 ''' Complete the object creation process:
1070 ''' - Initialization of private members
1071 ''' - Collection of specific attributes
1072 ''' - Synchronization with parent form instance
1074 Dim vControlTypes As Variant
' Array of control types ordered by the ClassId property of XControlModel -
2
1075 Const acHiddenControl =
13 ' Class Id of an hidden control: has no ControlView
1077 vControlTypes = array( CTLBUTTON _
1088 , CTLHIDDENCONTROL _
1093 , CTLCURRENCYFIELD _
1097 , CTLNAVIGATIONBAR _
1101 ' _implementationName is set elsewhere for controls in table control
1102 If Len(_ImplementationName) =
0 Then _ImplementationName = ScriptForge.SF_Session.UnoObjectType(_ControlModel)
1103 _ClassId = _ControlModel.ClassId
1105 ' Identify the control type, ignore subforms and pay attention to formatted fields
1106 If ScriptForge.SF_Session.HasUnoproperty(_ControlModel,
"ClassId
") Then
' All control types have a ClassId property except subforms
1107 _ControlType = vControlTypes(_ClassId -
2)
1108 ' Formatted fields belong to the TextField family
1109 If _ControlType = CTLTEXTFIELD Then
1110 If _ImplementationName =
"com.sun.star.comp.forms.OFormattedFieldWrapper
" _
1111 Or _ImplementationName =
"com.sun.star.comp.forms.OFormattedFieldWrapper_ForcedFormatted
" _
1112 Or _ImplementationName =
"com.sun.star.form.component.FormattedField
" Then
' When in table control
1113 _ControlType = CTLFORMATTEDFIELD
1117 Exit Sub
' Ignore subforms, should not happen
1121 ' Set control view if not set yet
1122 If IsNull(_ControlView) Then
1123 If _ClassId
> 0 And _ClassId
<> acHiddenControl Then
' No view on hidden controls
1124 If IsNull(._FormDocument) Then
' Usual document
1125 Set _ControlView = ._Component.CurrentController.getControl(_ControlModel)
1126 Else
' Base form document
1127 Set _ControlView = ._FormDocument.Component.CurrentController.getControl(_ControlModel)
1133 ' Store the SF_FormControl object in the parent cache
1134 Set _Parent._ControlCache(_IndexOfNames) = [Me]
1138 End Sub
' SFDocuments.SF_FormControl._Initialize
1140 REM -----------------------------------------------------------------------------
1141 Private Function _ListboxBound() As Boolean
1142 ''' Return True if the actual control, which is a listbox, has a bound column
1143 ''' Called before setting the value of a listbox, i.e. the value to be rewritten in the underlying table data
1144 ''' The existence of a bound column is derived from the comparison between StringItemList and ValueItemList
1145 ''' String ... : the strings displayed in the list box
1146 ''' Value ... : the database values
1147 ''' If they are different, then there is a bound column
1149 Dim bListboxBound As Boolean
' Return value
1150 Dim vValue() As Variant
' Alias of the control model ValueItemList
1151 Dim vString() As Variant
' Alias of the control model StringItemList
1154 bListboxBound = False
1157 If Not IsNull(.ValueItemList) _
1158 And .DataField
<> "" _
1159 And Not IsNull(.BoundField) _
1160 And ScriptForge.SF_Array.Contains(Array( _
1161 com.sun.star.form.ListSourceType.TABLE _
1162 , com.sun.star.form.ListSourceType.QUERY _
1163 , com.sun.star.form.ListSourceType.SQL _
1164 , com.sun.star.form.ListSourceType.SQLPASSTHROUGH _
1165 ), .ListSourceType) Then
1166 If IsArray(.ValueItemList) Then
1167 vValue = .ValueItemList
1168 vString = .StringItemList
1169 For i =
0 To UBound(vValue)
1170 If VarType(vValue(i))
<> VarType(vString(i)) Then
1171 bListboxBound = True
1172 ElseIf vValue(i)
<> vString(i) Then
1173 bListboxBound = True
1175 If bListboxBound Then Exit For
1181 _ListboxBound = bListboxBound
1183 End Function
' _ListboxBound V0.9
.0
1185 REM -----------------------------------------------------------------------------
1186 Private Function _PropertyGet(Optional ByVal psProperty As String _
1187 , Optional ByVal pvDefault As Variant _
1189 ''' Return the value of the named property
1190 ''' Args:
1191 ''' psProperty: the name of the property
1192 ''' pvDefault: the value returned when the property is not applicable on the control
's type
1193 ''' Getting a non-existing property for a specific control type should
1194 ''' not generate an error to not disrupt the Basic IDE debugger
1196 Dim vGet As Variant
' Return value
1197 Static oSession As Object
' Alias of SF_Session
1198 Dim vSelection As Variant
' Alias of Model.SelectedItems or Model.Selection
1199 Dim vList As Variant
' Alias of Model.StringItemList
1200 Dim lIndex As Long
' Index in StringItemList
1201 Dim sItem As String
' A single item
1202 Dim vDate As Variant
' Date after conversion from com.sun.star.util.Date or com.sun.star.util.Time
1203 Dim vValues As Variant
' Array of listbox values
1204 Dim oControlEvents As Object
' com.sun.star.container.XNameContainer
1205 Dim sEventName As String
' Internal event name
1206 Const cstUnoUrl =
".uno:FormController/
"
1208 Dim cstThisSub As String
1209 Const cstSubArgs =
""
1211 cstThisSub =
"SFDocuments.FormControl.get
" & psProperty
1212 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1214 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1215 If Not _ParentForm._IsStillAlive() Then GoTo Finally
1217 If IsMissing(pvDefault) Or IsEmpty(pvDefault) Then pvDefault = Null
1218 _PropertyGet = pvDefault
1220 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
1221 Select Case UCase(psProperty)
1222 Case UCase(
"Action
")
1223 Select Case _ControlType
1225 If oSession.HasUNOProperty(_ControlModel,
"ButtonType
") Then
1226 Select Case _ControlModel.ButtonType
1227 Case com.sun.star.form.FormButtonType.PUSH : _PropertyGet =
"none
"
1228 Case com.sun.star.form.FormButtonType.SUBMIT : _PropertyGet =
"submitForm
"
1229 Case com.sun.star.form.FormButtonType.RESET : _PropertyGet =
"resetForm
"
1230 Case com.sun.star.form.FormButtonType.URL
1231 ' ".uno:FormController/moveToFirst
"
1232 If Left(_ControlModel.TargetURL, Len(cstUnoUrl)) = cstUnoUrl Then
1233 _PropertyGet = Mid(_ControlModel.TargetURL, Len(cstUnoUrl) +
1)
1234 ElseIf Left(_ControlModel.TargetURL,
4) =
"http
" Then
1235 _PropertyGet =
"openWebPage
"
1236 ElseIf Left(_ControlModel.TargetURL,
4) =
"file
" Then
1237 _PropertyGet =
"openDocument
"
1241 Case Else : GoTo CatchType
1243 Case UCase(
"Caption
")
1244 Select Case _ControlType
1245 Case CTLBUTTON, CTLCHECKBOX, CTLFIXEDTEXT, CTLGROUPBOX, CTLRADIOBUTTON
1246 If oSession.HasUNOProperty(_ControlModel,
"Label
") Then _PropertyGet = _ControlModel.Label
1247 Case Else : GoTo CatchType
1249 Case UCase(
"ControlSource
")
1250 Select Case _ControlType
1251 Case CTLCHECKBOX, CTLCOMBOBOX, CTLCURRENCYFIELD, CTLDATEFIELD, CTLFORMATTEDFIELD, CTLIMAGECONTROL, CTLLISTBOX _
1252 , CTLNUMERICFIELD, CTLPATTERNFIELD, CTLRADIOBUTTON, CTLTEXTFIELD, CTLTIMEFIELD
1253 If oSession.HasUNOProperty(_ControlModel,
"DataField
") Then _PropertyGet = _ControlModel.DataField
1254 Case Else : GoTo CatchType
1256 Case UCase(
"ControlType
")
1257 _PropertyGet = _ControlType
1258 Case UCase(
"Default
")
1259 Select Case _ControlType
1261 If oSession.HasUNOProperty(_ControlModel,
"DefaultButton
") Then _PropertyGet = _ControlModel.DefaultButton
1262 Case Else : GoTo CatchType
1264 Case UCase(
"DefaultValue
")
1265 Select Case _ControlType
1266 Case CTLCHECKBOX, CTLRADIOBUTTON
1267 If oSession.HasUNOProperty(_ControlModel,
"DefaultState
") Then _PropertyGet = _ControlModel.DefaultState
1268 Case CTLCOMBOBOX, CTLFILECONTROL, CTLPATTERNFIELD, CTLTEXTFIELD
1269 If oSession.HasUNOProperty(_ControlModel,
"DefaultText
") Then _PropertyGet = _ControlModel.DefaultText
1270 Case CTLCURRENCYFIELD, CTLNUMERICFIELD
1271 If oSession.HasUNOProperty(_ControlModel,
"DefaultValue
") Then _PropertyGet = _ControlModel.DefaultValue
1273 If oSession.HasUNOProperty(_ControlModel,
"DefaultDate
") Then
1274 If Not IsEmpty(_ControlModel.DefaultDate) Then
1275 With _ControlModel.DefaultDate
1276 vDate = DateSerial(.Year, .Month, .Day)
1278 _PropertyGet = vDate
1281 Case CTLFORMATTEDFIELD
1282 If oSession.HasUNOProperty(_ControlModel,
"EffectiveDefault
") Then _PropertyGet = _ControlModel.EffectiveDefault
1284 If oSession.HasUNOProperty(_ControlModel,
"DefaultSelection
") And oSession.HasUNOProperty(_ControlModel,
"StringItemList
") Then
1285 vList = _ControlModel.DefaultSelection
1286 If IsArray(vList) Then
1287 If UBound(vList)
>= LBound(vList) Then
' Is array initialized ?
1288 lIndex = UBound(_ControlModel.StringItemList)
1289 If vList(
0)
>=
0 And vList(
0)
<= lIndex Then _PropertyGet = _ControlModel.StringItemList(vList(
0))
1290 ' Only first default value is considered
1295 If oSession.HasUNOProperty(_ControlModel,
"DefaultSpinValue
") Then _PropertyGet = _ControlModel.DefaultSpinValue
1297 If oSession.HasUNOProperty(_ControlModel,
"DefaultTime
") Then
1298 If Not IsEmpty(_ControlModel.DefaultTime) Then
1299 With _ControlModel.DefaultTime
1300 vDate = TimeSerial(.Hours, .Minutes, .Seconds)
1302 _PropertyGet = vDate
1305 Case Else : GoTo CatchType
1307 Case UCase(
"Enabled
")
1308 Select Case _ControlType
1309 Case CTLHIDDENCONTROL : GoTo CatchType
1311 If oSession.HasUnoProperty(_ControlModel,
"Enabled
") Then _PropertyGet = _ControlModel.Enabled
1313 Case UCase(
"Format
")
1314 Select Case _ControlType
1316 If oSession.HasUNOProperty(_ControlModel,
"DateFormat
") Then _PropertyGet = _FormatsList()(_ControlModel.DateFormat)
1318 If oSession.HasUNOProperty(_ControlModel,
"TimeFormat
") Then _PropertyGet = _FormatsList()(_ControlModel.TimeFormat)
1319 Case CTLFORMATTEDFIELD
1320 If oSession.HasUNOProperty(_ControlModel,
"FormatsSupplier
") And oSession.HasUNOProperty(_ControlModel,
"FormatKey
") Then
1321 _PropertyGet = _ControlModel.FormatsSupplier.getNumberFormats.getByKey(_ControlModel.FormatKey).FormatString
1323 Case Else : GoTo CatchType
1325 Case UCase(
"ListCount
")
1326 Select Case _ControlType
1327 Case CTLCOMBOBOX, CTLLISTBOX
1328 If oSession.HasUNOProperty(_ControlModel,
"StringItemList
") Then _PropertyGet = UBound(_ControlModel.StringItemList) +
1
1329 Case Else : GoTo CatchType
1331 Case UCase(
"ListIndex
")
1332 Select Case _ControlType
1334 _PropertyGet = -
1 ' Not found, multiselection
1335 If oSession.HasUNOProperty(_ControlModel,
"Text
") And oSession.HasUNOProperty(_ControlModel,
"StringItemList
") Then
1336 _PropertyGet = ScriptForge.SF_Array.IndexOf(_ControlModel.StringItemList, _ControlModel.Text, CaseSensitive := True)
1339 _PropertyGet = -
1 ' Not found, multiselection
1340 If oSession.HasUNOProperty(_ControlModel,
"SelectedItems
") And oSession.HasUNOProperty(_ControlModel,
"StringItemList
") Then
1341 vSelection = _ControlModel.SelectedItems
1342 If UBound(vSelection)
>=
0 Then _PropertyGet = vSelection(
0)
1344 Case Else : GoTo CatchType
1346 Case UCase(
"ListSource
")
1347 Select Case _ControlType
1348 Case CTLCOMBOBOX, CTLLISTBOX
1349 If oSession.HasUNOProperty(_ControlModel,
"ListSource
") Then
1350 With com.sun.star.form.ListSourceType
1351 Select Case _ControlModel.ListSourceType
1354 If IsArray(_ControlModel.StringItemList) Then vValues = _ControlModel.StringItemList Else vValues = Array(_ControlModel.StringItemList)
1359 If IsArray(_ControlModel.ListSource) Then vValues = _ControlModel.ListSource Else vValues = Array(_ControlModel.ListSource)
1362 _PropertyGet = Join(vValues,
";
")
1364 Case Else : GoTo CatchType
1366 Case UCase(
"ListSourceType
")
1367 Select Case _ControlType
1368 Case CTLCOMBOBOX, CTLLISTBOX
1369 If oSession.HasUnoProperty(_ControlModel,
"ListSourceType
") Then _PropertyGet = _ControlModel.ListSourceType
1370 Case Else : GoTo CatchType
1372 Case UCase(
"Locked
")
1373 Select Case _ControlType
1374 Case CTLCOMBOBOX, CTLCURRENCYFIELD, CTLDATEFIELD, CTLFILECONTROL, CTLFORMATTEDFIELD, CTLIMAGECONTROL _
1375 , CTLLISTBOX, CTLNUMERICFIELD, CTLPATTERNFIELD, CTLTEXTFIELD, CTLTIMEFIELD
1376 If oSession.HasUnoProperty(_ControlModel,
"ReadOnly
") Then _PropertyGet = _ControlModel.ReadOnly
1377 Case Else : GoTo CatchType
1379 Case UCase(
"MultiSelect
")
1380 Select Case _ControlType
1382 If oSession.HasUnoProperty(_ControlModel,
"MultiSelection
") Then
1383 _PropertyGet = _ControlModel.MultiSelection
1384 ElseIf oSession.HasUnoProperty(_ControlModel,
"MultiSelectionSimpleMode
") Then
' Not documented: gridcontrols only TBC ??
1385 _PropertyGet = _ControlModel.MultiSelectionSimpleMode
1387 Case Else : GoTo CatchType
1389 Case UCase(
"Name
")
1390 _PropertyGet = _Name
1391 Case UCase(
"OnActionPerformed
"), UCase(
"OnAdjustmentValueChanged
"), UCase(
"OnApproveAction
"), UCase(
"OnApproveReset
"), UCase(
"OnApproveUpdate
") _
1392 , UCase(
"OnChanged
"), UCase(
"OnErrorOccurred
"), UCase(
"OnFocusGained
"), UCase(
"OnFocusLost
") _
1393 , UCase(
"OnItemStateChanged
"), UCase(
"OnKeyPressed
"), UCase(
"OnKeyReleased
") _
1394 , UCase(
"OnMouseDragged
"), UCase(
"OnMouseEntered
"), UCase(
"OnMouseExited
"), UCase(
"OnMouseMoved
") _
1395 , UCase(
"OnMousePressed
"), UCase(
"OnMouseReleased
"), UCase(
"OnResetted
") _
1396 , UCase(
"OnTextChanged
"), UCase(
"OnUpdated
")
1397 If IsNull(_ControlModel) Then _PropertyGet =
"" Else _PropertyGet = SF_Register._GetEventScriptCode(_ControlModel, psProperty, _Name)
1398 Case UCase(
"Parent
")
1399 Set _PropertyGet = [_Parent]
1400 Case UCase(
"Picture
")
1401 Select Case _ControlType
1402 Case CTLBUTTON, CTLIMAGEBUTTON, CTLIMAGECONTROL
1403 If oSession.HasUnoProperty(_ControlModel,
"ImageURL
") Then _PropertyGet = ScriptForge.SF_FileSystem._ConvertFromUrl(_ControlModel.ImageURL)
1404 Case Else : GoTo CatchType
1406 Case UCase(
"Required
")
1407 Select Case _ControlType
1408 Case CTLCHECKBOX, CTLCOMBOBOX, CTLCURRENCYFIELD, CTLDATEFIELD, CTLIMAGECONTROL, CTLLISTBOX, CTLNUMERICFIELD _
1409 , CTLPATTERNFIELD, CTLRADIOBUTTON, CTLTEXTFIELD, CTLTIMEFIELD
1410 If oSession.HasUnoProperty(_ControlModel,
"InputRequired
") Then _PropertyGet = _ControlModel.InputRequired
1411 Case Else : GoTo CatchType
1413 Case UCase(
"Text
")
1414 Select Case _ControlType
1416 If oSession.HasUNOProperty(_ControlModel,
"Date
") _
1417 And oSession.HasUNOProperty(_ControlModel,
"FormatKey
") _
1418 And oSession.HasUNOProperty(_ControlModel,
"FormatsSupplier
") Then
1419 If Not IsEmpty(_ControlModel.Date) Then
1420 With _ControlModel.Date
1421 vDate = DateSerial(.Year, .Month, .Day)
1423 _PropertyGet = Format(vDate, _ControlModel.FormatsSupplier.getNumberFormats.getByKey(_ControlModel.FormatKey).FormatString)
1427 If oSession.HasUNOProperty(_ControlModel,
"Text
") Then
1428 If Not IsEmpty(_ControlModel.Time) Then
1429 With _ControlModel.Time
1430 vDate = TimeSerial(.Hours, .Minutes, .Seconds)
1432 _PropertyGet = Format(vDate,
"HH:MM:SS
")
1435 Case CTLCOMBOBOX, CTLFILECONTROL, CTLFORMATTEDFIELD, CTLPATTERNFIELD, CTLTEXTFIELD
1436 If oSession.HasUnoProperty(_ControlModel,
"Text
") Then _PropertyGet = _ControlModel.Text
1437 Case Else : GoTo CatchType
1439 Case UCase(
"TipText
")
1440 Select Case _ControlType
1441 Case CTLHIDDENCONTROL : GoTo CatchType
1443 If oSession.HasUnoProperty(_ControlModel,
"HelpText
") Then _PropertyGet = _ControlModel.HelpText
1445 Case UCase(
"TripleState
")
1446 Select Case _ControlType
1448 If oSession.HasUnoProperty(_ControlModel,
"TriState
") Then _PropertyGet = _ControlModel.TriState
1449 Case Else : GoTo CatchType
1451 Case UCase(
"Value
")
' Default values are set here by control type, not in the
2nd argument (pvDefault)
1453 Select Case _ControlType
1454 Case CTLBUTTON
'Boolean, toggle buttons only
1456 If oSession.HasUnoProperty(_ControlModel,
"Toggle
") Then
1457 If oSession.HasUnoProperty(_ControlModel,
"State
") Then vGet = ( _ControlModel.State =
1 )
1459 Case CTLCHECKBOX
'0 = Not checked,
1 = Checked,
2 = Don
't know
1460 If oSession.HasUnoProperty(_ControlModel,
"State
") Then vGet = _ControlModel.State Else vGet =
2
1461 Case CTLCOMBOBOX, CTLFILECONTROL, CTLPATTERNFIELD, CTLTEXTFIELD
'String
1462 If oSession.HasUnoProperty(_ControlModel,
"Text
") Then vGet = _ControlModel.Text Else vGet =
""
1463 Case CTLCURRENCYFIELD, CTLNUMERICFIELD
'Numeric
1464 If oSession.HasUnoProperty(_ControlModel,
"Value
") Then vGet = _ControlModel.Value Else vGet =
0
1465 Case CTLDATEFIELD
'Date
1467 If oSession.HasUnoProperty(_ControlModel,
"Date
") Then
1468 If VarType(_ControlModel.Date) = ScriptForge.V_OBJECT Then
' com.sun.star.util.Date
1469 With _ControlModel.Date
1470 vDate = DateSerial(.Year, .Month, .Day)
1473 Else
' .Date = Empty
1476 Case CTLFORMATTEDFIELD
'String or numeric
1477 If oSession.HasUnoProperty(_ControlModel,
"EffectiveValue
") Then vGet = _ControlModel.EffectiveValue Else vGet =
""
1478 Case CTLHIDDENCONTROL
'String
1479 If oSession.HasUnoProperty(_ControlModel,
"HiddenValue
") Then vGet = _ControlModel.HiddenValue Else vGet =
""
1480 Case CTLLISTBOX
'String or array of strings depending on MultiSelection
1481 ' StringItemList is the list of the items displayed in the box
1482 ' ValueItemList is the list of the values in the underlying database field
1483 ' SelectedItems is the list of the indexes in StringItemList of the selected items
1484 ' It can go beyond the limits of StringItemList
1485 ' It can contain multiple values even if the listbox is not multiselect
1486 If oSession.HasUnoProperty(_ControlModel,
"StringItemList
") And oSession.HasUnoProperty(_ControlModel,
"SelectedItems
") _
1487 And oSession.HasUnoProperty(_ControlModel,
"MultiSelection
") Then
1488 vSelection = _ControlModel.SelectedItems
1489 ' The list of allowed values depends on the existence of a bound column
1490 If _ListBoxBound() Then vList = _ControlModel.ValueItemList Else vList = _ControlModel.StringItemList
1491 If _ControlModel.MultiSelection Then vValues = Array()
1492 For i =
0 To UBound(vSelection)
1493 lIndex = vSelection(i)
1494 If lIndex
>=
0 And lIndex
<= UBound(vList) Then
1495 If Not _ControlModel.MultiSelection Then
1496 vValues = vList(lIndex)
1499 vValues = ScriptForge.SF_Array.Append(vValues, vList(lIndex))
1506 Case CTLRADIOBUTTON
'Boolean
1507 If oSession.HasUnoProperty(_ControlModel,
"State
") Then vGet = ( _ControlModel.State =
1 ) Else vGet = False
1508 Case CTLSCROLLBAR
'Numeric
1510 If oSession.HasUnoProperty(_ControlModel,
"ScrollValue
") Then
1511 If Not IsEmpty(_ControlModel.ScrollValue) Then vGet = _ControlModel.ScrollValue
1514 If oSession.HasUnoProperty(_ControlModel,
"SpinValue
") Then vGet = _ControlModel.SpinValue Else vGet =
0
1517 If oSession.HasUnoProperty(_ControlModel,
"Time
") Then
1518 If VarType(_ControlModel.Time) = ScriptForge.V_OBJECT Then
' com.sun.star.Util.Time
1519 With _ControlModel.Time
1520 vDate = TimeSerial(.Hours, .Minutes, .Seconds)
1523 Else
' .Time = Empty
1526 Case Else : GoTo CatchType
1529 Case UCase(
"Visible
")
1530 If oSession.HasUnoMethod(_ControlView,
"isVisible
") Then _PropertyGet = CBool(_ControlView.isVisible())
1531 Case UCase(
"XControlModel
")
1532 Set _PropertyGet = _ControlModel
1533 Case UCase(
"XControlView
")
1534 Set _PropertyGet = _ControlView
1540 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1546 End Function
' SFDocuments.SF_FormControl._PropertyGet
1548 REM -----------------------------------------------------------------------------
1549 Private Function _PropertySet(Optional ByVal psProperty As String _
1550 , Optional ByVal pvValue As Variant _
1552 ''' Set the new value of the named property
1553 ''' Args:
1554 ''' psProperty: the name of the property
1555 ''' pvValue: the new value of the given property
1557 Dim bSet As Boolean
' Return value
1558 Static oSession As Object
' Alias of SF_Session
1559 Dim sFormName As String
' Full form identification for error messages
1560 Dim vSet As Variant
' Value to set in UNO model or view property
1561 Dim vActions As Variant
' Action property: list of available actions
1562 Dim sAction As String
' A single action
1563 Dim vFormats As Variant
' Format property: output of _FormatsList()
1564 Dim iFormat As Integer
' Format property: index in vFormats
1565 Dim vSelection As Variant
' Alias of Model.SelectedItems
1566 Dim vList As Variant
' Alias of Model.StringItemList
1567 Dim lIndex As Long
' Index in StringItemList
1568 Dim sItem As String
' A single item
1569 Dim oDatabase As Object
' The database object related to the parent form of the control instance
1571 Dim cstThisSub As String
1572 Const cstSubArgs =
"Value
"
1574 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1577 cstThisSub =
"SFDocuments.FormControl.set
" & psProperty
1578 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1579 If Not _ParentForm._IsStillAlive() Then GoTo Finally
1581 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
1583 Select Case UCase(psProperty)
1584 Case UCase(
"Action
")
1585 Select Case _ControlType
1587 vActions = Array(
"none
",
"submitForm
",
"resetForm
",
"refreshForm
",
"moveToFirst
",
"moveToLast
",
"moveToNext
",
"moveToPrev
" _
1588 ,
"saveRecord
",
"moveToNew
",
"deleteRecord
",
"undoRecord
")
1589 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Action
", ScriptForge.V_STRING, vActions) Then GoTo Finally
1590 If oSession.HasUNOProperty(_ControlModel,
"ButtonType
") Then
1591 sAction = vActions(ScriptForge.SF_Array.IndexOf(vActions, pvValue, CaseSensitive := False))
1592 _ControlModel.TargetURL =
""
1594 Case
"none
" : vSet = com.sun.star.form.FormButtonType.PUSH
1595 Case
"submitForm
" : vSet = com.sun.star.form.FormButtonType.SUBMIT
1596 Case
"resetForm
" : vSet = com.sun.star.form.FormButtonType.RESET
1598 vSet = com.sun.star.form.FormButtonType.URL
1599 _ControlModel.TargetURL =
".uno:FormController/
" & sAction
1601 _ControlModel.ButtonType = vSet
1603 Case Else : GoTo CatchType
1605 Case UCase(
"Caption
")
1606 Select Case _ControlType
1607 Case CTLBUTTON, CTLCHECKBOX, CTLFIXEDTEXT, CTLGROUPBOX, CTLRADIOBUTTON
1608 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Caption
", V_STRING) Then GoTo Finally
1609 If oSession.HasUNOProperty(_ControlModel,
"Label
") Then _ControlModel.Label = pvValue
1610 Case Else : GoTo CatchType
1612 Case UCase(
"Default
")
1613 Select Case _ControlType
1615 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Default
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1616 If oSession.HasUNOProperty(_ControlModel,
"DefaultButton
") Then _ControlModel.DefaultButton = pvValue
1617 Case Else : GoTo CatchType
1619 Case UCase(
"Enabled
")
1620 Select Case _ControlType
1621 Case CTLHIDDENCONTROL : GoTo CatchType
1623 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Enabled
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1624 If oSession.HasUnoProperty(_ControlModel,
"Enabled
") Then _ControlModel.Enabled = pvValue
1626 Case UCase(
"Format
")
1627 Select Case _ControlType
1628 Case CTLDATEFIELD, CTLTIMEFIELD
1629 vFormats = _FormatsList()
1630 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Format
", V_STRING, vFormats) Then GoTo Finally
1631 iFormat = ScriptForge.SF_Array.IndexOf(vFormats, pvValue, CaseSensitive := False)
1632 If oSession.HasUNOProperty(_ControlModel,
"DateFormat
") Then
1633 _ControlModel.DateFormat = iFormat
1634 ElseIf oSession.HasUNOProperty(_ControlModel,
"TimeFormat
") Then
1635 _ControlModel.TimeFormat = iFormat
1637 Case Else : GoTo CatchType
1639 Case UCase(
"ListIndex
")
1640 If Not ScriptForge.SF_Utils._Validate(pvValue,
"ListIndex
", ScriptForge.V_NUMERIC) Then GoTo Finally
1641 Select Case _ControlType
1643 If oSession.HasUNOProperty(_ControlModel,
"Text
") And oSession.HasUNOProperty(_ControlModel,
"StringItemList
") Then
1644 If pvValue
>=
0 And pvValue
<= UBound(_ControlModel.StringItemList) Then _ControlModel.Text = _ControlModel.StringItemList(CInt(pvValue))
1647 If oSession.HasUNOProperty(_ControlModel,
"SelectedItems
") Then _ControlModel.SelectedItems = Array(CInt(pvValue))
1648 Case Else : GoTo CatchType
1650 Case UCase(
"ListSource
")
1651 Select Case _ControlType
1652 Case CTLCOMBOBOX, CTLLISTBOX
1653 If oSession.HasUNOProperty(_ControlModel,
"ListSource
") Then
1654 If Not ScriptForge.SF_Utils._Validate(pvValue, psProperty, V_STRING) Then Goto Finally
1655 With com.sun.star.form.ListSourceType
1656 Select Case _ControlModel.ListSourceType
1660 Set oDatabase = _ParentForm.GetDatabase()
1661 If _ControlModel.ListSourceType = .QUERY Then vList = oDatabase.Queries Else vList = oDatabase.Tables
1662 If Not ScriptForge.SF_Utils._Validate(pvValue, psProperty, V_STRING, vList) Then Goto Finally
1663 If _ControlType = CTLCOMBOBOX Then _ControlModel.ListSource = pvValue Else _ControlModel.ListSource = Array(pvValue)
1664 _ControlModel.refresh()
1666 Set oDatabase = _ParentForm.GetDatabase()
1667 If _ControlType = CTLCOMBOBOX Then _ControlModel.ListSource = oDatabase._ReplaceSquareBrackets(pvValue) Else _ControlModel.ListSource = Array(oDatabase._ReplaceSquareBrackets(pvValue))
1668 _ControlModel.refresh()
1669 Case .VALUELIST
' ListBox only !
1670 _ControlModel.ListSource = Split(pvValue,
";
")
1671 _ControlModel.StringItemList = _ControlModel.ListSource
1672 Case .SQLPASSTHROUGH
1673 If _ControlType = CTLCOMBOBOX Then _ControlModel.ListSource = pvValue Else _ControlModel.ListSource = Array(pvValue)
1674 _ControlModel.refresh()
1678 Case Else : GoTo CatchType
1680 Case UCase(
"ListSourceType
")
1681 With com.sun.star.form.ListSourceType
1682 Select Case _ControlType
1684 If Not ScriptForge.SF_Utils._Validate(pvValue,
"ListSourceType
", ScriptForge.V_NUMERIC, Array( _
1690 )) Then GoTo Finally
1692 If Not ScriptForge.SF_Utils._Validate(pvValue,
"ListSourceType
", ScriptForge.V_NUMERIC, Array( _
1699 )) Then GoTo Finally
1700 Case Else : GoTo CatchType
1703 If oSession.HasUnoProperty(_ControlModel,
"ListSourceType
") Then _ControlModel.ListSourceType = pvValue
1704 Case UCase(
"Locked
")
1705 Select Case _ControlType
1706 Case CTLCOMBOBOX, CTLCURRENCYFIELD, CTLDATEFIELD, CTLFILECONTROL, CTLFORMATTEDFIELD, CTLIMAGECONTROL _
1707 , CTLLISTBOX, CTLNUMERICFIELD, CTLPATTERNFIELD, CTLTEXTFIELD, CTLTIMEFIELD
1708 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Locked
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1709 If oSession.HasUnoProperty(_ControlModel,
"ReadOnly
") Then _ControlModel.ReadOnly = pvValue
1710 Case Else : GoTo CatchType
1712 Case UCase(
"MultiSelect
")
1713 Select Case _ControlType
1715 If Not ScriptForge.SF_Utils._Validate(pvValue,
"MultiSelect
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1716 If oSession.HasUnoProperty(_ControlModel,
"MultiSelection
") Then _ControlModel.MultiSelection = pvValue
1717 If oSession.HasUnoProperty(_ControlModel,
"MultiSelectionSimpleMode
") Then _ControlModel.MultiSelectionSimpleMode = pvValue
1718 If oSession.HasUnoProperty(_ControlModel,
"SelectedItems
") Then
1719 ' Cancel selections when MultiSelect becomes False
1720 If Not pvValue And UBound(_ControlModel.SelectedItems)
> 0 Then
1721 lIndex = _ControlModel.SelectedItems(
0)
1722 _ControlModel.SelectedItems = Array(lIndex)
1725 Case Else : GoTo CatchType
1727 Case UCase(
"OnActionPerformed
"), UCase(
"OnAdjustmentValueChanged
"), UCase(
"OnApproveAction
"), UCase(
"OnApproveReset
"), UCase(
"OnApproveUpdate
") _
1728 , UCase(
"OnChanged
"), UCase(
"OnErrorOccurred
"), UCase(
"OnFocusGained
"), UCase(
"OnFocusLost
") _
1729 , UCase(
"OnItemStateChanged
"), UCase(
"OnKeyPressed
"), UCase(
"OnKeyReleased
") _
1730 , UCase(
"OnMouseDragged
"), UCase(
"OnMouseEntered
"), UCase(
"OnMouseExited
"), UCase(
"OnMouseMoved
") _
1731 , UCase(
"OnMousePressed
"), UCase(
"OnMouseReleased
"), UCase(
"OnResetted
") _
1732 , UCase(
"OnTextChanged
"), UCase(
"OnUpdated
")
1733 If Not ScriptForge.SF_Utils._Validate(pvValue, psProperty, V_STRING) Then Goto Finally
1734 If Not IsNull(_ControlModel) Then
1735 bSet = SF_Register._RegisterEventScript(_ControlModel _
1737 , _GetListener(psProperty) _
1742 Case UCase(
"Picture
")
1743 Select Case _ControlType
1744 Case CTLBUTTON, CTLIMAGEBUTTON, CTLIMAGECONTROL
1745 If Not ScriptForge.SF_Utils._ValidateFile(pvValue,
"Picture
") Then GoTo Finally
1746 If oSession.HasUnoProperty(_ControlModel,
"ImageURL
") Then _ControlModel.ImageURL = ScriptForge.SF_FileSystem._ConvertToUrl(pvValue)
1747 Case Else : GoTo CatchType
1749 Case UCase(
"TipText
")
1750 Select Case _ControlType
1751 Case CTLHIDDENCONTROL : GoTo CatchType
1753 If Not ScriptForge.SF_Utils._Validate(pvValue,
"TipText
", V_STRING) Then GoTo Finally
1754 If oSession.HasUnoProperty(_ControlModel,
"HelpText
") Then _ControlModel.HelpText = pvValue
1756 Case UCase(
"TripleState
")
1757 Select Case _ControlType
1759 If Not ScriptForge.SF_Utils._Validate(pvValue,
"TripleState
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1760 If oSession.HasUnoProperty(_ControlModel,
"TriState
") Then _ControlModel.TriState = pvValue
1761 Case Else : GoTo CatchType
1763 Case UCase(
"Value
")
1764 Select Case _ControlType
1765 Case CTLBUTTON
'Boolean, toggle buttons only
1766 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1767 If oSession.HasUnoProperty(_ControlModel,
"Toggle
") And oSession.HasUnoProperty(_ControlModel,
"State
") Then
1768 _ControlModel.State = Iif(pvValue,
1,
0)
1770 Case CTLCHECKBOX
'0 = Not checked,
1 = Checked,
2 = Don
't know
1771 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", Array(ScriptForge.V_BOOLEAN, ScriptForge.V_NUMERIC), Array(
0,
1,
2, True, False)) Then GoTo Finally
1772 If oSession.HasUnoProperty(_ControlModel,
"State
") Then
1773 If VarType(pvValue) = ScriptForge.V_BOOLEAN Then pvValue = Iif(pvValue,
1,
0)
1774 _ControlModel.State = pvValue
1777 If oSession.HasUnoProperty(_ControlModel,
"Text
") And oSession.HasUnoProperty(_ControlModel,
"StringItemList
") Then
1778 If pvValue
<> "" Then
1779 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", V_STRING, _ControlModel.StringItemList) Then Goto Finally
1781 _ControlModel.Text = pvValue
1783 Case CTLCURRENCYFIELD, CTLNUMERICFIELD
'Numeric
1784 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", ScriptForge.V_NUMERIC) Then GoTo Finally
1785 If oSession.HasUnoProperty(_ControlModel,
"Value
") Then _ControlModel.Value = pvValue
1786 Case CTLDATEFIELD
'Date
1787 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", V_DATE) Then GoTo Finally
1788 If oSession.HasUnoProperty(_ControlModel,
"Date
") Then
1789 Set vSet = New com.sun.star.util.Date
1790 vSet.Year = Year(pvValue)
1791 vSet.Month = Month(pvValue)
1792 vSet.Day = Day(pvValue)
1793 _ControlModel.Date = vSet
1796 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", V_STRING) Then GoTo Finally
1797 If oSession.HasUnoProperty(_ControlModel,
"Text
") Then _ControlModel.Text = ScriptForge.SF_FileSystem._ConvertToUrl(pvValue)
1798 Case CTLFORMATTEDFIELD
'String or numeric
1799 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
1800 If oSession.HasUnoProperty(_ControlModel,
"EffectiveValue
") Then _ControlModel.EffectiveValue = pvValue
1801 Case CTLHIDDENCONTROL
'String
1802 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", V_STRING) Then GoTo Finally
1803 If oSession.HasUnoProperty(_ControlModel,
"HiddenValue
") Then _ControlModel.HiddenValue = pvValue
1804 Case CTLLISTBOX
'String or number - Only a single value may be set
1805 ' StringItemList is the list of the items displayed in the box
1806 ' ValueItemList is the list of the values in the underlying database field
1807 ' SelectedItems is the list of the indexes in StringItemList of the selected items
1808 If oSession.HasUnoProperty(_ControlModel,
"StringItemList
") And oSession.HasUnoProperty(_ControlModel,
"SelectedItems
") Then
1809 ' Setting the value on a listbox is allowed only if single value and value in the list
1810 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
1811 ' The list of allowed values depends on the existence of a bound column
1812 If _ListboxBound() Then vList = _ControlModel.ValueItemList Else vList = _ControlModel.StringItemList
1813 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", , vList) Then GoTo Finally
1814 _ControlModel.SelectedItems = Array(ScriptForge.SF_Array.IndexOf(vList, pvValue, CaseSensitive := True))
1816 Case CTLPATTERNFIELD, CTLTEXTFIELD
'String
1817 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", V_STRING) Then GoTo Finally
1818 If oSession.HasUnoProperty(_ControlModel,
"Text
") Then _ControlModel.Text = pvValue
1819 Case CTLRADIOBUTTON
'Boolean
1820 ' A group of radio buttons is presumed sharing the same GroupName
1821 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1822 If oSession.HasUnoProperty(_ControlModel,
"State
") Then _ControlModel.State = Iif(pvValue,
1,
0)
1823 Case CTLSCROLLBAR
'Numeric
1824 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", ScriptForge.V_NUMERIC) Then GoTo Finally
1825 If oSession.HasUnoProperty(_ControlModel,
"ScrollValueMin
") Then
1826 If pvValue
< _ControlModel.ScrollValueMin Then pvValue = _ControlModel.ScrollValueMin
1828 If oSession.HasUnoProperty(_ControlModel,
"ScrollValueMax
") Then
1829 If pvValue
> _ControlModel.ScrollValueMax Then pvValue = _ControlModel.ScrollValueMax
1831 If oSession.HasUnoProperty(_ControlModel,
"ScrollValue
") Then _ControlModel.ScrollValue = pvValue
1832 Case CTLSPINBUTTON
'Numeric
1833 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", ScriptForge.V_NUMERIC) Then GoTo Finally
1834 If oSession.HasUnoProperty(_ControlModel,
"SpinValueMin
") Then
1835 If pvValue
< _ControlModel.SpinValueMin Then pvValue = _ControlModel.SpinValueMin
1837 If oSession.HasUnoProperty(_ControlModel,
"SpinValueMax
") Then
1838 If pvValue
> _ControlModel.SpinValueMax Then pvValue = _ControlModel.SpinValueMax
1840 If oSession.HasUnoProperty(_ControlModel,
"SpinValue
") Then _ControlModel.SpinValue = pvValue
1842 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Value
", V_DATE) Then GoTo Finally
1843 If oSession.HasUnoProperty(_ControlModel,
"Time
") Then
1844 Set vSet = New com.sun.star.util.Time
1845 vSet.Hours = Hour(pvValue)
1846 vSet.Minutes = Minute(pvValue)
1847 vSet.Seconds = Second(pvValue)
1848 _ControlModel.Time = vSet
1850 Case Else : GoTo CatchType
1852 ' FINAL COMMITMENT
1853 If oSession.HasUNOMethod(_ControlModel,
"commit
") Then _ControlModel.commit()
' f.i. checkboxes have no commit method ??
1854 Case UCase(
"Visible
")
1855 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Visible
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1856 If oSession.HasUnoMethod(_ControlView,
"setVisible
") Then
1857 If pvValue Then _ControlModel.EnableVisible = True
1858 _ControlView.setVisible(pvValue)
1866 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1872 If Len(_ParentForm._FormDocumentName)
> 0 Then sFormName = _ParentForm._FormDocumentName
& ".
" Else sFormName =
""
1873 ScriptForge.SF_Exception.RaiseFatal(FORMCONTROLTYPEERROR, _Name, sFormName
& _FormName, _ControlType, psProperty)
1875 End Function
' SFDocuments.SF_FormControl._PropertySet
1877 REM -----------------------------------------------------------------------------
1878 Private Function _Repr() As String
1879 ''' Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
1880 ''' Args:
1881 ''' Return:
1882 ''' "[FORMCONTROL]: Name, Type (formname)
1883 _Repr =
"[FORMCONTROL]:
" & _Name
& ",
" & _ControlType
& " (
" & _FormName
& ")
"
1885 End Function
' SFDocuments.SF_FormControl._Repr
1887 REM ============================================ END OF SFDOCUMENTS.SF_FORMCONTROL