Search and Replace in a Drawing Document crashing...

Creating a macro - Writing a Script - Using the API

Search and Replace in a Drawing Document crashing...

Postby swingkyd » Sat Jan 05, 2008 9:48 pm

A few things to note which appear to be bugs to me. For a DrawingDocument:
  1. The XSearchable interface provides the createSearchDescriptor() method. This interface can only be created with a DrawPage (not the Draw document). After creation of the search descriptor:
    • if the findFirst method is called and the created search string is not found, the application crashes.
    • If the findFirst method is called and the created search string is found, the application returns not the string, but the interface: ::com::sun::star::uno::XInterface of the object found. If one were to xray this object, (mine are just text boxes) then the following string is found: "resent=" (because I have "Mitigated{CR}Ipresent=$LEVkA" as my string and {CR} is actually a newline or carriage return). I would have expected the string to be "present" and not "resent=".... note this for the next comment
  2. The XReplaceable interface provides the createReplaceDescriptor() method. This interface is created with the DrawPage as well. After creation of both the replaceDescriptor and the searchDescriptor:
    • The replaceAll method can be called. I have not checked if it crashes on not finding anything yet.
    • The replaceAll method replaces the text SHIFTED by one character to the right for me. That is, it replaces the "resent=" text with "myreplace". For example, if I'm replacing "Mitigated" with "Unmitigated" in the text box string "Mitigated{CR}Ipresent=$LEVkA", the result is UnmitigatedIpresent=$LEVkA"... the {CR} gets overwritten!!!! not good!
So, are these bugs or am I totally missing something? If they are bugs, I guess I'll file a bug report.

The following code snips are the drivers used to test these bugs:
make sure you have the following text in a textbox and replace the {CR} with a return on your keyboard:
Mitigated{CR}Ipresent=$LEVkA

here is the code for the replaceAll method call
Code: Select all   Expand viewCollapse view
sub driveSearch1
  Dim oDoc    As Object
  Dim oDrawPages   As Object
  Dim oDrawPage      As Object
  Dim oReplaceDesc   As Object

  oDoc = thisComponent
  oDrawPages    = oDoc.getDrawPages()
  oDrawPage    = oDrawPages.getByIndex(0)

  oReplaceDesc   = oDrawPage.createReplaceDescriptor
  oReplaceDesc.searchString    = "Mitigated"
  oReplaceDesc.replaceString    = "Unmitigated"
  oReplaceDesc.SearchCaseSensitive = false
  oReplaceDesc.SearchWords = true
  oDrawPage.replaceAll(oReplaceDesc)
end sub



Finally the ugly crash one:
Code: Select all   Expand viewCollapse view
sub driveSearch2
  Dim oDoc    As Object
  Dim oDrawPages   As Object
  Dim oDrawPage      As Object
  Dim sMyResult      As Object
  Dim oFound      As Object   ' object which was found to test
  oDoc = thisComponent
  oDrawPages    = oDoc.getDrawPages()
  oDrawPage    = oDrawPages.getByIndex(0)
  oSearchDesc   = oDrawPage.createSearchDescriptor
  oSearchDesc.searchString = "Present"
' crash here at this next line. put a stop on this line and step into it.
  oFound   = oDrawPage.findFirst(oSearchDesc)
end sub

note: this was also posted in the old forum...i hope that's OK
swingkyd
 
Posts: 24
Joined: Sat Jan 05, 2008 8:31 pm

Re: Search and Replace in a Drawing Document crashing...

Postby hol.sten » Sun Jan 13, 2008 1:24 am

swingkyd wrote:So, are these bugs or am I totally missing something? If they are bugs, I guess I'll file a bug report.

Is your problem related to the problem described in this thread:
- Why Search and Replace doesn't work on all Text? http://www.oooforum.org/forum/viewtopic.phtml?t=59175&highlight=search+replace+drawing+document

Regards
hol.sten
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: Google [Bot] and 5 guests