home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 May / PCWorld_2004-05_cd.bin / akce / openoffice / f_0191 / CalendarMain.xba < prev    next >
Extensible Markup Language  |  2004-01-27  |  10KB  |  302 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="CalendarMain" script:language="StarBasic">Option Explicit
  4.  
  5. Const _DEBUG = 0
  6.  
  7. ' CalenderMain
  8. Public sCurLangLocale as String
  9. Public sCurCountryLocale as String
  10. ' This flag serves as a query if the individual Data should be saved
  11. Public bCalOwnDataChanged as Boolean
  12.  
  13. 'BankHoliday Functions
  14. Public CalBankholidayName$ (1 To 374)
  15. Public CalTypeOfBankHoliday% (1 To 374)
  16.  
  17. Public Const cHolidayType_None = 0
  18. Public Const cHolidayType_Full = 1
  19. Public Const cHolidayType_Half = 2
  20. Public Const cHolidayType_Own = 4
  21.  
  22. Public cCalSubcmdDeleteSelect_DeleteSelEntry$
  23. Public cCalSubcmdDeleteSelect_DeleteSelEntryTitle$
  24. Public cCalSubcmdSwitchOwnDataOrGeneral_Back$
  25. Public cCalSubcmdSwitchOwnDataOrGeneral_OwnData$
  26.  
  27. 'Language
  28. Public cCalLongMonthNames(11) as String
  29. Public cCalShortMonthNames(11) as String
  30.  
  31. Public sBitmapFilename$
  32. Public sCalendarTitle$, sMonthTitle$, sWizardTitle$, sError$
  33. Public cCalStyleWorkday$, cCalStyleWeekend$
  34.  
  35. Public CalChoosenLand as Integer
  36.  
  37. Public oDocument as Object
  38. Public oSheets as Object
  39. Public oSheet as Object
  40. Public oStatusLine as Object
  41. Public bCancelTask as Boolean
  42. Public oNumberFormatter as Object
  43.  
  44. ' BL* means "BundesLand" (for german states only)
  45. Public CONST CalBLBayern         = 1
  46. Public CONST CalBLBadenWuert     = 2
  47. Public CONST CalBLBerlin         = 3
  48. Public CONST CalBLBremen         = 4
  49. Public CONST CalBLBrandenburg    = 5
  50. Public CONST CalBLHamburg        = 6
  51. Public CONST CalBLHessen         = 7
  52. Public CONST CalBLMeckPomm       = 8
  53. Public CONST CalBLNiedersachsen  = 9
  54. Public CONST CalBLNordrheinWest  = 10
  55. Public CONST CalBLRheinlandPfalz = 11
  56. Public CONST CalBLSaarland       = 12
  57. Public CONST CalBLSachsen        = 13
  58. Public CONST CalBLSachsenAnhalt  = 14
  59. Public CONST CalBLSchlHolstein   = 15
  60. Public CONST CalBLThueringen     = 16
  61.  
  62. Public DlgCalendar as Object
  63. Public DlgCalModel as Object
  64. Public lDateFormat as Long
  65. Public lDateStandardFormat as Long
  66.  
  67.  
  68.  
  69. Sub CalAutopilotTable()
  70. Dim BitmapDir as String
  71. Dim iThisMonth as Integer
  72.  
  73. 'On Error Goto ErrorHandler
  74.     BasicLibraries.LoadLibrary("Tools")
  75.     bSelectByMouseMove = True
  76.     oDocument = ThisComponent
  77.     oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  78.     ToggleWindow(False)
  79.     sCurLangLocale = oDocument.CharLocale.Language
  80.     sCurCountryLocale = oDocument.CharLocale.Country
  81.     DlgCalendar = LoadDialog("Schedule", "DlgCalendar")
  82.     DlgCalModel = DlgCalendar.Model
  83.     LoadLanguage(sCurLangLocale)
  84.     CalInitGlobalVariablesDate()
  85.     BitmapDir = GetOfficeSubPath("Template","wizard/bitmap")
  86.     DlgCalModel.imgCountry.ImageURL = BitmapDir & sBitmapFilename
  87.     CalChoosenLand = -2
  88.     CalLoadOwnData()
  89.     
  90.     With DlgCalModel
  91.         .cmdDelete.Enabled = False
  92.         .lstMonth.StringItemList() = cCalShortMonthNames()
  93.         Select Case sCurLangLocale
  94.             Case cLANGUAGE_JAPANESE
  95.                 .lstOwnData.FontName = "HG Mincho Light J"
  96.                 .txtEvent.FontName = "HG Mincho Light J"
  97.             Case cLANGUAGE_CHINESE
  98.                 If oDocument.CharLocale.Country = "CN" Then
  99.                     .lstOwnData.FontName = "HG MSung Light SC"
  100.                     .txtEvent.FontName = "HG MSung Light SC"
  101.                 Else
  102.                     .lstOwnData.FontName = "HG MSung Light TC"
  103.                     .txtEvent.FontName = "HG MSung Light TC"
  104.                 End If
  105.             Case "ko"
  106.                 .lstOwnData.FontName = "HG MyeongJo Light K"
  107.                 .txtEvent.FontName = "HG MyeongJo Light K"
  108.         End Select
  109.         .lstOwnEventMonth.StringItemList() = cCalShortMonthNames()
  110.         .optYear.State = 1
  111.         .txtYear.Value = Year(Now())
  112.         .txtYear.Tag = .txtYear.Value
  113.         .Step = 1
  114.     End With
  115.     SetupNumberFormatter(sCurLangLocale, sCurCountryLocale)
  116.     CalChooseCalendar()  ' month
  117.     iThisMonth = Month(Now)
  118.     DlgCalendar.GetControl("lstMonth").SelectItemPos(iThisMonth-1, True)
  119.     DlgCalendar.GetControl("lstHolidays").SelectItemPos(0,True)
  120.     DlgCalModel.cmdGoOn.DefaultButton = True
  121.     ToggleWindow(True)
  122.     DlgCalendar.GetControl("lblHolidays").Visible = sCurLangLocale  = cLANGUAGE_GERMAN
  123.     DlgCalendar.GetControl("lstHolidays").Visible = sCurLangLocale  = cLANGUAGE_GERMAN    
  124.     fHeightCorrFactor = DlgCalendar.GetControl("imgCountry").Size.Height/198
  125.     fWidthCorrFactor = DlgCalendar.GetControl("imgCountry").Size.Width/166
  126.     DlgCalendar.Execute()
  127.     DlgCalendar.Dispose()
  128.     Exit Sub
  129. ErrorHandler:
  130.     MsgBox(sError$, 16, sWizardTitle$)
  131. End Sub
  132.  
  133.  
  134. Sub SetupNumberFormatter(sCurLangLocale as String, sCurCountryLocale as String)
  135. Dim oFormats as Object
  136. Dim DateFormatString as String
  137.     oFormats = oDocument.getNumberFormats()
  138.     Select Case sCurLangLocale
  139.         Case cLANGUAGE_GERMAN
  140.             DateFormatString = "TT.MMM"
  141.         Case cLANGUAGE_ENGLISH
  142.             DateFormatString = "MMM DD"
  143.         Case cLANGUAGE_FRENCH
  144.             DateFormatString = "JJ/MMM"
  145.         Case cLANGUAGE_ITALIAN
  146.             DateFormatString = "GG/MMM"
  147.         Case cLANGUAGE_SPANISH
  148.             DateFormatString = "DD/MMM"
  149.         Case cLANGUAGE_PORTUGUESE
  150.             If sCurCountryLocale = "BR" Then
  151.                 DateFormatString = "DD/MMM"
  152.             Else
  153.                 DateFormatString = "DD-MMM"
  154.             End If        
  155.         Case cLANGUAGE_DUTCH
  156.             DateFormatString = "DD-MMM"
  157.         Case cLANGUAGE_SWEDISH
  158.             DateFormatString = "MMM DD"
  159.         Case cLANGUAGE_DANISH
  160.             DateFormatString = "DD-MMM"
  161.         Case cLANGUAGE_POLISH
  162.             DateFormatString = "MMM DD"
  163.         Case cLANGUAGE_RUSSIAN
  164.             DateFormatString = "MMM DD"
  165.         Case cLANGUAGE_JAPANESE
  166.             DateFormatString = "Mµ£êDµùÑ"
  167.         Case cLANGUAGE_CHINESE
  168.             If sCurCountryLocale = "TW" Then
  169.                 DateFormatString = "MMMMD" &"""" & "µùÑ" & """"
  170.             Else
  171.                 DateFormatString = "M" & """" & "µ£ê" & """" & "D" &"""" & "µùÑ" & """"
  172.             End If
  173.         Case cLANGUAGE_GREEK
  174.             DateFormatString = "DD/MMM"        
  175.         Case cLANGUAGE_TURKISH
  176.             DateFormatString = "DD/MMM"        
  177.         Case cLANGUAGE_POLISH
  178.             DateFormatString = "MMM DD"        
  179.         Case cLANGUAGE_FINNISH
  180.             DateFormatString = "PP.KKK"        
  181.     End Select
  182.  
  183.     lDateFormat = AddNumberFormat(oFormats, DateFormatString, oDocument.CharLocale)
  184.     lDateStandardFormat = oFormats.getStandardFormat(com.sun.star.util.NumberFormat.DATE, oDocument.CharLocale)
  185.  
  186. '    lDateStandardFormat = AddNumberFormat(oFormats, StandardDateFormatString, oDocument.CharLocale)
  187.     oNumberFormatter = createUNOService("com.sun.star.util.NumberFormatter")
  188.     oNumberFormatter.attachNumberFormatsSupplier(oDocument)
  189. End Sub
  190.  
  191.  
  192. Function AddNumberFormat(oNumberFormats as Object, FormatString as String, oLocale as Object) as Long
  193. Dim lLocDateFormat as Long
  194.     lLocDateFormat = oNumberFormats.QueryKey(FormatString, oLocale, True)
  195.     If lLocDateFormat = -1 Then
  196.         lLocDateFormat = oNumberFormats.addNew(FormatString, oLocale)
  197.     End If
  198.     AddNumberFormat() = lLocDateFormat
  199. End Function
  200.  
  201.  
  202. Sub CalChooseCalendar()
  203.     With DlgCalModel
  204.         .lstMonth.Enabled = .optMonth.State = 1
  205.         .lblMonth.Enabled = .optMonth.State = 1
  206.     End With
  207. End Sub
  208.  
  209.  
  210. Sub CalcmdCancel()
  211.     Call CalSaveOwnData()
  212.     DlgCalendar.EndExecute
  213. End Sub
  214.  
  215.  
  216. Sub CalcmdOk()
  217.     ' cmdOk is called when the Button 'Read' is clicked on
  218.     ' It is either given out a month or a year
  219. Dim i, iSelYear as Integer
  220. Dim SelYear as String
  221. '    DlgCalendar.Visible = False
  222.  
  223.     oSheets = oDocument.sheets
  224.     Call CalSaveOwnData()
  225.     UnprotectSheets(oSheets)
  226.     oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
  227.     iSelYear = DlgCalModel.txtYear.Value
  228.     Select Case sCurLangLocale
  229.         Case cLANGUAGE_GERMAN
  230.             If Ubound(DlgCalModel.lstHolidays.SelectedItems()) > -1 Then
  231.                 CalChoosenLand = DlgCalModel.lstHolidays.SelectedItems(0)
  232.             Else
  233.                 CalChoosenLand = 0
  234.             End If
  235.             Call CalFindWholeYearHolidays_GERMANY(iSelYear, CalChoosenLand)
  236.         Case cLANGUAGE_ENGLISH
  237.             Call FindWholeYearHolidays_US(iSelYear)
  238.         Case cLANGUAGE_FRENCH
  239.             Call FindWholeYearHolidays_FRANCE(iSelYear)
  240.         Case cLANGUAGE_ITALIAN
  241.             Call FindWholeYearHolidays_ITA(iSelYear)
  242.         Case cLANGUAGE_SPANISH
  243.             Call FindWholeYearHolidays_SPAIN(iSelYear)
  244.         Case cLANGUAGE_PORTUGUESE
  245.             Call FindWholeYearHolidays_PORT(iSelYear)
  246.         Case cLANGUAGE_DUTCH
  247.             Call FindWholeYearHolidays_NL(iSelYear)
  248.         Case cLANGUAGE_SWEDISH
  249.             Call FindWholeYearHolidays_SWED(iSelYear)
  250.         Case cLANGUAGE_DANISH
  251.             Call FindWholeYearHolidays_DK(iSelYear)
  252.         Case cLANGUAGE_POLISH
  253.             Call FindWholeYearHolidays_PL(iSelYear)
  254.         Case cLANGUAGE_RUSSIAN
  255.             Call FindWholeYearHolidays_RU(iSelYear)
  256.         Case cLANGUAGE_JAPANESE
  257.             Call FindWholeYearHolidays_JP(iSelYear)
  258.         Case cLANGUAGE_CHINESE
  259.             If sCurCountryLocale = "TW" Then
  260.                 Call FindWholeYearHolidays_TW(iSelYear)
  261.             Else
  262.                 Call FindWholeYearHolidays_CN(iSelYear)
  263.             End If
  264.         Case cLANGUAGE_GREEK
  265.             Call FindWholeYearHolidays_GREEK(iSelYear)
  266.         Case cLANGUAGE_TURKISH
  267.             Call FindWholeYearHolidays_TRK(iSelYear)
  268.         Case cLANGUAGE_POLISH
  269.             Call FindWholeYearHolidays_PL(iSelYear)
  270.         Case cLANGUAGE_FINNISH
  271.             Call FindWholeYearHolidays_FI(iSelYear)
  272.     End Select
  273.  
  274.     Call CalInsertOwnDataInTables(iSelYear)
  275.  
  276.     If DlgCalModel.optYear.State = 1 Then
  277.         oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
  278.         oSheet = oSheets.GetbyIndex(0)
  279.         oSheet.Name = sCalendarTitle$ + " " + iSelYear
  280.         oDocument.AddActionLock
  281.         Call CalCreateYearTable(iSelYear)
  282.     ElseIf DlgCalModel.optMonth.State = 1 Then
  283.         Dim iMonth
  284.         iMonth = DlgCalModel.lstMonth.SelectedItems(0) + 1
  285.         oSheets.RemovebyName(oSheets.GetbyIndex(1).Name)
  286.         oSheet = oSheets.GetbyIndex(0)
  287.         If sMonthTitle = "" Then
  288.             oSheet.Name = cCalLongMonthNames(iMonth-1)
  289.         Else
  290.             oSheet.Name = sMonthTitle + " " + cCalLongMonthNames(iMonth-1)
  291.         End If
  292.         oDocument.AddActionLock
  293.         Call CalCreateMonthTable(iSelYear, iMonth)
  294.     End If
  295.  
  296.     oDocument.RemoveActionLock
  297.     oSheet.protect("")
  298.     oStatusLine.End
  299.     DlgCalendar.EndExecute()
  300.     bCancelTask = True
  301. End Sub
  302. </script:module>