~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to kpresenter/kpresenter_doc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of the KDE project
2
2
   Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
 
3
   Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
3
4
 
4
5
   This library is free software; you can redistribute it and/or
5
6
   modify it under the terms of the GNU Library General Public
20
21
#include "kpresenter_doc.h"
21
22
#include "kpresenter_view.h"
22
23
#include "kprcanvas.h"
 
24
#include "kprpage.h"
 
25
#include "kpobject.h"
23
26
#include "kplineobject.h"
24
27
#include "kprectobject.h"
25
28
#include "kpellipseobject.h"
31
34
#include "kppartobject.h"
32
35
#include "kpgroupobject.h"
33
36
#include "kprcommand.h"
34
 
#include "styledia.h"
35
 
#include <insertpagedia.h>
 
37
#include "insertpagedia.h"
36
38
#include "kpfreehandobject.h"
37
39
#include "kppolylineobject.h"
38
40
#include "kpquadricbeziercurveobject.h"
45
47
#include <qregexp.h>
46
48
#include <qfileinfo.h>
47
49
#include <qdom.h>
 
50
#include <qdict.h>
 
51
 
 
52
#include <kodom.h>
 
53
#include <koxmlns.h>
48
54
 
49
55
#include <kurl.h>
50
56
#include <kdebug.h>
62
68
 
63
69
#include <koTemplateChooseDia.h>
64
70
#include <koRuler.h>
 
71
#include <koGenStyles.h>
65
72
#include <koFilterManager.h>
66
73
#include <koStore.h>
67
74
#include <koStoreDevice.h>
68
75
#include <koQueryTrader.h>
 
76
#include <koxmlwriter.h>
 
77
#include <koOasisSettings.h>
69
78
 
70
79
#include <stdlib.h>
71
80
#include <stdio.h>
79
88
#include <kostyle.h>
80
89
#include <kcommand.h>
81
90
#include "KPresenterDocIface.h"
82
 
#include <kspell.h>
 
91
 
 
92
#ifdef HAVE_LIBKSPELL2
 
93
#include <kspell2/settings.h>
 
94
#endif
83
95
 
84
96
#include <kovariable.h>
85
97
#include <koAutoFormat.h>
91
103
#include <kglobalsettings.h>
92
104
#include <kocommandhistory.h>
93
105
#include "koApplication.h"
 
106
#include <koOasisStyles.h>
 
107
#include <kooasiscontext.h>
94
108
 
95
 
#include <koSconfig.h>
 
109
#include "kprloadinginfo.h"
96
110
 
97
111
using namespace std;
98
112
 
124
138
KPresenterDoc::KPresenterDoc( QWidget *parentWidget, const char *widgetName, QObject* parent, const char* name,
125
139
                              bool singleViewMode )
126
140
    : KoDocument( parentWidget,widgetName, parent, name, singleViewMode ),
127
 
      _gradientCollection(),
128
 
      _hasHeader( false ),
129
 
      _hasFooter( false ),
130
 
      m_unit( KoUnit::U_MM )
 
141
      _gradientCollection(), m_customListTest( 0L ),
 
142
      m_childCountBeforeInsert( 0 )
131
143
{
132
144
    setInstance( KPresenterFactory::global() );
133
145
    //Necessary to define page where we load object otherwise copy-duplicate page doesn't work.
 
146
    if (KGlobal::locale()->measureSystem() == KLocale::Imperial) {
 
147
        m_unit = KoUnit::U_INCH;
 
148
    } else {
 
149
        m_unit = KoUnit::U_CM;
 
150
    }
134
151
    m_pageWhereLoadObject=0L;
135
 
    bgObjSpellChecked = 0L;
 
152
    m_loadingInfo=0L;
136
153
    m_tabStop = MM_TO_POINT( 15.0 );
137
154
    m_styleColl=new KoStyleCollection();
138
155
    m_insertFilePage = 0;
141
158
    m_bGlobalHyphenation = false;
142
159
    _duplicatePage=false;
143
160
 
144
 
    KoStyle* m_standardStyle = new KoStyle( "Standard" );
 
161
    KoParagStyle* m_standardStyle = new KoParagStyle( "Standard" );
145
162
    m_styleColl->addStyleTemplate( m_standardStyle );
146
163
 
147
164
    KConfig *config = KPresenterFactory::global()->config();
180
197
 
181
198
    m_varFormatCollection = new KoVariableFormatCollection;
182
199
    m_varColl = new KPrVariableCollection( new KoVariableSettings(), m_varFormatCollection );
 
200
#ifdef HAVE_LIBKSPELL2
183
201
    m_bgSpellCheck = new KPrBgSpellCheck(this);
184
 
 
 
202
#endif
185
203
    dcop = 0;
186
204
    m_initialActivePage=0;
187
205
    m_bShowStatusBar = true;
195
213
    _yRnd = 20;
196
214
    _txtBackCol = lightGray;
197
215
    _otxtBackCol = lightGray;
198
 
    m_pKOSpellConfig = 0;
199
216
 
200
217
    m_bShowRuler=true;
201
218
    m_bAllowAutoFormat = true;
213
230
    usedSoundFile = QStringList();
214
231
    haveNotOwnDiskSoundFile = QStringList();
215
232
 
216
 
    m_zoomHandler->setZoomAndResolution( 100, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
 
233
    m_zoomHandler->setZoomAndResolution( 100, KoGlobal::dpiX(), KoGlobal::dpiY() );
217
234
    newZoomAndResolution(false,false);
218
235
 
219
236
    //   _pageLayout.format = PG_SCREEN;
239
256
    oldGridX = m_gridX;
240
257
    oldGridY = m_gridY;
241
258
 
242
 
    KPrPage *newpage=new KPrPage(this);
 
259
    m_masterPage=new KPrPage(this);
 
260
    KPrPage *newpage = new KPrPage( this, m_masterPage );
243
261
    m_pageList.insert( 0,newpage);
244
 
    m_stickyPage=new KPrPage(this);
245
262
    m_bInsertDirectCursor = false;
246
263
 
247
264
    objStartY = 0;
248
265
    setPageLayout( m_pageLayout );
249
266
    _presPen = QPen( red, 3, SolidLine );
250
 
    presSpeed = 2;
251
267
    ignoreSticky = TRUE;
252
 
    raiseAndLowerObject = false;
253
268
 
254
269
    m_gridColor=Qt::black;
255
270
 
274
289
    connect( m_commandHistory, SIGNAL( commandExecuted() ), this, SLOT( slotCommandExecuted() ) );
275
290
 
276
291
    connect(m_varColl,SIGNAL(repaintVariable()),this,SLOT(slotRepaintVariable()));
277
 
    if ( name )
278
 
        dcopObject();
 
292
    dcopObject();
279
293
}
280
294
 
281
295
void KPresenterDoc::refreshMenuCustomVariable()
306
320
 
307
321
void KPresenterDoc::saveConfig()
308
322
{
309
 
    if ( isEmbedded() || !isReadWrite())
 
323
    if ( !isReadWrite())
310
324
        return;
311
 
    KConfig *config = KPresenterFactory::global()->config();
312
 
    config->setGroup( "Interface" );
313
 
    config->writeEntry( "Zoom", m_zoomHandler->zoom() );
314
 
    config->writeEntry( "AllowAutoFormat" , m_bAllowAutoFormat );
315
 
    config->writeEntry( "ViewFormattingChars", m_bViewFormattingChars );
316
 
    config->writeEntry( "ShowGrid" , m_bShowGrid );
317
 
    config->writeEntry( "GridToFront" , m_bGridToFont );
318
 
    config->writeEntry( "SnapToGrid" , m_bSnapToGrid );
319
 
    config->writeEntry( "ResolutionX", m_gridX );
320
 
    config->writeEntry( "ResolutionY", m_gridY );
321
 
    config->writeEntry( "HelpLineToFront" , m_bHelplinesToFront );
 
325
    KConfigGroup group( KoGlobal::kofficeConfig(), "Spelling" );
 
326
    group.writeEntry( "PersonalDict", m_spellCheckPersonalDict );
 
327
    if ( !isEmbedded() )
 
328
    {
 
329
        KConfig *config = KPresenterFactory::global()->config();
 
330
        config->setGroup( "Interface" );
 
331
        config->writeEntry( "Zoom", m_zoomHandler->zoom() );
 
332
        config->writeEntry( "AllowAutoFormat" , m_bAllowAutoFormat );
 
333
        config->writeEntry( "ViewFormattingChars", m_bViewFormattingChars );
 
334
        config->writeEntry( "ShowGrid" , m_bShowGrid );
 
335
        config->writeEntry( "GridToFront" , m_bGridToFont );
 
336
        config->writeEntry( "SnapToGrid" , m_bSnapToGrid );
 
337
        config->writeEntry( "ResolutionX", m_gridX );
 
338
        config->writeEntry( "ResolutionY", m_gridY );
 
339
        config->writeEntry( "HelpLineToFront" , m_bHelplinesToFront );
 
340
    }
322
341
}
323
342
 
324
343
void KPresenterDoc::initConfig()
328
347
    if( config->hasGroup("Interface") ) {
329
348
        config->setGroup( "Interface" );
330
349
        setAutoSave( config->readNumEntry( "AutoSave", defaultAutoSave()/60 ) * 60 );
331
 
        setBackupFile( config->readNumEntry("BackupFile", true));
 
350
        setBackupFile( config->readBoolEntry("BackupFile", true));
332
351
        setCursorInProtectedArea( config->readBoolEntry( "cursorInProtectArea", true ));
333
352
 
334
353
        // Config-file value in mm, default 10 pt
362
381
        setGridColor(config->readColorEntry( "GridColor", &oldGridColor ));
363
382
    }
364
383
 
365
 
    KOSpellConfig kosconfig;
366
384
 
367
385
    if( config->hasGroup("KSpell kpresenter" ) )
368
386
    {
369
387
        config->setGroup( "KSpell kpresenter" );
370
 
        kosconfig.setNoRootAffix(config->readNumEntry ("KSpell_NoRootAffix", 0));
371
 
        kosconfig.setRunTogether(config->readNumEntry ("KSpell_RunTogether", 0));
372
 
        kosconfig.setDictionary(config->readEntry ("KSpell_Dictionary", ""));
373
 
        kosconfig.setDictFromList(config->readNumEntry ("KSpell_DictFromList", FALSE));
374
 
        kosconfig.setEncoding(config->readNumEntry ("KSpell_Encoding", KS_E_ASCII));
375
 
        kosconfig.setClient(config->readNumEntry ("KSpell_Client", KS_CLIENT_ISPELL));
376
 
        kosconfig.setDontCheckUpperWord(config->readBoolEntry("KSpell_dont_check_upper_word",false));
377
 
        kosconfig.setDontCheckTitleCase(config->readBoolEntry("KSpell_dont_check_title_case",false));
378
 
        kosconfig.setIgnoreCase( config->readNumEntry( "KSpell_IgnoreCase", 0));
379
 
        kosconfig.setIgnoreAccent( config->readNumEntry( "KSpell_IgnoreAccent", 0));
380
 
        kosconfig.setSpellWordWithNumber( config->readNumEntry("KSpell_SpellWordWithNumber", false));
381
 
        setKOSpellConfig(kosconfig);
382
 
 
383
 
        m_bgSpellCheck->enableBackgroundSpellCheck(config->readBoolEntry( "SpellCheck", false ));
384
 
 
 
388
 
 
389
       // Default is false for spellcheck, but the spell-check config dialog
 
390
       // should write out "true" when the user configures spell checking.
 
391
#ifdef HAVE_LIBKSPELL2
 
392
        if ( isReadWrite() )
 
393
          m_bgSpellCheck->setEnabled(config->readBoolEntry( "SpellCheck", false ));
 
394
       else
 
395
          m_bgSpellCheck->setEnabled( false );
 
396
#endif
385
397
    }
386
398
    int undo=30;
387
399
    if(config->hasGroup("Misc" ) )
399
411
        setBackupPath(config->readPathEntry( "backup path" ));
400
412
    }
401
413
 
 
414
    // Load personal dict
 
415
    KConfigGroup group( KoGlobal::kofficeConfig(), "Spelling" );
 
416
    m_spellCheckPersonalDict = group.readListEntry( "PersonalDict" );
 
417
 
402
418
    // Apply configuration, without creating an undo/redo command
403
419
    replaceObjs( false );
404
 
    zoomHandler()->setZoomAndResolution( zoom, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
 
420
    zoomHandler()->setZoom( zoom );
405
421
    newZoomAndResolution(false,false);
406
422
}
407
423
 
417
433
{
418
434
    if(isReadWrite())
419
435
        saveConfig();
420
 
    //_commands.clear(); // done before deleting the objectlist (e.g. for lowraicmd)
 
436
    clearTestCustomSlideShow();
421
437
    //Be carefull !!!!!! don't delete this pointer delete in stickypage
422
438
#if 0
423
439
    delete _header;
430
446
    delete m_varColl;
431
447
    delete m_varFormatCollection;
432
448
    delete dcop;
433
 
    delete m_stickyPage;
 
449
    delete m_masterPage;
 
450
#ifdef HAVE_LIBKSPELL2
434
451
    delete m_bgSpellCheck;
 
452
#endif
435
453
    delete m_styleColl;
436
 
    delete m_pKOSpellConfig;
437
454
 
438
455
    m_pageList.setAutoDelete( true );
439
456
    m_pageList.clear();
454
471
{
455
472
    int i = 0;
456
473
 
457
 
    if ( saveOnlyPage == -1 ) // Don't save all children into template for one page
458
 
        // ###### TODO: save objects that are on that page
459
 
    {
460
 
        QPtrListIterator<KoDocumentChild> it( children() );
461
 
        for( ; it.current(); ++it ) {
462
 
            // Don't save children that are only in the undo/redo history
463
 
            // but not anymore in the presentation
464
 
            QPtrListIterator<KPrPage> pageIt( m_pageList );
465
 
            for ( ; pageIt.current(); ++pageIt )
 
474
    QPtrListIterator<KoDocumentChild> it( children() );
 
475
    for( ; it.current(); ++it ) {
 
476
        // Don't save children that are only in the undo/redo history
 
477
        // but not anymore in the presentation
 
478
        QPtrListIterator<KPrPage> pageIt( m_pageList );
 
479
        for ( int pagePos = 0; pageIt.current(); ++pageIt, ++pagePos )
 
480
        {
 
481
            if ( saveOnlyPage == -1 || pagePos == saveOnlyPage )
466
482
            {
467
483
                QPtrListIterator<KPObject> oIt(pageIt.current()->objectList());
468
484
                for (; oIt.current(); ++oIt )
476
492
                    }
477
493
                }
478
494
            }
479
 
            QPtrListIterator<KPObject> oIt(m_stickyPage->objectList());
 
495
        }
 
496
        if ( saveOnlyPage == -1 )
 
497
        {
 
498
            QPtrListIterator<KPObject> oIt(m_masterPage->objectList());
480
499
            for (; oIt.current(); ++oIt )
481
500
            {
482
501
                if ( oIt.current()->getType() == OT_PART &&
483
 
                     dynamic_cast<KPPartObject*>( oIt.current() )->getChild() == it.current() )
 
502
                        dynamic_cast<KPPartObject*>( oIt.current() )->getChild() == it.current() )
484
503
                {
485
504
                    if (((KoDocumentChild*)(it.current()))->document()!=0)
486
505
                        if ( !((KoDocumentChild*)(it.current()))->document()->saveToStore( _store, QString::number( i++ ) ) )
539
558
    if ( saveOnlyPage == -1 )
540
559
        emit sigProgress( 10 );
541
560
 
 
561
    //TODO save correct page info for header/footer
542
562
    element=doc.createElement("HEADER");
543
 
    element.setAttribute("show", static_cast<int>( hasHeader() ));
 
563
    element.setAttribute("show", static_cast<int>( m_pageList.at(0)->hasHeader() ));
544
564
    element.appendChild(_header->save( doc,0 ));
545
565
    presenter.appendChild(element);
546
566
 
547
567
    element=doc.createElement("FOOTER");
548
 
    element.setAttribute("show", static_cast<int>( hasFooter() ));
 
568
    element.setAttribute("show", static_cast<int>( m_pageList.at(0)->hasFooter() ));
549
569
    element.appendChild(_footer->save( doc,0 ));
550
570
    presenter.appendChild(element);
551
571
 
 
572
    element = doc.createElement( "HEADERFOOTERBYPAGE" );
 
573
    element.setAttribute( "value", "true" );
 
574
    presenter.appendChild( element );
 
575
 
552
576
    element=doc.createElement("HELPLINES");
553
577
    element.setAttribute("show", static_cast<int>( showHelplines() ));
554
578
    saveHelpLines( doc, element );
556
580
 
557
581
    if ( saveOnlyPage == -1 )
558
582
    {
559
 
        if( !m_spellListIgnoreAll.isEmpty() )
 
583
        if( !m_spellCheckIgnoreList.isEmpty() )
560
584
        {
561
585
            QDomElement spellCheckIgnore = doc.createElement( "SPELLCHECKIGNORELIST" );
562
586
            presenter.appendChild( spellCheckIgnore );
563
 
            for ( QStringList::Iterator it = m_spellListIgnoreAll.begin(); it != m_spellListIgnoreAll.end(); ++it )
 
587
            for ( QStringList::Iterator it = m_spellCheckIgnoreList.begin(); it != m_spellCheckIgnoreList.end(); ++it )
564
588
            {
565
589
                QDomElement spellElem = doc.createElement( "SPELLCHECKIGNOREWORD" );
566
590
                spellCheckIgnore.appendChild( spellElem );
589
613
    element.setAttribute("value", _spManualSwitch);
590
614
    presenter.appendChild(element);
591
615
    element=doc.createElement("PRESSPEED");
592
 
    element.setAttribute("value", static_cast<int>( presSpeed ));
 
616
//TODO FIXME !!!!!!!!!!
 
617
//element.setAttribute("value", static_cast<int>( presSpeed ));
593
618
    presenter.appendChild(element);
594
619
    element=doc.createElement("SHOWPRESENTATIONDURATION");
595
620
    element.setAttribute("value", _showPresentationDuration);
596
621
    presenter.appendChild(element);
597
622
 
598
623
    if ( saveOnlyPage == -1 )
 
624
    {
 
625
        if ( !m_customListSlideShow.isEmpty() )
 
626
        {
 
627
            element = doc.createElement( "CUSTOMSLIDESHOWCONFIG" );
 
628
            ListCustomSlideShow::Iterator it;
 
629
            for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
 
630
            {
 
631
                QDomElement slide=doc.createElement("CUSTOMSLIDESHOW");
 
632
                slide.setAttribute("name", it.key() );
 
633
                QString tmp;
 
634
                QValueListIterator<KPrPage*> itPage ;
 
635
                for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
 
636
                {
 
637
                    int posPage = m_pageList.find(*itPage );
 
638
                    if ( posPage != -1 )
 
639
                        tmp+=( *itPage )->oasisNamePage(posPage+1)+",";
 
640
                }
 
641
                slide.setAttribute( "pages", tmp );
 
642
                element.appendChild(slide);
 
643
            }
 
644
            presenter.appendChild(element);
 
645
 
 
646
        }
 
647
 
 
648
        if ( !m_presentationName.isEmpty() )
 
649
        {
 
650
            element = doc.createElement( "DEFAULTCUSTOMSLIDESHOWNAME" );
 
651
            element.setAttribute( "name", m_presentationName );
 
652
            presenter.appendChild(element);
 
653
        }
 
654
    }
 
655
 
 
656
    if ( saveOnlyPage == -1 )
599
657
        emit sigProgress( 40 );
600
658
 
601
659
    if ( saveOnlyPage == -1 )
616
674
    {
617
675
        QDomElement styles = doc.createElement( "STYLES" );
618
676
        presenter.appendChild( styles );
619
 
        QPtrList<KoStyle> m_styleList(m_styleColl->styleList());
620
 
        for ( KoStyle * p = m_styleList.first(); p != 0L; p = m_styleList.next() )
 
677
        QPtrList<KoParagStyle> styleList(m_styleColl->styleList());
 
678
        for ( KoParagStyle * p = styleList.first(); p != 0L; p = styleList.next() )
621
679
            saveStyle( p, styles );
622
680
 
623
681
        emit sigProgress( 60 );
631
689
        for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
632
690
            if ( saveOnlyPage != -1 && i != saveOnlyPage )
633
691
                continue;
634
 
            double offset=i*m_pageList.at(i)->getPageRect().height();
 
692
            double offset=0;
 
693
            if ( saveOnlyPage == -1 )
 
694
            {
 
695
                offset = i * m_pageList.at(i)->getPageRect().height();
 
696
            }
635
697
            saveEmbeddedObject(m_pageList.at(i), chl.current(),doc,presenter,offset );
636
698
        }
637
 
        saveEmbeddedObject(m_stickyPage, chl.current(),doc,presenter,0.0 );
 
699
        if ( saveOnlyPage == -1 )
 
700
        {
 
701
            saveEmbeddedObject(m_masterPage, chl.current(),doc,presenter,0.0 );
 
702
        }
638
703
    }
639
704
 
640
705
    if ( saveOnlyPage == -1 )
657
722
    QDomElement soundFiles = saveUsedSoundFileToXML( doc, usedSoundFile );
658
723
    presenter.appendChild( soundFiles );
659
724
 
660
 
    setModified( false );
 
725
    if ( saveOnlyPage == -1 )
 
726
        setModified( false );
661
727
    return doc;
662
728
}
663
729
 
665
731
                                       QDomDocument &doc,QDomElement &presenter )
666
732
{
667
733
    QPtrListIterator<KoDocumentChild> chl( childList );
668
 
    double offset=m_pageList.findRef(page)*page->getPageRect().height();
 
734
    double offset = 0.0;
 
735
    // we need no offset for objects on the master page and when we copy a page
 
736
    if ( m_pageList.findRef( page ) )
 
737
    {
 
738
        offset=m_pageList.findRef(page)*page->getPageRect().height();
 
739
    }
669
740
    for( ; chl.current(); ++chl )
670
741
        saveEmbeddedObject(page, chl.current(),doc,presenter, offset );
671
742
}
674
745
                                       QDomElement &presenter, double offset )
675
746
{
676
747
    QPtrListIterator<KPObject> oIt(page->objectList());
677
 
    for (; oIt.current(); ++oIt )
 
748
    for ( int pos = 0; oIt.current(); ++oIt, ++pos )
678
749
    {
679
750
        if ( oIt.current()->getType() == OT_PART &&
680
751
             static_cast<KPPartObject*>( oIt.current() )->getChild() == chl )
695
766
            curr->setGeometry( _rect ); // replace zoom value
696
767
 
697
768
            QDomElement settings=doc.createElement("SETTINGS");
698
 
            if (  oIt.current()->isSticky() )
 
769
            settings.setAttribute( "z-index", pos );
 
770
            if ( page == m_masterPage )
699
771
                settings.setAttribute("sticky", 1 );
700
772
            QPtrListIterator<KPObject> setOIt(page->objectList());
701
773
            for (; setOIt.current(); ++setOIt )
711
783
 
712
784
}
713
785
 
 
786
//TODO with changes with new file format header/footer can't be change
 
787
void KPresenterDoc::compatibilityFromOldFileFormat()
 
788
{
 
789
    //function to keep compatibility with old file format
 
790
    //for example for presSpeed
 
791
    if ( m_loadingInfo && m_loadingInfo->oldFormat() )
 
792
    {
 
793
        EffectSpeed newValue = ES_MEDIUM;
 
794
        bool presSpeedChanged = ( m_loadingInfo->presSpeed != -1 );
 
795
        if ( presSpeedChanged )
 
796
        {
 
797
            if ( m_loadingInfo->presSpeed < 3 )
 
798
                newValue = ES_SLOW;
 
799
            else if ( m_loadingInfo->presSpeed > 7 )
 
800
                newValue = ES_FAST;
 
801
        }
 
802
        if ( !m_loadingInfo->m_headerFooterByPage )
 
803
        {
 
804
            for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
 
805
            {
 
806
                if ( presSpeedChanged )
 
807
                    m_pageList.at(i)->setPageEffectSpeed( newValue );
 
808
                m_pageList.at( i )->setHeader( m_loadingInfo->m_header );
 
809
                m_pageList.at( i )->setFooter( m_loadingInfo->m_footer );
 
810
            }
 
811
        }
 
812
 
 
813
    }
 
814
    delete m_loadingInfo;
 
815
    m_loadingInfo = 0L;
 
816
 
 
817
}
 
818
 
714
819
void KPresenterDoc::enableEmbeddedParts( bool f )
715
820
{
716
821
    QPtrListIterator<KPrPage> it( m_pageList );
725
830
    for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ ) {
726
831
        if ( saveOnlyPage != -1 && i != saveOnlyPage )
727
832
            continue;
728
 
        kpbackground = m_pageList.at(i)->background();
729
 
        fragment.appendChild(kpbackground->save( doc, (specialOutputFlag()==SaveAsKOffice1dot1) ));
 
833
        fragment.appendChild( m_pageList.at(i)->save( doc, (specialOutputFlag()==SaveAsKOffice1dot1) ));
730
834
    }
 
835
    // save backgound of masterpage
 
836
    fragment.appendChild( m_masterPage->save( doc, (specialOutputFlag()==SaveAsKOffice1dot1) ) );
731
837
    return fragment;
732
838
}
733
839
 
745
851
    if ( !_duplicatePage ) //don't copy sticky objects when we duplicate page
746
852
    {
747
853
        //offset = 0.0 when it's a sticky page.
748
 
        objects=m_stickyPage->saveObjects( doc, objects, /*yoffset*/0.0, m_zoomHandler, saveOnlyPage );
 
854
        objects=m_masterPage->saveObjects( doc, objects, /*yoffset*/0.0, m_zoomHandler, saveOnlyPage );
749
855
    }
750
856
 
751
857
    return objects;
856
962
    return true;
857
963
}
858
964
 
 
965
int KPresenterDoc::supportedSpecialFormats() const
 
966
{
 
967
    return SaveAsKOffice1dot1 | KoDocument::supportedSpecialFormats();
 
968
}
 
969
 
859
970
void KPresenterDoc::saveUsedSoundFileToStore( KoStore *_store, QStringList _list )
860
971
{
861
972
    unsigned int i = 0;
888
999
                return false;
889
1000
        }
890
1001
    }
891
 
    return true;
892
 
}
 
1002
    else // instead load form the correct child on, m_childCountBeforeInsert has the be set
 
1003
    {
 
1004
        QPtrListIterator<KoDocumentChild> it( children() );
 
1005
        for( int i = 0; it.current(); ++it, ++i ) {
 
1006
            if ( i < m_childCountBeforeInsert )
 
1007
                continue;
 
1008
            if ( !((KoDocumentChild*)it.current())->loadDocument( _store ) )
 
1009
                return false;
 
1010
        }
 
1011
    }
 
1012
    return true;
 
1013
}
 
1014
 
 
1015
bool KPresenterDoc::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
 
1016
{
 
1017
 
 
1018
    //todo necessary for new format ?
 
1019
    if ( saveOnlyPage == -1 ) {
 
1020
        emit sigProgress( 0 );
 
1021
    }
 
1022
    if ( !store->open( "content.xml" ) )
 
1023
        return false;
 
1024
    m_pictureCollection.assignUniqueIds();
 
1025
    KoStoreDevice contentDev( store );
 
1026
    KoXmlWriter* contentWriter = createOasisXmlWriter( &contentDev, "office:document-content" );
 
1027
 
 
1028
 
 
1029
    m_varColl->variableSetting()->setModificationDate(QDateTime::currentDateTime());
 
1030
    recalcVariables( VT_DATE );
 
1031
    recalcVariables( VT_TIME );
 
1032
 
 
1033
    KoGenStyles mainStyles;
 
1034
    KoSavingContext savingContext( mainStyles, 0, false, KoSavingContext::Store );
 
1035
 
 
1036
    // Save user styles as KoGenStyle objects
 
1037
    KoSavingContext::StyleNameMap map = m_styleColl->saveOasis( mainStyles, KoGenStyle::STYLE_USER, savingContext );
 
1038
    savingContext.setStyleNameMap( map );
 
1039
 
 
1040
    KTempFile contentTmpFile;
 
1041
    contentTmpFile.setAutoDelete( true );
 
1042
    QFile* tmpFile = contentTmpFile.file();
 
1043
    KoXmlWriter contentTmpWriter( tmpFile, 1 );
 
1044
 
 
1045
 
 
1046
    //For sticky objects
 
1047
    KTempFile stickyTmpFile;
 
1048
    stickyTmpFile.setAutoDelete( true );
 
1049
    QFile* tmpStickyFile = stickyTmpFile.file();
 
1050
    KoXmlWriter stickyTmpWriter( tmpStickyFile, 1 );
 
1051
 
 
1052
 
 
1053
    contentTmpWriter.startElement( "office:body" );
 
1054
    contentTmpWriter.startElement( "office:presentation" );
 
1055
 
 
1056
    int indexObj = 1;
 
1057
    int partIndexObj = 0;
 
1058
//save page
 
1059
 
 
1060
    if ( saveOnlyPage != -1 )
 
1061
    {
 
1062
        m_pageList.at( saveOnlyPage )->saveOasisPage( store, contentTmpWriter, ( saveOnlyPage+1 ), savingContext, indexObj, partIndexObj , manifestWriter);
 
1063
    }
 
1064
    else
 
1065
    {
 
1066
        for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
 
1067
        {
 
1068
            m_pageList.at( i )->saveOasisPage( store, contentTmpWriter, ( i+1 ), savingContext, indexObj, partIndexObj , manifestWriter);
 
1069
        }
 
1070
    }
 
1071
    QString styleMasterNamePage;
 
1072
    if ( !_duplicatePage )
 
1073
    {
 
1074
        m_masterPage->saveOasisStickyPage( store, stickyTmpWriter , savingContext, indexObj,partIndexObj, manifestWriter );
 
1075
        styleMasterNamePage = m_masterPage->saveOasisPageStyle( store, savingContext.mainStyles() );
 
1076
 
 
1077
    }
 
1078
    if ( saveOnlyPage == -1 ) //don't save setting when we save on page
 
1079
    {
 
1080
        saveOasisHeaderFooter( stickyTmpWriter , savingContext );
 
1081
        saveOasisPresentationSettings( contentTmpWriter );
 
1082
    }
 
1083
 
 
1084
    contentTmpWriter.endElement(); //office:presentation
 
1085
    contentTmpWriter.endElement(); //office:body
 
1086
 
 
1087
    writeAutomaticStyles( *contentWriter, mainStyles, savingContext );
 
1088
 
 
1089
    // And now we can copy over the contents from the tempfile to the real one
 
1090
    tmpFile->close();
 
1091
    contentWriter->addCompleteElement( tmpFile );
 
1092
    contentTmpFile.close();
 
1093
 
 
1094
    contentWriter->endElement(); // root element
 
1095
    contentWriter->endDocument();
 
1096
    delete contentWriter;
 
1097
 
 
1098
    if ( !store->close() ) // done with content.xml
 
1099
        return false;
 
1100
 
 
1101
 
 
1102
    KoGenStyle pageLayout = m_pageLayout.saveOasis();
 
1103
    pageLayout.addAttribute( "style:page-usage", "all" ); // needed?
 
1104
    mainStyles.lookup( pageLayout, "pm" );
 
1105
 
 
1106
 
 
1107
    //add manifest line for content.xml
 
1108
    manifestWriter->addManifestEntry( "content.xml", "text/xml" );
 
1109
 
 
1110
    if ( !store->open( "styles.xml" ) )
 
1111
        return false;
 
1112
 
 
1113
    manifestWriter->addManifestEntry( "styles.xml", "text/xml" );
 
1114
 
 
1115
    //todo fixme????
 
1116
    tmpStickyFile->close();
 
1117
    saveOasisDocumentStyles( store, mainStyles, tmpStickyFile, styleMasterNamePage);
 
1118
    stickyTmpFile.close();
 
1119
 
 
1120
    if ( !store->close() ) // done with styles.xml
 
1121
        return false;
 
1122
 
 
1123
 
 
1124
    if ( saveOnlyPage == -1 )
 
1125
        emit sigProgress( 90 );
 
1126
 
 
1127
    // Save sound file list.
 
1128
//todo ????
 
1129
 
 
1130
 
 
1131
    makeUsedPixmapList();
 
1132
 
 
1133
    m_pictureCollection.saveOasisToStore( store, usedPictures, manifestWriter);
 
1134
 
 
1135
    if(!store->open("settings.xml"))
 
1136
        return false;
 
1137
 
 
1138
    KoXmlWriter& settingsWriter = *createOasisXmlWriter(&contentDev, "office:document-settings");
 
1139
    settingsWriter.startElement("office:settings");
 
1140
 
 
1141
    settingsWriter.startElement("config:config-item-set");
 
1142
    settingsWriter.addAttribute("config:name", "view-settings");
 
1143
 
 
1144
    KoUnit::saveOasis(&settingsWriter, m_unit);
 
1145
    saveOasisSettings( settingsWriter );
 
1146
 
 
1147
    settingsWriter.endElement(); // config:config-item-set
 
1148
 
 
1149
    settingsWriter.startElement("config:config-item-set");
 
1150
    settingsWriter.addAttribute("config:name", "configuration-settings");
 
1151
    settingsWriter.addConfigItem("SpellCheckerIgnoreList", m_spellCheckIgnoreList.join( "," ) );
 
1152
    settingsWriter.endElement(); // config:config-item-set
 
1153
 
 
1154
    m_varColl->variableSetting()->saveOasis( settingsWriter );
 
1155
 
 
1156
    settingsWriter.endElement(); // office:settings
 
1157
    settingsWriter.endElement(); // Root:Element
 
1158
    settingsWriter.endDocument();
 
1159
    delete &settingsWriter;
 
1160
 
 
1161
    if(!store->close())
 
1162
        return false;
 
1163
 
 
1164
    manifestWriter->addManifestEntry("settings.xml", "text/xml");
 
1165
 
 
1166
    //reset progressbar
 
1167
    emit sigProgress( 100 );
 
1168
    emit sigProgress( -1 );
 
1169
 
 
1170
    setModified( false );
 
1171
 
 
1172
    return true;
 
1173
}
 
1174
 
 
1175
void KPresenterDoc::loadOasisIgnoreList( const KoOasisSettings& settings )
 
1176
{
 
1177
    KoOasisSettings::Items configurationSettings = settings.itemSet( "configuration-settings" );
 
1178
    if ( !configurationSettings.isNull() )
 
1179
    {
 
1180
        const QString ignorelist = configurationSettings.parseConfigItemString( "SpellCheckerIgnoreList" );
 
1181
        m_spellCheckIgnoreList = QStringList::split( ',', ignorelist );
 
1182
    }
 
1183
}
 
1184
 
 
1185
void KPresenterDoc::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles, KoSavingContext& context )
 
1186
{
 
1187
    context.writeFontFaces( contentWriter );
 
1188
    contentWriter.startElement( "office:automatic-styles" );
 
1189
    QValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_AUTO );
 
1190
    QValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
 
1191
    for ( ; it != styles.end() ; ++it ) {
 
1192
        (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
 
1193
    }
 
1194
 
 
1195
    styles = mainStyles.styles( KoGenStyle::STYLE_AUTO_LIST );
 
1196
    it = styles.begin();
 
1197
    for ( ; it != styles.end() ; ++it ) {
 
1198
        ( *it ).style->writeStyle( &contentWriter, mainStyles, "text:list-style", (*it).name, 0 );
 
1199
    }
 
1200
 
 
1201
    styles = mainStyles.styles( STYLE_BACKGROUNDPAGEAUTO );
 
1202
    it = styles.begin();
 
1203
    for ( ; it != styles.end() ; ++it ) {
 
1204
        (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:drawing-page-properties" );
 
1205
    }
 
1206
 
 
1207
    styles = mainStyles.styles( KoGenStyle::STYLE_GRAPHICAUTO );
 
1208
    it = styles.begin();
 
1209
    for ( ; it != styles.end() ; ++it ) {
 
1210
        (*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties"  );
 
1211
    }
 
1212
 
 
1213
    styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_DATE );
 
1214
    it = styles.begin();
 
1215
    for ( ; it != styles.end() ; ++it ) {
 
1216
        (*it).style->writeStyle( &contentWriter, mainStyles, "number:date-style", (*it).name, 0 /*TODO ????*/  );
 
1217
    }
 
1218
    styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_TIME );
 
1219
    it = styles.begin();
 
1220
    for ( ; it != styles.end() ; ++it ) {
 
1221
        (*it).style->writeStyle( &contentWriter, mainStyles, "number:time-style", (*it).name, 0 /*TODO ????*/  );
 
1222
    }
 
1223
 
 
1224
    contentWriter.endElement(); // office:automatic-styles
 
1225
}
 
1226
 
 
1227
void KPresenterDoc::saveOasisHeaderFooter( KoXmlWriter & stickyTmpWriter , KoSavingContext& context )
 
1228
{
 
1229
    stickyTmpWriter.startElement( "style:header" );
 
1230
    header()->textObject()->saveOasisContent( stickyTmpWriter, context );
 
1231
    stickyTmpWriter.endElement();
 
1232
 
 
1233
    stickyTmpWriter.startElement( "style:footer" );
 
1234
    footer()->textObject()->saveOasisContent( stickyTmpWriter, context );
 
1235
    stickyTmpWriter.endElement();
 
1236
}
 
1237
 
 
1238
void KPresenterDoc::loadOasisHeaderFooter(QDomNode & drawPage, KoOasisContext & context)
 
1239
{
 
1240
    QDomNode tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "header" );
 
1241
    if ( !tmp.isNull() )
 
1242
    {
 
1243
        //kdDebug()<<" there is a header \n";
 
1244
        _header->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
 
1245
    }
 
1246
    tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "footer" );
 
1247
    if ( !tmp.isNull() )
 
1248
    {
 
1249
        //kdDebug()<<" there is a footer \n";
 
1250
        _footer->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
 
1251
    }
 
1252
}
 
1253
 
 
1254
void KPresenterDoc::saveOasisSettings( KoXmlWriter &settingsWriter )
 
1255
{
 
1256
    settingsWriter.startElement("config:config-item-map-indexed");
 
1257
    settingsWriter.addAttribute("config:name", "Views");
 
1258
    settingsWriter.startElement( "config:config-item-map-entry" );
 
1259
 
 
1260
    //ooimpress save it as this line.
 
1261
    //<config:config-item config:name="SnapLinesDrawing" config:type="string">H2260V14397H7693H12415H15345H1424</config:config-item>
 
1262
    QString helpLineOasis;
 
1263
    //save in mm as in oo
 
1264
    for(QValueList<double>::Iterator it = m_vertHelplines.begin(); it != m_vertHelplines.end(); ++it)
 
1265
    {
 
1266
        int tmpX = ( int ) ( KoUnit::toMM( *it  )*100 );
 
1267
        helpLineOasis+="V"+QString::number( tmpX );
 
1268
    }
 
1269
 
 
1270
    for(QValueList<double>::Iterator it = m_horizHelplines.begin(); it != m_horizHelplines.end(); ++it)
 
1271
    {
 
1272
        int tmpY = ( int ) ( KoUnit::toMM( *it  )*100 );
 
1273
        helpLineOasis+="H"+QString::number( tmpY );
 
1274
    }
 
1275
    for(QValueList<KoPoint>::Iterator it = m_helpPoints.begin(); it != m_helpPoints.end(); ++it)
 
1276
    {
 
1277
        QString str( "P%1,%2" );
 
1278
        int tmpX = ( int ) ( KoUnit::toMM( ( *it ).x()  )*100 );
 
1279
        int tmpY = ( int ) ( KoUnit::toMM( ( *it ).y()  )*100 );
 
1280
        helpLineOasis+=str.arg( QString::number( tmpX ) ).arg( QString::number( tmpY ) );
 
1281
    }
 
1282
    if ( !helpLineOasis.isEmpty() )
 
1283
    {
 
1284
        settingsWriter.addConfigItem("SnapLinesDrawing", helpLineOasis );
 
1285
    }
 
1286
    //<config:config-item config:name="IsSnapToGrid" config:type="boolean">false</config:config-item>
 
1287
    settingsWriter.addConfigItem( "IsSnapToGrid", m_bSnapToGrid );
 
1288
 
 
1289
    //<config:config-item config:name="GridFineWidth" config:type="int">500</config:config-item>
 
1290
    settingsWriter.addConfigItem( "GridFineWidth", ( ( int ) ( KoUnit::toMM( ( m_gridX )  )*100 ) ) );
 
1291
 
 
1292
 
 
1293
    //<config:config-item config:name="GridFineHeight" config:type="int">500</config:config-item>
 
1294
    settingsWriter.addConfigItem( "GridFineHeight", ( ( int ) ( KoUnit::toMM( ( m_gridY )  )*100 ) ) );
 
1295
 
 
1296
    //<config:config-item config:name="SelectedPage" config:type="short">3</config:config-item>
 
1297
    //store first view parameter.
 
1298
    int activePage=0;
 
1299
    if ( m_initialActivePage )
 
1300
        activePage=m_pageList.findRef(m_initialActivePage);
 
1301
    activePage = QMAX( activePage, 0);
 
1302
    settingsWriter.addConfigItem( "SelectedPage", activePage );
 
1303
 
 
1304
    //not define into oo spec
 
1305
    settingsWriter.addConfigItem( "SnapLineIsVisible", showHelplines() );
 
1306
    settingsWriter.endElement();
 
1307
    settingsWriter.endElement();
 
1308
}
 
1309
 
 
1310
void KPresenterDoc::loadOasisSettings(const QDomDocument&settingsDoc)
 
1311
{
 
1312
    kdDebug()<<"void KPresenterDoc::loadOasisSettings(const QDomDocument&settingsDoc)**********\n";
 
1313
    KoOasisSettings settings( settingsDoc );
 
1314
    KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
 
1315
    setUnit(KoUnit::unit(viewSettings.parseConfigItemString("unit")));
 
1316
    KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
 
1317
    KoOasisSettings::Items firstView = viewMap.entry( 0 );
 
1318
    if ( !firstView.isNull() )
 
1319
    {
 
1320
        parseOasisHelpLine( firstView.parseConfigItemString( "SnapLinesDrawing" ) );
 
1321
        setShowHelplines( firstView.parseConfigItemBool( "SnapLineIsVisible" ) );
 
1322
        int valx = firstView.parseConfigItemInt( "GridFineWidth" );
 
1323
        m_gridX = MM_TO_POINT( valx / 100.0 );
 
1324
        int valy = firstView.parseConfigItemInt( "GridFineHeight" );
 
1325
        m_gridY = MM_TO_POINT( valy / 100.0 );
 
1326
 
 
1327
        m_bSnapToGrid = firstView.parseConfigItemBool( "IsSnapToGrid" );
 
1328
 
 
1329
        int activePage = firstView.parseConfigItemInt( "SelectedPage" );
 
1330
        kdDebug()<<" activePage :"<<activePage<<endl;
 
1331
        if(activePage!=-1)
 
1332
            m_initialActivePage=m_pageList.at(activePage);
 
1333
 
 
1334
    }
 
1335
    loadOasisIgnoreList( settings );
 
1336
    m_varColl->variableSetting()->loadOasis( settings );
 
1337
}
 
1338
 
 
1339
void KPresenterDoc::parseOasisHelpLine( const QString &text )
 
1340
{
 
1341
    QString str;
 
1342
    int newPos = text.length()-1; //start to element = 1
 
1343
    for ( int pos = text.length()-1; pos >=0;--pos )
 
1344
    {
 
1345
        if ( text[pos]=='P' )
 
1346
        {
 
1347
            //point
 
1348
            str = text.mid( pos+1, ( newPos-pos ) );
 
1349
            //kdDebug()<<" point element  :"<< str <<endl;
 
1350
            QStringList listVal = QStringList::split( ",", str );
 
1351
            int posX = ( listVal[0].toInt()/100 );
 
1352
            int posY = ( listVal[1].toInt()/100 );
 
1353
            m_helpPoints.append( KoPoint( MM_TO_POINT( posX ), MM_TO_POINT( posY )));
 
1354
            newPos = pos-1;
 
1355
        }
 
1356
        else if ( text[pos]=='V' )
 
1357
        {
 
1358
            //vertical element
 
1359
            str = text.mid( pos+1, ( newPos-pos ) );
 
1360
            //kdDebug()<<" vertical  :"<< str <<endl;
 
1361
            int posX = ( str.toInt()/100 );
 
1362
            m_vertHelplines.append( MM_TO_POINT( posX ) );
 
1363
            newPos = pos-1;
 
1364
        }
 
1365
        else if ( text[pos]=='H' )
 
1366
        {
 
1367
            //horizontal element
 
1368
            str = text.mid( pos+1, ( newPos-pos ) );
 
1369
            //kdDebug()<<" horizontal  :"<< str <<endl;
 
1370
            int posY = ( str.toInt()/100 );
 
1371
            m_horizHelplines.append( MM_TO_POINT( posY ) );
 
1372
            newPos = pos-1;
 
1373
        }
 
1374
    }
 
1375
}
 
1376
 
 
1377
void KPresenterDoc::loadOasisPresentationSettings( QDomNode &settingsDoc )
 
1378
{
 
1379
    //kdDebug()<<"presentation:settings ********************************************* \n";
 
1380
    QDomElement settings( settingsDoc.toElement() );
 
1381
    //kdDebug()<<"settings.attribute(presentation:endless) :"<<settings.attributeNS( KoXmlNS::presentation, "endless", QString::null)<<endl;
 
1382
    if (settings.attributeNS( KoXmlNS::presentation, "endless", QString::null)=="true")
 
1383
        _spInfiniteLoop = true;
 
1384
 
 
1385
    if (settings.attributeNS( KoXmlNS::presentation, "force-manual", QString::null)=="true")
 
1386
        _spManualSwitch = true;
 
1387
    if ( settings.hasAttributeNS( KoXmlNS::presentation, "start-page" ) )
 
1388
    {
 
1389
        //TODO allow to start presentation to specific page
 
1390
        //???? = settings.attributeNS( KoXmlNS::presentation, "start-page", QString::null );
 
1391
    }
 
1392
    if ( settings.hasAttributeNS( KoXmlNS::presentation, "show" ) )
 
1393
    {
 
1394
        m_presentationName = settings.attributeNS( KoXmlNS::presentation, "show", QString::null );
 
1395
        kdDebug()<<" default presentation name :"<<m_presentationName<<endl;
 
1396
    }
 
1397
    loadOasisPresentationCustomSlideShow( settingsDoc );
 
1398
}
 
1399
 
 
1400
void KPresenterDoc::loadOasisPresentationCustomSlideShow( QDomNode &settingsDoc )
 
1401
{
 
1402
    //kdDebug()<<"void KPresenterDoc::loadOasisPresentationCustomSlideShow( QDomNode &settingsDoc )**********\n";
 
1403
    for ( QDomNode element = settingsDoc.firstChild(); !element.isNull(); element = element.nextSibling() )
 
1404
    {
 
1405
        QDomElement e = element.toElement();
 
1406
        QCString tagName = e.tagName().latin1();
 
1407
        //kdDebug()<<" tagName :"<<tagName<<endl;
 
1408
        if ( tagName == "show" && e.namespaceURI() == KoXmlNS::presentation)
 
1409
        {
 
1410
            //kdDebug()<<" e.attribute(presentation:name) :"<<e.attributeNS( KoXmlNS::presentation, "name", QString::null)<< " e.attribute(presentation:pages) :"<<e.attributeNS( KoXmlNS::presentation, "pages", QString::null)<<endl;
 
1411
            QStringList tmp = QStringList::split( ",", e.attributeNS( KoXmlNS::presentation, "pages", QString::null) );
 
1412
            m_loadingInfo->m_tmpCustomListMap.insert( e.attributeNS( KoXmlNS::presentation, "name", QString::null), tmp );
 
1413
        }
 
1414
    }
 
1415
}
 
1416
 
 
1417
void KPresenterDoc::saveOasisPresentationSettings( KoXmlWriter &contentTmpWriter )
 
1418
{
 
1419
    //todo don't save when is not value by default (check with oo)
 
1420
    //FIXME
 
1421
    contentTmpWriter.startElement( "presentation:settings" );
 
1422
    contentTmpWriter.addAttribute( "presentation:endless",  ( _spInfiniteLoop ? "true" : "false" ) );
 
1423
    contentTmpWriter.addAttribute( "presentation:force-manual",  ( _spManualSwitch ? "true" : "false" ) );
 
1424
    //add for default presentation
 
1425
    if ( !m_presentationName.isEmpty() )
 
1426
        contentTmpWriter.addAttribute( "presentation:show",  m_presentationName );
 
1427
 
 
1428
    saveOasisPresentationCustomSlideShow( contentTmpWriter );
 
1429
    contentTmpWriter.endElement();
 
1430
}
 
1431
 
 
1432
void KPresenterDoc::saveOasisPresentationCustomSlideShow( KoXmlWriter &contentTmpWriter )
 
1433
{
 
1434
    if ( m_customListSlideShow.isEmpty() )
 
1435
        return;
 
1436
 
 
1437
    ListCustomSlideShow::Iterator it;
 
1438
    for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
 
1439
    {
 
1440
        contentTmpWriter.startElement( "presentation:show" );
 
1441
        contentTmpWriter.addAttribute( "presentation:name", it.key() );
 
1442
        QString tmp;
 
1443
        QValueListIterator<KPrPage*> itPage ;
 
1444
        for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
 
1445
        {
 
1446
            int posPage = m_pageList.find(*itPage );
 
1447
            if ( posPage != -1 )
 
1448
                tmp+=( *itPage )->oasisNamePage(posPage+1)+",";
 
1449
        }
 
1450
        contentTmpWriter.addAttribute( "presentation:pages", tmp );
 
1451
        contentTmpWriter.endElement();
 
1452
    }
 
1453
    //<presentation:show presentation:name="New Custom Slide Show" presentation:pages="page1,page1,page1,page1,page1"/>
 
1454
}
 
1455
 
 
1456
void KPresenterDoc::saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles, QFile* tmpStyckyFile, const QString &_styleMasterPageName ) const
 
1457
{
 
1458
    QString pageLayoutName;
 
1459
    KoStoreDevice stylesDev( store );
 
1460
    KoXmlWriter* stylesWriter = createOasisXmlWriter( &stylesDev, "office:document-styles" );
 
1461
 
 
1462
    stylesWriter->startElement( "office:styles" );
 
1463
    QValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_USER );
 
1464
    QValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
 
1465
    for ( ; it != styles.end() ; ++it ) {
 
1466
        (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
 
1467
    }
 
1468
    styles = mainStyles.styles( KoGenStyle::STYLE_LIST );
 
1469
    it = styles.begin();
 
1470
    for ( ; it != styles.end() ; ++it ) {
 
1471
        (*it).style->writeStyle( stylesWriter, mainStyles, "text:list-style", (*it).name, 0 );
 
1472
    }
 
1473
    styles = mainStyles.styles( KoGenStyle::STYLE_HATCH );
 
1474
    it = styles.begin();
 
1475
    for ( ; it != styles.end() ; ++it ) {
 
1476
        (*it).style->writeStyle( stylesWriter, mainStyles, "draw:hatch", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
 
1477
    }
 
1478
    styles = mainStyles.styles( STYLE_GRADIENT );
 
1479
    it = styles.begin();
 
1480
    for ( ; it != styles.end() ; ++it ) {
 
1481
        (*it).style->writeStyle( stylesWriter, mainStyles, "draw:gradient", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
 
1482
    }
 
1483
 
 
1484
    styles = mainStyles.styles( STYLE_STROKE );
 
1485
    it = styles.begin();
 
1486
    for ( ; it != styles.end() ; ++it ) {
 
1487
        (*it).style->writeStyle( stylesWriter, mainStyles, "draw:stroke-dash", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
 
1488
    }
 
1489
 
 
1490
    styles = mainStyles.styles( STYLE_MARKER );
 
1491
    it = styles.begin();
 
1492
    for ( ; it != styles.end() ; ++it ) {
 
1493
        (*it).style->writeStyle( stylesWriter, mainStyles, "draw:marker", (*it).name, "style:graphic-properties" ,  true,  true /*add draw:name*/);
 
1494
    }
 
1495
    styles = mainStyles.styles( STYLE_PICTURE );
 
1496
    it = styles.begin();
 
1497
    for ( ; it != styles.end() ; ++it ) {
 
1498
        (*it).style->writeStyle( stylesWriter, mainStyles, "draw:fill-image", (*it).name, "style:image-properties" ,  true,  true /*add draw:name*/);
 
1499
    }
 
1500
 
 
1501
    stylesWriter->endElement(); // office:styles
 
1502
 
 
1503
    stylesWriter->startElement( "office:automatic-styles" );
 
1504
    styles = mainStyles.styles( STYLE_BACKGROUNDPAGE );
 
1505
    it = styles.begin();
 
1506
    for ( ; it != styles.end() ; ++it ) {
 
1507
        (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:drawing-page-properties"  );
 
1508
    }
 
1509
 
 
1510
    styles = mainStyles.styles( KoGenStyle::STYLE_PAGELAYOUT );
 
1511
    Q_ASSERT( styles.count() == 1 );
 
1512
    it = styles.begin();
 
1513
    for ( ; it != styles.end() ; ++it ) {
 
1514
        (*it).style->writeStyle( stylesWriter, mainStyles, "style:page-layout", (*it).name, "style:page-layout-properties", false /*don't close*/ );
 
1515
        stylesWriter->endElement();
 
1516
        Q_ASSERT( pageLayoutName.isEmpty() ); // if there's more than one pagemaster we need to rethink all this
 
1517
        pageLayoutName = (*it).name;
 
1518
    }
 
1519
 
 
1520
    styles = mainStyles.styles( STYLE_PRESENTATIONSTICKYOBJECT );
 
1521
    it = styles.begin();
 
1522
    for ( ; it != styles.end() ; ++it ) {
 
1523
        //TODO fix me graphic-properties ???
 
1524
        (*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties"  );
 
1525
    }
 
1526
 
 
1527
    stylesWriter->endElement(); // office:automatic-styles
 
1528
 
 
1529
    //code from kword
 
1530
    stylesWriter->startElement( "office:master-styles" );
 
1531
    stylesWriter->startElement( "style:master-page" );
 
1532
    stylesWriter->addAttribute( "style:name", "Standard" );
 
1533
    stylesWriter->addAttribute( "style:page-layout-name", pageLayoutName );
 
1534
    kdDebug()<<" styleMasterNamePage :"<<_styleMasterPageName<<endl;
 
1535
    if ( !_styleMasterPageName.isEmpty() )
 
1536
        stylesWriter->addAttribute( "draw:style-name", _styleMasterPageName );
 
1537
 
 
1538
 
 
1539
    //save sticky object
 
1540
    stylesWriter->addCompleteElement( tmpStyckyFile );
 
1541
    stylesWriter->endElement();
 
1542
    stylesWriter->endElement(); // office:master-style
 
1543
 
 
1544
 
 
1545
    stylesWriter->endElement(); // root element (office:document-styles)
 
1546
    stylesWriter->endDocument();
 
1547
    delete stylesWriter;
 
1548
}
 
1549
 
 
1550
bool KPresenterDoc::loadOasis( const QDomDocument& doc, KoOasisStyles&oasisStyles, const QDomDocument&settingsDoc, KoStore*store )
 
1551
{
 
1552
    QTime dt;
 
1553
    dt.start();
 
1554
    m_loadingInfo = new KPRLoadingInfo;
 
1555
    ignoreSticky = FALSE;
 
1556
    emit sigProgress( 0 );
 
1557
    int activePage=0;
 
1558
    lastObj = -1;
 
1559
    bool allSlides = false;
 
1560
    // clean
 
1561
    if ( _clean ) {
 
1562
        __pgLayout = KoPageLayout::standardLayout();
 
1563
        _spInfiniteLoop = false;
 
1564
        _spManualSwitch = true;
 
1565
        _showPresentationDuration = false;
 
1566
        _xRnd = 20;
 
1567
        _yRnd = 20;
 
1568
        urlIntern = url().path();
 
1569
    }
 
1570
    else
 
1571
        m_spellCheckIgnoreList.clear();
 
1572
    emit sigProgress( 5 );
 
1573
 
 
1574
    QDomElement content = doc.documentElement();
 
1575
    QDomElement body (KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
 
1576
    if ( body.isNull() )
 
1577
    {
 
1578
        kdError(33001) << "No office:body found!" << endl;
 
1579
        setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
 
1580
        return false;
 
1581
    }
 
1582
    body = KoDom::namedItemNS( body, KoXmlNS::office, "presentation" );
 
1583
    if ( body.isNull() )
 
1584
    {
 
1585
        kdError(33001) << "No office:presentation found!" << endl;
 
1586
        setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
 
1587
       return false;
 
1588
    }
 
1589
        //load settings
 
1590
    QDomNode settings  = KoDom::namedItemNS( body, KoXmlNS::presentation, "settings" );
 
1591
    kdDebug()<<"settings :"<<settings.isNull()<<endl;
 
1592
    if (!settings.isNull() && _clean /*don't load settings when we copy/paste a page*/)
 
1593
        loadOasisPresentationSettings( settings );
 
1594
 
 
1595
// it seems that ooimpress has different paper-settings for every slide.
 
1596
    // we take the settings of the first slide for the whole document.
 
1597
    QDomNode drawPage = KoDom::namedItemNS( body, KoXmlNS::draw, "page" );
 
1598
    if ( drawPage.isNull() ) // no slides? give up.
 
1599
        return false;
 
1600
    QDomElement dp = drawPage.toElement();
 
1601
 
 
1602
    //code from kword
 
1603
    // TODO variable settings
 
1604
    // By default display real variable value
 
1605
    if ( !isReadWrite())
 
1606
        getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
 
1607
 
 
1608
    KoOasisContext context( this, *m_varColl, oasisStyles, store );
 
1609
    Q_ASSERT( !oasisStyles.officeStyle().isNull() );
 
1610
 
 
1611
    // Load all styles before the corresponding paragraphs try to use them!
 
1612
    m_styleColl->loadOasisStyleTemplates( context );
 
1613
 
 
1614
 
 
1615
 
 
1616
 
 
1617
    QString masterPageName = drawPage.toElement().attributeNS( KoXmlNS::draw, "master-page-name", QString::null );
 
1618
    QDomElement *master = oasisStyles.masterPages()[ masterPageName];
 
1619
 
 
1620
    kdDebug()<<" master :"<<master<<endl;
 
1621
    kdDebug()<<" masterPageName:"<<masterPageName<<endl;
 
1622
    if ( ! master )
 
1623
    {
 
1624
        masterPageName = "Standard"; // use default layout as fallback (default in kpresenter)
 
1625
        master = oasisStyles.masterPages()[ masterPageName];
 
1626
        if ( !master ) //last test...
 
1627
            master = oasisStyles.masterPages()["Default"];
 
1628
    }
 
1629
    kdDebug()<<" load sticky oasis object \n";
 
1630
    kdDebug()<<" master.isNull() :"<<master->isNull()<<endl;
 
1631
    QDomNode node = *master;
 
1632
    kdDebug()<<" node.isNull() :"<<node.isNull()<<endl;
 
1633
    loadOasisObject( m_masterPage, node , context);
 
1634
    loadOasisHeaderFooter( node,context );
 
1635
 
 
1636
    kdDebug()<<" end load sticky oasis object \n";
 
1637
 
 
1638
    Q_ASSERT( master );
 
1639
    QDomElement *style =master ? oasisStyles.styles()[master->attributeNS( KoXmlNS::style, "page-layout-name", QString::null )] : 0;
 
1640
    QDomElement *backgroundStyle = oasisStyles.styles()[ "Standard-background"];
 
1641
    kdDebug()<<"Standard background "<<backgroundStyle<<endl;
 
1642
    // parse all pages
 
1643
    Q_ASSERT( style );
 
1644
    if ( style )
 
1645
    {
 
1646
        __pgLayout.loadOasis( *style );
 
1647
        kdDebug()<<"Page size __pgLayout.ptWidth :"<<__pgLayout.ptWidth<<" __pgLayout.ptHeight :"<<__pgLayout.ptHeight<<endl;
 
1648
        kdDebug()<<"Page orientation :"<<(( __pgLayout.orientation== PG_LANDSCAPE )? " landscape " : " portrait ")<<endl;
 
1649
 
 
1650
        kdDebug()<<" margin right:"<< __pgLayout.ptRight <<" __pgLayout.ptBottom :"<<__pgLayout.ptBottom<<" __pgLayout.ptLeft :"<<__pgLayout.ptLeft<<" __pgLayout.ptTop :"<<__pgLayout.ptTop<<endl;
 
1651
    }
 
1652
    if ( _clean )
 
1653
    {
 
1654
        /// ### this has already been done, no?
 
1655
        setPageLayout( __pgLayout );
 
1656
    }
 
1657
 
 
1658
 
 
1659
    int pos = 0;
 
1660
    for ( drawPage = body.firstChild(); !drawPage.isNull(); drawPage = drawPage.nextSibling() )
 
1661
    {
 
1662
        dp = drawPage.toElement();
 
1663
        kdDebug()<<"dp.tagName() :"<<dp.tagName()<<endl;
 
1664
        if ( dp.tagName()== "page" && dp.namespaceURI() == KoXmlNS::draw ) // don't try to parse "</draw:page>" as page
 
1665
        {
 
1666
            context.styleStack().clear(); // remove all styles
 
1667
            fillStyleStack( dp, context );
 
1668
            context.styleStack().save();
 
1669
            kdDebug ()<<"insert new page "<<pos<<endl;
 
1670
            KPrPage *newpage = 0L;
 
1671
            if ( m_pageWhereLoadObject )
 
1672
            {
 
1673
                newpage = m_pageWhereLoadObject;
 
1674
            }
 
1675
            else
 
1676
            {
 
1677
                if ( pos != 0 )
 
1678
                {
 
1679
                    newpage = new KPrPage( this, m_masterPage );
 
1680
                    m_pageList.insert( pos,newpage);
 
1681
                }
 
1682
                else //we create a first page into KPresenterDoc()
 
1683
                {
 
1684
                    newpage = m_pageList.at(pos);
 
1685
                }
 
1686
            }
 
1687
            //m_pageList.at(pos)->insertManualTitle(dp.attributeNS( KoXmlNS::draw, "name", QString::null ));
 
1688
 
 
1689
            //necessary to create a unique name for page
 
1690
            QString str = dp.attributeNS( KoXmlNS::draw, "name", QString::null );
 
1691
            QString idPage = dp.attributeNS( KoXmlNS::draw, "id", QString::null );
 
1692
            if ( str != QString( "page%1" ).arg( idPage ) )
 
1693
                newpage->insertManualTitle(str);
 
1694
            context.styleStack().setTypeProperties( "drawing-page" );
 
1695
            if ( context.styleStack().hasAttributeNS( KoXmlNS::draw, "fill" )
 
1696
                 || context.styleStack().hasAttributeNS( KoXmlNS::presentation, "transition-style" ) )
 
1697
            {
 
1698
                kdDebug()<<" fill or presentation-style found \n";
 
1699
                newpage->loadOasis( context );
 
1700
            }
 
1701
            else if ( !context.styleStack().hasAttributeNS( KoXmlNS::draw, "fill" ) && backgroundStyle)
 
1702
            {
 
1703
                context.styleStack().save();
 
1704
                context.addStyles( backgroundStyle );
 
1705
                newpage->loadOasis(context);
 
1706
                context.styleStack().restore();
 
1707
                kdDebug()<<" load standard background \n";
 
1708
            }
 
1709
 
 
1710
            //All animation object for current page is store into this element
 
1711
            createPresentationAnimation(KoDom::namedItemNS( drawPage, KoXmlNS::presentation, "animations"));
 
1712
            // parse all objects
 
1713
            loadOasisObject( newpage, drawPage, context );
 
1714
 
 
1715
            context.styleStack().restore();
 
1716
            m_loadingInfo->clearAnimationShowDict(); // clear all show animations style
 
1717
            m_loadingInfo->clearAnimationHideDict(); // clear all hide animations style
 
1718
            ++pos;
 
1719
        }
 
1720
    }
 
1721
 
 
1722
 
 
1723
    ignoreSticky = TRUE;
 
1724
    kdDebug()<<" _clean :"<<_clean<<endl;
 
1725
    if(_clean)
 
1726
    {
 
1727
        setModified(false);
 
1728
#if 0   //FIXME
 
1729
        //it crashed, I don't know why for the moment.
 
1730
        startBackgroundSpellCheck();
 
1731
#endif
 
1732
    }
 
1733
    updateCustomListSlideShow( m_loadingInfo->m_tmpCustomListMap, true );
 
1734
    kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
 
1735
 
 
1736
    if ( !settingsDoc.isNull() )
 
1737
    {
 
1738
        loadOasisSettings( settingsDoc );
 
1739
    }
 
1740
    emit sigProgress( 100 );
 
1741
    recalcVariables( VT_FIELD );
 
1742
    emit sigProgress( -1 );
 
1743
 
 
1744
    setModified( false );
 
1745
    return true;
 
1746
}
 
1747
 
 
1748
 
 
1749
void KPresenterDoc::loadOasisObject( KPrPage * newpage, QDomNode & drawPage, KoOasisContext & context, KPGroupObject *groupObject )
 
1750
{
 
1751
    for ( QDomNode object = drawPage.firstChild(); !object.isNull(); object = object.nextSibling() )
 
1752
    {
 
1753
        QDomElement o = object.toElement();
 
1754
        QString name = o.tagName();
 
1755
        kdDebug()<<" name :"<<name<<endl;
 
1756
        context.styleStack().save();
 
1757
        const bool isDrawNS = o.namespaceURI() == KoXmlNS::draw;
 
1758
        //"draw:text-box"
 
1759
        if ( name == "frame" && isDrawNS) // textbox
 
1760
        {
 
1761
            fillStyleStack( o, context );
 
1762
 
 
1763
            QDomNode imageBox = KoDom::namedItemNS( o, KoXmlNS::draw, "image" );
 
1764
            kdDebug()<<" imageBox:"<<imageBox.isNull()<<endl;
 
1765
            if ( !imageBox.isNull() )
 
1766
            {
 
1767
                KPPixmapObject *kppixmapobject = new KPPixmapObject( pictureCollection() );
 
1768
                kppixmapobject->loadOasis( o, context, m_loadingInfo);
 
1769
                if ( groupObject )
 
1770
                    groupObject->addObjects( kppixmapobject );
 
1771
                else
 
1772
                    newpage->appendObject(kppixmapobject);
 
1773
            }
 
1774
            else
 
1775
            {
 
1776
                QDomNode object = KoDom::namedItemNS( o, KoXmlNS::draw, "object" );
 
1777
                kdDebug()<<" object:"<<object.isNull()<<endl;
 
1778
                if ( !object.isNull() )
 
1779
                {
 
1780
                    fillStyleStack( o, context );
 
1781
                    KPresenterChild *ch = new KPresenterChild( this );
 
1782
                    QRect r;
 
1783
                    KPPartObject *kppartobject = new KPPartObject( ch );
 
1784
                    kppartobject->loadOasis( o, context, m_loadingInfo );
 
1785
                    r = ch->geometry();
 
1786
                    if ( groupObject )
 
1787
                        groupObject->addObjects( kppartobject );
 
1788
                    else
 
1789
                        newpage->appendObject(kppartobject);
 
1790
                    insertChild( ch );
 
1791
                    kppartobject->setOrig( r.x(), r.y() );
 
1792
                    kppartobject->setSize( r.width(), r.height() );
 
1793
                }
 
1794
                else
 
1795
                {
 
1796
                    KPTextObject *kptextobject = new KPTextObject( this );
 
1797
                    kptextobject->loadOasis(o, context, m_loadingInfo);
 
1798
                    if ( groupObject )
 
1799
                        groupObject->addObjects( kptextobject );
 
1800
                    else
 
1801
                        newpage->appendObject(kptextobject);
 
1802
                }
 
1803
            }
 
1804
        }
 
1805
        else if ( name == "rect" && isDrawNS) // rectangle
 
1806
        {
 
1807
            fillStyleStack( o, context );
 
1808
            KPRectObject *kprectobject = new KPRectObject();
 
1809
            kprectobject->loadOasis(o, context , m_loadingInfo);
 
1810
            if ( groupObject )
 
1811
                groupObject->addObjects( kprectobject );
 
1812
            else
 
1813
                newpage->appendObject(kprectobject);
 
1814
        }
 
1815
        else if ( ( name == "circle" || name == "ellipse" )&& isDrawNS)
 
1816
        {
 
1817
            fillStyleStack( o, context );
 
1818
            if ( o.hasAttributeNS( KoXmlNS::draw, "kind" ) ) // pie, chord or arc
 
1819
            {
 
1820
                KPPieObject *kppieobject = new KPPieObject();
 
1821
                kppieobject->loadOasis(o, context, m_loadingInfo);
 
1822
                if ( groupObject )
 
1823
                    groupObject->addObjects( kppieobject );
 
1824
                else
 
1825
                    newpage->appendObject(kppieobject);
 
1826
            }
 
1827
            else  // circle or ellipse
 
1828
            {
 
1829
                KPEllipseObject *kpellipseobject = new KPEllipseObject();
 
1830
                kpellipseobject->loadOasis(o,context, m_loadingInfo);
 
1831
                if ( groupObject )
 
1832
                    groupObject->addObjects( kpellipseobject );
 
1833
                else
 
1834
                    newpage->appendObject(kpellipseobject);
 
1835
            }
 
1836
        }
 
1837
        else if ( name == "line" && isDrawNS) // line
 
1838
        {
 
1839
            fillStyleStack( o, context );
 
1840
            KPLineObject *kplineobject = new KPLineObject();
 
1841
            kplineobject->loadOasis(o, context, m_loadingInfo);
 
1842
            if ( groupObject )
 
1843
                groupObject->addObjects( kplineobject );
 
1844
            else
 
1845
                newpage->appendObject( kplineobject );
 
1846
        }
 
1847
        else if (name=="polyline" && isDrawNS) { // polyline
 
1848
            fillStyleStack( o, context );
 
1849
            KPPolylineObject *kppolylineobject = new KPPolylineObject();
 
1850
            kppolylineobject->loadOasis(o, context, m_loadingInfo);
 
1851
            if ( groupObject )
 
1852
                groupObject->addObjects( kppolylineobject );
 
1853
            else
 
1854
                newpage->appendObject(kppolylineobject);
 
1855
        }
 
1856
        else if (name=="polygon" && isDrawNS) { // plcloseobject
 
1857
            fillStyleStack( o, context );
 
1858
            KPClosedLineObject *kpClosedObject = new KPClosedLineObject();
 
1859
            kpClosedObject->loadOasis( o, context, m_loadingInfo);
 
1860
            if ( groupObject )
 
1861
                groupObject->addObjects( kpClosedObject );
 
1862
            else
 
1863
                newpage->appendObject(kpClosedObject);
 
1864
        }
 
1865
        //FIXME wait that it will ok'ed by oo spec
 
1866
        else if (name=="regular-polygon"&& isDrawNS) { // kppolygone object
 
1867
            fillStyleStack( o, context );
 
1868
            KPPolygonObject *kpPolygoneObject = new KPPolygonObject();
 
1869
            kpPolygoneObject->loadOasis( o, context, m_loadingInfo);
 
1870
            if ( groupObject )
 
1871
                groupObject->addObjects( kpPolygoneObject );
 
1872
            else
 
1873
                newpage->appendObject(kpPolygoneObject);
 
1874
        }
 
1875
#if 0 //old code
 
1876
        else if ( name == "image" && isDrawNS) // image
 
1877
        {
 
1878
            fillStyleStack( o, context );
 
1879
            KPPixmapObject *kppixmapobject = new KPPixmapObject( pictureCollection() );
 
1880
            kppixmapobject->loadOasis( o, context, m_loadingInfo);
 
1881
            if ( groupObject )
 
1882
                groupObject->addObjects( kppixmapobject );
 
1883
            else
 
1884
                newpage->appendObject(kppixmapobject);
 
1885
        }
 
1886
#endif
 
1887
        else if ( name == "path" && isDrawNS)
 
1888
        {
 
1889
            //we have 4 elements to use here.
 
1890
            //Cubicbeziercurve/Quadricbeziercurve/closeline/KPFreehandObject
 
1891
            //we must parse svd:d argument
 
1892
            // "z" close element
 
1893
            // "c" cubic element
 
1894
            // "q" quadic element
 
1895
            // parse line we use relative position
 
1896
            // see http://www.w3.org/TR/SVG/paths.html#PathData
 
1897
            // see svgpathparser.cc (ksvg)
 
1898
            QString pathDefinition = o.attributeNS( KoXmlNS::svg, "d", QString::null);
 
1899
            kdDebug()<<"pathDefinition :"<<pathDefinition<<endl;
 
1900
            fillStyleStack( o, context );
 
1901
 
 
1902
            if ( pathDefinition.contains( "c" ) )
 
1903
            {
 
1904
                kdDebug()<<"Cubicbeziercurve \n";
 
1905
                KPCubicBezierCurveObject *kpCurveObject = new KPCubicBezierCurveObject();
 
1906
                kpCurveObject->loadOasis( o, context, m_loadingInfo);
 
1907
                if ( groupObject )
 
1908
                    groupObject->addObjects( kpCurveObject );
 
1909
                else
 
1910
                    newpage->appendObject( kpCurveObject );
 
1911
 
 
1912
            }
 
1913
            else if ( pathDefinition.contains( "q" ) )
 
1914
            {
 
1915
                kdDebug()<<"Quadricbeziercurve \n";
 
1916
                KPQuadricBezierCurveObject *kpQuadricObject = new KPQuadricBezierCurveObject();
 
1917
                kpQuadricObject->loadOasis( o, context, m_loadingInfo);
 
1918
                if ( groupObject )
 
1919
                    groupObject->addObjects( kpQuadricObject );
 
1920
                else
 
1921
                    newpage->appendObject( kpQuadricObject );
 
1922
            }
 
1923
            else
 
1924
            {
 
1925
                kdDebug()<<"KPFreehandObject \n";
 
1926
                KPFreehandObject *kpFreeHandObject = new KPFreehandObject();
 
1927
                kpFreeHandObject->loadOasis( o, context, m_loadingInfo);
 
1928
                if ( groupObject )
 
1929
                    groupObject->addObjects( kpFreeHandObject );
 
1930
                else
 
1931
                    newpage->appendObject( kpFreeHandObject );
 
1932
            }
 
1933
        }
 
1934
        else if ( name == "g" && isDrawNS)
 
1935
        {
 
1936
            fillStyleStack( o, context );
 
1937
            KPGroupObject *kpgroupobject = new KPGroupObject();
 
1938
            QDomNode nodegroup = object.firstChild();
 
1939
 
 
1940
            kpgroupobject->loadOasisGroupObject( this, newpage, object, context, m_loadingInfo);
 
1941
            if ( groupObject )
 
1942
                groupObject->addObjects( kpgroupobject );
 
1943
            else
 
1944
                newpage->appendObject(kpgroupobject);
 
1945
        }
 
1946
        else if ( name == "notes" && o.namespaceURI() == KoXmlNS::presentation ) // notes
 
1947
        {
 
1948
            //we must extend note attribute
 
1949
            //kdDebug()<<"presentation:notes----------------------------------\n";
 
1950
            QDomNode frameBox = KoDom::namedItemNS( o, KoXmlNS::draw, "frame" );
 
1951
            //todo load layout for note.
 
1952
            QDomNode textBox = KoDom::namedItemNS( frameBox, KoXmlNS::draw, "text-box" );
 
1953
 
 
1954
            if ( !textBox.isNull() )
 
1955
            {
 
1956
                QString note;
 
1957
                for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
 
1958
                {
 
1959
                    // We don't care about styles as they are not supported in kpresenter.
 
1960
                    // Only add a linebreak for every child.
 
1961
                    QDomElement t = text.toElement();
 
1962
                    note += t.text() + "\n";
 
1963
                    kdDebug()<<" note :"<<note<<endl;
 
1964
                }
 
1965
                newpage->setNoteText( note );
 
1966
            }
 
1967
        }
 
1968
        else if ( ( name == "header" || name == "footer" ) && o.namespaceURI() == KoXmlNS::style )
 
1969
        {
 
1970
            //nothing
 
1971
        }
 
1972
        else
 
1973
        {
 
1974
            kdDebug() << "Unsupported object '" << name << "'" << endl;
 
1975
            context.styleStack().restore();
 
1976
            continue;
 
1977
        }
 
1978
        context.styleStack().restore();
 
1979
    }
 
1980
 
 
1981
}
 
1982
 
 
1983
int KPresenterDoc::createPresentationAnimation(const QDomElement& element, int order, bool increaseOrder)
 
1984
{
 
1985
  kdDebug()<<"void KPresenterDoc::createPresentationAnimation(const QDomElement& element)\n";
 
1986
  int orderAnimation = increaseOrder ? 0 : order;
 
1987
  for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
 
1988
    {
 
1989
        QDomElement e = n.toElement();
 
1990
        QCString tagName = e.tagName().latin1();
 
1991
        const bool isPresentationNS = e.namespaceURI() == KoXmlNS::presentation;
 
1992
        kdDebug()<<"(createPresentationAnimation) tagName found :"<<tagName<<endl;
 
1993
        if ( tagName == "show-shape" && isPresentationNS )
 
1994
        {
 
1995
            Q_ASSERT( e.hasAttributeNS( KoXmlNS::draw, "shape-id" ) );
 
1996
            QString name = e.attributeNS( KoXmlNS::draw, "shape-id", QString::null );
 
1997
            kdDebug()<<" insert animation show style : name :"<<name<<endl;
 
1998
            QDomElement* ep = new QDomElement( e );
 
1999
            lstAnimation *tmp = new lstAnimation;
 
2000
            tmp->element = ep;
 
2001
            tmp->order = orderAnimation;
 
2002
            m_loadingInfo->storePresentationShowAnimation( tmp, name );
 
2003
            if ( increaseOrder )
 
2004
                ++orderAnimation;
 
2005
 
 
2006
        }
 
2007
        else if ( tagName == "hide-shape" && isPresentationNS)
 
2008
        {
 
2009
            Q_ASSERT( e.hasAttributeNS( KoXmlNS::draw, "shape-id" ) );
 
2010
            QString name = e.attributeNS( KoXmlNS::draw, "shape-id", QString::null );
 
2011
            kdDebug()<<" insert animation hide style : name :"<<name<<endl;
 
2012
            QDomElement* ep = new QDomElement( e );
 
2013
            lstAnimation *tmp = new lstAnimation;
 
2014
            tmp->element = ep;
 
2015
            tmp->order = orderAnimation;
 
2016
            m_loadingInfo->storePresentationHideAnimation( tmp, name );
 
2017
            if ( increaseOrder )
 
2018
                ++orderAnimation;
 
2019
 
 
2020
        }
 
2021
        else if ( tagName == "animation-group" && isPresentationNS)
 
2022
        {
 
2023
            kdDebug()<<" presentation:animation-group exist \n";
 
2024
            orderAnimation = createPresentationAnimation( e, orderAnimation, false );
 
2025
            kdDebug()<<" end presentation:animation-group exist\n";
 
2026
        }
 
2027
    }
 
2028
  //increase when we finish it necessary for group object
 
2029
  ++orderAnimation;
 
2030
  return orderAnimation;
 
2031
}
 
2032
 
 
2033
void KPresenterDoc::fillStyleStack( const QDomElement& object, KoOasisContext & context )
 
2034
{
 
2035
    // find all styles associated with an object and push them on the stack
 
2036
    if ( object.hasAttributeNS( KoXmlNS::presentation, "style-name" ))
 
2037
    {
 
2038
        //kdDebug()<<"Add 'presentation:style-name' \n";
 
2039
        addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::presentation, "style-name", QString::null )], context );
 
2040
    }
 
2041
    if ( object.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
 
2042
    {
 
2043
        kdDebug()<<"draw:style-name :"<<object.attributeNS( KoXmlNS::draw, "style-name", QString::null )<<endl;
 
2044
        addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::draw, "style-name", QString::null )], context);
 
2045
    }
 
2046
    if ( object.hasAttributeNS( KoXmlNS::draw, "text-style-name" ) )
 
2047
    {
 
2048
        //kdDebug()<<"Add 'draw:text-style-name' \n";
 
2049
        addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::draw, "text-style-name", QString::null )], context );
 
2050
    }
 
2051
    if ( object.hasAttributeNS( KoXmlNS::text, "style-name" ) )
 
2052
    {
 
2053
        //kdDebug()<<"Add 'text:style-name' : "<<object.attributeNS( KoXmlNS::text, "style-name", QString::null )<<endl;
 
2054
        addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::text, "style-name", QString::null )], context );
 
2055
    }
 
2056
}
 
2057
 
 
2058
void KPresenterDoc::addStyles( const QDomElement* style, KoOasisContext & context )
 
2059
{
 
2060
    // this function is necessary as parent styles can have parents themself
 
2061
    if ( style->hasAttributeNS( KoXmlNS::style, "parent-style-name" ) )
 
2062
        addStyles( context.oasisStyles().styles()[style->attributeNS( KoXmlNS::style, "parent-style-name", QString::null )], context );
 
2063
    context.addStyles( style );
 
2064
}
 
2065
 
893
2066
 
894
2067
bool KPresenterDoc::loadXML( QIODevice * dev, const QDomDocument& doc )
895
2068
{
896
2069
    QTime dt;
897
2070
    dt.start();
 
2071
    m_loadingInfo = new KPRLoadingInfo( true );
898
2072
 
899
2073
    ignoreSticky = FALSE;
900
2074
    bool b=false;
945
2119
            return false;
946
2120
        }
947
2121
        b = loadXML( newdoc );
948
 
        ignoreSticky = TRUE;
949
2122
    }
950
2123
    else
951
 
    {
952
2124
        b = loadXML( doc );
953
 
        ignoreSticky = TRUE;
954
 
    }
 
2125
 
 
2126
    ignoreSticky = TRUE;
 
2127
 
955
2128
    if(_clean)
956
2129
    {
957
 
        setModified(false);
958
2130
        startBackgroundSpellCheck();
 
2131
        updateCustomListSlideShow( m_loadingInfo->m_tmpCustomListMap, true );
959
2132
    }
960
 
 
 
2133
    if ( m_pageWhereLoadObject == 0 && m_insertFilePage == 0 )
 
2134
        setModified( false );
961
2135
    kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
962
2136
    return b;
963
2137
}
965
2139
void KPresenterDoc::createHeaderFooter()
966
2140
{
967
2141
    //add header/footer to sticky page
968
 
    KoRect pageRect=m_stickyPage->getPageRect();
 
2142
    KoRect pageRect=m_masterPage->getPageRect();
969
2143
    _header->setOrig(pageRect.topLeft());
970
2144
    _header->setSize(pageRect.width(),20);
971
2145
 
972
2146
    _footer->setOrig(pageRect.left(),pageRect.bottom()-20);
973
2147
    _footer->setSize(pageRect.width(),20);
974
2148
 
975
 
    m_stickyPage->appendObject(_header);
976
 
    m_stickyPage->appendObject(_footer);
 
2149
    m_masterPage->appendObject(_header);
 
2150
    m_masterPage->appendObject(_footer);
977
2151
}
978
2152
 
979
 
void KPresenterDoc::insertEmbedded( KoStore *store, QDomElement topElem, KMacroCommand * macroCmd, KPrPage *page )
 
2153
void KPresenterDoc::insertEmbedded( KoStore *store, QDomElement topElem, KMacroCommand * macroCmd, KPrPage *page, int pos )
980
2154
{
981
2155
    QDomElement elem = topElem.firstChild().toElement();
982
2156
    for ( ; !elem.isNull() ; elem = elem.nextSibling().toElement() )
996
2170
                kppartobject = new KPPartObject( ch );
997
2171
            }
998
2172
            QDomElement settings=elem.namedItem("SETTINGS").toElement();
 
2173
            int zIndex = 0;
 
2174
            if ( settings.hasAttribute( "z-index" ) )
 
2175
            {
 
2176
                zIndex = settings.attribute( "z-index" ).toInt();
 
2177
            }
999
2178
            double offset = 0.0;
1000
2179
            if(!settings.isNull() && kppartobject!=0)
1001
2180
                offset=kppartobject->load(settings);
1011
2190
            kppartobject->setOrig(kppartobject->getOrig().x(),newPos);
1012
2191
 
1013
2192
            InsertCmd *insertCmd = new InsertCmd( i18n( "Insert Part Object" ), kppartobject, this,page );
1014
 
            kdDebug(33001)<<" InsertCmd *insertCmd*********************\n";
1015
2193
            insertCmd->execute();
1016
2194
            if ( !macroCmd )
1017
2195
                macroCmd = new KMacroCommand( i18n("Insert Part Object"));
1018
2196
            macroCmd->addCommand( insertCmd );
 
2197
            if ( pos != 0 )
 
2198
            {
 
2199
                QPtrList<KPObject> oldList( page->objectList() );
 
2200
                // tz TODO this is not 100% correct
 
2201
                if ( oldList.count() > pos + zIndex )
 
2202
                {
 
2203
                    page->takeObject( kppartobject );
 
2204
                    page->insertObject( kppartobject, pos + zIndex );
 
2205
                    LowerRaiseCmd *lrCmd = new LowerRaiseCmd( i18n("Insert Part Object"),
 
2206
                                                              oldList, page->objectList(),
 
2207
                                                              this, page );
 
2208
                    macroCmd->addCommand( lrCmd );
 
2209
                }
 
2210
            }
1019
2211
        }
1020
2212
    }
1021
2213
}
1028
2220
    bool allSlides = false;
1029
2221
    // clean
1030
2222
    if ( _clean ) {
1031
 
        //KoPageLayout __pgLayout;
1032
 
        __pgLayout = KoPageLayoutDia::standardLayout();
1033
 
        //__pgLayout.unit = KoUnit::U_MM;
 
2223
        __pgLayout = KoPageLayout::standardLayout();
1034
2224
        _spInfiniteLoop = false;
1035
2225
        _spManualSwitch = true;
1036
2226
        _showPresentationDuration = false;
1040
2230
        urlIntern = url().path();
1041
2231
    }
1042
2232
    else
1043
 
        m_spellListIgnoreAll.clear();
 
2233
        m_spellCheckIgnoreList.clear();
1044
2234
    emit sigProgress( 5 );
1045
2235
 
1046
2236
    QDomElement document=doc.documentElement();
1087
2277
            }
1088
2278
            QDomElement settings=elem.namedItem("SETTINGS").toElement();
1089
2279
            int tmp=0;
 
2280
            int pos = -1;
 
2281
            if ( settings.hasAttribute( "z-index" ) )
 
2282
            {
 
2283
                pos = settings.attribute( "z-index" ).toInt();
 
2284
            }
1090
2285
            if(settings.hasAttribute("sticky"))
1091
2286
                tmp=settings.attribute("sticky").toInt();
1092
2287
            bool sticky=static_cast<bool>(tmp);
1093
2288
            double offset = 0.0;
1094
2289
            if(!settings.isNull() && kppartobject!=0)
 
2290
            {
1095
2291
                offset=kppartobject->load(settings);
 
2292
            }
1096
2293
            else if ( settings.isNull() ) // all embedded obj must have SETTING tags
1097
2294
            {
1098
2295
                delete kppartobject;
1103
2300
                offset = r.y();
1104
2301
            if ( sticky && !ignoreSticky && kppartobject )
1105
2302
            {
1106
 
                m_stickyPage->appendObject(kppartobject );
1107
 
                kppartobject->setOrig(r.x(), offset);
1108
 
                kppartobject->setSize( r.width(), r.height() );
 
2303
                if ( pos == -1 )
 
2304
                {
 
2305
                    m_masterPage->appendObject( kppartobject );
 
2306
                }
 
2307
                else
 
2308
                {
 
2309
                    m_masterPage->insertObject( kppartobject, pos );
 
2310
                }
 
2311
                kppartobject->setOrig(kppartobject->getOrig().x(), offset);
1109
2312
                kppartobject->setSticky(sticky);
1110
2313
            }
1111
2314
            else if ( kppartobject ) {
1112
 
                kppartobject->setOrig( r.x(), 0 );
1113
 
                kppartobject->setSize( r.width(), r.height() );
1114
 
                insertObjectInPage(offset, kppartobject);
 
2315
                if ( m_pageWhereLoadObject )
 
2316
                {
 
2317
                    kppartobject->setOrig(kppartobject->getOrig().x(), offset);
 
2318
                    m_pageWhereLoadObject->insertObject( kppartobject, pos );
 
2319
                }
 
2320
                else
 
2321
                {
 
2322
                    insertObjectInPage( offset, kppartobject, pos );
 
2323
                }
1115
2324
            }
1116
2325
        } else if(elem.tagName()=="PAPER" && _clean)  {
1117
2326
            if(elem.hasAttribute("format"))
1207
2416
                }
1208
2417
                _header->load(elem);
1209
2418
            }
 
2419
        } else if ( elem.tagName()=="HEADERFOOTERBYPAGE" ) {
 
2420
            if ( elem.hasAttribute( "value" ) ) {
 
2421
                m_loadingInfo->m_headerFooterByPage = true;
 
2422
            }
1210
2423
        } else if(elem.tagName()=="FOOTER") {
1211
2424
            if ( _clean /*|| !hasFooter()*/ ) {
1212
2425
                if(elem.hasAttribute("show")) {
1228
2441
            {
1229
2442
                if ( spellWord.tagName()=="SPELLCHECKIGNOREWORD" )
1230
2443
                {
1231
 
                    m_spellListIgnoreAll.append(spellWord.attribute("word"));
 
2444
                    m_spellCheckIgnoreList.append(spellWord.attribute("word"));
1232
2445
                }
1233
2446
                spellWord=spellWord.nextSibling().toElement();
1234
2447
            }
1235
 
            m_bgSpellCheck->addIgnoreWordAllList( m_spellListIgnoreAll );
1236
2448
        }else if(elem.tagName()=="ATTRIBUTES" && _clean) {
1237
2449
            if(elem.hasAttribute("activePage"))
1238
2450
                activePage=elem.attribute("activePage").toInt();
1263
2475
        } else if(elem.tagName()=="PRESSPEED") {
1264
2476
            if(_clean) {
1265
2477
                if(elem.hasAttribute("value"))
1266
 
                    presSpeed = static_cast<PresSpeed>(elem.attribute("value").toInt());
 
2478
                    m_loadingInfo->presSpeed = elem.attribute("value").toInt();
1267
2479
            }
1268
2480
        } else if(elem.tagName()=="MANUALSWITCH") {
1269
2481
            if(_clean) {
1278
2490
        } else if(elem.tagName()=="PRESSLIDES") {
1279
2491
            if(elem.hasAttribute("value") && elem.attribute("value").toInt()==0)
1280
2492
                allSlides = TRUE;
 
2493
        } else if ( elem.tagName()=="DEFAULTCUSTOMSLIDESHOWNAME" ) {
 
2494
            if(elem.hasAttribute("name") )
 
2495
                m_presentationName=elem.attribute( "name" );
 
2496
        } else if ( elem.tagName()=="CUSTOMSLIDESHOWCONFIG" ) {
 
2497
            if ( _clean ) {
 
2498
                QDomElement slide=elem.firstChild().toElement();
 
2499
                while(!slide.isNull()) {
 
2500
                    if(slide.tagName()=="CUSTOMSLIDESHOW") {
 
2501
                        QStringList tmp = QStringList::split( ",", slide.attribute( "pages" ) );
 
2502
                        m_loadingInfo->m_tmpCustomListMap.insert( slide.attribute( "name" ), tmp );
 
2503
 
 
2504
                    }
 
2505
                    slide=slide.nextSibling().toElement();
 
2506
                }
 
2507
            }
1281
2508
        } else if(elem.tagName()=="SELSLIDES") {
1282
2509
            if( _clean ) { // Skip this when loading a single page
1283
2510
                QDomElement slide=elem.firstChild().toElement();
1295
2522
                            if ( nr > ( (int)m_pageList.count() - 1 ) )
1296
2523
                            {
1297
2524
                                for (int i=(m_pageList.count()-1); i<nr;i++)
1298
 
                                    m_pageList.append(new KPrPage(this));
 
2525
                                    m_pageList.append( new KPrPage( this, m_masterPage ) );
1299
2526
                            }
1300
2527
                            m_pageList.at(nr)->slideSelected(show);
1301
2528
                        } else kdWarning(33001) << "Parse error. No nr in <SLIDE> !" << endl;
1316
2543
 
1317
2544
    if(activePage!=-1)
1318
2545
        m_initialActivePage=m_pageList.at(activePage);
1319
 
    setModified(false);
 
2546
    if ( m_pageWhereLoadObject == 0 && m_insertFilePage == 0 )
 
2547
        setModified(false);
1320
2548
 
1321
2549
    return true;
1322
2550
}
1352
2580
{
1353
2581
    kdDebug(33001) << "KPresenterDoc::loadBackground" << endl;
1354
2582
    QDomElement page=element.firstChild().toElement();
1355
 
    int i=0+m_insertFilePage;
 
2583
    int i=m_insertFilePage;
1356
2584
    while(!page.isNull()) {
1357
2585
        if(m_pageWhereLoadObject)
1358
 
            m_pageWhereLoadObject->background()->load(page);
 
2586
            m_pageWhereLoadObject->load(page);
1359
2587
        else
1360
2588
        {
1361
 
            //test if there is a page at this index
1362
 
            //=> don't add new page if there is again a page
1363
 
            if ( i > ( (int)m_pageList.count() - 1 ) )
1364
 
                m_pageList.append(new KPrPage(this));
1365
 
            m_pageList.at(i)->background()->load(page);
1366
 
            i++;
 
2589
            if ( page.tagName() == "MASTERPAGE" )
 
2590
            {
 
2591
                m_masterPage->load( page );
 
2592
            }
 
2593
            else
 
2594
            {
 
2595
                //test if there is a page at this index
 
2596
                //=> don't add new page if there is again a page
 
2597
                if ( i > ( (int)m_pageList.count() - 1 ) )
 
2598
                    m_pageList.append( new KPrPage( this, m_masterPage ) );
 
2599
                m_pageList.at(i)->load(page);
 
2600
                i++;
 
2601
            }
1367
2602
        }
1368
2603
        page=page.nextSibling().toElement();
1369
2604
    }
1393
2628
                offset=kplineobject->load(obj);
1394
2629
                if ( sticky && !ignoreSticky)
1395
2630
                {
1396
 
                    m_stickyPage->appendObject(kplineobject);
 
2631
                    m_masterPage->appendObject(kplineobject);
1397
2632
                    kplineobject->setOrig(kplineobject->getOrig().x(),offset);
1398
2633
                    kplineobject->setSticky(sticky);
1399
2634
                }
1417
2652
                offset=kprectobject->load(obj);
1418
2653
                if ( sticky && !ignoreSticky)
1419
2654
                {
1420
 
                    m_stickyPage->appendObject(kprectobject);
 
2655
                    m_masterPage->appendObject(kprectobject);
1421
2656
                    kprectobject->setOrig(kprectobject->getOrig().x(),offset);
1422
2657
                    kprectobject->setSticky(sticky);
1423
2658
                }
1440
2675
                offset=kpellipseobject->load(obj);
1441
2676
                if ( sticky && !ignoreSticky)
1442
2677
                {
1443
 
                    m_stickyPage->appendObject(kpellipseobject);
 
2678
                    m_masterPage->appendObject(kpellipseobject);
1444
2679
                    kpellipseobject->setOrig(kpellipseobject->getOrig().x(),offset);
1445
2680
                    kpellipseobject->setSticky(sticky);
1446
2681
                }
1464
2699
                offset=kppieobject->load(obj);
1465
2700
                if ( sticky && !ignoreSticky)
1466
2701
                {
1467
 
                    m_stickyPage->appendObject(kppieobject);
 
2702
                    m_masterPage->appendObject(kppieobject);
1468
2703
                    kppieobject->setOrig(kppieobject->getOrig().x(),offset);
1469
2704
                    kppieobject->setSticky(sticky);
1470
2705
                }
1487
2722
                offset=kpautoformobject->load(obj);
1488
2723
                if ( sticky && !ignoreSticky)
1489
2724
                {
1490
 
                    m_stickyPage->appendObject(kpautoformobject);
 
2725
                    m_masterPage->appendObject(kpautoformobject);
1491
2726
                    kpautoformobject->setOrig(kpautoformobject->getOrig().x(),offset);
1492
2727
                    kpautoformobject->setSticky(sticky);
1493
2728
                }
1510
2745
                offset=kptextobject->load(obj);
1511
2746
                if ( sticky && !ignoreSticky)
1512
2747
                {
1513
 
                    m_stickyPage->appendObject(kptextobject);
 
2748
                    m_masterPage->appendObject(kptextobject);
1514
2749
                    kptextobject->setOrig(kptextobject->getOrig().x(),offset);
1515
2750
                    kptextobject->setSticky(sticky);
1516
2751
                }
1534
2769
                offset=kppixmapobject->load(obj);
1535
2770
                if ( sticky && !ignoreSticky)
1536
2771
                {
1537
 
                    m_stickyPage->appendObject(kppixmapobject);
 
2772
                    m_masterPage->appendObject(kppixmapobject);
1538
2773
                    kppixmapobject->setOrig(kppixmapobject->getOrig().x(),offset);
1539
2774
                    kppixmapobject->setSticky(sticky);
1540
2775
                }
1559
2794
 
1560
2795
                if ( sticky && !ignoreSticky)
1561
2796
                {
1562
 
                    m_stickyPage->appendObject(kpfreehandobject);
 
2797
                    m_masterPage->appendObject(kpfreehandobject);
1563
2798
                    kpfreehandobject->setOrig(kpfreehandobject->getOrig().x(),offset);
1564
2799
                    kpfreehandobject->setSticky(sticky);
1565
2800
                }
1582
2817
                offset=kppolylineobject->load(obj);
1583
2818
                if ( sticky && !ignoreSticky)
1584
2819
                {
1585
 
                    m_stickyPage->appendObject(kppolylineobject);
 
2820
                    m_masterPage->appendObject(kppolylineobject);
1586
2821
                    kppolylineobject->setOrig(kppolylineobject->getOrig().x(),offset);
1587
2822
                    kppolylineobject->setSticky(sticky);
1588
2823
                }
1606
2841
                offset=kpQuadricBezierCurveObject->load(obj);
1607
2842
                if ( sticky && !ignoreSticky)
1608
2843
                {
1609
 
                    m_stickyPage->appendObject(kpQuadricBezierCurveObject);
 
2844
                    m_masterPage->appendObject(kpQuadricBezierCurveObject);
1610
2845
                    kpQuadricBezierCurveObject->setOrig(kpQuadricBezierCurveObject->getOrig().x(),offset);
1611
2846
                    kpQuadricBezierCurveObject->setSticky(sticky);
1612
2847
                }
1630
2865
                offset=kpCubicBezierCurveObject->load(obj);
1631
2866
                if ( sticky && !ignoreSticky)
1632
2867
                {
1633
 
                    m_stickyPage->appendObject(kpCubicBezierCurveObject);
 
2868
                    m_masterPage->appendObject(kpCubicBezierCurveObject);
1634
2869
                    kpCubicBezierCurveObject->setOrig(kpCubicBezierCurveObject->getOrig().x(),offset);
1635
2870
                    kpCubicBezierCurveObject->setSticky(sticky);
1636
2871
                }
1655
2890
                offset=kpPolygonObject->load( obj );
1656
2891
                if ( sticky && !ignoreSticky)
1657
2892
                {
1658
 
                    m_stickyPage->appendObject(kpPolygonObject);
 
2893
                    m_masterPage->appendObject(kpPolygonObject);
1659
2894
                    kpPolygonObject->setOrig(kpPolygonObject->getOrig().x(),offset);
1660
2895
                    kpPolygonObject->setSticky(sticky);
1661
2896
                }
1678
2913
                KPClosedLineObject *kpClosedLinneObject = new KPClosedLineObject();
1679
2914
                offset = kpClosedLinneObject->load( obj );
1680
2915
                if ( sticky && !ignoreSticky) {
1681
 
                    m_stickyPage->appendObject( kpClosedLinneObject );
 
2916
                    m_masterPage->appendObject( kpClosedLinneObject );
1682
2917
                    kpClosedLinneObject->setOrig( kpClosedLinneObject->getOrig().x(), offset );
1683
2918
                    kpClosedLinneObject->setSticky( sticky );
1684
2919
                }
1703
2938
                offset=kpgroupobject->load(obj, this);
1704
2939
                if ( sticky && !ignoreSticky)
1705
2940
                {
1706
 
                    m_stickyPage->appendObject(kpgroupobject);
 
2941
                    m_masterPage->appendObject(kpgroupobject);
1707
2942
                    kpgroupobject->setOrig(kpgroupobject->getOrig().x(),offset);
1708
2943
                    kpgroupobject->setSticky(sticky);
1709
2944
                }
1743
2978
void KPresenterDoc::loadTitle( const QDomElement &element )
1744
2979
{
1745
2980
    QDomElement title=element.firstChild().toElement();
1746
 
    int i=0+m_insertFilePage;
 
2981
    int i=m_insertFilePage;
1747
2982
    while ( !title.isNull() ) {
1748
2983
        if ( title.tagName()=="Title" )
1749
2984
        {
1752
2987
            if(!m_pageWhereLoadObject)
1753
2988
            {
1754
2989
                if ( i > ( (int)m_pageList.count() - 1 ) )
1755
 
                    m_pageList.append(new KPrPage(this));
 
2990
                    m_pageList.append( new KPrPage( this, m_masterPage ) );
1756
2991
                m_pageList.at(i)->insertManualTitle(title.attribute("title"));
1757
2992
                i++;
1758
2993
            }
1766
3001
void KPresenterDoc::loadNote( const QDomElement &element )
1767
3002
{
1768
3003
    QDomElement note=element.firstChild().toElement();
1769
 
    int i=0+m_insertFilePage;
 
3004
    int i=m_insertFilePage;
1770
3005
    while ( !note.isNull() ) {
1771
3006
        if ( note.tagName()=="Note" )
1772
3007
        {
1775
3010
            if(!m_pageWhereLoadObject)
1776
3011
            {
1777
3012
                if ( i > ( (int)m_pageList.count() - 1 ) )
1778
 
                    m_pageList.append(new KPrPage(this));
 
3013
                    m_pageList.append( new KPrPage( this, m_masterPage ) );
1779
3014
                m_pageList.at(i)->setNoteText(note.attribute("note"));
1780
3015
                i++;
1781
3016
            }
1823
3058
    }
1824
3059
}
1825
3060
 
 
3061
//TODO test if it's call when we load oasis format
1826
3062
bool KPresenterDoc::completeLoading( KoStore* _store )
1827
3063
{
 
3064
    //kdDebug()<<"bool KPresenterDoc::completeLoading( KoStore* _store )*************************\n";
1828
3065
    emit sigProgress( 80 );
1829
3066
 
1830
3067
    if ( _store ) {
1842
3079
 
1843
3080
 
1844
3081
        if ( saveOnlyPage == -1 ) {
 
3082
            // ### following call independant of saveOnlyPage's value?
 
3083
            m_masterPage->completeLoading( _clean, lastObj );
1845
3084
            QPtrListIterator<KPrPage> it( m_pageList );
1846
3085
            for ( ; it.current(); ++it )
1847
3086
                it.current()->completeLoading( _clean, lastObj );
1856
3095
            setPageLayout( m_pageLayout );
1857
3096
    }
1858
3097
 
 
3098
    compatibilityFromOldFileFormat();
 
3099
 
1859
3100
    emit sigProgress( 100 );
1860
3101
    recalcVariables( VT_FIELD );
1861
3102
    emit sigProgress( -1 );
1870
3111
 
1871
3112
void KPresenterDoc::loadUsedSoundFileFromStore( KoStore *_store, QStringList _list )
1872
3113
{
1873
 
    int i = 0+m_insertFilePage;
 
3114
    int i = m_insertFilePage;
1874
3115
    QStringList::Iterator it = _list.begin();
1875
3116
    for ( ; it != _list.end(); ++it ) {
1876
3117
        QString soundFile = *it;
1940
3181
//when we change pagelayout we must re-position header/footer
1941
3182
void KPresenterDoc::updateHeaderFooterPosition( )
1942
3183
{
1943
 
    KoRect pageRect=m_stickyPage->getPageRect();
 
3184
    KoRect pageRect=m_masterPage->getPageRect();
1944
3185
    QRect oldBoundingRect=zoomHandler()->zoomRect(_header->getBoundingRect());
1945
3186
    _header->setOrig(pageRect.topLeft ());
1946
3187
    _header->setSize(pageRect.width(),_header->getSize().height());
1954
3195
    repaint(_footer);
1955
3196
}
1956
3197
 
1957
 
bool KPresenterDoc::initDoc()
 
3198
bool KPresenterDoc::initDoc(InitDocFlags flags, QWidget* parentWidget)
1958
3199
{
1959
 
    QString _template;
 
3200
 
 
3201
    if (flags==KoDocument::InitDocEmpty)
 
3202
    {
 
3203
        QString fileName( locate("kpresenter_template", "Screenpresentations/.source/Plain.kpt",
 
3204
                                 KPresenterFactory::global() ) );
 
3205
        objStartY = 0;
 
3206
        _clean = true;
 
3207
        bool ok = loadNativeFormat( fileName );
 
3208
        if ( !ok )
 
3209
            showLoadingErrorDialog();
 
3210
        resetURL();
 
3211
        setEmpty();
 
3212
        return ok;
 
3213
    }
 
3214
 
 
3215
    QString file;
1960
3216
    KoTemplateChooseDia::ReturnType ret;
1961
 
 
1962
3217
    KoTemplateChooseDia::DialogType dlgtype;
1963
 
    if (initDocFlags() != InitDocFileNew)
 
3218
    if (flags != InitDocFileNew)
1964
3219
            dlgtype = KoTemplateChooseDia::Everything;
1965
3220
    else
1966
3221
            dlgtype = KoTemplateChooseDia::OnlyTemplates;
1967
3222
 
1968
 
    ret = KoTemplateChooseDia::choose(  KPresenterFactory::global(), _template,
1969
 
                                        "application/x-kpresenter", "*.kpr",
1970
 
                                        i18n("KPresenter"), dlgtype,
1971
 
                                        "kpresenter_template" );
 
3223
    ret = KoTemplateChooseDia::choose( KPresenterFactory::global(), file,
 
3224
                                       dlgtype, "kpresenter_template", parentWidget );
1972
3225
 
1973
3226
    if ( ret == KoTemplateChooseDia::Template ) {
1974
 
        QFileInfo fileInfo( _template );
1975
 
        QString fileName( fileInfo.dirPath( true ) + "/" + fileInfo.baseName() + ".kpt" );
1976
3227
        _clean = true; //was a parameter called "clean", but unused
1977
 
        bool ok = loadNativeFormat( fileName );
 
3228
        bool ok = loadNativeFormat( file );
 
3229
        if ( !ok )
 
3230
            showLoadingErrorDialog();
1978
3231
        objStartY = 0;
1979
3232
        _clean = true;
1980
3233
        resetURL();
1983
3236
    } else if ( ret == KoTemplateChooseDia::File ) {
1984
3237
        objStartY = 0;
1985
3238
        _clean = true;
1986
 
        KURL url( _template );
 
3239
        KURL url( file );
1987
3240
        bool ok = openURL( url );
1988
3241
        return ok;
1989
3242
    } else if ( ret == KoTemplateChooseDia::Empty ) {
1992
3245
        objStartY = 0;
1993
3246
        _clean = true;
1994
3247
        bool ok = loadNativeFormat( fileName );
 
3248
        if ( !ok )
 
3249
            showLoadingErrorDialog();
1995
3250
        resetURL();
1996
3251
        setEmpty();
1997
3252
        return ok;
2006
3261
    objStartY = 0;
2007
3262
    _clean = true;
2008
3263
    setModified(true);
2009
 
    loadNativeFormat( fileName );
 
3264
    bool ok = loadNativeFormat( fileName );
 
3265
    if ( !ok )
 
3266
        showLoadingErrorDialog();
2010
3267
    resetURL();
2011
3268
}
2012
3269
 
2070
3327
    repaint( m_zoomHandler->zoomRect(kpobject->getBoundingRect()) );
2071
3328
}
2072
3329
 
2073
 
QValueList<int> KPresenterDoc::reorderPage( unsigned int num )
 
3330
QValueList<int> KPresenterDoc::getPageEffectSteps( unsigned int num )
2074
3331
{
2075
 
    return m_pageList.at(num)->reorderPage();
 
3332
    return m_pageList.at(num)->getEffectSteps();
2076
3333
}
2077
3334
 
2078
3335
QRect KPresenterDoc::getPageRect( bool decBorders ) const
2123
3380
    //m_pageList.at(_page)->deletePage();
2124
3381
    if ( m_pageList.count()==1 )
2125
3382
        return;
2126
 
    KPrDeletePageCmd *cmd=new KPrDeletePageCmd(i18n("Delete Slide"),_page,m_pageList.at(_page),this);
 
3383
    KPrDeletePageCmd *cmd = new KPrDeletePageCmd( i18n("Delete Slide"), _page, this );
2127
3384
    cmd->execute();
2128
3385
    addCommand(cmd);
2129
3386
}
2130
3387
 
2131
 
void KPresenterDoc::insertPage( KPrPage *_page, int position)
 
3388
void KPresenterDoc::insertPage( KPrPage *page, int currentPageNum, int insertPageNum )
2132
3389
{
2133
 
    int pos=m_deletedPageList.findRef(_page);
 
3390
    // check if page was allready deleted
 
3391
    int pos = m_deletedPageList.findRef( page );
2134
3392
    if ( pos != -1 )
2135
 
        m_deletedPageList.take( pos);
2136
 
 
2137
 
    if ( m_deletedPageList.findRef( _page ) )
2138
 
        m_deletedPageList.remove( _page );
2139
 
    m_pageList.insert( position,_page);
2140
 
    //activate this page in all views
 
3393
        m_deletedPageList.take( pos );
 
3394
 
 
3395
    m_pageList.insert( insertPageNum, page );
 
3396
 
 
3397
    pageOrderChanged();
 
3398
    //activate this page in all views which on slide currentPageNum
2141
3399
    QPtrListIterator<KoView> it( views() );
2142
3400
    for (; it.current(); ++it )
2143
 
        static_cast<KPresenterView*>(it.current())->skipToPage(position);
 
3401
    {
 
3402
        KPresenterView *view = static_cast<KPresenterView*>( it.current() );
 
3403
        view->addSideBarItem( insertPageNum );
 
3404
 
 
3405
        // change to the new page if the view was on the current page.
 
3406
        if ( (int)view->getCurrPgNum() - 1 == currentPageNum )
 
3407
        {
 
3408
            view->skipToPage( insertPageNum );
 
3409
        }
 
3410
        else // recalc the page number as it might have been changed
 
3411
        {
 
3412
            view->recalcCurrentPageNum();
 
3413
        }
 
3414
    }
2144
3415
}
2145
3416
 
2146
 
void KPresenterDoc::takePage(KPrPage *_page)
 
3417
void KPresenterDoc::takePage( KPrPage *page, int pageNum )
2147
3418
{
2148
 
    int pos=m_pageList.findRef(_page);
2149
 
    m_pageList.take( pos);
2150
 
    m_deletedPageList.append( _page );
 
3419
    int pos = m_pageList.findRef( page );
 
3420
    m_pageList.take( pos );
 
3421
    m_deletedPageList.append( page );
 
3422
 
 
3423
    pageOrderChanged();
2151
3424
 
2152
3425
    QPtrListIterator<KoView> it( views() );
2153
3426
    for (; it.current(); ++it )
2154
 
        static_cast<KPresenterView*>(it.current())->skipToPage(pos-1);
 
3427
    {
 
3428
        KPresenterView *view = static_cast<KPresenterView*>( it.current() );
 
3429
        view->removeSideBarItem( pos );
 
3430
 
 
3431
        // change to the new page if the view was on the current page.
 
3432
        if ( (int)view->getCurrPgNum() - 1 == pos )
 
3433
        {
 
3434
            view->skipToPage( pageNum );
 
3435
        }
 
3436
        else // recalc the page number as it might have been changed
 
3437
        {
 
3438
            view->recalcCurrentPageNum();
 
3439
        }
 
3440
    }
2155
3441
 
2156
3442
    repaint( false );
2157
 
 
2158
 
    emit sig_updateMenuBar();
2159
3443
}
2160
3444
 
2161
 
void KPresenterDoc::addRemovePage( int pos, bool addPage )
 
3445
void KPresenterDoc::pageOrderChanged()
2162
3446
{
2163
 
    kdDebug(33001) << "addRemovePage pos = " << pos << endl;
2164
 
    recalcPageNum();
2165
 
 
2166
3447
    recalcVariables( VT_PGNUM );
2167
3448
 
2168
 
    // Update the sidebars
2169
 
    QPtrListIterator<KoView> it( views() );
2170
 
    for (; it.current(); ++it ) {
2171
 
        if ( addPage )
2172
 
            static_cast<KPresenterView*>(it.current())->addSideBarItem( pos );
2173
 
        else
2174
 
            static_cast<KPresenterView*>(it.current())->removeSideBarItem( pos );
2175
 
    }
2176
 
 
2177
3449
    //update statusbar
2178
3450
    emit pageNumChanged();
2179
3451
    emit sig_updateMenuBar();
2182
3454
void KPresenterDoc::movePageTo( int oldPos, int newPos )
2183
3455
{
2184
3456
    kdDebug(33001) << "movePage oldPos = " << oldPos << ", neuPos = " << newPos << endl;
2185
 
    recalcPageNum();
2186
 
 
2187
 
    recalcVariables( VT_PGNUM );
 
3457
 
 
3458
    KPrPage * page = m_pageList.take( oldPos );
 
3459
    m_pageList.insert( newPos, page );
 
3460
 
 
3461
    pageOrderChanged();
2188
3462
 
2189
3463
    // Update the sidebars
2190
3464
    QPtrListIterator<KoView> it( views() );
2191
3465
    for (; it.current(); ++it )
2192
 
        static_cast<KPresenterView*>(it.current())->moveSideBarItem( oldPos, newPos );
 
3466
    {
 
3467
        KPresenterView *view = static_cast<KPresenterView*>( it.current() );
 
3468
        view->moveSideBarItem( oldPos, newPos );
2193
3469
 
2194
 
    //update statusbar
2195
 
    emit pageNumChanged();
2196
 
    emit sig_updateMenuBar();
 
3470
        // change to the new page if the view was on the old pos.
 
3471
        if ( (int)view->getCurrPgNum() - 1 == oldPos )
 
3472
        {
 
3473
            view->skipToPage( newPos );
 
3474
        }
 
3475
        else // recalc the page number as it might have been changed
 
3476
        {
 
3477
            view->recalcCurrentPageNum();
 
3478
        }
 
3479
    }
2197
3480
}
2198
3481
 
2199
3482
QString KPresenterDoc::templateFileName( bool chooseTemplate, const QString &theFile )
2205
3488
        else
2206
3489
            fileName = theFile;
2207
3490
    } else {
 
3491
        // TODO: pass parentWidget as parameter to this method
 
3492
        QWidget* parentWidget = 0;
2208
3493
        QString _template;
2209
 
        if ( KoTemplateChooseDia::choose(  KPresenterFactory::global(), _template,
2210
 
                                           "", QString::null, QString::null,
2211
 
                                           KoTemplateChooseDia::OnlyTemplates,
2212
 
                                           "kpresenter_template") == KoTemplateChooseDia::Cancel )
 
3494
        if ( KoTemplateChooseDia::choose( KPresenterFactory::global(), _template,
 
3495
                                          KoTemplateChooseDia::OnlyTemplates,
 
3496
                                          "kpresenter_template", parentWidget ) == KoTemplateChooseDia::Cancel )
2213
3497
            return QString::null;
2214
3498
        QFileInfo fileInfo( _template );
2215
3499
        fileName = fileInfo.dirPath( true ) + "/" + fileInfo.baseName() + ".kpt";
2220
3504
        kdDebug(33001) << "Copying template  (in KPresenterDoc::templateFileName)" << endl
2221
3505
                       << "  from: " << src.prettyURL() << endl
2222
3506
                       << "  to: " << dest.prettyURL() << endl;
2223
 
        KIO::NetAccess::del( dest ); // copy does *not* delete, so have to do it explicitly!
2224
 
        KIO::NetAccess::copy( src, dest );
 
3507
        KIO::NetAccess::file_copy( src,
 
3508
                                   dest,
 
3509
                                   -1, /* default permissions */
 
3510
                                   true /* overwrite */ );
2225
3511
    }
2226
3512
    return fileName;
2227
3513
}
2237
3523
 
2238
3524
    _clean = false;
2239
3525
 
2240
 
    if ( _insPos == IP_AFTER )
2241
 
        _page++;
2242
 
 
2243
3526
    objStartY=-1;
2244
3527
 
2245
3528
    //insert page.
2246
 
    KPrPage *newpage=new KPrPage(this);
 
3529
    KPrPage *newpage = new KPrPage( this, m_masterPage );
2247
3530
 
2248
3531
    m_pageWhereLoadObject=newpage;
 
3532
    m_childCountBeforeInsert = children().count();
2249
3533
 
2250
 
    loadNativeFormat( fileName );
 
3534
    bool ok = loadNativeFormat( fileName );
 
3535
    if ( !ok )
 
3536
        showLoadingErrorDialog();
2251
3537
 
2252
3538
    objStartY = 0;
2253
3539
 
2254
 
    KPrInsertPageCmd *cmd=new KPrInsertPageCmd(cmdName, _page, newpage, this);
 
3540
    KPrInsertPageCmd *cmd = new KPrInsertPageCmd( cmdName, _page, _insPos, newpage, this );
2255
3541
    cmd->execute();
2256
3542
    addCommand(cmd);
2257
3543
 
2258
3544
    _clean = true;
2259
3545
    m_pageWhereLoadObject=0L;
 
3546
    m_childCountBeforeInsert = 0;
2260
3547
    return _page;
2261
3548
}
2262
3549
 
 
3550
void KPresenterDoc::saveOasisPage( const QString &file, int pgnum, bool ignore )
 
3551
{
 
3552
    saveOnlyPage = pgnum;
 
3553
    _duplicatePage=ignore;
 
3554
    //save in oasis format
 
3555
    saveNativeFormat( file );
 
3556
    _duplicatePage=false;
 
3557
    saveOnlyPage = -1;
 
3558
}
 
3559
 
 
3560
 
2263
3561
void KPresenterDoc::savePage( const QString &file, int pgnum, bool ignore )
2264
3562
{
2265
3563
    saveOnlyPage = pgnum;
2343
3641
 
2344
3642
void KPresenterDoc::setHeader( bool b )
2345
3643
{
2346
 
    _hasHeader = b;
2347
3644
    _header->setDrawEditRect( b );
2348
3645
    _header->setDrawEmpty( b );
2349
3646
    if(!b)
2352
3649
        deSelectObj(_header);
2353
3650
    }
2354
3651
    updateHeaderFooterButton();
2355
 
    repaint(_hasHeader);
 
3652
    repaint(b);
2356
3653
}
2357
3654
 
2358
3655
void KPresenterDoc::setFooter( bool b )
2359
3656
{
2360
 
    _hasFooter = b;
2361
3657
    _footer->setDrawEditRect( b );
2362
3658
    _footer->setDrawEmpty( b );
2363
3659
    if(!b)
2366
3662
        deSelectObj(_footer);
2367
3663
    }
2368
3664
    updateHeaderFooterButton();
2369
 
    repaint(_footer);
 
3665
    repaint(b);
2370
3666
}
2371
3667
 
2372
3668
void KPresenterDoc::updateHeaderFooterButton()
2386
3682
            continue;
2387
3683
        m_pageList.at(i)->makeUsedPixmapList();
2388
3684
    }
 
3685
    // ### following call independant of saveOnlyPage's value?
 
3686
    if ( saveOnlyPage == -1 )
 
3687
        m_masterPage->makeUsedPixmapList();
2389
3688
}
2390
3689
 
2391
3690
void KPresenterDoc::makeUsedSoundFileList()
2425
3724
void KPresenterDoc::paintContent( QPainter& painter, const QRect& rect,
2426
3725
                                  bool /*transparent*/, double zoomX, double zoomY )
2427
3726
{
2428
 
    m_zoomHandler->setZoomAndResolution( 100, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
 
3727
    m_zoomHandler->setZoom( 100 );
2429
3728
    if ( zoomHandler()->zoomedResolutionX() != zoomX || zoomHandler()->zoomedResolutionY() != zoomY )
2430
3729
    {
2431
3730
        zoomHandler()->setResolution( zoomX, zoomY );
2435
3734
    KPrPage *page=m_pageList.first();
2436
3735
    if( m_initialActivePage )
2437
3736
        page=m_initialActivePage;
2438
 
    //draw background
2439
 
    page->background()->draw( &painter, zoomHandler(), rect, false );
 
3737
 
 
3738
    int pageNum = m_pageList.findRef( page );
 
3739
 
 
3740
    page->background()->drawBackground( &painter, zoomHandler(), rect, false );
2440
3741
    //for the moment draw first page.
2441
3742
    QPtrListIterator<KPObject> it( page->objectList() );
2442
3743
    for ( ; it.current() ; ++it )
2443
 
        it.current()->draw( &painter, zoomHandler(), SM_NONE );
2444
 
    it= m_stickyPage->objectList();
 
3744
        it.current()->draw( &painter, zoomHandler(), pageNum, SM_NONE );
 
3745
    it= m_masterPage->objectList();
2445
3746
    //draw sticky obj
2446
3747
    for ( ; it.current() ; ++it )
2447
3748
    {
2448
 
        if( (it.current()==_header && !hasHeader())||(it.current()==_footer && !hasFooter()))
 
3749
        if( (it.current()==_header && !page->hasHeader())||(it.current()==_footer && !page->hasFooter()))
2449
3750
            continue;
2450
 
        it.current()->draw( &painter, zoomHandler(), SM_NONE );
 
3751
        it.current()->draw( &painter, zoomHandler(), pageNum, SM_NONE );
2451
3752
    }
2452
3753
}
2453
3754
 
2454
3755
QPixmap KPresenterDoc::generatePreview( const QSize& size )
2455
3756
{
2456
3757
    int oldZoom = zoomHandler()->zoom();
2457
 
    double oldResX = zoomHandler()->resolutionX();
2458
 
    double oldResY = zoomHandler()->resolutionY();
 
3758
    double oldResolutionX = zoomHandler()->resolutionX();
 
3759
    double oldResolutionY = zoomHandler()->resolutionY();
2459
3760
 
2460
3761
    QPixmap pix = KoDocument::generatePreview(size);
2461
3762
 
2462
 
    zoomHandler()->setZoomAndResolution(oldZoom, int(oldResX * 72), int(oldResY * 72));
 
3763
    zoomHandler()->setResolution( oldResolutionX, oldResolutionY );
 
3764
    zoomHandler()->setZoom(oldZoom);
2463
3765
    newZoomAndResolution( false, false );
2464
3766
 
2465
3767
    return pix;
2468
3770
void KPresenterDoc::movePage( int from, int to )
2469
3771
{
2470
3772
    kdDebug(33001) << "KPresenterDoc::movePage from=" << from << " to=" << to << endl;
2471
 
    KPrMovePageCmd *cmd=new KPrMovePageCmd( i18n("Move Slide"),from,to, m_pageList.at(from) ,this );
2472
 
    cmd->execute();
2473
 
    addCommand(cmd);
2474
 
}
2475
 
 
2476
 
void KPresenterDoc::copyPage( int from, int to )
2477
 
{
2478
 
    _clean = false;
2479
 
    _duplicatePage=true;
2480
 
 
2481
 
    kdDebug(33001) << "KPresenterDoc::copyPage from=" << from << " to=" << to << endl;
 
3773
    KPrMovePageCmd *cmd = new KPrMovePageCmd( i18n("Move Slide"), from, to, this );
 
3774
    cmd->execute();
 
3775
    addCommand(cmd);
 
3776
}
 
3777
 
 
3778
void KPresenterDoc::copyOasisPage( int from )
 
3779
{
 
3780
    _clean = false;
 
3781
    _duplicatePage=true; // ### now also set via saveOasisPage() parameter below
 
3782
 
 
3783
    kdDebug(33001) << "KPresenterDoc::copyOasisPage from=" << from << " to=" << from + 1 << endl;
 
3784
    bool wasSelected = isSlideSelected( from );
 
3785
    KTempFile tempFile( QString::null, ".oop" );
 
3786
    tempFile.setAutoDelete( true );
 
3787
    saveOasisPage( tempFile.name(), from, true );
 
3788
 
 
3789
    //insert page.
 
3790
    KPrPage *newpage = new KPrPage( this, m_masterPage );
 
3791
 
 
3792
    m_pageWhereLoadObject = newpage;
 
3793
 
 
3794
    bool ok = loadNativeFormat( tempFile.name() );
 
3795
    if ( !ok )
 
3796
        showLoadingErrorDialog();
 
3797
 
 
3798
    KPrInsertPageCmd *cmd = new KPrInsertPageCmd( i18n("Duplicate Slide"), from, IP_AFTER, newpage, this );
 
3799
    cmd->execute();
 
3800
    addCommand(cmd);
 
3801
 
 
3802
    _duplicatePage=false;
 
3803
 
 
3804
    _clean = true;
 
3805
    m_pageWhereLoadObject=0L;
 
3806
 
 
3807
    selectPage( from + 1, wasSelected );
 
3808
}
 
3809
 
 
3810
void KPresenterDoc::copyPage( int from )
 
3811
{
 
3812
    _clean = false;
 
3813
    m_childCountBeforeInsert = children().count();
 
3814
 
 
3815
    _duplicatePage=true; // ### now also set via savePage() parameter below
 
3816
 
 
3817
    kdDebug(33001) << "KPresenterDoc::copyPage from=" << from << " to=" << from + 1 << endl;
2482
3818
    bool wasSelected = isSlideSelected( from );
2483
3819
    KTempFile tempFile( QString::null, ".kpr" );
2484
3820
    tempFile.setAutoDelete( true );
2485
 
    savePage( tempFile.name(), from );
 
3821
    savePage( tempFile.name(), from, true );
2486
3822
 
2487
3823
    //insert page.
2488
 
    KPrPage *newpage=new KPrPage(this);
2489
 
 
2490
 
    m_pageWhereLoadObject=newpage;
2491
 
 
2492
 
    loadNativeFormat( tempFile.name() );
2493
 
 
2494
 
    KPrInsertPageCmd *cmd=new KPrInsertPageCmd(i18n("Duplicate Slide"), to, newpage, this );
 
3824
    KPrPage *newpage = new KPrPage( this, m_masterPage );
 
3825
 
 
3826
    m_pageWhereLoadObject = newpage;
 
3827
 
 
3828
    bool ok = loadNativeFormat( tempFile.name() );
 
3829
    if ( !ok )
 
3830
        showLoadingErrorDialog();
 
3831
 
 
3832
    KPrInsertPageCmd *cmd = new KPrInsertPageCmd( i18n("Duplicate Slide"), from, IP_AFTER, newpage, this );
2495
3833
    cmd->execute();
2496
3834
    addCommand(cmd);
2497
3835
 
2499
3837
 
2500
3838
    _clean = true;
2501
3839
    m_pageWhereLoadObject=0L;
2502
 
 
2503
 
    selectPage( to, wasSelected );
 
3840
    m_childCountBeforeInsert = 0;
 
3841
 
 
3842
    selectPage( from + 1, wasSelected );
 
3843
}
 
3844
 
 
3845
void KPresenterDoc::copyOasisPageToClipboard( int pgnum )
 
3846
{
 
3847
    // We save the page to a temp file and set the URL of the file in the clipboard
 
3848
    // Yes it's a hack but at least we don't hit the clipboard size limit :)
 
3849
    // (and we don't have to implement copy-tar-structure-to-clipboard)
 
3850
    // In fact it even allows copying a [1-page] kpr in konq and pasting it in kpresenter :))
 
3851
    kdDebug(33001) << "KPresenterDoc::copyPageToClipboard pgnum=" << pgnum << endl;
 
3852
    KTempFile tempFile( QString::null, ".oop" );
 
3853
    saveOasisPage( tempFile.name(), pgnum );
 
3854
    KURL url; url.setPath( tempFile.name() );
 
3855
    KURL::List lst;
 
3856
    lst.append( url );
 
3857
    QApplication::clipboard()->setData( new KURLDrag( lst ) );
 
3858
    m_tempFileInClipboard = tempFile.name(); // do this last, the above calls clipboardDataChanged
2504
3859
}
2505
3860
 
2506
3861
void KPresenterDoc::copyPageToClipboard( int pgnum )
2511
3866
    // In fact it even allows copying a [1-page] kpr in konq and pasting it in kpresenter :))
2512
3867
    kdDebug(33001) << "KPresenterDoc::copyPageToClipboard pgnum=" << pgnum << endl;
2513
3868
    KTempFile tempFile( QString::null, ".kpr" );
2514
 
    savePage( tempFile.name(), pgnum );
 
3869
    savePage( tempFile.name(), pgnum, true );
2515
3870
    KURL url; url.setPath( tempFile.name() );
2516
3871
    KURL::List lst;
2517
3872
    lst.append( url );
2518
 
    QApplication::clipboard()->setData( KURLDrag::newDrag( lst ) );
 
3873
    QApplication::clipboard()->setData( new KURLDrag( lst ) );
2519
3874
    m_tempFileInClipboard = tempFile.name(); // do this last, the above calls clipboardDataChanged
2520
3875
}
2521
3876
 
2547
3902
void KPresenterDoc::selectPage( int pgNum /* 0-based */, bool select )
2548
3903
{
2549
3904
    Q_ASSERT( pgNum >= 0 );
2550
 
    m_pageList.at(pgNum)->slideSelected(select);
 
3905
    KPrPage *page = m_pageList.at( pgNum );
 
3906
    page->slideSelected(select);
2551
3907
    kdDebug(33001) << "KPresenterDoc::selectPage pgNum=" << pgNum << " select=" << select << endl;
2552
3908
    setModified(true);
2553
3909
 
2554
 
    updateSideBarItem(pgNum);
 
3910
    updateSideBarItem( page );
2555
3911
    updatePresentationButton();
2556
3912
    //update statusbar
2557
3913
    emit pageNumChanged();
2558
3914
}
2559
3915
 
2560
 
// TOGO remove SideBar from the name, it's a general helper (object->page)
2561
 
KPrPage * KPresenterDoc::findSideBarPage(KPObject *object)
 
3916
KPrPage * KPresenterDoc::findPage(KPObject *object)
2562
3917
{
2563
 
    if ( object->isSticky() ) {
2564
 
        //kdDebug(33001) << "Object is on sticky page" << endl;
2565
 
        return m_stickyPage;
 
3918
    QPtrList<KPObject> masterObjects( m_masterPage->objectList() );
 
3919
    if ( masterObjects.findRef( object ) != -1 )
 
3920
    {
 
3921
        //kdDebug(33001) << "Object is on the master page" << endl;
 
3922
        return m_masterPage;
2566
3923
    }
2567
3924
    QPtrListIterator<KPrPage> it( m_pageList );
2568
3925
    for ( ; it.current(); ++it ) {
2576
3933
    return 0L;
2577
3934
}
2578
3935
 
2579
 
// TOGO remove SideBar from the name, it's a general helper (object->page)
2580
 
KPrPage * KPresenterDoc::findSideBarPage(QPtrList<KPObject> &objects)
 
3936
KPrPage * KPresenterDoc::findPage(QPtrList<KPObject> &objects)
2581
3937
{
2582
3938
    KPObject *object;
2583
3939
    for ( object = objects.first(); object; object=objects.next() ) {
2584
 
        if ( object->isSticky() ) {
2585
 
            //kdDebug(33001) << "A Object is on the sticky page" << endl;
2586
 
            return m_stickyPage;
 
3940
        QPtrList<KPObject> list( m_masterPage->objectList() );
 
3941
        if ( list.findRef( object ) != -1 )
 
3942
        {
 
3943
            //kdDebug(33001) << "Object is on the master page" << endl;
 
3944
            return m_masterPage;
2587
3945
        }
2588
3946
    }
2589
3947
    object = objects.first();
2598
3956
    return 0L;
2599
3957
}
2600
3958
 
2601
 
void KPresenterDoc::updateSideBarItem(int pgNum, bool sticky )
 
3959
void KPresenterDoc::updateSideBarItem( KPrPage * page )
2602
3960
{
2603
3961
    // Update the views
2604
3962
    QPtrListIterator<KoView> it( views() );
2605
3963
    for (; it.current(); ++it )
2606
 
        static_cast<KPresenterView*>(it.current())->updateSideBarItem( pgNum, sticky );
 
3964
        static_cast<KPresenterView*>( it.current() )->updateSideBarItem( page );
2607
3965
}
2608
3966
 
2609
3967
bool KPresenterDoc::isSlideSelected( int pgNum /* 0-based */ )
2612
3970
    return m_pageList.at(pgNum)->isSlideSelected();
2613
3971
}
2614
3972
 
 
3973
QValueList<int> KPresenterDoc::listOfDisplaySelectedSlides( const QValueList<KPrPage*> & lst) /* returned list is 0-based */
 
3974
{
 
3975
    QValueList<int> result;
 
3976
    QValueListConstIterator<KPrPage*> itPage;
 
3977
    QValueListConstIterator<KPrPage*> itPageEnd = lst.end();
 
3978
    for( itPage =  lst.begin() ; itPage != itPageEnd; ++itPage )
 
3979
    {
 
3980
        int pageNum = m_pageList.find(*itPage );
 
3981
        if ( pageNum != -1 )
 
3982
        {
 
3983
            kdDebug()<<" KPresenterDoc::displaySelectedSlide : add slide number :"<<pageNum<<endl;
 
3984
            result << pageNum;
 
3985
        }
 
3986
    }
 
3987
    return result;
 
3988
}
 
3989
 
 
3990
 
 
3991
QValueList<int> KPresenterDoc::displaySelectedSlides()  /* returned list is 0-based */
 
3992
{
 
3993
    QValueList<int> result;
 
3994
    if ( m_customListTest )
 
3995
        return *m_customListTest;
 
3996
    if ( m_presentationName.isEmpty() )
 
3997
        return selectedSlides();
 
3998
    else
 
3999
    {
 
4000
        kdDebug()<<" KPresenterDoc::displaySelectedSlide m_presentationName : "<<m_presentationName<<endl;
 
4001
        result = listOfDisplaySelectedSlides( m_customListSlideShow[m_presentationName]);
 
4002
    }
 
4003
    return result;
 
4004
}
 
4005
 
2615
4006
QValueList<int> KPresenterDoc::selectedSlides() /* returned list is 0-based */
2616
4007
{
2617
4008
    QValueList<int> result;
2677
4068
    QPtrListIterator<KPrPage> it( m_pageList );
2678
4069
    for ( ; it.current(); ++it )
2679
4070
        it.current()->slotRepaintVariable();
2680
 
    m_stickyPage->slotRepaintVariable();
 
4071
    m_masterPage->slotRepaintVariable();
2681
4072
}
2682
4073
 
2683
4074
void KPresenterDoc::slotDocumentInfoModifed()
2714
4105
    QPtrListIterator<KPrPage> it( m_pageList );
2715
4106
    for ( ; it.current(); ++it )
2716
4107
        it.current()->recalcPageNum();
2717
 
    m_stickyPage->recalcPageNum();
 
4108
    m_masterPage->recalcPageNum();
2718
4109
}
2719
4110
 
2720
4111
KPrPage * KPresenterDoc::activePage()const
2722
4113
    return m_initialActivePage;
2723
4114
}
2724
4115
 
2725
 
void KPresenterDoc::insertObjectInPage(double offset, KPObject *_obj)
 
4116
void KPresenterDoc::insertObjectInPage(double offset, KPObject *_obj, int pos)
2726
4117
{
2727
4118
    /// Why does this use __pgLayout instead of m_pageLayout ?
2728
4119
    int page = (int)(offset/__pgLayout.ptHeight)+m_insertFilePage;
2729
4120
    double newPos = offset - ( page - m_insertFilePage ) * __pgLayout.ptHeight;
 
4121
    // due to a very small caluculating error which gives us the wrong page
 
4122
    // for objects placed on top of the page we have to move them to the right page.
 
4123
    if ( __pgLayout.ptHeight - newPos < 1e-6 )
 
4124
    {
 
4125
        page++;
 
4126
        newPos = 0.0;
 
4127
    }
2730
4128
    if ( page > ( (int)m_pageList.count()-1 ) )
2731
4129
    {
2732
4130
        for (int i=(m_pageList.count()-1); i<page;i++)
2733
 
            m_pageList.append(new KPrPage(this));
 
4131
            m_pageList.append( new KPrPage( this, m_masterPage ) );
2734
4132
    }
2735
4133
    _obj->setOrig(_obj->getOrig().x(),newPos);
2736
4134
 
2737
 
    m_pageList.at(page)->appendObject(_obj);
 
4135
    if ( pos == -1 )
 
4136
    {
 
4137
        m_pageList.at(page)->appendObject(_obj);
 
4138
    }
 
4139
    else
 
4140
    {
 
4141
        m_pageList.at( page )->insertObject( _obj, pos );
 
4142
    }
2738
4143
}
2739
4144
 
2740
4145
void KPresenterDoc::insertPixmapKey( KoPictureKey key )
2766
4171
 
2767
4172
void KPresenterDoc::newZoomAndResolution( bool updateViews, bool /*forPrint*/ )
2768
4173
{
 
4174
    QPtrListIterator<KPrPage> it( m_pageList );
 
4175
    for ( ; it.current(); ++it ) {
 
4176
        QPtrListIterator<KPObject> oit(it.current()->objectList());
 
4177
        for ( ; oit.current(); ++oit ) {
 
4178
            if ( oit.current()->getType() == OT_TEXT )
 
4179
                static_cast<KPTextObject *>( oit.current() )->textDocument()->formatCollection()->zoomChanged();
 
4180
        }
 
4181
    }
2769
4182
    if ( updateViews )
2770
4183
    {
2771
4184
        QPtrListIterator<KoView> it( views() );
2777
4190
    }
2778
4191
}
2779
4192
 
2780
 
KPrPage * KPresenterDoc::stickyPage() const
2781
 
{
2782
 
    return m_stickyPage;
2783
 
}
2784
 
 
2785
4193
bool KPresenterDoc::isHeader(const KPObject *obj) const
2786
4194
{
2787
4195
    return (obj==_header);
2808
4216
    }
2809
4217
}
2810
4218
 
 
4219
void KPresenterDoc::refreshAllNoteBarMasterPage(const QString &text, KPresenterView *exceptView)
 
4220
{
 
4221
    m_masterPage->setNoteText(text );
 
4222
    QPtrListIterator<KoView> it( views() );
 
4223
    for (; it.current(); ++it )
 
4224
    {
 
4225
        KPresenterView* view=(KPresenterView*)it.current();
 
4226
        if ( view->getNoteBar() && view != exceptView && view->editMaster() )
 
4227
            view->getNoteBar()->setCurrentNoteText(text );
 
4228
    }
 
4229
}
 
4230
 
2811
4231
void KPresenterDoc::refreshAllNoteBar(int page, const QString &text, KPresenterView *exceptView)
2812
4232
{
2813
4233
    m_pageList.at(page)->setNoteText(text );
2823
4243
void KPresenterDoc::loadStyleTemplates( const QDomElement &stylesElem )
2824
4244
{
2825
4245
    QValueList<QString> followingStyles;
2826
 
    QPtrList<KoStyle>m_styleList(m_styleColl->styleList());
2827
4246
 
2828
4247
    QDomNodeList listStyles = stylesElem.elementsByTagName( "STYLE" );
 
4248
    if( listStyles.count() > 0) { // we are going to import at least one style.
 
4249
        KoParagStyle *s = m_styleColl->findStyle("Standard");
 
4250
        kdDebug(32001) << "KPresenterDoc::loadStyleTemplates looking for Standard, to delete it. Found " << s << endl;
 
4251
        if(s) // delete the standard style.
 
4252
            m_styleColl->removeStyleTemplate(s);
 
4253
    }
2829
4254
    for (unsigned int item = 0; item < listStyles.count(); item++) {
2830
4255
        QDomElement styleElem = listStyles.item( item ).toElement();
2831
4256
 
2832
 
        KoStyle *sty = new KoStyle( QString::null );
 
4257
        KoParagStyle *sty = new KoParagStyle( QString::null );
2833
4258
        // Load the style from the <STYLE> element
2834
4259
        sty->loadStyle( styleElem );
2835
4260
 
2841
4266
 
2842
4267
        // Style created, now let's try to add it
2843
4268
        sty = m_styleColl->addStyleTemplate( sty );
2844
 
        if(m_styleList.count() > followingStyles.count() )
 
4269
        kdDebug() << k_funcinfo << m_styleColl->styleList().count() << " styles, " << followingStyles.count() << " following styles" << endl;
 
4270
        if(m_styleColl->styleList().count() > followingStyles.count() )
2845
4271
        {
2846
4272
            QString following = styleElem.namedItem("FOLLOWING").toElement().attribute("name");
2847
4273
            followingStyles.append( following );
2850
4276
            kdWarning (33001) << "Found duplicate style declaration, overwriting former " << sty->name() << endl;
2851
4277
    }
2852
4278
 
2853
 
    Q_ASSERT( followingStyles.count() == m_styleList.count() );
 
4279
    Q_ASSERT( followingStyles.count() == m_styleColl->styleList().count() );
2854
4280
    unsigned int i=0;
2855
4281
    for( QValueList<QString>::Iterator it = followingStyles.begin(); it != followingStyles.end(); ++it ) {
2856
 
        KoStyle * style = m_styleColl->findStyle(*it);
 
4282
        KoParagStyle * style = m_styleColl->findStyle(*it);
2857
4283
        m_styleColl->styleAt( i++)->setFollowingStyle( style );
2858
4284
    }
2859
4285
}
2866
4292
        ((KPresenterView*)it.current())->updateStyleList();
2867
4293
}
2868
4294
 
2869
 
void KPresenterDoc::applyStyleChange( StyleChangeDefMap changed )
 
4295
void KPresenterDoc::applyStyleChange( KoStyleChangeDefMap changed )
2870
4296
{
2871
4297
    QPtrListIterator<KPrPage> it( m_pageList );
2872
4298
    for ( ; it.current(); ++it )
2873
4299
        it.current()->applyStyleChange( changed );
2874
 
    m_stickyPage->applyStyleChange( changed );
 
4300
    m_masterPage->applyStyleChange( changed );
2875
4301
}
2876
4302
 
2877
 
void KPresenterDoc::saveStyle( KoStyle *sty, QDomElement parentElem )
 
4303
void KPresenterDoc::saveStyle( KoParagStyle *sty, QDomElement parentElem )
2878
4304
{
2879
4305
    QDomDocument doc = parentElem.ownerDocument();
2880
4306
    QDomElement styleElem = doc.createElement( "STYLE" );
2893
4319
    {
2894
4320
        if(m_initialActivePage->allTextObjects().count()>0)
2895
4321
        {
2896
 
            m_bgSpellCheck->objectForSpell(m_initialActivePage->textFrameSet(0));
2897
 
            m_bgSpellCheck->startBackgroundSpellCheck();
 
4322
#ifdef HAVE_LIBKSPELL2
 
4323
            m_bgSpellCheck->start();
 
4324
#endif
2898
4325
        }
2899
4326
    }
2900
4327
}
2901
4328
 
2902
4329
void KPresenterDoc::enableBackgroundSpellCheck( bool b )
2903
4330
{
2904
 
    m_bgSpellCheck->enableBackgroundSpellCheck(b);
 
4331
    //m_bgSpellCheck->enableBackgroundSpellCheck(b);
 
4332
#ifdef HAVE_LIBKSPELL2
 
4333
    m_bgSpellCheck->setEnabled(b);
 
4334
#endif
2905
4335
    QPtrListIterator<KoView> it( views() );
2906
4336
    for( ; it.current(); ++it )
2907
4337
        ((KPresenterView*)it.current())->updateBgSpellCheckingState();
2909
4339
 
2910
4340
bool KPresenterDoc::backgroundSpellCheckEnabled() const
2911
4341
{
2912
 
    return m_bgSpellCheck->backgroundSpellCheckEnabled();
 
4342
#ifdef HAVE_LIBKSPELL2
 
4343
    return m_bgSpellCheck->enabled();
 
4344
#else
 
4345
    return false;
 
4346
#endif
2913
4347
}
2914
4348
 
2915
4349
void KPresenterDoc::reactivateBgSpellChecking(bool refreshTextObj)
2927
4361
        else
2928
4362
            it.current()->reactivateBgSpellChecking( true);
2929
4363
    }
2930
 
    m_stickyPage->reactivateBgSpellChecking(refreshTextObj);
 
4364
    m_masterPage->reactivateBgSpellChecking(refreshTextObj);
2931
4365
    startBackgroundSpellCheck();
2932
4366
}
2933
4367
 
2937
4371
    QPtrListIterator<KPrPage> it( m_pageList );
2938
4372
    for ( ; it.current(); ++it )
2939
4373
        it.current()->addTextObjects( lst );
2940
 
    m_stickyPage->addTextObjects( lst );
 
4374
    m_masterPage->addTextObjects( lst );
2941
4375
    return lst;
2942
4376
}
2943
4377
 
2944
 
KPTextObject* KPresenterDoc::nextTextFrameSet(KPTextObject *obj)
 
4378
QValueList<KoTextObject *> KPresenterDoc::visibleTextObjects( ) const
2945
4379
{
2946
 
    if(m_initialActivePage)
2947
 
    {
2948
 
        bool findObject = m_initialActivePage->findTextObject( bgObjSpellChecked );
2949
 
        if ( !findObject )
2950
 
        {
2951
 
            findObject = m_stickyPage->findTextObject( bgObjSpellChecked );
2952
 
            if ( findObject )
2953
 
            {
2954
 
                bgObjSpellChecked = m_stickyPage->nextTextObject( obj );
2955
 
                if ( bgObjSpellChecked )
2956
 
                    return bgObjSpellChecked->nextTextObject();
2957
 
                else
2958
 
                    return 0L;
2959
 
            }
2960
 
        }
2961
 
        bgObjSpellChecked = m_initialActivePage->nextTextObject( obj );
2962
 
        if ( bgObjSpellChecked )
2963
 
            return bgObjSpellChecked->nextTextObject();
2964
 
        else
2965
 
        {
2966
 
            bgObjSpellChecked = m_stickyPage->nextTextObject( obj );
2967
 
            if ( bgObjSpellChecked )
2968
 
                return bgObjSpellChecked->nextTextObject();
2969
 
            else
2970
 
                return 0L;
2971
 
        }
2972
 
        return 0L;
 
4380
    QValueList<KoTextObject *> lst;
 
4381
    QPtrList<KoTextObject> textFramesets = allTextObjects(  );
 
4382
 
 
4383
    KoTextObject *frm;
 
4384
    for ( frm=textFramesets.first(); frm != 0; frm=textFramesets.next() ) {
 
4385
        if ( frm && !frm->protectContent() )
 
4386
        {
 
4387
            lst.append( frm );
 
4388
        }
2973
4389
    }
2974
 
    return 0L;
 
4390
    return lst;
2975
4391
}
2976
4392
 
2977
4393
void KPresenterDoc::setShowHelplines(bool b)
3136
4552
    return -1;
3137
4553
}
3138
4554
 
3139
 
void KPresenterDoc::addIgnoreWordAll( const QString & word)
 
4555
void KPresenterDoc::setSpellCheckIgnoreList( const QStringList& lst )
3140
4556
{
3141
 
    if( m_spellListIgnoreAll.findIndex( word )==-1)
3142
 
        m_spellListIgnoreAll.append( word );
3143
 
    m_bgSpellCheck->addIgnoreWordAll( word );
 
4557
    m_spellCheckIgnoreList = lst;
 
4558
#ifdef HAVE_LIBKSPELL2
 
4559
    m_bgSpellCheck->settings()->setCurrentIgnoreList( m_spellCheckIgnoreList + m_spellCheckPersonalDict );
 
4560
#endif
 
4561
    setModified( true );
3144
4562
}
3145
4563
 
3146
 
void KPresenterDoc::clearIgnoreWordAll( )
 
4564
void KPresenterDoc::addSpellCheckIgnoreWord( const QString & word )
3147
4565
{
3148
 
    m_spellListIgnoreAll.clear();
3149
 
    m_bgSpellCheck->clearIgnoreWordAll( );
 
4566
    // ### missing: undo/redo support
 
4567
    if( m_spellCheckIgnoreList.findIndex( word ) == -1 )
 
4568
        m_spellCheckIgnoreList.append( word );
 
4569
    setSpellCheckIgnoreList( m_spellCheckIgnoreList );
3150
4570
}
3151
4571
 
3152
4572
void KPresenterDoc::updateObjectStatusBarItem()
3170
4590
    for ( ; it.current(); ++it )
3171
4591
        it.current()->changeTabStopValue( m_tabStop );
3172
4592
    //styckypage
3173
 
    m_stickyPage->changeTabStopValue( m_tabStop );
 
4593
    m_masterPage->changeTabStopValue( m_tabStop );
3174
4594
}
3175
4595
 
3176
4596
void KPresenterDoc::changeBgSpellCheckingState( bool b )
3208
4628
{
3209
4629
    m_insertFilePage = m_pageList.count();
3210
4630
 
 
4631
    m_childCountBeforeInsert = children().count();
3211
4632
    objStartY = 0;
3212
4633
    bool clean = _clean;
3213
4634
    _clean = false;
3214
4635
    bool ok = loadNativeFormat(file );
3215
4636
    if ( !ok )
3216
4637
    {
3217
 
        KMessageBox::error(0L, i18n("Error during file insertion."), i18n("Insert File"));
 
4638
        showLoadingErrorDialog();
3218
4639
        return;
3219
4640
    }
3220
4641
    KMacroCommand *macro = 0L;
3222
4643
    {
3223
4644
        if ( !macro )
3224
4645
            macro = new KMacroCommand( i18n("Insert File"));
3225
 
        KPrInsertPageCmd * cmd = new KPrInsertPageCmd( i18n("Insert File"),i, m_pageList.at(i), this ) ;
 
4646
        KPrInsertPageCmd * cmd = new KPrInsertPageCmd( i18n("Insert File"), i - 1, IP_AFTER, m_pageList.at(i), this ) ;
3226
4647
        macro->addCommand(cmd );
3227
4648
    }
3228
4649
    if ( macro )
3229
4650
        addCommand( macro );
3230
4651
 
3231
4652
    m_insertFilePage = 0;
 
4653
    m_childCountBeforeInsert = 0;
3232
4654
    // Update the views
3233
4655
    int newPos = m_pageList.count()-1;
3234
4656
    QPtrListIterator<KoView> it( views() );
3245
4667
 
3246
4668
void KPresenterDoc::spellCheckParagraphDeleted( KoTextParag *_parag,  KPTextObject *frm)
3247
4669
{
3248
 
    m_bgSpellCheck->spellCheckParagraphDeleted( _parag, frm->textObject());
3249
 
}
3250
 
 
3251
 
void KPresenterDoc::configureSpellChecker()
3252
 
{
3253
 
    KPresenterView * view = static_cast<KPresenterView*>(views().getFirst());
3254
 
    if ( view ) // no view if embedded document
3255
 
        view->configureSpellChecker();
 
4670
    //m_bgSpellCheck->spellCheckParagraphDeleted( _parag, frm->textObject());
3256
4671
}
3257
4672
 
3258
4673
void KPresenterDoc::updateRulerInProtectContentMode()
3323
4738
 
3324
4739
void KPresenterDoc::addWordToDictionary( const QString & word)
3325
4740
{
 
4741
#ifdef HAVE_LIBKSPELL2
3326
4742
    if ( m_bgSpellCheck )
3327
 
        m_bgSpellCheck->addPersonalDictonary( word );
3328
 
}
3329
 
 
3330
 
void KPresenterDoc::setKOSpellConfig(KOSpellConfig _kspell)
3331
 
{
3332
 
    if(m_pKOSpellConfig==0)
3333
 
        m_pKOSpellConfig=new KOSpellConfig();
3334
 
 
3335
 
    m_pKOSpellConfig->setNoRootAffix(_kspell.noRootAffix ());
3336
 
    m_pKOSpellConfig->setRunTogether(_kspell.runTogether ());
3337
 
    m_pKOSpellConfig->setDictionary(_kspell.dictionary ());
3338
 
    m_pKOSpellConfig->setDictFromList(_kspell.dictFromList());
3339
 
    m_pKOSpellConfig->setEncoding(_kspell.encoding());
3340
 
    m_pKOSpellConfig->setDontCheckTitleCase( _kspell.dontCheckTitleCase());
3341
 
    m_pKOSpellConfig->setDontCheckUpperWord( _kspell.dontCheckUpperWord() );
3342
 
    m_pKOSpellConfig->setIgnoreCase ( _kspell.ignoreCase ());
3343
 
    m_pKOSpellConfig->setIgnoreAccent( _kspell.ignoreAccent());
3344
 
    m_pKOSpellConfig->setSpellWordWithNumber( _kspell.spellWordWithNumber());
3345
 
    m_pKOSpellConfig->setClient (_kspell.client());
3346
 
    m_bgSpellCheck->setKSpellConfig(_kspell);
3347
 
}
 
4743
    {
 
4744
        if( m_spellCheckPersonalDict.findIndex( word ) == -1 )
 
4745
            m_spellCheckPersonalDict.append( word );
 
4746
        m_bgSpellCheck->settings()->setCurrentIgnoreList( m_spellCheckIgnoreList + m_spellCheckPersonalDict );
 
4747
        if ( backgroundSpellCheckEnabled() )
 
4748
            // Re-check everything to make this word normal again
 
4749
            reactivateBgSpellChecking();
 
4750
    }
 
4751
#endif
 
4752
}
 
4753
 
 
4754
CustomListMap KPresenterDoc::customListSlideShow()
 
4755
{
 
4756
    CustomListMap listMap;
 
4757
    if ( !m_customListSlideShow.isEmpty() )
 
4758
    {
 
4759
        //kdDebug()<<" m_customListSlideShow is not empty\n";
 
4760
        ListCustomSlideShow::Iterator it;
 
4761
        for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
 
4762
        {
 
4763
            QStringList tmp;
 
4764
            QValueListIterator<KPrPage*> itPage;
 
4765
            QValueListIterator<KPrPage*> itPageEnd = ( *it ).end();
 
4766
            for( itPage = ( *it ).begin() ; itPage != itPageEnd ; ++itPage )
 
4767
                if ( m_pageList.find(*itPage ) != -1 )
 
4768
                {
 
4769
                    //kdDebug()<<" add page :"<<itPage.current()->pageTitle()<<endl;
 
4770
                    tmp.append( ( *itPage )->pageTitle() );
 
4771
                }
 
4772
            listMap.insert( it.key(), tmp);
 
4773
        }
 
4774
    }
 
4775
    return listMap;
 
4776
}
 
4777
 
 
4778
QValueList <KPrPage *> KPresenterDoc::customListPage( const QStringList & lst, bool loadOasis )
 
4779
{
 
4780
    QStringList tmp( lst );
 
4781
    QValueList <KPrPage *> tmpValueList;
 
4782
    for ( QStringList::Iterator itList = tmp.begin(); itList != tmp.end(); ++itList )
 
4783
    {
 
4784
        for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
 
4785
        {
 
4786
            //kdDebug()<<" insert page name :"<<*itList<<endl;
 
4787
            if ( loadOasis )
 
4788
            {
 
4789
                if ( m_pageList.at( i )->oasisNamePage(i+1)== ( *itList ) )
 
4790
                {
 
4791
                    tmpValueList.append(  m_pageList.at( i ) );
 
4792
                    //kdDebug()<<" really insert\n";
 
4793
                    break;
 
4794
                }
 
4795
            }
 
4796
            else
 
4797
            {
 
4798
                if ( m_pageList.at( i )->pageTitle()== ( *itList ) )
 
4799
                {
 
4800
                    tmpValueList.append( m_pageList.at( i ) );
 
4801
                    //kdDebug()<<" really insert\n";
 
4802
                    break;
 
4803
                }
 
4804
            }
 
4805
 
 
4806
        }
 
4807
    }
 
4808
    return tmpValueList;
 
4809
 
 
4810
}
 
4811
 
 
4812
void KPresenterDoc::updateCustomListSlideShow( CustomListMap & map, bool loadOasis )
 
4813
{
 
4814
    m_customListSlideShow.clear();
 
4815
    CustomListMap::Iterator it;
 
4816
    for ( it = map.begin(); it != map.end(); ++it ) {
 
4817
        m_customListSlideShow.insert( it.key(), customListPage( it.data(), loadOasis )  );
 
4818
    }
 
4819
    setModified( true );
 
4820
}
 
4821
 
 
4822
QStringList KPresenterDoc::presentationList()
 
4823
{
 
4824
    QStringList lst;
 
4825
    if ( !m_customListSlideShow.isEmpty() )
 
4826
    {
 
4827
        ListCustomSlideShow::Iterator it;
 
4828
        for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
 
4829
            lst << it.key();
 
4830
    }
 
4831
    return lst;
 
4832
}
 
4833
 
 
4834
void KPresenterDoc::addTestCustomSlideShow( const QStringList &lst, KPresenterView *_view )
 
4835
{
 
4836
    delete m_customListTest;
 
4837
    m_customListTest = new QValueList<int>( listOfDisplaySelectedSlides( customListPage( lst) ) );
 
4838
    if ( _view )
 
4839
        _view->screenStartFromFirst();
 
4840
 
 
4841
}
 
4842
 
 
4843
void KPresenterDoc::clearTestCustomSlideShow()
 
4844
{
 
4845
    delete m_customListTest;
 
4846
    m_customListTest = 0L;
 
4847
}
 
4848
 
3348
4849
 
3349
4850
#include "kpresenter_doc.moc"