da tauchen schon ein paar merkwürdige Dinge auf, die nicht so simple aufzulösen sind.
Für deine Zwecke sollte die Variable oDialog als Global deklariert werden, da in deinem Fall das Ereignis "Auswahl geändert" (auch bei nur einem Klick) mehrfach ausgelöst wird. Das Auftauchen deines Dialoges ist auch ein solcher (der Focus wechselt, zumindest zwischenzeitlich, zum Dialog und wieder zurück). Wird das Tabellenblatt gewechselt, wird das Ereignis auch zweimal ausgelöst (ich vermute mal: 1. Tabellenblatt ausgewählt 2. Zelle ausgewählt).
Als Public deklarierte Variablen behalten ihren Wert nur solange das Makro läuft. Bei jedem Neuaufruf werden sie neu initialisiert.
Bei Global wird das Makro zwar auch mehrfach aufgerufen, aber da ist die Variable oDialog schon belegt und der Dialog wird nicht noch einmal gebaut, sondern "nur" aufgefrischt.
Die Ursache für deine eingangs genannte Fehlermeldung liegt eher daran, dass es eine Weile dauert, bis das Bild wirklich eingefügt ist (Ladezeiten). Um das zu umgehen, baust du eine Waretschleife ein:
Code: Alles auswählen
Global cardGraphic as Object, odialog as object
Sub ShowCardGraphic(cardGraphicName as String)
Dim oWindow As Object, odlgModel As Object, oMod As Object, oCntrl As Object, oTopWindowsListener As Object, oSimpleFileAccess As Object
if pathLackeyPlugin = "" then
cardGraphicName = "http://www.redemptionquick.com/lackey/sets/setimages/general/" & cardGraphicName & ".jpg"
end if
If isnull(odialog) Then
REM ***** Initialisierung der Eigenschaften des Dialogs
odlgModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
With odlgModel
' .setPropertyValue("FontName", Font)
.setPropertyValue("Width", 180)
.setPropertyValue("Height", 240)
.setPropertyValue("PositionX", -0)
.setPropertyValue("PositionY", 80)
.setPropertyValue("Title", "Picture")
.setPropertyValue("Name", "DLG_PICTURE")
End With
odialog = CreateUnoService("com.sun.star.awt.UnoControlDialog")
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlImageControlModel")
With oMod
'.setPropertyValue("Label", "X")
.setPropertyValue("Name", "IMG1")
.setPropertyValue("PositionX", 0)
.setPropertyValue("PositionY", 0)
.setPropertyValue("Width", 180)
.setPropertyValue("Height", 240)
.setPropertyValue("ImageURL" ,cardGraphicName)
.setPropertyValue("ScaleMode", 1)
End With
dim x
odlgModel.insertByName("IMG1", oMod)
odialog.setModel(odlgModel)
REM ********** Mittels des Modells den Dialog anzeigen
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
odialog.createPeer(oWindow, null)
Dim oWindowsListener as Object
oTopWindowsListener = CreateUnoListener( "Top_Win_", "com.sun.star.awt.XTopWindowListener" )
odialog.addTopWindowListener(oTopWindowsListener)
odialog.setVisible(True)
do
oCntrl = odialog.getcontrol("IMG1")
wait 100
loop while isnull(ocntrl)
Else
if not odialog.isVisible() Then
odialog.setVisible(True)
end if
do
oCntrl = odialog.getcontrol("IMG1")
wait 100
loop while isnull(ocntrl)
oCntrl.model.ImageURL = cardGraphicName
end if
End Sub
Code: Alles auswählen
Sub OnSheetContentChange(e) as boolean
'when a cell in column card name of sheet List is selected we need to take that name to get the cardimage name from sheet carddata.txt
Dim oDoc as Object, form as Object, showCardImgCB as Object
Dim oldRow as Long, oldColumn as Long
Dim foundCardName as String
Dim tmpevent 'Zwischenspeicher für Tabellenereignis
oDoc = thisComponent
form = oDoc.sheets(0).Drawpage.Forms.getByIndex(0)
'Tabellenereignis vorläufig entfernen
tmpevent=odoc.sheets(0).events.getbyname("OnSelect")
Dim oStruct as new com.sun.star.beans.PropertyValue
odoc.sheets(0).events.replaceByName("OnSelect",ostruct)
'Checkbox auslesen
showCardImgCB = form.getByName("ShowCardImage")
'print showCardImgCB.currentvalue
'remember last activated cell
oldRow = currentRow
oldColumn = currentColumn
'print "Vorher: oldRow=" & oldRow & " currentRow=" & currentRow
currentRow = GetCurrentRow
currentColumn = GetCurrentColumn
'print "Nachher: oldRow=" & oldRow & " currentRow=" & currentRow
'if selected cell has changed and if we are in column B then we can go ahead
'this unfortunately cannot cover if mouse pointer is over image or has image selected and image was deleted
if ((oldRow <> currentRow) and (currentColumn = 1)) then
'print currentColumn & " " & currentRow
foundCardName = oDoc.getcurrentcontroller.activesheet.getCellByPosition(14, currentRow).getString()
currentCardName = foundCardName
'print oDoc.getcurrentcontroller.activesheet.getCellByPosition(14, currentRow).getString()
end if
'only show card image if appropriate checkbox is ticked and if we are in column B
if (cbool (showCardImgCB.currentvalue) and (currentColumn = 1)) then
ShowCardGraphic(ByVal currentCardName)
end if
'Tabellenereigbnis wiederherstellen
odoc.sheets(0).events.replaceByName("OnSelect",tmpevent)
OnSheetContentChange=true
End Sub