home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #3 / K-CD_2002-03.iso / OpenOffice / f_0109 / Greeting.xba < prev    next >
Extensible Markup Language  |  2001-06-08  |  8KB  |  241 lines

  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="Greeting" script:language="StarBasic">REM  *****  BASIC  *****
  4. ' Todo: Identifizieren der Standardseitenvorlage ├â┬╝ber ihren programmatic Name
  5. ' Todo: Fertigstellen-Button muss disabled werden, wenn noch keine Grafik ausgew├â┬ñhlt
  6. '         ist und die Checkbox 'ChkPictureFirstPage' gew├â┬ñhlt ist.
  7. ' Todo: Unter Umst├â┬ñnden braucht die Tools Bibliothek nicht geladen werden
  8. Dim oDocument as Object
  9. Dim oDocText as Object
  10. Dim oGraphic as Object
  11. Dim oBookmarks as Object
  12. Dim GalleryDir as String
  13. Dim oTextShape as Object
  14. Dim Greetingmode as Integer
  15. Public Occasions(4,11,1) as String
  16.  
  17.  
  18. Public Const SBEXTRAVAGANT = 0
  19. Public Const SBCARDFOLD = 1
  20. Public Const SBDUPLEX = 2
  21.  
  22.  
  23. Sub StartExtravagantMacro()
  24.     GreetingMode = SBEXTRAVAGANT
  25.     DlgGreeting.Load
  26.     DlgGreeting.OptRight.Enabled = False
  27.     DlgGreeting.OptLeft.Value = True
  28.     ShowGreetingDialog()
  29. End Sub
  30.  
  31.  
  32. Sub StartDuplexMacro()
  33.     GreetingMode = SBDUPLEX
  34.     DlgGreeting.Load
  35.     DlgGreeting.OptRight.Value = True
  36.     ShowGreetingDialog
  37. End Sub
  38.  
  39.  
  40. Sub StartCardFoldMacro()
  41.     GreetingMode = SBCARDFOLD
  42.     DlgGreeting.Load
  43.     DlgGreeting.OptRight.Value = True
  44.     ShowGreetingDialog
  45. End Sub
  46.  
  47.  
  48.  
  49. Sub LoadLanguage()
  50.     With DlgGreeting
  51.         .FrmFirstPage.Caption = "Erste Seite"
  52.         .ChkPictureFirstPage.Caption = "Bild auf 1. Seite"
  53.         .ChkTextFirstPage.Caption = "Text auf 1. Seite"
  54.         .TxtFirstPage.Text = "Alles Gute zum Thema"
  55.         .CmdOwnPicture.Caption = "Bild w├â┬ñhlen"
  56.         .LblPictureFile.Caption = "<kein Bild gew├â┬ñhlt>"
  57.  
  58.         .FrmInside.Caption = "Innenseite"
  59.         .TxtInside.Text = "Alles Gute zum Thema"
  60.         .OptLeft.Caption = "&Linke Innenseite"
  61.         .OptRight.Caption = "&Rechte Innenseite"
  62.         .OptNoText.Caption = "Kein &Text"
  63.  
  64.         .CmdCancel.Caption = "&Abbrechen"
  65.         .CmdOk.Caption = "&Fertig stellen"
  66.         .Caption = "Gru├â┼╕karten-Assistent"
  67.     End With
  68. End Sub
  69.  
  70. Sub ShowGreetingDialog()
  71.     LoadLanguage()
  72. '  BasicLibraries.LoadLibrary("Tools")
  73.     oDocument = StarDesktop.CurrentFrame.Controller.Model
  74.     oDocText = oDocument.Text
  75.     oBookmarks = oDocument.BookMarks
  76.  
  77.     oTextShape = oDocument.CreateInstance("com.sun.star.drawing.TextShape")
  78.     oGraphic = oDocument.CreateInstance("com.sun.star.text.Graphic")
  79.     GalleryDir = GetPathSettings("Gallery", False, 0)
  80.     GalleryDir = ConvertToURL(GalleryDir)
  81.     DlgGreeting.ChkPictureFirstPage.Value = True
  82.     DlgGreeting.ChkTextFirstPage.Value = True
  83.     DlgGreeting.Show
  84. End Sub
  85.  
  86.  
  87. Sub CloseDialog
  88.     DlgGreeting.Unload
  89. End Sub
  90.  
  91.  
  92. Sub DisOrEnablePictureControls()
  93.     DlgGreeting.CmdOwnPicture.Enabled = DlgGreeting.ChkPictureFirstPage.Value
  94.     DlgGreeting.LblPictureFile.Enabled = DlgGreeting.ChkPictureFirstPage.Value
  95.     DlgGreeting.TxtFirstPage.Enabled = DlgGreeting.ChkTextFirstPage.Value
  96. End Sub
  97.  
  98.  
  99. Sub DisOrEnableTextBox()
  100.     DlgGreeting.TxtInside.Enabled = Not DlgGreeting.OptNoText.Value
  101. End Sub
  102.  
  103.  
  104. Sub EnableControls(bEnabled as Boolean)
  105.     With DlgGreeting
  106.         .FrmFirstPage.Enabled = bEnabled
  107.         .ChkPictureFirstPage.Enabled = bEnabled
  108.         .ChkTextFirstPage.Enabled = bEnabled
  109.         .CmdOwnPicture.Enabled = bEnabled
  110.         .LblPictureFile.Enabled = bEnabled
  111.         .FrmInside.Enabled = bEnabled
  112.         .TxtInside.Enabled = bEnabled
  113.         .OptLeft.Enabled = bEnabled
  114.         .OptRight.Enabled = bEnabled
  115.         .OptNoText.Enabled = bEnabled
  116.         .CmdOk.Enabled = bEnabled
  117.     End With
  118. End Sub
  119.  
  120.  
  121. Sub InsertGreetingObjects()
  122. Dim oStandardPageStyle as Object
  123. Dim oPageStyles as Object
  124. Dim oFrame as Object
  125. Dim oCursor as Object
  126. Dim WmfUrl as String
  127. Dim aPoint As New com.sun.star.awt.Point
  128. Dim aSize As New com.sun.star.awt.Size
  129. Dim oBookmark as Object
  130.  
  131. '    oDocument.LockControllers
  132.     WmfUrl = GalleryDir & "/clipart/car.wmf"
  133.     EnableControls(False)
  134.     oBookMark = oBookmarks.GetbyName("TitlePage")
  135.     oCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
  136.     oCursor.GoRight(1,True)
  137.     oGraphic.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
  138. '    oGraphic.Backtransparent = False
  139.     oGraphic.GraphicURL = WmfUrl
  140.     Select Case GreetingMode
  141.         Case SBDUPLEX
  142.             ' Zweiseitig, einfach gefaltet
  143.             ' Spiegele die Grafik
  144.             ' Der Text wird in eine Zeile unter der Grafik geschrieben.
  145.             oCursor.Text.InsertTextContent(oCursor,oGraphic,True)
  146.         Case SBCARDFOLD
  147.             oFrame = oDocument.TextFrames.GetByName("Picture and Title")
  148.             oCursor.Text.InsertTextContent(oCursor,oTextShape,True)
  149.             AdjustTextShape(oFrame)
  150.             oTextShape.SetString(DlgGreeting.TxtFirstPage.Text)
  151.             oCursor.CollapseToEnd()
  152.             oCursor.Text.InsertTextContent(oCursor,oGraphic,False)
  153.  
  154.             oGraphic.VertMirrored = True
  155.             oTextShape.RotateAngle = 18000
  156.             ' Die Breite muss so gro├â┼╕ sein, dass die Textshape oberhalb der Grafik steht.
  157.  
  158.         Case SBSBEXTRAVAGANT
  159.             oFrame = oDocument.TextFrames.GetByName("Picture")
  160.             oCursor.Text.InsertTextContent(oCursor,oGraphic,True)
  161.             ChangeSizeofGraphic(oFrame, oGraphic)
  162.             If DlgGreeting.ChkTextFirstPage.Value Then
  163.                 ' Insert Text in the frame "Title"
  164.                 oFrame = oDocument.TextFrames.GetByName("Title")
  165.                 oCursor = oFrame.CreateTextCursor
  166.                 oCursor.SetString(DlgGreeting.TxtFirstPage.Text)
  167.             End If
  168.     End Select
  169.  
  170.     If Not DlgGreeting.OptNoText.Value Then
  171.         If DlgGreeting.OptLeft.Value Then
  172.             InsertTextToPlaceholder("LeftPage", DlgGreeting.TxtInside.Text)
  173.             InsertTextToPlaceholder("RightPage", "")
  174.         ElseIf DlgGreeting.OptRight.Value Then
  175.             InsertTextToPlaceholder("LeftPage", "")
  176.             InsertTextToPlaceholder("RightPage", DlgGreeting.TxtInside.Text)
  177.         End If
  178.     End If
  179.     DlgGreeting.Unload
  180. '    oDocument.UnlockControllers
  181. End Sub
  182.  
  183.  
  184. Sub InsertTextToPlaceHolder(sPosition as String, sCaption as String)
  185. Dim oBookMark as Object
  186. Dim oBookmarkCursor as Object
  187.     oBookMark = oBookmarks.GetbyName(sPosition)
  188.     oBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
  189.     oBookMarkCursor.GoRight(1,True)
  190.     oBookMarkCursor.SetString(sCaption)
  191. End Sub
  192.  
  193.  
  194. Sub ChangeSizeofGraphic(oFrame as Object, oGraphic as Object)
  195. Dim NewGraphWidth as Long
  196. Dim NewGraphHeight as Long
  197. Dim OldGraphWidth as Long
  198. Dim OldGraphHeight as Long
  199. Dim PageWidth as Long
  200. Dim RightPageBorder as Long
  201. Dim TopPageBorder as Long
  202. Dim aSize As New com.sun.star.awt.Size
  203.  
  204.     OldGraphWidth = oGraphic.Size.Width
  205.     OldGraphHeight = oGraphic.Size.Height
  206.     PageWidth = GetPageWidth()
  207.     RightPageBorder = PageWidth - oFrame.HoriOrientPosition - oFrame.Size.Width
  208.     TopPageBorder = oFrame.VertOrientPosition
  209.     NewGraphWidth = CInt(((PageWidth/2 - TopPageBorder - RightPageBorder) * OldGraphWidth) /( OldGraphWidth + OldGraphHeight))
  210.     NewGraphHeight = CInt(((PageWidth/2 - TopPageBorder - RightPageBorder) * OldGraphHeight) /( OldGraphWidth + OldGraphHeight))
  211.     aSize.Width = NewGraphWidth
  212.     aSize.Height = NewGraphHeight
  213.     oGraphic.Size = aSize
  214. End Sub
  215.  
  216.  
  217. Function GetPageWidth()
  218. Dim oPageStyles as Object
  219. Dim oPageStyle as Object
  220.     oPageStyles = oDocument.StyleFamilies.GetbyName("PageStyles")
  221. ' Todo: Call template by Programmatic name
  222.     oPageStyle = oPageStyles.GetByName("Standard")
  223.     GetPageWidth = oPageStyle.Size.Width
  224. End Function
  225.  
  226.  
  227. Sub ChooseGreetingGraphic()
  228.     ' Todo: attach Call of Dialog
  229.     Msgbox("Jetzt soll eine Grafik ausgew├â┬ñhlt und die Caption des Controls" & chr(13) & _
  230.             "'LblPictureFile' entsprechend aktualisiert werden", 16, "StarOffice 6.0")
  231. End Sub
  232.  
  233.  
  234. Sub AdjustTextShape(oFrame as Object)
  235. Dim aSize As New com.sun.star.awt.Size
  236. Dim FrameWidth as Long
  237.     oTextShape.TextAutoGrowWidth = True
  238.     oTextShape.TextMaximumFrameWidth = oFrame.Size.Width
  239.     oTextShape.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
  240. End Sub
  241. </script:module>