1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/* This file is part of the KDE project
*
* Copyright (C) 2000 Simon Hausmann <[email protected]>
*
* 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 of the License, or (at your option) any later version.
*
* 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 "tdehtml_factory.h"
#include "tdehtml_part.h"
#include "tdehtml_settings.h"
#include "css/cssstyleselector.h"
#include "html/html_imageimpl.h"
#include "rendering/render_style.h"
#include "rendering/break_lines.h"
#include "misc/loader.h"
#include "misc/arena.h"
#include <kinstance.h>
#include <tdeaboutdata.h>
#include <tdelocale.h>
#include <assert.h>
#include <kdebug.h>
template class TQPtrList<TDEHTMLPart>;
extern "C" KDE_EXPORT void *init_libtdehtml()
{
// We can't use a plain self() here, because that would
// return the global factory, which might already exist
// at the time init_libtdehtml is called! As soon as someone
// does new TDEHTMLPart() in his application and loads up
// an html document into that part which either embeds
// embeds another TDEHTMLPart instance via <object> or
// as html frame, then we cannot return self(), as
// what we return here is what the KLibLoader deletes
// in the end, and we don't want the libloader to
// delete our global instance. Anyway, the new
// TDEHTMLFactory we create here is very cheap :)
// (Simon)
return new TDEHTMLFactory( true );
}
TDEHTMLFactory *TDEHTMLFactory::s_self = 0;
unsigned long int TDEHTMLFactory::s_refcnt = 0;
TDEInstance *TDEHTMLFactory::s_instance = 0;
TDEAboutData *TDEHTMLFactory::s_about = 0;
TDEHTMLSettings *TDEHTMLFactory::s_settings = 0;
TQPtrList<TDEHTMLPart> *TDEHTMLFactory::s_parts = 0;
TQString *TDEHTMLSettings::avFamilies = 0;
TDEHTMLFactory::TDEHTMLFactory( bool clone )
{
if ( clone )
ref();
}
TDEHTMLFactory::~TDEHTMLFactory()
{
if ( s_self == this )
{
assert( !s_refcnt );
delete s_instance;
delete s_about;
delete s_settings;
delete TDEHTMLSettings::avFamilies;
if ( s_parts )
{
assert( s_parts->isEmpty() );
delete s_parts;
}
s_instance = 0;
s_about = 0;
s_settings = 0;
s_parts = 0;
TDEHTMLSettings::avFamilies = 0;
// clean up static data
tdehtml::CSSStyleSelector::clear();
tdehtml::RenderStyle::cleanup();
tdehtml::Cache::clear();
tdehtml::cleanup_thaibreaks();
tdehtml::ArenaFinish();
}
else
deref();
}
KParts::Part *TDEHTMLFactory::createPartObject( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const char *className, const TQStringList & )
{
TDEHTMLPart::GUIProfile prof = TDEHTMLPart::DefaultGUI;
if ( strcmp( className, "Browser/View" ) == 0 )
prof = TDEHTMLPart::BrowserViewGUI;
return new TDEHTMLPart( parentWidget, widgetName, parent, name, prof );
}
void TDEHTMLFactory::ref()
{
if ( !s_refcnt && !s_self )
{
// we can't use a staticdeleter here, because that would mean
// that the factory gets deleted from within a qPostRoutine, called
// from the TQApplication destructor. That however is too late, because
// we want to destruct a TDEInstance object, which involves destructing
// a TDEConfig object, which might call TDEGlobal::dirs() (in sync()) which
// probably is not going to work ;-)
// well, perhaps I'm wrong here, but as I'm unsure I try to stay on the
// safe side ;-) -> let's use a simple reference counting scheme
// (Simon)
s_self = new TDEHTMLFactory;
tdehtml::Cache::init();
}
s_refcnt++;
}
void TDEHTMLFactory::deref()
{
if ( !--s_refcnt && s_self )
{
delete s_self;
s_self = 0;
}
}
void TDEHTMLFactory::registerPart( TDEHTMLPart *part )
{
if ( !s_parts )
s_parts = new TQPtrList<TDEHTMLPart>;
if ( !s_parts->containsRef( part ) )
{
s_parts->append( part );
ref();
}
}
void TDEHTMLFactory::deregisterPart( TDEHTMLPart *part )
{
assert( s_parts );
if ( s_parts->removeRef( part ) )
{
if ( s_parts->isEmpty() )
{
delete s_parts;
s_parts = 0;
}
deref();
}
}
TDEInstance *TDEHTMLFactory::instance()
{
assert( s_self );
if ( !s_instance )
{
s_about = new TDEAboutData( "tdehtml", I18N_NOOP( "TDEHTML" ), "4.0",
I18N_NOOP( "Embeddable HTML component" ),
TDEAboutData::License_LGPL );
s_about->addAuthor( "Lars Knoll", 0, "[email protected]" );
s_about->addAuthor( "Antti Koivisto", 0, "[email protected]" );
s_about->addAuthor( "Waldo Bastian", 0, "[email protected]" );
s_about->addAuthor( "Dirk Mueller", 0, "[email protected]" );
s_about->addAuthor( "Peter Kelly", 0, "[email protected]" );
s_about->addAuthor( "Torben Weis", 0, "[email protected]" );
s_about->addAuthor( "Martin Jones", 0, "[email protected]" );
s_about->addAuthor( "Simon Hausmann", 0, "[email protected]" );
s_about->addAuthor( "Tobias Anton", 0, "[email protected]" );
s_instance = new TDEInstance( s_about );
}
return s_instance;
}
TDEHTMLSettings *TDEHTMLFactory::defaultHTMLSettings()
{
assert( s_self );
if ( !s_settings )
s_settings = new TDEHTMLSettings();
return s_settings;
}
using namespace KParts;
#include "tdehtml_factory.moc"
|