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