khtml_factory.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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" void *init_libkhtml()
00041 {
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 return new KHTMLFactory( true );
00055 }
00056
00057 KHTMLFactory *KHTMLFactory::s_self = 0;
00058 unsigned long int KHTMLFactory::s_refcnt = 0;
00059 KInstance *KHTMLFactory::s_instance = 0;
00060 KAboutData *KHTMLFactory::s_about = 0;
00061 KHTMLSettings *KHTMLFactory::s_settings = 0;
00062 QPtrList<KHTMLPart> *KHTMLFactory::s_parts = 0;
00063 QString *KHTMLSettings::avFamilies = 0;
00064
00065 KHTMLFactory::KHTMLFactory( bool clone )
00066 {
00067 if ( clone )
00068 ref();
00069 }
00070
00071 KHTMLFactory::~KHTMLFactory()
00072 {
00073 if ( s_self == this )
00074 {
00075 assert( !s_refcnt );
00076
00077 delete s_instance;
00078 delete s_about;
00079 delete s_settings;
00080 delete KHTMLSettings::avFamilies;
00081 if ( s_parts )
00082 {
00083 assert( s_parts->isEmpty() );
00084 delete s_parts;
00085 }
00086
00087 s_instance = 0;
00088 s_about = 0;
00089 s_settings = 0;
00090 s_parts = 0;
00091 KHTMLSettings::avFamilies = 0;
00092
00093
00094 khtml::CSSStyleSelector::clear();
00095 khtml::RenderStyle::cleanup();
00096 khtml::Cache::clear();
00097 }
00098 else
00099 deref();
00100 }
00101
00102 KParts::Part *KHTMLFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *className, const QStringList & )
00103 {
00104 KHTMLPart::GUIProfile prof = KHTMLPart::DefaultGUI;
00105 if ( strcmp( className, "Browser/View" ) == 0 )
00106 prof = KHTMLPart::BrowserViewGUI;
00107
00108 return new KHTMLPart( parentWidget, widgetName, parent, name, prof );
00109 }
00110
00111 void KHTMLFactory::ref()
00112 {
00113 if ( !s_refcnt && !s_self )
00114 {
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 s_self = new KHTMLFactory;
00125 khtml::Cache::init();
00126 }
00127
00128 s_refcnt++;
00129 }
00130
00131 void KHTMLFactory::deref()
00132 {
00133 if ( !--s_refcnt && s_self )
00134 {
00135 delete s_self;
00136 s_self = 0;
00137 }
00138 }
00139
00140 void KHTMLFactory::registerPart( KHTMLPart *part )
00141 {
00142 if ( !s_parts )
00143 s_parts = new QPtrList<KHTMLPart>;
00144
00145 if ( !s_parts->containsRef( part ) )
00146 {
00147 s_parts->append( part );
00148 ref();
00149 }
00150 }
00151
00152 void KHTMLFactory::deregisterPart( KHTMLPart *part )
00153 {
00154 assert( s_parts );
00155
00156 if ( s_parts->removeRef( part ) )
00157 {
00158 if ( s_parts->isEmpty() )
00159 {
00160 delete s_parts;
00161 s_parts = 0;
00162 }
00163 deref();
00164 }
00165 }
00166
00167 KInstance *KHTMLFactory::instance()
00168 {
00169 assert( s_self );
00170
00171 if ( !s_instance )
00172 {
00173 s_about = new KAboutData( "khtml", I18N_NOOP( "KHTML" ), "4.0",
00174 I18N_NOOP( "Embeddable HTML component" ),
00175 KAboutData::License_LGPL );
00176 s_about->addAuthor( "Lars Knoll", 0, "knoll@kde.org" );
00177 s_about->addAuthor( "Antti Koivisto", 0, "koivisto@kde.org" );
00178 s_about->addAuthor( "Waldo Bastian", 0, "bastian@kde.org" );
00179 s_about->addAuthor( "Dirk Mueller", 0, "mueller@kde.org" );
00180 s_about->addAuthor( "Peter Kelly", 0, "pmk@kde.org" );
00181 s_about->addAuthor( "Torben Weis", 0, "weis@kde.org" );
00182 s_about->addAuthor( "Martin Jones", 0, "mjones@kde.org" );
00183 s_about->addAuthor( "Simon Hausmann", 0, "hausmann@kde.org" );
00184 s_about->addAuthor( "Tobias Anton", 0, "anton@stud.fbi.fh-darmstadt.de" );
00185
00186 s_instance = new KInstance( s_about );
00187 }
00188
00189 return s_instance;
00190 }
00191
00192 KHTMLSettings *KHTMLFactory::defaultHTMLSettings()
00193 {
00194 assert( s_self );
00195 if ( !s_settings )
00196 s_settings = new KHTMLSettings();
00197
00198 return s_settings;
00199 }
00200
00201 using namespace KParts;
00202 #include "khtml_factory.moc"
00203
This file is part of the documentation for khtml Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 21 18:45:03 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003