xref: /AOO41X/main/wizards/source/schedule/CalendarMain.xba (revision 83137a03adbb58b5b3bdafefefa1e93de35e0011)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="CalendarMain" script:language="StarBasic">Option Explicit
24
25Const _DEBUG = 0
26
27&apos; CalenderMain
28Public sCurLangLocale as String
29Public sCurCountryLocale as String
30&apos; This flag serves as a query if the individual Data should be saved
31Public bCalOwnDataChanged as Boolean
32
33&apos;BankHoliday Functions
34Public CalBankholidayName$ (1 To 374)
35Public CalTypeOfBankHoliday% (1 To 374)
36
37Public Const cHolidayType_None = 0
38Public Const cHolidayType_Full = 1
39Public Const cHolidayType_Half = 2
40Public Const cHolidayType_Own = 4
41
42Public cCalSubcmdDeleteSelect_DeleteSelEntry$
43Public cCalSubcmdDeleteSelect_DeleteSelEntryTitle$
44Public cCalSubcmdSwitchOwnDataOrGeneral_Back$
45Public cCalSubcmdSwitchOwnDataOrGeneral_OwnData$
46
47&apos;Language
48Public cCalLongMonthNames(11) as String
49Public cCalShortMonthNames(11) as String
50
51Public sBitmapFilename$
52Public sCalendarTitle$, sMonthTitle$, sWizardTitle$, sError$
53Public cCalStyleWorkday$, cCalStyleWeekend$
54
55Public CalChoosenLand as Integer
56
57Public oDocument as Object
58Public oSheets as Object
59Public oSheet as Object
60Public oStatusLine as Object
61Public bCancelTask as Boolean
62Public oNumberFormatter as Object
63
64&apos; BL* means &quot;BundesLand&quot; (for german states only)
65Public CONST CalBLBayern         = 1
66Public CONST CalBLBadenWuert     = 2
67Public CONST CalBLBerlin         = 3
68Public CONST CalBLBremen         = 4
69Public CONST CalBLBrandenburg    = 5
70Public CONST CalBLHamburg        = 6
71Public CONST CalBLHessen         = 7
72Public CONST CalBLMeckPomm       = 8
73Public CONST CalBLNiedersachsen  = 9
74Public CONST CalBLNordrheinWest  = 10
75Public CONST CalBLRheinlandPfalz = 11
76Public CONST CalBLSaarland       = 12
77Public CONST CalBLSachsen        = 13
78Public CONST CalBLSachsenAnhalt  = 14
79Public CONST CalBLSchlHolstein   = 15
80Public CONST CalBLThueringen     = 16
81
82Public DlgCalendar as Object
83Public DlgCalModel as Object
84Public lDateFormat as Long
85Public lDateStandardFormat as Long
86
87
88
89Sub CalAutopilotTable()
90Dim BitmapDir as String
91Dim iThisMonth as Integer
92
93&apos;On Error Goto ErrorHandler
94    BasicLibraries.LoadLibrary(&quot;Tools&quot;)
95    bSelectByMouseMove = True
96    oDocument = ThisComponent
97    oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
98    ToggleWindow(False)
99    sCurLangLocale = oDocument.CharLocale.Language
100    sCurCountryLocale = oDocument.CharLocale.Country
101    DlgCalendar = LoadDialog(&quot;Schedule&quot;, &quot;DlgCalendar&quot;)
102    DlgCalModel = DlgCalendar.Model
103    LoadLanguage(sCurLangLocale)
104    CalInitGlobalVariablesDate()
105    BitmapDir = GetOfficeSubPath(&quot;Template&quot;,&quot;../wizard/bitmap&quot;)
106    DlgCalModel.imgCountry.ImageURL = BitmapDir &amp; sBitmapFilename
107    CalChoosenLand = -2
108    CalLoadOwnData()
109
110    With DlgCalModel
111        .cmdDelete.Enabled = False
112        .lstMonth.StringItemList() = cCalShortMonthNames()
113        Select Case sCurLangLocale
114            Case cLANGUAGE_JAPANESE
115                .lstOwnData.FontName = &quot;HG MinochoL&quot;
116                .txtEvent.FontName = &quot;HG MinchoL&quot;
117            Case cLANGUAGE_CHINESE
118                If oDocument.CharLocale.Country = &quot;CN&quot; Then
119                    .lstOwnData.FontName = &quot;FZ Song Ti&quot;
120                    .txtEvent.FontName = &quot;FZ Song Ti&quot;
121                Else
122                    .lstOwnData.FontName = &quot;FZ Ming Ti&quot;
123                    .txtEvent.FontName = &quot;FZ Ming Ti&quot;
124                End If
125            Case &quot;ko&quot;
126                .lstOwnData.FontName = &quot;Sun Gulim&quot;
127                .txtEvent.FontName = &quot;Sun Gulim&quot;
128        End Select
129        .lstOwnEventMonth.StringItemList() = cCalShortMonthNames()
130        .optYear.State = 1
131        .txtYear.Value = Year(Now())
132        .txtYear.Tag = .txtYear.Value
133        .Step = 1
134    End With
135    SetupNumberFormatter(sCurLangLocale, sCurCountryLocale)
136    CalChooseCalendar()  &apos; month
137    iThisMonth = Month(Now)
138    DlgCalendar.GetControl(&quot;lstMonth&quot;).SelectItemPos(iThisMonth-1, True)
139    DlgCalendar.GetControl(&quot;lstHolidays&quot;).SelectItemPos(0,True)
140    DlgCalModel.cmdGoOn.DefaultButton = True
141    ToggleWindow(True)
142    DlgCalendar.GetControl(&quot;lblHolidays&quot;).Visible = sCurLangLocale  = cLANGUAGE_GERMAN
143    DlgCalendar.GetControl(&quot;lstHolidays&quot;).Visible = sCurLangLocale  = cLANGUAGE_GERMAN
144    fHeightCorrFactor = DlgCalendar.GetControl(&quot;imgCountry&quot;).Size.Height/198
145    fWidthCorrFactor = DlgCalendar.GetControl(&quot;imgCountry&quot;).Size.Width/166
146    DlgCalendar.Execute()
147    DlgCalendar.Dispose()
148    Exit Sub
149ErrorHandler:
150    MsgBox(sError$, 16, sWizardTitle$)
151End Sub
152
153
154Sub SetupNumberFormatter(sCurLangLocale as String, sCurCountryLocale as String)
155Dim oFormats as Object
156Dim DateFormatString as String
157    oFormats = oDocument.getNumberFormats()
158    Select Case sCurLangLocale
159        Case cLANGUAGE_GERMAN
160            DateFormatString = &quot;TT.MMM&quot;
161        Case cLANGUAGE_ENGLISH
162            DateFormatString = &quot;MMM DD&quot;
163        Case cLANGUAGE_FRENCH
164            DateFormatString = &quot;JJ/MMM&quot;
165        Case cLANGUAGE_ITALIAN
166            DateFormatString = &quot;GG/MMM&quot;
167        Case cLANGUAGE_SPANISH
168            DateFormatString = &quot;DD/MMM&quot;
169        Case cLANGUAGE_PORTUGUESE
170            If sCurCountryLocale = &quot;BR&quot; Then
171                DateFormatString = &quot;DD/MMM&quot;
172            Else
173                DateFormatString = &quot;DD-MMM&quot;
174            End If
175        Case cLANGUAGE_DUTCH
176            DateFormatString = &quot;DD/MMM&quot;
177        Case cLANGUAGE_SWEDISH
178            DateFormatString = &quot;MMM DD&quot;
179        Case cLANGUAGE_DANISH
180            DateFormatString = &quot;DD-MMM&quot;
181        Case cLANGUAGE_POLISH
182            DateFormatString = &quot;MMM DD&quot;
183        Case cLANGUAGE_RUSSIAN
184            DateFormatString = &quot;MMM DD&quot;
185        Case cLANGUAGE_JAPANESE
186            DateFormatString = &quot;M月D日&quot;
187        Case cLANGUAGE_CHINESE
188            If sCurCountryLocale = &quot;TW&quot; Then
189                DateFormatString = &quot;MMMMD&quot; &amp;&quot;&quot;&quot;&quot; &amp; &quot;日&quot; &amp; &quot;&quot;&quot;&quot;
190            Else
191                DateFormatString = &quot;M&quot; &amp; &quot;&quot;&quot;&quot; &amp; &quot;月&quot; &amp; &quot;&quot;&quot;&quot; &amp; &quot;D&quot; &amp;&quot;&quot;&quot;&quot; &amp; &quot;日&quot; &amp; &quot;&quot;&quot;&quot;
192            End If
193        Case cLANGUAGE_GREEK
194            DateFormatString = &quot;DD/MMM&quot;
195        Case cLANGUAGE_TURKISH
196            DateFormatString = &quot;DD/MMM&quot;
197        Case cLANGUAGE_POLISH
198            DateFormatString = &quot;MMM DD&quot;
199        Case cLANGUAGE_FINNISH
200            DateFormatString = &quot;PP.KKK&quot;
201    End Select
202
203    lDateFormat = AddNumberFormat(oFormats, DateFormatString, oDocument.CharLocale)
204    lDateStandardFormat = oFormats.getStandardFormat(com.sun.star.util.NumberFormat.DATE, oDocument.CharLocale)
205
206&apos;  lDateStandardFormat = AddNumberFormat(oFormats, StandardDateFormatString, oDocument.CharLocale)
207    oNumberFormatter = createUNOService(&quot;com.sun.star.util.NumberFormatter&quot;)
208    oNumberFormatter.attachNumberFormatsSupplier(oDocument)
209End Sub
210
211
212Function AddNumberFormat(oNumberFormats as Object, FormatString as String, oLocale as Object) as Long
213Dim lLocDateFormat as Long
214    lLocDateFormat = oNumberFormats.QueryKey(FormatString, oLocale, True)
215    If lLocDateFormat = -1 Then
216        lLocDateFormat = oNumberFormats.addNew(FormatString, oLocale)
217    End If
218    AddNumberFormat() = lLocDateFormat
219End Function
220
221
222Sub CalChooseCalendar()
223    With DlgCalModel
224        .lstMonth.Enabled = .optMonth.State = 1
225        .lblMonth.Enabled = .optMonth.State = 1
226    End With
227End Sub
228
229
230Sub CalcmdCancel()
231    Call CalSaveOwnData()
232    DlgCalendar.EndExecute
233End Sub
234
235
236Sub CalcmdOk()
237    &apos; cmdOk is called when the Button &apos;Read&apos; is clicked on
238    &apos; It is either given out a month or a year
239Dim i, iSelYear as Integer
240Dim SelYear as String
241&apos;  DlgCalendar.Visible = False
242
243    oSheets = oDocument.sheets
244    Call CalSaveOwnData()
245    UnprotectSheets(oSheets)
246    oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
247    iSelYear = DlgCalModel.txtYear.Value
248    Select Case sCurLangLocale
249        Case cLANGUAGE_GERMAN
250            If Ubound(DlgCalModel.lstHolidays.SelectedItems()) &gt; -1 Then
251                CalChoosenLand = DlgCalModel.lstHolidays.SelectedItems(0)
252            Else
253                CalChoosenLand = 0
254            End If
255            Call CalFindWholeYearHolidays_GERMANY(iSelYear, CalChoosenLand)
256        Case cLANGUAGE_ENGLISH
257            Call FindWholeYearHolidays_US(iSelYear)
258        Case cLANGUAGE_FRENCH
259            Call FindWholeYearHolidays_FRANCE(iSelYear)
260        Case cLANGUAGE_ITALIAN
261            Call FindWholeYearHolidays_ITA(iSelYear)
262        Case cLANGUAGE_SPANISH
263            Call FindWholeYearHolidays_SPAIN(iSelYear)
264        Case cLANGUAGE_PORTUGUESE
265            Call FindWholeYearHolidays_PORT(iSelYear)
266        Case cLANGUAGE_DUTCH
267            Call FindWholeYearHolidays_NL(iSelYear)
268        Case cLANGUAGE_SWEDISH
269            Call FindWholeYearHolidays_SWED(iSelYear)
270        Case cLANGUAGE_DANISH
271            Call FindWholeYearHolidays_DK(iSelYear)
272        Case cLANGUAGE_POLISH
273            Call FindWholeYearHolidays_PL(iSelYear)
274        Case cLANGUAGE_RUSSIAN
275            Call FindWholeYearHolidays_RU(iSelYear)
276        Case cLANGUAGE_JAPANESE
277            Call FindWholeYearHolidays_JP(iSelYear)
278        Case cLANGUAGE_CHINESE
279            If sCurCountryLocale = &quot;TW&quot; Then
280                Call FindWholeYearHolidays_TW(iSelYear)
281            Else
282                Call FindWholeYearHolidays_CN(iSelYear)
283            End If
284        Case cLANGUAGE_GREEK
285            Call FindWholeYearHolidays_GREEK(iSelYear)
286        Case cLANGUAGE_TURKISH
287            Call FindWholeYearHolidays_TRK(iSelYear)
288        Case cLANGUAGE_POLISH
289            Call FindWholeYearHolidays_PL(iSelYear)
290        Case cLANGUAGE_FINNISH
291            Call FindWholeYearHolidays_FI(iSelYear)
292    End Select
293
294    Call CalInsertOwnDataInTables(iSelYear)
295
296    If DlgCalModel.optYear.State = 1 Then
297        oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
298        oSheet = oSheets.GetbyIndex(0)
299        oSheet.Name = sCalendarTitle$ + &quot; &quot; + iSelYear
300        oDocument.AddActionLock
301        Call CalCreateYearTable(iSelYear)
302    ElseIf DlgCalModel.optMonth.State = 1 Then
303        Dim iMonth
304        iMonth = DlgCalModel.lstMonth.SelectedItems(0) + 1
305        oSheets.RemovebyName(oSheets.GetbyIndex(1).Name)
306        oSheet = oSheets.GetbyIndex(0)
307        If sMonthTitle = &quot;&quot; Then
308            oSheet.Name = cCalLongMonthNames(iMonth-1)
309        Else
310            oSheet.Name = sMonthTitle + &quot; &quot; + cCalLongMonthNames(iMonth-1)
311        End If
312        oDocument.AddActionLock
313        Call CalCreateMonthTable(iSelYear, iMonth)
314    End If
315
316    oDocument.RemoveActionLock
317    oSheet.protect(&quot;&quot;)
318    oStatusLine.End
319    DlgCalendar.EndExecute()
320    bCancelTask = True
321End Sub
322</script:module>
323