OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Moving table captions - above/below

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
jenpc
General User
General User


Joined: 25 Mar 2004
Posts: 34
Location: Ithaca, NY, USA

PostPosted: Fri Jun 04, 2004 2:23 pm    Post subject: Moving table captions - above/below Reply with quote

Is there an automated way to move all table captions from above the table to below, or vice versa (below to above)?

I know there have been other posts on the general subject of moving captions, but table captions work differently than other captions and a new frame is not inserted the way one is when you insert a figure and the new frame contains the figure and the caption.

(And yes, I agree that it's pretty easy to drag the caption from above the table to below the table, or vice versa. It's just a pain when there are about 100 tables and it is decided that the caption location needs to change.)

So if anyone knows of an easier way than manually dragging the caption for each table, I'd be much obliged.

-Jen
Back to top
View user's profile Send private message
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Fri Jun 04, 2004 7:29 pm    Post subject: Reply with quote

Sounds like another useful macro to write. If no one else has written it, I'll have a look at it when I get back from looking after my Mum who has just had another heart turn (just browsing this forum while waiting for a break in a storm to drive the 2 hours to see her).
_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.
Back to top
View user's profile Send private message
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Mon Jun 07, 2004 10:25 pm    Post subject: Reply with quote

Looks like no one else did it so here is some quick and dirty code that should do the job. See the sticky posting at the top of the code snippets forum for instructions on installing macros:
Code:
sub MoveCaptionsFromAboveTablesToBelow
subMoveCaptions("below")
end sub


sub MoveCaptionsFromBelowTablesToAbove
subMoveCaptions("above")
end sub


sub subMoveCaptions(sDestination as string)
'The cursor must be in the main document (i.e not in a table) otherwise nothing will happen
oDoc = thisComponent
oVC = oDoc.currentController.ViewCursor
oCursor = oVC.text.CreateTextCursorByRange(oVC)
oCursor.gotoEnd(true)
oParagraphEnum = oCursor.createEnumeration
while oParagraphEnum.hasMoreElements
   oParagraph = oParagraphEnum.nextElement
   if  oParagraph.supportsService("com.sun.star.text.Paragraph") then
      oCursor.gotoRange(oParagraph.start, false)
   elseif oParagraph.supportsService("com.sun.star.text.TextTable") then
      if sDestination = "above" then oCursor.gotoNextParagraph(false)
      oCursor.gotoStartOfParagraph(false)
      oCursor.gotoEndOfParagraph(true)
      oVC.gotoRange(oCursor, false)
      if oCursor.isCollapsed then
         if msgbox("Nothing in this paragraph to select.", 1, "No caption") = 2 then exit sub
      else
         nResponse = msgbox("Move this caption to " & sDestination & " table", 3, "Move Caption")
         if nResponse = 2 then exit sub
         if nResponse = 6 then
            fnDispatch("Cut")
            if sDestination = "above" then
               fnDispatch("GoRight", array("Count",1, "Select",False)
               fnDispatch("swBackspace")
               oCursor.gotoPreviousParagraph(false)
            else
               fnDispatch("Delete")
               oCursor.gotoNextParagraph(false)
            end if
            oVC.gotoRange(oCursor, false)
            fnDispatch("InsertPara")
            if sDestination = "below" then
               oCursor.gotoPreviousParagraph(false)
               oVC.gotoRange(oCursor, false)
            end if
            fnDispatch("Paste")
         end if
      end if
   end if
wend
end sub


function fnDispatch(sCommand as string, optional mArgs)
oFrame = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
on error resume next
if isMissing(mArgs) then
   fnDispatch = oDispatcher.executeDispatch(oFrame, ".uno:" & sCommand, "", 0, array())
else
   nArgs = uBound(mArgs) \ 2
   dim Args(nArgs) as new com.sun.star.beans.PropertyValue
   for i = 0 to nArgs
      Args(i).name = mArgs(i * 2)
      Args(i).value = mArgs(i * 2 + 1)
   next
   fnDispatch = oDispatcher.executeDispatch(oFrame, ".uno:" & sCommand, "", 0, Args())
end if
end function

_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.


Last edited by Iannz on Tue Jun 08, 2004 3:26 pm; edited 1 time in total
Back to top
View user's profile Send private message
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Mon Jun 07, 2004 10:49 pm    Post subject: Reply with quote

I edited my above post as just after posting the code I realized that there was a much better way of getting around the anchor property of tables bug. The revised way is now in the previous posting.
_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.
Back to top
View user's profile Send private message
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Tue Jun 08, 2004 3:29 pm    Post subject: Reply with quote

I have edited the code a second time as there was a bug in it Embarassed and I had private message requesting that it work from the current cursor location rather than simply iterating through all the tables.
_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.
Back to top
View user's profile Send private message
jenpc
General User
General User


Joined: 25 Mar 2004
Posts: 34
Location: Ithaca, NY, USA

PostPosted: Wed Jun 09, 2004 9:26 am    Post subject: Reply with quote

Hi Ian,

The macro to move table captions works much more consistently now. There are two additional annoyances, but I can work around them.

One is that when a caption is moved (above to below or below to above) the italics are sometimes lost. In particular this tends to happen after the table caption has been inserted and then is moved for the first time. It also happens if I manually drag & drop the caption, so it's probably more an OpenOffice feature/bug than your macro. I can work-around it by doing a search afterwards for the "table" paragraph style and then re-applying it (using replace) whenever it's found. (FYI for newbies - OpenOffice uses the "table" paragraph style by default when it inserts a caption for a table.)

The second annoyance is that if there is text (e.g. "Text body" paragraph style) immediately above or below the table, it is mistaken for a caption. That, too, is easy to work-around because I can just say "No" and skip to the next table.

Since someone might have their own paragraph style for captions instead of using the default "table" style, it's probably best to just leave the macro as it is. (If you wanted to note which lines of code to change to modify the behavior, and had trouble reproducing it, I can send a short file with a table that demonstrates both of the behaviors I've mentioned. But it's probably best to leave the posted code with the current functionality since it will work for people who are using a different style for captions. That makes it versatile.)

Thanks very much for writing this macro for me. I imagine some other people will find it quite useful also. Smile
_________________
Jen
Back to top
View user's profile Send private message
jenpc
General User
General User


Joined: 25 Mar 2004
Posts: 34
Location: Ithaca, NY, USA

PostPosted: Tue Jun 22, 2004 9:06 am    Post subject: Be forewarned of the consequences of dragging table captions Reply with quote

I've discovered that dragging a table caption (from above to below the table, or vice versa) instead of using cut & paste, causes any references to that table to no longer refer to the table. (Note that Ian's macro uses cut & paste, not drag & drop, so this issue doesn't affect the macro.)

An issue has been created for this ( http://www.openoffice.org/issues/show_bug.cgi?id=30534 ) and the problem has been confirmed.

So this is a warning against using drag & drop to move table captions.

If you have moved a table caption and the references to it no longer refer to it, here is one way to resolve the references (once you've found them):
1. Put your cursor over the reference - it should say "Table" in the little box the appears.
2. Double click- this should open the "Edit Fields: References" dialog box/window.
3. Note that the "Type" should already be set to "Table" and the "Name" is set to the table number.
4. Find the table corresponding to the number listed under "Name" and select it - this changes the name to "Table X" where X is the number.
5. Click on the "OK" button

Unfortunately I don't know how to search for unresolved references to tables. If anyone knows of a way to do this, please post it here!
_________________
Jen
Back to top
View user's profile Send private message
ftack
Moderator
Moderator


Joined: 27 Jan 2003
Posts: 3102
Location: Belgium

PostPosted: Tue Jun 22, 2004 11:43 am    Post subject: Reply with quote

Very well observed! I do not have the habit of dragging (and besides, I enter my captions manually) and therefore I never bumped into that issue. It is strange that that issue is set with a status "Enhancement". This is, If you ask me, a prime example of "a bug".
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group