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

[SOLVED] Redline information based on cursor position

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


Joined: 19 Oct 2011
Posts: 32
Location: Harrisburg, Pa

PostPosted: Thu May 10, 2012 6:51 am    Post subject: [SOLVED] Redline information based on cursor position Reply with quote

Is there anyway to retrieve redline information based on where the cursor is. For example, whether selected text is in fact a redline and if so what type of redline?

Project: I am searching a document for invalid characters (everything above chr 128), when I replace the character in the document I need the new character to retain the redline type if it existed prior. So if the invalid character was deleted, then the new character must also display as deleted.

Thanks.


Last edited by lknoll on Thu May 24, 2012 5:29 am; edited 1 time in total
Back to top
View user's profile Send private message
lknoll
General User
General User


Joined: 19 Oct 2011
Posts: 32
Location: Harrisburg, Pa

PostPosted: Thu May 10, 2012 12:25 pm    Post subject: Reply with quote

This was a mess. If anyone finds a better solution please post. Thanks.

To get around the problem stated I:
1. find the total number of Inserts and Deletes in the document
2. Reject changes where the cursor sit
3. Find the new total for Inserts and Deletes.

This will find the redline information, unforntunately when rejecting the change, you will loose the cursor information on inserts. To get around this I had to insert bookmarks. Ugly stuff, but it works.

Code:

Sub FindHighAscii

   Dim oDoc As Object
   oDoc = ThisComponent
   oVC  = oDoc.CurrentController.getViewCursor()
   
   charUpTo128 = "^\x00-\x7F"
   'chr(160) = non breaking space; chr(167) = section symbol
   omitList = ",^\" & chr(160) & ",^\" & chr(167)
   regex = "[" & charUpTo128 & omitList & "]"
   
   oDescriptor = oDoc.createSearchDescriptor()
   oDescriptor.SearchAll = true
   oDescriptor.SearchRegularExpression = true
   oDescriptor.SearchCaseSensitive = false
   oDescriptor.SearchWords = true
   oDescriptor.SearchString = regex
   oFoundAll = oDoc.findAll(oDescriptor)
   
   Total = oFoundAll.getCount()
   
   'Insert bookmarks to set initial positions
   For i=0 to Total-1
      oFound = oFoundAll.getByIndex(i)
      oVC.gotoRange(oFound, false)
      selection = fixRedlineEnds(oDoc, oVC.Start, oVC.End)
      oVC.goToRange(selection(0), false)
      insertBookmark("temp_" & i)
   next i
   
   oRedLines = oDoc.Redlines
    Counter = 0
   
   'Loop through search results
   For i=0 to Total-1
      
      'returns the total number of ADDS and DELETES. [0] = Add; [1] = Delete
       RlTypeCountsArr = RlTypeCounts(oRedLines)   
      RlStartAdds = RlTypeCountsArr(0)
      RlStartDeletes = RlTypeCountsArr(1)
      
      Bookmark = oDoc.Bookmarks.getByName("temp_" & i)
      psn = Bookmark.Anchor
      oVC.gotorange(psn, False)      
      CounterText = Counter+1 & " of " & oFoundAll.getCount()
      Counter = Counter + 1
      
      'Reject the change tracking
      rejectChange(oDoc)
      
      RlTypeCountsArr = RlTypeCounts(oRedLines)   
      RlAdds = RlTypeCountsArr(0)
      RlDeletes = RlTypeCountsArr(1)
   
      if RlAdds <> RlStartAdds then
         action = "Insert"
      elseif RlDeletes <> RlStartDeletes then
         action = "Delete"
      else
         action = "None"
      end if
      
      if action <> "None" then
         'Undo the reject change if applicable
         docUndo(oDoc, 1)
      end if
      ''''''''''''''''''''''
      
      Bookmark = oDoc.Bookmarks.getByName("temp_" & i)
      psn = Bookmark.Anchor
      Bookmark.dispose()
      
      oVC.gotorange(psn, false)      
      oVC.goRight(1, true)
      'Cursor still ends up on the wrong side for some chars (chr(153)).
      if asc(getString()) < 128 then
         oVC.gotorange(psn, false)      
         oVC.goLeft(1, true)
      end if
      
      if asc(getString()) >= 128 then
         OpenReplaceDialog(currentSelection, action, CounterText)
      end if
   next i
   
   if found = true then
      writeLog("User has been alerted to a high ascii value in the document")
   end if
   
End Sub
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