merge the formfield patch from ooo-build
[ooovba.git] / wizards / source / schedule / CalendarMain.xba
blobbfe49121dbd3fc85ca4a72806933b3901e9f0773
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
5 Const _DEBUG = 0
7 &apos; CalenderMain
8 Public sCurLangLocale as String
9 Public sCurCountryLocale as String
10 &apos; This flag serves as a query if the individual Data should be saved
11 Public bCalOwnDataChanged as Boolean
13 &apos;BankHoliday Functions
14 Public CalBankholidayName$ (1 To 374)
15 Public CalTypeOfBankHoliday% (1 To 374)
17 Public Const cHolidayType_None = 0
18 Public Const cHolidayType_Full = 1
19 Public Const cHolidayType_Half = 2
20 Public Const cHolidayType_Own = 4
22 Public cCalSubcmdDeleteSelect_DeleteSelEntry$
23 Public cCalSubcmdDeleteSelect_DeleteSelEntryTitle$
24 Public cCalSubcmdSwitchOwnDataOrGeneral_Back$
25 Public cCalSubcmdSwitchOwnDataOrGeneral_OwnData$
27 &apos;Language
28 Public cCalLongMonthNames(11) as String
29 Public cCalShortMonthNames(11) as String
31 Public sBitmapFilename$
32 Public sCalendarTitle$, sMonthTitle$, sWizardTitle$, sError$
33 Public cCalStyleWorkday$, cCalStyleWeekend$
35 Public CalChoosenLand as Integer
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
44 &apos; BL* means &quot;BundesLand&quot; (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
62 Public DlgCalendar as Object
63 Public DlgCalModel as Object
64 Public lDateFormat as Long
65 Public lDateStandardFormat as Long
69 Sub CalAutopilotTable()
70 Dim BitmapDir as String
71 Dim iThisMonth as Integer
73 &apos;On Error Goto ErrorHandler
74 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
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(&quot;Schedule&quot;, &quot;DlgCalendar&quot;)
82 DlgCalModel = DlgCalendar.Model
83 LoadLanguage(sCurLangLocale)
84 CalInitGlobalVariablesDate()
85 BitmapDir = GetOfficeSubPath(&quot;Template&quot;,&quot;wizard/bitmap&quot;)
86 DlgCalModel.imgCountry.ImageURL = BitmapDir &amp; sBitmapFilename
87 CalChoosenLand = -2
88 CalLoadOwnData()
90 With DlgCalModel
91 .cmdDelete.Enabled = False
92 .lstMonth.StringItemList() = cCalShortMonthNames()
93 Select Case sCurLangLocale
94 Case cLANGUAGE_JAPANESE
95 .lstOwnData.FontName = &quot;HG MinochoL&quot;
96 .txtEvent.FontName = &quot;HG MinchoL&quot;
97 Case cLANGUAGE_CHINESE
98 If oDocument.CharLocale.Country = &quot;CN&quot; Then
99 .lstOwnData.FontName = &quot;FZ Song Ti&quot;
100 .txtEvent.FontName = &quot;FZ Song Ti&quot;
101 Else
102 .lstOwnData.FontName = &quot;FZ Ming Ti&quot;
103 .txtEvent.FontName = &quot;FZ Ming Ti&quot;
104 End If
105 Case &quot;ko&quot;
106 .lstOwnData.FontName = &quot;Sun Gulim&quot;
107 .txtEvent.FontName = &quot;Sun Gulim&quot;
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() &apos; month
117 iThisMonth = Month(Now)
118 DlgCalendar.GetControl(&quot;lstMonth&quot;).SelectItemPos(iThisMonth-1, True)
119 DlgCalendar.GetControl(&quot;lstHolidays&quot;).SelectItemPos(0,True)
120 DlgCalModel.cmdGoOn.DefaultButton = True
121 ToggleWindow(True)
122 DlgCalendar.GetControl(&quot;lblHolidays&quot;).Visible = sCurLangLocale = cLANGUAGE_GERMAN
123 DlgCalendar.GetControl(&quot;lstHolidays&quot;).Visible = sCurLangLocale = cLANGUAGE_GERMAN
124 fHeightCorrFactor = DlgCalendar.GetControl(&quot;imgCountry&quot;).Size.Height/198
125 fWidthCorrFactor = DlgCalendar.GetControl(&quot;imgCountry&quot;).Size.Width/166
126 DlgCalendar.Execute()
127 DlgCalendar.Dispose()
128 Exit Sub
129 ErrorHandler:
130 MsgBox(sError$, 16, sWizardTitle$)
131 End Sub
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 = &quot;TT.MMM&quot;
141 Case cLANGUAGE_ENGLISH
142 DateFormatString = &quot;MMM DD&quot;
143 Case cLANGUAGE_FRENCH
144 DateFormatString = &quot;JJ/MMM&quot;
145 Case cLANGUAGE_ITALIAN
146 DateFormatString = &quot;GG/MMM&quot;
147 Case cLANGUAGE_SPANISH
148 DateFormatString = &quot;DD/MMM&quot;
149 Case cLANGUAGE_PORTUGUESE
150 If sCurCountryLocale = &quot;BR&quot; Then
151 DateFormatString = &quot;DD/MMM&quot;
152 Else
153 DateFormatString = &quot;DD-MMM&quot;
154 End If
155 Case cLANGUAGE_DUTCH
156 DateFormatString = &quot;DD/MMM&quot;
157 Case cLANGUAGE_SWEDISH
158 DateFormatString = &quot;MMM DD&quot;
159 Case cLANGUAGE_DANISH
160 DateFormatString = &quot;DD-MMM&quot;
161 Case cLANGUAGE_POLISH
162 DateFormatString = &quot;MMM DD&quot;
163 Case cLANGUAGE_RUSSIAN
164 DateFormatString = &quot;MMM DD&quot;
165 Case cLANGUAGE_JAPANESE
166 DateFormatString = &quot;M月D日&quot;
167 Case cLANGUAGE_CHINESE
168 If sCurCountryLocale = &quot;TW&quot; Then
169 DateFormatString = &quot;MMMMD&quot; &amp;&quot;&quot;&quot;&quot; &amp; &quot;&quot; &amp; &quot;&quot;&quot;&quot;
170 Else
171 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;
172 End If
173 Case cLANGUAGE_GREEK
174 DateFormatString = &quot;DD/MMM&quot;
175 Case cLANGUAGE_TURKISH
176 DateFormatString = &quot;DD/MMM&quot;
177 Case cLANGUAGE_POLISH
178 DateFormatString = &quot;MMM DD&quot;
179 Case cLANGUAGE_FINNISH
180 DateFormatString = &quot;PP.KKK&quot;
181 End Select
183 lDateFormat = AddNumberFormat(oFormats, DateFormatString, oDocument.CharLocale)
184 lDateStandardFormat = oFormats.getStandardFormat(com.sun.star.util.NumberFormat.DATE, oDocument.CharLocale)
186 &apos; lDateStandardFormat = AddNumberFormat(oFormats, StandardDateFormatString, oDocument.CharLocale)
187 oNumberFormatter = createUNOService(&quot;com.sun.star.util.NumberFormatter&quot;)
188 oNumberFormatter.attachNumberFormatsSupplier(oDocument)
189 End Sub
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
202 Sub CalChooseCalendar()
203 With DlgCalModel
204 .lstMonth.Enabled = .optMonth.State = 1
205 .lblMonth.Enabled = .optMonth.State = 1
206 End With
207 End Sub
210 Sub CalcmdCancel()
211 Call CalSaveOwnData()
212 DlgCalendar.EndExecute
213 End Sub
216 Sub CalcmdOk()
217 &apos; cmdOk is called when the Button &apos;Read&apos; is clicked on
218 &apos; It is either given out a month or a year
219 Dim i, iSelYear as Integer
220 Dim SelYear as String
221 &apos; DlgCalendar.Visible = False
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()) &gt; -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 = &quot;TW&quot; 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
274 Call CalInsertOwnDataInTables(iSelYear)
276 If DlgCalModel.optYear.State = 1 Then
277 oSheets.RemovebyName(oSheets.GetbyIndex(0).Name)
278 oSheet = oSheets.GetbyIndex(0)
279 oSheet.Name = sCalendarTitle$ + &quot; &quot; + 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 = &quot;&quot; Then
288 oSheet.Name = cCalLongMonthNames(iMonth-1)
289 Else
290 oSheet.Name = sMonthTitle + &quot; &quot; + cCalLongMonthNames(iMonth-1)
291 End If
292 oDocument.AddActionLock
293 Call CalCreateMonthTable(iSelYear, iMonth)
294 End If
296 oDocument.RemoveActionLock
297 oSheet.protect(&quot;&quot;)
298 oStatusLine.End
299 DlgCalendar.EndExecute()
300 bCancelTask = True
301 End Sub
302 </script:module>