• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdehtml
 

tdehtml

tdehtml_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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "tdehtml_factory.h"
00022 #include "tdehtml_part.h"
00023 #include "tdehtml_settings.h"
00024 
00025 #include "css/cssstyleselector.h"
00026 #include "html/html_imageimpl.h"
00027 #include "rendering/render_style.h"
00028 #include "rendering/break_lines.h"
00029 #include "misc/loader.h"
00030 #include "misc/arena.h"
00031 
00032 #include <kinstance.h>
00033 #include <tdeaboutdata.h>
00034 #include <tdelocale.h>
00035 
00036 #include <assert.h>
00037 
00038 #include <kdebug.h>
00039 
00040 template class TQPtrList<TDEHTMLPart>;
00041 
00042 extern "C" KDE_EXPORT void *init_libtdehtml()
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_libtdehtml is called! As soon as someone
00047     // does new TDEHTMLPart() in his application and loads up
00048     // an html document into that part which either embeds
00049     // embeds another TDEHTMLPart 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     // TDEHTMLFactory we create here is very cheap :)
00055     // (Simon)
00056     return new TDEHTMLFactory( true );
00057 }
00058 
00059 TDEHTMLFactory *TDEHTMLFactory::s_self = 0;
00060 unsigned long int TDEHTMLFactory::s_refcnt = 0;
00061 TDEInstance *TDEHTMLFactory::s_instance = 0;
00062 TDEAboutData *TDEHTMLFactory::s_about = 0;
00063 TDEHTMLSettings *TDEHTMLFactory::s_settings = 0;
00064 TQPtrList<TDEHTMLPart> *TDEHTMLFactory::s_parts = 0;
00065 TQString *TDEHTMLSettings::avFamilies = 0;
00066 
00067 TDEHTMLFactory::TDEHTMLFactory( bool clone )
00068 {
00069     if ( clone )
00070         ref();
00071 }
00072 
00073 TDEHTMLFactory::~TDEHTMLFactory()
00074 {
00075     if ( s_self == this )
00076     {
00077         assert( !s_refcnt );
00078 
00079         delete s_instance;
00080         delete s_about;
00081         delete s_settings;
00082     delete TDEHTMLSettings::avFamilies;
00083         if ( s_parts )
00084         {
00085             assert( s_parts->isEmpty() );
00086             delete s_parts;
00087         }
00088 
00089         s_instance = 0;
00090         s_about = 0;
00091         s_settings = 0;
00092         s_parts = 0;
00093     TDEHTMLSettings::avFamilies = 0;
00094 
00095         // clean up static data
00096         tdehtml::CSSStyleSelector::clear();
00097         tdehtml::RenderStyle::cleanup();
00098         tdehtml::Cache::clear();
00099         tdehtml::cleanup_thaibreaks();
00100         tdehtml::ArenaFinish();
00101     }
00102     else
00103         deref();
00104 }
00105 
00106 KParts::Part *TDEHTMLFactory::createPartObject( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const char *className, const TQStringList & )
00107 {
00108   TDEHTMLPart::GUIProfile prof = TDEHTMLPart::DefaultGUI;
00109   if ( strcmp( className, "Browser/View" ) == 0 )
00110     prof = TDEHTMLPart::BrowserViewGUI;
00111 
00112   return new TDEHTMLPart( parentWidget, widgetName, parent, name, prof );
00113 }
00114 
00115 void TDEHTMLFactory::ref()
00116 {
00117     if ( !s_refcnt && !s_self )
00118     {
00119         // we can't use a staticdeleter here, because that would mean
00120         // that the factory gets deleted from within a qPostRoutine, called
00121         // from the TQApplication destructor. That however is too late, because
00122         // we want to destruct a TDEInstance object, which involves destructing
00123         // a TDEConfig object, which might call TDEGlobal::dirs() (in sync()) which
00124         // probably is not going to work ;-)
00125         // well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
00126         // safe side ;-) -> let's use a simple reference counting scheme
00127         // (Simon)
00128         s_self = new TDEHTMLFactory;
00129         tdehtml::Cache::init();
00130     }
00131 
00132     s_refcnt++;
00133 }
00134 
00135 void TDEHTMLFactory::deref()
00136 {
00137     if ( !--s_refcnt && s_self )
00138     {
00139         delete s_self;
00140         s_self = 0;
00141     }
00142 }
00143 
00144 void TDEHTMLFactory::registerPart( TDEHTMLPart *part )
00145 {
00146     if ( !s_parts )
00147         s_parts = new TQPtrList<TDEHTMLPart>;
00148 
00149     if ( !s_parts->containsRef( part ) )
00150     {
00151         s_parts->append( part );
00152         ref();
00153     }
00154 }
00155 
00156 void TDEHTMLFactory::deregisterPart( TDEHTMLPart *part )
00157 {
00158     assert( s_parts );
00159 
00160     if ( s_parts->removeRef( part ) )
00161     {
00162         if ( s_parts->isEmpty() )
00163         {
00164             delete s_parts;
00165             s_parts = 0;
00166         }
00167         deref();
00168     }
00169 }
00170 
00171 TDEInstance *TDEHTMLFactory::instance()
00172 {
00173   assert( s_self );
00174 
00175   if ( !s_instance )
00176   {
00177     s_about = new TDEAboutData( "tdehtml", I18N_NOOP( "TDEHTML" ), "4.0",
00178                               I18N_NOOP( "Embeddable HTML component" ),
00179                               TDEAboutData::License_LGPL );
00180     s_about->addAuthor( "Lars Knoll", 0, "knoll@kde.org" );
00181     s_about->addAuthor( "Antti Koivisto", 0, "koivisto@kde.org" );
00182     s_about->addAuthor( "Waldo Bastian", 0, "bastian@kde.org" );
00183     s_about->addAuthor( "Dirk Mueller", 0, "mueller@kde.org" );
00184     s_about->addAuthor( "Peter Kelly", 0, "pmk@kde.org" );
00185     s_about->addAuthor( "Torben Weis", 0, "weis@kde.org" );
00186     s_about->addAuthor( "Martin Jones", 0, "mjones@kde.org" );
00187     s_about->addAuthor( "Simon Hausmann", 0, "hausmann@kde.org" );
00188     s_about->addAuthor( "Tobias Anton", 0, "anton@stud.fbi.fh-darmstadt.de" );
00189 
00190     s_instance = new TDEInstance( s_about );
00191   }
00192 
00193   return s_instance;
00194 }
00195 
00196 TDEHTMLSettings *TDEHTMLFactory::defaultHTMLSettings()
00197 {
00198   assert( s_self );
00199   if ( !s_settings )
00200     s_settings = new TDEHTMLSettings();
00201 
00202   return s_settings;
00203 }
00204 
00205 using namespace KParts;
00206 #include "tdehtml_factory.moc"
00207 

tdehtml

Skip menu "tdehtml"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdehtml

Skip menu "tdehtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.6.3
This website is maintained by Timothy Pearson.