home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0179 / ModuleControls.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-21  |  8.8 KB  |  263 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="ModuleControls" script:language="StarBasic">Option Explicit
  4. 'bla
  5.  
  6. ' Accepts the name of a control and returns the respective control model as object
  7. ' The Container can either be a whole document or a specific sheet of a Calc-Document
  8. ' 'CName' is the name of the Control
  9. Function getControlModel(oContainer as Object, CName as String)
  10. Dim aForm, oForms as Object
  11. Dim i as Integer
  12.     oForms = oContainer.Drawpage.GetForms
  13.     For i = 0 To oForms.Count-1
  14.         aForm = oForms.GetbyIndex(i)
  15.         If aForm.HasByName(CName) Then
  16.             GetControlModel = aForm.GetbyName(CName)
  17.             Exit Function
  18.         End If
  19.     Next i
  20.     Msgbox("No Control with the name '" & CName & "' found" , 16, GetProductName())
  21. End Function
  22.  
  23.  
  24.  
  25. ' Gets the Shape of a Control( e. g. to reset the size or Position of the control
  26. ' Parameters:
  27. ' The 'oContainer' is the Document or a specific sheet of a Calc - Document
  28. ' 'CName' is the Name of the Control
  29. Function GetControlShape(oContainer as Object,CName as String)
  30. Dim i as integer
  31. Dim aShape as Object
  32.     For i = 0 to oContainer.DrawPage.Count-1
  33.         aShape = oContainer.DrawPage(i)
  34.         If HasUnoInterfaces(aShape, "com.sun.star.drawing.XControlShape") then
  35.             If ashape.Control.Name = CName then
  36.                 GetControlShape = aShape
  37.                 exit Function
  38.             End If
  39.         End If
  40.     Next
  41. End Function
  42.  
  43.  
  44. ' Returns the View of a Control
  45. ' Parameters:
  46. ' The 'oContainer' is the Document or a specific sheet of a Calc - Document
  47. ' The 'oController' is always directly attached to the Document
  48. ' 'CName' is the Name of the Control
  49. Function getControlView(oContainer , oController as Object, CName as String) as Object
  50. Dim aForm, oForms, oControlModel as Object
  51. Dim i as Integer
  52.     oForms = oContainer.DrawPage.Forms
  53.     For i = 0 To oForms.Count-1
  54.         aForm = oforms.GetbyIndex(i)
  55.         If aForm.HasByName(CName) Then
  56.             oControlModel = aForm.GetbyName(CName)
  57.             GetControlView = oController.GetControl(oControlModel)
  58.             Exit Function
  59.         End If
  60.     Next i
  61.     Msgbox("No Control with the name '" & CName & "' found" , 16, GetProductName())
  62. End Function
  63.  
  64.  
  65.  
  66. ' Parameters:
  67. ' The 'oContainer' is the Document or a specific sheet of a Calc - Document
  68. ' 'CName' is the Name of the Control
  69. Function DisposeControl(oContainer as Object, CName as String) as Boolean
  70. Dim aControl as Object
  71.  
  72.     aControl = GetControlModel(oContainer,CName)
  73.     If not IsNull(aControl) Then
  74.         aControl.Dispose()
  75.         DisposeControl = True
  76.     Else
  77.         DisposeControl = False
  78.     End If
  79. End Function
  80.  
  81.  
  82. ' Returns a sequence of a group of controls like option buttons or checkboxes
  83. ' The 'oContainer' is the Document or a specific sheet of a Calc - Document
  84. ' 'sGroupName' is the Name of the Controlgroup
  85. Function GetControlGroupModel(oContainer as Object, sGroupName as String )
  86. Dim aForm, oForms As Object
  87. Dim aControlModel() As Object
  88. Dim i as integer
  89.  
  90.     oForms = oContainer.DrawPage.Forms
  91.     For i = 0 To oForms.Count-1
  92.         aForm = oForms(i)
  93.         If aForm.HasbyName(sGroupName) Then
  94.             aForm.GetGroupbyName(sGroupName,aControlModel)
  95.             GetControlGroupModel = aControlModel
  96.             Exit Function
  97.         End If
  98.     Next i
  99.     Msgbox("No Controlgroup with the name '" & sGroupName & "' found" , 16, GetProductName())
  100. End Function
  101.  
  102.  
  103. ' Returns the Referencevalue of a group of e.g. option buttons or check boxes
  104. ' 'oControlGroup' is a sequence of the Control objects
  105. Function GetRefValue(oControlGroup() as Object)
  106. Dim i as Integer
  107.     For i = 0 To Ubound(oControlGroup())
  108. '        oControlGroup(i).DefaultState = oControlGroup(i).State
  109.         If oControlGroup(i).State Then
  110.             GetRefValue = oControlGroup(i).RefValue
  111.             exit Function
  112.         End If
  113.     Next
  114.     Msgbox("No Control selected!",16, GetProductName())
  115. End Function
  116.  
  117.  
  118. Function GetRefValueOfControlGroup(oContainer as Object, GroupName as String)
  119. Dim oOptGroup() as Object
  120. Dim iRef as Integer
  121.     oOptGroup() = GetControlGroupModel(oContainer, GroupName)
  122.     iRef = GetRefValue(oOptGroup())
  123.     GetRefValueofControlGroup = iRef
  124. End Function
  125.  
  126.  
  127. Function GetOptionGroupValue(oContainer as Object, OptGroupName as String) as Boolean
  128. Dim oRulesOptions() as Object
  129.     oRulesOptions() = GetControlGroupModel(oContainer, OptGroupName)
  130.     GetOptionGroupValue = oRulesOptions(0).State
  131. End Function
  132.  
  133.  
  134.  
  135. Function WriteOptValueToCell(oSheet as Object, OptGroupName as String, iCol as Integer, iRow as Integer) as Boolean
  136. Dim bOptValue as Boolean
  137. Dim oCell as Object
  138.     bOptValue = GetOptionGroupValue(oSheet, OptGroupName)
  139.     oCell = oSheet.GetCellByPosition(iCol, iRow)
  140.     oCell.SetValue(ABS(CInt(bOptValue)))
  141.     WriteOptValueToCell() = bOptValue
  142. End Function
  143.  
  144.  
  145. Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
  146. Dim oLib as Object
  147. Dim oLibDialog as Object
  148. Dim oRuntimeDialog as Object
  149.     If IsMissing(oLibContainer ) then
  150.         oLibContainer = DialogLibraries
  151.     End If
  152.     oLibContainer.LoadLibrary(LibName)
  153.     oLib = oLibContainer.GetByName(Libname)
  154.     oLibDialog = oLib.GetByName(DialogName)
  155.     oRuntimeDialog = CreateUnoDialog(oLibDialog)
  156.     LoadDialog() = oRuntimeDialog
  157. End Function
  158.  
  159.  
  160. Sub GetFolderName(oRefModel as Object)
  161. Dim oFolderDialog as Object
  162. Dim iAccept as Integer
  163. Dim sPath as String
  164. Dim InitPath as String
  165. Dim RefControlName as String
  166. Dim oUcb as object
  167.     oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
  168.     oFolderDialog = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
  169.     InitPath = ConvertToUrl(oRefModel.Text)
  170.     If InitPath = "" Then
  171.         InitPath = GetPathSettings("Work")
  172.     End If
  173.     If oUcb.Exists(InitPath) Then
  174.         oFolderDialog.SetDisplayDirectory(InitPath)
  175.     End If
  176.     iAccept = oFolderDialog.Execute()
  177.     If iAccept = 1 Then
  178.         sPath = oFolderDialog.GetDirectory()
  179.         If oUcb.Exists(sPath) Then
  180.             oRefModel.Text = ConvertFromUrl(sPath)
  181.         End If
  182.     End If
  183. End Sub
  184.  
  185.  
  186. Sub GetFileName(oRefModel as Object, Filternames())
  187. Dim oFileDialog as Object
  188. Dim iAccept as Integer
  189. Dim sPath as String
  190. Dim InitPath as String
  191. Dim RefControlName as String
  192. Dim oUcb as object
  193. 'Dim ListAny(0)
  194.     oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
  195.     oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
  196.     'ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
  197.     'oFileDialog.initialize(ListAny())
  198.     AddFiltersToDialog(FilterNames(), oFileDialog)
  199.     InitPath = ConvertToUrl(oRefModel.Text)
  200.     If InitPath = "" Then
  201.         InitPath = GetPathSettings("Work")
  202.     End If
  203.     If oUcb.Exists(InitPath) Then
  204.         oFileDialog.SetDisplayDirectory(InitPath)
  205.     End If
  206.     iAccept = oFileDialog.Execute()
  207.     If iAccept = 1 Then
  208.         sPath = oFileDialog.Files(0)
  209.         If oUcb.Exists(sPath) Then
  210.             oRefModel.Text = ConvertFromUrl(sPath)
  211.         End If
  212.     End If
  213. End Sub
  214.  
  215.  
  216. Function StoreDocument(oDocument as Object, FilterNames() as String, DefaultName as String, DisplayDirectory as String)
  217. Dim NoArgs() as New com.sun.star.beans.PropertyValue
  218. Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
  219. Dim oStoreDialog as Object
  220. Dim iAccept as Integer
  221. Dim sPath as String
  222. Dim ListAny(0) as Long
  223. Dim UIFilterName as String
  224. Dim FilterName as String
  225. Dim FilterIndex as Integer
  226.     ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
  227.     oStoreDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
  228.     oStoreDialog.Initialize(ListAny())
  229.     AddFiltersToDialog(FilterNames(), oStoreDialog)
  230.     oStoreDialog.SetDisplayDirectory(DisplayDirectory)
  231.     oStoreDialog.SetDefaultName(DefaultName)
  232.     iAccept = oStoreDialog.Execute()
  233.     If iAccept = 1 Then
  234.         sPath = oStoreDialog.Files(0)
  235.         UIFilterName = oStoreDialog.GetCurrentFilter()
  236.         FilterIndex = IndexInArray(UIFilterName, FilterNames())
  237.         FilterName = FilterNames(FilterIndex,2)
  238.         If FilterName = ""  Then
  239.             oDocument.StoreAsUrl(sPath, NoArgs())
  240.         Else
  241.             oStoreProperties(0).Name = "FilterName"
  242.             oStoreProperties(0).Value = FilterName
  243.             oDocument.StoreAsUrl(sPath, oStoreProperties())
  244.         End If
  245.         StoreDocument() = True
  246.     Else
  247.         StoreDocument() = False
  248.     End If
  249. End Function
  250.  
  251.  
  252. Sub AddFiltersToDialog(FilterNames() as String, oDialog as Object)    
  253. Dim i as Integer
  254. Dim MaxIndex as Integer
  255.     MaxIndex = Ubound(FilterNames(), 1)
  256.     For i = 0 To MaxIndex
  257.         oDialog.AppendFilter(FilterNames(i,0), FilterNames(i,1))
  258.     Next i
  259.     oDialog.SetCurrentFilter(FilterNames(0,0)
  260. End Sub
  261.  
  262.  
  263. </script:module>