/usr/lib/libreoffice/share/extensions/DmathsAddon/OOoGdmath/AdditionCode.xba is in libreoffice-dmaths 3.4+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AdditionCode" script:language="StarBasic">'OOoGdmath
'Copyright (C) 2005-2009 Gilles Daurat
'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Option Explicit
Dim oAdditionForm as Object
Sub Main
oAdditionForm = LoadDialog("OOoGdmath","AdditionForm")
ChangeTitreDialog(oAdditionForm)
' RestaureForm(oAdditionForm)
oAdditionForm.Execute()
End Sub
Private Sub AdditionCode_CheckBox1_Click()
oAdditionForm.Model.TextBox3.Enabled = oAdditionForm.Model.CheckBox1.State
End Sub
Private Sub AdditionCode_CommandButton1_Click()
oAdditionForm.EndExecute()
SauveForm(oAdditionForm)
Operation(oAdditionForm.Model.TextBox1.Text, oAdditionForm.Model.CheckBox1.State)
End Sub
Private Sub AdditionCode_CommandButton2_Click()
oAdditionForm.EndExecute()
End Sub
Private Sub AdditionCode_Image1_Click()
ChangeCouleur oAdditionForm.Model.Image1
End Sub
Private Sub AdditionCode_TextBox3_Change()
oAdditionForm.Model.TextBox3.Text = Left$(oAdditionForm.Model.TextBox3.Text, 1)
End Sub
Sub InsereAdditionSoustractionSexa(tableau$(), Operation)
Dim Resultat$(3)
Dim l,h, retenue, i, resnum, terme1, terme2, resul
Dim Shapes as Object
InitialiseDessin(False)
Shapes=InitialiseGroupe()
DimensionTexte "8",12,l,h
Select Case Operation
Case "+"
retenue = 0
For i = 2 To 0 Step -1
tableau$(0,i)=right("00" & tableau$(0,i),2)
tableau$(1,i)=right("00" & tableau$(1,i),2)
resnum = Val(tableau$(0, i)) + Val(tableau$(1, i)) + retenue
If resnum > 59 Then
resnum = resnum - 60
retenue = 1
else
retenue = 0
End If
Resultat$(i) = Right$("00" + Trim(Str(resnum)), 2)
Next i
Case "-"
retenue = 0
For i = 2 To 0 Step -1
tableau$(0,i)=right("00" & tableau$(0,i),2)
tableau$(1,i)=right("00" & tableau$(1,i),2)
If Val(tableau$(0, i)) < Val(tableau$(1, i)) Then
resnum = 60 + Val(tableau$(0, i)) - (Val(tableau$(1, i)) + retenue)
retenue = 1
Else
resnum = Val(tableau$(0, i)) - (Val(tableau$(1, i)) + retenue)
retenue = 0
End If
Resultat$(i) = Right$("00" + Trim(Str(resnum)), 2)
Next i
End Select
if tableau$(0,0)="00" and tableau$(1,0)="00" then
terme1 = MIif(Left$(tableau$(0, 1), 1) = "0", Right$(tableau$(0, 1), 1), tableau$(0, 1)) & "m" & tableau$(0, 2) & "s"
terme2 = Operation & MIif(Left$(tableau$(1, 1), 1) = "0", Right$(tableau$(1, 1), 1), tableau$(1, 1)) & "m" & tableau$(1, 2) & "s"
resul = MIif(Left$(Resultat$(1), 1) = "0", Right$(Resultat$(1), 1), Resultat$(1)) & "m" & Resultat$(2) & "s"
else
terme1 = MIif(Left$(tableau$(0, 0) = "0", Right$(tableau$(0, 0), 1), tableau$(0, 0)) & "h" & tableau$(0, 1) & "m" & tableau$(0, 2) & "s"
terme2 = Operation & MIif(Left$(tableau$(1, 0), 1) = "0", Right$(tableau$(1, 0), 1), tableau$(1, 0)) & "h" & tableau$(1, 1) & "m" & tableau$(1, 2) & "s"
resul = MIif(Left$(Resultat$(0), 1) = "0", Right$(Resultat$(0), 1), Resultat$(0)) & "h" & Resultat$(1) & "m" & Resultat$(2) & "s"
End If
AfficheTexte 10, 1, terme1, False, 0, Shapes, l, h
AfficheTexte 10, 2, terme2, False, 0, Shapes, l, h
TraceLigneGroupe Shapes, "s", oAdditionForm.Model.Image1
AfficheTexte 10, 3, resul, False, 0, Shapes, l, h
GroupeObjet(Shapes)
TermineDessin()
End Sub
Sub DimensionTexte(texte,taillefonte,l,h)
Dim xShape As Object
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
xShape = oDocumentDessin.createInstance("com.sun.star.drawing.TextShape")
aPoint.x = 0
aPoint.y = 0
aSize.Width = 10
aSize.Height = 10
xShape.Position = aPoint
xShape.Size=aSize
oDocumentDessin.DrawPages.GetByIndex(0).add(xShape)
xShape.String = texte
xShape.Text.CharHeight=taillefonte
xShape.Text.TextAutoGrowWidth=True
xShape.Text.TextAutoGrowHeight=True
l=xShape.Size.Width
h=xShape.Size.Height
oDocumentDessin.DrawPages.GetByIndex(0).remove(xShape)
End Sub
Function AfficheRetenue(x, y, t, sgroupe As Object,l,h) as Object
Dim j As Integer
Dim c As String
Dim xShape As Object
Dim aPoint As New com.sun.star.awt.Point
Dim n
For j = 1 To Len(t)
c = Mid$(t, Len(t) + 1 - j, 1)
if c<>"0" then
xShape = oDocumentDessin.createInstance("com.sun.star.drawing.TextShape")
oDocumentDessin.DrawPages.GetByIndex(0).add(xShape)
xShape.String = c
xShape.Text.CharFontName = OOoGdmath_NomPolice
xShape.Text.CharHeight = OOoGdmath_TaillePolice/2.4
xShape.Text.CharPosture=com.sun.star.awt.FontSlant.ITALIC
xShape.Text.TextAutoGrowWidth=True
xShape.Text.TextAutoGrowHeight=True
aPoint.x = (x-j)*l*2
aPoint.y = y*h
xShape.Position = aPoint
If Not IsMissing(sgroupe) Then sgroupe.add(xShape)
n=1
End if
Next j
if n=1 then
AfficheRetenue()=xShape
else
AfficheRetenue()=Nothing
end if
End Function
Function AfficheTexte(x, y, t, virgule, place, sgroupe As Object,l,h) as Object
Dim j As Integer
Dim c As String
Dim xShape As Object
Dim aPoint As New com.sun.star.awt.Point
If virgule Then
While place >= Len(t)
t = "0" & t
Wend
End If
For j = 1 To Len(t)
c = Mid$(t, Len(t) + 1 - j, 1)
If c = "m" Then c = "min"
xShape = oDocumentDessin.createInstance("com.sun.star.drawing.TextShape")
oDocumentDessin.DrawPages.GetByIndex(0).add(xShape)
If virgule And j - 1 = place Then
xShape.String = c & ","
Else
xShape.String = c
End If
if c=chr(180) then
xShape.Text.CharFontName="Symbol"
else
xShape.Text.CharFontName = OOoGdmath_NomPolice
end if
xShape.Text.CharHeight = OOoGdmath_TaillePolice
xShape.Text.TextAutoGrowWidth=True
xShape.Text.TextAutoGrowHeight=True
aPoint.x = (x-j)*l*2
aPoint.y = y*h
xShape.Position = aPoint
If Not IsMissing(sgroupe) Then sgroupe.add(xShape)
Next j
AfficheTexte()=xShape
End Function
Sub RemplaceChiffreCaractere(texte$, Caractere)
Dim k, nTexte$, j
Dim a$
k = Len(texte$)
nTexte$ = ""
For j = 1 To k
a$ = Mid$(texte$, j, 1)
If a$ >= "0" And a$ <= "9" Then
nTexte$ = nTexte$ & Caractere
Else
nTexte$ = nTexte$ & a$
End If
Next j
texte$ = nTexte$
End Sub
Sub Operation(UnTexte As String, Optional Resultat as Boolean)
Dim Param$(2, 3)
Dim parametre() as string
Dim operande() as string
Dim texte$, a, b, texte1$, texte2$, noperande1, i, noperande2, MM, m, terme1, terme2
Dim uneOperation
if instr(1,unTexte,"+")<>0 then UneOperation="+"
if instr(1,unTexte,"-")<>0 then UneOperation="-"
if instr(1,unTexte,"*")<>0 then UneOperation="*"
if instr(1,unTexte,"/")<>0 then UneOperation="/"
if ismissing(Resultat) then Resultat=False
texte$ = unTexte
If InStr(1, texte$, ":") Then
SupprimeEspace texte$
' Operations sexegesimales
ChargeParametre texte$, operande(), UneOperation
ChargeParametre operande(0), parametre(), ":"
for i=lbound(parametre()) to ubound(parametre())
parametre(i)=left("00", 2-len(parametre(i))) & parametre(i)
param$(0,i + 2 - ubound(parametre()))=parametre(i)
next i
ChargeParametre operande(1), parametre(), ":"
for i=lbound(parametre()) to ubound(parametre())
parametre(i)=left("00", 2-len(parametre(i))) & parametre(i)
param$(1,i + 2 - ubound(parametre()))=parametre(i)
next i
InsereAdditionSoustractionSexa Param$(), UneOperation
Else
MM = Left$(texte$, InStr(1, texte$, UneOperation) - 1)
m = Right$(texte$, Len(texte$) - InStr(1, texte$, UneOperation))
Select Case UneOperation
Case "*"
' InsereMultiplication MM, m, False
Case "+"
InsereAdditionSoustraction MM, m, "+", MIif(Resultat, oAdditionForm.Model.TextBox3.Text, "")
Case "-"
If Val(MM) < Val(m) Then
MsgBoxP "message1"
Else
InsereAdditionSoustraction MM, m, "-", MIif(Resultat, oAdditionForm.Model.TextBox3.Text, "")
End If
Case "/"
InsereDivisionEntiere MM, m, False
End Select
End If
End Sub
Sub InsereAdditionSoustraction(terme1, terme2, Operation, OperationTrou)
Dim terme(10) As String
Dim sterme(10) As String
Dim retenue as string
Dim retenues as string
Dim pemax as Integer
Dim ncmax as integer
Dim nchiffre(10) As Integer
Dim pechiffre(10) as integer
Dim l,h, i, j, k, ResultatN, Resultat$, imax, imaxd, Signe
Dim Shapes as Object
Dim tot as integer
terme(1) = terme1
terme(2) = terme2
RemplaceVirgulePoint terme(1)
RemplaceVirgulePoint terme(2)
i = 1
k = 2
While InStr(i, terme2, "+") <> 0
j = InStr(i, terme2, "+")
terme(k) = Mid$(terme2, i, j - i)
RemplaceVirgulePoint terme(k)
i = j + 1
k = k + 1
Wend
terme(k) = Right$(terme2, Len(terme2) - i + 1)
RemplaceVirgulePoint terme(k)
k = k + 1
If Operation = "+" Then
ResultatN = 0
For i = 1 To k
ResultatN = ResultatN + Val(terme(i))
Next i
Resultat$ = Str(ResultatN)
End If
If Operation = "-" Then Resultat$ = Str(Val(terme(1)) - Val(terme(2)))
Resultat$ = Right$(Resultat$, Len(Resultat$) - 1)
terme(k) = Resultat$
pemax = 0
ncmax = 0
For i = 1 To k
nchiffre(i) = InStr(1, terme(i), ".")
if nchiffre(i) = 0 then
pechiffre(i) = len(terme(i))
else
pechiffre(i) = nchiffre(i) - 1
end if
if pemax < pechiffre(i) then pemax = pechiffre(i)
If nchiffre(i) > 0 Then nchiffre(i) = Len(terme(i)) - nchiffre(i)
If nchiffre(i) > 0 Then terme(i) = Left$(terme(i), Len(terme(i)) - 1 - nchiffre(i)) & Right$(terme(i), nchiffre(i))
if ncmax < nchiffre(i) then ncmax = nchiffre(i)
Next i
For i=1 to k
sterme(i) = left$("0000000000", pemax-pechiffre(i)) & terme(i) & left$("0000000000", ncmax-nchiffre(i))
next i
if oAdditionForm.Model.CheckBox2.State Then
if Operation="+" then
retenue = ""
for i = 1 to len(sterme(1))
tot = 0
for j= 1 to k-1
tot = tot + val(mid(sterme(j),i,1)
next j
retenue = retenue & trim(str(int(tot/10)))
next i
retenue = retenue & "0"
else
retenue = ""
retenues = ""
for i = 1 to len(sterme(1))
if val(mid(sterme(1),i,1)) < val(mid(sterme(2),i,1)) then
retenue = retenue & "1"
retenues = retenues & "1"
else
retenue = retenue & "0"
retenues = retenues & "0"
end if
next i
retenues = retenues & "0"
End if
End if
InitialiseDessin(False)
Shapes=InitialiseGroupe()
DimensionTexte "8",12,l,h
if oAdditionForm.Model.CheckBox2.State Then
AfficheRetenue 9.8 + ncmax, 0.8, retenue, Shapes, l, h
if Operation <> "+" then AfficheRetenue 9.7 + ncmax, 2.7, retenues, Shapes, l, h
End if
AfficheTexte 10 + nchiffre(1), 1, terme(1), nchiffre(1) > 0, nchiffre(1), Shapes, l, h
imax = Len(terme(1)) - nchiffre(1)
imaxd = nchiffre(1)
For i = 2 To k
If imax < Len(terme(i)) - nchiffre(i) Then
imax = Len(terme(i)) - nchiffre(i)
End If
If imaxd < nchiffre(i) Then
imaxd = nchiffre(i)
End If
Next i
For i = 2 To k-1
AfficheTexte 10 + nchiffre(i), i, Operation & left(" ", pemax - pechiffre(i)) & terme(i), nchiffre(i) > 0, nchiffre(i), Shapes,l,h
Next i
TraceLigneGroupe Shapes, "s", oAdditionForm.Model.Image1
If OperationTrou <> "" Then RemplaceChiffreCaractere terme(k), OperationTrou
AfficheTexte 10 + nchiffre(k), k, terme(k), nchiffre(k) > 0, nchiffre(k), Shapes,l,h
GroupeObjet(Shapes)
TermineDessin()
End Sub
</script:module>
|