36#include <tqapplication.h>
37#include <tqfileinfo.h>
41#include <kstandarddirs.h>
44#include <tdemessagebox.h>
46#include <tdetempfile.h>
48#include <KoApplication.h>
49#include <KoCommandHistory.h>
50#include <KoDocumentInfo.h>
52#include <KoMainWindow.h>
53#include <KoOasisSettings.h>
54#include <KoOasisStyles.h>
55#include <KoStoreDevice.h>
56#include <KoTemplateChooseDia.h>
57#include <KoVariable.h>
59#include <KoXmlWriter.h>
61#include "kspread_canvas.h"
62#include "kspread_locale.h"
63#include "kspread_map.h"
64#include "kspread_sheet.h"
65#include "kspread_sheetprint.h"
66#include "kspread_style_manager.h"
67#include "kspread_undo.h"
68#include "kspread_util.h"
69#include "kspread_view.h"
75#include "ksploadinginfo.h"
78#include "valueconverter.h"
79#include "valueformatter.h"
80#include "valueparser.h"
82#include "KSpreadDocIface.h"
84#include "kspread_doc.h"
89static const int CURRENT_SYNTAX_VERSION = 1;
91static const char * CURRENT_DTD_VERSION =
"1.2";
99 StyleManager *styleManager;
107 static TQValueList<Doc*> s_docs;
118 KoCommandHistory* commandHistory;
124 TQColor pageBorderColor;
126 TQPtrList<Plugin> plugins;
128 TQValueList<Reference> refs;
129 TDECompletion listCompletion;
133 TQValueList<Damage*> damages;
137 bool verticalScrollBar:1;
138 bool horizontalScrollBar:1;
143 bool showStatusBar:1;
145 bool showFormulaBar:1;
147 TDEGlobalSettings::Completion completionMode;
148 KSpread::MoveTo moveTo;
149 MethodOfCalc calcMethod;
150 bool delayCalculation:1;
151 KSpellConfig *spellConfig;
152 bool dontCheckUpperWord:1;
153 bool dontCheckTitleCase:1;
154 bool configLoadFromFile:1;
155 TQStringList spellListIgnoreAll;
157 TQPtrList<EmbeddedObject> m_embeddedObjects;
158 KoPictureCollection m_pictureCollection;
159 TQValueList<KoPictureKey> usedPictures;
160 bool m_savingWholeDocument;
169TQValueList<Doc*> Doc::Private::s_docs;
170int Doc::Private::s_docId = 0;
172Doc::Doc( TQWidget *parentWidget,
const char *widgetName, TQObject* parent,
const char* name,
bool singleViewMode )
173 : KoDocument( parentWidget, widgetName, parent, name, singleViewMode )
176 d->m_loadingInfo = 0L;
178 d->map =
new Map(
this,
"Map" );
179 d->locale =
new Locale;
180 d->styleManager =
new StyleManager();
185 d->calc->setDoc (
this);
190 d->pageBorderColor = TQt::red;
191 d->configLoadFromFile =
false;
193 TQFont f( KoGlobal::defaultFont() );
194 Format::setGlobalRowHeight( f.pointSizeFloat() + 3 );
195 Format::setGlobalColWidth( ( f.pointSizeFloat() + 3 ) * 5 );
197 d->plugins.setAutoDelete(
false );
199 d->delayCalculation =
false;
203 setInstance( Factory::global(),
false );
204 setTemplateType(
"kspread_template" );
207 d->isLoading =
false;
208 d->numOperations = 1;
211 d->commandHistory =
new KoCommandHistory( actionCollection() );
212 connect( d->commandHistory, TQ_SIGNAL( commandExecuted() ), TQ_SLOT( commandExecuted() ) );
213 connect( d->commandHistory, TQ_SIGNAL( documentRestored() ), TQ_SLOT( documentRestored() ) );
220 TQString tmp(
"Document%1" );
221 tmp = tmp.arg( d->s_docId++ );
222 setName( tmp.local8Bit());
229 d->syntaxVersion = CURRENT_SYNTAX_VERSION;
230 d->verticalScrollBar =
true;
231 d->horizontalScrollBar =
true;
232 d->columnHeader =
true;
234 d->gridColor = TQt::lightGray;
235 d->indentValue = 10.0;
236 d->showStatusBar =
true;
237 d->showFormulaBar =
true;
238 d->showTabBar =
true;
239 d->showError =
false;
240 d->calcMethod = SumOfNumber;
241 d->moveTo = KSpread::Bottom;
242 d->completionMode = TDEGlobalSettings::CompletionAuto;
244 d->dontCheckUpperWord =
false;
245 d->dontCheckTitleCase =
false;
255 d->s_docs.remove(
this );
257 kdDebug(36001) <<
"alive 1" << endl;
259 delete d->commandHistory;
261 delete d->spellConfig;
265 delete d->styleManager;
276 return Private::s_docs;
279bool Doc::initDoc(InitDocFlags flags, TQWidget* parentWidget)
285 if (flags==KoDocument::InitDocEmpty)
287 TDEConfig *config = Factory::global()->config();
289 if( config->hasGroup(
"Parameters" ))
291 config->setGroup(
"Parameters" );
292 _page=config->readNumEntry(
"NbPage",1 ) ;
295 for(
int i=0; i<_page; i++ )
301 styleManager()->createBuiltinStyles();
306 KoTemplateChooseDia::ReturnType ret;
307 KoTemplateChooseDia::DialogType dlgtype;
308 if (flags != KoDocument::InitDocFileNew )
309 dlgtype = KoTemplateChooseDia::Everything;
311 dlgtype = KoTemplateChooseDia::OnlyTemplates;
313 ret = KoTemplateChooseDia::choose( Factory::global(), f,
314 dlgtype,
"kspread_template", parentWidget );
316 if ( ret == KoTemplateChooseDia::File )
320 bool ok=openURL(url);
322 while (KoDocument::isLoading())
323 kapp->processEvents();
330 if ( ret == KoTemplateChooseDia::Empty )
332 TDEConfig *config = Factory::global()->config();
334 if( config->hasGroup(
"Parameters" ))
336 config->setGroup(
"Parameters" );
337 _page=config->readNumEntry(
"NbPage",1 ) ;
340 for(
int i=0; i<_page; i++ )
346 styleManager()->createBuiltinStyles();
350 if ( ret == KoTemplateChooseDia::Template )
354 d->m_loadingInfo->setLoadTemplate(
true );
355 bool ok = loadNativeFormat( f );
358 showLoadingErrorDialog();
369void Doc::openTemplate (
const TQString& file)
372 d->m_loadingInfo->setLoadTemplate(
true );
373 KoDocument::openTemplate( file );
380 TDEConfig *config = Factory::global()->config();
382 if( config->hasGroup(
"Parameters" ))
384 config->setGroup(
"Parameters" );
385 _page=config->readNumEntry(
"NbPage",1 ) ;
388 for(
int i=0; i<_page; i++ )
393 styleManager()->createBuiltinStyles();
395 KoDocument::initEmpty();
398TDELocale *Doc::locale ()
const
403Map *Doc::map ()
const
408StyleManager *Doc::styleManager ()
const
410 return d->styleManager;
433void Doc::saveConfig()
435 if ( isEmbedded() ||!isReadWrite())
437 TDEConfig *config = Factory::global()->config();
438 config->setGroup(
"Parameters" );
439 config->writeEntry(
"Zoom", m_zoom );
443void Doc::initConfig()
445 TDEConfig *config = Factory::global()->config();
447 if( config->hasGroup(
"KSpread Page Layout" ))
449 config->setGroup(
"KSpread Page Layout" );
450 setUnit( (KoUnit::Unit)config->readNumEntry(
"Default unit page" ,0));
452 if( config->hasGroup(
"Parameters" ))
454 config->setGroup(
"Parameters" );
455 m_zoom = config->readNumEntry(
"Zoom", 100 );
461 if(config->hasGroup(
"Misc" ) )
463 config->setGroup(
"Misc" );
464 undo=config->readNumEntry(
"UndoRedo",-1);
467 setUndoRedoLimit(
undo);
474 return d->syntaxVersion;
479 return d->isLoading || KoDocument::isLoading();
484 d->isLoading = status;
488TQColor Doc::pageBorderColor()
const
490 return d->pageBorderColor;
493void Doc::changePageBorderColor(
const TQColor & _color)
495 d->pageBorderColor = _color;
498const TQValueList<Reference> &Doc::listArea()
503TDECompletion& Doc::completion()
505 return d->listCompletion;
508KoView* Doc::createViewInstance( TQWidget* parent,
const char* name )
512 return new View( parent, name,
this );
517 return map()->saveChildren( _store );
520int Doc::supportedSpecialFormats()
const
522 return KoDocument::supportedSpecialFormats();
525bool Doc::completeSaving( KoStore* _store )
527 d->m_pictureCollection.saveToStore( KoPictureCollection::CollectionPicture, _store, d->usedPictures );
533TQDomDocument Doc::saveXML()
536 TQPtrListIterator<KoView> it( views() );
542 for (; it.current(); ++it )
546 TQDomDocument doc = createDomDocument(
"spreadsheet", CURRENT_DTD_VERSION );
547 TQDomElement spread = doc.documentElement();
548 spread.setAttribute(
"editor",
"KSpread" );
549 spread.setAttribute(
"mime",
"application/x-kspread" );
550 spread.setAttribute(
"syntaxVersion", CURRENT_SYNTAX_VERSION );
552 TQDomElement dlocale = ((Locale *)locale())->save( doc );
553 spread.appendChild( dlocale );
555 if (d->refs.count() != 0 )
557 TQDomElement areaname = saveAreaName( doc );
558 spread.appendChild( areaname );
561 if( !d->spellListIgnoreAll.isEmpty() )
563 TQDomElement spellCheckIgnore = doc.createElement(
"SPELLCHECKIGNORELIST" );
564 spread.appendChild( spellCheckIgnore );
565 for ( TQStringList::Iterator it = d->spellListIgnoreAll.begin(); it != d->spellListIgnoreAll.end(); ++it )
567 TQDomElement spellElem = doc.createElement(
"SPELLCHECKIGNOREWORD" );
568 spellCheckIgnore.appendChild( spellElem );
569 spellElem.setAttribute(
"word", *it );
573 SavedDocParts::const_iterator iter = m_savedDocParts.begin();
574 SavedDocParts::const_iterator end = m_savedDocParts.end();
575 while ( iter != end )
578 spread.appendChild( iter.data() );
582 TQDomElement defaults = doc.createElement(
"defaults" );
583 defaults.setAttribute(
"row-height", Format::globalRowHeight() );
584 defaults.setAttribute(
"col-width", Format::globalColWidth() );
585 spread.appendChild( defaults );
587 Plugin * plugin = d->plugins.first();
588 for ( ; plugin != 0; plugin = d->plugins.next() )
590 TQDomElement data( plugin->saveXML( doc ) );
591 if ( !data.isNull() )
592 spread.appendChild( data );
595 TQDomElement s = styleManager()->save( doc );
596 spread.appendChild( s );
597 TQDomElement e = map()->save( doc );
598 spread.appendChild( e );
600 setModified(
false );
605bool Doc::loadChildren( KoStore* _store )
607 return map()->loadChildren( _store );
610bool Doc::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
620 TQString* , KoPicture* )
622 d->m_pictureCollection.assignUniqueIds();
624 TQPtrListIterator<KoView> it2( views() );
625 d->m_savingWholeDocument = saveFlag == SaveAll ? true :
false;
631 for (; it2.current(); ++it2 )
634 if ( !store->open(
"content.xml" ) )
637 KoStoreDevice dev( store );
638 KoXmlWriter* contentWriter = createOasisXmlWriter( &dev,
"office:document-content" );
639 KoGenStyles mainStyles;
641 KTempFile contentTmpFile;
643 if (contentTmpFile.status() != 0)
645 tqWarning(
"Creation of temporary file to store document content failed.");
649 contentTmpFile.setAutoDelete(
true );
650 TQFile* tmpFile = contentTmpFile.file();
651 KoXmlWriter contentTmpWriter( tmpFile, 1 );
656 contentTmpWriter.startElement(
"office:body" );
657 contentTmpWriter.startElement(
"office:spreadsheet" );
660 int partIndexObj = 0;
663 styleManager()->saveOasis( mainStyles );
667 defaultColumnStyle.addPropertyPt(
"style:column-width", Format::globalColWidth() );
668 defaultColumnStyle.setDefaultStyle(
true );
669 mainStyles.lookup( defaultColumnStyle,
"Default", KoGenStyles::DontForceNumbering );
673 defaultRowStyle.addPropertyPt(
"style:row-height", Format::globalRowHeight() );
674 defaultRowStyle.setDefaultStyle(
true );
675 mainStyles.lookup( defaultRowStyle,
"Default", KoGenStyles::DontForceNumbering );
678 map()->saveOasis( contentTmpWriter, mainStyles, store, manifestWriter, indexObj, partIndexObj );
680 saveOasisAreaName( contentTmpWriter );
681 contentTmpWriter.endElement();
682 contentTmpWriter.endElement();
685 contentWriter->startElement(
"office:automatic-styles" );
687 TQValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_AUTO );
688 TQValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
689 for ( ; it != styles.end() ; ++it ) {
690 (*it).style->writeStyle( contentWriter, mainStyles,
"style:style", (*it).name,
"style:paragraph-properties" );
693 styles = mainStyles.styles( STYLE_PAGE );
695 for ( ; it != styles.end() ; ++it ) {
696 (*it).style->writeStyle( contentWriter, mainStyles,
"style:style", (*it).name,
"style:table-properties" );
701 for ( ; it != styles.end() ; ++it ) {
702 (*it).style->writeStyle( contentWriter, mainStyles,
"style:style", (*it).name,
"style:table-column-properties" );
707 for ( ; it != styles.end() ; ++it ) {
708 (*it).style->writeStyle( contentWriter, mainStyles,
"style:style", (*it).name,
"style:table-row-properties" );
711 styles = mainStyles.styles( STYLE_CELL_AUTO );
713 for ( ; it != styles.end() ; ++it ) {
714 (*it).style->writeStyle( contentWriter, mainStyles,
"style:style", (*it).name,
"style:table-cell-properties" );
717 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_NUMBER );
719 for ( ; it != styles.end() ; ++it ) {
720 (*it).style->writeStyle( contentWriter, mainStyles,
"number:number-style", (*it).name, 0 );
724 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_DATE );
726 for ( ; it != styles.end() ; ++it ) {
727 (*it).style->writeStyle( contentWriter, mainStyles,
"number:date-style", (*it).name, 0 );
730 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_TIME );
732 for ( ; it != styles.end() ; ++it ) {
733 (*it).style->writeStyle( contentWriter, mainStyles,
"number:time-style", (*it).name, 0 );
736 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_FRACTION );
738 for ( ; it != styles.end() ; ++it ) {
739 (*it).style->writeStyle( contentWriter, mainStyles,
"number:number-style", (*it).name, 0 );
743 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_PERCENTAGE );
745 for ( ; it != styles.end() ; ++it ) {
746 (*it).style->writeStyle( contentWriter, mainStyles,
"number:percentage-style", (*it).name, 0 );
750 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_CURRENCY );
752 for ( ; it != styles.end() ; ++it ) {
753 (*it).style->writeStyle( contentWriter, mainStyles,
"number:currency-style", (*it).name, 0 );
756 styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_SCIENTIFIC );
758 for ( ; it != styles.end() ; ++it ) {
759 (*it).style->writeStyle( contentWriter, mainStyles,
"number:number-style", (*it).name, 0 );
763 contentWriter->endElement();
768 contentWriter->addCompleteElement( tmpFile );
769 contentTmpFile.close();
772 contentWriter->endElement();
773 contentWriter->endDocument();
774 delete contentWriter;
775 if ( !store->close() )
778 manifestWriter->addManifestEntry(
"content.xml",
"text/xml" );
781 if ( !store->open(
"styles.xml" ) )
784 manifestWriter->addManifestEntry(
"styles.xml",
"text/xml" );
785 saveOasisDocumentStyles( store, mainStyles );
787 if ( !store->close() )
790 makeUsedPixmapList();
791 d->m_pictureCollection.saveOasisToStore( store, d->usedPictures, manifestWriter);
793 if(!store->open(
"settings.xml"))
796 KoXmlWriter* settingsWriter = createOasisXmlWriter(&dev,
"office:document-settings");
797 settingsWriter->startElement(
"office:settings");
798 settingsWriter->startElement(
"config:config-item-set");
799 settingsWriter->addAttribute(
"config:name",
"view-settings");
801 KoUnit::saveOasis(settingsWriter, unit());
803 saveOasisSettings( *settingsWriter );
805 settingsWriter->endElement();
807 settingsWriter->startElement(
"config:config-item-set");
808 settingsWriter->addAttribute(
"config:name",
"configuration-settings");
809 settingsWriter->addConfigItem(
"SpellCheckerIgnoreList", d->spellListIgnoreAll.join(
"," ) );
810 settingsWriter->endElement();
811 settingsWriter->endElement();
812 settingsWriter->endElement();
813 settingsWriter->endDocument();
814 delete settingsWriter;
819 manifestWriter->addManifestEntry(
"settings.xml",
"text/xml");
822 if ( saveFlag == SaveSelected )
825 for( ; it.current(); ++it )
827 if ( it.current()->getType() != OBJECT_CHART && it.current()->getType() != OBJECT_KOFFICE_PART )
833 if ( !embedded->saveOasis( store, manifestWriter ) )
839 setModified(
false );
844void Doc::loadOasisSettings(
const TQDomDocument&settingsDoc )
846 KoOasisSettings settings( settingsDoc );
847 KoOasisSettings::Items viewSettings = settings.itemSet(
"view-settings" );
848 if ( !viewSettings.isNull() )
850 setUnit(KoUnit::unit(viewSettings.parseConfigItemString(
"unit")));
852 map()->loadOasisSettings( settings );
853 loadOasisIgnoreList( settings );
856void Doc::saveOasisSettings( KoXmlWriter &settingsWriter )
858 settingsWriter.startElement(
"config:config-item-map-indexed");
859 settingsWriter.addAttribute(
"config:name",
"Views");
860 settingsWriter.startElement(
"config:config-item-map-entry" );
861 map()->saveOasisSettings( settingsWriter );
862 settingsWriter.endElement();
863 settingsWriter.endElement();
867void Doc::loadOasisIgnoreList(
const KoOasisSettings& settings )
869 KoOasisSettings::Items configurationSettings = settings.itemSet(
"configuration-settings" );
870 if ( !configurationSettings.isNull() )
872 const TQString ignorelist = configurationSettings.parseConfigItemString(
"SpellCheckerIgnoreList" );
874 d->spellListIgnoreAll = TQStringList::split(
',', ignorelist );
879void Doc::saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles )
const
881 KoStoreDevice stylesDev( store );
882 KoXmlWriter* stylesWriter = createOasisXmlWriter( &stylesDev,
"office:document-styles" );
884 stylesWriter->startElement(
"office:styles" );
885 TQValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_USER );
886 TQValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
887 for ( ; it != styles.end() ; ++it ) {
888 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:style", (*it).name,
"style:paragraph-properties" );
894 for ( ; it != styles.end() ; ++it ) {
895 if ( (*it).style->isDefaultStyle() ) {
896 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:default-style", (*it).name,
"style:table-column-properties" );
899 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:style", (*it).name,
"style:table-column-properties" );
906 for ( ; it != styles.end() ; ++it ) {
907 if ( (*it).style->isDefaultStyle() ) {
908 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:default-style", (*it).name,
"style:table-row-properties" );
911 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:style", (*it).name,
"style:table-row-properties" );
916 styles = mainStyles.styles( Doc::STYLE_CELL_USER );
918 for ( ; it != styles.end() ; ++it ) {
919 if ( (*it).style->isDefaultStyle() ) {
920 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:default-style", (*it).name,
"style:table-cell-properties" );
923 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:style", (*it).name,
"style:table-cell-properties" );
927 styles = mainStyles.styles( KoGenStyle::STYLE_HATCH );
929 for ( ; it != styles.end() ; ++it ) {
930 (*it).style->writeStyle( stylesWriter, mainStyles,
"draw:hatch", (*it).name,
"style:graphic-properties" ,
true,
true );
932 styles = mainStyles.styles( KoGenStyle::STYLE_GRAPHICAUTO );
934 for ( ; it != styles.end() ; ++it ) {
935 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:style", (*it).name ,
"style:graphic-properties" );
938 stylesWriter->endElement();
940 stylesWriter->startElement(
"office:automatic-styles" );
941 styles = mainStyles.styles( KoGenStyle::STYLE_PAGELAYOUT );
943 for ( ; it != styles.end() ; ++it ) {
944 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:page-layout", (*it).name,
"style:page-layout-properties",
false );
945 stylesWriter->endElement();
948 stylesWriter->endElement();
950 stylesWriter->startElement(
"office:master-styles" );
952 styles = mainStyles.styles( Doc::STYLE_PAGEMASTER );
954 for ( ; it != styles.end() ; ++it ) {
955 (*it).style->writeStyle( stylesWriter, mainStyles,
"style:master-page", (*it).name,
"" );
958 stylesWriter->endElement();
961 stylesWriter->endElement();
962 stylesWriter->endDocument();
963 delete stylesWriter;;
966bool Doc::loadOasis(
const TQDomDocument& doc, KoOasisStyles& oasisStyles,
const TQDomDocument& settings, KoStore* store)
968 if ( !d->m_loadingInfo )
974 emit sigProgress( 0 );
976 d->spellListIgnoreAll.clear();
980 TQDomElement content = doc.documentElement();
981 TQDomElement realBody ( KoDom::namedItemNS( content, KoXmlNS::office,
"body" ) );
982 if ( realBody.isNull() )
984 setErrorMessage( i18n(
"Invalid OASIS OpenDocument file. No office:body tag found." ));
988 TQDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office,
"spreadsheet" );
992 kdError(32001) <<
"No office:spreadsheet found!" << endl;
993 TQDomElement childElem;
995 forEachElement( childElem, realBody ) {
996 localName = childElem.localName();
998 if ( localName.isEmpty() )
999 setErrorMessage( i18n(
"Invalid OASIS OpenDocument file. No tag found inside office:body." ) );
1001 setErrorMessage( i18n(
"This document is not a spreadsheet, but %1. Please try opening it with the appropriate application." ).arg( KoDocument::tagNameToDocumentType( localName ) ) );
1006 KoOasisLoadingContext context(
this, oasisStyles, store );
1009 styleManager()->loadOasisStyleTemplate( oasisStyles );
1012 const TQDomElement* defaultColumnStyle = oasisStyles.defaultStyle(
"table-column" );
1013 if ( defaultColumnStyle )
1016 KoStyleStack styleStack;
1017 styleStack.push( *defaultColumnStyle );
1018 styleStack.setTypeProperties(
"table-column" );
1019 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"column-width" ) )
1021 const double width = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::style,
"column-width" ), -1.0 );
1022 if ( width != -1.0 )
1025 Format::setGlobalColWidth( width );
1031 const TQDomElement* defaultRowStyle = oasisStyles.defaultStyle(
"table-row" );
1032 if ( defaultRowStyle )
1035 KoStyleStack styleStack;
1036 styleStack.push( *defaultRowStyle );
1037 styleStack.setTypeProperties(
"table-row" );
1038 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"row-height" ) )
1040 const double height = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::style,
"row-height" ), -1.0 );
1041 if ( height != -1.0 )
1044 Format::setGlobalRowHeight( height );
1050 loadOasisAreaName( body );
1051 loadOasisCellValidation( body );
1054 if ( !map()->loadOasis( body, context ) )
1056 d->isLoading =
false;
1062 if ( !settings.isNull() )
1064 loadOasisSettings( settings );
1066 emit sigProgress( 90 );
1068 emit sigProgress(-1);
1071 kdDebug(36001) <<
"Loading took " << (float)(dt.elapsed()) / 1000.0 <<
" seconds" << endl;
1075bool Doc::loadXML( TQIODevice *,
const TQDomDocument& doc )
1080 emit sigProgress( 0 );
1081 d->isLoading =
true;
1082 d->spellListIgnoreAll.clear();
1084 TQDomElement spread = doc.documentElement();
1086 if ( spread.attribute(
"mime" ) !=
"application/x-kspread" && spread.attribute(
"mime" ) !=
"application/vnd.kde.kspread" )
1088 d->isLoading =
false;
1089 setErrorMessage( i18n(
"Invalid document. Expected mimetype application/x-kspread or application/vnd.kde.kspread, got %1" ).arg( spread.attribute(
"mime") ) );
1093 d->syntaxVersion = Doc::getAttribute( spread,
"syntaxVersion", 0 );
1094 if ( d->syntaxVersion > CURRENT_SYNTAX_VERSION )
1096 int ret = KMessageBox::warningContinueCancel(
1097 0, i18n(
"This document was created with a newer version of KSpread (syntax version: %1)\n"
1098 "When you open it with this version of KSpread, some information may be lost.").arg(d->syntaxVersion),
1099 i18n(
"File Format Mismatch"), KStdGuiItem::cont() );
1100 if ( ret == KMessageBox::Cancel )
1102 setErrorMessage(
"USER_CANCELED" );
1108 TQDomElement loc = spread.namedItem(
"locale" ).toElement();
1109 if ( !loc.isNull() )
1110 ((Locale *) locale())->load( loc );
1112 emit sigProgress( 5 );
1114 TQDomElement defaults = spread.namedItem(
"defaults" ).toElement();
1115 if ( !defaults.isNull() )
1118 double d = defaults.attribute(
"row-height" ).toDouble( &ok );
1121 Format::setGlobalRowHeight( d );
1123 d = defaults.attribute(
"col-width" ).toDouble( &ok );
1128 Format::setGlobalColWidth( d );
1133 TQDomElement areaname = spread.namedItem(
"areaname" ).toElement();
1134 if ( !areaname.isNull())
1135 loadAreaName(areaname);
1137 TQDomElement ignoreAll = spread.namedItem(
"SPELLCHECKIGNORELIST").toElement();
1138 if ( !ignoreAll.isNull())
1140 TQDomElement spellWord=spread.namedItem(
"SPELLCHECKIGNORELIST").toElement();
1142 spellWord=spellWord.firstChild().toElement();
1143 while ( !spellWord.isNull() )
1145 if ( spellWord.tagName()==
"SPELLCHECKIGNOREWORD" )
1147 d->spellListIgnoreAll.append(spellWord.attribute(
"word"));
1149 spellWord=spellWord.nextSibling().toElement();
1153 emit sigProgress( 40 );
1155 map()->sheetList().clear();
1157 TQDomElement styles = spread.namedItem(
"styles" ).toElement();
1158 if ( !styles.isNull() )
1160 if ( !styleManager()->loadXML( styles ) )
1162 setErrorMessage( i18n(
"Styles cannot be loaded." ) );
1163 d->isLoading =
false;
1169 TQDomElement mymap = spread.namedItem(
"map" ).toElement();
1170 if ( mymap.isNull() )
1172 setErrorMessage( i18n(
"Invalid document. No map tag.") );
1173 d->isLoading =
false;
1176 if ( !map()->loadXML( mymap ) )
1178 d->isLoading =
false;
1183 if ( d->syntaxVersion < 1 )
1185 TQDomElement paper = spread.namedItem(
"paper" ).toElement();
1186 if ( !paper.isNull() )
1192 emit sigProgress( 85 );
1194 TQDomElement element( spread.firstChild().toElement() );
1195 while ( !element.isNull() )
1197 TQString tagName( element.tagName() );
1199 if ( tagName !=
"locale" && tagName !=
"map" && tagName !=
"styles"
1200 && tagName !=
"SPELLCHECKIGNORELIST" && tagName !=
"areaname"
1201 && tagName !=
"paper" )
1204 m_savedDocParts[ tagName ] = element;
1207 element = element.nextSibling().toElement();
1210 emit sigProgress( 90 );
1212 emit sigProgress(-1);
1214 kdDebug(36001) <<
"Loading took " << (float)(dt.elapsed()) / 1000.0 <<
" seconds" << endl;
1221void Doc::loadPaper( TQDomElement
const & paper )
1224 TQString format = paper.attribute(
"format" );
1225 TQString orientation = paper.attribute(
"orientation" );
1228 TQDomElement borders = paper.namedItem(
"borders" ).toElement();
1229 if ( !borders.isNull() )
1231 float left = borders.attribute(
"left" ).toFloat();
1232 float right = borders.attribute(
"right" ).toFloat();
1233 float top = borders.attribute(
"top" ).toFloat();
1234 float bottom = borders.attribute(
"bottom" ).toFloat();
1237 TQPtrListIterator<Sheet> it ( map()->sheetList() );
1238 for( ; it.current(); ++it )
1240 it.current()->print()->setPaperLayout( left, top, right, bottom,
1241 format, orientation );
1245 TQString hleft, hright, hcenter;
1246 TQString fleft, fright, fcenter;
1248 TQDomElement head = paper.namedItem(
"head" ).toElement();
1249 if ( !head.isNull() )
1251 TQDomElement left = head.namedItem(
"left" ).toElement();
1252 if ( !left.isNull() )
1253 hleft = left.text();
1254 TQDomElement center = head.namedItem(
"center" ).toElement();
1255 if ( !center.isNull() )
1256 hcenter = center.text();
1257 TQDomElement right = head.namedItem(
"right" ).toElement();
1258 if ( !right.isNull() )
1259 hright = right.text();
1262 TQDomElement foot = paper.namedItem(
"foot" ).toElement();
1263 if ( !foot.isNull() )
1265 TQDomElement left = foot.namedItem(
"left" ).toElement();
1266 if ( !left.isNull() )
1267 fleft = left.text();
1268 TQDomElement center = foot.namedItem(
"center" ).toElement();
1269 if ( !center.isNull() )
1270 fcenter = center.text();
1271 TQDomElement right = foot.namedItem(
"right" ).toElement();
1272 if ( !right.isNull() )
1273 fright = right.text();
1276 hleft = hleft.replace(
"<table>",
"<sheet>" );
1277 hcenter = hcenter.replace(
"<table>",
"<sheet>" );
1278 hright = hright.replace(
"<table>",
"<sheet>" );
1279 fleft = fleft.replace(
"<table>",
"<sheet>" );
1280 fcenter = fcenter.replace(
"<table>",
"<sheet>" );
1281 fright = fright.replace(
"<table>",
"<sheet>" );
1283 TQPtrListIterator<Sheet> it ( map()->sheetList() );
1284 for( ; it.current(); ++it )
1286 it.current()->print()->setHeadFootLine( hleft, hcenter, hright,
1287 fleft, fcenter, fright);
1293 kdDebug(36001) <<
"------------------------ COMPLETING --------------------" << endl;
1295 d->isLoading =
false;
1299 TQPtrListIterator<KoView> it( views() );
1300 for (; it.current(); ++it )
1301 ((
View*)it.current())->initialPosition();
1303 kdDebug(36001) <<
"------------------------ COMPLETION DONE --------------------" << endl;
1305 setModified(
false );
1310void Doc::registerPlugin( Plugin * plugin )
1312 d->plugins.append( plugin );
1315void Doc::deregisterPlugin( Plugin * plugin )
1317 d->plugins.remove( plugin );
1320bool Doc::docData( TQString
const & xmlTag, TQDomElement & data )
1322 SavedDocParts::iterator iter = m_savedDocParts.find( xmlTag );
1323 if ( iter == m_savedDocParts.end() )
1327 m_savedDocParts.erase( iter );
1334 d->verticalScrollBar=_show;
1339 return d->verticalScrollBar;
1344 d->horizontalScrollBar=_show;
1349 return d->horizontalScrollBar;
1354 return d->completionMode;
1359 d->columnHeader=_show;
1364 return d->columnHeader;
1374 return d->rowHeader;
1379 d->gridColor = color;
1384 return d->gridColor;
1387void Doc::setCompletionMode( TDEGlobalSettings::Completion complMode)
1389 d->completionMode= complMode;
1394 return d->indentValue;
1399 d->indentValue = val;
1404 d->showStatusBar=_statusBar;
1409 return d->showStatusBar;
1414 d->showTabBar=_tabbar;
1419 return d->showTabBar;
1424 d->showFormulaBar=_formulaBar;
1429 return d->showFormulaBar;
1439 return d->showError;
1442KSpread::MoveTo Doc::getMoveToValue()
const
1447void Doc::setMoveToValue(KSpread::MoveTo _moveTo)
1449 d->moveTo = _moveTo;
1454 d->calcMethod=_calc;
1457MethodOfCalc Doc::getTypeOfCalc()
const
1459 return d->calcMethod;
1464 if (d->spellConfig == 0 )
1465 d->spellConfig =
new KSpellConfig();
1467 d->spellConfig->setNoRootAffix(_tdespell.noRootAffix ());
1468 d->spellConfig->setRunTogether(_tdespell.runTogether ());
1469 d->spellConfig->setDictionary(_tdespell.dictionary ());
1470 d->spellConfig->setDictFromList(_tdespell.dictFromList());
1471 d->spellConfig->setEncoding(_tdespell.encoding());
1472 d->spellConfig->setClient(_tdespell.client());
1475KSpellConfig * Doc::getKSpellConfig()
1477 if (!d->spellConfig)
1479 KSpellConfig ksconfig;
1481 TDEConfig *config = Factory::global()->config();
1482 if( config->hasGroup(
"KSpell kspread" ) )
1484 config->setGroup(
"KSpell kspread" );
1485 ksconfig.setNoRootAffix(config->readNumEntry (
"KSpell_NoRootAffix", 0));
1486 ksconfig.setRunTogether(config->readNumEntry (
"KSpell_RunTogether", 0));
1487 ksconfig.setDictionary(config->readEntry (
"KSpell_Dictionary",
""));
1488 ksconfig.setDictFromList(config->readNumEntry (
"KSpell_DictFromList",
false));
1489 ksconfig.setEncoding(config->readNumEntry (
"KSpell_Encoding", KS_E_ASCII));
1490 ksconfig.setClient(config->readNumEntry (
"KSpell_Client", KS_CLIENT_ISPELL));
1493 setDontCheckUpperWord(config->readBoolEntry(
"KSpell_IgnoreUppercaseWords",
false));
1494 setDontCheckTitleCase(config->readBoolEntry(
"KSpell_IgnoreTitleCaseWords",
false));
1497 return d->spellConfig;
1500bool Doc::dontCheckUpperWord()
const
1502 return d->dontCheckUpperWord;
1505void Doc::setDontCheckUpperWord(
bool b )
1507 d->dontCheckUpperWord = b;
1510bool Doc::dontCheckTitleCase()
const
1512 return d->dontCheckTitleCase;
1515void Doc::setDontCheckTitleCase(
bool b )
1517 d->dontCheckTitleCase = b;
1522 return KoUnit::unitName( unit() );
1525void Doc::increaseNumOperation()
1530void Doc::decreaseNumOperation()
1535void Doc::addIgnoreWordAllList(
const TQStringList & _lst)
1537 d->spellListIgnoreAll = _lst;
1540TQStringList Doc::spellListIgnoreAll()
const
1542 return d->spellListIgnoreAll;
1547 KoZoomHandler::setZoomAndResolution( zoom, dpiX, dpiY );
1563 d->commandHistory->addCommand( command,
false );
1564 setModified(
true );
1572 setModified(
true );
1578 d->commandHistory->undo();
1585 d->commandHistory->redo();
1589void Doc::commandExecuted()
1591 setModified(
true );
1594void Doc::documentRestored()
1596 setModified(
false );
1611 return (d->undoLocked > 0);
1616 return d->commandHistory;
1619void Doc::enableUndo(
bool _b )
1621 TQPtrListIterator<KoView> it( views() );
1622 for (; it.current(); ++it )
1623 static_cast<View *
>( it.current() )->enableUndo( _b );
1626void Doc::enableRedo(
bool _b )
1628 TQPtrListIterator<KoView> it( views() );
1629 for (; it.current(); ++it )
1630 static_cast<View *
>( it.current() )->enableRedo( _b );
1633void Doc::paintContent( TQPainter& painter,
const TQRect& rect,
1634 bool transparent,
double zoomX,
double )
1636 kdDebug(36001) <<
"paintContent() called on " << rect << endl;
1642 int oldZoom = m_zoom;
1646 if ( !d->activeSheet )
1649 sheet = d->activeSheet;
1654 double d_zoom = 1.0;
1656 if ( m_zoomedResolutionX != zoomX )
1657 d_zoom *= ( zoomX / m_zoomedResolutionX );
1660 TQWMatrix matrix = painter.worldMatrix();
1661 matrix.setMatrix( 1, 0, 0, 1, matrix.dx(), matrix.dy() );
1662 TQRect prect = rect;
1663 prect.setWidth( (
int) (prect.width() * painter.worldMatrix().m11()) );
1664 prect.setHeight( (
int) (prect.height() * painter.worldMatrix().m22()) );
1667 kdDebug(36001)<<
"paintContent-------------------------------------\n";
1669 painter.setWorldMatrix( matrix );
1670 paintContent( painter, prect, transparent, sheet,
false );
1678void Doc::paintContent( TQPainter& painter,
const TQRect& rect,
bool , Sheet* sheet,
bool drawCursor )
1689 int left_col = sheet->leftColumn( unzoomItX( rect.x() ), xpos );
1690 int right_col = sheet->rightColumn( unzoomItX( rect.right() ) );
1691 int top_row = sheet->topRow( unzoomItY( rect.y() ), ypos );
1692 int bottom_row = sheet->bottomRow( unzoomItY( rect.bottom() ) );
1695 painter.setPen( pen );
1698 TQValueList<TQRect> cellAreaList;
1699 cellAreaList.append( TQRect( left_col,
1701 right_col - left_col + 1,
1702 bottom_row - top_row + 1) );
1707void Doc::paintUpdates()
1711 TQPtrListIterator<KoView> it( views() );
1713 Sheet * sheet = NULL;
1715 for (; it.current(); ++it )
1717 view =
static_cast<View *
>( it.current() );
1721 for (sheet = map()->
firstSheet(); sheet != NULL;
1722 sheet = map()->nextSheet())
1724 sheet->clearPaintDirtyData();
1730 TQValueList<TQRect> cellRegions,
1731 const Sheet* sheet,
bool )
1737 TQRegion rgn = painter.clipRegion();
1738 if ( rgn.isEmpty() )
1739 rgn = TQRegion( TQRect( 0, 0, viewRect.width(), viewRect.height() ) );
1743 matrix.scale( zoomedResolutionX(),
1744 zoomedResolutionY() );
1749 matrix = painter.worldMatrix();
1759 painter.setClipRegion( rgn );
1763 painter.setPen( pen );
1766 KoRect unzoomedViewRect = unzoomRect( viewRect );
1768 for (
unsigned int i=0; i < cellRegions.size(); i++) {
1769 cellRegion = cellRegions[i];
1771 PaintRegion(painter, unzoomedViewRect, view, cellRegion, sheet);
1776void Doc::PaintRegion(TQPainter &painter,
const KoRect &viewRegion,
1777 View* view,
const TQRect &paintRegion,
1784 if ( paintRegion.left() <= 0 || paintRegion.top() <= 0 )
1796 dblCorner = KoPoint( sheet->dblColumnPos( paintRegion.left() ),
1797 sheet->dblRowPos( paintRegion.top() ) );
1799 dblCorner = KoPoint( sheet->dblColumnPos( paintRegion.left() )
1801 sheet->dblRowPos( paintRegion.top() )
1803 KoPoint dblCurrentCellPos( dblCorner );
1805 int regionBottom = paintRegion.bottom();
1806 int regionRight = paintRegion.right();
1807 int regionLeft = paintRegion.left();
1808 int regionTop = paintRegion.top();
1810 TQValueList<TQPoint> mergedCellsPainted;
1811 for (
int y = regionTop;
1812 y <= regionBottom && dblCurrentCellPos.y() <= viewRegion.bottom();
1815 const RowFormat * row_lay = sheet->rowFormat( y );
1816 dblCurrentCellPos.setX( dblCorner.x() );
1818 for (
int x = regionLeft;
1819 x <= regionRight && dblCurrentCellPos.x() <= viewRegion.right();
1822 const ColumnFormat *col_lay = sheet->columnFormat( x );
1823 Cell* cell = sheet->cellAt( x, y );
1825 TQPoint cellRef( x, y );
1828 bool paintBordersBottom =
false;
1829 bool paintBordersRight =
false;
1830 bool paintBordersLeft =
false;
1831 bool paintBordersTop =
false;
1833 int paintBorder = Cell::Border_None;
1846 if ( x >= KS_colMax )
1848 paintBorder |= Cell::Border_Right;
1849 else if ( x == regionRight ) {
1850 paintBorder |= Cell::Border_Right;
1852 < sheet->cellAt( x + 1, y )->effLeftBorderValue( x + 1, y ) )
1853 rightPen = sheet->cellAt( x + 1, y )->effLeftBorderPen( x + 1, y );
1856 paintBorder |= Cell::Border_Right;
1858 < sheet->cellAt( x + 1, y )->effLeftBorderValue( x + 1, y ) )
1859 rightPen = sheet->cellAt( x + 1, y )->effLeftBorderPen( x + 1, y );
1864 if ( y >= KS_rowMax )
1865 paintBorder |= Cell::Border_Bottom;
1866 else if ( y == regionBottom ) {
1867 paintBorder |= Cell::Border_Bottom;
1869 < sheet->cellAt( x, y + 1 )->effTopBorderValue( x, y + 1) )
1870 bottomPen = sheet->cellAt( x, y + 1 )->effTopBorderPen( x, y + 1 );
1873 paintBorder |= Cell::Border_Bottom;
1875 < sheet->cellAt( x, y + 1 )->effTopBorderValue( x, y + 1) )
1876 bottomPen = sheet->cellAt( x, y + 1 )->effTopBorderPen( x, y + 1 );
1881 paintBorder |= Cell::Border_Left;
1882 else if ( x == regionLeft ) {
1883 paintBorder |= Cell::Border_Left;
1885 < sheet->cellAt( x - 1, y )->effRightBorderValue( x - 1, y ) )
1886 leftPen = sheet->cellAt( x - 1, y )->effRightBorderPen( x - 1, y );
1889 paintBorder |= Cell::Border_Left;
1891 < sheet->cellAt( x - 1, y )->effRightBorderValue( x - 1, y ) )
1892 leftPen = sheet->cellAt( x - 1, y )->effRightBorderPen( x - 1, y );
1897 paintBorder |= Cell::Border_Top;
1898 else if ( y == regionTop ) {
1899 paintBorder |= Cell::Border_Top;
1901 < sheet->cellAt( x, y - 1 )->effBottomBorderValue( x, y - 1 ) )
1902 topPen = sheet->cellAt( x, y - 1 )->effBottomBorderPen( x, y - 1 );
1905 paintBorder |= Cell::Border_Top;
1907 < sheet->cellAt( x, y - 1 )->effBottomBorderValue( x, y - 1 ) )
1908 topPen = sheet->cellAt( x, y - 1 )->effBottomBorderPen( x, y - 1 );
1912 cell->
paintCell( viewRegion, painter, view, dblCurrentCellPos, cellRef,
1913 paintBordersRight, paintBordersBottom,
1914 paintBordersLeft, paintBordersTop,
1915 rightPen, bottomPen, leftPen, topPen,
1916 mergedCellsPainted,
false );
1918 Cell::BorderSides highlightBorder=Cell::Border_None;
1922 cell->
paintCell( viewRegion, painter, view, dblCurrentCellPos, cellRef,
1924 rightPen, bottomPen, leftPen, topPen,
1925 mergedCellsPainted,
false );
1928 dblCurrentCellPos.setX( dblCurrentCellPos.x() + col_lay->dblWidth() );
1930 dblCurrentCellPos.setY( dblCurrentCellPos.y() + row_lay->dblHeight() );
1935DCOPObject* Doc::dcopObject()
1938 d->dcop =
new DocIface(
this );
1943void Doc::addAreaName(
const TQRect &_rect,
const TQString & name,
const TQString & sheetName)
1945 setModified(
true );
1948 tmp.sheet_name = sheetName;
1949 tmp.ref_name = name;
1950 d->refs.append( tmp);
1951 emit sig_addAreaName( name );
1954void Doc::removeArea(
const TQString & name)
1956 TQValueList<Reference>::Iterator it2;
1957 for ( it2 = d->refs.begin(); it2 != d->refs.end(); ++it2 )
1959 if((*it2).ref_name==name)
1961 d->refs.remove(it2);
1962 emit sig_removeAreaName( name );
1968void Doc::changeAreaSheetName(
const TQString & oldName,
const TQString & sheetName)
1970 TQValueList<Reference>::Iterator it2;
1971 for ( it2 = d->refs.begin(); it2 != d->refs.end(); ++it2 )
1973 if((*it2).sheet_name==oldName)
1974 (*it2).sheet_name=sheetName;
1978TQRect Doc::getRectArea(
const TQString &_sheetName)
1980 TQValueList<Reference>::Iterator it2;
1981 for ( it2 = d->refs.begin(); it2 != d->refs.end(); ++it2 )
1983 if((*it2).ref_name==_sheetName)
1988 return TQRect(-1,-1,-1,-1);
1991TQDomElement Doc::saveAreaName( TQDomDocument& doc )
1993 TQDomElement element = doc.createElement(
"areaname" );
1994 TQValueList<Reference>::Iterator it2;
1995 for ( it2 = d->refs.begin(); it2 != d->refs.end(); ++it2 )
1997 TQDomElement e = doc.createElement(
"reference");
1998 TQDomElement tabname = doc.createElement(
"tabname" );
1999 tabname.appendChild( doc.createTextNode( (*it2).sheet_name ) );
2000 e.appendChild( tabname );
2002 TQDomElement refname = doc.createElement(
"refname" );
2003 refname.appendChild( doc.createTextNode( (*it2).ref_name ) );
2004 e.appendChild( refname );
2006 TQDomElement rect = doc.createElement(
"rect" );
2007 rect.setAttribute(
"left-rect", ((*it2).rect).left() );
2008 rect.setAttribute(
"right-rect",((*it2).rect).right() );
2009 rect.setAttribute(
"top-rect", ((*it2).rect).top() );
2010 rect.setAttribute(
"bottom-rect", ((*it2).rect).bottom() );
2011 e.appendChild( rect );
2012 element.appendChild(e);
2017void Doc::loadOasisCellValidation(
const TQDomElement&body )
2019 TQDomNode validation = KoDom::namedItemNS( body, KoXmlNS::table,
"content-validations" );
2020 kdDebug()<<
"void Doc::loadOasisCellValidation( const TQDomElement&body ) \n";
2021 kdDebug()<<
"validation.isNull ? "<<validation.isNull()<<endl;
2022 if ( !validation.isNull() )
2024 TQDomNode n = validation.firstChild();
2025 for( ; !n.isNull(); n = n.nextSibling() )
2027 if ( n.isElement() )
2029 TQDomElement element = n.toElement();
2031 if ( element.tagName() ==
"content-validation" && element.namespaceURI() == KoXmlNS::table ) {
2032 d->m_loadingInfo->appendValidation(element.attributeNS( KoXmlNS::table,
"name", TQString() ), element );
2033 kdDebug()<<
" validation found :"<<element.attributeNS( KoXmlNS::table,
"name", TQString() )<<endl;
2036 kdDebug()<<
" Tag not recognize :"<<element.tagName()<<endl;
2043void Doc::saveOasisAreaName( KoXmlWriter & xmlWriter )
2045 if ( listArea().count()>0 )
2047 xmlWriter.startElement(
"table:named-expressions" );
2048 TQValueList<Reference>::Iterator it;
2049 for ( it = d->refs.begin(); it != d->refs.end(); ++it )
2051 xmlWriter.startElement(
"table:named-range" );
2053 xmlWriter.addAttribute(
"table:name", ( *it ).ref_name );
2054 xmlWriter.addAttribute(
"table:base-cell-address", convertRefToBase( ( *it ).sheet_name, ( *it ).rect ) );
2055 xmlWriter.addAttribute(
"table:cell-range-address", convertRefToRange( ( *it ).sheet_name, ( *it ).rect ) );
2057 xmlWriter.endElement();
2059 xmlWriter.endElement();
2063void Doc::loadOasisAreaName(
const TQDomElement& body )
2065 kdDebug()<<
"void Doc::loadOasisAreaName( const TQDomElement& body ) \n";
2066 TQDomNode namedAreas = KoDom::namedItemNS( body, KoXmlNS::table,
"named-expressions" );
2067 if ( !namedAreas.isNull() )
2069 kdDebug()<<
" area name exist \n";
2070 TQDomNode area = namedAreas.firstChild();
2071 while ( !area.isNull() )
2073 TQDomElement e = area.toElement();
2075 if ( e.localName() ==
"named-range" )
2077 if ( !e.hasAttributeNS( KoXmlNS::table,
"name" ) || !e.hasAttributeNS( KoXmlNS::table,
"cell-range-address" ) )
2079 kdDebug() <<
"Reading in named area failed" << endl;
2080 area = area.nextSibling();
2085 TQString name = e.attributeNS( KoXmlNS::table,
"name", TQString() );
2086 TQString range = e.attributeNS( KoXmlNS::table,
"cell-range-address", TQString() );
2087 kdDebug()<<
"area name : "<<name<<
" range :"<<range<<endl;
2088 d->m_loadingInfo->addWordInAreaList( name );
2089 kdDebug() <<
"Reading in named area, name: " << name <<
", area: " << range << endl;
2091 range = Oasis::decodeFormula( range );
2093 if ( range.find(
':' ) == -1 )
2097 int n = range.find(
'!' );
2099 range = range +
":" + range.right( range.length() - n - 1);
2101 kdDebug() <<
"=> Area: " << range << endl;
2104 if ( range.contains(
'!' ) && range[0] ==
'$' )
2107 range.remove( 0, 1 );
2112 addAreaName( p.range(), name, p.sheetName() );
2113 kdDebug() <<
"Area range: " << p.toString() << endl;
2115 else if ( e.localName() ==
"named-expression" )
2117 kdDebug() <<
"Named expression found." << endl;
2121 area = area.nextSibling();
2126void Doc::loadAreaName(
const TQDomElement& element )
2128 TQDomElement tmp=element.firstChild().toElement();
2129 for( ; !tmp.isNull(); tmp=tmp.nextSibling().toElement() )
2131 if ( tmp.tagName() ==
"reference" )
2139 TQDomElement sheetName = tmp.namedItem(
"tabname" ).toElement();
2140 if ( !sheetName.isNull() )
2142 tabname=sheetName.text();
2144 TQDomElement referenceName = tmp.namedItem(
"refname" ).toElement();
2145 if ( !referenceName.isNull() )
2147 refname=referenceName.text();
2149 TQDomElement rect =tmp.namedItem(
"rect" ).toElement();
2153 if ( rect.hasAttribute(
"left-rect" ) )
2154 left=rect.attribute(
"left-rect").toInt( &ok );
2155 if ( rect.hasAttribute(
"right-rect" ) )
2156 right=rect.attribute(
"right-rect").toInt( &ok );
2157 if ( rect.hasAttribute(
"top-rect" ) )
2158 top=rect.attribute(
"top-rect").toInt( &ok );
2159 if ( rect.hasAttribute(
"bottom-rect" ) )
2160 bottom=rect.attribute(
"bottom-rect").toInt( &ok );
2163 _rect.setCoords(left,top,right,bottom);
2164 addAreaName(_rect,refname,tabname);
2169void Doc::addStringCompletion(
const TQString &stringCompletion)
2171 if ( d->listCompletion.items().contains(stringCompletion) == 0 )
2172 d->listCompletion.addItem( stringCompletion );
2175void Doc::refreshInterface()
2180void Doc::refreshLocale()
2193 TQCursor* activeOverride =
static_cast<TQCursor*
>(TQApplication::overrideCursor());
2195 if (waitCursor && ( (!activeOverride) || (activeOverride->shape() != TQt::waitCursor.shape()) ) )
2197 TQApplication::setOverrideCursor(TQt::waitCursor);
2206 KoDocument::emitBeginOperation();
2207 d->delayCalculation =
true;
2221 if (d->numOperations <= 0)
2223 d->numOperations = 0;
2224 d->delayCalculation =
false;
2227 KoDocument::emitEndOperation();
2229 if (d->numOperations == 0)
2231 TQApplication::restoreOverrideCursor();
2244 if ( d->numOperations > 0 || !d->activeSheet )
2246 KoDocument::emitEndOperation();
2250 d->numOperations = 0;
2251 d->delayCalculation =
false;
2253 KoDocument::emitEndOperation();
2255 TQApplication::restoreOverrideCursor();
2263bool Doc::delayCalculation()
const
2265 return d->delayCalculation;
2268void Doc::updateBorderButton()
2270 TQPtrListIterator<KoView> it( views() );
2271 for (; it.current(); ++it )
2272 static_cast<View *
>( it.current() )->updateBorderButton();
2275void Doc::insertSheet( Sheet * sheet )
2277 TQPtrListIterator<KoView> it( views() );
2278 for (; it.current(); ++it )
2279 ((
View*)it.current())->insertSheet( sheet );
2282void Doc::takeSheet( Sheet * sheet )
2284 TQPtrListIterator<KoView> it( views() );
2285 for (; it.current(); ++it )
2286 ((
View*)it.current())->removeSheet( sheet );
2289void Doc::addIgnoreWordAll(
const TQString & word)
2291 if( d->spellListIgnoreAll.findIndex( word )==-1)
2292 d->spellListIgnoreAll.append( word );
2295void Doc::clearIgnoreWordAll( )
2297 d->spellListIgnoreAll.clear();
2300void Doc::setDisplaySheet(Sheet *_sheet )
2302 d->activeSheet = _sheet;
2307 return d->m_loadingInfo;
2312 delete d->m_loadingInfo;
2313 d->m_loadingInfo = 0;
2316Sheet * Doc::displaySheet()
const
2318 return d->activeSheet;
2321void Doc::addView( KoView *_view )
2323 KoDocument::addView( _view );
2324 TQPtrListIterator<KoView> it( views() );
2325 for (; it.current(); ++it )
2326 ((
View*)it.current())->closeEditor();
2329void Doc::addDamage( Damage* damage )
2331 d->damages.append( damage );
2333 if( d->damages.count() == 1 )
2334 TQTimer::singleShot( 0,
this, TQ_SLOT( flushDamages() ) );
2337void Doc::flushDamages()
2339 emit damagesFlushed( d->damages );
2340 TQValueList<Damage*>::Iterator it;
2341 for( it = d->damages.begin(); it != d->damages.end(); ++it )
2346void Doc::loadConfigFromFile()
2348 d->configLoadFromFile =
true;
2351bool Doc::configLoadFromFile()
const
2353 return d->configLoadFromFile;
2359 switch ( obj->getType() )
2361 case OBJECT_KOFFICE_PART:
case OBJECT_CHART:
2369 d->m_embeddedObjects.append( obj );
2374 return d->m_embeddedObjects;
2377KoPictureCollection *Doc::pictureCollection()
2379 return &d->m_pictureCollection;
2382void Doc::repaint(
const TQRect& rect )
2385 TQPtrListIterator<KoView> it( views() );
2386 for( ; it.current(); ++it )
2389 Canvas* canvas = ((
View*)it.current())->canvasWidget();
2390 r.moveTopLeft( TQPoint( r.x() - (int) canvas->
xOffset(),
2391 r.y() - (int) canvas->
yOffset() ) );
2392 canvas->update( r );
2398 TQPtrListIterator<KoView> it( views() );
2399 for( ; it.current(); ++it )
2401 Canvas* canvas = ((
View*)it.current())->canvasWidget();
2403 canvas->repaintObject( obj );
2407void Doc::repaint(
const KoRect& rect )
2410 TQPtrListIterator<KoView> it( views() );
2411 for( ; it.current(); ++it )
2413 Canvas* canvas = ((
View*)it.current())->canvasWidget();
2415 r = zoomRect( rect );
2416 r.moveBy( (
int)( -canvas->
xOffset()*zoomedResolutionX() ) ,
2417 (
int)( -canvas->
yOffset() *zoomedResolutionY()) );
2418 canvas->update( r );
2422void Doc::addShell( KoMainWindow *shell )
2424 connect( shell, TQ_SIGNAL( documentSaved() ), d->commandHistory, TQ_SLOT( documentSaved() ) );
2425 KoDocument::addShell( shell );
2428int Doc::undoRedoLimit()
const
2430 return d->commandHistory->undoLimit();
2433void Doc::setUndoRedoLimit(
int val)
2435 d->commandHistory->setUndoLimit(val);
2436 d->commandHistory->setRedoLimit(val);
2439void Doc::insertPixmapKey( KoPictureKey key )
2441 if ( !d->usedPictures.contains( key ) )
2442 d->usedPictures.append( key );
2445void Doc::makeUsedPixmapList()
2447 d->usedPictures.clear();
2448 TQPtrListIterator<EmbeddedObject> it( d->m_embeddedObjects );
2449 for ( ; it.current() ; ++it )
2451 if( it.current()->getType() == OBJECT_PICTURE && ( d->m_savingWholeDocument || it.current()->isSelected() ) )
2456bool Doc::savingWholeDocument()
2458 return d->m_savingWholeDocument;
2461#include "kspread_doc.moc"
The canvas builds a part of the GUI of KSpread.
Sheet * activeSheet() const
For every cell in the spread sheet there is a Cell object.
const TQPen & effBottomBorderPen(int col, int row) const
void paintCell(const KoRect &rect, TQPainter &painter, View *view, const KoPoint &coordinate, const TQPoint &cellRef, int paintBorder, TQPen &rightPen, TQPen &bottomPen, TQPen &leftPen, TQPen &topPen, TQValueList< TQPoint > &mergedCellsPainted, bool drawCursor=true)
Paints the cell.
uint effRightBorderValue(int col, int row) const
const TQPen & effTopBorderPen(int col, int row) const
const TQPen & effRightBorderPen(int col, int row) const
uint effLeftBorderValue(int col, int row) const
uint effTopBorderValue(int col, int row) const
const TQPen & effLeftBorderPen(int col, int row) const
uint effBottomBorderValue(int col, int row) const
bool showMessageError() const
Returns true if error message should pop up whenever error occurs.
void setShowTabBar(bool b)
If b is true, tab bar is visible, otherwise it will be hidden.
void setShowVerticalScrollBar(bool b)
If b is true, vertical scrollbar is visible, otherwise it will be hidden.
void setShowStatusBar(bool b)
If b is true, status bar is visible, otherwise it will be hidden.
bool showStatusBar() const
Returns true if status bar is visible.
int syntaxVersion() const
Returns the syntax version of the currently opened file.
virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY)
Change the zoom factor to z (e.g.
bool showColumnHeader() const
Returns true if column header is visible.
void setIndentValue(double val)
Sets the indentation value.
void redo()
Redoes the last undo.
void setShowColumnHeader(bool b)
If b is true, column header is visible, otherwise it will be hidden.
void sig_refreshLocale()
Emitted if we update to locale system.
void setTypeOfCalc(MethodOfCalc _calc)
Method of calc.
KoCommandHistory * commandHistory()
Returns the command history for the document.
void sig_refreshView()
Emitted if all interfaces have to be updated.
bool undoLocked() const
Returns true if undo buffer is locked.
bool saveOasisHelper(KoStore *store, KoXmlWriter *manifestWriter, SaveFlag saveFlag, TQString *plainText=0, KoPicture *picture=0)
Save the whole document, or just the selection, into OASIS format When saving the selection,...
void doNotPaint(bool status)
Prevents painting.
virtual bool completeLoading(KoStore *)
Overloaded function of KoDocument.
~Doc()
Destroys the document.
void setGridColor(const TQColor &color)
Sets the color of the grid.
void setShowMessageError(bool b)
If b is true, an error message will pop up whenever error occurs.
void setShowHorizontalScrollBar(bool b)
If b is true, horizontal scrollbar is visible, otherwise it will be hidden.
Doc(TQWidget *parentWidget=0, const char *widgetName=0, TQObject *parent=0, const char *name=0, bool singleViewMode=false)
Creates a new document.
bool showVerticalScrollBar() const
Returns true if vertical scroll bar is visible.
bool showRowHeader() const
Returns true if row header is visible.
void newZoomAndResolution(bool updateViews, bool forPrint)
updates all properties after zoom changed
virtual bool saveChildren(KoStore *_store)
Overloaded function of KoDocument.
void addCommand(KCommand *command)
Adds a command to the command history.
void setShowFormulaBar(bool b)
If b is true, formula bar is visible, otherwise it will be hidden.
bool showFormulaBar() const
Returns true if formula bar is visible.
virtual void emitBeginOperation()
default override of koDocument version.
TDEGlobalSettings::Completion completionMode() const
completion mode
@ STYLE_COLUMN_AUTO
auto column styles
@ STYLE_COLUMN_USER
commmon column styles
@ STYLE_ROW_AUTO
auto row styles
@ STYLE_ROW_USER
common row styles
KSPLoadingInfo * loadingInfo() const
void undoUnlock()
Releases lock of undo buffer.
TQString unitName() const
Returns the name of the unit used to display margins.
void insertObject(EmbeddedObject *obj)
Inserts an object to the object list.
void setKSpellConfig(KSpellConfig _tdespell)
get custom tdespell config
bool showHorizontalScrollBar() const
Returns true if horizontal scroll bar is visible.
bool showTabBar() const
Returns true if tab bar is visible.
void deleteLoadingInfo()
deletes the loading info after loading is complete
void undoLock()
Locks the undo buffer.
TQColor gridColor() const
Returns the color of the grid.
virtual void emitEndOperation()
Mark the end of an operation and triggers a repaint of any cells or regions of cells which have been ...
void paintCellRegions(TQPainter &painter, const TQRect &viewRect, View *view, TQValueList< TQRect > cellRegions, const Sheet *sheet, bool drawCursor)
Primary entry point for painting.
double indentValue() const
Returns the indentation value.
static TQValueList< Doc * > documents()
Returns list of all documents.
void undo()
Undoes the last operation.
TQPtrList< EmbeddedObject > & embeddedObjects()
void setShowRowHeader(bool b)
If b is true, row header is visible, otherwise it will be hidden.
Holds an embedded koffice object.
Contains basic information for every object.
Temporary information used only during loading.
A map is a simple container for all sheets.
Sheet * addNewSheet()
add a new sheet to the map, returning a pointer to it
Sheet * firstSheet()
Use the #nextSheet function to get all the other sheets.
Represents the position of a single cell in a workbook.
Represents a region within a workbook.
The one for all class for points and ranges.
Class UndoWrapperCommand is used to help migration from custom UndoAction to KCommand-based system.
The ValueCalc class is used to perform all sorts of calculations.
The ValueConverter class can convert Value between various different formats.
The ValueParser parses a text input from the user, generating Value in the desired format.
The View class displays a KSpread document.
void deleteEditor(bool saveChanges=true)
Called before saving, to finish the current edition (if any)
Canvas * canvasWidget() const
Returns the canvas of the view.
void paintUpdates()
Repaint any cell with the paintDirty flag that is visible in this view.