dotfiles/eggs/libreoffice/4/user/basic/Standard/ConditionalShow.xba
2025-10-13 14:25:15 +02:00

65 lines
2.0 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConditionalShow" script:language="StarBasic" script:moduleType="normal">Sub ShowImageBasedOnValue(oEvent)
Dim oListBox As Object
oListBox = oEvent.Source.Model
&apos; Get the selected indices (array, since multi-select is possible)
Dim sel() As Long
sel = oListBox.SelectedItems
If UBound(sel) &gt;= 0 Then
Dim idx As Long
idx = sel(0) &apos; take the first selected index
&apos; Get the corresponding string
Dim selectedValue As String
selectedValue = oListBox.StringItemList(idx)
&apos;MsgBox &quot;Selected index: &quot; &amp; idx &amp; Chr(10) &amp; &quot;Selected value: &quot; &amp; selectedValue
&apos; Define possible values and matching image names
Dim values(1) As String
Dim images(1) As String
values(0) = &quot;Bremen&quot;
images(0) = &quot;Shape 1&quot;
values(1) = &quot;Bremerhaven&quot;
images(1) = &quot;Shape 2&quot;
&apos; Hide all images first
Dim i As Integer
For i = LBound(images) To UBound(images)
Dim slide As Object
Dim shape As Object
Dim j As Integer
slide = ThisComponent.DrawPages(0) &apos; first slide, index starts at 0
For j = 0 To UBound(images)
&apos; Loop through shapes to find one with the name
For Each shape In slide.Shapes
If shape.Name = images(i) Then
shape.Visible = False
End If
Next
Next j
Next i
&apos; Show the one that matches
For i = LBound(values) To UBound(values)
If selectedValue = values(i) Then
ThisComponent.DrawPage.getByName(images(i)).Visible = True
Exit For
End If
Next i
Else
MsgBox &quot;Nothing selected&quot;
End If
End Sub
</script:module>