/usr/lib/libreoffice/share/extensions/DmathsAddon/CmathOOo/mDocumentEnumeration.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 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | <?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="mDocumentEnumeration" script:language="StarBasic">' +-------------------------------------------------------------------------+
' | This source file is part of MaXOpenInfo.com and MaXForms.com projects |
' | |
' +-------------------------------------------------------------------------+
' | Copyright © 2003-2004 - Robert DARGAUD - BOBICIEL. All rights reserved. |
' +-------------------------------------------------------------------------+
' | This source file is free software; you can redistribute it and/or |
' | modify it under the terms of the GNU Lesser General Public |
' | License as published by the Free Software Foundation; either |
' | version 2.1 of the License, or (at your option) any later version. |
' | |
' | This source file 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 |
' | Lesser General Public License for more details. |
' | http://www.opensource.org/licenses/lgpl-license.php |
' | |
' | You should have received a copy of the GNU General Public License |
' | along with this source file; if not, write to the Free Software |
' | Foundation Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
' +-------------------------------------------------------------------------+
' | Author: Robert DARGAUD <rdargaud@bobiciel.com> |
' +-------------------------------------------------------------------------+
' | Download new version : www.maxopeninfo.com / www.maxopeninfo.org |
' +-------------------------------------------------------------------------+
' | |
' | WriterEnumeration : Robert DARGAUD - BOBICIEL - FRANCE - July 2004 |
' | CalcEnumeration : ................................................... |
' | DrawEnumeration : ................................................... |
' | |
' | C/C++ version : ................................................... |
' | |
' +-------------------------------------------------------------------------+
' | AddOn OpenOffice.org / Sun StarOffice |
' +-------------------------------------------------------------------------+
' | History : |
' +-------------------------------------------------------------------------+
' | beta 0.1 : 2004/08/02 |
' | beta 0.2 : 2004/08/09 support des cellules fusionnées |
' | |
' | novembre 2005 : code modifé par C. Devalland pour repérer les formules |
' | mathématiques |
' +-------------------------------------------------------------------------+
' <en>
REM ***** BASIC (currently ;-) *****
'
' This module is doing a complete or partial enumeration against an OpenOffice.org document (currently for Writer).
'
' For Calc, Draw and Impress it is just a matter of pizza, cups of coffee, pizza, coca, pop corn, ...
' and additional nigthly hours. So, if you like pizzas, ... by night, it's your turn ...
'
' This enumeration is working on OOo document in the same way as a sax parser on an xml document.
' This way allows to develop macros fastly just coding event controlers using basic language.
' For instance refer to mCopyWikiWiki in this doc which translate document content to WikiWiki tags
' (as www.WikiPedia.org, www.wikini.net, www.Spip.net, ...).
'
' Currently the document components are systematically enumerated in paragraphs order, but the "OrderBy" parameter
' will allow to optimize the algorithm.
'
' This enumeration are running in background letting the user free to work (or not :-), this required a FIFO stack.
'
' This is a draft to validate the enumeration algorithm.
' The basic version is currently usable and fast enought to use it with complex and 10 pages long documents.
'
' The real implementation should be writen in C/C++ to package it and boost up the process :-)
' But, in order to let the end user able to customize his own applications, the events controls must stay in OOoBasic
' language.
' Is it possible and easy to code ? ...
' Any participation (coding, remarques, suggestions, tests, ...) is welcom !
'
' </en>
' <fr>
REM ***** BASIC (pour le moment ;-) *****
'
' Ce module effectue une énumération complète ou partielle d'un document OpenOffice.org (pour le moment Writer).
' Pour Calc, Draw et Impress ce n'est qu'une question de quelques pizza, bière, saucisson, p'tit coup de rouge, fromage, ...
' et heures de nuit supplémentaires. Si vous aimer manger des pizzas, ... la nuit, à vous de jouer ...
'
' Cette énumération déclenche des évènements sur un document OOo à la manière d'un parseur sax sur un document xml.
' Cette technique permet de développer rapidement des macros en enrichissant simplement les gestionnaires d'évènement
' en basic. Voir par exemple le module mCopyWikiWiki dans ce même doc qui traduit le contenu d'un document en balisage
' de type WikiWiki (comme www.WikiPedia.org, www.Spip.net, ...).
'
' Actuellement les composants du document sont systématiquement énumérés dans l'ordre des paragraphes, mais le paramètre
' "OrderBy" permettra d'effectuer des optimisations lorsque l'ordre d'énumération n'a pas d'importance.
'
' Ces énumérations s'exécutent en tâche de fond en laissant la main à l'utilisateur, ce qui nécessite une pile FIFO pour
' mémoriser les requêtes d'énumération.
'
' Ce code peut être considéré comme une première approche pour valider l'algorithme d'énumération.
' Cette version OOoBasic est actuellement utilisable et suffisament performante pour être utilisée sur des documents
' à l'architecture complexe et d'une dizaine de pages (comme par exemple des formulaires ;-)
'
' La vraie implémentation de ce code doit être écrite en C/C++ pour le "packager" et augmenter ses performances :-)
' Mais, pour laisser à l'utilisateur la possibilité de créer ses propres applications macros, les gestionnaires
' d'évènements doivent rester en OOoBasic.
' Est-ce possible et simple à réaliser ? ...
' Toute participation (pour l'écriture, des remarques, des suggestions, des tests, ...) est la bienvenue !
'
' </fr>
option explicit
'<fr> RMQ: à passer en paramètres, pour qu'ils ne puissent pas être modifiés par les gestionaires d'évènement
' car bien qu'en private, les autres modules y on accès !!??!!
private oEventsModule as object
private iOrderBy as integer
private EnumerationIsEnabled as boolean
private EnumerationInProgress as boolean
'<fr> variables indiquant si un gestionnaire d'évènement est implémenté
'<fr> RMQ: actuellement, ça ne fonctionne pas (voir sub DetectImplementedEnumerationEvents)
private onStartOfEnumeration_isImplemented as boolean
private onEndOfEnumeration_isImplemented as boolean
private onStartOfParagraph_isImplemented as boolean
private onEndOfParagraph_isImplemented as boolean
private onStartOfTextTable_isImplemented as boolean
private onEndOfTextTable_isImplemented as boolean
private onStartOfRow_isImplemented as boolean
private onEndOfRow_isImplemented as boolean
private onStartOfCell_isImplemented as boolean
private onEndOfCell_isImplemented as boolean
private onStartOfTextSection_isImplemented as boolean
private onEndOfTextSection_isImplemented as boolean
private onStartOfTextFrame_isImplemented as boolean
private onEndOfTextFrame_isImplemented as boolean
private onStartOfTextEmbeddedObject_isImplemented as boolean
private onEndOfTextEmbeddedObject_isImplemented as boolean
private onTextPortion_isImplemented as boolean
private onTextField_isImplemented as boolean
private onFootnote_isImplemented as boolean
private onControlCharacter_isImplemented as boolean
private onReferenceMark_isImplemented as boolean
private onDocumentIndexMark_isImplemented as boolean
private onBookmark_isImplemented as boolean
private onRedline_isImplemented as boolean
private onRuby_isImplemented as boolean
private onTextGraphicObject_isImplemented as boolean
private onTextShape_isImplemented as boolean
private onDrawingShape_isImplemented as boolean
private onFormControl_isImplemented as boolean
'<fr> RMQ: voir pourquoi on doit les déclarer en global pour que la valeur soit conservée
global sFifoComponentType(10) as string
global oFifoComponent(ubound(sFifoComponentType()))
global oFifoEventsModule(ubound(sFifoComponentType()))
global iFifoOrderBy(ubound(sFifoComponentType()))
global iLoadFifoCursor as integer
global iUnLoadFifoCursor as integer
' *********************************************************************************
' <fr> critère d'ordre pour l'énumération des composants
' RMQ: actuellement seul "ParagraphsOrder" est implémenté.
' ultérieurement, ce critère permettra d'effectuer des optimisations lorsque l'ordre d'énumération n'a pas d'importance.
private const ParagraphsOrder = 0 ' les composants sont énumérés selon leur ordre d'apparition dans le document
private const FormControlsOrder = 1 ' les controles de formulaires sont énumérés selon leur attribut "ordre"
private const CreationOrder = 2 ' les composants sont énumérés selon leur ordre de création
private const AsIsOrder = 4 ' les composants peuvent être énumérés dans n'importe quel ordre
' *********************************************************************************
' <fr> désactivation de l'énumération
' ce qui permet une optimisation de l'analyse du document en plaçant judicieusement des appels à "DisableEnumeration"
' dans les gestionnaires d'évènements.
sub DisableEnumeration
EnumerationIsEnabled = false
end sub
' *********************************************************************************
' <fr> version AVEC pile FIFO (non entièrement opérationnelle, mais peut être testée ;-)
sub DocumentEnumeration(sTheComponentType as string, oTheComponent as object, oTheEventsModule as object, optional iTheOrderBy as integer)
'<fr> RMQ: contrôler le type des objets passés en paramètres
EnumerationIsEnabled = true
'<fr> empilage de la requête d'énumération
if IsMissing(iTheOrderBy) then
LoadFifoEnumerations(sTheComponentType, oTheComponent, oTheEventsModule, 0)
else
LoadFifoEnumerations(sTheComponentType, oTheComponent, oTheEventsModule, iTheOrderBy)
end if
end sub
' *********************************************************************************
' <fr> version SANS pile FIFO
sub _DocumentEnumeration(sTheComponentType as string, oTheComponent as object, oTheEventsModule as object, optional iTheOrderBy as integer)
'<fr> RMQ: contrôler le type des objets passés en paramètres
' <fr> si une énumération est déja en cours, la nouvelle requête est tout simplement ignorée (d'ou l'intéret d'une pile FIFO :-)
if EnumerationInProgress then
exit sub
end if
oEventsModule = oTheEventsModule
if IsMissing(iTheOrderBy) then
iOrderBy = 0
else
iOrderBy = iTheOrderBy
end if
' <fr> RMQ: non opérationnel (voir DetectImplementedEnumerationEvents en fin de module)
' DetectImplementedEnumerationEvents
EnumerationInProgress = true
EnumerationIsEnabled = true
' <fr> RMQ: l'idéal serait que le type soit détecté automatiquement
' avec .supportsService ?
oEventsModule.onStartOfEnumeration(oTheComponent)
select case lcase(sTheComponentType)
case "writer"
WriterEnumeration(oTheComponent)
case "calc"
CalcEnumeration(oTheComponent)
case "draw"
DrawEnumeration(oTheComponent)
end select
oEventsModule.onEndOfEnumeration(oTheComponent)
' <fr> délai minimum entre 2 énumérations (RMQ: à ajuster)
wait 500
EnumerationInProgress = false
end sub
' *********************************************************************************
' <fr> empilage des requêtes d'énumération
sub LoadFifoEnumerations(sTheComponentType as string, oTheComponent as object, oTheEventsModule as object, iTheOrderBy as integer)
dim i as integer
dim ok as boolean
'<fr> RMQ: contrôler le type des objets passés en paramètres
' <fr> Contrôle des limtes du curseur sur la pile FIFO circulaire
if (iLoadFifoCursor < 0) or (iLoadFifoCursor >= ubound(sFifoComponentType())) then
iLoadFifoCursor = 0
end if
' <fr> Contrôle qu'il n'y ai rien à cet emplacement dans la pile FIFO
if (sFifoComponentType(iLoadFifoCursor) <> "") then
print "La pile FIFO est pleine, Impossible d'empiler !!!" & " curseur load =" + iLoadFifoCursor & " curseur unLoad =" + iUnLoadFifoCursor
' <fr> vidage de la pile (pour debug)
iLoadFifoCursor = 0
iUnLoadFifoCursor = 0
for i = 0 to ubound(sFifoComponentType())
sFifoComponentType(i) = ""
next i
exit sub
end if
' <fr> si cette requête est déja dans la pile FIFO, on ne l'empile pas une nouvelle fois
ok = true
for i = 0 to ubound(sFifoComponentType())
if (sFifoComponentType(i) = sTheComponentType) then
if EqualUnoObjects(oFifoComponent(i), oTheComponent) then
if (oFifoEventsModule(i).Name = oTheEventsModule.Name) then
' debug
' print "déja dans la pile (" & i & ") " & sTheComponentType & " " & oTheEventsModule.Name
ok = false
end if
end if
end if
next i
if ok then
' <fr> empilage de la requête
sFifoComponentType(iLoadFifoCursor) = sTheComponentType
oFifoComponent(iLoadFifoCursor) = oTheComponent
oFifoEventsModule(iLoadFifoCursor) = oTheEventsModule
iFifoOrderBy(iLoadFifoCursor) = iTheOrderBy
' incrémentation du curseur d'empilage
iLoadFifoCursor = iLoadFifoCursor + 1
end if
' <fr> si aucune énumération n'est en cours, on exécute un dépilage
if not EnumerationInProgress then
UnLoadFifoEnumerations
end if
end sub
' *********************************************************************************
' <fr> dépilage des requêtes d'énumération
sub UnLoadFifoEnumerations
dim i as integer
' <fr> le dépilage ne peut s'effectuer que si aucune énumération n'est en cours
if EnumerationInProgress then
exit sub
end if
do
' <fr> Contrôle des limtes du curseur sur le FIFO circulaire
if (iUnLoadFifoCursor < 0) or (iUnLoadFifoCursor >= ubound(sFifoComponentType())) then
iUnLoadFifoCursor = 0
end if
' <fr> Contrôle du contenu de la pile FIFO pour le curseur de dépilage
' <fr> RMQ: revoir isempty() car il ne va pas permettre de détecter si le composant a été supprimé depuis l'empilage
if (instr("writer,calc,draw", lcase(sFifoComponentType(iUnLoadFifoCursor))) > 0) _
and not isempty(oFifoComponent(iUnLoadFifoCursor)) _
and not isempty(oFifoEventsModule(iUnLoadFifoCursor)) then
oEventsModule = oFifoEventsModule(iUnLoadFifoCursor)
iOrderBy = iFifoOrderBy(iUnLoadFifoCursor)
EnumerationInProgress = true
EnumerationIsEnabled = true
' <fr> RMQ: non opérationnel (voir DetectImplementedEnumerationEvents en fin de module)
' DetectImplementedEnumerationEvents
' <fr> RMQ: l'idéal serait que le type soit détecté automatiquement
' avec .supportsService ?
oEventsModule.onStartOfEnumeration(oFifoComponent(iUnLoadFifoCursor))
select case lcase(sFifoComponentType(iUnLoadFifoCursor))
case "writer"
WriterEnumeration(oFifoComponent(iUnLoadFifoCursor))
case "calc"
CalcEnumeration(oFifoComponent(iUnLoadFifoCursor))
case "draw"
DrawEnumeration(oFifoComponent(iUnLoadFifoCursor))
end select
oEventsModule.onEndOfEnumeration(oFifoComponent(iUnLoadFifoCursor))
else
print "Impossible de dépiler la pile FIFO !!!" & " curseur load =" + iLoadFifoCursor & " curseur unLoad =" + iUnLoadFifoCursor
end if
' <fr> effacement de l'emplacement dans la pile FIFO
sFifoComponentType(iUnLoadFifoCursor) = ""
' <fr> incrémentation du curseur de dépilage
iUnLoadFifoCursor = iUnLoadFifoCursor + 1
' <fr> délai minimum entre 2 énumérations (RMQ: à ajuster)
wait 500
' <fr> boucle jusqu'à ce que la pile FIFO soit vide
loop until (iUnLoadFifoCursor = iLoadFifoCursor)
' <fr> raz du drapeau "Enumération en cours"
EnumerationInProgress = false
end sub
' *********************************************************************************
sub WriterEnumeration(oTheTextComponent as object, optional oTheCurrentTextSection)
dim oParagraphEnum
dim oParagraph
dim oPortionEnum
dim oPortion
dim oRows
dim iRowIndex as integer
dim oCols
dim iColIndex as integer
dim oCell
dim oCurrentTextSection
dim i as integer
dim nombreMax as integer, compteur as integer
dim oPgb as Object
' <fr> RMQ: actuellement, oTheTextComponent ne peut être qu'un document texte ou un cadre texte.
' <fr> Il est également prévu de pouvoir lancer le traitement sur une section texte et un groupe de paragraphes (pas forcément contigues)
' <fr> RMQ: tester on<<event>>_isImplemented avant d'appeler la sub correspondante
' <fr> RMQ: voir si on gagne réellement du temps en n'implémentant pas tous les gestionnaires d'évènements
' <fr> RMQ: OPTIMISATIONS A PREVOIR : ajouter des UserFields aux composants pour mémoriser s'il est nécessaire d'analyser leur contenu.
' Ces UserFields seront renseignés au premier traitement (ou en tâche de fond). L'énumération tiendra compte de leur contenu
' pour optimiser le traitement.
' Ce mécanisme permettra par exemple :
' - d'analyser uniquement les champs de formulaire contenus dans une section ou un cadre en lecture seule
' - ...
' <fr> si l'énumération a été désactivée pour ce composant, on n'effectue pas le traitement
' (cette fonctionnalité permet d'optimiser l'analyse du document)
if not EnumerationIsEnabled then
EnumerationIsEnabled = true
exit sub
end if
' <fr> si aucune section texte courante n'a été passée en paramètre, elle est initialisée à null
if IsMissing(oTheCurrentTextSection) then
oCurrentTextSection = null
else
oCurrentTextSection = oTheCurrentTextSection
end if
' <fr> énumération de tous les paragraphes inclus
' (rmq: les tableaux sont vus comme des paragraphes particuliers (depuis OOo 1.1.0)
oParagraphEnum = oTheTextComponent.getText().createEnumeration()
nombreMax=Thiscomponent.ParagraphCount
oPgb=Thiscomponent.currentcontroller.statusIndicator
oPgb.Start ("Conversion vers SPIP en cours ...",nombreMax)
compteur=0
do while oParagraphEnum.hasMoreElements()
oParagraph = oParagraphEnum.nextElement()
oPgb.value=compteur
compteur=compteur+1
' if onStartOfTextSection_isImplemented or onEndOfTextSection_isImplemented then
' <fr> merci à Bernard Marcelly pour l'idée du parcourt des paragraphes pour analyser la structure des sections
' déclenchement des évènements liés aux début et fin de "section texte"
if not isempty(oParagraph.TextSection) then
AncestorsTextSections(oParagraph.TextSection, oCurrentTextSection)
oCurrentTextSection = oParagraph.TextSection
elseif not isempty(oCurrentTextSection) then
AncestorsTextSections(null, oCurrentTextSection)
oCurrentTextSection = null
end if
' end if
' <fr> paragraphe texte
if oParagraph.supportsService("com.sun.star.text.Paragraph") then
oEventsModule.onStartOfParagraph(oParagraph)
' <fr> énumération des composants ancrés au paragraphe
ContentEnumeration(oParagraph, "com.sun.star.text.TextContent")
' <fr> énumération des portions de texte et des composants ancrés "au caractère" ou "comme caractère"
oPortionEnum = oParagraph.createEnumeration()
do while oPortionEnum.hasMoreElements()
oPortion = oPortionEnum.nextElement()
' a=oPortion.TextPortionType
with oPortion
select case .TextPortionType
' portion de texte pur
case "Text"
oEventsModule.onTextPortion(oPortion)
' champ texte
case "TextField"
oEventsModule.onTextField(oPortion.TextField, oPortion.String)
' <fr> RMQ: à priory, d'après l'api, TextField supporte une énumération du contenu (à voir)
' ContentEnumeration(oPortion, "")
' <fr> note de bas de page
case "Footnote"
oEventsModule.onFootnote(oPortion)
' <fr> caractère de contrôle
case "ControlCharacter"
oEventsModule.onControlCharacter(oPortion)
' <fr> légende
case "ReferenceMark"
oEventsModule.onReferenceMark(oPortion)
' <fr> index
case "DocumentIndexMark"
oEventsModule.onDocumentIndexMark(oPortion)
' <fr> signet
case "Bookmark"
oEventsModule.onBookmark(oPortion)
' <fr> modification
case "Redline"
oEventsModule.onRedline(oPortion)
' <fr> attribut utilisé pour les textes asiatiques
case "Ruby"
oEventsModule.onRuby(oPortion)
' <fr> cadre
case "Frame"
ContentEnumeration(oPortion, "")
case else
'debug
Print "<" + .TextPortionType + "/>";
end select
end with
loop
oEventsModule.onEndOfParagraph(oParagraph)
' <fr> paragraphe tableau
elseif oParagraph.supportsService("com.sun.star.text.TextTable") Then
oEventsModule.onStartOfTextTable(oParagraph)
oRows = oParagraph.getRows()
oCols = oParagraph.getColumns()
' <fr> énumération de chaque ligne du tableau
for iRowIndex = 0 to (oRows.getCount()-1)
oEventsModule.onStartOfRow(oRows(iRowIndex), iRowIndex)
' <fr> énumération de chaque cellule de la ligne
for iColIndex = 0 to (oCols.getCount()-1)
'RMQ: ligne à supprimer oCell = oParagraph.getCellByPosition(iColIndex, iRowIndex)
oCell = oCellByPosition(oParagraph, iColIndex, iRowIndex)
if not isempty(oCell) then
oEventsModule.onStartOfCell(oCell, iColIndex)
WriterEnumeration(oCell, oCurrentTextSection)
oEventsModule.onEndOfCell(oCell, iColIndex)
end if
next iColIndex
oEventsModule.onEndOfRow(oRows(iRowIndex), iRowIndex)
next iRowIndex
oEventsModule.onEndOfTextTable(oParagraph)
else
msgbox("type inconnu")
' debug
print "<paragraphe_de_type_inconnu/>";
end if
loop
' <fr> si aucune section courante n'a été passée en paramètre, on s'assure que toutes les sections sont bien refermées
if IsMissing(oTheCurrentTextSection) then
AncestorsTextSections(null, oCurrentTextSection)
' <fr> sinon, la section courante doit être celle passée en paramètre en début d'énumération
elseif not (isnull(oCurrentTextSection) and isnull(oTheCurrentTextSection)) _
and not EqualUnoObjects(oCurrentTextSection, oTheCurrentTextSection) then
print "Erreur interne dans la gestion des sections !!!"
end if
oPgb.end
' <fr> RMQ: ne devrait-on pas libérer oParagraphEnum ?
end sub
' *********************************************************************************
sub AncestorsTextSections(oTheNewTextSection, oTheCurrentTextSection)
' <fr> la section est inchangée, on ne fait rien
if EqualUnoObjects(oTheNewTextSection, oTheCurrentTextSection) _
or (isnull(oTheNewTextSection) and isnull(oTheCurrentTextSection))then
exit sub
end if
dim oAncestorNewTextSection(100)
dim oAncestorCurrentTextSection(100)
dim iCountNew as integer
dim iCountCurrent as integer
dim i as integer
dim icur as integer
dim inew as integer
' <fr> mémorisation des sections ancêtres dans 2 tableaux (un pour la section courante l'autre pour la nouvelle section).
oAncestorNewTextSection(0) = oTheNewTextSection
oAncestorCurrentTextSection(0) = oTheCurrentTextSection
iCountNew = 0
iCountCurrent = 0
' <fr> le parcourt des 2 sections est effectué en parallèle afin de détecter le plus rapidement possible si l'une des
' 2 sections est l'ancêtre de l'autre (ce qui est souvent le cas), le traitement est alors écourté car devenu inutile.
do until isnull(oAncestorNewTextSection(iCountNew)) and isnull(oAncestorCurrentTextSection(iCountCurrent))
' <fr> parcourt des sections ancêtres de la nouvelle section
if not isnull(oAncestorNewTextSection(iCountNew)) then
if not isempty(oAncestorNewTextSection(iCountNew).ParentSection) then
iCountNew = iCountNew + 1
oAncestorNewTextSection(iCountNew) = oAncestorNewTextSection(iCountNew-1).ParentSection
' <fr> si cet ancêtre est la section courante, alors des sections filles ont été ouvertes
if EqualUnoObjects(oAncestorNewTextSection(iCountNew), oTheCurrentTextSection) then
for inew = iCountNew-1 to 0 step -1
oEventsModule.onStartOfTextSection(oAncestorNewTextSection(inew))
next inew
exit sub ' <fr> désolé, mais c'est le plus efficace :-)
end if
else
oAncestorNewTextSection(iCountNew) = null
end if
end if
' <fr> parcourt des sections ancêtres de la section courante
if not isnull(oAncestorCurrentTextSection(iCountCurrent)) then
if not isempty(oAncestorCurrentTextSection(iCountCurrent).ParentSection) then
iCountCurrent = iCountCurrent + 1
oAncestorCurrentTextSection(iCountCurrent) = oAncestorCurrentTextSection(iCountCurrent-1).ParentSection
' <fr> si cet ancêtre est la nouvelle section, alors des sections filles ont été fermées
if EqualUnoObjects(oAncestorCurrentTextSection(iCountCurrent), oTheNewTextSection) then
for icur = 0 to iCountCurrent-1
oEventsModule.onEndOfTextSection(oAncestorCurrentTextSection(icur))
next icur
exit sub ' <fr> désolé, mais c'est le plus efficace :-)
end if
else
oAncestorCurrentTextSection(iCountCurrent) = null
end if
end if
loop
' <fr> aucune section n'est ouverte et une ou plusieurs sections imbriquées nouvelles viennent d'être ouvertes
if isnull(oTheCurrentTextSection) and not isnull(oTheNewTextSection) then
for inew = iCountNew-1 to 0 step -1
oEventsModule.onStartOfTextSection(oAncestorNewTextSection(inew))
next inew
' <fr> toutes les sections imbriquées ouvertes précédemment ont été fermées
elseif isnull(oTheNewTextSection) and not isnull(oTheCurrentTextSection) then
for icur = 0 to iCountCurrent-1
oEventsModule.onEndOfTextSection(oAncestorCurrentTextSection(icur))
next icur
' <fr> une ou plusieurs sections imbriquées ont été fermées et d'autres ont été ouvertes
elseif not isnull(oTheNewTextSection) and not isnull(oTheCurrentTextSection) then
icur = iCountCurrent - 1
inew = iCountNew - 1
' <fr> recherche de la section ancêtre commune
do while (icur >= 0) and (inew >=0)
' <fr> si cette section est un ancêtre commun
' et que celles au niveau suivant sont différentes
' if EqualUnoObjects(oAncestorCurrentTextSection(icur), oAncestorNewTextSection(inew)) _
' and not EqualUnoObjects(oAncestorCurrentTextSection(icur-1), oAncestorNewTextSection(inew-1)) then
' <fr> merci Thierry, effectivement, c'est plus simple :-)
if not EqualUnoObjects(oAncestorCurrentTextSection(icur), oAncestorNewTextSection(inew)) then
' <fr> fermeture des sections jusqu'à l'ancêtre commun exclu
' for i = 0 to icur-1
for i = 0 to icur
oEventsModule.onEndOfTextSection(oAncestorCurrentTextSection(i))
next i
' <fr> ouverture des nouvelles sections à partir de l'ancêtre commun exclu
' for i = inew-1 to 0 step -1
for i = inew to 0 step -1
oEventsModule.onStartOfTextSection(oAncestorNewTextSection(i))
next i
exit do
end if
icur = icur - 1
inew = inew - 1
loop
end if
end sub
' *********************************************************************************
'<fr> Cette fonction retourne un Objet Cellule (ou un objet vide si l'adresse de la cellule est incorrecte)
' merci Thierry !
function oCellByPosition(oTheTable as object, iTheColIndex as integer, iTheRowIndex as integer) as variant
dim oCell
on error resume next
oCell = oTheTable.getCellByPosition(iTheColIndex, iTheRowIndex)
oCellByPosition = oCell
end function
' *********************************************************************************
sub CalcEnumeration(oTheTextComponent as object)
' <fr> ... y'a encore du boulot ...
end sub
' *********************************************************************************
sub DrawEnumeration(oTheTextComponent as object)
' <fr> ... ici aussi, mais ça vaut le coup ;-)
end sub
' *********************************************************************************
sub ContentEnumeration(oTheComponent as object, sTheServiceName as string)
dim oContentEnum
dim oContent
' <fr> RMQ: tester on<<event>>_isImplemented avant d'appeler la sub correspondante
' <fr> RMQ: voir si on gagne réellement du temps en n'implémentant pas tous les gestionnaires d'évènements
' <fr> si l'énumération a été désactivée pour ce composant, on n'effectue pas le traitement
' (cette fonctionnalité permet d'optimiser l'analyse du document)
if not EnumerationIsEnabled then
EnumerationIsEnabled = true
exit sub
end if
' <fr> énumération de tous les composants contenus
oContentEnum = oTheComponent.createContentEnumeration(sTheServiceName)
do while oContentEnum.hasMoreElements()
oContent = oContentEnum.nextElement()
' <fr> cadre de texte
if oContent.supportsService("com.sun.star.text.TextFrame") then
' <fr> les cadres de texte chainés sont vus comme un seul cadre
if (oContent.ChainPrevName = "") then
oEventsModule.onStartOfTextFrame(oContent)
WriterEnumeration(oContent)
oEventsModule.onEndOfTextFrame(oContent)
end if
' <fr> RMQ : apparemment, c'est déja traité comme ça par l'api !!!
' le code ci dessous est donc inutile. Merci StarDivision ;-)
' if (oContent.ChainNextName <> "") then
' RMQ: récuperer le cadre suivant
' oEventsModule.onStartOfTextFrame(oContent)
' WriterEnumeration(oContent)
' oEventsModule.onEndOfTextFrame(oContent)
' end if
' <fr> image
elseif oContent.supportsService("com.sun.star.text.TextGraphicObject") then
oEventsModule.onTextGraphicObject(oContent)
' <fr> objet incrusté (embbeded)
elseif oContent.supportsService("com.sun.star.text.TextEmbeddedObject") then
' ajouté par C. Devalland
' est-ce une formule ?
dim a as string
a=oContent.embeddedObject.getImplementationName
if oContent.embeddedObject.getImplementationName="com.sun.star.comp.math.FormulaDocument" then
oEventsModule.onFormulaEmbeddedObject(oContent)
end if
' <fr> RMQ: énumérer le contenu de l'objet en fonction de son type Calc ou Draw
' contenu de la formule
' CalcEnumeration(oContent)
' DrawEnumeration(oContent)
elseif oContent.supportsService("com.sun.star.text.Shape") then
oEventsModule.onTextShape(oContent)
' <fr> dessin ou contrôle de formulaire
elseif oContent.supportsService("com.sun.star.drawing.Shape") then
if oContent.ShapeType = "com.sun.star.drawing.ControlShape" then
' <fr> contrôle de formulaire
oEventsModule.onFormControl(oContent.Control)
else
' <fr> dessin
oEventsModule.onDrawingShape(oContent)
end if
end if
loop
' <fr> RMQ: ne devrait-on pas libérer oContentEnum ?
end sub
' *********************************************************************************
' <fr> merci à Bernard Marcelly pour cette idée
' RMQ: dommage que OOo prenne l'initiative étrange d'aller chercher dans un autre module, la fonction inexistante !!!
sub DetectImplementedEnumerationEvents
onStartOfEnumeration_isImplemented = true
onEndOfEnumeration_isImplemented = true
onStartOfParagraph_isImplemented = true
onEndOfParagraph_isImplemented = true
onStartOfTextTable_isImplemented = true
onEndOfTextTable_isImplemented = true
onStartOfRow_isImplemented = true
onEndOfRow_isImplemented = true
onStartOfCell_isImplemented = true
onEndOfCell_isImplemented = true
onStartOfTextSection_isImplemented = true
onEndOfTextSection_isImplemented = true
onStartOfTextFrame_isImplemented = true
onEndOfTextFrame_isImplemented = true
onStartOfTextEmbeddedObject_isImplemented = true
onEndOfTextEmbeddedObject_isImplemented = true
onTextPortion_isImplemented = true
onTextField_isImplemented = true
onFootnote_isImplemented = true
onControlCharacter_isImplemented = true
onReferenceMark_isImplemented = true
onDocumentIndexMark_isImplemented = true
onBookmark_isImplemented = true
onRedline_isImplemented = true
onRuby_isImplemented = true
onTextGraphicObject_isImplemented = true
onTextShape_isImplemented = true
onDrawingShape_isImplemented = true
onFormControl_isImplemented = true
on error goto errorOnStartOfParagraph
' <fr> RMQ: étrange, si OOoBasic ne trouve pas onStartOfParagraph dans le module, il appelle le premier onStartOfParagraph d'un autre module
oEventsModule.onStartOfPage(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' <fr> passage de paramètres incohérents de façon à ne pas exécuter la sub
exit sub
errorOnStartOfParagraph:
print err
onStartOfParagraph_isImplemented = (err<>423)
resume next
' <fr> RMQ: à répéter pour tous les évènements
end sub
</script:module>
|