ok, here is the opus:
for changing multiple images depending on selection range. Images can be in frames or in texttables (but not more complex situations like images in frames in a table).
If cursor is a point (no selection) then all images will be changed (also in header, footer, foot- and end-notes, or anchored to page or images in frames in frames etc.).
If a selection range in document is made all images within the selection are changed. if there are frames or tables within the selection range then all contained images will be changed.
Selection range can also be in a table, frame or header, footer etc.
You can select an image to be changed. If you select a frame, all images in the frame will be changed. You can make table range selections.
Perhaps all this could be solved more elegant and better and I will have a look at it someday.
If you ask yourself what is it all about - only to adjust the Red?, then have a look at the PicTool of the free Project in my Signature. If I managed to make an extension of that tool alone, I will post it in the extension thread.
Code: Select all
sub changeimageswithinselection7 'with textframes and texttables, Anchor at frames or pages, Textframe selection, selection range also in not main text
oDoc = ThisComponent
oText = oDoc.Text
go = oDoc.getGraphicObjects
oFrames = oDoc.getTextFrames()
oTables = oDoc.getTextTables()
oRange = oDoc.currentSelection(0)
g = ThisComponent.CurrentSelection(0)
if g.supportsService("com.sun.star.text.TextGraphicObject")=true then 'single image selected
gosub processimage
elseif g.supportsService("com.sun.star.text.TextFrame") then 'Textframe selected
oFrame = g
For i = 0 to go.Count-1
g = go.getByIndex(i)
if EqualUnoObjects(oFrame.text, g.anchor.Text)=true then
gosub processimage
elseif g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_FRAME then
if g.AnchorFrame.name = oFrame.name then gosub processimage
end if
next i
else 'no single image selected
For i = 0 to go.Count-1
g = go.getByIndex(i)
rem------TextTable cellrange selection
if oRange.supportsService("com.sun.star.text.TextTableCursor") Then
oTextTable = ThisComponent.CurrentController.ViewCursor.TextTable
if instr(oRange.RangeName, ":")>0 then
selrange = oTextTable.getCellRangeByName(oRange.RangeName)
rem---------------------------------------------------
iNumCols = UBound(selrange.getColumnDescriptions())
iNumRows = UBound(selrange.GetRowDescriptions())
For iCol = 0 To iNumCols
For iRow = 0 To iNumRows
oCell = selrange.getCellByPosition(iCol, iRow)
if EqualUnoObjects(g.anchor.text,oCell)=true then 'if image is in selected cell of table
gosub processimage
end if
Next
Next
rem----------alternatively---------------------------------
' oData() = selrange.getDataArray()
' For i = LBound(oData()) To UBound(oData())
' oRow() = oData(i)
' For j = LBound(oRow()) To UBound(oRow())
' oCell = selrange.getCellByPosition(j,i)
' if EqualUnoObjects(g.anchor.text,oCell)=true then 'if image is in selected cell of table
' gosub processimages
' end if
' Next j
' Next i
rem---------------------------------------------
else 'if cellrange is only 1 single cell (eg. in complex tables)
oCell = oTextTable.getCellByName(oRange.RangeName)
if EqualUnoObjects(g.anchor.text,oCell)=true then 'if image is in selected cell of table
gosub processimage
end if
end if
rem--------if no selection then process all images
elseif oRange.text.compareRegionStarts(oRange.getStart, oRange.getEnd)=0 then 'if no selection then process all images
gosub processimage
rem--------don't process images anchored to page
elseif g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE then 'don't process images anchored to page
rem--------if selection range is not in main text eg.textframe, 1tablecelltext, footer etc.
elseif EqualUnoObjects(oRange.text, oText)=false then 'if selection range is not in main text eg.textframe, 1tablecelltext, footer etc.
if EqualUnoObjects(oRange.text, g.anchor.Text)=false or g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_FRAME then
elseif oRange.text.compareRegionStarts(g.anchor, oRange)=1 OR oRange.text.compareRegionEnds(g.anchor, oRange)=-1 then 'out of selection
else
gosub processimage
end if
rem----if image anchor not in main text or is anchored to frame compare it with textframes and texttables
elseif EqualUnoObjects(oText, g.anchor.Text)=false or g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_FRAME then 'if image anchor not in main text or is anchored to frame compare it with texttables
rem--------textframes
For l = 0 to oFrames.Count-1
oFrame = oFrames.getByIndex(l)
if oText.compareRegionStarts(oFrame.anchor, oRange)=1 OR oText.compareRegionEnds(oFrame.anchor, oRange)=-1 then 'out of selection
elseif EqualUnoObjects(oFrame.text, g.anchor.Text)=true then
gosub processimage
elseif g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_FRAME then
if g.AnchorFrame.name = oFrame.name then gosub processimage
end if
next l
rem--------texttables
oTextElementEnum = thisComponent.getCurrentSelection().getByIndex(0).createEnumeration()
while oTextElementEnum.hasMoreElements()
oTextElement = oTextElementEnum.nextElement
if oTextElement.supportsService("com.sun.star.text.TextTable") then
oTable = oTextElement
cellnames = oTable.getCellNames()
For c = LBound(cellnames) To UBound(cellnames)
cellname = cellnames(c)
if EqualUnoObjects(g.anchor.text, oTable.getCellByName(cellname))=true then 'if image is in any cell of table
gosub processimage
end if
next c
end if
wend
rem------regular selection
elseif oText.compareRegionStarts(g.anchor, oRange)=1 OR oText.compareRegionEnds(g.anchor, oRange)=-1 then 'out of selection
else 'images within selection range
gosub processimage
end if
next i
end if 'no single image selected
exit sub
processimage:
g.AdjustRed=100
RETURN
end sub