1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Helpers" script:language="StarBasic">' *** MODULE HELPERS *** 24 25'======================================================= 26' Main 27'------------------------------------------------------- 28' Ensure that necessary library functions are available 29'======================================================= 30Sub Main 31 GlobalScope.BasicLibraries.loadLibrary("Tools") 32End Sub 33 34'======================================================= 35' ShowProp 36'------------------------------------------------------- 37' Displays a dialog that shows the properties and 38' the methods of an object. Used for debugging. 39'======================================================= 40Sub ShowProp(Elem As Object) 41 dim oDialog As Object 42 43 BasicLibraries.LoadLibrary("HelpAuthoring") 44 oDialog = LoadDialog("HelpAuthoring", "dlgObjProp") 45 oDialogModel = oDialog.Model 46 47 oTxtProp = oDialog.GetControl("txtProp") 48 oTxtProp.Text = Join(Split(Elem.dbg_properties,";"),chr(13)) 49 50 oTxtMeth = oDialog.GetControl("txtMeth") 51 oTxtMeth.Text = Join(Split(Elem.dbg_methods,";"),chr(13)) 52 53 oTxtInt = oDialog.GetControl("txtInt") 54 oTxtInt.Text = Join(Split(Elem.dbg_supportedInterfaces,";"),chr(13)) 55 56 oDialog.Execute() 57 oDialog.dispose 58End Sub 59 60'======================================================= 61' AlphaNum 62'------------------------------------------------------- 63' Removes all invalid characters from a string 64'======================================================= 65Function AlphaNum(Strg As String) 66 dim OutStrg As String 67 dim sValid As String 68 69 sValid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789" 70 71 For i=1 to Len(Strg) 72 If (Instr(sValid,LCase(Mid(Strg,i,1)))) Then 73 OutStrg = OutStrg + Mid(Strg,i,1) 74 End If 75 Next i 76 AlphaNum = OutStrg 77End Function 78 79'======================================================= 80' Replace 81'------------------------------------------------------- 82' Replaces a character with another character in a string 83'======================================================= 84Function Replace(txt As String, ReplaceFrom As String, ReplaceTo As String) 85 dim OutStr As String 86 For i=1 to len(txt) 87 If LCase(mid(txt,i,1))=ReplaceFrom Then 88 OutStr = OutStr + ReplaceTo 89 Else 90 OutStr = OutStr + mid(txt,i,1) 91 End If 92 Next i 93 Replace = OutStr 94End Function 95 96 97'======================================================= 98' ReplaceAll 99'------------------------------------------------------- 100' Replaces a character with another character in a string 101'======================================================= 102Function ReplaceAll(txt As String, ReplaceFrom As String, ReplaceTo As String) 103 dim OutStr As String 104 For i=1 to len(txt) 105 bFound = 0 106 For j=1 to len(ReplaceFrom) 107 If LCase(mid(txt,i,1))=LCase(mid(ReplaceFrom,j,1)) Then 108 bFound = 1 109 OutStr = OutStr + ReplaceTo 110 j = len(ReplaceFrom) 111 End If 112 Next j 113 If bFound=0 Then 114 OutStr = OutStr + mid(txt,i,1) 115 End If 116 Next i 117 ReplaceAll = OutStr 118End Function 119 120 121 122'======================================================= 123' CreateID 124'------------------------------------------------------- 125' Creates a numerical randomized ID 126'======================================================= 127Function CreateID 128 sDate = ReplaceAll(Date,"/:. \","") 129 sTime = ReplaceAll(Time,"/:. \AMP","") 130 Randomize 131 CreateID = sDate + sTime + Int(Rnd * 100) 132End Function 133 134'======================================================= 135' InsertTag 136'------------------------------------------------------- 137' Inserts an inline tag (element) in the document at the 138' current cursor position. It also sets the character 139' format to hlp_aux_tag 140'======================================================= 141Sub InsertTag (Element As String, Content As String) 142 dim document as object 143 dim dispatcher as object 144 145 document = ThisComponent.CurrentController.Frame 146 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 147 148 dim args(5) as new com.sun.star.beans.PropertyValue 149 args(0).Name = "Type" 150 args(0).Value = 8 151 args(1).Name = "SubType" 152 args(1).Value = 1 153 args(2).Name = "Name" 154 args(2).Value = Element 155 args(3).Name = "Content" 156 args(3).Value = Content 157 args(4).Name = "Format" 158 args(4).Value = -1 159 args(5).Name = "Separator" 160 args(5).Value = " " 161 SetCharStyle("hlp_aux_tag") 162 dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args()) 163 SetCharStyle("Default") 164End Sub 165 166'======================================================= 167' INSERTTAGCR 168'------------------------------------------------------- 169' Inserts a tag (element) in the document at the 170' current cursor position in its own newly created paragraph. 171' It also sets the character format to hlp_aux_tag and 172' the paragraph to the specified value (should start with hlp_) 173'======================================================= 174Sub InsertTagCR (Element As String, Content As String, Style As String) 175 dim document as object 176 dim dispatcher as object 177 178 document = ThisComponent.CurrentController.Frame 179 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 180 181 dim args(5) as new com.sun.star.beans.PropertyValue 182 args(0).Name = "Type" 183 args(0).Value = 8 184 args(1).Name = "SubType" 185 args(1).Value = 1 186 args(2).Name = "Name" 187 args(2).Value = Element 188 args(3).Name = "Content" 189 args(3).Value = Content 190 args(4).Name = "Format" 191 args(4).Value = -1 192 args(5).Name = "Separator" 193 args(5).Value = " " 194 195 CR 196 goUp(1) 197 SetParaStyle(Style) 198 SetCharStyle("hlp_aux_tag") 199 dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args()) 200 SetCharStyle("Default") 201 goDown(1) 202End Sub 203 204'======================================================= 205' InsertField 206'------------------------------------------------------- 207' Inserts a field in the document at the 208' current cursor position. 209'======================================================= 210Sub InsertField(Field as String, Content as String) 211 dim document as object 212 dim dispatcher as object 213 214 document = ThisComponent.CurrentController.Frame 215 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 216 217 dim args(5) as new com.sun.star.beans.PropertyValue 218 args(0).Name = "Type" 219 args(0).Value = 8 220 args(1).Name = "SubType" 221 args(1).Value = 1 222 args(2).Name = "Name" 223 args(2).Value = Field 224 args(3).Name = "Content" 225 args(3).Value = Content 226 args(4).Name = "Format" 227 args(4).Value = -1 228 args(5).Name = "Separator" 229 args(5).Value = " " 230 231 dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args()) 232End Sub 233 234'======================================================= 235' GoUp 236'------------------------------------------------------- 237' Simulates the CursorUp key 238'======================================================= 239Sub goUp(Count As Integer, Optional bSelect As Boolean) 240 dim document as object 241 dim dispatcher as object 242 243 document = ThisComponent.CurrentController.Frame 244 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 245 246 dim args(1) as new com.sun.star.beans.PropertyValue 247 args(0).Name = "Count" 248 args(0).Value = Count 249 args(1).Name = "Select" 250 If IsMissing(bSelect) Then 251 args(1).Value = false 252 Else 253 args(1).Value = bSelect 254 End If 255 256 dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args()) 257End Sub 258 259'======================================================= 260' GoDown 261'------------------------------------------------------- 262' Simulates the CursorDown key 263'======================================================= 264Sub goDown(Count As Integer, Optional bSelect As Boolean) 265 dim document as object 266 dim dispatcher as object 267 268 document = ThisComponent.CurrentController.Frame 269 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 270 271 dim args(1) as new com.sun.star.beans.PropertyValue 272 args(0).Name = "Count" 273 args(0).Value = Count 274 args(1).Name = "Select" 275 If IsMissing(bSelect) Then 276 args(1).Value = false 277 Else 278 args(1).Value = bSelect 279 End If 280 281 dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args()) 282End Sub 283 284 285'======================================================= 286' GoRight 287'------------------------------------------------------- 288' Simulates the CursorRight key 289'======================================================= 290Sub goRight(Count As Integer, Optional bSelect As Boolean) 291 dim document as object 292 dim dispatcher as object 293 294 document = ThisComponent.CurrentController.Frame 295 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 296 297 dim args(1) as new com.sun.star.beans.PropertyValue 298 args(0).Name = "Count" 299 args(0).Value = Count 300 args(1).Name = "Select" 301 If IsMissing(bSelect) Then 302 args(1).Value = false 303 Else 304 args(1).Value = bSelect 305 End If 306 307 dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args()) 308End Sub 309 310'======================================================= 311' GoLeft 312'------------------------------------------------------- 313' Simulates the CursorLeft key 314'======================================================= 315Sub goLeft(Count As Integer, optional bSelect As boolean) 316 dim document as object 317 dim dispatcher as object 318 319 document = ThisComponent.CurrentController.Frame 320 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 321 322 dim args(1) as new com.sun.star.beans.PropertyValue 323 args(0).Name = "Count" 324 args(0).Value = Count 325 args(1).Name = "Select" 326 If IsMissing(bSelect) Then 327 args(1).Value = false 328 Else 329 args(1).Value = bSelect 330 End If 331 332 dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args()) 333End Sub 334 335'======================================================= 336' CR 337'------------------------------------------------------- 338' Inserts a Carriage Return (a new paragraph) 339'======================================================= 340Sub CR 341 dim document as object 342 dim dispatcher as object 343 344 document = ThisComponent.CurrentController.Frame 345 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 346 347 oSel = thiscomponent.getcurrentcontroller.getselection 348 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 349 oCur.gotoEndOfParagraph(0) 350 thiscomponent.getcurrentcontroller.select(oCur) 351 352 dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array()) 353End Sub 354 355'======================================================= 356' CR_before 357'------------------------------------------------------- 358' Inserts a Carriage Return (a new paragraph) before the current para 359'======================================================= 360Sub CR_before 361 dim document as object 362 dim dispatcher as object 363 364 document = ThisComponent.CurrentController.Frame 365 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 366 367 oSel = thiscomponent.getcurrentcontroller.getselection 368 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 369 oCur.gotoStartOfParagraph(0) 370 thiscomponent.getcurrentcontroller.select(oCur) 371 372 dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array()) 373End Sub 374 375'======================================================= 376' LF 377'------------------------------------------------------- 378' Inserts a line feed (manual line break) 379'======================================================= 380sub LF 381 dim document as object 382 dim dispatcher as object 383 document = ThisComponent.CurrentController.Frame 384 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 385 386 dispatcher.executeDispatch(document, ".uno:InsertLinebreak", "", 0, Array()) 387end sub 388 389'======================================================= 390' SetParaStyle 391'------------------------------------------------------- 392' Sets the para style to the given value 393'======================================================= 394Sub SetParaStyle(StyleName As String) 395 dim document as object 396 dim dispatcher as object 397 398 document = ThisComponent.CurrentController.Frame 399 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 400 401 dim args(1) as new com.sun.star.beans.PropertyValue 402 args(0).Name = "Template" 403 args(0).Value = StyleName 404 args(1).Name = "Family" 405 args(1).Value = 2 406 407 dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args()) 408end Sub 409 410'======================================================= 411' SetCharStyle 412'------------------------------------------------------- 413' Sets the character style to the given value 414'======================================================= 415Sub SetCharStyle(StyleName As String) 416 dim document as object 417 dim dispatcher as object 418 419 document = ThisComponent.CurrentController.Frame 420 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 421 422 dim args(1) as new com.sun.star.beans.PropertyValue 423 args(0).Name = "Template" 424 args(0).Value = StyleName 425 args(1).Name = "Family" 426 args(1).Value = 1 427 428 dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args()) 429end Sub 430 431'======================================================= 432' InsertNewParaData 433'------------------------------------------------------- 434' Inserts a new ID for the paragraph 435'======================================================= 436Sub InsertNewParaData 437 438 If not IsHelpFile Then 439 msgbox(strErr_NoHelpFile) 440 Exit Sub 441 End If 442 443 oSel = thiscomponent.getcurrentcontroller.getselection 444 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 445 446 arParaData = GetParaData 447 sID = arParaData(0) 448 slocalize = arParaData(1) 449 sMsg = arParaData(2) 450 451 If sMsg <> "" Then 452 msgbox "Cannot assign paragraph id:"+chr(13)+sMsg,48,"Error" 453 Exit Sub 454 End If 455 456 If sID <> "" Then 457 msgbox "Paragraph already has an ID."+chr(13)+"If you want to assign a new ID delete the existing one first.",48,"Error" 458 Exit Sub 459 End If 460 461 oCur.gotoStartOfParagraph(0) 462 463 If (Left(oCur.ParaStyleName,8) = "hlp_head") Then 464 id = "hd_id" + CreateID 465 thiscomponent.getcurrentcontroller.select(oCur) 466 MetaData = id 467 SetCharStyle("hlp_aux_parachanged") 468 InsertField("ID",MetaData) 469 SetCharStyle("Default") 470 Else 471 id = "par_id" + CreateID 472 thiscomponent.getcurrentcontroller.select(oCur) 473 MetaData = id 474 SetCharStyle("hlp_aux_parachanged") 475 InsertField("ID",MetaData) 476 SetCharStyle("Default") 477 End If 478 479 480End Sub 481 482'======================================================= 483' LoadDialog 484'------------------------------------------------------- 485' Loads a BASIC dialog 486'======================================================= 487Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer) 488 Dim oLib as Object 489 Dim oLibDialog as Object 490 Dim oRuntimeDialog as Object 491 492 If IsMissing(oLibContainer ) then 493 oLibContainer = DialogLibraries 494 End If 495 496 oLibContainer.LoadLibrary(LibName) 497 oLib = oLibContainer.GetByName(Libname) 498 oLibDialog = oLib.GetByName(DialogName) 499 oRuntimeDialog = CreateUnoDialog(oLibDialog) 500 LoadDialog() = oRuntimeDialog 501End Function 502 503'======================================================= 504' Surprise 505'------------------------------------------------------- 506' D'oh 507'======================================================= 508Sub Surprise 509 msgbox "This function is unsupported."+chr(13)+"If you know how to implement this -- go ahead!",0,"D'oh!" 510End Sub 511 512'======================================================= 513' InsertNote 514'------------------------------------------------------- 515' Inserts a note (annotation) at the current position 516'======================================================= 517sub InsertNote(Content As String) 518 dim document as object 519 dim dispatcher as object 520 521 document = ThisComponent.CurrentController.Frame 522 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 523 524 dim args(2) as new com.sun.star.beans.PropertyValue 525 args(0).Name = "Text" 526 args(0).Value = Content 527 args(1).Name = "Author" 528 args(1).Value = "Help Tooling - DO NOT EDIT" 529 args(2).Name = "Date" 530 args(2).Value = "02/27/2004" 531 532 dispatcher.executeDispatch(document, ".uno:InsertAnnotation", "", 0, args()) 533end sub 534 535'======================================================= 536' InsertText 537'------------------------------------------------------- 538' Inserts a string at the current position 539'======================================================= 540Sub InsertText(strg As String) 541 oSel = thiscomponent.getcurrentcontroller.getselection 542 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 543 oCur.String = strg 544End Sub 545 546'======================================================= 547' ParaIsEmpty 548'------------------------------------------------------- 549' Evaluates if a paragraph is empty. 550'======================================================= 551Function ParaIsEmpty 552 oSel = thiscomponent.getcurrentcontroller.getselection 553 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 554 oCur.gotoStartOfParagraph(0) 555 ParaIsEmpty = oCur.IsEndOfParagraph 556End Function 557 558'======================================================= 559' IsInBookmark 560'------------------------------------------------------- 561' Evaluates if the cursor is inside a <bookmark> </bookmark> element 562'======================================================= 563Function IsInBookmark 564 oSel = thiscomponent.getcurrentcontroller.getselection 565 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 566 567 If ((oCur.ParaStyleName = "hlp_aux_bookmark") AND (not(oCur.IsEndOfParagraph))) Then 568 oCur.GotoStartOfParagraph(0) 569 oCur.GotoEndOfParagraph(1) 570 sText = Left(oCur.GetString,Instr(oCur.GetString,""" id=""")-1) 571 sText = Right(sText,Len(sText)-InStr(sText,"""")) 572 Select Case Left(sText,3) 573 Case "ind" 574 IsInBookmark = 1 575 Case "hid" 576 IsInBookmark = 2 577 Case "con" 578 IsInBookmark = 3 579 Case Else 580 IsInBookmark = 0 581 End Select 582 Else 583 IsInBookmark = 0 584 End If 585End Function 586 587'======================================================= 588' IsInTable 589'------------------------------------------------------- 590' Evaluates if the cursor is in a table 591'======================================================= 592Function IsInTable 593 oSel = thiscomponent.getcurrentcontroller.getselection 594 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 595 596 IsInTable = (VarType(oCur.TextTable) <> 0) 597End Function 598 599'======================================================= 600' InsertLink 601'------------------------------------------------------- 602' Inserts a hyperlink at the current position 603'======================================================= 604Sub InsertLink(sPath As String, sText As String, sName As String) 605 dim document as object 606 dim dispatcher as object 607 608 document = ThisComponent.CurrentController.Frame 609 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 610 611 dim args(4) as new com.sun.star.beans.PropertyValue 612 args(0).Name = "Hyperlink.Text" 613 args(0).Value = sText 614 args(1).Name = "Hyperlink.URL" 615 args(1).Value = sPath 616 args(2).Name = "Hyperlink.Target" 617 args(2).Value = "" 618 args(3).Name = "Hyperlink.Name" 619 args(3).Value = sName 620 args(4).Name = "Hyperlink.Type" 621 args(4).Value = 1 622 623 dispatcher.executeDispatch(document, ".uno:SetHyperlink", "", 0, args()) 624 args(0).Name = "Count" 625 args(0).Value = 1 626 args(1).Name = "Select" 627 args(1).Value = false 628 629 dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args()) 630 631End Sub 632 633'======================================================= 634' AssignMissingIDs 635'------------------------------------------------------- 636' Assigns IDs to elements that miss them 637'======================================================= 638Sub AssignMissingIDs 639' NOT IMPLEMENTED YET 640end sub 641 642'======================================================= 643' CreateTable 644'------------------------------------------------------- 645' Creates a new table 646'======================================================= 647Sub CreateTable(nRows as Integer, nCols as Integer, sID as String) 648 dim document as object 649 dim dispatcher as object 650 651 document = ThisComponent.CurrentController.Frame 652 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 653 654 dim args1(3) as new com.sun.star.beans.PropertyValue 655 args1(0).Name = "TableName" 656 args1(0).Value = sID 657 args1(1).Name = "Columns" 658 args1(1).Value = nCols 659 args1(2).Name = "Rows" 660 args1(2).Value = nRows 661 args1(3).Name = "Flags" 662 args1(3).Value = 9 663 664 dispatcher.executeDispatch(document, ".uno:InsertTable", "", 0, args1()) 665 666 args1(0).Name = "TopBottomMargin.TopMargin" 667 args1(0).Value = 500 668 args1(1).Name = "TopBottomMargin.BottomMargin" 669 args1(1).Value = 0 670 args1(2).Name = "TopBottomMargin.TopRelMargin" 671 args1(2).Value = 100 672 args1(3).Name = "TopBottomMargin.BottomRelMargin" 673 args1(3).Value = 100 674 675 dispatcher.executeDispatch(document, ".uno:TopBottomMargin", "", 0, args1()) 676 dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array()) 677 SetParaStyle("hlp_tablecontent") 678 GoDown(1) 679end Sub 680 681'======================================================= 682' IsBlockImage 683'------------------------------------------------------- 684' Evaluates if the cursor is in a paragraph with 685' a block image (image in its own paragraph) 686'======================================================= 687Function IsBlockImage 688 oSel = thiscomponent.getcurrentcontroller.getselection 689 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 690 oCur.gotoStartOfParagraph(0) 691 oCur.gotoEndOfParagraph(1) 692 sStr = Right(oCur.String,Len(oCur.String)-InStr(oCur.String," ")) 'string must start with <IMG and end with IMG with no <IMG in between 693 IsBlockImage = (not(Left(sStr,4)="IMG>") AND (Right(sStr,6)="</IMG>")) 694End Function 695 696'======================================================= 697' HasCaption 698'------------------------------------------------------- 699' Evaluates if the current image has a caption element 700'======================================================= 701Function HasCaption 702 oSel = thiscomponent.getcurrentcontroller.getselection 703 If oSel.ImplementationName = "SwXTextGraphicObject" Then 704 oCur = oSel(0).getAnchor.getText.createTextCursorByRange(oSel(0).getAnchor) 705 Else 706 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 707 End If 708 oCur.gotoStartOfParagraph(0) 709 oCur.gotoEndOfParagraph(1) 710 HasCaption = (InStr(oCur.String,"<IMGCAPTION")>0) 711End Function 712 713'======================================================= 714' GetImageID 715'------------------------------------------------------- 716' Returns the ID of an image at the cursor position 717'======================================================= 718Function GetImageID 719 oSel = thiscomponent.getcurrentcontroller.getselection 720 If oSel.ImplementationName = "SwXTextGraphicObject" Then 721 oCur = oSel(0).getAnchor.getText.createTextCursorByRange(oSel(0).getAnchor) 722 Else 723 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 724 End If 725 oCur.gotoStartOfParagraph(0) 726 oCur.gotoEndOfParagraph(1) 727 sStr = Right(oCur.String,Len(oCur.String)-(InStr(oCur.String,"IMG ID=""")+7)) 728 GetImageID = Left(sStr,InStr(sStr,""">")+1) 'string must start with <IMG and end with IMG with no <IMG in between 729End Function 730 731'======================================================= 732' SelAll 733'------------------------------------------------------- 734' Selects everything 735'======================================================= 736Sub SelAll 737 dim document as object 738 dim dispatcher as object 739 740 document = ThisComponent.CurrentController.Frame 741 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 742 743 dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array()) 744End Sub 745 746'======================================================= 747' GetParaData 748'------------------------------------------------------- 749' Returns the Paragraph ID and localization status 750'======================================================= 751Function GetParaData 752 arParaData = Array("","","") ' ID, localize, #message 753 754 oSel = thiscomponent.getcurrentcontroller.getselection 755 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 756 oCur.gotoStartOfParagraph(0) 757 oCur.gotoEndOfParagraph(1) 758 sID = "" 759 Enum = oCur.createEnumeration 760 Fd = FALSE 761 762 763 TE = Enum.nextElement 764 765 TP = TE.createEnumeration 766 Ct = 0 767 posID = 0 768 769 Do While TP.hasmoreElements 770 Ct = Ct+1 771 TPE = TP.nextElement 772 If TPE.TextPortionType="TextField" Then 773 If TPE.TextField.TextFieldMaster.Name="ID" Then 774 sID = TPE.TextField.Content 775 Fd = TRUE 776 Exit Do 777 End If 778 End If 779 If TPE.String = "" Then 780 Ct = Ct-1 781 End If 782 Loop 783 784 If ((Left(oCur.ParaStyleName,8) = "hlp_aux_") or (Left(oCur.ParaStyleName,4) <> "hlp_")) Then 785 arParaData(2)="Invalid Paragraph Style" 786 GetParaData = arParaData 787 Exit Function 788 End If 789 790 If sID = "" Then 791 GetParaData = arParaData 792 Exit Function 793 End If 794 795 If Right(sID,7) = "_NOL10N" Then 796 arParaData(0) = Left(sID,Len(sID)-7) 797 arParaData(1) = "no" 798 Else 799 arParaData(0) = sID 800 arParaData(1) = "yes" 801 End If 802 803 GetParaData = arParaData 804End Function 805 806'======================================================= 807' SetsParaData 808'------------------------------------------------------- 809' Sets the Paragraph ID and localization status 810'======================================================= 811 812Sub SetParaData(sID as String, sLocalize as String) 813 814 oSel = thiscomponent.getcurrentcontroller.getselection 815 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 816 oCur.gotoStartOfParagraph(0) 817 oCur.gotoEndOfParagraph(1) 818 Enum = oCur.createEnumeration 819 Fd = FALSE 820 821 822 Do While Enum.hasMoreElements 823 TE = Enum.nextElement 824 825 TP = TE.createEnumeration 826 Ct = 0 827 posID = 0 828 829 Do While TP.hasmoreElements 830 Ct = Ct+1 831 TPE = TP.nextElement 832 If TPE.TextPortionType="TextField" Then 833 If TPE.TextField.TextFieldMaster.Name="ID" Then 834 posID = Ct 835 If sLocalize = "no" Then 836 TPE.TextField.Content = sID+"_NOL10N" 837 TPE.TextField.IsVisible = TRUE 838 ElseIf sLocalize = "yes" Then 839 TPE.TextField.Content = sID 840 TPE.TextField.IsVisible = TRUE 841 Else 842 msgbox "Unknown localization parameter: "+sLocalize,0,"Error" 843 End If 844 Fd = TRUE 845 Exit Do 846 End If 847 End If 848 If TPE.String = "" Then 849 Ct = Ct-1 850 End If 851 Loop 852 If Fd Then 853 Exit Do 854 End If 855 Loop 856 857 oCur.TextField.update 858 UpdateFields 859 860End Sub 861 862 863'======================================================= 864' IsInList 865'------------------------------------------------------- 866' Evaluates if the cursor is inside a list (ordered or unordered) 867'======================================================= 868Function IsInList 869 oSel = thiscomponent.getcurrentcontroller.getselection 870 oCur = oSel(0).getText.createTextCursorByRange(oSel(0)) 871 If oCur.NumberingStyleName = "" Then 872 IsInList = false 873 ElseIf oCur.NumberingRules.NumberingIsOutline = true Then 874 IsInList = false 875 Else 876 IsInList = true 877 End If 878End Function 879 880'======================================================= 881' TagFormatIsCorrect 882'------------------------------------------------------- 883' Checks for correct paragraph format for tags 884'======================================================= 885Function TagFormatIsCorrect(sTN As String, sPS As String) 886 887 arTag = Array("BOOKMARK","SORT","SECTION","SWITCH","CASE","DEFAULT") 888 arTagFormat = Array("hlp_aux_bookmark","hlp_aux_sort","hlp_aux_section","hlp_aux_switch","hlp_aux_switch","hlp_aux_switch") 889 890 For n=0 to ubound(arTag) 891 If (sTN = arTag(n) AND sPS <> arTagFormat(n)) Then 892 TagFormatIsCorrect = arTagFormat(n) 893 Exit Function 894 End If 895 TagFormatIsCorrect = "" 896 Next n 897 898End Function 899 900'======================================================= 901' GetFilePath 902'------------------------------------------------------- 903' look for the "text/..." part of the file name and separate it 904'======================================================= 905Function GetFilePath(fname As String) 906 907 i = 1 908 Do 909 If (Mid(fname,i,5) = "text/") Then 910 Strg = Mid(fname,i,Len(fname)-i+1) 911 Exit Do 912 Else 913 i = i+1 914 Strg = fname 915 End If 916 Loop While (i+5 < Len(fname)) 917 GetFilePath = Strg 918End Function 919 920'======================================================= 921' OpenGraphics 922'------------------------------------------------------- 923' Calls the graphic open dialog for inserting an image 924'======================================================= 925Function OpenGraphics(oDoc As Object) 926Dim ListAny(0) as Long 927Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue 928 GlobalScope.BasicLibraries.loadLibrary("Tools") 929 ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE 930' ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE 931 oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker") 932 oFileDialog.Initialize(ListAny()) 933 934 sLastImgDir = ReadConfig("LastImgDir") 935 If sLastImgDir <> "" Then 936 oFileDialog.setDisplayDirectory(sLastImgDir) 937 End If 938 939 oMasterKey = GetRegistryKeyContent("org.openoffice.TypeDetection.Types/") 940 oTypes() = oMasterKey.Types 941 942 oFileDialog.AppendFilter(oTypes.GetByName("gif_Graphics_Interchange").UIName, "*.gif") 943 oFileDialog.AppendFilter(oTypes.GetByName("png_Portable_Network_Graphic").UIName, "*.png") 944 945 oFileDialog.SetTitle("Insert Image") 946 iAccept = oFileDialog.Execute() 947 If iAccept = 1 Then 948 sPath = oFileDialog.Files(0) 949 WriteConfig("LastImgDir",oFileDialog.getDisplayDirectory) 950 UIFilterName = oFileDialog.GetCurrentFilter() 951 OpenGraphics = oFileDialog.Files(0) 952 Else 953 OpenGraphics = "" 954 End If 955 oFileDialog.Dispose() 956End Function 957 958'======================================================= 959' WriteConfig 960'------------------------------------------------------- 961' Reads a parameter value from the config file 962'======================================================= 963Function ReadConfig(Parm As String) 964 oPath = createUNOService("com.sun.star.util.PathSettings") 965 filename = oPath.UserConfig+"/helpauthoring.cfg" 966 iNumber = Freefile 967 bFound = false 968 If FileExists(filename) Then 969 Open filename For Input As iNumber 970 Do While (not eof(iNumber) AND not(bFound)) 971 Line Input #iNumber, sLine 972 If InStr(sLine, "=") > 0 Then 973 arLine = split(sLine,"=") 974 If arLine(0) = Parm Then 975 sResult = arLine(1) 976 bFound = true 977 End If 978 End If 979 Loop 980 Close #iNumber 981 If bFound Then 982 ReadConfig = sResult 983 Else 984 ReadConfig = "" 985 End If 986 Else 987 ReadConfig = "" 988 End If 989End Function 990 991 992'======================================================= 993' WriteConfig 994'------------------------------------------------------- 995' Writes a parameter/value pair to the config file 996'======================================================= 997Function WriteConfig(Parm As String, Value As String) 998 Dim arLines(0) As String 999 bFound = false 1000 oPath = createUNOService("com.sun.star.util.PathSettings") 1001 filename = oPath.UserConfig+"/helpauthoring.cfg" 1002 iNumber = Freefile 1003 If FileExists(filename) Then 1004 1005 Open filename For Input As iNumber 1006 Do While (not eof(iNumber)) 1007 Line Input #iNumber, sLine 1008 If InStr(sLine, "=") > 0 Then 1009 sDim = ubound(arLines())+1 1010 ReDim Preserve arLines(sDim) 1011 arLines(sDim) = sLine 1012 End If 1013 Loop 1014 Close #iNumber 1015 1016 nLine = 1 1017 Do While (nLine <= ubound(arLines())) and (not bFound) 1018 arLine = split(arLines(nLine),"=") 1019 If arLine(0) = Parm Then 1020 arLines(nLine) = Parm+"="+Value 1021 bFound = true 1022 End If 1023 nLine = nLine +1 1024 Loop 1025 1026 nLine = 1 1027 Open filename For Output As iNumber 1028 Do While (nLine <= ubound(arLines())) 1029 Print #iNumber, arLines(nLine) 1030 nLine = nLine + 1 1031 Loop 1032 If (not bFound) Then 1033 Print #iNumber, Parm+"="+Value 1034 End If 1035 Close #iNumber 1036 1037 Else 1038 Open filename For Output As iNumber 1039 Print #iNumber, Parm+"="+Value 1040 Close #iNumber 1041 End If 1042End Function 1043 1044Function GetRelPath(sPath As String) 1045 sHelpPrefix = ReadConfig("HelpPrefix") 1046 If sHelpPrefix = "" Then 1047 sHelpPrefix = SetDocumentRoot 1048 End If 1049 GetRelPath = Right(sPath, Len(sPath)-(InStr(sPath,sHelpPrefix) + Len(sHelpPrefix)-1)) 1050End Function 1051 1052Function SetDocumentRoot 1053 sHelpPrefix = ReadConfig("HelpPrefix") 1054 oFolderDialog = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker") 1055 oFolderDialog.SetTitle("Select Document Root Folder") 1056 If sHelpPrefix > "" Then 1057 oFolderDialog.setDisplayDirectory(sHelpPrefix) 1058 End If 1059 iAccept = oFolderDialog.Execute() 1060 1061 If iAccept = 1 Then 1062 sHelpPrefix = oFolderDialog.getDirectory + "/" 1063 WriteConfig("HelpPrefix",sHelpPrefix) 1064 End If 1065 1066 SetDocumentRoot = sHelpPrefix 1067End Function 1068 1069Function MakeAbsPath(sPath As String) 1070 1071 sHelpPrefix = ReadConfig("HelpPrefix") 1072 If sHelpPrefix = "" Then 1073 sHelpPrefix = SetDocumentRoot 1074 End If 1075 1076 If Right(sPath,4) <> ".xhp" Then 1077 sPath=sPath+".xhp" 1078 End If 1079 MakeAbsPath = sHelpPrefix+sPath 1080End Function 1081 1082 1083Sub UpdateFields 1084 dim document as object 1085 dim dispatcher as object 1086 document = ThisComponent.CurrentController.Frame 1087 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 1088 1089 dispatcher.executeDispatch(document, ".uno:UpdateFields", "", 0, Array()) 1090End Sub 1091 1092Function IsHelpFile 1093 document = StarDesktop.CurrentComponent 1094 IsHelpFile = (Right(GetFilePath(document.URL),4)=".xhp") 1095End Function 1096 1097Function GetUserFieldNumber(fn as String) 1098 fnum = -1 1099 For a=0 to document.DocumentInfo.getUserFieldCount - 1 1100 If document.DocumentInfo.getUserFieldName(a) = fn Then 1101 fnum = a 1102 Exit for 1103 End If 1104 Next a 1105 GetUserFieldNumber = fnum 1106End Function 1107</script:module> 1108