home *** CD-ROM | disk | FTP | other *** search
/ Freelog 52 / Freelog052.iso / Dossier / OpenOffice / f_0066 / Main.xba < prev    next >
Extensible Markup Language  |  2003-04-24  |  8KB  |  277 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="Main" script:language="StarBasic">Option Explicit
  4.  
  5. '  *****  BASIC  *****
  6. Public HeaderPreviews(4) as Object
  7. Public ImportDialog as Object
  8. Public ImportDialogArea as Object
  9. Public oFactoryKey as Object
  10.  
  11.  
  12. ' If the ProgressPage ist already on Top The Dialog will be immediately closed when this flag is
  13. ' set to False
  14. Public bConversionIsRunning as Boolean
  15. Public RetValue as Integer
  16.  
  17. Sub Main()
  18.     If Not bDebugWizard Then
  19.         On Local Error Goto RTError
  20.     End If
  21.     BasicLibraries.LoadLibrary("Tools")
  22.     RetValue = 10
  23.     bConversionIsRunning = False
  24.     sCRLF = CHR(13) & CHR(10)
  25.     oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
  26.     oFactoryKey = GetRegistryKeyContent("org.openoffice.Setup/Office/Factories")
  27.     If GetImportWizardPaths() = False Then
  28.         Exit Sub
  29.     End If
  30.       bCancelTask = False
  31.       bDoKeepApplValues = False
  32.     CurOffice = 0
  33.     ImportDialogArea = LoadDialog("ImportWizard","ImportDialog")
  34.     ImportDialog = ImportDialogArea.Model
  35.     LoadLanguage()
  36.     WizardMode = SBXMLMODE
  37.     MaxApplCount = 4
  38.     FillStep_Welcome()
  39.     RepaintHeaderPreview()
  40.     ImportDialog.ImportPreview.BackGroundColor = RGB(0,60,126)    
  41.     ImportDialog.cmdGoOn.DefaultButton = True
  42.     ImportDialogArea.GetControl("optSODocuments").SetFocus()
  43.     RetValue = ImportDialogArea.Execute()
  44.     If RetValue = 0 Then
  45.         CancelTask()
  46.     End If
  47.     ImportDialogArea.Dispose()
  48.     End
  49.     Exit Sub
  50. RTError:
  51.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  52. End Sub
  53.  
  54.  
  55.  
  56. Sub NextStep()
  57. Dim iCurStep as Integer
  58.     If Not bDebugWizard Then
  59.         On Error Goto RTError
  60.     End If
  61.     bConversionIsRunning = False
  62.     iCurStep = ImportDialog.Step
  63.     Select Case iCurStep
  64.         Case 1
  65.             FillStep_InputPaths(0, True)
  66.         Case 2
  67.             If CheckInputPaths Then
  68.                 SaveStep_InputPath
  69.                 If CurOffice < ApplCount - 1 Then
  70.                     CurOffice = CurOffice + 1
  71.                     TakeOverPathSettings()
  72.                     FillStep_InputPaths(CurOffice, False)
  73.                 Else
  74.                     FillStep_Summary()
  75.                 End If
  76.             End If
  77.         Case 3
  78.             FillStep_Progress()
  79.             Select Case WizardMode
  80.                 Case SBMICROSOFTMODE
  81.                     Call ConvertAllDocuments(MSFilterName())
  82.                 CASE SBXMLMODE
  83.                     Call ConvertAllDocuments(XMLFilterName())
  84.             End Select
  85.         Case 4
  86.             CancelTask(True)
  87.     End Select
  88.  
  89.     If ((ImportDialog.chkLogfile.State <> 1) OR (iCurStep <> 3)) Then
  90.         ImportDialog.cmdGoOn.DefaultButton = True
  91.     End If
  92.     
  93.     RepaintHeaderPreview()    
  94.     Exit Sub
  95. RTError:
  96.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  97. End Sub
  98.  
  99.  
  100.  
  101. Sub PrevStep()
  102. Dim iCurStep as Integer
  103.     If Not bDebugWizard Then
  104.         On Error Goto RTError
  105.     End If
  106.     bConversionIsRunning = False
  107.     iCurStep = ImportDialog.Step
  108.     Select Case iCurStep
  109.         Case 4
  110.             ImportDialog.cmdCancel.Label = sCancelButton
  111.             FillStep_Summary()
  112.         Case 3
  113.             FillStep_InputPaths(Applcount-1, False)
  114.         Case 2
  115.             SaveStep_InputPath
  116.             If CurOffice > 0 Then
  117.                 CurOffice = CurOffice - 1
  118.                 FillStep_InputPaths(CurOffice, False)
  119.             Else
  120.                 FillStep_Welcome()
  121.                 bDoKeepApplValues = True
  122.             End If
  123.     End Select
  124.     ImportDialog.cmdGoOn.DefaultButton = True
  125.     RepaintHeaderPreview()    
  126.     Exit Sub
  127. RTError:
  128.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  129. End Sub
  130.  
  131.  
  132.  
  133. Sub CancelTask()
  134.     If bConversionIsRunning Then
  135.         If Msgbox(sConvertError1, 36, sConvertError2) = 6 Then
  136.             bCancelTask = True
  137.             bInterruptSearch = True
  138.         Else
  139.             bCancelTask = False
  140.             ImportDialog.cmdCancel.Enabled = True
  141.         End If
  142.     Else
  143.         ImportDialogArea.EndExecute()
  144.     End If
  145. End Sub
  146.  
  147.  
  148. Sub TemplateDirSearchDialog()
  149.     CallDirSearchDialog(ImportDialog.TemplateImportPath)
  150. End Sub
  151.  
  152.  
  153. Sub RepaintHeaderPreview()
  154. Dim Bitmap As Object
  155. Dim CurStep as Integer
  156. Dim sBitmapPath as String
  157. Dim LocPrefix as String
  158.     CurStep = ImportDialog.Step
  159.     LocPrefix = WizardMode
  160.     LocPrefix = ReplaceString(LocPrefix,"XML", "SO")
  161.     If CurStep = 2 Then
  162.         sBitmapPath = SOBitmapPath & LocPrefix & "-Import_" & CurStep & "-" & Applications(CurOffice,SBAPPLKEY) + 1 & ".bmp"
  163.     Else
  164.         sBitmapPath = SOBitmapPath & "Import_" & CurStep & ".bmp"
  165.     End If
  166.     ImportDialog.ImportPreview.ImageURL = sBitmapPath
  167. End Sub
  168.  
  169.  
  170. Sub CheckModuleInstallation()
  171. Dim i as Integer
  172.     For i = 1 To MaxApplCount
  173.         ImportDialogArea.GetControl("chk" & WizardMode & "Application" & i).Model.Enabled = Abs(CheckInstalledModule(i-1))
  174.     Next i
  175. End Sub
  176.  
  177.  
  178. Function CheckInstalledModule(Index as Integer) as Boolean
  179. Dim ModuleName as String
  180. Dim NameList() as String
  181. Dim MaxIndex as Integer
  182. Dim i as Integer
  183.     ModuleName = ModuleList(Index)
  184.     If Instr(1,ModuleName,"/") <> 0 Then
  185.         NameList() = ArrayoutOfString(ModuleName,"/", MaxIndex)
  186.         For i = 0 To MaxIndex
  187.             If Not oFactoryKey.HasByName(NameList(i)) Then
  188.                 CheckInstalledModule() = False
  189.                 Exit Function
  190.             End If
  191.         Next i
  192.         CheckInstalledModule() = True
  193.     Else
  194.         CheckInstalledModule() = oFactoryKey.HasByName(ModuleName)
  195.     End If
  196. End Function
  197.  
  198.  
  199. Sub ToggleCheckboxes(oEvent as Object)
  200. Dim bMSEnable as Boolean
  201.     WizardMode = oEvent.Source.Model.Tag
  202.     bMSEnable = WizardMode = "MS"
  203.     If WizardMode = "MS" Then
  204.         MaxApplCount = 3
  205.     Else
  206.         MaxApplCount = 4
  207.     End If
  208.     With ImportDialogArea
  209.         .GetControl("chkSOApplication1").Model.Enabled = Not bMSEnable
  210.         .GetControl("chkSOApplication2").Model.Enabled = Not bMSEnable
  211.         .GetControl("chkSOApplication3").Model.Enabled = Not bMSEnable
  212.         .GetControl("chkSOApplication4").Model.Enabled = Not bMSEnable
  213.         .GetControl("chkMSApplication1").Model.Enabled = bMSEnable
  214.         .GetControl("chkMSApplication2").Model.Enabled = bMSEnable
  215.         .GetControl("chkMSApplication3").Model.Enabled = bMSEnable
  216.     End With
  217.     CheckModuleInstallation()
  218.     ImportDialog.WelcomeTextLabel2.Enabled = bMSEnable
  219.     bDoKeepApplValues = False
  220.     ToggleNextButton()
  221. End Sub
  222.  
  223.  
  224. Sub ToggleNextButton()
  225. Dim iCurStep as Integer
  226. Dim bDoEnable as Boolean
  227. Dim i as Integer
  228.     iCurStep = ImportDialog.Step
  229.     Select Case iCurStep
  230.         Case 1
  231.             With ImportDialog
  232.                 If .optMSDocuments.State = 1 Then
  233.                       bDoEnable = .chkMSApplication1.State = 1 Or .chkMSApplication2.State = 1 Or .chkMSApplication3.State = 1
  234.                 Else
  235.                       bDoEnable = .chkSOApplication1.State = 1 Or .chkSOApplication2.State = 1 Or .chkSOApplication3.State = 1 Or .chkSOApplication4.State = 1
  236.                 End If
  237.             End With
  238.             bDoKeepApplValues = False
  239.         Case 2
  240.             bDoEnable = CheckControlPath(ImportDialog.chkTemplatePath, ImportDialog.txtTemplateImportPath, True)
  241.             bDoEnable = CheckControlPath(ImportDialog.chkDocumentPath, ImportDialog.txtDocumentImportPath, bDoEnable)
  242.     End Select
  243.     ImportDialog.cmdGoOn.Enabled = bDoEnable
  244. End Sub
  245.  
  246.  
  247. Sub TakeOverPathSettings()                    
  248. 'Takes over the Pathsettings from the first selected application to the next applications
  249.     If Applications(CurOffice,SBDOCSOURCE) = "" Then
  250.         Applications(CurOffice,SBDOCSOURCE) = Applications(0,SBDOCSOURCE)
  251.         Applications(CurOffice,SBDOCTARGET) = Applications(0,SBDOCTARGET)
  252.         If WizardMode = SBXMLMODE AND Applications(CurOffice,SBAPPLKEY) = 3 Then
  253.             Applications(CurOffice,SBTEMPLSOURCE) = Applications(CurOffice,SBDOCSOURCE)
  254.             Applications(CurOffice,SBTEMPLTARGET) = Applications(CurOffice,SBDOCTARGET)                                            
  255.         Else
  256.             Applications(CurOffice,SBTEMPLSOURCE) = Applications(0,SBTEMPLSOURCE)
  257.             Applications(CurOffice,SBTEMPLTARGET) = Applications(0,SBTEMPLTARGET)
  258.         End If
  259.     End If
  260. End Sub
  261.  
  262.  
  263. Function GetImportWizardPaths() as Boolean
  264.     SOBitmapPath = GetOfficeSubPath("Template", "wizard/bitmap")
  265.     If SOBitmapPath <> "" Then
  266.         SOWorkPath = GetPathSettings("Work", False)
  267.         If SOWorkPath <> "" Then
  268.             SOTemplatePath = GetPathSettings("Template",False,1)
  269.             If SOTemplatePath <> "" Then
  270.                 GetImportWizardPaths() = True
  271.                 Exit Function
  272.             End If
  273.         End If
  274.     End  If
  275.     GetImportWizardPaths() = False
  276. End Function
  277. </script:module>