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

How to assign paragraph style to a level in writer?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Rookie
Guest





PostPosted: Mon Jun 28, 2004 2:51 am    Post subject: How to assign paragraph style to a level in writer? Reply with quote

Hi all,

I want to assign a paragraph style to a level using Java, I have two question about this

1) How do I know which style was assigned to a numbering level?

2) How to assign a style to a numbering level?

I have read through http://api.openoffice.org/docs/DevelopersGuide/Text/Text.htm#1+4+3+Line+Numbering+and+Outline+Numbering about paragraph and outline number. It introduce a service called "NumberingLevel" and I think this service may be useful. But it seems that it don't have any property to set the paragraph style for a level.

Can anyone help me? Thanks for any help!

Rookie
Back to top
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3152
Location: Columbus, Ohio, USA

PostPosted: Mon Jun 28, 2004 11:55 am    Post subject: Reply with quote

Although I do not know the answer to your question, I do know that the outline numbering things are NOT set by the paragraph. At least I do not think that they are. If you run the following macro, it will provide you an idea as to the type of information saved in the numbering. On my single check, the last value contained the style used to format the levels. I did very little testing on this, but I suspect that if you change the paragraph style names, then you can change which paragraphs corresponding to which outline numbering. Be sure to post your final conclusions and I hope that this points you in the correct direction.

Code:
Sub checkNumbering
  Dim x
  Dim i%
  Dim s$
  Dim oRules
  oRules = ThisComponent.getChapterNumberingRules()
  x = oRules().getByIndex(1)
  'Inspect(ThisComponent.getChapterNumberingRules().getByIndex(1))
  For i=LBound(x) To UBound(x)
    s = s & x(i).Name & CHR$(10)
  Next
  MsgBox s, 0, "Values in first rule"
  For i=0 To oRules.getCount()-1
    x = oRules.getByIndex(i)
    s = s & x(Ubound(x)).Value & CHR$(10)
  Next
  MsgBox s, 0, "Last property in each rule"
 
  'Print "Count = " & ThisComponent.getChapterNumberingRules().getCount()
  'Print "Name = " & ThisComponent.getChapterNumberingRules().getName()
'getDefaultOutlineNumberings
End Sub

_________________
--
Andrew Pitonyak
My Document: http://www.pitonyak.org/AndrewMacro.odt
Free Info: http://www.pitonyak.org/oo.php
Most hated bug: http://www.openoffice.org/issues/show_bug.cgi?id=84159
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Guest






PostPosted: Mon Jun 28, 2004 4:31 pm    Post subject: Reply with quote

Thank you very much pitonyak! That's exactly what I need.

The last property value can be used to format the level. Here is my Java coding

To display the heading corresponding to which outline numbering:

Code:
      // lxTextDocument is my document that queried as XTextDocument Interface
      XChapterNumberingSupplier xChapterNumberingSupplier = QIUtility.xChapterNumberingSupplier(lxTextDocument);
      
        // Get the ChapterNumberingRule's XIndexReplace interface
        XIndexReplace xReplace = xChapterNumberingSupplier.getChapterNumberingRules();
      
        // Loop through each level
        for (int i = 0; i < xReplace.getCount(); i++){
           
         PropertyValue[] aProps = (PropertyValue[]) xReplace.getByIndex(i);
         
         // Loop through each property value
         for (int s = 0;s< aProps.length; s++){
            
            if (aProps[s].Name.equals("HeadingStyleName")){
                System.out.println(aProps[s].Value);
            }
            
         }
      }


To change the heading corresponding to the first outline numbering (Default is Heading 1):

Code:
      XChapterNumberingSupplier xChapterNumberingSupplier = QIUtility.xChapterNumberingSupplier(lxTextDocument);
      
        // Get the ChapterNumberingRule's XIndexReplace interface
        XIndexReplace xReplace = xChapterNumberingSupplier.getChapterNumberingRules();
      
        // Loop through each level
        for (int i = 0; i < xReplace.getCount(); i++){
           
         PropertyValue[] aProps = (PropertyValue[]) xReplace.getByIndex(i);
         
         // Loop through each property value
         for (int s = 0;s< aProps.length; s++){
            
            if (aProps[s].Name.equals("HeadingStyleName")){
               
                if (i == 0){
                    aProps[s].Value = "Caption";
                     xReplace.replaceByIndex(i, aProps);
                }
               
                System.out.println(aProps[s].Value);
            }
            
         }
      }
         
Back to top
Rookie
Guest





PostPosted: Mon Jun 28, 2004 5:12 pm    Post subject: Reply with quote

One more question, do you know how to get the "evaluate up to level" value in the insert index/table dialog?

I try to print it by the following code, it always print "10", no matter how I adjust the value

Code:
      XInterface xTocInterface = (XInterface)lmsf.createInstance("com.sun.star.text.ContentIndex");
      XDocumentIndex xDocIndex = (XDocumentIndex)UnoRuntime.queryInterface(XDocumentIndex.class, xTocInterface);

      XPropertySet pSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDocIndex);
      System.out.println("Total number of level " + pSet.getPropertyValue("Level").toString());
Back to top
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3152
Location: Columbus, Ohio, USA

PostPosted: Mon Jun 28, 2004 6:02 pm    Post subject: Reply with quote

I noticed a few things. First, all of the properties are considered optional. I assume that the value is always 10 because you are creating a new one and perhaps you need to obtain a reference to an existng one. This is a guess, and only a guess because I have not attempted to do anything with this... I did notice that the LevelParagraphStyles property returns the levels that are used to generate the index. Hmmmm....

The base service is http://api.openoffice.org/docs/common/ref/com/sun/star/text/BaseIndex.html

I suspect that what you want to do, is to use getDocumentIndexes() to obtain the desired index. You can then modify the Level of the existing object. Otherwise, you are changing the value of a new one rather than on an existing index.
Code:
Sub findIndex()
  Dim oIndexes
  Dim oIndex
  Dim i As Integer
  Dim bIndexFound As Boolean
  oIndexes = ThisComponent.getDocumentIndexes()
'  Inspect()
  MsgBox Join(oIndexes.getElementNames(), CHR$(10)), 0, "Index Names"
  Print "Number of indexes = " & oIndexes.getCount()
  bIndexFound = False
  For i = 0 To oIndexes.getCount() - 1
    oIndex = oIndexes.getByIndex(i)
    If oIndex.supportsService("com.sun.star.text.ContentIndex") Then
      bIndexFound = True
      REM Set the level here on the existing content index
      REM oIndex.Level = 10
    End If
    If Not bIndexFound Then
      Print "I did not find an existing content index"
      REM Perhaps you should create and insert a new one!
    End If
  Next
End Sub

_________________
--
Andrew Pitonyak
My Document: http://www.pitonyak.org/AndrewMacro.odt
Free Info: http://www.pitonyak.org/oo.php
Most hated bug: http://www.openoffice.org/issues/show_bug.cgi?id=84159
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Angellina
OOo Enthusiast
OOo Enthusiast


Joined: 28 May 2004
Posts: 130
Location: France - Paris

PostPosted: Tue Jul 13, 2004 1:23 am    Post subject: Reply with quote

hello,
I have a problem similar to this one, when I insert an index with this sub:
Sub InsertATOC()

oIndexes = ThisComponent.getDocumentIndexes()
bIndexFound = False
For i = 0 To oIndexes.getCount() - 1
oIndex = oIndexes.getByIndex(i)
If oIndex.supportsService("com.sun.star.text.ContentIndex") Then
bIndexFound = True
Exit For
End If
Next

If Not bIndexFound Then
Print "I did not find an existing content index"
REM Perhaps you should create and insert a new one!
REM Notice that this MUST be created by the document that will contain
REM the index.
oIndex = ThisComponent.createInstance("com.sun.star.text.ContentIndex")

REM On my system, these are the default values
REM How do you want to create the index?
REM CreateFromChapter = False
REM CreateFromLevelParagraphStyles = False
REM CreateFromMarks = True
REM CreateFromOutline = False
with oIndex
.CreateFromOutline = True
.CreateFromLevelParagraphStyles = True
.Title= "Sommaire"
.ParaStyleLevel1= "Partie"
.ParaStyleLevel2= "Titre 1"
.ParaStyleLevel3= "Titre 2"
.IsProtected= false
end with

REM You can set all sorts of other things such as the
REM Title or Level

' oCurs = ThisComponent.getText().createTextCursor()
oCurs= thisComponent.getCurrentController().getViewCursor()

' oCurs.gotoStart(False)
'il faut un saut de ligne
saut_de_ligne
ThisComponent.getText().insertTextContent(oCurs, oIndex, False)
End If

REM Even the newly inserted index is not updated until right HERE!
oIndex.update()

End Sub
I obtain an index like this:

Sommaire
Partie ......................... 3
Chapitre ..........................4
Module ......................... 4

THEY ARE ALL ALLIGNED ALTHAUGH I'VE PRECISED LEVEL1, LEVEL2 AND LEVEL3
WHY I DON'T OBTAIN:
Sommaire
Partie ......................... 3
Chapitre ..........................4
Module ......................... 4

I don't know if I must worgk with NumberingRules() or NumberingLevel which I cannot understand!!!
Back to top
View user's profile Send private message
Angellina
OOo Enthusiast
OOo Enthusiast


Joined: 28 May 2004
Posts: 130
Location: France - Paris

PostPosted: Tue Jul 13, 2004 1:26 am    Post subject: Reply with quote

sorry, I mean:

Sommaire
Partie 3
Chapitre 4
Module 4
(like stairs)
Back to top
View user's profile Send private message
Angellina
OOo Enthusiast
OOo Enthusiast


Joined: 28 May 2004
Posts: 130
Location: France - Paris

PostPosted: Tue Jul 13, 2004 7:58 am    Post subject: Reply with quote

can someone help me please?

How can I manipulate the paragraph level property Question
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 Macros and API 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