home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 January / PCWorld_2004-01_cd.bin / akce / openoffice / f_0183 / CalendarMain.xba < prev    next >
Extensible Markup Language  |  2002-10-29  |  10KB  |  298 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.             DateFormatString = "DD-MMM"
  151.         Case cLANGUAGE_DUTCH
  152.             DateFormatString = "DD-MMM"
  153.         Case cLANGUAGE_SWEDISH
  154.             DateFormatString = "MMM DD"
  155.         Case cLANGUAGE_DANISH
  156.             DateFormatString = "DD-MMM"
  157.         Case cLANGUAGE_POLISH
  158.             DateFormatString = "MMM DD"
  159.         Case cLANGUAGE_RUSSIAN
  160.             DateFormatString = "MMM DD"
  161.         Case cLANGUAGE_JAPANESE
  162.             DateFormatString = "Mµ£êDµùÑ"
  163.         Case cLANGUAGE_CHINESE
  164.             If sCurCountryLocale = "TW" Then
  165.                 DateFormatString = "MMMMD" &"""" & "µùÑ" & """"
  166.             Else
  167.                 DateFormatString = "M" & """" & "µ£ê" & """" & "D" &"""" & "µùÑ" & """"
  168.             End If
  169.         Case cLANGUAGE_GREEK
  170.             DateFormatString = "DD/MMM"        
  171.         Case cLANGUAGE_TURKISH
  172.             DateFormatString = "DD/MMM"        
  173.         Case cLANGUAGE_POLISH
  174.             DateFormatString = "MMM DD"        
  175.         Case cLANGUAGE_FINNISH
  176.             DateFormatString = "PP.KKK"        
  177.     End Select
  178.  
  179.     lDateFormat = AddNumberFormat(oFormats, DateFormatString, oDocument.CharLocale)
  180.     lDateStandardFormat = oFormats.getStandardFormat(com.sun.star.util.NumberFormat.DATE, oDocument.CharLocale)
  181.  
  182. '    lDateStandardFormat = AddNumberFormat(oFormats, StandardDateFormatString, oDocument.CharLocale)
  183.     oNumberFormatter = createUNOService("com.sun.star.util.NumberFormatter")
  184.     oNumberFormatter.attachNumberFormatsSupplier(oDocument)
  185. End Sub
  186.  
  187.  
  188. Function AddNumberFormat(oNumberFormats as Object, FormatString as String, oLocale as Object) as Long
  189. Dim lLocDateFormat as Long
  190.     lLocDateFormat = oNumberFormats.QueryKey(FormatString, oLocale, True)
  191.     If lLocDateFormat = -1 Then
  192.         lLocDateFormat = oNumberFormats.addNew(FormatString, oLocale)
  193.     End If
  194.     AddNumberFormat() = lLocDateFormat
  195. End Function
  196.  
  197.  
  198. Sub CalChooseCalendar()
  199.     With DlgCalModel
  200.         .lstMonth.Enabled = .optMonth.State = 1
  201.         .lblMonth.Enabled = .optMonth.State = 1
  202.     End With
  203. End Sub
  204.  
  205.  
  206. Sub CalcmdCancel()
  207.     Call CalSaveOwnData()
  208.     DlgCalendar.EndExecute
  209. End Sub
  210.  
  211.  
  212. Sub CalcmdOk()
  213.     ' cmdOk is called when the Button 'Read' is clicked on
  214.     ' It is either given out a month or a year
  215. Dim i, iSelYear as Integer
  216. Dim SelYear as String
  217. '    DlgCalendar.Visible = False
  218.  
  219.     oSheets = oDocument.sheets
  220.     Call CalSaveOwnData()
  221.     UnprotectSheets(oSheets)
  222.     oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
  223.     iSelYear = DlgCalModel.txtYear.Value
  224.     Select Case sCurLangLocale
  225.         Case cLANGUAGE_GERMAN
  226.             If Ubound(DlgCalModel.lstHolidays.SelectedItems()) > -1 Then
  227.                 CalChoosenLand = DlgCalModel.lstHolidays.SelectedItems(0)
  228.             Else
  229.                 CalChoosenLand = 0
  230.             End If
  231.             Call CalFindWholeYearHolidays_GERMANY(iSelYear, CalChoosenLand)
  232.         Case cLANGUAGE_ENGLISH
  233.             Call FindWholeYearHolidays_US(iSelYear)
  234.         Case cLANGUAGE_FRENCH
  235.             Call FindWholeYearHolidays_FRANCE(iSelYear)
  236.         Case cLANGUAGE_ITALIAN
  237.             Call FindWholeYearHolidays_ITA(iSelYear)
  238.         Case cLANGUAGE_SPANISH
  239.             Call FindWholeYearHolidays_SPAIN(iSelYear)
  240.         Case cLANGUAGE_PORTUGUESE
  241.             Call FindWholeYearHolidays_PORT(iSelYear)
  242.         Case cLANGUAGE_DUTCH
  243.             Call FindWholeYearHolidays_NL(iSelYear)
  244.         Case cLANGUAGE_SWEDISH
  245.             Call FindWholeYearHolidays_SWED(iSelYear)
  246.         Case cLANGUAGE_DANISH
  247.             Call FindWholeYearHolidays_DK(iSelYear)
  248.         Case cLANGUAGE_POLISH
  249.             Call FindWholeYearHolidays_PL(iSelYear)
  250.         Case cLANGUAGE_RUSSIAN
  251.             Call FindWholeYearHolidays_RU(iSelYear)
  252.         Case cLANGUAGE_JAPANESE
  253.             Call FindWholeYearHolidays_JP(iSelYear)
  254.         Case cLANGUAGE_CHINESE
  255.             If sCurCountryLocale = "TW" Then
  256.                 Call FindWholeYearHolidays_TW(iSelYear)
  257.             Else
  258.                 Call FindWholeYearHolidays_CN(iSelYear)
  259.             End If
  260.         Case cLANGUAGE_GREEK
  261.             Call FindWholeYearHolidays_GREEK(iSelYear)
  262.         Case cLANGUAGE_TURKISH
  263.             Call FindWholeYearHolidays_TRK(iSelYear)
  264.         Case cLANGUAGE_POLISH
  265.             Call FindWholeYearHolidays_PL(iSelYear)
  266.         Case cLANGUAGE_FINNISH
  267.             Call FindWholeYearHolidays_FI(iSelYear)
  268.     End Select
  269.  
  270.     Call CalInsertOwnDataInTables(iSelYear)
  271.  
  272.     If DlgCalModel.optYear.State = 1 Then
  273.         oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
  274.         oSheet = oSheets.GetbyIndex(0)
  275.         oSheet.Name = sCalendarTitle$ + " " + iSelYear
  276.         oDocument.AddActionLock
  277.         Call CalCreateYearTable(iSelYear)
  278.     ElseIf DlgCalModel.optMonth.State = 1 Then
  279.         Dim iMonth
  280.         iMonth = DlgCalModel.lstMonth.SelectedItems(0) + 1
  281.         oSheets.RemovebyName(oSheets.GetbyIndex(1).Name)
  282.         oSheet = oSheets.GetbyIndex(0)
  283.         If sMonthTitle = "" Then
  284.             oSheet.Name = cCalLongMonthNames(iMonth-1)
  285.         Else
  286.             oSheet.Name = sMonthTitle + " " + cCalLongMonthNames(iMonth-1)
  287.         End If
  288.         oDocument.AddActionLock
  289.         Call CalCreateMonthTable(iSelYear, iMonth)
  290.     End If
  291.  
  292.     oDocument.RemoveActionLock
  293.     oSheet.protect("")
  294.     oStatusLine.End
  295.     DlgCalendar.EndExecute()
  296.     bCancelTask = True
  297. End Sub
  298. </script:module>