# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# khtml_factory.cpp

    00001 /* This file is part of the KDE project
    00002  *
    00003  * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public License
    00016  * along with this library; see the file COPYING.LIB.  If not, write to
    00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021 #include "khtml_factory.h"
    00022 #include "khtml_part.h"
    00023 #include "khtml_settings.h"
    00024
    00025 #include "css/cssstyleselector.h"
    00026 #include "html/html_imageimpl.h"
    00027 #include "rendering/render_style.h"
    00028 #include "misc/loader.h"
    00029
    00030 #include <kinstance.h>
    00031 #include <kaboutdata.h>
    00032 #include <klocale.h>
    00033
    00034 #include <assert.h>
    00035
    00036 #include <kdebug.h>
    00037
    00038 template class QPtrList<KHTMLPart>;
    00039
    00040 extern "C"
    00041 {
    00042   void *init_libkhtml()
    00043   {
    00044       // We can't use a plain self() here, because that would
    00045       // return the global factory, which might already exist
    00046       // at the time init_libkhtml is called! As soon as someone
    00047       // does new KHTMLPart() in his application and loads up
    00048       // an html document into that part which either embeds
    00049       // embeds another KHTMLPart instance via <object> or
    00050       // as html frame, then we cannot return self(), as
    00051       // what we return here is what the KLibLoader deletes
    00052       // in the end, and we don't want the libloader to
    00053       // delete our global instance. Anyway, the new
    00054       // KHTMLFactory we create here is very cheap :)
    00055       // (Simon)
    00056       return new KHTMLFactory( true );
    00057   }
    00058 }
    00059
    00060 KHTMLFactory *KHTMLFactory::s_self = 0;
    00061 unsigned long int KHTMLFactory::s_refcnt = 0;
    00062 KInstance *KHTMLFactory::s_instance = 0;
    00063 KAboutData *KHTMLFactory::s_about = 0;
    00064 KHTMLSettings *KHTMLFactory::s_settings = 0;
    00065 QPtrList<KHTMLPart> *KHTMLFactory::s_parts = 0;
    00066 QString *KHTMLSettings::avFamilies = 0;
    00067
    00068 KHTMLFactory::KHTMLFactory( bool clone )
    00069 {
    00070     if ( clone )
    00071         ref();
    00072 }
    00073
    00074 KHTMLFactory::~KHTMLFactory()
    00075 {
    00076     if ( s_self == this )
    00077     {
    00078         assert( !s_refcnt );
    00079
    00080         if ( s_instance )
    00081             delete s_instance;
    00082         if ( s_about )
    00083             delete s_about;
    00084         if ( s_settings )
    00085             delete s_settings;
    00086         if ( KHTMLSettings::avFamilies )
    00087             delete KHTMLSettings::avFamilies;
    00088         if ( s_parts )
    00089         {
    00090             assert( s_parts->isEmpty() );
    00091             delete s_parts;
    00092         }
    00093
    00094         s_instance = 0;
    00095         s_about = 0;
    00096         s_settings = 0;
    00097         s_parts = 0;
    00098         KHTMLSettings::avFamilies = 0;
    00099
    00100         kdDebug( 6000 ) << "KHTMLFactory::~KHTMLFactory" << endl;
    00101         // clean up static data
    00102         khtml::CSSStyleSelector::clear();
    00103         khtml::RenderStyle::cleanup();
    00104         khtml::Cache::clear();
    00105     }
    00106     else
    00107         deref();
    00108 }
    00109
    00110 KParts::Part *KHTMLFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *className, const QStringList & )
    00111 {
    00112   KHTMLPart::GUIProfile prof = KHTMLPart::DefaultGUI;
    00113   if ( strcmp( className, "Browser/View" ) == 0 )
    00114     prof = KHTMLPart::BrowserViewGUI;
    00115
    00116   return new KHTMLPart( parentWidget, widgetName, parent, name, prof );
    00117 }
    00118
    00119 void KHTMLFactory::ref()
    00120 {
    00121     if ( !s_refcnt && !s_self )
    00122     {
    00123         // we can't use a staticdeleter here, because that would mean
    00124         // that the factory gets deleted from within a qPostRoutine, called
    00125         // from the QApplication destructor. That however is too late, because
    00126         // we want to destruct a KInstance object, which involves destructing
    00127         // a KConfig object, which might call KGlobal::dirs() (in sync()) which
    00128         // probably is not going to work ;-)
    00129         // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
    00130         // safe side ;-) -> let's use a simple reference counting scheme
    00131         // (Simon)
    00132         s_self = new KHTMLFactory;
    00133         khtml::Cache::init();
    00134     }
    00135
    00136     s_refcnt++;
    00137 }
    00138
    00139 void KHTMLFactory::deref()
    00140 {
    00141     if ( !--s_refcnt && s_self )
    00142     {
    00143         delete s_self;
    00144         s_self = 0;
    00145     }
    00146 }
    00147
    00148 void KHTMLFactory::registerPart( KHTMLPart *part )
    00149 {
    00150     if ( !s_parts )
    00151         s_parts = new QPtrList<KHTMLPart>;
    00152
    00153     if ( !s_parts->containsRef( part ) )
    00154     {
    00155         s_parts->append( part );
    00156         ref();
    00157     }
    00158 }
    00159
    00160 void KHTMLFactory::deregisterPart( KHTMLPart *part )
    00161 {
    00162     assert( s_parts );
    00163
    00164     if ( s_parts->removeRef( part ) )
    00165     {
    00166         if ( s_parts->isEmpty() )
    00167         {
    00168             delete s_parts;
    00169             s_parts = 0;
    00170         }
    00171         deref();
    00172     }
    00173 }
    00174
    00175 KInstance *KHTMLFactory::instance()
    00176 {
    00177   assert( s_self );
    00178
    00179   if ( !s_instance )
    00180   {
    00181     s_about = new KAboutData( "khtml", I18N_NOOP( "KHTML" ), "4.0",
    00182                               I18N_NOOP( "Embeddable HTML component" ),
    00183                               KAboutData::License_LGPL );
    00184     s_about->addAuthor( "Lars Knoll", 0, "knoll@kde.org" );
    00185     s_about->addAuthor( "Antti Koivisto", 0, "koivisto@kde.org" );
    00186     s_about->addAuthor( "Waldo Bastian", 0, "bastian@kde.org" );
    00187     s_about->addAuthor( "Dirk Mueller", 0, "mueller@kde.org" );
    00188     s_about->addAuthor( "Peter Kelly", 0, "ptrkelly@hotmail.com" );
    00189     s_about->addAuthor( "Torben Weis", 0, "weis@kde.org" );
    00190     s_about->addAuthor( "Martin Jones", 0, "mjones@kde.org" );
    00191     s_about->addAuthor( "Simon Hausmann", 0, "hausmann@kde.org" );
    00192     s_about->addAuthor( "Tobias Anton", 0, "anton@stud.fbi.fh-darmstadt.de" );
    00193
    00194     s_instance = new KInstance( s_about );
    00195   }
    00196
    00197   return s_instance;
    00198 }
    00199
    00200 KHTMLSettings *KHTMLFactory::defaultHTMLSettings()
    00201 {
    00202   assert( s_self );
    00203   if ( !s_settings )
    00204     s_settings = new KHTMLSettings();
    00205
    00206   return s_settings;
    00207 }
    00208
    00209 using namespace KParts;
    00210 #include "khtml_factory.moc"
    00211

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:01 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001