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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
/*
* Copyright (C) 2001-2004, Richard J. Moore <[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 <stdio.h>
#include <string.h>
#include <errno.h>
#include <tqobject.h>
#include <tqcombobox.h>
#include <tqdialog.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqimage.h>
#include <tqlistview.h>
#include <tqmainwindow.h>
//#include <tqpainter.h>
#include <tqprogressdialog.h>
#include <tqtextstream.h>
#include <tqtimer.h>
#include <tqwidget.h>
#include <tqwidgetfactory.h>
#include <tqsplitter.h>
#include <tqscrollview.h>
#include <tqcanvas.h>
#include <tqlayout.h>
#include <tqsplashscreen.h>
#ifndef QT_ONLY
#include <tdeapplication.h>
#include <dcopref.h>
#include <dcopclient.h>
#include <tdeaction.h>
#include <klibloader.h>
#include <tdelocale.h>
#include <tdemainwindow.h>
#include <kservice.h>
#include <ksystemtray.h>
#include <ktrader.h>
#include <tdeparts/part.h>
#include <tdeparts/mainwindow.h>
#include <tdeparts/componentfactory.h>
#endif // QT_ONLY
#include <kjs/interpreter.h>
#include <kjs/identifier.h>
#include <kjs/types.h>
#include "jsbinding.h"
#include "jsbindingbase.h"
#include "jsobjectproxy.h"
#include "jsopaqueproxy.h"
#include "jsvalueproxy.h"
#include "jsconsolewidget.h"
#include "jseventmapper.h"
#include "jseventutils.h"
#include "kjsembedpart.h"
#include "customobject_imp.h"
#include "builtins/stddialog_imp.h"
#include "builtins/textstream_imp.h"
#include "builtins/qdir_imp.h"
#include "qtbindings/qcombobox_imp.h"
#include "qtbindings/qpopupmenu_imp.h"
#include "qtbindings/qlistviewitem_imp.h"
#include "qtbindings/qchecklistitem_imp.h"
#include "qtbindings/qcanvasellipse_imp.h"
#include "qtbindings/qcanvas_imp.h"
#include "qtbindings/qcanvasitem_imp.h"
#include "qtbindings/qcanvasitemlist_imp.h"
#include "qtbindings/qcanvasline_imp.h"
#include "qtbindings/qcanvaspixmaparray_imp.h"
#include "qtbindings/qcanvaspixmap_imp.h"
#include "qtbindings/qcanvaspolygonalitem_imp.h"
#include "qtbindings/qcanvaspolygon_imp.h"
#include "qtbindings/qcanvasrectangle_imp.h"
#include "qtbindings/qcanvasspline_imp.h"
#include "qtbindings/qcanvassprite_imp.h"
#include "qtbindings/qcanvastext_imp.h"
#include "qtbindings/qcanvasview_imp.h"
#ifndef QT_ONLY
#include "builtins/stdaction_imp.h"
#include "bindings/dcop_imp.h"
#include "bindings/netaccess_imp.h"
#endif // QT_ONLY
#include "bindings/image_imp.h"
#include "bindings/pen_imp.h"
#include "bindings/pixmap_imp.h"
#include "bindings/painter_imp.h"
#include "bindings/movie_imp.h"
#include "bindings/sql_imp.h"
#include "bindings/tdeconfig_imp.h"
#include "bindings/brush_imp.h"
#include "bindings/size_imp.h"
#include "bindings/rect_imp.h"
#include "bindings/point_imp.h"
#include "global.h"
#include "jsbindingplugin.h"
#include "jsfactory_imp.h"
#include "jsfactory.h"
//
// KPart Implementation
//
namespace KJSEmbed {
typedef Bindings::JSFactoryImp JSFactoryImp;
typedef Bindings::CustomObjectImp CustomObjectImp;
typedef BuiltIns::StdDialogImp StdDialogImp;
typedef BuiltIns::TextStreamImp TextStreamImp;
class JSFactoryPrivate {
public:
TQDict<KJSEmbed::Bindings::JSBindingPlugin> plugins;
TQDict<KJSEmbed::Bindings::JSBindingBase> opaqueTypes;
TQDict<KJSEmbed::Bindings::JSBindingBase> objectTypes;
};
JSFactory::JSFactory( KJSEmbedPart *part )
: jspart( part ) {
evmapper = new JSEventMapper();
d = new JSFactoryPrivate;
registerOpaqueType("TQDir", new Bindings::TQDirLoader());
registerOpaqueType("TQCheckListItem", new Bindings::TQCheckListItemLoader());
registerOpaqueType("TQListViewItem", new Bindings::TQListViewItemLoader());
registerOpaqueType("Painter", new Bindings::PainterLoader());
#ifndef QT_ONLY
registerOpaqueType("DCOPClient", new Bindings::JSDCOPClientLoader());
registerObjectType("DCOPInterface", new Bindings::JSDCOPInterfacerLoader());
registerOpaqueType("DCOPRef", new Bindings::JSDCOPRefLoader());
#endif
}
JSFactory::~JSFactory() {
delete evmapper;
}
void JSFactory::addBindingPluginTypes( KJS::ExecState *exec, KJS::Object &parent ) {
#ifndef QT_ONLY
// Get list of valid plugin types
TDETrader::OfferList offers = TDETrader::self() ->query( "JSBindingPlugin/Binding" );
if ( !offers.count() )
return ;
TDETrader::OfferListIterator itr = offers.begin();
while ( itr != offers.end() ) {
TQString classname = ( *itr ) ->name();
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classname );
parent.put( exec, KJS::Identifier( cons->parameter() ), KJS::Object( cons ) );
addType( classname, TypePlugin );
++itr;
}
#else
Q_UNUSED( exec );
Q_UNUSED( parent );
#endif // QT_ONLY
}
bool JSFactory::isBindingPlugin( const TQString &classname ) const {
if ( !isSupported( classname ) )
return false;
return ( objtypes[ classname ] & TypePlugin );
}
KJS::Object JSFactory::createBindingPlugin( KJS::ExecState *exec, const TQString &classname, const KJS::List &args ) {
#ifndef QT_ONLY
Bindings::JSBindingPlugin * plugin = d->plugins[ classname ];
if ( plugin == 0L ) {
TQString query = "JSBindingPlugin/Binding";
TQString constraint = "[Name] == '" + classname + "'";
plugin = KParts::ComponentFactory::createInstanceFromQuery<Bindings::JSBindingPlugin>( query, constraint );
if ( plugin != 0L )
d->plugins.insert( classname, plugin );
}
if ( plugin != 0L )
return plugin->createBinding( jspart, exec, args );
#else
Q_UNUSED( exec );
Q_UNUSED( args );
#endif // QT_ONLY
kdWarning( 80001 ) << "Unable to load binding " << classname << "." << endl;
return KJS::Object();
}
KJS::Object JSFactory::create( KJS::ExecState *exec, const TQString &classname, const KJS::List &args ) {
KJS::Object returnObject;
if ( !isSupported( classname ) ) {
TQString msg = i18n( "Object of type '%1' is not supported." ).arg( classname );
return throwError(exec, msg,KJS::TypeError);
}
if ( isTQObject( classname ) ) {
// create via widget factory...
Bindings::JSBindingBase *factory = d->objectTypes.find(classname);
if( factory ) {
returnObject = factory->createBinding( jspart, exec, args );
JSProxy::toProxy( returnObject.imp() ) ->setOwner( JSProxy::JavaScript );
} else {
TQObject *parent = extractTQObject(exec, args, 0);
TQString name = extractTQString(exec, args, 1);
TQObject *obj = create( classname, parent, name.latin1() );
if ( obj ) {
returnObject = createProxy( exec, obj );
JSProxy::toProxy( returnObject.imp() ) ->setOwner( JSProxy::JavaScript );
} else {
TQString msg = i18n( "TQObject of type '%1' could not be created." ).arg( classname );
returnObject = throwError(exec, msg,KJS::TypeError);
}
}
} else if ( isOpaque( classname ) ) {
// Try to create from the registry
Bindings::JSBindingBase *factory = d->opaqueTypes.find(classname);
if( factory )
returnObject = factory->createBinding( jspart, exec, args );
else
returnObject = createOpaque( exec, classname, args );
if ( !returnObject.isValid() ) {
TQString msg = i18n( "Opaque object of type '%1' could not be created." ).arg( classname );
returnObject = throwError(exec, msg,KJS::TypeError);
}
} else if ( isValue( classname ) ) {
returnObject = createValue( exec, classname, args );
if ( !returnObject.isValid() ) {
TQString msg = i18n( "Value object of type '%1' could not be created." ).arg( classname );
returnObject = throwError(exec, msg,KJS::TypeError);
}
} else if ( isBindingPlugin( classname ) ) {
returnObject = createBindingPlugin( exec, classname, args );
if ( !returnObject.isValid() ) {
TQString msg = i18n( "Plugin object of type '%1' could not be created." ).arg( classname );
returnObject = throwError(exec, msg,KJS::TypeError);
} else
JSProxy::toProxy( returnObject.imp() ) ->setOwner( JSProxy::JavaScript );
} else {
TQString msg = i18n( "Could not create object of type '%1'." ).arg( classname );
returnObject = throwError(exec, msg,KJS::TypeError);
}
return returnObject;
}
KJS::Object JSFactory::createProxy( KJS::ExecState *exec, TQObject *target,
const JSObjectProxy *ctx ) const {
kdDebug( 80001 ) << "JSFactory::createProxy: Target '" << target->name()
<< "' type " << target->className() << endl;
JSObjectProxy *prx;
if ( ctx )
prx = new JSObjectProxy( jspart, target, ctx->rootObject(), ctx->securityPolicy() );
else {
prx = new JSObjectProxy( jspart, target );
}
kdDebug( 80001 ) << "Proxy created" << endl;
KJS::Object proxyObj( prx );
prx->addBindings( exec, proxyObj );
extendProxy( exec, proxyObj );
prx->setOwner(JSProxy::Native);
kdDebug( 80001 ) << "Returning object" << endl;
return proxyObj;
}
KJS::Object JSFactory::createProxy( KJS::ExecState *exec,
TQTextStream *target, const JSObjectProxy *context ) const {
Q_UNUSED( context )
kdDebug( 80001 ) << "TextStream proxy created" << endl;
JSOpaqueProxy *prx = new JSOpaqueProxy( target );
KJS::Object proxyObj( prx );
prx->addBindings( exec, proxyObj );
TextStreamImp::addBindings( exec, proxyObj );
return proxyObj;
}
KJS::Object JSFactory::createProxy( KJS::ExecState *exec,
TQEvent *target, const JSObjectProxy *context ) const {
switch ( target->type() ) {
case TQEvent::MouseButtonPress:
case TQEvent::MouseButtonRelease:
case TQEvent::MouseMove:
case TQEvent::MouseButtonDblClick:
return JSEventUtils::convertEvent( exec, ( TQMouseEvent * ) target, context );
break;
case TQEvent::KeyPress:
case TQEvent::KeyRelease:
case TQEvent::Accel:
case TQEvent::AccelOverride:
return JSEventUtils::convertEvent( exec, ( TQKeyEvent * ) target, context );
break;
case TQEvent::IMStart:
case TQEvent::IMCompose:
case TQEvent::IMEnd:
return JSEventUtils::convertEvent( exec, ( TQIMEvent * ) target, context );
break;
case TQEvent::Paint:
return JSEventUtils::convertEvent( exec, ( TQPaintEvent * ) target, context );
break;
case TQEvent::Resize:
return JSEventUtils::convertEvent( exec, ( TQResizeEvent * ) target, context );
break;
case TQEvent::FocusIn:
case TQEvent::FocusOut:
return JSEventUtils::convertEvent( exec, ( TQFocusEvent * ) target, context );
break;
case TQEvent::Close:
return JSEventUtils::convertEvent( exec, ( TQCloseEvent * ) target, context );
break;
case TQEvent::ChildInserted:
case TQEvent::ChildRemoved:
return JSEventUtils::convertEvent( exec, ( TQChildEvent * ) target, context );
break;
case TQEvent::Move:
return JSEventUtils::convertEvent( exec, ( TQMoveEvent * ) target, context );
break;
case TQEvent::Wheel:
return JSEventUtils::convertEvent( exec, ( TQWheelEvent * ) target, context );
break;
case TQEvent::Timer:
return JSEventUtils::convertEvent( exec, ( TQTimerEvent * ) target, context );
break;
case TQEvent::ContextMenu:
return JSEventUtils::convertEvent( exec, ( TQContextMenuEvent * ) target, context );
break;
case TQEvent::DragMove:
case TQEvent::DragEnter:
return JSEventUtils::convertEvent( exec, ( TQDragMoveEvent * ) target, context );
break;
case TQEvent::Drop:
return JSEventUtils::convertEvent( exec, ( TQDropEvent * ) target, context );
break;
case TQEvent::Enter:
case TQEvent::Leave:
case TQEvent::Clipboard:
case TQEvent::DragLeave:
case TQEvent::Show:
case TQEvent::Hide:
return JSEventUtils::convertEvent( exec, ( TQEvent * ) target, context );
break;
default:
break;
}
return JSEventUtils::convertEvent( exec, ( TQEvent * ) target, context );
}
KJS::Object JSFactory::extendProxy( KJS::ExecState *exec, KJS::Object &target ) const {
CustomObjectImp::addBindings( exec, target );
addBindingsPlugin( exec, target );
return target;
}
void JSFactory::addBindingsPlugin( KJS::ExecState *exec, KJS::Object &target ) const {
kdDebug( 800001 ) << "JSFactory::addBindingsPlugin" << endl;
JSObjectProxy *proxy = JSProxy::toObjectProxy( target.imp() );
if ( !proxy )
return ;
if ( !isBindingPlugin( proxy->object() ->className() ) )
return ;
#ifndef QT_ONLY
Bindings::JSBindingPlugin *plugin = d->plugins[ proxy->object() ->className() ];
if ( plugin == 0L ) {
TQString query = "JSBindingPlugin/Binding";
TQString constraint = "[Name] == '" + TQString::fromUtf8( proxy->object() ->className() ) + "'";
plugin = KParts::ComponentFactory::createInstanceFromQuery<Bindings::JSBindingPlugin>( query, constraint );
if ( plugin != 0L )
d->plugins.insert( proxy->object() ->className(), plugin );
}
if ( plugin != 0L ) {
kdDebug( 800001 ) << "JSFactory::addBindingsPlugin: calling plugin function" << endl;
plugin->addBindings( exec, target );
return ;
}
#else
Q_UNUSED( exec );
#endif // QT_ONLY
kdWarning( 80001 ) << "Unable to add bindings to " << proxy->object() ->className() << "." << endl;
return ;
}
TQObject *JSFactory::createBinding( const TQString &cname, TQObject *parent, const char *name ) {
#ifndef QT_ONLY
// Bindings
/*if ( cname == "DCOPInterface" )
return new Bindings::JSDCOPInterface( jspart->interpreter(), parent, name );
else */if ( cname == "NetAccess" )
return new Bindings::NetAccess( parent, name );
else
#endif // QT_ONLY
if ( cname == "Movie" )
return new Bindings::Movie( parent, name );
else if ( cname == "SqlDatabase" )
return new Bindings::SqlDatabase( parent, name );
else if ( cname == "SqlQuery" )
return new Bindings::SqlQuery( parent, name );
else if ( cname == "Config" )
return new Bindings::Config( parent, name );
return 0;
}
TQObject *JSFactory::createObject( const TQString &cname, TQObject *parent, const char *name ) {
// TQObjects defined by Qt
if ( cname == "TQObject" )
return new TQObject( parent, name );
else if ( cname == "TQTimer" )
return new TQTimer( parent, name );
else if ( cname == "TQCanvas" )
return new TQCanvas( parent, name );
#ifndef QT_ONLY
// TQObjects defined by KDE
else if ( cname == "TDEAction" )
return new TDEAction( parent, name );
else if ( cname == "TDEToggleAction" )
return new TDEToggleAction( parent, name );
#endif // QT_ONLY
TQWidget *w = dynamic_cast<TQWidget *>( parent );
if ( !w )
return 0;
if ( cname == "TQHBoxLayout" )
return new TQHBoxLayout( w, 0, -1, name );
else if ( cname == "TQVBoxLayout" )
return new TQVBoxLayout( w, 0, -1, name );
return 0;
}
KJS::Object JSFactory::createOpaque( KJS::ExecState *exec, const TQString &cname, const KJS::List &args ) {
if ( cname == "TQCanvasText" ) {
kdDebug( 80001 ) << "Creating canvas item, type is " << cname << endl;
JSOpaqueProxy *prx = 0;
if ( args.size() == 0 ) {
// FALL THRU
} else if ( args.size() == 1 ) {
JSObjectProxy * arg0 = JSProxy::toObjectProxy( args[ 0 ].imp() );
if ( arg0 ) {
TQObject * obj0 = arg0->object();
if ( obj0->inherits( "TQCanvas" ) ) {
TQCanvas * parent = ( TQCanvas * ) ( obj0 );
prx = new JSOpaqueProxy( new TQCanvasText( parent ), "TQCanvasText" );
KJS::Object proxyObj( prx );
TQCanvasItemImp::addBindings( exec, proxyObj );
TQCanvasTextImp::addBindings( exec, proxyObj );
return proxyObj;
} else {
kdDebug( 80001 ) << " canvas item create failed, arg0 is " << obj0->className() << endl;
return KJS::Object();
}
} else {
kdDebug( 80001 ) << " canvas item create failed, arg0 is not an object" << endl;
return KJS::Object();
}
} else if ( args.size() == 2 ) {
TQString arg0 = args[ 0 ].toString( exec ).qstring();
JSObjectProxy *arg1 = JSProxy::toObjectProxy( args[ 1 ].imp() );
if ( arg1 ) {
TQString arg0 = args[ 0 ].toString( exec ).qstring();
TQObject *obj1 = arg1->object();
if ( obj1->inherits( "TQCanvas" ) ) {
TQCanvas * parent = ( TQCanvas * ) ( obj1 );
prx = new JSOpaqueProxy( new TQCanvasText( parent ), "TQCanvasText" );
KJS::Object proxyObj( prx );
TQCanvasItemImp::addBindings( exec, proxyObj );
TQCanvasTextImp::addBindings( exec, proxyObj );
return proxyObj;
} else {
kdDebug( 80001 ) << " canvas item create failed, arg0 is " << obj1->className() << endl;
return KJS::Object();
}
} else {
kdDebug( 80001 ) << " canvas item create failed, arg1 is not an object" << endl;
return KJS::Object();
}
}
}
return KJS::Object();
}
KJS::Object JSFactory::createValue( KJS::ExecState *exec, const TQString &cname, const KJS::List & args ) {
if ( cname == "Image" ) {
TQImage img = TQImage();
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( img );
KJS::Object proxyObj( prx );
Bindings::ImageImp::addBindings( exec, proxyObj );
return proxyObj;
}
if ( cname == "Pixmap" ) {
TQPixmap pix = TQPixmap();
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( pix );
KJS::Object proxyObj( prx );
Bindings::Pixmap::addBindings( exec, proxyObj );
return proxyObj;
}
if ( cname == "Brush" ) {
TQBrush brsh;
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( brsh );
KJS::Object proxyObj( prx );
Bindings::BrushImp::addBindings( exec, proxyObj );
return proxyObj;
}
if ( cname == "Pen" ) {
TQPen pen;
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( pen );
KJS::Object proxyObj( prx );
Bindings::Pen::addBindings( exec, proxyObj );
return proxyObj;
}
if ( cname == "Rect" ) {
TQRect rect;
if ( args.size() == 4 ) {
rect.setX( extractInt( exec, args, 0 ) );
rect.setY( extractInt( exec, args, 1 ) );
rect.setWidth( extractInt( exec, args, 2 ) );
rect.setHeight( extractInt( exec, args, 3 ) );
}
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( rect );
KJS::Object proxyObj( prx );
Bindings::Rect::addBindings( exec, proxyObj );
return proxyObj;
}
if ( cname == "Point" ) {
TQPoint point;
if ( args.size() == 2 ) {
point.setX( extractInt( exec, args, 0 ) );
point.setY( extractInt( exec, args, 1 ) );
}
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( point );
KJS::Object proxyObj( prx );
Bindings::Point::addBindings( exec, proxyObj );
return proxyObj;
}
if ( cname == "Size" ) {
TQSize size;
if ( args.size() == 2 ) {
size.setWidth( extractInt( exec, args, 0 ) );
size.setHeight( extractInt( exec, args, 1 ) );
}
JSValueProxy *prx = new JSValueProxy( );
prx->setValue( size );
KJS::Object proxyObj( prx );
Bindings::Size::addBindings( exec, proxyObj );
return proxyObj;
}
return KJS::Object();
}
TQWidget *JSFactory::createWidget( const TQString &cname, TQWidget *pw, const char *name ) {
if ( cname == "TQSplitter" )
return new TQSplitter( pw, name );
else if ( cname == "TQMainWindow" )
return new TQMainWindow( pw, name );
else if ( cname == "TQProgressDialog" )
return new TQProgressDialog( pw, name );
else if ( cname == "TQScrollView" )
return new TQScrollView( pw, name );
else if ( cname == "TQCanvasView" )
return new TQCanvasView( pw, name );
else if ( cname == "TQSplashScreen" ) {
TQPixmap pix( 16, 16 );
pix.fill();
return new TQSplashScreen( pix );
}
#ifndef QT_ONLY
else if ( cname == "TDEMainWindow" )
return new TDEMainWindow( pw, name );
else if ( cname == "KParts_MainWindow" )
return new KParts::MainWindow( pw, name );
else if ( cname == "KSystemTray" )
return new KSystemTray( pw, name );
#endif // QT_ONLY
return 0;
}
TQObject *JSFactory::create( const TQString &cname, TQObject *parent, const char *name ) {
kdDebug( 80001 ) << "KJSEmbedPart::create() name " << name << " class " << cname << endl;
// Factory widgets
TQWidgetFactory wf;
TQWidget *pw = ( parent && parent->isWidgetType() ) ? static_cast<TQWidget *>( parent ) : 0;
TQWidget *w = wf.createWidget( cname, pw, name );
if ( w ) {
kdDebug( 80001 ) << "Created from factory" << endl;
return w;
}
// Custom widgets
TQObject *obj;
obj = createWidget( cname, pw, name );
if ( obj ) {
if ( !isTQObject( obj->className() ) )
addType( obj->className() );
kdDebug( 80001 ) << "Created from createWidget" << endl;
return obj;
}
// Custom objects
obj = JSFactory::createObject( cname, parent, name );
if ( obj ) {
if ( !isTQObject( obj->className() ) )
addType( obj->className() );
kdDebug( 80001 ) << "Created from createObject" << endl;
return obj;
}
// Binding objects
obj = JSFactory::createBinding( cname, parent, name );
if ( obj ) {
if ( !isTQObject( obj->className() ) )
addType( obj->className() );
kdDebug( 80001 ) << "Created from bindings" << endl;
return obj;
}
kdDebug( 80001 ) << "Found nothing in :" << cname << ":" << endl;
return 0;
}
KParts::ReadOnlyPart *JSFactory::createROPart( const TQString &svc, TQObject *parent, const char *name ) {
kdDebug( 80001 ) << "JSFactory::createROPart svc " << svc << " parent " << ( long ) parent << endl;
return createROPart( svc, "'KParts/ReadOnlyPart' in ServiceTypes", parent, name );
}
KParts::ReadOnlyPart *JSFactory::createROPart( const TQString &svc, const TQString &con,
TQObject *parent, const char *name ) {
kdDebug( 80001 ) << "JSFactory::createROPart svc " << svc << " constraint " << con
<< " parent " << ( long ) parent << endl;
return createROPart( svc, con, parent, name, TQStringList() );
}
KParts::ReadOnlyPart *JSFactory::createROPart( const TQString &svc, const TQString &con,
TQObject *parent, const char *name,
const TQStringList &args ) {
#ifndef QT_ONLY
kdDebug( 80001 ) << "JSFactory::createROPart svc " << svc << " constraint " << con
<< " parent " << ( long ) parent
<< " args: " << args << endl;
TDETrader::OfferList offers = TDETrader::self() ->query( svc, con );
if ( !offers.count() )
return 0;
KService::Ptr ptr = offers.first();
KLibFactory *fact = KLibLoader::self() ->factory( ptr->library().ascii() );
if ( !fact ) {
kdDebug( 80001 ) << "Unable to find a matching part" << endl;
return 0;
}
TQObject *obj = fact->create( parent, name, "KParts::ReadOnlyPart", args );
addType( obj->className() );
return static_cast<KParts::ReadOnlyPart *>( obj );
#else // QT_ONLY
Q_UNUSED( svc );
Q_UNUSED( con );
Q_UNUSED( parent );
Q_UNUSED( name );
Q_UNUSED( args );
return 0;
#endif // QT_ONLY
}
KParts::ReadWritePart *JSFactory::createRWPart( const TQString &svc, TQObject *parent, const char *name ) {
kdDebug( 80001 ) << "JSFactory::createRWPart svc " << svc << " parent " << ( long ) parent << endl;
return createRWPart( svc, "'KParts/ReadWritePart' in ServiceTypes", parent, name );
}
KParts::ReadWritePart *JSFactory::createRWPart( const TQString &svc, const TQString &con,
TQObject *parent, const char *name ) {
kdDebug( 80001 ) << "JSFactory::createRWPart svc " << svc << " constraint " << con
<< " parent " << ( long ) parent << endl;
return createRWPart( svc, con, parent, name, TQStringList() );
}
KParts::ReadWritePart *JSFactory::createRWPart( const TQString &svc, const TQString &con,
TQObject *parent, const char *name,
const TQStringList &args ) {
#ifndef QT_ONLY
kdDebug( 80001 ) << "JSFactory::createRWPart svc " << svc << " constraint " << con
<< " parent " << ( long ) parent
<< " args: " << args << endl;
TDETrader::OfferList offers = TDETrader::self() ->query( svc, con );
if ( !offers.count() )
return 0;
KService::Ptr ptr = offers.first();
KLibFactory *fact = KLibLoader::self() ->factory( ptr->library().ascii() );
if ( !fact ) {
kdDebug( 80001 ) << "Unable to find a matching part" << endl;
return 0;
}
TQObject *obj = fact->create( parent, name, "KParts::ReadWritePart", args );
addType( obj->className() );
return static_cast<KParts::ReadWritePart *>( obj );
#else // QT_ONLY
Q_UNUSED( svc );
Q_UNUSED( con );
Q_UNUSED( parent );
Q_UNUSED( name );
Q_UNUSED( args );
return 0;
#endif // QT_ONLY
}
TQWidget *JSFactory::loadUI( const TQString &uiFile, TQObject *connector, TQWidget *parent, const char *name ) {
return TQWidgetFactory::create( uiFile, connector, parent, name );
}
TQStringList JSFactory::listBindingPlugins( KJS::ExecState *exec, KJS::Object &self ) {
Q_UNUSED( exec )
Q_UNUSED( self )
TQStringList pluginList;
TQStringList allTypes = objtypes.keys();
for ( uint idx = 0; idx < allTypes.count(); ++idx ) {
if ( objtypes[ allTypes[ idx ] ] & TypePlugin )
pluginList.append( allTypes[ idx ] );
}
return pluginList;
}
bool JSFactory::isTQObject( const TQString &clazz ) const {
if ( !isSupported( clazz ) )
return false;
return ( objtypes[ clazz ] & TypeTQObject );
}
bool JSFactory::isValue( const TQString &clazz ) const {
if ( !isSupported( clazz ) )
return false;
return objtypes[ clazz ] == TypeValue;
}
bool JSFactory::isOpaque( const TQString &clazz ) const {
if ( !isSupported( clazz ) )
return false;
return objtypes[ clazz ] == TypeOpaque;
}
void JSFactory::addTQObjectPlugin( const TQString &classname, KJSEmbed::Bindings::JSBindingPlugin* plugin ) {
if ( plugin ) {
addType( classname, TypeTQObjectPlugin );
d->plugins.insert( classname, plugin );
}
}
void JSFactory::addType( const TQString &clazz, uint prxtype ) {
if ( prxtype == TypeInvalid ) {
objtypes.remove( clazz );
return ;
}
kdDebug() << "Add type " << clazz << endl;
objtypes[ clazz ] = prxtype;
}
bool JSFactory::isSupported( const TQString &clazz ) const {
kdDebug() << "Checking " << clazz << endl;
return objtypes.contains( clazz );
}
uint JSFactory::proxyType( const TQString &clazz ) const {
if ( !isSupported( clazz ) )
return TypeInvalid;
return objtypes[ clazz ];
}
void JSFactory::addTypes( KJS::ExecState *exec, KJS::Object &parent ) {
addWidgetFactoryTypes( exec, parent );
addCustomTypes( exec, parent );
addBindingTypes( exec, parent );
addObjectTypes( exec, parent );
addOpaqueTypes( exec, parent );
addValueTypes( exec, parent );
addBindingPluginTypes( exec, parent );
}
TQStringList JSFactory::types() const {
return objtypes.keys();
}
void JSFactory::addWidgetFactoryTypes( KJS::ExecState *exec, KJS::Object &parent ) {
TQStringList sl = TQWidgetFactory::widgets();
for ( TQStringList::Iterator it = sl.begin(); it != sl.end(); ++it ) {
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, *it );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( *it );
}
}
void JSFactory::addCustomTypes( KJS::ExecState *exec, KJS::Object &parent ) {
const char * classes[] = {
"TQSplitter", "TQScrollView", "TQCanvasView", "TQCanvas",
"TQObject", "TQTimer", "TQSplashScreen", "TQProgressDialog",
"TQLayout", "TQBoxLayout", "TQHBoxLayout", "TQVBoxLayout",
#ifndef QT_ONLY
"TDEMainWindow", "KXMLGUIClient", "KSystemTray",
"TDEAction", "TDEToggleAction",
"KParts_MainWindow",
#endif // QT_ONLY
0
};
for ( int i = 0 ; classes[ i ] ; i++ ) {
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classes[ i ] );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( classes[ i ] );
}
}
void JSFactory::addBindingTypes( KJS::ExecState *exec, KJS::Object &parent ) {
const char * bindings[] = {
"Pixmap", "KJSEmbed::Bindings::Pixmap",
"SqlDatabase", "KJSEmbed::Bindings::SqlDatabase",
"Movie", "KJSEmbed::Bindings::Movie",
"SqlQuery", "KJSEmbed::Bindings::SqlQuery",
#ifndef QT_ONLY
"NetAccess", "KJSEmbed::Bindings::NetAccess",
/*"DCOPInterface", "KJSEmbed::Bindings::JSDCOPInterface",*/
#endif
"Config", "KJSEmbed::Bindings::Config",
0, 0
};
for ( int i = 0 ; bindings[ i ] ; i += 2 ) {
JSFactoryImp * cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, bindings[ i ] );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( bindings[ i ] );
addType( bindings[ i + 1 ] );
}
}
void JSFactory::addOpaqueTypes( KJS::ExecState *exec, KJS::Object &parent ) {
const char * classes[] = {
"TQTextStream",
"TextStream",
"TQCanvasItem",
"TQCanvasText",
0
};
for ( int i = 0 ; classes[ i ] ; i++ ) {
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classes[ i ] );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( classes[ i ], TypeOpaque );
}
// Create the custom added types.
TQDictIterator<KJSEmbed::Bindings::JSBindingBase> idx( d->opaqueTypes );
for( ; idx.current(); ++idx){
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, idx.currentKey() );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( idx.currentKey(), TypeOpaque );
}
}
void JSFactory::addValueTypes( KJS::ExecState *exec, KJS::Object &parent ) {
const char * classes[] = {
"Image",
"Brush",
"Pixmap",
"Pen",
"Rect",
"Size",
"Point",
0
};
for ( int i = 0 ; classes[ i ] ; i++ ) {
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classes[ i ] );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( classes[ i ], TypeValue );
}
}
void JSFactory::addObjectTypes( KJS::ExecState *exec, KJS::Object & parent ) {
const char * classes[] = {
"TQAccel",
"TQAccessibleObject",
"TQAction",
"TQActionGroup",
"TQApplication",
"TQAquaStyle",
"TQAssistantClient",
"TQAxObject",
"TQAxWidget",
"TQButton",
"TQCDEStyle",
"TQClipboard",
"TQColorDialog",
"TQColorDrag",
"TQComboBox",
"TQCommonStyle",
"TQCopChannel",
"TQDataPump",
"TQDateTimeEditBase",
"TQDesktopWidget",
"TQDns",
"TQDockArea",
"TQDockWindow",
"TQDoubleValidator",
"TQDragObject",
"TQEditorFactory",
"TQErrorMessage",
"TQEventLoop",
"TQFileDialog",
"TQFileIconProvider",
"TQFontDialog",
"TQFtp",
"TQGLWidget",
"TQGridLayout",
"TQGridView",
"TQHButtonGroup",
"TQHGroupBox",
"TQHeader",
"TQHttp",
"TQIconDrag",
"TQImageDrag",
"TQInputDialog",
"TQIntValidator",
"TQLocalFs",
"TQMacStyle",
"TQMenuBar",
"TQMessageBox",
"TQMotif",
"TQMotifDialog",
"TQMotifPlusStyle",
"TQMotifStyle",
"TQMotifWidget",
"TQNPInstance",
"TQNPWidget",
"TQNetworkOperation",
"TQNetworkProtocol",
"TQObjectCleanupHandler",
"TQPlatinumStyle",
"TQProcess",
"TQPopupMenu",
"TQProgressDialog",
"TQRegExpValidator",
"TQSGIStyle",
"TQServerSocket",
"TQSessionManager",
"TQSignal",
"TQSignalMapper",
"TQSizeGrip",
"TQSocket",
"TQSocketNotifier",
"TQSound",
"TQSqlDatabase",
"TQSqlDriver",
"TQSqlEditorFactory",
"TQSqlForm",
"TQStatusBar",
"TQStoredDrag",
"TQStyle",
"TQStyleSheet",
"TQTabBar",
"TQTabDialog",
"TQTextDrag",
"TQToolBar",
"TQToolTipGroup",
"TQTranslator",
"TQUriDrag",
"TQUrlOperator",
"TQVButtonGroup",
"TQVGroupBox",
"TQValidator",
"TQWSKeyboardHandler",
"TQWindowsStyle",
"TQWindowsXPStyle",
"TQWorkspace",
"TQXtWidget",
0
};
for ( int i = 0 ; classes[ i ] ; i++ ) {
if ( !isSupported( classes[ i ] ) )
addType( classes[ i ] );
}
// Create the custom added types.
TQDictIterator<KJSEmbed::Bindings::JSBindingBase> idx( d->objectTypes );
for( ; idx.current(); ++idx){
JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, idx.currentKey() );
parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) );
addType( idx.currentKey(), TypeTQObject );
}
}
void JSFactory::registerOpaqueType( const TQString & className, KJSEmbed::Bindings::JSBindingBase * bindingFactory )
{
d->opaqueTypes.insert(className,bindingFactory);
}
void JSFactory::unregisterOpaqueType( const TQString & className )
{
d->opaqueTypes.remove(className);
}
void JSFactory::extendOpaqueProxy( KJS::ExecState * exec, KJS::Object &proxy ) const
{
JSOpaqueProxy *prx = JSProxy::toOpaqueProxy( proxy.imp() );
if( prx )
{
kdDebug() << "Looking for " << prx->typeName() << endl;
Bindings::JSBindingBase *bindingFactory = d->opaqueTypes.find( prx->typeName() );
if( bindingFactory )
{
kdDebug() << "Extending proxy" << endl;
bindingFactory->addBindings(jspart, exec, proxy );
}
}
}
void JSFactory::registerObjectType( const TQString & className, KJSEmbed::Bindings::JSBindingBase * bindingFactory )
{
d->objectTypes.insert(className,bindingFactory);
}
void JSFactory::unregisterObjectType( const TQString & className )
{
d->objectTypes.remove(className);
}
void JSFactory::extendObjectProxy( KJS::ExecState * exec, KJS::Object &proxy ) const
{
JSObjectProxy *prx = JSProxy::toObjectProxy( proxy.imp() );
if( prx )
{
kdDebug() << "Looking for " << prx->typeName() << endl;
Bindings::JSBindingBase *bindingFactory = d->objectTypes.find( prx->typeName() );
if( bindingFactory )
{
kdDebug() << "Extending proxy" << endl;
bindingFactory->addBindings(jspart, exec, proxy );
}
}
}
}// namespace KJSEmbed
// Local Variables:
// c-basic-offset: 4
// End:
|