Apache OpenOffice (AOO) Bugzilla – Issue 33783
can not set AnchorType of a control in calc via API
Last modified: 2017-05-20 10:47:56 UTC
Hi, AFAIK it is not possible to anchor a control AT_PAGE as I can do it in writer. In calc all controls will be anchored at cell ... Please have a look at the macro ... Has it something to do with my issue http://www.openoffice.org/issues/show_bug.cgi?id=10019 or can this be fixed soon ? Ciao Oliver -- Option Explicit Sub CreateControl Dim oDocument as Object Dim oView as Object Dim oDrawPage as Object Dim oController as Object Dim oControlShape as Object Dim oControlModel as Object Dim oSize as New com.sun.star.awt.Size Dim oPosition as New com.sun.star.awt.Point oDocument = StarDesktop.getCurrentComponent oView = oDocument.CurrentController If Not hasUnoInterfaces(oDocument, "com.sun.star.sheet.XSpreadsheetDocument") Then oDrawPage = oDocument.DrawPage Else oDrawPage = oView.getActiveSheet.DrawPage EndIf oControlShape = oDocument.createInstance("com.sun.star.drawing.ControlShape") oSize.Height = 1000 oSize.Width = 3000 oPosition.X = 2000 oPosition.Y = 3000 oControlShape.setSize(oSize) oControlShape.setPosition(oPosition) ' this works only for Writer ... ' I am missing the "AnchorType" for calc with the options AT_CELL / AT_PAGE ' all controlls will be anchored at cell ... oControlShape.setPropertyValue("AnchorType", com.sun.star.text.TextContentAnchorType.AT_PAGE) oControlModel = createUNOService("com.sun.star.form.component.CommandButton") oControlModel.Name = "My Control" oControlModel.Enabled = True oControlShape.setControl(oControlModel) oDrawPage.add(oControlShape) oController = oView.getControl(oControlModel) oController.SetFocus() End Sub
Hi Frank, the attached macro doesn't work as expect. Is there any anchor type for spreadsheets? Bye Marc
well, as the name suggests, css.text.TextContentAnchorType is a Writer feature. It seems that in Calc, shapes cannot be anchored via API at all. You could argue whether this is a bug (since our API should be complete, shouldn't it?) or a missing feature ... Anyway, assigning to nn, who's in charge for the Calc/API.
Shapes in a spreadsheet have the property "Anchor" (can be set only after inserting the shape, modifies the position).
Hi Niklas, > Shapes in a spreadsheet have the property "Anchor" this seems to be true, I can access the anchored cell ... > (can be set only after inserting the shape, modifies the position). I don't know how to *set* a new anchor "at cell", or how to set "at page" oControlShape.Anchor = oCell does not work, seems to be write protected ... Could you please provide an example ? best regards Oliver
Hi, this issue is still valid for oo 2.0.2 rc1 ... Oliver
verified in oo 3.1 - all controls are anchored AT_CELL. AT_PAGE can be done only via GUI. are there any plans to fix this issue ?
Created attachment 62390 [details] here's an example that works right now
FWIW, after insertion, using... oControlShape.setPropertyValue("Anchor", oCell) oControlShape.setPropertyValue("Anchor", oSheet) toggles from cell anchored to sheet anchored in the attached example
Oliver, can you verify this works now? Without looking at Caolan's macro, I am pretty sure the issue is fixed: I used the API to change an object's anchor in Calc, when I fixed issue 99056, and it worked flawlessly :)
i just tried: oDrawPage.add(oControlShape) oControlShape.setPropertyValue("Anchor", oSheet) this will toggle to sheet anchored - but also set the controls position to strange X/Y positions: for example: X/Y controls X/Y 100/100 0,1/0,1cm 1000/1000 1,0/0,1cm 2000/2000 2,0/0,19 cm 3000/3000 0,74/0,29cm using oControlShape.setPropertyValue("Anchor", oSheet.getCellByPosition(2,2)) will set the *anchor* to cell C3 - with shapes oPosition.X=0 and oPosition.Y=0 it works like expected. setPropertyValue("Anchor") before inserting the control has no effect in this case the control is anchored to cell...
Oliver, I remember having had strange effects with the position, too. Well, at least unexpected, though perhaps explainable ... First, when you switch the anchor from a cell to the sheet, you need to get the shape's position first, and restore it after setting the Anchor property. This way, the control/shape stays where it was before changing the anchor. Otherwise, the position previously relative to the cell is now relative to the sheet, which makes the control jumping. Second, when you switch the anchor from the sheet to a cell, you also need to adjust the position, to prevent the control jumping. You might want to look into the impl_setSheetAnchorType_nothrow method in http://svn.services.openoffice.org/ooo/cws/dba32b/extensions/source/propctrlr/formgeometryhandler.cxx to see how I solved that. In any way, I would argue that the strange behavior of the position is another issue (if at all), since this one here is named "can not set AnchorType ...", which is not true anymore.
Hi Frank, from my point of view it should be possible to set a control - anchored to the sheet - for example to an absolut X/Y position like 3cm/3cm at the moment it will added to the drawpage - first set all properties, than add to drawpage .. in writer there is a property "AnchorType": com.sun.star.text. TextContentAnchorType.AT_PAGE/AT_CELL which will do the job ... in calc i have to add the control to the drawpage first, change the "Anchor" form cell to sheet (cause cell is default) and than have to set the new position cause 3/3cm changed undefinitly to 0,74/0,29 cm - so as you mentionend - before - the control will move ...... this is a bit unfortune i agree we could open a new issue ... Oliver
so this is the workaound for the moment: oPosition.X = 3000 oPosition.Y = 3000 [...] oDrawPage.add(oControlShape) oControlShape.setPropertyValue("Anchor", oSheet) oControlShape.setPosition(oPosition)
Reset assigne to the default "issues@openoffice.apache.org".