update dev300-m58
[ooovba.git] / wizards / source / depot / Currency.xba
blobc432fecc26612a400370213d6f4ecc24475664d3
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="Currency" script:language="StarBasic">REM ***** BASIC *****
4 Option Explicit
6 Dim bDoUnLoad as Boolean
9 Sub Startup()
10 Dim i as Integer
11 Dim a as Integer
12 Dim ListString as String
13 Dim MarketListBoxControl as Object
14 Initialize(False)
15 MarketListBoxControl = DlgStartUp.GetControl(&quot;lstMarkets&quot;)
16 a = 0
17 For i = 0 To Ubound(sMarket(),1)
18 ListString = sMarket(i,0)
19 If sMarket(i,0) &lt;&gt; &quot;&quot; Then
20 If sMarket(i,3) = &quot;&quot; Then
21 ListString = ListString &amp; &quot; (&quot; &amp; sNoInternetUpdate &amp; &quot;)&quot;
22 Else
23 ListString = ListString &amp; &quot; (&quot; &amp; sMarketplace &amp; &quot; &quot; &amp; sMarket(i,2) &amp; &quot;)&quot;
24 End If
25 MarketListBoxControl.AddItem(ListString, a)
26 a = a + 1
27 End If
28 Next i
29 MarketListBoxControl.SelectItemPos(GlobListIndex, True)
30 DlgStartUp.Title = sDepotCurrency
31 DlgStartUp.Model.cmdGoOn.DefaultButton = True
32 DlgStartUp.GetControl(&quot;lstMarkets&quot;).SetFocus()
33 DlgStartUp.Execute()
34 DlgStartUp.Dispose()
35 End Sub
38 Sub EnableGoOnButton()
39 StartUpModel.cmdGoOn.Enabled = True
40 StartUpModel.cmdGoOn.DefaultButton = True
41 End Sub
44 Sub CloseStartUpDialog()
45 DlgStartUp.EndExecute()
46 &apos; oDocument.Dispose()
47 End Sub
50 Sub DisposeDocument()
51 If bDoUnload Then
52 oDocument.Dispose()
53 End If
54 End Sub
57 Sub ChooseMarket(Optional aEvent)
58 Dim Index as Integer
59 Dim bIsDocLanguage as Boolean
60 Dim bIsDocCountry as Boolean
61 oInternetModel = GetControlModel(oDocument.Sheets(0), &quot;CmdInternet&quot;)
62 If Not IsMissing(aEvent) Then
63 Index = StartupModel.lstMarkets.SelectedItems(0)
64 oInternetModel.Tag = Index
65 Else
66 Index = oInternetModel.Tag
67 End If
68 oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
69 sCurCurrency = sMarket(Index,1)
70 If Index = 0 Then
71 HistoryChartSource = sMarket(Index,4)
72 End If
73 sCurStockIDLabel = sMarket(Index,5)
74 sCurExtension = sMarket(Index,8)
75 iValueCol = Val(sMarket(Index,10)
76 If Instr(sCurExtension,&quot;;&quot;) &lt;&gt; 0 Then
77 &apos; Take the german extension as the stock place is Frankfurt
78 sCurExtension = &quot;407&quot;
79 End If
80 sCurChartSource = sMarket(Index,3)
81 bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) &lt;&gt; 0
82 bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) &lt;&gt; 0 OR SDocCountry = &quot;&quot;
83 sCurSeparator = sMarket(Index,9)
84 TransactModel.txtRate.CurrencySymbol = sCurCurrency
85 TransactModel.txtFix.CurrencySymbol = sCurCurrency
86 TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
87 bEnableMarket = Index = 0
88 bEnableInternet = sCurChartSource &lt;&gt; &quot;&quot;
89 oMarketModel.Enabled = bEnableMarket
90 oInternetModel.Enabled = bEnableInternet
91 If Not IsMissing(aEvent) Then
92 ConvertStylesCurrencies()
93 bDoUnload = False
94 DlgStartUp.EndExecute()
95 End If
96 End Sub
99 Sub ConvertStylesCurrencies()
100 Dim m as integer
101 Dim aStyleFormat as Object
102 Dim StyleName as String
103 Dim bAddToList as Boolean
104 Dim oStyle as Object
105 Dim oStyles as Object
106 UnprotectSheets(oSheets)
107 oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
108 oStyles = oDocument.StyleFamilies.GetbyIndex(0)
109 For m = 0 To oStyles.count-1
110 oStyle = oStyles.GetbyIndex(m)
111 StyleName = oStyle.Name
112 bAddToList = CheckFormatType(oStyle)
113 If bAddToList Then
114 SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
115 End If
116 Next m
117 ProtectSheets(oSheets)
118 End Sub
121 Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
122 Dim nFormatLanguage as Integer
123 Dim nFormatDecimals as Integer
124 Dim nFormatLeading as Integer
125 Dim bFormatLeading as Integer
126 Dim bFormatNegRed as Integer
127 Dim bFormatThousands as Integer
128 Dim aNewStr as String
129 Dim iNumberFormat as Long
130 Dim sSimpleStr as String
131 Dim nSimpleKey as Long
132 Dim aFormat()
133 Dim oLocale as New com.sun.star.lang.Locale
134 &apos; Numberformat with the new Symbol as Base for new Format
135 sSimpleStr = &quot;0 [$&quot; &amp; sNewSymbol &amp; &quot;-&quot; &amp; sNewExtension &amp; &quot;]&quot;
136 nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
137 On Local Error Resume Next
138 iNumberFormat = oObject.NumberFormat
139 If Err &lt;&gt; 0 Then
140 Msgbox &quot;Error Reading the Number Format&quot;
141 Resume CLERROR
142 End If
144 On Local Error GoTo NOKEY
145 aFormat() = oFormats.getByKey(iNumberFormat)
146 On Local Error GoTo 0
147 &apos; set new currency format with according settings
148 nFormatDecimals = aFormat.Decimals
149 nFormatLeading = aFormat.LeadingZeros
150 bFormatNegRed = aFormat.NegativeRed
151 bFormatThousands = aFormat.ThousandsSeparator
152 oLocale = aFormat.Locale
153 aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
154 oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
155 NOKEY:
156 If Err &lt;&gt; 0 Then
157 Resume CLERROR
158 End If
159 CLERROR:
160 End Sub
163 Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
164 Dim nRetkey
165 nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
166 If nRetKey = -1 Then
167 nRetKey = oFormats.addNew( aFormatStr, oLocale )
168 If nRetKey = -1 Then nRetKey = 0
169 End If
170 Numberformat = nRetKey
171 End Function
174 Function CheckFormatType(oStyle as Object)
175 Dim oFormatofObject as Object
176 oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
177 CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
178 End Function</script:module>