You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
6.7 KiB
248 lines
6.7 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
|
||
|
Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
|
#include "kformula_doc.h"
|
||
|
#include "kformula_view.h"
|
||
|
#include "kformula_factory.h"
|
||
|
|
||
14 years ago
|
#include <tqbitmap.h>
|
||
|
#include <tqcolor.h>
|
||
|
#include <tqdom.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqprinter.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqwmatrix.h>
|
||
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
|
#include <config.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
12 years ago
|
#include <tdeaboutdialog.h>
|
||
12 years ago
|
#include <tdeaction.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <KoGlobal.h>
|
||
|
#include <kiconloader.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kstdaction.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kurl.h>
|
||
|
#include <KoXmlWriter.h>
|
||
|
#include <KoStoreDevice.h>
|
||
12 years ago
|
#include <tdetempfile.h>
|
||
15 years ago
|
#include <KoMainWindow.h>
|
||
|
|
||
|
#include <kformulacontainer.h>
|
||
|
#include <kformuladocument.h>
|
||
|
|
||
|
|
||
13 years ago
|
KFormulaDoc::KFormulaDoc(TQWidget *parentWidget, const char *widgetName, TQObject* parent, const char* name, bool singleViewMode)
|
||
|
: KoDocument(parentWidget, widgetName, parent, name, singleViewMode)
|
||
15 years ago
|
{
|
||
|
setInstance(KFormulaFactory::global(), false);
|
||
|
//kdDebug(39001) << "General Settings" << endl;
|
||
|
|
||
|
history = new KoCommandHistory( actionCollection() );
|
||
|
wrapper = new KFormula::DocumentWrapper( kapp->config(),
|
||
|
actionCollection(),
|
||
|
history );
|
||
|
document = new KFormula::Document;
|
||
|
wrapper->document( document );
|
||
|
formula = document->createFormula();
|
||
|
|
||
|
document->setEnabled( true );
|
||
|
|
||
|
// the modify flag
|
||
14 years ago
|
connect(history, TQT_SIGNAL(commandExecuted()), this, TQT_SLOT(commandExecuted()));
|
||
|
connect(history, TQT_SIGNAL(documentRestored()), this, TQT_SLOT(documentRestored()));
|
||
15 years ago
|
dcopObject();
|
||
|
}
|
||
|
|
||
|
|
||
|
KFormulaDoc::~KFormulaDoc()
|
||
|
{
|
||
|
delete history;
|
||
|
delete wrapper;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KFormulaDoc::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
|
||
|
{
|
||
|
if ( !store->open( "content.xml" ) )
|
||
|
return false;
|
||
|
|
||
|
KoStoreDevice dev( store );
|
||
|
KoXmlWriter* contentWriter = createOasisXmlWriter( &dev, "math:math" );
|
||
|
|
||
|
|
||
|
KTempFile contentTmpFile;
|
||
|
contentTmpFile.setAutoDelete( true );
|
||
14 years ago
|
TQFile* tmpFile = contentTmpFile.file();
|
||
15 years ago
|
|
||
|
//todo save content
|
||
14 years ago
|
TQTextStream stream(tmpFile);
|
||
|
stream.setEncoding( TQTextStream::UnicodeUTF8 );
|
||
15 years ago
|
formula->saveMathML( stream, true );
|
||
|
|
||
|
tmpFile->close();
|
||
14 years ago
|
contentWriter->addCompleteElement( TQT_TQIODEVICE(tmpFile) );
|
||
15 years ago
|
contentTmpFile.close();
|
||
|
|
||
|
|
||
|
|
||
|
contentWriter->endElement();
|
||
|
delete contentWriter;
|
||
|
|
||
|
if(!store->close())
|
||
|
return false;
|
||
|
|
||
|
manifestWriter->addManifestEntry("content.xml", "text/xml");
|
||
|
|
||
|
setModified( false );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQDomDocument KFormulaDoc::saveXML()
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomDocument doc = document->saveXML();
|
||
15 years ago
|
history->documentSaved();
|
||
|
return doc;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KFormulaDoc::loadOasis( const TQDomDocument& doc, KoOasisStyles&, const TQDomDocument&, KoStore* )
|
||
15 years ago
|
{
|
||
|
// we don't have style into this format
|
||
|
// we don't have settings into kformula (for the moment)
|
||
|
// necessary to adapt kformula code to load MathML format with Oasis Extension.
|
||
|
|
||
|
if ( document->loadOasis( doc ) ) {
|
||
|
history->clear();
|
||
|
history->documentSaved();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KFormulaDoc::loadXML(TQIODevice *, const TQDomDocument& doc)
|
||
15 years ago
|
{
|
||
|
if ( doc.doctype().name().lower() == "math"
|
||
|
|| doc.documentElement().tagName().lower() == "math" )
|
||
|
if ( document->loadOasis( doc ) ) {
|
||
|
history->clear();
|
||
|
history->documentSaved();
|
||
|
return true;
|
||
|
}
|
||
|
if ( document->loadXML( doc ) ) {
|
||
|
history->clear();
|
||
|
history->documentSaved();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Saves the document in native format, to a given file.
|
||
|
* It is reimplemented to handle the special case of MathML, since it is
|
||
|
* a native format but not compressed.
|
||
|
*/
|
||
14 years ago
|
bool KFormulaDoc::saveNativeFormat( const TQString & file )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQCString mimeType = outputMimeType();
|
||
13 years ago
|
bool mathml = !mimeType.isEmpty() && mimeType.contains( "mathml", false );
|
||
15 years ago
|
if ( mathml ) {
|
||
14 years ago
|
TQFile f( file );
|
||
15 years ago
|
if ( f.open( IO_WriteOnly | IO_Translate ) )
|
||
|
{
|
||
14 years ago
|
TQTextStream stream( &f );
|
||
|
stream.setEncoding( TQTextStream::UnicodeUTF8 );
|
||
15 years ago
|
formula->saveMathML( stream, false );
|
||
|
f.close();
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
13 years ago
|
// If it's not MathML, let the parent handle it
|
||
15 years ago
|
return KoDocument::saveNativeFormat( file );
|
||
|
}
|
||
|
|
||
14 years ago
|
KoView* KFormulaDoc::createViewInstance(TQWidget* _parent, const char *name)
|
||
15 years ago
|
{
|
||
|
return new KFormulaPartView(this, _parent, name);
|
||
|
}
|
||
|
|
||
|
void KFormulaDoc::commandExecuted()
|
||
|
{
|
||
|
if (formula->isEmpty()) {
|
||
|
setEmpty();
|
||
|
}
|
||
|
setModified(true);
|
||
|
}
|
||
|
|
||
|
void KFormulaDoc::documentRestored()
|
||
|
{
|
||
|
setModified(false);
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
bool KFormulaDoc::initDoc(InitDocFlags /*flags*/, TQWidget* /*parentWidget*/)
|
||
15 years ago
|
{
|
||
|
// If nothing is loaded, do initialize here
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
13 years ago
|
void KFormulaDoc::showStartUpWidget(KoMainWindow* parent, bool /*alwaysShow*/)
|
||
15 years ago
|
{
|
||
13 years ago
|
parent->setRootDocument( this );
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
bool KFormulaDoc::showEmbedInitDialog(TQWidget* /*parent*/)
|
||
15 years ago
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
void KFormulaDoc::paintContent(TQPainter& painter, const TQRect& rect, bool transparent, double zoomX, double zoomY)
|
||
15 years ago
|
{
|
||
|
// ####### handle transparency and zoom
|
||
|
// Need to draw only the document rectangle described in the parameter rect.
|
||
|
|
||
14 years ago
|
bool forPrint = painter.device() && painter.device()->devType() == TQInternal::Printer;
|
||
15 years ago
|
document->setZoomAndResolution( 100, zoomX, zoomY, true, forPrint );
|
||
|
if ( !transparent ) {
|
||
14 years ago
|
painter.fillRect( rect, TQt::white );
|
||
15 years ago
|
}
|
||
|
formula->draw( painter, rect );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KFormulaDoc::configFile() const
|
||
15 years ago
|
{
|
||
|
// return readConfigFile( locate( "data", "kformula/kformula.rc",
|
||
|
// KFormulaFactory::global() ) );
|
||
|
|
||
|
// return readConfigFile( "kformula.rc" );
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
|
#include "kformula_doc.moc"
|