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

text fields and master fields

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


Joined: 23 Feb 2005
Posts: 152

PostPosted: Fri Apr 01, 2005 4:42 am    Post subject: text fields and master fields Reply with quote

Hi! If I had this code

Code:

Sub InsertFieldMaster

      Dim oMasters, oText, oUField, oMField, oDoc, oMasterField as Object
      Dim sLead$, sName$, sTotname$

   sName = "testfield"
   sLead = "com.sun.star.text.FieldMaster.User"
   sTotName = sLead & "." & sName
   oDoc = ThisComponent
   oText = oDoc.Text
   oMasters = oDoc.getTextFieldMasters()

         oUField = oDoc.createInstance("com.sun.star.text.TextField.User")
   oMasterField = oDoc.createInstance(sLead)
   oMasterField.Name = sName
   oMasterField.Content = "ENUN"
   oUField.attachTextFieldMaster(oMasterField)
   oText.insertTextContent(oText.getEnd(), oUField, False)
   
       End If   

End Sub



Could i possibly insert the conetnt of a masterfield as much as I want in my document without having to recreate another name for it?Tnx
_________________
codebits... Smile
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Fri Apr 01, 2005 12:58 pm    Post subject: Reply with quote

Would you believe me if I said no Laughing
Code:
Sub InsertFieldMaster
  REM You declare a bunch of varients and one Object. odd!
  REM I will declare them all as varient.
  REM Dim oMasters, oText, oUField, oMField, oDoc, oMasterField as Object
  Dim oMasters, oText, oUField, oMField, oDoc, oMasterField
  Dim sLead$, sName$, sTotname$

  sName = "testfield"
  sLead = "com.sun.star.text.FieldMaster.User"
  sTotName = sLead & "." & sName
  oDoc = ThisComponent
  oText = oDoc.Text
  oMasters = oDoc.getTextFieldMasters()
  oUField = oDoc.createInstance("com.sun.star.text.TextField.User")
  oMasterField = oDoc.createInstance(sLead)
  oMasterField.Name = sName
  oMasterField.Content = "ENUN"
  oUField.attachTextFieldMaster(oMasterField)
  oText.insertTextContent(oText.getEnd(), oUField, False)

  oUField = oDoc.createInstance("com.sun.star.text.TextField.User")
  oUField.attachTextFieldMaster(oMasterField)
  oText.insertTextContent(oText.getStart(), oUField, False)
End Sub

_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
jelaih
OOo Enthusiast
OOo Enthusiast


Joined: 23 Feb 2005
Posts: 152

PostPosted: Sun Apr 03, 2005 10:29 pm    Post subject: Reply with quote

really? I got that piece of code form your book and tried to modified some things, I just want to try if I could insert lots of field codes wihout renaming my master field, I just felt there is still a way... Smile tnx
_________________
codebits... Smile
Back to top
View user's profile Send private message
jelaih
OOo Enthusiast
OOo Enthusiast


Joined: 23 Feb 2005
Posts: 152

PostPosted: Sun Apr 03, 2005 10:47 pm    Post subject: Reply with quote

your code works fine It simultaneously prints the field code but once I run the macro again...it give an error in these part

Code:

oMasterField.Name = sName


But once I recreate another name for the masterfield, It works fine again...but the way...Could i create text cursors while running a macro? Just thinking...tnx
_________________
codebits... Smile
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Mon Apr 04, 2005 6:31 am    Post subject: Reply with quote

Quote:
your code works fine It simultaneously prints the field code but once I run the macro again...it give an error in these part

Yes, because the master field already exists. Do not try to create it if it already exists...

You mention that you have my book. Notice that on pages 319-320 and Listing 49, I use hasByName() to see if a specific master field already exists. Perhaps even better, page 322 Listing 51, I create a master field if it does not exist. If it does exist, I either use it or delete it...


Quote:
Could i create text cursors while running a macro? Just thinking...tnx

yes, of course. What do you want to do with the text cursor?
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
jelaih
OOo Enthusiast
OOo Enthusiast


Joined: 23 Feb 2005
Posts: 152

PostPosted: Tue Apr 05, 2005 1:28 am    Post subject: Reply with quote

nice... Smile I have tested your code and its what I want to do.

I had these code and what is does is it keeps on inserting the field code to where my physical cursor is in the document, assuming that is has already master field named "testing". It can't add a masterfield is just uses the masterfield that is available evryting you run it


Code:

Sub Again

  Dim oDoc, oText
  Dim oField
  Dim oUField as Object
  Dim oViewCursor

  oDoc = ThisComponent
  oText = oDoc.getText()


  oViewCursor = oDoc.CurrentController.getViewCursor()

  If Doc.getTextFieldMasters().hasByName("com.sun.star.text.FieldMaster.User.testing") Then
    oField = oDoc.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User.testing")
    oField.Content = "ENUN"
  End If
   
   oUField = oDoc.createInstance("com.sun.star.text.TextField.User")
   oUField.attachTextFieldMaster(oField)   
   oText.insertTextContent(oViewCursor, oUField, False)
   
End Sub


My observation..I cannot run the physical cursors through the field code...It means I could not edit the content of my field code in the document, instead, I should edit it in a dialog form that pops once I doubled clicked it...Was that really the situation?

I was thinking of creating a textcursor at run time and scans through the paragraphs which is between the field codes that i will be creating. The Starting field codes and the ending field codes will be the boundary of my textcursor.
_________________
codebits... Smile
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Tue Apr 05, 2005 4:58 am    Post subject: Reply with quote

Quote:
My observation..I cannot run the physical cursors through the field code...It means I could not edit the content of my field code in the document, instead, I should edit it in a dialog form that pops once I doubled clicked it...Was that really the situation?.

You are correct, you can not edit a text field inline.
Quote:
I was thinking of creating a textcursor at run time and scans through the paragraphs which is between the field codes that i will be creating. The Starting field codes and the ending field codes will be the boundary of my textcursor.
Yes, you can do this. I have used a similar technique to find text fields and other text content in the current paragraph.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
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